1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
!function(i){Galleria.requires(1.25,"The Picasa Plugin requires Galleria version 1.2.5 or later.");var e=Galleria.utils.getScriptPath();Galleria.Picasa=function(){this.options={max:30,imageSize:"medium",thumbSize:"thumb",complete:function(){}}};Galleria.Picasa.prototype={constructor:Galleria.Picasa,search:function(i,e){return this._call("search","all",{q:i},e)},user:function(i,e){return this._call("user","user/"+i,e)},useralbum:function(i,e,t){return this._call("useralbum","user/"+i+"/album/"+e,t)},setOptions:function(e){i.extend(this.options,e);return this},_call:function(e,t,a,s){t="https://picasaweb.google.com/data/feed/api/"+t+"?";if(typeof a=="function"){s=a;a={}}var r=this;a=i.extend({kind:"photo",access:"public","max-results":this.options.max,thumbsize:this._getSizes().join(","),alt:"json-in-script",callback:"?"},a);i.each(a,function(i,e){t+="&"+i+"="+e});var l=false;Galleria.utils.wait({until:function(){return l},success:function(){r._parse.call(r,l.feed.entry,s)},error:function(){var i="";if(e=="user"){i="user not found."}else if(e=="useralbum"){i="album or user not found."}Galleria.raise("Picasa request failed"+(i?": "+i:"."))},timeout:5e3});i.getJSON(t,function(i){l=i});return r},_getSizes:function(){var e=this,t={small:"72c",thumb:"104u",medium:"640u",big:"1024u",original:"1600u"},a=e.options,s={},r,l=[32,48,64,72,94,104,110,128,144,150,160,200,220,288,320,400,512,576,640,720,800,912,1024,1152,1280,1440,1600];i(["thumbSize","imageSize"]).each(function(){if(a[this]in t){s[this]=t[a[this]]}else{r=Galleria.utils.parseValue(a[this]);if(r>1600){r=1600}else{i.each(l,function(i){if(r<this){r=l[i-1];return false}})}s[this]=r}});return[s.thumbSize,s.imageSize,"1280u"]},_parse:function(e,t){var a=this,s=[],r;i.each(e,function(){r=this.media$group.media$thumbnail;s.push({thumb:r[0].url,image:r[1].url,big:r[2].url,title:this.summary.$t})});t.call(this,s)}};var t=Galleria.prototype.load;Galleria.prototype.load=function(){if(arguments.length||typeof this._options.picasa!=="string"){t.apply(this,Galleria.utils.array(arguments));return}var a=this,s=Galleria.utils.array(arguments),r=this._options.picasa.split(":"),l,n=i.extend({},a._options.picasaOptions),u=typeof n.loader!=="undefined"?n.loader:i("<div>").css({width:48,height:48,opacity:.7,background:"#000 url("+e+"loader.gif) no-repeat 50% 50%"});if(r.length){if(typeof Galleria.Picasa.prototype[r[0]]!=="function"){Galleria.raise(r[0]+" method not found in Picasa plugin");return t.apply(this,s)}if(!r[1]){Galleria.raise("No picasa argument found");return t.apply(this,s)}window.setTimeout(function(){a.$("target").append(u)},100);l=new Galleria.Picasa;if(typeof a._options.picasaOptions==="object"){l.setOptions(a._options.picasaOptions)}var o=[];if(r[0]=="useralbum"){o=r[1].split("/");if(o.length!=2){Galleria.raise("Picasa useralbum not correctly formatted (should be [user]/[album])");return}}else{o.push(r[1])}o.push(function(i){a._data=i;u.remove();a.trigger(Galleria.DATA);l.options.complete.call(l,i)});l[r[0]].apply(l,o)}else{t.apply(this,s)}}}(jQuery); |