]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/plugins/wordcount/plugin.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / plugins / wordcount / plugin.js
1 /**
2  * plugin.js
3  *
4  * Copyright, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://www.tinymce.com/license
8  * Contributing: http://www.tinymce.com/contributing
9  */
10
11 /*global tinymce:true */
12
13 tinymce.PluginManager.add('wordcount', function(editor) {
14         var self = this, countre, cleanre;
15
16         countre = editor.getParam('wordcount_countregex', /[\w\u2019\x27\-]+/g); // u2019 == ’
17         cleanre = editor.getParam('wordcount_cleanregex', /[0-9.(),;:!?%#$?\x27\x22_+=\\\/\-]*/g);
18
19         function update() {
20                 editor.theme.panel.find('#wordcount').text(['Words: {0}', self.getCount()]);
21         }
22
23         editor.on('init', function() {
24                 var statusbar = editor.theme.panel && editor.theme.panel.find('#statusbar')[0];
25
26                 if (statusbar) {
27                         window.setTimeout(function() {
28                                 statusbar.insert({
29                                         type: 'label',
30                                         name: 'wordcount',
31                                         text: ['Words: {0}', self.getCount()],
32                                         classes: 'wordcount'
33                                 }, 0);
34
35                                 editor.on('setcontent beforeaddundo', update);
36
37                                 editor.on('keyup', function(e) {
38                                         if (e.keyCode == 32) {
39                                                 update();
40                                         }
41                                 });
42                         }, 0);
43                 }
44         });
45
46         self.getCount = function() {
47                 var tx = editor.getContent({format: 'raw'});
48                 var tc = 0;
49
50                 if (tx) {
51                         tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces
52                         tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' '); // remove html tags and space chars
53
54                         // deal with html entities
55                         tx = tx.replace(/(\w+)(&.+?;)+(\w+)/, "$1$3").replace(/&.+?;/g, ' ');
56                         tx = tx.replace(cleanre, ''); // remove numbers and punctuation
57
58                         var wordArray = tx.match(countre);
59                         if (wordArray) {
60                                 tc = wordArray.length;
61                         }
62                 }
63
64                 return tc;
65         };
66 });