text: !function(a,b,c,d){"use strict";function e(b){this.options=a.extend({},f,b),a.extend(this,this.options)}b.Tptr=b.Tptr||{};var f={id:"unknown",title:"Unknown",icon:function(){var a="unknown"!==this.id?this.id+".svg":"source.svg";return this.delegate.options.image_url_prefix+a},image_data:null,delegate:null};e.prototype.setImageData=function(a,b){this.image_data=a,this.delegate.imageDataSet(this,b)},e.prototype.pick=function(){this.delegate.pickSource(this)},e.prototype.getInstance=function(){return a.extend(!0,{},this)},e.prototype.downloadImage=function(a,c){var d=new XMLHttpRequest;d.open("GET",a,!0),d.responseType="arraybuffer",d.onload=function(a){if(200==this.status){for(var d=new Uint8Array(this.response),e=d.length,f=new Array(e);e--;)f[e]=String.fromCharCode(d[e]);var g=f.join(""),h=b.btoa(g);c("data:image/png;base64,"+h,"success")}else c(null,"error",this.status)},d.onerror=d.onabort=function(a){c(null,"error",a.error)},d.send()},Tptr.TapatarSource=e}(jQuery,window,document);var Tptr=Tptr||{};Tptr.sources=Tptr.sources||{},Tptr.sources.facebook=new Tptr.TapatarSource({id:"facebook",title:"Facebook",action:{content:"Get",onClick:function(a){function b(a){FB.api("/me/picture?type=large",function(b){c.downloadImage(b.data.url,function(b){if(b)c.setImageData(b,a),c.imageLoaded=!0;else try{c.delegate.options.sources.facebook.enabled=!1}catch(d){}})})}var c=this;return c.imageLoaded?void c.pick():void("connected"===c.fbStatus?b(!0):FB.login(function(){b(!0)}))}},onAdd:function(){var a=this;return a.delegate.options.sources.facebook.appId?(window.fbAsyncInit=function(){FB.init({appId:a.delegate.options.sources.facebook.appId,xfbml:!0,version:"v2.3"}),FB.getLoginStatus(function(b){a.fbStatus=b.status})},void function(a,b,c){var d,e=a.getElementsByTagName(b)[0];a.getElementById(c)||(d=a.createElement(b),d.id=c,d.src="https://connect.facebook.net/en_US/sdk.js",e.parentNode.insertBefore(d,e))}(document,"script","facebook-jssdk")):void(a.delegate.options.sources.facebook.enabled=!1)}});var Tptr=Tptr||{};Tptr.sources=Tptr.sources||{},Tptr.sources.gravatar=new Tptr.TapatarSource({id:"gravatar",title:"Gravatar",action:{content:"Pick",onClick:function(a){this.image_data&&this.setImageData(this.image_data,!0)}},onAdd:function(){var a=function(a){function b(a,b){return a<<b|a>>>32-b}function c(a,b){var c,d,e,f,g;return e=2147483648&a,f=2147483648&b,c=1073741824&a,d=1073741824&b,g=(1073741823&a)+(1073741823&b),c&d?2147483648^g^e^f:c|d?1073741824&g?3221225472^g^e^f:1073741824^g^e^f:g^e^f}function d(a,b,c){return a&b|~a&c}function e(a,b,c){return a&c|b&~c}function f(a,b,c){return a^b^c}function g(a,b,c){return b^(a|~c)}function h(a,e,f,g,h,i,j){return a=c(a,c(c(d(e,f,g),h),j)),c(b(a,i),e)}function i(a,d,f,g,h,i,j){return a=c(a,c(c(e(d,f,g),h),j)),c(b(a,i),d)}function j(a,d,e,g,h,i,j){return a=c(a,c(c(f(d,e,g),h),j)),c(b(a,i),d)}function k(a,d,e,f,h,i,j){return a=c(a,c(c(g(d,e,f),h),j)),c(b(a,i),d)}function l(a){for(var b,c=a.length,d=c+8,e=(d-d%64)/64,f=16*(e+1),g=Array(f-1),h=0,i=0;c>i;)b=(i-i%4)/4,h=i%4*8,g[b]=g[b]|a.charCodeAt(i)<<h,i++;return b=(i-i%4)/4,h=i%4*8,g[b]=g[b]|128<<h,g[f-2]=c<<3,g[f-1]=c>>>29,g}function m(a){var b,c,d="",e="";for(c=0;3>=c;c++)b=a>>>8*c&255,e="0"+b.toString(16),d+=e.substr(e.length-2,2);return d}function n(a){a=a.replace(/rn/g,"n");for(var b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b}var o,p,q,r,s,t,u,v,w,x=Array(),y=7,z=12,A=17,B=22,C=5,D=9,E=14,F=20,G=4,H=11,I=16,J=23,K=6,L=10,M=15,N=21;for(a=n(a),x=l(a),t=1732584193,u=4023233417,v=2562383102,w=271733878,o=0;o<x.length;o+=16)p=t,q=u,r=v,s=w,t=h(t,u,v,w,x[o+0],y,3614090360),w=h(w,t,u,v,x[o+1],z,3905402710),v=h(v,w,t,u,x[o+2],A,606105819),u=h(u,v,w,t,x[o+3],B,3250441966),t=h(t,u,v,w,x[o+4],y,4118548399),w=h(w,t,u,v,x[o+5],z,1200080426),v=h(v,w,t,u,x[o+6],A,2821735955),u=h(u,v,w,t,x[o+7],B,4249261313),t=h(t,u,v,w,x[o+8],y,1770035416),w=h(w,t,u,v,x[o+9],z,2336552879),v=h(v,w,t,u,x[o+10],A,4294925233),u=h(u,v,w,t,x[o+11],B,2304563134),t=h(t,u,v,w,x[o+12],y,1804603682),w=h(w,t,u,v,x[o+13],z,4254626195),v=h(v,w,t,u,x[o+14],A,2792965006),u=h(u,v,w,t,x[o+15],B,1236535329),t=i(t,u,v,w,x[o+1],C,4129170786),w=i(w,t,u,v,x[o+6],D,3225465664),v=i(v,w,t,u,x[o+11],E,643717713),u=i(u,v,w,t,x[o+0],F,3921069994),t=i(t,u,v,w,x[o+5],C,3593408605),w=i(w,t,u,v,x[o+10],D,38016083),v=i(v,w,t,u,x[o+15],E,3634488961),u=i(u,v,w,t,x[o+4],F,3889429448),t=i(t,u,v,w,x[o+9],C,568446438),w=i(w,t,u,v,x[o+14],D,3275163606),v=i(v,w,t,u,x[o+3],E,4107603335),u=i(u,v,w,t,x[o+8],F,1163531501),t=i(t,u,v,w,x[o+13],C,2850285829),w=i(w,t,u,v,x[o+2],D,4243563512),v=i(v,w,t,u,x[o+7],E,1735328473),u=i(u,v,w,t,x[o+12],F,2368359562),t=j(t,u,v,w,x[o+5],G,4294588738),w=j(w,t,u,v,x[o+8],H,2272392833),v=j(v,w,t,u,x[o+11],I,1839030562),u=j(u,v,w,t,x[o+14],J,4259657740),t=j(t,u,v,w,x[o+1],G,2763975236),w=j(w,t,u,v,x[o+4],H,1272893353),v=j(v,w,t,u,x[o+7],I,4139469664),u=j(u,v,w,t,x[o+10],J,3200236656),t=j(t,u,v,w,x[o+13],G,681279174),w=j(w,t,u,v,x[o+0],H,3936430074),v=j(v,w,t,u,x[o+3],I,3572445317),u=j(u,v,w,t,x[o+6],J,76029189),t=j(t,u,v,w,x[o+9],G,3654602809),w=j(w,t,u,v,x[o+12],H,3873151461),v=j(v,w,t,u,x[o+15],I,530742520),u=j(u,v,w,t,x[o+2],J,3299628645),t=k(t,u,v,w,x[o+0],K,4096336452),w=k(w,t,u,v,x[o+7],L,1126891415),v=k(v,w,t,u,x[o+14],M,2878612391),u=k(u,v,w,t,x[o+5],N,4237533241),t=k(t,u,v,w,x[o+12],K,1700485571),w=k(w,t,u,v,x[o+3],L,2399980690),v=k(v,w,t,u,x[o+10],M,4293915773),u=k(u,v,w,t,x[o+1],N,2240044497),t=k(t,u,v,w,x[o+8],K,1873313359),w=k(w,t,u,v,x[o+15],L,4264355552),v=k(v,w,t,u,x[o+6],M,2734768916),u=k(u,v,w,t,x[o+13],N,1309151649),t=k(t,u,v,w,x[o+4],K,4149444226),w=k(w,t,u,v,x[o+11],L,3174756917),v=k(v,w,t,u,x[o+2],M,718787259),u=k(u,v,w,t,x[o+9],N,3951481745),t=c(t,p),u=c(u,q),v=c(v,r),w=c(w,s);var O=m(t)+m(u)+m(v)+m(w);return O.toLowerCase()},b=b||200;try{var c=this.delegate.options.sources.gravatar.email;if(!c)throw"no email"}catch(d){try{this.delegate.options.sources.gravatar.enabled=!1}catch(d){}return}var e="https://secure.gravatar.com/avatar/"+a(c)+".jpg?s="+b+"&d=404",f=this;this.downloadImage(e,function(a){if(a)f.setImageData(a);else try{f.delegate.options.sources.gravatar.enabled=!1}catch(b){}})}});var Tptr=Tptr||{};Tptr.sources=Tptr.sources||{},Tptr.sources.local=new Tptr.TapatarSource({id:"local",title:"local",action:{content:"Browse",onClick:function(a){this.fileInput.click()}},onAdd:function(){function a(a){for(var c,d=a.target.files,e=0;c=d[e];e++)if(c.type.match("image.*")){var f=new FileReader;f.onload=function(a){return function(a){b.setImageData(a.target.result,!0)}}(c),f.readAsDataURL(c)}}var b=this;this.fileInput=$('<input type="file" style="display:none;" accept=".png,.jpeg,.jpg,.gif">'),b.fileInput.on("change",a)}}),function(a,b,c,d){"use strict";function e(b,c){return this.element=b,this.options=a.extend(!0,{},g,c),this._defaults=g,this._name=f,this.sources=[],this.pickerActive=!1,this.init(),this}b.Tptr=b.Tptr||{};var f="tapatar",g={sources:{local:{enabled:!0,order:1},facebook:{enabled:!0,order:2},gravatar:{enabled:!0,order:3}},image_url_prefix:"img/",default_image:function(){return this.image_url_prefix+"default.svg"},templates:{widget:'<div class="tptr-widget"><span class="tptr-widget-pick">pick</span></div>',overlay:'<div class="tptr-container" style="display: none"><div class="tptr-overlay"></div></div>',picker:'<div class="tptr-picker"><div class="tptr-close"></div><div class="tptr-image-holder tptr-box-part"><div class="tptr-big-image"> </div></div><div class="tptr-sources-holder tptr-box-part"><div class="tptr-sources"></div><button class="tptr-save">Save</button></div></div>',source:'<div class="tptr-source"><div class="tptr-source-part tptr-source-icon"><img /></div><div class="tptr-source-part tptr-source-content"></div><div class="tptr-source-part tptr-source-image-preview"></div><button class="tptr-source-part tptr-source-pick">Pick</button></div>'}};e.prototype={init:function(){if(!a(this.element).is("input[type=hidden]"))throw"Tapatar target element should be an input of type hidden";for(var b in this.options.sources)this.options.sources[b].enabled&&Tptr.sources[b]&&this.registerSource(Tptr.sources[b]);var c=a('<div class="tptr"></div>');a(this.element).addClass("tptr-file-input").hide().wrap(c),this.$tptrEl=a(this.element).parent();var d=a('<div class="tptr-inner"></div>');this.$tptrEl.append('<div class="tptr-inner"></div>');var d=this.$tptrEl.find(".tptr-inner"),e=this,f=a(this.options.templates.widget);f.css("background-image","url("+this._getImageFromPathOrFunction(this.options.default_image,this.options)+")"),d.html(f).on("click",function(){e._popPicker()})},registerSource:function(a){if(a=a.getInstance(),!a.id)throw"Source id missing";a.delegate=this,this.sources[a.id]=a,a.onAdd&&a.onAdd()},pickSource:function(b){this.selectedSource=b.id,this._setPickedImage(b),a(this.element).trigger("tapatar.source.picked",[b])},imageDataSet:function(b,c){this._updateSourceUi(b),a(this.element).trigger("tapatar.source.image_data.set",[b]),c===!0&&this.pickSource(b)},_registerHandlers:function(){var b=this;this.$containerEl.on("click",".tptr-source-image-preview",function(){var c=a(this).parents("[data-source-id]").data("source-id");b.selectedSource=c,b._setPickedImage(b.sources[c])}),this.$containerEl.on("click",".tptr-save",function(){b._save()}),this.$containerEl.on("click",".tptr-close",function(){b._closePicker()}),a(c).on("keyup",function(a){27==a.keyCode&&b._closePicker()})},_getImageFromPathOrFunction:function(b,c){return"function"==typeof b?a.proxy(b,c)():b},_setPickedImage:function(a){a.image_data&&this.$containerEl.find(".tptr-image-holder .tptr-big-image").css("background-image","url("+a.image_data+")")},_popPicker:function(){var b=a(this.options.templates.picker),c=this.selectedSource?this.sources[this.selectedSource].image_data:this._getImageFromPathOrFunction(this.options.default_image,this.options);b.find(".tptr-big-image").css("background-image","url("+c+")");var d=b.find(".tptr-sources"),e=[];for(var f in this.options.sources)e.push([f,this.options.sources[f].order]),e.sort(function(a,b){return a[1]-b[1]});e.reverse();for(var g=e.length-1;g>=0;g--){var f=this.sources[e[g][0]];f&&this.options.sources[f.id].enabled&&d.append(a(this._buildSource(f)))}var h=a(this.options.templates.overlay);h.find(".tptr-overlay").html(b),a("body").append(h);this.pickerActive=!0,h.fadeIn(),this.$containerEl=h,this._registerHandlers(),this._updateAllSourcesUi()},_closePicker:function(){this.$containerEl.fadeOut(function(){a(this).remove()})},_buildSource:function(b){var c=a(this.options.templates.source);c.find(".tptr-source-content").html(b.title),c.attr("data-source-id",b.id),c.find(".tptr-source-icon img").attr("src",this._getImageFromPathOrFunction(b.icon,b));var d=c.find(".tptr-source-pick");return b.action?(d.html(b.action.content),b.action.onClick&&d.on("click",a.proxy(b.action.onClick,b))):d.prop("disabled"),c},_getSourceEl:function(a){return this.$containerEl.find("[data-source-id="+a.id+"]")},_updateAllSourcesUi:function(){for(var a in this.sources)this._updateSourceUi(this.sources[a])},_updateSourceUi:function(a){this.pickerActive&&this._setPreviewImage(a)},_setPreviewImage:function(b){b.image_data&&this._getSourceEl(b).find(".tptr-source-image-preview").html(a("<div></div>").css("background-image","url("+b.image_data+")"))},_save:function(){if(this.sources[this.selectedSource]){var b=this.sources[this.selectedSource].image_data;a(this.element).val(b),this.$tptrEl.find(".tptr-widget").css("background-image","url("+b+")")}this._closePicker()}},a.fn[f]=function(b){var c=arguments;if(b===d||"object"==typeof b)return this.each(function(){a.data(this,"plugin_"+f)||a.data(this,"plugin_"+f,new e(this,b))});if("string"==typeof b&&"_"!==b[0]&&"init"!==b){if(0==Array.prototype.slice.call(c,1).length&&-1!=a.inArray(b,a.fn[f].getters)){var g=a.data(this[0],"plugin_"+f);return g[b].apply(g,Array.prototype.slice.call(c,1))}return this.each(function(){var d=a.data(this,"plugin_"+f);d instanceof e&&"function"==typeof d[b]&&d[b].apply(d,Array.prototype.slice.call(c,1))})}},a.fn[f].getters=[]}(jQuery,window,document);