1 /******/ (function(modules) { // webpackBootstrap |
1 /******/ (function() { // webpackBootstrap |
2 /******/ // The module cache |
2 /******/ var __webpack_modules__ = ({ |
3 /******/ var installedModules = {}; |
3 |
4 /******/ |
4 /***/ 7727: |
5 /******/ // The require function |
5 /***/ (function(module) { |
6 /******/ function __webpack_require__(moduleId) { |
|
7 /******/ |
|
8 /******/ // Check if module is in cache |
|
9 /******/ if(installedModules[moduleId]) { |
|
10 /******/ return installedModules[moduleId].exports; |
|
11 /******/ } |
|
12 /******/ // Create a new module (and put it into the cache) |
|
13 /******/ var module = installedModules[moduleId] = { |
|
14 /******/ i: moduleId, |
|
15 /******/ l: false, |
|
16 /******/ exports: {} |
|
17 /******/ }; |
|
18 /******/ |
|
19 /******/ // Execute the module function |
|
20 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
|
21 /******/ |
|
22 /******/ // Flag the module as loaded |
|
23 /******/ module.l = true; |
|
24 /******/ |
|
25 /******/ // Return the exports of the module |
|
26 /******/ return module.exports; |
|
27 /******/ } |
|
28 /******/ |
|
29 /******/ |
|
30 /******/ // expose the modules object (__webpack_modules__) |
|
31 /******/ __webpack_require__.m = modules; |
|
32 /******/ |
|
33 /******/ // expose the module cache |
|
34 /******/ __webpack_require__.c = installedModules; |
|
35 /******/ |
|
36 /******/ // define getter function for harmony exports |
|
37 /******/ __webpack_require__.d = function(exports, name, getter) { |
|
38 /******/ if(!__webpack_require__.o(exports, name)) { |
|
39 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
|
40 /******/ } |
|
41 /******/ }; |
|
42 /******/ |
|
43 /******/ // define __esModule on exports |
|
44 /******/ __webpack_require__.r = function(exports) { |
|
45 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
46 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
47 /******/ } |
|
48 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
49 /******/ }; |
|
50 /******/ |
|
51 /******/ // create a fake namespace object |
|
52 /******/ // mode & 1: value is a module id, require it |
|
53 /******/ // mode & 2: merge all properties of value into the ns |
|
54 /******/ // mode & 4: return value when already ns object |
|
55 /******/ // mode & 8|1: behave like require |
|
56 /******/ __webpack_require__.t = function(value, mode) { |
|
57 /******/ if(mode & 1) value = __webpack_require__(value); |
|
58 /******/ if(mode & 8) return value; |
|
59 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
|
60 /******/ var ns = Object.create(null); |
|
61 /******/ __webpack_require__.r(ns); |
|
62 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
|
63 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
|
64 /******/ return ns; |
|
65 /******/ }; |
|
66 /******/ |
|
67 /******/ // getDefaultExport function for compatibility with non-harmony modules |
|
68 /******/ __webpack_require__.n = function(module) { |
|
69 /******/ var getter = module && module.__esModule ? |
|
70 /******/ function getDefault() { return module['default']; } : |
|
71 /******/ function getModuleExports() { return module; }; |
|
72 /******/ __webpack_require__.d(getter, 'a', getter); |
|
73 /******/ return getter; |
|
74 /******/ }; |
|
75 /******/ |
|
76 /******/ // Object.prototype.hasOwnProperty.call |
|
77 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
|
78 /******/ |
|
79 /******/ // __webpack_public_path__ |
|
80 /******/ __webpack_require__.p = ""; |
|
81 /******/ |
|
82 /******/ |
|
83 /******/ // Load entry module and return exports |
|
84 /******/ return __webpack_require__(__webpack_require__.s = 2); |
|
85 /******/ }) |
|
86 /************************************************************************/ |
|
87 /******/ ({ |
|
88 |
|
89 /***/ "0Ym0": |
|
90 /***/ (function(module, exports) { |
|
91 |
6 |
92 var $ = Backbone.$, |
7 var $ = Backbone.$, |
93 Attachment; |
8 Attachment; |
94 |
9 |
95 /** |
10 /** |
260 module.exports = Attachment; |
175 module.exports = Attachment; |
261 |
176 |
262 |
177 |
263 /***/ }), |
178 /***/ }), |
264 |
179 |
265 /***/ 2: |
180 /***/ 6940: |
266 /***/ (function(module, exports, __webpack_require__) { |
181 /***/ (function(module) { |
267 |
|
268 module.exports = __webpack_require__("dx5j"); |
|
269 |
|
270 |
|
271 /***/ }), |
|
272 |
|
273 /***/ "Io+g": |
|
274 /***/ (function(module, exports) { |
|
275 |
|
276 var Attachments = wp.media.model.Attachments, |
|
277 Selection; |
|
278 |
|
279 /** |
|
280 * wp.media.model.Selection |
|
281 * |
|
282 * A selection of attachments. |
|
283 * |
|
284 * @memberOf wp.media.model |
|
285 * |
|
286 * @class |
|
287 * @augments wp.media.model.Attachments |
|
288 * @augments Backbone.Collection |
|
289 */ |
|
290 Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{ |
|
291 /** |
|
292 * Refresh the `single` model whenever the selection changes. |
|
293 * Binds `single` instead of using the context argument to ensure |
|
294 * it receives no parameters. |
|
295 * |
|
296 * @param {Array} [models=[]] Array of models used to populate the collection. |
|
297 * @param {Object} [options={}] |
|
298 */ |
|
299 initialize: function( models, options ) { |
|
300 /** |
|
301 * call 'initialize' directly on the parent class |
|
302 */ |
|
303 Attachments.prototype.initialize.apply( this, arguments ); |
|
304 this.multiple = options && options.multiple; |
|
305 |
|
306 this.on( 'add remove reset', _.bind( this.single, this, false ) ); |
|
307 }, |
|
308 |
|
309 /** |
|
310 * If the workflow does not support multi-select, clear out the selection |
|
311 * before adding a new attachment to it. |
|
312 * |
|
313 * @param {Array} models |
|
314 * @param {Object} options |
|
315 * @return {wp.media.model.Attachment[]} |
|
316 */ |
|
317 add: function( models, options ) { |
|
318 if ( ! this.multiple ) { |
|
319 this.remove( this.models ); |
|
320 } |
|
321 /** |
|
322 * call 'add' directly on the parent class |
|
323 */ |
|
324 return Attachments.prototype.add.call( this, models, options ); |
|
325 }, |
|
326 |
|
327 /** |
|
328 * Fired when toggling (clicking on) an attachment in the modal. |
|
329 * |
|
330 * @param {undefined|boolean|wp.media.model.Attachment} model |
|
331 * |
|
332 * @fires wp.media.model.Selection#selection:single |
|
333 * @fires wp.media.model.Selection#selection:unsingle |
|
334 * |
|
335 * @return {Backbone.Model} |
|
336 */ |
|
337 single: function( model ) { |
|
338 var previous = this._single; |
|
339 |
|
340 // If a `model` is provided, use it as the single model. |
|
341 if ( model ) { |
|
342 this._single = model; |
|
343 } |
|
344 // If the single model isn't in the selection, remove it. |
|
345 if ( this._single && ! this.get( this._single.cid ) ) { |
|
346 delete this._single; |
|
347 } |
|
348 |
|
349 this._single = this._single || this.last(); |
|
350 |
|
351 // If single has changed, fire an event. |
|
352 if ( this._single !== previous ) { |
|
353 if ( previous ) { |
|
354 previous.trigger( 'selection:unsingle', previous, this ); |
|
355 |
|
356 // If the model was already removed, trigger the collection |
|
357 // event manually. |
|
358 if ( ! this.get( previous.cid ) ) { |
|
359 this.trigger( 'selection:unsingle', previous, this ); |
|
360 } |
|
361 } |
|
362 if ( this._single ) { |
|
363 this._single.trigger( 'selection:single', this._single, this ); |
|
364 } |
|
365 } |
|
366 |
|
367 // Return the single model, or the last model as a fallback. |
|
368 return this._single; |
|
369 } |
|
370 }); |
|
371 |
|
372 module.exports = Selection; |
|
373 |
|
374 |
|
375 /***/ }), |
|
376 |
|
377 /***/ "K0z/": |
|
378 /***/ (function(module, exports) { |
|
379 |
182 |
380 /** |
183 /** |
381 * wp.media.model.Attachments |
184 * wp.media.model.Attachments |
382 * |
185 * |
383 * A collection of attachments. |
186 * A collection of attachments. |
980 module.exports = Attachments; |
783 module.exports = Attachments; |
981 |
784 |
982 |
785 |
983 /***/ }), |
786 /***/ }), |
984 |
787 |
985 /***/ "dx5j": |
788 /***/ 5927: |
986 /***/ (function(module, exports, __webpack_require__) { |
789 /***/ (function(module) { |
987 |
790 |
|
791 /** |
|
792 * wp.media.model.PostImage |
|
793 * |
|
794 * An instance of an image that's been embedded into a post. |
|
795 * |
|
796 * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. |
|
797 * |
|
798 * @memberOf wp.media.model |
|
799 * |
|
800 * @class |
|
801 * @augments Backbone.Model |
|
802 * |
|
803 * @param {int} [attributes] Initial model attributes. |
|
804 * @param {int} [attributes.attachment_id] ID of the attachment. |
|
805 **/ |
|
806 var PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{ |
|
807 |
|
808 initialize: function( attributes ) { |
|
809 var Attachment = wp.media.model.Attachment; |
|
810 this.attachment = false; |
|
811 |
|
812 if ( attributes.attachment_id ) { |
|
813 this.attachment = Attachment.get( attributes.attachment_id ); |
|
814 if ( this.attachment.get( 'url' ) ) { |
|
815 this.dfd = jQuery.Deferred(); |
|
816 this.dfd.resolve(); |
|
817 } else { |
|
818 this.dfd = this.attachment.fetch(); |
|
819 } |
|
820 this.bindAttachmentListeners(); |
|
821 } |
|
822 |
|
823 // Keep URL in sync with changes to the type of link. |
|
824 this.on( 'change:link', this.updateLinkUrl, this ); |
|
825 this.on( 'change:size', this.updateSize, this ); |
|
826 |
|
827 this.setLinkTypeFromUrl(); |
|
828 this.setAspectRatio(); |
|
829 |
|
830 this.set( 'originalUrl', attributes.url ); |
|
831 }, |
|
832 |
|
833 bindAttachmentListeners: function() { |
|
834 this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl ); |
|
835 this.listenTo( this.attachment, 'sync', this.setAspectRatio ); |
|
836 this.listenTo( this.attachment, 'change', this.updateSize ); |
|
837 }, |
|
838 |
|
839 changeAttachment: function( attachment, props ) { |
|
840 this.stopListening( this.attachment ); |
|
841 this.attachment = attachment; |
|
842 this.bindAttachmentListeners(); |
|
843 |
|
844 this.set( 'attachment_id', this.attachment.get( 'id' ) ); |
|
845 this.set( 'caption', this.attachment.get( 'caption' ) ); |
|
846 this.set( 'alt', this.attachment.get( 'alt' ) ); |
|
847 this.set( 'size', props.get( 'size' ) ); |
|
848 this.set( 'align', props.get( 'align' ) ); |
|
849 this.set( 'link', props.get( 'link' ) ); |
|
850 this.updateLinkUrl(); |
|
851 this.updateSize(); |
|
852 }, |
|
853 |
|
854 setLinkTypeFromUrl: function() { |
|
855 var linkUrl = this.get( 'linkUrl' ), |
|
856 type; |
|
857 |
|
858 if ( ! linkUrl ) { |
|
859 this.set( 'link', 'none' ); |
|
860 return; |
|
861 } |
|
862 |
|
863 // Default to custom if there is a linkUrl. |
|
864 type = 'custom'; |
|
865 |
|
866 if ( this.attachment ) { |
|
867 if ( this.attachment.get( 'url' ) === linkUrl ) { |
|
868 type = 'file'; |
|
869 } else if ( this.attachment.get( 'link' ) === linkUrl ) { |
|
870 type = 'post'; |
|
871 } |
|
872 } else { |
|
873 if ( this.get( 'url' ) === linkUrl ) { |
|
874 type = 'file'; |
|
875 } |
|
876 } |
|
877 |
|
878 this.set( 'link', type ); |
|
879 }, |
|
880 |
|
881 updateLinkUrl: function() { |
|
882 var link = this.get( 'link' ), |
|
883 url; |
|
884 |
|
885 switch( link ) { |
|
886 case 'file': |
|
887 if ( this.attachment ) { |
|
888 url = this.attachment.get( 'url' ); |
|
889 } else { |
|
890 url = this.get( 'url' ); |
|
891 } |
|
892 this.set( 'linkUrl', url ); |
|
893 break; |
|
894 case 'post': |
|
895 this.set( 'linkUrl', this.attachment.get( 'link' ) ); |
|
896 break; |
|
897 case 'none': |
|
898 this.set( 'linkUrl', '' ); |
|
899 break; |
|
900 } |
|
901 }, |
|
902 |
|
903 updateSize: function() { |
|
904 var size; |
|
905 |
|
906 if ( ! this.attachment ) { |
|
907 return; |
|
908 } |
|
909 |
|
910 if ( this.get( 'size' ) === 'custom' ) { |
|
911 this.set( 'width', this.get( 'customWidth' ) ); |
|
912 this.set( 'height', this.get( 'customHeight' ) ); |
|
913 this.set( 'url', this.get( 'originalUrl' ) ); |
|
914 return; |
|
915 } |
|
916 |
|
917 size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ]; |
|
918 |
|
919 if ( ! size ) { |
|
920 return; |
|
921 } |
|
922 |
|
923 this.set( 'url', size.url ); |
|
924 this.set( 'width', size.width ); |
|
925 this.set( 'height', size.height ); |
|
926 }, |
|
927 |
|
928 setAspectRatio: function() { |
|
929 var full; |
|
930 |
|
931 if ( this.attachment && this.attachment.get( 'sizes' ) ) { |
|
932 full = this.attachment.get( 'sizes' ).full; |
|
933 |
|
934 if ( full ) { |
|
935 this.set( 'aspectRatio', full.width / full.height ); |
|
936 return; |
|
937 } |
|
938 } |
|
939 |
|
940 this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) ); |
|
941 } |
|
942 }); |
|
943 |
|
944 module.exports = PostImage; |
|
945 |
|
946 |
|
947 /***/ }), |
|
948 |
|
949 /***/ 4009: |
|
950 /***/ (function(module) { |
|
951 |
|
952 var Attachments = wp.media.model.Attachments, |
|
953 Query; |
|
954 |
|
955 /** |
|
956 * wp.media.model.Query |
|
957 * |
|
958 * A collection of attachments that match the supplied query arguments. |
|
959 * |
|
960 * Note: Do NOT change this.args after the query has been initialized. |
|
961 * Things will break. |
|
962 * |
|
963 * @memberOf wp.media.model |
|
964 * |
|
965 * @class |
|
966 * @augments wp.media.model.Attachments |
|
967 * @augments Backbone.Collection |
|
968 * |
|
969 * @param {array} [models] Models to initialize with the collection. |
|
970 * @param {object} [options] Options hash. |
|
971 * @param {object} [options.args] Attachments query arguments. |
|
972 * @param {object} [options.args.posts_per_page] |
|
973 */ |
|
974 Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ |
|
975 /** |
|
976 * @param {Array} [models=[]] Array of initial models to populate the collection. |
|
977 * @param {Object} [options={}] |
|
978 */ |
|
979 initialize: function( models, options ) { |
|
980 var allowed; |
|
981 |
|
982 options = options || {}; |
|
983 Attachments.prototype.initialize.apply( this, arguments ); |
|
984 |
|
985 this.args = options.args; |
|
986 this._hasMore = true; |
|
987 this.created = new Date(); |
|
988 |
|
989 this.filters.order = function( attachment ) { |
|
990 var orderby = this.props.get('orderby'), |
|
991 order = this.props.get('order'); |
|
992 |
|
993 if ( ! this.comparator ) { |
|
994 return true; |
|
995 } |
|
996 |
|
997 /* |
|
998 * We want any items that can be placed before the last |
|
999 * item in the set. If we add any items after the last |
|
1000 * item, then we can't guarantee the set is complete. |
|
1001 */ |
|
1002 if ( this.length ) { |
|
1003 return 1 !== this.comparator( attachment, this.last(), { ties: true }); |
|
1004 |
|
1005 /* |
|
1006 * Handle the case where there are no items yet and |
|
1007 * we're sorting for recent items. In that case, we want |
|
1008 * changes that occurred after we created the query. |
|
1009 */ |
|
1010 } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { |
|
1011 return attachment.get( orderby ) >= this.created; |
|
1012 |
|
1013 // If we're sorting by menu order and we have no items, |
|
1014 // accept any items that have the default menu order (0). |
|
1015 } else if ( 'ASC' === order && 'menuOrder' === orderby ) { |
|
1016 return attachment.get( orderby ) === 0; |
|
1017 } |
|
1018 |
|
1019 // Otherwise, we don't want any items yet. |
|
1020 return false; |
|
1021 }; |
|
1022 |
|
1023 /* |
|
1024 * Observe the central `wp.Uploader.queue` collection to watch for |
|
1025 * new matches for the query. |
|
1026 * |
|
1027 * Only observe when a limited number of query args are set. There |
|
1028 * are no filters for other properties, so observing will result in |
|
1029 * false positives in those queries. |
|
1030 */ |
|
1031 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ]; |
|
1032 if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { |
|
1033 this.observe( wp.Uploader.queue ); |
|
1034 } |
|
1035 }, |
|
1036 /** |
|
1037 * Whether there are more attachments that haven't been sync'd from the server |
|
1038 * that match the collection's query. |
|
1039 * |
|
1040 * @return {boolean} |
|
1041 */ |
|
1042 hasMore: function() { |
|
1043 return this._hasMore; |
|
1044 }, |
|
1045 /** |
|
1046 * Fetch more attachments from the server for the collection. |
|
1047 * |
|
1048 * @param {Object} [options={}] |
|
1049 * @return {Promise} |
|
1050 */ |
|
1051 more: function( options ) { |
|
1052 var query = this; |
|
1053 |
|
1054 // If there is already a request pending, return early with the Deferred object. |
|
1055 if ( this._more && 'pending' === this._more.state() ) { |
|
1056 return this._more; |
|
1057 } |
|
1058 |
|
1059 if ( ! this.hasMore() ) { |
|
1060 return jQuery.Deferred().resolveWith( this ).promise(); |
|
1061 } |
|
1062 |
|
1063 options = options || {}; |
|
1064 options.remove = false; |
|
1065 |
|
1066 return this._more = this.fetch( options ).done( function( response ) { |
|
1067 if ( _.isEmpty( response ) || -1 === query.args.posts_per_page || response.length < query.args.posts_per_page ) { |
|
1068 query._hasMore = false; |
|
1069 } |
|
1070 }); |
|
1071 }, |
|
1072 /** |
|
1073 * Overrides Backbone.Collection.sync |
|
1074 * Overrides wp.media.model.Attachments.sync |
|
1075 * |
|
1076 * @param {string} method |
|
1077 * @param {Backbone.Model} model |
|
1078 * @param {Object} [options={}] |
|
1079 * @return {Promise} |
|
1080 */ |
|
1081 sync: function( method, model, options ) { |
|
1082 var args, fallback; |
|
1083 |
|
1084 // Overload the read method so Attachment.fetch() functions correctly. |
|
1085 if ( 'read' === method ) { |
|
1086 options = options || {}; |
|
1087 options.context = this; |
|
1088 options.data = _.extend( options.data || {}, { |
|
1089 action: 'query-attachments', |
|
1090 post_id: wp.media.model.settings.post.id |
|
1091 }); |
|
1092 |
|
1093 // Clone the args so manipulation is non-destructive. |
|
1094 args = _.clone( this.args ); |
|
1095 |
|
1096 // Determine which page to query. |
|
1097 if ( -1 !== args.posts_per_page ) { |
|
1098 args.paged = Math.round( this.length / args.posts_per_page ) + 1; |
|
1099 } |
|
1100 |
|
1101 options.data.query = args; |
|
1102 return wp.media.ajax( options ); |
|
1103 |
|
1104 // Otherwise, fall back to `Backbone.sync()`. |
|
1105 } else { |
|
1106 /** |
|
1107 * Call wp.media.model.Attachments.sync or Backbone.sync |
|
1108 */ |
|
1109 fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; |
|
1110 return fallback.sync.apply( this, arguments ); |
|
1111 } |
|
1112 } |
|
1113 }, /** @lends wp.media.model.Query */{ |
|
1114 /** |
|
1115 * @readonly |
|
1116 */ |
|
1117 defaultProps: { |
|
1118 orderby: 'date', |
|
1119 order: 'DESC' |
|
1120 }, |
|
1121 /** |
|
1122 * @readonly |
|
1123 */ |
|
1124 defaultArgs: { |
|
1125 posts_per_page: 80 |
|
1126 }, |
|
1127 /** |
|
1128 * @readonly |
|
1129 */ |
|
1130 orderby: { |
|
1131 allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], |
|
1132 /** |
|
1133 * A map of JavaScript orderby values to their WP_Query equivalents. |
|
1134 * @type {Object} |
|
1135 */ |
|
1136 valuemap: { |
|
1137 'id': 'ID', |
|
1138 'uploadedTo': 'parent', |
|
1139 'menuOrder': 'menu_order ID' |
|
1140 } |
|
1141 }, |
|
1142 /** |
|
1143 * A map of JavaScript query properties to their WP_Query equivalents. |
|
1144 * |
|
1145 * @readonly |
|
1146 */ |
|
1147 propmap: { |
|
1148 'search': 's', |
|
1149 'type': 'post_mime_type', |
|
1150 'perPage': 'posts_per_page', |
|
1151 'menuOrder': 'menu_order', |
|
1152 'uploadedTo': 'post_parent', |
|
1153 'status': 'post_status', |
|
1154 'include': 'post__in', |
|
1155 'exclude': 'post__not_in', |
|
1156 'author': 'author' |
|
1157 }, |
|
1158 /** |
|
1159 * Creates and returns an Attachments Query collection given the properties. |
|
1160 * |
|
1161 * Caches query objects and reuses where possible. |
|
1162 * |
|
1163 * @static |
|
1164 * @method |
|
1165 * |
|
1166 * @param {object} [props] |
|
1167 * @param {Object} [props.order] |
|
1168 * @param {Object} [props.orderby] |
|
1169 * @param {Object} [props.include] |
|
1170 * @param {Object} [props.exclude] |
|
1171 * @param {Object} [props.s] |
|
1172 * @param {Object} [props.post_mime_type] |
|
1173 * @param {Object} [props.posts_per_page] |
|
1174 * @param {Object} [props.menu_order] |
|
1175 * @param {Object} [props.post_parent] |
|
1176 * @param {Object} [props.post_status] |
|
1177 * @param {Object} [props.author] |
|
1178 * @param {Object} [options] |
|
1179 * |
|
1180 * @return {wp.media.model.Query} A new Attachments Query collection. |
|
1181 */ |
|
1182 get: (function(){ |
|
1183 /** |
|
1184 * @static |
|
1185 * @type Array |
|
1186 */ |
|
1187 var queries = []; |
|
1188 |
|
1189 /** |
|
1190 * @return {Query} |
|
1191 */ |
|
1192 return function( props, options ) { |
|
1193 var args = {}, |
|
1194 orderby = Query.orderby, |
|
1195 defaults = Query.defaultProps, |
|
1196 query; |
|
1197 |
|
1198 // Remove the `query` property. This isn't linked to a query, |
|
1199 // this *is* the query. |
|
1200 delete props.query; |
|
1201 |
|
1202 // Fill default args. |
|
1203 _.defaults( props, defaults ); |
|
1204 |
|
1205 // Normalize the order. |
|
1206 props.order = props.order.toUpperCase(); |
|
1207 if ( 'DESC' !== props.order && 'ASC' !== props.order ) { |
|
1208 props.order = defaults.order.toUpperCase(); |
|
1209 } |
|
1210 |
|
1211 // Ensure we have a valid orderby value. |
|
1212 if ( ! _.contains( orderby.allowed, props.orderby ) ) { |
|
1213 props.orderby = defaults.orderby; |
|
1214 } |
|
1215 |
|
1216 _.each( [ 'include', 'exclude' ], function( prop ) { |
|
1217 if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { |
|
1218 props[ prop ] = [ props[ prop ] ]; |
|
1219 } |
|
1220 } ); |
|
1221 |
|
1222 // Generate the query `args` object. |
|
1223 // Correct any differing property names. |
|
1224 _.each( props, function( value, prop ) { |
|
1225 if ( _.isNull( value ) ) { |
|
1226 return; |
|
1227 } |
|
1228 |
|
1229 args[ Query.propmap[ prop ] || prop ] = value; |
|
1230 }); |
|
1231 |
|
1232 // Fill any other default query args. |
|
1233 _.defaults( args, Query.defaultArgs ); |
|
1234 |
|
1235 // `props.orderby` does not always map directly to `args.orderby`. |
|
1236 // Substitute exceptions specified in orderby.keymap. |
|
1237 args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; |
|
1238 |
|
1239 queries = []; |
|
1240 |
|
1241 // Otherwise, create a new query and add it to the cache. |
|
1242 if ( ! query ) { |
|
1243 query = new Query( [], _.extend( options || {}, { |
|
1244 props: props, |
|
1245 args: args |
|
1246 } ) ); |
|
1247 queries.push( query ); |
|
1248 } |
|
1249 |
|
1250 return query; |
|
1251 }; |
|
1252 }()) |
|
1253 }); |
|
1254 |
|
1255 module.exports = Query; |
|
1256 |
|
1257 |
|
1258 /***/ }), |
|
1259 |
|
1260 /***/ 6584: |
|
1261 /***/ (function(module) { |
|
1262 |
|
1263 var Attachments = wp.media.model.Attachments, |
|
1264 Selection; |
|
1265 |
|
1266 /** |
|
1267 * wp.media.model.Selection |
|
1268 * |
|
1269 * A selection of attachments. |
|
1270 * |
|
1271 * @memberOf wp.media.model |
|
1272 * |
|
1273 * @class |
|
1274 * @augments wp.media.model.Attachments |
|
1275 * @augments Backbone.Collection |
|
1276 */ |
|
1277 Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{ |
|
1278 /** |
|
1279 * Refresh the `single` model whenever the selection changes. |
|
1280 * Binds `single` instead of using the context argument to ensure |
|
1281 * it receives no parameters. |
|
1282 * |
|
1283 * @param {Array} [models=[]] Array of models used to populate the collection. |
|
1284 * @param {Object} [options={}] |
|
1285 */ |
|
1286 initialize: function( models, options ) { |
|
1287 /** |
|
1288 * call 'initialize' directly on the parent class |
|
1289 */ |
|
1290 Attachments.prototype.initialize.apply( this, arguments ); |
|
1291 this.multiple = options && options.multiple; |
|
1292 |
|
1293 this.on( 'add remove reset', _.bind( this.single, this, false ) ); |
|
1294 }, |
|
1295 |
|
1296 /** |
|
1297 * If the workflow does not support multi-select, clear out the selection |
|
1298 * before adding a new attachment to it. |
|
1299 * |
|
1300 * @param {Array} models |
|
1301 * @param {Object} options |
|
1302 * @return {wp.media.model.Attachment[]} |
|
1303 */ |
|
1304 add: function( models, options ) { |
|
1305 if ( ! this.multiple ) { |
|
1306 this.remove( this.models ); |
|
1307 } |
|
1308 /** |
|
1309 * call 'add' directly on the parent class |
|
1310 */ |
|
1311 return Attachments.prototype.add.call( this, models, options ); |
|
1312 }, |
|
1313 |
|
1314 /** |
|
1315 * Fired when toggling (clicking on) an attachment in the modal. |
|
1316 * |
|
1317 * @param {undefined|boolean|wp.media.model.Attachment} model |
|
1318 * |
|
1319 * @fires wp.media.model.Selection#selection:single |
|
1320 * @fires wp.media.model.Selection#selection:unsingle |
|
1321 * |
|
1322 * @return {Backbone.Model} |
|
1323 */ |
|
1324 single: function( model ) { |
|
1325 var previous = this._single; |
|
1326 |
|
1327 // If a `model` is provided, use it as the single model. |
|
1328 if ( model ) { |
|
1329 this._single = model; |
|
1330 } |
|
1331 // If the single model isn't in the selection, remove it. |
|
1332 if ( this._single && ! this.get( this._single.cid ) ) { |
|
1333 delete this._single; |
|
1334 } |
|
1335 |
|
1336 this._single = this._single || this.last(); |
|
1337 |
|
1338 // If single has changed, fire an event. |
|
1339 if ( this._single !== previous ) { |
|
1340 if ( previous ) { |
|
1341 previous.trigger( 'selection:unsingle', previous, this ); |
|
1342 |
|
1343 // If the model was already removed, trigger the collection |
|
1344 // event manually. |
|
1345 if ( ! this.get( previous.cid ) ) { |
|
1346 this.trigger( 'selection:unsingle', previous, this ); |
|
1347 } |
|
1348 } |
|
1349 if ( this._single ) { |
|
1350 this._single.trigger( 'selection:single', this._single, this ); |
|
1351 } |
|
1352 } |
|
1353 |
|
1354 // Return the single model, or the last model as a fallback. |
|
1355 return this._single; |
|
1356 } |
|
1357 }); |
|
1358 |
|
1359 module.exports = Selection; |
|
1360 |
|
1361 |
|
1362 /***/ }) |
|
1363 |
|
1364 /******/ }); |
|
1365 /************************************************************************/ |
|
1366 /******/ // The module cache |
|
1367 /******/ var __webpack_module_cache__ = {}; |
|
1368 /******/ |
|
1369 /******/ // The require function |
|
1370 /******/ function __webpack_require__(moduleId) { |
|
1371 /******/ // Check if module is in cache |
|
1372 /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
1373 /******/ if (cachedModule !== undefined) { |
|
1374 /******/ return cachedModule.exports; |
|
1375 /******/ } |
|
1376 /******/ // Create a new module (and put it into the cache) |
|
1377 /******/ var module = __webpack_module_cache__[moduleId] = { |
|
1378 /******/ // no module.id needed |
|
1379 /******/ // no module.loaded needed |
|
1380 /******/ exports: {} |
|
1381 /******/ }; |
|
1382 /******/ |
|
1383 /******/ // Execute the module function |
|
1384 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
1385 /******/ |
|
1386 /******/ // Return the exports of the module |
|
1387 /******/ return module.exports; |
|
1388 /******/ } |
|
1389 /******/ |
|
1390 /************************************************************************/ |
|
1391 var __webpack_exports__ = {}; |
|
1392 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
|
1393 !function() { |
988 /** |
1394 /** |
989 * @output wp-includes/js/media-models.js |
1395 * @output wp-includes/js/media-models.js |
990 */ |
1396 */ |
991 |
1397 |
992 var $ = jQuery, |
1398 var $ = jQuery, |
1228 // Clean up. Prevents mobile browsers caching. |
1634 // Clean up. Prevents mobile browsers caching. |
1229 $(window).on('unload', function(){ |
1635 $(window).on('unload', function(){ |
1230 window.wp = null; |
1636 window.wp = null; |
1231 }); |
1637 }); |
1232 |
1638 |
1233 |
1639 }(); |
1234 /***/ }), |
1640 /******/ })() |
1235 |
1641 ; |
1236 /***/ "efdO": |
|
1237 /***/ (function(module, exports) { |
|
1238 |
|
1239 var Attachments = wp.media.model.Attachments, |
|
1240 Query; |
|
1241 |
|
1242 /** |
|
1243 * wp.media.model.Query |
|
1244 * |
|
1245 * A collection of attachments that match the supplied query arguments. |
|
1246 * |
|
1247 * Note: Do NOT change this.args after the query has been initialized. |
|
1248 * Things will break. |
|
1249 * |
|
1250 * @memberOf wp.media.model |
|
1251 * |
|
1252 * @class |
|
1253 * @augments wp.media.model.Attachments |
|
1254 * @augments Backbone.Collection |
|
1255 * |
|
1256 * @param {array} [models] Models to initialize with the collection. |
|
1257 * @param {object} [options] Options hash. |
|
1258 * @param {object} [options.args] Attachments query arguments. |
|
1259 * @param {object} [options.args.posts_per_page] |
|
1260 */ |
|
1261 Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ |
|
1262 /** |
|
1263 * @param {Array} [models=[]] Array of initial models to populate the collection. |
|
1264 * @param {Object} [options={}] |
|
1265 */ |
|
1266 initialize: function( models, options ) { |
|
1267 var allowed; |
|
1268 |
|
1269 options = options || {}; |
|
1270 Attachments.prototype.initialize.apply( this, arguments ); |
|
1271 |
|
1272 this.args = options.args; |
|
1273 this._hasMore = true; |
|
1274 this.created = new Date(); |
|
1275 |
|
1276 this.filters.order = function( attachment ) { |
|
1277 var orderby = this.props.get('orderby'), |
|
1278 order = this.props.get('order'); |
|
1279 |
|
1280 if ( ! this.comparator ) { |
|
1281 return true; |
|
1282 } |
|
1283 |
|
1284 /* |
|
1285 * We want any items that can be placed before the last |
|
1286 * item in the set. If we add any items after the last |
|
1287 * item, then we can't guarantee the set is complete. |
|
1288 */ |
|
1289 if ( this.length ) { |
|
1290 return 1 !== this.comparator( attachment, this.last(), { ties: true }); |
|
1291 |
|
1292 /* |
|
1293 * Handle the case where there are no items yet and |
|
1294 * we're sorting for recent items. In that case, we want |
|
1295 * changes that occurred after we created the query. |
|
1296 */ |
|
1297 } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { |
|
1298 return attachment.get( orderby ) >= this.created; |
|
1299 |
|
1300 // If we're sorting by menu order and we have no items, |
|
1301 // accept any items that have the default menu order (0). |
|
1302 } else if ( 'ASC' === order && 'menuOrder' === orderby ) { |
|
1303 return attachment.get( orderby ) === 0; |
|
1304 } |
|
1305 |
|
1306 // Otherwise, we don't want any items yet. |
|
1307 return false; |
|
1308 }; |
|
1309 |
|
1310 /* |
|
1311 * Observe the central `wp.Uploader.queue` collection to watch for |
|
1312 * new matches for the query. |
|
1313 * |
|
1314 * Only observe when a limited number of query args are set. There |
|
1315 * are no filters for other properties, so observing will result in |
|
1316 * false positives in those queries. |
|
1317 */ |
|
1318 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ]; |
|
1319 if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { |
|
1320 this.observe( wp.Uploader.queue ); |
|
1321 } |
|
1322 }, |
|
1323 /** |
|
1324 * Whether there are more attachments that haven't been sync'd from the server |
|
1325 * that match the collection's query. |
|
1326 * |
|
1327 * @return {boolean} |
|
1328 */ |
|
1329 hasMore: function() { |
|
1330 return this._hasMore; |
|
1331 }, |
|
1332 /** |
|
1333 * Fetch more attachments from the server for the collection. |
|
1334 * |
|
1335 * @param {Object} [options={}] |
|
1336 * @return {Promise} |
|
1337 */ |
|
1338 more: function( options ) { |
|
1339 var query = this; |
|
1340 |
|
1341 // If there is already a request pending, return early with the Deferred object. |
|
1342 if ( this._more && 'pending' === this._more.state() ) { |
|
1343 return this._more; |
|
1344 } |
|
1345 |
|
1346 if ( ! this.hasMore() ) { |
|
1347 return jQuery.Deferred().resolveWith( this ).promise(); |
|
1348 } |
|
1349 |
|
1350 options = options || {}; |
|
1351 options.remove = false; |
|
1352 |
|
1353 return this._more = this.fetch( options ).done( function( response ) { |
|
1354 if ( _.isEmpty( response ) || -1 === query.args.posts_per_page || response.length < query.args.posts_per_page ) { |
|
1355 query._hasMore = false; |
|
1356 } |
|
1357 }); |
|
1358 }, |
|
1359 /** |
|
1360 * Overrides Backbone.Collection.sync |
|
1361 * Overrides wp.media.model.Attachments.sync |
|
1362 * |
|
1363 * @param {string} method |
|
1364 * @param {Backbone.Model} model |
|
1365 * @param {Object} [options={}] |
|
1366 * @return {Promise} |
|
1367 */ |
|
1368 sync: function( method, model, options ) { |
|
1369 var args, fallback; |
|
1370 |
|
1371 // Overload the read method so Attachment.fetch() functions correctly. |
|
1372 if ( 'read' === method ) { |
|
1373 options = options || {}; |
|
1374 options.context = this; |
|
1375 options.data = _.extend( options.data || {}, { |
|
1376 action: 'query-attachments', |
|
1377 post_id: wp.media.model.settings.post.id |
|
1378 }); |
|
1379 |
|
1380 // Clone the args so manipulation is non-destructive. |
|
1381 args = _.clone( this.args ); |
|
1382 |
|
1383 // Determine which page to query. |
|
1384 if ( -1 !== args.posts_per_page ) { |
|
1385 args.paged = Math.round( this.length / args.posts_per_page ) + 1; |
|
1386 } |
|
1387 |
|
1388 options.data.query = args; |
|
1389 return wp.media.ajax( options ); |
|
1390 |
|
1391 // Otherwise, fall back to `Backbone.sync()`. |
|
1392 } else { |
|
1393 /** |
|
1394 * Call wp.media.model.Attachments.sync or Backbone.sync |
|
1395 */ |
|
1396 fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; |
|
1397 return fallback.sync.apply( this, arguments ); |
|
1398 } |
|
1399 } |
|
1400 }, /** @lends wp.media.model.Query */{ |
|
1401 /** |
|
1402 * @readonly |
|
1403 */ |
|
1404 defaultProps: { |
|
1405 orderby: 'date', |
|
1406 order: 'DESC' |
|
1407 }, |
|
1408 /** |
|
1409 * @readonly |
|
1410 */ |
|
1411 defaultArgs: { |
|
1412 posts_per_page: 80 |
|
1413 }, |
|
1414 /** |
|
1415 * @readonly |
|
1416 */ |
|
1417 orderby: { |
|
1418 allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], |
|
1419 /** |
|
1420 * A map of JavaScript orderby values to their WP_Query equivalents. |
|
1421 * @type {Object} |
|
1422 */ |
|
1423 valuemap: { |
|
1424 'id': 'ID', |
|
1425 'uploadedTo': 'parent', |
|
1426 'menuOrder': 'menu_order ID' |
|
1427 } |
|
1428 }, |
|
1429 /** |
|
1430 * A map of JavaScript query properties to their WP_Query equivalents. |
|
1431 * |
|
1432 * @readonly |
|
1433 */ |
|
1434 propmap: { |
|
1435 'search': 's', |
|
1436 'type': 'post_mime_type', |
|
1437 'perPage': 'posts_per_page', |
|
1438 'menuOrder': 'menu_order', |
|
1439 'uploadedTo': 'post_parent', |
|
1440 'status': 'post_status', |
|
1441 'include': 'post__in', |
|
1442 'exclude': 'post__not_in', |
|
1443 'author': 'author' |
|
1444 }, |
|
1445 /** |
|
1446 * Creates and returns an Attachments Query collection given the properties. |
|
1447 * |
|
1448 * Caches query objects and reuses where possible. |
|
1449 * |
|
1450 * @static |
|
1451 * @method |
|
1452 * |
|
1453 * @param {object} [props] |
|
1454 * @param {Object} [props.order] |
|
1455 * @param {Object} [props.orderby] |
|
1456 * @param {Object} [props.include] |
|
1457 * @param {Object} [props.exclude] |
|
1458 * @param {Object} [props.s] |
|
1459 * @param {Object} [props.post_mime_type] |
|
1460 * @param {Object} [props.posts_per_page] |
|
1461 * @param {Object} [props.menu_order] |
|
1462 * @param {Object} [props.post_parent] |
|
1463 * @param {Object} [props.post_status] |
|
1464 * @param {Object} [props.author] |
|
1465 * @param {Object} [options] |
|
1466 * |
|
1467 * @return {wp.media.model.Query} A new Attachments Query collection. |
|
1468 */ |
|
1469 get: (function(){ |
|
1470 /** |
|
1471 * @static |
|
1472 * @type Array |
|
1473 */ |
|
1474 var queries = []; |
|
1475 |
|
1476 /** |
|
1477 * @return {Query} |
|
1478 */ |
|
1479 return function( props, options ) { |
|
1480 var args = {}, |
|
1481 orderby = Query.orderby, |
|
1482 defaults = Query.defaultProps, |
|
1483 query; |
|
1484 |
|
1485 // Remove the `query` property. This isn't linked to a query, |
|
1486 // this *is* the query. |
|
1487 delete props.query; |
|
1488 |
|
1489 // Fill default args. |
|
1490 _.defaults( props, defaults ); |
|
1491 |
|
1492 // Normalize the order. |
|
1493 props.order = props.order.toUpperCase(); |
|
1494 if ( 'DESC' !== props.order && 'ASC' !== props.order ) { |
|
1495 props.order = defaults.order.toUpperCase(); |
|
1496 } |
|
1497 |
|
1498 // Ensure we have a valid orderby value. |
|
1499 if ( ! _.contains( orderby.allowed, props.orderby ) ) { |
|
1500 props.orderby = defaults.orderby; |
|
1501 } |
|
1502 |
|
1503 _.each( [ 'include', 'exclude' ], function( prop ) { |
|
1504 if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { |
|
1505 props[ prop ] = [ props[ prop ] ]; |
|
1506 } |
|
1507 } ); |
|
1508 |
|
1509 // Generate the query `args` object. |
|
1510 // Correct any differing property names. |
|
1511 _.each( props, function( value, prop ) { |
|
1512 if ( _.isNull( value ) ) { |
|
1513 return; |
|
1514 } |
|
1515 |
|
1516 args[ Query.propmap[ prop ] || prop ] = value; |
|
1517 }); |
|
1518 |
|
1519 // Fill any other default query args. |
|
1520 _.defaults( args, Query.defaultArgs ); |
|
1521 |
|
1522 // `props.orderby` does not always map directly to `args.orderby`. |
|
1523 // Substitute exceptions specified in orderby.keymap. |
|
1524 args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; |
|
1525 |
|
1526 queries = []; |
|
1527 |
|
1528 // Otherwise, create a new query and add it to the cache. |
|
1529 if ( ! query ) { |
|
1530 query = new Query( [], _.extend( options || {}, { |
|
1531 props: props, |
|
1532 args: args |
|
1533 } ) ); |
|
1534 queries.push( query ); |
|
1535 } |
|
1536 |
|
1537 return query; |
|
1538 }; |
|
1539 }()) |
|
1540 }); |
|
1541 |
|
1542 module.exports = Query; |
|
1543 |
|
1544 |
|
1545 /***/ }), |
|
1546 |
|
1547 /***/ "r1z7": |
|
1548 /***/ (function(module, exports) { |
|
1549 |
|
1550 /** |
|
1551 * wp.media.model.PostImage |
|
1552 * |
|
1553 * An instance of an image that's been embedded into a post. |
|
1554 * |
|
1555 * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. |
|
1556 * |
|
1557 * @memberOf wp.media.model |
|
1558 * |
|
1559 * @class |
|
1560 * @augments Backbone.Model |
|
1561 * |
|
1562 * @param {int} [attributes] Initial model attributes. |
|
1563 * @param {int} [attributes.attachment_id] ID of the attachment. |
|
1564 **/ |
|
1565 var PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{ |
|
1566 |
|
1567 initialize: function( attributes ) { |
|
1568 var Attachment = wp.media.model.Attachment; |
|
1569 this.attachment = false; |
|
1570 |
|
1571 if ( attributes.attachment_id ) { |
|
1572 this.attachment = Attachment.get( attributes.attachment_id ); |
|
1573 if ( this.attachment.get( 'url' ) ) { |
|
1574 this.dfd = jQuery.Deferred(); |
|
1575 this.dfd.resolve(); |
|
1576 } else { |
|
1577 this.dfd = this.attachment.fetch(); |
|
1578 } |
|
1579 this.bindAttachmentListeners(); |
|
1580 } |
|
1581 |
|
1582 // Keep URL in sync with changes to the type of link. |
|
1583 this.on( 'change:link', this.updateLinkUrl, this ); |
|
1584 this.on( 'change:size', this.updateSize, this ); |
|
1585 |
|
1586 this.setLinkTypeFromUrl(); |
|
1587 this.setAspectRatio(); |
|
1588 |
|
1589 this.set( 'originalUrl', attributes.url ); |
|
1590 }, |
|
1591 |
|
1592 bindAttachmentListeners: function() { |
|
1593 this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl ); |
|
1594 this.listenTo( this.attachment, 'sync', this.setAspectRatio ); |
|
1595 this.listenTo( this.attachment, 'change', this.updateSize ); |
|
1596 }, |
|
1597 |
|
1598 changeAttachment: function( attachment, props ) { |
|
1599 this.stopListening( this.attachment ); |
|
1600 this.attachment = attachment; |
|
1601 this.bindAttachmentListeners(); |
|
1602 |
|
1603 this.set( 'attachment_id', this.attachment.get( 'id' ) ); |
|
1604 this.set( 'caption', this.attachment.get( 'caption' ) ); |
|
1605 this.set( 'alt', this.attachment.get( 'alt' ) ); |
|
1606 this.set( 'size', props.get( 'size' ) ); |
|
1607 this.set( 'align', props.get( 'align' ) ); |
|
1608 this.set( 'link', props.get( 'link' ) ); |
|
1609 this.updateLinkUrl(); |
|
1610 this.updateSize(); |
|
1611 }, |
|
1612 |
|
1613 setLinkTypeFromUrl: function() { |
|
1614 var linkUrl = this.get( 'linkUrl' ), |
|
1615 type; |
|
1616 |
|
1617 if ( ! linkUrl ) { |
|
1618 this.set( 'link', 'none' ); |
|
1619 return; |
|
1620 } |
|
1621 |
|
1622 // Default to custom if there is a linkUrl. |
|
1623 type = 'custom'; |
|
1624 |
|
1625 if ( this.attachment ) { |
|
1626 if ( this.attachment.get( 'url' ) === linkUrl ) { |
|
1627 type = 'file'; |
|
1628 } else if ( this.attachment.get( 'link' ) === linkUrl ) { |
|
1629 type = 'post'; |
|
1630 } |
|
1631 } else { |
|
1632 if ( this.get( 'url' ) === linkUrl ) { |
|
1633 type = 'file'; |
|
1634 } |
|
1635 } |
|
1636 |
|
1637 this.set( 'link', type ); |
|
1638 }, |
|
1639 |
|
1640 updateLinkUrl: function() { |
|
1641 var link = this.get( 'link' ), |
|
1642 url; |
|
1643 |
|
1644 switch( link ) { |
|
1645 case 'file': |
|
1646 if ( this.attachment ) { |
|
1647 url = this.attachment.get( 'url' ); |
|
1648 } else { |
|
1649 url = this.get( 'url' ); |
|
1650 } |
|
1651 this.set( 'linkUrl', url ); |
|
1652 break; |
|
1653 case 'post': |
|
1654 this.set( 'linkUrl', this.attachment.get( 'link' ) ); |
|
1655 break; |
|
1656 case 'none': |
|
1657 this.set( 'linkUrl', '' ); |
|
1658 break; |
|
1659 } |
|
1660 }, |
|
1661 |
|
1662 updateSize: function() { |
|
1663 var size; |
|
1664 |
|
1665 if ( ! this.attachment ) { |
|
1666 return; |
|
1667 } |
|
1668 |
|
1669 if ( this.get( 'size' ) === 'custom' ) { |
|
1670 this.set( 'width', this.get( 'customWidth' ) ); |
|
1671 this.set( 'height', this.get( 'customHeight' ) ); |
|
1672 this.set( 'url', this.get( 'originalUrl' ) ); |
|
1673 return; |
|
1674 } |
|
1675 |
|
1676 size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ]; |
|
1677 |
|
1678 if ( ! size ) { |
|
1679 return; |
|
1680 } |
|
1681 |
|
1682 this.set( 'url', size.url ); |
|
1683 this.set( 'width', size.width ); |
|
1684 this.set( 'height', size.height ); |
|
1685 }, |
|
1686 |
|
1687 setAspectRatio: function() { |
|
1688 var full; |
|
1689 |
|
1690 if ( this.attachment && this.attachment.get( 'sizes' ) ) { |
|
1691 full = this.attachment.get( 'sizes' ).full; |
|
1692 |
|
1693 if ( full ) { |
|
1694 this.set( 'aspectRatio', full.width / full.height ); |
|
1695 return; |
|
1696 } |
|
1697 } |
|
1698 |
|
1699 this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) ); |
|
1700 } |
|
1701 }); |
|
1702 |
|
1703 module.exports = PostImage; |
|
1704 |
|
1705 |
|
1706 /***/ }) |
|
1707 |
|
1708 /******/ }); |
|