author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-admin/js/theme.js |
|
3 |
*/ |
|
4 |
||
5 |
/* global _wpThemeSettings, confirm, tb_position */ |
|
5 | 6 |
window.wp = window.wp || {}; |
7 |
||
8 |
( function($) { |
|
9 |
||
10 |
// Set up our namespace... |
|
11 |
var themes, l10n; |
|
12 |
themes = wp.themes = wp.themes || {}; |
|
13 |
||
16 | 14 |
// Store the theme data and settings for organized and quick access. |
15 |
// themes.data.settings, themes.data.themes, themes.data.l10n. |
|
5 | 16 |
themes.data = _wpThemeSettings; |
17 |
l10n = themes.data.l10n; |
|
18 |
||
16 | 19 |
// Shortcut for isInstall check. |
5 | 20 |
themes.isInstall = !! themes.data.settings.isInstall; |
21 |
||
16 | 22 |
// Setup app structure. |
5 | 23 |
_.extend( themes, { model: {}, view: {}, routes: {}, router: {}, template: wp.template }); |
24 |
||
25 |
themes.Model = Backbone.Model.extend({ |
|
16 | 26 |
// Adds attributes to the default data coming through the .org themes api. |
27 |
// Map `id` to `slug` for shared code. |
|
5 | 28 |
initialize: function() { |
29 |
var description; |
|
30 |
||
16 | 31 |
if ( this.get( 'slug' ) ) { |
32 |
// If the theme is already installed, set an attribute. |
|
33 |
if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) { |
|
34 |
this.set({ installed: true }); |
|
35 |
} |
|
36 |
||
37 |
// If the theme is active, set an attribute. |
|
38 |
if ( themes.data.activeTheme === this.get( 'slug' ) ) { |
|
39 |
this.set({ active: true }); |
|
40 |
} |
|
5 | 41 |
} |
42 |
||
16 | 43 |
// Set the attributes. |
5 | 44 |
this.set({ |
16 | 45 |
// `slug` is for installation, `id` is for existing. |
5 | 46 |
id: this.get( 'slug' ) || this.get( 'id' ) |
47 |
}); |
|
48 |
||
49 |
// Map `section.description` to `description` |
|
16 | 50 |
// as the API sometimes returns it differently. |
5 | 51 |
if ( this.has( 'sections' ) ) { |
52 |
description = this.get( 'sections' ).description; |
|
53 |
this.set({ description: description }); |
|
54 |
} |
|
55 |
} |
|
56 |
}); |
|
57 |
||
16 | 58 |
// Main view controller for themes.php. |
59 |
// Unifies and renders all available views. |
|
5 | 60 |
themes.view.Appearance = wp.Backbone.View.extend({ |
61 |
||
62 |
el: '#wpbody-content .wrap .theme-browser', |
|
63 |
||
64 |
window: $( window ), |
|
16 | 65 |
// Pagination instance. |
5 | 66 |
page: 0, |
67 |
||
16 | 68 |
// Sets up a throttler for binding to 'scroll'. |
5 | 69 |
initialize: function( options ) { |
16 | 70 |
// Scroller checks how far the scroll position is. |
5 | 71 |
_.bindAll( this, 'scroller' ); |
72 |
||
73 |
this.SearchView = options.SearchView ? options.SearchView : themes.view.Search; |
|
74 |
// Bind to the scroll event and throttle |
|
16 | 75 |
// the results from this.scroller. |
18 | 76 |
this.window.on( 'scroll', _.throttle( this.scroller, 300 ) ); |
5 | 77 |
}, |
78 |
||
16 | 79 |
// Main render control. |
5 | 80 |
render: function() { |
81 |
// Setup the main theme view |
|
16 | 82 |
// with the current theme collection. |
5 | 83 |
this.view = new themes.view.Themes({ |
84 |
collection: this.collection, |
|
85 |
parent: this |
|
86 |
}); |
|
87 |
||
88 |
// Render search form. |
|
89 |
this.search(); |
|
90 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
this.$el.removeClass( 'search-loading' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
|
16 | 93 |
// Render and append. |
5 | 94 |
this.view.render(); |
95 |
this.$el.empty().append( this.view.el ).addClass( 'rendered' ); |
|
96 |
}, |
|
97 |
||
16 | 98 |
// Defines search element container. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
searchContainer: $( '.search-form' ), |
5 | 100 |
|
101 |
// Search input and view |
|
16 | 102 |
// for current theme collection. |
5 | 103 |
search: function() { |
104 |
var view, |
|
105 |
self = this; |
|
106 |
||
16 | 107 |
// Don't render the search if there is only one theme. |
5 | 108 |
if ( themes.data.themes.length === 1 ) { |
109 |
return; |
|
110 |
} |
|
111 |
||
112 |
view = new this.SearchView({ |
|
113 |
collection: self.collection, |
|
114 |
parent: this |
|
115 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
self.SearchView = view; |
5 | 117 |
|
16 | 118 |
// Render and append after screen title. |
5 | 119 |
view.render(); |
120 |
this.searchContainer |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
.find( '.search-box' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
.append( $.parseHTML( '<label for="wp-filter-search-input">' + l10n.search + '</label>' ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
.append( view.el ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
this.searchContainer.on( 'submit', function( event ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
event.preventDefault(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
}); |
5 | 128 |
}, |
129 |
||
130 |
// Checks when the user gets close to the bottom |
|
16 | 131 |
// of the mage and triggers a theme:scroll event. |
5 | 132 |
scroller: function() { |
133 |
var self = this, |
|
134 |
bottom, threshold; |
|
135 |
||
136 |
bottom = this.window.scrollTop() + self.window.height(); |
|
137 |
threshold = self.$el.offset().top + self.$el.outerHeight( false ) - self.window.height(); |
|
138 |
threshold = Math.round( threshold * 0.9 ); |
|
139 |
||
140 |
if ( bottom > threshold ) { |
|
141 |
this.trigger( 'theme:scroll' ); |
|
142 |
} |
|
143 |
} |
|
144 |
}); |
|
145 |
||
16 | 146 |
// Set up the Collection for our theme data. |
5 | 147 |
// @has 'id' 'name' 'screenshot' 'author' 'authorURI' 'version' 'active' ... |
148 |
themes.Collection = Backbone.Collection.extend({ |
|
149 |
||
150 |
model: themes.Model, |
|
151 |
||
16 | 152 |
// Search terms. |
5 | 153 |
terms: '', |
154 |
||
155 |
// Controls searching on the current theme collection |
|
16 | 156 |
// and triggers an update event. |
5 | 157 |
doSearch: function( value ) { |
158 |
||
16 | 159 |
// Don't do anything if we've already done this search. |
160 |
// Useful because the Search handler fires multiple times per keystroke. |
|
5 | 161 |
if ( this.terms === value ) { |
162 |
return; |
|
163 |
} |
|
164 |
||
16 | 165 |
// Updates terms with the value passed. |
5 | 166 |
this.terms = value; |
167 |
||
168 |
// If we have terms, run a search... |
|
169 |
if ( this.terms.length > 0 ) { |
|
170 |
this.search( this.terms ); |
|
171 |
} |
|
172 |
||
16 | 173 |
// If search is blank, show all themes. |
174 |
// Useful for resetting the views when you clean the input. |
|
5 | 175 |
if ( this.terms === '' ) { |
176 |
this.reset( themes.data.themes ); |
|
177 |
$( 'body' ).removeClass( 'no-results' ); |
|
178 |
} |
|
179 |
||
16 | 180 |
// Trigger a 'themes:update' event. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
this.trigger( 'themes:update' ); |
5 | 182 |
}, |
183 |
||
16 | 184 |
/** |
185 |
* Performs a search within the collection. |
|
186 |
* |
|
187 |
* @uses RegExp |
|
188 |
*/ |
|
5 | 189 |
search: function( term ) { |
190 |
var match, results, haystack, name, description, author; |
|
191 |
||
16 | 192 |
// Start with a full collection. |
5 | 193 |
this.reset( themes.data.themes, { silent: true } ); |
194 |
||
16 | 195 |
// Trim the term. |
196 |
term = term.trim(); |
|
197 |
||
198 |
// Escape the term string for RegExp meta characters. |
|
5 | 199 |
term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); |
200 |
||
201 |
// Consider spaces as word delimiters and match the whole string |
|
16 | 202 |
// so matching terms can be combined. |
5 | 203 |
term = term.replace( / /g, ')(?=.*' ); |
204 |
match = new RegExp( '^(?=.*' + term + ').+', 'i' ); |
|
205 |
||
16 | 206 |
// Find results. |
207 |
// _.filter() and .test(). |
|
5 | 208 |
results = this.filter( function( data ) { |
209 |
name = data.get( 'name' ).replace( /(<([^>]+)>)/ig, '' ); |
|
210 |
description = data.get( 'description' ).replace( /(<([^>]+)>)/ig, '' ); |
|
211 |
author = data.get( 'author' ).replace( /(<([^>]+)>)/ig, '' ); |
|
212 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
haystack = _.union( [ name, data.get( 'id' ), description, author, data.get( 'tags' ) ] ); |
5 | 214 |
|
215 |
if ( match.test( data.get( 'author' ) ) && term.length > 2 ) { |
|
216 |
data.set( 'displayAuthor', true ); |
|
217 |
} |
|
218 |
||
219 |
return match.test( haystack ); |
|
220 |
}); |
|
221 |
||
222 |
if ( results.length === 0 ) { |
|
223 |
this.trigger( 'query:empty' ); |
|
224 |
} else { |
|
225 |
$( 'body' ).removeClass( 'no-results' ); |
|
226 |
} |
|
227 |
||
228 |
this.reset( results ); |
|
229 |
}, |
|
230 |
||
231 |
// Paginates the collection with a helper method |
|
16 | 232 |
// that slices the collection. |
5 | 233 |
paginate: function( instance ) { |
234 |
var collection = this; |
|
235 |
instance = instance || 0; |
|
236 |
||
16 | 237 |
// Themes per instance are set at 20. |
5 | 238 |
collection = _( collection.rest( 20 * instance ) ); |
239 |
collection = _( collection.first( 20 ) ); |
|
240 |
||
241 |
return collection; |
|
242 |
}, |
|
243 |
||
244 |
count: false, |
|
245 |
||
16 | 246 |
/* |
247 |
* Handles requests for more themes and caches results. |
|
248 |
* |
|
249 |
* |
|
250 |
* When we are missing a cache object we fire an apiCall() |
|
251 |
* which triggers events of `query:success` or `query:fail`. |
|
252 |
*/ |
|
5 | 253 |
query: function( request ) { |
254 |
/** |
|
255 |
* @static |
|
256 |
* @type Array |
|
257 |
*/ |
|
258 |
var queries = this.queries, |
|
259 |
self = this, |
|
260 |
query, isPaginated, count; |
|
261 |
||
262 |
// Store current query request args |
|
16 | 263 |
// for later use with the event `theme:end`. |
5 | 264 |
this.currentQuery.request = request; |
265 |
||
266 |
// Search the query cache for matches. |
|
267 |
query = _.find( queries, function( query ) { |
|
268 |
return _.isEqual( query.request, request ); |
|
269 |
}); |
|
270 |
||
271 |
// If the request matches the stored currentQuery.request |
|
272 |
// it means we have a paginated request. |
|
273 |
isPaginated = _.has( request, 'page' ); |
|
274 |
||
16 | 275 |
// Reset the internal api page counter for non-paginated queries. |
5 | 276 |
if ( ! isPaginated ) { |
277 |
this.currentQuery.page = 1; |
|
278 |
} |
|
279 |
||
280 |
// Otherwise, send a new API call and add it to the cache. |
|
281 |
if ( ! query && ! isPaginated ) { |
|
282 |
query = this.apiCall( request ).done( function( data ) { |
|
283 |
||
284 |
// Update the collection with the queried data. |
|
285 |
if ( data.themes ) { |
|
286 |
self.reset( data.themes ); |
|
287 |
count = data.info.results; |
|
16 | 288 |
// Store the results and the query request. |
5 | 289 |
queries.push( { themes: data.themes, request: request, total: count } ); |
290 |
} |
|
291 |
||
292 |
// Trigger a collection refresh event |
|
293 |
// and a `query:success` event with a `count` argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
self.trigger( 'themes:update' ); |
5 | 295 |
self.trigger( 'query:success', count ); |
296 |
||
297 |
if ( data.themes && data.themes.length === 0 ) { |
|
298 |
self.trigger( 'query:empty' ); |
|
299 |
} |
|
300 |
||
301 |
}).fail( function() { |
|
302 |
self.trigger( 'query:fail' ); |
|
303 |
}); |
|
304 |
} else { |
|
305 |
// If it's a paginated request we need to fetch more themes... |
|
306 |
if ( isPaginated ) { |
|
307 |
return this.apiCall( request, isPaginated ).done( function( data ) { |
|
16 | 308 |
// Add the new themes to the current collection. |
309 |
// @todo Update counter. |
|
5 | 310 |
self.add( data.themes ); |
311 |
self.trigger( 'query:success' ); |
|
312 |
||
313 |
// We are done loading themes for now. |
|
314 |
self.loadingThemes = false; |
|
315 |
||
316 |
}).fail( function() { |
|
317 |
self.trigger( 'query:fail' ); |
|
318 |
}); |
|
319 |
} |
|
320 |
||
321 |
if ( query.themes.length === 0 ) { |
|
322 |
self.trigger( 'query:empty' ); |
|
323 |
} else { |
|
324 |
$( 'body' ).removeClass( 'no-results' ); |
|
325 |
} |
|
326 |
||
327 |
// Only trigger an update event since we already have the themes |
|
16 | 328 |
// on our cached object. |
5 | 329 |
if ( _.isNumber( query.total ) ) { |
330 |
this.count = query.total; |
|
331 |
} |
|
332 |
||
333 |
this.reset( query.themes ); |
|
334 |
if ( ! query.total ) { |
|
335 |
this.count = this.length; |
|
336 |
} |
|
337 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
this.trigger( 'themes:update' ); |
5 | 339 |
this.trigger( 'query:success', this.count ); |
340 |
} |
|
341 |
}, |
|
342 |
||
16 | 343 |
// Local cache array for API queries. |
5 | 344 |
queries: [], |
345 |
||
16 | 346 |
// Keep track of current query so we can handle pagination. |
5 | 347 |
currentQuery: { |
348 |
page: 1, |
|
349 |
request: {} |
|
350 |
}, |
|
351 |
||
16 | 352 |
// Send request to api.wordpress.org/themes. |
5 | 353 |
apiCall: function( request, paginated ) { |
354 |
return wp.ajax.send( 'query-themes', { |
|
355 |
data: { |
|
16 | 356 |
// Request data. |
5 | 357 |
request: _.extend({ |
9 | 358 |
per_page: 100 |
5 | 359 |
}, request) |
360 |
}, |
|
361 |
||
362 |
beforeSend: function() { |
|
363 |
if ( ! paginated ) { |
|
16 | 364 |
// Spin it. |
5 | 365 |
$( 'body' ).addClass( 'loading-content' ).removeClass( 'no-results' ); |
366 |
} |
|
367 |
} |
|
368 |
}); |
|
369 |
}, |
|
370 |
||
371 |
// Static status controller for when we are loading themes. |
|
372 |
loadingThemes: false |
|
373 |
}); |
|
374 |
||
375 |
// This is the view that controls each theme item |
|
16 | 376 |
// that will be displayed on the screen. |
5 | 377 |
themes.view.Theme = wp.Backbone.View.extend({ |
378 |
||
16 | 379 |
// Wrap theme data on a div.theme element. |
5 | 380 |
className: 'theme', |
381 |
||
16 | 382 |
// Reflects which theme view we have. |
383 |
// 'grid' (default) or 'detail'. |
|
5 | 384 |
state: 'grid', |
385 |
||
16 | 386 |
// The HTML template for each element to be rendered. |
5 | 387 |
html: themes.template( 'theme' ), |
388 |
||
389 |
events: { |
|
390 |
'click': themes.isInstall ? 'preview': 'expand', |
|
391 |
'keydown': themes.isInstall ? 'preview': 'expand', |
|
392 |
'touchend': themes.isInstall ? 'preview': 'expand', |
|
393 |
'keyup': 'addFocus', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
'touchmove': 'preventExpand', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
'click .theme-install': 'installTheme', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
'click .update-message': 'updateTheme' |
5 | 397 |
}, |
398 |
||
399 |
touchDrag: false, |
|
400 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
initialize: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
this.model.on( 'change', this.render, this ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
|
5 | 405 |
render: function() { |
406 |
var data = this.model.toJSON(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
|
16 | 408 |
// Render themes using the html template. |
18 | 409 |
this.$el.html( this.html( data ) ).attr( 'data-slug', data.id ); |
5 | 410 |
|
16 | 411 |
// Renders active theme styles. |
5 | 412 |
this.activeTheme(); |
413 |
||
414 |
if ( this.model.get( 'displayAuthor' ) ) { |
|
415 |
this.$el.addClass( 'display-author' ); |
|
416 |
} |
|
417 |
}, |
|
0 | 418 |
|
5 | 419 |
// Adds a class to the currently active theme |
16 | 420 |
// and to the overlay in detailed view mode. |
5 | 421 |
activeTheme: function() { |
422 |
if ( this.model.get( 'active' ) ) { |
|
423 |
this.$el.addClass( 'active' ); |
|
424 |
} |
|
425 |
}, |
|
426 |
||
427 |
// Add class of focus to the theme we are focused on. |
|
428 |
addFocus: function() { |
|
429 |
var $themeToFocus = ( $( ':focus' ).hasClass( 'theme' ) ) ? $( ':focus' ) : $(':focus').parents('.theme'); |
|
430 |
||
431 |
$('.theme.focus').removeClass('focus'); |
|
432 |
$themeToFocus.addClass('focus'); |
|
433 |
}, |
|
434 |
||
16 | 435 |
// Single theme overlay screen. |
436 |
// It's shown when clicking a theme. |
|
5 | 437 |
expand: function( event ) { |
438 |
var self = this; |
|
439 |
||
440 |
event = event || window.event; |
|
441 |
||
16 | 442 |
// 'Enter' and 'Space' keys expand the details view when a theme is :focused. |
5 | 443 |
if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) { |
444 |
return; |
|
445 |
} |
|
446 |
||
16 | 447 |
// Bail if the user scrolled on a touch device. |
5 | 448 |
if ( this.touchDrag === true ) { |
449 |
return this.touchDrag = false; |
|
450 |
} |
|
451 |
||
452 |
// Prevent the modal from showing when the user clicks |
|
16 | 453 |
// one of the direct action buttons. |
5 | 454 |
if ( $( event.target ).is( '.theme-actions a' ) ) { |
455 |
return; |
|
456 |
} |
|
457 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
// Prevent the modal from showing when the user clicks one of the direct action buttons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
if ( $( event.target ).is( '.theme-actions a, .update-message, .button-link, .notice-dismiss' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
|
16 | 463 |
// Set focused theme to current element. |
5 | 464 |
themes.focusedTheme = this.$el; |
465 |
||
466 |
this.trigger( 'theme:expand', self.model.cid ); |
|
467 |
}, |
|
468 |
||
469 |
preventExpand: function() { |
|
470 |
this.touchDrag = true; |
|
471 |
}, |
|
472 |
||
473 |
preview: function( event ) { |
|
474 |
var self = this, |
|
475 |
current, preview; |
|
476 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
event = event || window.event; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
|
16 | 479 |
// Bail if the user scrolled on a touch device. |
5 | 480 |
if ( this.touchDrag === true ) { |
481 |
return this.touchDrag = false; |
|
482 |
} |
|
483 |
||
484 |
// Allow direct link path to installing a theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
if ( $( event.target ).not( '.install-theme-preview' ).parents( '.theme-actions' ).length ) { |
5 | 486 |
return; |
487 |
} |
|
488 |
||
16 | 489 |
// 'Enter' and 'Space' keys expand the details view when a theme is :focused. |
5 | 490 |
if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) { |
491 |
return; |
|
492 |
} |
|
493 |
||
16 | 494 |
// Pressing Enter while focused on the buttons shouldn't open the preview. |
5 | 495 |
if ( event.type === 'keydown' && event.which !== 13 && $( ':focus' ).hasClass( 'button' ) ) { |
496 |
return; |
|
497 |
} |
|
498 |
||
499 |
event.preventDefault(); |
|
500 |
||
501 |
event = event || window.event; |
|
502 |
||
503 |
// Set focus to current theme. |
|
504 |
themes.focusedTheme = this.$el; |
|
505 |
||
506 |
// Construct a new Preview view. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
themes.preview = preview = new themes.view.Preview({ |
5 | 508 |
model: this.model |
509 |
}); |
|
510 |
||
511 |
// Render the view and append it. |
|
512 |
preview.render(); |
|
513 |
this.setNavButtonsState(); |
|
514 |
||
16 | 515 |
// Hide previous/next navigation if there is only one theme. |
5 | 516 |
if ( this.model.collection.length === 1 ) { |
517 |
preview.$el.addClass( 'no-navigation' ); |
|
518 |
} else { |
|
519 |
preview.$el.removeClass( 'no-navigation' ); |
|
520 |
} |
|
521 |
||
16 | 522 |
// Append preview. |
5 | 523 |
$( 'div.wrap' ).append( preview.el ); |
524 |
||
525 |
// Listen to our preview object |
|
526 |
// for `theme:next` and `theme:previous` events. |
|
527 |
this.listenTo( preview, 'theme:next', function() { |
|
528 |
||
529 |
// Keep local track of current theme model. |
|
530 |
current = self.model; |
|
531 |
||
532 |
// If we have ventured away from current model update the current model position. |
|
533 |
if ( ! _.isUndefined( self.current ) ) { |
|
534 |
current = self.current; |
|
535 |
} |
|
536 |
||
537 |
// Get next theme model. |
|
538 |
self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 ); |
|
539 |
||
540 |
// If we have no more themes, bail. |
|
541 |
if ( _.isUndefined( self.current ) ) { |
|
542 |
self.options.parent.parent.trigger( 'theme:end' ); |
|
543 |
return self.current = current; |
|
544 |
} |
|
545 |
||
546 |
preview.model = self.current; |
|
547 |
||
548 |
// Render and append. |
|
549 |
preview.render(); |
|
550 |
this.setNavButtonsState(); |
|
18 | 551 |
$( '.next-theme' ).trigger( 'focus' ); |
5 | 552 |
}) |
553 |
.listenTo( preview, 'theme:previous', function() { |
|
554 |
||
555 |
// Keep track of current theme model. |
|
556 |
current = self.model; |
|
557 |
||
16 | 558 |
// Bail early if we are at the beginning of the collection. |
5 | 559 |
if ( self.model.collection.indexOf( self.current ) === 0 ) { |
560 |
return; |
|
561 |
} |
|
562 |
||
563 |
// If we have ventured away from current model update the current model position. |
|
564 |
if ( ! _.isUndefined( self.current ) ) { |
|
565 |
current = self.current; |
|
566 |
} |
|
567 |
||
568 |
// Get previous theme model. |
|
569 |
self.current = self.model.collection.at( self.model.collection.indexOf( current ) - 1 ); |
|
570 |
||
571 |
// If we have no more themes, bail. |
|
572 |
if ( _.isUndefined( self.current ) ) { |
|
573 |
return; |
|
574 |
} |
|
575 |
||
576 |
preview.model = self.current; |
|
577 |
||
578 |
// Render and append. |
|
579 |
preview.render(); |
|
580 |
this.setNavButtonsState(); |
|
18 | 581 |
$( '.previous-theme' ).trigger( 'focus' ); |
5 | 582 |
}); |
583 |
||
584 |
this.listenTo( preview, 'preview:close', function() { |
|
585 |
self.current = self.model; |
|
586 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
|
5 | 588 |
}, |
589 |
||
16 | 590 |
// Handles .disabled classes for previous/next buttons in theme installer preview. |
5 | 591 |
setNavButtonsState: function() { |
592 |
var $themeInstaller = $( '.theme-install-overlay' ), |
|
9 | 593 |
current = _.isUndefined( this.current ) ? this.model : this.current, |
594 |
previousThemeButton = $themeInstaller.find( '.previous-theme' ), |
|
595 |
nextThemeButton = $themeInstaller.find( '.next-theme' ); |
|
5 | 596 |
|
16 | 597 |
// Disable previous at the zero position. |
5 | 598 |
if ( 0 === this.model.collection.indexOf( current ) ) { |
9 | 599 |
previousThemeButton |
600 |
.addClass( 'disabled' ) |
|
601 |
.prop( 'disabled', true ); |
|
602 |
||
18 | 603 |
nextThemeButton.trigger( 'focus' ); |
5 | 604 |
} |
605 |
||
16 | 606 |
// Disable next if the next model is undefined. |
5 | 607 |
if ( _.isUndefined( this.model.collection.at( this.model.collection.indexOf( current ) + 1 ) ) ) { |
9 | 608 |
nextThemeButton |
609 |
.addClass( 'disabled' ) |
|
610 |
.prop( 'disabled', true ); |
|
611 |
||
18 | 612 |
previousThemeButton.trigger( 'focus' ); |
5 | 613 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
installTheme: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
var _this = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
wp.updates.maybeRequestFilesystemCredentials( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
$( document ).on( 'wp-theme-install-success', function( event, response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
if ( _this.model.get( 'id' ) === response.slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
_this.model.set( { 'installed': true } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
19 | 627 |
if ( response.blockTheme ) { |
628 |
_this.model.set( { 'block_theme': true } ); |
|
629 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
wp.updates.installTheme( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
slug: $( event.target ).data( 'slug' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
updateTheme: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
var _this = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
if ( ! this.model.get( 'hasPackage' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
wp.updates.maybeRequestFilesystemCredentials( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
$( document ).on( 'wp-theme-update-success', function( event, response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
_this.model.off( 'change', _this.render, _this ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
if ( _this.model.get( 'id' ) === response.slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
_this.model.set( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
hasUpdate: false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
version: response.newVersion |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
_this.model.on( 'change', _this.render, _this ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
wp.updates.updateTheme( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
slug: $( event.target ).parents( 'div.theme' ).first().data( 'slug' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
} ); |
5 | 662 |
} |
663 |
}); |
|
664 |
||
16 | 665 |
// Theme Details view. |
666 |
// Sets up a modal overlay with the expanded theme data. |
|
5 | 667 |
themes.view.Details = wp.Backbone.View.extend({ |
668 |
||
16 | 669 |
// Wrap theme data on a div.theme element. |
5 | 670 |
className: 'theme-overlay', |
671 |
||
672 |
events: { |
|
673 |
'click': 'collapse', |
|
674 |
'click .delete-theme': 'deleteTheme', |
|
675 |
'click .left': 'previousTheme', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
'click .right': 'nextTheme', |
16 | 677 |
'click #update-theme': 'updateTheme', |
678 |
'click .toggle-auto-update': 'autoupdateState' |
|
5 | 679 |
}, |
680 |
||
16 | 681 |
// The HTML template for the theme overlay. |
5 | 682 |
html: themes.template( 'theme-single' ), |
683 |
||
684 |
render: function() { |
|
685 |
var data = this.model.toJSON(); |
|
686 |
this.$el.html( this.html( data ) ); |
|
16 | 687 |
// Renders active theme styles. |
5 | 688 |
this.activeTheme(); |
16 | 689 |
// Set up navigation events. |
5 | 690 |
this.navigation(); |
16 | 691 |
// Checks screenshot size. |
5 | 692 |
this.screenshotCheck( this.$el ); |
16 | 693 |
// Contain "tabbing" inside the overlay. |
5 | 694 |
this.containFocus( this.$el ); |
695 |
}, |
|
696 |
||
697 |
// Adds a class to the currently active theme |
|
16 | 698 |
// and to the overlay in detailed view mode. |
5 | 699 |
activeTheme: function() { |
16 | 700 |
// Check the model has the active property. |
5 | 701 |
this.$el.toggleClass( 'active', this.model.get( 'active' ) ); |
702 |
}, |
|
703 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
// Set initial focus and constrain tabbing within the theme browser modal. |
5 | 705 |
containFocus: function( $el ) { |
706 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
// Set initial focus on the primary action control. |
5 | 708 |
_.delay( function() { |
18 | 709 |
$( '.theme-overlay' ).trigger( 'focus' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
}, 100 ); |
5 | 711 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
// Constrain tabbing within the modal. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
$el.on( 'keydown.wp-themes', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
var $firstFocusable = $el.find( '.theme-header button:not(.disabled)' ).first(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
$lastFocusable = $el.find( '.theme-actions a:visible' ).last(); |
5 | 716 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
// Check for the Tab key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
if ( 9 === event.which ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
if ( $firstFocusable[0] === event.target && event.shiftKey ) { |
18 | 720 |
$lastFocusable.trigger( 'focus' ); |
5 | 721 |
event.preventDefault(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
} else if ( $lastFocusable[0] === event.target && ! event.shiftKey ) { |
18 | 723 |
$firstFocusable.trigger( 'focus' ); |
5 | 724 |
event.preventDefault(); |
725 |
} |
|
726 |
} |
|
727 |
}); |
|
728 |
}, |
|
729 |
||
16 | 730 |
// Single theme overlay screen. |
731 |
// It's shown when clicking a theme. |
|
5 | 732 |
collapse: function( event ) { |
733 |
var self = this, |
|
734 |
scroll; |
|
735 |
||
736 |
event = event || window.event; |
|
737 |
||
16 | 738 |
// Prevent collapsing detailed view when there is only one theme available. |
5 | 739 |
if ( themes.data.themes.length === 1 ) { |
740 |
return; |
|
741 |
} |
|
742 |
||
16 | 743 |
// Detect if the click is inside the overlay and don't close it |
744 |
// unless the target was the div.back button. |
|
5 | 745 |
if ( $( event.target ).is( '.theme-backdrop' ) || $( event.target ).is( '.close' ) || event.keyCode === 27 ) { |
746 |
||
16 | 747 |
// Add a temporary closing class while overlay fades out. |
5 | 748 |
$( 'body' ).addClass( 'closing-overlay' ); |
749 |
||
16 | 750 |
// With a quick fade out animation. |
5 | 751 |
this.$el.fadeOut( 130, function() { |
16 | 752 |
// Clicking outside the modal box closes the overlay. |
5 | 753 |
$( 'body' ).removeClass( 'closing-overlay' ); |
16 | 754 |
// Handle event cleanup. |
5 | 755 |
self.closeOverlay(); |
756 |
||
16 | 757 |
// Get scroll position to avoid jumping to the top. |
5 | 758 |
scroll = document.body.scrollTop; |
759 |
||
16 | 760 |
// Clean the URL structure. |
5 | 761 |
themes.router.navigate( themes.router.baseUrl( '' ) ); |
762 |
||
16 | 763 |
// Restore scroll position. |
5 | 764 |
document.body.scrollTop = scroll; |
765 |
||
16 | 766 |
// Return focus to the theme div. |
5 | 767 |
if ( themes.focusedTheme ) { |
18 | 768 |
themes.focusedTheme.find('.more-details').trigger( 'focus' ); |
5 | 769 |
} |
770 |
}); |
|
771 |
} |
|
772 |
}, |
|
773 |
||
16 | 774 |
// Handles .disabled classes for next/previous buttons. |
5 | 775 |
navigation: function() { |
776 |
||
16 | 777 |
// Disable Left/Right when at the start or end of the collection. |
5 | 778 |
if ( this.model.cid === this.model.collection.at(0).cid ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
this.$el.find( '.left' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
.addClass( 'disabled' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
.prop( 'disabled', true ); |
5 | 782 |
} |
783 |
if ( this.model.cid === this.model.collection.at( this.model.collection.length - 1 ).cid ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
this.$el.find( '.right' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
.addClass( 'disabled' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
.prop( 'disabled', true ); |
5 | 787 |
} |
788 |
}, |
|
789 |
||
790 |
// Performs the actions to effectively close |
|
16 | 791 |
// the theme details overlay. |
5 | 792 |
closeOverlay: function() { |
793 |
$( 'body' ).removeClass( 'modal-open' ); |
|
794 |
this.remove(); |
|
795 |
this.unbind(); |
|
796 |
this.trigger( 'theme:collapse' ); |
|
797 |
}, |
|
798 |
||
16 | 799 |
// Set state of the auto-update settings link after it has been changed and saved. |
800 |
autoupdateState: function() { |
|
801 |
var callback, |
|
802 |
_this = this; |
|
803 |
||
804 |
// Support concurrent clicks in different Theme Details overlays. |
|
805 |
callback = function( event, data ) { |
|
806 |
var autoupdate; |
|
807 |
if ( _this.model.get( 'id' ) === data.asset ) { |
|
808 |
autoupdate = _this.model.get( 'autoupdate' ); |
|
809 |
autoupdate.enabled = 'enable' === data.state; |
|
810 |
_this.model.set( { autoupdate: autoupdate } ); |
|
811 |
$( document ).off( 'wp-auto-update-setting-changed', callback ); |
|
812 |
} |
|
813 |
}; |
|
814 |
||
815 |
// Triggered in updates.js |
|
816 |
$( document ).on( 'wp-auto-update-setting-changed', callback ); |
|
817 |
}, |
|
818 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
updateTheme: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
var _this = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
wp.updates.maybeRequestFilesystemCredentials( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
$( document ).on( 'wp-theme-update-success', function( event, response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
if ( _this.model.get( 'id' ) === response.slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
_this.model.set( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
hasUpdate: false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
version: response.newVersion |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
_this.render(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
wp.updates.updateTheme( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
slug: $( event.target ).data( 'slug' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
deleteTheme: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
var _this = this, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
_collection = _this.model.collection, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
_themes = themes; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
// Confirmation dialog for deleting a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
if ( ! window.confirm( wp.themes.data.settings.confirmDelete ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
wp.updates.maybeRequestFilesystemCredentials( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
$( document ).one( 'wp-theme-delete-success', function( event, response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
_this.$el.find( '.close' ).trigger( 'click' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
$( '[data-slug="' + response.slug + '"]' ).css( { backgroundColor:'#faafaa' } ).fadeOut( 350, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
$( this ).remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
_themes.data.themes = _.without( _themes.data.themes, _.findWhere( _themes.data.themes, { id: response.slug } ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
$( '.wp-filter-search' ).val( '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
_collection.doSearch( '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
_collection.remove( _this.model ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
_collection.trigger( 'themes:update' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
wp.updates.deleteTheme( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
slug: this.model.get( 'id' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
} ); |
5 | 869 |
}, |
870 |
||
871 |
nextTheme: function() { |
|
872 |
var self = this; |
|
873 |
self.trigger( 'theme:next', self.model.cid ); |
|
874 |
return false; |
|
875 |
}, |
|
876 |
||
877 |
previousTheme: function() { |
|
878 |
var self = this; |
|
879 |
self.trigger( 'theme:previous', self.model.cid ); |
|
880 |
return false; |
|
881 |
}, |
|
882 |
||
883 |
// Checks if the theme screenshot is the old 300px width version |
|
16 | 884 |
// and adds a corresponding class if it's true. |
5 | 885 |
screenshotCheck: function( el ) { |
886 |
var screenshot, image; |
|
887 |
||
888 |
screenshot = el.find( '.screenshot img' ); |
|
889 |
image = new Image(); |
|
890 |
image.src = screenshot.attr( 'src' ); |
|
891 |
||
16 | 892 |
// Width check. |
5 | 893 |
if ( image.width && image.width <= 300 ) { |
894 |
el.addClass( 'small-screenshot' ); |
|
895 |
} |
|
896 |
} |
|
897 |
}); |
|
898 |
||
16 | 899 |
// Theme Preview view. |
900 |
// Sets up a modal overlay with the expanded theme data. |
|
5 | 901 |
themes.view.Preview = themes.view.Details.extend({ |
902 |
||
903 |
className: 'wp-full-overlay expanded', |
|
904 |
el: '.theme-install-overlay', |
|
905 |
||
906 |
events: { |
|
907 |
'click .close-full-overlay': 'close', |
|
908 |
'click .collapse-sidebar': 'collapse', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
'click .devices button': 'previewDevice', |
5 | 910 |
'click .previous-theme': 'previousTheme', |
911 |
'click .next-theme': 'nextTheme', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
'keyup': 'keyEvent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
'click .theme-install': 'installTheme' |
5 | 914 |
}, |
915 |
||
16 | 916 |
// The HTML template for the theme preview. |
5 | 917 |
html: themes.template( 'theme-preview' ), |
918 |
||
919 |
render: function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
var self = this, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
currentPreviewDevice, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
data = this.model.toJSON(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
$body = $( document.body ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
$body.attr( 'aria-busy', 'true' ); |
5 | 926 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
this.$el.removeClass( 'iframe-ready' ).html( this.html( data ) ); |
5 | 928 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
currentPreviewDevice = this.$el.data( 'current-preview-device' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
if ( currentPreviewDevice ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
931 |
self.togglePreviewDeviceButtons( currentPreviewDevice ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: false } ); |
5 | 935 |
|
936 |
this.$el.fadeIn( 200, function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
$body.addClass( 'theme-installer-active full-overlay-active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
this.$el.find( 'iframe' ).one( 'load', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
self.iframeLoaded(); |
5 | 942 |
}); |
943 |
}, |
|
944 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
iframeLoaded: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
this.$el.addClass( 'iframe-ready' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
$( document.body ).attr( 'aria-busy', 'false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
|
5 | 950 |
close: function() { |
951 |
this.$el.fadeOut( 200, function() { |
|
952 |
$( 'body' ).removeClass( 'theme-installer-active full-overlay-active' ); |
|
953 |
||
16 | 954 |
// Return focus to the theme div. |
5 | 955 |
if ( themes.focusedTheme ) { |
18 | 956 |
themes.focusedTheme.find('.more-details').trigger( 'focus' ); |
5 | 957 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
}).removeClass( 'iframe-ready' ); |
5 | 959 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
// Restore the previous browse tab if available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
if ( themes.router.selectedTab ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
themes.router.navigate( themes.router.baseUrl( '?browse=' + themes.router.selectedTab ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
themes.router.selectedTab = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
themes.router.navigate( themes.router.baseUrl( '' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
} |
5 | 967 |
this.trigger( 'preview:close' ); |
968 |
this.undelegateEvents(); |
|
969 |
this.unbind(); |
|
970 |
return false; |
|
971 |
}, |
|
972 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
collapse: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
var $button = $( event.currentTarget ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
if ( 'true' === $button.attr( 'aria-expanded' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
$button.attr({ 'aria-expanded': 'false', 'aria-label': l10n.expandSidebar }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
$button.attr({ 'aria-expanded': 'true', 'aria-label': l10n.collapseSidebar }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
} |
5 | 980 |
|
981 |
this.$el.toggleClass( 'collapsed' ).toggleClass( 'expanded' ); |
|
982 |
return false; |
|
983 |
}, |
|
984 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
previewDevice: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
var device = $( event.currentTarget ).data( 'device' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
this.$el |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
.removeClass( 'preview-desktop preview-tablet preview-mobile' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
.addClass( 'preview-' + device ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
.data( 'current-preview-device', device ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
993 |
this.togglePreviewDeviceButtons( device ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
996 |
togglePreviewDeviceButtons: function( newDevice ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
var $devices = $( '.wp-full-overlay-footer .devices' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
$devices.find( 'button' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
.removeClass( 'active' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
.attr( 'aria-pressed', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
$devices.find( 'button.preview-' + newDevice ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
.addClass( 'active' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
.attr( 'aria-pressed', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
|
5 | 1008 |
keyEvent: function( event ) { |
16 | 1009 |
// The escape key closes the preview. |
5 | 1010 |
if ( event.keyCode === 27 ) { |
1011 |
this.undelegateEvents(); |
|
1012 |
this.close(); |
|
1013 |
} |
|
16 | 1014 |
// The right arrow key, next theme. |
5 | 1015 |
if ( event.keyCode === 39 ) { |
1016 |
_.once( this.nextTheme() ); |
|
0 | 1017 |
} |
1018 |
||
16 | 1019 |
// The left arrow key, previous theme. |
5 | 1020 |
if ( event.keyCode === 37 ) { |
1021 |
this.previousTheme(); |
|
1022 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
installTheme: function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
var _this = this, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
$target = $( event.target ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
if ( $target.hasClass( 'disabled' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
wp.updates.maybeRequestFilesystemCredentials( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
$( document ).on( 'wp-theme-install-success', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
_this.model.set( { 'installed': true } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
wp.updates.installTheme( { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
slug: $target.data( 'slug' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
} ); |
5 | 1043 |
} |
1044 |
}); |
|
1045 |
||
1046 |
// Controls the rendering of div.themes, |
|
16 | 1047 |
// a wrapper that will hold all the theme elements. |
5 | 1048 |
themes.view.Themes = wp.Backbone.View.extend({ |
1049 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
className: 'themes wp-clearfix', |
5 | 1051 |
$overlay: $( 'div.theme-overlay' ), |
1052 |
||
1053 |
// Number to keep track of scroll position |
|
16 | 1054 |
// while in theme-overlay mode. |
5 | 1055 |
index: 0, |
1056 |
||
16 | 1057 |
// The theme count element. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
count: $( '.wrap .theme-count' ), |
5 | 1059 |
|
16 | 1060 |
// The live themes count. |
5 | 1061 |
liveThemeCount: 0, |
1062 |
||
1063 |
initialize: function( options ) { |
|
1064 |
var self = this; |
|
1065 |
||
16 | 1066 |
// Set up parent. |
5 | 1067 |
this.parent = options.parent; |
1068 |
||
16 | 1069 |
// Set current view to [grid]. |
5 | 1070 |
this.setView( 'grid' ); |
1071 |
||
16 | 1072 |
// Move the active theme to the beginning of the collection. |
5 | 1073 |
self.currentTheme(); |
1074 |
||
1075 |
// When the collection is updated by user input... |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
this.listenTo( self.collection, 'themes:update', function() { |
5 | 1077 |
self.parent.page = 0; |
1078 |
self.currentTheme(); |
|
1079 |
self.render( this ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
} ); |
5 | 1081 |
|
1082 |
// Update theme count to full result set when available. |
|
1083 |
this.listenTo( self.collection, 'query:success', function( count ) { |
|
1084 |
if ( _.isNumber( count ) ) { |
|
1085 |
self.count.text( count ); |
|
1086 |
self.announceSearchResults( count ); |
|
1087 |
} else { |
|
1088 |
self.count.text( self.collection.length ); |
|
1089 |
self.announceSearchResults( self.collection.length ); |
|
1090 |
} |
|
1091 |
}); |
|
1092 |
||
1093 |
this.listenTo( self.collection, 'query:empty', function() { |
|
1094 |
$( 'body' ).addClass( 'no-results' ); |
|
1095 |
}); |
|
1096 |
||
1097 |
this.listenTo( this.parent, 'theme:scroll', function() { |
|
1098 |
self.renderThemes( self.parent.page ); |
|
1099 |
}); |
|
1100 |
||
1101 |
this.listenTo( this.parent, 'theme:close', function() { |
|
1102 |
if ( self.overlay ) { |
|
1103 |
self.overlay.closeOverlay(); |
|
1104 |
} |
|
1105 |
} ); |
|
1106 |
||
1107 |
// Bind keyboard events. |
|
1108 |
$( 'body' ).on( 'keyup', function( event ) { |
|
1109 |
if ( ! self.overlay ) { |
|
1110 |
return; |
|
1111 |
} |
|
1112 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
// Bail if the filesystem credentials dialog is shown. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
if ( $( '#request-filesystem-credentials-dialog' ).is( ':visible' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
|
16 | 1118 |
// Pressing the right arrow key fires a theme:next event. |
5 | 1119 |
if ( event.keyCode === 39 ) { |
1120 |
self.overlay.nextTheme(); |
|
1121 |
} |
|
1122 |
||
16 | 1123 |
// Pressing the left arrow key fires a theme:previous event. |
5 | 1124 |
if ( event.keyCode === 37 ) { |
1125 |
self.overlay.previousTheme(); |
|
1126 |
} |
|
1127 |
||
16 | 1128 |
// Pressing the escape key fires a theme:collapse event. |
5 | 1129 |
if ( event.keyCode === 27 ) { |
1130 |
self.overlay.collapse( event ); |
|
1131 |
} |
|
1132 |
}); |
|
1133 |
}, |
|
1134 |
||
1135 |
// Manages rendering of theme pages |
|
16 | 1136 |
// and keeping theme count in sync. |
5 | 1137 |
render: function() { |
16 | 1138 |
// Clear the DOM, please. |
5 | 1139 |
this.$el.empty(); |
1140 |
||
16 | 1141 |
// If the user doesn't have switch capabilities or there is only one theme |
1142 |
// in the collection, render the detailed view of the active theme. |
|
5 | 1143 |
if ( themes.data.themes.length === 1 ) { |
1144 |
||
16 | 1145 |
// Constructs the view. |
5 | 1146 |
this.singleTheme = new themes.view.Details({ |
1147 |
model: this.collection.models[0] |
|
1148 |
}); |
|
1149 |
||
16 | 1150 |
// Render and apply a 'single-theme' class to our container. |
5 | 1151 |
this.singleTheme.render(); |
1152 |
this.$el.addClass( 'single-theme' ); |
|
1153 |
this.$el.append( this.singleTheme.el ); |
|
1154 |
} |
|
1155 |
||
16 | 1156 |
// Generate the themes using page instance |
1157 |
// while checking the collection has items. |
|
5 | 1158 |
if ( this.options.collection.size() > 0 ) { |
1159 |
this.renderThemes( this.parent.page ); |
|
1160 |
} |
|
1161 |
||
16 | 1162 |
// Display a live theme count for the collection. |
5 | 1163 |
this.liveThemeCount = this.collection.count ? this.collection.count : this.collection.length; |
1164 |
this.count.text( this.liveThemeCount ); |
|
1165 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
* In the theme installer the themes count is already announced |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
* because `announceSearchResults` is called on `query:success`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
if ( ! themes.isInstall ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
this.announceSearchResults( this.liveThemeCount ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
} |
5 | 1173 |
}, |
1174 |
||
1175 |
// Iterates through each instance of the collection |
|
16 | 1176 |
// and renders each theme module. |
5 | 1177 |
renderThemes: function( page ) { |
1178 |
var self = this; |
|
1179 |
||
1180 |
self.instance = self.collection.paginate( page ); |
|
1181 |
||
16 | 1182 |
// If we have no more themes, bail. |
5 | 1183 |
if ( self.instance.size() === 0 ) { |
1184 |
// Fire a no-more-themes event. |
|
1185 |
this.parent.trigger( 'theme:end' ); |
|
1186 |
return; |
|
1187 |
} |
|
1188 |
||
16 | 1189 |
// Make sure the add-new stays at the end. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
if ( ! themes.isInstall && page >= 1 ) { |
5 | 1191 |
$( '.add-new-theme' ).remove(); |
1192 |
} |
|
1193 |
||
16 | 1194 |
// Loop through the themes and setup each theme view. |
5 | 1195 |
self.instance.each( function( theme ) { |
1196 |
self.theme = new themes.view.Theme({ |
|
1197 |
model: theme, |
|
1198 |
parent: self |
|
1199 |
}); |
|
1200 |
||
1201 |
// Render the views... |
|
1202 |
self.theme.render(); |
|
16 | 1203 |
// ...and append them to div.themes. |
5 | 1204 |
self.$el.append( self.theme.el ); |
1205 |
||
1206 |
// Binds to theme:expand to show the modal box |
|
16 | 1207 |
// with the theme details. |
5 | 1208 |
self.listenTo( self.theme, 'theme:expand', self.expand, self ); |
1209 |
}); |
|
1210 |
||
16 | 1211 |
// 'Add new theme' element shown at the end of the grid. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
if ( ! themes.isInstall && themes.data.settings.canInstall ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
this.$el.append( '<div class="theme add-new-theme"><a href="' + themes.data.settings.installURI + '"><div class="theme-screenshot"><span></span></div><h2 class="theme-name">' + l10n.addNew + '</h2></a></div>' ); |
5 | 1214 |
} |
1215 |
||
1216 |
this.parent.page++; |
|
1217 |
}, |
|
1218 |
||
16 | 1219 |
// Grabs current theme and puts it at the beginning of the collection. |
5 | 1220 |
currentTheme: function() { |
1221 |
var self = this, |
|
1222 |
current; |
|
1223 |
||
1224 |
current = self.collection.findWhere({ active: true }); |
|
1225 |
||
16 | 1226 |
// Move the active theme to the beginning of the collection. |
5 | 1227 |
if ( current ) { |
1228 |
self.collection.remove( current ); |
|
1229 |
self.collection.add( current, { at:0 } ); |
|
1230 |
} |
|
1231 |
}, |
|
1232 |
||
16 | 1233 |
// Sets current view. |
5 | 1234 |
setView: function( view ) { |
1235 |
return view; |
|
1236 |
}, |
|
1237 |
||
16 | 1238 |
// Renders the overlay with the ThemeDetails view. |
1239 |
// Uses the current model data. |
|
5 | 1240 |
expand: function( id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
var self = this, $card, $modal; |
5 | 1242 |
|
16 | 1243 |
// Set the current theme model. |
5 | 1244 |
this.model = self.collection.get( id ); |
1245 |
||
16 | 1246 |
// Trigger a route update for the current model. |
5 | 1247 |
themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.id ) ); |
1248 |
||
16 | 1249 |
// Sets this.view to 'detail'. |
5 | 1250 |
this.setView( 'detail' ); |
1251 |
$( 'body' ).addClass( 'modal-open' ); |
|
1252 |
||
16 | 1253 |
// Set up the theme details view. |
5 | 1254 |
this.overlay = new themes.view.Details({ |
1255 |
model: self.model |
|
1256 |
}); |
|
1257 |
||
1258 |
this.overlay.render(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
if ( this.model.get( 'hasUpdate' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
$card = $( '[data-slug="' + this.model.id + '"]' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
$modal = $( this.overlay.el ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
if ( $card.find( '.updating-message' ).length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
$modal.find( '.notice-warning h3' ).remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
$modal.find( '.notice-warning' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
.removeClass( 'notice-large' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
.addClass( 'updating-message' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
.find( 'p' ).text( wp.updates.l10n.updating ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
} else if ( $card.find( '.notice-error' ).length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
$modal.find( '.notice-warning' ).remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
|
5 | 1275 |
this.$overlay.html( this.overlay.el ); |
1276 |
||
16 | 1277 |
// Bind to theme:next and theme:previous triggered by the arrow keys. |
1278 |
// Keep track of the current model so we can infer an index position. |
|
5 | 1279 |
this.listenTo( this.overlay, 'theme:next', function() { |
16 | 1280 |
// Renders the next theme on the overlay. |
5 | 1281 |
self.next( [ self.model.cid ] ); |
1282 |
||
1283 |
}) |
|
1284 |
.listenTo( this.overlay, 'theme:previous', function() { |
|
16 | 1285 |
// Renders the previous theme on the overlay. |
5 | 1286 |
self.previous( [ self.model.cid ] ); |
1287 |
}); |
|
1288 |
}, |
|
1289 |
||
16 | 1290 |
/* |
1291 |
* This method renders the next theme on the overlay modal |
|
1292 |
* based on the current position in the collection. |
|
1293 |
* |
|
1294 |
* @params [model cid] |
|
1295 |
*/ |
|
5 | 1296 |
next: function( args ) { |
1297 |
var self = this, |
|
1298 |
model, nextModel; |
|
1299 |
||
16 | 1300 |
// Get the current theme. |
5 | 1301 |
model = self.collection.get( args[0] ); |
16 | 1302 |
// Find the next model within the collection. |
5 | 1303 |
nextModel = self.collection.at( self.collection.indexOf( model ) + 1 ); |
1304 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
// Confidence check which also serves as a boundary test. |
5 | 1306 |
if ( nextModel !== undefined ) { |
1307 |
||
1308 |
// We have a new theme... |
|
16 | 1309 |
// Close the overlay. |
5 | 1310 |
this.overlay.closeOverlay(); |
1311 |
||
16 | 1312 |
// Trigger a route update for the current model. |
5 | 1313 |
self.theme.trigger( 'theme:expand', nextModel.cid ); |
1314 |
||
1315 |
} |
|
1316 |
}, |
|
1317 |
||
16 | 1318 |
/* |
1319 |
* This method renders the previous theme on the overlay modal |
|
1320 |
* based on the current position in the collection. |
|
1321 |
* |
|
1322 |
* @params [model cid] |
|
1323 |
*/ |
|
5 | 1324 |
previous: function( args ) { |
1325 |
var self = this, |
|
1326 |
model, previousModel; |
|
1327 |
||
16 | 1328 |
// Get the current theme. |
5 | 1329 |
model = self.collection.get( args[0] ); |
16 | 1330 |
// Find the previous model within the collection. |
5 | 1331 |
previousModel = self.collection.at( self.collection.indexOf( model ) - 1 ); |
1332 |
||
1333 |
if ( previousModel !== undefined ) { |
|
1334 |
||
1335 |
// We have a new theme... |
|
16 | 1336 |
// Close the overlay. |
5 | 1337 |
this.overlay.closeOverlay(); |
1338 |
||
16 | 1339 |
// Trigger a route update for the current model. |
5 | 1340 |
self.theme.trigger( 'theme:expand', previousModel.cid ); |
1341 |
||
1342 |
} |
|
1343 |
}, |
|
1344 |
||
16 | 1345 |
// Dispatch audible search results feedback message. |
5 | 1346 |
announceSearchResults: function( count ) { |
1347 |
if ( 0 === count ) { |
|
1348 |
wp.a11y.speak( l10n.noThemesFound ); |
|
1349 |
} else { |
|
1350 |
wp.a11y.speak( l10n.themesFound.replace( '%d', count ) ); |
|
1351 |
} |
|
1352 |
} |
|
1353 |
}); |
|
1354 |
||
1355 |
// Search input view controller. |
|
1356 |
themes.view.Search = wp.Backbone.View.extend({ |
|
1357 |
||
1358 |
tagName: 'input', |
|
1359 |
className: 'wp-filter-search', |
|
1360 |
id: 'wp-filter-search-input', |
|
1361 |
searching: false, |
|
1362 |
||
1363 |
attributes: { |
|
1364 |
type: 'search', |
|
1365 |
'aria-describedby': 'live-search-desc' |
|
1366 |
}, |
|
1367 |
||
1368 |
events: { |
|
1369 |
'input': 'search', |
|
1370 |
'keyup': 'search', |
|
1371 |
'blur': 'pushState' |
|
1372 |
}, |
|
1373 |
||
1374 |
initialize: function( options ) { |
|
1375 |
||
1376 |
this.parent = options.parent; |
|
1377 |
||
1378 |
this.listenTo( this.parent, 'theme:close', function() { |
|
1379 |
this.searching = false; |
|
1380 |
} ); |
|
1381 |
||
1382 |
}, |
|
1383 |
||
1384 |
search: function( event ) { |
|
1385 |
// Clear on escape. |
|
1386 |
if ( event.type === 'keyup' && event.which === 27 ) { |
|
1387 |
event.target.value = ''; |
|
1388 |
} |
|
1389 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
// Since doSearch is debounced, it will only run when user input comes to a rest. |
5 | 1391 |
this.doSearch( event ); |
1392 |
}, |
|
1393 |
||
1394 |
// Runs a search on the theme collection. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
doSearch: function( event ) { |
5 | 1396 |
var options = {}; |
1397 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
this.collection.doSearch( event.target.value.replace( /\+/g, ' ' ) ); |
5 | 1399 |
|
16 | 1400 |
// if search is initiated and key is not return. |
5 | 1401 |
if ( this.searching && event.which !== 13 ) { |
1402 |
options.replace = true; |
|
1403 |
} else { |
|
1404 |
this.searching = true; |
|
1405 |
} |
|
1406 |
||
16 | 1407 |
// Update the URL hash. |
5 | 1408 |
if ( event.target.value ) { |
1409 |
themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + event.target.value ), options ); |
|
1410 |
} else { |
|
1411 |
themes.router.navigate( themes.router.baseUrl( '' ) ); |
|
1412 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
}, |
5 | 1414 |
|
1415 |
pushState: function( event ) { |
|
1416 |
var url = themes.router.baseUrl( '' ); |
|
1417 |
||
1418 |
if ( event.target.value ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
url = themes.router.baseUrl( themes.router.searchPath + encodeURIComponent( event.target.value ) ); |
5 | 1420 |
} |
1421 |
||
1422 |
this.searching = false; |
|
1423 |
themes.router.navigate( url ); |
|
1424 |
||
1425 |
} |
|
1426 |
}); |
|
1427 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
* Navigate router. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* @param {string} url - URL to navigate to. |
16 | 1434 |
* @param {Object} state - State. |
1435 |
* @return {void} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
function navigateRouter( url, state ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
var router = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
if ( Backbone.history._hasPushState ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
Backbone.Router.prototype.navigate.call( router, url, state ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
|
16 | 1444 |
// Sets up the routes events for relevant url queries. |
1445 |
// Listens to [theme] and [search] params. |
|
5 | 1446 |
themes.Router = Backbone.Router.extend({ |
1447 |
||
1448 |
routes: { |
|
1449 |
'themes.php?theme=:slug': 'theme', |
|
1450 |
'themes.php?search=:query': 'search', |
|
1451 |
'themes.php?s=:query': 'search', |
|
1452 |
'themes.php': 'themes', |
|
1453 |
'': 'themes' |
|
1454 |
}, |
|
1455 |
||
1456 |
baseUrl: function( url ) { |
|
1457 |
return 'themes.php' + url; |
|
1458 |
}, |
|
1459 |
||
1460 |
themePath: '?theme=', |
|
1461 |
searchPath: '?search=', |
|
1462 |
||
1463 |
search: function( query ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
$( '.wp-filter-search' ).val( query.replace( /\+/g, ' ' ) ); |
5 | 1465 |
}, |
1466 |
||
1467 |
themes: function() { |
|
1468 |
$( '.wp-filter-search' ).val( '' ); |
|
1469 |
}, |
|
1470 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
navigate: navigateRouter |
5 | 1472 |
|
1473 |
}); |
|
1474 |
||
16 | 1475 |
// Execute and setup the application. |
5 | 1476 |
themes.Run = { |
1477 |
init: function() { |
|
16 | 1478 |
// Initializes the blog's theme library view. |
1479 |
// Create a new collection with data. |
|
5 | 1480 |
this.themes = new themes.Collection( themes.data.themes ); |
1481 |
||
16 | 1482 |
// Set up the view. |
5 | 1483 |
this.view = new themes.view.Appearance({ |
1484 |
collection: this.themes |
|
1485 |
}); |
|
1486 |
||
1487 |
this.render(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
// Start debouncing user searches after Backbone.history.start(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
this.view.SearchView.doSearch = _.debounce( this.view.SearchView.doSearch, 500 ); |
5 | 1491 |
}, |
1492 |
||
1493 |
render: function() { |
|
1494 |
||
16 | 1495 |
// Render results. |
5 | 1496 |
this.view.render(); |
1497 |
this.routes(); |
|
1498 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
if ( Backbone.History.started ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
Backbone.history.stop(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
} |
5 | 1502 |
Backbone.history.start({ |
1503 |
root: themes.data.settings.adminUrl, |
|
1504 |
pushState: true, |
|
1505 |
hashChange: false |
|
1506 |
}); |
|
1507 |
}, |
|
1508 |
||
1509 |
routes: function() { |
|
1510 |
var self = this; |
|
1511 |
// Bind to our global thx object |
|
16 | 1512 |
// so that the object is available to sub-views. |
5 | 1513 |
themes.router = new themes.Router(); |
1514 |
||
16 | 1515 |
// Handles theme details route event. |
5 | 1516 |
themes.router.on( 'route:theme', function( slug ) { |
1517 |
self.view.view.expand( slug ); |
|
1518 |
}); |
|
1519 |
||
1520 |
themes.router.on( 'route:themes', function() { |
|
1521 |
self.themes.doSearch( '' ); |
|
1522 |
self.view.trigger( 'theme:close' ); |
|
1523 |
}); |
|
1524 |
||
16 | 1525 |
// Handles search route event. |
5 | 1526 |
themes.router.on( 'route:search', function() { |
1527 |
$( '.wp-filter-search' ).trigger( 'keyup' ); |
|
1528 |
}); |
|
1529 |
||
1530 |
this.extraRoutes(); |
|
1531 |
}, |
|
1532 |
||
1533 |
extraRoutes: function() { |
|
1534 |
return false; |
|
1535 |
} |
|
1536 |
}; |
|
1537 |
||
16 | 1538 |
// Extend the main Search view. |
5 | 1539 |
themes.view.InstallerSearch = themes.view.Search.extend({ |
1540 |
||
1541 |
events: { |
|
1542 |
'input': 'search', |
|
1543 |
'keyup': 'search' |
|
1544 |
}, |
|
1545 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
terms: '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
|
16 | 1548 |
// Handles Ajax request for searching through themes in public repo. |
5 | 1549 |
search: function( event ) { |
1550 |
||
16 | 1551 |
// Tabbing or reverse tabbing into the search input shouldn't trigger a search. |
5 | 1552 |
if ( event.type === 'keyup' && ( event.which === 9 || event.which === 16 ) ) { |
1553 |
return; |
|
1554 |
} |
|
1555 |
||
1556 |
this.collection = this.options.parent.view.collection; |
|
1557 |
||
1558 |
// Clear on escape. |
|
1559 |
if ( event.type === 'keyup' && event.which === 27 ) { |
|
1560 |
event.target.value = ''; |
|
1561 |
} |
|
1562 |
||
1563 |
this.doSearch( event.target.value ); |
|
1564 |
}, |
|
1565 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1566 |
doSearch: function( value ) { |
5 | 1567 |
var request = {}; |
1568 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
// Don't do anything if the search terms haven't changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
if ( this.terms === value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
// Updates terms with the value passed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
this.terms = value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
|
5 | 1577 |
request.search = value; |
1578 |
||
16 | 1579 |
/* |
1580 |
* Intercept an [author] search. |
|
1581 |
* |
|
1582 |
* If input value starts with `author:` send a request |
|
1583 |
* for `author` instead of a regular `search`. |
|
1584 |
*/ |
|
5 | 1585 |
if ( value.substring( 0, 7 ) === 'author:' ) { |
1586 |
request.search = ''; |
|
1587 |
request.author = value.slice( 7 ); |
|
1588 |
} |
|
1589 |
||
16 | 1590 |
/* |
1591 |
* Intercept a [tag] search. |
|
1592 |
* |
|
1593 |
* If input value starts with `tag:` send a request |
|
1594 |
* for `tag` instead of a regular `search`. |
|
1595 |
*/ |
|
5 | 1596 |
if ( value.substring( 0, 4 ) === 'tag:' ) { |
1597 |
request.search = ''; |
|
1598 |
request.tag = [ value.slice( 4 ) ]; |
|
1599 |
} |
|
1600 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1601 |
$( '.filter-links li > a.current' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
.removeClass( 'current' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1603 |
.removeAttr( 'aria-current' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
$( 'body' ).removeClass( 'show-filters filters-applied show-favorites-form' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
$( '.drawer-toggle' ).attr( 'aria-expanded', 'false' ); |
5 | 1607 |
|
1608 |
// Get the themes by sending Ajax POST request to api.wordpress.org/themes |
|
16 | 1609 |
// or searching the local cache. |
5 | 1610 |
this.collection.query( request ); |
1611 |
||
16 | 1612 |
// Set route. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + encodeURIComponent( value ) ), { replace: true } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
} |
5 | 1615 |
}); |
1616 |
||
1617 |
themes.view.Installer = themes.view.Appearance.extend({ |
|
1618 |
||
1619 |
el: '#wpbody-content .wrap', |
|
1620 |
||
16 | 1621 |
// Register events for sorting and filters in theme-navigation. |
5 | 1622 |
events: { |
1623 |
'click .filter-links li > a': 'onSort', |
|
1624 |
'click .theme-filter': 'onFilter', |
|
1625 |
'click .drawer-toggle': 'moreFilters', |
|
1626 |
'click .filter-drawer .apply-filters': 'applyFilters', |
|
1627 |
'click .filter-group [type="checkbox"]': 'addFilter', |
|
1628 |
'click .filter-drawer .clear-filters': 'clearFilters', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
'click .edit-filters': 'backToFilters', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
'click .favorites-form-submit' : 'saveUsername', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
'keyup #wporg-username-input': 'saveUsername' |
5 | 1632 |
}, |
1633 |
||
16 | 1634 |
// Initial render method. |
5 | 1635 |
render: function() { |
1636 |
var self = this; |
|
1637 |
||
1638 |
this.search(); |
|
1639 |
this.uploader(); |
|
1640 |
||
1641 |
this.collection = new themes.Collection(); |
|
1642 |
||
1643 |
// Bump `collection.currentQuery.page` and request more themes if we hit the end of the page. |
|
1644 |
this.listenTo( this, 'theme:end', function() { |
|
1645 |
||
16 | 1646 |
// Make sure we are not already loading. |
5 | 1647 |
if ( self.collection.loadingThemes ) { |
1648 |
return; |
|
1649 |
} |
|
1650 |
||
1651 |
// Set loadingThemes to true and bump page instance of currentQuery. |
|
1652 |
self.collection.loadingThemes = true; |
|
1653 |
self.collection.currentQuery.page++; |
|
1654 |
||
1655 |
// Use currentQuery.page to build the themes request. |
|
1656 |
_.extend( self.collection.currentQuery.request, { page: self.collection.currentQuery.page } ); |
|
1657 |
self.collection.query( self.collection.currentQuery.request ); |
|
1658 |
}); |
|
1659 |
||
1660 |
this.listenTo( this.collection, 'query:success', function() { |
|
1661 |
$( 'body' ).removeClass( 'loading-content' ); |
|
1662 |
$( '.theme-browser' ).find( 'div.error' ).remove(); |
|
1663 |
}); |
|
1664 |
||
1665 |
this.listenTo( this.collection, 'query:fail', function() { |
|
1666 |
$( 'body' ).removeClass( 'loading-content' ); |
|
1667 |
$( '.theme-browser' ).find( 'div.error' ).remove(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
$( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p><p><button class="button try-again">' + l10n.tryAgain + '</button></p></div>' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
$( '.theme-browser .error .try-again' ).on( 'click', function( e ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1670 |
e.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
$( 'input.wp-filter-search' ).trigger( 'input' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
} ); |
5 | 1673 |
}); |
1674 |
||
1675 |
if ( this.view ) { |
|
1676 |
this.view.remove(); |
|
1677 |
} |
|
1678 |
||
16 | 1679 |
// Sets up the view and passes the section argument. |
5 | 1680 |
this.view = new themes.view.Themes({ |
1681 |
collection: this.collection, |
|
1682 |
parent: this |
|
1683 |
}); |
|
1684 |
||
16 | 1685 |
// Reset pagination every time the install view handler is run. |
5 | 1686 |
this.page = 0; |
1687 |
||
16 | 1688 |
// Render and append. |
5 | 1689 |
this.$el.find( '.themes' ).remove(); |
1690 |
this.view.render(); |
|
1691 |
this.$el.find( '.theme-browser' ).append( this.view.el ).addClass( 'rendered' ); |
|
1692 |
}, |
|
1693 |
||
16 | 1694 |
// Handles all the rendering of the public theme directory. |
5 | 1695 |
browse: function( section ) { |
1696 |
// Create a new collection with the proper theme data |
|
16 | 1697 |
// for each section. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1698 |
if ( 'block-themes' === section ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1699 |
// Get the themes by sending Ajax POST request to api.wordpress.org/themes |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1700 |
// or searching the local cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
this.collection.query( { tag: 'full-site-editing' } ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
this.collection.query( { browse: section } ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1704 |
} |
5 | 1705 |
}, |
1706 |
||
16 | 1707 |
// Sorting navigation. |
5 | 1708 |
onSort: function( event ) { |
1709 |
var $el = $( event.target ), |
|
1710 |
sort = $el.data( 'sort' ); |
|
1711 |
||
0 | 1712 |
event.preventDefault(); |
5 | 1713 |
|
1714 |
$( 'body' ).removeClass( 'filters-applied show-filters' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
$( '.drawer-toggle' ).attr( 'aria-expanded', 'false' ); |
5 | 1716 |
|
16 | 1717 |
// Bail if this is already active. |
5 | 1718 |
if ( $el.hasClass( this.activeClass ) ) { |
1719 |
return; |
|
1720 |
} |
|
1721 |
||
1722 |
this.sort( sort ); |
|
1723 |
||
16 | 1724 |
// Trigger a router.navigate update. |
5 | 1725 |
themes.router.navigate( themes.router.baseUrl( themes.router.browsePath + sort ) ); |
1726 |
}, |
|
1727 |
||
1728 |
sort: function( sort ) { |
|
1729 |
this.clearSearch(); |
|
1730 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
// Track sorting so we can restore the correct tab when closing preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
themes.router.selectedTab = sort; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
$( '.filter-links li > a, .theme-filter' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
.removeClass( this.activeClass ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
.removeAttr( 'aria-current' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
$( '[data-sort="' + sort + '"]' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
.addClass( this.activeClass ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
.attr( 'aria-current', 'page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
if ( 'favorites' === sort ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
$( 'body' ).addClass( 'show-favorites-form' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
$( 'body' ).removeClass( 'show-favorites-form' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
} |
5 | 1747 |
|
1748 |
this.browse( sort ); |
|
1749 |
}, |
|
1750 |
||
16 | 1751 |
// Filters and Tags. |
5 | 1752 |
onFilter: function( event ) { |
1753 |
var request, |
|
1754 |
$el = $( event.target ), |
|
1755 |
filter = $el.data( 'filter' ); |
|
1756 |
||
16 | 1757 |
// Bail if this is already active. |
5 | 1758 |
if ( $el.hasClass( this.activeClass ) ) { |
1759 |
return; |
|
1760 |
} |
|
1761 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
$( '.filter-links li > a, .theme-section' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
.removeClass( this.activeClass ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
.removeAttr( 'aria-current' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
$el |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
.addClass( this.activeClass ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
.attr( 'aria-current', 'page' ); |
5 | 1768 |
|
1769 |
if ( ! filter ) { |
|
1770 |
return; |
|
1771 |
} |
|
1772 |
||
1773 |
// Construct the filter request |
|
16 | 1774 |
// using the default values. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
filter = _.union( [ filter, this.filtersChecked() ] ); |
5 | 1776 |
request = { tag: [ filter ] }; |
1777 |
||
1778 |
// Get the themes by sending Ajax POST request to api.wordpress.org/themes |
|
16 | 1779 |
// or searching the local cache. |
5 | 1780 |
this.collection.query( request ); |
1781 |
}, |
|
1782 |
||
16 | 1783 |
// Clicking on a checkbox to add another filter to the request. |
5 | 1784 |
addFilter: function() { |
1785 |
this.filtersChecked(); |
|
1786 |
}, |
|
1787 |
||
16 | 1788 |
// Applying filters triggers a tag request. |
5 | 1789 |
applyFilters: function( event ) { |
1790 |
var name, |
|
1791 |
tags = this.filtersChecked(), |
|
1792 |
request = { tag: tags }, |
|
1793 |
filteringBy = $( '.filtered-by .tags' ); |
|
1794 |
||
1795 |
if ( event ) { |
|
1796 |
event.preventDefault(); |
|
1797 |
} |
|
1798 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
if ( ! tags ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
wp.a11y.speak( l10n.selectFeatureFilter ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
|
5 | 1804 |
$( 'body' ).addClass( 'filters-applied' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
$( '.filter-links li > a.current' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
.removeClass( 'current' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
.removeAttr( 'aria-current' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
|
5 | 1809 |
filteringBy.empty(); |
1810 |
||
1811 |
_.each( tags, function( tag ) { |
|
1812 |
name = $( 'label[for="filter-id-' + tag + '"]' ).text(); |
|
1813 |
filteringBy.append( '<span class="tag">' + name + '</span>' ); |
|
1814 |
}); |
|
1815 |
||
1816 |
// Get the themes by sending Ajax POST request to api.wordpress.org/themes |
|
16 | 1817 |
// or searching the local cache. |
5 | 1818 |
this.collection.query( request ); |
1819 |
}, |
|
1820 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
// Save the user's WordPress.org username and get his favorite themes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
saveUsername: function ( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1823 |
var username = $( '#wporg-username-input' ).val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
nonce = $( '#wporg-username-nonce' ).val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
request = { browse: 'favorites', user: username }, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
that = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1827 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
if ( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1831 |
|
16 | 1832 |
// Save username on enter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1833 |
if ( event.type === 'keyup' && event.which !== 13 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1834 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1835 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1836 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1837 |
return wp.ajax.send( 'save-wporg-username', { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1838 |
data: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
_wpnonce: nonce, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1840 |
username: username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1841 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1842 |
success: function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
// Get the themes by sending Ajax POST request to api.wordpress.org/themes |
16 | 1844 |
// or searching the local cache. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1845 |
that.collection.query( request ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1846 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1849 |
|
16 | 1850 |
/** |
1851 |
* Get the checked filters. |
|
1852 |
* |
|
1853 |
* @return {Array} of tags or false |
|
1854 |
*/ |
|
5 | 1855 |
filtersChecked: function() { |
1856 |
var items = $( '.filter-group' ).find( ':checkbox' ), |
|
1857 |
tags = []; |
|
1858 |
||
1859 |
_.each( items.filter( ':checked' ), function( item ) { |
|
1860 |
tags.push( $( item ).prop( 'value' ) ); |
|
1861 |
}); |
|
1862 |
||
16 | 1863 |
// When no filters are checked, restore initial state and return. |
5 | 1864 |
if ( tags.length === 0 ) { |
1865 |
$( '.filter-drawer .apply-filters' ).find( 'span' ).text( '' ); |
|
1866 |
$( '.filter-drawer .clear-filters' ).hide(); |
|
1867 |
$( 'body' ).removeClass( 'filters-applied' ); |
|
1868 |
return false; |
|
1869 |
} |
|
1870 |
||
1871 |
$( '.filter-drawer .apply-filters' ).find( 'span' ).text( tags.length ); |
|
1872 |
$( '.filter-drawer .clear-filters' ).css( 'display', 'inline-block' ); |
|
1873 |
||
1874 |
return tags; |
|
1875 |
}, |
|
1876 |
||
1877 |
activeClass: 'current', |
|
1878 |
||
16 | 1879 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
* When users press the "Upload Theme" button, show the upload form in place. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
*/ |
5 | 1882 |
uploader: function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1883 |
var uploadViewToggle = $( '.upload-view-toggle' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
$body = $( document.body ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1885 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
uploadViewToggle.on( 'click', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1887 |
// Toggle the upload view. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
$body.toggleClass( 'show-upload-view' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
// Toggle the `aria-expanded` button attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1890 |
uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) ); |
5 | 1891 |
}); |
1892 |
}, |
|
1893 |
||
16 | 1894 |
// Toggle the full filters navigation. |
5 | 1895 |
moreFilters: function( event ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
var $body = $( 'body' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
$toggleButton = $( '.drawer-toggle' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1898 |
|
5 | 1899 |
event.preventDefault(); |
1900 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1901 |
if ( $body.hasClass( 'filters-applied' ) ) { |
5 | 1902 |
return this.backToFilters(); |
1903 |
} |
|
1904 |
||
1905 |
this.clearSearch(); |
|
1906 |
||
1907 |
themes.router.navigate( themes.router.baseUrl( '' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
// Toggle the feature filters view. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
$body.toggleClass( 'show-filters' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
// Toggle the `aria-expanded` button attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
$toggleButton.attr( 'aria-expanded', $body.hasClass( 'show-filters' ) ); |
5 | 1912 |
}, |
1913 |
||
16 | 1914 |
/** |
1915 |
* Clears all the checked filters. |
|
1916 |
* |
|
1917 |
* @uses filtersChecked() |
|
1918 |
*/ |
|
5 | 1919 |
clearFilters: function( event ) { |
1920 |
var items = $( '.filter-group' ).find( ':checkbox' ), |
|
1921 |
self = this; |
|
1922 |
||
1923 |
event.preventDefault(); |
|
1924 |
||
1925 |
_.each( items.filter( ':checked' ), function( item ) { |
|
1926 |
$( item ).prop( 'checked', false ); |
|
1927 |
return self.filtersChecked(); |
|
1928 |
}); |
|
1929 |
}, |
|
1930 |
||
1931 |
backToFilters: function( event ) { |
|
1932 |
if ( event ) { |
|
1933 |
event.preventDefault(); |
|
1934 |
} |
|
1935 |
||
1936 |
$( 'body' ).removeClass( 'filters-applied' ); |
|
1937 |
}, |
|
1938 |
||
1939 |
clearSearch: function() { |
|
1940 |
$( '#wp-filter-search-input').val( '' ); |
|
1941 |
} |
|
1942 |
}); |
|
1943 |
||
1944 |
themes.InstallerRouter = Backbone.Router.extend({ |
|
1945 |
routes: { |
|
1946 |
'theme-install.php?theme=:slug': 'preview', |
|
1947 |
'theme-install.php?browse=:sort': 'sort', |
|
1948 |
'theme-install.php?search=:query': 'search', |
|
1949 |
'theme-install.php': 'sort' |
|
1950 |
}, |
|
1951 |
||
1952 |
baseUrl: function( url ) { |
|
1953 |
return 'theme-install.php' + url; |
|
1954 |
}, |
|
1955 |
||
1956 |
themePath: '?theme=', |
|
1957 |
browsePath: '?browse=', |
|
1958 |
searchPath: '?search=', |
|
1959 |
||
1960 |
search: function( query ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
$( '.wp-filter-search' ).val( query.replace( /\+/g, ' ' ) ); |
5 | 1962 |
}, |
1963 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
navigate: navigateRouter |
5 | 1965 |
}); |
1966 |
||
1967 |
||
1968 |
themes.RunInstaller = { |
|
1969 |
||
1970 |
init: function() { |
|
16 | 1971 |
// Set up the view. |
1972 |
// Passes the default 'section' as an option. |
|
5 | 1973 |
this.view = new themes.view.Installer({ |
18 | 1974 |
section: 'popular', |
5 | 1975 |
SearchView: themes.view.InstallerSearch |
1976 |
}); |
|
1977 |
||
16 | 1978 |
// Render results. |
5 | 1979 |
this.render(); |
1980 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
// Start debouncing user searches after Backbone.history.start(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
this.view.SearchView.doSearch = _.debounce( this.view.SearchView.doSearch, 500 ); |
5 | 1983 |
}, |
1984 |
||
1985 |
render: function() { |
|
1986 |
||
16 | 1987 |
// Render results. |
5 | 1988 |
this.view.render(); |
1989 |
this.routes(); |
|
1990 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
if ( Backbone.History.started ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
Backbone.history.stop(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
} |
5 | 1994 |
Backbone.history.start({ |
1995 |
root: themes.data.settings.adminUrl, |
|
1996 |
pushState: true, |
|
1997 |
hashChange: false |
|
1998 |
}); |
|
1999 |
}, |
|
2000 |
||
2001 |
routes: function() { |
|
2002 |
var self = this, |
|
2003 |
request = {}; |
|
2004 |
||
2005 |
// Bind to our global `wp.themes` object |
|
16 | 2006 |
// so that the router is available to sub-views. |
5 | 2007 |
themes.router = new themes.InstallerRouter(); |
2008 |
||
16 | 2009 |
// Handles `theme` route event. |
2010 |
// Queries the API for the passed theme slug. |
|
5 | 2011 |
themes.router.on( 'route:preview', function( slug ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
// Remove existing handlers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2014 |
if ( themes.preview ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2015 |
themes.preview.undelegateEvents(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2016 |
themes.preview.unbind(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2017 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2019 |
// If the theme preview is active, set the current theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
if ( self.view.view.theme && self.view.view.theme.preview ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
self.view.view.theme.model = self.view.collection.findWhere( { 'slug': slug } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
self.view.view.theme.preview(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
// Select the theme by slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
request.theme = slug; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
self.view.collection.query( request ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
self.view.collection.trigger( 'update' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2030 |
// Open the theme preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
self.view.collection.once( 'query:success', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
$( 'div[data-slug="' + slug + '"]' ).trigger( 'click' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
} |
5 | 2036 |
}); |
2037 |
||
16 | 2038 |
/* |
2039 |
* Handles sorting / browsing routes. |
|
2040 |
* Also handles the root URL triggering a sort request |
|
18 | 2041 |
* for `popular`, the default view. |
16 | 2042 |
*/ |
5 | 2043 |
themes.router.on( 'route:sort', function( sort ) { |
2044 |
if ( ! sort ) { |
|
18 | 2045 |
sort = 'popular'; |
2046 |
themes.router.navigate( themes.router.baseUrl( '?browse=popular' ), { replace: true } ); |
|
5 | 2047 |
} |
2048 |
self.view.sort( sort ); |
|
2049 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
// Close the preview if open. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
if ( themes.preview ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
themes.preview.close(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
} |
5 | 2054 |
}); |
2055 |
||
2056 |
// The `search` route event. The router populates the input field. |
|
2057 |
themes.router.on( 'route:search', function() { |
|
18 | 2058 |
$( '.wp-filter-search' ).trigger( 'focus' ).trigger( 'keyup' ); |
5 | 2059 |
}); |
2060 |
||
2061 |
this.extraRoutes(); |
|
2062 |
}, |
|
2063 |
||
2064 |
extraRoutes: function() { |
|
2065 |
return false; |
|
2066 |
} |
|
2067 |
}; |
|
2068 |
||
2069 |
// Ready... |
|
18 | 2070 |
$( function() { |
5 | 2071 |
if ( themes.isInstall ) { |
2072 |
themes.RunInstaller.init(); |
|
2073 |
} else { |
|
2074 |
themes.Run.init(); |
|
2075 |
} |
|
2076 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
// Update the return param just in time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
$( document.body ).on( 'click', '.load-customize', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
var link = $( this ), urlParser = document.createElement( 'a' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
urlParser.href = link.prop( 'href' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
urlParser.search = $.param( _.extend( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
wp.customize.utils.parseQueryString( urlParser.search.substr( 1 ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
'return': window.location.href |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
link.prop( 'href', urlParser.href ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
|
5 | 2090 |
$( '.broken-themes .delete-theme' ).on( 'click', function() { |
2091 |
return confirm( _wpThemeSettings.settings.confirmDelete ); |
|
0 | 2092 |
}); |
2093 |
}); |
|
2094 |
||
5 | 2095 |
})( jQuery ); |
2096 |
||
16 | 2097 |
// Align theme browser thickbox. |
18 | 2098 |
jQuery( function($) { |
9 | 2099 |
window.tb_position = function() { |
5 | 2100 |
var tbWindow = $('#TB_window'), |
2101 |
width = $(window).width(), |
|
2102 |
H = $(window).height(), |
|
2103 |
W = ( 1040 < width ) ? 1040 : width, |
|
2104 |
adminbar_height = 0; |
|
0 | 2105 |
|
5 | 2106 |
if ( $('#wpadminbar').length ) { |
2107 |
adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 ); |
|
2108 |
} |
|
0 | 2109 |
|
18 | 2110 |
if ( tbWindow.length >= 1 ) { |
0 | 2111 |
tbWindow.width( W - 50 ).height( H - 45 - adminbar_height ); |
2112 |
$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height ); |
|
2113 |
tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'}); |
|
5 | 2114 |
if ( typeof document.body.style.maxWidth !== 'undefined' ) { |
2115 |
tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'}); |
|
2116 |
} |
|
2117 |
} |
|
0 | 2118 |
}; |
2119 |
||
18 | 2120 |
$(window).on( 'resize', function(){ tb_position(); }); |
0 | 2121 |
}); |