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

1 line
21 KiB
JavaScript
Raw Normal View History

var tb_position;window.wp=window.wp||{},function(o){var i,a=wp.themes=wp.themes||{};a.data=_wpThemeSettings,i=a.data.l10n,a.isInstall=!!a.data.settings.isInstall,_.extend(a,{model:{},view:{},routes:{},router:{},template:wp.template}),a.Model=Backbone.Model.extend({initialize:function(){var e;-1!==_.indexOf(a.data.installedThemes,this.get("slug"))&&this.set({installed:!0}),this.set({id:this.get("slug")||this.get("id")}),this.has("sections")&&(e=this.get("sections").description,this.set({description:e}))}}),a.view.Appearance=wp.Backbone.View.extend({el:"#wpbody-content .wrap .theme-browser",window:o(window),page:0,initialize:function(e){_.bindAll(this,"scroller"),this.SearchView=e.SearchView||a.view.Search,this.window.bind("scroll",_.throttle(this.scroller,300))},render:function(){this.view=new a.view.Themes({collection:this.collection,parent:this}),this.search(),this.view.render(),this.$el.empty().append(this.view.el).addClass("rendered"),this.$el.append('<br class="clear"/>')},searchContainer:o("#wpbody h2:first"),search:function(){var e;1!==a.data.themes.length&&((e=new this.SearchView({collection:this.collection,parent:this})).render(),this.searchContainer.append(o.parseHTML('<label class="screen-reader-text" for="wp-filter-search-input">'+i.search+"</label>")).append(e.el))},scroller:function(){var e=this,t=this.window.scrollTop()+e.window.height(),e=e.$el.offset().top+e.$el.outerHeight(!1)-e.window.height();Math.round(.9*e)<t&&this.trigger("theme:scroll")}}),a.Collection=Backbone.Collection.extend({model:a.Model,terms:"",doSearch:function(e){this.terms!==e&&(this.terms=e,0<this.terms.length&&this.search(this.terms),""===this.terms&&(this.reset(a.data.themes),o("body").removeClass("no-results")),this.trigger("update"))},search:function(t){var i,e,s,r,n;this.reset(a.data.themes,{silent:!0}),t=(t=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")).replace(/ /g,")(?=.*"),i=new RegExp("^(?=.*"+t+").+","i"),0===(e=this.filter(function(e){return s=e.get("name").replace(/(<([^>]+)>)/gi,""),r=e.get("description").replace(/(<([^>]+)>)/gi,""),n=e.get("author").replace(/(<([^>]+)>)/gi,""),n=_.union(s,e.get("id"),r,n,e.get("tags")),i.test(e.get("author"))&&2<t.length&&e.set("displayAuthor",!0),i.test(n)})).length?this.trigger("query:empty"):o("body").removeClass("no-results"),this.reset(e)},paginate:function(e){var t=this;return e=e||0,t=_(t.rest(20*e)),t=_(t.first(20))},count:!1,query:function(t){var e,i,s,r=this.queries,n=this;if(this.currentQuery.request=t,e=_.find(r,function(e){return _.isEqual(e.request,t)}),(i=_.has(t,"page"))||(this.currentQuery.page=1),e||i){if(i)return this.apiCall(t,i).done(function(e){n.add(e.themes),n.trigger("query:success"),n.loadingThemes=!1}).fail(function(){n.trigger("query:fail")});0===e.themes.length?n.trigger("query:empty"):o("body").removeClass("no-results"),_.isNumber(e.total)&&(this.count=e.total),this.reset(e.themes),e.total||(this.count=this.length),this.trigger("update"),this.trigger("query:success",this.count)}else e=this.apiCall(t).done(function(e){e.themes&&(n.reset(e.themes),s=e.info.results,r.push({themes:e.themes,request:t,total:s})),n.trigger("update"),n.trigger("query:success",s),e.themes&&0===e.themes.length&&n.trigger("query:empty")}).fail(function(){n.trigger("query:fail")})},queries:[],currentQuery:{page:1,request:{}},apiCall:function(e,t){return wp.ajax.send("query-themes",{data:{request:_.extend({per_page:100,fields:{description:!0,tested:!0,requires:!0,rating:!0,downloaded:!0,downloadLink:!0,last_updated:!0,homepage:!0,num_ratings:!0}},e)},beforeSend:function(){t||o("body").addClass("loading-content").removeClass("no-results")}})},loadingThemes:!1}),a.view.Theme=wp.Backbone.View.extend({className:"theme",state:"grid",html:a.template("theme"),events:{click:a.isInstall?"preview":"expand",keydown:a.isInstall?"preview":"expand",touchend:a.isInstall?"preview":"expand",keyup:"addFocus",touchmove:"preventExpand"},touchDrag:!1,render:function(){var e=this.model.toJSON();this.$el.html(this.html(e)).attr({tabindex:0,"aria-describedby":e.id+"-action "+e.id+"-name"}),this.activeTheme(),this.