12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset=utf-8 />
- <title>Tabify Textareas Bookmarklet</title>
- <style type="text/css">
- body {
- font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
- color: black;
- background: white none;
- }
- .tip {
- color: #888;
- }
- .bml {
- padding: .2em .4em;
- display: inline-block;
- margin-right: 0.4em;
- text-decoration: none;
- color: black;
- border-radius: 1em;
- background: #ddd;
- background: #ddd -moz-linear-gradient(#eee, #ccc);
- background: #ddd -webkit-linear-gradient(#eee, #ccc);
- background: #ddd linear-gradient(#eee, #ccc);
- }
- </style>
- </head>
- <body>
-
- <h1>Tabify Textareas Bookmarklet</h1>
- <a class="bml" href="javascript:(function(){function a(){(function(i){i.fn.tabby=function(k){var e=i.extend({},i.fn.tabby.defaults,k);var d=i.fn.tabby.pressed;return this.each(function(){$this=i(this);var l=i.meta?i.extend({},e,$this.data()):e;$this.bind("keydown",function(m){var n=i.fn.tabby.catch_kc(m);if(16==n){d.shft=true}if(17==n){d.ctrl=true;setTimeout("$.fn.tabby.pressed.ctrl = false;",1000)}if(18==n){d.alt=true;setTimeout("$.fn.tabby.pressed.alt = false;",1000)}if(9==n&&!d.ctrl&&!d.alt){m.preventDefault;d.last=n;setTimeout("$.fn.tabby.pressed.last = null;",0);h(i(m.target).get(0),d.shft,l);return false}}).bind("keyup",function(m){if(16==i.fn.tabby.catch_kc(m)){d.shft=false}}).bind("blur",function(m){if(9==d.last){i(m.target).one("focus",function(n){d.last=null}).get(0).focus()}})})};i.fn.tabby.catch_kc=function(d){return d.keyCode?d.keyCode:d.charCode?d.charCode:d.which};i.fn.tabby.pressed={shft:false,ctrl:false,alt:false,last:null};function f(d){if(window.console&&window.console.log){window.console.log("textarea count: "+d.size())}}function h(d,e,k){var l=d.scrollTop;if(d.setSelectionRange){g(d,e,k)}else{if(document.selection){j(d,e,k)}}d.scrollTop=l}i.fn.tabby.defaults={tabString:String.fromCharCode(9)};function g(A,D,F){var G=A.selectionStart;var d=A.selectionEnd;if(G==d){if(D){if(G-F.tabString==A.value.substring(G-F.tabString.length,G)){A.value=A.value.substring(0,G-F.tabString.length)+A.value.substring(G);A.focus();A.setSelectionRange(G-F.tabString.length,G-F.tabString.length)}else{if(G-F.tabString==A.value.substring(G,G+F.tabString.length)){A.value=A.value.substring(0,G)+A.value.substring(G+F.tabString.length);A.focus();A.setSelectionRange(G,G)}}}else{A.value=A.value.substring(0,G)+F.tabString+A.value.substring(G);A.focus();A.setSelectionRange(G+F.tabString.length,G+F.tabString.length)}}else{while(G<A.value.length&&A.value.charAt(G).match(/[ \t]/)){G++}var E=A.value.split("\n");var H=new Array();var y=0;var B=0;var C=false;for(var w in E){B=y+E[w].length;H.push({start:y,end:B,selected:(y<=G&&B>G)||(B>=d&&y<d)||(y>G&&B<d)});y=B+1}var z=0;for(var w in H){if(H[w].selected){var e=H[w].start+z;if(D&&F.tabString==A.value.substring(e,e+F.tabString.length)){A.value=A.value.substring(0,e)+A.value.substring(e+F.tabString.length);z-=F.tabString.length}else{if(!D){A.value=A.value.substring(0,e)+F.tabString+A.value.substring(e);z+=F.tabString.length}}}}A.focus();var o=G+((z>0)?F.tabString.length:(z<0)?-F.tabString.length:0);var x=d+z;A.setSelectionRange(o,x)}}function j(G,A,P){var H=document.selection.createRange();if(G==H.parentElement()){if(""==H.text){if(A){var K=H.getBookmark();H.moveStart("character",-P.tabString.length);if(P.tabString==H.text){H.text=""}else{H.moveToBookmark(K);H.moveEnd("character",P.tabString.length);if(P.tabString==H.text){H.text=""}}H.collapse(true);H.select()}else{H.text=P.tabString;H.collapse(false);H.select()}}else{var L=H.text;var I=L.length;var C=L.split("\r\n");var d=document.body.createTextRange();d.moveToElementText(G);d.setEndPoint("EndToStart",H);var J=d.text;var o=J.split("\r\n");var F=J.length;var e=document.body.createTextRange();e.moveToElementText(G);e.setEndPoint("StartToEnd",H);var B=e.text;var O=document.body.createTextRange();O.moveToElementText(G);O.setEndPoint("StartToEnd",d);var E=O.text;var N=i(G).html();i("#r3").text(F+" + "+I+" + "+B.length+" = "+N.length);if((F+E.length)<N.length){o.push("");F+=2;if(A&&P.tabString==C[0].substring(0,P.tabString.length)){C[0]=C[0].substring(P.tabString.length)}else{if(!A){C[0]=P.tabString+C[0]}}}else{if(A&&P.tabString==o[o.length-1].substring(0,P.tabString.length)){o[o.length-1]=o[o.length-1].substring(P.tabString.length)}else{if(!A){o[o.length-1]=P.tabString+o[o.length-1]}}}for(var D=1;D<C.length;D++){if(A&&P.tabString==C[D].substring(0,P.tabString.length)){C[D]=C[D].substring(P.tabString.length)}else{if(!A){C[D]=P.tabString+C[D]}}}if(1==o.length&&0==F){if(A&&P.tabString==C[0].substring(0,P.tabString.length)){C[0]=C[0].substring(P.tabString.length)}else{if(!A){C[0]=P.tabString+C[0]}}}if((F+I+B.length)<N.length){C.push("");I+=2}d.text=o.join("\r\n");H.text=C.join("\r\n");var M=document.body.createTextRange();M.moveToElementText(G);if(0<F){M.setEndPoint("StartToEnd",d)}else{M.setEndPoint("StartToStart",d)}M.setEndPoint("EndToEnd",H);M.select()}}}})(window.jQuery);window.jQuery("textarea").tabby({tabString:" "})}function c(){if(window.jQuery){a()}else{window.setTimeout(c,100)}}if(window.jQuery){a()}else{var b=document.createElement("script");b.setAttribute("src","http://code.jquery.com/jquery-1.5.2.min.js");document.getElementsByTagName("body")[0].appendChild(b);c()}})();">Tabify Textareas</a> <span class="tip">← Drag to your bookmark bar!</span>
-
- <br /><br />
- <textarea name="textarea" rows="4" cols="100" wrap="wrap">Try Me Out
-
- Click the bookmarklet and then use tabs within this textarea!
- </textarea>
- </body>
- </html>
|