WordPress/wp-admin/js/theme.min.js

1 line
6.6 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{},function(a){var b,c;b=wp.themes=wp.themes||{},b.data=_wpThemeSettings,c=b.data.l10n,_.extend(b,{model:{},view:{},routes:{},router:{},template:wp.template}),b.model=Backbone.Model.extend({}),b.view.Appearance=wp.Backbone.View.extend({el:"#wpbody-content .wrap .theme-browser",window:a(window),page:0,initialize:function(){var a=this;this.window.bind("scroll.themes",function(){this.throttle=!0}),setInterval(function(){this.throttle&&(this.throttle=!1,a.scroller())},300)},render:function(){this.view=new b.view.Themes({collection:this.collection,parent:this}),this.search(),this.view.render(),this.$el.append(this.view.el)},search:function(){var a,c=this;a=new b.view.Search({collection:c.collection}),a.render(),c.$el.append(a.el)},scroller:function(){var a,b,c=this;a=this.window.scrollTop()+c.window.height(),b=c.$el.offset().top+c.$el.outerHeight(!1)-c.window.height(),b=Math.round(.9*b),a>b&&this.trigger("theme:scroll")}}),b.Collection=Backbone.Collection.extend({model:b.model,terms:"",doSearch:function(a){this.terms=a,this.terms.length>0&&this.search(this.terms),""===this.terms&&this.reset(b.data.themes),this.trigger("update")},search:function(a){var c,d,e,f=this;f.reset(b.data.themes),a=a.replace(" ",")(?=.*"),c=new RegExp("^(?=.*"+a+").+","i"),d=f.filter(function(a){return e=_.union(a.get("name"),a.get("author"),a.get("tags")),c.test(a.get("author"))&&a.set("displayAuthor",!0),c.test(e)}),f.reset(d)},paginate:function(a){var b=this;return a=a||0,b=_(b.rest(15*a)),b=_(b.first(15))}}),b.view.Theme=wp.Backbone.View.extend({className:"theme",state:"grid",html:b.template("theme"),events:{click:"expand"},render:function(){var a=this.model.toJSON();this.$el.html(this.html(a)),this.activeTheme(),this.model.get("displayAuthor")&&this.$el.addClass("display-author")},activeTheme:function(){this.model.get("active")&&(this.$el.addClass("active"),this.$el.find(".theme-name").addClass("mp6-primary"),a(".theme-overlay").addClass("active"))},expand:function(b){var c=this;b=b||window.event,a(b.target).is(".theme-actions a, .delete-theme")||this.trigger("theme:expand",c.model.cid)}}),b.view.Details=wp.Backbone.View.extend({className:"theme-overlay",events:{click:"collapse","click .delete-theme":"deleteTheme","click .left":"previousTheme","click .right":"nextTheme"},html:b.template("theme-single"),render:function(){var a=this.model.toJSON();this.$el.html(this.html(a)),this.activeTheme(),this.navigation()},activeTheme:function(){this.$el.toggleClass("active",this.model.get("active"))},collapse:function(c){var d,e=this;c=c||window.event,(a(c.target).is(".theme-backdrop")||a(c.target).is("div.back")||27===c.keyCode)&&(a("body").addClass("closing-overlay"),this.$el.fadeOut(130,function(){a("body").removeClass("theme-overlay-open closing-overlay"),e.closeOverlay(),d=document.body.scrollTop,b.router.navigate(""),document.body.scrollTop=d}))},navigation:function(){var b=this;a("body").on("keyup",function(a){39===a.keyCode&&b.trigger("theme:next",b.model.cid),37===a.keyCode&&b.trigger("theme:previous",b.model.cid),27===a.keyCode&&b.collapse()})},closeOverlay:function(){this.remove(),this.unbind(),this.trigger("theme:collapse")},screenshotGallery:function(){var b,c,d=a("#theme-screenshots");d.find("div.first").next().addClass("selected"),d.on("click","div.thumb",function(){b=a(this),c=a(this).find("img").clone(),b.siblings(".first").html(c),b.siblings(".selected").removeClass("selected"),b.addClass("selected")})},deleteTheme:function(){return confirm(b.data.settings.confirmDelete)},nextTheme:function(){var a=this;a.trigger("theme:next",a.model.cid)},previousTheme:function(){var a=this;a.trigger("theme:previous",a.model.cid)}}),b.view.Themes=wp.Backbone.View.extend({className:"themes",index:0,count:a(".theme-count"),initialize:function(a){var b=this;this.parent=a.parent,this.setView("grid"),b.currentTheme(),this.listenTo(b.collection,"update",function(){b.parent.page=0,b.currentTheme(),b.render(this)}),this.listenTo(this.parent,"theme:scroll",function(){b.renderThemes(b.parent.page)})},render:function(){this.$el.html(""),this.rend