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