]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fixes issue where replaced event was firing early on html file replacement with inter...
authorChris Oyler <chris@zurb.com>
Thu, 14 Jan 2016 19:30:30 +0000 (11:30 -0800)
committerChris Oyler <chris@zurb.com>
Thu, 14 Jan 2016 19:30:36 +0000 (11:30 -0800)
js/foundation.interchange.js

index 08f4758ec6247303f6bcc3bba791e622bde757f5..e37af8bfc2b37d96a369eb6d4b16d3648e64bc2e 100644 (file)
   Interchange.prototype.replace = function(path) {
     if (this.currentPath === path) return;
 
-    var _this = this;
+    var _this = this,
+        trigger = 'replaced.zf.interchange';
 
     // Replacing images
     if (this.$element[0].nodeName === 'IMG') {
       this.$element.attr('src', path).load(function() {
         _this.currentPath = path;
-      });
+      })
+      .trigger(trigger);
     }
     // Replacing background images
     else if (path.match(/\.(gif|jpg|jpeg|tiff|png)([?#].*)?/i)) {
-      this.$element.css({ 'background-image': 'url('+path+')' });
+      this.$element.css({ 'background-image': 'url('+path+')' })
+          .trigger(trigger);
     }
     // Replacing HTML
     else {
       $.get(path, function(response) {
-        _this.$element.html(response);
+        _this.$element.html(response)
+             .trigger(trigger);
         $(response).foundation();
         _this.currentPath = path;
       });
      * Fires when content in an Interchange element is done being loaded.
      * @event Interchange#replaced
      */
-    this.$element.trigger('replaced.zf.interchange');
+    // this.$element.trigger('replaced.zf.interchange');
   };
   /**
    * Destroys an instance of interchange.