From de38cf35ab781e9fbb495f9c2f58ef66f5ad4cf8 Mon Sep 17 00:00:00 2001 From: Gianluca Guarini Date: Sun, 22 Jun 2014 00:50:19 +0200 Subject: [PATCH] small update --- jquery.BlackAndWhite.js | 4 +++- src/jquery.BlackAndWhite.js | 4 +++- src/jquery.BlackAndWhite.min.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jquery.BlackAndWhite.js b/jquery.BlackAndWhite.js index 8b4d622..ad3412c 100644 --- a/jquery.BlackAndWhite.js +++ b/jquery.BlackAndWhite.js @@ -227,11 +227,12 @@ } }; this.init = function(options) { + // convert all the images $container.each(function(index, tmpImageWrapper) { var $imageWrapper = $(tmpImageWrapper), $img = $imageWrapper.find('img'); - + if ($img.data('_b&w')) return; if (!$img[0].complete || (typeof $img[0].naturalWidth !== "undefined" && !$img[0].naturalWidth)) { $img.on('load', function() { _injectTags($img, $imageWrapper); @@ -239,6 +240,7 @@ } else { _injectTags($img, $imageWrapper); } + $img.data('_b&w', true); }); // start the webworker if (BnWWorker) { diff --git a/src/jquery.BlackAndWhite.js b/src/jquery.BlackAndWhite.js index 8b4d622..ad3412c 100755 --- a/src/jquery.BlackAndWhite.js +++ b/src/jquery.BlackAndWhite.js @@ -227,11 +227,12 @@ } }; this.init = function(options) { + // convert all the images $container.each(function(index, tmpImageWrapper) { var $imageWrapper = $(tmpImageWrapper), $img = $imageWrapper.find('img'); - + if ($img.data('_b&w')) return; if (!$img[0].complete || (typeof $img[0].naturalWidth !== "undefined" && !$img[0].naturalWidth)) { $img.on('load', function() { _injectTags($img, $imageWrapper); @@ -239,6 +240,7 @@ } else { _injectTags($img, $imageWrapper); } + $img.data('_b&w', true); }); // start the webworker if (BnWWorker) { diff --git a/src/jquery.BlackAndWhite.min.js b/src/jquery.BlackAndWhite.min.js index c894ba4..2770a0a 100755 --- a/src/jquery.BlackAndWhite.min.js +++ b/src/jquery.BlackAndWhite.min.js @@ -8,4 +8,4 @@ * * Copyright (c) Gianluca Guarini */ -!function(a){a.fn.extend({BlackAndWhite:function(b){"use strict";var c=this,d={hoverEffect:!0,webworkerPath:!1,responsive:!0,invertHoverEffect:!1,speed:500,onImageReady:null,intensity:1};b=a.extend(d,b);var e=b.hoverEffect,f=b.webworkerPath,g=b.invertHoverEffect,h=b.responsive,i="number"==typeof b.intensity&&b.intensity<1&&b.intensity>0?b.intensity:1,j=a.isPlainObject(b.speed)?b.speed.fadeIn:b.speed,k=a.isPlainObject(b.speed)?b.speed.fadeOut:b.speed,l=document.all&&!window.opera&&window.XMLHttpRequest?!0:!1,m=" -webkit- -moz- -o- -ms- ".split(" "),n={},o=function(a){if(n[a]||""===n[a])return n[a]+a;var b=document.createElement("div"),c=["","Moz","Webkit","O","ms","Khtml"];for(var d in c)if("undefined"!=typeof b.style[c[d]+a])return n[a]=c[d],c[d]+a;return a.toLowerCase()},p=function(){var a=document.createElement("div");return a.style.cssText=m.join("filter:blur(2px); "),!!a.style.length&&(void 0===document.documentMode||document.documentMode>9)}(),q=!!document.createElement("canvas").getContext,r=a(window),s=function(){return"undefined"!=typeof Worker?!0:!1}(),t=(o("Filter"),[]),u=s&&f?new Worker(f+"BnWWorker.js"):!1,v=function(b){a(b.currentTarget).find(".BWfade").stop(!0,!0)[g?"fadeOut":"fadeIn"](k)},w=function(b){a(b.currentTarget).find(".BWfade").stop(!0,!0)[g?"fadeIn":"fadeOut"](j)},x=function(a){"function"==typeof b.onImageReady&&b.onImageReady(a)},y=function(){return t.length?(u.postMessage({imgData:t[0].imageData,intensity:i}),void(u.onmessage=function(a){t[0].ctx.putImageData(a.data,0,0),x(t[0].img),t.splice(0,1),y()})):(u.terminate&&u.terminate(),void(u.close&&u.close()))},z=function(a,b,c,d){var e=b.getContext("2d"),f=0;e.drawImage(a,0,0,c,d);var g=e.getImageData(0,0,c,d),h=g.data,j=h.length;if(u)t.push({imageData:g,ctx:e,img:a});else{for(;j>f;f+=4){var k=.3*h[f]+.59*h[f+1]+.11*h[f+2];h[f]=~~(k*i+h[f]*(1-i)),h[f+1]=~~(k*i+h[f+1]*(1-i)),h[f+2]=~~(k*i+h[f+2]*(1-i))}e.putImageData(g,0,0),x(a)}},A=function(b,c){var d,e=b[0],f=e.src,h=b.width(),j=b.height(),k=b.position(),l={position:"absolute","-webkit-transform":"translate3d(0,0,0)",top:k.top,left:k.left,display:g?"none":"block"};if(e.crossOrigin="anonymous",q&&!p){var m=e.width,n=e.height;d=a(''),d.css(l),d.prependTo(c),z(e,d.get(0),m,n)}else l[o("Filter")]="grayscale("+100*i+"%)",d=a(" '),d.css(a.extend(l,{filter:"progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"})),d.prependTo(c),x(e)};return this.init=function(){c.each(function(b,c){var d=a(c),e=d.find("img");!e[0].complete||"undefined"!=typeof e[0].naturalWidth&&!e[0].naturalWidth?e.on("load",function(){A(e,d)}).load():A(e,d)}),u&&y(),e&&(c.on("mouseleave",v),c.on("mouseenter",w)),h&&r.on("resize orientationchange",c.resizeImages)},this.resizeImages=function(){c.each(function(b,c){var d=a(c).find("img:not(.BWFilter)"),e=l?a(d).prop("width"):a(d).width(),f=l?a(d).prop("height"):a(d).height();a(this).find(".BWFilter, canvas").css({width:e,height:f})})},this.init(b)}})}(jQuery); \ No newline at end of file +!function(a){a.fn.extend({BlackAndWhite:function(b){"use strict";var c=this,d={hoverEffect:!0,webworkerPath:!1,responsive:!0,invertHoverEffect:!1,speed:500,onImageReady:null,intensity:1};b=a.extend(d,b);var e=b.hoverEffect,f=b.webworkerPath,g=b.invertHoverEffect,h=b.responsive,i="number"==typeof b.intensity&&b.intensity<1&&b.intensity>0?b.intensity:1,j=a.isPlainObject(b.speed)?b.speed.fadeIn:b.speed,k=a.isPlainObject(b.speed)?b.speed.fadeOut:b.speed,l=document.all&&!window.opera&&window.XMLHttpRequest?!0:!1,m=" -webkit- -moz- -o- -ms- ".split(" "),n={},o=function(a){if(n[a]||""===n[a])return n[a]+a;var b=document.createElement("div"),c=["","Moz","Webkit","O","ms","Khtml"];for(var d in c)if("undefined"!=typeof b.style[c[d]+a])return n[a]=c[d],c[d]+a;return a.toLowerCase()},p=function(){var a=document.createElement("div");return a.style.cssText=m.join("filter:blur(2px); "),!!a.style.length&&(void 0===document.documentMode||document.documentMode>9)}(),q=!!document.createElement("canvas").getContext,r=a(window),s=function(){return"undefined"!=typeof Worker?!0:!1}(),t=(o("Filter"),[]),u=s&&f?new Worker(f+"BnWWorker.js"):!1,v=function(b){a(b.currentTarget).find(".BWfade").stop(!0,!0)[g?"fadeOut":"fadeIn"](k)},w=function(b){a(b.currentTarget).find(".BWfade").stop(!0,!0)[g?"fadeIn":"fadeOut"](j)},x=function(a){"function"==typeof b.onImageReady&&b.onImageReady(a)},y=function(){return t.length?(u.postMessage({imgData:t[0].imageData,intensity:i}),void(u.onmessage=function(a){t[0].ctx.putImageData(a.data,0,0),x(t[0].img),t.splice(0,1),y()})):(u.terminate&&u.terminate(),void(u.close&&u.close()))},z=function(a,b,c,d){var e=b.getContext("2d"),f=0;e.drawImage(a,0,0,c,d);var g=e.getImageData(0,0,c,d),h=g.data,j=h.length;if(u)t.push({imageData:g,ctx:e,img:a});else{for(;j>f;f+=4){var k=.3*h[f]+.59*h[f+1]+.11*h[f+2];h[f]=~~(k*i+h[f]*(1-i)),h[f+1]=~~(k*i+h[f+1]*(1-i)),h[f+2]=~~(k*i+h[f+2]*(1-i))}e.putImageData(g,0,0),x(a)}},A=function(b,c){var d,e=b[0],f=e.src,h=b.width(),j=b.height(),k=b.position(),l={position:"absolute","-webkit-transform":"translate3d(0,0,0)",top:k.top,left:k.left,display:g?"none":"block"};if(e.crossOrigin="anonymous",q&&!p){var m=e.width,n=e.height;d=a(''),d.css(l),d.prependTo(c),z(e,d.get(0),m,n)}else l[o("Filter")]="grayscale("+100*i+"%)",d=a(" '),d.css(a.extend(l,{filter:"progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"})),d.prependTo(c),x(e)};return this.init=function(){c.each(function(b,c){var d=a(c),e=d.find("img");e.data("_b&w")||(!e[0].complete||"undefined"!=typeof e[0].naturalWidth&&!e[0].naturalWidth?e.on("load",function(){A(e,d)}).load():A(e,d),e.data("_b&w",!0))}),u&&y(),e&&(c.on("mouseleave",v),c.on("mouseenter",w)),h&&r.on("resize orientationchange",c.resizeImages)},this.resizeImages=function(){c.each(function(b,c){var d=a(c).find("img:not(.BWFilter)"),e=l?a(d).prop("width"):a(d).width(),f=l?a(d).prop("height"):a(d).height();a(this).find(".BWFilter, canvas").css({width:e,height:f})})},this.init(b)}})}(jQuery); \ No newline at end of file