1(function ($) { 2 $.fn.ellipsis = function (options) { 3 4 // default option 5 var defaults = { 6 'row': 1, // show rows 7 'onlyFullWords': false, // set to true to avoid cutting the text in the middle of a word 8 'char': '...', // ellipsis 9 'callback': function () { }, 10 'position': 'tail' // middle, tail 11 }; 12 13 options = $.extend(defaults, options); 14 15 this.each(function () { 16 // get element text 17 var $this = $(this); 18 var text = $this.text(); 19 var origText = text; 20 var origLength = origText.length; 21 var origHeight = $this.height(); 22 23 // get height 24 $this.text('a'); 25 var lineHeight = parseFloat($this.css("lineHeight"), 10); 26 var rowHeight = $this.height(); 27 var gapHeight = lineHeight > rowHeight ? (lineHeight - rowHeight) : 0; 28 var targetHeight = gapHeight * (options.row - 1) + rowHeight * options.row; 29 30 if (origHeight <= targetHeight) { 31 $this.text(text); 32 options.callback.call(this); 33 return; 34 } 35 36 var start = 1, length = 0; 37 var end = text.length; 38 39 if (options.position === 'tail') { 40 while (start < end) { // Binary search for max length 41 length = Math.ceil((start + end) / 2); 42 43 $this.text(text.slice(0, length) + options['char']); 44 45 if ($this.height() <= targetHeight) { 46 start = length; 47 } else { 48 end = length - 1; 49 } 50 } 51 52 text = text.slice(0, start); 53 54 if (options.onlyFullWords) { 55 text = text.replace(/[\u00AD\w\uac00-\ud7af]+$/, ''); // remove fragment of the last word together with possible soft-hyphen characters 56 } 57 text += options['char']; 58 59 } else if (options.position === 'middle') { 60 61 var sliceLength = 0; 62 while (start < end) { // Binary search for max length 63 length = Math.ceil((start + end) / 2); 64 sliceLength = Math.max(origLength - length, 0); 65 66 $this.text( 67 origText.slice(0, Math.floor((origLength - sliceLength) / 2)) + 68 options['char'] + 69 origText.slice(Math.floor((origLength + sliceLength) / 2), origLength) 70 ); 71 72 if ($this.height() <= targetHeight) { 73 start = length; 74 } else { 75 end = length - 1; 76 } 77 } 78 79 sliceLength = Math.max(origLength - start, 0); 80 var head = origText.slice(0, Math.floor((origLength - sliceLength) / 2)); 81 var tail = origText.slice(Math.floor((origLength + sliceLength) / 2), origLength); 82 83 if (options.onlyFullWords) { 84 // remove fragment of the last or first word together with possible soft-hyphen characters 85 head = head.replace(/[\u00AD\w\uac00-\ud7af]+$/, ''); 86 } 87 88 text = head + options['char'] + tail; 89 } 90 91 $this.text(text); 92 93 options.callback.call(this); 94 }); 95 96 return this; 97 }; 98})(jQuery);
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.