]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Initialize foundation elements in ajax-loaded content; protect against 4884/head
authorBen Schreiber <ben@fastmodeltechnologies.com>
Thu, 3 Apr 2014 16:05:09 +0000 (09:05 -0700)
committerBen Schreiber <ben@fastmodeltechnologies.com>
Thu, 3 Apr 2014 16:05:09 +0000 (09:05 -0700)
multiple instances of reveal target id; be explicit about background
visibility

js/foundation/foundation.reveal.js

index 288a4a71ff01df3a7def1225f99d8c031adda1ae..1063913978adcb38ab70dda2e3157ce199286a0c 100644 (file)
       var self = this;
       if (target) {
         if (typeof target.selector !== 'undefined') {
-          var modal = self.S('#' + target.data(self.data_attr('reveal-id')));
+          // Find the named node; only use the first one found, since the rest of the code assumes there's only one node
+          var modal = self.S('#' + target.data(self.data_attr('reveal-id'))).first();
         } else {
           var modal = self.S(this.scope);
 
         modal.trigger('open');
 
         if (open_modal.length < 1) {
-          this.toggle_bg(modal);
+          this.toggle_bg(modal, true);
         }
 
         if (typeof ajax_settings === 'string') {
 
               modal.html(data);
               self.S(modal).foundation('section', 'reflow');
+              self.S(modal).children().foundation();
 
               if (open_modal.length > 0) {
                 self.hide(open_modal, settings.css.close);
         this.locked = true;
         this.key_up_off(modal);   // PATCH #3: turning on key up capture only when a reveal window is open
         modal.trigger('close');
-        this.toggle_bg(modal);
+        this.toggle_bg(modal, false);
         this.hide(open_modals, settings.css.close, settings);
       }
     },
       return base;
     },
 
-    toggle_bg : function (modal) {
-      var settings = modal.data(this.attr_name(true));
-
+    toggle_bg : function (modal, state) {
       if (this.S('.' + this.settings.bg_class).length === 0) {
         this.settings.bg = $('<div />', {'class': this.settings.bg_class})
           .appendTo('body').hide();
       }
 
-      if (this.settings.bg.filter(':visible').length > 0) {
-        this.hide(this.settings.bg);
-      } else {
-        this.show(this.settings.bg);
+      var visible = this.settings.bg.filter(':visible').length > 0;
+      if ( state != visible ) {
+        if ( state == undefined ? visible : !state ) {
+          this.hide(this.settings.bg);
+        } else {
+          this.show(this.settings.bg);
+        }
       }
     },