diff --git a/inc/fields/class-field-post-select.php b/inc/fields/class-field-post-select.php index 839ba45f..f2b0588b 100644 --- a/inc/fields/class-field-post-select.php +++ b/inc/fields/class-field-post-select.php @@ -40,16 +40,10 @@ public function action_enqueue_shortcode_ui() { $plugin_dir = dirname( dirname( __FILE__ ) ); - wp_enqueue_script( - 'shortcode-ui-field-post-select', - plugins_url( 'js/build/field-post-select.js', $plugin_dir ), - array( 'shortcode-ui', 'select2' ) - ); - wp_enqueue_script( 'select2', plugins_url( 'lib/select2/select2.min.js', $plugin_dir ) , array( 'jquery', 'jquery-ui-sortable' ), '3.5.2' ); wp_enqueue_style( 'select2', plugins_url( 'lib/select2/select2.css', $plugin_dir ), null, '3.5.2' ); - wp_localize_script( 'shortcode-ui-field-post-select', 'shortcodeUiPostFieldData', array( + wp_localize_script( 'shortcode-ui', 'shortcodeUiPostFieldData', array( 'nonce' => wp_create_nonce( 'shortcode_ui_field_post_select' ), ) ); diff --git a/js/build/field-post-select.js b/js/build/field-post-select.js index 7e9f41a4..dff19995 100644 --- a/js/build/field-post-select.js +++ b/js/build/field-post-select.js @@ -1,202 +1 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o ids.indexOf( b.id ) ) return 1; - if ( ids.indexOf( a.id ) < ids.indexOf( b.id ) ) return -1; - return 0; - }); - - callback( parsedData ); - return; - - } ); - - } - - }, - - } ); - - // Make multiple values sortable. - if ( this.model.get( 'multiple' ) ) { - $field.select2('container').find('ul.select2-choices').sortable({ - containment: 'parent', - start: function() { $('.shortcode-ui-post-select').select2('onSortStart'); }, - update: function() { $('.shortcode-ui-post-select').select2('onSortEnd'); } - }); - } - - return this; - - } - - } ); - - /** - * Extending SUI Media Controller to hide Select2 UI Drop-Down when menu - * changes in Meida modal - * 1. going back/forth between different shortcakes (refresh) - * 2. changing the menu in left column (deactivate) - * 3. @TODO closing the modal. - */ - var mediaController = sui.controllers.MediaController; - sui.controllers.MediaController = mediaController.extend({ - - refresh: function(){ - mediaController.prototype.refresh.apply( this, arguments ); - this.destroySelect2UI(); - }, - - //doesn't need to call parent as it already an "abstract" method in parent to provide callback - deactivate: function() { - this.destroySelect2UI(); - }, - - destroySelect2UI: function() { - $('.shortcode-ui-post-select.select2-container').select2( "close" ); - } - - }); - - /** - * Extending the SUI Tabbed View to hide Select2 UI dropdown when previewing the shortcake - */ - var tabbedView = sui.views.TabbedView; - sui.views.TabbedView = tabbedView.extend({ - tabSwitcher: function() { - tabbedView.prototype.tabSwitcher.apply( this, arguments ); - $('.shortcode-ui-post-select.select2-container').select2( "close" ); - } - }); - -} )( jQuery ); - -},{}]},{},[1]); +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o ids.indexOf( b.id ) ) return 1; + if ( ids.indexOf( a.id ) < ids.indexOf( b.id ) ) return -1; + return 0; + }); + + callback( parsedData ); + return; + + } ); + + } + + }, + + } ); + + // Make multiple values sortable. + if ( this.model.get( 'multiple' ) ) { + $field.select2('container').find('ul.select2-choices').sortable({ + containment: 'parent', + start: function() { $('.shortcode-ui-post-select').select2('onSortStart'); }, + update: function() { $('.shortcode-ui-post-select').select2('onSortEnd'); } + }); + } + + return this; + + } + + } ); + + /** + * Extending SUI Media Controller to hide Select2 UI Drop-Down when menu + * changes in Meida modal + * 1. going back/forth between different shortcakes (refresh) + * 2. changing the menu in left column (deactivate) + * 3. @TODO closing the modal. + */ + var mediaController = sui.controllers.MediaController; + sui.controllers.MediaController = mediaController.extend({ + + refresh: function(){ + mediaController.prototype.refresh.apply( this, arguments ); + this.destroySelect2UI(); + }, + + //doesn't need to call parent as it already an "abstract" method in parent to provide callback + deactivate: function() { + this.destroySelect2UI(); + }, + + destroySelect2UI: function() { + $('.shortcode-ui-post-select.select2-container').select2( "close" ); + } + + }); + + /** + * Extending the SUI Tabbed View to hide Select2 UI dropdown when previewing the shortcake + */ + var tabbedView = sui.views.TabbedView; + sui.views.TabbedView = tabbedView.extend({ + tabSwitcher: function() { + tabbedView.prototype.tabSwitcher.apply( this, arguments ); + $('.shortcode-ui-post-select.select2-container').select2( "close" ); + } + }); + +} )( jQuery ); + +},{}],12:[function(require,module,exports){ (function (global){ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null), sui = require('./../utils/sui.js'), @@ -929,7 +1135,7 @@ sui.views.editAttributeField = editAttributeField; module.exports = editAttributeField; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../utils/sui.js":9}],12:[function(require,module,exports){ +},{"./../utils/sui.js":9}],13:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null), sui = require('./../utils/sui.js'), @@ -938,7 +1144,8 @@ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefin // Additional attribute field types: these fields are all standalone in functionality, // but bundled here for simplicity to save an HTTP request. - editAttributeFieldAttachment = require('./edit-attribute-field-attachment.js'); + editAttributeFieldAttachment = require('./edit-attribute-field-attachment.js'), + editAttributeFieldPostSelect = require('./edit-attribute-field-post-select.js'); /** @@ -1011,7 +1218,7 @@ var EditShortcodeForm = wp.Backbone.View.extend({ module.exports = EditShortcodeForm; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../utils/sui.js":9,"./edit-attribute-field-attachment.js":10,"./edit-attribute-field.js":11}],13:[function(require,module,exports){ +},{"./../utils/sui.js":9,"./edit-attribute-field-attachment.js":10,"./edit-attribute-field-post-select.js":11,"./edit-attribute-field.js":12}],14:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null); @@ -1045,7 +1252,7 @@ var insertShortcodeListItem = wp.Backbone.View.extend({ module.exports = insertShortcodeListItem; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],14:[function(require,module,exports){ +},{}],15:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null); var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null); @@ -1091,7 +1298,7 @@ var insertShortcodeList = wp.Backbone.View.extend({ module.exports = insertShortcodeList; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../collections/shortcodes.js":2,"./insert-shortcode-list-item.js":13}],15:[function(require,module,exports){ +},{"./../collections/shortcodes.js":2,"./insert-shortcode-list-item.js":14}],16:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null), $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null), @@ -1218,7 +1425,7 @@ var mediaFrame = postMediaFrame.extend( { module.exports = mediaFrame; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../controllers/media-controller.js":3,"./media-toolbar":16,"./shortcode-ui":19}],16:[function(require,module,exports){ +},{"./../controllers/media-controller.js":3,"./media-toolbar":17,"./shortcode-ui":20}],17:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null); @@ -1250,7 +1457,7 @@ var Toolbar = wp.media.view.Toolbar.extend({ module.exports = Toolbar; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ (function (global){ var wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null); sui = require('./../utils/sui.js'); @@ -1297,7 +1504,7 @@ var SearchShortcode = wp.media.view.Search.extend({ sui.views.SearchShortcode = SearchShortcode; module.exports = SearchShortcode; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../utils/sui.js":9}],18:[function(require,module,exports){ +},{"./../utils/sui.js":9}],19:[function(require,module,exports){ (function (global){ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null), $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null); @@ -1485,7 +1692,7 @@ var ShortcodePreview = Backbone.View.extend({ module.exports = ShortcodePreview; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],19:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ (function (global){ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null), insertShortcodeList = require('./insert-shortcode-list.js'), @@ -1613,7 +1820,7 @@ var Shortcode_UI = Backbone.View.extend({ module.exports = Shortcode_UI; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../utils/sui.js":9,"./edit-shortcode-form.js":12,"./insert-shortcode-list.js":14,"./media-toolbar.js":16,"./search-shortcode.js":17,"./shortcode-preview.js":18,"./tabbed-view.js":20}],20:[function(require,module,exports){ +},{"./../utils/sui.js":9,"./edit-shortcode-form.js":13,"./insert-shortcode-list.js":15,"./media-toolbar.js":17,"./search-shortcode.js":18,"./shortcode-preview.js":19,"./tabbed-view.js":21}],21:[function(require,module,exports){ (function (global){ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null); var sui = require('./../utils/sui.js'); diff --git a/js/src/field-post-select.js b/js/src/views/edit-attribute-field-post-select.js similarity index 97% rename from js/src/field-post-select.js rename to js/src/views/edit-attribute-field-post-select.js index 4df5bdc6..b6fad34a 100644 --- a/js/src/field-post-select.js +++ b/js/src/views/edit-attribute-field-post-select.js @@ -8,7 +8,12 @@ sui.views.editAttributeFieldPostSelect = sui.views.editAttributeField.extend( { events: { - 'change .shortcode-ui-post-select': 'updateValue', + 'change .shortcode-ui-post-select': 'inputChanged', + }, + + inputChanged: function(e) { + this.setValue( e.val ); + this.triggerCallbacks(); }, render: function() { diff --git a/js/src/views/edit-shortcode-form.js b/js/src/views/edit-shortcode-form.js index ff30249f..82b77e6f 100644 --- a/js/src/views/edit-shortcode-form.js +++ b/js/src/views/edit-shortcode-form.js @@ -5,7 +5,8 @@ var wp = require('wp'), // Additional attribute field types: these fields are all standalone in functionality, // but bundled here for simplicity to save an HTTP request. - editAttributeFieldAttachment = require( 'sui-views/edit-attribute-field-attachment' ); + editAttributeFieldAttachment = require( 'sui-views/edit-attribute-field-attachment' ), + editAttributeFieldPostSelect = require( 'sui-views/edit-attribute-field-post-select' ); /**