forked from flamejs/flame.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompatibility.js
47 lines (43 loc) · 1.7 KB
/
compatibility.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// In IE7, Range is not defined, which Metamorph handles with a fallback
if (typeof Range !== "undefined") {
// In IE9, Range is defined but createContextualFragment is not, which Metamorph doesn't handle
// From http://stackoverflow.com/questions/5375616/extjs4-ie9-object-doesnt-support-property-or-method-createcontextualfragme
if (typeof Range.prototype.createContextualFragment === "undefined") {
Range.prototype.createContextualFragment = function(html) {
var doc = this.startContainer.ownerDocument;
var container = doc.createElement("div");
container.innerHTML = html;
var frag = doc.createDocumentFragment(), n;
while ( (n = container.firstChild) ) {
frag.appendChild(n);
}
return frag;
};
}
}
if (String.prototype.trim === undefined) {
String.prototype.trim = function() {
return jQuery.trim(this);
};
}
//nicked from stack overflow http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
function selectText(element) {
var doc = document;
var text = doc.getElementById(element);
var range = null;
if (doc.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
if (selection.setBaseAndExtent) {
selection.setBaseAndExtent(text, 0, text, 1);
} else {
range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
}