{"size": 159101, "ext": "js", "max_stars_repo_path": "img/clouds_files/footer.js", "max_stars_repo_name": "thomasjohan/thomasjohan.github.io", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "img/clouds_files/footer.js", "max_issues_repo_name": "thomasjohan/thomasjohan.github.io", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "img/clouds_files/footer.js", "max_forks_repo_name": "thomasjohan/thomasjohan.github.io", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 159101.0, "max_line_length": 159101, "alphanum_fraction": 0.7134210344}
(function(){var a=this.Giphy=a||{};var b=this.Timer=undefined;var c=this.Utils={};var d=this.Sharing={};var e=this.Analytics={};var f=this.Etc={};var g=this.Images={};var h=this.SearchResults={};var i=this.Nav={};var j=this.Login={};var k=this.Favorites={};var l=this.Search={};var m=this.Tags={};var n=this.Instagram={};var o=this.Browsebar={};var p=this.GifDetail={};var q=this.ArtistLanding={};var r=this.PartnerLanding={};var s=this.HeaderNav={};var t=this.Users={};var u=this.Upload={};var v=this.Newsletter={};var w=this.Facebook={};}).call(this);(function(a){var b={initialize:function(){var a=this;$.ajaxSetup({beforeSend:function(b,c){b.setRequestHeader("Authorization","ApiKey giphy-website:e0771ed7b244ec9c942bea646ad08e6bf514f51a");if(!a.csrfSafeMethod(c.type)&&!this.crossDomain)b.setRequestHeader("X-CSRFToken",$.cookie('csrftoken'));}});},csrfSafeMethod:function(a){return(/^(GET|HEAD|OPTIONS|TRACE)$/.test(a));}};a.CSRF=b;b.initialize();})(Giphy);(function(a,b){var c={loadUrl:function(b){var c=$.Deferred();var d=new XMLHttpRequest();d.onload=a.bind(function(a){var b=d.response;if(b){var e=new Uint8Array(b);this.parse(e,c);}else c.reject();},this);d.onerror=function(){c.reject();};d.open('GET',b,true);d.responseType='arraybuffer';d.send();return c.promise();},loadBinary:function(a){var b=$.Deferred();this.parse(a,b);return b.promise();},parse:function(b,c){var d=document.createElement('canvas');var e=d.getContext('2d');var g=new f(b);var i=null;var j=null;var k=null;var l=null;var m=0;var n=null;var o={frames:[],duration:0,still:''};setTimeout(function(){h(g,{hdr:function(a){i=a;d.width=i.width;d.height=i.height;o.width=i.width;o.height=i.height;},gce:function(a){var b=(a.delayTime||10)*10;l=k;j=a.transparencyGiven?a.transparencyIndex:null;k=a.disposalMethod;o.frames.push({index:o.frames.length,delay:b});o.duration+=b;},img:function(b){var c=o.frames.length-1;if(c>0){if(l===3)e.putImageData(o.frames[m].data,0,0);else m=c;if(l===2)e.clearRect(n.leftPos,n.topPos,n.width,n.height);}var f=b.lctFlag?b.lct:i.gct;var g=e.getImageData(b.leftPos,b.topPos,b.width,b.height);var h=g.data;b.pixels.forEach(function(a,b){if(a!==j){h[b*4+0]=f[a][0];h[b*4+1]=f[a][1];h[b*4+2]=f[a][2];h[b*4+3]=255;}else if(l===2){h[b*4+0]=0;h[b*4+1]=0;h[b*4+2]=0;h[b*4+3]=0;}});e.putImageData(g,b.leftPos,b.topPos);n=b;if(o.frames[c]){o.frames[c]=a.extend(o.frames[c],{width:d.width,height:d.height,data:e.getImageData(0,0,d.width,d.height)||null});if(c===0)o.still=d.toDataURL('image/png');}},eof:function(a){c.resolve(o);}});},10);}};b.GifParser=c;var d=function(a){return a.reduce(function(a,b){return a*2+b;},0);};var e=function(a){var b=[];for(var c=7;c>=0;c--)b.push(!!(a&(1<<c)));return b;};var f=function(a){this.data=a;this.len=this.data.length;this.pos=0;this.readByte=function(){if(this.pos>=this.data.length)throw new Error('Attempted to read past end of stream.');return a[this.pos++];};this.readBytes=function(a){var b=[];for(var c=0;c<a;c++)b.push(this.readByte());return b;};this.read=function(a){var b='';for(var c=0;c<a;c++)b+=String.fromCharCode(this.readByte());return b;};this.readUnsigned=function(){var a=this.readBytes(2);return(a[1]<<8)+a[0];};};var g=function(a,b){var c=b.length;var d=0;var e=0x01;var f=[];var g=1<<a;var h=g+1;var i=a+1;var j=[];var k=function(){j=[];i=a+1;for(var b=0;b<g;b++)j[b]={val:b,prv:-1,len:1};j[g]=null;j[h]=null;};var l=function(a){if(a===-1||j[a]===null)return;l(j[a].prv);f.push(j[a].val);};var m;var n;while(c>0){n=m;m=0;for(var o=0;o<i;o++){if(b.charCodeAt(d>>3)&(1<<(d&7)))m|=1<<o;d++;e<<=1;if(e===0x100){e=0x01;c--;}}if(m===g){k();continue;}if(m===h)break;if(m<j.length){if(n!==g){ptr=m;while(j[ptr].prv!=-1)ptr=j[ptr].prv;j.push({val:j[ptr].val,prv:n,len:j[n].len+1});}}else{if(m!==j.length)throw new Error('Invalid LZW code.');ptr=n;while(j[ptr].prv!=-1)ptr=j[ptr].prv;j.push({val:j[ptr].val,prv:n,len:j[n].len+1});}l(m);if(j.length===(1<<i)&&i<12)i++;}return f;};var h=function(a,b){b||(b={});var c=function(b){var c=[];for(var d=0;d<b;d++)c.push(a.readBytes(3));return c;};var f=function(){var b,c;c='';do{b=a.readByte();c+=a.read(b);}while(b!==0);return c;};var h=function(){var f={};f.sig=a.read(3);f.ver=a.read(3);if(f.sig!=='GIF')throw new Error('Not a GIF file.');f.width=a.readUnsigned();f.height=a.readUnsigned();var g=e(a.readByte());f.gctFlag=g.shift();f.colorRes=d(g.splice(0,3));f.sorted=g.shift();f.gctSize=d(g.splice(0,3));f.bgColor=a.readByte();f.pixelAspectRatio=a.readByte();if(f.gctFlag)f.gct=c(1<<(f.gctSize+1));b.hdr&&b.hdr(f);};var i=function(c){var g=function(c){var f=a.readByte();var g=e(a.readByte());c.reserved=g.splice(0,3);c.disposalMethod=d(g.splice(0,3));c.userInput=g.shift();c.transparencyGiven=g.shift();c.delayTime=a.readUnsigned();c.transparencyIndex=a.readByte();c.terminator=a.readByte();b.gce&&b.gce(c);};var h=function(a){a.comment=f();b.com&&b.com(a);};var i=function(c){var d=a.readByte();c.ptHeader=a.readBytes(12);c.ptData=f();b.pte&&b.pte(c);};var j=function(c){var d=function(c){var d=a.readByte();c.unknown=a.readByte();c.iterations=a.readUnsigned();c.terminator=a.readByte();b.app&&b.app.NETSCAPE&&b.app.NETSCAPE(c);};var e=function(a){a.appData=f();b.app&&b.app[a.identifier]&&b.app[a.identifier](a);};var g=a.readByte();c.identifier=a.read(8);c.authCode=a.read(3);switch(c.identifier){case 'NETSCAPE':d(c);break;default:e(c);break;}};var k=function(a){a.data=f();b.unknown&&b.unknown(a);};c.label=a.readByte();switch(c.label){case 0xF9:c.extType='gce';g(c);break;case 0xFE:c.extType='com';h(c);break;case 0x01:c.extType='pte';i(c);break;case 0xFF:c.extType='app';j(c);break;default:c.extType='unknown';k(c);break;}};var j=function(h){var i=function(a,b){var c=new Array(a.length);var d=a.length/b;var e=function(d,e){var f=a.slice(e*b,(e+1)*b);c.splice.apply(c,[d*b,b].concat(f));};var f=[0,4,2,1];var g=[8,8,4,2];var h=0;for(var i=0;i<4;i++)for(var j=f[i];j<d;j+=g[i]){e(j,h);h++;}return c;};h.leftPos=a.readUnsigned();h.topPos=a.readUnsigned();h.width=a.readUnsigned();h.height=a.readUnsigned();var j=e(a.readByte());h.lctFlag=j.shift();h.interlaced=j.shift();h.sorted=j.shift();h.reserved=j.splice(0,2);h.lctSize=d(j.splice(0,3));if(h.lctFlag)h.lct=c(1<<(h.lctSize+1));h.lzwMinCodeSize=a.readByte();var k=f();h.pixels=g(h.lzwMinCodeSize,k);if(h.interlaced)h.pixels=i(h.pixels,h.width);b.img&&b.img(h);};var k=function(){var c={};c.sentinel=a.readByte();switch(String.fromCharCode(c.sentinel)){case '!':c.type='ext';i(c);break;case ',':c.type='img';j(c);break;default:c.type='eof';b.eof&&b.eof(c);break;}if(c.type!=='eof')setTimeout(k,0);};var l=function(){h();setTimeout(k,0);};l();};})(_,Giphy);(function(a,b){b.GifRouter={gifPageOffset:1,xhr:null,setMoreGifs:function(b){if(!window.sessionStorage||a.isEmpty(b)||!a.isArray(b))return;var c=a.first(b,500);window.sessionStorage.setItem('giphy_history',JSON.stringify(c));},getMoreGifs:function(){var b=$.Deferred();var c=[];var d=(this.gifPageOffset>1)?'/page/'+this.gifPageOffset:'/';if(this.gifPageOffset<=1&&window.sessionStorage){var e=window.sessionStorage.getItem('giphy_history');var f=JSON.parse(e);if(a.size(f))c=f;}$.ajax({url:d+'?is=1',type:'GET',data:{json:true},success:function(d){var e=d.data;if(!e||!e.gifs){b.reject();return;}var f=a.shuffle(e.gifs);for(var g=0;g<f.length;g++){var h=f[g];c.push({id:h.id,url:h.url,preview:(h.images&&h.images.fixed_height_small)?h.images.fixed_height_small.url:''});}b.resolve(c);},error:function(){b.reject();}});this.gifPageOffset++;return b.promise();},navigateTo:function(a){if(!a)return;var c=$.Deferred();a=a.replace('http://giphy.com','');a=a.replace(/.*?:\/\//g,'//');if(this.xhr){this.xhr.abort();this.xhr=null;}this.xhr=$.ajax({type:'GET',url:a,success:$.proxy(function(d){var e=$('<div></div>').html(d);var f=e.find('#gif-detail');var g=e.find('title').text();var h={};if(!f.length){c.reject();return;}var i=f.find('#gif-wrap');if(i.length)h.gif=i.html();var j=f.find('#gif-actions-wrapper');if(j.length)h.actions=j.html();var k=f.find('#tags-wrapper');if(k.length)h.tags=k.html();var l=f.find('.gif-figure-wrapper meta');if(l.length){var m=$('<div></div>').append(l);h.metadata=m.html();}if(window.history&&a!==window.location.pathname){document.title=g;window.history.pushState(h,null,a);}c.resolve(h);if(b.Globals)b.Globals.refresh();this.xhr=null;},this),error:function(){c.reject();}});return c.promise();}};})(_,Giphy);(function(a,b){var c=function(a){this._configure(a||{});this.initialize.apply(this,arguments);};c.prototype={defaults:{},$:function(a){return this.$el.find(a);},_configure:function(b){this.viewId=a.uniqueId('view-');this.options=a.extend({},this.defaults,b);this.elements=this.elements||{};this.events=this.events||{};this.globalEvents=this.globalEvents||{};this.subviews=this.subviews||{};this.isRendered=false;this.el=this.el||this.options.el||document.createElement('div');this.$el=$(this.el).addClass(this.className);this.bindEvents();this.bindGlobalEvents();if(this.$el.length)this.cacheSelectors();},initialize:function(){},cacheSelectors:function(){if(a.isEmpty(this.elements))return;a.each(this.elements,function(a,b){this[b]=this.$el.find(a);},this);},render:function(){this.renderSubviews();this.cacheSelectors();this.renderComplete();this.isRendered=true;return this;},renderSubviews:function(){if(a.isEmpty(this.subviews))return;a.each(this.subviews,function(b){if(a.isFunction(b.render)&&!b.isRendered)b.render.call(b);});return this;},removeSubviews:function(b){if(a.isEmpty(this.subviews))return;a.each(this.subviews,function(b){if(a.isFunction(b.remove))b.remove.call(b);});if(b)this.subviews={};return this;},renderComplete:function(){return this;},bindEvents:function(b){if(!b&&a.isEmpty(this.events))return;b=b||this.events;this.unbindEvents();a.each(b,function(c,d){var e=b[d];if(!a.isFunction(e))e=this[c];if(!e)throw new Error('No handler for '+c);var f=d.split(' ');var g=f[0];var h=f.length>1?f[1]:false;e=a.bind(e,this);g+='.'+this.viewId;if(h)this.$el.on(g,h,e);else this.$el.on(g,e);},this);},unbindEvents:function(){this.$el.off('.'+this.viewId);},bindGlobalEvents:function(){if(a.isEmpty(this.globalEvents))return;this.unbindGlobalEvents();a.each(this.globalEvents,function(c,d){var e=d;var f=this.globalEvents[d];if(!a.isFunction(f))f=this[c];f=a.bind(f,this);e+='.'+this.viewId;b.Events.on(e,f);},this);},unbindGlobalEvents:function(){b.Events.off('.'+this.viewId);},remove:function(){this.unbindEvents();this.unbindGlobalEvents();this.removeSubviews(true);this.isRendered=false;return this;}};c.extend=function(b,c){var d=this;var e;if(b&&a.has(b,'constructor'))e=b.constructor;else e=function(){return d.apply(this,arguments);};a.extend(e,d,c);var f=function(){this.constructor=e;};f.prototype=d.prototype;e.prototype=new f();if(b)a.extend(e.prototype,b);return e;};b.BaseView=c;})(_,Giphy);(function(){var a=Giphy.Analytics={trackSearchResultsView:function(){$.ajax({type:"post",beforeSend:function(a){a.setRequestHeader("Authorization","ApiKey giphy-website:e0771ed7b244ec9c942bea646ad08e6bf514f51a");},url:"/api/v1/analytics/",data:JSON.stringify({"search_term_encoded":$('#search-term').attr("data-term"),"analytic_type":"view"}),dataType:"application/json",contentType:"application/json"});},fireEvents:function(a,b){_gaq.push(['_trackPageview',a]);if(!b)window.history.pushState("","",a);_qevents=[];__qc=undefined;$("#quantcast").remove();var c=$('<script async id="quantcast" src="//edge.quantserve.com/quant.js" type="text/javascript">');_qevents.push({qacct:"p-7A3Yj5VenXEQG"});$('body').append(c);}};})(window,Giphy);(function(a){var b=a.CreationApiHelper={apiBaseUrl:'//api.giphy.com/v1',gceBaseUrl:'//rxjthjm1pofte.com',apiKey:'ftOQZt7zJTlrG',postCreateVideo:function(a,b,c){a=a||{};var d=this.apiBaseUrl+'/create/video';a.api_key=this.apiKey;$.ajax({"url":d,"method":"post","beforeSend":function(a){a.setRequestHeader("");},"dataType":"json","data":a,"success":function(a){if(b)b(a);},"error":function(a){if(c)c(a);}});},postCreateSlideshow:function(a,b,c){var d=this.apiBaseUrl+'/create/slideshow';a.api_key=this.apiKey;$.ajax({"url":d,"method":"post","beforeSend":function(a){a.setRequestHeader("");},"dataType":"json","data":a,"success":function(a){if(b)b(a);},"error":function(a){if(c)c(a);}});},pollCreateStatus:function(a,b,c,d){var e=this.apiBaseUrl+'/create/status';var f=_.bind(function(){$.ajax({"url":e,"beforeSend":function(a){a.setRequestHeader("");},"dataType":"json","cache":false,"data":{"api_key":this.apiKey,"job_id":a},"success":function(a){var e=a.data.status;if(e==='STATUS_SUCCESSFUL'||e==='STATUS_FAILED'){if(d)d(a);}else{if(c)c(a);setTimeout(f,b);}}});},this);f();},getVideoInfo:function(a,b,c){$.ajax({type:'GET',dataType:"json",url:this.gceBaseUrl+'/info',data:{url:a},timeout:6000,success:function(a){if(b)b(a);},error:function(a){if(c)c(a);}});}};})(Giphy);(function(a,b){var c={__scroll:function(){if(this.scrollTimeout){clearTimeout(this.scrollTimeout);this.scrollTimeout=null;}this.scrollTimeout=setTimeout(a.bind(this._updateApps,this),300);},_updateApps:function(b){if(!this.$apps.length)return;var c=this.$win.scrollTop();var d=c+(this.$win.height()*0.5);var e=c+this.$win.height()-100;var f=[];this.$apps.each(function(){var a=$(this);var b=a.offset().top;var c=b+a.height();var e=b<d&&c>d;if(a.hasClass('snoozin')&&e)f.push(a.find('.app-screenshot'));a.toggleClass('snoozin',!e);});if(!b&&f.length)this._powerPoint(a.last(f));},_powerPoint:function(b){var c=$(b);if(!c.length)return;if(this.gloveTimeout){this.$powerglove.removeClass('boop');clearTimeout(this.gloveTimeout);}var d=Math.round(Math.random()*180);var e=c.offset();var f=(e.left>this.$win.width()*0.5)?-1:1;e.top-=this.$win.scrollTop();d*=f;this.$powerglove.css(a.extend(e,{'-webkit-transform':'rotate('+d+'deg) translate3d(0, 0, 0)','-moz-transform':'rotate('+d+'deg) translate3d(0, 0, 0)','-ms-transform':'rotate('+d+'deg) translate3d(0, 0, 0)','transform':'rotate('+d+'deg) translate3d(0, 0, 0)'}));this.$powerglove.addClass('boop');this.gloveTimeout=setTimeout(a.bind(function(){this.$powerglove.removeClass('boop');},this),220);},initialize:function(a){a=a||{};this.$win=$(window);this.$el=$(a.el||'.apps-page');this.$apps=$();this.$powerglove=$();this.scrollTimeout=null;this.gloveTimeout=null;this.render();return this;},render:function(){if(!this.$el.length)return;this.$apps=this.$el.find('.app');this.$powerglove=this.$el.find('.powerglove');if(this.$el.outerHeight(true)>this.$win.height()){this._updateApps(true);this.$win.on('scroll.apps-landing',a.throttle(a.bind(this.__scroll,this),100));}},remove:function(){if(!this.$el.length)return;this.$win.off('.apps-landing');}};b.AppsLanding=c;})(_,Giphy);(function(){var a=Giphy.Backgrounds={setRandomBackground:function(){if($("#animated-background-wrapper").length>0)$.ajax({type:"get",url:"/ajax/animated-backgrounds/",success:function(a){Giphy.Backgrounds.createBackgrounds(a);}});},createBackgrounds:function(a){var b=a.result;var c=b[Math.floor(Math.random()*b.length)];var d=$('<video></video>').attr({id:"animated-background",preload:"auto",autoplay:true,loop:"loop"}).css('opacity',0);var e=$('<source></source>').attr({src:c.webm_url,type:"video/webm"});var f=$('<source></source>').attr({src:c.mp4_url,type:"video/mp4"});d.append(f);d.append(e);$("#animated-background-wrapper").append(d);var g=$("#attribution");g.find('.byline').attr({"href":c.artist.profile_url});g.find('.avatar').css({"background-image":"url('"+c.artist.avatar_url+"')"});g.find('.username-text').text(c.artist.name);d.on('canplaythrough',function(){d.fadeTo("slow",0.6);g.css({opacity:1});});}};})(window,Giphy);(function(){var a=Giphy.Browsebar={init:function(){this.nextDisplayIndex=0;this.currGifIndex=-1;this.BrowsebarTimeout=undefined;this.CloseAnimationTimeout=undefined;this.DISPLAY_TIMEOUT_DELAY;this.CLOSE_TIMEOUT_DELAY=200;this.pastDisplayIndex=-1;},attachBrowsebarHovers:function(){var b=$("#browsebar a");var c=0;b.mouseenter(function(b){var c=$(this);$("#browsebar a").eq(a.pastDisplayIndex).removeClass("open");$(this).addClass("open");});b.mouseleave(function(a){var b=$(this);setTimeout(closeAnimation=function(){b.removeClass("open");},200);});}};})(window,Giphy);(function(){var a=Giphy.Etc={reAuthFacebook:function(){FB.login(function(a){if(a.status=='connected'){window.FACEBOOK_PERMISSION=true;window.FB_ACCESS_TOKEN=a.authResponse.accessToken;$.ajax({type:"POST",url:"/login/fb/update",data:{access_token:a.authResponse.accessToken},success:function(a,b,c){},error:function(a,b,c){}});}},{scope:'email,publish_actions'});},checkPermission:function(a){var b=function(){return setTimeout(function(){console.log("etc.js got called");FB.api("/me/permissions",{access_token:window.FB_ACCESS_TOKEN},function(b){for(var c=0;c<b.data.length;c++)if(b.data[c].permission=='publish_actions'&&b.data[c].status=='granted')window.FACEBOOK_PERMISSION=true;if(!window.FACEBOOK_PERMISSION)Giphy.Etc.reAuthFacebook();else a();});},1000);};if(typeof FB!="undefined")b();else window.fbAsyncInit=function(){return b();};},checkLogin:function(a){if(window.HAS_CHECKED_LOGIN)a.success();$.ajax({type:"GET",url:"/login/check/",dataType:"json",success:function(b){window.LOGGED_IN=b.result.logged_in;window.IS_PARTNER=b.result.is_partner;window.IS_ARTIST=b.result.is_artist;window.IS_STAFF=b.result.is_staff;window.HAS_CHECKED_LOGIN=true;window.FB_AUTH=b.result.fb_auth;window.FB_ID=b.result.fb_id;if(window.FB_AUTH)window.FB_ACCESS_TOKEN=b.result.fb_access_token;if(typeof b.result.user!==undefined)window.USER=b.result.user;for(var c=0;c<b.result.messages.length;c++){var d=b.result.messages[c];var e=d.tags;var f=d.text;var g=$("<div>");g.addClass("flash");g.addClass(e);g.text(f);$("#messages").append(g);setTimeout(function(){$('.flash').fadeOut('slow');},3000);}$(window).trigger("login:check");if(a!=undefined&&a.success!=undefined)a.success();},error:function(a,b,c){window.LOGGED_IN=false;window.IS_PARTNER=false;}});return this;}};})(window,Giphy);(function(a){var b={el:$({}),trigger:function(a){if(!a)return;var b=Math.max(0,arguments.length-1);var c=Array(b);for(var d=0;d<b;d++)c[d]=arguments[d+1];this.el.trigger(a,c);},on:function(a,b,c){if(!a||!b)return;c=c||this;this.el.on(a+'.giphy-events',$.proxy(b,c));},one:function(a,b,c){if(!a||!b)return;c=c||this;this.el.one(a+'.giphy-events',$.proxy(b,c));},off:function(a,b){if(!a)return;if(b)this.el.off(a+'.giphy-events',b);else this.el.off(a+'.giphy-events');}};a.Events=b;})(Giphy);(function(){var a=Giphy.Favorites={nav:function(){$("#favorites-nav").click(function(a){if(!window.LOGGED_IN){window.location="https://"+document.domain+"/login/?next=/favorites";return false;}});},permalink:function(){if($(".gif-detail").length>0){var a=$("#gif").attr("data-gif_id");$.ajax({type:"get",url:"/favorites/"+a+"/",success:function(a){$(".favorite").each(function(b){var c=$(this);if(a.result.has_favorited){c.addClass('favorited');c.addClass('_011_heart_red');c.removeClass('_012_heart_white');}else{c.removeClass('favorited');c.addClass('_012_heart_white');c.removeClass('_011_heart_red');}c.show();});}});$(".favorite").unbind('click').bind('click',function(a){if(!window.LOGGED_IN){_gaq.push(['_trackEvent','Favorites','ModalOpened']);_gaq.push(['_trackEvent','Favorites','HeartClick','LoggedOut']);window.location="https://"+document.domain+"/login/?next="+location.pathname+"&ref=fave";return false;}var b=$(this);_gaq.push(['_trackEvent','Favorites','HeartClick','LoggedIn',$(this).attr('data-gif_id')]);if(!b.hasClass('favorited'))$(".favorite").each(function(){$(this).addClass('favorited');$(this).addClass('_011_heart_red');$(this).removeClass('_012_heart_white');});else $(".favorite").each(function(){$(this).removeClass('favorited');$(this).addClass('_012_heart_white');$(this).removeClass('_011_heart_red');});$.ajax({type:"post",url:"/favorites/"+$(this).attr('data-gif_id')+"/",success:function(a){if(a.result.has_favorited)showSuccess("Added to favorites!");else showSuccess("Removed from favorites!");}});return false;});$(".favorite").mouseenter(function(a){var b=$(this);if(!b.hasClass('favorited')){b.addClass('_011_heart_red');b.removeClass('_012_heart_white');}else{b.removeClass('_011_heart_red');b.addClass('_012_heart_white');}});$(".favorite").mouseleave(function(a){var b=$(this);if(!b.hasClass('favorited')){b.removeClass('_011_heart_red');b.addClass('_012_heart_white');}else{b.addClass('_011_heart_red');b.removeClass('_012_heart_white');}});}}};})(window,Giphy);(function(){var a=Giphy.Facebook={search:function(a){$(".choice.active").removeClass("active");$("#searchresults").html('');$("#no-results").hide();$("#searchresults").show();$("#searchresults").addClass("loading");$.ajax({url:"/ajax/fb/tag/"+a,method:"GET",success:function(a){$("#searchresults").removeClass("loading");$("#searchresults").html(a);Giphy.SearchResults.attachInfiniteScroll();Giphy.Images.sizeImages("#searchresults");var b=$(".hoverable li, .row-tag, .featured-item, .featured-user");if(b.length==0){$("#no-results").show();$("#searchresults").hide();}else{$("#no-results").hide();$("#searchresults").show();$(".gifs-gif").each(function(){$(this).attr('src',$(this).data('animated'));});}}});},checkPermissions:function(a,b,c){var d=function(){console.log("fb.js got called");FB.api('/me/permissions',function(d){for(var e=0;e<d.data.length;e++)if(d.data[e].permission=='publish_actions'){window.ACCESS_TOKEN=a;if(b!==undefined)b();return false;}if(c===undefined)FB.login(function(a){if(a.status=='connected')Giphy.Facebook.checkPermissions(a.authResponse.accessToken,b,true);},{scope:'publish_actions, email'});});};if(typeof FB!="undefined")d();else window.fbAsyncInit=function(){return d();};},setup:function(){Giphy.Facebook.search("happy");$(".choice").first().addClass("active");$(document).bind("search:success",function(a,b){$("#searchresults").show();$("#no-results").hide();});$(document).bind('search:execute',function(a){$("#no-results").hide();});$(document).bind('search:dont_display',function(a){$(document).trigger("search:clear");});$(".no-result").on('click',function(){$("#search-box").val($(this).text());$("#placeholder").hide();Giphy.Facebook.search($(this).text());return false;});$(document).bind('images:done_sizing',function(a,b){$("a.gif-link").off('click').on('click',function(){var a=$(this).data('id');if(!window.ACCESS_TOKEN)FB.getLoginStatus(function(b){if(b.status=='connected')Giphy.Facebook.checkPermissions(b.authResponse.accessToken,function(){Giphy.Facebook.showModal(a);});else FB.login(function(b){if(b.status=='connected')Giphy.Facebook.checkPermissions(b.authResponse.accessToken,function(){Giphy.Facebook.showModal(a);});else{}},{scope:'publish_actions, email'});});else Giphy.Facebook.showModal(a);return false;});$(".tags").hide();});$('.choice').on('click',function(){$("#search-box").val($(this).data("tag-encoded"));$("#placeholder").hide();Giphy.Facebook.search($(this).data("tag-encoded"));$(this).addClass('active');return false;});},showModal:function(a){$("#fb_status").val('');$("#fb_details").show();$("#fb_response").hide();$("#fb_submit").show();$("#fb_submitting").hide();$("#fb_status").focus();$("#fb_post").off('click').on('click',function(){$("#fb_submit").hide();$("#fb_submitting").show();$.ajax({url:"/ajax/fb/upload/",method:"POST",data:{"gif_id":a,"status":$("#fb_status").val(),"token":window.ACCESS_TOKEN},success:function(a){$("#fb_submit").hide();$("#fb_submitting").hide();$("#fb_details").hide();$("#fb_response").show();},error:function(){$("#fb_submit").hide();$("#fb_submitting").hide();$("#fb_response").show();$("#fb_response_text").text("Oh no! Something went wrong. Please try posting your status update again.");}});});$("#fb_ok").off('click').on('click',function(){$.modal.close();});$("#fb_cancel").off('click').on('click',function(){$.modal.close();});$("#gif_id").val(a);$("#gif_preview").attr("src","");$("#gif_preview").attr("src","https://media.giphy.com/media/"+a+"/giphy.gif");$("#fb_modal").modal({overlay:"#000",opacity:0.8,modalClass:"lolwhatever",showClose:false,showSpinner:false,zIndex:101});}};})(window,Giphy);(function(a,b){var c={__mousemove:a.throttle(function(a){if(!this.$gif.length)return;this.$gif.css({left:a.pageX,top:a.pageY-this.$win.scrollTop()});this.$gif.toggleClass('right',a.pageX>this.previousPosition.x);this.$gif.toggleClass('left',a.pageX<=this.previousPosition.x);this.previousPosition={x:a.pageX,y:a.pageY};},50),_parseDateString:function(a){var b=new Date();if(!a)return b;var c=a.split('/');if(c.length){b.setMonth(parseInt(c[0],10)-1);if(c.length>1)b=b.setDate(parseInt(c[1],10));}return b;},_checkDateRange:function(){if(!this.dates)return true;var a=this.dates.split('-');if(!a.length)return true;var b=this._parseDateString(a[0].trim());if(a.length>1)endDate=this._parseDateString(a[1].trim());var c=new Date();if(endDate)return c>=b&&c<endDate;else return c>=b;},initialize:function(b){b=b||{};this.$win=$(window);this.$doc=$(document);this.$body=$('body');this.$gif=$();this.backgroundUrl=a.isArray(b.background)?a.sample(b.background):b.background||'';this.cursorUrl=a.isArray(b.cursor)?a.sample(b.cursor):b.cursor||'';this.previousPosition={x:999999999,y:999999999};this.isFlipped=b.flipped||false;this.dates=b.dates||'';this.render();return this;},render:function(){if(!this._checkDateRange())return;if(this.backgroundUrl)this.$body.css('background-image','url('+this.backgroundUrl+')');if(this.cursorUrl)this.renderCursor();},renderCursor:function(){var b=this.template({gif:this.cursorUrl});this.$body.append(b);this.$gif=this.$body.find('.gif-cursor').toggleClass('flipped',this.isFlipped);this.$doc.on('mousemove.gif-cursor',a.bind(this.__mousemove,this));},remove:function(){this.$doc.off('.gif-cursor');},template:a.template('<div class="gif-cursor" style="background-image:url(<%- gif %>)"></div>')};b.FestiveMode=c;})(_,Giphy);(function(a,b){var c={__facebookSDKReady:function(a,b){this.isFBReady=true;this.facebookId=b;},__socialLinkClick:function(b){var c=$(b.currentTarget);var d=c.closest('.social-link');var e=d.data();this._sendAnalytics(e.type);if(this.isFBReady&&e.type==='facebook'){b.preventDefault();this._facebookShareDialog();return;}if(e.popup){b.preventDefault();a.Utils.openPopup(c.attr('href'),e.popupWidth||this.popupWidth,e.popupHeight||this.popupHeight);}},__showMoreSocialLinksClick:function(a){a.preventDefault();$(a.currentTarget).remove();this.$socialLinks.removeClass('truncated');},__showMoreActionsClick:function(a){a.preventDefault();this.$moreOptions.toggleClass('hide');var b=this.$moreOptions.hasClass('hide');$(a.currentTarget).text(b?'More options':'Fewer options');if(b)this.$moreOptions.find('.copy-paste .checkmark').remove();},__navButtonClick:function(a){a.preventDefault();var b=$(a.currentTarget);this._toggleAdvancedOptions(b.attr('href')==='#gif-advanced-actions');},__autoplayToggle:function(a,b){var c=this.$jsEmbedInput.val();if(b){delete this.iframeParams.playOnHover;delete this.html5Params.playOnHover;c=c.replace("var _giphy_play_on_hover = true;","");}else{this.iframeParams.playOnHover=true;this.html5Params.playOnHover=true;c=c.replace("var _giphy","var _giphy_play_on_hover = true; var _giphy");}this.$jsEmbedInput.val(c);this._updateEmbedCode();},__socialToggle:function(a,b){if(b){delete this.iframeParams.hideSocial;delete this.html5Params.hideSocial;}else{this.iframeParams.hideSocial=true;this.html5Params.hideSocial=true;}this._updateEmbedCode();},_updateEmbedCode:function(){var a=this.$iframeEmbedInput.val();var b=this.$html5EmbedInput.val();var c=$(a);var d=c.attr('src').split('?')[0];c.attr('src',d+this._objectToQueryString(this.iframeParams));var e=$(b);var f=e.attr('src').split('?')[0];e.attr('src',f+this._objectToQueryString(this.html5Params));this.$iframeEmbedInput.val(c.prop('outerHTML').replace(/&amp;/g,'&'));this.$html5EmbedInput.val(e.prop('outerHTML').replace(/&amp;/g,'&'));},_objectToQueryString:function(a){var b=[];for(var c in a)if(a.hasOwnProperty(c))b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return(b.length)?'?'+b.join('&'):'';},_sendAnalytics:function(a){a=a||'';$.ajax({type:'POST',url:"/ajax/gif/"+this.gifId+"/analytic/"+a,success:function(a){return a;},error:function(){return null;}});},_facebookShareDialog:function(a){if(!window.FB)return;window.FB.ui({app_id:this.facebookId,href:this.shareUrl,method:'share'},function(){});},_truncateSocialLinks:function(){if(!this.truncateSocialLinks||!this.$socialLinks.length)return;var a=this.$socialLinks.find('.social-link');var b=3;if(a.length>b){var c=$('<li class="show-more"><i class="ss-icon ss-ellipsis"></i></li>');a.filter(':gt('+(b-1)+')').addClass('hide');this.$socialLinks.addClass('truncated').append(c);}},_toggleAdvancedOptions:function(a){a=a||false;this.$navButtons.removeClass('active');if(a){this.$navButtons.filter('[href="#gif-advanced-actions"]').addClass('active');this.$shareActions.hide();this.$advandedActions.show();}else{this.$navButtons.filter('[href="#gif-share-actions"]').addClass('active');this.$shareActions.show();this.$advandedActions.hide();}},_truncateEmbedOptions:function(){if(!this.$moreOptions.length)return;var a=$('<a class="show-more-actions" href="#">More options</a>');this.$moreOptions.addClass('hide').before(a);},_initializeTwitterUpload:function(){if(a.Utils.getParameterByName("twit_auth")){this._toggleAdvancedOptions(true);$('html, body').animate({scrollTop:this.$advandedActions.offset().top},100);}this.subviews.uploadTwitter=a.UploadToTwitter.initialize({el:this.$el.find('#upload-to-twitter'),gifId:this.gifId});},initialize:function(b){b=b||{};this.options=b;this.shareUrl='';this.permalinkUrl='';this.gifId='';this.popupWidth=b.popupWidth||540;this.popupHeight=b.popupHeight||600;this.scrollbarWidth=a.Utils.getScrollbarWidth()||0;this.truncateSocialLinks=b.truncateSocialLinks||false;this.uploadToTwitter=null;this.gifShortener=null;this.subviews={};this.iframeParams={};this.html5Params={html5:true};this.isFBReady=false;this.facebookId=null;this.$el=$(b.el||'.gif-actions');a.Events.on('gifdetail:fbinit',_.bind(this.__facebookSDKReady,this));this.render();return this;},cacheSelectors:function(){if(!this.$el.length)return;this.$socialLinks=this.$el.find('.gif-social-links');this.$moreOptions=this.$el.find('.more-actions');this.$copyInputs=this.$el.find('input[data-copy="true"]');this.$autoplayToggle=this.$el.find('.autoplay-toggle');this.$socialToggle=this.$el.find('.social-toggle');this.$iframeEmbedInput=this.$el.find('#iframe-embed-code');this.$html5EmbedInput=this.$el.find('#smart-embed-code');this.$jsEmbedInput=this.$el.find('#optimized-embed-code');this.$navButtons=this.$el.find('.gif-actions-nav .nav-button');this.$shareActions=this.$el.find('#gif-share-actions');this.$advandedActions=this.$el.find('#gif-advanced-actions');},render:function(){if(!this.$el.length)return;this.cacheSelectors();var b=this.$el.data();this.shareUrl=this.options.shareUrl||b.shareUrl;this.permalinkUrl=this.options.permalinkUrl||b.permalinkUrl;this.gifId=this.options.gifId||b.gifId;this.$el.removeClass('no-animate');this._toggleAdvancedOptions(false);if(this.truncateSocialLinks)this._truncateSocialLinks();this._truncateEmbedOptions();this.subviews.instagramModal=a.InstagramModal.initialize({gifId:this.gifId});this.subviews.gifShortener=a.GifShortener.initialize({el:this.$el.find('#gif-shortener'),gifId:this.gifId});this._initializeTwitterUpload();this.$el.on('click.gif-sharing','.social-link a',$.proxy(this.__socialLinkClick,this));this.$el.on('click.gif-sharing','.show-more',$.proxy(this.__showMoreSocialLinksClick,this));this.$el.on('click.gif-sharing','.show-more-actions',$.proxy(this.__showMoreActionsClick,this));this.$el.on('click.gif-sharing','.gif-actions-nav .nav-button',$.proxy(this.__navButtonClick,this));if(this.$autoplayToggle.length)this.$autoplayToggle.on('toggle.gif-sharing',$.proxy(this.__autoplayToggle,this));if(this.$socialToggle.length)this.$socialToggle.on('toggle.gif-sharing',$.proxy(this.__socialToggle,this));},remove:function(){this.$el.off('.gif-sharing');if(this.$autoplayToggle&&this.$autoplayToggle.length)this.$autoplayToggle.off('.gif-sharing');if(this.$socialToggle&&this.$socialToggle.length)this.$socialToggle.off('.gif-sharing');for(var a in this.subviews){var b=this.subviews[a];b.remove();}}};var d={__keyup:function(a){var b=this.$input.val()||'';if(a.which===13&&b.trim().length>0)this.shortenUrl(b);},__focus:function(){this.$input.select();},__input:function(){var a=this.$input.val()||'';this.$button.toggleClass('disabled',a.trim().length<1);this._reset();},__copy:function(){if(!this.isShortened)return;window.showSuccess('Copied to clipboard!');},__click:function(a){a.preventDefault();var b=$(a.currentTarget);if(b.hasClass('disabled')||b.hasClass('saving'))return;this.shortenUrl(this.$input.val());},__success:function(a){if(!a||!a.result||a.result.code!==200){this.__error();return;}this.$input.val(a.result.short_url);this.$input.focus().select();this.isShortened=true;this.$el.addClass('saved');this.$button.removeClass('saving').addClass('saved').text(this.savedLabel);},__error:function(){this.$button.removeClass('saving').addClass('error').text(this.errorLabel);window.showError('An error has occurred.');},_reset:function(){this.isShortened=false;this.$el.removeClass('saved');this.$button.removeClass('saving saved error').text(this.label);},initialize:function(a){a=a||{};this.gifId=a.gifId||$('#gif').data('gif_id');this.savingLabel=a.savingLabel||'Shortening';this.savedLabel=a.savedLabel||'Booyah!';this.errorLabel=a.errorLabel||'Oops...';this.label='';this.isShortened=false;this.$el=$(a.el||'#gif-shortener');this.$input=$();this.$button=$();this.render();return this;},render:function(){if(!this.$el.length)return;this.$input=this.$el.find('.gif-shortener-input');this.$button=this.$el.find('.gif-shortener-button');this.label=this.$button.text();this.$el.on('keyup.gif-shortener','.gif-shortener-input',$.proxy(this.__keyup,this));this.$el.on('click.gif-shortener','.gif-shortener-input',$.proxy(this.__focus,this));this.$el.on('copy.gif-shortener','.gif-shortener-input',$.proxy(this.__copy,this));this.$el.on('input.gif-shortener','.gif-shortener-input',$.proxy(this.__input,this));this.$el.on('click.gif-shortener','.gif-shortener-button',$.proxy(this.__click,this));},remove:function(){if(!this.$el.length)return;this._reset();this.$el.off('.gif-shortener').remove();},shortenUrl:function(a){a=a||'';if(!a.trim().length)return;this.$button.addClass('saving').text(this.savingLabel);$.ajax({type:'POST',url:'//'+window.ASSET_DOMAIN+'/ajax/shorturl/create/',data:{gif_id:this.gifId,redirect_to:a},success:$.proxy(this.__success,this),error:$.proxy(this.__error,this)});}};var e={__input:function(){this._reset();this.updateTweet();},__blur:function(){var a=this.$input.val();var b=this.$input.data();if(b.originalValue&&!a.length){this.$text.html('<i>'+b.originalValue+'</i>&nbsp;');this.updateTweet();}},__keydown:function(a){if(a.which===13){a.preventDefault();a.stopPropagation();this.tweet();return false;}},__click:function(a){a.preventDefault();var b=$(a.currentTarget);if(b.hasClass('disabled')||b.hasClass('too-long')||b.hasClass('saving'))return;this.tweet();},__logoutClick:function(a){a.preventDefault();$.removeCookie('giphy-twitter-upload');window.location=a.currentTarget.href;},_reset:function(){this.$button.removeClass('saved saving').text(this.buttonLabel);this.$text.removeClass('readonly');},_setInputHeight:function(){if(!this.$preview.length)return;var a=this.$preview.attr('src');var b=new Image();var c=this.$preview.width();b.onload=$.proxy(function(){var a=c/b.width;this.$text.height(Math.round(b.height*a)-20);},this);b.src=a;},initialize:function(a){a=a||{};this.gifId=a.gifId||$('#gif').data('gif_id');this.maxCharacters=a.maxCharacters||117;this.cookie=$.cookie("giphy-twitter-upload");this.tweetingLabel=a.tweetingLabel||"Tweetin'";this.successLabel=a.successLabel||'Tweeted!';this.buttonLabel='';this.linkText='';this.$el=$(a.el||'#upload-to-twitter');this.$count=$();this.$button=$();this.$preview=$();this.render();return this;},render:function(){if(!this.$el.length)return;this.$count=this.$el.find('.tweet-count');this.$button=this.$el.find('.tweet-button');this.$input=this.$el.find('.tweet-input');this.$text=this.$el.find('.tweet-text');this.$loginButtons=this.$el.find('.login-buttons');this.$preview=this.$el.find('.image-preview');this.buttonLabel=this.$button.text();this.linkText=this.$input.val();this._setInputHeight();this.$el.on('click.upload-twitter','.tweet-button',$.proxy(this.__click,this));this.$el.on('input.upload-twitter','.tweet-text',$.proxy(this.__input,this));this.$el.on('keydown.upload-twitter','.tweet-text',$.proxy(this.__keydown,this));this.$el.on('blur.upload-twitter','.tweet-text',$.proxy(this.__blur,this));this.$el.on('click.upload-twitter','.logout',$.proxy(this.__logoutClick,this));this.updateTweet();this.updateLoginStatus();},remove:function(){this.$el.off('.upload-twitter');},tweet:function(){var a=this.$input.val();if(!a||a.length>this.maxCharacters)return;this.$button.addClass('saving').text(this.tweetingLabel);this.$text.addClass('readonly');$.ajax({type:'POST',url:'/ajax/twitter_upload',data:{gif_id:this.gifId,status:a},success:$.proxy(function(a){if(!a.result||!a.result.response||!a.result.response.meta){this._reset();return;}var b=a.result.response.meta;if(b.status&&b.status===200){this.$button.removeClass('saving').addClass('saved').text(this.successLabel);this.$text.removeClass('readonly');window.showSuccess('Your tweet has been sent.');}else if(b.msg){this._reset();window.showError('ERROR: '+b.msg);}if(b.status&&b.status===400){this.cookie=null;this._reset();this.updateLoginStatus();}},this),error:$.proxy(function(){this._reset();window.showError('An error has occurred. Please try again later.');},this)});},updateTweet:function(){var a=this.$text.text().replace('&nbsp;',' ');var c=[];var d=this.maxCharacters;this.$input.val(a);if(b)c=b.txt.extractUrls(a);for(var e=0;e<c.length;e++){a=a.replace(c[e],'');if(c[e].toLowerCase().substring(0,5)=='http:')d-=22;else d-=23;}d-=a.length;this.$count.text('('+d+')').toggleClass('too-long',d<0);this.$button.toggleClass('too-long',d<0);},updateLoginStatus:function(){if(this.cookie){this.$el.addClass('logged-in');this.$button.removeClass('disabled');this.$text.removeClass('readonly');}else{this.$el.removeClass('logged-in');this.$button.addClass('disabled');this.$text.addClass('readonly');}}};var f={__keydown:function(a){if(a.which===13){a.preventDefault();this.submitEmail();}},__click:function(a){a.preventDefault();this.submitEmail();},initialize:function(a){a=a||{};this.gifId=a.gifId||$('#gif').data('gif_id');this.url=a.url||'/ajax/instashare/';this.savingButtonText=a.savingButtonText||'Sending';this.successButtonText=a.successButtonText||'Sent!';this.successText=a.successText||'Success! Check your email in about 5 minutes. We sent you a GIF you can upload to Instagram.';this.errorText=a.errorText||'UH OH! Something went wrong. Try again?';this.$body=$('body');this.render();return this;},render:function(){this.$body.on('keydown.instagram-modal','.rad-modal .instagram-input',$.proxy(this.__keydown,this));this.$body.on('click.instagram-modal','.rad-modal .instagram-send-button',$.proxy(this.__click,this));},remove:function(){this.$body.off('.instagram-modal');},submitEmail:function(){var b=this.$body.find('.rad-modal .instagram-input');var c=this.$body.find('.rad-modal .instagram-send-button');var d=c.text();var e=b.val();if(!e||e.indexOf('@')<0)return;c.addClass('saving').text(this.savingButtonText);$.ajax({type:'POST',url:this.url,data:{'gif_id':this.gifId,'to':e},success:$.proxy(function(b){if(b.result&&b.result.code===200){window.showSuccess('Success! Check your email in about 5 minutes. We sent you a GIF you can upload to Instagram.');c.removeClass('saving').addClass('saved').text(this.successButtonText);a.Events.trigger('radmodal:close');}else{window.showError(this.errorText);c.removeClass('saving').text(d);}},this),error:$.proxy(function(){window.showError(this.errorText);c.removeClass('saving').text(d);},this)});}};a.GifActions=c;a.GifShortener=d;a.UploadToTwitter=e;a.InstagramModal=f;})(Giphy,twttr||{});(function(a){var b={__checkboxChange:function(a){var b=$(a.currentTarget);this.model.save(b.attr('name'),b.is(':checked'));},__radioButtonChange:function(a,b,c){var d=$(b);if(d.data('name')!=='rating')return;this.model.save('rating',c);},__privacyToggle:function(a,b){var c=$(a.currentTarget);b?this.$privateGifIndicator.hide():this.$privateGifIndicator.show();this.model.save(c.data('name'),!b);},__editToggle:function(a,b){this.toggleEditMode(!b);},__confirmDeleteClick:function(b){b.preventDefault();var c=$(b.currentTarget).prop('disabled',true);var d=window.USER.channel;this.model.save('delete-gif',true).fail(function(){c.prop('disabled',false);}).done(function(b){a.Events.trigger('radmodal:close');c.prop('disabled',false);if(b.result)window.location=d+'?message=gifdeleted&status=200';else window.showError('Unable to delete GIF. '+b.result.message);});},__saveMetadata:function(a){if(!a)return;var b=$(a);var c=b.find('.metadata-field');var d=b.find('.metadata-label .value');var e=c.find('input:text');if(e.length)this.model.save(e.attr('name'),e.val().trim()).done(function(){var a=e.val().trim();e.data('original-value',a);d.text(a);c.removeClass('open');});},initialize:function(b){b=b||{};this.$win=$(window);this.$body=$('body');this.$el=$(b.el||'#gif-info-container');this.model=a.GifEditModel;this.gifId=b.gifId||$('#gif').data('gif_id');this.editUrl=b.editUrl||$('#gif').data('editUrl');this.absoluteUrl=b.absoluteUrl||$('#gif').data('absoluteUrl');this.subviews={};this.originalHtml='';this.model.initialize({gifId:this.gifId}).fetch().done($.proxy(this.render,this));return this;},cacheSelectors:function(){this.$infoWrapper=this.$el.find('.gif-info-wrapper');this.$editWrapper=this.$el.find('.gif-edit-wrapper');this.$editToggle=this.$el.find('.edit-gif-toggle');this.$privateGifIndicator=this.$el.find('#private-gif-indicator');},render:function(b){if(!b||!this.$el.length)return;this.originalHtml=this.$el.html();this.$el.html(b);this.cacheSelectors();a.Globals.refresh();this.subviews.editTags=a.GifEditTags.initialize({gifId:this.gifId,el:this.$el.find('#tags')});this.subviews.editMetadata=a.GifEditMetadata.initialize({onSave:$.proxy(this.__saveMetadata,this)});this.$el.on('toggle.gif-edit','.edit-gif-toggle',$.proxy(this.__editToggle,this));this.$el.on('change.gif-edit','.checkbox input:checkbox',$.proxy(this.__checkboxChange,this));this.$el.on('toggle.gif-edit','.privacy-toggle',$.proxy(this.__privacyToggle,this));this.$body.on('click.gif-edit','.rad-modal .delete-button',$.proxy(this.__confirmDeleteClick,this));a.Events.on('radiobutton:change',$.proxy(this.__radioButtonChange,this));if(window.location.pathname===this.editUrl)this.toggleEditMode(true);},remove:function(){this.$el.off('.gif-edit');this.$body.off('.gif-edit');for(key in this.subviews){var b=this.subviews[key];b.remove();}this.$el.html(this.originalHtml);a.Events.off('radiobutton:change');},toggleEditMode:function(b){b=b||false;b?this.$infoWrapper.hide():this.$infoWrapper.show();b?this.$editWrapper.show():this.$editWrapper.hide();this.$editToggle.toggleClass('active',!b);if(window.history){var c=(b&&this.editUrl)?this.editUrl:this.absoluteUrl;window.history.replaceState(window.history.state,document.title,c);}if(b)setTimeout($.proxy(function(){$('html, body').animate({scrollTop:this.$editWrapper.offset().top},200);},this),100);else setTimeout(function(){a.Events.trigger('gifedit:toggle');},400);}};var c={__editClick:function(a){a.preventDefault();var b=$(a.currentTarget);var c=b.closest('.metadata-section').find('.metadata-field');var d=c.hasClass('open');this.$fields.removeClass('open');this.$win.off('.gif-metadata');if(!d&&c.length){c.addClass('open');c.find('input:text').select();this.$win.on('keydown.gif-metadata',$.proxy(this.__windowKeydown,this));}else b.val(b.data('original-value'));},__clearClick:function(a){a.preventDefault();var b=$(a.currentTarget);var c=b.closest('.metadata-field').find('input:text');if(c.length)c.val('').focus();},__saveClick:function(a){a.preventDefault();var b=$(a.currentTarget);this.save(b.closest('.metadata-section'));},__inputKeydown:function(a){if(a.which===13){var b=$(a.currentTarget);this.save(b.closest('.metadata-section'));}},__windowKeydown:function(a){if(a.which===27){this.$fields.removeClass('open');this.$inputs.each(function(){$(this).val($(this).data('original-value'));});}},initialize:function(a){a=a||{};this.$win=$(window);this.$el=$(a.el||'.metadata');this.$sections=$();this.$field=$();this.$inputs=$();this.onSave=a.onSave||$.noop;this.render();return this;},render:function(){if(!this.$el.length)return;this.$sections=this.$el.find('.metadata-section');this.$fields=this.$el.find('.metadata-field');this.$inputs=this.$el.find('.metadata-field input:text');this.$inputs.each(function(){var a=$(this);a.data('original-value',a.val());});this.$el.on('click.gif-metadata','.edit-icon',$.proxy(this.__editClick,this));this.$el.on('click.gif-metadata','.clear-button',$.proxy(this.__clearClick,this));this.$el.on('click.gif-metadata','.save-button',$.proxy(this.__saveClick,this));this.$el.on('keydown.gif-metadata','.metadata-field input:text',$.proxy(this.__inputKeydown,this));},save:function(a){this.onSave.call(this,a);},remove:function(){this.$el.off('.gif-metadata');}};var d={initialize:function(a){a=a||{};this.gifId=a.gifId;return this;},fetch:function(){var a=$.Deferred();if(String(this.gifId).length)$.ajax({url:'/ajax/gif/'+this.gifId+'/detail',type:'GET',success:function(b){a.resolve(b);},error:function(){a.reject();}});else a.reject();return a.promise();},save:function(a,b){var c=$.Deferred();if(String(this.gifId).length)$.ajax({type:'POST',url:'/ajax/gif/update',data:{key:a,value:b,gif_id:this.gifId},success:function(a){if(a.result&&a.result.code!==200){window.showError(a.result.message||'Uh-oh. Something went wrong. Please try again.');c.reject();}else{window.showSuccess('GIF updated!');c.resolve(a);}return a;},error:function(){window.showError('Uh-oh. Something went wrong. Please try again.');c.reject();}});else c.reject();return c.promise();}};var e={__deleteClick:function(a){a.preventDefault();var b=$(a.currentTarget);var c=b.closest('.tag');c.addClass('deleted');setTimeout($.proxy(function(){this.submitTag(c.data('tag'),true);c.remove();},this),300);},__addClick:function(a){a.preventDefault();this.submitTag(this.$input.val());},__input:function(){this.$addButton.toggleClass('disabled',this.$input.val().trim().length<1);},__keydown:function(a){if(a.which===13)this.submitTag(this.$input.val());},__success:function(a,b){if(!b||!b.result||b.result.code!==200){this.__error();return;}this._reset();if(!a){var c=b.result.data;this._addNewTag(c.name,c.name_encoded);this.$input.select();window.showSuccess('Tag added!');}else window.showSuccess('Tag deleted!');},__error:function(){this._reset();window.showError('Uh oh. Something went wrong. Please try again.');},_reset:function(){this.$addButton.addClass('disabled');this.$input.val('');},_addNewTag:function(a,b){var c=this.template.replace(/TAGNAME/g,a).replace(/TAGURL/g,b);var d=$(c);this.$el.append(d);setTimeout(function(){d.removeClass('new-tag');},500);},initialize:function(a){a=a||{};this.url=a.url||'/ajax/gif/update';this.gifId=a.gifId||$('#gif').data('gif_id');this.template=$(a.template||'#new-tag-template').html();this.$el=$(a.el||'#tags');this.render();return this;},render:function(){this.$input=this.$el.find('.add-tag-input');this.$addButton=this.$el.find('.add-tag-button');this._reset();this.$el.on('input.edit-tags','.add-tag-input',$.proxy(this.__input,this));this.$el.on('keydown.edit-tags','.add-tag-input',$.proxy(this.__keydown,this));this.$el.on('click.edit-tags','.add-tag-button',$.proxy(this.__addClick,this));this.$el.on('click.edit-tags','.delete-tag-button',$.proxy(this.__deleteClick,this));},submitTag:function(a,b){if(!a||!a.trim().length)return;b=b||false;if(!b)a=a.replace('#','');$.ajax({type:'POST',url:this.url,data:{'gif_id':this.gifId,'key':b?'delete-tag':'create-tag','value':a},success:$.proxy(this.__success,this,b),error:$.proxy(this.__error,this)});},remove:function(){this._reset();this.$el.off('.edit-tags');}};a.GifEdit=b;a.GifEditModel=d;a.GifEditMetadata=c;a.GifEditTags=e;})(Giphy);(function(a){var b={_checkIfIE:function(){var a=false;var b=window.navigator.userAgent;var c=b.indexOf('MSIE ');var d=b.indexOf('Trident/');if((c>-1)||(d>-1))return true;return false;},initialize:function(){this.subviews={};this.$body=$('body');this.subviews.copyInputs=a.CopyInputs.initialize();this.subviews.toggleInputs=a.ToggleInputs.initialize();this.subviews.checkboxInputs=a.CheckboxInputs.initialize();this.subviews.radioButtons=a.RadioButtons.initialize();this.subviews.tooltips=a.Tooltips.initialize();this.subviews.ui=a.GiphyUI.initialize();this.subviews.radModal=a.RadModal.initialize();if(this._checkIfIE())this.$body.addClass('is-ie');},refresh:function(){for(key in this.subviews){var a=this.subviews[key];a.remove();a.initialize();}}};var c={__click:function(a){var b=$(a.currentTarget);b.select();},__copy:function(a){window.showSuccess('Copied to clipboard!');},initialize:function(a){a=a||{};this.$inputs=$('input[data-copy="true"]');this.render();return this;},render:function(){if(!this.$inputs.length)return;this.$inputs.on('click.copy-input',$.proxy(this.__click,this));this.$inputs.on('copy.copy-input',$.proxy(this.__copy,this));},remove:function(){if(!this.$inputs.length)return;this.$inputs.off('.copy-input');}};var d={__click:function(b){b.preventDefault();var c=$(b.currentTarget);var d=c.data();var e=false;if(d.isAnimating)return;c.toggleClass('active');e=c.hasClass('active');c.data('is-animating',true);setTimeout(function(){c.data('is-animating',false);},this.animationDelay);c.trigger('toggle',e);a.Events.trigger('toggleinput:toggle',c,e);},initialize:function(a){a=a||{};this.$toggles=$('.settings-toggle');this.animationDelay=a.animationDelay||500;this.render();return this;},render:function(){if(!this.$toggles.length)return;this.$toggles.on('click.toggle-input',$.proxy(this.__click,this));},remove:function(){if(!this.$toggles.length)return;this.$toggles.off('.toggle-input');}};var e={__click:function(a){a.preventDefault();var b=$(a.currentTarget);var c=b.closest('.checkbox');var d=c.find('input:checkbox');c.toggleClass('checked');if(d.length)d.prop('checked',c.hasClass('checked')).trigger('change');},initialize:function(a){a=a||{};this.$checkboxes=$('.checkbox');this.render();return this;},render:function(){if(!this.$checkboxes.length)return;this.$checkboxes.each(function(){var a=$(this);var b=a.find('input:checkbox');if(b.length)a.toggleClass('checked',b.prop('checked'));});this.$checkboxes.on('click.checkbox-input','.checkbox-icon',$.proxy(this.__click,this));},remove:function(){if(!this.$checkboxes.length)return;this.$checkboxes.off('.checkbox-input');}};var f={__click:function(b){b.preventDefault();var c=$(b.currentTarget);var d=c.closest('.radio-options');var e=c.data('value');d.find('.selected').removeClass('selected');c.addClass('selected');d.trigger('change',e);a.Events.trigger('radiobutton:change',d,e);},initialize:function(a){a=a||{};this.$radioButtons=$('.radio-options');this.render();return this;},render:function(){if(!this.$radioButtons.length)return;this.$radioButtons.on('click.radio-buttons','.radio-option',$.proxy(this.__click,this));},remove:function(){if(!this.$radioButtons.length)return;this.$radioButtons.off('.radio-buttons');}};var g={__mouseover:function(a){var b=$(a.currentTarget);var c=b.outerWidth();var d=b.outerHeight();var e=b.offset();this.$tooltip.text(b.data('tooltip')).css({left:e.left+(c*0.5),top:e.top+d-this.$win.scrollTop()}).appendTo(this.$body);},__mouseout:function(){this.$tooltip.remove();},initialize:function(a){a=a||{};this.$win=$(window);this.$body=$('body');this.$elements=$('*[data-tooltip]');this.$tooltip=$('<div class="giphy-tooltip"></div>');this.render();return this;},render:function(){if(!this.$elements.length)return;this.$elements.on('mouseover.tooltip',$.proxy(this.__mouseover,this));this.$elements.on('mouseout.tooltip',$.proxy(this.__mouseout,this));},remove:function(){if(!this.$elements.length)return;this.$elements.off('.tooltip');}};var h={__keydown:function(a){if(a.which===27)this._reset();},__triggerClick:function(a){a.preventDefault();var b=$(a.currentTarget).data();if(b.content){var c=$(b.content);this.open({title:b.title,description:b.description,content:c.html()});}},__cancelClick:function(a){a.preventDefault();this._reset();},_reset:function(){this.$modal.remove();this.$dim.remove();this.$title.html('');this.$description.html('');this.$content.html('');this.$body.removeClass('no-scroll');this.$win.off('.rad-modal');},initialize:function(){this.$win=$(window);this.$body=$('body');this.$modal=$('<div class="rad-modal"></div>');this.$dim=$('<div class="rad-modal-dim"></div>');this.render();return this;},render:function(){this.$hand=$('<div class="rad-modal-hand"><div class="hand-inner"></div></div>').appendTo(this.$modal);this.$title=$('<span class="title"></span>').appendTo(this.$modal);this.$description=$('<span class="description"></span>').appendTo(this.$modal);this.$content=$('<div class="content"></div>').appendTo(this.$modal);this.$body.on('click.rad-modal','.rad-modal-trigger',$.proxy(this.__triggerClick,this));this.$body.on('click.rad-modal','.rad-modal-dim',$.proxy(this._reset,this));this.$body.on('click.rad-modal','.rad-modal .cancel-button',$.proxy(this.__cancelClick,this));a.Events.on('radmodal:close',$.proxy(this._reset,this));},open:function(a){a=a||{};this._reset();if(a.title)this.$title.text(a.title);if(a.description)this.$description.text(a.description);if(a.content)this.$content.html(a.content);this.$body.addClass('no-scroll').append(this.$modal).append(this.$dim);this.$win.on('keydown.rad-modal',$.proxy(this.__keydown,this));},close:function(){this._reset();},remove:function(){this._reset();this.$body.off('.rad-modal');this.$win.off('.rad-modal');a.Events.off('radmodal:close');}};a.Globals=b;a.CopyInputs=c;a.ToggleInputs=d;a.CheckboxInputs=e;a.RadioButtons=f;a.Tooltips=g;a.RadModal=h;})(Giphy);(function(){var a=Giphy.Homepage={init:function(){var a=$('#homepage');if(a.length){Giphy.Homepage.attachInfiniteScroll();Giphy.Homepage.attachHovers();Giphy.Homepage.playFeaturedViewport();Giphy.Homepage.attachNotice();$(document).on('scroll',function(){Giphy.Homepage.playFeaturedViewport();});}},attachInfiniteScroll:function(){$.extend($.infinitescroll.prototype,{beginAjax:function a(a){var b=this,c=a.path,d,e;if(typeof a.state.nextPage!='undefined')e=a.state.nextPage;else e=c[0];var f=$(a.contentSelector).is('table, tbody')?$('<tbody/>'):$('<div/>');f.load(e+' '+a.itemSelector,undefined,function g(c){next=$($(c).find(a.nextSelector));a.state.nextPage=next.attr("href");e=a.state.nextPage;b._loadcallback(f,c,e);});}});window.CURRENT_PAGE=1;$('.homepage').infinitescroll({nextSelector:"a#next-page-arrow",navSelector:"div#paging",itemSelector:".homepage-half",bufferPx:10,state:{currPage:window.CURRENT_PAGE},pathParse:function(a,b){var c=a.split('?')[0];var d=a.split('?')[1];var e=d?"?"+d+"&is=1":"?is=1";var f=['/page/'+b+e+''];return f;},behavior:"giphy",loading:{finishedMsg:"",img:"/static/img/loading_bar_page.gif",msgText:"",speed:'fast',finished:function(){$('#infscr-loading').remove();var a=$(this).data('infinitescroll');window.CURRENT_PAGE+=1;window.OFFSET_PAGE=window.CURRENT_PAGE-1;Giphy.Analytics.fireEvents('/page/'+window.CURRENT_PAGE);Giphy.Homepage.attachHovers();}}});},attachHovers:function(){var a=$('.hoverable');a.mouseenter(function(a){var b=$(this).find('img'),c=$(this).find('.loader'),d=b.attr('data-animated');$('.loader').hide();c.show();b.addClass('hovering');$("<img />").attr('src',d).load(function(){c.css('display','none');if(b.hasClass('hovering')){b.removeAttr('nopin');b.attr('src',d);}});});a.mouseleave(function(a){var b=$(this).find('img'),c=$(this).find('.loader'),d=b.attr('data-static');b.removeClass('hovering');b.attr('nopin','nopin');b.attr('src',d);c.hide();});},playFeaturedViewport:function(){var a=$('.homepage-featured');var b=$(window).scrollTop();var c=b+$(window).height();$.each(a,function(a,d){var e=$(d),f=e.find('img'),g=e.find('.loader'),h=f.attr('data-animated'),i=f.attr('data-static');if((((e.offset().top+e.height())<=c)&&((e.offset().top+e.height())>=b))){if(f.attr("src")!=f.attr("data-animated")){f.addClass('hovering');$("<img />").attr('src',h).load(function(){g.css('display','none');if(f.hasClass('hovering')){f.removeAttr('nopin');f.attr('src',h);}});}}else{f.removeClass('hovering');f.attr('nopin','nopin');f.attr('src',i);g.hide();}});},attachNotice:function(){if($("#notice-banner").length>0){var a="giphy-"+$("#notice-banner").data('name');if(!$.cookie(a)){setTimeout(function(){$("#notice-content").appendTo("#notice-banner");$("#notice-content").show();$("#notice-banner").slideDown();},3000);$("#notice-dismiss").on('click',function(b){b.preventDefault();Giphy.Homepage.dismissNotice(a);return false;});}}},dismissNotice:function(a){$.cookie(a,"1",{expires:365});if($("#notice-banner").length>0)$("#notice-banner").slideUp();}};})(window,Giphy);(function(){var a=Giphy.Images={preloadImages:function(){var a=["/static/img/facebook_animated.gif","/static/img/twitter_animated.gif","/static/img/loading_bar.gif"];for(i=0;i<a.length;i++){var b=new Image();b.src=a[i];}},showOriginalSize:function(){if($("#gif").attr("data-padding-top")>0){$("#gif").css('height',$("#gif").attr("data-original-height"));$("#gif").css('width',$("#gif").attr("data-original-width"));$("#gif").css('padding-top',$("#gif").attr("data-padding-top")+'px');}return false;},sizeImages:function(){var a=$('.last-row').find('li');var b=$('.freeform').find('li.ungrouped');var c=$('li.ungrouped .upload-gif');b.removeClass("ungrouped");var d=$.merge(a,b);var e=d.find('img');if(c.length)if(!window.uploadButtonPlaced){e=$.merge(c,e);window.uploadButtonPlaced=true;}else c.closest('li').remove();if(e.length===0)return;var f=0;if($(".fb_container").length==0){var g=$('#content').width();var h=200;var i=$("#_giphy_tv").length>0&&(typeof _suppress_tv_resize=='undefined');}else{var g=700;var h=150;var h=200;var i=false;}if(typeof window.margin==='undefined'){var j=parseInt($(e[0]).closest('li').css("margin-right"),10);window.margin=j;}else var j=window.margin;var k=[];var l=0;var m=0;window.tvPlaced=window.tvPlaced||false;$.each(e,function(a){var b=e[a];var c=parseInt($(b).attr("data-width"),10);var d=parseInt($(b).attr("data-height"),10);if(d!=h)c=Math.floor(c*(h/d));k.push(parseInt(c,10));});while(f<e.length){var n=0;var o=0;var p=0;var q=0;var r=false;var s=(l<2&&i&&$(window).width()>480&&!window.tvPlaced)?g/2:g+j;while(p<s){if(f+n==k.length){p+=j;r=true;break;}var t=k[f+n]+j;p+=t;if(f+n>=e.length){r=true;break;}n++;}var u=$("<div class='hoverable'/>");if(i&&!tvPlaced&&l<2){$(u).css('float','left');$(u).css('width',s);$(u).css('clear','left');}var v=s/p;while(o<n){var w=k[f]*v;var x=h*v;var y=$(e[f]);if(r){w=parseInt($(y).attr('data-width'),10);x=parseInt($(y).attr('data-height'),10);}q+=w+j;y.width(w);y.height(x);var z=y.closest('li');u.append('<li style="width: '+w+'px;">'+z.html()+'</li>');z.remove();if(o==n-1){B=$(u).find("li:last");B.css('margin-right','0px');}o++;f++;}if(!r)if(q>s){var A=0;while(q>s){var B=$(u).find("li:nth-child("+(A+1)+")");var y=B.find('img, .upload-gif');$(y).width($(y).width()-1);$(B).width($(B).width()-1);q--;if(++A>=$(u).find("img").length)A=0;}}else if(q<s){var A=0;while(q<s){var B=$(u).find("li:nth-child("+(A+1)+")");var y=B.find('img, .upload-gif');$(y).width($(y).width()+1);$(B).width($(B).width()+1);q++;if(++A>=$(u).find("img").length)A=0;}}if(r===true)u.addClass('last-row');$('.gifs').append(u);if(i&&!window.tvPlaced&&l<2)m+=$(u).height();l++;$(document).trigger("images:done_sizing");}if(i&&!window.tvPlaced){var C=function(){if($("#asdf-container").length==0){setTimeout(C,100);return;}window.tvPlaced=true;$("#_giphy_tv").width(g/2);$("#_giphy_tv").height(m-5);__TV.sizeTo(g/2,m-5);__TV.resize();__TV.sizeTo(g/2,m-5);$("#_giphy_tv").css('margin-top','-35px');$(document).trigger('images:tv_placed');};C();}else $(document).trigger('images:no_tv');$('.bottom-tags a').show();return this;},sizeImagesToFrame:function(){var a=$('.framed-gif');if(a.length)$.each(a,function(a,b){var c=$(b),d=c.attr("data-original-height"),e=c.attr("data-original-width"),f=c.parents(".frame"),g=f.width(),h=f.height(),i=e/d,j=g/h,k,l,m,n;if(i>=j){m=(h/d)*e;n=h;l=-(m-g)/2;k=0;}else{m=g;n=(g/e)*d;l=0;k=-(n-h)/2;}c.css({"margin-top":k,"margin-left":l});c.attr({"height":n,"width":m});});},removePageNumbersForBackButton:function(){var a=$('.hoverable li');if(a.length)a.each(function(a,b){href=$(b).find(".a-gif");href.click(function(a){var b=window.location.href;var c=b.replace('http://','').split('/').length;if(b.indexOf("search")!=-1&&c==4){var d=b.replace(b.substr(b.lastIndexOf('/')+1),'');if(window.history.pushState)window.history.pushState("","",d);}});});},attachHovers:function(){var a=$(".hoverable li, .row-tag, .featured-item, .featured-user");if(a.length){a.off("mouseenter","**").mouseenter(function(a){var b=$(this).find(".hover-target").length?$(this).find(".hover-target"):$(this).find('img'),c=$(this).find('.loader'),d=b.attr('data-animated'),e=$(this).find('.promote-gif-hover');if($(a.currentTarget).find('.hoverable-gif.waiting').length)return;$('.loader').hide();c.css('display','block');b.addClass('hovering');$("<img />").attr('src',d).load(function(){c.css('display','none');if(b.hasClass('hovering')){b.removeAttr('nopin');b.attr('src',d);if(b.width()<150){e.find('h1').text('top').css('margin-right',10);e.find('.promote-gif-text').css('width','auto');}e.show();}});});a.off("mouseleave","**").mouseleave(function(a){var b=$(this).find(".hover-target").length?$(this).find(".hover-target"):$(this).find('img');b.removeClass('hovering');b.attr('nopin','nopin');b.attr('src',$(b).attr('data-still'));b.parent('.gif').parent().children('.loader').css('display','none');$(this).find('.promote-gif-hover').hide();});}return this;}};})(window,Giphy);(function(){var a=Giphy.Instagram={showModal:function(){var a=$("#instagram-share"),b=$('#instashare-share'),c=$('#instashare-send-button'),d=$("#instashare-loader"),e=$('#instashare-email-input');e.keypress(function(a){if(a.which==13)c.click();});$(".instashare-okbutton").click(function(){a.removeClass('hover');$("#instashare-modal").hide();});a.click(function(){if($('#instashare-modal').css('display')=='block'){$("#instashare-modal").hide();a.removeClass('hover');}else{$(".dialog").hide();$('.hover').removeClass('hover');$("#instashare-modal").show();a.addClass('hover');}b.show();c.show();d.hide();e.val('');});c.click(function(){c.hide();d.show();var b="/ajax/instashare/";$.ajax({type:"post",url:b,data:{"gif_id":$('#gif').attr("data-gif_id"),"to":$("#instashare-email-input").val()}}).always(function(b){if(b.result)if(b.result.code!=200){showError("UH OH. Something went wrong. Try again?");a.removeClass('hover');$("#instashare-modal").hide();}else{showSuccess("Success! Check your email in about 5 minutes. We sent you a GIF you can upload to Instagram.");a.removeClass('hover');$("#instashare-modal").hide();}else{showError("UH OH. Something went wrong. Try again?");a.removeClass('hover');$("#instashare-modal").hide();}});});}};})(window,Giphy);(function(){var a=Giphy.Login={facebook:function(){var a=Giphy.Utils.getParameterByName("next");if(a)window.LOGIN_NEXT=location.protocol+"//"+location.host+a;$(".facebook-login").click(function(){if(window.LOGIN_NEXT)document.location.href='/login/facebook/?next='+window.LOGIN_NEXT+"?status=200&message=login";else document.location.href='/login/facebook/';return false;});return this;},loginFocus:function(){var a=$("#login-form");if(a.length)$("#email").focus();}};})(window,Giphy);(function(){var a=Giphy.Nav={share:function(){$("input[type='text']").on("click",function(){$(this).select();});},attachFooter:function(){if(($('#homepage').length>0)||($(".freeform").length>0)){var a=$("#footer");a.css('position','fixed');a.css('bottom','0px');a.css('opacity','0');a.css('z-index','10000');$(document).mousemove(function(b){var c=$(window);var d=b.pageY;var e=c.height()+c.scrollTop()-d-200;if(e<=100)a.css('opacity','1');else a.css('opacity','0');});}}};})(window,Giphy);(function(){var a=Giphy.Newsletter={attachNewsletter:function(){if($("#newsletter-placeholder").length>0)if(!$.cookie("dismiss-newsletter")){setTimeout(function(){$("#newsletter-content").appendTo("#newsletter-placeholder");$("#newsletter-content").show();$("#newsletter-placeholder").slideDown();},3000);$("#newsletter-dismiss").on('click',function(a){a.preventDefault();Giphy.Newsletter.dismissNewsletter();return false;});}$("#newsletter-form").on('submit',function(a){a.preventDefault();var b=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;if(!b.test($("#newsletter-email").val())){showError("Please enter a valid email address.");return;}$("#newsletter-content").removeClass('inactive');$("#newsletter-content").addClass('active');$.ajax({type:'post',url:'/ajax/newsletter',data:{'email':$("#newsletter-email").val(),'action':$(this).attr('data-action')},dataType:'json',error:function(a){$("#newsletter-content").removeClass('active');$("#newsletter-content").addClass('inactive');showError("An error occurred.");},success:function(a){if(a.result.error){showError(a.result.error);$("#newsletter-content").removeClass('active');$("#newsletter-content").addClass('inactive');}else{if($("#newsletter-content").length>0)$("#newsletter-form").animate({"margin-top":"200"},300,function(){});$("#newsletter-content").removeClass('active');$("#newsletter-content").addClass('success');if(document.location.pathname!='/'){Giphy.Newsletter.dismissNewsletter();showSuccess(a.result.response,'/',1500);}else setTimeout(function(){Giphy.Newsletter.dismissNewsletter();},2000);}}});});},dismissNewsletter:function(){$.cookie("dismiss-newsletter","1",{expires:365});if($("#newsletter-placeholder").length>0)$("#newsletter-placeholder").slideUp();}};})(window,Giphy);(function(){var a=Giphy.Overlays={getShareHtml:function(){return [$("<a>",{"id":"fb-share","class":"facebook facebook-blue social-share","title":"Share on Facebook","target":"_blank","href":"#","click":function(){window.open("http://www.facebook.com/sharer/sharer.php?u="+document.URL,"1361370515039","width=650,height=280,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0");return false;}}),$("<a>",{"id":"twitter-share","class":"twitter twitter-blue social-share","title":"Share on Twitter","target":"_blank","href":"#","click":function(){window.open("http://twitter.com/share?url="+document.URL+"?tc=1&text="+window.socialShareTitle+"&via=giphy","1361370074860","width=500,height=252,toolbar=0,menubar=0,location=0,status=1,scrollbars=0,resizable=1,left=0,top=0");return false;}})];},getGifViewHtml:function(){var a=this;var b=[$("<a>",{"id":"gif-tile-link","class":"gif-tile-link sprite _023_tile","title":"Tile View","href":a.createOverlayUrl('tile')}),$("<a>",{"id":"gif-fullscreen-link","class":"gif-fullscreen-link sprite _004_fullscreen","title":"Fullscreen View","href":a.createOverlayUrl('fullscreen')})];if($("#gif-mp4").length>0)b.push($("<a>",{"id":"gif-version-link","class":"gif-version-link","title":"GIF View","href":a.createOverlayUrl('gif')}).text('GIF'));return b;},createOverlayUrl:function(a){var b=document.URL.split('?');var c=b[0].replace("home","").replace("edit","").replace("tile","").replace("fullscreen","").replace(/\/$/,'');if(a=="gif")return c;if(b[1]!=undefined)return c+"/"+a+"?"+b[1];else return c+"/"+a;},addShareLinksToPostIframes:function(){var a=this,b=$("#post-detail");if(b.length)$(document).ready(function(){$("#post-content iframe").each(function(){var b=$(this);b.wrap("<div class='iframe-wrap' style='position:relative;'></div>");b.after($("<div>",{"class":"iframe-overlay-share grid_8","html":a.getShareHtml()}));b.parent(".iframe-wrap").mouseover(function(a){$(this).find(".iframe-overlay-share").fadeIn();});b.parent(".iframe-wrap").mouseleave(function(a){$(this).find(".iframe-overlay-share").fadeOut();});});});},addOverlayToGifDetail:function(){var a=this,b=$("img#gif, video#gif-mp4"),c=$("#gif-wrap"),d=$("#fullscreen-overlay"),e=$("#gif-wrap .gif-hover");if(c.length){$(document).ready(function(){e.append($("<div>",{"class":"gif-overlay-views","id":"gif-overlay-views","html":a.getGifViewHtml()}));});c.bind({mouseenter:function(a){$("#gif-overlay-share, #gif-overlay-views").fadeIn();},mouseleave:function(a){$("#gif-overlay-share, #gif-overlay-views").fadeOut();}});}if(d.length)d.click(function(){window.location=document.URL.replace("tile","").replace("fullscreen","").replace(/\/$/,'');});},sizeFSOverlay:function(){var a=$("#fullscreen-overlay");if(a.length){var b=function(){var a=$("#gif,#gif-mp4"),b=$("#fullscreen-overlay"),c=a.data("original-height"),d=a.data("original-width"),e=$(window).width(),f=$(window).height(),g=d/c,h=e/f,i,j,k,l;if(g>=h){k=(f/c)*d;l=f;j=-(k-e)/2;i=0;}else{k=e;l=(e/d)*c;j=0;i=-(l-f)/2;}b.css({"height":l,"width":k,"margin-top":i,"margin-left":j});$('body').css({"overflow":"hidden","margin":0});};b();$(window).resize(function(){b();});}}};})(window,Giphy);(function(){var a=Giphy.Search={initMini:function(){if(!$("#mini-search-form").length)return;var a=$("#searchbar"),b=$("#search-box"),c=$("#search-button");b.blur();b.click(function(){var a=$('.search-bar-form button').find('img');if(a.hasClass('color'))return false;else{a.attr('src',a.attr('data-focus'));a.addClass('color');}});$(document).mouseup(function(b){var c=$('.search-bar-form button').find('img');if(!a.is(b.target)&&a.has(b.target).length===0){c.attr('src',c.attr('data-blur'));c.removeClass('color');}});b.keydown(function(a){var b=$('.searchbar button').find('img');if(!b.hasClass('color')){b.attr('src',b.attr('data-focus'));b.addClass('color');}});$("#mini-search-form").on('submit',function(a){var b=$('.search-bar-form button').find('img');if(b.attr('src')!=b.attr('data-submit')){a.preventDefault();a.stopImmediatePropagation();b.attr('src',b.attr('data-submit'));searchDelay=setTimeout(function c(){$("#mini-search-form").submit();},500);}});},init:function(){a.hasBeenEntered=false;a.hasKeyDown=false;var b=-1;var c=$("#searchbar"),d=$("#search-box"),e=$("#search-button");if(!(d.length>0))return;$("#placeholder").click(function(a){d.focus();});d.hover(function(){e.addClass("active");},function(){if(!$(this).is(":focus")&&$('.search-result').length==1)e.removeClass("active");});d.click(function(){var a=$('.searchbar button').find('img');if(a.hasClass('color'))return false;else{a.attr('src',a.attr('data-focus'));a.addClass('color');}});$(document).mouseup(function(a){var b=$('.searchbar button').find('img');if(!c.is(a.target)&&c.has(a.target).length===0){b.attr('src',b.attr('data-blur'));b.removeClass('color');}});d.focus(function(){$(".autocomplete").text("");e.addClass("active");});d.blur(function(){$(document).trigger("search:clear");});e.click(function(a){a.preventDefault();if(d.val().length>0)$(document).trigger("search:enter");});d.keydown(function(b){var c=$('.searchbar button').find('img');if(!c.hasClass('color')){c.attr('src',c.attr('data-focus'));c.addClass('color');}a.hasKeyDown=true;var d=b.which;if(d==38||d==40||d==9)b.preventDefault();else $("#placeholder").hide();});d.keyup(function(b){if(a.hasKeyDown===true){if(!a.hasBeenEntered){a.hasBeenEntered=true;_gaq.push(['_trackEvent','Search','QueryEntered']);}var c=b.which;var d=$("#search-box");var e=d.val();if(!e)$("#placeholder").show();if(c==37)return;if(c==38){$(document).trigger("search:up",b);b.preventDefault();return;}if(c==39){var f=$('.autocomplete').text();if(f&&f!=e)$(document).trigger("search:tab",f);b.preventDefault();return;}if(c==40){$(document).trigger("search:down",b);b.preventDefault();return;}if(c==9){var f=$('.autocomplete').text();if(f&&f!=e)$(document).trigger("search:tab",f);b.preventDefault();return;}if(c==13){b.preventDefault();a.enterPressed=true;$(document).trigger("search:enter",b);return;}var g=this;encoded=encodeURIComponent(e);if(typeof encoded==='undefined'||!encoded)return;$(document).trigger("search:execute");}});$(document).bind('search:execute',function(b){b.preventDefault();b.stopPropagation();var c=$("#search-box").val();var d=function(){$.get("/api/v1/tags/search/?q="+c,function(b){b.q=c;b.encoded=encoded;b.dont_display=false;if(a.enterPressed){a.enterPressed=false;b.dont_display=true;}$(document).trigger("search:success",b);}).fail(function(){$(document).trigger("search:error");});};if(Giphy.Timer!==undefined)Giphy.Timer.cancel();Giphy.Timer=new Giphy.Utils.timeout();Giphy.Timer.init(d,300,null);});$(document).bind('search:success',function(a,b){if(b.q!=$("#search-box").val())return;$(document).trigger("search:clear");for(var c=0;c<b.objects.length;c++){var d=$(".search-results").find('.search-result').first().clone();$(d).find('.word').text(b.objects[c].name);$(d).find('.word').attr("name-encoded",b.objects[c].name_encoded);d.mousedown(function(){if($(".fb_container").length==0)document.location.href="http://"+window.REAL_HOSTNAME+"/search/"+$(this).find(".word").attr("name-encoded");else{$("#search-box").val($(this).find(".word").attr("name-encoded"));$("#placeholder").hide();Giphy.Facebook.search($(this).find(".word").attr("name-encoded"));}});d.hover(function(){$(".hover").removeClass("hover");$(this).addClass("hover");},function(){$(this).removeClass("hover");});$(".search-results").append(d);$(".search-results").show();$(d).show();}if(b.dont_display)$(document).trigger("search:dont_display");});$(document).bind("search:clear",function(a){$(".autocomplete").text("");$('.search-result:visible').each(function(){$(this).remove();});b=-1;$('.search-results').hide();});$(document).bind("search:reset",function(a){$(document).trigger("search:clear");$('#search-box').val("");$("#placeholder").show();$('#search-box').blur();});$(document).bind("search:down",function(a){$('.search-result').removeClass('hover');b++;var c=$('.search-result:visible').length;if(b>=c)b=c-1;var d=$('.search-result:visible').eq(b);d.addClass("hover");$(document).trigger("search:selected",$(d).find('.word').text());});$(document).bind("search:up",function(a){$('.search-result').removeClass('hover');b--;if(b<0){$(".autocomplete").text("");$('#search_box').focus();b=-1;}else{var c=$('.search-result:visible').eq(b);c.addClass("hover");$(document).trigger("search:selected",$(c).find('.word').text());}});$(document).bind("search:enter",function(b){var c;b.preventDefault();b.stopImmediatePropagation();var d=$('.search-bar-form button').find('img');d.attr('src',d.attr('data-submit'));var e=$("#search-box").val();var f=$(".search-result.hover");var g=f.find(".word").text();var h=f.find(".word").attr("name-encoded");c=setTimeout(function i(){if(g)if($(".fb_container").length==0)document.location.href="http://"+window.REAL_HOSTNAME+"/search/"+h;else{Giphy.Facebook.search(h);$("#search-box").blur();a.hasKeyDown=false;$(document).trigger("search:clear");}else if(e.length>0)if($(".fb_container").length==0){var b=$("#searchbarform").length?$("#searchbarform"):$("#mini-searchbar-form");b.submit();}else{Giphy.Facebook.search(e);$("#search-box").blur();a.hasKeyDown=false;$(document).trigger("search:clear");}},500);return;});$(document).bind("search:selected",function(a,b){var c=$('#search-box');var d=$('.autocomplete');var e=c.val();var f="<span>";if(!b||e.trim().toLowerCase()==b)d.text('');else d.html(b);});$(document).bind("search:tab",function(a,b){$("#search-box").val(b);$(document).trigger("search:execute");});var f=navigator.userAgent.toLowerCase();if(!f.indexOf("android")>-1)d.focus();if($("#reaction-gifs").length>0)$("#reaction-gifs").mouseover(function(){$("#search-box").blur();});if($('.gifs').length)$('.gifs .gif img').each(function(){var a=$(this).attr('data-animated');if(a)$('<img/>')[0].src=a;});}};})(window,Giphy);(function(){var a=Giphy.SearchResults={attachInfiniteScroll:function(a){$('ul.freeform').infinitescroll({nextSelector:"a#next-page-arrow",navSelector:"div#paging",itemSelector:".freeform li.ungrouped",bufferPx:10,state:{currPage:window.CURRENT_PAGE},behavior:"giphy",loading:{finished:function(){$('#infscr-loading').remove();var a=$(this).data('infinitescroll');Giphy.Images.sizeImages();Giphy.Images.attachHovers();if(window.ADD_EDIT_JS===true)Giphy.UserEdit.addEditGifLinks();window.CURRENT_PAGE=a.options.state.currPage;window.OFFSET_PAGE=window.CURRENT_PAGE-1;current_page=a.options.path[0]+a.options.state.currPage;if($(".fb_container").length==0)Giphy.Analytics.fireEvents(current_page);else Giphy.Analytics.fireEvents(current_page,true);},finishedMsg:"",img:"/static/img/loading_bar_page.gif",msgText:"",speed:'fast'},pathParse:function(a,b){var c=a.split('/'),d=a.split('?')[1],e=$(".gif").last().parent().attr('href');appendParams=d?"?"+d+"&is=1":"?is=1",base=c[1],term=c[c.indexOf(base)+1];try{var f=parseInt(c[c.indexOf('search')+2],10);}catch(g){var f=1;}if(base=='search')return ['/'+base+'/'+term+'/',appendParams];else if(base=='channel')return ['/'+base+'/'+term+'/',appendParams];else return ['/'+base+'/',appendParams];}});if(a!==undefined)a();return this;}};})(window,Giphy);(function(){var a=Giphy.Sharing={shortURLs:function(){ZeroClipboard.config({swfPath:"/static/js/zeroclipboard.swf"});var a=new ZeroClipboard($(".short-link"));a.on('copy',function(a){a.clipboardData.setData("text/plain",$(".short-link").attr("data-url"));showSuccess("Short URL copied to clipboard!");});},attachShareTools:function(){ZeroClipboard.config({swfPath:"/static/js/zeroclipboard.swf"});var a=new ZeroClipboard($("#share-giphy-link-icon"));a.on('copy',function(a){a.clipboardData.setData("text/plain",$("#share-giphy-link").val());showSuccess("Giphy link copied to clipboard!");});var b=new ZeroClipboard($("#share-gif-link-icon"));b.on('copy',function(a){a.clipboardData.setData("text/plain",$("#share-gif-link").val());showSuccess("GIF link copied to clipboard!");});var c=new ZeroClipboard($("#share-html5-link-icon"));c.on('copy',function(a){a.clipboardData.setData("text/plain",$("#share-smart-link").val());showSuccess("HTML5 link copied to clipboard!");});var d=new ZeroClipboard($("#iframe-embed-code-icon"));d.on('copy',function(a){a.clipboardData.setData("text/plain",$("#iframe-embed-code").val());showSuccess("IFrame embed code copied to clipboard!");});var e=new ZeroClipboard($("#optimized-embed-code-icon"));e.on('copy',function(a){a.clipboardData.setData("text/plain",$("#optimized-embed-code").val());showSuccess("JS embed code copied to clipboard!");});var f=new ZeroClipboard($("#smart-embed-code-icon"));f.on('copy',function(a){a.clipboardData.setData("text/plain",$("#smart-embed-code").val());showSuccess("HTML5 embed code copied to clipboard!");});$("#modal-container").find("input[type='text']").click(function(){$(this).select();});$(document).bind("share-tools:open",function(){if($("#modal-container").css('display')=='none')$("#modal-container").show();});$(document).bind("close-all-modals",function(){if($("#modal-container").css('display')=='block')$("#modal-container").hide();});$(document).bind("share-tools:close",function(){if($("#modal-container").css('display')=='block')$("#modal-container").hide();});$(document).bind("share-tools:close-children",function(){$(".modal-child").hide();$('.hover').removeClass("hover");});$(".action").click(function(){if($(this).hasClass("hover")){$(document).trigger("share-tools:close");$(this).removeClass("hover");}else{$(document).trigger("share-tools:close-children");$(document).trigger("share-tools:open");$(this).addClass('hover');}return false;});$(".playchoice").on('click',function(){if($(this).attr('id')=='autoplay'&&!$(this).hasClass('active-playchoice')){$("#hoverplay").removeClass("active-playchoice");$("#hoverplay").addClass("inactive-playchoice");$(this).removeClass("inactive-playchoice");$(this).addClass("active-playchoice");$("#iframe-embed-code").val($("#iframe-embed-code").val().replace("?playOnHover=true",""));$("#optimized-embed-code").val($("#optimized-embed-code").val().replace("var _giphy_play_on_hover = true;",""));}else if($(this).attr('id')=='hoverplay'&&!$(this).hasClass('active-playchoice')){$("#autoplay").addClass("inactive-playchoice");$("#autoplay").removeClass("active-playchoice");$(this).addClass("active-playchoice");$(this).removeClass("inactive-playchoice");$("#iframe-embed-code").val($("#iframe-embed-code").val().replace(/embed\/([a-zA-Z0-9-_]*)/,"embed\/$1?playOnHover=true"));$("#optimized-embed-code").val($("#optimized-embed-code").val().replace("var _giphy","var _giphy_play_on_hover = true; var _giphy"));}});$("#shorten-url").click(function(){$(".shortener-options").show();});$("#embed-share").click(function(){$(".embed-options").show();});$("#share-link").click(function(){$(".share-options").show();});$("#redirect-to").on('click',function(){$(this).select();});$("#redirect-to").keyup(function(a){var b=a.which;if(b==13){a.preventDefault();$("#shorten-create-submit").click();return;}});var g=$("#shorten-create-submit");g.click(function(a){a.preventDefault();var b=this;$(b).prop('disabled',true);$(b).attr('value','ONE SEC...');$.ajax({type:"post",url:"//"+window.ASSET_DOMAIN+"/ajax/shorturl/create/",data:{'gif_id':$("#gif").attr('data-id'),'redirect_to':$('#redirect-to').val()}}).success(function(a){if(a.result.code!=200)return;else{$(b).prop('disabled',false);$(b).attr('value','Shorten');$("#redirect-to").val(a.result.short_url);var c=new ZeroClipboard(g);g.val("Copy");g.css('background-color','#2afd9c');c.on('copy',function(b){b.clipboardData.setData("text/plain",a.result.short_url);showSuccess("Short URL copied to clipboard!");});}}).error(function(){$(b).prop('disabled',false);$(b).attr('value','Shorten');showError("An error has occurred.");});});var h=$('#tumblr-share').not('.post');if(h.length)h.click(function(a){a.preventDefault();if(window.PHOTOBOOTH)window.open("http://www.tumblr.com/share/photo?source="+encodeURIComponent($('#gif').attr('data-image_original_url').replace('giphy.gif','500w.gif'))+"&caption="+encodeURIComponent(document.title)+"&clickthru="+encodeURIComponent($('#gif').attr('data-bitly_gif_url')),'1361370515040','width=620,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0');else window.open("http://www.tumblr.com/share/photo?source="+encodeURIComponent($('#gif').attr('data-tumblr_share_url'))+"&caption="+encodeURIComponent(document.title)+"&clickthru="+encodeURIComponent($('#gif').attr('data-bitly_gif_url')),'1361370515040','width=620,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0');});},postAnalytic:function(a){var b=$('#gif').attr("data-gif_id"),c="http://api.giphy.com/v1/gifs/"+gifID+"/share";$.ajax({type:"post",url:c,data:JSON.stringify({"share_type":a}),contentType:"application/json",dataType:"application/json"});},attachSharingAnalytics:function(){var a=$('#embed-share');if(a.length)a.click(function(a){Giphy.Sharing.postAnalytic("embed");});var b=$('#tumblr-share');if(b.length)a.click(function(a){Giphy.Sharing.postAnalytic("tumblr");});var c=$('#fb-share');if(c.length)c.click(function(){Giphy.Sharing.postAnalytic("facebook");});var d=$('#pinterest-share');if(d.length)d.click(function(){Giphy.Sharing.postAnalytic("pinterest");});var e=$('#instagram-share');if(e.length)e.click(function(){Giphy.Sharing.postAnalytic("instagram");});var f=$('#twitter-share');if(f.length)f.click(function(){Giphy.Sharing.postAnalytic("twitter");});}};})(window,Giphy);(function(a,b){var c={__submit:function(){this.filePortal.submit();},__loginCheck:function(a){a.target.LOGGED_IN?this.$footer.hide():this.$footer.show();},initialize:function(a){this.$win=$(window);this.$el=$('.creation-tools-upload');this.$footer=this.$el.find('.tool-footer');this.user=null;this.fileportal=null;this.fileTypes=["image/gif","video/mpg","video/m4v","video/x-m4v","video/mov","video/mp4","video/mpeg","video/quicktime"];this.submitUrl=a.submitUrl||'';this.render();},render:function(){if(!this.$el.length)return;this.filePortal=b.FilePortal.initialize({url:this.submitUrl,fileTypes:this.fileTypes,sortableList:this.$el.find('#upload-queue'),allowAnonymous:false,multipleRequiresLogin:true,maxVideoLength:15,defaultTags:'giphyupload',preventDuplicates:true});this.$win.on('login:check.upload-gif',a.bind(this.__loginCheck,this));b.Events.on('optionalfields:upload.upload-gif',this.__submit,this);}};b.Upload=c;})(_,Giphy);(function(a){var b={__aboutButtonClick:function(a){a.preventDefault();this.$aboutContainer.toggleClass('show-info');},__aboutGlassClick:function(a){a.preventDefault();this.$aboutContainer.removeClass('show-info');},initialize:function(a){a=a||{};this.$el=$(a.el||'#user-channel');this.render();},render:function(){if(!this.$el.length)return;this._cacheSelectors();this._bindEvents();this.determineBioLayout();},determineBioLayout:function(){if(!this.$aboutBio.length||!this.$aboutInfo.length)return;var a=0;var b=140;this.$aboutInfo.css('display','block');a=this.$aboutBio.height();this.$aboutInfo.css('display','');if(a>b)this.$aboutInfo.addClass('wide-layout');},_cacheSelectors:function(){this.$aboutContainer=this.$el.find('.about-container');this.$aboutBtn=this.$el.find('.about-button');this.$aboutGlass=this.$el.find('.about-glass');this.$aboutInfo=this.$el.find('.about-info');this.$aboutBio=this.$el.find('.about-bio');},_bindEvents:function(){this.$aboutBtn.on('click',$.proxy(this.__aboutButtonClick,this));this.$aboutGlass.on('click',$.proxy(this.__aboutGlassClick,this));}};a.UserChannel=b;})(Giphy);(function(){var a=Giphy.UserEdit={errorMessages:{'password':'Must be at least 6 characters.','email':'Please enter a valid email address.','url':'Please enter a valid url.','required':'This field can\'t be left blank.'},_addErrorToInput:function(a,b){if(!a)return;var c=$(a);_.defer(function(){$('html, body').stop(true,true).animate({scrollTop:c.offset().top-50});});if(c.hasClass('error'))return;var d=c.attr('type');var e=c.attr('required')||false;var f=c.get(0).validationMessage;if(e&&!c.val())f=this.errorMessages.required;else if(this.errorMessages[d])f=this.errorMessages[d];Giphy.Utils.showInputMessage(c,b||f,true);},_ajaxSubmitForm:function(a,b){if(!a)return;var c=$.Deferred();var d=$(a);var e=d.find(':input:visible');if(!d.get(0).checkValidity()){e.each($.proxy(function(a,b){if(!b.validity.valid)this._addErrorToInput(b);},this));c.reject();}else{var f=new FormData(d.get(0));$.ajax({url:d.attr('action'),type:'POST',data:f,processData:false,contentType:false,success:function(a){window.showSuccess('Settings updated!');if(a.result&&a.result.channel_url)$('.user-url').attr('href',a.result.channel_url);c.resolve(a);},error:$.proxy(function(a){var b=a.responseJSON.result;window.showError('Uh-oh. Something went wrong. Please try again.');c.reject(b);},this)});}return c.promise();},_bindSaveButtonEvents:function(a){if(!a)return;var b=$(a).attr('disabled',true);var c=b.closest('form');var d=c.find('.settings-field');var e=c.find(':input');var f=b.text();var g="Saving";var h="Success";var i=c.serialize();e.on('input',function(a){var e=i===c.serialize();d.removeClass('saved');b.attr('disabled',e).text(f);});b.on('click',$.proxy(function(a){a.preventDefault();a.stopPropagation();d.addClass('saving');b.text(g);this._ajaxSubmitForm(c).done(function(){setTimeout(function(){i=c.serialize();d.removeClass('saving').addClass('saved');b.text(h);},1000);}).fail($.proxy(function(a){var e=a||{};for(var g in e)this._addErrorToInput(c.find(':input[name='+g+']'),e[g]);d.removeClass('saving');b.text(f);},this));return false;},this));},_reloadEmbedIframe:function(){var a=$('#settings-embed-iframe');if(!a.length)return;var b=a.attr('src').replace('?bust=1','');$.ajax({type:"POST",url:"/status/cachebust/",data:{"url":b},success:function(c){a.attr('src',b+"?bust=1");}});},_preloadImage:function(a){var b=$.Deferred();if(!a)b.reject();else{var c=new Image();c.onload=function(){b.resolve();};c.src=a;}return b.promise();},initializeFormEvents:function(){var a=$("form button.save");var b=$(".settings-toggle");var c=$("#id_username");var d=$("#user_url_text");var e=$('#id_about_bio');e.height(e.get(0).scrollHeight);if(c.length)c.on('input',function(a){var b=c.val();d.text(b);});Giphy.Events.on('toggleinput:toggle',function(a,b,c){var d=$(b);var e=$('input[name='+d.data('input')+']');var f=d.data('inverse-toggle')||false;c=c||false;if(e.length)f?e.val(!c):e.val(c);this._ajaxSubmitForm(window.settingsForm).done($.proxy(function(){if(d.data('input')==='suppress_chrome')this._reloadEmbedIframe();},this));},this);a.each($.proxy(function(a,b){this._bindSaveButtonEvents(b);},this));},addEditGifLinks:function(){var a=$(".user-search-results");if(a.length)$.each($(".a-gif").not(".editLink").not(".no-edit"),function(a,b){var c=$(b),d="/gifs/"+c.attr("data-id")+"/edit/",e=$("<a></a>").addClass("button small transparent-background edit-image").attr("href",d).html("EDIT");c.addClass("editLink");c.attr("href",d);c.after(e);});},addEditBanner:function(){var a=$(".banner img").not("#settings-banner");if(a.length){var b=$("<a></a>").addClass("small button transparent-background edit-image").attr("href","/dashboard/").html("EDIT");a.after(b);}},userSettingsInit:function(){var a=$('#channel-settings-form');if(a.length){window.settingsForm=a;Giphy.UserEdit.uploadNewBanner();Giphy.UserEdit.uploadNewAvatar();Giphy.UserEdit.resetAvatar();Giphy.UserEdit.initializeFormEvents();Giphy.UserEdit.resizeEmbedGif();Giphy.UserEdit.jazzText();if(Giphy.SettingsTourGuide)Giphy.SettingsTourGuide.initialize();}},jazzText:function(){var a=$('#dashboard-banner-text.jazz-text');if(!a.length)return;var b=a.text().split('');a.html('');for(var c=0;c<b.length;c++){var d=$('<span class="dancing-text">'+b[c]+'</span>');a.append(d);}},uploadNewBanner:function(){var a=$('#upload-banner-button');var b=$('#remove-banner-button');var c=$('#id_banner_image');var d=$('#settings-banner');var e=$('#id_is_remove_banner');var f=a.closest('.settings-field');var g=a.closest('.form-row');var h=c.attr('name');var i=a.text();var j=function(){f.removeClass('saving');a.text(i);};a.on('click',$.proxy(function(a){a.preventDefault();c.click();},this));b.on('click',$.proxy(function(a){a.preventDefault();g.addClass('no-banner');d.css('background-image','none');e.val(true);this._ajaxSubmitForm(window.settingsForm).done(function(){e.val(false);});},this));c.on('change',$.proxy(function(b){var e=c.get(0).files;f.addClass('saving');a.text('Uploading');this._ajaxSubmitForm(window.settingsForm).done($.proxy(function(a){var b=a.result;this._preloadImage(b.banner_image).done(function(){d.css('background-image','url('+b.banner_image+')');g.removeClass('no-banner');j();});},this)).fail(function(a){a=a||{};j();if(window.showError&&a[h])window.showError(a[h],6000);});},this));},uploadNewAvatar:function(){var a=$('#upload-avatar');var b=$('#id_avatar');var c=a.find('.upload-label');var d=$('#header .avatar');var e=b.attr('name');var f=c.text();var g=function(){a.removeClass('uploading');c.text(f);};a.on('click',function(a){a.preventDefault();b.click();});b.on('change',$.proxy(function(){a.addClass('uploading');c.text('Uploading');this._ajaxSubmitForm(window.settingsForm).done($.proxy(function(b){var c=b.result;this._preloadImage(c.avatar).done(function(){g();a.css('background-image','url('+c.avatar+')');if(d.length)d.css('background-image','url('+c.avatar+')');});},this)).fail(function(a){a=a||{};g();if(window.showError&&a[e])window.showError(a[e],6000);});},this));},resetAvatar:function(){},showSettingsExampleModal:function(){$('#guide-text').click(function(a){$('#metadata-example').modal({closeText:'',zIndex:100});});},resizeEmbedGif:function(){var a=$('#settings-embed-iframe');if(a.length){var b=a.data();var c=a.width()/b.imagewidth;a.height(b.imageheight*c);}},resetListner:function(){var a=$('.reset');a.click(function(a){$(this).siblings('.reset-input').prop('checked',true);if(a.target.form)setTimeout(function(){a.target.form.submit();},200);});}};})(window,Giphy);(function(a){var b={__scroll:function(){var a=this.$messages.not('[data-seen="true"]');this.windowScrollTop=this.$win.scrollTop();if(a.length)a.each($.proxy(function(a,b){$(b).attr('data-seen',this._isInViewport(b));},this));else{this.remove();this.markAsSeen();}},__resize:function(){this.windowHeight=this.$win.height();},_isInViewport:function(a){var b=$(a);var c=b.offset().top+b.height()+100;return c-this.windowScrollTop<this.windowHeight;},initialize:function(a){a=a||{};if(!window.giphyMessages)return;this.id=window.giphyMessages.id;this.messages=window.giphyMessages.messages;this.isSeen=false;this.windowHeight=0;this.windowScrollTop=0;this.endpoint='/ajax/seenmessages/';this.$el=$(a.el||'#account-settings');this.$body=$('body');this.$win=$(window);this.$messages=$();if(this.messages)this.render();},render:function(){for(var b in this.messages){var c=this.messages[b];var d=$('.settings-toggle[data-input='+c.element+'], :input[name='+c.element+']').filter(':visible');if(d.length){var e=a.Utils.showInputMessage(d,c.message);this.$messages=this.$messages.add(e);}}this.windowHeight=this.$win.height();this.windowScrollTop=this.$win.scrollTop();this.$win.on('scroll.settingsTourGuide',$.proxy(this.__scroll,this));this.$win.on('resize.settingsTourGuide',$.proxy(this.__resize,this));},markAsSeen:function(){$.ajax({url:this.endpoint,type:'POST',data:{message_id:this.id}});},remove:function(){this.$win.off('.settingsTourGuide');}};a.SettingsTourGuide=b;})(Giphy);(function(){var a=Giphy.Utils={fadeMessages:function(a){$(document).ready(function(){clearTimeout(window.messageFadeTimeout);window.messageFadeTimeout=setTimeout(function(){$('.flash').fadeOut('slow');},a||2000);});},canPlayMP4:function(){return !!document.createElement('video').canPlayType('video/mp4; codecs=avc1.42E01E,mp4a.40.2');},getParameterByName:function(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var b=new RegExp("[\\?&]"+a+"=([^&#]*)"),c=b.exec(location.search);return c==null?"":decodeURIComponent(c[1].replace(/\+/g," "));},hideLogo:function(){$("#logo-image").hide();},checkLogin:function(){if(window.LOGGED_IN)return true;return false;},log:function(a){if(window.console)console.log(a);return;},timeout:function(){var a=null;var b=null;var c=0;var d=[];var e=false;var f=false;this.init=function(h,i,j){var k;if(e)return false;if(!h)return false;if(!i)return false;a=h;b=i;e=true;f=false;c=j?j:0;d=[];for(k=3;k<arguments.length;k++)d[d.length]=arguments[k];setTimeout(g,b);};this.cancel=function(){f=true;e=false;c=0;};function g(){e=false;if(f)return;a.apply(null,d);if(c>0){c--;setTimeout(g,b);}}},showInputMessage:function(a,b,c,d){$input=$(a);b=b||'';c=c||false;d=d||false;if(!$input.length||!b.length||$input.hasClass('message'))return;var e=$input.position();var f=$('<div class="input-message"></div>');var g=function(){f.trigger('removed').remove();$(this).removeClass('message error').off('.input-message');};f.toggleClass('error',c).html(b).css({minHeight:($input.hasClass('settings-toggle'))?'':$input.outerHeight(),left:e.left+$input.outerWidth(),top:e.top});$input.addClass('message').toggleClass('error',c).after(f).one('removemessage.input-message',g);if(!d)if($input.is(':input'))$input.one('input.input-message',g);else $input.one('click.input-message',g);return f;},removeInputMessage:function(a){$input=$(a);$input.trigger('removemessage');},getScrollbarWidth:function(){var a=0;var b=document.createElement('div');b.style.height=100;b.style.width=100;b.style.overflow='scroll';document.body.appendChild(b);a=b.offsetWidth-b.clientWidth;document.body.removeChild(b);return a;},getExtension:function(a){if(!a)return;var b=/\.([^\.]+)$/;var c='';var d=a.match(b);if(d&&d.length>1)c=d[1];return c;},canPlayType:function(a){var b=document.createElement('video');return b.canPlayType(a);},preloadImage:function(){var a=arguments.length>1?arguments:arguments[0];if(_.isArray(a))return $.when.apply(window,_.map(a,function(a){return this.preloadImage(a);},this));var b=$.Deferred();var c=new Image();if(a.indexOf('data:image')!==0)c.crossOrigin='anonymous';if(!a)b.reject();else{c.onload=function(){b.resolve(c);};c.onerror=function(){b.reject();};c.src=a;}return b.promise();},getImageData:function(a){var b=$.Deferred();var c=document.createElement('canvas');var d=c.getContext('2d');this.preloadImage(a).done(function(a){c.width=a.width;c.height=a.height;d.drawImage(a,0,0);b.resolve({data:d.getImageData(0,0,c.width,c.height),width:c.width,height:c.height});});return b.promise();},jazzText:function(a,b){var c=$(a);b=b||false;if(!c.length)return;c.each(function(){var a=$(this);var c=a.text().split('');a.addClass('jazz-text').toggleClass('soft-jazz',b).html('');for(var d=0;d<c.length;d++){var e=$('<span class="dancing-text">'+c[d]+'</span>');a.append(e);}});},openPopup:function(a,b,c){if(!a)return;var d='';var e={height:c||480,left:0,location:0,menubar:0,resizable:1,status:0,toolbar:0,top:0,width:(b||480)+this.getScrollbarWidth()};for(var f in e)d+=f+'='+e[f]+',';window.open(a,'_blank',d);},urlRE:RegExp("^"+"("+"(?:(?:https?:)?//)?"+"(?:\\S+(?::\\S*)?@)?"+"(?:"+"(?!(?:10|127)(?:\\.\\d{1,3}){3})"+"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})"+"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})"+"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])"+"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}"+"(?:\\.(?:1\\d\\d|2[0-4]\\d|25[0-4]|[1-9]\\d?))"+"|"+"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)"+"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*"+"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))"+"\\.?"+")"+"(?::\\d{2,5})?"+"(?:[/?#][^\\s\\?#]*)?"+")"+"(?:\\?{0,1})"+"(?:\\S*)?"+"$","i"),placeCaretAtEnd:function(a){if(!a)return;a.focus();if(typeof window.getSelection!="undefined"&&typeof document.createRange!="undefined"){var b=document.createRange();b.selectNodeContents(a);b.collapse(false);var c=window.getSelection();c.removeAllRanges();c.addRange(b);}else if(typeof document.body.createTextRange!="undefined"){var d=document.body.createTextRange();d.moveToElementText(a);d.collapse(false);d.select();}},selectText:function(a){if(!a)return;var b=document.createRange();b.selectNodeContents(a);var c=window.getSelection();c.removeAllRanges();c.addRange(b);},prefixStyle:function(a,b){var c={};c['-webkit-'+a]=b;c['-moz-'+a]=b;c['-ms-'+a]=b;c[a]=b;return c;},transitionEnd:function(){var a;var b=document.createElement('fakeelement');var c={'transition':'transitionend','OTransition':'oTransitionEnd','MozTransition':'transitionend','WebkitTransition':'webkitTransitionEnd'};for(a in c)if(b.style[a]!==undefined)return c[a];},animationEnd:function(){var a;var b=document.createElement('fakeelement');var c={'animation':'animationend','OAnimation':'oAnimationEnd','MozAnimation':'animationend','WebkitAnimation':'webkitAnimationEnd'};for(a in c)if(b.style[a]!==undefined)return c[a];},getVideoDuration:function(a){var b=$.Deferred();var c=document.createElement('video');var d=$(c);a=a||null;c.autoplay=false;c.preload='metadata';d.one('loadedmetadata',function(){d.off();b.resolve(c.duration);});d.one('error',function(){d.off();b.reject();});if(typeof a!=='string')c.src=window.URL.createObjectURL(a);else c.src=a;return b.promise();},isGifmakerUrl:function(a){if(!a)return false;var b;var c=false;var d={'vine':/^(?:https?:\/\/)?(?:www\.)?(?:vine\.co)\/v\/(?:[a-z0-9]{10})/i,'cc_episode_error':/^(?:https?:\/\/)?([a-z0-9]+\.)?(?:cc\.com)\/(episodes|full-episodes)\//i,'cc_clip':/^(?:https?:\/\/)?([a-z0-9]+\.)?(?:cc\.com)\/(video-clips|video-collections|clips)\//i};_.each(d,function(d,e){b=a.match(d);if(!c&&b&&b.length)c=e;});return c;},isVineUrl:function(a){if(!a)return false;var b=a.match(/^(?:https?:\/\/)?(?:www\.)?(?:vine\.co)\/v\/(?:[a-z0-9]{10})/i);return(b&&b.length>0);},getYoutubeId:function(a){if(!a)return false;var b=a.match(/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/);return(b&&b.length>1)?b[1]:false;},getVimeoId:function(a){if(!a)return false;var b=a.match(/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/);return(b&&b.length>2)?b[3]:false;},formatTimeObject:function(a){var b=Math.floor(a/(60*60));var c=(a%(60*60));var d=Math.floor(c/60);var e=Math.ceil(c%60);var f={h:b,m:d,s:e};return f;},formatTime:function(a){a=a||0;var b=Math.floor(a/3600);var c=Math.floor(a%3600/60);var d=Math.floor(a%3600%60);var e=(b>0)?[b,c,d]:[c,d];var f=_.map(e,function(a){return(a<10)?'0'+a:a;});return f.join(':');},fitFrameArrayToLength:function(a,b){if(_.isEmpty(a)||!b||a.length===b)return a;var c=[];var d=b>a.length?Math.round(b/a.length):1;var e=b/d;var f=_.range(0,a.length,a.length/e);_.each(f,function(b){var d=a[Math.floor(b)];if(d)c.push(d);});if(d>1){var g=_.clone(c);for(var h=1;h<d;h++)c=c.concat(g);}return _.first(c,b);},padNumber:function(a,b){return('000000000'+a).substr(-b);},formatNumberString:function(a){a=a||0;a+='';x=a.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var b=/(\d+)(\d{3})/;while(b.test(x1))x1=x1.replace(b,'$1'+','+'$2');return x1+x2;},hexToRgb:function(a){if(!a)return;var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return b?{r:parseInt(b[1],16),g:parseInt(b[2],16),b:parseInt(b[3],16)}:null;},rgbToHsl:function(a,b,c){a/=255;b/=255;c/=255;var d=Math.max(a,b,c),e=Math.min(a,b,c);var f,g,h=(d+e)/2;if(d==e)f=g=0;else{var i=d-e;g=h>0.5?i/(2-d-e):i/(d+e);switch(d){case a:f=(b-c)/i+(b<c?6:0);break;case b:f=(c-a)/i+2;break;case c:f=(a-b)/i+4;break;}f/=6;}return [f,g,h];},hslToRgb:function(a,b,c){var d,e,f;if(b===0)d=e=f=c;else{var g=function(a,b,c){if(c<0)c+=1;if(c>1)c-=1;if(c<1/6)return a+(b-a)*6*c;if(c<1/2)return b;if(c<2/3)return a+(b-a)*(2/3-c)*6;return a;};var h=c<0.5?c*(1+b):c+b-c*b;var i=2*c-h;d=g(i,h,a+1/3);e=g(i,h,a);f=g(i,h,a-1/3);}return [d*255,e*255,f*255];}};var b=3000;window.showSuccess=function(a,c,d){if(typeof d!=='undefined')var e=d;else var e=b;var f=$("<div>");$(f).addClass("flash");$(f).addClass("success");$(f).text(a);$("#messages").html(f);setTimeout(function(){if(typeof c!=='undefined')document.location.pathname=c;f.fadeOut('slow');},e);};window.showFancyMessage=function(a,b){var c=$("<div>");$(c).addClass("flash");$(c).addClass("fancy");$(c).text(a);$("#messages").html(c);Giphy.Utils.fadeMessages(b);};window.showError=function(a,b){b=b||5000;var c=$("<div>");$(c).addClass("flash");$(c).addClass("error");$(c).text(a);$("#messages").html(c);Giphy.Utils.fadeMessages(b);};})(window,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{maxBlocks:5,items:[]},events:{'click .left-arrow':'__previousClick','click .right-arrow':'__nextClick','click .item':'__itemClick'},elements:{'$items':'.item-wrapper','$previous':'.left-arrow','$next':'.right-arrow'},__previousClick:function(a){a.preventDefault();this.previous();},__nextClick:function(a){a.preventDefault();this.next();},__itemClick:function(){},_renderItems:function(a){a=a||false;this.$el.toggleClass('is-previous',a).toggleClass('is-next',!a).toggleClass('pink',(this.page+1)%2===0).toggleClass('purple',(this.page+1)%3===0);var b=this.page*this.blocks;var c=Math.min(b+this.blocks,this.itemCount);var d=this.options.items.slice(b,c);this._renderItemContent(d);},_renderItemContent:function(b){if(a.isEmpty(b))return;this.$items.empty();a.each(b,function(a,b){this.$items.eq(b).html(this.itemTemplate(a));},this);},initialize:function(){this.page=0;this.totalPages=1;this.blocks=this.options.maxBlocks;this.itemCount=a.size(this.options.items);},renderComplete:function(){if(a.isEmpty(this.options.items))return;this.blocks=Math.min(this.options.maxBlocks,this.itemCount);this.totalPages=Math.ceil(this.itemCount/this.blocks);this.$el.addClass('carousel').attr('data-total',this.blocks).toggleClass('no-nav',this.totalPages<2).html(this.template({blocks:this.blocks}));this.cacheSelectors();this._renderItems();},next:function(){if(this.totalPages<2)return;this.page++;if(this.page>this.totalPages-1)this.page=0;this._renderItems();},previous:function(){if(this.totalPages<2)return;this.page--;if(this.page<0)this.page=this.totalPages-1;this._renderItems(true);},template:a.template(['<div class="carousel-nav left-arrow inactive"><i class="ss-icon ss-navigateleft"></i></div>','<div class="items">','<% for (var i = 0; i < blocks; i++) { %>','<div class="item-wrapper"></div>','<% }; %>','</div>','<div class="carousel-nav right-arrow inactive"><i class="ss-icon ss-navigateright"></i></div>'].join('')),itemTemplate:a.template(['<div class="item"></div>'].join(''))});b.Carousel=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{emojis:false,multiline:false},events:{'keydown':'__keydown','paste':'__paste','input':'__input','blur':'__blur','keyup':'__input'},__keydown:function(a){if(!this.options.multiline&&a.which===13){a.preventDefault();a.stopPropagation();return false;}},__blur:function(a){var b=this.$el.html();b=b.replace(/<(?!img\s*\/?)[^>]+>/g,'');if(!b.length){this.$el.html('').addClass('empty');this.currentHtml="";this.$el.trigger('inputelement:input');}},__paste:function(a){a.preventDefault();a.stopPropagation();a=a.originalEvent||a;var b=a.clipboardData.getData('text/plain');if(b.length){b=b.replace(/<(?!i\s*\/?)[^>]+>/g,'');this._pasteAtCaret(b);this.$el.trigger('input');}return false;},__input:function(){var a=this.$el.html();this.$el.toggleClass('empty',!a.length);if(a===this.currentHtml)return;if(this.options.emojis&&emojione){var b=$('<div></div>').html(a);b.find('.emojione').each(function(){$(this).attr('data-rendered',true);});var c=emojione.toImage(b.html());b.html(c);if(b.find('.emojione:not([data-rendered])').length){this.$el.html(c);var d=this.$el.find('.emojione:not([data-rendered])').last();this._setCaretToElement(d.get(0));}}this.currentHtml=this.$el.html();this.$el.trigger('inputelement:input');},_setCaretToElement:function(a){var b=document.createRange();b.setStartAfter(a);b.setEndAfter(a);var c=window.getSelection();c.removeAllRanges();c.addRange(b);},_pasteAtCaret:function(a,b){if(!window.getSelection)return;var c,d;b=b||0;c=window.getSelection();if(c.getRangeAt&&c.rangeCount){d=c.getRangeAt(0);if(b){var e=d.cloneRange();e.setStart(d.startContainer,d.startOffset-b);e.setEnd(d.startContainer,d.startOffset);e.deleteContents();}d.deleteContents();var f=document.createElement("div");f.innerHTML=a;var g=document.createDocumentFragment(),h,i;while((h=f.firstChild))i=g.appendChild(h);d.insertNode(g);if(i){d=d.cloneRange();d.setStartAfter(i);d.collapse(true);c.removeAllRanges();c.addRange(d);}}},initialize:function(){this.currentHtml="";this.isPaste=false;if(emojione)emojione.unicodeAlt=false;this.$el.attr({autocomplete:'off',autocorrect:'off',autocapitalize:'off',spellcheck:'false'});if(!this.$el.html().length)this.$el.addClass('empty');document.execCommand('insertBrOnReturn',false,"false");}});b.GiphyInputElement=c;})(_,Giphy);(function(a,b){var c=function(a){a=a||{};this._configure(a);};c.prototype={__mousedown:function(a){a.preventDefault();this.offset.x=this.$el.offset().left;this.offset.width=this.$el.width();this._startDrag();this.__mousemove(a);},__mouseup:function(a){a.preventDefault();this._stopDrag();},__mousemove:function(a){var b=Math.ceil(a.pageX-this.offset.x);if(b>=0&&b<=this.offset.width)this.updatePercent(b/this.offset.width);},__keydown:function(a){if(a.which===37||a.which===39){a.preventDefault();a.stopPropagation();var b=a.shiftKey?0.1:0.01;b*=(a.which===37)?-1:1;this.incrementValue(b);return false;}if(a.which===38||a.which===40){a.preventDefault();a.stopPropagation();var b=a.shiftKey?10:1;b*=(a.which===40)?-1:1;this.incrementValue(b);return false;}},__updateTime:function(b,c){if(a.isEmpty(c))return;if(c.min)this.minValue=c.min;if(c.max)this.maxValue=c.max;this.updateValue(c.value||this.currentValue,true);},__updateValue:function(b,c){if(a.isUndefined(c))return;this.updateValue(c);},__updatePercent:function(b,c){if(a.isUndefined(c))return;this.updatePercent(c);},__incrementValue:function(a,b){if(!b)return;this.incrementValue(b);},_startDrag:function(){this.$el.trigger('sliderstart');this.$slider.addClass('dragging');this.$body.on('mousemove.giphyslider',a.bind(this.__mousemove,this));this.$body.on('mouseup.giphyslider',a.bind(this.__mouseup,this));this.$doc.on('mouseleave.giphyslider',a.bind(this.__mouseup,this));this.$slider.focus();},_stopDrag:function(){this.$el.trigger('sliderstop');this.$slider.removeClass('dragging');this.$body.off('.giphyslider');this.$doc.off('.giphyslider');},_configure:function(a){this.$el=$(a.el);this.options=a;this.offset={x:0,width:0};this.value=a.value||0;this.minValue=a.minValue||0;this.maxValue=a.maxValue||1;this.isReverse=a.reverse||false;this.isAnimated=a.animated||false;},_cacheSelectors:function(){this.$doc=$(document);this.$body=$('body');this.$slider=this.$el.find('.giphy-slider');this.$fill=this.$el.find('.fill');this.$time=this.$el.find('.time');},render:function(){if(!this.$el.length)return;this.$el.html(this.template());this._cacheSelectors();this.currentValue=this.value||this.minValue;this.currentPercent=0;this.$slider.attr('tabindex',1);if(!this.isAnimated)this.$el.find('.stripes').remove();this.$el.on('mousedown.giphyslider',a.bind(this.__mousedown,this));this.$el.on('slidervalue.giphyslider',a.bind(this.__updateValue,this));this.$el.on('sliderpercent.giphyslider',a.bind(this.__updatePercent,this));this.$el.on('sliderincrement.giphyslider',a.bind(this.__incrementValue,this));this.$el.on('update.giphyslider',a.bind(this.__updateTime,this));this.$el.on('reset.giphyslider',a.bind(this.resetValue,this));this.$slider.on('keydown.giphyslider',a.bind(this.__keydown,this));this.resetValue();return this;},incrementValue:function(a){if(!a)return;this.updateValue(this.currentValue+a);},updatePercent:function(a){a=a||0;a=Math.min(a,1);a=Math.max(a,0);this.updateValue(this.minValue+(a*(this.maxValue-this.minValue)));},updateValue:function(b,c){b=b||this.currentValue;b=Math.min(this.maxValue,b);b=Math.max(this.minValue,b);this.currentValue=b;this.currentPercent=(b-this.minValue)/(this.maxValue-this.minValue);this.$time.text(this.currentValue.toFixed(2));this.$fill.width(Math.round(this.currentPercent*100)+'%');this.$el.trigger('sliderupdate',{percent:this.isReverse?1-this.currentPercent:this.currentPercent,value:this.isReverse?this.maxValue-this.currentValue:this.currentValue});if(!c){this.$slider.addClass('updated');setTimeout(a.bind(this.$slider.removeClass,this.$slider,'updated'),50);}},resetValue:function(){this.currentValue=this.value;this.minValue=this.options.minValue||0;this.maxValue=this.options.maxValue||1;this.updateValue(this.currentValue,true);},remove:function(){this.$el.off('.giphyslider');this.$slider.off('.giphyslider');this.$el.empty();},template:a.template(['<div class="giphy-slider">','<div class="fill">','<div class="stripes-wrapper">','<div class="stripes"></div>','</div>','<div class="dragger">','<div class="grip"></div>','<div class="time"></div>','</div>','</div>','</div>'].join(""))};b.GiphySlider=c;})(_,Giphy);(function(a,b){var c=function(a){this._configure(a);};a.extend(c.prototype,b.GiphySlider.prototype,{_cacheSelectors:function(){b.GiphySlider.prototype._cacheSelectors.call(this);this.$slower=this.$el.find('.speed-container.slower');this.$faster=this.$el.find('.speed-container.faster');},_stopDrag:function(){b.GiphySlider.prototype._stopDrag.call(this);this.$slower.removeClass('active');this.$faster.removeClass('active');},updateValue:function(a,c){var d=this.currentValue;var e=0;b.GiphySlider.prototype.updateValue.call(this,a,c);e=this.$fill.width();this.$slower.toggleClass('active',this.currentValue<d).width(e);this.$faster.toggleClass('active',this.currentValue>d).width(this.$el.width()-e);},template:a.template(['<div class="giphy-slider speed-slider">','<div class="speed-container slower">','<div class="speed-label">Slower</div>','</div>','<div class="fill">','<div class="dragger">','<div class="grip"></div>','</div>','</div>','<div class="speed-container faster">','<div class="speed-label">Faster</div>','</div>','</div>'].join(""))});b.GiphySpeedSlider=c;})(_,Giphy);(function(a,b){var c=function(a){this._configure(a);};a.extend(c.prototype,b.GiphySlider.prototype,{__updateDuration:function(a,b){this.updateDuration(b);},_configure:function(a){b.GiphySlider.prototype._configure.call(this,a);this.duration=a.duration||0;},_cacheSelectors:function(){b.GiphySlider.prototype._cacheSelectors.call(this);this.$duration=this.$el.find('.duration');},render:function(){b.GiphySlider.prototype.render.call(this);this.$el.on('sliderduration.giphyslider',a.bind(this.__updateDuration,this));},updateValue:function(c,d){c=c||this.currentValue;if(c+this.duration>this.maxValue)c=this.maxValue-this.duration;b.GiphySlider.prototype.updateValue.call(this,c,d);var e=a.last(this.currentValue.toFixed(2).split('.'));var f=b.Utils.formatTime(this.currentValue);f+='<span class="milliseconds">.'+e+'</span>';this.$time.html(f);},updateDuration:function(a){a=a||0;a=Math.min(a,this.maxValue);a=Math.max(a,0);this.duration=a;var b=this.duration/this.maxValue;var c=Math.ceil(this.$el.width()*b);this.$duration.width(c);this.$time.css('left',c);this.updateValue(this.currentValue,true);},resetValue:function(){this.updateDuration(this.options.duration||0);b.GiphySlider.prototype.resetValue.call(this);},template:a.template(['<div class="giphy-slider time-slider">','<div class="fill">','<div class="duration stripes-wrapper">','<div class="stripes"></div>','</div>','<div class="dragger">','<div class="grip"></div>','<div class="time"></div>','</div>','</div>','</div>'].join(""))});b.GiphyTimeSlider=c;})(_,Giphy);(function(a,b){var c=function(a){this._configure(a);};a.extend(c.prototype,b.GiphyTimeSlider.prototype,{$playhead:null,playheadValue:0,_startDrag:function(){this.setPlayheadValue(0);b.GiphyTimeSlider.prototype._startDrag.call(this);},_stopDrag:function(){b.GiphyTimeSlider.prototype._stopDrag.call(this);},setPlayheadValue:function(a){this.playheadValue=a;this.$playhead.css('left',a+'%');},getPlayheadValue:function(){return this.playheadValue;},cacheSelectors:function(){this.$playhead=this.$el.find('.playhead');},render:function(){b.GiphyTimeSlider.prototype.render.call(this);this.cacheSelectors();this.$el.on('sliderplayhead.giphyslider',a.bind(function(a,b){this.setPlayheadValue(b);},this));},template:a.template(['<div class="giphy-slider">','<div class="fill">','<div class="playhead"></div>','<div class="stripes-wrapper">','<div class="stripes"></div>','</div>','<div class="dragger">','<div class="grip"></div>','<div class="time"></div>','</div>','</div>','</div>'].join(""))});b.GiphyVideoPlayheadSlider=c;})(_,Giphy);(function(a,b){var c={views:{'slider':'GiphySlider','time-slider':'GiphyTimeSlider','speed-slider':'GiphySpeedSlider','video-playhead-slider':'GiphyVideoPlayheadSlider','input-element':'GiphyInputElement'},initialize:function(a){a=a||{};this.$elements=$('*[data-ui]');this.subviews=[];this.render();return this;},render:function(){if(!this.$elements.length)return;a.each(this.$elements,function(c){var d=$(c);var e=d.data();if(e.ui&&a.has(this.views,e.ui)){var f=this.views[e.ui];var g=a.omit(e,'ui');var h=b[f];if(h){var i=a.extend(g,{el:d});this.subviews.push(new h(i).render());}}},this);},remove:function(){a.each(this.subviews,function(a){a.remove();});this.subviews={};}};b.GiphyUI=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({globalEvents:{'captionstyle:updateanimation':'__updateAnimation'},defaults:{duration:0,frameCount:0,canvas:'',maxFrames:20},__updateAnimation:function(a,c){this.animationName=c||'';b.Events.trigger('captionlayer:animating',this.animationName.length&&this.animationName!=='none');},_none:function(a){this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedContext.drawImage(this.canvas,a.left,a.top);},_wave:function(a,b){var c=this.animatedCanvas.width/30;var d=Math.PI*2;var e=-d*a;this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedContext.save();for(var f=0;f<this.animatedCanvas.width;f++){var g=(f/this.animatedCanvas.width)*d;var h=Math.sin(g+e)*c;this.animatedContext.drawImage(this.canvas,f,0,1,this.canvas.height,b.left+f,b.top+h,1,this.canvas.height);}this.animatedContext.restore();},_glitter:function(b,c){if(!a.has(this.animationAssets,'bling')||!a.has(this.animationAssets,'sparkles'))return;var d=this.context.createPattern(this.animationAssets.bling,'repeat');var e=this.context.createPattern(this.animationAssets.sparkles,'repeat');var f=Math.round(100*Math.random());var g=Math.round(100*Math.random());this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedContext.drawImage(this.canvas,c.left,c.top);this.animatedContext.save();this.animatedContext.globalCompositeOperation='source-atop';this.animatedContext.fillStyle=d;this.animatedContext.translate(f,g);this.animatedContext.fillRect(-f,-g,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedContext.translate(-f,-g);this.animatedContext.globalCompositeOperation='screen';this.animatedContext.drawImage(this.canvas,c.left,c.top);f=Math.round(150*Math.random());g=Math.round(150*Math.random());this.animatedContext.globalCompositeOperation='source-atop';this.animatedContext.fillStyle=e;this.animatedContext.translate(f,g);this.animatedContext.fillRect(-f,-g,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedContext.translate(-f,-g);this.animatedContext.restore();},_glitch:function(a,b){this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);if(Math.random()<0.8&&Math.round(a*10)!==5){this.animatedContext.drawImage(this.canvas,b.left,b.top);return;}var c=Math.random()*(13-1)+1;var d=this.animatedCanvas.width;var e=this.canvas.height;for(var f=0;f<c;f++){var g=d*Math.random()*0.4;var h=e*Math.random();var i=d-g;var j=e/3;j=Math.random()*(j-5)+5;this.animatedContext.drawImage(this.canvas,0,h,i,j,b.left+g,b.top+h,i,j);this.animatedContext.drawImage(this.canvas,i,h,g,j,b.left,b.top+h,g,j);}},_blink:function(a,b){this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);if(Math.round(a*10)>4)this.animatedContext.drawImage(this.canvas,b.left,b.top);},_preloadAnimationAssets:function(){var c={bling:'/static/img/creation_tools/fx/bling.png',sparkles:'/static/img/creation_tools/fx/sparkles.png'};b.Utils.preloadImage(a.values(c)).done(a.bind(function(){var b=a.keys(c);for(var d=0;d<arguments.length;d++)this.animationAssets[b[d]]=arguments[d];},this));},initialize:function(){this.$canvas=$(this.options.canvas);this.loops=Math.round(this.options.frameCount/this.options.maxFrames);this.totalFrames=this.options.frameCount/(this.loops>1?this.loops:1);this.animationName='';this.animationAssets={};},renderComplete:function(){if(!this.$canvas.length)return;this.canvas=this.$canvas.get(0);this.context=this.canvas.getContext('2d');this.animatedCanvas=document.createElement('canvas');this.animatedContext=this.animatedCanvas.getContext('2d');this.animatedContext.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height);this.animatedCanvas.className='animated-caption-canvas';this.$el.css('width','100%');this.$canvas.css('opacity',0);this.$canvas.after(this.animatedCanvas);this._preloadAnimationAssets();},draw:function(a){if(!this.context)return;this.animatedContext.clearRect(0,0,this.animatedCanvas.width,this.animatedCanvas.height);this.animatedCanvas.width=this.$el.width();this.animatedCanvas.height=this.$el.height();var b=(a/this.totalFrames)%1;var c=this.$canvas.position();switch(this.animationName){case 'wave':this._wave(b,c);break;case 'glitter':this._glitter(b,c);break;case 'glitch':this._glitch(b,c);break;case 'blink':this._blink(b,c);break;default:this._none(c);break;}},getFrameData:function(b){if(!this.canvas)return;this.draw(b);var c=a.extend(this.$el.position(),{canvas:this.animatedCanvas});return c;}});b.GifCanvasCaptionLayer=c;})(_,Giphy);(function(a,b,c){var d={overlayCanvas:document.createElement('canvas'),colors:{blue:c.Utils.hexToRgb('#23cefd'),green:c.Utils.hexToRgb('#2afd9c'),purple:c.Utils.hexToRgb('#9840fb'),red:c.Utils.hexToRgb('#fc6769'),pink:c.Utils.hexToRgb('#e646b6')},_colorize:function(a,c){if(!a||!b||!c)return;var d=a.getContext('2d');var e=d.getImageData(0,0,a.width,a.height);var f=this.overlayCanvas.getContext('2d');b.grayscale.filter(e);b.contrast.filter(e,{amount:1.1});var g=e.data;for(var h=0;h<g.length;h+=4){g[h]=c.r*g[h]/255;g[h+1]=c.g*g[h+1]/255;g[h+2]=c.b*g[h+2]/255;}d.putImageData(e,0,0);},greyscale:function(a){if(!a||!b)return;var c=a.getContext('2d');var d=c.getImageData(0,0,a.width,a.height);var e=this.overlayCanvas.getContext('2d');b.sepia.filter(d,{amount:30});b.contrast.filter(d,{amount:1.1});b.brightness.filter(d,{amount:0.1});b.grayscale.filter(d);c.putImageData(d,0,0);},invert:function(a){if(!a)return;var c=a.getContext('2d');var d=c.getImageData(0,0,a.width,a.height);b.invert.filter(d);c.putImageData(d,0,0);},blue:function(a){this._colorize(a,this.colors.blue);},green:function(a){this._colorize(a,this.colors.green);},purple:function(a){this._colorize(a,this.colors.purple);},red:function(a){this._colorize(a,this.colors.red);},pink:function(a){this._colorize(a,this.colors.pink);},yellow:function(a){this._colorize(a,this.colors.yellow);},kaleidoscope:function(a){if(!a||!b)return;var c=a.getContext('2d');var d=c.getImageData(0,0,a.width,a.height);b.kaleidoscope.filter(d,{sides:5});c.putImageData(d,0,0);},toast:function(a){if(!a||!b)return;var c=a.getContext('2d');var d=c.getImageData(0,0,a.width,a.height);var e=this.overlayCanvas.getContext('2d');var f=a.width*0.5;b.contrast.filter(d,{amount:1.2});b.brightness.filter(d,{amount:-0.1});e.clearRect(0,0,this.overlayCanvas.width,this.overlayCanvas.height);this.overlayCanvas.width=a.width;this.overlayCanvas.height=a.height;var g=e.createRadialGradient(f,f,0,f,f,f);g.addColorStop(0,'#804e0f');g.addColorStop(1,'#3b003b');e.save();e.putImageData(d,0,0);e.fillStyle=g;e.globalCompositeOperation='screen';e.fillRect(0,0,a.width,a.height);e.restore();c.save();c.globalCompositeOperation='source-atop';c.drawImage(this.overlayCanvas,0,0);c.restore();},sunset:function(a){if(!a)return;var c=a.getContext('2d');var d=c.getImageData(0,0,a.width,a.height);var e=this.overlayCanvas.getContext('2d');b.contrast.filter(d,{amount:1.1});b.brightness.filter(d,{amount:0.05});b.saturation.filter(d,{amount:1.3});e.clearRect(0,0,this.overlayCanvas.width,this.overlayCanvas.height);this.overlayCanvas.width=a.width;this.overlayCanvas.height=a.height;e.save();e.putImageData(d,0,0);e.fillStyle='rgba(243, 106, 188, 0.3)';e.globalCompositeOperation='screen';e.fillRect(0,0,a.width,a.height);e.restore();c.save();c.globalCompositeOperation='source-atop';c.drawImage(this.overlayCanvas,0,0);c.restore();}};c.GifCanvasFilters=d;})(_,JSManipulate,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{fps:10,image:'',minFrames:10,maxFrames:60},globalEvents:{'giphytest:creategif':'__testCreate','giphytest:addgif':'__addImageLayer','captionpreview:add':'__addCaption','captionpreview:remove':'__removeCaption','captionlayer:animating':'__captionLayerAnimating','gifcanvas:addlayer':'__addImageLayer','gifcanvas:removelayer':'__removeLayer','gifcanvas:toggleoverlayfilter':'__toggleOverlayFilter','gifcanvas:filter':'__addFilter'},elements:{$base:'.gif-base-layer',$overlays:'.gif-overlays'},__testCreate:function(){this.createGif(true);},__addCaption:function(a,c){if(!c)return;this.captionLayer=new b.GifCanvasCaptionLayer({el:c.getResizeElement(),frameCount:this.utils.getBaseFrames(),canvas:c.getCanvas()});this.layers.push(this.captionLayer.render());this._checkIfAnimating();},__removeCaption:function(){if(!this.captionLayer)return;this.layers=a.without(this.layers,this.captionLayer);this.captionLayer.remove();this.captionLayer=null;this.isCaptionAnimating=false;this._checkIfAnimating();},__addImageLayer:function(a,b,c){this.addImageLayer(b,c);},__removeLayer:function(b,c){if(!c)return;if(a.isFunction(c.remove))c.remove();this.layers=a.without(this.layers,c);this._checkIfAnimating();},__toggleOverlayFilter:function(b,c){this.isFilteringOverlays=a.isBoolean(c)?c:!this.isFilteringOverlays;a.each(this.layers,function(b){if(a.isFunction(b.setFilter))b.setFilter.call(b,'');});this._applyFilter();},__addFilter:function(a,b){this.currentFilter=b||'';this._applyFilter();},__captionLayerAnimating:function(a,b){this.isCaptionAnimating=b;this._checkIfAnimating();},_applyFilter:function(){var b=this.isFilteringOverlays?this.layers.length:1;for(var c=0;c<b;c++){var d=this.layers[c];if(d&&a.isFunction(d.setFilter))d.setFilter.call(d,this.currentFilter);}this._checkIfAnimating();},_renderLayer:function(c){if(a.isEmpty(c))return;var d=this.layers.length<1;var e=this.utils.downsampleFrames(c.frames,Math.max(c.duration,1));var f=new b.GifCanvasLayer(a.extend(c,{container:this.$el,duration:c.duration,filter:this.isFilteringOverlays?this.currentFilter:null,frames:e,isOverlay:!d,isInteractive:!d}));if(d){this.$el.removeClass('loading');this.$base.append(f.render().el);b.Events.trigger('gifcanvas:ready');}else this.$overlays.append(f.render().el);this.layers.push(f);if(d&&!this.$el.hasClass('processing'))this._startDrawing();this._checkIfAnimating();},_checkIfAnimating:function(){var c=0;var d=this.$overlays.children();a.each(this.layers,function(b){if(a.isFunction(b.getDuration)){var d=b.getDuration.call(b);if(c<d)c=d;}});if(!d.length&&!this.captionLayer&&!this.currentFilter)b.Events.trigger('gifcanvas:animating',false,true);else b.Events.trigger('gifcanvas:animating',!!(c>1||this.isCaptionAnimating),false);},_startDrawing:function(){this._stopDrawing();this.isDrawing=true;this.drawInterval=setInterval(a.bind(this.draw,this),1000/this.options.fps);},_stopDrawing:function(){clearInterval(this.drawInterval);this.isDrawing=false;},initialize:function(){this.drawInterval=null;this.layers=[];this.captionLayer=null;this.currentFilter='';this.currentFrame=0;this.isDrawing=false;this.isCaptionAnimating=false;this.isFilteringOverlays=false;this.utils=new b.GifCanvasUtils({fps:this.options.fps,minFrames:this.options.minFrames,maxFrames:this.options.maxFrames});},render:function(){this.$el.html(this.template());return b.BaseView.prototype.render.call(this,arguments);},renderComplete:function(){if(this.options.image){this.$el.addClass('loading');this.addImageLayer(this.options.image);b.Events.trigger('gifcanvas:loading');}},draw:function(){if(!this.layers.length)return;a.each(this.layers,function(b){if(a.isFunction(b.draw))b.draw(this.currentFrame);},this);this.currentFrame++;if(this.currentFrame>=this.utils.getBaseFrames())this.currentFrame=0;},addImageLayer:function(c,d){if(!c)return;this.utils.processImage(c).done(a.bind(function(a){this._renderLayer(a);b.Events.trigger('gifcanvas:imageadded',c,d);},this));},createGif:function(b){var c=$.Deferred();var d=this.utils.getBaseFrames();if(a.isUndefined(GIF))c.reject('GIF JS is required!');else if(d<2)c.reject('GIF is not animating!');else{this._stopDrawing();this.currentFrame=0;this.$el.addClass('processing');var e=this.$('.caption-resize');var f=this.$('.caption-canvas');var g=this.$el.width();var h=this.$el.height();var i=new GIF({background:'#000',workers:(navigator&&navigator.hardwareConcurrency)?navigator.hardwareConcurrency:4,workerScript:'/static/js/site/no_compile/gif.worker.js',quality:10,height:h,width:g});for(var j=0;j<d;j++){var k=[];for(var l=0;l<this.layers.length;l++)k.push(this.layers[l].getFrameData(j));i.addFrame(this.utils.combineCanvasLayers(k,g,h),{delay:1000/this.options.fps});}i.on('finished',a.bind(function(a){c.resolve(a);this._startDrawing();if(b)window.open(URL.createObjectURL(a));},this));a.defer(a.bind(i.render,i));}return c.promise();},remove:function(){this._stopDrawing();this.$el.empty();a.each(this.layers,function(a){a.remove();});this.layers=[];this.utils.remove();return b.BaseView.prototype.remove.call(this,arguments);},template:a.template(['<div class="gif-base-layer"></div>','<div class="gif-overlays"></div>'].join(''))});b.GifCanvas=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({className:'gif-layer-wrapper',defaults:{container:'',duration:0,filter:'',frames:[],height:1,still:'',width:1,isOverlay:false,isInteractive:true},events:{'mousedown':'__mousedown','click .remove-button':'__removeClick'},elements:{$canvas:'.gif-layer-canvas'},__removeClick:function(a){a.preventDefault();b.Events.trigger('gifcanvas:removelayer',this);},__mousedown:function(b){if(!this.options.isInteractive)return;var c=this.$el.offset();this.dragPosition={left:b.pageX-c.left,top:b.pageY-c.top,width:this.$container.width(),height:this.$container.height(),isResizing:$(b.target).hasClass('dragger')};this.$el.addClass('dragging');this.$body.on('mousemove.gif-canvas-layer',a.bind(this.__mousemove,this));this.$body.on('mouseup.gif-canvas-layer',a.bind(this.__mouseup,this));},__mousemove:function(a){if(!this.options.isInteractive)return;var b;if(this.dragPosition.isResizing){b=this.$el.offset();var c=a.pageX-b.left;this.resize(c+5);}else{b=this.$container.offset();var d=a.pageX-b.left-this.dragPosition.left;var e=a.pageY-b.top-this.dragPosition.top;this.move(d,e,this.dragPosition.width,this.dragPosition.height);}},__mouseup:function(a){if(!this.options.isInteractive)return;this.$el.removeClass('dragging');this.$body.off('.gif-canvas-layer');},_center:function(){var a=this.$el.width();var b=this.$el.height();if(!a||!b)return;this.dimensions.width=a;this.dimensions.height=b;this.$el.css({left:(this.$container.width()-a)*0.5,top:(this.$container.height()-b)*0.5});},_applyFilter:function(){if(a.isFunction(this.filters[this.currentFilter]))this.filters[this.currentFilter].call(this.filters,this.canvas);},_drawFrameData:function(a,b,c){if(!a)return;this.bufferCanvas.width=b||this.canvas.width;this.bufferCanvas.height=c||this.canvas.height;this.bufferContext.clearRect(0,0,this.canvas.width,this.canvas.height);this.bufferContext.putImageData(a,0,0);this.context.drawImage(this.bufferCanvas,0,0,this.canvas.width,this.canvas.height);},initialize:function(){this.$body=$('body');this.$container=$(this.options.container);this.aspectRatio=this.options.width/this.options.height;this.frames=this.options.frames;this.bufferCanvas=document.createElement('canvas');this.bufferContext=this.bufferCanvas.getContext('2d');this.dragPosition={};this.dimensions={};this.renderedFrames={};this.currentFilter=this.options.filter;this.filters=b.GifCanvasFilters;},render:function(){if(a.isEmpty(this.frames))return;this.$el.toggleClass('overlay-draggable',this.options.isInteractive).append(this.template({isInteractive:this.options.isInteractive}));this.cacheSelectors();if(this.$canvas.length){this.canvas=this.$canvas.get(0);this.context=this.canvas.getContext('2d');this.canvas.width=this.options.isOverlay?Math.min(this.options.width,this.$container.width()):this.$container.width();this.canvas.height=this.canvas.width/this.aspectRatio;if(this.options.isOverlay&&this.canvas.height>this.$container.height()){this.canvas.height=this.$container.height();this.canvas.width=this.canvas.height*this.aspectRatio;}}a.defer(a.bind(function(){this._center();if(!this.options.isOverlay&&a.size(this.options.frames))b.Events.trigger('gifcanvas:baselayerready',this,a.sample(this.options.frames));},this));return this;},draw:function(b){if(!this.canvas||!this.context)return;var c;this.context.clearRect(0,0,this.canvas.width,this.canvas.height);this.canvas.width=this.dimensions.width||this.$el.width();this.canvas.height=this.dimensions.height||this.$el.height();if(a.has(this.renderedFrames,'frame'+b)){c=this.renderedFrames['frame'+b];this._drawFrameData(c.data,c.width,c.height);return;}c=this.frames[b];if(!a.isEmpty(c)){if(a.has(c,'image'))this.context.drawImage(c.image,0,0,this.canvas.width,this.canvas.height);else this._drawFrameData(c.data,c.width,c.height);if(this.currentFilter)this._applyFilter();this.renderedFrames['frame'+b]={data:this.context.getImageData(0,0,this.canvas.width,this.canvas.height),width:this.canvas.width,height:this.canvas.height};}},resize:function(a,b,c){if(!a)return;var d=this.$el.position();var e=0;b=b||this.$container.width();c=c||this.$container.height();a=Math.min(a,b-d.left);e=a/this.aspectRatio;if(d.top+e>c){e=c-d.top;a=e*this.aspectRatio;}this.dimensions.width=a;this.dimensions.height=e;this.$el.css(this.dimensions);},move:function(a,b,c,d){a=a||0;b=b||0;c=c||this.$container.width();d=d||this.$container.height();a=Math.max(a,0);a=Math.min(a,c-this.$el.width());b=Math.max(b,0);b=Math.min(b,d-this.$el.height());this.$el.css({left:a,top:b});},setFilter:function(a){this.renderedFrames={};this.currentFilter=a||'';},getFrameData:function(b){if(!this.canvas||!this.context)return;this.draw(b);var c=a.extend(this.$el.position(),{canvas:this.canvas});return c;},getDuration:function(){return this.options.duration;},remove:function(){b.BaseView.prototype.remove.call(this,arguments);this.$body.off('.gif-canvas-layer');this.$el.remove();return this;},template:a.template(['<canvas class="gif-layer-canvas"></canvas>','<% if (isInteractive) { %>','<div class="dragger"></div>','<div class="remove-button button red"><i class="ss-icon ss-delete"></i></div>','<% } %>'].join(''))});b.GifCanvasLayer=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{fps:10,baseFrames:0,minFrames:10,maxFrames:60,imageProxyUrl:'//i.giphy.com/fetch?gif='},initialize:function(){this.baseFrames=this.options.baseFrames;},combineCanvasLayers:function(b,c,d){if(a.isEmpty(b))return;var e=document.createElement('canvas');var f=e.getContext('2d');e.width=c||480;e.height=d||360;a.each(b,function(a){f.drawImage(a.canvas,a.left,a.top);});return e;},downsampleFrames:function(c,d){if(a.isEmpty(c)||!d)return c;var e=d/1000;var f=Math.min(c.length/e,this.options.fps);var g=e*f;var h=b.Utils.fitFrameArrayToLength(c,Math.min(Math.floor(g),this.options.maxFrames));if(this.baseFrames>0)h=b.Utils.fitFrameArrayToLength(h,this.baseFrames);else{var i=Math.round(this.options.minFrames/h.length);this.baseFrames=(h.length<this.options.minFrames)?h.length*i:h.length;h=b.Utils.fitFrameArrayToLength(h,this.baseFrames);}return h;},processImage:function(b){var c=$.Deferred();if(a.isString(b))this.processImageUrl(b).done(c.resolve);else if(a.isObject(b))this.processImageFile(b).done(c.resolve);else c.reject();return c.promise();},processImageFile:function(c){var d=$.Deferred();if(!c||!c.type)d.reject('Not an image file.');else{var e=new FileReader();var f=c.type;if(f.indexOf('gif')>-1){e.onloadend=a.bind(function(){var a=new Uint8Array(e.result);b.GifParser.loadBinary(a).done(d.resolve);},this);e.readAsArrayBuffer(c);}else{e.onloadend=a.bind(function(){this.processImageUrl(e.result).done(d.resolve);},this);e.readAsDataURL(c);}}return d.promise();},processImageUrl:function(a){var c=$.Deferred();var d=b.Utils.urlRE.exec(a);if(a.indexOf('base64')>-1)b.Utils.preloadImage(a).done(function(a){c.resolve({duration:0,height:a.naturalHeight,frames:[{image:a}],width:a.naturalWidth});});else if(d.length&&d.length>1){var e=d[1];var f=b.Utils.getExtension(e);if(e.indexOf('giphy.com')<0)e=this.options.imageProxyUrl+e.replace(/.*?:\/\//g,"");if(f==='gif')b.GifParser.loadUrl(e).done(c.resolve);else b.Utils.preloadImage(e).done(function(a){c.resolve({duration:0,height:a.naturalHeight,frames:[{image:a}],width:a.naturalWidth});});}else c.reject();return c.promise();},resetBaseFrames:function(){this.baseFrames=0;},getBaseFrames:function(){return this.baseFrames;}});b.GifCanvasUtils=c;})(_,Giphy);(function(a,b){var c=b.Carousel.extend({className:'gif-explorer-featured carousel',defaults:a.extend({},b.Carousel.prototype.defaults,{autoSearch:true}),globalEvents:{'gifexplorer:search':'__search'},__itemClick:function(a){a.preventDefault();var b=$(a.currentTarget).data();this._searchTag(b.tag);},__search:function(a,b){this.currentSearch=b;this.$items.each(function(a,c){var d=$(c).find('.item');var e=d.data();d.toggleClass('selected',e.tag===b);});},_searchTag:function(a){if(!a)return;b.Events.trigger('gifexplorer:search',a);},_renderItemContent:function(b){this.$items.empty();a.each(b,function(b,c){this.$items.eq(c).html(this.itemTemplate(a.extend(b,{isSelected:this.currentSearch===b.tag})));},this);},initialize:function(){b.Carousel.prototype.initialize.call(this);this.currentSearch='';},renderComplete:function(){b.Carousel.prototype.renderComplete.call(this);if(this.options.autoSearch)a.defer(a.bind(this._searchTag,this,this.options.items[0].tag));},itemTemplate:a.template(['<div class="item<% if (isSelected) { %> selected<% } %>" data-tag="<%- tag %>">','<div class="item-image" style="background-image:url(<%- gif %>)"></div>','<div class="item-label">','<span class="item-label-text"><%- title %></span>','</div>','</div>'].join(''))});b.GifExplorerFeatured=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{featured:[],isStickerSearch:false,placeholder:null},globalEvents:{'gifexplorer:search':'__search'},__search:function(c,d){if(!d)return;if(a.has(this.subviews,'results'))this.subviews.results.remove();if(this.options.isStickerSearch&&d.indexOf('sticker')<0)d+=' sticker';this.subviews.results=new b.GifExplorerResults({searchTerm:d});this.$el.append(this.subviews.results.render().el);a.delay(a.bind(this._scrollToResults,this),100);},_scrollToResults:function(){var a=this.$('.gif-explorer-results');if(a.length)$('html, body').animate({scrollTop:a.offset().top-20},250);},initialize:function(){this.$el.addClass('gif-explorer');this.render();},renderSubviews:function(){if(this.isRendered)return;a.each(this.subviews,function(b){if(a.isFunction(b.render)&&!b.isRendered)this.$el.append(b.render().el);},this);this.$el.children().toggleClass('is-sticker',this.options.isStickerSearch);},renderComplete:function(){this.subviews.input=new b.GifExplorerInput();if(!a.isEmpty(this.options.featured))this.subviews.featured=new b.GifExplorerFeatured({items:this.options.featured});this.renderSubviews();}});b.GifExplorer=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({className:'gif-explorer-input',defaults:{placeholder:'Search on GIPHY'},events:{'input .big-input':'__input','keydown .big-input':'__keydown','click .search-button':'__searchClick'},globalEvents:{'gifexplorer:search':'__search'},elements:{$input:'.big-input',$button:'.search-button'},__input:function(){var a=this.$input.val();this.$button.toggleClass('active',!!a.trim().length);},__search:function(a,b){if(b&&b.indexOf('giphy')!==0)this.$input.val(b.replace('-',' '));else this.$input.val('');},__keydown:function(a){if(a.which===13){a.preventDefault();a.stopPropagation();this._triggerSearch();return false;}},__searchClick:function(a){a.preventDefault();this._triggerSearch();},_triggerSearch:function(){var a=this.$input.val().trim();var c=this.$button.hasClass('active');if(a.length&&c){this.$button.removeClass('active');b.Events.trigger('gifexplorer:search',a.toLowerCase());}},render:function(){this.$el.html(this.template({placeholder:this.options.placeholder}));b.BaseView.prototype.render.call(this,arguments);return this;},template:a.template(['<div class="gif-explorer-input">','<input class="big-input" type="text" placeholder="<%- placeholder %>" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />','<button class="search-button" type="button"><i class="ss-icon ss-search"></i></button>','</div>'].join(''))});b.GifExplorerInput=c;})(_,Giphy);(function(a,b){var c=function(a){this.initialize(a);};c.prototype={initialize:function(a){this.options=a||{};this.url=String(this.options.url||'/search').replace(/\/$/,'');this.term=String(this.options.term||'').replace(' ','-');this.page=this.options.page||1;this.total=0;this.gifs={};this.isRequesting=false;this.isFinished=false;},get:function(b){if(b)return a.clone(this.gifs[b]);else return a.clone(this.gifs);},getTotal:function(){return this.total||a.size(this.gifs);},isEmpty:function(){return a.isEmpty(this.gifs.length);},fetch:function(){if(this.isRequesting||this.isFinished)return;var c=this.url+'/'+this.term+'/'+this.page;c=c.replace(' ','-');b.Events.trigger('gifexplorermodel:fetch');var d=$.ajax({url:c+'?is=1',type:'GET',data:{json:true},success:a.bind(this.parse,this),error:a.bind(function(){this.isRequesting=false;b.Events.trigger('gifexplorermodel:error');},this)});this.isRequesting=true;},parse:function(c){this.isRequesting=false;this.page++;if(!c||!a.has(c,'data')||!a.has(c.data,'gifs'))return;var d=c.data;if(a.isEmpty(d.gifs)){this.isFinished=true;return;}if(a.has(d,'count')){var e=d.count.replace(',','');this.total=parseInt(e,10);}var f=this.term.replace('-',' ').replace('sticker','').toLowerCase().trim();var g=["sticker","transparent","transparency","youtube","tumblr","myspace","pinterest","twitter","gay","fat","fuck","shit","png","gif","images","reaction",f];a.each(d.gifs,function(b){var c=b.id;var d=b.is_hidden;var e=a.reject(b.tags,function(a){var b=false;a=a.toLowerCase().trim();for(var c=0;c<g.length;c++)if(a===g[c]||a.indexOf(g[c])>-1)b=true;return a.length<3||a.length>12||b;});b.hovertag=a.first(e)||(f.indexOf('giphy')<0?f:"animated gif");if(!this.gifs[c]&&!d)this.gifs[c]=b;},this);b.Events.trigger('gifexplorermodel:change',d.gifs);}};b.GifExplorerModel=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({defaults:{gifs:{}},events:{'scroll':'__scroll','click .gif-explorer-result':'__resultClick'},__resultClick:function(a){a.preventDefault();var c=$(a.currentTarget);var d=c.find('.result-gif');var e=d.data();b.Events.trigger('gifexplorer:resultclick',c,e.animated);},__scroll:a.throttle(function(c){var d=this.$el.scrollTop();var e=this.$el.height()*3;var f=d>=(this.$el.get(0).scrollHeight-e);if(f)b.Events.trigger('gifexplorer:infinitescroll');clearTimeout(this.scrollTimeout);this.scrollTimeout=setTimeout(a.bind(this.animateGifs,this),100);},50),_animateGif:function(a){if(!a)return;var b=$(a);var c=b.data();b.attr('src',c.animated);},initialize:function(){this.scrollTimeout=null;this.resultHeight=0;this.containerHeight=0;this.columnCount=0;this.animatingStartIndex=0;this.animatingEndIndex=0;this.$results=$();},renderComplete:function(){if(!a.isEmpty(this.options.gifs))this.addGifs(this.options.gifs);},addGifs:function(b){if(a.isEmpty(b))return;this.$el.append(this.template({gifs:b}));this.$results=this.$('.gif-explorer-result');this.$resultGifs=this.$('.result-gif');var c=this.$results.first();this.resultHeight=Math.round(c.outerHeight());this.containerHeight=Math.round(this.$el.outerHeight());this.columnCount=Math.floor(this.$el.width()/c.width());this.animateGifs();},pauseGifs:function(){this.$resultGifs.each(a.bind(function(a,b){if(a<this.animatingStartIndex||a>=this.animatingEndIndex){var c=$(b);var d=c.data();c.attr('src',d.still);}},this));},animateGifs:function(){var c=Math.ceil(this.$el.scrollTop()/this.resultHeight)-1;var d=c+Math.ceil(this.containerHeight/this.resultHeight);this.animatingStartIndex=c*this.columnCount;this.animatingEndIndex=d*this.columnCount;this.pauseGifs();for(var e=this.animatingStartIndex;e<this.animatingEndIndex;e++){var f=this.$resultGifs.eq(e);if(f.length){var g=f.data('animated');if(f.attr('src')!==g)b.Utils.preloadImage(g).done(a.bind(this._animateGif,this,f));}}},template:a.template(['<% _.each(gifs, function(gif) { %>','<div id="<%- gif.id %>" class="gif-explorer-result">','<img class="result-gif" src="<%- gif.images.fixed_height_still.url %>" ','data-still="<%- gif.images.fixed_height_still.url %>" ','data-animated="<%- gif.images.fixed_height.url %>" />','<div class="result-hover">','<div class="result-hover-label">Click to add','<span class="result-tag"><%- gif.hovertag %></span>','</div>','</div>','<div class="progress-bar">','<div class="process-complete"><i class="ss-icon ss-check"></i></div>','</div>','</div>','<% }); %>'].join(''))});b.GifExplorerResultsGrid=c;})(_,Giphy);(function(a,b){var c=b.BaseView.extend({className:'gif-explorer-results',defaults:{searchTerm:''},globalEvents:{'gifexplorermodel:change':'__modelChange','gifexplorer:infinitescroll':'__infiniteScroll'},elements:{$label:'.gif-explorer-label',$grid:'.gif-explorer-grid'},__modelChange:function(b,c){if(!this.gridView||a.isEmpty(c))return;this.$el.removeClass('loading');this._renderHeader();this.gridView.addGifs(c);},__infiniteScroll:function(){if(this.model.isRequesting||this.model.isFinished)return;this._getMoreGifs();},_renderHeader:function(){var a=this.model.getTotal();var c=this.isSticker?'sticker':'GIF';var d=String(this.options.searchTerm||'').replace('-',' ').toLowerCase();if(d!=='giphy'&&d.indexOf('giphy')===0)d=d.substr(5);if(d.indexOf(' sticker')>-1)d=d.replace(' sticker','');if(parseInt(a,10)!==1)c+='s';this.$label.html(this.headerTemplate({count:b.Utils.formatNumberString(a),label:c,term:d}));},_getMoreGifs:function(){this.$el.addClass('loading');this.model.fetch();},initialize:function(){this.isSticker=this.options.searchTerm.indexOf('sticker')>-1;this.model=new b.GifExplorerModel({term:this.options.searchTerm});},render:function(){this.$el.html(this.template()).toggleClass('sticker-results',this.isSticker);return b.BaseView.prototype.render.call(this,arguments);},renderComplete:function(){this._renderHeader();this.gridView=new b.GifExplorerResultsGrid({el:this.$grid,gifs:this.model.get()});if(this.model.isEmpty())this._getMoreGifs();},remove:function(){if(this.gridView)this.gridView.remove();b.BaseView.prototype.remove.call(this,arguments);this.$el.remove();},template:a.template(['<div class="gif-explorer-label-wrapper">','<div class="gif-explorer-label"></div>','</div>','<div class="gif-explorer-grid"></div>'].join('')),headerTemplate:a.template('<%-count %> <%-label %> found for <span class="search-term"><%- term %></span>')});b.GifExplorerResults=c;})(_,Giphy);(function(a,b){var c={_queue:[],isLoading:false,_loadNext:function(){var c=a.first(this._queue);if(a.isEmpty(c))return;this.isLoading=true;a.each(c,function(a){var c=$(a);var d=c.data();if(a.src!==d.still)b.Utils.preloadImage(d.still).done(function(){a.src=d.still;c.closest('.waiting').removeClass('waiting');});},this);this._queue=a.without(this._queue,c);if(this._queue.length)this._loadNext();else this.isLoading=false;},queue:function(b){if(a.isEmpty(b))return;b=a.isArray(b)?b:[b];this._queue.unshift(b);if(!this.isLoading)this._loadNext();}};b.GifGridImages=c;})(_,Giphy);(function(a,b){var c=function(a){this.initialize(a);};c.prototype={__scroll:a.throttle(function(){var b=this.$win.scrollTop();var c=b-this.previousScrollY;this.previousScrollY=b;this.pagination.update();clearTimeout(this.loadImageDelay);if(Math.abs(c)<120)this._loadImages();else this.loadImageDelay=setTimeout(a.bind(this._loadImages,this),160);if(!this.isRequesting&&!this.isFinished){var d=this.$el.offset().top+this.$el.height();var e=2+Math.floor(c/200);d-=this.windowHeight*e;if(b>d)this.model.fetch();}},150),__resize:function(a){this.windowHeight=window.innerHeight;this.requestThresholdOffset=this.windowHeight*2;},__modelFetch:function(){this.$el.addClass('loading');},__modelFetchComplete:function(){this.$el.removeClass('loading');},__modelChange:function(c,d){this.$el.removeClass('loading').append(this.template(a.extend(d,{colorPlaceholders:this.colorPlaceholders})));a.defer(a.bind(function(){b.Images.sizeImages();b.Images.attachHovers();this.$rows=this.$el.find('.hoverable');},this));this.isFinished=d.isFinished||false;this.pagination.addNewPage(d.page,this.$el.offset().top+this.$el.height());this._updateGifRouter();this.__scroll();},_loadImages:function(){var b=this.$win.scrollTop();var c=300;var d=b-c;var e=b+this.windowHeight+c;var f=[];this.$rows.each(a.bind(function(a,b){var c=$(b);var g=c.offset().top;var h=c.height();if(g+h>d&&g<e)c.find('.waiting img.gifs-gif').each(function(){f.push(this);});},this));this.imageQueue.queue(f);},_updateGifRouter:function(){if(!b.GifRouter)return;var c=[];this.$el.find('img.gifs-gif').each(function(a,b){var d=$(b);c.push({id:b.id,url:d.data('url')||d.closest('a.gif').attr('href'),preview:d.data('animated')});});b.GifRouter.setMoreGifs(a.last(c,500));},_configure:function(){this.url=this.options.url||window.location.pathname;this.windowHeight=window.innerHeight;this.requestThreshold=this.options.requestThreshold||0.6;this.requestThresholdOffset=this.windowHeight*2;this.previousScrollY=0;this.loadImageDelay=null;this.isFinished=false;this.isRendered=false;this.colorPlaceholders=['data:image/gif;base64,R0lGODlhAQABAPAAAOZGtv///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==','data:image/gif;base64,R0lGODlhAQABAPAAAGFX/////yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==','data:image/gif;base64,R0lGODlhAQABAPAAAADmzP///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==','data:image/gif;base64,R0lGODlhAQABAPAAADGR/////yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==','data:image/gif;base64,R0lGODlhAQABAPAAAP/zXP///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='];this.imageQueue=b.GifGridImages;this.pagination=b.GifGridPagination.initialize({url:this.url});this.model=b.GifGridModel.initialize({url:this.url,gifCount:this.$el.find('.gif').length});},_cacheSelectors:function(){this.$win=$(window);this.$doc=$(document);this.$rows=this.$el.find('.hoverable');},initialize:function(b){this.options=b||{};this.$el=$(this.options.el||'');this._configure();$(document).one('images:tv_placed images:no_tv',a.bind(this.render,this));},render:function(){if(this.isRendered||!this.$el.length)return;this._cacheSelectors();this.$win.on('scroll.gif-grid',a.bind(this.__scroll,this));this.$win.on('resize.gif-grid',a.bind(this.__resize,this));if(this.$el.offset().top+this.$el.height()<this.$win.height())this.model.fetch();b.Events.on('gifgridmodel:change',this.__modelChange,this);b.Events.on('gifgridmodel:fetch',this.__modelFetch,this);b.Events.on('gifgridmodel:parse',this.__modelFetchComplete,this);b.Events.on('gifgridmodel:error',this.__modelFetchComplete,this);this.isRendered=true;},template:a.template(['<% _.each(gifs, function(gif) { %>','<% var color = _.sample(colorPlaceholders) %>','<li class="ungrouped">','<div class="hoverable-gif waiting">','<% if (gif.is_hidden) { %>','<a class="is-private" href="<%- gif.url.replace("http://giphy.com", "").replace("https://giphy.com", "") %>"><i class="ss-icon ss-lock"></i></a>','<% } %>','<a data-id="<%- gif.id %>" class="gif-link a-gif favable gif" href="<%- gif.url.replace("http://giphy.com", "").replace("https://giphy.com", "") %>">','<figure>','<img nopin="nopin" ','data-width="<%- gif.images.fixed_height.width %>" ','data-height="<%- gif.images.fixed_height.height %>" ','data-animated="<%- gif.images.fixed_height.url %>" ','data-still="<%- gif.images.fixed_height_still.url %>" ','data-color="<%- color %>" ','id="<%- gif.id %>" ','class="gifs-gif unloaded" ','src="<%- color %>" />','<figcaption></figcaption>','</figure>','</a>','<% if (!_.isEmpty(gif.tags)) { %>','<span class="caption tags">','<% _.each(gif.tags, function(tag) { %>','<a data-tag-encoded="<%- tag %>" class="tag" href="/search/<%- tag %>"><span class="hashtag">#</span><%- tag %>&nbsp;</a>','<% }); %>','</span>','<% } %>','<span class="loader"></span>','</div>','</li>','<% }); %>'].join(''))};b.GifGrid=c;})(_,Giphy);(function(a,b){var c={initialize:function(a){a=a||{};this.url=(a.url||'/page').replace(/\/$/,'');this.page=a.page||2;this.gifCount=a.gifCount||0;this.isRequesting=false;this.isFinished=false;return this;},set:function(a,b){if(!a)return;this[a]=b||null;},get:function(b){if(!b||!a.has(this,b))return;return this[b];},fetch:function(){if(this.isRequesting||this.isFinished)return;var c=this.url+'/'+this.page;b.Events.trigger('gifgridmodel:fetch');var d=$.ajax({url:c+'?is=1',type:'GET',data:{json:true},success:a.bind(this.parse,this),error:a.bind(function(){this.isRequesting=false;b.Events.trigger('gifgridmodel:error');},this)});this.isRequesting=true;},parse:function(c){this.isRequesting=false;b.Events.trigger('gifgridmodel:parse');if(a.isEmpty(c)||!c.data)return;if(a.has(c.data,'count')||a.has(c.data,'gif_count')){var d=a.has(c.data,'gif_count')?c.data.gif_count:c.data.count;if(a.isString(d))d=parseInt(d.replace(',',''),10);if(this.gifCount>=d)this.isFinished=true;}if(!a.isEmpty(c.data.gifs)){var e=this.page;this.gifCount+=a.size(c.data.gifs);this.page++;b.Events.trigger('gifgridmodel:change',a.extend({},c.data,{isFinished:this.isFinished,page:e}));}}};b.GifGridModel=c;})(_,Giphy);(function(a,b){var c={initialize:function(a){a=a||{};this.$win=$(window);this.url=(a.url||window.location.pathname).replace(/\/$/,'');this.currentPage=a.currentPage||0;this.pageOffsets={};this.seenPages=[];return this;},addNewPage:function(a,c){if(!a)return;if(c)this.pageOffsets[a]=c;if(b.UserEdit&&window.ADD_EDIT_JS===true)b.UserEdit.addEditGifLinks();b.Analytics.fireEvents(this.url+'/'+a,true);},update:function(){if(!window.history)return;var b=this.$win.scrollTop();var c=0;var d=this.url;var e=false;a.each(this.pageOffsets,function(a,d){if(b>=a)c=d;});if(c===this.currentPage)return;if(c>1)d+='/'+c;window.history.replaceState("","",d);window.CURRENT_PAGE=c;window.OFFSET_PAGE=window.CURRENT_PAGE-1;this.currentPage=c;}};b.GifGridPagination=c;})(_,Giphy);$(function(){$(document).ready(function(){if(!$(".gif-detail").length>0)return;if(Giphy.GifDetail)Giphy.GifDetail.initialize();});});$(function(){$(document).ready(function(){if($(".fb_container").length===0)Giphy.Etc.checkLogin({success:function(){var a=$("#default-nav");if(a.length)$.get("/ajax/userheader/?parent="+location.href,function(a){$("#default-nav").replaceWith(a);$("#default-nav").show();Giphy.UserEdit.userSettingsInit();var b=$("#login-button");if(b.length&&window.LOGIN_NEXT){var c=b.attr("href");b.attr("href",c+"?next="+window.LOGIN_NEXT);}var d=Giphy.Utils.getParameterByName('ref');if(d=='fave'){var e=$("#share-heart");if(e.length)e.trigger('click');}});}});Giphy.Globals.initialize();if(Giphy.UserChannel)Giphy.UserChannel.initialize();Giphy.Images.preloadImages();Giphy.Backgrounds.setRandomBackground();Giphy.Login.facebook();Giphy.Favorites.nav();Giphy.Search.init();Giphy.Search.initMini();Giphy.Browsebar.init();Giphy.Browsebar.attachBrowsebarHovers();Giphy.Images.attachHovers();Giphy.Images.sizeImagesToFrame();if(Giphy.Utils.getParameterByName('hideLogo')=='true')Giphy.Utils.hideLogo();if(Giphy.Utils.getParameterByName('status')&&Giphy.Utils.getParameterByName('message')){var a={"uploaded":"GIF uploaded successfully! It's been added to your channel page.","welcome":"Welcome To Giphy!","login":"You are now logged in.","userexists":"That email address has already been registered. Did you forget your password?","twautherror":"Looks like Twitter is experiencing technical difficulties. Please try again.","fbautherror":"Looks like Facebook is experiencing technical difficulties. Please try again.","gifdeleted":"Your GIF has been deleted."},b=Giphy.Utils.getParameterByName('message');if(parseInt(Giphy.Utils.getParameterByName('status'),10)==200)(b==='welcome')?showFancyMessage(a[b],5000):showSuccess(a[b]);else showError(a[b]);}});});$(function(){$(document).ready(function(){if(!$("#homepage").length>0)return;Giphy.Nav.share();Giphy.Nav.attachFooter();Giphy.Homepage.init();});});(function(a,b){var c={__mouseover:function(a){var b=$(a.currentTarget);var c=b.find('.onboarding-background');if(c.length){c.addClass('hovering');this._setVideoSpeed(c,1);}},__mouseout:function(a){var b=$(a.currentTarget);var c=b.find('.onboarding-background');if(c.length){c.removeClass('hovering');this._setVideoSpeed(c,this.videoSpeed);}},_setVideoSpeed:function(a,b){b=b||this.videoSpeed;var c=$(a).find('video');if(c.length)c.get(0).playbackRate=b;},initialize:function(a){a=a||{};this.$el=$(a.el||'.onboarding-container');this.artistGifs=a.artistGifs||[];this.partnerGifs=a.partnerGifs||[];this.videoSpeed=a.videoSpeed||0.3;this.render();},cacheSelectors:function(){this.$artistCreate=this.$el.find('.artist-create');this.$partnerCreate=this.$el.find('.partner-create');},render:function(){if(!this.$el.length)return;this.cacheSelectors();if(this.artistGifs.length){var b=a.sample(this.artistGifs);this.$artistCreate.append(this.template(b));this._setVideoSpeed(this.$artistCreate,this.videoSpeed);}if(this.partnerGifs.length){var b=a.sample(this.partnerGifs);this.$partnerCreate.append(this.template(b));this._setVideoSpeed(this.$partnerCreate,this.videoSpeed);}this.$el.on('mouseover.join-apply','.onboarding .inner',$.proxy(this.__mouseover,this));this.$el.on('mouseout.join-apply','.onboarding .inner',$.proxy(this.__mouseout,this));},remove:function(){this.$el.off('.join-apply');},template:a.template('<div class="onboarding-background">                <video class="background-video" poster="<%- images.original_still.url %>" src="<%- images.original.mp4 %>" loop autoplay>                    <div class="background-image" style="background-image:url(<%- images.original.url %>)"></div>                </video>            </div>')};b.JoinApply=c;})(_,Giphy);$(function(){$(document).ready(function(){if(!$("#user-login").length>0)return;Giphy.Login.loginFocus();});});$(function(){$(document).ready(function(){if(!$(".post-content").length>0)return;Giphy.Sharing.shortURLs();Giphy.Sharing.attachShareTools();Giphy.Sharing.attachSharingAnalytics();Giphy.Overlays.addOverlayToGifDetail();Giphy.Overlays.sizeFSOverlay();$('.post-content iframe').each(function(){var a=parseInt($(this).css('width').replace('px',''));var b=parseInt($(this).css('height').replace('px',''));var c=643;var d=(c*b)/a;$(this).css('height',d+'px');$(this).css('width',c+'px');});var a=document.URL.split('posts');a.shift();var b=a.join('posts').split('?')[0].replace('/','').replace('#','');var c="/posts/related/gifs/"+b;var d=$("#post-detail").data("post_id");var e="/posts/related/posts/"+d;e=e.replace("//","/");$(document).on('scroll',function(){$("iframe").each(function(){var a=document.createElement('a');a.href=$(this).attr('src');if(a.protocol==document.location.protocol&&a.hostname==document.location.hostname){var b=$(this).contents().find('#gif');if(($(this).offset().top<=$(window).height()+$(window).scrollTop())&&($(this).offset().top+$(this).height()>=$(window).scrollTop())){if($(b).attr('src')!=$(b).attr('data-animated'))$(b).attr('src',$(b).attr('data-animated'));}else if($(b).attr('src')!=$(b).attr('data-still'))$(b).attr('src',$(b).attr('data-still'));}});});});});$(function(){$(document).ready(function(){var a=$("#searchresults");if(!a.length>0)return;Giphy.Analytics.trackSearchResultsView();if(!a.hasClass('favorites')&&!a.hasClass('channel-private'))var b=new Giphy.GifGrid({el:a.find('.gifs')});else Giphy.SearchResults.attachInfiniteScroll();Giphy.Images.sizeImages();Giphy.Images.attachHovers();});});