From b9b28c0bd96f9575d34584e9ce04e0c22bb50d88 Mon Sep 17 00:00:00 2001 From: noodlebox Date: Sat, 10 Sep 2016 05:06:17 -0500 Subject: [PATCH] Fix AutoPlayGifs plugin --- Plugins/AutoPlayGifs.plugin.js | 54 ++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/Plugins/AutoPlayGifs.plugin.js b/Plugins/AutoPlayGifs.plugin.js index f7e3b8d..ef61e8c 100644 --- a/Plugins/AutoPlayGifs.plugin.js +++ b/Plugins/AutoPlayGifs.plugin.js @@ -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(''); +// 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($("", { + 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"; -}; \ No newline at end of file + return "noodlebox"; +};