-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathampersand_plugin.js
More file actions
25 lines (25 loc) · 885 Bytes
/
ampersand_plugin.js
File metadata and controls
25 lines (25 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(function($){
$.fn.ampersand = function(ampClass) {
if (ampClass === undefined) {
ampClass = "ampersand";
}
var get_contents = function(el) {
$(el).contents().each(function(i,el) {
if (el.nodeType === 3) {
if (el.textContent) {
el.textContent = el.textContent.replace(/&/g, "#ampersandmarker#")
} else if (el.text) /* IE */ {
el.text = el.text.replace(/&/g, "#ampersandmarker#")
}
} else if (el.nodeType === 1) {
get_contents(el);
}
});
}
$(this).each(function(i, el) {
get_contents(el); /* Walk the dom finding only ampersands in text nodes. Don't bother splitting them. */
el.innerHTML = el.innerHTML.replace(/#ampersandmarker#/g, "<span class='"+ampClass+"'>&</span>") /* replace the markers. */
});
return this;
};
})(jQuery);;