WIP work on drop down change event for blank-start
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Jun 2016 21:01:26 +0000 (17:01 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Jun 2016 21:01:26 +0000 (17:01 -0400)
Still working on getting it to update the shortcode.

js/shortcodeBuilder.js

index ee86ae5..071c1c6 100644 (file)
@@ -10,7 +10,7 @@ jQuery(document).ready(function ($) {
     
     'use strict';
     
-    var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString,
+    var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString,
     editor_shortcodes, category_id, shortcodeValues = {}, editor_content, debug = false;
     
     debug = true;
@@ -141,13 +141,15 @@ jQuery(document).ready(function ($) {
             }
         }
         if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) {
+            blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1];
             if ( debug ) {
-                console.info('DEBUG INFO: editor_shortcodes.match blank-start ', editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1] );
+                console.info('DEBUG INFO: editor_shortcodes.match blank-start ', blankStart );
             }
         }
         if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) {
+            memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1];
             if ( debug ) {
-                console.info('DEBUG INFO: editor_shortcodes.match view ', editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1] );
+                console.info('DEBUG INFO: editor_shortcodes.match view ', memberView );
             }
         }
         if(editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){
@@ -189,11 +191,11 @@ jQuery(document).ready(function ($) {
     $('#category-scDropdown').change( function() {
        editor_shortcodes = get_tinymce_content();
 
-       if(editor_shortcodes){
-            if(editor_shortcodes.match(/category="(.*?)"/) !== null){
-                category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
+       if ( editor_shortcodes ) {
+            if ( editor_shortcodes.match( /category="(.*?)"/ ) !== null ){
+                category_id = editor_shortcodes.match( /glm-members-list category="(.*?)"/ )[1];
              
-                if(category_id !== ""){
+                if ( category_id !== "" ) {
                     category_id = category_id.split(',');
      
                     ids = category_id.join(',');
@@ -241,30 +243,29 @@ jQuery(document).ready(function ($) {
        });   
         
         // if more than one category id in the array, join together with ',' otherwise set the id string to a single value    
-       if ( new_ids.length > 1){
+       if ( new_ids.length > 1 ){
            id_string = new_ids.join(',');
-       } else if ( new_ids.length === 1) {
+       } else if ( new_ids.length === 1 ) {
            id_string = new_ids[0];
        }
         
         
         // replace the current content in either the visual or text editor and replace it with a filtered version of the categories
-       if($("#content").css("display") !== "none"){
+       if ( $("#content").css("display") !== "none" ) {
            editor_content = content.val();
-           if(empty_space){
-                editor_content = editor_content.replace(ids, 'category="' + id_string + '"');
-                content.val(editor_content);
+           if ( empty_space ) {
+                editor_content = editor_content.replace( ids, 'category="' + id_string + '"' );
+                content.val( editor_content );
            } else {
-               editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
-               content.val(editor_content);
+               editor_content = editor_content.replace( 'category="' + ids, 'category="' + id_string );
+               content.val( editor_content );
            }
-       } else if(tinyMCE.activeEditor !== null){
-           if(empty_space){
+       } else if ( tinyMCE.activeEditor !== null ) {
+           if ( empty_space ) {
                 editor_content = tinyMCE.get('content').getContent({format: 'raw'});
                 editor_content = editor_content.replace(ids, 'category="' + id_string + '"' );
                 tinyMCE.activeEditor.setContent(editor_content);
            } else {
-
                 editor_content = tinyMCE.get('content').getContent({format: 'raw'});
                 editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
                 tinyMCE.activeEditor.setContent(editor_content);
@@ -276,16 +277,22 @@ jQuery(document).ready(function ($) {
     });
 
     $('#blank-start-scDropdown').change(function(){
-        
+        editor_shortcodes = get_tinymce_content();
+        editor_content = content.val();
+        if ( editor_shortcodes ) {
+            if ( $("#content").css("display") !== "none" ) {
+                editor_content = editor_content.replace( ids, 'blank-start="' + $(this).val() + '"' );
+            } else if ( tinyMCE.activeEditor !== null ) {
+            }
+        }
     });
-    
-    
-    function insert_tag(text){
-        if(tinyMCE && tinyMCE.activeEditor)
-        {
+
+
+    function insert_tag( text ) {
+        if ( tinyMCE && tinyMCE.activeEditor ) {
             tinyMCE.activeEditor.selection.setContent(text);
         }
-            return false;
+        return false;
     }
     
     /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -433,29 +440,37 @@ jQuery(document).ready(function ($) {
     var members = document.getElementById('member-scDropdown');
     var view    = document.getElementById('view-scDropdown');
 
-    if(scd){
+    if ( editor_shortcodes ) {
+        $('#shortcodeDropdown').val('glm-members-list');
+        $('#shortcodeDropdown').change();
+        $('#generate').hide();
+    }
+    if( scd ){
         window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
     }
-    if(catscd){
+    if( catscd ){
         window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected';
     }
-    if(blank){
-        window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
+    if( blank ){
+        if ( blankStart ) {
+            $('#blank-start-scDropdown').val( blankStart );
+            console.log( blankStart );
+        } else {
+            window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
+        }
     }
-    if(list){
+    if( list ){
         window.onload = document.getElementById('type-scList').options[0].selected = 'selected';
     }
-    if(members){
+    if( members ){
         window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected';
     }
-    if(view){
-        window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
-    }
-    if ( editor_shortcodes ) {
-        $('#shortcodeDropdown').val('glm-members-list');
-        $('#shortcodeDropdown').change();
-        $('#generate').hide();
+    if( view ){
+        if ( memberView ) {
+            $('#view-scDropdown').val( memberView );
+        } else {
+            window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
+        }
     }
-//    window.onload = uncheckAll();
 });