1/** 2* 2007-2025 PrestaShop 3* 4* NOTICE OF LICENSE 5* 6* This source file is subject to the Academic Free License (AFL 3.0) 7* that is bundled with this package in the file LICENSE.txt. 8* It is also available through the world-wide-web at this URL: 9* http://opensource.org/licenses/afl-3.0.php 10* If you did not receive a copy of the license and are unable to 11* obtain it through the world-wide-web, please send an email 12* to [email protected] so we can send you a copy immediately. 13* 14* DISCLAIMER 15* 16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer 17* versions in the future. If you wish to customize PrestaShop for your 18* needs please refer to http://www.prestashop.com for more information. 19* 20* @author PrestaShop SA <[email protected]> 21* @copyright 2007-2025 PrestaShop SA 22* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 23* International Registered Trademark & Property of PrestaShop SA 24*/ 25 26(function($){ 27 $.fn.textareaCount = function(options, fn) { 28 var defaults = { 29 maxCharacterSize: -1, 30 originalStyle: 'originalTextareaInfo', 31 warningStyle: 'warningTextareaInfo', 32 warningNumber: 20, 33 displayFormat: '#input characters | #words words' 34 }; 35 var options = $.extend(defaults, options); 36 37 var container = $(this); 38 39 $("<div class='charleft'> </div>").insertAfter(container); 40 41 //create charleft css 42 var charLeftCss = { 43 'width' : container.width() 44 }; 45 46 var charLeftInfo = getNextCharLeftInformation(container); 47 charLeftInfo.addClass(options.originalStyle); 48 charLeftInfo.css(charLeftCss); 49 50 var numInput = 0; 51 var maxCharacters = options.maxCharacterSize; 52 var numLeft = 0; 53 var numWords = 0; 54 55 container.bind('keyup', function(event){limitTextAreaByCharacterCount();}) 56 .bind('mouseover', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);}) 57 .bind('paste', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);}); 58 59 60 function limitTextAreaByCharacterCount(){ 61 charLeftInfo.html(countByCharacters()); 62 //function call back 63 if(typeof fn != 'undefined'){ 64 fn.call(this, getInfo()); 65 } 66 return true; 67 } 68 69 function countByCharacters(){ 70 var content = container.val(); 71 var contentLength = content.length; 72 73 //Start Cut 74 if(options.maxCharacterSize > 0){ 75 //If copied content is already more than maxCharacterSize, chop it to maxCharacterSize. 76 if(contentLength >= options.maxCharacterSize) { 77 content = content.substring(0, options.maxCharacterSize); 78 } 79 80 var newlineCount = getNewlineCount(content); 81 82 // newlineCount new line character. For windows, it occupies 2 characters 83 var systemmaxCharacterSize = options.maxCharacterSize - newlineCount; 84 if (!isWin()){ 85 systemmaxCharacterSize = options.maxCharacterSize 86 } 87 if(contentLength > systemmaxCharacterSize){ 88 //avoid scroll bar moving 89 var originalScrollTopPosition = this.scrollTop; 90 container.val(content.substring(0, systemmaxCharacterSize)); 91 this.scrollTop = originalScrollTopPosition; 92 } 93 charLeftInfo.removeClass(options.warningStyle); 94 if(systemmaxCharacterSize - contentLength <= options.warningNumber){ 95 charLeftInfo.addClass(options.warningStyle); 96 } 97 98 numInput = container.val().length + newlineCount; 99 if(!isWin()){ 100 numInput = container.val().length; 101 } 102 103 numWords = countWord(getCleanedWordString(container.val())); 104 105 numLeft = maxCharacters - numInput; 106 } else { 107 //normal count, no cut 108 var newlineCount = getNewlineCount(content); 109 numInput = container.val().length + newlineCount; 110 if(!isWin()){ 111 numInput = container.val().length; 112 } 113 numWords = countWord(getCleanedWordString(container.val())); 114 } 115 116 return formatDisplayInfo(); 117 } 118 119 function formatDisplayInfo(){ 120 var format = options.displayFormat; 121 format = format.replace('#input', numInput); 122 format = format.replace('#words', numWords); 123 //When maxCharacters <= 0, #max, #left cannot be substituted. 124 if(maxCharacters > 0){ 125 format = format.replace('#max', maxCharacters); 126 format = format.replace('#left', numLeft); 127 } 128 return format; 129 } 130 131 function getInfo(){ 132 var info = { 133 input: numInput, 134 max: maxCharacters, 135 left: numLeft, 136 words: numWords 137 }; 138 return info; 139 } 140 141 function getNextCharLeftInformation(container){ 142 return container.next('.charleft'); 143 } 144 145 function isWin(){ 146 var strOS = navigator.appVersion; 147 if (strOS.toLowerCase().indexOf('win') != -1){ 148 return true; 149 } 150 return false;
151 } 152 153 function getNewlineCount(content){ 154 var newlineCount = 0; 155 for(var i=0; i<content.length;i++){ 156 if(content.charAt(i) == '\n'){ 157 newlineCount++; 158 } 159 } 160 return newlineCount; 161 } 162 163 function getCleanedWordString(content){ 164 var fullStr = content + " "; 165 var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 166 var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 167 var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 168 var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 169 var splitString = cleanedStr.split(" "); 170 return splitString; 171 } 172 173 function countWord(cleanedWordString){ 174 var word_count = cleanedWordString.length-1; 175 return word_count; 176 } 177 }; 178})(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.