Changeset 28126 for trunk/src/wp-admin/js/theme.js
- Timestamp:
- 04/15/2014 01:15:43 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/theme.js
r28123 r28126 23 23 // Map `id` to `slug` for shared code 24 24 initialize: function() { 25 var install, description; 26 27 // Install url for the theme 28 // using the install nonce 29 install = { 30 action: 'install-theme', 31 theme: this.get( 'slug' ), 32 _wpnonce: themes.data.settings._nonceInstall 33 }; 34 35 // Build the url query 36 install = themes.data.settings.updateURI + '?' + $.param( install ); 25 var description; 37 26 38 27 // If theme is already installed, set an attribute. … … 43 32 // Set the attributes 44 33 this.set({ 45 installURI: ( this.get( 'slug' ) ) ? install : false,46 34 // slug is for installation, id is for existing. 47 35 id: this.get( 'slug' ) || this.get( 'id' ) … … 226 214 // When we are missing a cache object we fire an apiCall() 227 215 // which triggers events of `query:success` or `query:fail` 228 query: function( request , action) {216 query: function( request ) { 229 217 /** 230 218 * @static … … 255 243 // Otherwise, send a new API call and add it to the cache. 256 244 if ( ! query && ! isPaginated ) { 257 query = this.apiCall( request , action).done( function( data ) {245 query = this.apiCall( request ).done( function( data ) { 258 246 259 247 // Update the collection with the queried data. … … 263 251 // Store the results and the query request 264 252 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 253 } 271 254 … … 285 268 // If it's a paginated request we need to fetch more themes... 286 269 if ( isPaginated ) { 287 return this.apiCall( request, action,isPaginated ).done( function( data ) {270 return this.apiCall( request, isPaginated ).done( function( data ) { 288 271 // Add the new themes to the current collection 289 272 // @todo update counter … … 311 294 } 312 295 296 this.reset( query.themes ); 313 297 if ( ! query.total ) { 314 298 this.count = this.length; 315 299 } 316 300 317 this.reset( query.themes );318 301 this.trigger( 'update' ); 302 this.trigger( 'query:success', this.count ); 319 303 } 320 304 }, … … 330 314 331 315 // Send request to api.wordpress.org/themes 332 apiCall: function( request, action, paginated ) { 333 334 // Send tags (and fields) as comma-separated to keep the JSONP query string short. 335 if ( request.tag && _.isArray( request.tag ) ) { 336 request.tag = request.tag.join( ',' ); 337 } 338 339 // Set request action 340 if ( ! action ) { 341 action = 'query_themes' 342 } 343 344 // JSONP request to .org API 345 return $.ajax({ 346 url: 'https://api.wordpress.org/themes/info/1.1/?callback=?', 347 dataType: 'jsonp', 348 timeout: 15000, // 15 seconds 349 316 apiCall: function( request, paginated ) { 317 return wp.ajax.send( 'query-themes', { 318 data: { 350 319 // Request data 351 data: {352 action: action,353 320 request: _.extend({ 354 per_page: 72, 355 fields: 'description,tested,requires,rating,downloaded,downloadLink,last_updated,homepage,num_ratings' 321 per_page: 100, 322 fields: { 323 description: true, 324 tested: true, 325 requires: true, 326 rating: true, 327 downloaded: true, 328 downloadLink: true, 329 last_updated: true, 330 homepage: true, 331 num_ratings: true 332 } 356 333 }, request) 357 334 }, … … 1568 1545 }, 1569 1546 1570 backToFilters: function() { 1547 backToFilters: function( event ) { 1548 if ( event ) { 1549 event.preventDefault(); 1550 } 1551 1571 1552 $( 'body' ).removeClass( 'filters-applied' ); 1572 1553 }, … … 1635 1616 // Queries the API for the passed theme slug 1636 1617 themes.router.on( 'route:preview', function( slug ) { 1637 request. slug= slug;1638 self.view.collection.query( request , 'theme_information');1618 request.theme = slug; 1619 self.view.collection.query( request ); 1639 1620 }); 1640 1621
Note: See TracChangeset
for help on using the changeset viewer.