fixed bug with adding shortcode to text or visual mode
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 9 May 2016 15:25:21 +0000 (11:25 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 9 May 2016 15:25:21 +0000 (11:25 -0400)
js/shortcodeBuilder.js

index eb79c70..7449353 100644 (file)
@@ -150,25 +150,24 @@ jQuery(document).ready(function ($) {
             shortcodeString += ']';
 
             // insert shortcode at current cursor position
-//             if($("#content").css("display") !== "none"){
-//                var cursorPos = $('#content').prop('selectionStart');
-//                var v = $('#content').val();
-//                var textBefore = v.substring(0,  cursorPos );
-//                var textAfter  = v.substring( cursorPos, v.length );
-//                $('#content').val( textBefore + shortcodeString + textAfter );
-//                 
-//             } else {
+             if($("#content").css("display") !== "none"){
+                var cursorPos = $('#content').prop('selectionStart');
+                var v = $('#content').val();
+                var textBefore = v.substring(0,  cursorPos );
+                var textAfter  = v.substring( cursorPos, v.length );
+                $('#content').val( textBefore + shortcodeString + textAfter );
+                 
+            } else if($("#content").css("display") === "none") {
                 function insert_tag(text){
-                if(tinyMCE && tinyMCE.activeEditor)
-                {
-                   tinyMCE.activeEditor.selection.setContent(text);
-                }
-                    return false;
+                    if(tinyMCE && tinyMCE.activeEditor)
+                    {
+                        tinyMCE.activeEditor.selection.setContent(text);
+                    }
+                        return false;
                 }
+            }
                 insert_tag(shortcodeString);
-//            }
-
-        } else {
+            } else {
             alert("Please Select a Shortcode");
         }
     });