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