author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
/******/ (function(modules) { // webpackBootstrap |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
/******/ // The module cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
/******/ var installedModules = {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
/******/ // The require function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
/******/ function __webpack_require__(moduleId) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
/******/ // Check if module is in cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
/******/ if(installedModules[moduleId]) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/******/ return installedModules[moduleId].exports; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
/******/ } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
/******/ // Create a new module (and put it into the cache) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
/******/ var module = installedModules[moduleId] = { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
/******/ i: moduleId, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
/******/ l: false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
/******/ exports: {} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
/******/ }; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
/******/ // Execute the module function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
/******/ // Flag the module as loaded |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
/******/ module.l = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
/******/ // Return the exports of the module |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
/******/ return module.exports; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
/******/ } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
/******/ // expose the modules object (__webpack_modules__) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
/******/ __webpack_require__.m = modules; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
/******/ // expose the module cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
/******/ __webpack_require__.c = installedModules; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
/******/ // define getter function for harmony exports |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
/******/ __webpack_require__.d = function(exports, name, getter) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
/******/ if(!__webpack_require__.o(exports, name)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
/******/ Object.defineProperty(exports, name, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
/******/ configurable: false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
/******/ enumerable: true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
/******/ get: getter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
/******/ }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
/******/ } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
/******/ }; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
/******/ __webpack_require__.n = function(module) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
/******/ var getter = module && module.__esModule ? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
/******/ function getDefault() { return module['default']; } : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
/******/ function getModuleExports() { return module; }; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
/******/ __webpack_require__.d(getter, 'a', getter); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
/******/ return getter; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
/******/ }; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
/******/ // Object.prototype.hasOwnProperty.call |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
/******/ // __webpack_public_path__ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
/******/ __webpack_require__.p = ""; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
/******/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
/******/ // Load entry module and return exports |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
/******/ return __webpack_require__(__webpack_require__.s = 20); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
/******/ }) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
/************************************************************************/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
/******/ ({ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
/***/ 20: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
/***/ (function(module, exports, __webpack_require__) { |
5 | 70 |
|
71 |
var $ = jQuery, |
|
72 |
Attachment, Attachments, l10n, media; |
|
73 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
/** @namespace wp */ |
0 | 75 |
window.wp = window.wp || {}; |
76 |
||
5 | 77 |
/** |
78 |
* Create and return a media frame. |
|
79 |
* |
|
80 |
* Handles the default media experience. |
|
81 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @alias wp.media |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @memberOf wp |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @namespace |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* |
5 | 86 |
* @param {object} attributes The properties passed to the main media controller. |
87 |
* @return {wp.media.view.MediaFrame} A media workflow. |
|
88 |
*/ |
|
89 |
media = wp.media = function( attributes ) { |
|
90 |
var MediaFrame = media.view.MediaFrame, |
|
91 |
frame; |
|
92 |
||
93 |
if ( ! MediaFrame ) { |
|
94 |
return; |
|
95 |
} |
|
96 |
||
97 |
attributes = _.defaults( attributes || {}, { |
|
98 |
frame: 'select' |
|
99 |
}); |
|
0 | 100 |
|
5 | 101 |
if ( 'select' === attributes.frame && MediaFrame.Select ) { |
102 |
frame = new MediaFrame.Select( attributes ); |
|
103 |
} else if ( 'post' === attributes.frame && MediaFrame.Post ) { |
|
104 |
frame = new MediaFrame.Post( attributes ); |
|
105 |
} else if ( 'manage' === attributes.frame && MediaFrame.Manage ) { |
|
106 |
frame = new MediaFrame.Manage( attributes ); |
|
107 |
} else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) { |
|
108 |
frame = new MediaFrame.ImageDetails( attributes ); |
|
109 |
} else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) { |
|
110 |
frame = new MediaFrame.AudioDetails( attributes ); |
|
111 |
} else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) { |
|
112 |
frame = new MediaFrame.VideoDetails( attributes ); |
|
113 |
} else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) { |
|
114 |
frame = new MediaFrame.EditAttachments( attributes ); |
|
115 |
} |
|
0 | 116 |
|
5 | 117 |
delete attributes.frame; |
118 |
||
119 |
media.frame = frame; |
|
0 | 120 |
|
5 | 121 |
return frame; |
122 |
}; |
|
123 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
/** @namespace wp.media.model */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
/** @namespace wp.media.view */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
/** @namespace wp.media.controller */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
/** @namespace wp.media.frames */ |
5 | 128 |
_.extend( media, { model: {}, view: {}, controller: {}, frames: {} }); |
129 |
||
130 |
// Link any localized strings. |
|
131 |
l10n = media.model.l10n = window._wpMediaModelsL10n || {}; |
|
0 | 132 |
|
5 | 133 |
// Link any settings. |
134 |
media.model.settings = l10n.settings || {}; |
|
135 |
delete l10n.settings; |
|
136 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
Attachment = media.model.Attachment = __webpack_require__( 21 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
Attachments = media.model.Attachments = __webpack_require__( 22 ); |
0 | 139 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
media.model.Query = __webpack_require__( 23 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
media.model.PostImage = __webpack_require__( 24 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
media.model.Selection = __webpack_require__( 25 ); |
0 | 143 |
|
5 | 144 |
/** |
145 |
* ======================================================================== |
|
146 |
* UTILITIES |
|
147 |
* ======================================================================== |
|
148 |
*/ |
|
0 | 149 |
|
5 | 150 |
/** |
151 |
* A basic equality comparator for Backbone models. |
|
152 |
* |
|
153 |
* Used to order models within a collection - @see wp.media.model.Attachments.comparator(). |
|
154 |
* |
|
155 |
* @param {mixed} a The primary parameter to compare. |
|
156 |
* @param {mixed} b The primary parameter to compare. |
|
157 |
* @param {string} ac The fallback parameter to compare, a's cid. |
|
158 |
* @param {string} bc The fallback parameter to compare, b's cid. |
|
159 |
* @return {number} -1: a should come before b. |
|
160 |
* 0: a and b are of the same rank. |
|
161 |
* 1: b should come before a. |
|
162 |
*/ |
|
163 |
media.compare = function( a, b, ac, bc ) { |
|
164 |
if ( _.isEqual( a, b ) ) { |
|
165 |
return ac === bc ? 0 : (ac > bc ? -1 : 1); |
|
166 |
} else { |
|
167 |
return a > b ? -1 : 1; |
|
168 |
} |
|
169 |
}; |
|
0 | 170 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
_.extend( media, /** @lends wp.media */{ |
0 | 172 |
/** |
5 | 173 |
* media.template( id ) |
174 |
* |
|
175 |
* Fetch a JavaScript template for an id, and return a templating function for it. |
|
176 |
* |
|
177 |
* See wp.template() in `wp-includes/js/wp-util.js`. |
|
178 |
* |
|
179 |
* @borrows wp.template as template |
|
0 | 180 |
*/ |
5 | 181 |
template: wp.template, |
0 | 182 |
|
183 |
/** |
|
5 | 184 |
* media.post( [action], [data] ) |
0 | 185 |
* |
5 | 186 |
* Sends a POST request to WordPress. |
187 |
* See wp.ajax.post() in `wp-includes/js/wp-util.js`. |
|
188 |
* |
|
189 |
* @borrows wp.ajax.post as post |
|
0 | 190 |
*/ |
5 | 191 |
post: wp.ajax.post, |
0 | 192 |
|
193 |
/** |
|
5 | 194 |
* media.ajax( [action], [options] ) |
195 |
* |
|
196 |
* Sends an XHR request to WordPress. |
|
197 |
* See wp.ajax.send() in `wp-includes/js/wp-util.js`. |
|
198 |
* |
|
199 |
* @borrows wp.ajax.send as ajax |
|
0 | 200 |
*/ |
5 | 201 |
ajax: wp.ajax.send, |
0 | 202 |
|
203 |
/** |
|
5 | 204 |
* Scales a set of dimensions to fit within bounding dimensions. |
205 |
* |
|
206 |
* @param {Object} dimensions |
|
207 |
* @returns {Object} |
|
0 | 208 |
*/ |
5 | 209 |
fit: function( dimensions ) { |
210 |
var width = dimensions.width, |
|
211 |
height = dimensions.height, |
|
212 |
maxWidth = dimensions.maxWidth, |
|
213 |
maxHeight = dimensions.maxHeight, |
|
214 |
constraint; |
|
0 | 215 |
|
5 | 216 |
// Compare ratios between the two values to determine which |
217 |
// max to constrain by. If a max value doesn't exist, then the |
|
218 |
// opposite side is the constraint. |
|
219 |
if ( ! _.isUndefined( maxWidth ) && ! _.isUndefined( maxHeight ) ) { |
|
220 |
constraint = ( width / height > maxWidth / maxHeight ) ? 'width' : 'height'; |
|
221 |
} else if ( _.isUndefined( maxHeight ) ) { |
|
222 |
constraint = 'width'; |
|
223 |
} else if ( _.isUndefined( maxWidth ) && height > maxHeight ) { |
|
224 |
constraint = 'height'; |
|
225 |
} |
|
0 | 226 |
|
5 | 227 |
// If the value of the constrained side is larger than the max, |
228 |
// then scale the values. Otherwise return the originals; they fit. |
|
229 |
if ( 'width' === constraint && width > maxWidth ) { |
|
230 |
return { |
|
231 |
width : maxWidth, |
|
232 |
height: Math.round( maxWidth * height / width ) |
|
233 |
}; |
|
234 |
} else if ( 'height' === constraint && height > maxHeight ) { |
|
235 |
return { |
|
236 |
width : Math.round( maxHeight * width / height ), |
|
237 |
height: maxHeight |
|
238 |
}; |
|
239 |
} else { |
|
240 |
return { |
|
241 |
width : width, |
|
242 |
height: height |
|
243 |
}; |
|
244 |
} |
|
245 |
}, |
|
246 |
/** |
|
247 |
* Truncates a string by injecting an ellipsis into the middle. |
|
248 |
* Useful for filenames. |
|
249 |
* |
|
250 |
* @param {String} string |
|
251 |
* @param {Number} [length=30] |
|
252 |
* @param {String} [replacement=…] |
|
253 |
* @returns {String} The string, unless length is greater than string.length. |
|
254 |
*/ |
|
255 |
truncate: function( string, length, replacement ) { |
|
256 |
length = length || 30; |
|
257 |
replacement = replacement || '…'; |
|
0 | 258 |
|
5 | 259 |
if ( string.length <= length ) { |
260 |
return string; |
|
261 |
} |
|
262 |
||
263 |
return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 ); |
|
264 |
} |
|
265 |
}); |
|
0 | 266 |
|
5 | 267 |
/** |
268 |
* ======================================================================== |
|
269 |
* MODELS |
|
270 |
* ======================================================================== |
|
271 |
*/ |
|
272 |
/** |
|
273 |
* wp.media.attachment |
|
274 |
* |
|
275 |
* @static |
|
276 |
* @param {String} id A string used to identify a model. |
|
277 |
* @returns {wp.media.model.Attachment} |
|
278 |
*/ |
|
279 |
media.attachment = function( id ) { |
|
280 |
return Attachment.get( id ); |
|
281 |
}; |
|
0 | 282 |
|
5 | 283 |
/** |
284 |
* A collection of all attachments that have been fetched from the server. |
|
285 |
* |
|
286 |
* @static |
|
287 |
* @member {wp.media.model.Attachments} |
|
288 |
*/ |
|
289 |
Attachments.all = new Attachments(); |
|
0 | 290 |
|
5 | 291 |
/** |
292 |
* wp.media.query |
|
293 |
* |
|
294 |
* Shorthand for creating a new Attachments Query. |
|
295 |
* |
|
296 |
* @param {object} [props] |
|
297 |
* @returns {wp.media.model.Attachments} |
|
298 |
*/ |
|
299 |
media.query = function( props ) { |
|
300 |
return new Attachments( null, { |
|
301 |
props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } ) |
|
302 |
}); |
|
303 |
}; |
|
0 | 304 |
|
5 | 305 |
// Clean up. Prevents mobile browsers caching |
306 |
$(window).on('unload', function(){ |
|
307 |
window.wp = null; |
|
308 |
}); |
|
309 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
/***/ 21: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
/***/ (function(module, exports) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
var $ = Backbone.$, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
Attachment; |
5 | 318 |
|
319 |
/** |
|
320 |
* wp.media.model.Attachment |
|
321 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* |
5 | 324 |
* @class |
325 |
* @augments Backbone.Model |
|
326 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
Attachment = Backbone.Model.extend(/** @lends wp.media.model.Attachment.prototype */{ |
5 | 328 |
/** |
329 |
* Triggered when attachment details change |
|
330 |
* Overrides Backbone.Model.sync |
|
331 |
* |
|
332 |
* @param {string} method |
|
333 |
* @param {wp.media.model.Attachment} model |
|
334 |
* @param {Object} [options={}] |
|
335 |
* |
|
336 |
* @returns {Promise} |
|
337 |
*/ |
|
338 |
sync: function( method, model, options ) { |
|
339 |
// If the attachment does not yet have an `id`, return an instantly |
|
340 |
// rejected promise. Otherwise, all of our requests will fail. |
|
341 |
if ( _.isUndefined( this.id ) ) { |
|
342 |
return $.Deferred().rejectWith( this ).promise(); |
|
343 |
} |
|
0 | 344 |
|
5 | 345 |
// Overload the `read` request so Attachment.fetch() functions correctly. |
346 |
if ( 'read' === method ) { |
|
347 |
options = options || {}; |
|
348 |
options.context = this; |
|
349 |
options.data = _.extend( options.data || {}, { |
|
350 |
action: 'get-attachment', |
|
351 |
id: this.id |
|
352 |
}); |
|
353 |
return wp.media.ajax( options ); |
|
0 | 354 |
|
5 | 355 |
// Overload the `update` request so properties can be saved. |
356 |
} else if ( 'update' === method ) { |
|
0 | 357 |
// If we do not have the necessary nonce, fail immeditately. |
5 | 358 |
if ( ! this.get('nonces') || ! this.get('nonces').update ) { |
0 | 359 |
return $.Deferred().rejectWith( this ).promise(); |
5 | 360 |
} |
0 | 361 |
|
5 | 362 |
options = options || {}; |
363 |
options.context = this; |
|
364 |
||
365 |
// Set the action and ID. |
|
366 |
options.data = _.extend( options.data || {}, { |
|
367 |
action: 'save-attachment', |
|
0 | 368 |
id: this.id, |
369 |
nonce: this.get('nonces').update, |
|
5 | 370 |
post_id: wp.media.model.settings.post.id |
0 | 371 |
}); |
372 |
||
5 | 373 |
// Record the values of the changed attributes. |
374 |
if ( model.hasChanged() ) { |
|
375 |
options.data.changes = {}; |
|
0 | 376 |
|
5 | 377 |
_.each( model.changed, function( value, key ) { |
378 |
options.data.changes[ key ] = this.get( key ); |
|
379 |
}, this ); |
|
0 | 380 |
} |
381 |
||
5 | 382 |
return wp.media.ajax( options ); |
0 | 383 |
|
5 | 384 |
// Overload the `delete` request so attachments can be removed. |
385 |
// This will permanently delete an attachment. |
|
386 |
} else if ( 'delete' === method ) { |
|
0 | 387 |
options = options || {}; |
388 |
||
5 | 389 |
if ( ! options.wait ) { |
390 |
this.destroyed = true; |
|
391 |
} |
|
392 |
||
393 |
options.context = this; |
|
394 |
options.data = _.extend( options.data || {}, { |
|
395 |
action: 'delete-post', |
|
396 |
id: this.id, |
|
397 |
_wpnonce: this.get('nonces')['delete'] |
|
398 |
}); |
|
399 |
||
400 |
return wp.media.ajax( options ).done( function() { |
|
401 |
this.destroyed = true; |
|
402 |
}).fail( function() { |
|
403 |
this.destroyed = false; |
|
404 |
}); |
|
0 | 405 |
|
5 | 406 |
// Otherwise, fall back to `Backbone.sync()`. |
407 |
} else { |
|
408 |
/** |
|
409 |
* Call `sync` directly on Backbone.Model |
|
410 |
*/ |
|
411 |
return Backbone.Model.prototype.sync.apply( this, arguments ); |
|
412 |
} |
|
413 |
}, |
|
414 |
/** |
|
415 |
* Convert date strings into Date objects. |
|
416 |
* |
|
417 |
* @param {Object} resp The raw response object, typically returned by fetch() |
|
418 |
* @returns {Object} The modified response object, which is the attributes hash |
|
419 |
* to be set on the model. |
|
420 |
*/ |
|
421 |
parse: function( resp ) { |
|
422 |
if ( ! resp ) { |
|
423 |
return resp; |
|
424 |
} |
|
0 | 425 |
|
5 | 426 |
resp.date = new Date( resp.date ); |
427 |
resp.modified = new Date( resp.modified ); |
|
428 |
return resp; |
|
429 |
}, |
|
430 |
/** |
|
431 |
* @param {Object} data The properties to be saved. |
|
432 |
* @param {Object} options Sync options. e.g. patch, wait, success, error. |
|
433 |
* |
|
434 |
* @this Backbone.Model |
|
435 |
* |
|
436 |
* @returns {Promise} |
|
437 |
*/ |
|
438 |
saveCompat: function( data, options ) { |
|
439 |
var model = this; |
|
440 |
||
441 |
// If we do not have the necessary nonce, fail immeditately. |
|
442 |
if ( ! this.get('nonces') || ! this.get('nonces').update ) { |
|
443 |
return $.Deferred().rejectWith( this ).promise(); |
|
444 |
} |
|
0 | 445 |
|
5 | 446 |
return wp.media.post( 'save-attachment-compat', _.defaults({ |
447 |
id: this.id, |
|
448 |
nonce: this.get('nonces').update, |
|
449 |
post_id: wp.media.model.settings.post.id |
|
450 |
}, data ) ).done( function( resp, status, xhr ) { |
|
451 |
model.set( model.parse( resp, xhr ), options ); |
|
452 |
}); |
|
453 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
},/** @lends wp.media.model.Attachment */{ |
5 | 455 |
/** |
456 |
* Create a new model on the static 'all' attachments collection and return it. |
|
457 |
* |
|
458 |
* @static |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* |
5 | 460 |
* @param {Object} attrs |
461 |
* @returns {wp.media.model.Attachment} |
|
462 |
*/ |
|
463 |
create: function( attrs ) { |
|
464 |
var Attachments = wp.media.model.Attachments; |
|
465 |
return Attachments.all.push( attrs ); |
|
466 |
}, |
|
467 |
/** |
|
468 |
* Create a new model on the static 'all' attachments collection and return it. |
|
469 |
* |
|
470 |
* If this function has already been called for the id, |
|
471 |
* it returns the specified attachment. |
|
472 |
* |
|
473 |
* @static |
|
474 |
* @param {string} id A string used to identify a model. |
|
475 |
* @param {Backbone.Model|undefined} attachment |
|
476 |
* @returns {wp.media.model.Attachment} |
|
477 |
*/ |
|
478 |
get: _.memoize( function( id, attachment ) { |
|
479 |
var Attachments = wp.media.model.Attachments; |
|
480 |
return Attachments.all.push( attachment || { id: id } ); |
|
481 |
}) |
|
482 |
}); |
|
483 |
||
484 |
module.exports = Attachment; |
|
485 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
/***/ 22: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
/***/ (function(module, exports) { |
0 | 491 |
|
5 | 492 |
/** |
493 |
* wp.media.model.Attachments |
|
494 |
* |
|
495 |
* A collection of attachments. |
|
496 |
* |
|
497 |
* This collection has no persistence with the server without supplying |
|
498 |
* 'options.props.query = true', which will mirror the collection |
|
499 |
* to an Attachments Query collection - @see wp.media.model.Attachments.mirror(). |
|
500 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* |
5 | 503 |
* @class |
504 |
* @augments Backbone.Collection |
|
505 |
* |
|
506 |
* @param {array} [models] Models to initialize with the collection. |
|
507 |
* @param {object} [options] Options hash for the collection. |
|
508 |
* @param {string} [options.props] Options hash for the initial query properties. |
|
509 |
* @param {string} [options.props.order] Initial order (ASC or DESC) for the collection. |
|
510 |
* @param {string} [options.props.orderby] Initial attribute key to order the collection by. |
|
511 |
* @param {string} [options.props.query] Whether the collection is linked to an attachments query. |
|
512 |
* @param {string} [options.observe] |
|
513 |
* @param {string} [options.filters] |
|
514 |
* |
|
515 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachments.prototype */{ |
5 | 517 |
/** |
518 |
* @type {wp.media.model.Attachment} |
|
519 |
*/ |
|
520 |
model: wp.media.model.Attachment, |
|
521 |
/** |
|
522 |
* @param {Array} [models=[]] Array of models used to populate the collection. |
|
523 |
* @param {Object} [options={}] |
|
524 |
*/ |
|
525 |
initialize: function( models, options ) { |
|
526 |
options = options || {}; |
|
527 |
||
528 |
this.props = new Backbone.Model(); |
|
529 |
this.filters = options.filters || {}; |
|
530 |
||
531 |
// Bind default `change` events to the `props` model. |
|
532 |
this.props.on( 'change', this._changeFilteredProps, this ); |
|
533 |
||
534 |
this.props.on( 'change:order', this._changeOrder, this ); |
|
535 |
this.props.on( 'change:orderby', this._changeOrderby, this ); |
|
536 |
this.props.on( 'change:query', this._changeQuery, this ); |
|
537 |
||
538 |
this.props.set( _.defaults( options.props || {} ) ); |
|
0 | 539 |
|
5 | 540 |
if ( options.observe ) { |
541 |
this.observe( options.observe ); |
|
542 |
} |
|
543 |
}, |
|
544 |
/** |
|
545 |
* Sort the collection when the order attribute changes. |
|
546 |
* |
|
547 |
* @access private |
|
548 |
*/ |
|
549 |
_changeOrder: function() { |
|
550 |
if ( this.comparator ) { |
|
551 |
this.sort(); |
|
552 |
} |
|
553 |
}, |
|
554 |
/** |
|
555 |
* Set the default comparator only when the `orderby` property is set. |
|
556 |
* |
|
557 |
* @access private |
|
558 |
* |
|
559 |
* @param {Backbone.Model} model |
|
560 |
* @param {string} orderby |
|
561 |
*/ |
|
562 |
_changeOrderby: function( model, orderby ) { |
|
563 |
// If a different comparator is defined, bail. |
|
564 |
if ( this.comparator && this.comparator !== Attachments.comparator ) { |
|
565 |
return; |
|
566 |
} |
|
0 | 567 |
|
5 | 568 |
if ( orderby && 'post__in' !== orderby ) { |
569 |
this.comparator = Attachments.comparator; |
|
570 |
} else { |
|
571 |
delete this.comparator; |
|
572 |
} |
|
573 |
}, |
|
574 |
/** |
|
575 |
* If the `query` property is set to true, query the server using |
|
576 |
* the `props` values, and sync the results to this collection. |
|
577 |
* |
|
578 |
* @access private |
|
579 |
* |
|
580 |
* @param {Backbone.Model} model |
|
581 |
* @param {Boolean} query |
|
582 |
*/ |
|
583 |
_changeQuery: function( model, query ) { |
|
584 |
if ( query ) { |
|
585 |
this.props.on( 'change', this._requery, this ); |
|
586 |
this._requery(); |
|
587 |
} else { |
|
588 |
this.props.off( 'change', this._requery, this ); |
|
589 |
} |
|
590 |
}, |
|
591 |
/** |
|
592 |
* @access private |
|
593 |
* |
|
594 |
* @param {Backbone.Model} model |
|
595 |
*/ |
|
596 |
_changeFilteredProps: function( model ) { |
|
597 |
// If this is a query, updating the collection will be handled by |
|
598 |
// `this._requery()`. |
|
599 |
if ( this.props.get('query') ) { |
|
600 |
return; |
|
601 |
} |
|
602 |
||
603 |
var changed = _.chain( model.changed ).map( function( t, prop ) { |
|
604 |
var filter = Attachments.filters[ prop ], |
|
605 |
term = model.get( prop ); |
|
606 |
||
607 |
if ( ! filter ) { |
|
608 |
return; |
|
609 |
} |
|
610 |
||
611 |
if ( term && ! this.filters[ prop ] ) { |
|
612 |
this.filters[ prop ] = filter; |
|
613 |
} else if ( ! term && this.filters[ prop ] === filter ) { |
|
614 |
delete this.filters[ prop ]; |
|
0 | 615 |
} else { |
5 | 616 |
return; |
0 | 617 |
} |
618 |
||
5 | 619 |
// Record the change. |
620 |
return true; |
|
621 |
}, this ).any().value(); |
|
622 |
||
623 |
if ( ! changed ) { |
|
624 |
return; |
|
625 |
} |
|
0 | 626 |
|
5 | 627 |
// If no `Attachments` model is provided to source the searches |
628 |
// from, then automatically generate a source from the existing |
|
629 |
// models. |
|
630 |
if ( ! this._source ) { |
|
631 |
this._source = new Attachments( this.models ); |
|
632 |
} |
|
0 | 633 |
|
5 | 634 |
this.reset( this._source.filter( this.validator, this ) ); |
635 |
}, |
|
0 | 636 |
|
5 | 637 |
validateDestroyed: false, |
638 |
/** |
|
639 |
* Checks whether an attachment is valid. |
|
640 |
* |
|
641 |
* @param {wp.media.model.Attachment} attachment |
|
642 |
* @returns {Boolean} |
|
643 |
*/ |
|
644 |
validator: function( attachment ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
// Filter out contextually created attachments (e.g. headers, logos, etc.). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
if ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
! _.isUndefined( attachment.attributes.context ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
'' !== attachment.attributes.context |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
|
5 | 654 |
if ( ! this.validateDestroyed && attachment.destroyed ) { |
655 |
return false; |
|
656 |
} |
|
657 |
return _.all( this.filters, function( filter ) { |
|
658 |
return !! filter.call( this, attachment ); |
|
659 |
}, this ); |
|
660 |
}, |
|
661 |
/** |
|
662 |
* Add or remove an attachment to the collection depending on its validity. |
|
663 |
* |
|
664 |
* @param {wp.media.model.Attachment} attachment |
|
665 |
* @param {Object} options |
|
666 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
667 |
*/ |
|
668 |
validate: function( attachment, options ) { |
|
669 |
var valid = this.validator( attachment ), |
|
670 |
hasAttachment = !! this.get( attachment.cid ); |
|
0 | 671 |
|
5 | 672 |
if ( ! valid && hasAttachment ) { |
673 |
this.remove( attachment, options ); |
|
674 |
} else if ( valid && ! hasAttachment ) { |
|
675 |
this.add( attachment, options ); |
|
676 |
} |
|
0 | 677 |
|
5 | 678 |
return this; |
679 |
}, |
|
0 | 680 |
|
5 | 681 |
/** |
682 |
* Add or remove all attachments from another collection depending on each one's validity. |
|
683 |
* |
|
684 |
* @param {wp.media.model.Attachments} attachments |
|
685 |
* @param {object} [options={}] |
|
686 |
* |
|
687 |
* @fires wp.media.model.Attachments#reset |
|
688 |
* |
|
689 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
690 |
*/ |
|
691 |
validateAll: function( attachments, options ) { |
|
692 |
options = options || {}; |
|
0 | 693 |
|
5 | 694 |
_.each( attachments.models, function( attachment ) { |
695 |
this.validate( attachment, { silent: true }); |
|
696 |
}, this ); |
|
0 | 697 |
|
5 | 698 |
if ( ! options.silent ) { |
699 |
this.trigger( 'reset', this, options ); |
|
700 |
} |
|
701 |
return this; |
|
702 |
}, |
|
703 |
/** |
|
704 |
* Start observing another attachments collection change events |
|
705 |
* and replicate them on this collection. |
|
706 |
* |
|
707 |
* @param {wp.media.model.Attachments} The attachments collection to observe. |
|
708 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining. |
|
709 |
*/ |
|
710 |
observe: function( attachments ) { |
|
711 |
this.observers = this.observers || []; |
|
712 |
this.observers.push( attachments ); |
|
0 | 713 |
|
5 | 714 |
attachments.on( 'add change remove', this._validateHandler, this ); |
715 |
attachments.on( 'reset', this._validateAllHandler, this ); |
|
716 |
this.validateAll( attachments ); |
|
717 |
return this; |
|
718 |
}, |
|
719 |
/** |
|
720 |
* Stop replicating collection change events from another attachments collection. |
|
721 |
* |
|
722 |
* @param {wp.media.model.Attachments} The attachments collection to stop observing. |
|
723 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
724 |
*/ |
|
725 |
unobserve: function( attachments ) { |
|
726 |
if ( attachments ) { |
|
727 |
attachments.off( null, null, this ); |
|
728 |
this.observers = _.without( this.observers, attachments ); |
|
0 | 729 |
|
5 | 730 |
} else { |
731 |
_.each( this.observers, function( attachments ) { |
|
732 |
attachments.off( null, null, this ); |
|
733 |
}, this ); |
|
734 |
delete this.observers; |
|
735 |
} |
|
0 | 736 |
|
5 | 737 |
return this; |
738 |
}, |
|
739 |
/** |
|
740 |
* @access private |
|
741 |
* |
|
742 |
* @param {wp.media.model.Attachments} attachment |
|
743 |
* @param {wp.media.model.Attachments} attachments |
|
744 |
* @param {Object} options |
|
745 |
* |
|
746 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
747 |
*/ |
|
748 |
_validateHandler: function( attachment, attachments, options ) { |
|
749 |
// If we're not mirroring this `attachments` collection, |
|
750 |
// only retain the `silent` option. |
|
751 |
options = attachments === this.mirroring ? options : { |
|
752 |
silent: options && options.silent |
|
753 |
}; |
|
0 | 754 |
|
5 | 755 |
return this.validate( attachment, options ); |
756 |
}, |
|
757 |
/** |
|
758 |
* @access private |
|
759 |
* |
|
760 |
* @param {wp.media.model.Attachments} attachments |
|
761 |
* @param {Object} options |
|
762 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
763 |
*/ |
|
764 |
_validateAllHandler: function( attachments, options ) { |
|
765 |
return this.validateAll( attachments, options ); |
|
766 |
}, |
|
767 |
/** |
|
768 |
* Start mirroring another attachments collection, clearing out any models already |
|
769 |
* in the collection. |
|
770 |
* |
|
771 |
* @param {wp.media.model.Attachments} The attachments collection to mirror. |
|
772 |
* @returns {wp.media.model.Attachments} Returns itself to allow chaining |
|
773 |
*/ |
|
774 |
mirror: function( attachments ) { |
|
775 |
if ( this.mirroring && this.mirroring === attachments ) { |
|
776 |
return this; |
|
777 |
} |
|
0 | 778 |
|
5 | 779 |
this.unmirror(); |
780 |
this.mirroring = attachments; |
|
781 |
||
782 |
// Clear the collection silently. A `reset` event will be fired |
|
783 |
// when `observe()` calls `validateAll()`. |
|
784 |
this.reset( [], { silent: true } ); |
|
785 |
this.observe( attachments ); |
|
0 | 786 |
|
5 | 787 |
return this; |
788 |
}, |
|
789 |
/** |
|
790 |
* Stop mirroring another attachments collection. |
|
791 |
*/ |
|
792 |
unmirror: function() { |
|
793 |
if ( ! this.mirroring ) { |
|
794 |
return; |
|
795 |
} |
|
0 | 796 |
|
5 | 797 |
this.unobserve( this.mirroring ); |
798 |
delete this.mirroring; |
|
799 |
}, |
|
800 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
* Retrieve more attachments from the server for the collection. |
5 | 802 |
* |
803 |
* Only works if the collection is mirroring a Query Attachments collection, |
|
804 |
* and forwards to its `more` method. This collection class doesn't have |
|
805 |
* server persistence by itself. |
|
806 |
* |
|
807 |
* @param {object} options |
|
808 |
* @returns {Promise} |
|
809 |
*/ |
|
810 |
more: function( options ) { |
|
811 |
var deferred = jQuery.Deferred(), |
|
812 |
mirroring = this.mirroring, |
|
813 |
attachments = this; |
|
0 | 814 |
|
5 | 815 |
if ( ! mirroring || ! mirroring.more ) { |
816 |
return deferred.resolveWith( this ).promise(); |
|
817 |
} |
|
818 |
// If we're mirroring another collection, forward `more` to |
|
819 |
// the mirrored collection. Account for a race condition by |
|
820 |
// checking if we're still mirroring that collection when |
|
821 |
// the request resolves. |
|
822 |
mirroring.more( options ).done( function() { |
|
823 |
if ( this === attachments.mirroring ) { |
|
824 |
deferred.resolveWith( this ); |
|
825 |
} |
|
826 |
}); |
|
0 | 827 |
|
5 | 828 |
return deferred.promise(); |
829 |
}, |
|
830 |
/** |
|
831 |
* Whether there are more attachments that haven't been sync'd from the server |
|
832 |
* that match the collection's query. |
|
833 |
* |
|
834 |
* Only works if the collection is mirroring a Query Attachments collection, |
|
835 |
* and forwards to its `hasMore` method. This collection class doesn't have |
|
836 |
* server persistence by itself. |
|
837 |
* |
|
838 |
* @returns {boolean} |
|
839 |
*/ |
|
840 |
hasMore: function() { |
|
841 |
return this.mirroring ? this.mirroring.hasMore() : false; |
|
842 |
}, |
|
843 |
/** |
|
844 |
* A custom AJAX-response parser. |
|
845 |
* |
|
846 |
* See trac ticket #24753 |
|
847 |
* |
|
848 |
* @param {Object|Array} resp The raw response Object/Array. |
|
849 |
* @param {Object} xhr |
|
850 |
* @returns {Array} The array of model attributes to be added to the collection |
|
851 |
*/ |
|
852 |
parse: function( resp, xhr ) { |
|
853 |
if ( ! _.isArray( resp ) ) { |
|
854 |
resp = [resp]; |
|
0 | 855 |
} |
5 | 856 |
|
857 |
return _.map( resp, function( attrs ) { |
|
858 |
var id, attachment, newAttributes; |
|
0 | 859 |
|
5 | 860 |
if ( attrs instanceof Backbone.Model ) { |
861 |
id = attrs.get( 'id' ); |
|
862 |
attrs = attrs.attributes; |
|
863 |
} else { |
|
864 |
id = attrs.id; |
|
865 |
} |
|
0 | 866 |
|
5 | 867 |
attachment = wp.media.model.Attachment.get( id ); |
868 |
newAttributes = attachment.parse( attrs, xhr ); |
|
869 |
||
870 |
if ( ! _.isEqual( attachment.attributes, newAttributes ) ) { |
|
871 |
attachment.set( newAttributes ); |
|
0 | 872 |
} |
873 |
||
5 | 874 |
return attachment; |
875 |
}); |
|
876 |
}, |
|
877 |
/** |
|
878 |
* If the collection is a query, create and mirror an Attachments Query collection. |
|
879 |
* |
|
880 |
* @access private |
|
881 |
*/ |
|
882 |
_requery: function( refresh ) { |
|
883 |
var props; |
|
884 |
if ( this.props.get('query') ) { |
|
885 |
props = this.props.toJSON(); |
|
886 |
props.cache = ( true !== refresh ); |
|
887 |
this.mirror( wp.media.model.Query.get( props ) ); |
|
888 |
} |
|
889 |
}, |
|
890 |
/** |
|
891 |
* If this collection is sorted by `menuOrder`, recalculates and saves |
|
892 |
* the menu order to the database. |
|
893 |
* |
|
894 |
* @returns {undefined|Promise} |
|
895 |
*/ |
|
896 |
saveMenuOrder: function() { |
|
897 |
if ( 'menuOrder' !== this.props.get('orderby') ) { |
|
898 |
return; |
|
899 |
} |
|
0 | 900 |
|
5 | 901 |
// Removes any uploading attachments, updates each attachment's |
902 |
// menu order, and returns an object with an { id: menuOrder } |
|
903 |
// mapping to pass to the request. |
|
904 |
var attachments = this.chain().filter( function( attachment ) { |
|
905 |
return ! _.isUndefined( attachment.id ); |
|
906 |
}).map( function( attachment, index ) { |
|
907 |
// Indices start at 1. |
|
908 |
index = index + 1; |
|
909 |
attachment.set( 'menuOrder', index ); |
|
910 |
return [ attachment.id, index ]; |
|
911 |
}).object().value(); |
|
912 |
||
913 |
if ( _.isEmpty( attachments ) ) { |
|
914 |
return; |
|
915 |
} |
|
0 | 916 |
|
5 | 917 |
return wp.media.post( 'save-attachment-order', { |
918 |
nonce: wp.media.model.settings.post.nonce, |
|
919 |
post_id: wp.media.model.settings.post.id, |
|
920 |
attachments: attachments |
|
921 |
}); |
|
922 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
},/** @lends wp.media.model.Attachments */{ |
5 | 924 |
/** |
925 |
* A function to compare two attachment models in an attachments collection. |
|
926 |
* |
|
927 |
* Used as the default comparator for instances of wp.media.model.Attachments |
|
928 |
* and its subclasses. @see wp.media.model.Attachments._changeOrderby(). |
|
929 |
* |
|
930 |
* @param {Backbone.Model} a |
|
931 |
* @param {Backbone.Model} b |
|
932 |
* @param {Object} options |
|
933 |
* @returns {Number} -1 if the first model should come before the second, |
|
934 |
* 0 if they are of the same rank and |
|
935 |
* 1 if the first model should come after. |
|
936 |
*/ |
|
937 |
comparator: function( a, b, options ) { |
|
938 |
var key = this.props.get('orderby'), |
|
939 |
order = this.props.get('order') || 'DESC', |
|
940 |
ac = a.cid, |
|
941 |
bc = b.cid; |
|
942 |
||
943 |
a = a.get( key ); |
|
944 |
b = b.get( key ); |
|
945 |
||
946 |
if ( 'date' === key || 'modified' === key ) { |
|
947 |
a = a || new Date(); |
|
948 |
b = b || new Date(); |
|
949 |
} |
|
950 |
||
951 |
// If `options.ties` is set, don't enforce the `cid` tiebreaker. |
|
952 |
if ( options && options.ties ) { |
|
953 |
ac = bc = null; |
|
954 |
} |
|
955 |
||
956 |
return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac ); |
|
957 |
}, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
/** @namespace wp.media.model.Attachments.filters */ |
5 | 959 |
filters: { |
960 |
/** |
|
961 |
* @static |
|
962 |
* Note that this client-side searching is *not* equivalent |
|
963 |
* to our server-side searching. |
|
964 |
* |
|
965 |
* @param {wp.media.model.Attachment} attachment |
|
966 |
* |
|
967 |
* @this wp.media.model.Attachments |
|
968 |
* |
|
969 |
* @returns {Boolean} |
|
970 |
*/ |
|
971 |
search: function( attachment ) { |
|
972 |
if ( ! this.props.get('search') ) { |
|
973 |
return true; |
|
974 |
} |
|
0 | 975 |
|
5 | 976 |
return _.any(['title','filename','description','caption','name'], function( key ) { |
977 |
var value = attachment.get( key ); |
|
978 |
return value && -1 !== value.search( this.props.get('search') ); |
|
979 |
}, this ); |
|
980 |
}, |
|
981 |
/** |
|
982 |
* @static |
|
983 |
* @param {wp.media.model.Attachment} attachment |
|
984 |
* |
|
985 |
* @this wp.media.model.Attachments |
|
986 |
* |
|
987 |
* @returns {Boolean} |
|
988 |
*/ |
|
989 |
type: function( attachment ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
var type = this.props.get('type'), atts = attachment.toJSON(), mime, found; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
if ( ! type || ( _.isArray( type ) && ! type.length ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
mime = atts.mime || ( atts.file && atts.file.type ) || ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
if ( _.isArray( type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
found = _.find( type, function (t) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
return -1 !== mime.indexOf( t ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
found = -1 !== mime.indexOf( type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
return found; |
5 | 1007 |
}, |
1008 |
/** |
|
1009 |
* @static |
|
1010 |
* @param {wp.media.model.Attachment} attachment |
|
1011 |
* |
|
1012 |
* @this wp.media.model.Attachments |
|
1013 |
* |
|
1014 |
* @returns {Boolean} |
|
1015 |
*/ |
|
1016 |
uploadedTo: function( attachment ) { |
|
1017 |
var uploadedTo = this.props.get('uploadedTo'); |
|
1018 |
if ( _.isUndefined( uploadedTo ) ) { |
|
1019 |
return true; |
|
1020 |
} |
|
1021 |
||
1022 |
return uploadedTo === attachment.get('uploadedTo'); |
|
1023 |
}, |
|
1024 |
/** |
|
1025 |
* @static |
|
1026 |
* @param {wp.media.model.Attachment} attachment |
|
1027 |
* |
|
1028 |
* @this wp.media.model.Attachments |
|
1029 |
* |
|
1030 |
* @returns {Boolean} |
|
1031 |
*/ |
|
1032 |
status: function( attachment ) { |
|
1033 |
var status = this.props.get('status'); |
|
1034 |
if ( _.isUndefined( status ) ) { |
|
1035 |
return true; |
|
1036 |
} |
|
1037 |
||
1038 |
return status === attachment.get('status'); |
|
1039 |
} |
|
1040 |
} |
|
1041 |
}); |
|
1042 |
||
1043 |
module.exports = Attachments; |
|
1044 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
/***/ 23: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
/***/ (function(module, exports) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
var Attachments = wp.media.model.Attachments, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
Query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
* wp.media.model.Query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
* A collection of attachments that match the supplied query arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
* Note: Do NOT change this.args after the query has been initialized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
* Things will break. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* @class |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
* @augments wp.media.model.Attachments |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* @augments Backbone.Collection |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @param {array} [models] Models to initialize with the collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @param {object} [options] Options hash. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
* @param {object} [options.args] Attachments query arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
* @param {object} [options.args.posts_per_page] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* @param {array} [models=[]] Array of initial models to populate the collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
* @param {object} [options={}] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
initialize: function( models, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
var allowed; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
Attachments.prototype.initialize.apply( this, arguments ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
this.args = options.args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
this._hasMore = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
this.created = new Date(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
this.filters.order = function( attachment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
var orderby = this.props.get('orderby'), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
order = this.props.get('order'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
if ( ! this.comparator ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
// We want any items that can be placed before the last |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
// item in the set. If we add any items after the last |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
// item, then we can't guarantee the set is complete. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
if ( this.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
return 1 !== this.comparator( attachment, this.last(), { ties: true }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
// Handle the case where there are no items yet and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
// we're sorting for recent items. In that case, we want |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
// changes that occurred after we created the query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
} else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
return attachment.get( orderby ) >= this.created; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
// If we're sorting by menu order and we have no items, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
// accept any items that have the default menu order (0). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
} else if ( 'ASC' === order && 'menuOrder' === orderby ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
return attachment.get( orderby ) === 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
// Otherwise, we don't want any items yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
// Observe the central `wp.Uploader.queue` collection to watch for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
// new matches for the query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
// |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
// Only observe when a limited number of query args are set. There |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
// are no filters for other properties, so observing will result in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
// false positives in those queries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
this.observe( wp.Uploader.queue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* Whether there are more attachments that haven't been sync'd from the server |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
* that match the collection's query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* @returns {boolean} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
hasMore: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
return this._hasMore; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* Fetch more attachments from the server for the collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* @param {object} [options={}] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @returns {Promise} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
more: function( options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
var query = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
// If there is already a request pending, return early with the Deferred object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
if ( this._more && 'pending' === this._more.state() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
return this._more; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
if ( ! this.hasMore() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
return jQuery.Deferred().resolveWith( this ).promise(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
options.remove = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
return this._more = this.fetch( options ).done( function( resp ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
query._hasMore = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
* Overrides Backbone.Collection.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
* Overrides wp.media.model.Attachments.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
* @param {String} method |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
* @param {Backbone.Model} model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* @param {Object} [options={}] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @returns {Promise} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
sync: function( method, model, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
var args, fallback; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
// Overload the read method so Attachment.fetch() functions correctly. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
if ( 'read' === method ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
options.context = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
options.data = _.extend( options.data || {}, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
action: 'query-attachments', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
post_id: wp.media.model.settings.post.id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
// Clone the args so manipulation is non-destructive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
args = _.clone( this.args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
// Determine which page to query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
if ( -1 !== args.posts_per_page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
args.paged = Math.round( this.length / args.posts_per_page ) + 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
options.data.query = args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
return wp.media.ajax( options ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
// Otherwise, fall back to Backbone.sync() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
* Call wp.media.model.Attachments.sync or Backbone.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
return fallback.sync.apply( this, arguments ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
}, /** @lends wp.media.model.Query */{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
defaultProps: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
orderby: 'date', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
order: 'DESC' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
defaultArgs: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
posts_per_page: 40 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
orderby: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* A map of JavaScript orderby values to their WP_Query equivalents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @type {Object} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
valuemap: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
'id': 'ID', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
'uploadedTo': 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
'menuOrder': 'menu_order ID' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* A map of JavaScript query properties to their WP_Query equivalents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
propmap: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
'search': 's', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
'type': 'post_mime_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
'perPage': 'posts_per_page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
'menuOrder': 'menu_order', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
'uploadedTo': 'post_parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
'status': 'post_status', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
'include': 'post__in', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
'exclude': 'post__not_in', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
'author': 'author' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* Creates and returns an Attachments Query collection given the properties. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* Caches query objects and reuses where possible. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
* @method |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* @param {object} [props] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* @param {Object} [props.cache=true] Whether to use the query cache or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
* @param {Object} [props.order] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
* @param {Object} [props.orderby] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
* @param {Object} [props.include] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
* @param {Object} [props.exclude] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
* @param {Object} [props.s] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
* @param {Object} [props.post_mime_type] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
* @param {Object} [props.posts_per_page] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
* @param {Object} [props.menu_order] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
* @param {Object} [props.post_parent] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
* @param {Object} [props.post_status] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
* @param {Object} [props.author] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* @param {Object} [options] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
* @returns {wp.media.model.Query} A new Attachments Query collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
get: (function(){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* @type Array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
var queries = []; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* @returns {Query} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
return function( props, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
var args = {}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
orderby = Query.orderby, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
defaults = Query.defaultProps, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
query, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
cache = !! props.cache || _.isUndefined( props.cache ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
// Remove the `query` property. This isn't linked to a query, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
// this *is* the query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
delete props.query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
delete props.cache; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
// Fill default args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
_.defaults( props, defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
// Normalize the order. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
props.order = props.order.toUpperCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
if ( 'DESC' !== props.order && 'ASC' !== props.order ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
props.order = defaults.order.toUpperCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
// Ensure we have a valid orderby value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
if ( ! _.contains( orderby.allowed, props.orderby ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
props.orderby = defaults.orderby; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
_.each( [ 'include', 'exclude' ], function( prop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
props[ prop ] = [ props[ prop ] ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
// Generate the query `args` object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
// Correct any differing property names. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
_.each( props, function( value, prop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
if ( _.isNull( value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
args[ Query.propmap[ prop ] || prop ] = value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
// Fill any other default query args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
_.defaults( args, Query.defaultArgs ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
// `props.orderby` does not always map directly to `args.orderby`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
// Substitute exceptions specified in orderby.keymap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
// Search the query cache for a matching query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
if ( cache ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
query = _.find( queries, function( query ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
return _.isEqual( query.args, args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
queries = []; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
// Otherwise, create a new query and add it to the cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
if ( ! query ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
query = new Query( [], _.extend( options || {}, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
props: props, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
args: args |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
} ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
queries.push( query ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
return query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
}()) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
module.exports = Query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
/***/ 24: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
/***/ (function(module, exports) { |
0 | 1365 |
|
5 | 1366 |
/** |
1367 |
* wp.media.model.PostImage |
|
1368 |
* |
|
1369 |
* An instance of an image that's been embedded into a post. |
|
1370 |
* |
|
1371 |
* Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. |
|
1372 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
* |
5 | 1375 |
* @class |
1376 |
* @augments Backbone.Model |
|
1377 |
* |
|
1378 |
* @param {int} [attributes] Initial model attributes. |
|
1379 |
* @param {int} [attributes.attachment_id] ID of the attachment. |
|
1380 |
**/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
var PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{ |
5 | 1382 |
|
1383 |
initialize: function( attributes ) { |
|
1384 |
var Attachment = wp.media.model.Attachment; |
|
1385 |
this.attachment = false; |
|
1386 |
||
1387 |
if ( attributes.attachment_id ) { |
|
1388 |
this.attachment = Attachment.get( attributes.attachment_id ); |
|
1389 |
if ( this.attachment.get( 'url' ) ) { |
|
1390 |
this.dfd = jQuery.Deferred(); |
|
1391 |
this.dfd.resolve(); |
|
1392 |
} else { |
|
1393 |
this.dfd = this.attachment.fetch(); |
|
1394 |
} |
|
1395 |
this.bindAttachmentListeners(); |
|
1396 |
} |
|
1397 |
||
1398 |
// keep url in sync with changes to the type of link |
|
1399 |
this.on( 'change:link', this.updateLinkUrl, this ); |
|
1400 |
this.on( 'change:size', this.updateSize, this ); |
|
1401 |
||
1402 |
this.setLinkTypeFromUrl(); |
|
1403 |
this.setAspectRatio(); |
|
1404 |
||
1405 |
this.set( 'originalUrl', attributes.url ); |
|
1406 |
}, |
|
0 | 1407 |
|
5 | 1408 |
bindAttachmentListeners: function() { |
1409 |
this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl ); |
|
1410 |
this.listenTo( this.attachment, 'sync', this.setAspectRatio ); |
|
1411 |
this.listenTo( this.attachment, 'change', this.updateSize ); |
|
1412 |
}, |
|
1413 |
||
1414 |
changeAttachment: function( attachment, props ) { |
|
1415 |
this.stopListening( this.attachment ); |
|
1416 |
this.attachment = attachment; |
|
1417 |
this.bindAttachmentListeners(); |
|
1418 |
||
1419 |
this.set( 'attachment_id', this.attachment.get( 'id' ) ); |
|
1420 |
this.set( 'caption', this.attachment.get( 'caption' ) ); |
|
1421 |
this.set( 'alt', this.attachment.get( 'alt' ) ); |
|
1422 |
this.set( 'size', props.get( 'size' ) ); |
|
1423 |
this.set( 'align', props.get( 'align' ) ); |
|
1424 |
this.set( 'link', props.get( 'link' ) ); |
|
1425 |
this.updateLinkUrl(); |
|
1426 |
this.updateSize(); |
|
1427 |
}, |
|
0 | 1428 |
|
5 | 1429 |
setLinkTypeFromUrl: function() { |
1430 |
var linkUrl = this.get( 'linkUrl' ), |
|
1431 |
type; |
|
1432 |
||
1433 |
if ( ! linkUrl ) { |
|
1434 |
this.set( 'link', 'none' ); |
|
1435 |
return; |
|
1436 |
} |
|
1437 |
||
1438 |
// default to custom if there is a linkUrl |
|
1439 |
type = 'custom'; |
|
1440 |
||
1441 |
if ( this.attachment ) { |
|
1442 |
if ( this.attachment.get( 'url' ) === linkUrl ) { |
|
1443 |
type = 'file'; |
|
1444 |
} else if ( this.attachment.get( 'link' ) === linkUrl ) { |
|
1445 |
type = 'post'; |
|
1446 |
} |
|
1447 |
} else { |
|
1448 |
if ( this.get( 'url' ) === linkUrl ) { |
|
1449 |
type = 'file'; |
|
0 | 1450 |
} |
1451 |
} |
|
5 | 1452 |
|
1453 |
this.set( 'link', type ); |
|
1454 |
}, |
|
1455 |
||
1456 |
updateLinkUrl: function() { |
|
1457 |
var link = this.get( 'link' ), |
|
1458 |
url; |
|
0 | 1459 |
|
5 | 1460 |
switch( link ) { |
1461 |
case 'file': |
|
1462 |
if ( this.attachment ) { |
|
1463 |
url = this.attachment.get( 'url' ); |
|
1464 |
} else { |
|
1465 |
url = this.get( 'url' ); |
|
1466 |
} |
|
1467 |
this.set( 'linkUrl', url ); |
|
1468 |
break; |
|
1469 |
case 'post': |
|
1470 |
this.set( 'linkUrl', this.attachment.get( 'link' ) ); |
|
1471 |
break; |
|
1472 |
case 'none': |
|
1473 |
this.set( 'linkUrl', '' ); |
|
1474 |
break; |
|
1475 |
} |
|
1476 |
}, |
|
1477 |
||
1478 |
updateSize: function() { |
|
1479 |
var size; |
|
1480 |
||
1481 |
if ( ! this.attachment ) { |
|
1482 |
return; |
|
1483 |
} |
|
1484 |
||
1485 |
if ( this.get( 'size' ) === 'custom' ) { |
|
1486 |
this.set( 'width', this.get( 'customWidth' ) ); |
|
1487 |
this.set( 'height', this.get( 'customHeight' ) ); |
|
1488 |
this.set( 'url', this.get( 'originalUrl' ) ); |
|
1489 |
return; |
|
1490 |
} |
|
1491 |
||
1492 |
size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ]; |
|
1493 |
||
1494 |
if ( ! size ) { |
|
1495 |
return; |
|
1496 |
} |
|
0 | 1497 |
|
5 | 1498 |
this.set( 'url', size.url ); |
1499 |
this.set( 'width', size.width ); |
|
1500 |
this.set( 'height', size.height ); |
|
1501 |
}, |
|
1502 |
||
1503 |
setAspectRatio: function() { |
|
1504 |
var full; |
|
1505 |
||
1506 |
if ( this.attachment && this.attachment.get( 'sizes' ) ) { |
|
1507 |
full = this.attachment.get( 'sizes' ).full; |
|
1508 |
||
1509 |
if ( full ) { |
|
1510 |
this.set( 'aspectRatio', full.width / full.height ); |
|
1511 |
return; |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) ); |
|
1516 |
} |
|
1517 |
}); |
|
1518 |
||
1519 |
module.exports = PostImage; |
|
1520 |
||
1521 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
/***/ }), |
0 | 1523 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
/***/ 25: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
/***/ (function(module, exports) { |
0 | 1526 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
var Attachments = wp.media.model.Attachments, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
Selection; |
0 | 1529 |
|
5 | 1530 |
/** |
1531 |
* wp.media.model.Selection |
|
1532 |
* |
|
1533 |
* A selection of attachments. |
|
1534 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
* |
5 | 1537 |
* @class |
1538 |
* @augments wp.media.model.Attachments |
|
1539 |
* @augments Backbone.Collection |
|
1540 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{ |
5 | 1542 |
/** |
1543 |
* Refresh the `single` model whenever the selection changes. |
|
1544 |
* Binds `single` instead of using the context argument to ensure |
|
1545 |
* it receives no parameters. |
|
1546 |
* |
|
1547 |
* @param {Array} [models=[]] Array of models used to populate the collection. |
|
1548 |
* @param {Object} [options={}] |
|
1549 |
*/ |
|
1550 |
initialize: function( models, options ) { |
|
1551 |
/** |
|
1552 |
* call 'initialize' directly on the parent class |
|
1553 |
*/ |
|
1554 |
Attachments.prototype.initialize.apply( this, arguments ); |
|
1555 |
this.multiple = options && options.multiple; |
|
1556 |
||
1557 |
this.on( 'add remove reset', _.bind( this.single, this, false ) ); |
|
1558 |
}, |
|
0 | 1559 |
|
1560 |
/** |
|
5 | 1561 |
* If the workflow does not support multi-select, clear out the selection |
1562 |
* before adding a new attachment to it. |
|
0 | 1563 |
* |
5 | 1564 |
* @param {Array} models |
1565 |
* @param {Object} options |
|
1566 |
* @returns {wp.media.model.Attachment[]} |
|
0 | 1567 |
*/ |
5 | 1568 |
add: function( models, options ) { |
1569 |
if ( ! this.multiple ) { |
|
1570 |
this.remove( this.models ); |
|
1571 |
} |
|
1572 |
/** |
|
1573 |
* call 'add' directly on the parent class |
|
1574 |
*/ |
|
1575 |
return Attachments.prototype.add.call( this, models, options ); |
|
1576 |
}, |
|
0 | 1577 |
|
5 | 1578 |
/** |
1579 |
* Fired when toggling (clicking on) an attachment in the modal. |
|
1580 |
* |
|
1581 |
* @param {undefined|boolean|wp.media.model.Attachment} model |
|
1582 |
* |
|
1583 |
* @fires wp.media.model.Selection#selection:single |
|
1584 |
* @fires wp.media.model.Selection#selection:unsingle |
|
1585 |
* |
|
1586 |
* @returns {Backbone.Model} |
|
1587 |
*/ |
|
1588 |
single: function( model ) { |
|
1589 |
var previous = this._single; |
|
0 | 1590 |
|
5 | 1591 |
// If a `model` is provided, use it as the single model. |
1592 |
if ( model ) { |
|
1593 |
this._single = model; |
|
1594 |
} |
|
1595 |
// If the single model isn't in the selection, remove it. |
|
1596 |
if ( this._single && ! this.get( this._single.cid ) ) { |
|
1597 |
delete this._single; |
|
1598 |
} |
|
0 | 1599 |
|
5 | 1600 |
this._single = this._single || this.last(); |
0 | 1601 |
|
5 | 1602 |
// If single has changed, fire an event. |
1603 |
if ( this._single !== previous ) { |
|
1604 |
if ( previous ) { |
|
1605 |
previous.trigger( 'selection:unsingle', previous, this ); |
|
1606 |
||
1607 |
// If the model was already removed, trigger the collection |
|
1608 |
// event manually. |
|
1609 |
if ( ! this.get( previous.cid ) ) { |
|
1610 |
this.trigger( 'selection:unsingle', previous, this ); |
|
0 | 1611 |
} |
1612 |
} |
|
5 | 1613 |
if ( this._single ) { |
1614 |
this._single.trigger( 'selection:single', this._single, this ); |
|
1615 |
} |
|
0 | 1616 |
} |
1617 |
||
5 | 1618 |
// Return the single model, or the last model as a fallback. |
1619 |
return this._single; |
|
1620 |
} |
|
1621 |
}); |
|
0 | 1622 |
|
5 | 1623 |
module.exports = Selection; |
1624 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1625 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
/***/ }) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
/******/ }); |