We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20394
    • 134 Posts
    When I edit a chunkor a snippet, I’d like to use the tab key to make soft indentation.
    I have found a solution from a site of Greg Taff.
    For chunks (to adapt for snippets) :
    <textarea id="htmlta" name="post" style="width:100%; height: 370px;" onChange='documentDirty=true;'><?php echo htmlspecialchars($content['snippet']); ?></textarea>
    	</div>
    	<!-- HTML text editor end -->
    <input type="submit" name="save" style="display:none">
    </div>
    <script>
    function insert(input, theText) {
    	  if(typeof input.selectionStart != 'undefined')
    	  {
    	    var start = input.selectionStart;
    	    var end = input.selectionEnd;
    	    input.value = input.value.substr(0, start) + theText + input.value.substr(end);
    	   	input.selectionStart = start + theText.length;
    	   	input.selectionEnd = start + theText.length;
    		input.focus();
    	  }
    	}
    function keyDownHandler(e){
    		
    		/*  enable the tab key for the text areas */
    		
    		if(e.keyCode == 9){
    			var cacheScrollTop = e.target.scrollTop;
    			setTimeout("insert($('"+e.target.id+"'), unescape('%09'));", 0);
    			setTimeout("$('"+e.target.id+"').scrollTop = " + cacheScrollTop, 10);
    			return false;
    			}
    	}
    $("htmlta").onkeydown=keyDownHandler;
    
    </script>

    Note the attribute "id" for the textarea, and that this code makes use of prototype.js
      • 25663 MODX Staff
      • 12,272 Posts
      Very nice find indeed. Thanks for sharing.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 32963
        • 1,732 Posts
        Cool contribution. You might want to log it in feature request.
          xWisdom
          www.xwisdomhtml.com
          The fear of the Lord is the beginning of wisdom:
          MODx Co-Founder - Create and do more with less.