summaryrefslogtreecommitdiffstats
path: root/slider/css/boxsizing.htc
blob: fbeaa56c80908447c25ca00d9690826f3a9758d9 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<component lightWeight="true">
<attach event="onpropertychange" onevent="checkPropertyChange()" />
<attach event="ondetach" onevent="restore()" />
<script>
//<![CDATA[

var doc = element.document;

function init() {
	updateBorderBoxWidth();
	updateBorderBoxHeight();
}

function restore() {
	element.runtimeStyle.width = "";
	element.runtimeStyle.height = "";
}

/* border width getters */
function getBorderWidth(sSide) {
	if (element.currentStyle["border" + sSide + "Style"] == "none")
		return 0;
	var n = parseInt(element.currentStyle["border" + sSide + "Width"]);
	return n || 0;
}

function getBorderLeftWidth() { return getBorderWidth("Left"); }
function getBorderRightWidth() { return getBorderWidth("Right"); }
function getBorderTopWidth() { return getBorderWidth("Top"); }
function getBorderBottomWidth() { return getBorderWidth("Bottom"); }
/* end border width getters */

/* padding getters */
function getPadding(sSide) {
	var n = parseInt(element.currentStyle["padding" + sSide]);
	return n || 0;
}

function getPaddingLeft() { return getPadding("Left"); }
function getPaddingRight() { return getPadding("Right"); }
function getPaddingTop() { return getPadding("Top"); }
function getPaddingBottom() { return getPadding("Bottom"); }
/* end padding getters */

function getBoxSizing() {
	var s = element.style;
	var cs = element.currentStyle

	if (typeof s.boxSizing != "undefined" && s.boxSizing != "")
		return s.boxSizing;
	if (typeof s["box-sizing"] != "undefined" && s["box-sizing"] != "")
		return s["box-sizing"];
	if (typeof cs.boxSizing != "undefined" && cs.boxSizing != "")
		return cs.boxSizing;
	if (typeof cs["box-sizing"] != "undefined" && cs["box-sizing"] != "")
		return cs["box-sizing"];
	return getDocumentBoxSizing();
}

function getDocumentBoxSizing() {
	if (doc.compatMode == null || doc.compatMode == "BackCompat")
		return "border-box";
	return "content-box"
}

/* width and height setters */
function setBorderBoxWidth(n) {
	element.runtimeStyle.width = Math.max(0, n - getBorderLeftWidth() -
		getPaddingLeft() - getPaddingRight() - getBorderRightWidth()) + "px";
}

function setBorderBoxHeight(n) {
	element.runtimeStyle.height = Math.max(0, n - getBorderTopWidth() -
		getPaddingTop() - getPaddingBottom() - getBorderBottomWidth()) + "px";
}

function setContentBoxWidth(n) {
	element.runtimeStyle.width = Math.max(0, n + getBorderLeftWidth() +
		getPaddingLeft() + getPaddingRight() + getBorderRightWidth()) + "px";
}

function setContentBoxHeight(n) {
	element.runtimeStyle.height = Math.max(0, n + getBorderTopWidth() +
		getPaddingTop() + getPaddingBottom() + getBorderBottomWidth()) + "px";
}
/* end width and height setters */

function updateBorderBoxWidth() {
	element.runtimeStyle.width = "";
	if (getDocumentBoxSizing() == getBoxSizing())
		return;
	var csw = element.currentStyle.width;
	if (csw != "auto" && csw.indexOf("px") != -1) {
		if (getBoxSizing() == "border-box")
			setBorderBoxWidth(parseInt(csw));
		else
			setContentBoxWidth(parseInt(csw));
	}
}

function updateBorderBoxHeight() {
	element.runtimeStyle.height = "";	
	if (getDocumentBoxSizing() == getBoxSizing())
		return;
	var csh = element.currentStyle.height;
	if (csh != "auto" && csh.indexOf("px") != -1) {
		if (getBoxSizing() == "border-box")
			setBorderBoxHeight(parseInt(csh));
		else
			setContentBoxHeight(parseInt(csh));
	}
}

function checkPropertyChange() {
	var pn = event.propertyName;
	var undef;

	if (pn == "style.boxSizing" && element.style.boxSizing == "") {
		element.style.removeAttribute("boxSizing");
		element.runtimeStyle.boxSizing = undef;		
	}


	switch (pn) {
		case "style.width":
		case "style.borderLeftWidth":
		case "style.borderLeftStyle":
		case "style.borderRightWidth":
		case "style.borderRightStyle":
		case "style.paddingLeft":
		case "style.paddingRight":
			updateBorderBoxWidth();
			break;
		
		case "style.height":
		case "style.borderTopWidth":
		case "style.borderTopStyle":
		case "style.borderBottomWidth":
		case "style.borderBottomStyle":
		case "style.paddingTop":
		case "style.paddingBottom":
			updateBorderBoxHeight();
			break;
		
		case "className":
		case "style.boxSizing":
			updateBorderBoxWidth();
			updateBorderBoxHeight();
			break;
	}
}

init();

//]]>
</script>
</component>