-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdom.js
More file actions
79 lines (70 loc) · 1.99 KB
/
Copy pathdom.js
File metadata and controls
79 lines (70 loc) · 1.99 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2006 Google Inc.
// All Rights Reserved
//
// Author: Bret Taylor
// Disables text selection for the given element.
function disableSelection(element) {
element.onselectstart = returnFalse;
element.unselectable = "on";
element.style.MozUserSelect = "none";
element.style.cursor = "default";
}
// Enables text selection for the given element.
function enableSelection(element) {
element.onselectstart = null;
element.unselectable = "off";
element.style.MozUserSelect = "";
}
// Sets the opacity of the given element to the given value (between 0 and 1)
function setOpacity(element, opacity) {
if (Browser.instance().isIEBased()) {
element.style.filter = "alpha(opacity=" + Math.round(opacity * 100) + ")";
} else {
element.style.opacity = opacity;
}
}
// Stops propagation of the event, but leaves the default action enabled.
function stopEvent(e) {
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
// Cancels the default action of the given event.
function cancelEvent(e) {
if (!e) e = window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
// Disables the right click context menu
function disableContextMenu(e) {
e.oncontextmenu = function() {
return false;
}
}
// Adds the given CSS class name to the given element.
function cssAddClass(element, className) {
cssClassManipulate(element, className, true);
}
// Removes the given CSS class name to the given element.
function cssRemoveClass(element, className) {
cssClassManipulate(element, className, false);
}
// Adds or removes the given CSS class name to the given element.
function cssClassManipulate(element, className, add) {
var classes = element.className.split(" ");
var newClasses = [];
for (var i = 0; i < classes.length; i++) {
if (classes[i] != className) {
newClasses.push(classes[i]);
}
}
if (add) {
newClasses.push(className);
}
element.className = newClasses.join(" ");
}