From 89021fec061dc71a284fef7ea2d10177b7f62d74 Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Mon, 29 Aug 2016 14:23:07 +0300 Subject: [PATCH 01/15] Start editing from select2 --- js/customize-object-selector-component.js | 39 +++++++++++++++++++++++ php/class-plugin.php | 6 +++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index f337dd2..5c1f374 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -125,6 +125,8 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { component.setupAddNewButtons(); + component.setupEditLinks(); + component.repopulateSelectOptionsForSettingChange = _.bind( component.repopulateSelectOptionsForSettingChange, component ); api.bind( 'change', component.repopulateSelectOptionsForSettingChange ); }, @@ -365,6 +367,43 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { } ); }, + setupEditLinks: function setupEditLinks() { + var component = this; + + // Set up the add new post buttons + component.container.on( 'click', '.edit-post-link', function() { + var ensuredPromise, link, returnPromise, postId; + link = $( this ); + postId = $( this ).data( 'postId' ); + + ensuredPromise = api.Posts.ensurePosts( [ 711 ] ); + ensuredPromise.done( function( postsData ) { + var postData = postsData[ 711 ]; + if ( postData ) { + returnPromise = component.focusConstructWithBreadcrumb( postData.section, component.containing_construct ); + returnPromise.done( function() { + /*var values; + if ( 'publish' === data.setting.get().post_status ) { + values = component.getSettingValues().slice( 0 ); + if ( ! component.select2_options.multiple ) { + values = [ data.postId ]; + } else { + + // @todo Really the add new buttons should be disabled when the limit is reached. + if ( component.select2_options.multiple && component.select2_options.limit >= values.length ) { + values.length = component.select2_options.limit - 1; + } + values.unshift( data.postId ); + } + component.setSettingValues( values ); + }*/ + link.focus(); // @todo Focus on the select2? + } ); + } + } ); + } ); + }, + /** * Focus (expand) one construct and then focus on another construct after the first is collapsed. * diff --git a/php/class-plugin.php b/php/class-plugin.php index 84e4417..c24860c 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -391,8 +391,12 @@ public function print_templates() { {{{ data.text }}} - <# } else { #> + <# } else if ( data.disable_edit_from_select2 ) { #> {{{ data.text }}} + <# } else { #> + + {{{ data.text }}} + <# } #> Date: Mon, 29 Aug 2016 15:51:08 +0300 Subject: [PATCH 02/15] Continue with select2 edit. --- js/customize-object-selector-component.js | 32 +++++++++-------------- php/class-plugin.php | 4 +-- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 5c1f374..ac8cb4c 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -85,9 +85,11 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { } }, templateResult: function( data ) { + data.disable_edit = true; return $.trim( component.select2_result_template( data ) ); }, templateSelection: function( data ) { + data.disable_edit = ! data.id; return $.trim( component.select2_selection_template( data ) ); }, escapeMarkup: function( m ) { @@ -367,37 +369,27 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { } ); }, + /** + * Setup links for editing objects in select2. + * + * @returns {void} + */ setupEditLinks: function setupEditLinks() { var component = this; // Set up the add new post buttons component.container.on( 'click', '.edit-post-link', function() { - var ensuredPromise, link, returnPromise, postId; - link = $( this ); + var ensuredPromise, returnPromise, postId; + postId = $( this ).data( 'postId' ); - ensuredPromise = api.Posts.ensurePosts( [ 711 ] ); + ensuredPromise = api.Posts.ensurePosts( [ postId ] ); ensuredPromise.done( function( postsData ) { - var postData = postsData[ 711 ]; + var postData = postsData[ postId ]; if ( postData ) { returnPromise = component.focusConstructWithBreadcrumb( postData.section, component.containing_construct ); returnPromise.done( function() { - /*var values; - if ( 'publish' === data.setting.get().post_status ) { - values = component.getSettingValues().slice( 0 ); - if ( ! component.select2_options.multiple ) { - values = [ data.postId ]; - } else { - - // @todo Really the add new buttons should be disabled when the limit is reached. - if ( component.select2_options.multiple && component.select2_options.limit >= values.length ) { - values.length = component.select2_options.limit - 1; - } - values.unshift( data.postId ); - } - component.setSettingValues( values ); - }*/ - link.focus(); // @todo Focus on the select2? + component.containing_construct.focus(); } ); } } ); diff --git a/php/class-plugin.php b/php/class-plugin.php index c24860c..68afb38 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -391,10 +391,10 @@ public function print_templates() { {{{ data.text }}} - <# } else if ( data.disable_edit_from_select2 ) { #> + <# } else if ( data.disable_edit ) { #> {{{ data.text }}} <# } else { #> - + {{{ data.text }}} <# } #> From a49a0bd850175f4d4cbf247f33fcf4149eb105dc Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Wed, 31 Aug 2016 15:49:51 +0300 Subject: [PATCH 03/15] Fix scrolling not working when returning. --- js/customize-object-selector-component.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index ac8cb4c..b1be16e 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -381,16 +381,26 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { component.container.on( 'click', '.edit-post-link', function() { var ensuredPromise, returnPromise, postId; + component.select.prop( 'disabled', true ); postId = $( this ).data( 'postId' ); ensuredPromise = api.Posts.ensurePosts( [ postId ] ); ensuredPromise.done( function( postsData ) { var postData = postsData[ postId ]; + + postData.section.focus(); + + if ( ! component.containing_construct ) { + return; + } if ( postData ) { returnPromise = component.focusConstructWithBreadcrumb( postData.section, component.containing_construct ); returnPromise.done( function() { component.containing_construct.focus(); + component.select.prop( 'disabled', false ); } ); + } else { + component.select.prop( 'disabled', false ); } } ); } ); From cc63d04a39780f2daaec164621cbab08b44a3bcf Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Thu, 1 Sep 2016 10:22:40 +0300 Subject: [PATCH 04/15] Use data.element instead of data.edit_disabled --- js/customize-object-selector-component.js | 2 -- php/class-plugin.php | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index b1be16e..0a02ff4 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -85,11 +85,9 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { } }, templateResult: function( data ) { - data.disable_edit = true; return $.trim( component.select2_result_template( data ) ); }, templateSelection: function( data ) { - data.disable_edit = ! data.id; return $.trim( component.select2_selection_template( data ) ); }, escapeMarkup: function( m ) { diff --git a/php/class-plugin.php b/php/class-plugin.php index 68afb38..fa92fc6 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -391,12 +391,12 @@ public function print_templates() { {{{ data.text }}} - <# } else if ( data.disable_edit ) { #> - {{{ data.text }}} - <# } else { #> + <# } else if ( data.element ) { #> {{{ data.text }}} + <# } else { #> + {{{ data.text }}} <# } #> Date: Fri, 2 Sep 2016 13:02:44 +0300 Subject: [PATCH 05/15] Add dashicon. Remove event delegation. --- js/customize-object-selector-component.js | 14 +++++++++----- php/class-plugin.php | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 0a02ff4..811682b 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -114,6 +114,7 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { return parseInt( value, 10 ); } ) ); + component.setupEditLinks(); } ); // Sync the setting values with the select2 values. @@ -125,8 +126,6 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { component.setupAddNewButtons(); - component.setupEditLinks(); - component.repopulateSelectOptionsForSettingChange = _.bind( component.repopulateSelectOptionsForSettingChange, component ); api.bind( 'change', component.repopulateSelectOptionsForSettingChange ); }, @@ -374,13 +373,18 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { */ setupEditLinks: function setupEditLinks() { var component = this; + debugger; + var oi = component.container.find( '.select2-selection__choice__edit' ); // Set up the add new post buttons - component.container.on( 'click', '.edit-post-link', function() { - var ensuredPromise, returnPromise, postId; + component.container.find( '.select2-selection__choice__edit' ).on( 'click' , function( e ) { + e.stopPropagation(); + var ensuredPromise, returnPromise, postId, $selection; component.select.prop( 'disabled', true ); - postId = $( this ).data( 'postId' ); + + $selection = $( this ).parent(); + postId = $selection.data('data').id; ensuredPromise = api.Posts.ensurePosts( [ postId ] ); ensuredPromise.done( function( postsData ) { diff --git a/php/class-plugin.php b/php/class-plugin.php index fa92fc6..6e8463e 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -392,9 +392,8 @@ public function print_templates() { {{{ data.text }}} <# } else if ( data.element ) { #> - {{{ data.text }}} - + <# } else { #> {{{ data.text }}} <# } #> From b8acc655da372354f5e49b4adc3ab09918b6b4d2 Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Fri, 2 Sep 2016 13:08:49 +0300 Subject: [PATCH 06/15] Remove debugging info. --- js/customize-object-selector-component.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 811682b..3192e98 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -373,8 +373,6 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { */ setupEditLinks: function setupEditLinks() { var component = this; - debugger; - var oi = component.container.find( '.select2-selection__choice__edit' ); // Set up the add new post buttons component.container.find( '.select2-selection__choice__edit' ).on( 'click' , function( e ) { From 7a80d1bab56adb006c40f5b4660ed800d7576c93 Mon Sep 17 00:00:00 2001 From: Derek Herman Date: Fri, 2 Sep 2016 05:19:20 -0700 Subject: [PATCH 07/15] Clean up styles --- css/customize-object-selector.css | 19 +++++++++++++++++++ images/spinner.gif | Bin 0 -> 4162 bytes js/customize-object-selector-component.js | 18 ++++++++++-------- php/class-plugin.php | 5 ++--- 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 images/spinner.gif diff --git a/css/customize-object-selector.css b/css/customize-object-selector.css index 5b2d545..8e308ed 100644 --- a/css/customize-object-selector.css +++ b/css/customize-object-selector.css @@ -1,8 +1,27 @@ .select2-container { z-index: 1000000; + margin-bottom: 5px; } + .select2-thumbnail-wrapper img { height: 32px; width: auto; vertical-align: middle; } + +.select2-selection__choice__edit { + cursor: pointer; +} + +.select2-selection--single .select2-selection__choice__edit { + line-height: 26px; +} + +.select2-selection__choice__edit.loading:before { + background: url(../images/spinner.gif) no-repeat; + -webkit-background-size: 20px 20px; + background-size: 20px 20px; + color: rgba( 255, 255, 255, 0 ); + opacity: 0.7; + filter: alpha(opacity=70); +} diff --git a/images/spinner.gif b/images/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..209d10b6bb1a443fa7488d5238b32b93a2bd8b8d GIT binary patch literal 4162 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 LsoI7F?dpF4ttiU7 literal 0 HcmV?d00001 diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 3192e98..d229477 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -114,7 +114,6 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { return parseInt( value, 10 ); } ) ); - component.setupEditLinks(); } ); // Sync the setting values with the select2 values. @@ -123,8 +122,8 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { } ); component.setupSortable(); - component.setupAddNewButtons(); + component.setupEditLinks(); component.repopulateSelectOptionsForSettingChange = _.bind( component.repopulateSelectOptionsForSettingChange, component ); api.bind( 'change', component.repopulateSelectOptionsForSettingChange ); @@ -375,14 +374,15 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { var component = this; // Set up the add new post buttons - component.container.find( '.select2-selection__choice__edit' ).on( 'click' , function( e ) { - e.stopPropagation(); - var ensuredPromise, returnPromise, postId, $selection; + component.container.on( 'click', '.select2-selection__choice__edit', function( event ) { + var ensuredPromise, returnPromise, postId, $elm = $( this ); - component.select.prop( 'disabled', true ); + event.preventDefault(); + event.stopPropagation(); - $selection = $( this ).parent(); - postId = $selection.data('data').id; + component.select.prop( 'disabled', true ); + postId = $( this ).data( 'postId' ); + $elm.addClass( 'loading' ); ensuredPromise = api.Posts.ensurePosts( [ postId ] ); ensuredPromise.done( function( postsData ) { @@ -398,9 +398,11 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { returnPromise.done( function() { component.containing_construct.focus(); component.select.prop( 'disabled', false ); + $elm.removeClass( 'loading' ); } ); } else { component.select.prop( 'disabled', false ); + $elm.removeClass( 'loading' ); } } ); } ); diff --git a/php/class-plugin.php b/php/class-plugin.php index 6e8463e..0d8cbb1 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -104,7 +104,7 @@ public function register_styles( \WP_Styles $wp_styles ) { $wp_styles->add( $handle, $src, $deps, $this->version ); } - $handle = 'customize-object-selector'; + $handle = 'customize-object-selector-control'; $src = plugins_url( 'css/customize-object-selector' . $suffix, dirname( __FILE__ ) ); $deps = array( 'customize-controls', 'select2' ); $wp_styles->add( $handle, $src, $deps, $this->version ); @@ -392,8 +392,7 @@ public function print_templates() { {{{ data.text }}} <# } else if ( data.element ) { #> - {{{ data.text }}} - + {{{ data.text }}} <# } else { #> {{{ data.text }}} <# } #> From b72e36ba17c1b2642f60ac1216d1895c0a7036c5 Mon Sep 17 00:00:00 2001 From: Derek Herman Date: Fri, 2 Sep 2016 05:25:26 -0700 Subject: [PATCH 08/15] Fix phpcs issue --- php/class-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-plugin.php b/php/class-plugin.php index 0d8cbb1..0e2fe79 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -392,7 +392,7 @@ public function print_templates() { {{{ data.text }}} <# } else if ( data.element ) { #> - {{{ data.text }}} + {{{ data.text }}} <# } else { #> {{{ data.text }}} <# } #> From a4de325f369a29f0277078c79d9d7dea93aef21e Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Fri, 2 Sep 2016 16:42:15 +0300 Subject: [PATCH 09/15] Fix scrolling issue. --- js/customize-object-selector-component.js | 6 ++---- php/class-plugin.php | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index d229477..a49bebd 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -374,12 +374,10 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { var component = this; // Set up the add new post buttons - component.container.on( 'click', '.select2-selection__choice__edit', function( event ) { + component.container.on( 'click', '.select2-selection__choice__edit', function() { var ensuredPromise, returnPromise, postId, $elm = $( this ); - event.preventDefault(); - event.stopPropagation(); - + component.select.select2( 'close' ); component.select.prop( 'disabled', true ); postId = $( this ).data( 'postId' ); $elm.addClass( 'loading' ); diff --git a/php/class-plugin.php b/php/class-plugin.php index 0e2fe79..47cd579 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -390,6 +390,9 @@ public function print_templates() { {{{ data.text }}} + <# if ( data.element ) { #> + + <# } #> <# } else if ( data.element ) { #> {{{ data.text }}} From e0ddbfbe8cfbe4873bae9ec37e45b2015aaf0a9a Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Thu, 22 Sep 2016 13:40:46 -0300 Subject: [PATCH 10/15] Fix cs. --- js/customize-object-selector-component.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 433cf8a..108b6cf 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -395,12 +395,13 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { // Set up the add new post buttons component.container.on( 'click', '.select2-selection__choice__edit', function( e ) { - e.preventDefault(); var $elm = $( this ), postId; + + e.preventDefault(); component.select.select2( 'close' ); component.select.prop( 'disabled', true ); postId = $( this ).data( 'postId' ); - + api.Posts.startEditPostFlow( { postId: parseInt( postId, 10 ), initiatingButton: $elm, From 7a5de3c3de064160fc5715519393873e48900cef Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Thu, 22 Sep 2016 14:52:00 -0300 Subject: [PATCH 11/15] Match adding new button with Customize Posts. --- css/customize-object-selector.css | 11 +++++++++++ js/customize-object-selector-component.js | 2 ++ js/customize-object-selector-control.js | 5 ++++- php/class-control.php | 2 +- php/class-plugin.php | 10 +++++----- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/css/customize-object-selector.css b/css/customize-object-selector.css index 26f68c3..46b0624 100644 --- a/css/customize-object-selector.css +++ b/css/customize-object-selector.css @@ -28,4 +28,15 @@ /* @todo A spinner would be better here */ .customize-object-selector-populating { opacity: 0.5; +} + +.customize-object-selector-container .add-new-post-stub:before { + content: "\f132"; + display: inline-block; + position: relative; + font: normal 20px/1 dashicons; + vertical-align: middle; + -webkit-transition: all 0.2s; + transition: all 0.2s; + -webkit-font-smoothing: antialiased; } \ No newline at end of file diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 108b6cf..916299e 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -401,6 +401,7 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { component.select.select2( 'close' ); component.select.prop( 'disabled', true ); postId = $( this ).data( 'postId' ); + $elm.addClass( 'loading' ); api.Posts.startEditPostFlow( { postId: parseInt( postId, 10 ), @@ -410,6 +411,7 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { returnToOriginatingConstruct: true, breadcrumbReturnCallback: function() { component.setSettingValues( component.getSettingValues().slice( 0 ) ); + $elm.removeClass( 'loading' ); component.select.prop( 'disabled', false ); component.containing_construct.focus(); } diff --git a/js/customize-object-selector-control.js b/js/customize-object-selector-control.js index a668bed..191dd1c 100644 --- a/js/customize-object-selector-control.js +++ b/js/customize-object-selector-control.js @@ -35,11 +35,14 @@ args.params.post_query_vars = args.params.post_query_args; } + if ( true === args.params.select2_options.multiple ) { + args.params.select2_options.width = '100%'; + } args.params.select2_options = _.extend( { multiple: false, cache: false, - width: '100%' + width: '80%' }, args.params.select2_options ); diff --git a/php/class-control.php b/php/class-control.php index 43185de..dfd022f 100644 --- a/php/class-control.php +++ b/php/class-control.php @@ -30,7 +30,7 @@ class Control extends \WP_Customize_Control { public $select2_options = array( 'multiple' => false, 'cache' => false, - 'width' => '100%', + 'width' => '80%', ); /** diff --git a/php/class-plugin.php b/php/class-plugin.php index 867acdc..210f8a7 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -163,7 +163,7 @@ public function register_styles( \WP_Styles $wp_styles ) { $wp_styles->add( $handle, $src, $deps, $this->version ); } - $handle = 'customize-object-selector'; + $handle = 'customize-object-selector-control'; $src = plugins_url( 'css/customize-object-selector' . $suffix, __DIR__ ); $deps = array( 'customize-controls', 'select2' ); $wp_styles->add( $handle, $src, $deps, $this->version ); @@ -663,13 +663,13 @@ public function print_templates() { <# if ( ! _.isEmpty( data.addable_post_types ) ) { #> - <# _.each( data.addable_post_types, function( addable_post_type ) { #> - <# } ) #> - <# } #> From 363224a11fd6ca81aab1e74bbf9327f094b877a0 Mon Sep 17 00:00:00 2001 From: Miina Sikk Date: Fri, 23 Sep 2016 16:22:07 -0300 Subject: [PATCH 12/15] Change edit button according to Customize Posts. --- css/customize-object-selector.css | 31 +++++++++++++++-------- js/customize-object-selector-component.js | 19 +++++++++++--- js/customize-object-selector-control.js | 2 +- php/class-plugin.php | 8 +++--- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/css/customize-object-selector.css b/css/customize-object-selector.css index 46b0624..6e953a7 100644 --- a/css/customize-object-selector.css +++ b/css/customize-object-selector.css @@ -9,6 +9,26 @@ vertical-align: middle; } +.customize-object-selector-container .single-selection.select2-selection__choice__edit, +.customize-object-selector-container .add-new-post-stub { + padding: 0 5px 1px; +} + +.customize-object-selector-container .single-selection.select2-selection__choice__edit:before { + content: "\f464"; + font: normal 20px/1 dashicons; + top: -2px; + vertical-align: middle; +} + +.customize-object-selector-container .add-new-post-stub:before { + content: "\f132"; + display: inline-block; + position: relative; + font: normal 20px/1 dashicons; + vertical-align: middle; +} + .select2-selection__choice__edit { cursor: pointer; } @@ -28,15 +48,4 @@ /* @todo A spinner would be better here */ .customize-object-selector-populating { opacity: 0.5; -} - -.customize-object-selector-container .add-new-post-stub:before { - content: "\f132"; - display: inline-block; - position: relative; - font: normal 20px/1 dashicons; - vertical-align: middle; - -webkit-transition: all 0.2s; - transition: all 0.2s; - -webkit-font-smoothing: antialiased; } \ No newline at end of file diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 916299e..1ebc56c 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -111,6 +111,7 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { return $.trim( component.select2_result_template( data ) ); }, templateSelection: function( data ) { + data.multiple = component.select2_options.multiple; return $.trim( component.select2_selection_template( data ) ); }, escapeMarkup: function( m ) { @@ -391,20 +392,32 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { * @returns {void} */ setupEditLinks: function setupEditLinks() { - var component = this; + var component = this, editButton, onSelect; + + editButton = component.container.find( '.select2-selection__choice__edit' ); + onSelect = function( pageId ) { + editButton.toggle( ( 0 !== parseInt( pageId, 10 ) ) && ! component.select2_options.multiple ); + }; + onSelect( component.model.get() ); + component.model.bind( onSelect ); // Set up the add new post buttons component.container.on( 'click', '.select2-selection__choice__edit', function( e ) { var $elm = $( this ), postId; + if ( component.select2_options.multiple ) { + postId = $elm.data( 'postId' ); + } else { + postId = parseInt( component.model.get(), 10 ); + } + e.preventDefault(); component.select.select2( 'close' ); component.select.prop( 'disabled', true ); - postId = $( this ).data( 'postId' ); $elm.addClass( 'loading' ); api.Posts.startEditPostFlow( { - postId: parseInt( postId, 10 ), + postId: postId, initiatingButton: $elm, originatingConstruct: component.containing_construct, restorePreviousUrl: true, diff --git a/js/customize-object-selector-control.js b/js/customize-object-selector-control.js index 191dd1c..953dc70 100644 --- a/js/customize-object-selector-control.js +++ b/js/customize-object-selector-control.js @@ -42,7 +42,7 @@ { multiple: false, cache: false, - width: '80%' + width: '70%' }, args.params.select2_options ); diff --git a/php/class-plugin.php b/php/class-plugin.php index 210f8a7..3c0a59b 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -661,7 +661,9 @@ public function print_templates() { <# } #> > - + <# if ( ! _.isEmpty( data.addable_post_types ) ) { #> <# _.each( data.addable_post_types, function( addable_post_type ) { #> <# if ( ! _.isEmpty( data.addable_post_types ) ) { #> <# _.each( data.addable_post_types, function( addable_post_type ) { #> - <# } ) #> @@ -681,11 +684,13 @@ public function print_templates() { {{{ data.text }}} <# if ( data.element && data.multiple ) { #> - + + + <# } #> <# } else if ( data.element && data.multiple ) { #> - {{{ data.text }}} + {{{ data.text }}} <# } else { #> <# if ( data.depth ) { #> <# From 2554cb18f4925d62a96edbefc7b16efb505101da Mon Sep 17 00:00:00 2001 From: Derek Herman Date: Sat, 24 Sep 2016 04:56:02 -0700 Subject: [PATCH 15/15] Fix eslint issues --- js/customize-object-selector-component.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/js/customize-object-selector-component.js b/js/customize-object-selector-component.js index 421126e..7a3ac92 100644 --- a/js/customize-object-selector-component.js +++ b/js/customize-object-selector-component.js @@ -396,14 +396,8 @@ wp.customize.ObjectSelectorComponent = (function( api, $ ) { editButton = component.container.find( '.select2-selection__choice__edit' ); onSelect = function( pageId ) { - var visible = ( - ! isNaN( parseInt( pageId ) ) - && - 0 !== parseInt( pageId, 10 ) - && - ! component.select2_options.multiple - ); - editButton.toggle( visible ); + pageId = parseInt( pageId, 10 ); + editButton.toggle( ! isNaN( pageId ) && 0 !== pageId && ! component.select2_options.multiple ); }; onSelect( component.model.get() ); component.model.bind( onSelect );