Merge pull request #385 from noodlebox/rewrite-autogif
Fix AutoPlayGifs plugin
This commit is contained in:
commit
4a7422039e
|
@ -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";
|
||||||
};
|
};
|
Loading…
Reference in New Issue