-
Notifications
You must be signed in to change notification settings - Fork 0
/
jbmflickr.min.js
12 lines (10 loc) · 11.3 KB
/
jbmflickr.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
Jbmflickr v1.2
by Jan Bashaijha Mwesigwa - http://www.seven-m.com
For more information, visit:
http://www.seven-m.com/jbmflickr
Licensed under the GPL v2 License
- free for use in both personal and commercial projects
- attribution requires leaving author name, author link, and the license info intact
*/
(function(e,t,n){e(function(){var n={debug:true,error:function(e){var n="JBMFlickr error";try{if(this.debug&&t.console&&t.console.error){t.console.error([n,e].join(": "))}}catch(r){}},info:function(e){var n="JBMFlickr notice";try{if(t.console&&t.console.info){t.console.info([n,e].join(": "))}}catch(r){}}};var r={xhrPool:[],init:function(t){return this.each(function(){var i={};e.each(this.attributes,function(e,t){if(/jbmflickr/.test(t.nodeName)){i[t.nodeName.replace("jbmflickr-","")]=t.nodeValue}});t=e.isPlainObject(t)?t:{};e.extend(t,i);var s=e(this),o={userid:"",link_images:true,lightbox:true,lightbox_theme:"default",template:"",thumbnail_size:"q",per_page:10};if(typeof s.data("jbmflickr")=="undefined"){s.data("jbmflickr",e.extend(o,t));r.$this=s;var u=r.getSettings()}else{n.info("jbmflickr already initialized");return}var a=r.set("basePath",e("script").filter(function(){return/(jbmflickr\.js|jbmflickr\.dev\.js)/.test(e(this).attr("src"))}).attr("src").replace("jbmflickr.js","").replace("jbmflickr.dev.js",""));e("<link />").appendTo(e("head")).attr({type:"text/css",rel:"stylesheet"}).attr("href",a+"jbmflickr.css");if(r.get("lightbox",true,"boolean")){e.getScript(a+"libs/lightbox/lightbox.js").done(function(){n.info("lightbox script loaded");e("<link />").appendTo(e("head")).attr({type:"text/css",rel:"stylesheet"}).attr("href",a+"libs/lightbox/css/"+r.get("lightbox_theme","default")+"/lightbox.css")}).fail(function(){n.error("failed to load lightbox script")})}r.jcycleLoaded=e.getScript(a+"libs/jcycle/jcycle.js").done(function(){n.info("jcycle2 script loaded")}).fail(function(){n.error("failed to load jcycle2 script")});r.$slides=e('<div class="slides" />').appendTo(s);r.Display.init();if(e(".jbmflickr-search-field").length){e(".jbmflickr-search-field").change(function(){r.load({text:e(this).val()})})}if(r.get("initial_load",false,"boolean")){r.load()}})},Display:{init:function(t){this.pager=r.get("pager",'<div class="pager" />');var i=r.$this,s=e(this.pager).appendTo(i),i=r.$this,o=this;this.params={fx:"scrollHorz",speed:parseInt(r.get("slideshow_speed",2e3)),timeout:parseInt(r.get("slideshow_timeout",3e3)),log:false,slides:".page",pager:".pager",events:{"cycle-slide-added":function(t,n,i,s){e(s).find("a.lightbox-link").attr("rel","lightbox[gallery]");if(typeof r.get("",null)=="function"){r.get("").call(e(s))}else{e(s).find(".flickr-item").hover(function(){e(this).find(".description").show(200)},function(){e(this).find(".description").hide(200)})}}}};e.when(r.jcycleLoaded).done(function(){r.$slides.bind(o.params.events).cycle(o.params)}).fail(function(){n.error("JCycle2 was not loaded.")})},clear:function(){r.$slides.empty()},show:function(t){function h(e){e='<div class="page">'+e+"</div>";return e}var n=r.$this,i=r.$slides,s=[],o=[],u=this,a={s:75,q:150,t:100,m:240,n:320,"-":500,z:640},f=[],l=r.get("template",'<div class="flickr-item"><a class="lightbox-link" href="{url_z}" title="{title}"><div class="photo-wrapper"><div class="photo" style="background-image: url({url_'+r.get("thumbnail_size","q")+'});width: {width_q}px;height: {height_q}px"></div></div></a><div class="description"><div class="inner">{title}</div></div></div>'),c=[];u.clear();if(!t.length){i.append(e('<div class="placeholder" />').css({width:a[r.get("thumbnail_size","q")]+"px",height:a[r.get("thumbnail_size","q")]+"px"}));i.cycle("destroy").off();return}e.each(t,function(t,n){var r=l;e.each(n,function(e,t){var i=new RegExp("{"+e+"}","g");r=r.replace(i,n[e])});c.push(r)});while(c.length>r.get("per_page")){f.push(h(c.splice(0,r.get("per_page")).join("")))}f.push(h(c.join("")));u.params["progressive"]=f.splice(1);i.find(".cycle-slide").remove();e.when(r.jcycleLoaded).done(function(){i.cycle("destroy").off().on(u.params.events).cycle(u.params).cycle("add",f[0])})}},getPhotosUrl:function(t){var n={page:1,per_page:500,media:"all",method:"flickr.photos.search"},i={api_key:"311d9b69c2112e4263bfec74f3febf0d",format:"json",user_id:encodeURIComponent(r.get("userid")),nojsoncallback:"1",content_type:"7",extras:"tags,description,url_sq,url_t,url_s,url_q,url_m,url_n,url_z,url_c, url_l,url_o"},s="https://api.flickr.com/services/rest/?";e.extend(n,t,i);if(n.tags)delete n.tags;if(n.text)delete n.text;return s+decodeURIComponent(e.param(n))},_filterData:function(t,n){if(!n.tags&&!n.text)return t;var r=[],i=false,s=function(e,t){e.replace(/[\W]/g,"|").replace(/\|{2,}/,"|").replace(/(^\||\|$)/g,"");return(new RegExp("("+e+")","i")).test(t)};e.each(t.photos.photo,function(e,t){if(n.tags){i=s(n.tags,t.tags)}if(n.text){i=s(n.text,t.title+" "+t.description)}if(i)r.push(t)});t.photos.photo=r;t.photos.total=r.length;return t},load:function(t){var i=r,s=r.$this;if(arguments.length==0){t={}}url=r.getPhotosUrl(t);r.xhrPool.push(e.ajax({url:url,type:"GET",cache:true,dataType:"json"}).fail(function(e,t,r){n.error(t)}).done(function(e){if(e.stat!=="ok"){n.error("Error retrieving data: "+e.message);return}e=r._filterData(e,t);r.Display.show(e.photos.photo)}))},get:function(e,t,n){var i=r.$this,s=r.getSettings();n=n?n:"";switch(n){case"int":return s[e]?parseInt(s[e]):t?t:false;break;case"float":return s[e]?parseFloat(s[e]):t?t:false;break;case"boolean":if(typeof s[e]==="boolean"){return s[e]}else if(typeof s[e]==="string"){p=s[e].toLowerCase();return p=="true"||p=="1"?true:false}else if(typeof s[e]==="number"){return s[e]==0?false:true}else{return t?t:false}break;default:return s[e]?s[e]:t?t:""}},set:function(e,t){var n=r.$this,i=r.getSettings();if(!i)return false;i[e]=t;return t},getSettings:function(){var e=r.$this;return e.data("jbmflickr")},search:function(e,t){return this.each(function(){r.load(e)})},destroy:function(){return this.each(function(){var t=e(this);t.unbind().empty()})}};e.fn.jbmflickr=function(e){var t="destroy, search",i=false;if(typeof e==="string"){var s=new RegExp(e,"i");i=s.test(t)}if(typeof e==="string"&&!i){n.error(e+" is a protected method on jQuery.JBMflickr")}else if(r[e]){return r[e].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof e==="object"||!e){return r.init.apply(this,arguments)}else{n.error("Method "+e+" does not exist on jQuery.JBMflickr")}};var i={init:function(t){return this.each(function(){function f(){function l(){var e=new google.maps.KmlLayer({url:f,preserveViewport:true,map:r})}var t=new google.maps.LatLng(44.699898,34.189453);var n={center:t,zoom:o.zoom,scrollwheel:false,keyboardShortcuts:false};var r=new google.maps.Map(s.get(0),n);var f=i.getFeedUrl(o);var c=e.ajax({url:f,type:"GET",cache:true,dataType:"text"});e.getScript("http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0.2/src/markerclusterer.js").done(function(){e.getScript(a+"libs/geoxml3/geoxml3.js").done(function(){markerclusterer=new MarkerClusterer(r,[]);var t=[];var n=new geoXML3.parser({map:r,zoom:false,processStyles:true,failedParse:function(){l()},createMarker:function(n,s){function u(n){if(e.inArray([n.lat,n.lng].join(":"),t)>=0){n.lng+=.02;u(n)}else return}var o={lat:n.Point.coordinates[0].lat,lng:n.Point.coordinates[0].lng};u(o);var a=new google.maps.LatLng(o.lat,o.lng);t.push([o.lat,o.lng].join(":"));var f=n.styleUrl.replace("#styleMap/photo","//www.flickr.com/photos/"+i.get("userid"));var l=e("<div />").append(e('<div class="title" />').text(n.name)).append(e("<img />").attr({src:n.style.href.replace("_s.jpg","_m.jpg"),alt:n.name})).append("<br />").append(e("<a />").text("view large").attr({href:f,target:"_blank"})).html();var c=new google.maps.InfoWindow({content:l,maxWidth:400});var h=null;switch(i.get("marker")){case"photo":h=n.style.icon;break;case"google":h=null;break;default:h=i.get("marker",null)}var p=new google.maps.Marker({position:o,icon:h,flat:false,title:n.name});google.maps.event.addListener(p,"click",function(){c.open(r,p)});markerclusterer.addMarker(p)}});c.done(function(e){n.parseKmlString(e)}).fail(function(){l()})})}).fail(function(){l()});u.map=r}function l(){google.load("maps","3",{callback:f,other_params:"sensor=false"})}var r={};e.each(this.attributes,function(e,t){if(/^jbmflickrmap/.test(t.nodeName)){r[t.nodeName.replace("jbmflickrmap-","")]=t.nodeValue}});t=e.isPlainObject(t)?t:{},e.extend(t,r);var s=e(this),o=e.extend({userid:null,zoom:5,limit:200,marker:"google"},t);if(typeof s.data("jbmflickrmap")=="undefined"){s.data("jbmflickrmap",e.extend(o,t));i.$this=s;var u=i.getSettings()}else{n.info("jbmflickrmap already initialized");return}var a=e("script").filter(function(){return/(jbmflickr|jbmflickr\.dev)\.js/.test(e(this).attr("src"))}).attr("src").replace("jbmflickr.js","").replace("jbmflickr.dev.js","");if(!o.userid)return;if(o.zoom)o.zoom=parseInt(o.zoom);if(typeof google=="undefined"||!google.load){e.getScript("//www.google.com/jsapi",function(){l()})}else{l()}})},getFeedUrl:function(t){var n={page:1,per_page:i.get("limit",40),tags:"",text:"",format:"feed-kml",media:"photos",method:"flickr.photos.search",has_geo:"1"},r={api_key:"311d9b69c2112e4263bfec74f3febf0d",user_id:i.get("userid"),jsoncallback:"?",content_type:"7"},s="https://api.flickr.com/services/rest/?";e.extend(n,t,r);return s+decodeURIComponent(e.param(n))},locate:function(t){return this.each(function(){var n=e(this),r=i.getSettings().map,s=new google.maps.Geocoder;if(s){s.geocode({address:t},function(t,n){if(n==google.maps.GeocoderStatus.OK){r.fitBounds(t[0].geometry.viewport);var i=r.getBounds();var s=i.getSouthWest().lat();var o=i.getSouthWest().lng();var u=i.getNorthEast().lat();var a=i.getNorthEast().lng();var f=[o,s,a,u].join(",");e(".jbmflickr").jbmflickr("search",{bbox:f,accuracy:1})}})}})},get:function(e,t,n){var r=i.$this,s=i.getSettings();n=n?n:"";switch(n){case"int":return s[e]?parseInt(s[e]):t?t:false;break;case"float":return s[e]?parseFloat(s[e]):t?t:false;break;case"boolean":if(typeof s[e]==="boolean"){return s[e]}else if(typeof s[e]==="string"){p=s[e].toLowerCase();return p=="true"||p=="1"?true:false}else if(typeof s[e]==="number"){return s[e]==0?false:true}else{return t?t:false}break;default:return s[e]?s[e]:t?t:""}},set:function(e,t){var n=i.$this,r=i.getSettings();if(!r)return false;r[e]=t;return t},getSettings:function(){var e=i.$this;return e.data("jbmflickrmap")}};e.fn.jbmflickrmap=function(e){var t="destroy, locate",r=false;if(typeof e==="string"){var s=new RegExp(e,"i");r=s.test(t)}if(typeof e==="string"&&!r){n.error(e+" is a protected method on jQuery.JBMflickrmap")}else if(i[e]){return i[e].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof e==="object"||!e){return i.init.apply(this,arguments)}else{n.error("Method "+e+" does not exist on jQuery.JBMflickrmap")}};if(e(".jbmflickrmap").length){e(".jbmflickrmap").jbmflickrmap()}if(e(".jbmflickrmap-location")){e(".jbmflickrmap-location").change(function(){if(e("#"+e(".jbmflickrmap-location").attr("rel")).length){e("#"+e(".jbmflickrmap-location").attr("rel")).jbmflickrmap("locate",e(this).val())}else{e(".jbmflickrmap").jbmflickrmap("locate",e(this).val())}})}if(e(".jbmflickr").length){e(".jbmflickr").jbmflickr()}if(e(".jbmflickr-tag-cloud").length){if(e(".jbmflickr").length){e(".jbmflickr-tag-cloud > a").click(function(t){t.preventDefault();e(".jbmflickr").jbmflickr("search",{tags:e(this).attr("href").replace("#","")})})}}})})(this.jQuery,this,this.document)