Make WordPress Core

Ticket #65119: 65119.diff

File 65119.diff, 7.0 KB (added by sabernhardt, 5 weeks ago)
  • src/js/_enqueues/wp/api.js

     
    9898        }
    9999
    100100        /**
    101          * Parse date into ISO8601 format.
     101         * Parse date into ISO 8601 format.
    102102         *
    103103         * @param {Date} date.
    104104         */
     
    306306                        /**
    307307                         * Mixin for all content that is time stamped.
    308308                         *
    309                          * This mixin converts between mysql timestamps and JavaScript Dates when syncing a model
     309                         * This mixin converts between MySQL timestamps and JavaScript Dates when syncing a model
    310310                         * to or from the server. For example, a date stored as `2015-12-27T21:22:24` on the server
    311311                         * gets expanded to `Sun Dec 27 2015 14:22:24 GMT-0700 (MST)` when the model is fetched.
    312312                         *
     
    361361                         * Build a helper function to retrieve related model.
    362362                         *
    363363                         * @param {string} parentModel      The parent model.
    364                          * @param {number} modelId          The model ID if the object to request
     364                         * @param {number} modelId          The model ID of the object to request.
    365365                         * @param {string} modelName        The model name to use when constructing the model.
    366366                         * @param {string} embedSourcePoint Where to check the embedded object for _embed data.
    367367                         * @param {string} embedCheckField  Which model field to check to see if the model has data.
     
    423423                         */
    424424                        buildCollectionGetter = function( parentModel, collectionName, embedSourcePoint, embedIndex ) {
    425425                                /**
    426                                  * Returns a promise that resolves to the requested collection
     426                                 * Returns a promise that resolves to the requested collection.
    427427                                 *
    428428                                 * Uses the embedded data if available, otherwise fetches the
    429429                                 * data from the server.
     
    467467                                // Create the new getObjects collection.
    468468                                getObjects = new wp.api.collections[ collectionName ]( properties, classProperties );
    469469
    470                                 // If we didn’t have embedded getObjects, fetch the getObjects data.
     470                                // If we don’t have embedded getObjects, fetch the getObjects data.
    471471                                if ( _.isUndefined( getObjects.models[0] ) ) {
    472472                                        getObjects.fetch( {
    473473                                                success: function( getObjects ) {
     
    497497                         */
    498498                        setHelperParentPost = function( collection, postId ) {
    499499
    500                                 // Attach post_parent id to the collection.
     500                                // Attach parent post ID to the collection.
    501501                                _.each( collection.models, function( model ) {
    502502                                        model.set( 'parent_post', postId );
    503503                                } );
     
    754754                        return model;
    755755                }
    756756
    757                 // Go thru the parsable date fields, if our model contains any of them it gets the TimeStampedMixin.
     757                // Go through the parsable date fields. If our model contains any of them, it gets the TimeStampedMixin.
    758758                _.each( parseableDates, function( theDateKey ) {
    759759                        if ( ! _.isUndefined( model.prototype.args[ theDateKey ] ) ) {
    760760                                hasDate = true;
     
    983983                        },
    984984
    985985                        /**
    986                          * Extend Backbone.Collection.sync to add nince and pagination support.
     986                         * Extend Backbone.Collection.sync to add nonce and pagination support.
    987987                         *
    988988                         * Set nonce header before every Backbone sync.
    989989                         *
     
    11681168                                sessionStorage.getItem( 'wp-api-schema-model' + model.get( 'apiRoot' ) + model.get( 'versionString' ) )
    11691169                        ) {
    11701170
    1171                                 // Used a cached copy of the schema model if available.
     1171                                // Use a cached copy of the schema model if available.
    11721172                                model.schemaModel.set( model.schemaModel.parse( JSON.parse( sessionStorage.getItem( 'wp-api-schema-model' + model.get( 'apiRoot' ) + model.get( 'versionString' ) ) ) ) );
    11731173                        } else {
    11741174                                model.schemaModel.fetch( {
     
    11871187                                                                sessionStorage.setItem( 'wp-api-schema-model' + model.get( 'apiRoot' ) + model.get( 'versionString' ), JSON.stringify( newSchemaModel ) );
    11881188                                                        } catch ( error ) {
    11891189
    1190                                                                 // Fail silently, fixes errors in safari private mode.
     1190                                                                // Fail silently, to avoid errors in Safari private mode.
    11911191                                                        }
    11921192                                                }
    11931193                                        },
     
    12071207                         * Set up the model and collection name mapping options. As the schema is built, the
    12081208                         * model and collection names will be adjusted if they are found in the mapping object.
    12091209                         *
    1210                          * Localizing a variable wpApiSettings.mapping will over-ride the default mapping options.
     1210                         * Localizing a variable wpApiSettings.mapping will override the default mapping options.
    12111211                         *
    12121212                         */
    12131213                        mapping = wpApiSettings.mapping || {
     
    12421242                        modelRegex     = new RegExp( '(?:.*[+)]|\/(' + modelEndpoints.join( '|' ) + '))$' );
    12431243
    12441244                        /**
    1245                          * Iterate thru the routes, picking up models and collections to build. Builds two arrays,
     1245                         * Iterate through the routes, picking up models and collections to build. Builds two arrays,
    12461246                         * one for models and one for collections.
    12471247                         */
    12481248                        modelRoutes      = [];
     
    12881288                                        parentName = wp.api.utils.extractRoutePart( modelRoute.index, 1, routeModel.get( 'versionString' ), false ),
    12891289                                        routeEnd   = wp.api.utils.extractRoutePart( modelRoute.index, 1, routeModel.get( 'versionString' ), true );
    12901290
    1291                                 // Clear the parent part of the rouite if its actually the version string.
     1291                                // Clear the parent part of the route if it is actually the version string.
    12921292                                if ( parentName === routeModel.get( 'versionString' ) ) {
    12931293                                        parentName = '';
    12941294                                }
     
    13041304                                        modelClassName = mapping.models[ modelClassName ] || modelClassName;
    13051305                                        loadingObjects.models[ modelClassName ] = wp.api.WPApiBaseModel.extend( {
    13061306
    1307                                                 // Return a constructed url based on the parent and id.
     1307                                                // Return a constructed URL based on the parent and ID.
    13081308                                                url: function() {
    13091309                                                        var url =
    13101310                                                                routeModel.get( 'apiRoot' ) +
     
    13471347                                        modelClassName = mapping.models[ modelClassName ] || modelClassName;
    13481348                                        loadingObjects.models[ modelClassName ] = wp.api.WPApiBaseModel.extend( {
    13491349
    1350                                                 // Function that returns a constructed url based on the ID.
     1350                                                // Function that returns a constructed URL based on the ID.
    13511351                                                url: function() {
    13521352                                                        var url = routeModel.get( 'apiRoot' ) +
    13531353                                                                routeModel.get( 'versionString' ) +
     
    14091409                                        collectionClassName = mapping.collections[ collectionClassName ] || collectionClassName;
    14101410                                        loadingObjects.collections[ collectionClassName ] = wp.api.WPApiBaseCollection.extend( {
    14111411
    1412                                                 // Function that returns a constructed url passed on the parent.
     1412                                                // Function that returns a constructed URL passed on the parent.
    14131413                                                url: function() {
    14141414                                                        return routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) +
    14151415                                                                parentName + '/' +
     
    14481448                                        collectionClassName = mapping.collections[ collectionClassName ] || collectionClassName;
    14491449                                        loadingObjects.collections[ collectionClassName ] = wp.api.WPApiBaseCollection.extend( {
    14501450
    1451                                                 // For the url of a root level collection, use a string.
     1451                                                // For the URL of a root level collection, use a string.
    14521452                                                url: function() {
    14531453                                                        return routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) + routeName;
    14541454                                                },