From d7425656d9ef50d3b416ac28807c285689c5a595 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Thu, 2 Nov 2017 09:12:25 -0400 Subject: [PATCH] Update shortcode button library --- includes/sixtenpress-shortcodes/README.md | 5 +++++ .../includes/class-sixtenpress-shortcodes.php | 12 +++++++----- .../includes/js/shortcode-editor.js | 6 +++--- .../includes/js/shortcode-editor.min.js | 2 +- .../sixtenpress-shortcodes.php | 12 ++++++------ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/includes/sixtenpress-shortcodes/README.md b/includes/sixtenpress-shortcodes/README.md index ca12e54..89ecd27 100644 --- a/includes/sixtenpress-shortcodes/README.md +++ b/includes/sixtenpress-shortcodes/README.md @@ -102,6 +102,11 @@ If an image ID is required, Six/Ten Press image fields in a group will work, as ### Changelog +#### 0.3.4 +* added: hooks before/after media buttons +* changed: target shortcode buttons by ID instead of class +* improved: modal insert button + #### 0.3.3 * fixed: check for script/style enqueue * fixed: localized scripts/inline styles output only once diff --git a/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php index 2a20c34..008e4ad 100644 --- a/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php +++ b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php @@ -151,6 +151,7 @@ class SixTenPressShortcodes { if ( ! $show ) { return; } + do_action( 'sixtenpress_shortcode_before_media_button', $this->shortcode_args, $id ); printf( '', esc_attr( $this->shortcode_args['button']['id'] ), esc_attr( $this->shortcode_args['button']['class'] ), @@ -158,6 +159,7 @@ class SixTenPressShortcodes { esc_html( $this->shortcode_args['button']['label'] ), esc_attr( $id ) ); + do_action( 'sixtenpress_shortcode_after_media_button', $this->shortcode_args, $id ); } /** @@ -168,7 +170,7 @@ class SixTenPressShortcodes { return; } $minify = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script( 'sixtenpress-editor-script', plugin_dir_url( __FILE__ ) . "js/shortcode-editor{$minify}.js", array( 'jquery' ), SIXTENPRESSSHORTCODES_VERSION, true ); + wp_enqueue_script( 'sixtenpress-shortcode-editor', plugin_dir_url( __FILE__ ) . "js/shortcode-editor{$minify}.js", array( 'jquery' ), SIXTENPRESSSHORTCODES_VERSION, true ); add_action( 'admin_print_scripts', array( $this, 'localize' ) ); } @@ -180,11 +182,11 @@ class SixTenPressShortcodes { return; } add_filter( 'sixtenpress_admin_style', '__return_true' ); - wp_enqueue_style( 'sixtenpress-editor', plugin_dir_url( __FILE__ ) . 'css/sixtenpress-editor.css', array(), SIXTENPRESSSHORTCODES_VERSION, 'screen' ); + wp_enqueue_style( 'sixtenpress-shortcode-editor', plugin_dir_url( __FILE__ ) . 'css/sixtenpress-editor.css', array(), SIXTENPRESSSHORTCODES_VERSION, 'screen' ); $css = apply_filters( 'sixtenpress_shortcode_inline_css', '' ); if ( $css ) { - wp_add_inline_style( 'sixtenpress-editor', $this->minify_css( $css ) ); + wp_add_inline_style( 'sixtenpress-shortcode-editor', $this->minify_css( $css ) ); } } @@ -206,7 +208,7 @@ class SixTenPressShortcodes { * Get the data for the script. */ public function localize() { - wp_localize_script( 'sixtenpress-editor-script', 'SixTenShortcodes', apply_filters( 'sixtenpress_shortcode_localization', array() ) ); + wp_localize_script( 'sixtenpress-shortcode-editor', 'SixTenShortcodes', apply_filters( 'sixtenpress_shortcode_localization', array() ) ); } /** @@ -219,7 +221,7 @@ class SixTenPressShortcodes { public function localization_args( $args ) { $new[ $this->shortcode ] = array( 'modal' => $this->shortcode_args['modal'], - 'button' => $this->shortcode_args['button']['class'], + 'button' => $this->shortcode_args['button']['id'], 'shortcode' => $this->shortcode, 'self' => $this->shortcode_args['self'], 'slug' => $this->shortcode_args['slug'], diff --git a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js index 5acb214..619a319 100644 --- a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js +++ b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js @@ -21,8 +21,8 @@ inputs = $( '#' + IndividualObject.modal ).find( ":input" ), defaults = _defaults( inputs ); - $( '.' + IndividualObject.button ).click( _open ); - $( '.sixtenpress-default-ui .sixtenpress-insert' ).click( _insert ); + $( '#' + IndividualObject.button ).click( _open ); + $( modal + '.sixtenpress-default-ui .sixtenpress-insert' ).click( _insert ); } /** @@ -49,7 +49,7 @@ */ function _insert( e ) { e.preventDefault(); - if ( $( sixtenpress_trigger_target ).hasClass( IndividualObject.button ) ) { + if ( IndividualObject.button === $( sixtenpress_trigger_target ).attr( 'id' ) ) { var string = _getAttributes( inputs, IndividualObject.group ), multi = IndividualObject.group ? _getMulti( IndividualObject.group, IndividualObject.slug ) : '', output = ''; diff --git a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js index 2ea3b98..357a13d 100644 --- a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js +++ b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js @@ -1 +1 @@ -!function(t,e,i){"use strict";function n(t){var n=[];return e(t).each(function(t){var r=e(this).attr("id");i!==r&&(n[r]=e(this).val()),e(this).is(":checked")&&(n[r]="checked")}),n}function r(t,i){var n="";return e(t).each(function(t){var r=e(this).attr("id"),a=e(this).val(),c=this.type;if(r){var o=r.substr(r.lastIndexOf("-")+1);if(o.includes("nonce")&&(a=""),"checkbox"===c)if(i.length&&o.includes(i))a="";else if(e(this).is(":checked")){var s=[1,"1","on"],d=s.indexOf(a);a=-1!==d?"true":a}else a=e(this).is(":required")?"false":"";"button"===c&&(a=""),"textarea"===c&&(a=""),(a||e(this).is(":required"))&&(n+=" "+o+'="'+a+'"')}}),n}function a(t,i){var n=e("#"+i),r=n.find("textarea").val();if(!r){var a=n.find("textarea[id*='"+t+"']").attr("id");"undefined"!==a&&a.length&&(r=tinymce.get(a).getContent({format:"text"}))}return r}function c(t,i){var n="";return e(t).each(function(t,r){var a=e("#"+i).find("[id*='"+r+"']"),c=[];e(a).each(function(t){e(this).is(":checked")&&c.push(e(this).val())}),n+=c.length?" "+r+'="'+c.toString()+'"':""}),n}var o={};o.init=function(){Object.keys(o.params).forEach(function(i){function s(i){i.preventDefault(),v=i.target,m=!0,e(k).show(),e(".media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion").click(u),e(t).on("keydown",function(t){27===t.keyCode&&m&&u(t)})}function d(t){if(t.preventDefault(),e(v).hasClass(p.button)){var i=r(x,p.group),n=p.group?c(p.group,p.slug):"",o="";i&&(o="["+p.shortcode+n+i+"]",p.self||(o+=a(p.slug,p.modal)+"[/"+p.shortcode+"]"),tinymce.get(e(v).attr("data-editor")).execCommand("mceInsertContent",!1,o))}u(t)}function u(t){t.preventDefault(),e(k).hide(),f(),v=m=!1}function f(){e(x).each(function(t){var i=e(this).attr("id");if("checkbox"===this.type){var n="checked"===g[i];e(this).attr("checked",n)}else e(this).val(g[i])}),e(k+" .upload-file-preview").remove(),h(),l()}function h(){var t=e(k).find(".wp-picker-container");t.length&&t.each(function(){var t=e(this).parent();t.html(t.find('input[type="text"].color-field').attr("style","")),t.find('input[type="text"].wp-color-picker').each(function(){var t=e(this),i=t.data("colorpicker")||{};t.wpColorPicker(e.extend({},!1,i))})})}function l(){var t=e(k).find("textarea[id*='"+p.slug+"']");if(t.length){var i=t.attr("id");tinymce.get(i).setContent("")}}if(o.params.hasOwnProperty(i)){var p=o.params[i],v=!1,m=!1,k="."+p.modal,x=e("#"+p.modal).find(":input"),g=n(x);e("."+p.button).click(s),e(".sixtenpress-default-ui .sixtenpress-insert").click(d)}})},e(t).ready(function(){o.params="undefined"==typeof SixTenShortcodes?"":SixTenShortcodes,void 0!==o.params&&o.init()})}(document,jQuery); \ No newline at end of file +!function(t,e,i){"use strict";function n(t){var n=[];return e(t).each(function(t){var r=e(this).attr("id");i!==r&&(n[r]=e(this).val()),e(this).is(":checked")&&(n[r]="checked")}),n}function r(t,i){var n="";return e(t).each(function(t){var r=e(this).attr("id"),a=e(this).val(),c=this.type;if(r){var o=r.substr(r.lastIndexOf("-")+1);if(o.includes("nonce")&&(a=""),"checkbox"===c)if(i.length&&o.includes(i))a="";else if(e(this).is(":checked")){var s=[1,"1","on"],d=s.indexOf(a);a=-1!==d?"true":a}else a=e(this).is(":required")?"false":"";"button"===c&&(a=""),"textarea"===c&&(a=""),(a||e(this).is(":required"))&&(n+=" "+o+'="'+a+'"')}}),n}function a(t,i){var n=e("#"+i),r=n.find("textarea").val();if(!r){var a=n.find("textarea[id*='"+t+"']").attr("id");"undefined"!==a&&a.length&&(r=tinymce.get(a).getContent({format:"text"}))}return r}function c(t,i){var n="";return e(t).each(function(t,r){var a=e("#"+i).find("[id*='"+r+"']"),c=[];e(a).each(function(t){e(this).is(":checked")&&c.push(e(this).val())}),n+=c.length?" "+r+'="'+c.toString()+'"':""}),n}var o={};o.init=function(){Object.keys(o.params).forEach(function(i){function s(i){i.preventDefault(),v=i.target,m=!0,e(k).show(),e(".media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion").click(u),e(t).on("keydown",function(t){27===t.keyCode&&m&&u(t)})}function d(t){if(t.preventDefault(),p.button===e(v).attr("id")){var i=r(x,p.group),n=p.group?c(p.group,p.slug):"",o="";i&&(o="["+p.shortcode+n+i+"]",p.self||(o+=a(p.slug,p.modal)+"[/"+p.shortcode+"]"),tinymce.get(e(v).attr("data-editor")).execCommand("mceInsertContent",!1,o))}u(t)}function u(t){t.preventDefault(),e(k).hide(),f(),v=m=!1}function f(){e(x).each(function(t){var i=e(this).attr("id");if("checkbox"===this.type){var n="checked"===g[i];e(this).attr("checked",n)}else e(this).val(g[i])}),e(k+" .upload-file-preview").remove(),h(),l()}function h(){var t=e(k).find(".wp-picker-container");t.length&&t.each(function(){var t=e(this).parent();t.html(t.find('input[type="text"].color-field').attr("style","")),t.find('input[type="text"].wp-color-picker').each(function(){var t=e(this),i=t.data("colorpicker")||{};t.wpColorPicker(e.extend({},!1,i))})})}function l(){var t=e(k).find("textarea[id*='"+p.slug+"']");if(t.length){var i=t.attr("id");tinymce.get(i).setContent("")}}if(o.params.hasOwnProperty(i)){var p=o.params[i],v=!1,m=!1,k="."+p.modal,x=e("#"+p.modal).find(":input"),g=n(x);e("#"+p.button).click(s),e(k+".sixtenpress-default-ui .sixtenpress-insert").click(d)}})},e(t).ready(function(){o.params="undefined"==typeof SixTenShortcodes?"":SixTenShortcodes,void 0!==o.params&&o.init()})}(document,jQuery); \ No newline at end of file diff --git a/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php b/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php index 4eae683..4e69092 100644 --- a/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php +++ b/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php @@ -10,7 +10,7 @@ * @author Robin Cornett * @copyright 2016 Robin Cornett * @license GPL-2.0+ - * @version 0.3.3 + * @version 0.3.4 * @link https://gitlab.com/robincornett/sixtenpress-shortcodes * @since 0.1.0 */ @@ -37,7 +37,7 @@ * Loader versioning: http://jtsternberg.github.io/wp-lib-loader/ */ -if ( ! class_exists( 'SixTenPressShortcodes_033', false ) ) { +if ( ! class_exists( 'SixTenPressShortcodes_034', false ) ) { /** * Versioned loader class-name @@ -52,14 +52,14 @@ if ( ! class_exists( 'SixTenPressShortcodes_033', false ) ) { * @link https://gitlab.com/robincornett/sixtenpress-shortcodes * @since 0.1.0 */ - class SixTenPressShortcodes_033 { + class SixTenPressShortcodes_034 { /** * SixTenPressShortcodes version number * @var string * @since 0.1.0 */ - const VERSION = '0.3.3'; + const VERSION = '0.3.4'; /** * Current version hook priority. @@ -68,7 +68,7 @@ if ( ! class_exists( 'SixTenPressShortcodes_033', false ) ) { * @var int * @since 0.1.0 */ - const PRIORITY = 9991; + const PRIORITY = 9990; /** * Starts the version checking process. @@ -152,5 +152,5 @@ if ( ! class_exists( 'SixTenPressShortcodes_033', false ) ) { } // Kick it off. - new SixTenPressShortcodes_033(); + new SixTenPressShortcodes_034(); }