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 () {};
agif.prototype.convert = function () {
$(".image canvas").each(function() {
var src = $(this).attr("src");
if(src != undefined) {
$(this).replaceWith('<img src="'+src+'"></img>');
// Autoplay GIFs
agif.prototype.convert = function (target) {
// Handle GIF
$(target).find(".image:has(canvas)").each(function () {
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 () {
this.convert();
};
agif.prototype.onSwitch = function () {
this.convert();
};
agif.prototype.onMessage = function () {};
agif.prototype.onSwitch = function () {};
agif.prototype.start = function () {
this.convert();
this.convert(document);
};
agif.prototype.observer = function (e) {
this.convert(e.target);
};
agif.prototype.load = function () {};
@ -35,8 +59,8 @@ agif.prototype.getDescription = function () {
return "Autoplay gifs without having to hover.";
};
agif.prototype.getVersion = function () {
return "0.1.0";
return "1.0.0";
};
agif.prototype.getAuthor = function () {
return "Jiiks";
};
return "noodlebox";
};