diff --git src/wp-includes/js/media-models.js src/wp-includes/js/media-models.js
index cba928d..c8b9b3f 100644
|
|
|
window.wp = window.wp || {};
|
| 65 | 65 | */ |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | | * A basic comparator. |
| | 68 | * A basic equality comparator for Backbone models. |
| | 69 | * |
| | 70 | * Used to order models within a collection - @see wp.media.model.Attachments.comparator(). |
| 69 | 71 | * |
| 70 | 72 | * @param {mixed} a The primary parameter to compare. |
| 71 | 73 | * @param {mixed} b The primary parameter to compare. |
| … |
… |
window.wp = window.wp || {};
|
| 87 | 89 | /** |
| 88 | 90 | * media.template( id ) |
| 89 | 91 | * |
| 90 | | * Fetches a template by id. |
| | 92 | * Fetch a JavaScript template for an id, and return a templating function for it. |
| | 93 | * |
| 91 | 94 | * See wp.template() in `wp-includes/js/wp-util.js`. |
| 92 | 95 | * |
| 93 | 96 | * @borrows wp.template as template |
| … |
… |
window.wp = window.wp || {};
|
| 197 | 200 | /** |
| 198 | 201 | * wp.media.model.Attachment |
| 199 | 202 | * |
| 200 | | * @constructor |
| | 203 | * @class |
| 201 | 204 | * @augments Backbone.Model |
| 202 | 205 | */ |
| 203 | 206 | Attachment = media.model.Attachment = Backbone.Model.extend({ |
| … |
… |
window.wp = window.wp || {};
|
| 329 | 332 | } |
| 330 | 333 | }, { |
| 331 | 334 | /** |
| 332 | | * Add a model to the end of the static 'all' collection and return it. |
| | 335 | * Create a new model on the static 'all' attachments collection and return it. |
| 333 | 336 | * |
| 334 | 337 | * @static |
| 335 | 338 | * @param {Object} attrs |
| … |
… |
window.wp = window.wp || {};
|
| 339 | 342 | return Attachments.all.push( attrs ); |
| 340 | 343 | }, |
| 341 | 344 | /** |
| 342 | | * Retrieve a model, or add it to the end of the static 'all' collection before returning it. |
| | 345 | * Create a new model on the static 'all' attachments collection and return it. |
| | 346 | * |
| | 347 | * If this function has already been called for the id, |
| | 348 | * it returns the specified attachment. |
| 343 | 349 | * |
| 344 | 350 | * @static |
| 345 | 351 | * @param {string} id A string used to identify a model. |
| … |
… |
window.wp = window.wp || {};
|
| 354 | 360 | /** |
| 355 | 361 | * wp.media.model.PostImage |
| 356 | 362 | * |
| 357 | | * @constructor |
| | 363 | * An instance of an image that's been embedded into a post. |
| | 364 | * |
| | 365 | * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. |
| | 366 | * |
| | 367 | * @class |
| 358 | 368 | * @augments Backbone.Model |
| | 369 | * |
| | 370 | * @param {int} [attributes] Initial model attributes. |
| | 371 | * @param {int} [attributes.attachment_id] ID of the attachment. |
| 359 | 372 | **/ |
| 360 | 373 | PostImage = media.model.PostImage = Backbone.Model.extend({ |
| 361 | 374 | |
| … |
… |
window.wp = window.wp || {};
|
| 497 | 510 | /** |
| 498 | 511 | * wp.media.model.Attachments |
| 499 | 512 | * |
| 500 | | * @constructor |
| | 513 | * A collection of attachments. |
| | 514 | * |
| | 515 | * This collection has no persistence with the server without supplying |
| | 516 | * 'options.props.query = true', which will mirror the collection |
| | 517 | * to an Attachments Query collection - @see wp.media.model.Attachments.mirror(). |
| | 518 | * |
| | 519 | * @class |
| 501 | 520 | * @augments Backbone.Collection |
| | 521 | * |
| | 522 | * @param {array} [models] Models to initialize with the collection. |
| | 523 | * @param {object} [options] Options hash for the collection. |
| | 524 | * @param {string} [options.props] Options hash for the initial query properties. |
| | 525 | * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection. |
| | 526 | * @param {string} [options.props.orderby] Initial attribute key to order the collection by. |
| | 527 | * @param {string} [options.props.query] Whether the collection is linked to an attachments query. |
| | 528 | * @param {string} [options.observe] |
| | 529 | * @param {string} [options.filters] |
| | 530 | * |
| 502 | 531 | */ |
| 503 | 532 | Attachments = media.model.Attachments = Backbone.Collection.extend({ |
| 504 | 533 | /** |
| … |
… |
window.wp = window.wp || {};
|
| 522 | 551 | this.props.on( 'change:orderby', this._changeOrderby, this ); |
| 523 | 552 | this.props.on( 'change:query', this._changeQuery, this ); |
| 524 | 553 | |
| 525 | | // Set the `props` model and fill the default property values. |
| 526 | 554 | this.props.set( _.defaults( options.props || {} ) ); |
| 527 | 555 | |
| 528 | | // Observe another `Attachments` collection if one is provided. |
| 529 | 556 | if ( options.observe ) { |
| 530 | 557 | this.observe( options.observe ); |
| 531 | 558 | } |
| 532 | 559 | }, |
| 533 | 560 | /** |
| 534 | | * Automatically sort the collection when the order changes. |
| | 561 | * Sort the collection when the order attribute changes. |
| 535 | 562 | * |
| 536 | 563 | * @access private |
| 537 | 564 | */ |
| … |
… |
window.wp = window.wp || {};
|
| 625 | 652 | |
| 626 | 653 | validateDestroyed: false, |
| 627 | 654 | /** |
| | 655 | * Checks whether an attachment is valid. |
| | 656 | * |
| 628 | 657 | * @param {wp.media.model.Attachment} attachment |
| 629 | 658 | * @returns {Boolean} |
| 630 | 659 | */ |
| … |
… |
window.wp = window.wp || {};
|
| 637 | 666 | }, this ); |
| 638 | 667 | }, |
| 639 | 668 | /** |
| | 669 | * Add or remove an attachment to the collection depending on its validity. |
| | 670 | * |
| 640 | 671 | * @param {wp.media.model.Attachment} attachment |
| 641 | 672 | * @param {Object} options |
| 642 | 673 | * @returns {wp.media.model.Attachments} Returns itself to allow chaining |
| … |
… |
window.wp = window.wp || {};
|
| 655 | 686 | }, |
| 656 | 687 | |
| 657 | 688 | /** |
| | 689 | * Add or remove all attachments from another collection depending on each one's validity. |
| | 690 | * |
| 658 | 691 | * @param {wp.media.model.Attachments} attachments |
| 659 | 692 | * @param {object} [options={}] |
| 660 | 693 | * |
| … |
… |
window.wp = window.wp || {};
|
| 675 | 708 | return this; |
| 676 | 709 | }, |
| 677 | 710 | /** |
| 678 | | * @param {wp.media.model.Attachments} attachments |
| 679 | | * @returns {wp.media.model.Attachments} Returns itself to allow chaining |
| | 711 | * Start observing another attachments collection change events |
| | 712 | * and replicate them on this collection. |
| | 713 | * |
| | 714 | * @param {wp.media.model.Attachments} The attachments collection to observe. |
| | 715 | * @returns {wp.media.model.Attachments} Returns itself to allow chaining. |
| 680 | 716 | */ |
| 681 | 717 | observe: function( attachments ) { |
| 682 | 718 | this.observers = this.observers || []; |
| … |
… |
window.wp = window.wp || {};
|
| 688 | 724 | return this; |
| 689 | 725 | }, |
| 690 | 726 | /** |
| 691 | | * @param {wp.media.model.Attachments} attachments |
| | 727 | * Stop replicating collection change events from another attachments collection. |
| | 728 | * |
| | 729 | * @param {wp.media.model.Attachments} The attachments collection to stop observing. |
| 692 | 730 | * @returns {wp.media.model.Attachments} Returns itself to allow chaining |
| 693 | 731 | */ |
| 694 | 732 | unobserve: function( attachments ) { |
| … |
… |
window.wp = window.wp || {};
|
| 734 | 772 | return this.validateAll( attachments, options ); |
| 735 | 773 | }, |
| 736 | 774 | /** |
| 737 | | * @param {wp.media.model.Attachments} attachments |
| | 775 | * Start mirroring another attachments collection, clearing out any models already |
| | 776 | * in the collection. |
| | 777 | * |
| | 778 | * @param {wp.media.model.Attachments} The attachments collection to mirror. |
| 738 | 779 | * @returns {wp.media.model.Attachments} Returns itself to allow chaining |
| 739 | 780 | */ |
| 740 | 781 | mirror: function( attachments ) { |
| … |
… |
window.wp = window.wp || {};
|
| 752 | 793 | |
| 753 | 794 | return this; |
| 754 | 795 | }, |
| | 796 | /** |
| | 797 | * Stop mirroring another attachments collection. |
| | 798 | */ |
| 755 | 799 | unmirror: function() { |
| 756 | 800 | if ( ! this.mirroring ) { |
| 757 | 801 | return; |
| … |
… |
window.wp = window.wp || {};
|
| 761 | 805 | delete this.mirroring; |
| 762 | 806 | }, |
| 763 | 807 | /** |
| 764 | | * @param {Object} options |
| | 808 | * Retrive more attachments from the server for the collection. |
| | 809 | * |
| | 810 | * Only works if the collection is mirroring a Query Attachments collection, |
| | 811 | * and forwards to its `more` method. This collection class doesn't have |
| | 812 | * server persistence by itself. |
| | 813 | * |
| | 814 | * @param {object} options |
| 765 | 815 | * @returns {Promise} |
| 766 | 816 | */ |
| 767 | 817 | more: function( options ) { |
| … |
… |
window.wp = window.wp || {};
|
| 784 | 834 | return deferred.promise(); |
| 785 | 835 | }, |
| 786 | 836 | /** |
| 787 | | * @returns {Boolean} |
| | 837 | * Whether there are more attachments that haven't been sync'd from the server |
| | 838 | * that match the collection's query. |
| | 839 | * |
| | 840 | * Only works if the collection is mirroring a Query Attachments collection, |
| | 841 | * and forwards to its `hasMore` method. This collection class doesn't have |
| | 842 | * server persistence by itself. |
| | 843 | * |
| | 844 | * @returns {boolean} |
| 788 | 845 | */ |
| 789 | 846 | hasMore: function() { |
| 790 | 847 | return this.mirroring ? this.mirroring.hasMore() : false; |
| 791 | 848 | }, |
| 792 | 849 | /** |
| 793 | | * Overrides Backbone.Collection.parse |
| | 850 | * A custom AJAX-response parser. |
| | 851 | * |
| | 852 | * See trac ticket #24753 |
| 794 | 853 | * |
| 795 | 854 | * @param {Object|Array} resp The raw response Object/Array. |
| 796 | 855 | * @param {Object} xhr |
| … |
… |
window.wp = window.wp || {};
|
| 822 | 881 | }); |
| 823 | 882 | }, |
| 824 | 883 | /** |
| | 884 | * If the collection is a query, create and mirror an Attachments Query collection. |
| | 885 | * |
| 825 | 886 | * @access private |
| 826 | 887 | */ |
| 827 | 888 | _requery: function( refresh ) { |
| … |
… |
window.wp = window.wp || {};
|
| 867 | 928 | } |
| 868 | 929 | }, { |
| 869 | 930 | /** |
| | 931 | * A function to compare two attachment models in an attachments collection. |
| | 932 | * |
| | 933 | * Used as the default comparator for instances of wp.media.model.Attachments |
| | 934 | * and its subclasses. @see wp.media.model.Attachments._changeOrderby(). |
| | 935 | * |
| 870 | 936 | * @static |
| 871 | | * Overrides Backbone.Collection.comparator |
| 872 | 937 | * |
| 873 | 938 | * @param {Backbone.Model} a |
| 874 | 939 | * @param {Backbone.Model} b |
| … |
… |
window.wp = window.wp || {};
|
| 971 | 1036 | }); |
| 972 | 1037 | |
| 973 | 1038 | /** |
| | 1039 | * A collection of all attachments that have been fetched from the server. |
| | 1040 | * |
| 974 | 1041 | * @static |
| 975 | 1042 | * @member {wp.media.model.Attachments} |
| 976 | 1043 | */ |
| … |
… |
window.wp = window.wp || {};
|
| 979 | 1046 | /** |
| 980 | 1047 | * wp.media.query |
| 981 | 1048 | * |
| 982 | | * @static |
| | 1049 | * Shorthand for creating a new Attachments Query. |
| | 1050 | * |
| | 1051 | * @param {object} [props] |
| 983 | 1052 | * @returns {wp.media.model.Attachments} |
| 984 | 1053 | */ |
| 985 | 1054 | media.query = function( props ) { |
| … |
… |
window.wp = window.wp || {};
|
| 991 | 1060 | /** |
| 992 | 1061 | * wp.media.model.Query |
| 993 | 1062 | * |
| 994 | | * A set of attachments that corresponds to a set of consecutively paged |
| 995 | | * queries on the server. |
| | 1063 | * A collection of attachments that match the supplied query arguments. |
| 996 | 1064 | * |
| 997 | 1065 | * Note: Do NOT change this.args after the query has been initialized. |
| 998 | 1066 | * Things will break. |
| 999 | 1067 | * |
| 1000 | | * @constructor |
| | 1068 | * @class |
| 1001 | 1069 | * @augments wp.media.model.Attachments |
| 1002 | 1070 | * @augments Backbone.Collection |
| | 1071 | * |
| | 1072 | * @param {array} [models] Models to initialize with the collection. |
| | 1073 | * @param {object} [options] Options hash. |
| | 1074 | * @param {object} [options.args] Attachments query arguments. |
| | 1075 | * @param {object} [options.args.posts_per_page] |
| 1003 | 1076 | */ |
| 1004 | 1077 | Query = media.model.Query = Attachments.extend({ |
| 1005 | 1078 | /** |
| 1006 | 1079 | * @global wp.Uploader |
| 1007 | 1080 | * |
| 1008 | | * @param {Array} [models=[]] Array of models used to populate the collection. |
| 1009 | | * @param {Object} [options={}] |
| | 1081 | * @param {array} [models=[]] Array of initial models to populate the collection. |
| | 1082 | * @param {object} [options={}] |
| 1010 | 1083 | */ |
| 1011 | 1084 | initialize: function( models, options ) { |
| 1012 | 1085 | var allowed; |
| … |
… |
window.wp = window.wp || {};
|
| 1060 | 1133 | } |
| 1061 | 1134 | }, |
| 1062 | 1135 | /** |
| 1063 | | * @returns {Boolean} |
| | 1136 | * Whether there are more attachments that haven't been sync'd from the server |
| | 1137 | * that match the collection's query. |
| | 1138 | * |
| | 1139 | * @returns {boolean} |
| 1064 | 1140 | */ |
| 1065 | 1141 | hasMore: function() { |
| 1066 | 1142 | return this._hasMore; |
| 1067 | 1143 | }, |
| 1068 | 1144 | /** |
| 1069 | | * @param {Object} [options={}] |
| | 1145 | * Fetch more attachments from the server for the collection. |
| | 1146 | * |
| | 1147 | * @param {object} [options={}] |
| 1070 | 1148 | * @returns {Promise} |
| 1071 | 1149 | */ |
| 1072 | 1150 | more: function( options ) { |
| 1073 | 1151 | var query = this; |
| 1074 | 1152 | |
| | 1153 | // If there is already a request pending, return early with the Deferred object. |
| 1075 | 1154 | if ( this._more && 'pending' === this._more.state() ) { |
| 1076 | 1155 | return this._more; |
| 1077 | 1156 | } |
| … |
… |
window.wp = window.wp || {};
|
| 1149 | 1228 | */ |
| 1150 | 1229 | orderby: { |
| 1151 | 1230 | allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], |
| | 1231 | /** |
| | 1232 | * A map of JavaScript orderby values to their WP_Query equivalents. |
| | 1233 | * @type {Object} |
| | 1234 | */ |
| 1152 | 1235 | valuemap: { |
| 1153 | 1236 | 'id': 'ID', |
| 1154 | 1237 | 'uploadedTo': 'parent', |
| … |
… |
window.wp = window.wp || {};
|
| 1156 | 1239 | } |
| 1157 | 1240 | }, |
| 1158 | 1241 | /** |
| | 1242 | * A map of JavaScript query properties to their WP_Query equivalents. |
| | 1243 | * |
| 1159 | 1244 | * @readonly |
| 1160 | 1245 | */ |
| 1161 | 1246 | propmap: { |
| … |
… |
window.wp = window.wp || {};
|
| 1169 | 1254 | 'exclude': 'post__not_in' |
| 1170 | 1255 | }, |
| 1171 | 1256 | /** |
| | 1257 | * Creates and returns an Attachments Query collection given the properties. |
| | 1258 | * |
| | 1259 | * Caches query objects and reuses where possible. |
| | 1260 | * |
| 1172 | 1261 | * @static |
| 1173 | 1262 | * @method |
| 1174 | 1263 | * |
| 1175 | | * @returns {wp.media.model.Query} A new query. |
| | 1264 | * @param {object} [props] |
| | 1265 | * @param {Object} [props.cache=true] Whether to use the query cache or not. |
| | 1266 | * @param {Object} [props.order] |
| | 1267 | * @param {Object} [props.orderby] |
| | 1268 | * @param {Object} [props.include] |
| | 1269 | * @param {Object} [props.exclude] |
| | 1270 | * @param {Object} [props.s] |
| | 1271 | * @param {Object} [props.post_mime_type] |
| | 1272 | * @param {Object} [props.posts_per_page] |
| | 1273 | * @param {Object} [props.menu_order] |
| | 1274 | * @param {Object} [props.post_parent] |
| | 1275 | * @param {Object} [props.post_status] |
| | 1276 | * @param {Object} [options] |
| | 1277 | * |
| | 1278 | * @returns {wp.media.model.Query} A new Attachments Query collection. |
| 1176 | 1279 | */ |
| 1177 | | // Caches query objects so queries can be easily reused. |
| 1178 | 1280 | get: (function(){ |
| 1179 | 1281 | /** |
| 1180 | 1282 | * @static |
| … |
… |
window.wp = window.wp || {};
|
| 1183 | 1285 | var queries = []; |
| 1184 | 1286 | |
| 1185 | 1287 | /** |
| 1186 | | * @param {Object} props |
| 1187 | | * @param {Object} options |
| 1188 | 1288 | * @returns {Query} |
| 1189 | 1289 | */ |
| 1190 | 1290 | return function( props, options ) { |
| … |
… |
window.wp = window.wp || {};
|
| 1236 | 1336 | // Substitute exceptions specified in orderby.keymap. |
| 1237 | 1337 | args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; |
| 1238 | 1338 | |
| 1239 | | // Search the query cache for matches. |
| | 1339 | // Search the query cache for a matching query. |
| 1240 | 1340 | if ( cache ) { |
| 1241 | 1341 | query = _.find( queries, function( query ) { |
| 1242 | 1342 | return _.isEqual( query.args, args ); |
| … |
… |
window.wp = window.wp || {};
|
| 1262 | 1362 | /** |
| 1263 | 1363 | * wp.media.model.Selection |
| 1264 | 1364 | * |
| 1265 | | * Used to manage a selection of attachments in the views. |
| | 1365 | * A selection of attachments. |
| 1266 | 1366 | * |
| 1267 | | * @constructor |
| | 1367 | * @class |
| 1268 | 1368 | * @augments wp.media.model.Attachments |
| 1269 | 1369 | * @augments Backbone.Collection |
| 1270 | 1370 | */ |
| … |
… |
window.wp = window.wp || {};
|
| 1288 | 1388 | }, |
| 1289 | 1389 | |
| 1290 | 1390 | /** |
| 1291 | | * Override the selection's add method. |
| 1292 | | * If the workflow does not support multiple |
| 1293 | | * selected attachments, reset the selection. |
| 1294 | | * |
| 1295 | | * Overrides Backbone.Collection.add |
| 1296 | | * Overrides wp.media.model.Attachments.add |
| | 1391 | * If the workflow does not support multi-select, clear out the selection |
| | 1392 | * before adding a new attachment to it. |
| 1297 | 1393 | * |
| 1298 | 1394 | * @param {Array} models |
| 1299 | 1395 | * @param {Object} options |
| … |
… |
window.wp = window.wp || {};
|
| 1310 | 1406 | }, |
| 1311 | 1407 | |
| 1312 | 1408 | /** |
| 1313 | | * Triggered when toggling (clicking on) an attachment in the modal |
| | 1409 | * Fired when toggling (clicking on) an attachment in the modal. |
| 1314 | 1410 | * |
| 1315 | 1411 | * @param {undefined|boolean|wp.media.model.Attachment} model |
| 1316 | 1412 | * |
diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
index cc02f43..96bd33f 100644
|
|
|
|
| 2664 | 2664 | state: 'insert', |
| 2665 | 2665 | metadata: {} |
| 2666 | 2666 | }); |
| 2667 | | /** |
| 2668 | | * call 'initialize' directly on the parent class |
| 2669 | | */ |
| | 2667 | |
| | 2668 | // Call 'initialize' directly on the parent class. |
| 2670 | 2669 | media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments ); |
| 2671 | 2670 | this.createIframeStates(); |
| 2672 | 2671 | |
| … |
… |
|
| 6013 | 6012 | }, |
| 6014 | 6013 | |
| 6015 | 6014 | /** |
| 6016 | | * When the selection changes, set the Query properties |
| 6017 | | * accordingly for the selected filter. |
| | 6015 | * When the selected filter changes, update the Attachment Query properties to match. |
| 6018 | 6016 | */ |
| 6019 | 6017 | change: function() { |
| 6020 | 6018 | var filter = this.filters[ this.el.value ]; |
| … |
… |
|
| 6221 | 6219 | * @augments wp.media.View |
| 6222 | 6220 | * @augments wp.Backbone.View |
| 6223 | 6221 | * @augments Backbone.View |
| | 6222 | * |
| | 6223 | * @param {object} options |
| | 6224 | * @param {object} [options.filters=false] Which filters to show in the browser's toolbar. |
| | 6225 | * Accepts 'uploaded' and 'all'. |
| | 6226 | * @param {object} [options.search=true] Whether to show the search interface in the |
| | 6227 | * browser's toolbar. |
| | 6228 | * @param {object} [options.display=false] Whether to show the attachments display settings |
| | 6229 | * view in the sidebar. |
| | 6230 | * @param {bool|string} [options.sidebar=true] Whether to create a sidebar for the browser. |
| | 6231 | * Accepts true, false, and 'errors'. |
| 6224 | 6232 | */ |
| 6225 | 6233 | media.view.AttachmentsBrowser = media.View.extend({ |
| 6226 | 6234 | tagName: 'div', |
diff --git src/wp-includes/js/wp-util.js src/wp-includes/js/wp-util.js
index 867d3a0..1985b35 100644
|
|
|
window.wp = window.wp || {};
|
| 8 | 8 | /** |
| 9 | 9 | * wp.template( id ) |
| 10 | 10 | * |
| 11 | | * Fetches a template by id. |
| | 11 | * Fetch a JavaScript template for an id, and return a templating function for it. |
| 12 | 12 | * |
| 13 | 13 | * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-". |
| 14 | 14 | * For example, "attachment" maps to "tmpl-attachment". |
| … |
… |
window.wp = window.wp || {};
|
| 16 | 16 | */ |
| 17 | 17 | wp.template = _.memoize(function ( id ) { |
| 18 | 18 | var compiled, |
| | 19 | /* |
| | 20 | * Underscore's default ERB-style templates are incompatible with PHP |
| | 21 | * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax. |
| | 22 | * |
| | 23 | * @see trac ticket #22344. |
| | 24 | */ |
| 19 | 25 | options = { |
| 20 | 26 | evaluate: /<#([\s\S]+?)#>/g, |
| 21 | 27 | interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, |