Permalink
Browse files

FIX: ui media

  • Loading branch information...
1 parent 27d9cbe commit 4e9e51bf545314302279a2b48a2a8b18665eec37 makhonkodenis committed Apr 20, 2016
View
@@ -28,8 +28,3 @@ node_modules
#########################
# Travis-si files
#########################
-.jscsrc
-.jshintignore
-.travis.yml
-codesniffer.ruleset.xml
-travis.sh
View
@@ -3,4 +3,5 @@ modules/cherry-ui-elements/inc/ui-elements/ui-select/assets/select2.js
modules/cherry-ui-elements/inc/ui-elements/ui-collection/assets/js/jquery.collection.js
#Cherry Framework
+modules/cherry-ui-elements/inc/ui-elements/ui-media/assets/ui-media.js
modules/cherry-js-core/assets/js/cherry-js-core.js
@@ -1 +1 @@
-!function(a){"use strict";CherryJsCore.utilites.namespace("ui_elements.media"),CherryJsCore.ui_elements.media={init:function(a){var b=this;CherryJsCore.status.document_ready?b.render(a):CherryJsCore.variable.$document.on("ready",b.render(a))},render:function(b){var c;a(".upload-button",b).on("click",function(){var b=a(this).parents(".cherry-ui-media-wrap"),e=a(".cherry-upload-input",b),f=a(".cherry-upload-preview",b),g=a(this).data("title"),h=a(this).data("multi-upload"),i=a(this).data("library-type");return void 0!==c?void c.open():(c=wp.media.frames.file_frame=wp.media({title:g,button:{text:g},multiple:h,library:{type:i}}),c.on("select",function(){var b=c.state().get("selection").toJSON(),g=0,i="",j="",k="";for(h&&(i=e.val(),k=",",j=a(".cherry-all-images-wrap",f).html());b[g];){var l=b[g],m=l.id,n=l.mime,o="",p="";switch(n){case"image/jpeg":case"image/png":case"image/gif":void 0!=l.sizes&&(o=l.sizes.thumbnail?l.sizes.thumbnail.url:l.sizes.full.url),p='<img src="'+o+'" alt="" data-img-attr="'+m+'">';break;case"image/x-icon":p='<span class="dashicons dashicons-format-image"></span>';break;case"video/mpeg":case"video/mp4":case"video/quicktime":case"video/webm":case"video/ogg":p='<span class="dashicons dashicons-format-video"></span>';break;case"audio/mpeg":case"audio/wav":case"audio/ogg":p='<span class="dashicons dashicons-format-audio"></span>'}j+='<div class="cherry-image-wrap"><div class="inner"><div class="preview-holder" data-id-attr="'+m+'"><div class="centered">'+p+'</div></div><a class="cherry-remove-image" href="#"><i class="dashicons dashicons-no"></i></a><span class="title">'+l.title+"</span></div></div>",i+=k+m,g++}e.val(i.replace(/(^,)/,"")).trigger("change"),a(".cherry-all-images-wrap",f).html(j),a(".cherry-remove-image").on("click",function(){return d(a(this)),!1})}).open(),!1)}),jQuery(".cherry-remove-image",b).on("click",function(){return d(jQuery(this)),!1});var d=function(a){var b=a.parents(".cherry-ui-media-wrap"),c=jQuery(".cherry-upload-input",b),d=a.parent().parent(".cherry-image-wrap"),e=jQuery(".preview-holder",d).data("id-attr"),f=c.attr("value"),g=new RegExp(""+e+"(,*)","i");f=f.replace(g,""),f=f.replace(/(,$)/,""),c.attr({value:f}).trigger("change"),d.remove()};jQuery(".cherry-all-images-wrap",b).sortable({items:"div.cherry-image-wrap",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"cherry-media-thumb-sortable-placeholder",start:function(a,b){},stop:function(a,b){},update:function(a,b){var c="";jQuery(".cherry-image-wrap",this).each(function(){var a=jQuery(".preview-holder",this).data("id-attr");c=c+a+","}),c=c.substr(0,c.lastIndexOf(",")),jQuery(this).parent().siblings(".cherry-element-wrap").find("input.cherry-upload-input").val(c).trigger("change")}})}},a(window).on("cherry-ui-elements-init",function(a,b){CherryJsCore.ui_elements.media.init(b.target)})}(jQuery);
+!function(e,a){"use strict";a.utilites.namespace("ui_elements.media"),a.ui_elements.media={init:function(e){var i=this;a.status.document_ready?i.render(e):a.variable.$document.on("ready",i.render(e))},render:function(a){var i=e(".upload-button",a),r=i.parents(".cherry-ui-media-wrap"),t={input:e(".cherry-upload-input",r),img_holder:e(".cherry-upload-preview",r),title_text:i.data("title"),multiple:i.data("multi-upload"),library_type:i.data("library-type")},s=wp.media.frames.file_frame=wp.media({title:t.title_text,button:{text:t.title_text},multiple:t.multiple,library:{type:t.library_type}});i.on("click",function(){return s.on("select",function(){var a=s.state().get("selection").toJSON(),i=0,r="",c=e(".cherry-all-images-wrap",t.img_holder),l="",o="";for(t.multiple&&(r=t.input.val(),o=",",l=c.html());a[i];){var d=a[i],u=d.id,p=d.mime,m="",h="";switch(p){case"image/jpeg":case"image/png":case"image/gif":void 0!==d.sizes&&(m=d.sizes.thumbnail?d.sizes.thumbnail.url:d.sizes.full.url),h='<img src="'+m+'" alt="" data-img-attr="'+u+'">';break;case"image/x-icon":h='<span class="dashicons dashicons-format-image"></span>';break;case"video/mpeg":case"video/mp4":case"video/quicktime":case"video/webm":case"video/ogg":h='<span class="dashicons dashicons-format-video"></span>';break;case"audio/mpeg":case"audio/wav":case"audio/ogg":h='<span class="dashicons dashicons-format-audio"></span>'}l+='<div class="cherry-image-wrap"><div class="inner"><div class="preview-holder" data-id-attr="'+u+'"><div class="centered">'+h+'</div></div><a class="cherry-remove-image" href="#"><i class="dashicons dashicons-no"></i></a><span class="title">'+d.title+"</span></div></div>",r+=o+u,i++}t.input.val(r.replace(/(^,)/,"")).trigger("change"),c.html(l),e(".cherry-remove-image").on("click",function(){return n(e(this)),!1})}).open(),!1}),jQuery(".cherry-remove-image",a).on("click",function(){return n(jQuery(this)),!1});var n=function(e){var a=e.parents(".cherry-ui-media-wrap"),i=jQuery(".cherry-upload-input",a),r=e.parent().parent(".cherry-image-wrap"),t=jQuery(".preview-holder",r).data("id-attr"),s=i.attr("value"),n=new RegExp(""+t+"(,*)","i");s=s.replace(n,""),s=s.replace(/(,$)/,""),i.attr({value:s}).trigger("change"),r.remove()};jQuery(".cherry-all-images-wrap",a).sortable({items:"div.cherry-image-wrap",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"cherry-media-thumb-sortable-placeholder",start:function(){},stop:function(){},update:function(){var e="";jQuery(".cherry-image-wrap",this).each(function(){var a=jQuery(".preview-holder",this).data("id-attr");e=e+a+","}),e=e.substr(0,e.lastIndexOf(",")),jQuery(this).parent().siblings(".cherry-element-wrap").find("input.cherry-upload-input").val(e).trigger("change")}})}},e(window).on("cherry-ui-elements-init",function(e,i){a.ui_elements.media.init(i.target)})}(jQuery,window.CherryJsCore);
@@ -1,8 +1,8 @@
/**
* Media
*/
-(function($){
- "use strict";
+(function( $, CherryJsCore){
+ 'use strict';
CherryJsCore.utilites.namespace('ui_elements.media');
CherryJsCore.ui_elements.media = {
@@ -15,39 +15,35 @@
}
},
render: function ( target ) {
- var cherry_uploader;
-
- $('.upload-button', target).on('click', function () {
- var button_parent = $(this).parents('.cherry-ui-media-wrap'),
- input = $('.cherry-upload-input', button_parent),
- img_holder = $('.cherry-upload-preview', button_parent),
- title_text = $(this).data('title'),
- multiple = $(this).data('multi-upload'),
- library_type = $(this).data('library-type');
-
- if ( undefined !== cherry_uploader ) {
- cherry_uploader.open();
- return;
- }
-
+ var button = $('.upload-button', target),
+ button_parent = button.parents('.cherry-ui-media-wrap'),
+ settings = {
+ input: $('.cherry-upload-input', button_parent),
+ img_holder: $('.cherry-upload-preview', button_parent),
+ title_text: button.data('title'),
+ multiple: button.data('multi-upload'),
+ library_type: button.data('library-type'),
+ },
cherry_uploader = wp.media.frames.file_frame = wp.media({
- title: title_text,
- button: {text: title_text},
- multiple: multiple,
- library : { type : library_type }
+ title: settings.title_text,
+ button: {text: settings.title_text},
+ multiple: settings.multiple,
+ library : { type : settings.library_type }
});
+ button.on('click', function () {
cherry_uploader.on('select', function() {
var attachment = cherry_uploader.state().get('selection').toJSON(),
count = 0,
input_value = '',
+ new_img_object = $('.cherry-all-images-wrap', settings.img_holder),
new_img = '',
delimiter = '';
- if ( multiple ) {
- input_value = input.val();
+ if ( settings.multiple ) {
+ input_value = settings.input.val();
delimiter = ',';
- new_img = $('.cherry-all-images-wrap', img_holder).html();
+ new_img = new_img_object.html();
}
while(attachment[count]){
@@ -61,7 +57,7 @@
case 'image/jpeg':
case 'image/png':
case 'image/gif':
- if( img_data.sizes != undefined){
+ if( img_data.sizes !== undefined){
img_src = img_data.sizes.thumbnail ? img_data.sizes.thumbnail.url : img_data.sizes.full.url;
}
thumb = '<img src="' + img_src + '" alt="" data-img-attr="'+return_data+'">';
@@ -95,13 +91,13 @@
count++;
}
- input.val(input_value.replace(/(^,)/, '')).trigger( 'change' );
- $('.cherry-all-images-wrap', img_holder).html(new_img);
+ settings.input.val(input_value.replace(/(^,)/, '')).trigger( 'change' );
+ new_img_object.html(new_img);
$('.cherry-remove-image').on('click', function () {
removeMediaPreview( $(this) );
return !1;
- })
+ });
}).open();
return !1;
@@ -111,7 +107,7 @@
jQuery('.cherry-remove-image', target).on('click', function () {
removeMediaPreview( jQuery(this) );
return !1;
- })
+ });
var removeMediaPreview = function( item ){
var button_parent = item.parents('.cherry-ui-media-wrap'),
input = jQuery('.cherry-upload-input', button_parent),
@@ -125,7 +121,7 @@
input.attr({'value':imput_value}).trigger( 'change' );
img_holder.remove();
- }
+ };
// Upload End
// Image ordering
jQuery('.cherry-all-images-wrap', target).sortable({
@@ -137,9 +133,9 @@
helper: 'clone',
opacity: 0.65,
placeholder: 'cherry-media-thumb-sortable-placeholder',
- start:function(event,ui){},
- stop:function(event,ui){},
- update: function(event, ui) {
+ start:function(){},
+ stop:function(){},
+ update: function() {
var attachment_ids = '';
jQuery('.cherry-image-wrap', this).each(
function() {
@@ -153,10 +149,10 @@
});
// End Image ordering
}
- }
+ };
$( window ).on( 'cherry-ui-elements-init',
function( event, data ) {
CherryJsCore.ui_elements.media.init( data.target );
}
);
-}(jQuery));
+}(jQuery , window.CherryJsCore));
@@ -75,7 +75,6 @@ function __construct( $args = array() ) {
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
- //self::enqueue_assets();
}
/**
@@ -103,9 +102,9 @@ public function render() {
$inline_style = $this->settings['inline_style'] ? 'style="' . esc_attr( $this->settings['inline_style'] ) . '"' : '' ;
$html .= '<select id="' . esc_attr( $this->settings['id'] ) . '" class="cherry-ui-select ' . esc_attr( $this->settings['class'] ) . '" name="' . esc_attr( $name ) . '" size="' . esc_attr( $this->settings['size'] ) . '" ' . $multi_state . ' ' . $filter_state . ' placeholder="' . $this->settings['placeholder'] . '" ' . $inline_style . ' >';
- if( $this->settings['options'] && !empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ){
- foreach ( $this->settings['options'] as $option => $option_value) {
- if ( !is_array( $this->settings['value'] ) ) {
+ if ( $this->settings['options'] && ! empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ) {
+ foreach ( $this->settings['options'] as $option => $option_value ) {
+ if ( ! is_array( $this->settings['value'] ) ) {
$this->settings['value'] = array( $this->settings['value'] );
}
if ( false === strpos( $option, 'optgroup' ) ) {

0 comments on commit 4e9e51b

Please sign in to comment.