wp/wp-includes/js/plupload/wp-plupload.js
author ymh <ymh.work@gmail.com>
Tue, 22 Oct 2019 16:11:46 +0200
changeset 15 3d4e9c994f10
parent 9 177826044cd9
child 16 a86126ab1dd4
permissions -rw-r--r--
Upgrade jquery-ui in in-motion theme version from 1.8.14 to 1.8.22 to avoid 'a.curCSS is not a function' errors in console that caused problems with circles and navigation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/* global pluploadL10n, plupload, _wpPluploadSettings */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     2
9
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
 * @namespace wp
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
window.wp = window.wp || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
( function( exports, $ ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
	var Uploader;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
	if ( typeof _wpPluploadSettings === 'undefined' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * A WordPress uploader.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 * The Plupload library provides cross-browser uploader UI integration.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 * This object bridges the Plupload API to integrate uploads into the
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
	 * WordPress back end and the WordPress media experience.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    22
	 * @class
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    23
	 * @memberOf wp
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    24
	 * @alias wp.Uploader
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    25
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	 * @param {object} options           The options passed to the new plupload instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	 * @param {object} options.container The id of uploader container.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	 * @param {object} options.browser   The id of button to trigger the file select.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	 * @param {object} options.dropzone  The id of file drop target.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	 * @param {object} options.plupload  An object of parameters to pass to the plupload instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	 * @param {object} options.params    An object of parameters to pass to $_POST when uploading the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	 *                                   Extends this.plupload.multipart_params under the hood.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	Uploader = function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		var self = this,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
			isIE = navigator.userAgent.indexOf('Trident/') != -1 || navigator.userAgent.indexOf('MSIE ') != -1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
			elements = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
				container: 'container',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
				browser:   'browse_button',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
				dropzone:  'drop_element'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
			key, error;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		this.supports = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
			upload: Uploader.browser.supported
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		this.supported = this.supports.upload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
		if ( ! this.supported ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
		}
0
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
		// Arguments to send to pluplad.Uploader().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		// Use deep extend to ensure that multipart_params and other objects are cloned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		this.plupload = $.extend( true, { multipart_params: {} }, Uploader.defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		this.container = document.body; // Set default container.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
		// Extend the instance with options.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		// Use deep extend to allow options.plupload to override individual
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		// default plupload keys.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		$.extend( true, this, options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		// Proxy all methods so this always refers to the current instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		for ( key in this ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
			if ( $.isFunction( this[ key ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
				this[ key ] = $.proxy( this[ key ], this );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
		// Ensure all elements are jQuery elements and have id attributes,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
		// then set the proper plupload arguments to the ids.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		for ( key in elements ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
			if ( ! this[ key ] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
				continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
			this[ key ] = $( this[ key ] ).first();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			if ( ! this[ key ].length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				delete this[ key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
			if ( ! this[ key ].prop('id') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
				this[ key ].prop( 'id', '__wp-uploader-id-' + Uploader.uuid++ );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
			this.plupload[ elements[ key ] ] = this[ key ].prop('id');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		// If the uploader has neither a browse button nor a dropzone, bail.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		if ( ! ( this.browser && this.browser.length ) && ! ( this.dropzone && this.dropzone.length ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		// Make sure flash sends cookies (seems in IE it does without switching to urlstream mode)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
		if ( ! isIE && 'flash' === plupload.predictRuntime( this.plupload ) &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
			( ! this.plupload.required_features || ! this.plupload.required_features.hasOwnProperty( 'send_binary_string' ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
			this.plupload.required_features = this.plupload.required_features || {};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
			this.plupload.required_features.send_binary_string = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
		// Initialize the plupload instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		this.uploader = new plupload.Uploader( this.plupload );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		delete this.plupload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		// Set default params and remove this.params alias.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		this.param( this.params || {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		delete this.params;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
		 * Custom error callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
		 * Add a new error to the errors collection, so other modules can track
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
		 * and display errors. @see wp.Uploader.errors.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
		 * @param  {string}        message
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
		 * @param  {object}        data
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
		 * @param  {plupload.File} file     File that was uploaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		error = function( message, data, file ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
			if ( file.attachment ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
				file.attachment.destroy();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
			Uploader.errors.unshift({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
				message: message || pluploadL10n.default_error,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
				data:    data,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
				file:    file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			self.error( message, data, file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
		 * After the Uploader has been initialized, initialize some behaviors for the dropzone.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		 * @param {plupload.Uploader} uploader Uploader instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
		this.uploader.bind( 'init', function( uploader ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
			var timer, active, dragdrop,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
				dropzone = self.dropzone;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
			dragdrop = self.supports.dragdrop = uploader.features.dragdrop && ! Uploader.browser.mobile;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
			// Generate drag/drop helper classes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
			if ( ! dropzone ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
			dropzone.toggleClass( 'supports-drag-drop', !! dragdrop );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
			if ( ! dragdrop ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
				return dropzone.unbind('.wp-uploader');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
			// 'dragenter' doesn't fire correctly, simulate it with a limited 'dragover'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
			dropzone.bind( 'dragover.wp-uploader', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
				if ( timer ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
					clearTimeout( timer );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
				if ( active ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
					return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
				dropzone.trigger('dropzone:enter').addClass('drag-over');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
				active = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
			dropzone.bind('dragleave.wp-uploader, drop.wp-uploader', function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				// Using an instant timer prevents the drag-over class from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				// being quickly removed and re-added when elements inside the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
				// dropzone are repositioned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				//
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
				// @see https://core.trac.wordpress.org/ticket/21705
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
				timer = setTimeout( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
					active = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
					dropzone.trigger('dropzone:leave').removeClass('drag-over');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
				}, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
			self.ready = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			$(self).trigger( 'uploader:ready' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
		this.uploader.bind( 'postinit', function( up ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
			up.refresh();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
			self.init();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
		this.uploader.init();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		if ( this.browser ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			this.browser.on( 'mouseenter', this.refresh );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			this.uploader.disableBrowse( true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
			// If HTML5 mode, hide the auto-created file container.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			$('#' + this.uploader.id + '_html5_container').hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
		 * After files were filtered and added to the queue, create a model for each.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
		 * @param {plupload.Uploader} uploader Uploader instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
		 * @param {Array}             files    Array of file objects that were added to queue by the user.
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
		this.uploader.bind( 'FilesAdded', function( up, files ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
			_.each( files, function( file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
				var attributes, image;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
				// Ignore failed uploads.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
				if ( plupload.FAILED === file.status ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
					return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
				// Generate attributes for a new `Attachment` model.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
				attributes = _.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
					file:      file,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
					uploading: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
					date:      new Date(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
					filename:  file.name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
					menuOrder: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
					uploadedTo: wp.media.model.settings.post.id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
				}, _.pick( file, 'loaded', 'size', 'percent' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
				// Handle early mime type scanning for images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
				image = /(?:jpe?g|png|gif)$/i.exec( file.name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
				// For images set the model's type and subtype attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
				if ( image ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
					attributes.type = 'image';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
					// `jpeg`, `png` and `gif` are valid subtypes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
					// `jpg` is not, so map it to `jpeg`.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
					attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
				// Create a model for the attachment, and add it to the Upload queue collection
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
				// so listeners to the upload queue can track and display upload progress.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
				file.attachment = wp.media.model.Attachment.create( attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
				Uploader.queue.add( file.attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
				self.added( file.attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			up.refresh();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			up.start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		this.uploader.bind( 'UploadProgress', function( up, file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			file.attachment.set( _.pick( file, 'loaded', 'percent' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
			self.progress( file.attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
		 * After a file is successfully uploaded, update its model.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
		 * @param {plupload.Uploader} uploader Uploader instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
		 * @param {plupload.File}     file     File that was uploaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
		 * @param {Object}            response Object with response properties.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
		 * @return {mixed}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		this.uploader.bind( 'FileUploaded', function( up, file, response ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
			var complete;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
			try {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
				response = JSON.parse( response.response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			} catch ( e ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				return error( pluploadL10n.default_error, e, file );
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
			if ( ! _.isObject( response ) || _.isUndefined( response.success ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
				return error( pluploadL10n.default_error, null, file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			else if ( ! response.success )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
				return error( response.data && response.data.message, response.data, file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
			_.each(['file','loaded','size','percent'], function( key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
				file.attachment.unset( key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			file.attachment.set( _.extend( response.data, { uploading: false }) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			wp.media.model.Attachment.get( response.data.id, file.attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			complete = Uploader.queue.all( function( attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				return ! attachment.get('uploading');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			if ( complete )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				Uploader.queue.reset();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			self.success( file.attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
		 * When plupload surfaces an error, send it to the error handler.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
		 * @param {plupload.Uploader} uploader Uploader instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
		 * @param {Object}            error    Contains code, message and sometimes file and other details.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		this.uploader.bind( 'Error', function( up, pluploadError ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			var message = pluploadL10n.default_error,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
			// Check for plupload errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
			for ( key in Uploader.errorMap ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
				if ( pluploadError.code === plupload[ key ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
					message = Uploader.errorMap[ key ];
5
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
					if ( _.isFunction( message ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
						message = message( pluploadError.file, pluploadError );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			error( message, pluploadError, pluploadError.file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
			up.refresh();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	// Adds the 'defaults' and 'browser' properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
	$.extend( Uploader, _wpPluploadSettings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	Uploader.uuid = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	// Map Plupload error codes to user friendly error messages.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	Uploader.errorMap = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		'FAILED':                 pluploadL10n.upload_failed,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		'FILE_EXTENSION_ERROR':   pluploadL10n.invalid_filetype,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
		'IMAGE_FORMAT_ERROR':     pluploadL10n.not_an_image,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		'IMAGE_MEMORY_ERROR':     pluploadL10n.image_memory_exceeded,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		'IMAGE_DIMENSIONS_ERROR': pluploadL10n.image_dimensions_exceeded,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
		'GENERIC_ERROR':          pluploadL10n.upload_failed,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
		'IO_ERROR':               pluploadL10n.io_error,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		'HTTP_ERROR':             pluploadL10n.http_error,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		'SECURITY_ERROR':         pluploadL10n.security_error,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		'FILE_SIZE_ERROR': function( file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			return pluploadL10n.file_exceeds_size_limit.replace('%s', file.name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
	$.extend( Uploader.prototype, /** @lends wp.Uploader.prototype */{
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		 * Acts as a shortcut to extending the uploader's multipart_params object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		 * param( key )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		 *    Returns the value of the key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		 * param( key, value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		 *    Sets the value of a key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		 * param( map )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		 *    Sets values for a map of data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		param: function( key, value ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
			if ( arguments.length === 1 && typeof key === 'string' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				return this.uploader.settings.multipart_params[ key ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			if ( arguments.length > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				this.uploader.settings.multipart_params[ key ] = value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
				$.extend( this.uploader.settings.multipart_params, key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
		 * Make a few internal event callbacks available on the wp.Uploader object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
		 * to change the Uploader internals if absolutely necessary.
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
		init:     function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		error:    function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		success:  function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		added:    function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		progress: function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		complete: function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		refresh:  function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			var node, attached, container, id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			if ( this.browser ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
				node = this.browser[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
				// Check if the browser node is in the DOM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				while ( node ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
					if ( node === document.body ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
						attached = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
					node = node.parentNode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
				// If the browser node is not attached to the DOM, use a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
				// temporary container to house it, as the browser button
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
				// shims require the button to exist in the DOM at all times.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
				if ( ! attached ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
					id = 'wp-uploader-browser-' + this.uploader.id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
					container = $( '#' + id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
					if ( ! container.length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
						container = $('<div class="wp-uploader-browser" />').css({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
							position: 'fixed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
							top: '-1000px',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
							left: '-1000px',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
							height: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
							width: 0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
						}).attr( 'id', 'wp-uploader-browser-' + this.uploader.id ).appendTo('body');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
					container.append( this.browser );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			this.uploader.refresh();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	// Create a collection of attachments in the upload queue,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	// so that other modules can track and display upload progress.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	Uploader.queue = new wp.media.model.Attachments( [], { query: false });
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	// Create a collection to collect errors incurred while attempting upload.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	Uploader.errors = new Backbone.Collection();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	exports.Uploader = Uploader;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
})( wp, jQuery );