sproutcore 0.9.13 → 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +19 -0
- data/Manifest.txt +103 -26
- data/app_generators/sproutcore/templates/README +1 -1
- data/bin/sc-build +1 -1
- data/bin/sc-gen +0 -0
- data/bin/sc-ide +278 -0
- data/bin/sc-init +38 -0
- data/bin/sc-install +96 -0
- data/bin/sc-remove +94 -0
- data/bin/sc-server +4 -0
- data/bin/sc-update +94 -0
- data/bin/sproutcore +3 -14
- data/clients/sc_docs/controllers/docs.js +1 -1
- data/clients/sc_docs/models/doc.js +6 -0
- data/clients/sc_docs/views/doc_frame.js +1 -1
- data/clients/sc_test_runner/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_test_runner/english.lproj/icons/small/reset.png +0 -0
- data/frameworks/sproutcore/HISTORY +34 -2
- data/frameworks/sproutcore/controllers/array.js +1 -1
- data/frameworks/sproutcore/controllers/controller.js +1 -1
- data/frameworks/sproutcore/controllers/object.js +9 -6
- data/frameworks/sproutcore/core.js +19 -4
- data/frameworks/sproutcore/english.lproj/blank.gif +0 -0
- data/frameworks/sproutcore/english.lproj/core.css +1 -0
- data/frameworks/sproutcore/english.lproj/menu.css +1 -0
- data/frameworks/sproutcore/foundation/application.js +3 -3
- data/frameworks/sproutcore/foundation/benchmark.js +1 -1
- data/frameworks/sproutcore/foundation/node_descriptor.js +13 -1
- data/frameworks/sproutcore/foundation/page.js +3 -2
- data/frameworks/sproutcore/foundation/path_module.js +33 -16
- data/frameworks/sproutcore/foundation/run_loop.js +1 -1
- data/frameworks/sproutcore/foundation/server.js +68 -18
- data/frameworks/sproutcore/foundation/string.js +1 -1
- data/frameworks/sproutcore/globals/window.js +62 -15
- data/frameworks/sproutcore/lib/core_views.rb +1 -0
- data/frameworks/sproutcore/lib/index.rhtml +4 -3
- data/frameworks/sproutcore/lib/menu_views.rb +2 -2
- data/frameworks/sproutcore/models/collection.js +122 -107
- data/frameworks/sproutcore/models/record.js +2 -2
- data/frameworks/sproutcore/panes/manager.js +1 -1
- data/frameworks/sproutcore/panes/overlay.js +3 -3
- data/frameworks/sproutcore/tests/controllers/object.rhtml +26 -0
- data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +2 -2
- data/frameworks/sproutcore/views/button/disclosure.js +1 -1
- data/frameworks/sproutcore/views/collection/collection.js +19 -15
- data/frameworks/sproutcore/views/collection/source_list.js +1 -1
- data/frameworks/sproutcore/views/collection/table.js +2 -2
- data/frameworks/sproutcore/views/error_explanation.js +1 -1
- data/frameworks/sproutcore/views/field/checkbox_field.js +1 -1
- data/frameworks/sproutcore/views/field/field.js +1 -1
- data/frameworks/sproutcore/views/field/radio_field.js +1 -1
- data/frameworks/sproutcore/views/field/select_field.js +1 -1
- data/frameworks/sproutcore/views/form.js +1 -1
- data/frameworks/sproutcore/views/image.js +1 -1
- data/frameworks/sproutcore/views/menu_item.js +1 -1
- data/frameworks/sproutcore/views/popup_button.js +1 -1
- data/frameworks/sproutcore/views/popup_menu.js +1 -1
- data/frameworks/sproutcore/views/progress.js +4 -2
- data/frameworks/sproutcore/views/radio_group.js +1 -1
- data/frameworks/sproutcore/views/scroll.js +1 -1
- data/frameworks/sproutcore/views/source_list_group.js +1 -1
- data/frameworks/sproutcore/views/split.js +1 -1
- data/frameworks/sproutcore/views/tab.js +3 -1
- data/frameworks/sproutcore/views/view.js +19 -3
- data/jsdoc/README.txt +89 -57
- data/jsdoc/app/frame/Chain.js +102 -0
- data/jsdoc/app/frame/Dumper.js +144 -0
- data/jsdoc/app/frame/Hash.js +47 -0
- data/jsdoc/app/frame/Link.js +142 -0
- data/jsdoc/app/frame/Namespace.js +10 -0
- data/jsdoc/app/frame/Opt.js +134 -0
- data/jsdoc/app/frame/Reflection.js +26 -0
- data/jsdoc/app/frame/String.js +93 -0
- data/jsdoc/app/frame/Testrun.js +129 -0
- data/jsdoc/app/frame.js +33 -0
- data/jsdoc/app/handlers/FOODOC.js +26 -0
- data/jsdoc/app/handlers/XMLDOC/DomReader.js +159 -0
- data/jsdoc/app/handlers/XMLDOC/XMLDoc.js +16 -0
- data/jsdoc/app/handlers/XMLDOC/XMLParse.js +292 -0
- data/jsdoc/app/handlers/XMLDOC.js +26 -0
- data/jsdoc/app/lib/JSDOC/DocComment.js +200 -0
- data/jsdoc/app/lib/JSDOC/DocTag.js +294 -0
- data/jsdoc/app/lib/JSDOC/JsDoc.js +180 -0
- data/jsdoc/app/lib/JSDOC/JsPlate.js +100 -0
- data/jsdoc/app/lib/JSDOC/Lang.js +144 -0
- data/jsdoc/app/lib/JSDOC/Parser.js +109 -0
- data/jsdoc/app/lib/JSDOC/PluginManager.js +33 -0
- data/jsdoc/app/lib/JSDOC/Symbol.js +600 -0
- data/jsdoc/app/lib/JSDOC/SymbolSet.js +220 -0
- data/jsdoc/app/lib/JSDOC/TextStream.js +41 -0
- data/jsdoc/app/lib/JSDOC/Token.js +18 -0
- data/jsdoc/app/lib/JSDOC/TokenReader.js +323 -0
- data/jsdoc/app/lib/JSDOC/TokenStream.js +133 -0
- data/jsdoc/app/lib/JSDOC/Util.js +32 -0
- data/jsdoc/app/lib/JSDOC/Walker.js +416 -0
- data/jsdoc/app/lib/JSDOC.js +97 -0
- data/jsdoc/app/main.js +74 -0
- data/jsdoc/app/plugins/commentSrcJson.js +19 -0
- data/jsdoc/app/plugins/frameworkPrototype.js +16 -0
- data/jsdoc/app/plugins/functionCall.js +10 -0
- data/jsdoc/app/plugins/publishSrcHilite.js +62 -0
- data/jsdoc/app/plugins/sproutcoreTags.js +26 -0
- data/jsdoc/app/plugins/symbolLink.js +9 -0
- data/jsdoc/app/plugins/tagParamConfig.js +31 -0
- data/jsdoc/app/plugins/tagSynonyms.js +43 -0
- data/jsdoc/app/run.js +339 -137
- data/jsdoc/changes.txt +47 -0
- data/jsdoc/conf/sample.conf +31 -0
- data/jsdoc/java/build.xml +36 -0
- data/jsdoc/java/build_1.4.xml +36 -0
- data/jsdoc/java/classes/js.jar +0 -0
- data/jsdoc/java/src/JsDebugRun.java +21 -0
- data/jsdoc/java/src/JsRun.java +21 -0
- data/jsdoc/jsdebug.jar +0 -0
- data/jsdoc/jsrun.jar +0 -0
- data/jsdoc/t/TestDoc.js +144 -0
- data/jsdoc/t/runner.js +13 -0
- data/jsdoc/templates/sproutcore/allclasses.tmpl +17 -0
- data/jsdoc/templates/sproutcore/allfiles.tmpl +56 -0
- data/jsdoc/templates/sproutcore/class.tmpl +408 -326
- data/jsdoc/templates/sproutcore/index.tmpl +30 -31
- data/jsdoc/templates/sproutcore/publish.js +173 -81
- data/jsdoc/templates/sproutcore/static/default.css +191 -0
- data/jsdoc/templates/sproutcore/static/header.html +2 -0
- data/jsdoc/templates/sproutcore/static/index.html +19 -0
- data/jsdoc/templates/sproutcore/symbol.tmpl +35 -0
- data/jsdoc/test/addon.js +24 -0
- data/jsdoc/test/anon_inner.js +14 -0
- data/jsdoc/test/augments.js +31 -0
- data/jsdoc/test/augments2.js +26 -0
- data/jsdoc/test/borrows.js +41 -0
- data/jsdoc/test/borrows2.js +23 -0
- data/jsdoc/test/config.js +22 -0
- data/jsdoc/test/constructs.js +18 -0
- data/jsdoc/test/encoding.js +10 -0
- data/jsdoc/test/encoding_other.js +12 -0
- data/jsdoc/test/functions_anon.js +39 -0
- data/jsdoc/test/functions_nested.js +33 -0
- data/jsdoc/test/global.js +13 -0
- data/jsdoc/test/globals.js +25 -0
- data/jsdoc/test/ignore.js +10 -0
- data/jsdoc/test/inner.js +16 -0
- data/jsdoc/test/jsdoc_test.js +477 -0
- data/jsdoc/test/lend.js +33 -0
- data/jsdoc/test/memberof.js +20 -0
- data/jsdoc/test/memberof_constructor.js +15 -0
- data/jsdoc/test/name.js +19 -0
- data/jsdoc/test/namespace_nested.js +23 -0
- data/jsdoc/test/nocode.js +13 -0
- data/jsdoc/test/oblit_anon.js +20 -0
- data/jsdoc/test/overview.js +20 -0
- data/jsdoc/test/param_inline.js +37 -0
- data/jsdoc/test/params_optional.js +8 -0
- data/jsdoc/test/prototype.js +17 -0
- data/jsdoc/test/prototype_nested.js +9 -0
- data/jsdoc/test/prototype_oblit.js +13 -0
- data/jsdoc/test/prototype_oblit_constructor.js +24 -0
- data/jsdoc/test/public.js +10 -0
- data/jsdoc/test/shared.js +42 -0
- data/jsdoc/test/shared2.js +2 -0
- data/jsdoc/test/shortcuts.js +22 -0
- data/jsdoc/test/static_this.js +13 -0
- data/jsdoc/test/synonyms.js +23 -0
- data/jsdoc/test/tosource.js +23 -0
- data/jsdoc/test/variable_redefine.js +14 -0
- data/jsdoc/test.js +304 -0
- data/lib/sproutcore/build_tools/resource_builder.rb +6 -1
- data/lib/sproutcore/bundle_installer.rb +268 -0
- data/lib/sproutcore/jsdoc.rb +7 -6
- data/lib/sproutcore/library.rb +38 -0
- data/lib/sproutcore/merb/bundle_controller.rb +8 -4
- data/lib/sproutcore/version.rb +1 -1
- data/lib/sproutcore.rb +1 -1
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- metadata +117 -29
- data/clients/view_builder/core.js +0 -19
- data/clients/view_builder/english.lproj/body.css +0 -149
- data/clients/view_builder/english.lproj/body.rhtml +0 -18
- data/clients/view_builder/english.lproj/strings.js +0 -14
- data/clients/view_builder/main.js +0 -37
- data/jsdoc/app/DocFile.js +0 -137
- data/jsdoc/app/DocTag.js +0 -110
- data/jsdoc/app/Doclet.js +0 -63
- data/jsdoc/app/Dumper.js +0 -143
- data/jsdoc/app/JsDoc.js +0 -103
- data/jsdoc/app/JsHilite.js +0 -45
- data/jsdoc/app/JsIO.js +0 -163
- data/jsdoc/app/JsParse.js +0 -385
- data/jsdoc/app/JsPlate.js +0 -130
- data/jsdoc/app/JsTestrun.js +0 -129
- data/jsdoc/app/JsToke.js +0 -564
- data/jsdoc/app/Symbol.js +0 -298
- data/jsdoc/app/Transformer.js +0 -14
- data/jsdoc/app/Util.js +0 -97
- data/jsdoc/app/js.jar +0 -0
- data/jsdoc/plugins/min.js +0 -316
- data/jsdoc/plugins/strip.js +0 -20
- data/jsdoc/templates/sproutcore/default.css +0 -191
- data/jsdoc/templates/sproutcore/index.html +0 -13
- data/jsdoc/templates/sproutcore/prototype.js +0 -4186
- data/jsdoc/templates/sproutcore/splash.html +0 -7
@@ -1,4186 +0,0 @@
|
|
1
|
-
/* @license
|
2
|
-
* Prototype JavaScript framework, version 1.6.0
|
3
|
-
* (c) 2005-2007 Sam Stephenson
|
4
|
-
*
|
5
|
-
* Prototype is freely distributable under the terms of an MIT-style license.
|
6
|
-
* For details, see the Prototype web site: http://www.prototypejs.org/
|
7
|
-
*
|
8
|
-
*--------------------------------------------------------------------------
|
9
|
-
@license */
|
10
|
-
|
11
|
-
var Prototype = {
|
12
|
-
Version: '1.6.0',
|
13
|
-
|
14
|
-
Browser: {
|
15
|
-
IE: !!(window.attachEvent && !window.opera),
|
16
|
-
Opera: !!window.opera,
|
17
|
-
WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
|
18
|
-
Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
|
19
|
-
MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
|
20
|
-
},
|
21
|
-
|
22
|
-
BrowserFeatures: {
|
23
|
-
XPath: !!document.evaluate,
|
24
|
-
ElementExtensions: !!window.HTMLElement,
|
25
|
-
SpecificElementExtensions:
|
26
|
-
document.createElement('div').__proto__ &&
|
27
|
-
document.createElement('div').__proto__ !==
|
28
|
-
document.createElement('form').__proto__
|
29
|
-
},
|
30
|
-
|
31
|
-
ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
|
32
|
-
JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
|
33
|
-
|
34
|
-
emptyFunction: function() { },
|
35
|
-
K: function(x) { return x }
|
36
|
-
};
|
37
|
-
|
38
|
-
if (Prototype.Browser.MobileSafari)
|
39
|
-
Prototype.BrowserFeatures.SpecificElementExtensions = false;
|
40
|
-
|
41
|
-
if (Prototype.Browser.WebKit)
|
42
|
-
Prototype.BrowserFeatures.XPath = false;
|
43
|
-
|
44
|
-
/* Based on Alex Arnell's inheritance implementation. */
|
45
|
-
var Class = {
|
46
|
-
create: function() {
|
47
|
-
var parent = null, properties = $A(arguments);
|
48
|
-
if (Object.isFunction(properties[0]))
|
49
|
-
parent = properties.shift();
|
50
|
-
|
51
|
-
function klass() {
|
52
|
-
this.initialize.apply(this, arguments);
|
53
|
-
}
|
54
|
-
|
55
|
-
Object.extend(klass, Class.Methods);
|
56
|
-
klass.superclass = parent;
|
57
|
-
klass.subclasses = [];
|
58
|
-
|
59
|
-
if (parent) {
|
60
|
-
var subclass = function() { };
|
61
|
-
subclass.prototype = parent.prototype;
|
62
|
-
klass.prototype = new subclass;
|
63
|
-
parent.subclasses.push(klass);
|
64
|
-
}
|
65
|
-
|
66
|
-
for (var i = 0; i < properties.length; i++)
|
67
|
-
klass.addMethods(properties[i]);
|
68
|
-
|
69
|
-
if (!klass.prototype.initialize)
|
70
|
-
klass.prototype.initialize = Prototype.emptyFunction;
|
71
|
-
|
72
|
-
klass.prototype.constructor = klass;
|
73
|
-
|
74
|
-
return klass;
|
75
|
-
}
|
76
|
-
};
|
77
|
-
|
78
|
-
Class.Methods = {
|
79
|
-
addMethods: function(source) {
|
80
|
-
var ancestor = this.superclass && this.superclass.prototype;
|
81
|
-
var properties = Object.keys(source);
|
82
|
-
|
83
|
-
if (!Object.keys({ toString: true }).length)
|
84
|
-
properties.push("toString", "valueOf");
|
85
|
-
|
86
|
-
for (var i = 0, length = properties.length; i < length; i++) {
|
87
|
-
var property = properties[i], value = source[property];
|
88
|
-
if (ancestor && Object.isFunction(value) &&
|
89
|
-
value.argumentNames().first() == "$super") {
|
90
|
-
var method = value, value = Object.extend((function(m) {
|
91
|
-
return function() { return ancestor[m].apply(this, arguments) };
|
92
|
-
})(property).wrap(method), {
|
93
|
-
valueOf: function() { return method },
|
94
|
-
toString: function() { return method.toString() }
|
95
|
-
});
|
96
|
-
}
|
97
|
-
this.prototype[property] = value;
|
98
|
-
}
|
99
|
-
|
100
|
-
return this;
|
101
|
-
}
|
102
|
-
};
|
103
|
-
|
104
|
-
var Abstract = { };
|
105
|
-
|
106
|
-
Object.extend = function(destination, source) {
|
107
|
-
for (var property in source)
|
108
|
-
destination[property] = source[property];
|
109
|
-
return destination;
|
110
|
-
};
|
111
|
-
|
112
|
-
Object.extend(Object, {
|
113
|
-
inspect: function(object) {
|
114
|
-
try {
|
115
|
-
if (object === undefined) return 'undefined';
|
116
|
-
if (object === null) return 'null';
|
117
|
-
return object.inspect ? object.inspect() : object.toString();
|
118
|
-
} catch (e) {
|
119
|
-
if (e instanceof RangeError) return '...';
|
120
|
-
throw e;
|
121
|
-
}
|
122
|
-
},
|
123
|
-
|
124
|
-
toJSON: function(object) {
|
125
|
-
var type = typeof object;
|
126
|
-
switch (type) {
|
127
|
-
case 'undefined':
|
128
|
-
case 'function':
|
129
|
-
case 'unknown': return;
|
130
|
-
case 'boolean': return object.toString();
|
131
|
-
}
|
132
|
-
|
133
|
-
if (object === null) return 'null';
|
134
|
-
if (object.toJSON) return object.toJSON();
|
135
|
-
if (Object.isElement(object)) return;
|
136
|
-
|
137
|
-
var results = [];
|
138
|
-
for (var property in object) {
|
139
|
-
var value = Object.toJSON(object[property]);
|
140
|
-
if (value !== undefined)
|
141
|
-
results.push(property.toJSON() + ': ' + value);
|
142
|
-
}
|
143
|
-
|
144
|
-
return '{' + results.join(', ') + '}';
|
145
|
-
},
|
146
|
-
|
147
|
-
toQueryString: function(object) {
|
148
|
-
return $H(object).toQueryString();
|
149
|
-
},
|
150
|
-
|
151
|
-
toHTML: function(object) {
|
152
|
-
return object && object.toHTML ? object.toHTML() : String.interpret(object);
|
153
|
-
},
|
154
|
-
|
155
|
-
keys: function(object) {
|
156
|
-
var keys = [];
|
157
|
-
for (var property in object)
|
158
|
-
keys.push(property);
|
159
|
-
return keys;
|
160
|
-
},
|
161
|
-
|
162
|
-
values: function(object) {
|
163
|
-
var values = [];
|
164
|
-
for (var property in object)
|
165
|
-
values.push(object[property]);
|
166
|
-
return values;
|
167
|
-
},
|
168
|
-
|
169
|
-
clone: function(object) {
|
170
|
-
return Object.extend({ }, object);
|
171
|
-
},
|
172
|
-
|
173
|
-
isElement: function(object) {
|
174
|
-
return object && object.nodeType == 1;
|
175
|
-
},
|
176
|
-
|
177
|
-
isArray: function(object) {
|
178
|
-
return object && object.constructor === Array;
|
179
|
-
},
|
180
|
-
|
181
|
-
isHash: function(object) {
|
182
|
-
return object instanceof Hash;
|
183
|
-
},
|
184
|
-
|
185
|
-
isFunction: function(object) {
|
186
|
-
return typeof object == "function";
|
187
|
-
},
|
188
|
-
|
189
|
-
isString: function(object) {
|
190
|
-
return typeof object == "string";
|
191
|
-
},
|
192
|
-
|
193
|
-
isNumber: function(object) {
|
194
|
-
return typeof object == "number";
|
195
|
-
},
|
196
|
-
|
197
|
-
isUndefined: function(object) {
|
198
|
-
return typeof object == "undefined";
|
199
|
-
}
|
200
|
-
});
|
201
|
-
|
202
|
-
Object.extend(Function.prototype, {
|
203
|
-
argumentNames: function() {
|
204
|
-
var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");
|
205
|
-
return names.length == 1 && !names[0] ? [] : names;
|
206
|
-
},
|
207
|
-
|
208
|
-
bind: function() {
|
209
|
-
if (arguments.length < 2 && arguments[0] === undefined) return this;
|
210
|
-
var __method = this, args = $A(arguments), object = args.shift();
|
211
|
-
return function() {
|
212
|
-
return __method.apply(object, args.concat($A(arguments)));
|
213
|
-
}
|
214
|
-
},
|
215
|
-
|
216
|
-
bindAsEventListener: function() {
|
217
|
-
var __method = this, args = $A(arguments), object = args.shift();
|
218
|
-
return function(event) {
|
219
|
-
return __method.apply(object, [event || window.event].concat(args));
|
220
|
-
}
|
221
|
-
},
|
222
|
-
|
223
|
-
curry: function() {
|
224
|
-
if (!arguments.length) return this;
|
225
|
-
var __method = this, args = $A(arguments);
|
226
|
-
return function() {
|
227
|
-
return __method.apply(this, args.concat($A(arguments)));
|
228
|
-
}
|
229
|
-
},
|
230
|
-
|
231
|
-
delay: function() {
|
232
|
-
var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
|
233
|
-
return window.setTimeout(function() {
|
234
|
-
return __method.apply(__method, args);
|
235
|
-
}, timeout);
|
236
|
-
},
|
237
|
-
|
238
|
-
wrap: function(wrapper) {
|
239
|
-
var __method = this;
|
240
|
-
return function() {
|
241
|
-
return wrapper.apply(this, [__method.bind(this)].concat($A(arguments)));
|
242
|
-
}
|
243
|
-
},
|
244
|
-
|
245
|
-
methodize: function() {
|
246
|
-
if (this._methodized) return this._methodized;
|
247
|
-
var __method = this;
|
248
|
-
return this._methodized = function() {
|
249
|
-
return __method.apply(null, [this].concat($A(arguments)));
|
250
|
-
};
|
251
|
-
}
|
252
|
-
});
|
253
|
-
|
254
|
-
Function.prototype.defer = Function.prototype.delay.curry(0.01);
|
255
|
-
|
256
|
-
Date.prototype.toJSON = function() {
|
257
|
-
return '"' + this.getUTCFullYear() + '-' +
|
258
|
-
(this.getUTCMonth() + 1).toPaddedString(2) + '-' +
|
259
|
-
this.getUTCDate().toPaddedString(2) + 'T' +
|
260
|
-
this.getUTCHours().toPaddedString(2) + ':' +
|
261
|
-
this.getUTCMinutes().toPaddedString(2) + ':' +
|
262
|
-
this.getUTCSeconds().toPaddedString(2) + 'Z"';
|
263
|
-
};
|
264
|
-
|
265
|
-
var Try = {
|
266
|
-
these: function() {
|
267
|
-
var returnValue;
|
268
|
-
|
269
|
-
for (var i = 0, length = arguments.length; i < length; i++) {
|
270
|
-
var lambda = arguments[i];
|
271
|
-
try {
|
272
|
-
returnValue = lambda();
|
273
|
-
break;
|
274
|
-
} catch (e) { }
|
275
|
-
}
|
276
|
-
|
277
|
-
return returnValue;
|
278
|
-
}
|
279
|
-
};
|
280
|
-
|
281
|
-
RegExp.prototype.match = RegExp.prototype.test;
|
282
|
-
|
283
|
-
RegExp.escape = function(str) {
|
284
|
-
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
285
|
-
};
|
286
|
-
|
287
|
-
/*--------------------------------------------------------------------------*/
|
288
|
-
|
289
|
-
var PeriodicalExecuter = Class.create({
|
290
|
-
initialize: function(callback, frequency) {
|
291
|
-
this.callback = callback;
|
292
|
-
this.frequency = frequency;
|
293
|
-
this.currentlyExecuting = false;
|
294
|
-
|
295
|
-
this.registerCallback();
|
296
|
-
},
|
297
|
-
|
298
|
-
registerCallback: function() {
|
299
|
-
this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
|
300
|
-
},
|
301
|
-
|
302
|
-
execute: function() {
|
303
|
-
this.callback(this);
|
304
|
-
},
|
305
|
-
|
306
|
-
stop: function() {
|
307
|
-
if (!this.timer) return;
|
308
|
-
clearInterval(this.timer);
|
309
|
-
this.timer = null;
|
310
|
-
},
|
311
|
-
|
312
|
-
onTimerEvent: function() {
|
313
|
-
if (!this.currentlyExecuting) {
|
314
|
-
try {
|
315
|
-
this.currentlyExecuting = true;
|
316
|
-
this.execute();
|
317
|
-
} finally {
|
318
|
-
this.currentlyExecuting = false;
|
319
|
-
}
|
320
|
-
}
|
321
|
-
}
|
322
|
-
});
|
323
|
-
Object.extend(String, {
|
324
|
-
interpret: function(value) {
|
325
|
-
return value == null ? '' : String(value);
|
326
|
-
},
|
327
|
-
specialChar: {
|
328
|
-
'\b': '\\b',
|
329
|
-
'\t': '\\t',
|
330
|
-
'\n': '\\n',
|
331
|
-
'\f': '\\f',
|
332
|
-
'\r': '\\r',
|
333
|
-
'\\': '\\\\'
|
334
|
-
}
|
335
|
-
});
|
336
|
-
|
337
|
-
Object.extend(String.prototype, {
|
338
|
-
gsub: function(pattern, replacement) {
|
339
|
-
var result = '', source = this, match;
|
340
|
-
replacement = arguments.callee.prepareReplacement(replacement);
|
341
|
-
|
342
|
-
while (source.length > 0) {
|
343
|
-
if (match = source.match(pattern)) {
|
344
|
-
result += source.slice(0, match.index);
|
345
|
-
result += String.interpret(replacement(match));
|
346
|
-
source = source.slice(match.index + match[0].length);
|
347
|
-
} else {
|
348
|
-
result += source, source = '';
|
349
|
-
}
|
350
|
-
}
|
351
|
-
return result;
|
352
|
-
},
|
353
|
-
|
354
|
-
sub: function(pattern, replacement, count) {
|
355
|
-
replacement = this.gsub.prepareReplacement(replacement);
|
356
|
-
count = count === undefined ? 1 : count;
|
357
|
-
|
358
|
-
return this.gsub(pattern, function(match) {
|
359
|
-
if (--count < 0) return match[0];
|
360
|
-
return replacement(match);
|
361
|
-
});
|
362
|
-
},
|
363
|
-
|
364
|
-
scan: function(pattern, iterator) {
|
365
|
-
this.gsub(pattern, iterator);
|
366
|
-
return String(this);
|
367
|
-
},
|
368
|
-
|
369
|
-
truncate: function(length, truncation) {
|
370
|
-
length = length || 30;
|
371
|
-
truncation = truncation === undefined ? '...' : truncation;
|
372
|
-
return this.length > length ?
|
373
|
-
this.slice(0, length - truncation.length) + truncation : String(this);
|
374
|
-
},
|
375
|
-
|
376
|
-
strip: function() {
|
377
|
-
return this.replace(/^\s+/, '').replace(/\s+$/, '');
|
378
|
-
},
|
379
|
-
|
380
|
-
stripTags: function() {
|
381
|
-
return this.replace(/<\/?[^>]+>/gi, '');
|
382
|
-
},
|
383
|
-
|
384
|
-
stripScripts: function() {
|
385
|
-
return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
|
386
|
-
},
|
387
|
-
|
388
|
-
extractScripts: function() {
|
389
|
-
var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
|
390
|
-
var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
|
391
|
-
return (this.match(matchAll) || []).map(function(scriptTag) {
|
392
|
-
return (scriptTag.match(matchOne) || ['', ''])[1];
|
393
|
-
});
|
394
|
-
},
|
395
|
-
|
396
|
-
evalScripts: function() {
|
397
|
-
return this.extractScripts().map(function(script) { return eval(script) });
|
398
|
-
},
|
399
|
-
|
400
|
-
escapeHTML: function() {
|
401
|
-
var self = arguments.callee;
|
402
|
-
self.text.data = this;
|
403
|
-
return self.div.innerHTML;
|
404
|
-
},
|
405
|
-
|
406
|
-
unescapeHTML: function() {
|
407
|
-
var div = new Element('div');
|
408
|
-
div.innerHTML = this.stripTags();
|
409
|
-
return div.childNodes[0] ? (div.childNodes.length > 1 ?
|
410
|
-
$A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
|
411
|
-
div.childNodes[0].nodeValue) : '';
|
412
|
-
},
|
413
|
-
|
414
|
-
toQueryParams: function(separator) {
|
415
|
-
var match = this.strip().match(/([^?#]*)(#.*)?$/);
|
416
|
-
if (!match) return { };
|
417
|
-
|
418
|
-
return match[1].split(separator || '&').inject({ }, function(hash, pair) {
|
419
|
-
if ((pair = pair.split('='))[0]) {
|
420
|
-
var key = decodeURIComponent(pair.shift());
|
421
|
-
var value = pair.length > 1 ? pair.join('=') : pair[0];
|
422
|
-
if (value != undefined) value = decodeURIComponent(value);
|
423
|
-
|
424
|
-
if (key in hash) {
|
425
|
-
if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
|
426
|
-
hash[key].push(value);
|
427
|
-
}
|
428
|
-
else hash[key] = value;
|
429
|
-
}
|
430
|
-
return hash;
|
431
|
-
});
|
432
|
-
},
|
433
|
-
|
434
|
-
toArray: function() {
|
435
|
-
return this.split('');
|
436
|
-
},
|
437
|
-
|
438
|
-
succ: function() {
|
439
|
-
return this.slice(0, this.length - 1) +
|
440
|
-
String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
|
441
|
-
},
|
442
|
-
|
443
|
-
times: function(count) {
|
444
|
-
return count < 1 ? '' : new Array(count + 1).join(this);
|
445
|
-
},
|
446
|
-
|
447
|
-
camelize: function() {
|
448
|
-
var parts = this.split('-'), len = parts.length;
|
449
|
-
if (len == 1) return parts[0];
|
450
|
-
|
451
|
-
var camelized = this.charAt(0) == '-'
|
452
|
-
? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
|
453
|
-
: parts[0];
|
454
|
-
|
455
|
-
for (var i = 1; i < len; i++)
|
456
|
-
camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
|
457
|
-
|
458
|
-
return camelized;
|
459
|
-
},
|
460
|
-
|
461
|
-
capitalize: function() {
|
462
|
-
return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
|
463
|
-
},
|
464
|
-
|
465
|
-
underscore: function() {
|
466
|
-
return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
|
467
|
-
},
|
468
|
-
|
469
|
-
dasherize: function() {
|
470
|
-
return this.gsub(/_/,'-');
|
471
|
-
},
|
472
|
-
|
473
|
-
inspect: function(useDoubleQuotes) {
|
474
|
-
var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
|
475
|
-
var character = String.specialChar[match[0]];
|
476
|
-
return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
|
477
|
-
});
|
478
|
-
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
|
479
|
-
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
|
480
|
-
},
|
481
|
-
|
482
|
-
toJSON: function() {
|
483
|
-
return this.inspect(true);
|
484
|
-
},
|
485
|
-
|
486
|
-
unfilterJSON: function(filter) {
|
487
|
-
return this.sub(filter || Prototype.JSONFilter, '#{1}');
|
488
|
-
},
|
489
|
-
|
490
|
-
isJSON: function() {
|
491
|
-
var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
|
492
|
-
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
|
493
|
-
},
|
494
|
-
|
495
|
-
evalJSON: function(sanitize) {
|
496
|
-
var json = this.unfilterJSON();
|
497
|
-
try {
|
498
|
-
if (!sanitize || json.isJSON()) return eval('(' + json + ')');
|
499
|
-
} catch (e) { }
|
500
|
-
throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
|
501
|
-
},
|
502
|
-
|
503
|
-
include: function(pattern) {
|
504
|
-
return this.indexOf(pattern) > -1;
|
505
|
-
},
|
506
|
-
|
507
|
-
startsWith: function(pattern) {
|
508
|
-
return this.indexOf(pattern) === 0;
|
509
|
-
},
|
510
|
-
|
511
|
-
endsWith: function(pattern) {
|
512
|
-
var d = this.length - pattern.length;
|
513
|
-
return d >= 0 && this.lastIndexOf(pattern) === d;
|
514
|
-
},
|
515
|
-
|
516
|
-
empty: function() {
|
517
|
-
return this == '';
|
518
|
-
},
|
519
|
-
|
520
|
-
blank: function() {
|
521
|
-
return /^\s*$/.test(this);
|
522
|
-
},
|
523
|
-
|
524
|
-
interpolate: function(object, pattern) {
|
525
|
-
return new Template(this, pattern).evaluate(object);
|
526
|
-
}
|
527
|
-
});
|
528
|
-
|
529
|
-
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
|
530
|
-
escapeHTML: function() {
|
531
|
-
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
532
|
-
},
|
533
|
-
unescapeHTML: function() {
|
534
|
-
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
535
|
-
}
|
536
|
-
});
|
537
|
-
|
538
|
-
String.prototype.gsub.prepareReplacement = function(replacement) {
|
539
|
-
if (Object.isFunction(replacement)) return replacement;
|
540
|
-
var template = new Template(replacement);
|
541
|
-
return function(match) { return template.evaluate(match) };
|
542
|
-
};
|
543
|
-
|
544
|
-
String.prototype.parseQuery = String.prototype.toQueryParams;
|
545
|
-
|
546
|
-
Object.extend(String.prototype.escapeHTML, {
|
547
|
-
div: document.createElement('div'),
|
548
|
-
text: document.createTextNode('')
|
549
|
-
});
|
550
|
-
|
551
|
-
with (String.prototype.escapeHTML) div.appendChild(text);
|
552
|
-
|
553
|
-
var Template = Class.create({
|
554
|
-
initialize: function(template, pattern) {
|
555
|
-
this.template = template.toString();
|
556
|
-
this.pattern = pattern || Template.Pattern;
|
557
|
-
},
|
558
|
-
|
559
|
-
evaluate: function(object) {
|
560
|
-
if (Object.isFunction(object.toTemplateReplacements))
|
561
|
-
object = object.toTemplateReplacements();
|
562
|
-
|
563
|
-
return this.template.gsub(this.pattern, function(match) {
|
564
|
-
if (object == null) return '';
|
565
|
-
|
566
|
-
var before = match[1] || '';
|
567
|
-
if (before == '\\') return match[2];
|
568
|
-
|
569
|
-
var ctx = object, expr = match[3];
|
570
|
-
var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/, match = pattern.exec(expr);
|
571
|
-
if (match == null) return before;
|
572
|
-
|
573
|
-
while (match != null) {
|
574
|
-
var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];
|
575
|
-
ctx = ctx[comp];
|
576
|
-
if (null == ctx || '' == match[3]) break;
|
577
|
-
expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
|
578
|
-
match = pattern.exec(expr);
|
579
|
-
}
|
580
|
-
|
581
|
-
return before + String.interpret(ctx);
|
582
|
-
}.bind(this));
|
583
|
-
}
|
584
|
-
});
|
585
|
-
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
586
|
-
|
587
|
-
var $break = { };
|
588
|
-
|
589
|
-
var Enumerable = {
|
590
|
-
each: function(iterator, context) {
|
591
|
-
var index = 0;
|
592
|
-
iterator = iterator.bind(context);
|
593
|
-
try {
|
594
|
-
this._each(function(value) {
|
595
|
-
iterator(value, index++);
|
596
|
-
});
|
597
|
-
} catch (e) {
|
598
|
-
if (e != $break) throw e;
|
599
|
-
}
|
600
|
-
return this;
|
601
|
-
},
|
602
|
-
|
603
|
-
eachSlice: function(number, iterator, context) {
|
604
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
605
|
-
var index = -number, slices = [], array = this.toArray();
|
606
|
-
while ((index += number) < array.length)
|
607
|
-
slices.push(array.slice(index, index+number));
|
608
|
-
return slices.collect(iterator, context);
|
609
|
-
},
|
610
|
-
|
611
|
-
all: function(iterator, context) {
|
612
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
613
|
-
var result = true;
|
614
|
-
this.each(function(value, index) {
|
615
|
-
result = result && !!iterator(value, index);
|
616
|
-
if (!result) throw $break;
|
617
|
-
});
|
618
|
-
return result;
|
619
|
-
},
|
620
|
-
|
621
|
-
any: function(iterator, context) {
|
622
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
623
|
-
var result = false;
|
624
|
-
this.each(function(value, index) {
|
625
|
-
if (result = !!iterator(value, index))
|
626
|
-
throw $break;
|
627
|
-
});
|
628
|
-
return result;
|
629
|
-
},
|
630
|
-
|
631
|
-
collect: function(iterator, context) {
|
632
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
633
|
-
var results = [];
|
634
|
-
this.each(function(value, index) {
|
635
|
-
results.push(iterator(value, index));
|
636
|
-
});
|
637
|
-
return results;
|
638
|
-
},
|
639
|
-
|
640
|
-
detect: function(iterator, context) {
|
641
|
-
iterator = iterator.bind(context);
|
642
|
-
var result;
|
643
|
-
this.each(function(value, index) {
|
644
|
-
if (iterator(value, index)) {
|
645
|
-
result = value;
|
646
|
-
throw $break;
|
647
|
-
}
|
648
|
-
});
|
649
|
-
return result;
|
650
|
-
},
|
651
|
-
|
652
|
-
findAll: function(iterator, context) {
|
653
|
-
iterator = iterator.bind(context);
|
654
|
-
var results = [];
|
655
|
-
this.each(function(value, index) {
|
656
|
-
if (iterator(value, index))
|
657
|
-
results.push(value);
|
658
|
-
});
|
659
|
-
return results;
|
660
|
-
},
|
661
|
-
|
662
|
-
grep: function(filter, iterator, context) {
|
663
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
664
|
-
var results = [];
|
665
|
-
|
666
|
-
if (Object.isString(filter))
|
667
|
-
filter = new RegExp(filter);
|
668
|
-
|
669
|
-
this.each(function(value, index) {
|
670
|
-
if (filter.match(value))
|
671
|
-
results.push(iterator(value, index));
|
672
|
-
});
|
673
|
-
return results;
|
674
|
-
},
|
675
|
-
|
676
|
-
include: function(object) {
|
677
|
-
if (Object.isFunction(this.indexOf))
|
678
|
-
if (this.indexOf(object) != -1) return true;
|
679
|
-
|
680
|
-
var found = false;
|
681
|
-
this.each(function(value) {
|
682
|
-
if (value == object) {
|
683
|
-
found = true;
|
684
|
-
throw $break;
|
685
|
-
}
|
686
|
-
});
|
687
|
-
return found;
|
688
|
-
},
|
689
|
-
|
690
|
-
inGroupsOf: function(number, fillWith) {
|
691
|
-
fillWith = fillWith === undefined ? null : fillWith;
|
692
|
-
return this.eachSlice(number, function(slice) {
|
693
|
-
while(slice.length < number) slice.push(fillWith);
|
694
|
-
return slice;
|
695
|
-
});
|
696
|
-
},
|
697
|
-
|
698
|
-
inject: function(memo, iterator, context) {
|
699
|
-
iterator = iterator.bind(context);
|
700
|
-
this.each(function(value, index) {
|
701
|
-
memo = iterator(memo, value, index);
|
702
|
-
});
|
703
|
-
return memo;
|
704
|
-
},
|
705
|
-
|
706
|
-
invoke: function(method) {
|
707
|
-
var args = $A(arguments).slice(1);
|
708
|
-
return this.map(function(value) {
|
709
|
-
return value[method].apply(value, args);
|
710
|
-
});
|
711
|
-
},
|
712
|
-
|
713
|
-
max: function(iterator, context) {
|
714
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
715
|
-
var result;
|
716
|
-
this.each(function(value, index) {
|
717
|
-
value = iterator(value, index);
|
718
|
-
if (result == undefined || value >= result)
|
719
|
-
result = value;
|
720
|
-
});
|
721
|
-
return result;
|
722
|
-
},
|
723
|
-
|
724
|
-
min: function(iterator, context) {
|
725
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
726
|
-
var result;
|
727
|
-
this.each(function(value, index) {
|
728
|
-
value = iterator(value, index);
|
729
|
-
if (result == undefined || value < result)
|
730
|
-
result = value;
|
731
|
-
});
|
732
|
-
return result;
|
733
|
-
},
|
734
|
-
|
735
|
-
partition: function(iterator, context) {
|
736
|
-
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
737
|
-
var trues = [], falses = [];
|
738
|
-
this.each(function(value, index) {
|
739
|
-
(iterator(value, index) ?
|
740
|
-
trues : falses).push(value);
|
741
|
-
});
|
742
|
-
return [trues, falses];
|
743
|
-
},
|
744
|
-
|
745
|
-
pluck: function(property) {
|
746
|
-
var results = [];
|
747
|
-
this.each(function(value) {
|
748
|
-
results.push(value[property]);
|
749
|
-
});
|
750
|
-
return results;
|
751
|
-
},
|
752
|
-
|
753
|
-
reject: function(iterator, context) {
|
754
|
-
iterator = iterator.bind(context);
|
755
|
-
var results = [];
|
756
|
-
this.each(function(value, index) {
|
757
|
-
if (!iterator(value, index))
|
758
|
-
results.push(value);
|
759
|
-
});
|
760
|
-
return results;
|
761
|
-
},
|
762
|
-
|
763
|
-
sortBy: function(iterator, context) {
|
764
|
-
iterator = iterator.bind(context);
|
765
|
-
return this.map(function(value, index) {
|
766
|
-
return {value: value, criteria: iterator(value, index)};
|
767
|
-
}).sort(function(left, right) {
|
768
|
-
var a = left.criteria, b = right.criteria;
|
769
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
770
|
-
}).pluck('value');
|
771
|
-
},
|
772
|
-
|
773
|
-
toArray: function() {
|
774
|
-
return this.map();
|
775
|
-
},
|
776
|
-
|
777
|
-
zip: function() {
|
778
|
-
var iterator = Prototype.K, args = $A(arguments);
|
779
|
-
if (Object.isFunction(args.last()))
|
780
|
-
iterator = args.pop();
|
781
|
-
|
782
|
-
var collections = [this].concat(args).map($A);
|
783
|
-
return this.map(function(value, index) {
|
784
|
-
return iterator(collections.pluck(index));
|
785
|
-
});
|
786
|
-
},
|
787
|
-
|
788
|
-
size: function() {
|
789
|
-
return this.toArray().length;
|
790
|
-
},
|
791
|
-
|
792
|
-
inspect: function() {
|
793
|
-
return '#<Enumerable:' + this.toArray().inspect() + '>';
|
794
|
-
}
|
795
|
-
};
|
796
|
-
|
797
|
-
Object.extend(Enumerable, {
|
798
|
-
map: Enumerable.collect,
|
799
|
-
find: Enumerable.detect,
|
800
|
-
select: Enumerable.findAll,
|
801
|
-
filter: Enumerable.findAll,
|
802
|
-
member: Enumerable.include,
|
803
|
-
entries: Enumerable.toArray,
|
804
|
-
every: Enumerable.all,
|
805
|
-
some: Enumerable.any
|
806
|
-
});
|
807
|
-
function $A(iterable) {
|
808
|
-
if (!iterable) return [];
|
809
|
-
if (iterable.toArray) return iterable.toArray();
|
810
|
-
var length = iterable.length, results = new Array(length);
|
811
|
-
while (length--) results[length] = iterable[length];
|
812
|
-
return results;
|
813
|
-
}
|
814
|
-
|
815
|
-
if (Prototype.Browser.WebKit) {
|
816
|
-
function $A(iterable) {
|
817
|
-
if (!iterable) return [];
|
818
|
-
if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
|
819
|
-
iterable.toArray) return iterable.toArray();
|
820
|
-
var length = iterable.length, results = new Array(length);
|
821
|
-
while (length--) results[length] = iterable[length];
|
822
|
-
return results;
|
823
|
-
}
|
824
|
-
}
|
825
|
-
|
826
|
-
Array.from = $A;
|
827
|
-
|
828
|
-
Object.extend(Array.prototype, Enumerable);
|
829
|
-
|
830
|
-
if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;
|
831
|
-
|
832
|
-
Object.extend(Array.prototype, {
|
833
|
-
_each: function(iterator) {
|
834
|
-
for (var i = 0, length = this.length; i < length; i++)
|
835
|
-
iterator(this[i]);
|
836
|
-
},
|
837
|
-
|
838
|
-
clear: function() {
|
839
|
-
this.length = 0;
|
840
|
-
return this;
|
841
|
-
},
|
842
|
-
|
843
|
-
first: function() {
|
844
|
-
return this[0];
|
845
|
-
},
|
846
|
-
|
847
|
-
last: function() {
|
848
|
-
return this[this.length - 1];
|
849
|
-
},
|
850
|
-
|
851
|
-
compact: function() {
|
852
|
-
return this.select(function(value) {
|
853
|
-
return value != null;
|
854
|
-
});
|
855
|
-
},
|
856
|
-
|
857
|
-
flatten: function() {
|
858
|
-
return this.inject([], function(array, value) {
|
859
|
-
return array.concat(Object.isArray(value) ?
|
860
|
-
value.flatten() : [value]);
|
861
|
-
});
|
862
|
-
},
|
863
|
-
|
864
|
-
without: function() {
|
865
|
-
var values = $A(arguments);
|
866
|
-
return this.select(function(value) {
|
867
|
-
return !values.include(value);
|
868
|
-
});
|
869
|
-
},
|
870
|
-
|
871
|
-
reverse: function(inline) {
|
872
|
-
return (inline !== false ? this : this.toArray())._reverse();
|
873
|
-
},
|
874
|
-
|
875
|
-
reduce: function() {
|
876
|
-
return this.length > 1 ? this : this[0];
|
877
|
-
},
|
878
|
-
|
879
|
-
uniq: function(sorted) {
|
880
|
-
return this.inject([], function(array, value, index) {
|
881
|
-
if (0 == index || (sorted ? array.last() != value : !array.include(value)))
|
882
|
-
array.push(value);
|
883
|
-
return array;
|
884
|
-
});
|
885
|
-
},
|
886
|
-
|
887
|
-
intersect: function(array) {
|
888
|
-
return this.uniq().findAll(function(item) {
|
889
|
-
return array.detect(function(value) { return item === value });
|
890
|
-
});
|
891
|
-
},
|
892
|
-
|
893
|
-
clone: function() {
|
894
|
-
return [].concat(this);
|
895
|
-
},
|
896
|
-
|
897
|
-
size: function() {
|
898
|
-
return this.length;
|
899
|
-
},
|
900
|
-
|
901
|
-
inspect: function() {
|
902
|
-
return '[' + this.map(Object.inspect).join(', ') + ']';
|
903
|
-
},
|
904
|
-
|
905
|
-
toJSON: function() {
|
906
|
-
var results = [];
|
907
|
-
this.each(function(object) {
|
908
|
-
var value = Object.toJSON(object);
|
909
|
-
if (value !== undefined) results.push(value);
|
910
|
-
});
|
911
|
-
return '[' + results.join(', ') + ']';
|
912
|
-
}
|
913
|
-
});
|
914
|
-
|
915
|
-
// use native browser JS 1.6 implementation if available
|
916
|
-
if (Object.isFunction(Array.prototype.forEach))
|
917
|
-
Array.prototype._each = Array.prototype.forEach;
|
918
|
-
|
919
|
-
if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
|
920
|
-
i || (i = 0);
|
921
|
-
var length = this.length;
|
922
|
-
if (i < 0) i = length + i;
|
923
|
-
for (; i < length; i++)
|
924
|
-
if (this[i] === item) return i;
|
925
|
-
return -1;
|
926
|
-
};
|
927
|
-
|
928
|
-
if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) {
|
929
|
-
i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
|
930
|
-
var n = this.slice(0, i).reverse().indexOf(item);
|
931
|
-
return (n < 0) ? n : i - n - 1;
|
932
|
-
};
|
933
|
-
|
934
|
-
Array.prototype.toArray = Array.prototype.clone;
|
935
|
-
|
936
|
-
function $w(string) {
|
937
|
-
if (!Object.isString(string)) return [];
|
938
|
-
string = string.strip();
|
939
|
-
return string ? string.split(/\s+/) : [];
|
940
|
-
}
|
941
|
-
|
942
|
-
if (Prototype.Browser.Opera){
|
943
|
-
Array.prototype.concat = function() {
|
944
|
-
var array = [];
|
945
|
-
for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
|
946
|
-
for (var i = 0, length = arguments.length; i < length; i++) {
|
947
|
-
if (Object.isArray(arguments[i])) {
|
948
|
-
for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
|
949
|
-
array.push(arguments[i][j]);
|
950
|
-
} else {
|
951
|
-
array.push(arguments[i]);
|
952
|
-
}
|
953
|
-
}
|
954
|
-
return array;
|
955
|
-
};
|
956
|
-
}
|
957
|
-
Object.extend(Number.prototype, {
|
958
|
-
toColorPart: function() {
|
959
|
-
return this.toPaddedString(2, 16);
|
960
|
-
},
|
961
|
-
|
962
|
-
succ: function() {
|
963
|
-
return this + 1;
|
964
|
-
},
|
965
|
-
|
966
|
-
times: function(iterator) {
|
967
|
-
$R(0, this, true).each(iterator);
|
968
|
-
return this;
|
969
|
-
},
|
970
|
-
|
971
|
-
toPaddedString: function(length, radix) {
|
972
|
-
var string = this.toString(radix || 10);
|
973
|
-
return '0'.times(length - string.length) + string;
|
974
|
-
},
|
975
|
-
|
976
|
-
toJSON: function() {
|
977
|
-
return isFinite(this) ? this.toString() : 'null';
|
978
|
-
}
|
979
|
-
});
|
980
|
-
|
981
|
-
$w('abs round ceil floor').each(function(method){
|
982
|
-
Number.prototype[method] = Math[method].methodize();
|
983
|
-
});
|
984
|
-
function $H(object) {
|
985
|
-
return new Hash(object);
|
986
|
-
};
|
987
|
-
|
988
|
-
var Hash = Class.create(Enumerable, (function() {
|
989
|
-
if (function() {
|
990
|
-
var i = 0, Test = function(value) { this.key = value };
|
991
|
-
Test.prototype.key = 'foo';
|
992
|
-
for (var property in new Test('bar')) i++;
|
993
|
-
return i > 1;
|
994
|
-
}()) {
|
995
|
-
function each(iterator) {
|
996
|
-
var cache = [];
|
997
|
-
for (var key in this._object) {
|
998
|
-
var value = this._object[key];
|
999
|
-
if (cache.include(key)) continue;
|
1000
|
-
cache.push(key);
|
1001
|
-
var pair = [key, value];
|
1002
|
-
pair.key = key;
|
1003
|
-
pair.value = value;
|
1004
|
-
iterator(pair);
|
1005
|
-
}
|
1006
|
-
}
|
1007
|
-
} else {
|
1008
|
-
function each(iterator) {
|
1009
|
-
for (var key in this._object) {
|
1010
|
-
var value = this._object[key], pair = [key, value];
|
1011
|
-
pair.key = key;
|
1012
|
-
pair.value = value;
|
1013
|
-
iterator(pair);
|
1014
|
-
}
|
1015
|
-
}
|
1016
|
-
}
|
1017
|
-
|
1018
|
-
function toQueryPair(key, value) {
|
1019
|
-
if (Object.isUndefined(value)) return key;
|
1020
|
-
return key + '=' + encodeURIComponent(String.interpret(value));
|
1021
|
-
}
|
1022
|
-
|
1023
|
-
return {
|
1024
|
-
initialize: function(object) {
|
1025
|
-
this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
|
1026
|
-
},
|
1027
|
-
|
1028
|
-
_each: each,
|
1029
|
-
|
1030
|
-
set: function(key, value) {
|
1031
|
-
return this._object[key] = value;
|
1032
|
-
},
|
1033
|
-
|
1034
|
-
get: function(key) {
|
1035
|
-
return this._object[key];
|
1036
|
-
},
|
1037
|
-
|
1038
|
-
unset: function(key) {
|
1039
|
-
var value = this._object[key];
|
1040
|
-
delete this._object[key];
|
1041
|
-
return value;
|
1042
|
-
},
|
1043
|
-
|
1044
|
-
toObject: function() {
|
1045
|
-
return Object.clone(this._object);
|
1046
|
-
},
|
1047
|
-
|
1048
|
-
keys: function() {
|
1049
|
-
return this.pluck('key');
|
1050
|
-
},
|
1051
|
-
|
1052
|
-
values: function() {
|
1053
|
-
return this.pluck('value');
|
1054
|
-
},
|
1055
|
-
|
1056
|
-
index: function(value) {
|
1057
|
-
var match = this.detect(function(pair) {
|
1058
|
-
return pair.value === value;
|
1059
|
-
});
|
1060
|
-
return match && match.key;
|
1061
|
-
},
|
1062
|
-
|
1063
|
-
merge: function(object) {
|
1064
|
-
return this.clone().update(object);
|
1065
|
-
},
|
1066
|
-
|
1067
|
-
update: function(object) {
|
1068
|
-
return new Hash(object).inject(this, function(result, pair) {
|
1069
|
-
result.set(pair.key, pair.value);
|
1070
|
-
return result;
|
1071
|
-
});
|
1072
|
-
},
|
1073
|
-
|
1074
|
-
toQueryString: function() {
|
1075
|
-
return this.map(function(pair) {
|
1076
|
-
var key = encodeURIComponent(pair.key), values = pair.value;
|
1077
|
-
|
1078
|
-
if (values && typeof values == 'object') {
|
1079
|
-
if (Object.isArray(values))
|
1080
|
-
return values.map(toQueryPair.curry(key)).join('&');
|
1081
|
-
}
|
1082
|
-
return toQueryPair(key, values);
|
1083
|
-
}).join('&');
|
1084
|
-
},
|
1085
|
-
|
1086
|
-
inspect: function() {
|
1087
|
-
return '#<Hash:{' + this.map(function(pair) {
|
1088
|
-
return pair.map(Object.inspect).join(': ');
|
1089
|
-
}).join(', ') + '}>';
|
1090
|
-
},
|
1091
|
-
|
1092
|
-
toJSON: function() {
|
1093
|
-
return Object.toJSON(this.toObject());
|
1094
|
-
},
|
1095
|
-
|
1096
|
-
clone: function() {
|
1097
|
-
return new Hash(this);
|
1098
|
-
}
|
1099
|
-
}
|
1100
|
-
})());
|
1101
|
-
|
1102
|
-
Hash.prototype.toTemplateReplacements = Hash.prototype.toObject;
|
1103
|
-
Hash.from = $H;
|
1104
|
-
var ObjectRange = Class.create(Enumerable, {
|
1105
|
-
initialize: function(start, end, exclusive) {
|
1106
|
-
this.start = start;
|
1107
|
-
this.end = end;
|
1108
|
-
this.exclusive = exclusive;
|
1109
|
-
},
|
1110
|
-
|
1111
|
-
_each: function(iterator) {
|
1112
|
-
var value = this.start;
|
1113
|
-
while (this.include(value)) {
|
1114
|
-
iterator(value);
|
1115
|
-
value = value.succ();
|
1116
|
-
}
|
1117
|
-
},
|
1118
|
-
|
1119
|
-
include: function(value) {
|
1120
|
-
if (value < this.start)
|
1121
|
-
return false;
|
1122
|
-
if (this.exclusive)
|
1123
|
-
return value < this.end;
|
1124
|
-
return value <= this.end;
|
1125
|
-
}
|
1126
|
-
});
|
1127
|
-
|
1128
|
-
var $R = function(start, end, exclusive) {
|
1129
|
-
return new ObjectRange(start, end, exclusive);
|
1130
|
-
};
|
1131
|
-
|
1132
|
-
var Ajax = {
|
1133
|
-
getTransport: function() {
|
1134
|
-
return Try.these(
|
1135
|
-
function() {return new XMLHttpRequest()},
|
1136
|
-
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
1137
|
-
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
|
1138
|
-
) || false;
|
1139
|
-
},
|
1140
|
-
|
1141
|
-
activeRequestCount: 0
|
1142
|
-
};
|
1143
|
-
|
1144
|
-
Ajax.Responders = {
|
1145
|
-
responders: [],
|
1146
|
-
|
1147
|
-
_each: function(iterator) {
|
1148
|
-
this.responders._each(iterator);
|
1149
|
-
},
|
1150
|
-
|
1151
|
-
register: function(responder) {
|
1152
|
-
if (!this.include(responder))
|
1153
|
-
this.responders.push(responder);
|
1154
|
-
},
|
1155
|
-
|
1156
|
-
unregister: function(responder) {
|
1157
|
-
this.responders = this.responders.without(responder);
|
1158
|
-
},
|
1159
|
-
|
1160
|
-
dispatch: function(callback, request, transport, json) {
|
1161
|
-
this.each(function(responder) {
|
1162
|
-
if (Object.isFunction(responder[callback])) {
|
1163
|
-
try {
|
1164
|
-
responder[callback].apply(responder, [request, transport, json]);
|
1165
|
-
} catch (e) { }
|
1166
|
-
}
|
1167
|
-
});
|
1168
|
-
}
|
1169
|
-
};
|
1170
|
-
|
1171
|
-
Object.extend(Ajax.Responders, Enumerable);
|
1172
|
-
|
1173
|
-
Ajax.Responders.register({
|
1174
|
-
onCreate: function() { Ajax.activeRequestCount++ },
|
1175
|
-
onComplete: function() { Ajax.activeRequestCount-- }
|
1176
|
-
});
|
1177
|
-
|
1178
|
-
Ajax.Base = Class.create({
|
1179
|
-
initialize: function(options) {
|
1180
|
-
this.options = {
|
1181
|
-
method: 'post',
|
1182
|
-
asynchronous: true,
|
1183
|
-
contentType: 'application/x-www-form-urlencoded',
|
1184
|
-
encoding: 'UTF-8',
|
1185
|
-
parameters: '',
|
1186
|
-
evalJSON: true,
|
1187
|
-
evalJS: true
|
1188
|
-
};
|
1189
|
-
Object.extend(this.options, options || { });
|
1190
|
-
|
1191
|
-
this.options.method = this.options.method.toLowerCase();
|
1192
|
-
if (Object.isString(this.options.parameters))
|
1193
|
-
this.options.parameters = this.options.parameters.toQueryParams();
|
1194
|
-
}
|
1195
|
-
});
|
1196
|
-
|
1197
|
-
Ajax.Request = Class.create(Ajax.Base, {
|
1198
|
-
_complete: false,
|
1199
|
-
|
1200
|
-
initialize: function($super, url, options) {
|
1201
|
-
$super(options);
|
1202
|
-
this.transport = Ajax.getTransport();
|
1203
|
-
this.request(url);
|
1204
|
-
},
|
1205
|
-
|
1206
|
-
request: function(url) {
|
1207
|
-
this.url = url;
|
1208
|
-
this.method = this.options.method;
|
1209
|
-
var params = Object.clone(this.options.parameters);
|
1210
|
-
|
1211
|
-
if (!['get', 'post'].include(this.method)) {
|
1212
|
-
// simulate other verbs over post
|
1213
|
-
params['_method'] = this.method;
|
1214
|
-
this.method = 'post';
|
1215
|
-
}
|
1216
|
-
|
1217
|
-
this.parameters = params;
|
1218
|
-
|
1219
|
-
if (params = Object.toQueryString(params)) {
|
1220
|
-
// when GET, append parameters to URL
|
1221
|
-
if (this.method == 'get')
|
1222
|
-
this.url += (this.url.include('?') ? '&' : '?') + params;
|
1223
|
-
else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
|
1224
|
-
params += '&_=';
|
1225
|
-
}
|
1226
|
-
|
1227
|
-
try {
|
1228
|
-
var response = new Ajax.Response(this);
|
1229
|
-
if (this.options.onCreate) this.options.onCreate(response);
|
1230
|
-
Ajax.Responders.dispatch('onCreate', this, response);
|
1231
|
-
|
1232
|
-
this.transport.open(this.method.toUpperCase(), this.url,
|
1233
|
-
this.options.asynchronous);
|
1234
|
-
|
1235
|
-
if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
|
1236
|
-
|
1237
|
-
this.transport.onreadystatechange = this.onStateChange.bind(this);
|
1238
|
-
this.setRequestHeaders();
|
1239
|
-
|
1240
|
-
this.body = this.method == 'post' ? (this.options.postBody || params) : null;
|
1241
|
-
this.transport.send(this.body);
|
1242
|
-
|
1243
|
-
/* Force Firefox to handle ready state 4 for synchronous requests */
|
1244
|
-
if (!this.options.asynchronous && this.transport.overrideMimeType)
|
1245
|
-
this.onStateChange();
|
1246
|
-
|
1247
|
-
}
|
1248
|
-
catch (e) {
|
1249
|
-
this.dispatchException(e);
|
1250
|
-
}
|
1251
|
-
},
|
1252
|
-
|
1253
|
-
onStateChange: function() {
|
1254
|
-
var readyState = this.transport.readyState;
|
1255
|
-
if (readyState > 1 && !((readyState == 4) && this._complete))
|
1256
|
-
this.respondToReadyState(this.transport.readyState);
|
1257
|
-
},
|
1258
|
-
|
1259
|
-
setRequestHeaders: function() {
|
1260
|
-
var headers = {
|
1261
|
-
'X-Requested-With': 'XMLHttpRequest',
|
1262
|
-
'X-Prototype-Version': Prototype.Version,
|
1263
|
-
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
|
1264
|
-
};
|
1265
|
-
|
1266
|
-
if (this.method == 'post') {
|
1267
|
-
headers['Content-type'] = this.options.contentType +
|
1268
|
-
(this.options.encoding ? '; charset=' + this.options.encoding : '');
|
1269
|
-
|
1270
|
-
/* Force "Connection: close" for older Mozilla browsers to work
|
1271
|
-
* around a bug where XMLHttpRequest sends an incorrect
|
1272
|
-
* Content-length header. See Mozilla Bugzilla #246651.
|
1273
|
-
*/
|
1274
|
-
if (this.transport.overrideMimeType &&
|
1275
|
-
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
|
1276
|
-
headers['Connection'] = 'close';
|
1277
|
-
}
|
1278
|
-
|
1279
|
-
// user-defined headers
|
1280
|
-
if (typeof this.options.requestHeaders == 'object') {
|
1281
|
-
var extras = this.options.requestHeaders;
|
1282
|
-
|
1283
|
-
if (Object.isFunction(extras.push))
|
1284
|
-
for (var i = 0, length = extras.length; i < length; i += 2)
|
1285
|
-
headers[extras[i]] = extras[i+1];
|
1286
|
-
else
|
1287
|
-
$H(extras).each(function(pair) { headers[pair.key] = pair.value });
|
1288
|
-
}
|
1289
|
-
|
1290
|
-
for (var name in headers)
|
1291
|
-
this.transport.setRequestHeader(name, headers[name]);
|
1292
|
-
},
|
1293
|
-
|
1294
|
-
success: function() {
|
1295
|
-
var status = this.getStatus();
|
1296
|
-
return !status || (status >= 200 && status < 300);
|
1297
|
-
},
|
1298
|
-
|
1299
|
-
getStatus: function() {
|
1300
|
-
try {
|
1301
|
-
return this.transport.status || 0;
|
1302
|
-
} catch (e) { return 0 }
|
1303
|
-
},
|
1304
|
-
|
1305
|
-
respondToReadyState: function(readyState) {
|
1306
|
-
var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
|
1307
|
-
|
1308
|
-
if (state == 'Complete') {
|
1309
|
-
try {
|
1310
|
-
this._complete = true;
|
1311
|
-
(this.options['on' + response.status]
|
1312
|
-
|| this.options['on' + (this.success() ? 'Success' : 'Failure')]
|
1313
|
-
|| Prototype.emptyFunction)(response, response.headerJSON);
|
1314
|
-
} catch (e) {
|
1315
|
-
this.dispatchException(e);
|
1316
|
-
}
|
1317
|
-
|
1318
|
-
var contentType = response.getHeader('Content-type');
|
1319
|
-
if (this.options.evalJS == 'force'
|
1320
|
-
|| (this.options.evalJS && contentType
|
1321
|
-
&& contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
|
1322
|
-
this.evalResponse();
|
1323
|
-
}
|
1324
|
-
|
1325
|
-
try {
|
1326
|
-
(this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
|
1327
|
-
Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
|
1328
|
-
} catch (e) {
|
1329
|
-
this.dispatchException(e);
|
1330
|
-
}
|
1331
|
-
|
1332
|
-
if (state == 'Complete') {
|
1333
|
-
// avoid memory leak in MSIE: clean up
|
1334
|
-
this.transport.onreadystatechange = Prototype.emptyFunction;
|
1335
|
-
}
|
1336
|
-
},
|
1337
|
-
|
1338
|
-
getHeader: function(name) {
|
1339
|
-
try {
|
1340
|
-
return this.transport.getResponseHeader(name);
|
1341
|
-
} catch (e) { return null }
|
1342
|
-
},
|
1343
|
-
|
1344
|
-
evalResponse: function() {
|
1345
|
-
try {
|
1346
|
-
return eval((this.transport.responseText || '').unfilterJSON());
|
1347
|
-
} catch (e) {
|
1348
|
-
this.dispatchException(e);
|
1349
|
-
}
|
1350
|
-
},
|
1351
|
-
|
1352
|
-
dispatchException: function(exception) {
|
1353
|
-
(this.options.onException || Prototype.emptyFunction)(this, exception);
|
1354
|
-
Ajax.Responders.dispatch('onException', this, exception);
|
1355
|
-
}
|
1356
|
-
});
|
1357
|
-
|
1358
|
-
Ajax.Request.Events =
|
1359
|
-
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
|
1360
|
-
|
1361
|
-
Ajax.Response = Class.create({
|
1362
|
-
initialize: function(request){
|
1363
|
-
this.request = request;
|
1364
|
-
var transport = this.transport = request.transport,
|
1365
|
-
readyState = this.readyState = transport.readyState;
|
1366
|
-
|
1367
|
-
if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
|
1368
|
-
this.status = this.getStatus();
|
1369
|
-
this.statusText = this.getStatusText();
|
1370
|
-
this.responseText = String.interpret(transport.responseText);
|
1371
|
-
this.headerJSON = this._getHeaderJSON();
|
1372
|
-
}
|
1373
|
-
|
1374
|
-
if(readyState == 4) {
|
1375
|
-
var xml = transport.responseXML;
|
1376
|
-
this.responseXML = xml === undefined ? null : xml;
|
1377
|
-
this.responseJSON = this._getResponseJSON();
|
1378
|
-
}
|
1379
|
-
},
|
1380
|
-
|
1381
|
-
status: 0,
|
1382
|
-
statusText: '',
|
1383
|
-
|
1384
|
-
getStatus: Ajax.Request.prototype.getStatus,
|
1385
|
-
|
1386
|
-
getStatusText: function() {
|
1387
|
-
try {
|
1388
|
-
return this.transport.statusText || '';
|
1389
|
-
} catch (e) { return '' }
|
1390
|
-
},
|
1391
|
-
|
1392
|
-
getHeader: Ajax.Request.prototype.getHeader,
|
1393
|
-
|
1394
|
-
getAllHeaders: function() {
|
1395
|
-
try {
|
1396
|
-
return this.getAllResponseHeaders();
|
1397
|
-
} catch (e) { return null }
|
1398
|
-
},
|
1399
|
-
|
1400
|
-
getResponseHeader: function(name) {
|
1401
|
-
return this.transport.getResponseHeader(name);
|
1402
|
-
},
|
1403
|
-
|
1404
|
-
getAllResponseHeaders: function() {
|
1405
|
-
return this.transport.getAllResponseHeaders();
|
1406
|
-
},
|
1407
|
-
|
1408
|
-
_getHeaderJSON: function() {
|
1409
|
-
var json = this.getHeader('X-JSON');
|
1410
|
-
if (!json) return null;
|
1411
|
-
json = decodeURIComponent(escape(json));
|
1412
|
-
try {
|
1413
|
-
return json.evalJSON(this.request.options.sanitizeJSON);
|
1414
|
-
} catch (e) {
|
1415
|
-
this.request.dispatchException(e);
|
1416
|
-
}
|
1417
|
-
},
|
1418
|
-
|
1419
|
-
_getResponseJSON: function() {
|
1420
|
-
var options = this.request.options;
|
1421
|
-
if (!options.evalJSON || (options.evalJSON != 'force' &&
|
1422
|
-
!(this.getHeader('Content-type') || '').include('application/json')))
|
1423
|
-
return null;
|
1424
|
-
try {
|
1425
|
-
return this.transport.responseText.evalJSON(options.sanitizeJSON);
|
1426
|
-
} catch (e) {
|
1427
|
-
this.request.dispatchException(e);
|
1428
|
-
}
|
1429
|
-
}
|
1430
|
-
});
|
1431
|
-
|
1432
|
-
Ajax.Updater = Class.create(Ajax.Request, {
|
1433
|
-
initialize: function($super, container, url, options) {
|
1434
|
-
this.container = {
|
1435
|
-
success: (container.success || container),
|
1436
|
-
failure: (container.failure || (container.success ? null : container))
|
1437
|
-
};
|
1438
|
-
|
1439
|
-
options = options || { };
|
1440
|
-
var onComplete = options.onComplete;
|
1441
|
-
options.onComplete = (function(response, param) {
|
1442
|
-
this.updateContent(response.responseText);
|
1443
|
-
if (Object.isFunction(onComplete)) onComplete(response, param);
|
1444
|
-
}).bind(this);
|
1445
|
-
|
1446
|
-
$super(url, options);
|
1447
|
-
},
|
1448
|
-
|
1449
|
-
updateContent: function(responseText) {
|
1450
|
-
var receiver = this.container[this.success() ? 'success' : 'failure'],
|
1451
|
-
options = this.options;
|
1452
|
-
|
1453
|
-
if (!options.evalScripts) responseText = responseText.stripScripts();
|
1454
|
-
|
1455
|
-
if (receiver = $(receiver)) {
|
1456
|
-
if (options.insertion) {
|
1457
|
-
if (Object.isString(options.insertion)) {
|
1458
|
-
var insertion = { }; insertion[options.insertion] = responseText;
|
1459
|
-
receiver.insert(insertion);
|
1460
|
-
}
|
1461
|
-
else options.insertion(receiver, responseText);
|
1462
|
-
}
|
1463
|
-
else receiver.update(responseText);
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
if (this.success()) {
|
1467
|
-
if (this.onComplete) this.onComplete.bind(this).defer();
|
1468
|
-
}
|
1469
|
-
}
|
1470
|
-
});
|
1471
|
-
|
1472
|
-
Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
|
1473
|
-
initialize: function($super, container, url, options) {
|
1474
|
-
$super(options);
|
1475
|
-
this.onComplete = this.options.onComplete;
|
1476
|
-
|
1477
|
-
this.frequency = (this.options.frequency || 2);
|
1478
|
-
this.decay = (this.options.decay || 1);
|
1479
|
-
|
1480
|
-
this.updater = { };
|
1481
|
-
this.container = container;
|
1482
|
-
this.url = url;
|
1483
|
-
|
1484
|
-
this.start();
|
1485
|
-
},
|
1486
|
-
|
1487
|
-
start: function() {
|
1488
|
-
this.options.onComplete = this.updateComplete.bind(this);
|
1489
|
-
this.onTimerEvent();
|
1490
|
-
},
|
1491
|
-
|
1492
|
-
stop: function() {
|
1493
|
-
this.updater.options.onComplete = undefined;
|
1494
|
-
clearTimeout(this.timer);
|
1495
|
-
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
|
1496
|
-
},
|
1497
|
-
|
1498
|
-
updateComplete: function(response) {
|
1499
|
-
if (this.options.decay) {
|
1500
|
-
this.decay = (response.responseText == this.lastText ?
|
1501
|
-
this.decay * this.options.decay : 1);
|
1502
|
-
|
1503
|
-
this.lastText = response.responseText;
|
1504
|
-
}
|
1505
|
-
this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
|
1506
|
-
},
|
1507
|
-
|
1508
|
-
onTimerEvent: function() {
|
1509
|
-
this.updater = new Ajax.Updater(this.container, this.url, this.options);
|
1510
|
-
}
|
1511
|
-
});
|
1512
|
-
function $(element) {
|
1513
|
-
if (arguments.length > 1) {
|
1514
|
-
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
|
1515
|
-
elements.push($(arguments[i]));
|
1516
|
-
return elements;
|
1517
|
-
}
|
1518
|
-
if (Object.isString(element))
|
1519
|
-
element = document.getElementById(element);
|
1520
|
-
return Element.extend(element);
|
1521
|
-
}
|
1522
|
-
|
1523
|
-
if (Prototype.BrowserFeatures.XPath) {
|
1524
|
-
document._getElementsByXPath = function(expression, parentElement) {
|
1525
|
-
var results = [];
|
1526
|
-
var query = document.evaluate(expression, $(parentElement) || document,
|
1527
|
-
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
1528
|
-
for (var i = 0, length = query.snapshotLength; i < length; i++)
|
1529
|
-
results.push(Element.extend(query.snapshotItem(i)));
|
1530
|
-
return results;
|
1531
|
-
};
|
1532
|
-
}
|
1533
|
-
|
1534
|
-
/*--------------------------------------------------------------------------*/
|
1535
|
-
|
1536
|
-
if (!window.Node) var Node = { };
|
1537
|
-
|
1538
|
-
if (!Node.ELEMENT_NODE) {
|
1539
|
-
// DOM level 2 ECMAScript Language Binding
|
1540
|
-
Object.extend(Node, {
|
1541
|
-
ELEMENT_NODE: 1,
|
1542
|
-
ATTRIBUTE_NODE: 2,
|
1543
|
-
TEXT_NODE: 3,
|
1544
|
-
CDATA_SECTION_NODE: 4,
|
1545
|
-
ENTITY_REFERENCE_NODE: 5,
|
1546
|
-
ENTITY_NODE: 6,
|
1547
|
-
PROCESSING_INSTRUCTION_NODE: 7,
|
1548
|
-
COMMENT_NODE: 8,
|
1549
|
-
DOCUMENT_NODE: 9,
|
1550
|
-
DOCUMENT_TYPE_NODE: 10,
|
1551
|
-
DOCUMENT_FRAGMENT_NODE: 11,
|
1552
|
-
NOTATION_NODE: 12
|
1553
|
-
});
|
1554
|
-
}
|
1555
|
-
|
1556
|
-
(function() {
|
1557
|
-
var element = this.Element;
|
1558
|
-
this.Element = function(tagName, attributes) {
|
1559
|
-
attributes = attributes || { };
|
1560
|
-
tagName = tagName.toLowerCase();
|
1561
|
-
var cache = Element.cache;
|
1562
|
-
if (Prototype.Browser.IE && attributes.name) {
|
1563
|
-
tagName = '<' + tagName + ' name="' + attributes.name + '">';
|
1564
|
-
delete attributes.name;
|
1565
|
-
return Element.writeAttribute(document.createElement(tagName), attributes);
|
1566
|
-
}
|
1567
|
-
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
|
1568
|
-
return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
|
1569
|
-
};
|
1570
|
-
Object.extend(this.Element, element || { });
|
1571
|
-
}).call(window);
|
1572
|
-
|
1573
|
-
Element.cache = { };
|
1574
|
-
|
1575
|
-
Element.Methods = {
|
1576
|
-
visible: function(element) {
|
1577
|
-
return $(element).style.display != 'none';
|
1578
|
-
},
|
1579
|
-
|
1580
|
-
toggle: function(element) {
|
1581
|
-
element = $(element);
|
1582
|
-
Element[Element.visible(element) ? 'hide' : 'show'](element);
|
1583
|
-
return element;
|
1584
|
-
},
|
1585
|
-
|
1586
|
-
hide: function(element) {
|
1587
|
-
$(element).style.display = 'none';
|
1588
|
-
return element;
|
1589
|
-
},
|
1590
|
-
|
1591
|
-
show: function(element) {
|
1592
|
-
$(element).style.display = '';
|
1593
|
-
return element;
|
1594
|
-
},
|
1595
|
-
|
1596
|
-
remove: function(element) {
|
1597
|
-
element = $(element);
|
1598
|
-
element.parentNode.removeChild(element);
|
1599
|
-
return element;
|
1600
|
-
},
|
1601
|
-
|
1602
|
-
update: function(element, content) {
|
1603
|
-
element = $(element);
|
1604
|
-
if (content && content.toElement) content = content.toElement();
|
1605
|
-
if (Object.isElement(content)) return element.update().insert(content);
|
1606
|
-
content = Object.toHTML(content);
|
1607
|
-
element.innerHTML = content.stripScripts();
|
1608
|
-
content.evalScripts.bind(content).defer();
|
1609
|
-
return element;
|
1610
|
-
},
|
1611
|
-
|
1612
|
-
replace: function(element, content) {
|
1613
|
-
element = $(element);
|
1614
|
-
if (content && content.toElement) content = content.toElement();
|
1615
|
-
else if (!Object.isElement(content)) {
|
1616
|
-
content = Object.toHTML(content);
|
1617
|
-
var range = element.ownerDocument.createRange();
|
1618
|
-
range.selectNode(element);
|
1619
|
-
content.evalScripts.bind(content).defer();
|
1620
|
-
content = range.createContextualFragment(content.stripScripts());
|
1621
|
-
}
|
1622
|
-
element.parentNode.replaceChild(content, element);
|
1623
|
-
return element;
|
1624
|
-
},
|
1625
|
-
|
1626
|
-
insert: function(element, insertions) {
|
1627
|
-
element = $(element);
|
1628
|
-
|
1629
|
-
if (Object.isString(insertions) || Object.isNumber(insertions) ||
|
1630
|
-
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
|
1631
|
-
insertions = {bottom:insertions};
|
1632
|
-
|
1633
|
-
var content, t, range;
|
1634
|
-
|
1635
|
-
for (position in insertions) {
|
1636
|
-
content = insertions[position];
|
1637
|
-
position = position.toLowerCase();
|
1638
|
-
t = Element._insertionTranslations[position];
|
1639
|
-
|
1640
|
-
if (content && content.toElement) content = content.toElement();
|
1641
|
-
if (Object.isElement(content)) {
|
1642
|
-
t.insert(element, content);
|
1643
|
-
continue;
|
1644
|
-
}
|
1645
|
-
|
1646
|
-
content = Object.toHTML(content);
|
1647
|
-
|
1648
|
-
range = element.ownerDocument.createRange();
|
1649
|
-
t.initializeRange(element, range);
|
1650
|
-
t.insert(element, range.createContextualFragment(content.stripScripts()));
|
1651
|
-
|
1652
|
-
content.evalScripts.bind(content).defer();
|
1653
|
-
}
|
1654
|
-
|
1655
|
-
return element;
|
1656
|
-
},
|
1657
|
-
|
1658
|
-
wrap: function(element, wrapper, attributes) {
|
1659
|
-
element = $(element);
|
1660
|
-
if (Object.isElement(wrapper))
|
1661
|
-
$(wrapper).writeAttribute(attributes || { });
|
1662
|
-
else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
|
1663
|
-
else wrapper = new Element('div', wrapper);
|
1664
|
-
if (element.parentNode)
|
1665
|
-
element.parentNode.replaceChild(wrapper, element);
|
1666
|
-
wrapper.appendChild(element);
|
1667
|
-
return wrapper;
|
1668
|
-
},
|
1669
|
-
|
1670
|
-
inspect: function(element) {
|
1671
|
-
element = $(element);
|
1672
|
-
var result = '<' + element.tagName.toLowerCase();
|
1673
|
-
$H({'id': 'id', 'className': 'class'}).each(function(pair) {
|
1674
|
-
var property = pair.first(), attribute = pair.last();
|
1675
|
-
var value = (element[property] || '').toString();
|
1676
|
-
if (value) result += ' ' + attribute + '=' + value.inspect(true);
|
1677
|
-
});
|
1678
|
-
return result + '>';
|
1679
|
-
},
|
1680
|
-
|
1681
|
-
recursivelyCollect: function(element, property) {
|
1682
|
-
element = $(element);
|
1683
|
-
var elements = [];
|
1684
|
-
while (element = element[property])
|
1685
|
-
if (element.nodeType == 1)
|
1686
|
-
elements.push(Element.extend(element));
|
1687
|
-
return elements;
|
1688
|
-
},
|
1689
|
-
|
1690
|
-
ancestors: function(element) {
|
1691
|
-
return $(element).recursivelyCollect('parentNode');
|
1692
|
-
},
|
1693
|
-
|
1694
|
-
descendants: function(element) {
|
1695
|
-
return $A($(element).getElementsByTagName('*')).each(Element.extend);
|
1696
|
-
},
|
1697
|
-
|
1698
|
-
firstDescendant: function(element) {
|
1699
|
-
element = $(element).firstChild;
|
1700
|
-
while (element && element.nodeType != 1) element = element.nextSibling;
|
1701
|
-
return $(element);
|
1702
|
-
},
|
1703
|
-
|
1704
|
-
immediateDescendants: function(element) {
|
1705
|
-
if (!(element = $(element).firstChild)) return [];
|
1706
|
-
while (element && element.nodeType != 1) element = element.nextSibling;
|
1707
|
-
if (element) return [element].concat($(element).nextSiblings());
|
1708
|
-
return [];
|
1709
|
-
},
|
1710
|
-
|
1711
|
-
previousSiblings: function(element) {
|
1712
|
-
return $(element).recursivelyCollect('previousSibling');
|
1713
|
-
},
|
1714
|
-
|
1715
|
-
nextSiblings: function(element) {
|
1716
|
-
return $(element).recursivelyCollect('nextSibling');
|
1717
|
-
},
|
1718
|
-
|
1719
|
-
siblings: function(element) {
|
1720
|
-
element = $(element);
|
1721
|
-
return element.previousSiblings().reverse().concat(element.nextSiblings());
|
1722
|
-
},
|
1723
|
-
|
1724
|
-
match: function(element, selector) {
|
1725
|
-
if (Object.isString(selector))
|
1726
|
-
selector = new Selector(selector);
|
1727
|
-
return selector.match($(element));
|
1728
|
-
},
|
1729
|
-
|
1730
|
-
up: function(element, expression, index) {
|
1731
|
-
element = $(element);
|
1732
|
-
if (arguments.length == 1) return $(element.parentNode);
|
1733
|
-
var ancestors = element.ancestors();
|
1734
|
-
return expression ? Selector.findElement(ancestors, expression, index) :
|
1735
|
-
ancestors[index || 0];
|
1736
|
-
},
|
1737
|
-
|
1738
|
-
down: function(element, expression, index) {
|
1739
|
-
element = $(element);
|
1740
|
-
if (arguments.length == 1) return element.firstDescendant();
|
1741
|
-
var descendants = element.descendants();
|
1742
|
-
return expression ? Selector.findElement(descendants, expression, index) :
|
1743
|
-
descendants[index || 0];
|
1744
|
-
},
|
1745
|
-
|
1746
|
-
previous: function(element, expression, index) {
|
1747
|
-
element = $(element);
|
1748
|
-
if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
|
1749
|
-
var previousSiblings = element.previousSiblings();
|
1750
|
-
return expression ? Selector.findElement(previousSiblings, expression, index) :
|
1751
|
-
previousSiblings[index || 0];
|
1752
|
-
},
|
1753
|
-
|
1754
|
-
next: function(element, expression, index) {
|
1755
|
-
element = $(element);
|
1756
|
-
if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
|
1757
|
-
var nextSiblings = element.nextSiblings();
|
1758
|
-
return expression ? Selector.findElement(nextSiblings, expression, index) :
|
1759
|
-
nextSiblings[index || 0];
|
1760
|
-
},
|
1761
|
-
|
1762
|
-
select: function() {
|
1763
|
-
var args = $A(arguments), element = $(args.shift());
|
1764
|
-
return Selector.findChildElements(element, args);
|
1765
|
-
},
|
1766
|
-
|
1767
|
-
adjacent: function() {
|
1768
|
-
var args = $A(arguments), element = $(args.shift());
|
1769
|
-
return Selector.findChildElements(element.parentNode, args).without(element);
|
1770
|
-
},
|
1771
|
-
|
1772
|
-
identify: function(element) {
|
1773
|
-
element = $(element);
|
1774
|
-
var id = element.readAttribute('id'), self = arguments.callee;
|
1775
|
-
if (id) return id;
|
1776
|
-
do { id = 'anonymous_element_' + self.counter++ } while ($(id));
|
1777
|
-
element.writeAttribute('id', id);
|
1778
|
-
return id;
|
1779
|
-
},
|
1780
|
-
|
1781
|
-
readAttribute: function(element, name) {
|
1782
|
-
element = $(element);
|
1783
|
-
if (Prototype.Browser.IE) {
|
1784
|
-
var t = Element._attributeTranslations.read;
|
1785
|
-
if (t.values[name]) return t.values[name](element, name);
|
1786
|
-
if (t.names[name]) name = t.names[name];
|
1787
|
-
if (name.include(':')) {
|
1788
|
-
return (!element.attributes || !element.attributes[name]) ? null :
|
1789
|
-
element.attributes[name].value;
|
1790
|
-
}
|
1791
|
-
}
|
1792
|
-
return element.getAttribute(name);
|
1793
|
-
},
|
1794
|
-
|
1795
|
-
writeAttribute: function(element, name, value) {
|
1796
|
-
element = $(element);
|
1797
|
-
var attributes = { }, t = Element._attributeTranslations.write;
|
1798
|
-
|
1799
|
-
if (typeof name == 'object') attributes = name;
|
1800
|
-
else attributes[name] = value === undefined ? true : value;
|
1801
|
-
|
1802
|
-
for (var attr in attributes) {
|
1803
|
-
var name = t.names[attr] || attr, value = attributes[attr];
|
1804
|
-
if (t.values[attr]) name = t.values[attr](element, value);
|
1805
|
-
if (value === false || value === null)
|
1806
|
-
element.removeAttribute(name);
|
1807
|
-
else if (value === true)
|
1808
|
-
element.setAttribute(name, name);
|
1809
|
-
else element.setAttribute(name, value);
|
1810
|
-
}
|
1811
|
-
return element;
|
1812
|
-
},
|
1813
|
-
|
1814
|
-
getHeight: function(element) {
|
1815
|
-
return $(element).getDimensions().height;
|
1816
|
-
},
|
1817
|
-
|
1818
|
-
getWidth: function(element) {
|
1819
|
-
return $(element).getDimensions().width;
|
1820
|
-
},
|
1821
|
-
|
1822
|
-
classNames: function(element) {
|
1823
|
-
return new Element.ClassNames(element);
|
1824
|
-
},
|
1825
|
-
|
1826
|
-
hasClassName: function(element, className) {
|
1827
|
-
if (!(element = $(element))) return;
|
1828
|
-
var elementClassName = element.className;
|
1829
|
-
return (elementClassName.length > 0 && (elementClassName == className ||
|
1830
|
-
new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
|
1831
|
-
},
|
1832
|
-
|
1833
|
-
addClassName: function(element, className) {
|
1834
|
-
if (!(element = $(element))) return;
|
1835
|
-
if (!element.hasClassName(className))
|
1836
|
-
element.className += (element.className ? ' ' : '') + className;
|
1837
|
-
return element;
|
1838
|
-
},
|
1839
|
-
|
1840
|
-
removeClassName: function(element, className) {
|
1841
|
-
if (!(element = $(element))) return;
|
1842
|
-
element.className = element.className.replace(
|
1843
|
-
new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
|
1844
|
-
return element;
|
1845
|
-
},
|
1846
|
-
|
1847
|
-
toggleClassName: function(element, className) {
|
1848
|
-
if (!(element = $(element))) return;
|
1849
|
-
return element[element.hasClassName(className) ?
|
1850
|
-
'removeClassName' : 'addClassName'](className);
|
1851
|
-
},
|
1852
|
-
|
1853
|
-
// removes whitespace-only text node children
|
1854
|
-
cleanWhitespace: function(element) {
|
1855
|
-
element = $(element);
|
1856
|
-
var node = element.firstChild;
|
1857
|
-
while (node) {
|
1858
|
-
var nextNode = node.nextSibling;
|
1859
|
-
if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
|
1860
|
-
element.removeChild(node);
|
1861
|
-
node = nextNode;
|
1862
|
-
}
|
1863
|
-
return element;
|
1864
|
-
},
|
1865
|
-
|
1866
|
-
empty: function(element) {
|
1867
|
-
return $(element).innerHTML.blank();
|
1868
|
-
},
|
1869
|
-
|
1870
|
-
descendantOf: function(element, ancestor) {
|
1871
|
-
element = $(element), ancestor = $(ancestor);
|
1872
|
-
|
1873
|
-
if (element.compareDocumentPosition)
|
1874
|
-
return (element.compareDocumentPosition(ancestor) & 8) === 8;
|
1875
|
-
|
1876
|
-
if (element.sourceIndex && !Prototype.Browser.Opera) {
|
1877
|
-
var e = element.sourceIndex, a = ancestor.sourceIndex,
|
1878
|
-
nextAncestor = ancestor.nextSibling;
|
1879
|
-
if (!nextAncestor) {
|
1880
|
-
do { ancestor = ancestor.parentNode; }
|
1881
|
-
while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
|
1882
|
-
}
|
1883
|
-
if (nextAncestor) return (e > a && e < nextAncestor.sourceIndex);
|
1884
|
-
}
|
1885
|
-
|
1886
|
-
while (element = element.parentNode)
|
1887
|
-
if (element == ancestor) return true;
|
1888
|
-
return false;
|
1889
|
-
},
|
1890
|
-
|
1891
|
-
scrollTo: function(element) {
|
1892
|
-
element = $(element);
|
1893
|
-
var pos = element.cumulativeOffset();
|
1894
|
-
window.scrollTo(pos[0], pos[1]);
|
1895
|
-
return element;
|
1896
|
-
},
|
1897
|
-
|
1898
|
-
getStyle: function(element, style) {
|
1899
|
-
element = $(element);
|
1900
|
-
style = style == 'float' ? 'cssFloat' : style.camelize();
|
1901
|
-
var value = element.style[style];
|
1902
|
-
if (!value) {
|
1903
|
-
var css = document.defaultView.getComputedStyle(element, null);
|
1904
|
-
value = css ? css[style] : null;
|
1905
|
-
}
|
1906
|
-
if (style == 'opacity') return value ? parseFloat(value) : 1.0;
|
1907
|
-
return value == 'auto' ? null : value;
|
1908
|
-
},
|
1909
|
-
|
1910
|
-
getOpacity: function(element) {
|
1911
|
-
return $(element).getStyle('opacity');
|
1912
|
-
},
|
1913
|
-
|
1914
|
-
setStyle: function(element, styles) {
|
1915
|
-
element = $(element);
|
1916
|
-
var elementStyle = element.style, match;
|
1917
|
-
if (Object.isString(styles)) {
|
1918
|
-
element.style.cssText += ';' + styles;
|
1919
|
-
return styles.include('opacity') ?
|
1920
|
-
element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
|
1921
|
-
}
|
1922
|
-
for (var property in styles)
|
1923
|
-
if (property == 'opacity') element.setOpacity(styles[property]);
|
1924
|
-
else
|
1925
|
-
elementStyle[(property == 'float' || property == 'cssFloat') ?
|
1926
|
-
(elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
|
1927
|
-
property] = styles[property];
|
1928
|
-
|
1929
|
-
return element;
|
1930
|
-
},
|
1931
|
-
|
1932
|
-
setOpacity: function(element, value) {
|
1933
|
-
element = $(element);
|
1934
|
-
element.style.opacity = (value == 1 || value === '') ? '' :
|
1935
|
-
(value < 0.00001) ? 0 : value;
|
1936
|
-
return element;
|
1937
|
-
},
|
1938
|
-
|
1939
|
-
getDimensions: function(element) {
|
1940
|
-
element = $(element);
|
1941
|
-
var display = $(element).getStyle('display');
|
1942
|
-
if (display != 'none' && display != null) // Safari bug
|
1943
|
-
return {width: element.offsetWidth, height: element.offsetHeight};
|
1944
|
-
|
1945
|
-
// All *Width and *Height properties give 0 on elements with display none,
|
1946
|
-
// so enable the element temporarily
|
1947
|
-
var els = element.style;
|
1948
|
-
var originalVisibility = els.visibility;
|
1949
|
-
var originalPosition = els.position;
|
1950
|
-
var originalDisplay = els.display;
|
1951
|
-
els.visibility = 'hidden';
|
1952
|
-
els.position = 'absolute';
|
1953
|
-
els.display = 'block';
|
1954
|
-
var originalWidth = element.clientWidth;
|
1955
|
-
var originalHeight = element.clientHeight;
|
1956
|
-
els.display = originalDisplay;
|
1957
|
-
els.position = originalPosition;
|
1958
|
-
els.visibility = originalVisibility;
|
1959
|
-
return {width: originalWidth, height: originalHeight};
|
1960
|
-
},
|
1961
|
-
|
1962
|
-
makePositioned: function(element) {
|
1963
|
-
element = $(element);
|
1964
|
-
var pos = Element.getStyle(element, 'position');
|
1965
|
-
if (pos == 'static' || !pos) {
|
1966
|
-
element._madePositioned = true;
|
1967
|
-
element.style.position = 'relative';
|
1968
|
-
// Opera returns the offset relative to the positioning context, when an
|
1969
|
-
// element is position relative but top and left have not been defined
|
1970
|
-
if (window.opera) {
|
1971
|
-
element.style.top = 0;
|
1972
|
-
element.style.left = 0;
|
1973
|
-
}
|
1974
|
-
}
|
1975
|
-
return element;
|
1976
|
-
},
|
1977
|
-
|
1978
|
-
undoPositioned: function(element) {
|
1979
|
-
element = $(element);
|
1980
|
-
if (element._madePositioned) {
|
1981
|
-
element._madePositioned = undefined;
|
1982
|
-
element.style.position =
|
1983
|
-
element.style.top =
|
1984
|
-
element.style.left =
|
1985
|
-
element.style.bottom =
|
1986
|
-
element.style.right = '';
|
1987
|
-
}
|
1988
|
-
return element;
|
1989
|
-
},
|
1990
|
-
|
1991
|
-
makeClipping: function(element) {
|
1992
|
-
element = $(element);
|
1993
|
-
if (element._overflow) return element;
|
1994
|
-
element._overflow = Element.getStyle(element, 'overflow') || 'auto';
|
1995
|
-
if (element._overflow !== 'hidden')
|
1996
|
-
element.style.overflow = 'hidden';
|
1997
|
-
return element;
|
1998
|
-
},
|
1999
|
-
|
2000
|
-
undoClipping: function(element) {
|
2001
|
-
element = $(element);
|
2002
|
-
if (!element._overflow) return element;
|
2003
|
-
element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
|
2004
|
-
element._overflow = null;
|
2005
|
-
return element;
|
2006
|
-
},
|
2007
|
-
|
2008
|
-
cumulativeOffset: function(element) {
|
2009
|
-
var valueT = 0, valueL = 0;
|
2010
|
-
do {
|
2011
|
-
valueT += element.offsetTop || 0;
|
2012
|
-
valueL += element.offsetLeft || 0;
|
2013
|
-
element = element.offsetParent;
|
2014
|
-
} while (element);
|
2015
|
-
return Element._returnOffset(valueL, valueT);
|
2016
|
-
},
|
2017
|
-
|
2018
|
-
positionedOffset: function(element) {
|
2019
|
-
var valueT = 0, valueL = 0;
|
2020
|
-
do {
|
2021
|
-
valueT += element.offsetTop || 0;
|
2022
|
-
valueL += element.offsetLeft || 0;
|
2023
|
-
element = element.offsetParent;
|
2024
|
-
if (element) {
|
2025
|
-
if (element.tagName == 'BODY') break;
|
2026
|
-
var p = Element.getStyle(element, 'position');
|
2027
|
-
if (p == 'relative' || p == 'absolute') break;
|
2028
|
-
}
|
2029
|
-
} while (element);
|
2030
|
-
return Element._returnOffset(valueL, valueT);
|
2031
|
-
},
|
2032
|
-
|
2033
|
-
absolutize: function(element) {
|
2034
|
-
element = $(element);
|
2035
|
-
if (element.getStyle('position') == 'absolute') return;
|
2036
|
-
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
2037
|
-
|
2038
|
-
var offsets = element.positionedOffset();
|
2039
|
-
var top = offsets[1];
|
2040
|
-
var left = offsets[0];
|
2041
|
-
var width = element.clientWidth;
|
2042
|
-
var height = element.clientHeight;
|
2043
|
-
|
2044
|
-
element._originalLeft = left - parseFloat(element.style.left || 0);
|
2045
|
-
element._originalTop = top - parseFloat(element.style.top || 0);
|
2046
|
-
element._originalWidth = element.style.width;
|
2047
|
-
element._originalHeight = element.style.height;
|
2048
|
-
|
2049
|
-
element.style.position = 'absolute';
|
2050
|
-
element.style.top = top + 'px';
|
2051
|
-
element.style.left = left + 'px';
|
2052
|
-
element.style.width = width + 'px';
|
2053
|
-
element.style.height = height + 'px';
|
2054
|
-
return element;
|
2055
|
-
},
|
2056
|
-
|
2057
|
-
relativize: function(element) {
|
2058
|
-
element = $(element);
|
2059
|
-
if (element.getStyle('position') == 'relative') return;
|
2060
|
-
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
2061
|
-
|
2062
|
-
element.style.position = 'relative';
|
2063
|
-
var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
|
2064
|
-
var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
|
2065
|
-
|
2066
|
-
element.style.top = top + 'px';
|
2067
|
-
element.style.left = left + 'px';
|
2068
|
-
element.style.height = element._originalHeight;
|
2069
|
-
element.style.width = element._originalWidth;
|
2070
|
-
return element;
|
2071
|
-
},
|
2072
|
-
|
2073
|
-
cumulativeScrollOffset: function(element) {
|
2074
|
-
var valueT = 0, valueL = 0;
|
2075
|
-
do {
|
2076
|
-
valueT += element.scrollTop || 0;
|
2077
|
-
valueL += element.scrollLeft || 0;
|
2078
|
-
element = element.parentNode;
|
2079
|
-
} while (element);
|
2080
|
-
return Element._returnOffset(valueL, valueT);
|
2081
|
-
},
|
2082
|
-
|
2083
|
-
getOffsetParent: function(element) {
|
2084
|
-
if (element.offsetParent) return $(element.offsetParent);
|
2085
|
-
if (element == document.body) return $(element);
|
2086
|
-
|
2087
|
-
while ((element = element.parentNode) && element != document.body)
|
2088
|
-
if (Element.getStyle(element, 'position') != 'static')
|
2089
|
-
return $(element);
|
2090
|
-
|
2091
|
-
return $(document.body);
|
2092
|
-
},
|
2093
|
-
|
2094
|
-
viewportOffset: function(forElement) {
|
2095
|
-
var valueT = 0, valueL = 0;
|
2096
|
-
|
2097
|
-
var element = forElement;
|
2098
|
-
do {
|
2099
|
-
valueT += element.offsetTop || 0;
|
2100
|
-
valueL += element.offsetLeft || 0;
|
2101
|
-
|
2102
|
-
// Safari fix
|
2103
|
-
if (element.offsetParent == document.body &&
|
2104
|
-
Element.getStyle(element, 'position') == 'absolute') break;
|
2105
|
-
|
2106
|
-
} while (element = element.offsetParent);
|
2107
|
-
|
2108
|
-
element = forElement;
|
2109
|
-
do {
|
2110
|
-
if (!Prototype.Browser.Opera || element.tagName == 'BODY') {
|
2111
|
-
valueT -= element.scrollTop || 0;
|
2112
|
-
valueL -= element.scrollLeft || 0;
|
2113
|
-
}
|
2114
|
-
} while (element = element.parentNode);
|
2115
|
-
|
2116
|
-
return Element._returnOffset(valueL, valueT);
|
2117
|
-
},
|
2118
|
-
|
2119
|
-
clonePosition: function(element, source) {
|
2120
|
-
var options = Object.extend({
|
2121
|
-
setLeft: true,
|
2122
|
-
setTop: true,
|
2123
|
-
setWidth: true,
|
2124
|
-
setHeight: true,
|
2125
|
-
offsetTop: 0,
|
2126
|
-
offsetLeft: 0
|
2127
|
-
}, arguments[2] || { });
|
2128
|
-
|
2129
|
-
// find page position of source
|
2130
|
-
source = $(source);
|
2131
|
-
var p = source.viewportOffset();
|
2132
|
-
|
2133
|
-
// find coordinate system to use
|
2134
|
-
element = $(element);
|
2135
|
-
var delta = [0, 0];
|
2136
|
-
var parent = null;
|
2137
|
-
// delta [0,0] will do fine with position: fixed elements,
|
2138
|
-
// position:absolute needs offsetParent deltas
|
2139
|
-
if (Element.getStyle(element, 'position') == 'absolute') {
|
2140
|
-
parent = element.getOffsetParent();
|
2141
|
-
delta = parent.viewportOffset();
|
2142
|
-
}
|
2143
|
-
|
2144
|
-
// correct by body offsets (fixes Safari)
|
2145
|
-
if (parent == document.body) {
|
2146
|
-
delta[0] -= document.body.offsetLeft;
|
2147
|
-
delta[1] -= document.body.offsetTop;
|
2148
|
-
}
|
2149
|
-
|
2150
|
-
// set position
|
2151
|
-
if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
|
2152
|
-
if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
|
2153
|
-
if (options.setWidth) element.style.width = source.offsetWidth + 'px';
|
2154
|
-
if (options.setHeight) element.style.height = source.offsetHeight + 'px';
|
2155
|
-
return element;
|
2156
|
-
}
|
2157
|
-
};
|
2158
|
-
|
2159
|
-
Element.Methods.identify.counter = 1;
|
2160
|
-
|
2161
|
-
Object.extend(Element.Methods, {
|
2162
|
-
getElementsBySelector: Element.Methods.select,
|
2163
|
-
childElements: Element.Methods.immediateDescendants
|
2164
|
-
});
|
2165
|
-
|
2166
|
-
Element._attributeTranslations = {
|
2167
|
-
write: {
|
2168
|
-
names: {
|
2169
|
-
className: 'class',
|
2170
|
-
htmlFor: 'for'
|
2171
|
-
},
|
2172
|
-
values: { }
|
2173
|
-
}
|
2174
|
-
};
|
2175
|
-
|
2176
|
-
|
2177
|
-
if (!document.createRange || Prototype.Browser.Opera) {
|
2178
|
-
Element.Methods.insert = function(element, insertions) {
|
2179
|
-
element = $(element);
|
2180
|
-
|
2181
|
-
if (Object.isString(insertions) || Object.isNumber(insertions) ||
|
2182
|
-
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
|
2183
|
-
insertions = { bottom: insertions };
|
2184
|
-
|
2185
|
-
var t = Element._insertionTranslations, content, position, pos, tagName;
|
2186
|
-
|
2187
|
-
for (position in insertions) {
|
2188
|
-
content = insertions[position];
|
2189
|
-
position = position.toLowerCase();
|
2190
|
-
pos = t[position];
|
2191
|
-
|
2192
|
-
if (content && content.toElement) content = content.toElement();
|
2193
|
-
if (Object.isElement(content)) {
|
2194
|
-
pos.insert(element, content);
|
2195
|
-
continue;
|
2196
|
-
}
|
2197
|
-
|
2198
|
-
content = Object.toHTML(content);
|
2199
|
-
tagName = ((position == 'before' || position == 'after')
|
2200
|
-
? element.parentNode : element).tagName.toUpperCase();
|
2201
|
-
|
2202
|
-
if (t.tags[tagName]) {
|
2203
|
-
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
2204
|
-
if (position == 'top' || position == 'after') fragments.reverse();
|
2205
|
-
fragments.each(pos.insert.curry(element));
|
2206
|
-
}
|
2207
|
-
else element.insertAdjacentHTML(pos.adjacency, content.stripScripts());
|
2208
|
-
|
2209
|
-
content.evalScripts.bind(content).defer();
|
2210
|
-
}
|
2211
|
-
|
2212
|
-
return element;
|
2213
|
-
};
|
2214
|
-
}
|
2215
|
-
|
2216
|
-
if (Prototype.Browser.Opera) {
|
2217
|
-
Element.Methods._getStyle = Element.Methods.getStyle;
|
2218
|
-
Element.Methods.getStyle = function(element, style) {
|
2219
|
-
switch(style) {
|
2220
|
-
case 'left':
|
2221
|
-
case 'top':
|
2222
|
-
case 'right':
|
2223
|
-
case 'bottom':
|
2224
|
-
if (Element._getStyle(element, 'position') == 'static') return null;
|
2225
|
-
default: return Element._getStyle(element, style);
|
2226
|
-
}
|
2227
|
-
};
|
2228
|
-
Element.Methods._readAttribute = Element.Methods.readAttribute;
|
2229
|
-
Element.Methods.readAttribute = function(element, attribute) {
|
2230
|
-
if (attribute == 'title') return element.title;
|
2231
|
-
return Element._readAttribute(element, attribute);
|
2232
|
-
};
|
2233
|
-
}
|
2234
|
-
|
2235
|
-
else if (Prototype.Browser.IE) {
|
2236
|
-
$w('positionedOffset getOffsetParent viewportOffset').each(function(method) {
|
2237
|
-
Element.Methods[method] = Element.Methods[method].wrap(
|
2238
|
-
function(proceed, element) {
|
2239
|
-
element = $(element);
|
2240
|
-
var position = element.getStyle('position');
|
2241
|
-
if (position != 'static') return proceed(element);
|
2242
|
-
element.setStyle({ position: 'relative' });
|
2243
|
-
var value = proceed(element);
|
2244
|
-
element.setStyle({ position: position });
|
2245
|
-
return value;
|
2246
|
-
}
|
2247
|
-
);
|
2248
|
-
});
|
2249
|
-
|
2250
|
-
Element.Methods.getStyle = function(element, style) {
|
2251
|
-
element = $(element);
|
2252
|
-
style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
|
2253
|
-
var value = element.style[style];
|
2254
|
-
if (!value && element.currentStyle) value = element.currentStyle[style];
|
2255
|
-
|
2256
|
-
if (style == 'opacity') {
|
2257
|
-
if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
|
2258
|
-
if (value[1]) return parseFloat(value[1]) / 100;
|
2259
|
-
return 1.0;
|
2260
|
-
}
|
2261
|
-
|
2262
|
-
if (value == 'auto') {
|
2263
|
-
if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
|
2264
|
-
return element['offset' + style.capitalize()] + 'px';
|
2265
|
-
return null;
|
2266
|
-
}
|
2267
|
-
return value;
|
2268
|
-
};
|
2269
|
-
|
2270
|
-
Element.Methods.setOpacity = function(element, value) {
|
2271
|
-
function stripAlpha(filter){
|
2272
|
-
return filter.replace(/alpha\([^\)]*\)/gi,'');
|
2273
|
-
}
|
2274
|
-
element = $(element);
|
2275
|
-
var currentStyle = element.currentStyle;
|
2276
|
-
if ((currentStyle && !currentStyle.hasLayout) ||
|
2277
|
-
(!currentStyle && element.style.zoom == 'normal'))
|
2278
|
-
element.style.zoom = 1;
|
2279
|
-
|
2280
|
-
var filter = element.getStyle('filter'), style = element.style;
|
2281
|
-
if (value == 1 || value === '') {
|
2282
|
-
(filter = stripAlpha(filter)) ?
|
2283
|
-
style.filter = filter : style.removeAttribute('filter');
|
2284
|
-
return element;
|
2285
|
-
} else if (value < 0.00001) value = 0;
|
2286
|
-
style.filter = stripAlpha(filter) +
|
2287
|
-
'alpha(opacity=' + (value * 100) + ')';
|
2288
|
-
return element;
|
2289
|
-
};
|
2290
|
-
|
2291
|
-
Element._attributeTranslations = {
|
2292
|
-
read: {
|
2293
|
-
names: {
|
2294
|
-
'class': 'className',
|
2295
|
-
'for': 'htmlFor'
|
2296
|
-
},
|
2297
|
-
values: {
|
2298
|
-
_getAttr: function(element, attribute) {
|
2299
|
-
return element.getAttribute(attribute, 2);
|
2300
|
-
},
|
2301
|
-
_getAttrNode: function(element, attribute) {
|
2302
|
-
var node = element.getAttributeNode(attribute);
|
2303
|
-
return node ? node.value : "";
|
2304
|
-
},
|
2305
|
-
_getEv: function(element, attribute) {
|
2306
|
-
var attribute = element.getAttribute(attribute);
|
2307
|
-
return attribute ? attribute.toString().slice(23, -2) : null;
|
2308
|
-
},
|
2309
|
-
_flag: function(element, attribute) {
|
2310
|
-
return $(element).hasAttribute(attribute) ? attribute : null;
|
2311
|
-
},
|
2312
|
-
style: function(element) {
|
2313
|
-
return element.style.cssText.toLowerCase();
|
2314
|
-
},
|
2315
|
-
title: function(element) {
|
2316
|
-
return element.title;
|
2317
|
-
}
|
2318
|
-
}
|
2319
|
-
}
|
2320
|
-
};
|
2321
|
-
|
2322
|
-
Element._attributeTranslations.write = {
|
2323
|
-
names: Object.clone(Element._attributeTranslations.read.names),
|
2324
|
-
values: {
|
2325
|
-
checked: function(element, value) {
|
2326
|
-
element.checked = !!value;
|
2327
|
-
},
|
2328
|
-
|
2329
|
-
style: function(element, value) {
|
2330
|
-
element.style.cssText = value ? value : '';
|
2331
|
-
}
|
2332
|
-
}
|
2333
|
-
};
|
2334
|
-
|
2335
|
-
Element._attributeTranslations.has = {};
|
2336
|
-
|
2337
|
-
$w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
|
2338
|
-
'encType maxLength readOnly longDesc').each(function(attr) {
|
2339
|
-
Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
|
2340
|
-
Element._attributeTranslations.has[attr.toLowerCase()] = attr;
|
2341
|
-
});
|
2342
|
-
|
2343
|
-
(function(v) {
|
2344
|
-
Object.extend(v, {
|
2345
|
-
href: v._getAttr,
|
2346
|
-
src: v._getAttr,
|
2347
|
-
type: v._getAttr,
|
2348
|
-
action: v._getAttrNode,
|
2349
|
-
disabled: v._flag,
|
2350
|
-
checked: v._flag,
|
2351
|
-
readonly: v._flag,
|
2352
|
-
multiple: v._flag,
|
2353
|
-
onload: v._getEv,
|
2354
|
-
onunload: v._getEv,
|
2355
|
-
onclick: v._getEv,
|
2356
|
-
ondblclick: v._getEv,
|
2357
|
-
onmousedown: v._getEv,
|
2358
|
-
onmouseup: v._getEv,
|
2359
|
-
onmouseover: v._getEv,
|
2360
|
-
onmousemove: v._getEv,
|
2361
|
-
onmouseout: v._getEv,
|
2362
|
-
onfocus: v._getEv,
|
2363
|
-
onblur: v._getEv,
|
2364
|
-
onkeypress: v._getEv,
|
2365
|
-
onkeydown: v._getEv,
|
2366
|
-
onkeyup: v._getEv,
|
2367
|
-
onsubmit: v._getEv,
|
2368
|
-
onreset: v._getEv,
|
2369
|
-
onselect: v._getEv,
|
2370
|
-
onchange: v._getEv
|
2371
|
-
});
|
2372
|
-
})(Element._attributeTranslations.read.values);
|
2373
|
-
}
|
2374
|
-
|
2375
|
-
else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
|
2376
|
-
Element.Methods.setOpacity = function(element, value) {
|
2377
|
-
element = $(element);
|
2378
|
-
element.style.opacity = (value == 1) ? 0.999999 :
|
2379
|
-
(value === '') ? '' : (value < 0.00001) ? 0 : value;
|
2380
|
-
return element;
|
2381
|
-
};
|
2382
|
-
}
|
2383
|
-
|
2384
|
-
else if (Prototype.Browser.WebKit) {
|
2385
|
-
Element.Methods.setOpacity = function(element, value) {
|
2386
|
-
element = $(element);
|
2387
|
-
element.style.opacity = (value == 1 || value === '') ? '' :
|
2388
|
-
(value < 0.00001) ? 0 : value;
|
2389
|
-
|
2390
|
-
if (value == 1)
|
2391
|
-
if(element.tagName == 'IMG' && element.width) {
|
2392
|
-
element.width++; element.width--;
|
2393
|
-
} else try {
|
2394
|
-
var n = document.createTextNode(' ');
|
2395
|
-
element.appendChild(n);
|
2396
|
-
element.removeChild(n);
|
2397
|
-
} catch (e) { }
|
2398
|
-
|
2399
|
-
return element;
|
2400
|
-
};
|
2401
|
-
|
2402
|
-
// Safari returns margins on body which is incorrect if the child is absolutely
|
2403
|
-
// positioned. For performance reasons, redefine Position.cumulativeOffset for
|
2404
|
-
// KHTML/WebKit only.
|
2405
|
-
Element.Methods.cumulativeOffset = function(element) {
|
2406
|
-
var valueT = 0, valueL = 0;
|
2407
|
-
do {
|
2408
|
-
valueT += element.offsetTop || 0;
|
2409
|
-
valueL += element.offsetLeft || 0;
|
2410
|
-
if (element.offsetParent == document.body)
|
2411
|
-
if (Element.getStyle(element, 'position') == 'absolute') break;
|
2412
|
-
|
2413
|
-
element = element.offsetParent;
|
2414
|
-
} while (element);
|
2415
|
-
|
2416
|
-
return Element._returnOffset(valueL, valueT);
|
2417
|
-
};
|
2418
|
-
}
|
2419
|
-
|
2420
|
-
if (Prototype.Browser.IE || Prototype.Browser.Opera) {
|
2421
|
-
// IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements
|
2422
|
-
Element.Methods.update = function(element, content) {
|
2423
|
-
element = $(element);
|
2424
|
-
|
2425
|
-
if (content && content.toElement) content = content.toElement();
|
2426
|
-
if (Object.isElement(content)) return element.update().insert(content);
|
2427
|
-
|
2428
|
-
content = Object.toHTML(content);
|
2429
|
-
var tagName = element.tagName.toUpperCase();
|
2430
|
-
|
2431
|
-
if (tagName in Element._insertionTranslations.tags) {
|
2432
|
-
$A(element.childNodes).each(function(node) { element.removeChild(node) });
|
2433
|
-
Element._getContentFromAnonymousElement(tagName, content.stripScripts())
|
2434
|
-
.each(function(node) { element.appendChild(node) });
|
2435
|
-
}
|
2436
|
-
else element.innerHTML = content.stripScripts();
|
2437
|
-
|
2438
|
-
content.evalScripts.bind(content).defer();
|
2439
|
-
return element;
|
2440
|
-
};
|
2441
|
-
}
|
2442
|
-
|
2443
|
-
if (document.createElement('div').outerHTML) {
|
2444
|
-
Element.Methods.replace = function(element, content) {
|
2445
|
-
element = $(element);
|
2446
|
-
|
2447
|
-
if (content && content.toElement) content = content.toElement();
|
2448
|
-
if (Object.isElement(content)) {
|
2449
|
-
element.parentNode.replaceChild(content, element);
|
2450
|
-
return element;
|
2451
|
-
}
|
2452
|
-
|
2453
|
-
content = Object.toHTML(content);
|
2454
|
-
var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
|
2455
|
-
|
2456
|
-
if (Element._insertionTranslations.tags[tagName]) {
|
2457
|
-
var nextSibling = element.next();
|
2458
|
-
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
2459
|
-
parent.removeChild(element);
|
2460
|
-
if (nextSibling)
|
2461
|
-
fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
|
2462
|
-
else
|
2463
|
-
fragments.each(function(node) { parent.appendChild(node) });
|
2464
|
-
}
|
2465
|
-
else element.outerHTML = content.stripScripts();
|
2466
|
-
|
2467
|
-
content.evalScripts.bind(content).defer();
|
2468
|
-
return element;
|
2469
|
-
};
|
2470
|
-
}
|
2471
|
-
|
2472
|
-
Element._returnOffset = function(l, t) {
|
2473
|
-
var result = [l, t];
|
2474
|
-
result.left = l;
|
2475
|
-
result.top = t;
|
2476
|
-
return result;
|
2477
|
-
};
|
2478
|
-
|
2479
|
-
Element._getContentFromAnonymousElement = function(tagName, html) {
|
2480
|
-
var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
|
2481
|
-
div.innerHTML = t[0] + html + t[1];
|
2482
|
-
t[2].times(function() { div = div.firstChild });
|
2483
|
-
return $A(div.childNodes);
|
2484
|
-
};
|
2485
|
-
|
2486
|
-
Element._insertionTranslations = {
|
2487
|
-
before: {
|
2488
|
-
adjacency: 'beforeBegin',
|
2489
|
-
insert: function(element, node) {
|
2490
|
-
element.parentNode.insertBefore(node, element);
|
2491
|
-
},
|
2492
|
-
initializeRange: function(element, range) {
|
2493
|
-
range.setStartBefore(element);
|
2494
|
-
}
|
2495
|
-
},
|
2496
|
-
top: {
|
2497
|
-
adjacency: 'afterBegin',
|
2498
|
-
insert: function(element, node) {
|
2499
|
-
element.insertBefore(node, element.firstChild);
|
2500
|
-
},
|
2501
|
-
initializeRange: function(element, range) {
|
2502
|
-
range.selectNodeContents(element);
|
2503
|
-
range.collapse(true);
|
2504
|
-
}
|
2505
|
-
},
|
2506
|
-
bottom: {
|
2507
|
-
adjacency: 'beforeEnd',
|
2508
|
-
insert: function(element, node) {
|
2509
|
-
element.appendChild(node);
|
2510
|
-
}
|
2511
|
-
},
|
2512
|
-
after: {
|
2513
|
-
adjacency: 'afterEnd',
|
2514
|
-
insert: function(element, node) {
|
2515
|
-
element.parentNode.insertBefore(node, element.nextSibling);
|
2516
|
-
},
|
2517
|
-
initializeRange: function(element, range) {
|
2518
|
-
range.setStartAfter(element);
|
2519
|
-
}
|
2520
|
-
},
|
2521
|
-
tags: {
|
2522
|
-
TABLE: ['<table>', '</table>', 1],
|
2523
|
-
TBODY: ['<table><tbody>', '</tbody></table>', 2],
|
2524
|
-
TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
|
2525
|
-
TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
|
2526
|
-
SELECT: ['<select>', '</select>', 1]
|
2527
|
-
}
|
2528
|
-
};
|
2529
|
-
|
2530
|
-
(function() {
|
2531
|
-
this.bottom.initializeRange = this.top.initializeRange;
|
2532
|
-
Object.extend(this.tags, {
|
2533
|
-
THEAD: this.tags.TBODY,
|
2534
|
-
TFOOT: this.tags.TBODY,
|
2535
|
-
TH: this.tags.TD
|
2536
|
-
});
|
2537
|
-
}).call(Element._insertionTranslations);
|
2538
|
-
|
2539
|
-
Element.Methods.Simulated = {
|
2540
|
-
hasAttribute: function(element, attribute) {
|
2541
|
-
attribute = Element._attributeTranslations.has[attribute] || attribute;
|
2542
|
-
var node = $(element).getAttributeNode(attribute);
|
2543
|
-
return node && node.specified;
|
2544
|
-
}
|
2545
|
-
};
|
2546
|
-
|
2547
|
-
Element.Methods.ByTag = { };
|
2548
|
-
|
2549
|
-
Object.extend(Element, Element.Methods);
|
2550
|
-
|
2551
|
-
if (!Prototype.BrowserFeatures.ElementExtensions &&
|
2552
|
-
document.createElement('div').__proto__) {
|
2553
|
-
window.HTMLElement = { };
|
2554
|
-
window.HTMLElement.prototype = document.createElement('div').__proto__;
|
2555
|
-
Prototype.BrowserFeatures.ElementExtensions = true;
|
2556
|
-
}
|
2557
|
-
|
2558
|
-
Element.extend = (function() {
|
2559
|
-
if (Prototype.BrowserFeatures.SpecificElementExtensions)
|
2560
|
-
return Prototype.K;
|
2561
|
-
|
2562
|
-
var Methods = { }, ByTag = Element.Methods.ByTag;
|
2563
|
-
|
2564
|
-
var extend = Object.extend(function(element) {
|
2565
|
-
if (!element || element._extendedByPrototype ||
|
2566
|
-
element.nodeType != 1 || element == window) return element;
|
2567
|
-
|
2568
|
-
var methods = Object.clone(Methods),
|
2569
|
-
tagName = element.tagName, property, value;
|
2570
|
-
|
2571
|
-
// extend methods for specific tags
|
2572
|
-
if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
|
2573
|
-
|
2574
|
-
for (property in methods) {
|
2575
|
-
value = methods[property];
|
2576
|
-
if (Object.isFunction(value) && !(property in element))
|
2577
|
-
element[property] = value.methodize();
|
2578
|
-
}
|
2579
|
-
|
2580
|
-
element._extendedByPrototype = Prototype.emptyFunction;
|
2581
|
-
return element;
|
2582
|
-
|
2583
|
-
}, {
|
2584
|
-
refresh: function() {
|
2585
|
-
// extend methods for all tags (Safari doesn't need this)
|
2586
|
-
if (!Prototype.BrowserFeatures.ElementExtensions) {
|
2587
|
-
Object.extend(Methods, Element.Methods);
|
2588
|
-
Object.extend(Methods, Element.Methods.Simulated);
|
2589
|
-
}
|
2590
|
-
}
|
2591
|
-
});
|
2592
|
-
|
2593
|
-
extend.refresh();
|
2594
|
-
return extend;
|
2595
|
-
})();
|
2596
|
-
|
2597
|
-
Element.hasAttribute = function(element, attribute) {
|
2598
|
-
if (element.hasAttribute) return element.hasAttribute(attribute);
|
2599
|
-
return Element.Methods.Simulated.hasAttribute(element, attribute);
|
2600
|
-
};
|
2601
|
-
|
2602
|
-
Element.addMethods = function(methods) {
|
2603
|
-
var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
|
2604
|
-
|
2605
|
-
if (!methods) {
|
2606
|
-
Object.extend(Form, Form.Methods);
|
2607
|
-
Object.extend(Form.Element, Form.Element.Methods);
|
2608
|
-
Object.extend(Element.Methods.ByTag, {
|
2609
|
-
"FORM": Object.clone(Form.Methods),
|
2610
|
-
"INPUT": Object.clone(Form.Element.Methods),
|
2611
|
-
"SELECT": Object.clone(Form.Element.Methods),
|
2612
|
-
"TEXTAREA": Object.clone(Form.Element.Methods)
|
2613
|
-
});
|
2614
|
-
}
|
2615
|
-
|
2616
|
-
if (arguments.length == 2) {
|
2617
|
-
var tagName = methods;
|
2618
|
-
methods = arguments[1];
|
2619
|
-
}
|
2620
|
-
|
2621
|
-
if (!tagName) Object.extend(Element.Methods, methods || { });
|
2622
|
-
else {
|
2623
|
-
if (Object.isArray(tagName)) tagName.each(extend);
|
2624
|
-
else extend(tagName);
|
2625
|
-
}
|
2626
|
-
|
2627
|
-
function extend(tagName) {
|
2628
|
-
tagName = tagName.toUpperCase();
|
2629
|
-
if (!Element.Methods.ByTag[tagName])
|
2630
|
-
Element.Methods.ByTag[tagName] = { };
|
2631
|
-
Object.extend(Element.Methods.ByTag[tagName], methods);
|
2632
|
-
}
|
2633
|
-
|
2634
|
-
function copy(methods, destination, onlyIfAbsent) {
|
2635
|
-
onlyIfAbsent = onlyIfAbsent || false;
|
2636
|
-
for (var property in methods) {
|
2637
|
-
var value = methods[property];
|
2638
|
-
if (!Object.isFunction(value)) continue;
|
2639
|
-
if (!onlyIfAbsent || !(property in destination))
|
2640
|
-
destination[property] = value.methodize();
|
2641
|
-
}
|
2642
|
-
}
|
2643
|
-
|
2644
|
-
function findDOMClass(tagName) {
|
2645
|
-
var klass;
|
2646
|
-
var trans = {
|
2647
|
-
"OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
|
2648
|
-
"FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
|
2649
|
-
"DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
|
2650
|
-
"H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
|
2651
|
-
"INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
|
2652
|
-
"TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
|
2653
|
-
"TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
|
2654
|
-
"TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
|
2655
|
-
"FrameSet", "IFRAME": "IFrame"
|
2656
|
-
};
|
2657
|
-
if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
|
2658
|
-
if (window[klass]) return window[klass];
|
2659
|
-
klass = 'HTML' + tagName + 'Element';
|
2660
|
-
if (window[klass]) return window[klass];
|
2661
|
-
klass = 'HTML' + tagName.capitalize() + 'Element';
|
2662
|
-
if (window[klass]) return window[klass];
|
2663
|
-
|
2664
|
-
window[klass] = { };
|
2665
|
-
window[klass].prototype = document.createElement(tagName).__proto__;
|
2666
|
-
return window[klass];
|
2667
|
-
}
|
2668
|
-
|
2669
|
-
if (F.ElementExtensions) {
|
2670
|
-
copy(Element.Methods, HTMLElement.prototype);
|
2671
|
-
copy(Element.Methods.Simulated, HTMLElement.prototype, true);
|
2672
|
-
}
|
2673
|
-
|
2674
|
-
if (F.SpecificElementExtensions) {
|
2675
|
-
for (var tag in Element.Methods.ByTag) {
|
2676
|
-
var klass = findDOMClass(tag);
|
2677
|
-
if (Object.isUndefined(klass)) continue;
|
2678
|
-
copy(T[tag], klass.prototype);
|
2679
|
-
}
|
2680
|
-
}
|
2681
|
-
|
2682
|
-
Object.extend(Element, Element.Methods);
|
2683
|
-
delete Element.ByTag;
|
2684
|
-
|
2685
|
-
if (Element.extend.refresh) Element.extend.refresh();
|
2686
|
-
Element.cache = { };
|
2687
|
-
};
|
2688
|
-
|
2689
|
-
document.viewport = {
|
2690
|
-
getDimensions: function() {
|
2691
|
-
var dimensions = { };
|
2692
|
-
$w('width height').each(function(d) {
|
2693
|
-
var D = d.capitalize();
|
2694
|
-
dimensions[d] = self['inner' + D] ||
|
2695
|
-
(document.documentElement['client' + D] || document.body['client' + D]);
|
2696
|
-
});
|
2697
|
-
return dimensions;
|
2698
|
-
},
|
2699
|
-
|
2700
|
-
getWidth: function() {
|
2701
|
-
return this.getDimensions().width;
|
2702
|
-
},
|
2703
|
-
|
2704
|
-
getHeight: function() {
|
2705
|
-
return this.getDimensions().height;
|
2706
|
-
},
|
2707
|
-
|
2708
|
-
getScrollOffsets: function() {
|
2709
|
-
return Element._returnOffset(
|
2710
|
-
window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
|
2711
|
-
window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
|
2712
|
-
}
|
2713
|
-
};
|
2714
|
-
/* Portions of the Selector class are derived from Jack Slocum’s DomQuery,
|
2715
|
-
* part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
|
2716
|
-
* license. Please see http://www.yui-ext.com/ for more information. */
|
2717
|
-
|
2718
|
-
var Selector = Class.create({
|
2719
|
-
initialize: function(expression) {
|
2720
|
-
this.expression = expression.strip();
|
2721
|
-
this.compileMatcher();
|
2722
|
-
},
|
2723
|
-
|
2724
|
-
compileMatcher: function() {
|
2725
|
-
// Selectors with namespaced attributes can't use the XPath version
|
2726
|
-
if (Prototype.BrowserFeatures.XPath && !(/(\[[\w-]*?:|:checked)/).test(this.expression))
|
2727
|
-
return this.compileXPathMatcher();
|
2728
|
-
|
2729
|
-
var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
|
2730
|
-
c = Selector.criteria, le, p, m;
|
2731
|
-
|
2732
|
-
if (Selector._cache[e]) {
|
2733
|
-
this.matcher = Selector._cache[e];
|
2734
|
-
return;
|
2735
|
-
}
|
2736
|
-
|
2737
|
-
this.matcher = ["this.matcher = function(root) {",
|
2738
|
-
"var r = root, h = Selector.handlers, c = false, n;"];
|
2739
|
-
|
2740
|
-
while (e && le != e && (/\S/).test(e)) {
|
2741
|
-
le = e;
|
2742
|
-
for (var i in ps) {
|
2743
|
-
p = ps[i];
|
2744
|
-
if (m = e.match(p)) {
|
2745
|
-
this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :
|
2746
|
-
new Template(c[i]).evaluate(m));
|
2747
|
-
e = e.replace(m[0], '');
|
2748
|
-
break;
|
2749
|
-
}
|
2750
|
-
}
|
2751
|
-
}
|
2752
|
-
|
2753
|
-
this.matcher.push("return h.unique(n);\n}");
|
2754
|
-
eval(this.matcher.join('\n'));
|
2755
|
-
Selector._cache[this.expression] = this.matcher;
|
2756
|
-
},
|
2757
|
-
|
2758
|
-
compileXPathMatcher: function() {
|
2759
|
-
var e = this.expression, ps = Selector.patterns,
|
2760
|
-
x = Selector.xpath, le, m;
|
2761
|
-
|
2762
|
-
if (Selector._cache[e]) {
|
2763
|
-
this.xpath = Selector._cache[e]; return;
|
2764
|
-
}
|
2765
|
-
|
2766
|
-
this.matcher = ['.//*'];
|
2767
|
-
while (e && le != e && (/\S/).test(e)) {
|
2768
|
-
le = e;
|
2769
|
-
for (var i in ps) {
|
2770
|
-
if (m = e.match(ps[i])) {
|
2771
|
-
this.matcher.push(Object.isFunction(x[i]) ? x[i](m) :
|
2772
|
-
new Template(x[i]).evaluate(m));
|
2773
|
-
e = e.replace(m[0], '');
|
2774
|
-
break;
|
2775
|
-
}
|
2776
|
-
}
|
2777
|
-
}
|
2778
|
-
|
2779
|
-
this.xpath = this.matcher.join('');
|
2780
|
-
Selector._cache[this.expression] = this.xpath;
|
2781
|
-
},
|
2782
|
-
|
2783
|
-
findElements: function(root) {
|
2784
|
-
root = root || document;
|
2785
|
-
if (this.xpath) return document._getElementsByXPath(this.xpath, root);
|
2786
|
-
return this.matcher(root);
|
2787
|
-
},
|
2788
|
-
|
2789
|
-
match: function(element) {
|
2790
|
-
this.tokens = [];
|
2791
|
-
|
2792
|
-
var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
|
2793
|
-
var le, p, m;
|
2794
|
-
|
2795
|
-
while (e && le !== e && (/\S/).test(e)) {
|
2796
|
-
le = e;
|
2797
|
-
for (var i in ps) {
|
2798
|
-
p = ps[i];
|
2799
|
-
if (m = e.match(p)) {
|
2800
|
-
// use the Selector.assertions methods unless the selector
|
2801
|
-
// is too complex.
|
2802
|
-
if (as[i]) {
|
2803
|
-
this.tokens.push([i, Object.clone(m)]);
|
2804
|
-
e = e.replace(m[0], '');
|
2805
|
-
} else {
|
2806
|
-
// reluctantly do a document-wide search
|
2807
|
-
// and look for a match in the array
|
2808
|
-
return this.findElements(document).include(element);
|
2809
|
-
}
|
2810
|
-
}
|
2811
|
-
}
|
2812
|
-
}
|
2813
|
-
|
2814
|
-
var match = true, name, matches;
|
2815
|
-
for (var i = 0, token; token = this.tokens[i]; i++) {
|
2816
|
-
name = token[0], matches = token[1];
|
2817
|
-
if (!Selector.assertions[name](element, matches)) {
|
2818
|
-
match = false; break;
|
2819
|
-
}
|
2820
|
-
}
|
2821
|
-
|
2822
|
-
return match;
|
2823
|
-
},
|
2824
|
-
|
2825
|
-
toString: function() {
|
2826
|
-
return this.expression;
|
2827
|
-
},
|
2828
|
-
|
2829
|
-
inspect: function() {
|
2830
|
-
return "#<Selector:" + this.expression.inspect() + ">";
|
2831
|
-
}
|
2832
|
-
});
|
2833
|
-
|
2834
|
-
Object.extend(Selector, {
|
2835
|
-
_cache: { },
|
2836
|
-
|
2837
|
-
xpath: {
|
2838
|
-
descendant: "//*",
|
2839
|
-
child: "/*",
|
2840
|
-
adjacent: "/following-sibling::*[1]",
|
2841
|
-
laterSibling: '/following-sibling::*',
|
2842
|
-
tagName: function(m) {
|
2843
|
-
if (m[1] == '*') return '';
|
2844
|
-
return "[local-name()='" + m[1].toLowerCase() +
|
2845
|
-
"' or local-name()='" + m[1].toUpperCase() + "']";
|
2846
|
-
},
|
2847
|
-
className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
|
2848
|
-
id: "[@id='#{1}']",
|
2849
|
-
attrPresence: "[@#{1}]",
|
2850
|
-
attr: function(m) {
|
2851
|
-
m[3] = m[5] || m[6];
|
2852
|
-
return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
|
2853
|
-
},
|
2854
|
-
pseudo: function(m) {
|
2855
|
-
var h = Selector.xpath.pseudos[m[1]];
|
2856
|
-
if (!h) return '';
|
2857
|
-
if (Object.isFunction(h)) return h(m);
|
2858
|
-
return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
|
2859
|
-
},
|
2860
|
-
operators: {
|
2861
|
-
'=': "[@#{1}='#{3}']",
|
2862
|
-
'!=': "[@#{1}!='#{3}']",
|
2863
|
-
'^=': "[starts-with(@#{1}, '#{3}')]",
|
2864
|
-
'$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
|
2865
|
-
'*=': "[contains(@#{1}, '#{3}')]",
|
2866
|
-
'~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
|
2867
|
-
'|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
|
2868
|
-
},
|
2869
|
-
pseudos: {
|
2870
|
-
'first-child': '[not(preceding-sibling::*)]',
|
2871
|
-
'last-child': '[not(following-sibling::*)]',
|
2872
|
-
'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
|
2873
|
-
'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",
|
2874
|
-
'checked': "[@checked]",
|
2875
|
-
'disabled': "[@disabled]",
|
2876
|
-
'enabled': "[not(@disabled)]",
|
2877
|
-
'not': function(m) {
|
2878
|
-
var e = m[6], p = Selector.patterns,
|
2879
|
-
x = Selector.xpath, le, m, v;
|
2880
|
-
|
2881
|
-
var exclusion = [];
|
2882
|
-
while (e && le != e && (/\S/).test(e)) {
|
2883
|
-
le = e;
|
2884
|
-
for (var i in p) {
|
2885
|
-
if (m = e.match(p[i])) {
|
2886
|
-
v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m);
|
2887
|
-
exclusion.push("(" + v.substring(1, v.length - 1) + ")");
|
2888
|
-
e = e.replace(m[0], '');
|
2889
|
-
break;
|
2890
|
-
}
|
2891
|
-
}
|
2892
|
-
}
|
2893
|
-
return "[not(" + exclusion.join(" and ") + ")]";
|
2894
|
-
},
|
2895
|
-
'nth-child': function(m) {
|
2896
|
-
return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
|
2897
|
-
},
|
2898
|
-
'nth-last-child': function(m) {
|
2899
|
-
return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
|
2900
|
-
},
|
2901
|
-
'nth-of-type': function(m) {
|
2902
|
-
return Selector.xpath.pseudos.nth("position() ", m);
|
2903
|
-
},
|
2904
|
-
'nth-last-of-type': function(m) {
|
2905
|
-
return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
|
2906
|
-
},
|
2907
|
-
'first-of-type': function(m) {
|
2908
|
-
m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
|
2909
|
-
},
|
2910
|
-
'last-of-type': function(m) {
|
2911
|
-
m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
|
2912
|
-
},
|
2913
|
-
'only-of-type': function(m) {
|
2914
|
-
var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
|
2915
|
-
},
|
2916
|
-
nth: function(fragment, m) {
|
2917
|
-
var mm, formula = m[6], predicate;
|
2918
|
-
if (formula == 'even') formula = '2n+0';
|
2919
|
-
if (formula == 'odd') formula = '2n+1';
|
2920
|
-
if (mm = formula.match(/^(\d+)$/)) // digit only
|
2921
|
-
return '[' + fragment + "= " + mm[1] + ']';
|
2922
|
-
if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
|
2923
|
-
if (mm[1] == "-") mm[1] = -1;
|
2924
|
-
var a = mm[1] ? Number(mm[1]) : 1;
|
2925
|
-
var b = mm[2] ? Number(mm[2]) : 0;
|
2926
|
-
predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
|
2927
|
-
"((#{fragment} - #{b}) div #{a} >= 0)]";
|
2928
|
-
return new Template(predicate).evaluate({
|
2929
|
-
fragment: fragment, a: a, b: b });
|
2930
|
-
}
|
2931
|
-
}
|
2932
|
-
}
|
2933
|
-
},
|
2934
|
-
|
2935
|
-
criteria: {
|
2936
|
-
tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
|
2937
|
-
className: 'n = h.className(n, r, "#{1}", c); c = false;',
|
2938
|
-
id: 'n = h.id(n, r, "#{1}", c); c = false;',
|
2939
|
-
attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;',
|
2940
|
-
attr: function(m) {
|
2941
|
-
m[3] = (m[5] || m[6]);
|
2942
|
-
return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m);
|
2943
|
-
},
|
2944
|
-
pseudo: function(m) {
|
2945
|
-
if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
|
2946
|
-
return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
|
2947
|
-
},
|
2948
|
-
descendant: 'c = "descendant";',
|
2949
|
-
child: 'c = "child";',
|
2950
|
-
adjacent: 'c = "adjacent";',
|
2951
|
-
laterSibling: 'c = "laterSibling";'
|
2952
|
-
},
|
2953
|
-
|
2954
|
-
patterns: {
|
2955
|
-
// combinators must be listed first
|
2956
|
-
// (and descendant needs to be last combinator)
|
2957
|
-
laterSibling: /^\s*~\s*/,
|
2958
|
-
child: /^\s*>\s*/,
|
2959
|
-
adjacent: /^\s*\+\s*/,
|
2960
|
-
descendant: /^\s/,
|
2961
|
-
|
2962
|
-
// selectors follow
|
2963
|
-
tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
|
2964
|
-
id: /^#([\w\-\*]+)(\b|$)/,
|
2965
|
-
className: /^\.([\w\-\*]+)(\b|$)/,
|
2966
|
-
pseudo: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s)|(?=:))/,
|
2967
|
-
attrPresence: /^\[([\w]+)\]/,
|
2968
|
-
attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
|
2969
|
-
},
|
2970
|
-
|
2971
|
-
// for Selector.match and Element#match
|
2972
|
-
assertions: {
|
2973
|
-
tagName: function(element, matches) {
|
2974
|
-
return matches[1].toUpperCase() == element.tagName.toUpperCase();
|
2975
|
-
},
|
2976
|
-
|
2977
|
-
className: function(element, matches) {
|
2978
|
-
return Element.hasClassName(element, matches[1]);
|
2979
|
-
},
|
2980
|
-
|
2981
|
-
id: function(element, matches) {
|
2982
|
-
return element.id === matches[1];
|
2983
|
-
},
|
2984
|
-
|
2985
|
-
attrPresence: function(element, matches) {
|
2986
|
-
return Element.hasAttribute(element, matches[1]);
|
2987
|
-
},
|
2988
|
-
|
2989
|
-
attr: function(element, matches) {
|
2990
|
-
var nodeValue = Element.readAttribute(element, matches[1]);
|
2991
|
-
return Selector.operators[matches[2]](nodeValue, matches[3]);
|
2992
|
-
}
|
2993
|
-
},
|
2994
|
-
|
2995
|
-
handlers: {
|
2996
|
-
// UTILITY FUNCTIONS
|
2997
|
-
// joins two collections
|
2998
|
-
concat: function(a, b) {
|
2999
|
-
for (var i = 0, node; node = b[i]; i++)
|
3000
|
-
a.push(node);
|
3001
|
-
return a;
|
3002
|
-
},
|
3003
|
-
|
3004
|
-
// marks an array of nodes for counting
|
3005
|
-
mark: function(nodes) {
|
3006
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3007
|
-
node._counted = true;
|
3008
|
-
return nodes;
|
3009
|
-
},
|
3010
|
-
|
3011
|
-
unmark: function(nodes) {
|
3012
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3013
|
-
node._counted = undefined;
|
3014
|
-
return nodes;
|
3015
|
-
},
|
3016
|
-
|
3017
|
-
// mark each child node with its position (for nth calls)
|
3018
|
-
// "ofType" flag indicates whether we're indexing for nth-of-type
|
3019
|
-
// rather than nth-child
|
3020
|
-
index: function(parentNode, reverse, ofType) {
|
3021
|
-
parentNode._counted = true;
|
3022
|
-
if (reverse) {
|
3023
|
-
for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
|
3024
|
-
var node = nodes[i];
|
3025
|
-
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
|
3026
|
-
}
|
3027
|
-
} else {
|
3028
|
-
for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
|
3029
|
-
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
|
3030
|
-
}
|
3031
|
-
},
|
3032
|
-
|
3033
|
-
// filters out duplicates and extends all nodes
|
3034
|
-
unique: function(nodes) {
|
3035
|
-
if (nodes.length == 0) return nodes;
|
3036
|
-
var results = [], n;
|
3037
|
-
for (var i = 0, l = nodes.length; i < l; i++)
|
3038
|
-
if (!(n = nodes[i])._counted) {
|
3039
|
-
n._counted = true;
|
3040
|
-
results.push(Element.extend(n));
|
3041
|
-
}
|
3042
|
-
return Selector.handlers.unmark(results);
|
3043
|
-
},
|
3044
|
-
|
3045
|
-
// COMBINATOR FUNCTIONS
|
3046
|
-
descendant: function(nodes) {
|
3047
|
-
var h = Selector.handlers;
|
3048
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3049
|
-
h.concat(results, node.getElementsByTagName('*'));
|
3050
|
-
return results;
|
3051
|
-
},
|
3052
|
-
|
3053
|
-
child: function(nodes) {
|
3054
|
-
var h = Selector.handlers;
|
3055
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3056
|
-
for (var j = 0, children = [], child; child = node.childNodes[j]; j++)
|
3057
|
-
if (child.nodeType == 1 && child.tagName != '!') results.push(child);
|
3058
|
-
}
|
3059
|
-
return results;
|
3060
|
-
},
|
3061
|
-
|
3062
|
-
adjacent: function(nodes) {
|
3063
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3064
|
-
var next = this.nextElementSibling(node);
|
3065
|
-
if (next) results.push(next);
|
3066
|
-
}
|
3067
|
-
return results;
|
3068
|
-
},
|
3069
|
-
|
3070
|
-
laterSibling: function(nodes) {
|
3071
|
-
var h = Selector.handlers;
|
3072
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3073
|
-
h.concat(results, Element.nextSiblings(node));
|
3074
|
-
return results;
|
3075
|
-
},
|
3076
|
-
|
3077
|
-
nextElementSibling: function(node) {
|
3078
|
-
while (node = node.nextSibling)
|
3079
|
-
if (node.nodeType == 1) return node;
|
3080
|
-
return null;
|
3081
|
-
},
|
3082
|
-
|
3083
|
-
previousElementSibling: function(node) {
|
3084
|
-
while (node = node.previousSibling)
|
3085
|
-
if (node.nodeType == 1) return node;
|
3086
|
-
return null;
|
3087
|
-
},
|
3088
|
-
|
3089
|
-
// TOKEN FUNCTIONS
|
3090
|
-
tagName: function(nodes, root, tagName, combinator) {
|
3091
|
-
tagName = tagName.toUpperCase();
|
3092
|
-
var results = [], h = Selector.handlers;
|
3093
|
-
if (nodes) {
|
3094
|
-
if (combinator) {
|
3095
|
-
// fastlane for ordinary descendant combinators
|
3096
|
-
if (combinator == "descendant") {
|
3097
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3098
|
-
h.concat(results, node.getElementsByTagName(tagName));
|
3099
|
-
return results;
|
3100
|
-
} else nodes = this[combinator](nodes);
|
3101
|
-
if (tagName == "*") return nodes;
|
3102
|
-
}
|
3103
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3104
|
-
if (node.tagName.toUpperCase() == tagName) results.push(node);
|
3105
|
-
return results;
|
3106
|
-
} else return root.getElementsByTagName(tagName);
|
3107
|
-
},
|
3108
|
-
|
3109
|
-
id: function(nodes, root, id, combinator) {
|
3110
|
-
var targetNode = $(id), h = Selector.handlers;
|
3111
|
-
if (!targetNode) return [];
|
3112
|
-
if (!nodes && root == document) return [targetNode];
|
3113
|
-
if (nodes) {
|
3114
|
-
if (combinator) {
|
3115
|
-
if (combinator == 'child') {
|
3116
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3117
|
-
if (targetNode.parentNode == node) return [targetNode];
|
3118
|
-
} else if (combinator == 'descendant') {
|
3119
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3120
|
-
if (Element.descendantOf(targetNode, node)) return [targetNode];
|
3121
|
-
} else if (combinator == 'adjacent') {
|
3122
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3123
|
-
if (Selector.handlers.previousElementSibling(targetNode) == node)
|
3124
|
-
return [targetNode];
|
3125
|
-
} else nodes = h[combinator](nodes);
|
3126
|
-
}
|
3127
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3128
|
-
if (node == targetNode) return [targetNode];
|
3129
|
-
return [];
|
3130
|
-
}
|
3131
|
-
return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
|
3132
|
-
},
|
3133
|
-
|
3134
|
-
className: function(nodes, root, className, combinator) {
|
3135
|
-
if (nodes && combinator) nodes = this[combinator](nodes);
|
3136
|
-
return Selector.handlers.byClassName(nodes, root, className);
|
3137
|
-
},
|
3138
|
-
|
3139
|
-
byClassName: function(nodes, root, className) {
|
3140
|
-
if (!nodes) nodes = Selector.handlers.descendant([root]);
|
3141
|
-
var needle = ' ' + className + ' ';
|
3142
|
-
for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {
|
3143
|
-
nodeClassName = node.className;
|
3144
|
-
if (nodeClassName.length == 0) continue;
|
3145
|
-
if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))
|
3146
|
-
results.push(node);
|
3147
|
-
}
|
3148
|
-
return results;
|
3149
|
-
},
|
3150
|
-
|
3151
|
-
attrPresence: function(nodes, root, attr) {
|
3152
|
-
if (!nodes) nodes = root.getElementsByTagName("*");
|
3153
|
-
var results = [];
|
3154
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3155
|
-
if (Element.hasAttribute(node, attr)) results.push(node);
|
3156
|
-
return results;
|
3157
|
-
},
|
3158
|
-
|
3159
|
-
attr: function(nodes, root, attr, value, operator) {
|
3160
|
-
if (!nodes) nodes = root.getElementsByTagName("*");
|
3161
|
-
var handler = Selector.operators[operator], results = [];
|
3162
|
-
for (var i = 0, node; node = nodes[i]; i++) {
|
3163
|
-
var nodeValue = Element.readAttribute(node, attr);
|
3164
|
-
if (nodeValue === null) continue;
|
3165
|
-
if (handler(nodeValue, value)) results.push(node);
|
3166
|
-
}
|
3167
|
-
return results;
|
3168
|
-
},
|
3169
|
-
|
3170
|
-
pseudo: function(nodes, name, value, root, combinator) {
|
3171
|
-
if (nodes && combinator) nodes = this[combinator](nodes);
|
3172
|
-
if (!nodes) nodes = root.getElementsByTagName("*");
|
3173
|
-
return Selector.pseudos[name](nodes, value, root);
|
3174
|
-
}
|
3175
|
-
},
|
3176
|
-
|
3177
|
-
pseudos: {
|
3178
|
-
'first-child': function(nodes, value, root) {
|
3179
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3180
|
-
if (Selector.handlers.previousElementSibling(node)) continue;
|
3181
|
-
results.push(node);
|
3182
|
-
}
|
3183
|
-
return results;
|
3184
|
-
},
|
3185
|
-
'last-child': function(nodes, value, root) {
|
3186
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3187
|
-
if (Selector.handlers.nextElementSibling(node)) continue;
|
3188
|
-
results.push(node);
|
3189
|
-
}
|
3190
|
-
return results;
|
3191
|
-
},
|
3192
|
-
'only-child': function(nodes, value, root) {
|
3193
|
-
var h = Selector.handlers;
|
3194
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3195
|
-
if (!h.previousElementSibling(node) && !h.nextElementSibling(node))
|
3196
|
-
results.push(node);
|
3197
|
-
return results;
|
3198
|
-
},
|
3199
|
-
'nth-child': function(nodes, formula, root) {
|
3200
|
-
return Selector.pseudos.nth(nodes, formula, root);
|
3201
|
-
},
|
3202
|
-
'nth-last-child': function(nodes, formula, root) {
|
3203
|
-
return Selector.pseudos.nth(nodes, formula, root, true);
|
3204
|
-
},
|
3205
|
-
'nth-of-type': function(nodes, formula, root) {
|
3206
|
-
return Selector.pseudos.nth(nodes, formula, root, false, true);
|
3207
|
-
},
|
3208
|
-
'nth-last-of-type': function(nodes, formula, root) {
|
3209
|
-
return Selector.pseudos.nth(nodes, formula, root, true, true);
|
3210
|
-
},
|
3211
|
-
'first-of-type': function(nodes, formula, root) {
|
3212
|
-
return Selector.pseudos.nth(nodes, "1", root, false, true);
|
3213
|
-
},
|
3214
|
-
'last-of-type': function(nodes, formula, root) {
|
3215
|
-
return Selector.pseudos.nth(nodes, "1", root, true, true);
|
3216
|
-
},
|
3217
|
-
'only-of-type': function(nodes, formula, root) {
|
3218
|
-
var p = Selector.pseudos;
|
3219
|
-
return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);
|
3220
|
-
},
|
3221
|
-
|
3222
|
-
// handles the an+b logic
|
3223
|
-
getIndices: function(a, b, total) {
|
3224
|
-
if (a == 0) return b > 0 ? [b] : [];
|
3225
|
-
return $R(1, total).inject([], function(memo, i) {
|
3226
|
-
if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);
|
3227
|
-
return memo;
|
3228
|
-
});
|
3229
|
-
},
|
3230
|
-
|
3231
|
-
// handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type
|
3232
|
-
nth: function(nodes, formula, root, reverse, ofType) {
|
3233
|
-
if (nodes.length == 0) return [];
|
3234
|
-
if (formula == 'even') formula = '2n+0';
|
3235
|
-
if (formula == 'odd') formula = '2n+1';
|
3236
|
-
var h = Selector.handlers, results = [], indexed = [], m;
|
3237
|
-
h.mark(nodes);
|
3238
|
-
for (var i = 0, node; node = nodes[i]; i++) {
|
3239
|
-
if (!node.parentNode._counted) {
|
3240
|
-
h.index(node.parentNode, reverse, ofType);
|
3241
|
-
indexed.push(node.parentNode);
|
3242
|
-
}
|
3243
|
-
}
|
3244
|
-
if (formula.match(/^\d+$/)) { // just a number
|
3245
|
-
formula = Number(formula);
|
3246
|
-
for (var i = 0, node; node = nodes[i]; i++)
|
3247
|
-
if (node.nodeIndex == formula) results.push(node);
|
3248
|
-
} else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
|
3249
|
-
if (m[1] == "-") m[1] = -1;
|
3250
|
-
var a = m[1] ? Number(m[1]) : 1;
|
3251
|
-
var b = m[2] ? Number(m[2]) : 0;
|
3252
|
-
var indices = Selector.pseudos.getIndices(a, b, nodes.length);
|
3253
|
-
for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {
|
3254
|
-
for (var j = 0; j < l; j++)
|
3255
|
-
if (node.nodeIndex == indices[j]) results.push(node);
|
3256
|
-
}
|
3257
|
-
}
|
3258
|
-
h.unmark(nodes);
|
3259
|
-
h.unmark(indexed);
|
3260
|
-
return results;
|
3261
|
-
},
|
3262
|
-
|
3263
|
-
'empty': function(nodes, value, root) {
|
3264
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3265
|
-
// IE treats comments as element nodes
|
3266
|
-
if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue;
|
3267
|
-
results.push(node);
|
3268
|
-
}
|
3269
|
-
return results;
|
3270
|
-
},
|
3271
|
-
|
3272
|
-
'not': function(nodes, selector, root) {
|
3273
|
-
var h = Selector.handlers, selectorType, m;
|
3274
|
-
var exclusions = new Selector(selector).findElements(root);
|
3275
|
-
h.mark(exclusions);
|
3276
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3277
|
-
if (!node._counted) results.push(node);
|
3278
|
-
h.unmark(exclusions);
|
3279
|
-
return results;
|
3280
|
-
},
|
3281
|
-
|
3282
|
-
'enabled': function(nodes, value, root) {
|
3283
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3284
|
-
if (!node.disabled) results.push(node);
|
3285
|
-
return results;
|
3286
|
-
},
|
3287
|
-
|
3288
|
-
'disabled': function(nodes, value, root) {
|
3289
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3290
|
-
if (node.disabled) results.push(node);
|
3291
|
-
return results;
|
3292
|
-
},
|
3293
|
-
|
3294
|
-
'checked': function(nodes, value, root) {
|
3295
|
-
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3296
|
-
if (node.checked) results.push(node);
|
3297
|
-
return results;
|
3298
|
-
}
|
3299
|
-
},
|
3300
|
-
|
3301
|
-
operators: {
|
3302
|
-
'=': function(nv, v) { return nv == v; },
|
3303
|
-
'!=': function(nv, v) { return nv != v; },
|
3304
|
-
'^=': function(nv, v) { return nv.startsWith(v); },
|
3305
|
-
'$=': function(nv, v) { return nv.endsWith(v); },
|
3306
|
-
'*=': function(nv, v) { return nv.include(v); },
|
3307
|
-
'~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
|
3308
|
-
'|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
|
3309
|
-
},
|
3310
|
-
|
3311
|
-
matchElements: function(elements, expression) {
|
3312
|
-
var matches = new Selector(expression).findElements(), h = Selector.handlers;
|
3313
|
-
h.mark(matches);
|
3314
|
-
for (var i = 0, results = [], element; element = elements[i]; i++)
|
3315
|
-
if (element._counted) results.push(element);
|
3316
|
-
h.unmark(matches);
|
3317
|
-
return results;
|
3318
|
-
},
|
3319
|
-
|
3320
|
-
findElement: function(elements, expression, index) {
|
3321
|
-
if (Object.isNumber(expression)) {
|
3322
|
-
index = expression; expression = false;
|
3323
|
-
}
|
3324
|
-
return Selector.matchElements(elements, expression || '*')[index || 0];
|
3325
|
-
},
|
3326
|
-
|
3327
|
-
findChildElements: function(element, expressions) {
|
3328
|
-
var exprs = expressions.join(','), expressions = [];
|
3329
|
-
exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
|
3330
|
-
expressions.push(m[1].strip());
|
3331
|
-
});
|
3332
|
-
var results = [], h = Selector.handlers;
|
3333
|
-
for (var i = 0, l = expressions.length, selector; i < l; i++) {
|
3334
|
-
selector = new Selector(expressions[i].strip());
|
3335
|
-
h.concat(results, selector.findElements(element));
|
3336
|
-
}
|
3337
|
-
return (l > 1) ? h.unique(results) : results;
|
3338
|
-
}
|
3339
|
-
});
|
3340
|
-
|
3341
|
-
function $$() {
|
3342
|
-
return Selector.findChildElements(document, $A(arguments));
|
3343
|
-
}
|
3344
|
-
var Form = {
|
3345
|
-
reset: function(form) {
|
3346
|
-
$(form).reset();
|
3347
|
-
return form;
|
3348
|
-
},
|
3349
|
-
|
3350
|
-
serializeElements: function(elements, options) {
|
3351
|
-
if (typeof options != 'object') options = { hash: !!options };
|
3352
|
-
else if (options.hash === undefined) options.hash = true;
|
3353
|
-
var key, value, submitted = false, submit = options.submit;
|
3354
|
-
|
3355
|
-
var data = elements.inject({ }, function(result, element) {
|
3356
|
-
if (!element.disabled && element.name) {
|
3357
|
-
key = element.name; value = $(element).getValue();
|
3358
|
-
if (value != null && (element.type != 'submit' || (!submitted &&
|
3359
|
-
submit !== false && (!submit || key == submit) && (submitted = true)))) {
|
3360
|
-
if (key in result) {
|
3361
|
-
// a key is already present; construct an array of values
|
3362
|
-
if (!Object.isArray(result[key])) result[key] = [result[key]];
|
3363
|
-
result[key].push(value);
|
3364
|
-
}
|
3365
|
-
else result[key] = value;
|
3366
|
-
}
|
3367
|
-
}
|
3368
|
-
return result;
|
3369
|
-
});
|
3370
|
-
|
3371
|
-
return options.hash ? data : Object.toQueryString(data);
|
3372
|
-
}
|
3373
|
-
};
|
3374
|
-
|
3375
|
-
Form.Methods = {
|
3376
|
-
serialize: function(form, options) {
|
3377
|
-
return Form.serializeElements(Form.getElements(form), options);
|
3378
|
-
},
|
3379
|
-
|
3380
|
-
getElements: function(form) {
|
3381
|
-
return $A($(form).getElementsByTagName('*')).inject([],
|
3382
|
-
function(elements, child) {
|
3383
|
-
if (Form.Element.Serializers[child.tagName.toLowerCase()])
|
3384
|
-
elements.push(Element.extend(child));
|
3385
|
-
return elements;
|
3386
|
-
}
|
3387
|
-
);
|
3388
|
-
},
|
3389
|
-
|
3390
|
-
getInputs: function(form, typeName, name) {
|
3391
|
-
form = $(form);
|
3392
|
-
var inputs = form.getElementsByTagName('input');
|
3393
|
-
|
3394
|
-
if (!typeName && !name) return $A(inputs).map(Element.extend);
|
3395
|
-
|
3396
|
-
for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
|
3397
|
-
var input = inputs[i];
|
3398
|
-
if ((typeName && input.type != typeName) || (name && input.name != name))
|
3399
|
-
continue;
|
3400
|
-
matchingInputs.push(Element.extend(input));
|
3401
|
-
}
|
3402
|
-
|
3403
|
-
return matchingInputs;
|
3404
|
-
},
|
3405
|
-
|
3406
|
-
disable: function(form) {
|
3407
|
-
form = $(form);
|
3408
|
-
Form.getElements(form).invoke('disable');
|
3409
|
-
return form;
|
3410
|
-
},
|
3411
|
-
|
3412
|
-
enable: function(form) {
|
3413
|
-
form = $(form);
|
3414
|
-
Form.getElements(form).invoke('enable');
|
3415
|
-
return form;
|
3416
|
-
},
|
3417
|
-
|
3418
|
-
findFirstElement: function(form) {
|
3419
|
-
var elements = $(form).getElements().findAll(function(element) {
|
3420
|
-
return 'hidden' != element.type && !element.disabled;
|
3421
|
-
});
|
3422
|
-
var firstByIndex = elements.findAll(function(element) {
|
3423
|
-
return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
|
3424
|
-
}).sortBy(function(element) { return element.tabIndex }).first();
|
3425
|
-
|
3426
|
-
return firstByIndex ? firstByIndex : elements.find(function(element) {
|
3427
|
-
return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
|
3428
|
-
});
|
3429
|
-
},
|
3430
|
-
|
3431
|
-
focusFirstElement: function(form) {
|
3432
|
-
form = $(form);
|
3433
|
-
form.findFirstElement().activate();
|
3434
|
-
return form;
|
3435
|
-
},
|
3436
|
-
|
3437
|
-
request: function(form, options) {
|
3438
|
-
form = $(form), options = Object.clone(options || { });
|
3439
|
-
|
3440
|
-
var params = options.parameters, action = form.readAttribute('action') || '';
|
3441
|
-
if (action.blank()) action = window.location.href;
|
3442
|
-
options.parameters = form.serialize(true);
|
3443
|
-
|
3444
|
-
if (params) {
|
3445
|
-
if (Object.isString(params)) params = params.toQueryParams();
|
3446
|
-
Object.extend(options.parameters, params);
|
3447
|
-
}
|
3448
|
-
|
3449
|
-
if (form.hasAttribute('method') && !options.method)
|
3450
|
-
options.method = form.method;
|
3451
|
-
|
3452
|
-
return new Ajax.Request(action, options);
|
3453
|
-
}
|
3454
|
-
};
|
3455
|
-
|
3456
|
-
/*--------------------------------------------------------------------------*/
|
3457
|
-
|
3458
|
-
Form.Element = {
|
3459
|
-
focus: function(element) {
|
3460
|
-
$(element).focus();
|
3461
|
-
return element;
|
3462
|
-
},
|
3463
|
-
|
3464
|
-
select: function(element) {
|
3465
|
-
$(element).select();
|
3466
|
-
return element;
|
3467
|
-
}
|
3468
|
-
};
|
3469
|
-
|
3470
|
-
Form.Element.Methods = {
|
3471
|
-
serialize: function(element) {
|
3472
|
-
element = $(element);
|
3473
|
-
if (!element.disabled && element.name) {
|
3474
|
-
var value = element.getValue();
|
3475
|
-
if (value != undefined) {
|
3476
|
-
var pair = { };
|
3477
|
-
pair[element.name] = value;
|
3478
|
-
return Object.toQueryString(pair);
|
3479
|
-
}
|
3480
|
-
}
|
3481
|
-
return '';
|
3482
|
-
},
|
3483
|
-
|
3484
|
-
getValue: function(element) {
|
3485
|
-
element = $(element);
|
3486
|
-
var method = element.tagName.toLowerCase();
|
3487
|
-
return Form.Element.Serializers[method](element);
|
3488
|
-
},
|
3489
|
-
|
3490
|
-
setValue: function(element, value) {
|
3491
|
-
element = $(element);
|
3492
|
-
var method = element.tagName.toLowerCase();
|
3493
|
-
Form.Element.Serializers[method](element, value);
|
3494
|
-
return element;
|
3495
|
-
},
|
3496
|
-
|
3497
|
-
clear: function(element) {
|
3498
|
-
$(element).value = '';
|
3499
|
-
return element;
|
3500
|
-
},
|
3501
|
-
|
3502
|
-
present: function(element) {
|
3503
|
-
return $(element).value != '';
|
3504
|
-
},
|
3505
|
-
|
3506
|
-
activate: function(element) {
|
3507
|
-
element = $(element);
|
3508
|
-
try {
|
3509
|
-
element.focus();
|
3510
|
-
if (element.select && (element.tagName.toLowerCase() != 'input' ||
|
3511
|
-
!['button', 'reset', 'submit'].include(element.type)))
|
3512
|
-
element.select();
|
3513
|
-
} catch (e) { }
|
3514
|
-
return element;
|
3515
|
-
},
|
3516
|
-
|
3517
|
-
disable: function(element) {
|
3518
|
-
element = $(element);
|
3519
|
-
element.blur();
|
3520
|
-
element.disabled = true;
|
3521
|
-
return element;
|
3522
|
-
},
|
3523
|
-
|
3524
|
-
enable: function(element) {
|
3525
|
-
element = $(element);
|
3526
|
-
element.disabled = false;
|
3527
|
-
return element;
|
3528
|
-
}
|
3529
|
-
};
|
3530
|
-
|
3531
|
-
/*--------------------------------------------------------------------------*/
|
3532
|
-
|
3533
|
-
var Field = Form.Element;
|
3534
|
-
var $F = Form.Element.Methods.getValue;
|
3535
|
-
|
3536
|
-
/*--------------------------------------------------------------------------*/
|
3537
|
-
|
3538
|
-
Form.Element.Serializers = {
|
3539
|
-
input: function(element, value) {
|
3540
|
-
switch (element.type.toLowerCase()) {
|
3541
|
-
case 'checkbox':
|
3542
|
-
case 'radio':
|
3543
|
-
return Form.Element.Serializers.inputSelector(element, value);
|
3544
|
-
default:
|
3545
|
-
return Form.Element.Serializers.textarea(element, value);
|
3546
|
-
}
|
3547
|
-
},
|
3548
|
-
|
3549
|
-
inputSelector: function(element, value) {
|
3550
|
-
if (value === undefined) return element.checked ? element.value : null;
|
3551
|
-
else element.checked = !!value;
|
3552
|
-
},
|
3553
|
-
|
3554
|
-
textarea: function(element, value) {
|
3555
|
-
if (value === undefined) return element.value;
|
3556
|
-
else element.value = value;
|
3557
|
-
},
|
3558
|
-
|
3559
|
-
select: function(element, index) {
|
3560
|
-
if (index === undefined)
|
3561
|
-
return this[element.type == 'select-one' ?
|
3562
|
-
'selectOne' : 'selectMany'](element);
|
3563
|
-
else {
|
3564
|
-
var opt, value, single = !Object.isArray(index);
|
3565
|
-
for (var i = 0, length = element.length; i < length; i++) {
|
3566
|
-
opt = element.options[i];
|
3567
|
-
value = this.optionValue(opt);
|
3568
|
-
if (single) {
|
3569
|
-
if (value == index) {
|
3570
|
-
opt.selected = true;
|
3571
|
-
return;
|
3572
|
-
}
|
3573
|
-
}
|
3574
|
-
else opt.selected = index.include(value);
|
3575
|
-
}
|
3576
|
-
}
|
3577
|
-
},
|
3578
|
-
|
3579
|
-
selectOne: function(element) {
|
3580
|
-
var index = element.selectedIndex;
|
3581
|
-
return index >= 0 ? this.optionValue(element.options[index]) : null;
|
3582
|
-
},
|
3583
|
-
|
3584
|
-
selectMany: function(element) {
|
3585
|
-
var values, length = element.length;
|
3586
|
-
if (!length) return null;
|
3587
|
-
|
3588
|
-
for (var i = 0, values = []; i < length; i++) {
|
3589
|
-
var opt = element.options[i];
|
3590
|
-
if (opt.selected) values.push(this.optionValue(opt));
|
3591
|
-
}
|
3592
|
-
return values;
|
3593
|
-
},
|
3594
|
-
|
3595
|
-
optionValue: function(opt) {
|
3596
|
-
// extend element because hasAttribute may not be native
|
3597
|
-
return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
|
3598
|
-
}
|
3599
|
-
};
|
3600
|
-
|
3601
|
-
/*--------------------------------------------------------------------------*/
|
3602
|
-
|
3603
|
-
Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
|
3604
|
-
initialize: function($super, element, frequency, callback) {
|
3605
|
-
$super(callback, frequency);
|
3606
|
-
this.element = $(element);
|
3607
|
-
this.lastValue = this.getValue();
|
3608
|
-
},
|
3609
|
-
|
3610
|
-
execute: function() {
|
3611
|
-
var value = this.getValue();
|
3612
|
-
if (Object.isString(this.lastValue) && Object.isString(value) ?
|
3613
|
-
this.lastValue != value : String(this.lastValue) != String(value)) {
|
3614
|
-
this.callback(this.element, value);
|
3615
|
-
this.lastValue = value;
|
3616
|
-
}
|
3617
|
-
}
|
3618
|
-
});
|
3619
|
-
|
3620
|
-
Form.Element.Observer = Class.create(Abstract.TimedObserver, {
|
3621
|
-
getValue: function() {
|
3622
|
-
return Form.Element.getValue(this.element);
|
3623
|
-
}
|
3624
|
-
});
|
3625
|
-
|
3626
|
-
Form.Observer = Class.create(Abstract.TimedObserver, {
|
3627
|
-
getValue: function() {
|
3628
|
-
return Form.serialize(this.element);
|
3629
|
-
}
|
3630
|
-
});
|
3631
|
-
|
3632
|
-
/*--------------------------------------------------------------------------*/
|
3633
|
-
|
3634
|
-
Abstract.EventObserver = Class.create({
|
3635
|
-
initialize: function(element, callback) {
|
3636
|
-
this.element = $(element);
|
3637
|
-
this.callback = callback;
|
3638
|
-
|
3639
|
-
this.lastValue = this.getValue();
|
3640
|
-
if (this.element.tagName.toLowerCase() == 'form')
|
3641
|
-
this.registerFormCallbacks();
|
3642
|
-
else
|
3643
|
-
this.registerCallback(this.element);
|
3644
|
-
},
|
3645
|
-
|
3646
|
-
onElementEvent: function() {
|
3647
|
-
var value = this.getValue();
|
3648
|
-
if (this.lastValue != value) {
|
3649
|
-
this.callback(this.element, value);
|
3650
|
-
this.lastValue = value;
|
3651
|
-
}
|
3652
|
-
},
|
3653
|
-
|
3654
|
-
registerFormCallbacks: function() {
|
3655
|
-
Form.getElements(this.element).each(this.registerCallback, this);
|
3656
|
-
},
|
3657
|
-
|
3658
|
-
registerCallback: function(element) {
|
3659
|
-
if (element.type) {
|
3660
|
-
switch (element.type.toLowerCase()) {
|
3661
|
-
case 'checkbox':
|
3662
|
-
case 'radio':
|
3663
|
-
Event.observe(element, 'click', this.onElementEvent.bind(this));
|
3664
|
-
break;
|
3665
|
-
default:
|
3666
|
-
Event.observe(element, 'change', this.onElementEvent.bind(this));
|
3667
|
-
break;
|
3668
|
-
}
|
3669
|
-
}
|
3670
|
-
}
|
3671
|
-
});
|
3672
|
-
|
3673
|
-
Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
|
3674
|
-
getValue: function() {
|
3675
|
-
return Form.Element.getValue(this.element);
|
3676
|
-
}
|
3677
|
-
});
|
3678
|
-
|
3679
|
-
Form.EventObserver = Class.create(Abstract.EventObserver, {
|
3680
|
-
getValue: function() {
|
3681
|
-
return Form.serialize(this.element);
|
3682
|
-
}
|
3683
|
-
});
|
3684
|
-
if (!window.Event) var Event = { };
|
3685
|
-
|
3686
|
-
Object.extend(Event, {
|
3687
|
-
KEY_BACKSPACE: 8,
|
3688
|
-
KEY_TAB: 9,
|
3689
|
-
KEY_RETURN: 13,
|
3690
|
-
KEY_ESC: 27,
|
3691
|
-
KEY_LEFT: 37,
|
3692
|
-
KEY_UP: 38,
|
3693
|
-
KEY_RIGHT: 39,
|
3694
|
-
KEY_DOWN: 40,
|
3695
|
-
KEY_DELETE: 46,
|
3696
|
-
KEY_HOME: 36,
|
3697
|
-
KEY_END: 35,
|
3698
|
-
KEY_PAGEUP: 33,
|
3699
|
-
KEY_PAGEDOWN: 34,
|
3700
|
-
KEY_INSERT: 45,
|
3701
|
-
|
3702
|
-
cache: { },
|
3703
|
-
|
3704
|
-
relatedTarget: function(event) {
|
3705
|
-
var element;
|
3706
|
-
switch(event.type) {
|
3707
|
-
case 'mouseover': element = event.fromElement; break;
|
3708
|
-
case 'mouseout': element = event.toElement; break;
|
3709
|
-
default: return null;
|
3710
|
-
}
|
3711
|
-
return Element.extend(element);
|
3712
|
-
}
|
3713
|
-
});
|
3714
|
-
|
3715
|
-
Event.Methods = (function() {
|
3716
|
-
var isButton;
|
3717
|
-
|
3718
|
-
if (Prototype.Browser.IE) {
|
3719
|
-
var buttonMap = { 0: 1, 1: 4, 2: 2 };
|
3720
|
-
isButton = function(event, code) {
|
3721
|
-
return event.button == buttonMap[code];
|
3722
|
-
};
|
3723
|
-
|
3724
|
-
} else if (Prototype.Browser.WebKit) {
|
3725
|
-
isButton = function(event, code) {
|
3726
|
-
switch (code) {
|
3727
|
-
case 0: return event.which == 1 && !event.metaKey;
|
3728
|
-
case 1: return event.which == 1 && event.metaKey;
|
3729
|
-
default: return false;
|
3730
|
-
}
|
3731
|
-
};
|
3732
|
-
|
3733
|
-
} else {
|
3734
|
-
isButton = function(event, code) {
|
3735
|
-
return event.which ? (event.which === code + 1) : (event.button === code);
|
3736
|
-
};
|
3737
|
-
}
|
3738
|
-
|
3739
|
-
return {
|
3740
|
-
isLeftClick: function(event) { return isButton(event, 0) },
|
3741
|
-
isMiddleClick: function(event) { return isButton(event, 1) },
|
3742
|
-
isRightClick: function(event) { return isButton(event, 2) },
|
3743
|
-
|
3744
|
-
element: function(event) {
|
3745
|
-
var node = Event.extend(event).target;
|
3746
|
-
return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);
|
3747
|
-
},
|
3748
|
-
|
3749
|
-
findElement: function(event, expression) {
|
3750
|
-
var element = Event.element(event);
|
3751
|
-
return element.match(expression) ? element : element.up(expression);
|
3752
|
-
},
|
3753
|
-
|
3754
|
-
pointer: function(event) {
|
3755
|
-
return {
|
3756
|
-
x: event.pageX || (event.clientX +
|
3757
|
-
(document.documentElement.scrollLeft || document.body.scrollLeft)),
|
3758
|
-
y: event.pageY || (event.clientY +
|
3759
|
-
(document.documentElement.scrollTop || document.body.scrollTop))
|
3760
|
-
};
|
3761
|
-
},
|
3762
|
-
|
3763
|
-
pointerX: function(event) { return Event.pointer(event).x },
|
3764
|
-
pointerY: function(event) { return Event.pointer(event).y },
|
3765
|
-
|
3766
|
-
stop: function(event) {
|
3767
|
-
Event.extend(event);
|
3768
|
-
event.preventDefault();
|
3769
|
-
event.stopPropagation();
|
3770
|
-
event.stopped = true;
|
3771
|
-
}
|
3772
|
-
};
|
3773
|
-
})();
|
3774
|
-
|
3775
|
-
Event.extend = (function() {
|
3776
|
-
var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
|
3777
|
-
m[name] = Event.Methods[name].methodize();
|
3778
|
-
return m;
|
3779
|
-
});
|
3780
|
-
|
3781
|
-
if (Prototype.Browser.IE) {
|
3782
|
-
Object.extend(methods, {
|
3783
|
-
stopPropagation: function() { this.cancelBubble = true },
|
3784
|
-
preventDefault: function() { this.returnValue = false },
|
3785
|
-
inspect: function() { return "[object Event]" }
|
3786
|
-
});
|
3787
|
-
|
3788
|
-
return function(event) {
|
3789
|
-
if (!event) return false;
|
3790
|
-
if (event._extendedByPrototype) return event;
|
3791
|
-
|
3792
|
-
event._extendedByPrototype = Prototype.emptyFunction;
|
3793
|
-
var pointer = Event.pointer(event);
|
3794
|
-
Object.extend(event, {
|
3795
|
-
target: event.srcElement,
|
3796
|
-
relatedTarget: Event.relatedTarget(event),
|
3797
|
-
pageX: pointer.x,
|
3798
|
-
pageY: pointer.y
|
3799
|
-
});
|
3800
|
-
return Object.extend(event, methods);
|
3801
|
-
};
|
3802
|
-
|
3803
|
-
} else {
|
3804
|
-
Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__;
|
3805
|
-
Object.extend(Event.prototype, methods);
|
3806
|
-
return Prototype.K;
|
3807
|
-
}
|
3808
|
-
})();
|
3809
|
-
|
3810
|
-
Object.extend(Event, (function() {
|
3811
|
-
var cache = Event.cache;
|
3812
|
-
|
3813
|
-
function getEventID(element) {
|
3814
|
-
if (element._eventID) return element._eventID;
|
3815
|
-
arguments.callee.id = arguments.callee.id || 1;
|
3816
|
-
return element._eventID = ++arguments.callee.id;
|
3817
|
-
}
|
3818
|
-
|
3819
|
-
function getDOMEventName(eventName) {
|
3820
|
-
if (eventName && eventName.include(':')) return "dataavailable";
|
3821
|
-
return eventName;
|
3822
|
-
}
|
3823
|
-
|
3824
|
-
function getCacheForID(id) {
|
3825
|
-
return cache[id] = cache[id] || { };
|
3826
|
-
}
|
3827
|
-
|
3828
|
-
function getWrappersForEventName(id, eventName) {
|
3829
|
-
var c = getCacheForID(id);
|
3830
|
-
return c[eventName] = c[eventName] || [];
|
3831
|
-
}
|
3832
|
-
|
3833
|
-
function createWrapper(element, eventName, handler) {
|
3834
|
-
var id = getEventID(element);
|
3835
|
-
var c = getWrappersForEventName(id, eventName);
|
3836
|
-
if (c.pluck("handler").include(handler)) return false;
|
3837
|
-
|
3838
|
-
var wrapper = function(event) {
|
3839
|
-
if (!Event || !Event.extend ||
|
3840
|
-
(event.eventName && event.eventName != eventName))
|
3841
|
-
return false;
|
3842
|
-
|
3843
|
-
Event.extend(event);
|
3844
|
-
handler.call(element, event)
|
3845
|
-
};
|
3846
|
-
|
3847
|
-
wrapper.handler = handler;
|
3848
|
-
c.push(wrapper);
|
3849
|
-
return wrapper;
|
3850
|
-
}
|
3851
|
-
|
3852
|
-
function findWrapper(id, eventName, handler) {
|
3853
|
-
var c = getWrappersForEventName(id, eventName);
|
3854
|
-
return c.find(function(wrapper) { return wrapper.handler == handler });
|
3855
|
-
}
|
3856
|
-
|
3857
|
-
function destroyWrapper(id, eventName, handler) {
|
3858
|
-
var c = getCacheForID(id);
|
3859
|
-
if (!c[eventName]) return false;
|
3860
|
-
c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));
|
3861
|
-
}
|
3862
|
-
|
3863
|
-
function destroyCache() {
|
3864
|
-
for (var id in cache)
|
3865
|
-
for (var eventName in cache[id])
|
3866
|
-
cache[id][eventName] = null;
|
3867
|
-
}
|
3868
|
-
|
3869
|
-
if (window.attachEvent) {
|
3870
|
-
window.attachEvent("onunload", destroyCache);
|
3871
|
-
}
|
3872
|
-
|
3873
|
-
return {
|
3874
|
-
observe: function(element, eventName, handler) {
|
3875
|
-
element = $(element);
|
3876
|
-
var name = getDOMEventName(eventName);
|
3877
|
-
|
3878
|
-
var wrapper = createWrapper(element, eventName, handler);
|
3879
|
-
if (!wrapper) return element;
|
3880
|
-
|
3881
|
-
if (element.addEventListener) {
|
3882
|
-
element.addEventListener(name, wrapper, false);
|
3883
|
-
} else {
|
3884
|
-
element.attachEvent("on" + name, wrapper);
|
3885
|
-
}
|
3886
|
-
|
3887
|
-
return element;
|
3888
|
-
},
|
3889
|
-
|
3890
|
-
stopObserving: function(element, eventName, handler) {
|
3891
|
-
element = $(element);
|
3892
|
-
var id = getEventID(element), name = getDOMEventName(eventName);
|
3893
|
-
|
3894
|
-
if (!handler && eventName) {
|
3895
|
-
getWrappersForEventName(id, eventName).each(function(wrapper) {
|
3896
|
-
element.stopObserving(eventName, wrapper.handler);
|
3897
|
-
});
|
3898
|
-
return element;
|
3899
|
-
|
3900
|
-
} else if (!eventName) {
|
3901
|
-
Object.keys(getCacheForID(id)).each(function(eventName) {
|
3902
|
-
element.stopObserving(eventName);
|
3903
|
-
});
|
3904
|
-
return element;
|
3905
|
-
}
|
3906
|
-
|
3907
|
-
var wrapper = findWrapper(id, eventName, handler);
|
3908
|
-
if (!wrapper) return element;
|
3909
|
-
|
3910
|
-
if (element.removeEventListener) {
|
3911
|
-
element.removeEventListener(name, wrapper, false);
|
3912
|
-
} else {
|
3913
|
-
element.detachEvent("on" + name, wrapper);
|
3914
|
-
}
|
3915
|
-
|
3916
|
-
destroyWrapper(id, eventName, handler);
|
3917
|
-
|
3918
|
-
return element;
|
3919
|
-
},
|
3920
|
-
|
3921
|
-
fire: function(element, eventName, memo) {
|
3922
|
-
element = $(element);
|
3923
|
-
if (element == document && document.createEvent && !element.dispatchEvent)
|
3924
|
-
element = document.documentElement;
|
3925
|
-
|
3926
|
-
if (document.createEvent) {
|
3927
|
-
var event = document.createEvent("HTMLEvents");
|
3928
|
-
event.initEvent("dataavailable", true, true);
|
3929
|
-
} else {
|
3930
|
-
var event = document.createEventObject();
|
3931
|
-
event.eventType = "ondataavailable";
|
3932
|
-
}
|
3933
|
-
|
3934
|
-
event.eventName = eventName;
|
3935
|
-
event.memo = memo || { };
|
3936
|
-
|
3937
|
-
if (document.createEvent) {
|
3938
|
-
element.dispatchEvent(event);
|
3939
|
-
} else {
|
3940
|
-
element.fireEvent(event.eventType, event);
|
3941
|
-
}
|
3942
|
-
|
3943
|
-
return event;
|
3944
|
-
}
|
3945
|
-
};
|
3946
|
-
})());
|
3947
|
-
|
3948
|
-
Object.extend(Event, Event.Methods);
|
3949
|
-
|
3950
|
-
Element.addMethods({
|
3951
|
-
fire: Event.fire,
|
3952
|
-
observe: Event.observe,
|
3953
|
-
stopObserving: Event.stopObserving
|
3954
|
-
});
|
3955
|
-
|
3956
|
-
Object.extend(document, {
|
3957
|
-
fire: Element.Methods.fire.methodize(),
|
3958
|
-
observe: Element.Methods.observe.methodize(),
|
3959
|
-
stopObserving: Element.Methods.stopObserving.methodize()
|
3960
|
-
});
|
3961
|
-
|
3962
|
-
(function() {
|
3963
|
-
/* Support for the DOMContentLoaded event is based on work by Dan Webb,
|
3964
|
-
Matthias Miller, Dean Edwards and John Resig. */
|
3965
|
-
|
3966
|
-
var timer, fired = false;
|
3967
|
-
|
3968
|
-
function fireContentLoadedEvent() {
|
3969
|
-
if (fired) return;
|
3970
|
-
if (timer) window.clearInterval(timer);
|
3971
|
-
document.fire("dom:loaded");
|
3972
|
-
fired = true;
|
3973
|
-
}
|
3974
|
-
|
3975
|
-
if (document.addEventListener) {
|
3976
|
-
if (Prototype.Browser.WebKit) {
|
3977
|
-
timer = window.setInterval(function() {
|
3978
|
-
if (/loaded|complete/.test(document.readyState))
|
3979
|
-
fireContentLoadedEvent();
|
3980
|
-
}, 0);
|
3981
|
-
|
3982
|
-
Event.observe(window, "load", fireContentLoadedEvent);
|
3983
|
-
|
3984
|
-
} else {
|
3985
|
-
document.addEventListener("DOMContentLoaded",
|
3986
|
-
fireContentLoadedEvent, false);
|
3987
|
-
}
|
3988
|
-
|
3989
|
-
} else {
|
3990
|
-
document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
|
3991
|
-
$("__onDOMContentLoaded").onreadystatechange = function() {
|
3992
|
-
if (this.readyState == "complete") {
|
3993
|
-
this.onreadystatechange = null;
|
3994
|
-
fireContentLoadedEvent();
|
3995
|
-
}
|
3996
|
-
};
|
3997
|
-
}
|
3998
|
-
})();
|
3999
|
-
/*------------------------------- DEPRECATED -------------------------------*/
|
4000
|
-
|
4001
|
-
Hash.toQueryString = Object.toQueryString;
|
4002
|
-
|
4003
|
-
var Toggle = { display: Element.toggle };
|
4004
|
-
|
4005
|
-
Element.Methods.childOf = Element.Methods.descendantOf;
|
4006
|
-
|
4007
|
-
var Insertion = {
|
4008
|
-
Before: function(element, content) {
|
4009
|
-
return Element.insert(element, {before:content});
|
4010
|
-
},
|
4011
|
-
|
4012
|
-
Top: function(element, content) {
|
4013
|
-
return Element.insert(element, {top:content});
|
4014
|
-
},
|
4015
|
-
|
4016
|
-
Bottom: function(element, content) {
|
4017
|
-
return Element.insert(element, {bottom:content});
|
4018
|
-
},
|
4019
|
-
|
4020
|
-
After: function(element, content) {
|
4021
|
-
return Element.insert(element, {after:content});
|
4022
|
-
}
|
4023
|
-
};
|
4024
|
-
|
4025
|
-
var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
|
4026
|
-
|
4027
|
-
// This should be moved to script.aculo.us; notice the deprecated methods
|
4028
|
-
// further below, that map to the newer Element methods.
|
4029
|
-
var Position = {
|
4030
|
-
// set to true if needed, warning: firefox performance problems
|
4031
|
-
// NOT neeeded for page scrolling, only if draggable contained in
|
4032
|
-
// scrollable elements
|
4033
|
-
includeScrollOffsets: false,
|
4034
|
-
|
4035
|
-
// must be called before calling withinIncludingScrolloffset, every time the
|
4036
|
-
// page is scrolled
|
4037
|
-
prepare: function() {
|
4038
|
-
this.deltaX = window.pageXOffset
|
4039
|
-
|| document.documentElement.scrollLeft
|
4040
|
-
|| document.body.scrollLeft
|
4041
|
-
|| 0;
|
4042
|
-
this.deltaY = window.pageYOffset
|
4043
|
-
|| document.documentElement.scrollTop
|
4044
|
-
|| document.body.scrollTop
|
4045
|
-
|| 0;
|
4046
|
-
},
|
4047
|
-
|
4048
|
-
// caches x/y coordinate pair to use with overlap
|
4049
|
-
within: function(element, x, y) {
|
4050
|
-
if (this.includeScrollOffsets)
|
4051
|
-
return this.withinIncludingScrolloffsets(element, x, y);
|
4052
|
-
this.xcomp = x;
|
4053
|
-
this.ycomp = y;
|
4054
|
-
this.offset = Element.cumulativeOffset(element);
|
4055
|
-
|
4056
|
-
return (y >= this.offset[1] &&
|
4057
|
-
y < this.offset[1] + element.offsetHeight &&
|
4058
|
-
x >= this.offset[0] &&
|
4059
|
-
x < this.offset[0] + element.offsetWidth);
|
4060
|
-
},
|
4061
|
-
|
4062
|
-
withinIncludingScrolloffsets: function(element, x, y) {
|
4063
|
-
var offsetcache = Element.cumulativeScrollOffset(element);
|
4064
|
-
|
4065
|
-
this.xcomp = x + offsetcache[0] - this.deltaX;
|
4066
|
-
this.ycomp = y + offsetcache[1] - this.deltaY;
|
4067
|
-
this.offset = Element.cumulativeOffset(element);
|
4068
|
-
|
4069
|
-
return (this.ycomp >= this.offset[1] &&
|
4070
|
-
this.ycomp < this.offset[1] + element.offsetHeight &&
|
4071
|
-
this.xcomp >= this.offset[0] &&
|
4072
|
-
this.xcomp < this.offset[0] + element.offsetWidth);
|
4073
|
-
},
|
4074
|
-
|
4075
|
-
// within must be called directly before
|
4076
|
-
overlap: function(mode, element) {
|
4077
|
-
if (!mode) return 0;
|
4078
|
-
if (mode == 'vertical')
|
4079
|
-
return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
|
4080
|
-
element.offsetHeight;
|
4081
|
-
if (mode == 'horizontal')
|
4082
|
-
return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
|
4083
|
-
element.offsetWidth;
|
4084
|
-
},
|
4085
|
-
|
4086
|
-
// Deprecation layer -- use newer Element methods now (1.5.2).
|
4087
|
-
|
4088
|
-
cumulativeOffset: Element.Methods.cumulativeOffset,
|
4089
|
-
|
4090
|
-
positionedOffset: Element.Methods.positionedOffset,
|
4091
|
-
|
4092
|
-
absolutize: function(element) {
|
4093
|
-
Position.prepare();
|
4094
|
-
return Element.absolutize(element);
|
4095
|
-
},
|
4096
|
-
|
4097
|
-
relativize: function(element) {
|
4098
|
-
Position.prepare();
|
4099
|
-
return Element.relativize(element);
|
4100
|
-
},
|
4101
|
-
|
4102
|
-
realOffset: Element.Methods.cumulativeScrollOffset,
|
4103
|
-
|
4104
|
-
offsetParent: Element.Methods.getOffsetParent,
|
4105
|
-
|
4106
|
-
page: Element.Methods.viewportOffset,
|
4107
|
-
|
4108
|
-
clone: function(source, target, options) {
|
4109
|
-
options = options || { };
|
4110
|
-
return Element.clonePosition(target, source, options);
|
4111
|
-
}
|
4112
|
-
};
|
4113
|
-
|
4114
|
-
/*--------------------------------------------------------------------------*/
|
4115
|
-
|
4116
|
-
if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
|
4117
|
-
function iter(name) {
|
4118
|
-
return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
|
4119
|
-
}
|
4120
|
-
|
4121
|
-
instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
|
4122
|
-
function(element, className) {
|
4123
|
-
className = className.toString().strip();
|
4124
|
-
var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
|
4125
|
-
return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
|
4126
|
-
} : function(element, className) {
|
4127
|
-
className = className.toString().strip();
|
4128
|
-
var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
|
4129
|
-
if (!classNames && !className) return elements;
|
4130
|
-
|
4131
|
-
var nodes = $(element).getElementsByTagName('*');
|
4132
|
-
className = ' ' + className + ' ';
|
4133
|
-
|
4134
|
-
for (var i = 0, child, cn; child = nodes[i]; i++) {
|
4135
|
-
if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
|
4136
|
-
(classNames && classNames.all(function(name) {
|
4137
|
-
return !name.toString().blank() && cn.include(' ' + name + ' ');
|
4138
|
-
}))))
|
4139
|
-
elements.push(Element.extend(child));
|
4140
|
-
}
|
4141
|
-
return elements;
|
4142
|
-
};
|
4143
|
-
|
4144
|
-
return function(className, parentElement) {
|
4145
|
-
return $(parentElement || document.body).getElementsByClassName(className);
|
4146
|
-
};
|
4147
|
-
}(Element.Methods);
|
4148
|
-
|
4149
|
-
/*--------------------------------------------------------------------------*/
|
4150
|
-
|
4151
|
-
Element.ClassNames = Class.create();
|
4152
|
-
Element.ClassNames.prototype = {
|
4153
|
-
initialize: function(element) {
|
4154
|
-
this.element = $(element);
|
4155
|
-
},
|
4156
|
-
|
4157
|
-
_each: function(iterator) {
|
4158
|
-
this.element.className.split(/\s+/).select(function(name) {
|
4159
|
-
return name.length > 0;
|
4160
|
-
})._each(iterator);
|
4161
|
-
},
|
4162
|
-
|
4163
|
-
set: function(className) {
|
4164
|
-
this.element.className = className;
|
4165
|
-
},
|
4166
|
-
|
4167
|
-
add: function(classNameToAdd) {
|
4168
|
-
if (this.include(classNameToAdd)) return;
|
4169
|
-
this.set($A(this).concat(classNameToAdd).join(' '));
|
4170
|
-
},
|
4171
|
-
|
4172
|
-
remove: function(classNameToRemove) {
|
4173
|
-
if (!this.include(classNameToRemove)) return;
|
4174
|
-
this.set($A(this).without(classNameToRemove).join(' '));
|
4175
|
-
},
|
4176
|
-
|
4177
|
-
toString: function() {
|
4178
|
-
return $A(this).join(' ');
|
4179
|
-
}
|
4180
|
-
};
|
4181
|
-
|
4182
|
-
Object.extend(Element.ClassNames.prototype, Enumerable);
|
4183
|
-
|
4184
|
-
/*--------------------------------------------------------------------------*/
|
4185
|
-
|
4186
|
-
Element.addMethods();
|