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