1/* 2 * jQuery plugin: fieldSelection - v0.1.1 - last change: 2006-12-16 3 * (c) 2006 Alex Brem <[email protected]> - http://blog.0xab.cd 4 */ 5 6(function() { 7 8 var fieldSelection = { 9 10 getSelection: function() { 11 12 var e = (this.jquery) ? this[0] : this; 13 14 return ( 15 16 /* mozilla / dom 3.0 */ 17 ('selectionStart' in e && function() { 18 var l = e.selectionEnd - e.selectionStart; 19 return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) }; 20 }) || 21 22 /* exploder */ 23 (document.selection && function() { 24 25 e.focus(); 26 27 var r = document.selection.createRange(); 28 if (r === null) { 29 return { start: 0, end: e.value.length, length: 0 } 30 } 31 32 var re = e.createTextRange(); 33 var rc = re.duplicate(); 34 re.moveToBookmark(r.getBookmark()); 35 rc.setEndPoint('EndToStart', re); 36 37 return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text }; 38 }) || 39 40 /* browser not supported */ 41 function() { return null; } 42 43 )(); 44 45 }, 46 47 setSelection: function(start, end) { 48 var e = document.getElementById($(this).attr('id')); // I don't know why... but $(this) don't want to work today :-/ 49 if (!e) { 50 return $(this); 51 } else if (e.setSelectionRange) { /* WebKit */ 52 e.focus(); e.setSelectionRange(start, end); 53 } else if (e.createTextRange) { /* IE */ 54 var range = e.createTextRange(); 55 range.collapse(true); 56 range.moveEnd('character', end); 57 range.moveStart('character', start); 58 range.select(); 59 } else if (e.selectionStart) { /* Others */ 60 e.selectionStart = start; 61 e.selectionEnd = end; 62 } 63 64 return $(this); 65 }, 66 67 replaceSelection: function() { 68 69 var e = (typeof this.id == 'function') ? this.get(0) : this; 70 var text = arguments[0] || ''; 71 72 return ( 73 74 /* mozilla / dom 3.0 */ 75 ('selectionStart' in e && function() { 76 e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length); 77 return this; 78 }) || 79 80 /* exploder */ 81 (document.selection && function() { 82 e.focus(); 83 document.selection.createRange().text = text; 84 return this; 85 }) || 86 87 /* browser not supported */ 88 function() { 89 e.value += text; 90 return jQuery(e); 91 } 92 93 )(); 94 95 } 96 97 }; 98 99 jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; }); 100 101})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.