dubuval/galleria/galleria-1.4.7.min.js

3 lines
90 KiB
JavaScript
Raw Normal View History

2016-10-16 09:52:29 +00:00
(function($,window,Galleria,undef){var doc=window.document,$doc=$(doc),$win=$(window),protoArray=Array.prototype,VERSION=1.47,DEBUG=true,TIMEOUT=3e4,DUMMY=false,NAV=navigator.userAgent.toLowerCase(),HASH=window.location.hash.replace(/#\//,""),PROT=window.location.protocol=="file:"?"http:":window.location.protocol,M=Math,F=function(){},FALSE=function(){return false},IE=function(){var v=3,div=doc.createElement("div"),all=div.getElementsByTagName("i");do{div.innerHTML="<!--[if gt IE "+ ++v+"]><i></i><![endif]-->"}while(all[0]);return v>4?v:doc.documentMode||undef}(),DOM=function(){return{html:doc.documentElement,body:doc.body,head:doc.getElementsByTagName("head")[0],title:doc.title}},IFRAME=window.parent!==window.self,_eventlist="data ready thumbnail loadstart loadfinish image play pause progress "+"fullscreen_enter fullscreen_exit idle_enter idle_exit rescale "+"lightbox_open lightbox_close lightbox_image",_events=function(){var evs=[];$.each(_eventlist.split(" "),function(i,ev){evs.push(ev);if(/_/.test(ev)){evs.push(ev.replace(/_/g,""))}});return evs}(),_legacyOptions=function(options){var n;if(typeof options!=="object"){return options}$.each(options,function(key,value){if(/^[a-z]+_/.test(key)){n="";$.each(key.split("_"),function(i,k){n+=i>0?k.substr(0,1).toUpperCase()+k.substr(1):k});options[n]=value;delete options[key]}});return options},_patchEvent=function(type){if($.inArray(type,_events)>-1){return Galleria[type.toUpperCase()]}return type},_video={youtube:{reg:/https?:\/\/(?:[a-zA_Z]{2,3}.)?(?:youtube\.com\/watch\?)((?:[\w\d\-\_\=]+&amp;(?:amp;)?)*v(?:&lt;[A-Z]+&gt;)?=([0-9a-zA-Z\-\_]+))/i,embed:function(){return PROT+"//www.youtube.com/embed/"+this.id},get_thumb:function(data){return PROT+"//img.youtube.com/vi/"+this.id+"/default.jpg"},get_image:function(data){return PROT+"//img.youtube.com/vi/"+this.id+"/hqdefault.jpg"}},vimeo:{reg:/https?:\/\/(?:www\.)?(vimeo\.com)\/(?:hd#)?([0-9]+)/i,embed:function(){return PROT+"//player.vimeo.com/video/"+this.id},getUrl:function(){return PROT+"//vimeo.com/api/v2/video/"+this.id+".json?callback=?"},get_thumb:function(data){return data[0].thumbnail_medium},get_image:function(data){return data[0].thumbnail_large}},dailymotion:{reg:/https?:\/\/(?:www\.)?(dailymotion\.com)\/video\/([^_]+)/,embed:function(){return PROT+"//www.dailymotion.com/embed/video/"+this.id},getUrl:function(){return"https://api.dailymotion.com/video/"+this.id+"?fields=thumbnail_240_url,thumbnail_720_url&callback=?"},get_thumb:function(data){return data.thumbnail_240_url},get_image:function(data){return data.thumbnail_720_url}},_inst:[]},Video=function(type,id){for(var i=0;i<_video._inst.length;i++){if(_video._inst[i].id===id&&_video._inst[i].type==type){return _video._inst[i]}}this.type=type;this.id=id;this.readys=[];_video._inst.push(this);var self=this;$.extend(this,_video[type]);_videoThumbs=function(data){self.data=data;$.each(self.readys,function(i,fn){fn(self.data)});self.readys=[]};if(this.hasOwnProperty("getUrl")){$.getJSON(this.getUrl(),_videoThumbs)}else{window.setTimeout(_videoThumbs,400)}this.getMedia=function(type,callback,fail){fail=fail||F;var self=this;var success=function(data){callback(self["get_"+type](data))};try{if(self.data){success(self.data)}else{self.readys.push(success)}}catch(e){fail()}}},_videoTest=function(url){var match;for(var v in _video){match=url&&_video[v].reg&&url.match(_video[v].reg);if(match&&match.length){return{id:match[2],provider:v}}}return false},_nativeFullscreen={support:function(){var html=DOM().html;return!IFRAME&&(html.requestFullscreen||html.msRequestFullscreen||html.mozRequestFullScreen||html.webkitRequestFullScreen)}(),callback:F,enter:function(instance,callback,elem){this.instance=instance;this.callback=callback||F;elem=elem||DOM().html;if(elem.requestFullscreen){elem.requestFullscreen()}else if(elem.msRequestFullscreen){elem.msRequestFullscreen()}else if(elem.mozRequestFullScreen){elem.mozRequestFullScreen()}else if(elem.webkitRequestFullScreen){elem.webkitRequestFullScreen()}},exit:function(callback){this.callback=callback||F;if(doc.exitFullscreen){doc.exit
overlay:"position:fixed;display:none;opacity:"+op.overlayOpacity+";filter:alpha(opacity="+op.overlayOpacity*100+");top:0;left:0;width:100%;height:100%;background:"+op.overlayBackground+";z-index:99990",box:"position:fixed;display:none;width:400px;height:400px;top:50%;left:50%;margin-top:-200px;margin-left:-200px;z-index:99991",shadow:abs+"background:#000;width:100%;height:100%;",content:abs+"background-color:#fff;top:10px;left:10px;right:10px;bottom:10px;overflow:hidden",info:abs+"bottom:10px;left:10px;right:10px;color:#444;font:11px/13px arial,sans-serif;height:13px",close:abs+"top:10px;right:10px;height:20px;width:20px;background:#fff;text-align:center;cursor:pointer;color:#444;font:16px/22px arial,sans-serif;z-index:99999",image:abs+"top:10px;left:10px;right:10px;bottom:30px;overflow:hidden;display:block;",prevholder:abs+"width:50%;top:0;bottom:40px;cursor:pointer;",nextholder:abs+"width:50%;top:0;bottom:40px;right:-1px;cursor:pointer;",prev:abs+"top:50%;margin-top:-20px;height:40px;width:30px;background:#fff;left:20px;display:none;text-align:center;color:#000;font:bold 16px/36px arial,sans-serif",next:abs+"top:50%;margin-top:-20px;height:40px;width:30px;background:#fff;right:20px;left:auto;display:none;font:bold 16px/36px arial,sans-serif;text-align:center;color:#000",title:"float:left",counter:"float:right;margin-left:8px;"},hover=function(elem){return elem.hover(function(){$(this).css("color","#bbb")},function(){$(this).css("color","#444")})},appends={};var exs="";if(IE>7){exs=IE<9?"background:#000;filter:alpha(opacity=0);":"background:rgba(0,0,0,0);"}else{exs="z-index:99999"}cssMap.nextholder+=exs;cssMap.prevholder+=exs;$.each(cssMap,function(key,value){css+=".galleria-"+prefix+key+"{"+value+"}"});css+=".galleria-"+prefix+"box.iframe .galleria-"+prefix+"prevholder,"+".galleria-"+prefix+"box.iframe .galleria-"+prefix+"nextholder{"+"width:100px;height:100px;top:50%;margin-top:-70px}";Utils.insertStyleTag(css,"galleria-lightbox");$.each(elems.split(" "),function(i,elemId){self.addElement("lightbox-"+elemId);el[elemId]=lightbox.elems[elemId]=self.get("lightbox-"+elemId)});lightbox.image=new Galleria.Picture;$.each({box:"shadow content close prevholder nextholder",info:"title counter",content:"info image",prevholder:"prev",nextholder:"next"},function(key,val){var arr=[];$.each(val.split(" "),function(i,prop){arr.push(prefix+prop)});appends[prefix+key]=arr});self.append(appends);$(el.image).append(lightbox.image.container);$(DOM().body).append(el.overlay,el.box);hover($(el.close).on("click:fast",lightbox.hide).html("&#215;"));$.each(["Prev","Next"],function(i,dir){var $d=$(el[dir.toLowerCase()]).html(/v/.test(dir)?"&#8249;&#160;":"&#160;&#8250;"),$e=$(el[dir.toLowerCase()+"holder"]);$e.on("click:fast",function(){lightbox["show"+dir]()});if(IE<8||Galleria.TOUCH){$d.show();return}$e.hover(function(){$d.show()},function(e){$d.stop().fadeOut(200)})});$(el.overlay).on("click:fast",lightbox.hide);if(Galleria.IPAD){self._options.lightboxTransitionSpeed=0}},rescale:function(event){var width=M.min($win.width()-40,lightbox.width),height=M.min($win.height()-60,lightbox.height),ratio=M.min(width/lightbox.width,height/lightbox.height),destWidth=M.round(lightbox.width*ratio)+40,destHeight=M.round(lightbox.height*ratio)+60,to={width:destWidth,height:destHeight,"margin-top":M.ceil(destHeight/2)*-1,"margin-left":M.ceil(destWidth/2)*-1};if(event){$(lightbox.elems.box).css(to)}else{$(lightbox.elems.box).animate(to,{duration:self._options.lightboxTransitionSpeed,easing:self._options.easing,complete:function(){var image=lightbox.image,speed=self._options.lightboxFadeSpeed;self.trigger({type:Galleria.LIGHTBOX_IMAGE,imageTarget:image.image});$(image.container).show();$(image.image).animate({opacity:1},speed);Utils.show(lightbox.elems.info,speed)}})}},hide:function(){lightbox.image.image=null;$win.off("resize",lightbox.rescale);$(lightbox.elems.box).hide().find("iframe").remove();Utils.hide(lightbox.elems.info);self.detachKeyboard();self.attachKeyboard(lightbox.keymap);lightbox.keymap=false;Utils.hide(lightbox.elems.overlay,200,function(){$(t
return this},prependChild:function(parentID,childID){this.$(parentID).prepend(this.get(childID)||childID);return this},remove:function(elemID){this.$(Utils.array(arguments).join(",")).remove();return this},append:function(data){var i,j;for(i in data){if(data.hasOwnProperty(i)){if(data[i].constructor===Array){for(j=0;data[i][j];j++){this.appendChild(i,data[i][j])}}else{this.appendChild(i,data[i])}}}return this},_scaleImage:function(image,options){image=image||this._controls.getActive();if(!image){return}var complete,scaleLayer=function(img){$(img.container).children(":first").css({top:M.max(0,Utils.parseValue(img.image.style.top)),left:M.max(0,Utils.parseValue(img.image.style.left)),width:Utils.parseValue(img.image.width),height:Utils.parseValue(img.image.height)})};options=$.extend({width:this._stageWidth,height:this._stageHeight,crop:this._options.imageCrop,max:this._options.maxScaleRatio,min:this._options.minScaleRatio,margin:this._options.imageMargin,position:this._options.imagePosition,iframelimit:this._options.maxVideoSize},options);if(this._options.layerFollow&&this._options.imageCrop!==true){if(typeof options.complete=="function"){complete=options.complete;options.complete=function(){complete.call(image,image);scaleLayer(image)}}else{options.complete=scaleLayer}}else{$(image.container).children(":first").css({top:0,left:0})}image.scale(options);return this},updateCarousel:function(){this._carousel.update();return this},resize:function(measures,complete){if(typeof measures=="function"){complete=measures;measures=undef}measures=$.extend({width:0,height:0},measures);var self=this,$container=this.$("container");$.each(measures,function(m,val){if(!val){$container[m]("auto");measures[m]=self._getWH()[m]}});$.each(measures,function(m,val){$container[m](val)});return this.rescale(complete)},rescale:function(width,height,complete){var self=this;if(typeof width==="function"){complete=width;width=undef}var scale=function(){self._stageWidth=width||self.$("stage").width();self._stageHeight=height||self.$("stage").height();if(self._options.swipe){$.each(self._controls.slides,function(i,img){self._scaleImage(img);$(img.container).css("left",self._stageWidth*i)});self.$("images").css("width",self._stageWidth*self.getDataLength())}else{self._scaleImage()}if(self._options.carousel){self.updateCarousel()}var frame=self._controls.frames[self._controls.active];if(frame){self._controls.frames[self._controls.active].scale({width:self._stageWidth,height:self._stageHeight,iframelimit:self._options.maxVideoSize})}self.trigger(Galleria.RESCALE);if(typeof complete==="function"){complete.call(self)}};scale.call(self);return this},refreshImage:function(){this._scaleImage();if(this._options.imagePan){this.addPan()}return this},_preload:function(){if(this._options.preload){var p,i,n=this.getNext(),ndata;try{for(i=this._options.preload;i>0;i--){p=new Galleria.Picture;ndata=this.getData(n);p.preload(this.isFullscreen()&&ndata.big?ndata.big:ndata.image);n=this.getNext(n)}}catch(e){}}},show:function(index,rewind,_history){var swipe=this._options.swipe;if(!swipe&&(this._queue.length>3||index===false||!this._options.queue&&this._queue.stalled)){return}index=M.max(0,M.min(parseInt(index,10),this.getDataLength()-1));rewind=typeof rewind!=="undefined"?!!rewind:index<this.getIndex();_history=_history||false;if(!_history&&Galleria.History){Galleria.History.set(index.toString());return}if(this.finger&&index!==this._active){this.finger.to=-(index*this.finger.width);this.finger.index=index}this._active=index;if(swipe){var data=this.getData(index),self=this;if(!data){return}var src=this.isFullscreen()&&data.big?data.big:data.image||data.iframe,image=this._controls.slides[index],cached=image.isCached(src),thumb=this._thumbnails[index];var evObj={cached:cached,index:index,rewind:rewind,imageTarget:image.image,thumbTarget:thumb.image,galleriaData:data};this.trigger($.extend(evObj,{type:Galleria.LOADSTART}));self.$("container").removeClass("videoplay");var complete=function(){self._layers[index].innerHTML=self.getData().layer||"";self.trigger($.extend(evObj,{type