js 代码
-
-
-
-
if
(
this
.options.evalScripts && scripts) {
-
-
-
-
-
-
-
-
-
match =
new
RegExp(Ajax.Updater.ScriptFragment, 'im');
-
setTimeout((
function
() {
-
for
(
var
i = 0; i < scripts.length; i++)
-
eval(scripts.match(match)[1]);
-
}).bind(
this
), 10);
-
}
-
}
-
});
-
-
-
-
Ajax.PeriodicalUpdater = Class.create();
-
Ajax.PeriodicalUpdater.prototype = (
new
Ajax.Base()).extend({
-
initialize:
function
(container, url, options) {
-
this
.setOptions(options);
-
this
.onComplete =
this
.options.onComplete;
-
this
.frequency = (
this
.options.frequency || 2);
-
-
this
.decay = 1;
-
this
.updater = {};
-
this
.container = container;
-
this
.url = url;
-
this
.start();
-
},
-
start:
function
() {
-
this
.options.onComplete =
this
.updateComplete.bind(
this
);
-
this
.onTimerEvent();
-
},
-
stop:
function
() {
-
this
.updater.onComplete = undefined;
-
clearTimeout(
this
.timer);
-
(
this
.onComplete || Ajax.emptyFunction).apply(
this
, arguments);
-
},
-
updateComplete:
function
(request) {
-
if
(
this
.options.decay) {
-
this
.decay = (request.responseText ==
this
.lastText ?
-
this
.decay *
this
.options.decay : 1);
-
this
.lastText = request.responseText;
-
}
-
this
.timer = setTimeout(
this
.onTimerEvent.bind(
this
),
-
this
.decay *
this
.frequency * 1000);
-
},
-
onTimerEvent:
function
() {
-
this
.updater =
new
Ajax.Updater(
this
.container,
this
.url,
this
.options);
-
}
-
});
-
-
-
-
-
document.getElementsByClassName =
function
(className) {
-
var
children = document.getElementsByTagName('*') || document.all;
-
var
elements =
new
Array();
-
for
(
var
i = 0; i < children.length; i++) {
-
var
child = children;
-
var
classNames = child.className.split(' ');
-
for
(
var
j = 0; j < classNames.length; j++) {
-
if
(classNames[j] == className) {
-
elements.push(child);
-
break
;
-
}
-
}
-
}
-
return
elements;
-
}
-
-
-
-
-
-
if
(!window.Element) {
-
var
Element =
new
Object();
-
}
-
Object.extend(Element, {
-
-
-
-
toggle:
function
() {
-
for
(
var
i = 0; i < arguments.length; i++) {
-
var
element = $(arguments);
-
element.style.display =
-
(element.style.display == 'none' ?
''
: 'none');
-
}
-
},
-
hide:
function
() {
-
for
(
var
i = 0; i < arguments.length; i++) {
-
var
element = $(arguments);
-
element.style.display = 'none';
-
}
-
},
-
show:
function
() {
-
for
(
var
i = 0; i < arguments.length; i++) {
-
var
element = $(arguments);
-
element.style.display =
''
;
-
}
-
},
-
-
-
-
remove:
function
(element) {
-
element = $(element);
-
element.parentNode.removeChild(element);
-
},
-
-
getHeight:
function
(element) {
-
element = $(element);
-
return
element.offsetHeight;
-
},
-
-
-
-
hasClassName:
function
(element, className) {
-
element = $(element);
-
if
(!element)
-
return
;
-
var
a = element.className.split(' ');
-
for
(
var
i = 0; i < a.length; i++) {
-
if
(a == className)
-
return
true
;
-
}
-
return
false
;
-
},
-
-
-
-
addClassName:
function
(element, className) {
-
element = $(element);
-
Element.removeClassName(element, className);
-
element.className += ' ' + className;
-
},
-
-
-
-
removeClassName:
function
(element, className) {
-
element = $(element);
-
if
(!element)
-
return
;
-
var
newClassName =
''
;
-
var
a = element.className.split(' ');
-
for
(
var
i = 0; i < a.length; i++) {
-
if
(a != className) {
-
if
(i > 0)
-
newClassName += ' ';
-
newClassName += a;
-
}
-
}
-
element.className = newClassName;
-
},
-
-
cleanWhitespace:
function
(element) {
-
var
element = $(element);
-
for
(
var
i = 0; i < element.childNodes.length; i++) {
-
var
node = element.childNodes;
-
if
(node.nodeType == 3 && !/S/.test(node.nodeValue))
-
Element.remove(node);
-
}
-
}
-
});
-
-
-
-
var
Toggle =
new
Object();
-
Toggle.display = Element.toggle;
-
-
-
-
-
Abstract.Insertion =
function
(adjacency) {
-
this
.adjacency = adjacency;
-
}
-
Abstract.Insertion.prototype = {
-
initialize:
function
(element, content) {
-
this
.element = $(element);
-
this
.content = content;
-
-
if
(
this
.adjacency &&
this
.element.insertAdjacentHTML) {
-
this
.element.insertAdjacentHTML(
this
.adjacency,
this
.content);
-
}
else
{
-
-
-
-
this
.range =
this
.element.ownerDocument.createRange();
-
-
-
-
if
(
this
.initializeRange)
this
.initializeRange();
-
this
.fragment =
this
.range.createContextualFragment(
this
.content);
-
-
-
-
this
.insertContent();
-
}
-
}
-
}
-
-
-
-
-
-
-
var
Insertion =
new
Object();
-
-
-
-
Insertion.Before = Class.create();
-
Insertion.Before.prototype = (
new
Abstract.Insertion('beforeBegin')).extend({
-
initializeRange:
function
() {
-
this
.range.setStartBefore(
this
.element);
-
},
-
insertContent:
function
() {
-
this
.element.parentNode.insertBefore(
this
.fragment,
this
.element);
-
}
-
});
-
-
-
-
Insertion.Top = Class.create();
-
Insertion.Top.prototype = (
new
Abstract.Insertion('afterBegin')).extend({
-
initializeRange:
function
() {
-
this
.range.selectNodeContents(
this
.element);
-
this
.range.collapse(
true
);
-
},
-
insertContent:
function
() {
-
this
.element.insertBefore(
this
.fragment,
this
.element.firstChild);
-
}
-
});
-
-
-
-
Insertion.Bottom = Class.create();
-
Insertion.Bottom.prototype = (
new
Abstract.Insertion('beforeEnd')).extend({
-
initializeRange:
function
() {
-
this
.range.selectNodeContents(
this
.element);
-
this
.range.collapse(
this
.element);
-
},
-
insertContent:
function
() {
-
this
.element.appendChild(
this
.fragment);
-
}
-
});
-
-
-
-
Insertion.After = Class.create();
-
Insertion.After.prototype = (
new
Abstract.Insertion('afterEnd')).extend({
-
initializeRange:
function
() {
-
this
.range.setStartAfter(
this
.element);
-
},
-
insertContent:
function
() {
-
this
.element.parentNode.insertBefore(
this
.fragment,
-
this
.element.nextSibling);
-
}
-
});
-
-
-
-
-
-
-
-
-
-
-
var
Field = {
-
-
-
-
clear:
function
() {
-
for
(
var
i = 0; i < arguments.length; i++)
-
$(arguments).value =
''
;
-
},
-
-
-
-
focus:
function
(element) {
-
$(element).focus();
-
},
-
-
-
-
present:
function
() {
-
for
(
var
i = 0; i < arguments.length; i++)
-
if
($(arguments).value ==
''
)
return
false
;
-
return
true
;
-
},
-
-
-
-
select:
function
(element) {
-
$(element).select();
-
},
-
-
-
-
activate:
function
(element) {
-
$(element).focus();
-
$(element).select();
-
}
-
}
-
-
-
-
var
Form = {
-
-
-
-
serialize:
function
(form) {
-
var
elements = Form.getElements($(form));
-
var
queryComponents =
new
Array();
-
-
for
(
var
i = 0; i < elements.length; i++) {
-
var
queryComponent = Form.Element.serialize(elements);
-
if
(queryComponent)
-
queryComponents.push(queryComponent);
-
}
-
-
return
queryComponents.join('&');
-
},
-
-
-
-
getElements:
function
(form) {
-
var
form = $(form);
-
var
elements =
new
Array();
-
for
(tagName
in
Form.Element.Serializers) {
-
var
tagElements = form.getElementsByTagName(tagName);
-
for
(
var
j = 0; j < tagElements.length; j++)
-
elements.push(tagElements[j]);
-
}
-
return
elements;
-
},
-
-
-
-
getInputs:
function
(form, typeName, name) {
-
var
form = $(form);
-
var
inputs = form.getElementsByTagName('input');
-
-
if
(!typeName && !name)
-
return
inputs;
-
-
var
matchingInputs =
new
Array();
-
for
(
var
i = 0; i < inputs.length; i++) {
-
var
input = inputs;
-
if
((typeName && input.type != typeName) ||
-
(name && input.name != name))
-
continue
;
-
matchingInputs.push(input);
-
}
-
return
matchingInputs;
-
},
-
-
-
-
disable:
function
(form) {
-
var
elements = Form.getElements(form);
-
for
(
var
i = 0; i < elements.length; i++) {
-
var
element = elements;
-
element.blur();
-
element.disabled = '
true
';
-
}
-
},
-
-
-
-
enable:
function
(form) {
-
var
elements = Form.getElements(form);
-
for
(
var
i = 0; i < elements.length; i++) {
-
var
element = elements;
-
element.disabled =
''
;
-
}
-
},
-
-
-
-
focusFirstElement:
function
(form) {
-
var
form = $(form);
-
var
elements = Form.getElements(form);
-
for
(
var
i = 0; i < elements.length; i++) {
-
var
element = elements;
-
if
(element.type != 'hidden' && !element.disabled) {
-
Field.activate(element);
-
break
;
-
}
-
}
-
},
-
-
-
-
reset:
function
(form) {
-
$(form).reset();
-
}
-
}
-
-
-
-
Form.Element = {
-
-
-
-
serialize:
function
(element) {
-
var
element = $(element);
-
var
method = element.tagName.toLowerCase();
-
var
parameter = Form.Element.Serializers[method](element);
-
-
if
(parameter)
-
return
encodeURIComponent(parameter[0]) + '=' +
-
encodeURIComponent(parameter[1]);
-
},
-
-
-
-
getValue:
function
(element) {
-
var
element = $(element);
-
var
method = element.tagName.toLowerCase();
-
var
parameter = Form.Element.Serializers[method](element);
-
-
if
(parameter)
-
return
parameter[1];
-
}
-
}
-
-
-
-
Form.Element.Serializers = {
-
input:
function
(element) {
-
switch
(element.type.toLowerCase()) {
-
case
'submit':
-
case
'hidden':
-
case
'password':
-
case
'text':
-
return
Form.Element.Serializers.textarea(element);
-
case
'checkbox':
-
case
'radio':
-
return
Form.Element.Serializers.inputSelector(element);
-
}
-
return
false
;
-
},
-
-
-
-
inputSelector:
function
(element) {
-
if
(element.checked)
-
return
[element.name, element.value];
-
},
-
-
-
-
textarea:
function
(element) {
-
return
[element.name, element.value];
-
},
-
-
-
-
select:
function
(element) {
-
var
value =
''
;
-
if
(element.type == 'select-one') {
-
var
index = element.selectedIndex;
-
if
(index >= 0)
-
value = element.options[index].value || element.options[index].text;
-
}
else
{
-
-
-
-
value =
new
Array();
-
for
(
var
i = 0; i < element.length; i++) {
-
var
opt = element.options;
-
if
(opt.selected)
-
value.push(opt.value || opt.text);
-
}
-
}
-
return
[element.name, value];
-
}
-
}
|