PageSourceSearch

https://montessoriparatodos.es/modules/correosexpress/views/js/textareaCounter.js

js montessoriparatodos.es collected 2026-10-03 23:14:59 UTC 6,540 bytes, 162 lines download raw bytes

1/*�
2 * jQuery Textarea Characters Counter Plugin v 2.0�
3 * Examples and documentation at: http://roy-jin.appspot.com/jsp/textareaCounter.jsp�
4 * Copyright (c) 2010 Roy Jin�
5 * Version: 2.0 (11-JUN-2010)�
6 * Dual licensed under the MIT and GPL licenses:�
7 * http://www.opensource.org/licenses/mit-license.php�
8 * http://www.gnu.org/licenses/gpl.html�
9 * Requires: jQuery v1.4.2 or later�
10 */�
11(function($){  �
12    $.fn.textareaCount = function(options, fn) {   �
13        var defaults = {  �
14            maxCharacterSize: -1,  �
15            originalStyle: 'originalTextareaInfo',�
16            warningStyle: 'warningTextareaInfo',  �
17            warningNumber: 20,�
18            displayFormat: '#input caracteres | #words palabras'�
19        };  �
20        var options = $.extend(defaults, options);�
21        �
22        var container = $(this);�
23        �
24        $("<div class='charleft'>&nbsp;</div>").insertAfter(container);�
25        �
26        //create charleft css�
27        var charLeftCss = {�
28            'width' : container.width()�
29        };�
30        �
31        var charLeftInfo = getNextCharLeftInformation(container);�
32        charLeftInfo.addClass(options.originalStyle);�
33        charLeftInfo.css(charLeftCss);�
34        �
35        var numInput = 0;�
36        var maxCharacters = options.maxCharacterSize;�
37        var numLeft = 0;�
38        var numWords = 0;�
39                �
40        container.bind('keyup', function(event){limitTextAreaByCharacterCount();})�
41                 .bind('mouseover', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);})�
42                 .bind('paste', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);});�
43        �
44        function limitTextAreaByCharacterCount(){�
45            charLeftInfo.html(countByCharacters());�
46            //function call back�
47            if(typeof fn != 'undefined'){�
48                fn.call(this, getInfo());�
49            }�
50            return true;�
51        }�
52        �
53        function countByCharacters(){�
54            var content = container.val();�
55            var contentLength = content.length;�
56            �
57            //Start Cut�
58            if(options.maxCharacterSize > 0){�
59                //If copied content is already more than maxCharacterSize, chop it to maxCharacterSize.�
60                if(contentLength >= options.maxCharacterSize) {�
61                    content = content.substring(0, options.maxCharacterSize);                 �
62                }�
63                �
64                var newlineCount = getNewlineCount(content);�
65                �
66                // newlineCount new line character. For windows, it occupies 2 characters�
67                var systemmaxCharacterSize = options.maxCharacterSize - newlineCount;�
68                if (!isWin()){�
69                     systemmaxCharacterSize = options.maxCharacterSize�
70                }�
71                if(contentLength > systemmaxCharacterSize){�
72                    //avoid scroll bar moving�
73                    var originalScrollTopPosition = this.scrollTop;�
74                    container.val(content.substring(0, systemmaxCharacterSize));�
75                    this.scrollTop = originalScrollTopPosition;�
76                }�
77                charLeftInfo.removeClass(options.warningStyle);�
78                if(systemmaxCharacterSize - contentLength <= options.warningNumber){�
79                    charLeftInfo.addClass(options.warningStyle);�
80                }�
81                �
82                numInput = container.val().length + newlineCount;�
83                if(!isWin()){�
84                    numInput = container.val().length;�
85                }�
86            �
87                numWords = countWord(getCleanedWordString(container.val()));�
88                �
89                numLeft = maxCharacters - numInput;�
90            } else {�
91                //normal count, no cut�
92                var newlineCount = getNewlineCount(content);�
93                numInput = container.val().length + newlineCount;�
94                if(!isWin()){�
95                    numInput = container.val().length;�
96                }�
97                numWords = countWord(getCleanedWordString(container.val()));�
98            }�
99            �
100            return formatDisplayInfo();�
101        }�
102        �
103        function formatDisplayInfo(){�
104            var format = options.displayFormat;�
105            format = format.replace('#input', numInput);�
106            format = format.replace('#words', numWords);�
107            //When maxCharacters <= 0, #max, #left cannot be substituted.�
108            if(maxCharacters > 0){�
109                format = format.replace('#max', maxCharacters);�
110                format = format.replace('#left', numLeft);�
111            }�
112            return format;�
113        }�
114        �
115        function getInfo(){�
116            var info = {�
117                input: numInput,�
118                max: maxCharacters,�
119                left: numLeft,�
120                words: numWords�
121            };�
122            return info;�
123        }�
124        �
125        function getNextCharLeftInformation(container){�
126                return container.next('.charleft');�
127        }�
128        �
129        function isWin(){�
130            var strOS = navigator.appVersion;�
131            if (strOS.toLowerCase().indexOf('win') != -1){�
132                return true;�
133            }�
134            return false;�
135        }�
136        �
137        function getNewlineCount(content){�
138            var newlineCount = 0;�
139            for(var i=0; i<content.length;i++){�
140                if(content.charAt(i) == '\n'){�
141                    newlineCount++;�
142                }�
143            }�
144            return newlineCount;�
145        }�
146        �
147        function getCleanedWordString(content){�
148            var fullStr = content + " ";�
149            var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;�
150            var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");�
151            var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;�
152            var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");�
153            var splitString = cleanedStr.split(" ");�
154            return splitString;�
155        }�
156        �
157        function countWord(cleanedWordString){�
158            var word_count = cleanedWordString.length-1;�
159            return word_count;�
160        }�
161    };  �
162})(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.