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