balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

image-upload.js (1000B)


      1 ( function ( $, rwmb ) {
      2 	'use strict';
      3 
      4 	var views = rwmb.views = rwmb.views || {},
      5 		ImageField = views.ImageField,
      6 		ImageUploadField,
      7 		UploadButton = views.UploadButton;
      8 
      9 	ImageUploadField = views.ImageUploadField = ImageField.extend( {
     10 		createAddButton: function () {
     11 			this.addButton = new UploadButton( {controller: this.controller} );
     12 		}
     13 	} );
     14 
     15 	function initImageUpload() {
     16 		var $this = $( this ),
     17 			view = $this.data( 'view' );
     18 
     19 		if ( view ) {
     20 			return;
     21 		}
     22 
     23 		view = new ImageUploadField( { input: this } );
     24 
     25 		$this.siblings( '.rwmb-media-view' ).remove();
     26 		$this.after( view.el );
     27 
     28 		// Init uploader after view is inserted to make wp.Uploader works.
     29 		view.addButton.initUploader();
     30 
     31 		$this.data( 'view', view );
     32 	}
     33 
     34 	function init( e ) {
     35 		$( e.target ).find( '.rwmb-image_upload, .rwmb-plupload_image' ).each( initImageUpload );
     36 	}
     37 
     38 	rwmb.$document
     39 		.on( 'mb_ready', init )
     40 		.on( 'clone', '.rwmb-image_upload, .rwmb-plupload_image', initImageUpload )
     41 } )( jQuery, rwmb );