js 代码
-
-
-
-
-
var
$F = Form.Element.getValue;
-
-
-
-
-
-
-
-
-
-
-
-
-
Abstract.TimedObserver =
function
() {}
-
-
-
-
Abstract.TimedObserver.prototype = {
-
initialize:
function
(element, frequency, callback) {
-
this
.frequency = frequency;
-
this
.element = $(element);
-
this
.callback = callback;
-
-
this
.lastValue =
this
.getValue();
-
this
.registerCallback();
-
},
-
registerCallback:
function
() {
-
setInterval(
this
.onTimerEvent.bind(
this
),
this
.frequency * 1000);
-
},
-
onTimerEvent:
function
() {
-
var
value =
this
.getValue();
-
if
(
this
.lastValue != value) {
-
this
.callback(
this
.element, value);
-
this
.lastValue = value;
-
}
-
}
-
}
-
-
-
-
Form.Element.Observer = Class.create();
-
Form.Element.Observer.prototype = (
new
Abstract.TimedObserver()).extend({
-
getValue:
function
() {
-
return
Form.Element.getValue(
this
.element);
-
}
-
});
-
-
-
-
Form.Observer = Class.create();
-
Form.Observer.prototype = (
new
Abstract.TimedObserver()).extend({
-
getValue:
function
() {
-
return
Form.serialize(
this
.element);
-
}
-
});
-
-
-
-
-
-
Abstract.EventObserver =
function
() {}
-
Abstract.EventObserver.prototype = {
-
initialize:
function
(element, callback) {
-
this
.element = $(element);
-
this
.callback = callback;
-
-
this
.lastValue =
this
.getValue();
-
if
(
this
.element.tagName.toLowerCase() == 'form')
-
this
.registerFormCallbacks();
-
else
-
this
.registerCallback(
this
.element);
-
},
-
onElementEvent:
function
() {
-
var
value =
this
.getValue();
-
if
(
this
.lastValue != value) {
-
this
.callback(
this
.element, value);
-
this
.lastValue = value;
-
}
-
},
-
registerFormCallbacks:
function
() {
-
var
elements = Form.getElements(
this
.element);
-
for
(
var
i = 0; i < elements.length; i++)
-
this
.registerCallback(elements);
-
},
-
registerCallback:
function
(element) {
-
if
(element.type) {
-
switch
(element.type.toLowerCase()) {
-
-
-
-
case
'checkbox':
-
case
'radio':
-
element.target =
this
;
-
element.prev_onclick = element.onclick || Prototype.emptyFunction;
-
-
-
-
element.onclick =
function
() {
-
this
.prev_onclick();
-
this
.target.onElementEvent();
-
}
-
break
;
-
-
-
-
case
'password':
-
case
'text':
-
case
'textarea':
-
case
'select-one':
-
case
'select-multiple':
-
element.target =
this
;
-
element.prev_onchange = element.onchange || Prototype.emptyFunction;
-
element.onchange =
function
() {
-
this
.prev_onchange();
-
this
.target.onElementEvent();
-
}
-
break
;
-
}
-
}
-
}
-
}
-
-
-
-
Form.Element.EventObserver = Class.create();
-
Form.Element.EventObserver.prototype = (
new
Abstract.EventObserver()).extend({
-
getValue:
function
() {
-
return
Form.Element.getValue(
this
.element);
-
}
-
});
-
-
-
-
Form.EventObserver = Class.create();
-
Form.EventObserver.prototype = (
new
Abstract.EventObserver()).extend({
-
getValue:
function
() {
-
return
Form.serialize(
this
.element);
-
}
-
});
-
-
-
-
if
(!window.Event) {
-
var
Event =
new
Object();
-
}
-
Object.extend(Event, {
-
KEY_BACKSPACE: 8,
-
KEY_TAB: 9,
-
KEY_RETURN: 13,
-
KEY_ESC: 27,
-
KEY_LEFT: 37,
-
KEY_UP: 38,
-
KEY_RIGHT: 39,
-
KEY_DOWN: 40,
-
KEY_DELETE: 46,
-
element:
function
(event) {
-
return
event.target || event.srcElement;
-
},
-
isLeftClick:
function
(event) {
-
return
(((event.which) && (event.which == 1)) ||
-
((event.button) && (event.button == 1)));
-
},
-
-
-
-
pointerX:
function
(event) {
-
return
event.pageX || (event.clientX +
-
(document.documentElement.scrollLeft || document.body.scrollLeft));
-
},
-
-
-
-
pointerY:
function
(event) {
-
return
event.pageY || (event.clientY +
-
(document.documentElement.scrollTop || document.body.scrollTop));
-
},
-
-
-
-
-
-
-
stop:
function
(event) {
-
if
(event.preventDefault) {
-
event.preventDefault();
-
event.stopPropagation();
-
}
else
{
-
event.returnValue =
false
;
-
}
-
},
-
-
-
-
-
-
-
findElement:
function
(event, tagName) {
-
var
element = Event.element(event);
-
while
(element.parentNode && (!element.tagName ||
-
(element.tagName.toUpperCase() != tagName.toUpperCase())))
-
element = element.parentNode;
-
return
element;
-
},
-
-
-
-
-
observers:
false
,
-
-
-
-
-
_observeAndCache:
function
(element, name, observer, useCapture) {
-
if
(!
this
.observers)
this
.observers = ;
-
if
(element.addEventListener) {
-
this
.observers.push([element, name, observer, useCapture]);
-
element.addEventListener(name, observer, useCapture);
-
}
else
if
(element.attachEvent) {
-
this
.observers.push([element, name, observer, useCapture]);
-
element.attachEvent('on' + name, observer);
-
}
-
},
-
unloadCache:
function
() {
-
if
(!Event.observers)
return
;
-
for
(
var
i = 0; i < Event.observers.length; i++) {
-
-
-
-
Event.stopObserving.apply(
this
, Event.observers);
-
Event.observers[0] =
null
;
-
}
-
Event.observers =
false
;
-
},
-
-
-
-
observe:
function
(element, name, observer, useCapture) {
-
var
element = $(element);
-
useCapture = useCapture ||
false
;
-
-
if
(name == 'keypress' &&
-
((navigator.appVersion.indexOf('AppleWebKit') > 0)
-
|| element.attachEvent))
-
name = 'keydown';
-
-
this
._observeAndCache(element, name, observer, useCapture);
-
},
-
-
-
-
stopObserving:
function
(element, name, observer, useCapture) {
-
var
element = $(element);
-
useCapture = useCapture ||
false
;
-
-
if
(name == 'keypress' &&
-
((navigator.appVersion.indexOf('AppleWebKit') > 0)
-
|| element.detachEvent))
-
name = 'keydown';
-
-
if
(element.removeEventListener) {
-
element.removeEventListener(name, observer, useCapture);
-
}
else
if
(element.detachEvent) {
-
element.detachEvent('on' + name, observer);
-
}
-
}
-
});
-
-
-
-
-
Event.observe(window, 'unload', Event.unloadCache,
false
);
-
-
-
-
-
var
Position = {
-
-
-
-
includeScrollOffsets:
false
,
-
-
-
prepare:
function
() {
-
this
.deltaX = window.pageXOffset
-
|| document.documentElement.scrollLeft
-
|| document.body.scrollLeft
-
|| 0;
-
this
.deltaY = window.pageYOffset
-
|| document.documentElement.scrollTop
-
|| document.body.scrollTop
-
|| 0;
-
},
-
-
-
-
realOffset:
function
(element) {
-
var
valueT = 0, valueL = 0;
-
do
{
-
valueT += element.scrollTop || 0;
-
valueL += element.scrollLeft || 0;
-
element = element.parentNode;
-
}
while
(element);
-
return
[valueL, valueT];
-
},
-
-
-
-
cumulativeOffset:
function
(element) {
-
var
valueT = 0, valueL = 0;
-
do
{
-
valueT += element.offsetTop || 0;
-
valueL += element.offsetLeft || 0;
-
element = element.offsetParent;
-
}
while
(element);
-
return
[valueL, valueT];
-
},
-
-
-
-
-
-
within:
function
(element, x, y) {
-
if
(
this
.includeScrollOffsets)
-
return
this
.withinIncludingScrolloffsets(element, x, y);
-
this
.xcomp = x;
-
this
.ycomp = y;
-
this
.offset =
this
.cumulativeOffset(element);
-
return
(y >=
this
.offset[1] &&
-
y <
this
.offset[1] + element.offsetHeight &&
-
x >=
this
.offset[0] &&
-
x <
this
.offset[0] + element.offsetWidth);
-
},
-
withinIncludingScrolloffsets:
function
(element, x, y) {
-
var
offsetcache =
this
.realOffset(element);
-
this
.xcomp = x + offsetcache[0] -
this
.deltaX;
-
this
.ycomp = y + offsetcache[1] -
this
.deltaY;
-
this
.offset =
this
.cumulativeOffset(element);
-
return
(
this
.ycomp >=
this
.offset[1] &&
-
this
.ycomp <
this
.offset[1] + element.offsetHeight &&
-
this
.xcomp >=
this
.offset[0] &&
-
this
.xcomp <
this
.offset[0] + element.offsetWidth);
-
},
-
-
-
-
-
-
overlap:
function
(mode, element) {
-
if
(!mode)
return
0;
-
if
(mode == 'vertical')
-
return
((
this
.offset[1] + element.offsetHeight) -
this
.ycomp) /
-
element.offsetHeight;
-
if
(mode == 'horizontal')
-
return
((
this
.offset[0] + element.offsetWidth) -
this
.xcomp) /
-
element.offsetWidth;
-
},
-
-
-
-
-
clone:
function
(source, target) {
-
source = $(source);
-
target = $(target);
-
target.style.position = 'absolute';
-
var
offsets =
this
.cumulativeOffset(source);
-
target.style.top = offsets[1] + 'px';
-
target.style.left = offsets[0] + 'px';
-
target.style.width = source.offsetWidth + 'px';
-
target.style.height = source.offsetHeight + 'px';
-
}
-
}
|