Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.dtl.filter.htmlstrings"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.dtl.filter.htmlstrings"] = true;
3
dojo.provide("dojox.dtl.filter.htmlstrings");
4
 
5
dojo.require("dojox.dtl._base");
6
 
7
dojo.mixin(dojox.dtl.filter.htmlstrings, {
8
	_escapeamp: /&/g,
9
	_escapelt: /</g,
10
	_escapegt: />/g,
11
	_escapeqt: /'/g,
12
	_escapedblqt: /"/g,
13
	_linebreaksrn: /(\r\n|\n\r)/g,
14
	_linebreaksn: /\n{2,}/g,
15
	_linebreakss: /(^\s+|\s+$)/g,
16
	_linebreaksbr: /\n/g,
17
	_removetagsfind: /[a-z0-9]+/g,
18
	_striptags: /<[^>]*?>/g,
19
	escape: function(value){
20
		// summary: Escapes a string's HTML
21
		var dh = dojox.dtl.filter.htmlstrings;
22
		return value.replace(dh._escapeamp, '&amp;').replace(dh._escapelt, '&lt;').replace(dh._escapegt, '&gt;').replace(dh._escapedblqt, '&quot;').replace(dh._escapeqt, '&#39;');
23
	},
24
	linebreaks: function(value){
25
		// summary: Converts newlines into <p> and <br />s
26
		var output = [];
27
		var dh = dojox.dtl.filter.htmlstrings;
28
		value = value.replace(dh._linebreaksrn, "\n");
29
		var parts = value.split(dh._linebreaksn);
30
		for(var i = 0; i < parts.length; i++){
31
			var part = parts[i].replace(dh._linebreakss, "").replace(dh._linebreaksbr, "<br />")
32
			output.push("<p>" + part + "</p>");
33
		}
34
 
35
		return output.join("\n\n");
36
	},
37
	linebreaksbr: function(value){
38
		// summary: Converts newlines into <br />s
39
		var dh = dojox.dtl.filter.htmlstrings;
40
		return value.replace(dh._linebreaksrn, "\n").replace(dh._linebreaksbr, "<br />");
41
	},
42
	removetags: function(value, arg){
43
		// summary: Removes a space separated list of [X]HTML tags from the output"
44
		var dh = dojox.dtl.filter.htmlstrings;
45
		var tags = [];
46
		var group;
47
		while(group = dh._removetagsfind.exec(arg)){
48
			tags.push(group[0]);
49
		}
50
		tags = "(" + tags.join("|") + ")";
51
		return value.replace(new RegExp("</?\s*" + tags + "\s*[^>]*>", "gi"), "");
52
	},
53
	striptags: function(value){
54
		// summary: Strips all [X]HTML tags
55
		return value.replace(dojox.dtl.filter.htmlstrings._striptags, "");
56
	}
57
});
58
 
59
}