Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions assets/gifplayer/jquery.gifplayer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
/*
* Gifplayer v0.3.2
* Gifplayer v0.3.4
* Customizable jquery plugin to play and stop animated gifs. Similar to 9gag's
* (c)2014 Rubén Torres - [email protected]
* Released under the MIT license
*/

(function ($) {
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
module.exports = factory(require("jquery"));
} else {
factory(jQuery);
}
}(function ($) {

function GifPlayer(preview, options) {
this.previewElement = preview;
this.options = options;
this.animationLoaded = false;
}

GifPlayer.scopes = [];
GifPlayer.scopes = new Array();

GifPlayer.prototype = {

Expand Down Expand Up @@ -75,10 +81,14 @@
gp.previewElement.trigger('click');
});
gp.previewElement.on('click', function (e) {
// Fire event onClick
gp.getOption('onClick').call(gp.previewElement, e);

gp.loadAnimation();
e.preventDefault();
e.stopPropagation();
});

break;
case 'hover':
gp.previewElement.on('click mouseover', function (e) {
Expand All @@ -96,7 +106,7 @@
},

processScope: function () {
scope = this.getOption('scope');
var scope = this.getOption('scope');
if (scope) {
if (GifPlayer.scopes[scope]) {
GifPlayer.scopes[scope].stopGif();
Expand Down Expand Up @@ -166,13 +176,15 @@
var wait = this.getOption('wait');
if (wait) {
//Wait until gif loads
this.gifElement.on('load', function () {
gp.animationLoaded = true;
gp.resetEvents();
gp.previewElement.hide();
gp.wrapper.append(gp.gifElement);
gp.spinnerElement.hide();
gp.getOption('onLoadComplete').call(gp.previewElement);
this.gifElement.on({
load: function () {
gp.animationLoaded = true;
gp.resetEvents();
gp.previewElement.hide();
gp.wrapper.append(gp.gifElement);
gp.spinnerElement.hide();
gp.getOption('onLoadComplete').call(gp.previewElement);
}
});
} else {
//Try to show gif instantly
Expand All @@ -188,6 +200,9 @@
this.gifElement.css('left', '0');
this.gifElement.attr('src', gifSrc);
this.gifElement.click(function (e) {
// Fire event onClick
gp.getOption('onClick').call(gp.previewElement, e);

$(this).remove();
gp.stopGif();
e.preventDefault();
Expand Down Expand Up @@ -358,10 +373,14 @@
},
onStop: function () {
},
onClick: function () {
},
onLoad: function () {
},
onLoadComplete: function () {
}
};

})(jQuery);
return GifPlayer;

}));