Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #240 from funkedgeek/master

Fix for advanced file uploads
  • Loading branch information...
commit 7bf8cb527128c8154024e6740e5cb31d0be32b74 2 parents ac86d0a + 9f0dfa7
Tran Ngoc Tuan Anh authored
Showing with 51 additions and 70 deletions.
  1. +25 −34 js/file-advanced.js
  2. +26 −36 js/image-advanced.js
59 js/file-advanced.js
View
@@ -1,44 +1,40 @@
jQuery( document ).ready( function( $ )
{
- var rwmbFileFrames = {};
-
- $( '.rwmb-file-advanced-upload' ).on( 'click', function(e) {
- e.preventDefault();
-
+ $( '.rwmb-file-advanced-upload' ).each(function(){
var $uploadButton = $(this),
$fileList = $uploadButton.siblings( '.rwmb-uploaded' ),
fieldID = $fileList.data('field_id'),
maxFileUploads = $fileList.data( 'max_file_uploads' ),
- mimeType = $fileList.data( 'mime_type' );
-
- // If the frame already exists, re-open it.
- if ( rwmbFileFrames[fieldID] ) {
- rwmbFileFrames[fieldID].open();
- return;
- }
- //Setup media frame
- frameOptions = {
- className : 'media-frame rwmb-file-frame',
- frame : 'select',
- multiple : true,
- title : 'Select files',
- button : {
- text : 'Select'
- }
- };
-
+ mimeType = $fileList.data( 'mime_type' ),
+ frameOptions = {
+ className : 'media-frame rwmb-file-frame',
+ frame : 'select',
+ multiple : true,
+ title : 'Select files',
+ button : {
+ text : 'Select'
+ }
+ },
+ rwmbFileFrame;
+
if( mimeType ) {
frameOptions.library = {
type : mimeType
};
}
+ //Setup media frame
+ rwmbFileFrame = wp.media( frameOptions );
- rwmbFileFrames[fieldID] = wp.media( frameOptions );
+ //Button click handler
+ $uploadButton.on( 'click', function(e) {
+ e.preventDefault();
+ rwmbFileFrame.open();
+ } );
- //Handle selection
- rwmbFileFrames[fieldID].on( 'select', function() {
+ //File select handler
+ rwmbFileFrame.on( 'select', function() {
//Get selections
- var selection = rwmbFileFrames[fieldID].state().get( 'selection' ).toJSON(),
+ var selection = rwmbFileFrame.state().get( 'selection' ).toJSON(),
msg = 'You may only upload ' + maxFileUploads + ' file',
uploaded = $fileList.children().length;
if ( maxFileUploads > 1 )
@@ -79,11 +75,6 @@ jQuery( document ).ready( function( $ )
if ( $fileList.children().length >= maxFileUploads ) $uploadButton.addClass( 'hidden' );
}, 'xml' );
}
- });
-
-
- //Open
- rwmbFileFrames[fieldID].open();
-
- } );
+ });
+ });
} );
62 js/image-advanced.js
View
@@ -1,38 +1,32 @@
jQuery( document ).ready( function( $ )
{
- var rwmbMediaFrame;
-
- $( '.rwmb-image-advanced-upload' ).on( 'click', function(e) {
- e.preventDefault();
-
+ $( '.rwmb-image-advanced-upload' ).each(function(){
var $uploadButton = $(this),
$imageList = $(this).siblings( '.rwmb-images' ),
- maxFileUploads = $imageList.data( 'max_file_uploads' );
-
-
- // If the frame already exists, re-open it.
- if ( rwmbMediaFrame ) {
- rwmbMediaFrame.open();
- return;
- }
- //Create media frame
- frameOptions = {
- className : 'media-frame rwmb-media-frame',
- frame : 'select',
- multiple : true,
- title : 'Select or Upload Images',
- library : {
- type : 'image'
- },
- button : {
- text : 'Select'
- }
- } ;
-
- rwmbMediaFrame = wp.media.frames.rwmbMediaFrame = wp.media( frameOptions );
-
+ maxFileUploads = $imageList.data( 'max_file_uploads' ),
+ frameOptions = {
+ className : 'media-frame rwmb-media-frame',
+ frame : 'select',
+ multiple : true,
+ title : 'Select or Upload Media',
+ library : {
+ type : 'image'
+ },
+ button : {
+ text : 'Select'
+ }
+ },
+ rwmbMediaFrame = wp.media( frameOptions ) ;
+
+ //Button click handler
+ $uploadButton.on( 'click', function(e) {
+ e.preventDefault();
+ rwmbMediaFrame.open();
+ } );
+
//Handle selection
rwmbMediaFrame.on( 'select', function() {
+ console.log($imageList);
//Get selections
var selection = rwmbMediaFrame.state().get( 'selection' ).toJSON(),
msg = 'You may only upload ' + maxFileUploads + ' file',
@@ -76,12 +70,8 @@ jQuery( document ).ready( function( $ )
// Hide files button if reach max file uploads
if ( $imageList.children().length >= maxFileUploads ) $uploadButton.addClass( 'hidden' );
}, 'xml' );
- }
-
+ }
+ });
- });
-
- //Open
- rwmbMediaFrame.open();
- } );
+ });
} );
Please sign in to comment.
Something went wrong with that request. Please try again.