Ticket #39683: 39683.diff
| File 39683.diff, 3.6 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/js/wp-api.js
1095 1095 /** 1096 1096 * Tracking objects for models and collections. 1097 1097 */ 1098 loadingObjects.models = routeModel.get( 'models' );1099 loadingObjects.collections = routeModel.get( 'collections' );1098 loadingObjects.models = {}; 1099 loadingObjects.collections = {}; 1100 1100 1101 1101 _.each( routeModel.schemaModel.get( 'routes' ), function( route, index ) { 1102 1102 … … 1266 1266 loadingObjects.collections[ collectionClassName ] = wp.api.WPApiBaseCollection.extend( { 1267 1267 1268 1268 // For the url of a root level collection, use a string. 1269 url: routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) + routeName, 1269 url: function() { 1270 return routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) + routeName; 1271 }, 1270 1272 1271 1273 // Specify the model that this collection contains. 1272 1274 model: function( attrs, options ) { … … 1293 1295 loadingObjects.models[ index ] = wp.api.utils.addMixinsAndHelpers( model, index, loadingObjects ); 1294 1296 } ); 1295 1297 1298 // Set the routeModel models and collections. 1299 routeModel.set( 'models', loadingObjects.models ); 1300 routeModel.set( 'collections', loadingObjects.collections ); 1301 1296 1302 } 1297 1303 1298 1304 } ); 1299 1305 1300 wp.api.endpoints = new Backbone.Collection( { 1301 model: Endpoint 1302 } ); 1306 wp.api.endpoints = new Backbone.Collection(); 1303 1307 1304 1308 /** 1305 1309 * Initialize the wp-api, optionally passing the API root. … … 1313 1317 var endpoint, attributes = {}, deferred, promise; 1314 1318 1315 1319 args = args || {}; 1316 attributes.apiRoot = args.apiRoot || wpApiSettings.root ;1317 attributes.versionString = args.versionString || wpApiSettings.versionString ;1320 attributes.apiRoot = args.apiRoot || wpApiSettings.root || '/wp-json'; 1321 attributes.versionString = args.versionString || wpApiSettings.versionString || 'wp/v2/'; 1318 1322 attributes.schema = args.schema || null; 1319 1323 if ( ! attributes.schema && attributes.apiRoot === wpApiSettings.root && attributes.versionString === wpApiSettings.versionString ) { 1320 1324 attributes.schema = wpApiSettings.schema; … … 1321 1325 } 1322 1326 1323 1327 if ( ! initializedDeferreds[ attributes.apiRoot + attributes.versionString ] ) { 1324 endpoint = wp.api.endpoints.findWhere( { apiRoot: attributes.apiRoot, versionString: attributes.versionString } ); 1328 1329 // Look for an existing copy of this endpoint 1330 endpoint = wp.api.endpoints.findWhere( { 'apiRoot': attributes.apiRoot, 'versionString': attributes.versionString } ); 1325 1331 if ( ! endpoint ) { 1326 1332 endpoint = new Endpoint( attributes ); 1327 wp.api.endpoints.add( endpoint );1328 1333 } 1329 1334 deferred = jQuery.Deferred(); 1330 1335 promise = deferred.promise(); 1331 1336 1332 endpoint.schemaConstructed.done( function( endpoint ) { 1337 endpoint.schemaConstructed.done( function( resolvedEndpoint ) { 1338 wp.api.endpoints.add( resolvedEndpoint ); 1333 1339 1334 1340 // Map the default endpoints, extending any already present items (including Schema model). 1335 wp.api.models = _.extend( endpoint.get( 'models' ), wp.api.models);1336 wp.api.collections = _.extend( endpoint.get( 'collections' ), wp.api.collections);1337 deferred.resolve With( wp.api, [ endpoint ]);1341 wp.api.models = _.extend( wp.api.models, resolvedEndpoint.get( 'models' ) ); 1342 wp.api.collections = _.extend( wp.api.collections, resolvedEndpoint.get( 'collections' ) ); 1343 deferred.resolve( resolvedEndpoint ); 1338 1344 } ); 1339 1345 initializedDeferreds[ attributes.apiRoot + attributes.versionString ] = promise; 1340 1346 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)