]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/text.js
internal: an alternative to default_focus
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / text.js
1 dump('entering util/text.js\n');
2
3 if (typeof util == 'undefined') var util = {};
4 util.text = {};
5
6 util.text.EXPORT_OK    = [ 
7     'wrap_on_space', 'preserve_string_in_html',
8 ];
9 util.text.EXPORT_TAGS    = { ':all' : util.text.EXPORT_OK };
10
11 util.text.wrap_on_space = function( text, length ) {
12     try {
13
14         if (String(text).length <= length) return [ text, '' ];
15
16         var truncated_text = String(text).substr(0,length);
17
18         var pivot_pos = truncated_text.lastIndexOf(' ');
19
20         return [ text.substr(0,pivot_pos).replace(/\s*$/,''), String(text).substr(pivot_pos+1) ];
21
22     } catch(E) {
23         alert('FIXME: util.text.wrap_on_space( "' + text + '", ' + length + ")");
24         return [ String(text).substr(0,length), String(text).substr(length) ];
25     }
26 }
27
28 util.text.preserve_string_in_html = function( text ) {
29     text = text.replace(/&/g,'&amp;');
30     text = text.replace(/"/g,'&quot;');
31     text = text.replace(/'/g,'&#39;');
32     text = text.replace(/ /g,'&nbsp;');
33     text = text.replace(/</g,'&lt;');
34     text = text.replace(/>/g,'&gt;');
35     return text;
36 }
37
38 util.text.reverse_preserve_string_in_html = function( text ) {
39     text = text.replace(/&amp;/g, '&');
40     text = text.replace(/&quot;/g, '"');
41     text = text.replace(/&#39;/g, "'");
42     text = text.replace(/&nbsp;/g, ' ');
43     text = text.replace(/&lt;/g, '<');
44     text = text.replace(/&gt;/g, '>');
45     return text;
46 }
47
48 dump('exiting util/text.js\n');