1/** 2 * @author Falchenko Maxim aka be3 3 * @plugin_page http://tops.net.ua/jquery_addtocopy/ 4 * @desc Adds a link to the copied text 5 * @version 1.2 6 * @example 7 * $("#content").addtocopy(); 8 * @license free 9 **/ 10jQuery.fn.addtocopy = function (usercopytxt) { 11 var options = { htmlcopytxt: '<br>More: <a href="' + window.location.href + '">' + window.location.href + '</a><br>', minlen: 25, addcopyfirst: false } 12 $.extend(options, usercopytxt); 13 var copy_sp = document.createElement('span'); 14 copy_sp.id = 'ctrlcopy'; 15 copy_sp.innerHTML = options.htmlcopytxt; 16 return this.each(function () { 17 $(this).mousedown(function () { $('#ctrlcopy').remove(); }); 18 $(this).mouseup(function () { 19 if (window.getSelection) { //good times 20 var slcted = window.getSelection(); 21 var seltxt = slcted.toString(); 22 if (!seltxt || seltxt.length < options.minlen) return; 23 var nslct = slcted.getRangeAt(0); 24 seltxt = nslct.cloneRange(); 25 seltxt.collapse(options.addcopyfirst); 26 seltxt.insertNode(copy_sp); 27 if (!options.addcopyfirst) nslct.setEndAfter(copy_sp); 28 slcted.removeAllRanges(); 29 slcted.addRange(nslct); 30 } else if (document.selection) { //bad times 31 var slcted = document.selection; 32 var nslct = slcted.createRange(); 33 var seltxt = nslct.text; 34 if (!seltxt || seltxt.length < options.minlen) return; 35 seltxt = nslct.duplicate(); 36 seltxt.collapse(options.addcopyfirst); 37 seltxt.pasteHTML(copy_sp.outerHTML); 38 if (!options.addcopyfirst) { nslct.setEndPoint("EndToEnd", seltxt); nslct.select(); } 39 } 40 }); 41 }); 42}
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.