Fix AutoPlayGifs plugin

This commit is contained in:
noodlebox 2016-09-10 05:06:17 -05:00
parent 2b361cbcc3
commit b9b28c0bd9
1 changed files with 39 additions and 15 deletions

View File

@ -2,23 +2,47 @@
var agif = function () {}; var agif = function () {};
agif.prototype.convert = function () { // Autoplay GIFs
$(".image canvas").each(function() { agif.prototype.convert = function (target) {
var src = $(this).attr("src"); // Handle GIF
if(src != undefined) { $(target).find(".image:has(canvas)").each(function () {
$(this).replaceWith('<img src="'+src+'"></img>'); var image = $(this);
var canvas = image.children("canvas").first();
// Replace GIF preview with actual image
var src = canvas.attr("src");
if(src !== undefined) {
image.replaceWith($("<img>", {
src: canvas.attr("src"),
width: canvas.attr("width"),
height: canvas.attr("height"),
}).addClass("image kawaii-autogif"));
} }
}); });
// Handle GIFV
$(target).find(".embed-thumbnail-gifv:has(video)").each(function () {
var embed = $(this);
var video = embed.children("video").first();
// Remove the class, embed-thumbnail-gifv, to avoid the "GIF" overlay
embed.removeClass("embed-thumbnail-gifv").addClass("kawaii-autogif");
// Prevent the default behavior of pausing the video
embed.parent().on("mouseout.autoGif", function (event) {
event.stopPropagation();
});
video[0].play();
});
}; };
agif.prototype.onMessage = function () { agif.prototype.onMessage = function () {};
this.convert();
}; agif.prototype.onSwitch = function () {};
agif.prototype.onSwitch = function () {
this.convert();
};
agif.prototype.start = function () { agif.prototype.start = function () {
this.convert(); this.convert(document);
};
agif.prototype.observer = function (e) {
this.convert(e.target);
}; };
agif.prototype.load = function () {}; agif.prototype.load = function () {};
@ -35,8 +59,8 @@ agif.prototype.getDescription = function () {
return "Autoplay gifs without having to hover."; return "Autoplay gifs without having to hover.";
}; };
agif.prototype.getVersion = function () { agif.prototype.getVersion = function () {
return "0.1.0"; return "1.0.0";
}; };
agif.prototype.getAuthor = function () { agif.prototype.getAuthor = function () {
return "Jiiks"; return "noodlebox";
}; };