Skip to content

Commit

Permalink
added afterInitialize and afterImageLoad hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-t committed Dec 22, 2016
1 parent f988407 commit 3f47963
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
11 changes: 10 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ <h2>
{src : 'demo-images/8.jpg', title : 'caption 3'},
],
imageSize : 'contain',
container : '#container3'
container : '#container3',
afterMarkup: function () {
console.log('afterMarkup hook is called')
},
afterImageLoad: function () {
console.log('afterImageLoad hook is called')
},
afterInitialize: function () {
console.log('afterInitialize hook is called')
}
}).data('chocolat');

$('.api-open').on('click', function(e) {
Expand Down
11 changes: 7 additions & 4 deletions dist/js/jquery.chocolat.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
this.settings.lastImage = this.settings.images.length - 1;
this.settings.initialized = true;
}
this.settings.afterInitialize.call(this);

return this.load(i);
},
Expand Down Expand Up @@ -99,6 +100,7 @@
})
.then(function (imgLoader) {
that.zoomable();
that.settings.afterImageLoad.call(that);
});

var nextIndex = i + 1;
Expand All @@ -107,7 +109,6 @@
}

return deferred;

},

place : function(i, imgLoader) {
Expand Down Expand Up @@ -561,7 +562,7 @@
return;
}
that.debounce(50, function() {
fitting = that.fit(that.settings.currentImage, that.elems.wrapper);
var fitting = that.fit(that.settings.currentImage, that.elems.wrapper);
that.center(fitting.width, fitting.height, fitting.left, fitting.top, 0);
that.zoomable();
});
Expand Down Expand Up @@ -596,7 +597,7 @@
this.elems.wrapper.trigger(event);

this.elems.domContainer.addClass('chocolat-zoomed');
fitting = this.fit(this.settings.currentImage, this.elems.wrapper);
var fitting = this.fit(this.settings.currentImage, this.elems.wrapper);
return this.center(fitting.width, fitting.height, fitting.left, fitting.top, this.settings.duration);
},

Expand All @@ -611,7 +612,7 @@
this.elems.img.animate({'margin': 0}, duration);

this.elems.domContainer.removeClass('chocolat-zoomed');
fitting = this.fit(this.settings.currentImage, this.elems.wrapper);
var fitting = this.fit(this.settings.currentImage, this.elems.wrapper);
return this.center(fitting.width, fitting.height, fitting.left, fitting.top, duration);
},

Expand Down Expand Up @@ -706,7 +707,9 @@
images : [],
enableZoom : true,
imageSource : "href",
afterInitialize : function () {},
afterMarkup : function () {},
afterImageLoad : function () {},
};

$.fn.Chocolat = function (options) {
Expand Down
Loading

0 comments on commit 3f47963

Please sign in to comment.