PluginProbe ʕ •ᴥ•ʔ
Meta Box / 4.13.3
Meta Box v4.13.3
trunk 4.1.10 4.1.11 4.10 4.10.1 4.10.2 4.10.3 4.10.4 4.11 4.11.1 4.11.2 4.12.1 4.12.4 4.12.5 4.12.6 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.10 4.14.11 4.14.2 4.14.4 4.14.5 4.14.6 4.14.7 4.14.8 4.14.9 4.15.0 4.15.1 4.15.2 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.2 4.16.3 4.17.0 4.17.1 4.17.2 4.17.3 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.3 4.3.1 4.3.10 4.3.11 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.3 4.5 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.6 4.7 4.7.1 4.7.2 4.7.3 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.10.0 5.10.1 5.10.10 5.10.11 5.10.12 5.10.13 5.10.14 5.10.15 5.10.16 5.10.17 5.10.18 5.10.19 5.10.2 5.10.3 5.10.4 5.10.5 5.10.6 5.10.7 5.10.8 5.10.9 5.11.0 5.11.1 5.11.2 5.11.3 5.11.4 5.12.0 5.2.0 5.2.1 5.2.10 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.10 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.3.8 5.3.9 5.4.0 5.4.1 5.4.2 5.4.3 5.4.4 5.4.5 5.4.6 5.4.7 5.4.8 5.5.0 5.5.1 5.6.0 5.6.1 5.6.10 5.6.11 5.6.12 5.6.13 5.6.14 5.6.15 5.6.16 5.6.17 5.6.18 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.2 5.7.3 5.7.4 5.7.5 5.8.0 5.8.1 5.8.2 5.9.0 5.9.1 5.9.10 5.9.11 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9
meta-box / js / file-upload.js
meta-box / js Last commit date
jquery-validation 9 years ago jqueryui 9 years ago select2 10 years ago wp-color-picker-alpha 8 years ago autocomplete.js 8 years ago autosave.js 8 years ago button-group.js 8 years ago clone.js 8 years ago color.js 9 years ago date.js 8 years ago datetime.js 8 years ago file-input.js 9 years ago file-upload.js 8 years ago file.js 8 years ago image-advanced.js 8 years ago image-select.js 9 years ago image-upload.js 8 years ago input-list.js 8 years ago map-frontend.js 8 years ago map.js 8 years ago media.js 8 years ago oembed.js 8 years ago range.js 8 years ago script.js 8 years ago select-advanced.js 8 years ago select-tree.js 9 years ago select.js 8 years ago slider.js 8 years ago thickbox-image.js 8 years ago time.js 9 years ago validate.js 8 years ago video.js 8 years ago wysiwyg.js 8 years ago
file-upload.js
191 lines
1 window.rwmb = window.rwmb || {};
2
3 jQuery( function ( $ ) {
4 'use strict';
5
6 var views = rwmb.views = rwmb.views || {},
7 MediaField = views.MediaField,
8 FileUploadField, UploadButton;
9
10 FileUploadField = views.FileUploadField = MediaField.extend( {
11 createAddButton: function () {
12 this.addButton = new UploadButton( {controller: this.controller} );
13 }
14 } );
15
16 UploadButton = views.UploadButton = Backbone.View.extend( {
17 className: 'rwmb-upload-area',
18 tagName: 'div',
19 template: wp.template( 'rwmb-upload-area' ),
20 render: function () {
21 this.$el.html( this.template( {} ) );
22 return this;
23 },
24
25 initialize: function ( options ) {
26 this.controller = options.controller;
27 this.el.id = _.uniqueId( 'rwmb-upload-area-' );
28 this.render();
29
30 //Areas
31 this.dropzone = this.el;
32 this.browser = this.$( '.rwmb-browse-button' )[0];
33
34 if ( wp.Uploader.browser.supported ) {
35 this.initUploader();
36 }
37
38 // Auto hide if you reach the max number of media
39 this.listenTo( this.controller, 'change:full', function () {
40 this.$el.toggle( ! this.controller.get( 'full' ) );
41 } );
42 },
43
44 //Initializes plupload
45 //Uses code from wp.Uploader
46 initUploader: function () {
47 var isIE = navigator.userAgent.indexOf( 'Trident/' ) != - 1 || navigator.userAgent.indexOf( 'MSIE ' ) != - 1,
48 self = this,
49 extensions = this.getExtensions().join( ',' ),
50 max_file_size;
51 this.plupload = $.extend( true, {
52 multipart_params: {
53 post_id : $( '#post_ID' ).val()
54 },
55 multipart: true,
56 urlstream_upload: true,
57 drop_element: this.dropzone,
58 browse_button: this.browser,
59 filters: {}
60 }, wp.Uploader.defaults );
61
62 if( max_file_size = this.controller.get( 'maxFileSize' ) ) {
63 this.plupload.filters.max_file_size = max_file_size;
64 }
65
66 if ( extensions ) {
67 this.plupload.filters.mime_types = [{title: i18nRwmbMedia.select, extensions: extensions}];
68 }
69
70 // Make sure flash sends cookies (seems in IE it does without switching to urlstream mode)
71 if ( ! isIE && 'flash' === plupload.predictRuntime( this.plupload ) &&
72 ( ! this.plupload.required_features || ! this.plupload.required_features.hasOwnProperty( 'send_binary_string' ) ) ) {
73 this.plupload.required_features = this.plupload.required_features || {};
74 this.plupload.required_features.send_binary_string = true;
75 }
76
77 // Initialize the plupload instance.
78 this.uploader = new plupload.Uploader( this.plupload );
79 this.uploader.init();
80
81 this.uploader.bind( 'FilesAdded', function ( up, files ) {
82 _.each( files, function ( file ) {
83 var attributes, image;
84
85 // Ignore failed uploads.
86 if ( plupload.FAILED === file.status ) {
87 return;
88 }
89
90 // Generate attributes for a new `Attachment` model.
91 attributes = _.extend( {
92 file: file,
93 uploading: true,
94 date: new Date(),
95 filename: file.name,
96 menuOrder: 0,
97 uploadedTo: wp.media.model.settings.post.id,
98 icon: i18nRwmbMedia.loadingUrl
99 }, _.pick( file, 'loaded', 'size', 'percent' ) );
100
101 // Handle early mime type scanning for images.
102 image = /(?:jpe?g|png|gif)$/i.exec( file.name );
103
104 // For images set the model's type and subtype attributes.
105 if ( image ) {
106 attributes.type = 'image';
107
108 // `jpeg`, `png` and `gif` are valid subtypes.
109 // `jpg` is not, so map it to `jpeg`.
110 attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0];
111 }
112
113 // Create a model for the attachment, and add it to the Upload queue collection
114 // so listeners to the upload queue can track and display upload progress.
115 file.attachment = wp.media.model.Attachment.create( attributes );
116 wp.Uploader.queue.add( file.attachment );
117 self.controller.get( 'items' ).add( [file.attachment] );
118 } );
119
120 up.refresh();
121 up.start();
122 } );
123
124 this.uploader.bind( 'UploadProgress', function ( up, file ) {
125 file.attachment.set( _.pick( file, 'loaded', 'percent' ) );
126 } );
127
128 this.uploader.bind( 'FileUploaded', function ( up, file, response ) {
129 var complete;
130
131 try {
132 response = JSON.parse( response.response );
133 } catch ( e ) {
134 return false;
135 }
136
137 if ( ! _.isObject( response ) || _.isUndefined( response.success ) || ! response.success ) {
138 return false;
139 }
140
141 _.each( ['file', 'loaded', 'size', 'percent'], function ( key ) {
142 file.attachment.unset( key );
143 } );
144
145 file.attachment.set( _.extend( response.data, {uploading: false} ) );
146 wp.media.model.Attachment.get( response.data.id, file.attachment );
147
148 complete = wp.Uploader.queue.all( function ( attachment ) {
149 return ! attachment.get( 'uploading' );
150 } );
151
152 if ( complete ) {
153 wp.Uploader.queue.reset();
154 }
155 } );
156
157 this.uploader.bind( 'Error', function ( up, error ) {
158 if ( error.file.attachment ) {
159 error.file.attachment.destroy();
160 }
161 } );
162 },
163
164 getExtensions: function () {
165 var mimeTypes = this.controller.get( 'mimeType' ).split( ',' ),
166 exts = [];
167
168 _.each( mimeTypes, function ( current, index ) {
169 if ( i18nRwmbMedia.extensions[current] ) {
170 exts = exts.concat( i18nRwmbMedia.extensions[current] );
171 }
172 } );
173 return exts;
174 }
175 } );
176
177 /**
178 * Initialize fields
179 * @return void
180 */
181 function init() {
182 var view = new FileUploadField( { input: this } );
183 //Remove old then add new
184 $( this ).siblings( 'div.rwmb-media-view' ).remove();
185 $( this ).after( view.el );
186 }
187
188 $( '.rwmb-file_upload' ).each( init );
189 $( document ).on( 'clone', '.rwmb-file_upload', init )
190 } );
191