adding test for elements in shortcode builder, adding !wp_script_is
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 16 May 2016 16:00:42 +0000 (12:00 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 16 May 2016 16:00:42 +0000 (12:00 -0400)
classes/glmPluginSupport.php
js/shortcodeBuilder.js

index 16f9652..634816a 100644 (file)
@@ -614,14 +614,18 @@ class GlmPluginSupport
 
     public function glmMembersShortcode(){
 
-        // load shortcodeBuilder.js when the shortcode function has been fired
-        add_action('admin_print_styles-post.php', 'custom_js_css');
-        add_action('admin_print_styles-post-new.php', 'custom_js_css');
+        // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet
+        if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){
+            wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true);
+            wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
+        }
 
         function custom_js_css() {
 
             wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true);
         }
+        add_action('admin_print_styles-post.php', 'custom_js_css');
+        add_action('admin_print_styles-post-new.php', 'custom_js_css');
         reset($this->config['addOns']);
         foreach ($this->config['addOns'] as $a) {
             $cssFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/css/admin.css';
index 34b0be1..8e794fc 100644 (file)
@@ -18,8 +18,9 @@ jQuery(document).ready(function ($) {
     $("#shortcodeDropdown").on("change", function () {
         // reset the dropdowns and checkbox if when switching shortcodes
         document.getElementById('category-scDropdown').options[0].selected = 'selected';
-        document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
-        if(document.getElementById('id-scDropdown').length > 0)
+        if($('#blank-start-scDropdown').length)
+            document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
+        if($('#id-scDropdown').length)
             document.getElementById('id-scDropdown').options[0].selected = 'selected';
         UncheckAll();