CL.Views.Region=Backbone.View.extend({initialize:function(){var view=this;this.state=this.options.state;this.currentRegion=this.state.get("page").get("regions")[this.id];this.options.animationDuration=this.options.animationDuration||250;this.objects=[];this.setup();this.state.on("change:page",function(){view.render();});},render:function(){var view=this,region=this.state.get("page").get("regions")[this.id];if(!this.state.get("renderlessNavigate")){this.applyHTML(region,function(){view.tearDown();view.setup();});} this.currentRegion=region;},applyHTML:function(region,success){this.$el.html(region.html);success&&success();},setup:function(){var view=this;$(".centered-image-container",this.$el).each(function(){var obj=new CL.Views.CenteredImageContainer({el:$(this)});view.objects.push(obj);});$(".collapsing-block",this.$el).each(function(){var obj=new CL.ToggleBlock($(this));view.objects.push(obj);});$(".dropdown",this.$el).each(function(){var obj=new CL.Views.Dropdown($(this));view.objects.push(obj);});$(".gallery-simple",this.$el).each(function(){var obj=new CL.Views.SimpleGallery({"el":$(this),});view.objects.push(obj);});$(".gallery-fullscreen",this.$el).each(function(){var obj=new CL.Views.FullscreenGallery({"el":$(this)});view.objects.push(obj);});$(".gallery-featured",this.$el).each(function(){var obj=new CL.Views.FeaturedGallery({"el":$(this)}).render();view.objects.push(obj);});$("header#page-header",this.$el).each(function(){var obj=new CL.Views.Header({"el":$(this)});view.objects.push(obj);});$("a.back-to-top",this.$el).each(function(){var obj=new CL.Views.BackToTop({"el":$(this)});view.objects.push(obj);});$("header#page-subheader",this.$el).each(function(){var obj=new CL.Views.Subheader({"el":$(this)});view.objects.push(obj);});$(".floating-action-container",this.$el).each(function(){var obj=new CL.Views.FloatingActionContainer({"el":$(this),"referenceID":$(this).data("reference-id")});view.objects.push(obj);});$(".media-list",this.$el).each(function(){var obj=new CL.Views.MediaList({"el":$(this)});view.objects.push(obj);});$(".mini-lightbox",this.$el).each(function(){var obj=new CL.Views.MiniLightbox({"el":$(this),"id":$(this).data("lightbox-id"),"templateID":$(this).data("lightbox-template")});view.objects.push(obj);});$(".photo-lightbox",this.$el).each(function(){var obj=new CL.Views.PhotoLightbox({"el":$(this),"id":$(this).data("lightbox-id"),"templateID":$(this).data("lightbox-template")});view.objects.push(obj);});$(".map",this.$el).each(function(){var obj=new CL.Views.Map({"el":$(this),"locations":$(this).data("locations")});view.objects.push(obj);});$("ul.separated-index",this.$el).each(function(){var obj=new CL.Views.Stream({"el":$(this)});view.objects.push(obj);});$('.wte').each(function(){var $this=$(this),address=$this.data('address'),decoded;if(address){var decoded=address.replace(/ at /g,'@').replace(/ dot /g,'.');$this.after(""+decoded+"");$this.remove();}});window.picturefill();setTimeout(function(){$(".media-list img",view.$el).attr("style","");},500);this.scanLocalLinks();},tearDown:function(){_.each(this.objects,function(object){object.tearDown&&object.tearDown();});this.objects=[];},scanLocalLinks:function(){var view=this;if(CL.router&&(true||CL.vars.environment=="PRODUCTION"||CL.vars.environment=="STAGING")){$("a[rel=internal][prefetch]",this.$el).each(function(){var url=CL.utilities.getRelativePath($(this).attr("href")),page=view.options.pages.getOrCreatePage(url);page.getOrFetchHTML();view.options.pages.push(page);});}}});CL.Views.HeaderRegion=CL.Views.Region.extend({id:"header"});CL.Views.SubheaderRegion=CL.Views.Region.extend({id:"subheader",applyHTML:function(region,success){var view=this,$oldSubheader=$("#page-subheader",this.$el),$newSubheader=$("#page-subheader",$("
").html(region.html));if(!$oldSubheader.length){$newSubheader.appendTo(this.$el).css({"opacity":0,"margin-top":-1*$newSubheader.outerHeight(true)}).transitionStop().transition({"opacity":1,"margin-top":0});}else if(!$newSubheader.length){$oldSubheader.transitionStop().transition({"opacity":0,"margin-top":-1*$oldSubheader.outerHeight(true)},function(){$oldSubheader.remove();});}else if($oldSubheader.length&&$newSubheader.length){this.$el.html(region.html);} success&&success();}});CL.Views.ActionsRegion=CL.Views.Region.extend({id:"actions",applyHTML:function(region,success){var oldKind=this.currentRegion.options.kind,kind=region.options.kind,view=this;if(oldKind&&kind&&(oldKind===kind)){var $oldActions=$(".floating-action-container",this.$el),$newActions=$(".floating-action-container",$("
").html(region.html)),newNextURL=$("li.next a",$newActions).attr("href"),newPrevURL=$("li.prev a",$newActions).attr("href");$("li.next a",$oldActions).attr("href",newNextURL);$("li.prev a",$oldActions).attr("href",newPrevURL);}else if(kind&&oldKind){if(CL.utilities.isMobile()){this.$el.html(region.html);}else{var before={opacity:0},after={opacity:1} this.$el.transition(before).show().transition(after);} success&&success();}else if(kind){var wait=750,$newActions;this.$el.hide().html(region.html);$newActions=$(".floating-action-container",this.$el).css({opacity:0});this.$el.show();setTimeout(function(){$(window).trigger("resize");$newActions.transition({opacity:1});},wait);success&&success();}else if(oldKind){this.$el.fadeOut();success&&success();}}});CL.Views.FiltersRegion=CL.Views.Region.extend({id:"filters",applyHTML:function(region,success){var oldKind=this.currentRegion.options.kind,kind=region.options.kind;if(oldKind&&kind&&oldKind==kind){this.updateDropdowns(region);}else if(oldKind&&kind){if(CL.utilities.isMobile()){this.$el.html(region.html);success&&success();}else{this.$el.transitionStop().transition({"opacity":0},function(){$(this).html(region.html).transitionStop().transition({"opacity":1});success&&success();});}}else if(oldKind){this.$el.transitionStop().transition({"opacity":0,"margin-top":-1*this.$el.outerHeight(true)},function(){$(this).empty().css({"margin-top":0});success&&success();});}else if(kind){this.$el.html(region.html).css({"opacity":0,"margin-top":-1*this.$el.outerHeight(true)}).transitionStop().transition({"opacity":1,"margin-top":0});success&&success();}},updateDropdowns:function(region){$(".dropdown",this.$el).each(function(){var $this=$(this),title=$(this).data("title"),$newDropdown=$(".dropdown[data-title="+title+"]",$("
").html(region.html));if($newDropdown.length&&$this.data("dropdown")){$this.data("dropdown").state.set({open:$newDropdown.hasClass("open"),activeItem:$("ul li.active a",$newDropdown).text()});}});},});CL.Views.BodyRegion=CL.Views.Region.extend({id:"body",applyHTML:function(region,success){var view=this,oldOptions=this.currentRegion.options,options=region.options,styles;this.options.slideDistance=8;if((oldOptions.type=="stream"&&options.type=="stream")&&(oldOptions.postType==options.postType)&&(oldOptions.pageNumber==(options.pageNumber-1))){this.appendStreamItemsFromMarkup(region);}else{if(CL.utilities.isMobile()){this.$el.html(region.html);this.scrollToTop();success&&success();}else{if((oldOptions.type=="grid"&&options.type=="grid")&&(oldOptions.postType==options.postType)){this.updateGridFromRegion(region);}else{styles={"enter":"drop","exit":"drop"} this.scrollToTop();if((oldOptions.type=="single"&&options.type=="single")&&(oldOptions.postType==options.postType)&&this.state.get("tempSlideDirection")){var transition=this.state.get("tempSlideDirection")=="next"?"slideLeft":"slideRight";_.extend(styles,{"enter":transition,"exit":transition});this.state.unset("tempSlideDirection");} if(oldOptions.type=="fullscreen"){_.extend(styles,{"exit":"fade"});} if(options.type=="fullscreen"){_.extend(styles,{"enter":"fade"});} this.animateCurrentBodyOut(styles.exit,function(){view.animateBodyIn(region,styles.enter);success&&success();});}}}},animateCurrentBodyOut:function(style,success){var $oldBody=$(".page-body",this.$el),transitions={before:{},after:{},duration:this.options.animationDuration};if(style){CL.utilities.lockWrapper();_.extend(transitions.after,{opacity:0});if(style=="slideLeft"){_.extend(transitions.after,{x:-4*this.options.slideDistance});}else if(style=="slideRight"){_.extend(transitions.after,{x:4*this.options.slideDistance});}else if(style=="drop"){_.extend(transitions.after,{y:4*this.options.slideDistance});}} if(transitions){$oldBody.css(transitions.before).transitionStop().transition(transitions.after,transitions.duration,function(){$(this).remove();success&&success();});}else{$oldBody.remove();success&&success();}},animateBodyIn:function(region,style){var $body=$(".page-body",$('
').html(region.html)),transitions={before:{},after:{},duration:this.options.animationDuration};if(style){_.extend(transitions.before,{opacity:0});_.extend(transitions.after,{opacity:1});if(style=="slideLeft"){_.extend(transitions.before,{x:8*this.options.slideDistance});_.extend(transitions.after,{x:0});}else if(style=="slideRight"){_.extend(transitions.before,{x:-8*this.options.slideDistance});_.extend(transitions.after,{x:0});}else if(style=="drop"){_.extend(transitions.before,{y:-8*this.options.slideDistance});_.extend(transitions.after,{y:0});} $body.css(transitions.before).appendTo(this.$el).transition(transitions.after,transitions.duration,function(){if(style){CL.utilities.unlockWrapper();$(window).trigger("resize");}});}else{this.$el.append($body);CL.utilities.unlockWrapper();} if($("section.level",this.$el).length>1){this.cascadeLevels();}},cascadeLevels:function(){var delay=0,sectionTransitions={"before":{"opacity":0},"after":{"opacity":1,},"duration":500,"delay":200};$("section.level",this.$el).each(function(){var $level=$(this);$(this).css(sectionTransitions.before).show();setTimeout(function(){$level.transition(sectionTransitions.after,sectionTransitions.duration);},delay);delay=delay+sectionTransitions.delay;});},updateGridFromRegion:function(region){var $list=$(".media-list",this.$el),$newList=$(".media-list",$("
").html(region.html)),mediaList=$list.data("media-list");if(mediaList){mediaList.state.set({"filterKey":$newList.data("filter-key"),"filterValue":$newList.data("filter-value")});}},appendStreamItemsFromMarkup:function(region){var $body=$(".page-body",$("
").html(region.html)),$oldStream=$("ul.separated-index",this.$el),$stream=$("ul.separated-index",$body);$stream.children("li").hide().appendTo($oldStream).fadeIn();if($(".next-posts-link a",$body).attr("href")){$(".next-posts-link a",this.$el).attr("href",$(".next-posts-link a",$body).attr("href"));}else{$(".next-posts-link a",this.$el).hide();} $(".page-body",this.$el).data("page-number",region.options.pageNumber);},scrollToTop:function(){$("html, body").animate({"scrollTop":0},200);}});CL.Views.LightboxesRegion=CL.Views.Region.extend({id:"lightboxes"});