ui_scripts
Differences
This shows you the differences between two versions of the page.
| ui_scripts [12/30/2024 06:34] – created johnsonjohn | ui_scripts [12/31/2025 05:42] (current) – removed johnsonjohn | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | =====UI SCRIPTS===== | ||
| - | ---- | ||
| - | ====Enable Syntax Editor Macros==== | ||
| - | < | ||
| - | <?xml version=" | ||
| - | <unload unload_date=" | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | | ||
| - | //object to store macros in | ||
| - | var macrosObj={ | ||
| - | }; | ||
| - | | ||
| - | var fn = function(e){ | ||
| - | var keyCode = e.keyCode || e.which; | ||
| - | | ||
| - | //check if key pressed is TAB | ||
| - | if (keyCode == 9) { | ||
| - | | ||
| - | //get DOM element for active pane | ||
| - | var cmEl = jQuery(document.activeElement).parents(' | ||
| - | | ||
| - | //get CodeMirror object for active pane. CodeMirror is the Syntax Editor library used in the Widget Editor | ||
| - | var cmObj = cmEl.CodeMirror; | ||
| - | | ||
| - | //get position of cursor and end of line | ||
| - | var tmpCursor=cmObj.getCursor(); | ||
| - | var eol=cmObj.getLine(tmpCursor.line).length; | ||
| - | | ||
| - | //do nothing if cursor is not at end of line | ||
| - | //this allows users to continue using TAB key for formatting/ | ||
| - | if(tmpCursor.ch < eol){ | ||
| - | return true; | ||
| - | } | ||
| - | | ||
| - | //do nothing if any text is selected | ||
| - | if(cmObj.somethingSelected()){ | ||
| - | return true; | ||
| - | } | ||
| - | | ||
| - | //find the start and end position of the word preceeding the cursor | ||
| - | var wordObj = cmObj.findWordAt({ | ||
| - | line: tmpCursor.line, | ||
| - | ch: tmpCursor.ch-2 | ||
| - | }); | ||
| - | | ||
| - | //get the actual word preceeding the cursor | ||
| - | var word = cmObj.getRange(wordObj.anchor, | ||
| - | | ||
| - | //do nothing if a corresponding Syntax Editor Macro does not exist | ||
| - | if(typeof macrosObj[word]===' | ||
| - | return true; | ||
| - | | ||
| - | //select the word preceeding the cursor | ||
| - | var sel = cmObj.setSelection(wordObj.anchor, | ||
| - | | ||
| - | //replace selection with the text of the Syntax Editor Macro | ||
| - | cmObj.replaceSelection( macrosObj[word].text ); | ||
| - | } | ||
| - | }; | ||
| - | | ||
| - | //add keyup event listener | ||
| - | jQuery(window).on(' | ||
| - | | ||
| - | //populate macrosObj with records from the Syntax Editor Macro table | ||
| - | var requestBody = ""; | ||
| - | var client=new XMLHttpRequest(); | ||
| - | client.open(" | ||
| - | | ||
| - | client.setRequestHeader(' | ||
| - | client.setRequestHeader(' | ||
| - | client.setRequestHeader(' | ||
| - | | ||
| - | var rsc = function(){ | ||
| - | if(this.readyState == this.DONE) { | ||
| - | var rspObj=JSON.parse(this.response).result; | ||
| - | for(var macro in rspObj){ | ||
| - | if(!rspObj.hasOwnProperty(macro)) | ||
| - | continue; | ||
| - | | ||
| - | var currentMacro=rspObj[macro]; | ||
| - | macrosObj[currentMacro.name]=currentMacro; | ||
| - | } | ||
| - | } | ||
| - | }; | ||
| - | | ||
| - | client.onreadystatechange = rsc; | ||
| - | client.send(requestBody); | ||
| - | })(); | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | < | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | ====Next Script==== | ||
| - | < | ||
| - | |||
| - | </ | ||
| - | ---- | ||
ui_scripts.1735569277.txt.gz · Last modified: by johnsonjohn
