From 05a785cfe0344ffef56f87391bee41f9de8af10b Mon Sep 17 00:00:00 2001 From: Jay Wood Date: Fri, 30 Sep 2016 13:26:14 -0400 Subject: [PATCH] Use select2 for category selects now - #45 --- includes/admin.php | 5 ++++- includes/settings.php | 2 +- js/admin.js | 8 +++++++- js/admin.min.js | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index 8d118e6..a965446 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -75,7 +75,10 @@ public function enqueue_admin_script( $hook ) { wp_enqueue_media(); } - wp_enqueue_script( 'cwv2-admin', $this->plugin->url( "js/admin{$this->plugin->min}.js" ), array( 'jquery' ), $this->plugin->version, true ); + wp_enqueue_style( 'select2', $this->plugin->url( "lib/select2-4.0.3/css/select2{$this->plugin->min}.css" ), false, '4.0.3' ); + wp_enqueue_script( 'select2', $this->plugin->url( "lib/select2-4.0.3/js/select2{$this->plugin->min}.js" ), array( 'jquery' ), '4.0.3', true ); + + wp_enqueue_script( 'cwv2-admin', $this->plugin->url( "js/admin{$this->plugin->min}.js" ), array( 'select2' ), $this->plugin->version, true ); } /** diff --git a/includes/settings.php b/includes/settings.php index 94973a0..e9220a5 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -293,7 +293,7 @@ public function select2_multi( $args = array() ) { $option_value = get_option( $field_id, $field_id, $default ); ?> - $v ) : ?> diff --git a/js/admin.js b/js/admin.js index 7f206f6..e8f19d8 100644 --- a/js/admin.js +++ b/js/admin.js @@ -15,17 +15,23 @@ window.cwv2Admin = {}; app.$c = { window: $(window), imgUploadBtn: $( '.upload_image_button' ), + select2Objects: $( '.cwv2_select2' ), }; }; // Combine all events app.bindEvents = function() { app.$c.imgUploadBtn.on( 'click', app.handleImageUploader ); + app.$c.window.on( 'load', app.windowLoad ); + }; + + app.windowLoad = function() { + app.$c.select2Objects.select2(); }; // Do we meet the requirements? app.meetsRequirements = function() { - return app.$c.imgUploadBtn.length; + return app.$c.imgUploadBtn.length && app.$c.select2Objects.length; }; /** diff --git a/js/admin.min.js b/js/admin.min.js index 5d052b7..7506720 100644 --- a/js/admin.min.js +++ b/js/admin.min.js @@ -1 +1 @@ -window.cwv2Admin={},function(window,$,app){app.init=function(){app.cache(),app.meetsRequirements()&&app.bindEvents()},app.cache=function(){app.$c={window:$(window),imgUploadBtn:$(".upload_image_button")}},app.bindEvents=function(){app.$c.imgUploadBtn.on("click",app.handleImageUploader)},app.meetsRequirements=function(){return app.$c.imgUploadBtn.length},app.handleImageUploader=function(){var btnObj=$(this);return window.uploadID=btnObj.data("target-id"),window.file_frame?(window.file_frame.open(),!0):(window.file_frame=wp.media.frames.file_frame=wp.media({title:btnObj.data("uploader-title"),button:{text:btnObj.data("uploader-btn-txt")},multiple:!1}),window.file_frame.on("select",function(){var attachment=window.file_frame.state().get("selection").first().toJSON();$("#"+window.uploadID).val(attachment.url),window.console.log(attachment)}),void window.file_frame.open())},$(app.init)}(window,jQuery,window.cwv2Admin); \ No newline at end of file +window.cwv2Admin={},function(window,$,app){app.init=function(){app.cache(),app.meetsRequirements()&&app.bindEvents()},app.cache=function(){app.$c={window:$(window),imgUploadBtn:$(".upload_image_button"),select2Objects:$(".cwv2_select2")}},app.bindEvents=function(){app.$c.imgUploadBtn.on("click",app.handleImageUploader),app.$c.window.on("load",app.windowLoad)},app.windowLoad=function(){app.$c.select2Objects.select2()},app.meetsRequirements=function(){return app.$c.imgUploadBtn.length&&app.$c.select2Objects.length},app.handleImageUploader=function(){var btnObj=$(this);return window.uploadID=btnObj.data("target-id"),window.file_frame?(window.file_frame.open(),!0):(window.file_frame=wp.media.frames.file_frame=wp.media({title:btnObj.data("uploader-title"),button:{text:btnObj.data("uploader-btn-txt")},multiple:!1}),window.file_frame.on("select",function(){var attachment=window.file_frame.state().get("selection").first().toJSON();$("#"+window.uploadID).val(attachment.url),window.console.log(attachment)}),void window.file_frame.open())},$(app.init)}(window,jQuery,window.cwv2Admin); \ No newline at end of file