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

1 line
7.3 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(){_.bindAll(this,"scroller"),this.window.bind("scroll",_.throttle(this.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),this.$el.append('<br class="clear"/>')},search:function(){var c,d=this;c=new b.view.Search({collection:d.collection}),c.render(),a("#wpbody h2:first").append(c.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("description"),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"),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()}),this.model.cid===this.model.collection.at(0).cid&&this.$el.find(".left").addClass("disabled"),this.model.cid===this.model.collection.at(this.model.collection.length-1).cid&&this.$el.find(".right").addClass("disabled")},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.par