author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-includes/js/media-editor.js |
|
3 |
*/ |
|
4 |
||
5 | 5 |
/* global getUserSetting, tinymce, QTags */ |
6 |
||
0 | 7 |
// WordPress, TinyMCE, and Media |
8 |
// ----------------------------- |
|
5 | 9 |
(function($, _){ |
10 |
/** |
|
11 |
* Stores the editors' `wp.media.controller.Frame` instances. |
|
12 |
* |
|
13 |
* @static |
|
14 |
*/ |
|
0 | 15 |
var workflows = {}; |
16 |
||
5 | 17 |
/** |
18 |
* A helper mixin function to avoid truthy and falsey values being |
|
19 |
* passed as an input that expects booleans. If key is undefined in the map, |
|
20 |
* but has a default value, set it. |
|
21 |
* |
|
22 |
* @param {object} attrs Map of props from a shortcode or settings. |
|
23 |
* @param {string} key The key within the passed map to check for a value. |
|
24 |
* @returns {mixed|undefined} The original or coerced value of key within attrs |
|
25 |
*/ |
|
26 |
wp.media.coerce = function ( attrs, key ) { |
|
27 |
if ( _.isUndefined( attrs[ key ] ) && ! _.isUndefined( this.defaults[ key ] ) ) { |
|
28 |
attrs[ key ] = this.defaults[ key ]; |
|
29 |
} else if ( 'true' === attrs[ key ] ) { |
|
30 |
attrs[ key ] = true; |
|
31 |
} else if ( 'false' === attrs[ key ] ) { |
|
32 |
attrs[ key ] = false; |
|
33 |
} |
|
34 |
return attrs[ key ]; |
|
35 |
}; |
|
36 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
/** @namespace wp.media.string */ |
0 | 38 |
wp.media.string = { |
5 | 39 |
/** |
40 |
* Joins the `props` and `attachment` objects, |
|
41 |
* outputting the proper object format based on the |
|
42 |
* attachment's type. |
|
43 |
* |
|
44 |
* @param {Object} [props={}] Attachment details (align, link, size, etc). |
|
45 |
* @param {Object} attachment The attachment object, media version of Post. |
|
46 |
* @returns {Object} Joined props |
|
47 |
*/ |
|
0 | 48 |
props: function( props, attachment ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
var link, linkUrl, size, sizes, |
0 | 50 |
defaultProps = wp.media.view.settings.defaultProps; |
51 |
||
52 |
props = props ? _.clone( props ) : {}; |
|
53 |
||
5 | 54 |
if ( attachment && attachment.type ) { |
0 | 55 |
props.type = attachment.type; |
5 | 56 |
} |
0 | 57 |
|
58 |
if ( 'image' === props.type ) { |
|
59 |
props = _.defaults( props || {}, { |
|
60 |
align: defaultProps.align || getUserSetting( 'align', 'none' ), |
|
61 |
size: defaultProps.size || getUserSetting( 'imgsize', 'medium' ), |
|
62 |
url: '', |
|
63 |
classes: [] |
|
64 |
}); |
|
65 |
} |
|
66 |
||
67 |
// All attachment-specific settings follow. |
|
5 | 68 |
if ( ! attachment ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
return props; |
5 | 70 |
} |
0 | 71 |
|
72 |
props.title = props.title || attachment.title; |
|
73 |
||
74 |
link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' ); |
|
5 | 75 |
if ( 'file' === link || 'embed' === link ) { |
0 | 76 |
linkUrl = attachment.url; |
5 | 77 |
} else if ( 'post' === link ) { |
0 | 78 |
linkUrl = attachment.link; |
5 | 79 |
} else if ( 'custom' === link ) { |
0 | 80 |
linkUrl = props.linkUrl; |
5 | 81 |
} |
0 | 82 |
props.linkUrl = linkUrl || ''; |
83 |
||
84 |
// Format properties for images. |
|
85 |
if ( 'image' === attachment.type ) { |
|
86 |
props.classes.push( 'wp-image-' + attachment.id ); |
|
87 |
||
88 |
sizes = attachment.sizes; |
|
89 |
size = sizes && sizes[ props.size ] ? sizes[ props.size ] : attachment; |
|
90 |
||
91 |
_.extend( props, _.pick( attachment, 'align', 'caption', 'alt' ), { |
|
92 |
width: size.width, |
|
93 |
height: size.height, |
|
94 |
src: size.url, |
|
95 |
captionId: 'attachment_' + attachment.id |
|
96 |
}); |
|
97 |
} else if ( 'video' === attachment.type || 'audio' === attachment.type ) { |
|
98 |
_.extend( props, _.pick( attachment, 'title', 'type', 'icon', 'mime' ) ); |
|
99 |
// Format properties for non-images. |
|
100 |
} else { |
|
101 |
props.title = props.title || attachment.filename; |
|
102 |
props.rel = props.rel || 'attachment wp-att-' + attachment.id; |
|
103 |
} |
|
104 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
return props; |
0 | 106 |
}, |
5 | 107 |
/** |
108 |
* Create link markup that is suitable for passing to the editor |
|
109 |
* |
|
110 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
111 |
* @param {Object} attachment The attachment object, media version of Post. |
|
112 |
* @returns {string} The link markup |
|
113 |
*/ |
|
0 | 114 |
link: function( props, attachment ) { |
115 |
var options; |
|
116 |
||
117 |
props = wp.media.string.props( props, attachment ); |
|
118 |
||
119 |
options = { |
|
120 |
tag: 'a', |
|
121 |
content: props.title, |
|
122 |
attrs: { |
|
123 |
href: props.linkUrl |
|
124 |
} |
|
125 |
}; |
|
126 |
||
5 | 127 |
if ( props.rel ) { |
0 | 128 |
options.attrs.rel = props.rel; |
5 | 129 |
} |
0 | 130 |
|
131 |
return wp.html.string( options ); |
|
132 |
}, |
|
5 | 133 |
/** |
134 |
* Create an Audio shortcode string that is suitable for passing to the editor |
|
135 |
* |
|
136 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
137 |
* @param {Object} attachment The attachment object, media version of Post. |
|
138 |
* @returns {string} The audio shortcode |
|
139 |
*/ |
|
0 | 140 |
audio: function( props, attachment ) { |
141 |
return wp.media.string._audioVideo( 'audio', props, attachment ); |
|
142 |
}, |
|
5 | 143 |
/** |
144 |
* Create a Video shortcode string that is suitable for passing to the editor |
|
145 |
* |
|
146 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
147 |
* @param {Object} attachment The attachment object, media version of Post. |
|
148 |
* @returns {string} The video shortcode |
|
149 |
*/ |
|
0 | 150 |
video: function( props, attachment ) { |
151 |
return wp.media.string._audioVideo( 'video', props, attachment ); |
|
152 |
}, |
|
5 | 153 |
/** |
154 |
* Helper function to create a media shortcode string |
|
155 |
* |
|
156 |
* @access private |
|
157 |
* |
|
158 |
* @param {string} type The shortcode tag name: 'audio' or 'video'. |
|
159 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
160 |
* @param {Object} attachment The attachment object, media version of Post. |
|
161 |
* @returns {string} The media shortcode |
|
162 |
*/ |
|
0 | 163 |
_audioVideo: function( type, props, attachment ) { |
164 |
var shortcode, html, extension; |
|
165 |
||
166 |
props = wp.media.string.props( props, attachment ); |
|
167 |
if ( props.link !== 'embed' ) |
|
168 |
return wp.media.string.link( props ); |
|
169 |
||
170 |
shortcode = {}; |
|
171 |
||
172 |
if ( 'video' === type ) { |
|
5 | 173 |
if ( attachment.image && -1 === attachment.image.src.indexOf( attachment.icon ) ) { |
174 |
shortcode.poster = attachment.image.src; |
|
175 |
} |
|
0 | 176 |
|
5 | 177 |
if ( attachment.width ) { |
178 |
shortcode.width = attachment.width; |
|
179 |
} |
|
180 |
||
181 |
if ( attachment.height ) { |
|
0 | 182 |
shortcode.height = attachment.height; |
5 | 183 |
} |
0 | 184 |
} |
185 |
||
186 |
extension = attachment.filename.split('.').pop(); |
|
187 |
||
188 |
if ( _.contains( wp.media.view.settings.embedExts, extension ) ) { |
|
189 |
shortcode[extension] = attachment.url; |
|
190 |
} else { |
|
191 |
// Render unsupported audio and video files as links. |
|
192 |
return wp.media.string.link( props ); |
|
193 |
} |
|
194 |
||
195 |
html = wp.shortcode.string({ |
|
196 |
tag: type, |
|
197 |
attrs: shortcode |
|
198 |
}); |
|
199 |
||
200 |
return html; |
|
201 |
}, |
|
5 | 202 |
/** |
203 |
* Create image markup, optionally with a link and/or wrapped in a caption shortcode, |
|
204 |
* that is suitable for passing to the editor |
|
205 |
* |
|
206 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
207 |
* @param {Object} attachment The attachment object, media version of Post. |
|
208 |
* @returns {string} |
|
209 |
*/ |
|
0 | 210 |
image: function( props, attachment ) { |
211 |
var img = {}, |
|
212 |
options, classes, shortcode, html; |
|
213 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
props.type = 'image'; |
0 | 215 |
props = wp.media.string.props( props, attachment ); |
216 |
classes = props.classes || []; |
|
217 |
||
5 | 218 |
img.src = ! _.isUndefined( attachment ) ? attachment.url : props.url; |
0 | 219 |
_.extend( img, _.pick( props, 'width', 'height', 'alt' ) ); |
220 |
||
221 |
// Only assign the align class to the image if we're not printing |
|
222 |
// a caption, since the alignment is sent to the shortcode. |
|
5 | 223 |
if ( props.align && ! props.caption ) { |
0 | 224 |
classes.push( 'align' + props.align ); |
5 | 225 |
} |
0 | 226 |
|
5 | 227 |
if ( props.size ) { |
0 | 228 |
classes.push( 'size-' + props.size ); |
5 | 229 |
} |
0 | 230 |
|
231 |
img['class'] = _.compact( classes ).join(' '); |
|
232 |
||
233 |
// Generate `img` tag options. |
|
234 |
options = { |
|
235 |
tag: 'img', |
|
236 |
attrs: img, |
|
237 |
single: true |
|
238 |
}; |
|
239 |
||
240 |
// Generate the `a` element options, if they exist. |
|
241 |
if ( props.linkUrl ) { |
|
242 |
options = { |
|
243 |
tag: 'a', |
|
244 |
attrs: { |
|
245 |
href: props.linkUrl |
|
246 |
}, |
|
247 |
content: options |
|
248 |
}; |
|
249 |
} |
|
250 |
||
251 |
html = wp.html.string( options ); |
|
252 |
||
253 |
// Generate the caption shortcode. |
|
254 |
if ( props.caption ) { |
|
255 |
shortcode = {}; |
|
256 |
||
5 | 257 |
if ( img.width ) { |
0 | 258 |
shortcode.width = img.width; |
5 | 259 |
} |
0 | 260 |
|
5 | 261 |
if ( props.captionId ) { |
0 | 262 |
shortcode.id = props.captionId; |
5 | 263 |
} |
0 | 264 |
|
5 | 265 |
if ( props.align ) { |
0 | 266 |
shortcode.align = 'align' + props.align; |
5 | 267 |
} |
0 | 268 |
|
269 |
html = wp.shortcode.string({ |
|
270 |
tag: 'caption', |
|
271 |
attrs: shortcode, |
|
272 |
content: html + ' ' + props.caption |
|
273 |
}); |
|
274 |
} |
|
275 |
||
276 |
return html; |
|
277 |
} |
|
278 |
}; |
|
279 |
||
5 | 280 |
wp.media.embed = { |
281 |
coerce : wp.media.coerce, |
|
282 |
||
283 |
defaults : { |
|
284 |
url : '', |
|
285 |
width: '', |
|
286 |
height: '' |
|
287 |
}, |
|
288 |
||
289 |
edit : function( data, isURL ) { |
|
290 |
var frame, props = {}, shortcode; |
|
291 |
||
292 |
if ( isURL ) { |
|
293 |
props.url = data.replace(/<[^>]+>/g, ''); |
|
294 |
} else { |
|
295 |
shortcode = wp.shortcode.next( 'embed', data ).shortcode; |
|
296 |
||
297 |
props = _.defaults( shortcode.attrs.named, this.defaults ); |
|
298 |
if ( shortcode.content ) { |
|
299 |
props.url = shortcode.content; |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
frame = wp.media({ |
|
304 |
frame: 'post', |
|
305 |
state: 'embed', |
|
306 |
metadata: props |
|
307 |
}); |
|
308 |
||
309 |
return frame; |
|
310 |
}, |
|
311 |
||
312 |
shortcode : function( model ) { |
|
313 |
var self = this, content; |
|
0 | 314 |
|
5 | 315 |
_.each( this.defaults, function( value, key ) { |
316 |
model[ key ] = self.coerce( model, key ); |
|
317 |
||
318 |
if ( value === model[ key ] ) { |
|
319 |
delete model[ key ]; |
|
320 |
} |
|
321 |
}); |
|
322 |
||
323 |
content = model.url; |
|
324 |
delete model.url; |
|
0 | 325 |
|
5 | 326 |
return new wp.shortcode({ |
327 |
tag: 'embed', |
|
328 |
attrs: model, |
|
329 |
content: content |
|
330 |
}); |
|
331 |
} |
|
332 |
}; |
|
333 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* @class wp.media.collection |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* @param {Object} attributes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
*/ |
5 | 339 |
wp.media.collection = function(attributes) { |
340 |
var collections = {}; |
|
341 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
return _.extend(/** @lends wp.media.collection.prototype */{ |
5 | 343 |
coerce : wp.media.coerce, |
344 |
/** |
|
345 |
* Retrieve attachments based on the properties of the passed shortcode |
|
346 |
* |
|
347 |
* @param {wp.shortcode} shortcode An instance of wp.shortcode(). |
|
348 |
* @returns {wp.media.model.Attachments} A Backbone.Collection containing |
|
349 |
* the media items belonging to a collection. |
|
350 |
* The query[ this.tag ] property is a Backbone.Model |
|
351 |
* containing the 'props' for the collection. |
|
352 |
*/ |
|
0 | 353 |
attachments: function( shortcode ) { |
354 |
var shortcodeString = shortcode.string(), |
|
5 | 355 |
result = collections[ shortcodeString ], |
356 |
attrs, args, query, others, self = this; |
|
0 | 357 |
|
5 | 358 |
delete collections[ shortcodeString ]; |
359 |
if ( result ) { |
|
0 | 360 |
return result; |
5 | 361 |
} |
0 | 362 |
// Fill the default shortcode attributes. |
5 | 363 |
attrs = _.defaults( shortcode.attrs.named, this.defaults ); |
0 | 364 |
args = _.pick( attrs, 'orderby', 'order' ); |
365 |
||
5 | 366 |
args.type = this.type; |
0 | 367 |
args.perPage = -1; |
368 |
||
369 |
// Mark the `orderby` override attribute. |
|
5 | 370 |
if ( undefined !== attrs.orderby ) { |
0 | 371 |
attrs._orderByField = attrs.orderby; |
5 | 372 |
} |
0 | 373 |
|
5 | 374 |
if ( 'rand' === attrs.orderby ) { |
0 | 375 |
attrs._orderbyRandom = true; |
5 | 376 |
} |
0 | 377 |
|
378 |
// Map the `orderby` attribute to the corresponding model property. |
|
5 | 379 |
if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) { |
0 | 380 |
args.orderby = 'menuOrder'; |
5 | 381 |
} |
0 | 382 |
|
383 |
// Map the `ids` param to the correct query args. |
|
384 |
if ( attrs.ids ) { |
|
385 |
args.post__in = attrs.ids.split(','); |
|
386 |
args.orderby = 'post__in'; |
|
387 |
} else if ( attrs.include ) { |
|
388 |
args.post__in = attrs.include.split(','); |
|
389 |
} |
|
390 |
||
5 | 391 |
if ( attrs.exclude ) { |
0 | 392 |
args.post__not_in = attrs.exclude.split(','); |
5 | 393 |
} |
0 | 394 |
|
5 | 395 |
if ( ! args.post__in ) { |
0 | 396 |
args.uploadedTo = attrs.id; |
5 | 397 |
} |
0 | 398 |
|
399 |
// Collect the attributes that were not included in `args`. |
|
400 |
others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' ); |
|
401 |
||
5 | 402 |
_.each( this.defaults, function( value, key ) { |
403 |
others[ key ] = self.coerce( others, key ); |
|
404 |
}); |
|
405 |
||
0 | 406 |
query = wp.media.query( args ); |
5 | 407 |
query[ this.tag ] = new Backbone.Model( others ); |
0 | 408 |
return query; |
409 |
}, |
|
5 | 410 |
/** |
411 |
* Triggered when clicking 'Insert {label}' or 'Update {label}' |
|
412 |
* |
|
413 |
* @param {wp.media.model.Attachments} attachments A Backbone.Collection containing |
|
414 |
* the media items belonging to a collection. |
|
415 |
* The query[ this.tag ] property is a Backbone.Model |
|
416 |
* containing the 'props' for the collection. |
|
417 |
* @returns {wp.shortcode} |
|
418 |
*/ |
|
0 | 419 |
shortcode: function( attachments ) { |
420 |
var props = attachments.props.toJSON(), |
|
421 |
attrs = _.pick( props, 'orderby', 'order' ), |
|
422 |
shortcode, clone; |
|
423 |
||
5 | 424 |
if ( attachments.type ) { |
425 |
attrs.type = attachments.type; |
|
426 |
delete attachments.type; |
|
427 |
} |
|
428 |
||
429 |
if ( attachments[this.tag] ) { |
|
430 |
_.extend( attrs, attachments[this.tag].toJSON() ); |
|
431 |
} |
|
0 | 432 |
|
433 |
// Convert all gallery shortcodes to use the `ids` property. |
|
434 |
// Ignore `post__in` and `post__not_in`; the attachments in |
|
435 |
// the collection will already reflect those properties. |
|
436 |
attrs.ids = attachments.pluck('id'); |
|
437 |
||
438 |
// Copy the `uploadedTo` post ID. |
|
5 | 439 |
if ( props.uploadedTo ) { |
0 | 440 |
attrs.id = props.uploadedTo; |
5 | 441 |
} |
0 | 442 |
// Check if the gallery is randomly ordered. |
443 |
delete attrs.orderby; |
|
444 |
||
5 | 445 |
if ( attrs._orderbyRandom ) { |
0 | 446 |
attrs.orderby = 'rand'; |
5 | 447 |
} else if ( attrs._orderByField && attrs._orderByField != 'rand' ) { |
0 | 448 |
attrs.orderby = attrs._orderByField; |
5 | 449 |
} |
0 | 450 |
|
451 |
delete attrs._orderbyRandom; |
|
452 |
delete attrs._orderByField; |
|
453 |
||
454 |
// If the `ids` attribute is set and `orderby` attribute |
|
455 |
// is the default value, clear it for cleaner output. |
|
5 | 456 |
if ( attrs.ids && 'post__in' === attrs.orderby ) { |
0 | 457 |
delete attrs.orderby; |
5 | 458 |
} |
0 | 459 |
|
5 | 460 |
attrs = this.setDefaults( attrs ); |
0 | 461 |
|
462 |
shortcode = new wp.shortcode({ |
|
5 | 463 |
tag: this.tag, |
0 | 464 |
attrs: attrs, |
465 |
type: 'single' |
|
466 |
}); |
|
467 |
||
468 |
// Use a cloned version of the gallery. |
|
469 |
clone = new wp.media.model.Attachments( attachments.models, { |
|
470 |
props: props |
|
471 |
}); |
|
5 | 472 |
clone[ this.tag ] = attachments[ this.tag ]; |
473 |
collections[ shortcode.string() ] = clone; |
|
0 | 474 |
|
475 |
return shortcode; |
|
476 |
}, |
|
5 | 477 |
/** |
478 |
* Triggered when double-clicking a collection shortcode placeholder |
|
479 |
* in the editor |
|
480 |
* |
|
481 |
* @param {string} content Content that is searched for possible |
|
482 |
* shortcode markup matching the passed tag name, |
|
483 |
* |
|
484 |
* @this wp.media.{prop} |
|
485 |
* |
|
486 |
* @returns {wp.media.view.MediaFrame.Select} A media workflow. |
|
487 |
*/ |
|
0 | 488 |
edit: function( content ) { |
5 | 489 |
var shortcode = wp.shortcode.next( this.tag, content ), |
490 |
defaultPostId = this.defaults.id, |
|
491 |
attachments, selection, state; |
|
0 | 492 |
|
493 |
// Bail if we didn't match the shortcode or all of the content. |
|
5 | 494 |
if ( ! shortcode || shortcode.content !== content ) { |
0 | 495 |
return; |
5 | 496 |
} |
0 | 497 |
|
498 |
// Ignore the rest of the match object. |
|
499 |
shortcode = shortcode.shortcode; |
|
500 |
||
5 | 501 |
if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) { |
0 | 502 |
shortcode.set( 'id', defaultPostId ); |
5 | 503 |
} |
0 | 504 |
|
5 | 505 |
attachments = this.attachments( shortcode ); |
0 | 506 |
|
507 |
selection = new wp.media.model.Selection( attachments.models, { |
|
508 |
props: attachments.props.toJSON(), |
|
509 |
multiple: true |
|
510 |
}); |
|
511 |
||
5 | 512 |
selection[ this.tag ] = attachments[ this.tag ]; |
0 | 513 |
|
514 |
// Fetch the query's attachments, and then break ties from the |
|
515 |
// query to allow for sorting. |
|
516 |
selection.more().done( function() { |
|
517 |
// Break ties with the query. |
|
518 |
selection.props.set({ query: false }); |
|
519 |
selection.unmirror(); |
|
520 |
selection.props.unset('orderby'); |
|
521 |
}); |
|
522 |
||
523 |
// Destroy the previous gallery frame. |
|
5 | 524 |
if ( this.frame ) { |
0 | 525 |
this.frame.dispose(); |
5 | 526 |
} |
0 | 527 |
|
5 | 528 |
if ( shortcode.attrs.named.type && 'video' === shortcode.attrs.named.type ) { |
529 |
state = 'video-' + this.tag + '-edit'; |
|
530 |
} else { |
|
531 |
state = this.tag + '-edit'; |
|
532 |
} |
|
533 |
||
534 |
// Store the current frame. |
|
0 | 535 |
this.frame = wp.media({ |
536 |
frame: 'post', |
|
5 | 537 |
state: state, |
538 |
title: this.editTitle, |
|
0 | 539 |
editing: true, |
540 |
multiple: true, |
|
541 |
selection: selection |
|
542 |
}).open(); |
|
543 |
||
544 |
return this.frame; |
|
5 | 545 |
}, |
546 |
||
547 |
setDefaults: function( attrs ) { |
|
548 |
var self = this; |
|
549 |
// Remove default attributes from the shortcode. |
|
550 |
_.each( this.defaults, function( value, key ) { |
|
551 |
attrs[ key ] = self.coerce( attrs, key ); |
|
552 |
if ( value === attrs[ key ] ) { |
|
553 |
delete attrs[ key ]; |
|
554 |
} |
|
555 |
}); |
|
556 |
||
557 |
return attrs; |
|
0 | 558 |
} |
5 | 559 |
}, attributes ); |
560 |
}; |
|
561 |
||
562 |
wp.media._galleryDefaults = { |
|
563 |
itemtag: 'dl', |
|
564 |
icontag: 'dt', |
|
565 |
captiontag: 'dd', |
|
566 |
columns: '3', |
|
567 |
link: 'post', |
|
568 |
size: 'thumbnail', |
|
569 |
order: 'ASC', |
|
570 |
id: wp.media.view.settings.post && wp.media.view.settings.post.id, |
|
571 |
orderby : 'menu_order ID' |
|
572 |
}; |
|
573 |
||
574 |
if ( wp.media.view.settings.galleryDefaults ) { |
|
575 |
wp.media.galleryDefaults = _.extend( {}, wp.media._galleryDefaults, wp.media.view.settings.galleryDefaults ); |
|
576 |
} else { |
|
577 |
wp.media.galleryDefaults = wp.media._galleryDefaults; |
|
578 |
} |
|
0 | 579 |
|
5 | 580 |
wp.media.gallery = new wp.media.collection({ |
581 |
tag: 'gallery', |
|
582 |
type : 'image', |
|
583 |
editTitle : wp.media.view.l10n.editGalleryTitle, |
|
584 |
defaults : wp.media.galleryDefaults, |
|
585 |
||
586 |
setDefaults: function( attrs ) { |
|
587 |
var self = this, changed = ! _.isEqual( wp.media.galleryDefaults, wp.media._galleryDefaults ); |
|
588 |
_.each( this.defaults, function( value, key ) { |
|
589 |
attrs[ key ] = self.coerce( attrs, key ); |
|
590 |
if ( value === attrs[ key ] && ( ! changed || value === wp.media._galleryDefaults[ key ] ) ) { |
|
591 |
delete attrs[ key ]; |
|
592 |
} |
|
593 |
} ); |
|
594 |
return attrs; |
|
595 |
} |
|
596 |
}); |
|
597 |
||
598 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
* @namespace wp.media.featuredImage |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
* @memberOf wp.media |
5 | 601 |
*/ |
0 | 602 |
wp.media.featuredImage = { |
5 | 603 |
/** |
604 |
* Get the featured image post ID |
|
605 |
* |
|
606 |
* @returns {wp.media.view.settings.post.featuredImageId|number} |
|
607 |
*/ |
|
0 | 608 |
get: function() { |
609 |
return wp.media.view.settings.post.featuredImageId; |
|
610 |
}, |
|
5 | 611 |
/** |
9 | 612 |
* Sets the featured image ID property and sets the HTML in the post meta box to the new featured image. |
5 | 613 |
* |
614 |
* @param {number} id The post ID of the featured image, or -1 to unset it. |
|
615 |
*/ |
|
0 | 616 |
set: function( id ) { |
617 |
var settings = wp.media.view.settings; |
|
618 |
||
619 |
settings.post.featuredImageId = id; |
|
620 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
wp.media.post( 'get-post-thumbnail-html', { |
0 | 622 |
post_id: settings.post.id, |
623 |
thumbnail_id: settings.post.featuredImageId, |
|
624 |
_wpnonce: settings.post.nonce |
|
625 |
}).done( function( html ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
if ( html == '0' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
window.alert( window.setPostThumbnailL10n.error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
} |
0 | 630 |
$( '.inside', '#postimagediv' ).html( html ); |
631 |
}); |
|
632 |
}, |
|
5 | 633 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* Remove the featured image id, save the post thumbnail data and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* set the HTML in the post meta box to no featured image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
remove: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
wp.media.featuredImage.set( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
/** |
5 | 641 |
* The Featured Image workflow |
642 |
* |
|
643 |
* @this wp.media.featuredImage |
|
644 |
* |
|
645 |
* @returns {wp.media.view.MediaFrame.Select} A media workflow. |
|
646 |
*/ |
|
0 | 647 |
frame: function() { |
5 | 648 |
if ( this._frame ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
wp.media.frame = this._frame; |
0 | 650 |
return this._frame; |
5 | 651 |
} |
0 | 652 |
|
653 |
this._frame = wp.media({ |
|
654 |
state: 'featured-image', |
|
5 | 655 |
states: [ new wp.media.controller.FeaturedImage() , new wp.media.controller.EditImage() ] |
0 | 656 |
}); |
657 |
||
658 |
this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { |
|
5 | 659 |
/** |
660 |
* @this wp.media.view.MediaFrame.Select |
|
661 |
*/ |
|
0 | 662 |
this.createSelectToolbar( toolbar, { |
663 |
text: wp.media.view.l10n.setFeaturedImage |
|
664 |
}); |
|
665 |
}, this._frame ); |
|
666 |
||
5 | 667 |
this._frame.on( 'content:render:edit-image', function() { |
668 |
var selection = this.state('featured-image').get('selection'), |
|
669 |
view = new wp.media.view.EditImage( { model: selection.single(), controller: this } ).render(); |
|
670 |
||
671 |
this.content.set( view ); |
|
672 |
||
673 |
// after bringing in the frame, load the actual editor via an ajax call |
|
674 |
view.loadEditor(); |
|
675 |
||
676 |
}, this._frame ); |
|
677 |
||
0 | 678 |
this._frame.state('featured-image').on( 'select', this.select ); |
679 |
return this._frame; |
|
680 |
}, |
|
5 | 681 |
/** |
682 |
* 'select' callback for Featured Image workflow, triggered when |
|
683 |
* the 'Set Featured Image' button is clicked in the media modal. |
|
684 |
* |
|
685 |
* @this wp.media.controller.FeaturedImage |
|
686 |
*/ |
|
0 | 687 |
select: function() { |
5 | 688 |
var selection = this.get('selection').single(); |
0 | 689 |
|
5 | 690 |
if ( ! wp.media.view.settings.post.featuredImageId ) { |
0 | 691 |
return; |
5 | 692 |
} |
0 | 693 |
|
694 |
wp.media.featuredImage.set( selection ? selection.id : -1 ); |
|
695 |
}, |
|
5 | 696 |
/** |
697 |
* Open the content media manager to the 'featured image' tab when |
|
698 |
* the post thumbnail is clicked. |
|
699 |
* |
|
700 |
* Update the featured image id when the 'remove' link is clicked. |
|
701 |
*/ |
|
0 | 702 |
init: function() { |
703 |
$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { |
|
704 |
event.preventDefault(); |
|
705 |
// Stop propagation to prevent thickbox from activating. |
|
706 |
event.stopPropagation(); |
|
707 |
||
708 |
wp.media.featuredImage.frame().open(); |
|
709 |
}).on( 'click', '#remove-post-thumbnail', function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
wp.media.featuredImage.remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
return false; |
0 | 712 |
}); |
713 |
} |
|
714 |
}; |
|
715 |
||
716 |
$( wp.media.featuredImage.init ); |
|
717 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
/** @namespace wp.media.editor */ |
0 | 719 |
wp.media.editor = { |
5 | 720 |
/** |
721 |
* Send content to the editor |
|
722 |
* |
|
723 |
* @param {string} html Content to send to the editor |
|
724 |
*/ |
|
725 |
insert: function( html ) { |
|
726 |
var editor, wpActiveEditor, |
|
727 |
hasTinymce = ! _.isUndefined( window.tinymce ), |
|
728 |
hasQuicktags = ! _.isUndefined( window.QTags ); |
|
729 |
||
730 |
if ( this.activeEditor ) { |
|
731 |
wpActiveEditor = window.wpActiveEditor = this.activeEditor; |
|
732 |
} else { |
|
733 |
wpActiveEditor = window.wpActiveEditor; |
|
734 |
} |
|
0 | 735 |
|
736 |
// Delegate to the global `send_to_editor` if it exists. |
|
737 |
// This attempts to play nice with any themes/plugins that have |
|
738 |
// overridden the insert functionality. |
|
5 | 739 |
if ( window.send_to_editor ) { |
0 | 740 |
return window.send_to_editor.apply( this, arguments ); |
741 |
} |
|
742 |
||
5 | 743 |
if ( ! wpActiveEditor ) { |
744 |
if ( hasTinymce && tinymce.activeEditor ) { |
|
745 |
editor = tinymce.activeEditor; |
|
746 |
wpActiveEditor = window.wpActiveEditor = editor.id; |
|
747 |
} else if ( ! hasQuicktags ) { |
|
748 |
return false; |
|
749 |
} |
|
750 |
} else if ( hasTinymce ) { |
|
751 |
editor = tinymce.get( wpActiveEditor ); |
|
752 |
} |
|
0 | 753 |
|
5 | 754 |
if ( editor && ! editor.isHidden() ) { |
755 |
editor.execCommand( 'mceInsertContent', false, html ); |
|
756 |
} else if ( hasQuicktags ) { |
|
757 |
QTags.insertContent( html ); |
|
0 | 758 |
} else { |
5 | 759 |
document.getElementById( wpActiveEditor ).value += html; |
0 | 760 |
} |
761 |
||
762 |
// If the old thickbox remove function exists, call it in case |
|
763 |
// a theme/plugin overloaded it. |
|
5 | 764 |
if ( window.tb_remove ) { |
0 | 765 |
try { window.tb_remove(); } catch( e ) {} |
5 | 766 |
} |
0 | 767 |
}, |
768 |
||
5 | 769 |
/** |
770 |
* Setup 'workflow' and add to the 'workflows' cache. 'open' can |
|
771 |
* subsequently be called upon it. |
|
772 |
* |
|
773 |
* @param {string} id A slug used to identify the workflow. |
|
774 |
* @param {Object} [options={}] |
|
775 |
* |
|
776 |
* @this wp.media.editor |
|
777 |
* |
|
778 |
* @returns {wp.media.view.MediaFrame.Select} A media workflow. |
|
779 |
*/ |
|
0 | 780 |
add: function( id, options ) { |
781 |
var workflow = this.get( id ); |
|
782 |
||
5 | 783 |
// only add once: if exists return existing |
784 |
if ( workflow ) { |
|
0 | 785 |
return workflow; |
5 | 786 |
} |
0 | 787 |
|
788 |
workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { |
|
789 |
frame: 'post', |
|
790 |
state: 'insert', |
|
791 |
title: wp.media.view.l10n.addMedia, |
|
792 |
multiple: true |
|
793 |
} ) ); |
|
794 |
||
795 |
workflow.on( 'insert', function( selection ) { |
|
796 |
var state = workflow.state(); |
|
797 |
||
798 |
selection = selection || state.get('selection'); |
|
799 |
||
800 |
if ( ! selection ) |
|
801 |
return; |
|
802 |
||
803 |
$.when.apply( $, selection.map( function( attachment ) { |
|
804 |
var display = state.display( attachment ).toJSON(); |
|
5 | 805 |
/** |
806 |
* @this wp.media.editor |
|
807 |
*/ |
|
0 | 808 |
return this.send.attachment( display, attachment.toJSON() ); |
809 |
}, this ) ).done( function() { |
|
5 | 810 |
wp.media.editor.insert( _.toArray( arguments ).join('\n\n') ); |
0 | 811 |
}); |
812 |
}, this ); |
|
813 |
||
814 |
workflow.state('gallery-edit').on( 'update', function( selection ) { |
|
5 | 815 |
/** |
816 |
* @this wp.media.editor |
|
817 |
*/ |
|
0 | 818 |
this.insert( wp.media.gallery.shortcode( selection ).string() ); |
819 |
}, this ); |
|
820 |
||
5 | 821 |
workflow.state('playlist-edit').on( 'update', function( selection ) { |
822 |
/** |
|
823 |
* @this wp.media.editor |
|
824 |
*/ |
|
825 |
this.insert( wp.media.playlist.shortcode( selection ).string() ); |
|
826 |
}, this ); |
|
827 |
||
828 |
workflow.state('video-playlist-edit').on( 'update', function( selection ) { |
|
829 |
/** |
|
830 |
* @this wp.media.editor |
|
831 |
*/ |
|
832 |
this.insert( wp.media.playlist.shortcode( selection ).string() ); |
|
833 |
}, this ); |
|
834 |
||
0 | 835 |
workflow.state('embed').on( 'select', function() { |
5 | 836 |
/** |
837 |
* @this wp.media.editor |
|
838 |
*/ |
|
0 | 839 |
var state = workflow.state(), |
840 |
type = state.get('type'), |
|
841 |
embed = state.props.toJSON(); |
|
842 |
||
843 |
embed.url = embed.url || ''; |
|
844 |
||
845 |
if ( 'link' === type ) { |
|
846 |
_.defaults( embed, { |
|
5 | 847 |
linkText: embed.url, |
0 | 848 |
linkUrl: embed.url |
849 |
}); |
|
850 |
||
851 |
this.send.link( embed ).done( function( resp ) { |
|
852 |
wp.media.editor.insert( resp ); |
|
853 |
}); |
|
854 |
||
855 |
} else if ( 'image' === type ) { |
|
856 |
_.defaults( embed, { |
|
857 |
title: embed.url, |
|
858 |
linkUrl: '', |
|
859 |
align: 'none', |
|
860 |
link: 'none' |
|
861 |
}); |
|
862 |
||
5 | 863 |
if ( 'none' === embed.link ) { |
0 | 864 |
embed.linkUrl = ''; |
5 | 865 |
} else if ( 'file' === embed.link ) { |
0 | 866 |
embed.linkUrl = embed.url; |
5 | 867 |
} |
0 | 868 |
|
869 |
this.insert( wp.media.string.image( embed ) ); |
|
870 |
} |
|
871 |
}, this ); |
|
872 |
||
873 |
workflow.state('featured-image').on( 'select', wp.media.featuredImage.select ); |
|
874 |
workflow.setState( workflow.options.state ); |
|
875 |
return workflow; |
|
876 |
}, |
|
5 | 877 |
/** |
878 |
* Determines the proper current workflow id |
|
879 |
* |
|
880 |
* @param {string} [id=''] A slug used to identify the workflow. |
|
881 |
* |
|
882 |
* @returns {wpActiveEditor|string|tinymce.activeEditor.id} |
|
883 |
*/ |
|
0 | 884 |
id: function( id ) { |
5 | 885 |
if ( id ) { |
0 | 886 |
return id; |
5 | 887 |
} |
0 | 888 |
|
889 |
// If an empty `id` is provided, default to `wpActiveEditor`. |
|
5 | 890 |
id = window.wpActiveEditor; |
0 | 891 |
|
892 |
// If that doesn't work, fall back to `tinymce.activeEditor.id`. |
|
5 | 893 |
if ( ! id && ! _.isUndefined( window.tinymce ) && tinymce.activeEditor ) { |
0 | 894 |
id = tinymce.activeEditor.id; |
5 | 895 |
} |
0 | 896 |
|
897 |
// Last but not least, fall back to the empty string. |
|
898 |
id = id || ''; |
|
899 |
return id; |
|
900 |
}, |
|
5 | 901 |
/** |
902 |
* Return the workflow specified by id |
|
903 |
* |
|
904 |
* @param {string} id A slug used to identify the workflow. |
|
905 |
* |
|
906 |
* @this wp.media.editor |
|
907 |
* |
|
908 |
* @returns {wp.media.view.MediaFrame} A media workflow. |
|
909 |
*/ |
|
0 | 910 |
get: function( id ) { |
911 |
id = this.id( id ); |
|
912 |
return workflows[ id ]; |
|
913 |
}, |
|
5 | 914 |
/** |
915 |
* Remove the workflow represented by id from the workflow cache |
|
916 |
* |
|
917 |
* @param {string} id A slug used to identify the workflow. |
|
918 |
* |
|
919 |
* @this wp.media.editor |
|
920 |
*/ |
|
0 | 921 |
remove: function( id ) { |
922 |
id = this.id( id ); |
|
923 |
delete workflows[ id ]; |
|
924 |
}, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
/** @namespace wp.media.editor.send */ |
0 | 926 |
send: { |
5 | 927 |
/** |
928 |
* Called when sending an attachment to the editor |
|
929 |
* from the medial modal. |
|
930 |
* |
|
931 |
* @param {Object} props Attachment details (align, link, size, etc). |
|
932 |
* @param {Object} attachment The attachment object, media version of Post. |
|
933 |
* @returns {Promise} |
|
934 |
*/ |
|
0 | 935 |
attachment: function( props, attachment ) { |
936 |
var caption = attachment.caption, |
|
937 |
options, html; |
|
938 |
||
939 |
// If captions are disabled, clear the caption. |
|
5 | 940 |
if ( ! wp.media.view.settings.captions ) { |
0 | 941 |
delete attachment.caption; |
5 | 942 |
} |
0 | 943 |
|
944 |
props = wp.media.string.props( props, attachment ); |
|
945 |
||
946 |
options = { |
|
947 |
id: attachment.id, |
|
948 |
post_content: attachment.description, |
|
949 |
post_excerpt: caption |
|
950 |
}; |
|
951 |
||
5 | 952 |
if ( props.linkUrl ) { |
0 | 953 |
options.url = props.linkUrl; |
5 | 954 |
} |
0 | 955 |
|
956 |
if ( 'image' === attachment.type ) { |
|
957 |
html = wp.media.string.image( props ); |
|
958 |
||
959 |
_.each({ |
|
960 |
align: 'align', |
|
961 |
size: 'image-size', |
|
962 |
alt: 'image_alt' |
|
963 |
}, function( option, prop ) { |
|
964 |
if ( props[ prop ] ) |
|
965 |
options[ option ] = props[ prop ]; |
|
966 |
}); |
|
967 |
} else if ( 'video' === attachment.type ) { |
|
968 |
html = wp.media.string.video( props, attachment ); |
|
969 |
} else if ( 'audio' === attachment.type ) { |
|
970 |
html = wp.media.string.audio( props, attachment ); |
|
971 |
} else { |
|
972 |
html = wp.media.string.link( props ); |
|
973 |
options.post_title = props.title; |
|
974 |
} |
|
975 |
||
976 |
return wp.media.post( 'send-attachment-to-editor', { |
|
977 |
nonce: wp.media.view.settings.nonce.sendToEditor, |
|
978 |
attachment: options, |
|
979 |
html: html, |
|
980 |
post_id: wp.media.view.settings.post.id |
|
981 |
}); |
|
982 |
}, |
|
5 | 983 |
/** |
984 |
* Called when 'Insert From URL' source is not an image. Example: YouTube url. |
|
985 |
* |
|
986 |
* @param {Object} embed |
|
987 |
* @returns {Promise} |
|
988 |
*/ |
|
0 | 989 |
link: function( embed ) { |
990 |
return wp.media.post( 'send-link-to-editor', { |
|
5 | 991 |
nonce: wp.media.view.settings.nonce.sendToEditor, |
992 |
src: embed.linkUrl, |
|
993 |
link_text: embed.linkText, |
|
994 |
html: wp.media.string.link( embed ), |
|
995 |
post_id: wp.media.view.settings.post.id |
|
0 | 996 |
}); |
997 |
} |
|
998 |
}, |
|
5 | 999 |
/** |
1000 |
* Open a workflow |
|
1001 |
* |
|
1002 |
* @param {string} [id=undefined] Optional. A slug used to identify the workflow. |
|
1003 |
* @param {Object} [options={}] |
|
1004 |
* |
|
1005 |
* @this wp.media.editor |
|
1006 |
* |
|
1007 |
* @returns {wp.media.view.MediaFrame} |
|
1008 |
*/ |
|
0 | 1009 |
open: function( id, options ) { |
5 | 1010 |
var workflow; |
0 | 1011 |
|
1012 |
options = options || {}; |
|
1013 |
||
1014 |
id = this.id( id ); |
|
5 | 1015 |
this.activeEditor = id; |
0 | 1016 |
|
1017 |
workflow = this.get( id ); |
|
1018 |
||
1019 |
// Redo workflow if state has changed |
|
5 | 1020 |
if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) { |
0 | 1021 |
workflow = this.add( id, options ); |
5 | 1022 |
} |
0 | 1023 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
wp.media.frame = workflow; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
|
0 | 1026 |
return workflow.open(); |
1027 |
}, |
|
1028 |
||
5 | 1029 |
/** |
1030 |
* Bind click event for .insert-media using event delegation |
|
1031 |
*/ |
|
0 | 1032 |
init: function() { |
5 | 1033 |
$(document.body) |
1034 |
.on( 'click.add-media-button', '.insert-media', function( event ) { |
|
1035 |
var elem = $( event.currentTarget ), |
|
1036 |
editor = elem.data('editor'), |
|
1037 |
options = { |
|
1038 |
frame: 'post', |
|
1039 |
state: 'insert', |
|
1040 |
title: wp.media.view.l10n.addMedia, |
|
1041 |
multiple: true |
|
1042 |
}; |
|
0 | 1043 |
|
5 | 1044 |
event.preventDefault(); |
1045 |
||
1046 |
if ( elem.hasClass( 'gallery' ) ) { |
|
1047 |
options.state = 'gallery'; |
|
1048 |
options.title = wp.media.view.l10n.createGalleryTitle; |
|
1049 |
} |
|
0 | 1050 |
|
5 | 1051 |
wp.media.editor.open( editor, options ); |
1052 |
}); |
|
1053 |
||
1054 |
// Initialize and render the Editor drag-and-drop uploader. |
|
1055 |
new wp.media.view.EditorUploader().render(); |
|
0 | 1056 |
} |
1057 |
}; |
|
1058 |
||
1059 |
_.bindAll( wp.media.editor, 'open' ); |
|
1060 |
$( wp.media.editor.init ); |
|
5 | 1061 |
}(jQuery, _)); |