Project

General

Profile

1 2 Manuela
/***
2
* SimplBox - v1.0.0 - 2014.08.04
3
* Author: (c) Dendrochronology - @Dendrochronolo - http://genert.laal.ee/
4
* Available for use under the MIT License.
5
***/
6
!(function(f,h,t){function l(a,c){this.m_Elements=a;this.m_UserOptions=c||{};this.m_Options={};this.m_AnimateDone=this.m_Alt=this.m_InstalledImageBox=this.m_InProgress=this.m_CurrentImageElement=this.m_CurrentTargetNumber=this.m_CurrentTargetElementsLength=this.m_CurrentTargetElements=g;for(var b in l.options)this.m_UserOptions.hasOwnProperty(b)?this.m_Options[b]=this.m_UserOptions[b]:this.m_Options[b]=l.options[b]}var n=h.documentElement,p=h.getElementsByTagName("body")[0],g=!1,q="addEventListener"in h;l.prototype={init:function(){this.API_AddEvent=this.addEvent;this.API_RemoveImageElement=this.removeImageElement;this.checkBrowser();this.addEvents()},checkBrowser:function(){var a="ontouchstart"in f||f.navigator.msMaxTouchPoints||navigator.maxTouchPoints||g,c=a&&(f.navigator.pointerEnabled||f.navigator.msPointerEnabled);this.browser={isHardwareAccelerated:"undefined"!==this.getcss3prop("transition")?!0:g,isTouch:a,hasPointers:c}},addEvents:function(){for(var a=this,c=0;c<a.m_Elements.length;c++)(function(b){a.addEvent(a.m_Elements[b], a.browser.hasPointers?"pointerup MSPointerUp":"click",function(c){c.preventDefault&&(c.preventDefault(),c.stopPropagation());f.event&&(f.event.returnValue=g,f.event.cancelBubble=g);if(a.isFunction(a.m_Options.onStart()))a.m_Options.onStart(this);a.m_CurrentTargetElements=a.m_Elements;a.m_CurrentTargetElementsLength=a.m_Elements.length;a.m_CurrentTargetNumber=b;a.openImage(a.m_Elements[a.m_CurrentTargetNumber])})})(c);a.addEvent(f,"resize",function(){a.calculateImagePositionAndSize(a.m_CurrentImageElement, !0)});a.leftAnimationFunction=function(){0>a.m_CurrentTargetNumber-1?(a.openImage(a.m_CurrentTargetElements[a.m_CurrentTargetElementsLength-1],"left"),a.m_CurrentTargetNumber=a.m_CurrentTargetElementsLength-1):(a.openImage(a.m_CurrentTargetElements[a.m_CurrentTargetNumber-1],"left"),a.m_CurrentTargetNumber-=1)};a.rightAnimationFunction=function(){a.m_CurrentTargetNumber+1>a.m_CurrentTargetElementsLength-1?(a.openImage(a.m_CurrentTargetElements[0],"right"),a.m_CurrentTargetNumber=0):(a.openImage(a.m_CurrentTargetElements[a.m_CurrentTargetNumber+ 1],"right"),a.m_CurrentTargetNumber+=1)};a.m_Options.enableKeyboard&&a.addEvent(f,"keydown",function(b){if(a.m_CurrentImageElement&&!a.m_InProgress)switch(b.preventDefault&&(b.preventDefault(),b.stopPropagation()),f.event&&(b=f.event,f.event.returnValue=g,f.event.cancelBubble=g),b.which||b.keyCode){case 27:return a.removeImageElement(),g;case 39:return a.rightAnimationFunction(),g;case 37:return a.leftAnimationFunction(),g}});a.m_Options.quitOnDocumentClick&&a.addEvent(q?p:h,"click",function(b){if(a.m_InProgress)return g; b.preventDefault&&b.preventDefault();f.event&&(b=f.event);if((b=b.target?b.target:b.srcElement)&&b.id!==a.m_Options.imageElementId&&a.m_InstalledImageBox&&!a.m_InProgress)return a.removeImageElement(),g})},openImage:function(a,c){var b=this,e=h.createDocumentFragment(),d=h.createElement("img"),k=h.getElementById(b.m_Options.imageElementId);if(a&&"a"===a.tagName.toLowerCase()){k&&(p.removeChild(k),b.m_CurrentImageElement=g,b.m_InstalledImageBox=g);b.m_Alt=a.firstChild.getAttribute("alt");b.m_InProgress= !0;if(b.isFunction(b.m_Options.onImageLoadStart()))b.m_Options.onImageLoadStart();if("undefined"!==typeof c)switch(c){case "left":c=-1;break;case "right":c=1}d.setAttribute("id",b.m_Options.imageElementId);d.setAttribute("src",a.getAttribute("href"));d.setAttribute("alt",b.m_Alt);d.setAttribute("style","position: fixed; cursor: pointer; opacity: 0;");e.appendChild(d);p.appendChild(e);b.m_CurrentImageElement=h.getElementById(b.m_Options.imageElementId);b.m_CurrentImageElement.style.filter="alpha(opacity=0)"; b.browser.isHardwareAccelerated&&("undefined"!==typeof c&&(b.m_CurrentImageElement.style[b.getcss3prop("transform")]="translateX("+c*b.m_Options.fadeInDistance+"px)"),b.m_CurrentImageElement.style[b.getcss3prop("transition")]="all "+b.m_Options.animationSpeed+"ms ease");b.calculateImagePositionAndSize(b.m_CurrentImageElement,g,c);b.m_Options.quitOnImageClick&&b.addEvent(b.m_CurrentImageElement,"click",function(a){a.preventDefault&&a.preventDefault();f.event&&(f.event.returnValue=g);b.removeImageElement()}); if(b.browser.isTouch){var r=-1,s=-1,m=0;b.addEvent(b.m_CurrentImageElement,"touchstart pointerdown MSPointerDown",function(a){a.preventDefault();r=a.pageX||a.touches[0].pageX});b.addEvent(b.m_CurrentImageElement,"touchmove pointermove MSPointerMove",function(a){a.preventDefault();s=a.pageX||a.touches[0].pageX;m=r-s;b.browser.isHardwareAccelerated&&(b.m_CurrentImageElement.style[b.getcss3prop("transition")]="none",b.m_CurrentImageElement.style[b.getcss3prop("transform")]="translateX("+-m+"px)")}); b.addEvent(b.m_CurrentImageElement,"touchend pointerup pointercancel MSPointerUp MSPointerCancel",function(a){a.preventDefault();75<Math.abs(m)?0>m?b.leftAnimationFunction():b.rightAnimationFunction():b.m_CurrentImageElement.style[b.getcss3prop("transform")]="translateX(0px)"})}}},calculateImagePositionAndSize:function(a,c){var b=this,e=new Image,d=0,k=0,h=0;a&&(b.m_ImageSource=a.getAttribute("src"),b.m_ScreenHeight=f.innerHeight||n.offsetHeight,b.m_ScreenWidth=f.innerWidth||n.offsetWidth,e.onload= function(){var e=this.width,f=this.height;d=e;k=f;h=d/k;Math.floor(b.m_ScreenWidth/h)>b.m_ScreenHeight?(d=b.m_ScreenHeight*h*b.m_Options.imageSize,k=b.m_ScreenHeight*b.m_Options.imageSize):(d=b.m_ScreenWidth*b.m_Options.imageSize,k=b.m_ScreenWidth/h*b.m_Options.imageSize);d>e&&(d=e);k>f&&(k=f);a.style.top=(b.m_ScreenHeight-k)/2+"px";a.style.left=(b.m_ScreenWidth-d)/2+"px";a.style.width=Math.floor(d)+"px";a.style.height=Math.floor(k)+"px";c||setTimeout(function(){b.browser.isHardwareAccelerated?(a.style.opacity= 1,a.style[b.getcss3prop("transform")]="translateX(0px)"):b.animate({delay:16,duration:b.m_Options.animationSpeed,delta:b.linear,step:function(b){a.style.opacity=1*b;a.style.filter="alpha(opacity="+100*b+")"}});b.m_InProgress=g;b.m_InstalledImageBox=!0;if(b.isFunction(b.m_Options.onImageLoadEnd()))b.m_Options.onImageLoadEnd(a)},100)},e.src=b.m_ImageSource)},removeImageElement:function(){var a=this;if(a.m_CurrentImageElement){if(a.isFunction(a.m_Options.onEnd()))a.m_Options.onEnd();if(a.m_InProgress&& a.isFunction(a.m_Options.onImageLoadEnd()))a.m_Options.onImageLoadEnd(p_Element);a.browser.isHardwareAccelerated?(a.m_CurrentImageElement.style.opacity=0,a.m_CurrentImageElement.style.transition="opacity 250ms ease"):a.animate({delay:16,duration:250,delta:a.linear,step:function(c){a.m_CurrentImageElement.style.opacity=0*c;a.m_CurrentImageElement.style.filter="alpha(opacity="+0*c+")"}});setTimeout(function(){a.m_CurrentImageElement&&a.m_CurrentImageElement.parentNode.removeChild(a.m_CurrentImageElement); a.m_CurrentImageElement=g;a.m_InstalledImageBox=g},a.browser.isHardwareAccelerated?250:350)}},isFunction:function(a){return!!(a&&a.constructor&&a.call&&a.apply)},addEvent:function(a,c,b){var e,d;c=c.split(" ");if(q)if(a&&(!(a instanceof Array)||a.length)&&0!==a.length||a===f)for(e=0;e<c.length;e++)a.addEventListener(c[e],b,g);else{if(a&&"undefined"!==a[0])for(e=0;e<a.length;e++)for(d=0;d<c.length;d++)a[e].addEventListener(c[d],b,g)}else for(e=0;e<c.length;e++)if(-1!==c[e].indexOf("keydown"))h.attachEvent("on"+ c[e],b);else if(a&&(!(a instanceof Array)||a.length)&&0!==a.length||a===f)a.attachEvent("on"+c[e],b);else if(a&&"undefined"!==a[0])for(d=0;d<a.length;d++)a[d].attachEvent(c[e],b)},animate:function(a){var c=this,b=new Date,e=setInterval(function(){var d=(new Date-b)/a.duration;1<d&&(d=1);var f=a.delta(d);a.step(f);1==d&&(c.m_AnimateDone=!0,clearInterval(e))},a.delay||10)},linear:function(a){return a},getcss3prop:function(a){for(var c=" -moz- -webkit- -o- -ms- -khtml-".split(" "),b=function(a){return a.replace(/\-([a-z])/gi, function(a,b){return b.toUpperCase()})},e=0;e<c.length;e++){var d=b(c[e]+a);"Ms"==d.substr(0,2)&&(d="m"+d.substr(1));if(d in n.style)return d}return"undefined"}};l.options={imageElementId:"simplbox",fadeInDistance:100,animationSpeed:350,imageSize:.8,quitOnImageClick:!0,quitOnDocumentClick:!0,enableKeyboard:!0,onImageLoadStart:function(){},onImageLoadEnd:function(){},onStart:function(){},onEnd:function(){}};f.SimplBox=l})(window,document);