diff --git a/.gitignore b/.gitignore index 90ec22bee..1848f37ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .svn +img/drag_icon.png diff --git a/css/select-advanced.css b/css/select-advanced.css index b1d363b5e..df8c06e18 100644 --- a/css/select-advanced.css +++ b/css/select-advanced.css @@ -20,4 +20,14 @@ } body > .select2-container { z-index: 999999; +} +a.rwmb-button.button-primary.add-clone, a.rwmb-button.button-primary.add-all, a.rwmb-button.button-primary.remove-all { + float: left; +} +a.rwmb-button.button-primary.add-all, a.rwmb-button.button-primary.remove-all { + margin-top: 10px; +} +a.rwmb-button.button-primary.add-all { + clear: left; + margin-right: 10px; } \ No newline at end of file diff --git a/img/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png b/img/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png index 5b5dab2ab..b3fe56f2a 100644 Binary files a/img/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png and b/img/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png differ diff --git a/img/jqueryui/ui-bg_flat_75_ffffff_40x100.png b/img/jqueryui/ui-bg_flat_75_ffffff_40x100.png index ac8b229af..6ebfa5026 100644 Binary files a/img/jqueryui/ui-bg_flat_75_ffffff_40x100.png and b/img/jqueryui/ui-bg_flat_75_ffffff_40x100.png differ diff --git a/img/jqueryui/ui-bg_glass_65_ffffff_1x400.png b/img/jqueryui/ui-bg_glass_65_ffffff_1x400.png index 42ccba269..6a436ad10 100644 Binary files a/img/jqueryui/ui-bg_glass_65_ffffff_1x400.png and b/img/jqueryui/ui-bg_glass_65_ffffff_1x400.png differ diff --git a/img/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png b/img/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png index 7c9fa6c6e..c07fd06df 100644 Binary files a/img/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png and b/img/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png differ diff --git a/img/jqueryui/ui-icons_222222_256x240.png b/img/jqueryui/ui-icons_222222_256x240.png index b273ff111..8bc06cbf0 100644 Binary files a/img/jqueryui/ui-icons_222222_256x240.png and b/img/jqueryui/ui-icons_222222_256x240.png differ diff --git a/img/jqueryui/ui-icons_2e83ff_256x240.png b/img/jqueryui/ui-icons_2e83ff_256x240.png index 09d1cdc85..7a3c7790d 100644 Binary files a/img/jqueryui/ui-icons_2e83ff_256x240.png and b/img/jqueryui/ui-icons_2e83ff_256x240.png differ diff --git a/img/jqueryui/ui-icons_454545_256x240.png b/img/jqueryui/ui-icons_454545_256x240.png index 59bd45b90..cfd1eaffa 100644 Binary files a/img/jqueryui/ui-icons_454545_256x240.png and b/img/jqueryui/ui-icons_454545_256x240.png differ diff --git a/img/jqueryui/ui-icons_888888_256x240.png b/img/jqueryui/ui-icons_888888_256x240.png index 6d02426c1..35f175092 100644 Binary files a/img/jqueryui/ui-icons_888888_256x240.png and b/img/jqueryui/ui-icons_888888_256x240.png differ diff --git a/img/jqueryui/ui-icons_cd0a0a_256x240.png b/img/jqueryui/ui-icons_cd0a0a_256x240.png index 2ab019b73..a239d6ca6 100644 Binary files a/img/jqueryui/ui-icons_cd0a0a_256x240.png and b/img/jqueryui/ui-icons_cd0a0a_256x240.png differ diff --git a/inc/clone.php b/inc/clone.php index 288b5cd45..363f07b60 100644 --- a/inc/clone.php +++ b/inc/clone.php @@ -127,4 +127,35 @@ public static function remove_clone_button( $field ) { $text = RWMB_Field::filter( 'remove_clone_button_text', '', $field ); return '' . $text . ''; } + + /** + * Add All button. + * + * @param array $field Field parameters. + * @return string $html + */ + public static function add_all_button( $field ) { + // Only add this button if bulk cloning is allowed and it is a select advanced field. + if ( ! $field['clone'] || ! $field['bulk_clone'] || ( 'select_advanced' !== $field['field_type'] ) ) { + return ''; + } + $text = RWMB_Field::filter( 'add_all_button_text', $field['add_all_button'], $field ); + return '' . esc_html( $text ) . ''; + } + + /** + * Remove All button. + * + * @param array $field Field parameters. + * @return string $html + */ + public static function remove_all_button( $field ) { + // Only add this button if bulk cloning is allowed and it is a select advanced field. + if ( ! $field['clone'] || ! $field['bulk_clone'] || ( 'select_advanced' !== $field['field_type'] ) ) { + return ''; + } + $text = RWMB_Field::filter( 'remove_all_button_text', $field['remove_all_button'], $field ); + return '' . esc_html( $text ) . ''; + } + } diff --git a/inc/field.php b/inc/field.php index 76132ce39..e59d1842c 100644 --- a/inc/field.php +++ b/inc/field.php @@ -126,7 +126,11 @@ public static function begin_html( $meta, $field ) { * @return string */ public static function end_html( $meta, $field ) { - return RWMB_Clone::add_clone_button( $field ) . self::call( 'input_description', $field ) . ''; + return RWMB_Clone::add_clone_button( $field ) . + RWMB_Clone::add_all_button( $field ) . + RWMB_Clone::remove_all_button( $field ) . + self::call( 'input_description', $field ) . + ''; } /** @@ -354,6 +358,9 @@ public static function normalize( $field ) { 'add_button' => __( '+ Add more', 'meta-box' ), 'clone_default' => false, 'clone_as_multiple' => false, + 'bulk_clone' => false, + 'add_all_button' => __( '+ Add All', 'meta-box' ), + 'remove_all_button' => __( '- Remove All', 'meta-box' ), 'class' => '', 'disabled' => false, diff --git a/js/clone.js b/js/clone.js index c8bd62dbe..ec7c9b6cb 100644 --- a/js/clone.js +++ b/js/clone.js @@ -192,8 +192,41 @@ function addClone( e ) { e.preventDefault(); - var $container = $( this ).closest( '.rwmb-input' ); + var $this = $( this ), + $container = $this.closest( '.rwmb-input' ); + clone( $container ); + $container.children( '.rwmb-clone' ).last().val('8349').change(); + toggleRemoveButtons( $container ); + toggleAddButton( $container ); + sortClones.apply( $container[0] ); + } + + function addAll( e ) { + e.preventDefault(); + + var $this = $( this ), + $container = $this.closest( '.rwmb-input' ), + $clones = $container.children( '.rwmb-clone' ), + options = [], + i = 0; + + $clones.find('select[class*="rwmb"]').first().find('option').each( function() { + options.push( $(this).val() ); + }); + + + $clones.find('select[class*="rwmb"]').each( function () { + var index = options.indexOf($( this ).val()); + if (index > -1) { + options.splice(index, 1); + } + } ); + + while( (i = options.shift()) !== undefined ) { + if ( '' !== $container.children( '.rwmb-clone' ).last().find('select[class*="rwmb"]').last().val() ) clone( $container ); + $container.children( '.rwmb-clone' ).last().find('select[class*="rwmb"]').last().val(i).change() + } toggleRemoveButtons( $container ); toggleAddButton( $container ); @@ -219,6 +252,30 @@ $container.find( rwmb.inputSelectors ).first().trigger( 'mb_change' ); } + function removeAll( e ) { + e.preventDefault(); + + var $this = $( this ), + $container = $this.closest( '.rwmb-input' ), + $clones = $container.children( '.rwmb-clone' ), + $firstClone = $clones.slice(0); + + // Iterate all and remove. Skip the first one so we can always clone. + $.each( $clones.slice(1), function () { + $( this ).trigger( 'remove' ).remove(); + } ); + + + // Trigger the clearing of the first value too, but leave the field there for future cloning. + $firstClone.find(".select2-selection__clear").first().mousedown(); + + // Close the dropdown that openned upon the clear + $firstClone.mousedown() + + toggleRemoveButtons( $container ); + toggleAddButton( $container ); + } + /** * Sort clones. * Expect this = .rwmb-input element. @@ -273,5 +330,7 @@ rwmb.$document .on( 'mb_ready', init ) .on( 'click', '.add-clone', addClone ) - .on( 'click', '.remove-clone', removeClone ); + .on( 'click', '.remove-clone', removeClone ) + .on( 'click', '.add-all', addAll ) + .on( 'click', '.remove-all', removeAll ); } )( jQuery, rwmb );