Changeset 28123
- Timestamp:
- 04/14/2014 10:05:20 PM (10 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/css/themes.css
r28104 r28123 1714 1714 float: right; 1715 1715 } 1716 .wp-full-overlay.no-navigation .theme-navigation { 1717 display: none; 1718 } 1716 1719 1717 1720 /* Animations */ -
trunk/src/wp-admin/js/theme.js
r28105 r28123 23 23 // Map `id` to `slug` for shared code 24 24 initialize: function() { 25 var install ;25 var install, description; 26 26 27 27 // Install url for the theme … … 47 47 id: this.get( 'slug' ) || this.get( 'id' ) 48 48 }); 49 50 // Map `section.description` to `description` 51 // as the API sometimes returns it differently 52 if ( this.has( 'sections' ) ) { 53 description = this.get( 'sections' ).description; 54 this.set({ description: description }); 55 } 49 56 } 50 57 }); … … 219 226 // When we are missing a cache object we fire an apiCall() 220 227 // which triggers events of `query:success` or `query:fail` 221 query: function( request ) {228 query: function( request, action ) { 222 229 /** 223 230 * @static … … 248 255 // Otherwise, send a new API call and add it to the cache. 249 256 if ( ! query && ! isPaginated ) { 250 query = this.apiCall( request ).done( function( data ) { 257 query = this.apiCall( request, action ).done( function( data ) { 258 251 259 // Update the collection with the queried data. 252 self.reset( data.themes ); 253 count = data.info.results; 260 if ( data.themes ) { 261 self.reset( data.themes ); 262 count = data.info.results; 263 // Store the results and the query request 264 queries.push( { themes: data.themes, request: request, total: count } ); 265 266 } else if ( action ) { 267 self.reset( data ); 268 count = 1; 269 self.trigger( 'query:theme' ); 270 } 254 271 255 272 // Trigger a collection refresh event … … 258 275 self.trigger( 'query:success', count ); 259 276 260 if ( data.themes .length === 0 ) {277 if ( data.themes && data.themes.length === 0 ) { 261 278 self.trigger( 'query:empty' ); 262 279 } 263 280 264 // Store the results and the query request265 queries.push( { themes: data.themes, request: request, total: count } );266 281 }).fail( function() { 267 282 self.trigger( 'query:fail' ); … … 270 285 // If it's a paginated request we need to fetch more themes... 271 286 if ( isPaginated ) { 272 return this.apiCall( request, isPaginated ).done( function( data ) {287 return this.apiCall( request, action, isPaginated ).done( function( data ) { 273 288 // Add the new themes to the current collection 274 289 // @todo update counter … … 315 330 316 331 // Send request to api.wordpress.org/themes 317 apiCall: function( request, paginated ) {332 apiCall: function( request, action, paginated ) { 318 333 319 334 // Send tags (and fields) as comma-separated to keep the JSONP query string short. 320 335 if ( request.tag && _.isArray( request.tag ) ) { 321 336 request.tag = request.tag.join( ',' ); 337 } 338 339 // Set request action 340 if ( ! action ) { 341 action = 'query_themes' 322 342 } 323 343 … … 330 350 // Request data 331 351 data: { 332 action: 'query_themes',352 action: action, 333 353 request: _.extend({ 334 354 per_page: 72, … … 483 503 preview.render(); 484 504 this.setNavButtonsState(); 505 506 // Hide previous/next navigation if there is only one theme 507 if ( this.model.collection.length === 1 ) { 508 preview.$el.addClass( 'no-navigation' ); 509 } else { 510 preview.$el.removeClass( 'no-navigation' ); 511 } 512 513 // Apend preview 485 514 $( 'div.wrap' ).append( preview.el ); 486 515 … … 781 810 themes.router.navigate( themes.router.baseUrl( '' ) ); 782 811 this.trigger( 'preview:close' ); 812 this.unbind(); 783 813 return false; 784 814 }, … … 1306 1336 }, 1307 1337 1308 // Handles all the rendering of the public theme directory1309 browse: function( section) {1338 // Initial render method 1339 render: function() { 1310 1340 var self = this; 1341 1342 this.search(); 1343 this.uploader(); 1311 1344 1312 1345 this.collection = new themes.Collection(); … … 1340 1373 }); 1341 1374 1342 // Create a new collection with the proper theme data1343 // for each section1344 this.collection.query( { browse: section } );1345 1346 1375 if ( this.view ) { 1347 1376 this.view.remove(); … … 1351 1380 this.view = new themes.view.Themes({ 1352 1381 collection: this.collection, 1353 section: section,1354 1382 parent: this 1355 1383 }); … … 1364 1392 }, 1365 1393 1366 // Initial render method1367 render: function() {1368 this.search();1369 this.uploader();1370 return this.browse( this.options.section);1394 // Handles all the rendering of the public theme directory 1395 browse: function( section ) { 1396 // Create a new collection with the proper theme data 1397 // for each section 1398 this.collection.query( { browse: section } ); 1371 1399 }, 1372 1400 … … 1555 1583 'theme-install.php?upload': 'upload', 1556 1584 'theme-install.php?search=:query': 'search', 1557 ' ': 'sort'1585 'theme-install.php': 'sort' 1558 1586 }, 1559 1587 … … 1597 1625 1598 1626 routes: function() { 1599 var self = this; 1600 // Bind to our global thx object 1601 // so that the object is available to sub-views 1627 var self = this, 1628 request = {}; 1629 1630 // Bind to our global `wp.themes` object 1631 // so that the router is available to sub-views 1602 1632 themes.router = new themes.InstallerRouter(); 1603 1633 1604 // Handles theme details route event 1605 themes.router.on( 'route:theme', function( slug ) { 1606 self.view.view.expand( slug ); 1607 }); 1608 1634 // Handles `theme` route event 1635 // Queries the API for the passed theme slug 1636 themes.router.on( 'route:preview', function( slug ) { 1637 request.slug = slug; 1638 self.view.collection.query( request, 'theme_information' ); 1639 }); 1640 1641 // Handles sorting / browsing routes 1642 // Also handles the root URL triggering a sort request 1643 // for `featured`, the default view 1609 1644 themes.router.on( 'route:sort', function( sort ) { 1610 1645 if ( ! sort ) { … … 1615 1650 }); 1616 1651 1652 // Support the `upload` route by going straight to upload section 1617 1653 themes.router.on( 'route:upload', function() { 1618 1654 $( 'a.upload' ).trigger( 'click' ); 1619 1655 }); 1620 1656 1621 // Handles search route event1657 // The `search` route event. The router populates the input field. 1622 1658 themes.router.on( 'route:search', function() { 1623 1659 $( '.theme-search' ).focus().trigger( 'keyup' ); -
trunk/src/wp-admin/theme-install.php
r28105 r28123 123 123 <div class="theme-navigation"> 124 124 <span class="theme-count"></span> 125 <a class="theme-section current" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>125 <a class="theme-section" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a> 126 126 <a class="theme-section" href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a> 127 127 <a class="theme-section" href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a>
Note: See TracChangeset
for help on using the changeset viewer.