]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/styleguide/docbook-xsl-1.75.2/slides/browser/xbStyle.js
stylesheet changes.
[working/Evergreen.git] / stylesheets / styleguide / docbook-xsl-1.75.2 / slides / browser / xbStyle.js
1 /*\r
2  * xbStyle.js\r
3  * $Revision: 1.2 $ $Date: 2003/02/07 16:04:22 $\r
4  */\r
5 \r
6 /* ***** BEGIN LICENSE BLOCK *****\r
7  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
8  *\r
9  * The contents of this file are subject to the Mozilla Public License Version\r
10  * 1.1 (the "License"); you may not use this file except in compliance with\r
11  * the License. You may obtain a copy of the License at\r
12  * http://www.mozilla.org/MPL/\r
13  *\r
14  * Software distributed under the License is distributed on an "AS IS" basis,\r
15  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
16  * for the specific language governing rights and limitations under the\r
17  * License.\r
18  *\r
19  * The Original Code is Netscape code.\r
20  *\r
21  * The Initial Developer of the Original Code is\r
22  * Netscape Corporation.\r
23  * Portions created by the Initial Developer are Copyright (C) 2001\r
24  * the Initial Developer. All Rights Reserved.\r
25  *\r
26  * Contributor(s): Bob Clary <bclary@netscape.com>\r
27  *\r
28  * ***** END LICENSE BLOCK ***** */\r
29 \r
30 function xbStyleNotSupported() {}\r
31 \r
32 function xbStyleNotSupportStringValue(propname) { xbDEBUG.dump(propname + ' is not supported in this browser'); return '';};\r
33 \r
34 /////////////////////////////////////////////////////////////\r
35 // xbClipRect\r
36 \r
37 function xbClipRect(a1, a2, a3, a4)\r
38 {\r
39   this.top  = 0;\r
40   this.right  = 0;\r
41   this.bottom  = 0;\r
42   this.left  = 0;\r
43 \r
44   if (typeof(a1) == 'string')\r
45   {\r
46     var val;\r
47     var ca;\r
48     var i;\r
49       \r
50     if (a1.indexOf('rect(') == 0)\r
51     {\r
52       // I would have preferred [0-9]+[a-zA-Z]+ for a regexp\r
53       // but NN4 returns null for that. \r
54       ca = a1.substring(5, a1.length-1).match(/-?[0-9a-zA-Z]+/g);\r
55       for (i = 0; i < 4; ++i)\r
56       {\r
57         val = xbToInt(ca[i]);\r
58         if (val != 0 && ca[i].indexOf('px') == -1)\r
59         {\r
60           xbDEBUG.dump('xbClipRect: A clipping region ' + a1 + ' was detected that did not use pixels as units.  Click Ok to continue, Cancel to Abort');\r
61           return;\r
62         }\r
63         ca[i] = val;\r
64       }\r
65       this.top    = ca[0];\r
66       this.right  = ca[1];\r
67       this.bottom = ca[2];\r
68       this.left   = ca[3];\r
69     }\r
70   }    \r
71   else if (typeof(a1) == 'number' && typeof(a2) == 'number' && typeof(a3) == 'number' && typeof(a4) == 'number')\r
72   {\r
73     this.top    = a1;\r
74     this.right  = a2;\r
75     this.bottom = a3;\r
76     this.left   = a4;\r
77   }\r
78 }\r
79 \r
80 xbClipRect.prototype.top = 0;\r
81 xbClipRect.prototype.right = 0;\r
82 xbClipRect.prototype.bottom = 0;\r
83 xbClipRect.prototype.left = 0;\r
84 \r
85 \r
86 function xbClipRectGetWidth()\r
87 {\r
88     return this.right - this.left;\r
89 }\r
90 xbClipRect.prototype.getWidth = xbClipRectGetWidth; \r
91 \r
92 function xbClipRectSetWidth(width)\r
93 {\r
94   this.right = this.left + width;\r
95 }\r
96 xbClipRect.prototype.setWidth = xbClipRectSetWidth;\r
97 \r
98 function xbClipRectGetHeight()\r
99 {\r
100     return this.bottom - this.top;\r
101 }\r
102 xbClipRect.prototype.getHeight = xbClipRectGetHeight; \r
103 \r
104 function xbClipRectSetHeight(height)\r
105 {\r
106   this.bottom = this.top + height;\r
107 }\r
108 xbClipRect.prototype.setHeight = xbClipRectSetHeight;\r
109 \r
110 function xbClipRectToString()\r
111 {\r
112   return 'rect(' + this.top + 'px ' + this.right + 'px ' + this.bottom + 'px ' + this.left + 'px )' ;\r
113 }\r
114 xbClipRect.prototype.toString = xbClipRectToString;\r
115 \r
116 /////////////////////////////////////////////////////////////\r
117 // xbStyle\r
118 //\r
119 // Note Opera violates the standard by cascading the effective values\r
120 // into the HTMLElement.style object. We can use IE's HTMLElement.currentStyle\r
121 // to get the effective values. In Gecko we will use the W3 DOM Style Standard getComputedStyle\r
122 \r
123 function xbStyle(obj, win, position)\r
124 {\r
125   if (typeof(obj) == 'object' && typeof(obj.style) != 'undefined') \r
126     this.styleObj = obj.style;\r
127   else if (document.layers) // NN4\r
128   {\r
129     if (typeof(position) == 'undefined')\r
130       position = '';\r
131         \r
132     this.styleObj = obj;\r
133     this.styleObj.position = position;\r
134   }\r
135   this.object = obj;\r
136   this.window = win ? win : window;\r
137 }\r
138 \r
139 xbStyle.prototype.styleObj = null;\r
140 xbStyle.prototype.object = null;\r
141 \r
142 /////////////////////////////////////////////////////////////\r
143 // xbStyle.getEffectiveValue()\r
144 // note that xbStyle's constructor uses the currentStyle object \r
145 // for IE5+ and that Opera's style object contains computed values\r
146 // already. Netscape Navigator's layer object also contains the \r
147 // computed values as well. Note that IE4 will not return the \r
148 // computed values.\r
149 \r
150 function xbStyleGetEffectiveValue(propname)\r
151 {\r
152   var value = null;\r
153 \r
154   if (this.window.document.defaultView && this.window.document.defaultView.getComputedStyle)\r
155   {\r
156     // W3\r
157     // Note that propname is the name of the property in the CSS Style\r
158     // Object. However the W3 method getPropertyValue takes the actual\r
159     // property name from the CSS Style rule, i.e., propname is \r
160     // 'backgroundColor' but getPropertyValue expects 'background-color'.\r
161 \r
162      var capIndex;\r
163      var cappropname = propname;\r
164 \r
165      while ( (capIndex = cappropname.search(/[A-Z]/)) != -1)\r
166      {\r
167        if (capIndex != -1)\r
168        {\r
169          cappropname = cappropname.substring(0, capIndex) + '-' + cappropname.substring(capIndex, capIndex+1).toLowerCase() + cappropname.substr(capIndex+1);\r
170        }\r
171      }\r
172 \r
173      value = this.window.document.defaultView.getComputedStyle(this.object, '').getPropertyValue(cappropname);\r
174 \r
175      // xxxHack for Gecko:\r
176      if (!value && this.styleObj[propname])\r
177      {\r
178        value = this.styleObj[propname];\r
179      }\r
180   }\r
181   else if (typeof(this.styleObj[propname]) == 'undefined') \r
182   {\r
183     value = xbStyleNotSupportStringValue(propname);\r
184   }\r
185   else if (typeof(this.object.currentStyle) != 'undefined')\r
186   {\r
187     // IE5+\r
188     value = this.object.currentStyle[propname];\r
189     if (!value)\r
190     {\r
191       value = this.styleObj[propname];\r
192     }\r
193 \r
194     if (propname == 'clip' && !value)\r
195     {\r
196       // clip is not stored in IE5/6 handle separately\r
197       value = 'rect(' + this.object.currentStyle.clipTop + ', ' + this.object.currentStyle.clipRight + ', ' + this.object.currentStyle.clipBottom + ', ' + this.object.currentStyle.clipLeft + ')';\r
198     }\r
199   }\r
200   else\r
201   {\r
202     // IE4+, Opera, NN4\r
203     value = this.styleObj[propname];\r
204   }\r
205 \r
206   return value;\r
207 }\r
208 \r
209 /////////////////////////////////////////////////////////////////////////////\r
210 // xbStyle.moveAbove()\r
211 \r
212 function xbStyleMoveAbove(cont)\r
213 {\r
214   this.setzIndex(cont.getzIndex()+1);\r
215 }\r
216 \r
217 /////////////////////////////////////////////////////////////////////////////\r
218 // xbStyle.moveBelow()\r
219 \r
220 function xbStyleMoveBelow(cont)\r
221 {\r
222   var zindex = cont.getzIndex() - 1;\r
223             \r
224   this.setzIndex(zindex);\r
225 }\r
226 \r
227 /////////////////////////////////////////////////////////////////////////////\r
228 // xbStyle.moveBy()\r
229 \r
230 function xbStyleMoveBy(deltaX, deltaY)\r
231 {\r
232   this.moveTo(this.getLeft() + deltaX, this.getTop() + deltaY);\r
233 }\r
234 \r
235 /////////////////////////////////////////////////////////////////////////////\r
236 // xbStyle.moveTo()\r
237 \r
238 function xbStyleMoveTo(x, y)\r
239 {\r
240   this.setLeft(x);\r
241   this.setTop(y);\r
242 }\r
243 \r
244 /////////////////////////////////////////////////////////////////////////////\r
245 // xbStyle.moveToAbsolute()\r
246 \r
247 function xbStyleMoveToAbsolute(x, y)\r
248 {\r
249   this.setPageX(x);\r
250   this.setPageY(y);\r
251 }\r
252 \r
253 /////////////////////////////////////////////////////////////////////////////\r
254 // xbStyle.resizeBy()\r
255 \r
256 function xbStyleResizeBy(deltaX, deltaY)\r
257 {\r
258   this.setWidth( this.getWidth() + deltaX );\r
259   this.setHeight( this.getHeight() + deltaY );\r
260 }\r
261 \r
262 /////////////////////////////////////////////////////////////////////////////\r
263 // xbStyle.resizeTo()\r
264 \r
265 function xbStyleResizeTo(x, y)\r
266 {\r
267   this.setWidth(x);\r
268   this.setHeight(y);\r
269 }\r
270 \r
271 ////////////////////////////////////////////////////////////////////////\r
272 \r
273 xbStyle.prototype.getEffectiveValue     = xbStyleGetEffectiveValue;\r
274 xbStyle.prototype.moveAbove             = xbStyleMoveAbove;\r
275 xbStyle.prototype.moveBelow             = xbStyleMoveBelow;\r
276 xbStyle.prototype.moveBy                = xbStyleMoveBy;\r
277 xbStyle.prototype.moveTo                = xbStyleMoveTo;\r
278 xbStyle.prototype.moveToAbsolute        = xbStyleMoveToAbsolute;\r
279 xbStyle.prototype.resizeBy              = xbStyleResizeBy;\r
280 xbStyle.prototype.resizeTo              = xbStyleResizeTo;\r
281 \r
282 if (document.all || document.getElementsByName)\r
283 {\r
284   xblibrary.loadScript('xbStyle-css.js');\r
285 }\r
286 else if (document.layers)\r
287 {\r
288   xblibrary.loadScript('xbStyle-nn4.js');\r
289 }\r
290 else \r
291 {\r
292   xblibrary.loadScript('xbStyle-not-supported.js');\r
293 }\r
294 \r
295 \r