From 35080a59b0c30c9c83d28a40c8caa9bc74cbfd09 Mon Sep 17 00:00:00 2001 From: "Mark P. Lindhout" Date: Thu, 3 Jan 2019 16:49:30 +0100 Subject: [PATCH] Fixed overwrites of previously set style properties on DOM objects, like the . --- js/lightbox.js | 14 +++++++------- js/lightbox.min.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/js/lightbox.js b/js/lightbox.js index 8a833ae..c68d045 100644 --- a/js/lightbox.js +++ b/js/lightbox.js @@ -622,10 +622,10 @@ function Lightbox() { // hide overflow by default / if set if (!CTX.opt || !isset(CTX.opt.hideOverflow) || CTX.opt.hideOverflow) { - body.setAttribute('style', 'overflow: hidden'); + body.style['overflow'] = 'hidden'; } - CTX.box.setAttribute('style', 'padding-top: 0'); + CTX.box.style['padding-top'] = '0'; CTX.wrapper.innerHTML = ''; CTX.wrapper.appendChild(currImage.img); // set animation class @@ -816,7 +816,7 @@ function Lightbox() { } currImage.img.setAttribute('width', newImgWidth); currImage.img.setAttribute('height', newImgHeight); - currImage.img.setAttribute('style', 'margin-top:' + ((getHeight() - newImgHeight) / 2) + 'px'); + currImage.img.style['margin-top'] = ((getHeight() - newImgHeight) / 2) + 'px'; // reposition controls after timeout setTimeout(repositionControls, 200); @@ -913,19 +913,19 @@ function Lightbox() { removeClass(CTX.wrapper, _const_class_prefix + '-wrapper-active'); removeClass(nextBtn, _const_class_prefix + '-active'); removeClass(prevBtn, _const_class_prefix + '-active'); - CTX.box.setAttribute('style', 'padding-top: 0px'); - + CTX.box.style['padding-top'] = '0'; + // stop animtation stopAnimation(); // Hide Lightbox if iE8 if (isIE8) { - CTX.box.setAttribute('style', 'display: none'); + CTX.box.style['display'] = 'none'; } // show overflow by default / if set if (!CTX.opt || !isset(CTX.opt.hideOverflow) || CTX.opt.hideOverflow) { - body.setAttribute('style', 'overflow: auto'); + body.style['overflow'] = 'auto'; } // execute close callback diff --git a/js/lightbox.min.js b/js/lightbox.min.js index 436c587..84be4a7 100755 --- a/js/lightbox.min.js +++ b/js/lightbox.min.js @@ -1 +1 @@ -"use strict";function Lightbox(){function t(){return window.innerHeight||document.documentElement.offsetHeight}function e(){return window.innerWidth||document.documentElement.offsetWidth}function n(t,e,n,o){t.addEventListener?t.addEventListener(e,n,o||!1):t.attachEvent&&t.attachEvent("on"+e,n)}function o(t,e){if(t&&e)return new RegExp("(^|\\s)"+e+"(\\s|$)").test(t.className)}function i(t,e){if(t&&e)return t.className=t.className.replace(new RegExp("(?:^|\\s)"+e+"(?!\\S)"),""),t}function r(t,e){if(t&&e)return o(t,e)||(t.className+=" "+e),t}function a(t){return void 0!==t}function l(t,e){if(!t||!a(t))return!1;var n;return t.getAttribute?n=t.getAttribute(e):t.getAttributeNode&&(n=t.getAttributeNode(e).value),!(!a(n)||""===n)&&n}function p(t,e){if(!t||!a(t))return!1;var n;return t.getAttribute?n=t.getAttribute(e):t.getAttributeNode&&(n=t.getAttributeNode(e).value),"string"==typeof n}function c(t){n(t,"click",function(e){s(e),u(e),j=l(t,z+"-group")||!1,V=t,A(t,!1,!1,!1)},!1)}function s(t){t.stopPropagation?t.stopPropagation():t.returnValue=!1}function u(t){t.preventDefault?t.preventDefault():t.returnValue=!1}function m(t){for(var e=[],n=0;n=q.length?0:t+=1},W.opt.loadingAnimation)}};I=setTimeout(t,500)}}function h(){if(!M&&(i(W.box,O+"-loading"),!N&&"string"!=typeof W.opt.loadingAnimation&&W.opt.loadingAnimation)){clearInterval(w);for(var t=0;t1&&(v(),b()),D.img.onerror=function(t){W.opt.onloaderror&&(t._happenedWhile=p||!1,W.opt.onloaderror(t))},D.img.onload=function(){if(D.originalWidth=this.naturalWidth||this.width,D.originalHeight=this.naturalHeight||this.height,M||N){var t=new Image;t.setAttribute("src",c),D.originalWidth=t.width,D.originalHeight=t.height}var e=setInterval(function(){o(W.box,O+"-active")&&(r(W.wrapper,O+"-wrapper-active"),"number"==typeof W.opt.animation&&r(D.img,O+"-animate-transition"),i&&i(),h(),clearTimeout(I),W.opt.preload&&d(),W.opt.nextOnClick&&(r(D.img,O+"-next-on-click"),n(D.img,"click",function(t){s(t),W.next()},!1)),W.opt.onimageclick&&n(D.img,"click",function(t){s(t),W.opt.onimageclick(D)},!1),W.opt.onload&&W.opt.onload(p),clearInterval(e),W.resize())},10)},D.img.setAttribute("src",c),f()}var y,w,I,C,k,E,H,O="jslghtbx",T="jslghtbx",z="data-jslghtbx",W=this,M=!1,N=!1,S=document.getElementsByTagName("body")[0],B='
',L=!1,j=!1,V=!1,D={},P=[],R=!1,q=[],X=!1,$=!1;W.opt={},W.box=!1,W.wrapper=!1,W.thumbnails=[],W.thumbnails.push=function(){for(var t=0,e=arguments.length;t0&&(M=!0),navigator.appVersion.indexOf("MSIE 9")>0&&(N=!0),x(t);for(var e=document.querySelectorAll("["+z+"]"),n=0;no?(E=o*L,H=o):(E=n,H=n/L),E=Math.floor(E*W.opt.maxImgSize),H=Math.floor(H*W.opt.maxImgSize),(W.opt.dimensions&&H>D.originalHeight||W.opt.dimensions&&E>D.originalWidth)&&(H=D.originalHeight,E=D.originalWidth),D.img.setAttribute("width",E),D.img.setAttribute("height",H),D.img.setAttribute("style","margin-top:"+(t()-H)/2+"px"),setTimeout(b,200),W.opt.onresize&&W.opt.onresize(D)}},W.next=function(){if(j){var t=g(V,j)+1;if(P[t])V=P[t];else{if(!W.opt.carousel)return;V=P[0]}"number"==typeof W.opt.animation?(i(D.img,O+"-animating-next"),setTimeout(function(){A(V,!1,function(){setTimeout(function(){r(D.img,O+"-animating-next")},W.opt.animation/2)},"next")},W.opt.animation/2)):A(V,!1,!1,"next")}},W.prev=function(){if(j){var t=g(V,j)-1;if(P[t])V=P[t];else{if(!W.opt.carousel)return;V=P[P.length-1]}"number"==typeof W.opt.animation?(i(D.img,O+"-animating-prev"),setTimeout(function(){A(V,!1,function(){setTimeout(function(){r(D.img,O+"-animating-next")},W.opt.animation/2)},"prev")},W.opt.animation/2)):A(V,!1,!1,"prev")}},W.close=function(){j=!1,V=!1;var t=D;D={},P=[],R=!1,i(W.box,O+"-active"),i(W.wrapper,O+"-wrapper-active"),i(X,O+"-active"),i($,O+"-active"),W.box.setAttribute("style","padding-top: 0px"),h(),M&&W.box.setAttribute("style","display: none"),W.opt&&a(W.opt.hideOverflow)&&!W.opt.hideOverflow||S.setAttribute("style","overflow: auto"),W.opt.onclose&&W.opt.onclose(t)}} +"use strict";function Lightbox(){var r,p,l,n,o,t="jslghtbx",c=t,s=t,m="data-"+t,u=this,d=!1,g=!1,f=document.getElementsByTagName("body")[0],h='
',v=!1,b=!1,x=!1,y={},w=[],A=!1,I=[],C=!1,k=!1;function i(){return window.innerHeight||document.documentElement.offsetHeight}function E(t,e,n,o){t.addEventListener?t.addEventListener(e,n,o||!1):t.attachEvent&&t.attachEvent("on"+e,n)}function H(t,e){if(t&&e)return new RegExp("(^|\\s)"+e+"(\\s|$)").test(t.className)}function O(t,e){if(t&&e)return t.className=t.className.replace(new RegExp("(?:^|\\s)"+e+"(?!\\S)"),""),t}function T(t,e){if(t&&e)return H(t,e)||(t.className+=" "+e),t}function z(t){return void 0!==t}function W(t,e){return!(!t||!z(t))&&(t.getAttribute?n=t.getAttribute(e):t.getAttributeNode&&(n=t.getAttributeNode(e).value),!(!z(n)||""===n)&&n);var n}function a(n){E(n,"click",function(t){var e;M(t),(e=t).preventDefault?e.preventDefault():e.returnValue=!1,b=W(n,m+"-group")||!1,V(x=n,!1,!1,!1)},!1)}function M(t){t.stopPropagation?t.stopPropagation():t.returnValue=!1}function N(t){for(var e=[],n=0;n=I.length?0:t+=1},u.opt.loadingAnimation)}},500))}u.opt={},u.box=!1,u.wrapper=!1,u.thumbnails=[],u.thumbnails.push=function(){for(var t=0,e=arguments.length;te?(n=e*v,e):(n=t)/v,n=Math.floor(n*u.opt.maxImgSize),o=Math.floor(o*u.opt.maxImgSize),(u.opt.dimensions&&o>y.originalHeight||u.opt.dimensions&&n>y.originalWidth)&&(o=y.originalHeight,n=y.originalWidth),y.img.setAttribute("width",n),y.img.setAttribute("height",o),y.img.style["margin-top"]=(i()-o)/2+"px",setTimeout(L,200),u.opt.onresize&&u.opt.onresize(y)}},u.next=function(){if(b){var t=S(x,b)+1;if(w[t])x=w[t];else{if(!u.opt.carousel)return;x=w[0]}"number"==typeof u.opt.animation?(O(y.img,c+"-animating-next"),setTimeout(function(){V(x,!1,function(){setTimeout(function(){T(y.img,c+"-animating-next")},u.opt.animation/2)},"next")},u.opt.animation/2)):V(x,!1,!1,"next")}},u.prev=function(){if(b){var t=S(x,b)-1;if(w[t])x=w[t];else{if(!u.opt.carousel)return;x=w[w.length-1]}"number"==typeof u.opt.animation?(O(y.img,c+"-animating-prev"),setTimeout(function(){V(x,!1,function(){setTimeout(function(){T(y.img,c+"-animating-next")},u.opt.animation/2)},"prev")},u.opt.animation/2)):V(x,!1,!1,"prev")}},u.close=function(){x=b=!1;var t=y;y={},A=!(w=[]),O(u.box,c+"-active"),O(u.wrapper,c+"-wrapper-active"),O(C,c+"-active"),O(k,c+"-active"),u.box.style["padding-top"]="0",B(),d&&(u.box.style.display="none"),u.opt&&z(u.opt.hideOverflow)&&!u.opt.hideOverflow||(f.style.overflow="auto"),u.opt.onclose&&u.opt.onclose(t)}} \ No newline at end of file