2 lines
2.3 KiB
JavaScript
2 lines
2.3 KiB
JavaScript
|
|
/*! picbookjs 0.3.1 Copyright (C) 2014 Henrique Alves, http://henriquea.github.io/picbookjs */
|
||
|
|
var _picbookOptions=null,picbookJs=function(a){"use strict";function b(a){this.options=this.extend(this._options,a),this.init(),_picbookOptions=this.options}return b.prototype={count:0,loaded:!1,dom:{},_options:{graph:"https://graph.facebook.com/",limit:10,target:".picbook"},init:function(){this.loaded=!1,this.getAlbum({callback:"picbookJs.prototype.albumComplete"}),this.dom.wrapper=a.querySelector(this.options.target),this.dom.title=a.createElement("h3"),this.dom.title.classList.add("album-title"),this.dom.photos=a.createElement("ul"),this.dom.photos.classList.add("photo-list"),this.dom.wrapper.appendChild(this.dom.title),this.dom.wrapper.appendChild(this.dom.photos)},getAlbum:function(b){var c,d=a.createElement("script"),e=_picbookOptions||this.options,f=e.graph+e.albumId;d.type="text/javascript",d.async=!0,d.src=f+"?callback="+b.callback,c=a.getElementsByTagName("script")[0],c.parentNode.insertBefore(d,c.nextSibling)},getPhotos:function(b){var c,d=a.createElement("script"),e=_picbookOptions||this.options,f=e.graph+e.albumId+"/photos";d.type="text/javascript",d.async=!0,d.src=f+"?limit="+e.limit+"&callback="+b.callback,c=a.getElementsByTagName("script")[0],c.parentNode.insertBefore(d,c.nextSibling)},albumComplete:function(a){var b=_picbookOptions||this.options;this.album=a,this.count=a.count,this.getPhotos({callback:"picbookJs.prototype.photosComplete"}),"function"==typeof b.albumLoaded&&b.albumLoaded(),this.dom.title.innerHTML=a.name},photosComplete:function(a){var b=_picbookOptions||this.options;this.photos=a.data,this.loaded=!0,this.createPhotos(),"function"==typeof b.photosLoaded&&b.photosLoaded()},createPhotos:function(){var b,c,d,e,f,g,h,i=[];for(c=0,d=this.photos.length;d>c;c++)e=this.photos[c].images[0],e.source.match(/oh=/)||(h=this.photos[c].link.replace(/graph.facebook/gi,"www.facebook"),f=a.createElement("li"),g=a.createElement("a"),f.classList.add("photo-list-item"),this.dom.photos.appendChild(f),f.appendChild(g),g.classList.add("item-thumb"),i=e.source.split("/").splice(0),i.splice(5,0,"p320x320"),b=i.join("/"),g.setAttribute("href",h),g.setAttribute("style","background-image: url("+b+")"))},extend:function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}},b}(document);
|