1 /* Prototype JavaScript framework, version 1.4.0_pre4
2 * (c) 2005 Sam Stephenson <sam@conio.net>
4 * THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
5 * against the source tree, available from the Prototype darcs repository.
7 * Prototype is freely distributable under the terms of an MIT-style license.
9 * For details, see the Prototype web site: http://prototype.conio.net/
11 /*--------------------------------------------------------------------------*/
14 Version: '1.4.0_pre4',
16 emptyFunction: function() {},
17 K: function(x) {return x}
23 this.initialize.apply(this, arguments);
28 var Abstract = new Object();
30 Object.extend = function(destination, source) {
31 for (property in source) {
32 destination[property] = source[property];
37 Function.prototype.bind = function(object) {
40 return __method.apply(object, arguments);
44 Function.prototype.bindAsEventListener = function(object) {
46 return function(event) {
47 return __method.call(object, event || window.event);
51 Number.prototype.toColorPart = function() {
52 var digits = this.toString(16);
53 if (this < 16) return '0' + digits;
61 for (var i = 0; i < arguments.length; i++) {
62 var lambda = arguments[i];
64 returnValue = lambda();
73 /*--------------------------------------------------------------------------*/
75 var PeriodicalExecuter = Class.create();
76 PeriodicalExecuter.prototype = {
77 initialize: function(callback, frequency) {
78 this.callback = callback;
79 this.frequency = frequency;
80 this.currentlyExecuting = false;
82 this.registerCallback();
85 registerCallback: function() {
86 setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
89 onTimerEvent: function() {
90 if (!this.currentlyExecuting) {
92 this.currentlyExecuting = true;
95 this.currentlyExecuting = false;
101 /*--------------------------------------------------------------------------*/
104 var elements = new Array();
106 for (var i = 0; i < arguments.length; i++) {
107 var element = arguments[i];
108 if (typeof element == 'string')
109 element = document.getElementById(element);
111 if (arguments.length == 1)
114 elements.push(element);
120 if (!Array.prototype.push) {
121 Array.prototype.push = function() {
122 var startLength = this.length;
123 for (var i = 0; i < arguments.length; i++)
124 this[startLength + i] = arguments[i];
129 if (!Function.prototype.apply) {
130 // Based on code from http://www.youngpup.net/
131 Function.prototype.apply = function(object, parameters) {
132 var parameterStrings = new Array();
133 if (!object) object = window;
134 if (!parameters) parameters = new Array();
136 for (var i = 0; i < parameters.length; i++)
137 parameterStrings[i] = 'parameters[' + i + ']';
139 object.__apply__ = this;
140 var result = eval('object.__apply__(' +
141 parameterStrings.join(', ') + ')');
142 object.__apply__ = null;
148 Object.extend(String.prototype, {
149 stripTags: function() {
150 return this.replace(/<\/?[^>]+>/gi, '');
153 escapeHTML: function() {
154 var div = document.createElement('div');
155 var text = document.createTextNode(this);
156 div.appendChild(text);
157 return div.innerHTML;
160 unescapeHTML: function() {
161 var div = document.createElement('div');
162 div.innerHTML = this.stripTags();
163 return div.childNodes[0].nodeValue;
166 parseQuery: function() {
168 if (str.substring(0,1) == '?') {
169 str = this.substring(1);
172 var pairs = str.split('&');
173 for (var i = 0; i < pairs.length; i++) {
174 var pair = pairs[i].split('=');
175 result[pair[0]] = pair[1];
182 var _break = new Object();
183 var _continue = new Object();
186 each: function(iterator) {
189 this._each(function(value) {
191 iterator(value, index++);
193 if (e != _continue) throw e;
197 if (e != _break) throw e;
201 all: function(iterator) {
203 this.each(function(value, index) {
204 if (!(result &= (iterator || Prototype.K)(value, index)))
210 any: function(iterator) {
212 this.each(function(value, index) {
213 if (result &= (iterator || Prototype.K)(value, index))
219 collect: function(iterator) {
221 this.each(function(value, index) {
222 results.push(iterator(value, index));
227 detect: function (iterator) {
229 this.each(function(value, index) {
230 if (iterator(value, index)) {
238 findAll: function(iterator) {
240 this.each(function(value, index) {
241 if (iterator(value, index))
247 grep: function(pattern, iterator) {
249 this.each(function(value, index) {
250 var stringValue = value.toString();
251 if (stringValue.match(pattern))
252 results.push((iterator || Prototype.K)(value, index));
257 include: function(object) {
259 this.each(function(value) {
260 if (value == object) {
268 inject: function(memo, iterator) {
269 this.each(function(value, index) {
270 memo = iterator(memo, value, index);
275 invoke: function(method) {
276 var args = $A(arguments).slice(1);
277 return this.collect(function(value) {
278 return value[method].apply(value, args);
282 max: function(iterator) {
284 this.each(function(value, index) {
285 value = (iterator || Prototype.K)(value, index);
286 if (value >= (result || value))
292 min: function(iterator) {
294 this.each(function(value, index) {
295 value = (iterator || Prototype.K)(value, index);
296 if (value <= (result || value))
302 partition: function(iterator) {
303 var trues = [], falses = [];
304 this.each(function(value, index) {
305 ((iterator || Prototype.K)(value, index) ?
306 trues : falses).push(value);
308 return [trues, falses];
311 pluck: function(property) {
313 this.each(function(value, index) {
314 results.push(value[property]);
319 reject: function(iterator) {
321 this.each(function(value, index) {
322 if (!iterator(value, index))
328 sortBy: function(iterator) {
329 return this.collect(function(value, index) {
330 return {value: value, criteria: iterator(value, index)};
331 }).sort(function(left, right) {
332 var a = left.criteria, b = right.criteria;
333 return a < b ? -1 : a > b ? 1 : 0;
337 toArray: function() {
338 return this.collect(Prototype.K);
342 var iterator = Prototype.K, args = $A(arguments);
343 if (typeof args.last() == 'function')
344 iterator = args.pop();
346 var collections = [this].concat(args).map($A);
347 return this.map(function(value, index) {
348 iterator(value = collections.pluck(index));
354 Object.extend(Enumerable, {
355 map: Enumerable.collect,
356 find: Enumerable.detect,
357 select: Enumerable.findAll,
358 member: Enumerable.include,
359 entries: Enumerable.toArray
362 $A = Array.from = function(iterable) {
364 for (var i = 0; i < iterable.length; i++)
365 results.push(iterable[i]);
369 Object.extend(Array.prototype, {
370 _each: function(iterator) {
371 for (var i = 0; i < this.length; i++)
380 return this[this.length - 1];
384 Object.extend(Array.prototype, Enumerable);
388 getTransport: function() {
390 function() {return new ActiveXObject('Msxml2.XMLHTTP')},
391 function() {return new ActiveXObject('Microsoft.XMLHTTP')},
392 function() {return new XMLHttpRequest()}
397 Ajax.Base = function() {};
398 Ajax.Base.prototype = {
399 setOptions: function(options) {
405 Object.extend(this.options, options || {});
408 responseIsSuccess: function() {
409 return this.transport.status == undefined
410 || this.transport.status == 0
411 || (this.transport.status >= 200 && this.transport.status < 300);
414 responseIsFailure: function() {
415 return !this.responseIsSuccess();
419 Ajax.Request = Class.create();
420 Ajax.Request.Events =
421 ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
423 Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
424 initialize: function(url, options) {
425 this.transport = Ajax.getTransport();
426 this.setOptions(options);
430 request: function(url) {
431 var parameters = this.options.parameters || '';
432 if (parameters.length > 0) parameters += '&_=';
435 if (this.options.method == 'get')
436 url += '?' + parameters;
438 this.transport.open(this.options.method, url,
439 this.options.asynchronous);
441 if (this.options.asynchronous) {
442 this.transport.onreadystatechange = this.onStateChange.bind(this);
443 setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
446 this.setRequestHeaders();
448 var body = this.options.postBody ? this.options.postBody : parameters;
449 this.transport.send(this.options.method == 'post' ? body : null);
455 setRequestHeaders: function() {
457 ['X-Requested-With', 'XMLHttpRequest',
458 'X-Prototype-Version', Prototype.Version];
460 if (this.options.method == 'post') {
461 requestHeaders.push('Content-type',
462 'application/x-www-form-urlencoded');
464 /* Force "Connection: close" for Mozilla browsers to work around
465 * a bug where XMLHttpReqeuest sends an incorrect Content-length
466 * header. See Mozilla Bugzilla #246651.
468 if (this.transport.overrideMimeType)
469 requestHeaders.push('Connection', 'close');
472 if (this.options.requestHeaders)
473 requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
475 for (var i = 0; i < requestHeaders.length; i += 2)
476 this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
479 onStateChange: function() {
480 var readyState = this.transport.readyState;
482 this.respondToReadyState(this.transport.readyState);
485 respondToReadyState: function(readyState) {
486 var event = Ajax.Request.Events[readyState];
488 if (event == 'Complete')
489 (this.options['on' + this.transport.status]
490 || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
491 || Prototype.emptyFunction)(this.transport);
493 (this.options['on' + event] || Prototype.emptyFunction)(this.transport);
495 /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
496 if (event == 'Complete')
497 this.transport.onreadystatechange = Prototype.emptyFunction;
501 Ajax.Updater = Class.create();
502 Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';
504 Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
505 initialize: function(container, url, options) {
507 success: container.success ? $(container.success) : $(container),
508 failure: container.failure ? $(container.failure) :
509 (container.success ? null : $(container))
512 this.transport = Ajax.getTransport();
513 this.setOptions(options);
515 var onComplete = this.options.onComplete || Prototype.emptyFunction;
516 this.options.onComplete = (function() {
517 this.updateContent();
518 onComplete(this.transport);
524 updateContent: function() {
525 var receiver = this.responseIsSuccess() ?
526 this.containers.success : this.containers.failure;
528 var match = new RegExp(Ajax.Updater.ScriptFragment, 'img');
529 var response = this.transport.responseText.replace(match, '');
530 var scripts = this.transport.responseText.match(match);
533 if (this.options.insertion) {
534 new this.options.insertion(receiver, response);
536 receiver.innerHTML = response;
540 if (this.responseIsSuccess()) {
542 setTimeout((function() {this.onComplete(
543 this.transport)}).bind(this), 10);
546 if (this.options.evalScripts && scripts) {
547 match = new RegExp(Ajax.Updater.ScriptFragment, 'im');
548 setTimeout((function() {
549 for (var i = 0; i < scripts.length; i++)
550 eval(scripts[i].match(match)[1]);
556 Ajax.PeriodicalUpdater = Class.create();
557 Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
558 initialize: function(container, url, options) {
559 this.setOptions(options);
560 this.onComplete = this.options.onComplete;
562 this.frequency = (this.options.frequency || 2);
566 this.container = container;
573 this.options.onComplete = this.updateComplete.bind(this);
578 this.updater.onComplete = undefined;
579 clearTimeout(this.timer);
580 (this.onComplete || Ajax.emptyFunction).apply(this, arguments);
583 updateComplete: function(request) {
584 if (this.options.decay) {
585 this.decay = (request.responseText == this.lastText ?
586 this.decay * this.options.decay : 1);
588 this.lastText = request.responseText;
590 this.timer = setTimeout(this.onTimerEvent.bind(this),
591 this.decay * this.frequency * 1000);
594 onTimerEvent: function() {
595 this.updater = new Ajax.Updater(this.container, this.url, this.options);
599 document.getElementsByClassName = function(className) {
600 var children = document.getElementsByTagName('*') || document.all;
601 var elements = new Array();
603 for (var i = 0; i < children.length; i++) {
604 var child = children[i];
605 var classNames = child.className.split(' ');
606 for (var j = 0; j < classNames.length; j++) {
607 if (classNames[j] == className) {
608 elements.push(child);
617 /*--------------------------------------------------------------------------*/
619 if (!window.Element) {
620 var Element = new Object();
623 Object.extend(Element, {
625 for (var i = 0; i < arguments.length; i++) {
626 var element = $(arguments[i]);
627 element.style.display =
628 (element.style.display == 'none' ? '' : 'none');
633 for (var i = 0; i < arguments.length; i++) {
634 var element = $(arguments[i]);
635 element.style.display = 'none';
640 for (var i = 0; i < arguments.length; i++) {
641 var element = $(arguments[i]);
642 element.style.display = '';
646 remove: function(element) {
647 element = $(element);
648 element.parentNode.removeChild(element);
651 getHeight: function(element) {
652 element = $(element);
653 return element.offsetHeight;
656 hasClassName: function(element, className) {
657 element = $(element);
660 var a = element.className.split(' ');
661 for (var i = 0; i < a.length; i++) {
662 if (a[i] == className)
668 addClassName: function(element, className) {
669 element = $(element);
670 Element.removeClassName(element, className);
671 element.className += ' ' + className;
674 removeClassName: function(element, className) {
675 element = $(element);
678 var newClassName = '';
679 var a = element.className.split(' ');
680 for (var i = 0; i < a.length; i++) {
681 if (a[i] != className) {
684 newClassName += a[i];
687 element.className = newClassName;
690 // removes whitespace-only text node children
691 cleanWhitespace: function(element) {
692 var element = $(element);
693 for (var i = 0; i < element.childNodes.length; i++) {
694 var node = element.childNodes[i];
695 if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
696 Element.remove(node);
701 var Toggle = new Object();
702 Toggle.display = Element.toggle;
704 /*--------------------------------------------------------------------------*/
706 Abstract.Insertion = function(adjacency) {
707 this.adjacency = adjacency;
710 Abstract.Insertion.prototype = {
711 initialize: function(element, content) {
712 this.element = $(element);
713 this.content = content;
715 if (this.adjacency && this.element.insertAdjacentHTML) {
716 this.element.insertAdjacentHTML(this.adjacency, this.content);
718 this.range = this.element.ownerDocument.createRange();
719 if (this.initializeRange) this.initializeRange();
720 this.fragment = this.range.createContextualFragment(this.content);
721 this.insertContent();
726 var Insertion = new Object();
728 Insertion.Before = Class.create();
729 Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), {
730 initializeRange: function() {
731 this.range.setStartBefore(this.element);
734 insertContent: function() {
735 this.element.parentNode.insertBefore(this.fragment, this.element);
739 Insertion.Top = Class.create();
740 Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), {
741 initializeRange: function() {
742 this.range.selectNodeContents(this.element);
743 this.range.collapse(true);
746 insertContent: function() {
747 this.element.insertBefore(this.fragment, this.element.firstChild);
751 Insertion.Bottom = Class.create();
752 Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), {
753 initializeRange: function() {
754 this.range.selectNodeContents(this.element);
755 this.range.collapse(this.element);
758 insertContent: function() {
759 this.element.appendChild(this.fragment);
763 Insertion.After = Class.create();
764 Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), {
765 initializeRange: function() {
766 this.range.setStartAfter(this.element);
769 insertContent: function() {
770 this.element.parentNode.insertBefore(this.fragment,
771 this.element.nextSibling);
777 for (var i = 0; i < arguments.length; i++)
778 $(arguments[i]).value = '';
781 focus: function(element) {
785 present: function() {
786 for (var i = 0; i < arguments.length; i++)
787 if ($(arguments[i]).value == '') return false;
791 select: function(element) {
795 activate: function(element) {
801 /*--------------------------------------------------------------------------*/
804 serialize: function(form) {
805 var elements = Form.getElements($(form));
806 var queryComponents = new Array();
808 for (var i = 0; i < elements.length; i++) {
809 var queryComponent = Form.Element.serialize(elements[i]);
811 queryComponents.push(queryComponent);
814 return queryComponents.join('&');
817 getElements: function(form) {
819 var elements = new Array();
821 for (tagName in Form.Element.Serializers) {
822 var tagElements = form.getElementsByTagName(tagName);
823 for (var j = 0; j < tagElements.length; j++)
824 elements.push(tagElements[j]);
829 getInputs: function(form, typeName, name) {
831 var inputs = form.getElementsByTagName('input');
833 if (!typeName && !name)
836 var matchingInputs = new Array();
837 for (var i = 0; i < inputs.length; i++) {
838 var input = inputs[i];
839 if ((typeName && input.type != typeName) ||
840 (name && input.name != name))
842 matchingInputs.push(input);
845 return matchingInputs;
848 disable: function(form) {
849 var elements = Form.getElements(form);
850 for (var i = 0; i < elements.length; i++) {
851 var element = elements[i];
853 element.disabled = 'true';
857 enable: function(form) {
858 var elements = Form.getElements(form);
859 for (var i = 0; i < elements.length; i++) {
860 var element = elements[i];
861 element.disabled = '';
865 focusFirstElement: function(form) {
867 var elements = Form.getElements(form);
868 for (var i = 0; i < elements.length; i++) {
869 var element = elements[i];
870 if (element.type != 'hidden' && !element.disabled) {
871 Field.activate(element);
877 reset: function(form) {
883 serialize: function(element) {
884 var element = $(element);
885 var method = element.tagName.toLowerCase();
886 var parameter = Form.Element.Serializers[method](element);
889 return encodeURIComponent(parameter[0]) + '=' +
890 encodeURIComponent(parameter[1]);
893 getValue: function(element) {
894 var element = $(element);
895 var method = element.tagName.toLowerCase();
896 var parameter = Form.Element.Serializers[method](element);
903 Form.Element.Serializers = {
904 input: function(element) {
905 switch (element.type.toLowerCase()) {
910 return Form.Element.Serializers.textarea(element);
913 return Form.Element.Serializers.inputSelector(element);
918 inputSelector: function(element) {
920 return [element.name, element.value];
923 textarea: function(element) {
924 return [element.name, element.value];
927 select: function(element) {
929 if (element.type == 'select-one') {
930 var index = element.selectedIndex;
932 value = element.options[index].value || element.options[index].text;
935 for (var i = 0; i < element.length; i++) {
936 var opt = element.options[i];
938 value.push(opt.value || opt.text);
941 return [element.name, value];
945 /*--------------------------------------------------------------------------*/
947 var $F = Form.Element.getValue;
949 /*--------------------------------------------------------------------------*/
951 Abstract.TimedObserver = function() {}
952 Abstract.TimedObserver.prototype = {
953 initialize: function(element, frequency, callback) {
954 this.frequency = frequency;
955 this.element = $(element);
956 this.callback = callback;
958 this.lastValue = this.getValue();
959 this.registerCallback();
962 registerCallback: function() {
963 setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
966 onTimerEvent: function() {
967 var value = this.getValue();
968 if (this.lastValue != value) {
969 this.callback(this.element, value);
970 this.lastValue = value;
975 Form.Element.Observer = Class.create();
976 Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
977 getValue: function() {
978 return Form.Element.getValue(this.element);
982 Form.Observer = Class.create();
983 Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
984 getValue: function() {
985 return Form.serialize(this.element);
989 /*--------------------------------------------------------------------------*/
991 Abstract.EventObserver = function() {}
992 Abstract.EventObserver.prototype = {
993 initialize: function(element, callback) {
994 this.element = $(element);
995 this.callback = callback;
997 this.lastValue = this.getValue();
998 if (this.element.tagName.toLowerCase() == 'form')
999 this.registerFormCallbacks();
1001 this.registerCallback(this.element);
1004 onElementEvent: function() {
1005 var value = this.getValue();
1006 if (this.lastValue != value) {
1007 this.callback(this.element, value);
1008 this.lastValue = value;
1012 registerFormCallbacks: function() {
1013 var elements = Form.getElements(this.element);
1014 for (var i = 0; i < elements.length; i++)
1015 this.registerCallback(elements[i]);
1018 registerCallback: function(element) {
1020 switch (element.type.toLowerCase()) {
1023 element.target = this;
1024 element.prev_onclick = element.onclick || Prototype.emptyFunction;
1025 element.onclick = function() {
1026 this.prev_onclick();
1027 this.target.onElementEvent();
1034 case 'select-multiple':
1035 element.target = this;
1036 element.prev_onchange = element.onchange || Prototype.emptyFunction;
1037 element.onchange = function() {
1038 this.prev_onchange();
1039 this.target.onElementEvent();
1047 Form.Element.EventObserver = Class.create();
1048 Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
1049 getValue: function() {
1050 return Form.Element.getValue(this.element);
1054 Form.EventObserver = Class.create();
1055 Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
1056 getValue: function() {
1057 return Form.serialize(this.element);
1062 if (!window.Event) {
1063 var Event = new Object();
1066 Object.extend(Event, {
1077 element: function(event) {
1078 return event.target || event.srcElement;
1081 isLeftClick: function(event) {
1082 return (((event.which) && (event.which == 1)) ||
1083 ((event.button) && (event.button == 1)));
1086 pointerX: function(event) {
1087 return event.pageX || (event.clientX +
1088 (document.documentElement.scrollLeft || document.body.scrollLeft));
1091 pointerY: function(event) {
1092 return event.pageY || (event.clientY +
1093 (document.documentElement.scrollTop || document.body.scrollTop));
1096 stop: function(event) {
1097 if (event.preventDefault) {
1098 event.preventDefault();
1099 event.stopPropagation();
1101 event.returnValue = false;
1105 // find the first node with the given tagName, starting from the
1106 // node the event was triggered on; traverses the DOM upwards
1107 findElement: function(event, tagName) {
1108 var element = Event.element(event);
1109 while (element.parentNode && (!element.tagName ||
1110 (element.tagName.toUpperCase() != tagName.toUpperCase())))
1111 element = element.parentNode;
1117 _observeAndCache: function(element, name, observer, useCapture) {
1118 if (!this.observers) this.observers = [];
1119 if (element.addEventListener) {
1120 this.observers.push([element, name, observer, useCapture]);
1121 element.addEventListener(name, observer, useCapture);
1122 } else if (element.attachEvent) {
1123 this.observers.push([element, name, observer, useCapture]);
1124 element.attachEvent('on' + name, observer);
1128 unloadCache: function() {
1129 if (!Event.observers) return;
1130 for (var i = 0; i < Event.observers.length; i++) {
1131 Event.stopObserving.apply(this, Event.observers[i]);
1132 Event.observers[i][0] = null;
1134 Event.observers = false;
1137 observe: function(element, name, observer, useCapture) {
1138 var element = $(element);
1139 useCapture = useCapture || false;
1141 if (name == 'keypress' &&
1142 ((/Konqueror|Safari|KHTML/.test(navigator.userAgent))
1143 || element.attachEvent))
1146 this._observeAndCache(element, name, observer, useCapture);
1149 stopObserving: function(element, name, observer, useCapture) {
1150 var element = $(element);
1151 useCapture = useCapture || false;
1153 if (name == 'keypress' &&
1154 ((/Konqueror|Safari|KHTML/.test(navigator.userAgent))
1155 || element.detachEvent))
1158 if (element.removeEventListener) {
1159 element.removeEventListener(name, observer, useCapture);
1160 } else if (element.detachEvent) {
1161 element.detachEvent('on' + name, observer);
1166 /* prevent memory leaks in IE */
1167 Event.observe(window, 'unload', Event.unloadCache, false);
1171 // set to true if needed, warning: firefox performance problems
1172 // NOT neeeded for page scrolling, only if draggable contained in
1173 // scrollable elements
1174 includeScrollOffsets: false,
1176 // must be called before calling withinIncludingScrolloffset, every time the
1178 prepare: function() {
1179 this.deltaX = window.pageXOffset
1180 || document.documentElement.scrollLeft
1181 || document.body.scrollLeft
1183 this.deltaY = window.pageYOffset
1184 || document.documentElement.scrollTop
1185 || document.body.scrollTop
1189 realOffset: function(element) {
1190 var valueT = 0, valueL = 0;
1192 valueT += element.scrollTop || 0;
1193 valueL += element.scrollLeft || 0;
1194 element = element.parentNode;
1196 return [valueL, valueT];
1199 cumulativeOffset: function(element) {
1200 var valueT = 0, valueL = 0;
1202 valueT += element.offsetTop || 0;
1203 valueL += element.offsetLeft || 0;
1204 element = element.offsetParent;
1206 return [valueL, valueT];
1209 // caches x/y coordinate pair to use with overlap
1210 within: function(element, x, y) {
1211 if (this.includeScrollOffsets)
1212 return this.withinIncludingScrolloffsets(element, x, y);
1215 this.offset = this.cumulativeOffset(element);
1217 return (y >= this.offset[1] &&
1218 y < this.offset[1] + element.offsetHeight &&
1219 x >= this.offset[0] &&
1220 x < this.offset[0] + element.offsetWidth);
1223 withinIncludingScrolloffsets: function(element, x, y) {
1224 var offsetcache = this.realOffset(element);
1226 this.xcomp = x + offsetcache[0] - this.deltaX;
1227 this.ycomp = y + offsetcache[1] - this.deltaY;
1228 this.offset = this.cumulativeOffset(element);
1230 return (this.ycomp >= this.offset[1] &&
1231 this.ycomp < this.offset[1] + element.offsetHeight &&
1232 this.xcomp >= this.offset[0] &&
1233 this.xcomp < this.offset[0] + element.offsetWidth);
1236 // within must be called directly before
1237 overlap: function(mode, element) {
1238 if (!mode) return 0;
1239 if (mode == 'vertical')
1240 return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
1241 element.offsetHeight;
1242 if (mode == 'horizontal')
1243 return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
1244 element.offsetWidth;
1247 clone: function(source, target) {
1250 target.style.position = 'absolute';
1251 var offsets = this.cumulativeOffset(source);
1252 target.style.top = offsets[1] + 'px';
1253 target.style.left = offsets[0] + 'px';
1254 target.style.width = source.offsetWidth + 'px';
1255 target.style.height = source.offsetHeight + 'px';