| 1 |
lars |
1 |
/**
|
|
|
2 |
* Utilities and extions to Prototype/Scriptaculous
|
|
|
3 |
* @file scriptaculous-adapter.js
|
|
|
4 |
*/
|
|
|
5 |
|
|
|
6 |
/**
|
|
|
7 |
* Extension to
|
|
|
8 |
* <a href="http://www.prototypejs.org/api/function" target="_blank">Prototype's Function</a>
|
|
|
9 |
* @namespace Function
|
|
|
10 |
*/
|
|
|
11 |
/**
|
|
|
12 |
* Similar to bindAsEventLister, but takes additional arguments.
|
|
|
13 |
* @function Function.bindEvent
|
|
|
14 |
*/
|
|
|
15 |
Function.prototype.bindEvent = function()
|
|
|
16 |
{
|
|
|
17 |
var __method = this, args = $A(arguments), object = args.shift();
|
|
|
18 |
return function(event)
|
|
|
19 |
{
|
|
|
20 |
return __method.apply(object, [event || window.event].concat(args));
|
|
|
21 |
}
|
|
|
22 |
};
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Extension to
|
|
|
26 |
* <a href="http://www.prototypejs.org/api/class" target="_blank">Prototype's Class</a>
|
|
|
27 |
* @namespace Class
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Creates a new class by copying class definition from
|
|
|
32 |
* the <tt>base</tt> and optional <tt>definition</tt>.
|
|
|
33 |
* @function {Class} Class.extend
|
|
|
34 |
* @param {function} base - Base class to copy from.
|
|
|
35 |
* @param {optional Array} - Additional definition
|
|
|
36 |
* @returns Constructor for the extended class
|
|
|
37 |
*/
|
|
|
38 |
Class.extend = function(base, definition)
|
|
|
39 |
{
|
|
|
40 |
var component = Class.create();
|
|
|
41 |
Object.extend(component.prototype, base.prototype);
|
|
|
42 |
if(definition)
|
|
|
43 |
Object.extend(component.prototype, definition);
|
|
|
44 |
return component;
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Base, version 1.0.2
|
|
|
49 |
* Copyright 2006, Dean Edwards
|
|
|
50 |
* License: http://creativecommons.org/licenses/LGPL/2.1/
|
|
|
51 |
* @class Base
|
|
|
52 |
*/
|
|
|
53 |
var Base = function() {
|
|
|
54 |
if (arguments.length) {
|
|
|
55 |
if (this == window) { // cast an object to this class
|
|
|
56 |
Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
|
|
|
57 |
} else {
|
|
|
58 |
this.extend(arguments[0]);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
};
|
|
|
62 |
|
|
|
63 |
Base.version = "1.0.2";
|
|
|
64 |
|
|
|
65 |
Base.prototype = {
|
|
|
66 |
extend: function(source, value) {
|
|
|
67 |
var extend = Base.prototype.extend;
|
|
|
68 |
if (arguments.length == 2) {
|
|
|
69 |
var ancestor = this[source];
|
|
|
70 |
// overriding?
|
|
|
71 |
if ((ancestor instanceof Function) && (value instanceof Function) &&
|
|
|
72 |
ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
|
|
|
73 |
var method = value;
|
|
|
74 |
// var _prototype = this.constructor.prototype;
|
|
|
75 |
// var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
|
|
|
76 |
value = function() {
|
|
|
77 |
var previous = this.base;
|
|
|
78 |
// this.base = fromPrototype ? _prototype[source] : ancestor;
|
|
|
79 |
this.base = ancestor;
|
|
|
80 |
var returnValue = method.apply(this, arguments);
|
|
|
81 |
this.base = previous;
|
|
|
82 |
return returnValue;
|
|
|
83 |
};
|
|
|
84 |
// point to the underlying method
|
|
|
85 |
value.valueOf = function() {
|
|
|
86 |
return method;
|
|
|
87 |
};
|
|
|
88 |
value.toString = function() {
|
|
|
89 |
return String(method);
|
|
|
90 |
};
|
|
|
91 |
}
|
|
|
92 |
return this[source] = value;
|
|
|
93 |
} else if (source) {
|
|
|
94 |
var _prototype = {toSource: null};
|
|
|
95 |
// do the "toString" and other methods manually
|
|
|
96 |
var _protected = ["toString", "valueOf"];
|
|
|
97 |
// if we are prototyping then include the constructor
|
|
|
98 |
if (Base._prototyping) _protected[2] = "constructor";
|
|
|
99 |
for (var i = 0; (name = _protected[i]); i++) {
|
|
|
100 |
if (source[name] != _prototype[name]) {
|
|
|
101 |
extend.call(this, name, source[name]);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
// copy each of the source object's properties to this object
|
|
|
105 |
for (var name in source) {
|
|
|
106 |
if (!_prototype[name]) {
|
|
|
107 |
extend.call(this, name, source[name]);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
return this;
|
|
|
112 |
},
|
|
|
113 |
|
|
|
114 |
base: function() {
|
|
|
115 |
// call this method from any other method to invoke that method's ancestor
|
|
|
116 |
}
|
|
|
117 |
};
|
|
|
118 |
|
|
|
119 |
Base.extend = function(_instance, _static) {
|
|
|
120 |
var extend = Base.prototype.extend;
|
|
|
121 |
if (!_instance) _instance = {};
|
|
|
122 |
// build the prototype
|
|
|
123 |
Base._prototyping = true;
|
|
|
124 |
var _prototype = new this;
|
|
|
125 |
extend.call(_prototype, _instance);
|
|
|
126 |
var constructor = _prototype.constructor;
|
|
|
127 |
_prototype.constructor = this;
|
|
|
128 |
delete Base._prototyping;
|
|
|
129 |
// create the wrapper for the constructor function
|
|
|
130 |
var klass = function() {
|
|
|
131 |
if (!Base._prototyping) constructor.apply(this, arguments);
|
|
|
132 |
this.constructor = klass;
|
|
|
133 |
};
|
|
|
134 |
klass.prototype = _prototype;
|
|
|
135 |
// build the class interface
|
|
|
136 |
klass.extend = this.extend;
|
|
|
137 |
klass.implement = this.implement;
|
|
|
138 |
klass.toString = function() {
|
|
|
139 |
return String(constructor);
|
|
|
140 |
};
|
|
|
141 |
extend.call(klass, _static);
|
|
|
142 |
// single instance
|
|
|
143 |
var object = constructor ? klass : _prototype;
|
|
|
144 |
// class initialisation
|
|
|
145 |
if (object.init instanceof Function) object.init();
|
|
|
146 |
return object;
|
|
|
147 |
};
|
|
|
148 |
|
|
|
149 |
Base.implement = function(_interface) {
|
|
|
150 |
if (_interface instanceof Function) _interface = _interface.prototype;
|
|
|
151 |
this.prototype.extend(_interface);
|
|
|
152 |
};
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Performs a PostBack using javascript.
|
|
|
156 |
* @function Prado.PostBack
|
|
|
157 |
* @param event - Event that triggered this postback
|
|
|
158 |
* @param options - Postback options
|
|
|
159 |
* @... {string} FormID - Form that should be posted back
|
|
|
160 |
* @... {optional boolean} CausesValidation - Validate before PostBack if true
|
|
|
161 |
* @... {optional string} ValidationGroup - Group to Validate
|
|
|
162 |
* @... {optional string} ID - Validation ID
|
|
|
163 |
* @... {optional string} PostBackUrl - Postback URL
|
|
|
164 |
* @... {optional boolean} TrackFocus - Keep track of focused element if true
|
|
|
165 |
* @... {string} EventTarget - Id of element that triggered PostBack
|
|
|
166 |
* @... {string} EventParameter - EventParameter for PostBack
|
|
|
167 |
*/
|
|
|
168 |
Prado.PostBack = function(event,options)
|
|
|
169 |
{
|
|
|
170 |
var form = $(options['FormID']);
|
|
|
171 |
var canSubmit = true;
|
|
|
172 |
|
|
|
173 |
if(options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
|
|
|
174 |
{
|
|
|
175 |
if(!Prado.Validation.validate(options['FormID'], options['ValidationGroup'], $(options['ID'])))
|
|
|
176 |
return Event.stop(event);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
if(options['PostBackUrl'] && options['PostBackUrl'].length > 0)
|
|
|
180 |
form.action = options['PostBackUrl'];
|
|
|
181 |
|
|
|
182 |
if(options['TrackFocus'])
|
|
|
183 |
{
|
|
|
184 |
var lastFocus = $('PRADO_LASTFOCUS');
|
|
|
185 |
if(lastFocus)
|
|
|
186 |
{
|
|
|
187 |
var active = document.activeElement; //where did this come from
|
|
|
188 |
if(active)
|
|
|
189 |
lastFocus.value = active.id;
|
|
|
190 |
else
|
|
|
191 |
lastFocus.value = options['EventTarget'];
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
$('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
|
|
|
196 |
$('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
|
|
|
197 |
/**
|
|
|
198 |
* Since google toolbar prevents browser default action,
|
|
|
199 |
* we will always disable default client-side browser action
|
|
|
200 |
*/
|
|
|
201 |
/*if(options['StopEvent']) */
|
|
|
202 |
Event.stop(event);
|
|
|
203 |
Event.fireEvent(form,"submit");
|
|
|
204 |
};
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Prado utilities to manipulate DOM elements.
|
|
|
208 |
* @object Prado.Element
|
|
|
209 |
*/
|
|
|
210 |
Prado.Element =
|
|
|
211 |
{
|
|
|
212 |
/**
|
|
|
213 |
* Set the value of a particular element.
|
|
|
214 |
* @function ?
|
|
|
215 |
* @param {string} element - Element id
|
|
|
216 |
* @param {string} value - New element value
|
|
|
217 |
*/
|
|
|
218 |
setValue : function(element, value)
|
|
|
219 |
{
|
|
|
220 |
var el = $(element);
|
|
|
221 |
if(el && typeof(el.value) != "undefined")
|
|
|
222 |
el.value = value;
|
|
|
223 |
},
|
|
|
224 |
|
|
|
225 |
/**
|
|
|
226 |
* Select options from a selectable element.
|
|
|
227 |
* @function ?
|
|
|
228 |
* @param {string} element - Element id
|
|
|
229 |
* @param {string} method - Name of any {@link Prado.Element.Selection} method
|
|
|
230 |
* @param {array|boolean|string} value - Values that should be selected
|
|
|
231 |
* @param {int} total - Number of elements
|
|
|
232 |
*/
|
|
|
233 |
select : function(element, method, value, total)
|
|
|
234 |
{
|
|
|
235 |
var el = $(element);
|
|
|
236 |
if(!el) return;
|
|
|
237 |
var selection = Prado.Element.Selection;
|
|
|
238 |
if(typeof(selection[method]) == "function")
|
|
|
239 |
{
|
|
|
240 |
control = selection.isSelectable(el) ? [el] : selection.getListElements(element,total);
|
|
|
241 |
selection[method](control, value);
|
|
|
242 |
}
|
|
|
243 |
},
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* Trigger a click event on a DOM element.
|
|
|
247 |
* @function ?
|
|
|
248 |
* @param {string} element - Element id
|
|
|
249 |
*/
|
|
|
250 |
click : function(element)
|
|
|
251 |
{
|
|
|
252 |
var el = $(element);
|
|
|
253 |
if(el)
|
|
|
254 |
Event.fireEvent(el,'click');
|
|
|
255 |
},
|
|
|
256 |
|
|
|
257 |
/**
|
|
|
258 |
* Check if an DOM element is disabled.
|
|
|
259 |
* @function {boolean} ?
|
|
|
260 |
* @param {string} element - Element id
|
|
|
261 |
* @returns true if element is disabled
|
|
|
262 |
*/
|
|
|
263 |
isDisabled : function(element)
|
|
|
264 |
{
|
|
|
265 |
if(!element.attributes['disabled']) //FF
|
|
|
266 |
return false;
|
|
|
267 |
var value = element.attributes['disabled'].nodeValue;
|
|
|
268 |
if(typeof(value)=="string")
|
|
|
269 |
return value.toLowerCase() == "disabled";
|
|
|
270 |
else
|
|
|
271 |
return value == true;
|
|
|
272 |
},
|
|
|
273 |
|
|
|
274 |
/**
|
|
|
275 |
* Sets an attribute of a DOM element.
|
|
|
276 |
* @function ?
|
|
|
277 |
* @param {string} element - Element id
|
|
|
278 |
* @param {string} attribute - Name of attribute
|
|
|
279 |
* @param {string} value - Value of attribute
|
|
|
280 |
*/
|
|
|
281 |
setAttribute : function(element, attribute, value)
|
|
|
282 |
{
|
|
|
283 |
var el = $(element);
|
|
|
284 |
if(!el) return;
|
|
|
285 |
if((attribute == "disabled" || attribute == "multiple") && value==false)
|
|
|
286 |
el.removeAttribute(attribute);
|
|
|
287 |
else if(attribute.match(/^on/i)) //event methods
|
|
|
288 |
{
|
|
|
289 |
try
|
|
|
290 |
{
|
|
|
291 |
eval("(func = function(event){"+value+"})");
|
|
|
292 |
el[attribute] = func;
|
|
|
293 |
}
|
|
|
294 |
catch(e)
|
|
|
295 |
{
|
|
|
296 |
throw "Error in evaluating '"+value+"' for attribute "+attribute+" for element "+element.id;
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
else
|
|
|
300 |
el.setAttribute(attribute, value);
|
|
|
301 |
},
|
|
|
302 |
|
|
|
303 |
/**
|
|
|
304 |
* Sets the options for a select element.
|
|
|
305 |
* @function ?
|
|
|
306 |
* @param {string} element - Element id
|
|
|
307 |
* @param {array[]} options - Array of options, each an array of structure
|
|
|
308 |
* [ "optionText" , "optionValue" , "optionGroup" ]
|
|
|
309 |
*/
|
|
|
310 |
setOptions : function(element, options)
|
|
|
311 |
{
|
|
|
312 |
var el = $(element);
|
|
|
313 |
if(!el) return;
|
|
|
314 |
var previousGroup = null;
|
|
|
315 |
var optGroup=null;
|
|
|
316 |
if(el && el.tagName.toLowerCase() == "select")
|
|
|
317 |
{
|
|
|
318 |
while(el.childNodes.length > 0)
|
|
|
319 |
el.removeChild(el.lastChild);
|
|
|
320 |
|
|
|
321 |
var optDom = Prado.Element.createOptions(options);
|
|
|
322 |
for(var i = 0; i < optDom.length; i++)
|
|
|
323 |
el.appendChild(optDom[i]);
|
|
|
324 |
}
|
|
|
325 |
},
|
|
|
326 |
|
|
|
327 |
/**
|
|
|
328 |
* Create opt-group options from an array of options.
|
|
|
329 |
* @function {array} ?
|
|
|
330 |
* @param {array[]} options - Array of options, each an array of structure
|
|
|
331 |
* [ "optionText" , "optionValue" , "optionGroup" ]
|
|
|
332 |
* @returns Array of option DOM elements
|
|
|
333 |
*/
|
|
|
334 |
createOptions : function(options)
|
|
|
335 |
{
|
|
|
336 |
var previousGroup = null;
|
|
|
337 |
var optgroup=null;
|
|
|
338 |
var result = [];
|
|
|
339 |
for(var i = 0; i<options.length; i++)
|
|
|
340 |
{
|
|
|
341 |
var option = options[i];
|
|
|
342 |
if(option.length > 2)
|
|
|
343 |
{
|
|
|
344 |
var group = option[2];
|
|
|
345 |
if(group!=previousGroup)
|
|
|
346 |
{
|
|
|
347 |
if(previousGroup!=null && optgroup!=null)
|
|
|
348 |
{
|
|
|
349 |
result.push(optgroup);
|
|
|
350 |
previousGroup=null;
|
|
|
351 |
optgroup=null;
|
|
|
352 |
}
|
|
|
353 |
optgroup = document.createElement('optgroup');
|
|
|
354 |
optgroup.label = group;
|
|
|
355 |
previousGroup = group;
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
var opt = document.createElement('option');
|
|
|
359 |
opt.text = option[0];
|
|
|
360 |
opt.innerText = option[0];
|
|
|
361 |
opt.value = option[1];
|
|
|
362 |
if(optgroup!=null)
|
|
|
363 |
optgroup.appendChild(opt);
|
|
|
364 |
else
|
|
|
365 |
result.push(opt);
|
|
|
366 |
}
|
|
|
367 |
if(optgroup!=null)
|
|
|
368 |
result.push(optgroup);
|
|
|
369 |
return result;
|
|
|
370 |
},
|
|
|
371 |
|
|
|
372 |
/**
|
|
|
373 |
* Set focus (delayed) on a particular element.
|
|
|
374 |
* @function ?
|
|
|
375 |
* @param {string} element - Element id
|
|
|
376 |
*/
|
|
|
377 |
focus : function(element)
|
|
|
378 |
{
|
|
|
379 |
var obj = $(element);
|
|
|
380 |
if(typeof(obj) != "undefined" && typeof(obj.focus) != "undefined")
|
|
|
381 |
setTimeout(function(){ obj.focus(); }, 100);
|
|
|
382 |
return false;
|
|
|
383 |
},
|
|
|
384 |
|
|
|
385 |
/**
|
|
|
386 |
* Replace a DOM element either with given content or
|
|
|
387 |
* with content from a CallBack response boundary
|
|
|
388 |
* using a replacement method.
|
|
|
389 |
* @function ?
|
|
|
390 |
* @param {string|element} element - DOM element or element id
|
|
|
391 |
* @param {string} method - Name of method to use for replacement
|
|
|
392 |
* @param {optional string} content - New content of element
|
|
|
393 |
* @param {optional string} boundary - Boundary of new content
|
|
|
394 |
*/
|
|
|
395 |
replace : function(element, method, content, boundary)
|
|
|
396 |
{
|
|
|
397 |
if(boundary)
|
|
|
398 |
{
|
|
|
399 |
result = Prado.Element.extractContent(this.transport.responseText, boundary);
|
|
|
400 |
if(result != null)
|
|
|
401 |
content = result;
|
|
|
402 |
}
|
|
|
403 |
if(typeof(element) == "string")
|
|
|
404 |
{
|
|
|
405 |
if($(element))
|
|
|
406 |
method.toFunction().apply(this,[element,""+content]);
|
|
|
407 |
}
|
|
|
408 |
else
|
|
|
409 |
{
|
|
|
410 |
method.toFunction().apply(this,[""+content]);
|
|
|
411 |
}
|
|
|
412 |
},
|
|
|
413 |
|
|
|
414 |
/**
|
|
|
415 |
* Extract content from a text by its boundary id.
|
|
|
416 |
* Boundaries have this form:
|
|
|
417 |
* <pre>
|
|
|
418 |
* <!--123456-->Democontent<!--//123456-->
|
|
|
419 |
* </pre>
|
|
|
420 |
* @function {string} ?
|
|
|
421 |
* @param {string} text - Text that contains boundaries
|
|
|
422 |
* @param {string} boundary - Boundary id
|
|
|
423 |
* @returns Content from given boundaries
|
|
|
424 |
*/
|
|
|
425 |
extractContent : function(text, boundary)
|
|
|
426 |
{
|
|
|
427 |
var tagStart = '<!--'+boundary+'-->';
|
|
|
428 |
var tagEnd = '<!--//'+boundary+'-->';
|
|
|
429 |
var start = text.indexOf(tagStart);
|
|
|
430 |
if(start > -1)
|
|
|
431 |
{
|
|
|
432 |
start += tagStart.length;
|
|
|
433 |
var end = text.indexOf(tagEnd,start);
|
|
|
434 |
if(end > -1)
|
|
|
435 |
return text.substring(start,end);
|
|
|
436 |
}
|
|
|
437 |
return null;
|
|
|
438 |
/*var f = RegExp('(?:<!--'+boundary+'-->)((?:.|\n|\r)+?)(?:<!--//'+boundary+'-->)',"m");
|
|
|
439 |
var result = text.match(f);
|
|
|
440 |
if(result && result.length >= 2)
|
|
|
441 |
return result[1];
|
|
|
442 |
else
|
|
|
443 |
return null;*/
|
|
|
444 |
},
|
|
|
445 |
|
|
|
446 |
/**
|
|
|
447 |
* Evaluate a javascript snippet from a string.
|
|
|
448 |
* @function ?
|
|
|
449 |
* @param {string} content - String containing the script
|
|
|
450 |
*/
|
|
|
451 |
evaluateScript : function(content)
|
|
|
452 |
{
|
|
|
453 |
content.evalScripts();
|
|
|
454 |
},
|
|
|
455 |
|
|
|
456 |
/**
|
|
|
457 |
* Set CSS style with Camelized keys.
|
|
|
458 |
* See <a href="http://www.prototypejs.org/api/element/setstyle" target="_blank">Prototype's
|
|
|
459 |
* Element.setStyle</a> for details.
|
|
|
460 |
* @function ?
|
|
|
461 |
* @param {string|element} element - DOM element or element id
|
|
|
462 |
* @param {object} styles - Object with style properties/values
|
|
|
463 |
*/
|
|
|
464 |
setStyle : function (element, styles)
|
|
|
465 |
{
|
|
|
466 |
var s = {}
|
|
|
467 |
// Camelize all styles keys
|
|
|
468 |
for (var property in styles)
|
|
|
469 |
{
|
|
|
470 |
s[property.camelize()]=styles[property].camelize();
|
|
|
471 |
}
|
|
|
472 |
Element.setStyle(element, s);
|
|
|
473 |
}
|
|
|
474 |
};
|
|
|
475 |
|
|
|
476 |
/**
|
|
|
477 |
* Utilities for selections.
|
|
|
478 |
* @object Prado.Element.Selection
|
|
|
479 |
*/
|
|
|
480 |
Prado.Element.Selection =
|
|
|
481 |
{
|
|
|
482 |
/**
|
|
|
483 |
* Check if an DOM element can be selected.
|
|
|
484 |
* @function {boolean} ?
|
|
|
485 |
* @param {element} el - DOM elemet
|
|
|
486 |
* @returns true if element is selectable
|
|
|
487 |
*/
|
|
|
488 |
isSelectable : function(el)
|
|
|
489 |
{
|
|
|
490 |
if(el && el.type)
|
|
|
491 |
{
|
|
|
492 |
switch(el.type.toLowerCase())
|
|
|
493 |
{
|
|
|
494 |
case 'checkbox':
|
|
|
495 |
case 'radio':
|
|
|
496 |
case 'select':
|
|
|
497 |
case 'select-multiple':
|
|
|
498 |
case 'select-one':
|
|
|
499 |
return true;
|
|
|
500 |
}
|
|
|
501 |
}
|
|
|
502 |
return false;
|
|
|
503 |
},
|
|
|
504 |
|
|
|
505 |
/**
|
|
|
506 |
* Set checked attribute of a checkbox or radiobutton to value.
|
|
|
507 |
* @function {boolean} ?
|
|
|
508 |
* @param {element} el - DOM element
|
|
|
509 |
* @param {boolean} value - New value of checked attribute
|
|
|
510 |
* @returns New value of checked attribute
|
|
|
511 |
*/
|
|
|
512 |
inputValue : function(el, value)
|
|
|
513 |
{
|
|
|
514 |
switch(el.type.toLowerCase())
|
|
|
515 |
{
|
|
|
516 |
case 'checkbox':
|
|
|
517 |
case 'radio':
|
|
|
518 |
return el.checked = value;
|
|
|
519 |
}
|
|
|
520 |
},
|
|
|
521 |
|
|
|
522 |
/**
|
|
|
523 |
* Set selected attribute for elements options by value.
|
|
|
524 |
* If value is boolean, all elements options selected attribute will be set
|
|
|
525 |
* to value. Otherwhise all options that have the given value will be selected.
|
|
|
526 |
* @function ?
|
|
|
527 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
528 |
* @param {boolean|string} value - Value of options that should be selected or boolean value of selection status
|
|
|
529 |
*/
|
|
|
530 |
selectValue : function(elements, value)
|
|
|
531 |
{
|
|
|
532 |
elements.each(function(el)
|
|
|
533 |
{
|
|
|
534 |
$A(el.options).each(function(option)
|
|
|
535 |
{
|
|
|
536 |
if(typeof(value) == "boolean")
|
|
|
537 |
options.selected = value;
|
|
|
538 |
else if(option.value == value)
|
|
|
539 |
option.selected = true;
|
|
|
540 |
});
|
|
|
541 |
})
|
|
|
542 |
},
|
|
|
543 |
|
|
|
544 |
/**
|
|
|
545 |
* Set selected attribute for elements options by array of values.
|
|
|
546 |
* @function ?
|
|
|
547 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
548 |
* @param {string[]} value - Array of values to select
|
|
|
549 |
*/
|
|
|
550 |
selectValues : function(elements, values)
|
|
|
551 |
{
|
|
|
552 |
selection = this;
|
|
|
553 |
values.each(function(value)
|
|
|
554 |
{
|
|
|
555 |
selection.selectValue(elements,value);
|
|
|
556 |
})
|
|
|
557 |
},
|
|
|
558 |
|
|
|
559 |
/**
|
|
|
560 |
* Set selected attribute for elements options by option index.
|
|
|
561 |
* @function ?
|
|
|
562 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
563 |
* @param {int} index - Index of option to select
|
|
|
564 |
*/
|
|
|
565 |
selectIndex : function(elements, index)
|
|
|
566 |
{
|
|
|
567 |
elements.each(function(el)
|
|
|
568 |
{
|
|
|
569 |
if(el.type.toLowerCase() == 'select-one')
|
|
|
570 |
el.selectedIndex = index;
|
|
|
571 |
else
|
|
|
572 |
{
|
|
|
573 |
for(var i = 0; i<el.length; i++)
|
|
|
574 |
{
|
|
|
575 |
if(i == index)
|
|
|
576 |
el.options[i].selected = true;
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
})
|
|
|
580 |
},
|
|
|
581 |
|
|
|
582 |
/**
|
|
|
583 |
* Set selected attribute to true for all elements options.
|
|
|
584 |
* @function ?
|
|
|
585 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
586 |
*/
|
|
|
587 |
selectAll : function(elements)
|
|
|
588 |
{
|
|
|
589 |
elements.each(function(el)
|
|
|
590 |
{
|
|
|
591 |
if(el.type.toLowerCase() != 'select-one')
|
|
|
592 |
{
|
|
|
593 |
$A(el.options).each(function(option)
|
|
|
594 |
{
|
|
|
595 |
option.selected = true;
|
|
|
596 |
})
|
|
|
597 |
}
|
|
|
598 |
})
|
|
|
599 |
},
|
|
|
600 |
|
|
|
601 |
/**
|
|
|
602 |
* Toggle the selected attribute for elements options.
|
|
|
603 |
* @function ?
|
|
|
604 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
605 |
*/
|
|
|
606 |
selectInvert : function(elements)
|
|
|
607 |
{
|
|
|
608 |
elements.each(function(el)
|
|
|
609 |
{
|
|
|
610 |
if(el.type.toLowerCase() != 'select-one')
|
|
|
611 |
{
|
|
|
612 |
$A(el.options).each(function(option)
|
|
|
613 |
{
|
|
|
614 |
option.selected = !options.selected;
|
|
|
615 |
})
|
|
|
616 |
}
|
|
|
617 |
})
|
|
|
618 |
},
|
|
|
619 |
|
|
|
620 |
/**
|
|
|
621 |
* Set selected attribute for elements options by array of option indices.
|
|
|
622 |
* @function ?
|
|
|
623 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
624 |
* @param {int[]} indices - Array of option indices to select
|
|
|
625 |
*/
|
|
|
626 |
selectIndices : function(elements, indices)
|
|
|
627 |
{
|
|
|
628 |
selection = this;
|
|
|
629 |
indices.each(function(index)
|
|
|
630 |
{
|
|
|
631 |
selection.selectIndex(elements,index);
|
|
|
632 |
})
|
|
|
633 |
},
|
|
|
634 |
|
|
|
635 |
/**
|
|
|
636 |
* Unselect elements.
|
|
|
637 |
* @function ?
|
|
|
638 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
639 |
*/
|
|
|
640 |
selectClear : function(elements)
|
|
|
641 |
{
|
|
|
642 |
elements.each(function(el)
|
|
|
643 |
{
|
|
|
644 |
el.selectedIndex = -1;
|
|
|
645 |
})
|
|
|
646 |
},
|
|
|
647 |
|
|
|
648 |
/**
|
|
|
649 |
* Get list elements of an element.
|
|
|
650 |
* @function {element[]} ?
|
|
|
651 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
652 |
* @param {int} total - Number of list elements to return
|
|
|
653 |
* @returns Array of list DOM elements
|
|
|
654 |
*/
|
|
|
655 |
getListElements : function(element, total)
|
|
|
656 |
{
|
|
|
657 |
elements = new Array();
|
|
|
658 |
for(i = 0; i < total; i++)
|
|
|
659 |
{
|
|
|
660 |
el = $(element+"_c"+i);
|
|
|
661 |
if(el)
|
|
|
662 |
elements.push(el);
|
|
|
663 |
}
|
|
|
664 |
return elements;
|
|
|
665 |
},
|
|
|
666 |
|
|
|
667 |
/**
|
|
|
668 |
* Set checked attribute of elements by value.
|
|
|
669 |
* If value is boolean, checked attribute will be set to value.
|
|
|
670 |
* Otherwhise all elements that have the given value will be checked.
|
|
|
671 |
* @function ?
|
|
|
672 |
* @param {element[]} elements - Array of checkable DOM elements
|
|
|
673 |
* @param {boolean|String} value - Value that should be checked or boolean value of checked status
|
|
|
674 |
*
|
|
|
675 |
*/
|
|
|
676 |
checkValue : function(elements, value)
|
|
|
677 |
{
|
|
|
678 |
elements.each(function(el)
|
|
|
679 |
{
|
|
|
680 |
if(typeof(value) == "boolean")
|
|
|
681 |
el.checked = value;
|
|
|
682 |
else if(el.value == value)
|
|
|
683 |
el.checked = true;
|
|
|
684 |
});
|
|
|
685 |
},
|
|
|
686 |
|
|
|
687 |
/**
|
|
|
688 |
* Set checked attribute of elements by array of values.
|
|
|
689 |
* @function ?
|
|
|
690 |
* @param {element[]} elements - Array of checkable DOM elements
|
|
|
691 |
* @param {string[]} values - Values that should be checked
|
|
|
692 |
*
|
|
|
693 |
*/
|
|
|
694 |
checkValues : function(elements, values)
|
|
|
695 |
{
|
|
|
696 |
selection = this;
|
|
|
697 |
values.each(function(value)
|
|
|
698 |
{
|
|
|
699 |
selection.checkValue(elements, value);
|
|
|
700 |
})
|
|
|
701 |
},
|
|
|
702 |
|
|
|
703 |
/**
|
|
|
704 |
* Set checked attribute of elements by list index.
|
|
|
705 |
* @function ?
|
|
|
706 |
* @param {element[]} elements - Array of checkable DOM elements
|
|
|
707 |
* @param {int} index - Index of element to set checked
|
|
|
708 |
*/
|
|
|
709 |
checkIndex : function(elements, index)
|
|
|
710 |
{
|
|
|
711 |
for(var i = 0; i<elements.length; i++)
|
|
|
712 |
{
|
|
|
713 |
if(i == index)
|
|
|
714 |
elements[i].checked = true;
|
|
|
715 |
}
|
|
|
716 |
},
|
|
|
717 |
|
|
|
718 |
/**
|
|
|
719 |
* Set checked attribute of elements by array of list indices.
|
|
|
720 |
* @function ?
|
|
|
721 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
722 |
* @param {int[]} indices - Array of list indices to set checked
|
|
|
723 |
*/
|
|
|
724 |
checkIndices : function(elements, indices)
|
|
|
725 |
{
|
|
|
726 |
selection = this;
|
|
|
727 |
indices.each(function(index)
|
|
|
728 |
{
|
|
|
729 |
selection.checkIndex(elements, index);
|
|
|
730 |
})
|
|
|
731 |
},
|
|
|
732 |
|
|
|
733 |
/**
|
|
|
734 |
* Uncheck elements.
|
|
|
735 |
* @function ?
|
|
|
736 |
* @param {element[]} elements - Array of checkable DOM elements
|
|
|
737 |
*/
|
|
|
738 |
checkClear : function(elements)
|
|
|
739 |
{
|
|
|
740 |
elements.each(function(el)
|
|
|
741 |
{
|
|
|
742 |
el.checked = false;
|
|
|
743 |
});
|
|
|
744 |
},
|
|
|
745 |
|
|
|
746 |
/**
|
|
|
747 |
* Set checked attribute of all elements to true.
|
|
|
748 |
* @function ?
|
|
|
749 |
* @param {element[]} elements - Array of checkable DOM elements
|
|
|
750 |
*/
|
|
|
751 |
checkAll : function(elements)
|
|
|
752 |
{
|
|
|
753 |
elements.each(function(el)
|
|
|
754 |
{
|
|
|
755 |
el.checked = true;
|
|
|
756 |
})
|
|
|
757 |
},
|
|
|
758 |
|
|
|
759 |
/**
|
|
|
760 |
* Toggle the checked attribute of elements.
|
|
|
761 |
* @function ?
|
|
|
762 |
* @param {element[]} elements - Array of selectable DOM elements
|
|
|
763 |
*/
|
|
|
764 |
checkInvert : function(elements)
|
|
|
765 |
{
|
|
|
766 |
elements.each(function(el)
|
|
|
767 |
{
|
|
|
768 |
el.checked != el.checked;
|
|
|
769 |
})
|
|
|
770 |
}
|
|
|
771 |
};
|
|
|
772 |
|
|
|
773 |
|
|
|
774 |
/**
|
|
|
775 |
* Utilities for insertion.
|
|
|
776 |
* @object Prado.Element.Insert
|
|
|
777 |
*/
|
|
|
778 |
Prado.Element.Insert =
|
|
|
779 |
{
|
|
|
780 |
/**
|
|
|
781 |
* Append content to element
|
|
|
782 |
* @function ?
|
|
|
783 |
* @param {element} element - DOM element that content should be appended to
|
|
|
784 |
* @param {element} content - DOM element to append
|
|
|
785 |
*/
|
|
|
786 |
append: function(element, content)
|
|
|
787 |
{
|
|
|
788 |
$(element).insert(content);
|
|
|
789 |
},
|
|
|
790 |
|
|
|
791 |
/**
|
|
|
792 |
* Prepend content to element
|
|
|
793 |
* @function ?
|
|
|
794 |
* @param {element} element - DOM element that content should be prepended to
|
|
|
795 |
* @param {element} content - DOM element to prepend
|
|
|
796 |
*/
|
|
|
797 |
prepend: function(element, content)
|
|
|
798 |
{
|
|
|
799 |
$(element).insert({top:content});
|
|
|
800 |
},
|
|
|
801 |
|
|
|
802 |
/**
|
|
|
803 |
* Insert content after element
|
|
|
804 |
* @function ?
|
|
|
805 |
* @param {element} element - DOM element that content should be inserted after
|
|
|
806 |
* @param {element} content - DOM element to insert
|
|
|
807 |
*/
|
|
|
808 |
after: function(element, content)
|
|
|
809 |
{
|
|
|
810 |
$(element).insert({after:content});
|
|
|
811 |
},
|
|
|
812 |
|
|
|
813 |
/**
|
|
|
814 |
* Insert content before element
|
|
|
815 |
* @function ?
|
|
|
816 |
* @param {element} element - DOM element that content should be inserted before
|
|
|
817 |
* @param {element} content - DOM element to insert
|
|
|
818 |
*/
|
|
|
819 |
before: function(element, content)
|
|
|
820 |
{
|
|
|
821 |
$(element).insert({before:content});
|
|
|
822 |
}
|
|
|
823 |
};
|
|
|
824 |
|
|
|
825 |
|
|
|
826 |
/**
|
|
|
827 |
* Extension to
|
|
|
828 |
* <a href="http://wiki.script.aculo.us/scriptaculous/show/builder" target="_blank">Scriptaculous' Builder</a>
|
|
|
829 |
* @namespace Builder
|
|
|
830 |
*/
|
|
|
831 |
|
|
|
832 |
Object.extend(Builder,
|
|
|
833 |
{
|
|
|
834 |
/**
|
|
|
835 |
* Export scriptaculous builder utilities as window[functions]
|
|
|
836 |
* @function ?
|
|
|
837 |
*/
|
|
|
838 |
exportTags:function()
|
|
|
839 |
{
|
|
|
840 |
var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG", "CAPTION"];
|
|
|
841 |
tags.each(function(tag)
|
|
|
842 |
{
|
|
|
843 |
window[tag]=function()
|
|
|
844 |
{
|
|
|
845 |
var args=$A(arguments);
|
|
|
846 |
if(args.length==0)
|
|
|
847 |
return Builder.node(tag,null);
|
|
|
848 |
if(args.length==1)
|
|
|
849 |
return Builder.node(tag,args[0]);
|
|
|
850 |
if(args.length>1)
|
|
|
851 |
return Builder.node(tag,args.shift(),args);
|
|
|
852 |
|
|
|
853 |
};
|
|
|
854 |
});
|
|
|
855 |
}
|
|
|
856 |
});
|
|
|
857 |
Builder.exportTags();
|
|
|
858 |
|
|
|
859 |
/**
|
|
|
860 |
* Extension to
|
|
|
861 |
* <a href="http://www.prototypejs.org/api/string" target="_blank">Prototype's String</a>
|
|
|
862 |
* @namespace String
|
|
|
863 |
*/
|
|
|
864 |
Object.extend(String.prototype, {
|
|
|
865 |
|
|
|
866 |
/**
|
|
|
867 |
* Add padding to string
|
|
|
868 |
* @function {string} ?
|
|
|
869 |
* @param {string} side - "left" to pad the string on the left, "right" to pad right.
|
|
|
870 |
* @param {int} len - Minimum string length.
|
|
|
871 |
* @param {string} chr - Character(s) to pad
|
|
|
872 |
* @returns Padded string
|
|
|
873 |
*/
|
|
|
874 |
pad : function(side, len, chr) {
|
|
|
875 |
if (!chr) chr = ' ';
|
|
|
876 |
var s = this;
|
|
|
877 |
var left = side.toLowerCase()=='left';
|
|
|
878 |
while (s.length<len) s = left? chr + s : s + chr;
|
|
|
879 |
return s;
|
|
|
880 |
},
|
|
|
881 |
|
|
|
882 |
/**
|
|
|
883 |
* Add left padding to string
|
|
|
884 |
* @function {string} ?
|
|
|
885 |
* @param {int} len - Minimum string length.
|
|
|
886 |
* @param {string} chr - Character(s) to pad
|
|
|
887 |
* @returns Padded string
|
|
|
888 |
*/
|
|
|
889 |
padLeft : function(len, chr) {
|
|
|
890 |
return this.pad('left',len,chr);
|
|
|
891 |
},
|
|
|
892 |
|
|
|
893 |
/**
|
|
|
894 |
* Add right padding to string
|
|
|
895 |
* @function {string} ?
|
|
|
896 |
* @param {int} len - Minimum string length.
|
|
|
897 |
* @param {string} chr - Character(s) to pad
|
|
|
898 |
* @returns Padded string
|
|
|
899 |
*/
|
|
|
900 |
padRight : function(len, chr) {
|
|
|
901 |
return this.pad('right',len,chr);
|
|
|
902 |
},
|
|
|
903 |
|
|
|
904 |
/**
|
|
|
905 |
* Add zeros to the right of string
|
|
|
906 |
* @function {string} ?
|
|
|
907 |
* @param {int} len - Minimum string length.
|
|
|
908 |
* @returns Padded string
|
|
|
909 |
*/
|
|
|
910 |
zerofill : function(len) {
|
|
|
911 |
return this.padLeft(len,'0');
|
|
|
912 |
},
|
|
|
913 |
|
|
|
914 |
/**
|
|
|
915 |
* Remove white spaces from both ends of string.
|
|
|
916 |
* @function {string} ?
|
|
|
917 |
* @returns Trimmed string
|
|
|
918 |
*/
|
|
|
919 |
trim : function() {
|
|
|
920 |
return this.replace(/^\s+|\s+$/g,'');
|
|
|
921 |
},
|
|
|
922 |
|
|
|
923 |
/**
|
|
|
924 |
* Remove white spaces from the left side of string.
|
|
|
925 |
* @function {string} ?
|
|
|
926 |
* @returns Trimmed string
|
|
|
927 |
*/
|
|
|
928 |
trimLeft : function() {
|
|
|
929 |
return this.replace(/^\s+/,'');
|
|
|
930 |
},
|
|
|
931 |
|
|
|
932 |
/**
|
|
|
933 |
* Remove white spaces from the right side of string.
|
|
|
934 |
* @function {string} ?
|
|
|
935 |
* @returns Trimmed string
|
|
|
936 |
*/
|
|
|
937 |
trimRight : function() {
|
|
|
938 |
return this.replace(/\s+$/,'');
|
|
|
939 |
},
|
|
|
940 |
|
|
|
941 |
/**
|
|
|
942 |
* Convert period separated function names into a function reference.
|
|
|
943 |
* <br />Example:
|
|
|
944 |
* <pre>
|
|
|
945 |
* "Prado.AJAX.Callback.Action.setValue".toFunction()
|
|
|
946 |
* </pre>
|
|
|
947 |
* @function {function} ?
|
|
|
948 |
* @returns Reference to the corresponding function
|
|
|
949 |
*/
|
|
|
950 |
toFunction : function()
|
|
|
951 |
{
|
|
|
952 |
var commands = this.split(/\./);
|
|
|
953 |
var command = window;
|
|
|
954 |
commands.each(function(action)
|
|
|
955 |
{
|
|
|
956 |
if(command[new String(action)])
|
|
|
957 |
command=command[new String(action)];
|
|
|
958 |
});
|
|
|
959 |
if(typeof(command) == "function")
|
|
|
960 |
return command;
|
|
|
961 |
else
|
|
|
962 |
{
|
|
|
963 |
if(typeof Logger != "undefined")
|
|
|
964 |
Logger.error("Missing function", this);
|
|
|
965 |
|
|
|
966 |
throw new Error ("Missing function '"+this+"'");
|
|
|
967 |
}
|
|
|
968 |
},
|
|
|
969 |
|
|
|
970 |
/**
|
|
|
971 |
* Convert string into integer, returns null if not integer.
|
|
|
972 |
* @function {int} ?
|
|
|
973 |
* @returns Integer, null if string does not represent an integer.
|
|
|
974 |
*/
|
|
|
975 |
toInteger : function()
|
|
|
976 |
{
|
|
|
977 |
var exp = /^\s*[-\+]?\d+\s*$/;
|
|
|
978 |
if (this.match(exp) == null)
|
|
|
979 |
return null;
|
|
|
980 |
var num = parseInt(this, 10);
|
|
|
981 |
return (isNaN(num) ? null : num);
|
|
|
982 |
},
|
|
|
983 |
|
|
|
984 |
/**
|
|
|
985 |
* Convert string into a double/float value. <b>Internationalization
|
|
|
986 |
* is not supported</b>
|
|
|
987 |
* @function {double} ?
|
|
|
988 |
* @param {string} decimalchar - Decimal character, defaults to "."
|
|
|
989 |
* @returns Double, null if string does not represent a float value
|
|
|
990 |
*/
|
|
|
991 |
toDouble : function(decimalchar)
|
|
|
992 |
{
|
|
|
993 |
if(this.length <= 0) return null;
|
|
|
994 |
decimalchar = decimalchar || ".";
|
|
|
995 |
var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
|
|
|
996 |
var m = this.match(exp);
|
|
|
997 |
|
|
|
998 |
if (m == null)
|
|
|
999 |
return null;
|
|
|
1000 |
m[1] = m[1] || "";
|
|
|
1001 |
m[2] = m[2] || "0";
|
|
|
1002 |
m[4] = m[4] || "0";
|
|
|
1003 |
|
|
|
1004 |
var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
|
|
|
1005 |
var num = parseFloat(cleanInput);
|
|
|
1006 |
return (isNaN(num) ? null : num);
|
|
|
1007 |
},
|
|
|
1008 |
|
|
|
1009 |
/**
|
|
|
1010 |
* Convert strings that represent a currency value to float.
|
|
|
1011 |
* E.g. "10,000.50" will become "10000.50". The number
|
|
|
1012 |
* of dicimal digits, grouping and decimal characters can be specified.
|
|
|
1013 |
* <i>The currency input format is <b>very</b> strict, null will be returned if
|
|
|
1014 |
* the pattern does not match</i>.
|
|
|
1015 |
* @function {double} ?
|
|
|
1016 |
* @param {string} groupchar - Grouping character, defaults to ","
|
|
|
1017 |
* @param {int} digits - Number of decimal digits
|
|
|
1018 |
* @param {string} decimalchar - Decimal character, defaults to "."
|
|
|
1019 |
* @returns Double, null if string does not represent a currency value
|
|
|
1020 |
*/
|
|
|
1021 |
toCurrency : function(groupchar, digits, decimalchar)
|
|
|
1022 |
{
|
|
|
1023 |
groupchar = groupchar || ",";
|
|
|
1024 |
decimalchar = decimalchar || ".";
|
|
|
1025 |
digits = typeof(digits) == "undefined" ? 2 : digits;
|
|
|
1026 |
|
|
|
1027 |
var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)"
|
|
|
1028 |
+ ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "")
|
|
|
1029 |
+ "\\s*$");
|
|
|
1030 |
var m = this.match(exp);
|
|
|
1031 |
if (m == null)
|
|
|
1032 |
return null;
|
|
|
1033 |
var intermed = m[2] + m[5] ;
|
|
|
1034 |
var cleanInput = m[1] + intermed.replace(
|
|
|
1035 |
new RegExp("(\\" + groupchar + ")", "g"), "")
|
|
|
1036 |
+ ((digits > 0) ? "." + m[7] : "");
|
|
|
1037 |
var num = parseFloat(cleanInput);
|
|
|
1038 |
return (isNaN(num) ? null : num);
|
|
|
1039 |
},
|
|
|
1040 |
|
|
|
1041 |
/**
|
|
|
1042 |
* Converts the string to a date by finding values that matches the
|
|
|
1043 |
* date format pattern.
|
|
|
1044 |
* @function {Date} ?
|
|
|
1045 |
* @param {string} format - Date format pattern, e.g. MM-dd-yyyy
|
|
|
1046 |
* @returns Date extracted from the string
|
|
|
1047 |
*/
|
|
|
1048 |
toDate : function(format)
|
|
|
1049 |
{
|
|
|
1050 |
return Date.SimpleParse(this, format);
|
|
|
1051 |
}
|
|
|
1052 |
});
|
|
|
1053 |
|
|
|
1054 |
/**
|
|
|
1055 |
* Extension to
|
|
|
1056 |
* <a href="http://www.prototypejs.org/api/event" target="_blank">Prototype's Event</a>
|
|
|
1057 |
* @namespace Event
|
|
|
1058 |
*/
|
|
|
1059 |
Object.extend(Event,
|
|
|
1060 |
{
|
|
|
1061 |
/**
|
|
|
1062 |
* Register a function to be executed when the page is loaded.
|
|
|
1063 |
* Note that the page is only loaded if all resources (e.g. images)
|
|
|
1064 |
* are loaded.
|
|
|
1065 |
* <br />Example:
|
|
|
1066 |
* <br />Show an alert box with message "Page Loaded!" when the
|
|
|
1067 |
* page finished loading.
|
|
|
1068 |
* <pre>
|
|
|
1069 |
* Event.OnLoad(function(){ alert("Page Loaded!"); });
|
|
|
1070 |
* </pre>
|
|
|
1071 |
* @function ?
|
|
|
1072 |
* @param {function} fn - Function to execute when page is loaded.
|
|
|
1073 |
*/
|
|
|
1074 |
OnLoad : function (fn)
|
|
|
1075 |
{
|
|
|
1076 |
// opera onload is in document, not window
|
|
|
1077 |
var w = document.addEventListener &&
|
|
|
1078 |
!window.addEventListener ? document : window;
|
|
|
1079 |
Event.observe(w,'load',fn);
|
|
|
1080 |
},
|
|
|
1081 |
|
|
|
1082 |
/**
|
|
|
1083 |
* Returns the unicode character generated by key.
|
|
|
1084 |
* @param {event} e - Keyboard event
|
|
|
1085 |
* @function {int} ?
|
|
|
1086 |
* @returns Unicode character code generated by the key that was struck.
|
|
|
1087 |
*/
|
|
|
1088 |
keyCode : function(e)
|
|
|
1089 |
{
|
|
|
1090 |
return e.keyCode != null ? e.keyCode : e.charCode
|
|
|
1091 |
},
|
|
|
1092 |
|
|
|
1093 |
/**
|
|
|
1094 |
* Checks if an Event is of type HTMLEvent.
|
|
|
1095 |
* @function {boolean} ?
|
|
|
1096 |
* @param {string} type - Event type or event name.
|
|
|
1097 |
* @return true if event is of type HTMLEvent.
|
|
|
1098 |
*/
|
|
|
1099 |
isHTMLEvent : function(type)
|
|
|
1100 |
{
|
|
|
1101 |
var events = ['abort', 'blur', 'change', 'error', 'focus',
|
|
|
1102 |
'load', 'reset', 'resize', 'scroll', 'select',
|
|
|
1103 |
'submit', 'unload'];
|
|
|
1104 |
return events.include(type);
|
|
|
1105 |
},
|
|
|
1106 |
|
|
|
1107 |
/**
|
|
|
1108 |
* Checks if an Event is a mouse event.
|
|
|
1109 |
* @function {boolean} ?
|
|
|
1110 |
* @param {string} type - Event type or event name
|
|
|
1111 |
* @return true if event is of type MouseEvent.
|
|
|
1112 |
*/
|
|
|
1113 |
isMouseEvent : function(type)
|
|
|
1114 |
{
|
|
|
1115 |
var events = ['click', 'mousedown', 'mousemove', 'mouseout',
|
|
|
1116 |
'mouseover', 'mouseup'];
|
|
|
1117 |
return events.include(type);
|
|
|
1118 |
},
|
|
|
1119 |
|
|
|
1120 |
/**
|
|
|
1121 |
* Dispatch the DOM event of a given <tt>type</tt> on a DOM
|
|
|
1122 |
* <tt>element</tt>. Only HTMLEvent and MouseEvent can be
|
|
|
1123 |
* dispatched, keyboard events or UIEvent can not be dispatch
|
|
|
1124 |
* via javascript consistently.
|
|
|
1125 |
* For the "submit" event the submit() method is called.
|
|
|
1126 |
* @function ?
|
|
|
1127 |
* @param {element|string} element - Element id string or DOM element.
|
|
|
1128 |
* @param {string} type - Event type to dispatch.
|
|
|
1129 |
*/
|
|
|
1130 |
fireEvent : function(element,type)
|
|
|
1131 |
{
|
|
|
1132 |
element = $(element);
|
|
|
1133 |
if(type == "submit")
|
|
|
1134 |
return element.submit();
|
|
|
1135 |
if(document.createEvent)
|
|
|
1136 |
{
|
|
|
1137 |
if(Event.isHTMLEvent(type))
|
|
|
1138 |
{
|
|
|
1139 |
var event = document.createEvent('HTMLEvents');
|
|
|
1140 |
event.initEvent(type, true, true);
|
|
|
1141 |
}
|
|
|
1142 |
else if(Event.isMouseEvent(type))
|
|
|
1143 |
{
|
|
|
1144 |
var event = document.createEvent('MouseEvents');
|
|
|
1145 |
if (event.initMouseEvent)
|
|
|
1146 |
{
|
|
|
1147 |
event.initMouseEvent(type,true,true,
|
|
|
1148 |
document.defaultView, 1, 0, 0, 0, 0, false,
|
|
|
1149 |
false, false, false, 0, null);
|
|
|
1150 |
}
|
|
|
1151 |
else
|
|
|
1152 |
{
|
|
|
1153 |
// Safari
|
|
|
1154 |
// TODO we should be initialising other mouse-event related attributes here
|
|
|
1155 |
event.initEvent(type, true, true);
|
|
|
1156 |
}
|
|
|
1157 |
}
|
|
|
1158 |
element.dispatchEvent(event);
|
|
|
1159 |
}
|
|
|
1160 |
else if(document.createEventObject)
|
|
|
1161 |
{
|
|
|
1162 |
var evObj = document.createEventObject();
|
|
|
1163 |
element.fireEvent('on'+type, evObj);
|
|
|
1164 |
}
|
|
|
1165 |
else if(typeof(element['on'+type]) == "function")
|
|
|
1166 |
element['on'+type]();
|
|
|
1167 |
}
|
|
|
1168 |
});
|
|
|
1169 |
|
|
|
1170 |
|
|
|
1171 |
/**
|
|
|
1172 |
* Extension to
|
|
|
1173 |
* <a href="http://www.prototypejs.org/api/date" target="_blank">Prototype's Date</a>
|
|
|
1174 |
* @namespace Date
|
|
|
1175 |
*/
|
|
|
1176 |
Object.extend(Date.prototype,
|
|
|
1177 |
{
|
|
|
1178 |
/**
|
|
|
1179 |
* SimpleFormat
|
|
|
1180 |
* @function ?
|
|
|
1181 |
* @param {string} format - TODO
|
|
|
1182 |
* @param {string} data - TODO
|
|
|
1183 |
* @returns TODO
|
|
|
1184 |
*/
|
|
|
1185 |
SimpleFormat: function(format, data)
|
|
|
1186 |
{
|
|
|
1187 |
data = data || {};
|
|
|
1188 |
var bits = new Array();
|
|
|
1189 |
bits['d'] = this.getDate();
|
|
|
1190 |
bits['dd'] = String(this.getDate()).zerofill(2);
|
|
|
1191 |
|
|
|
1192 |
bits['M'] = this.getMonth()+1;
|
|
|
1193 |
bits['MM'] = String(this.getMonth()+1).zerofill(2);
|
|
|
1194 |
if(data.AbbreviatedMonthNames)
|
|
|
1195 |
bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()];
|
|
|
1196 |
if(data.MonthNames)
|
|
|
1197 |
bits['MMMM'] = data.MonthNames[this.getMonth()];
|
|
|
1198 |
var yearStr = "" + this.getFullYear();
|
|
|
1199 |
yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
|
|
|
1200 |
bits['yyyy'] = yearStr;
|
|
|
1201 |
bits['yy'] = bits['yyyy'].toString().substr(2,2);
|
|
|
1202 |
|
|
|
1203 |
// do some funky regexs to replace the format string
|
|
|
1204 |
// with the real values
|
|
|
1205 |
var frm = new String(format);
|
|
|
1206 |
for (var sect in bits)
|
|
|
1207 |
{
|
|
|
1208 |
var reg = new RegExp("\\b"+sect+"\\b" ,"g");
|
|
|
1209 |
frm = frm.replace(reg, bits[sect]);
|
|
|
1210 |
}
|
|
|
1211 |
return frm;
|
|
|
1212 |
},
|
|
|
1213 |
|
|
|
1214 |
/**
|
|
|
1215 |
* toISODate
|
|
|
1216 |
* @function {string} ?
|
|
|
1217 |
* @returns TODO
|
|
|
1218 |
*/
|
|
|
1219 |
toISODate : function()
|
|
|
1220 |
{
|
|
|
1221 |
var y = this.getFullYear();
|
|
|
1222 |
var m = String(this.getMonth() + 1).zerofill(2);
|
|
|
1223 |
var d = String(this.getDate()).zerofill(2);
|
|
|
1224 |
return String(y) + String(m) + String(d);
|
|
|
1225 |
}
|
|
|
1226 |
});
|
|
|
1227 |
|
|
|
1228 |
Object.extend(Date,
|
|
|
1229 |
{
|
|
|
1230 |
/**
|
|
|
1231 |
* SimpleParse
|
|
|
1232 |
* @function ?
|
|
|
1233 |
* @param {string} format - TODO
|
|
|
1234 |
* @param {string} data - TODO
|
|
|
1235 |
* @returns TODO
|
|
|
1236 |
*/
|
|
|
1237 |
SimpleParse: function(value, format)
|
|
|
1238 |
{
|
|
|
1239 |
val=String(value);
|
|
|
1240 |
format=String(format);
|
|
|
1241 |
|
|
|
1242 |
if(val.length <= 0) return null;
|
|
|
1243 |
|
|
|
1244 |
if(format.length <= 0) return new Date(value);
|
|
|
1245 |
|
|
|
1246 |
var isInteger = function (val)
|
|
|
1247 |
{
|
|
|
1248 |
var digits="1234567890";
|
|
|
1249 |
for (var i=0; i < val.length; i++)
|
|
|
1250 |
{
|
|
|
1251 |
if (digits.indexOf(val.charAt(i))==-1) { return false; }
|
|
|
1252 |
}
|
|
|
1253 |
return true;
|
|
|
1254 |
};
|
|
|
1255 |
|
|
|
1256 |
var getInt = function(str,i,minlength,maxlength)
|
|
|
1257 |
{
|
|
|
1258 |
for (var x=maxlength; x>=minlength; x--)
|
|
|
1259 |
{
|
|
|
1260 |
var token=str.substring(i,i+x);
|
|
|
1261 |
if (token.length < minlength) { return null; }
|
|
|
1262 |
if (isInteger(token)) { return token; }
|
|
|
1263 |
}
|
|
|
1264 |
return null;
|
|
|
1265 |
};
|
|
|
1266 |
|
|
|
1267 |
var i_val=0;
|
|
|
1268 |
var i_format=0;
|
|
|
1269 |
var c="";
|
|
|
1270 |
var token="";
|
|
|
1271 |
var token2="";
|
|
|
1272 |
var x,y;
|
|
|
1273 |
var now=new Date();
|
|
|
1274 |
var year=now.getFullYear();
|
|
|
1275 |
var month=now.getMonth()+1;
|
|
|
1276 |
var date=1;
|
|
|
1277 |
|
|
|
1278 |
while (i_format < format.length)
|
|
|
1279 |
{
|
|
|
1280 |
// Get next token from format string
|
|
|
1281 |
c=format.charAt(i_format);
|
|
|
1282 |
token="";
|
|
|
1283 |
while ((format.charAt(i_format)==c) && (i_format < format.length))
|
|
|
1284 |
{
|
|
|
1285 |
token += format.charAt(i_format++);
|
|
|
1286 |
}
|
|
|
1287 |
|
|
|
1288 |
// Extract contents of value based on format token
|
|
|
1289 |
if (token=="yyyy" || token=="yy" || token=="y")
|
|
|
1290 |
{
|
|
|
1291 |
if (token=="yyyy") { x=4;y=4; }
|
|
|
1292 |
if (token=="yy") { x=2;y=2; }
|
|
|
1293 |
if (token=="y") { x=2;y=4; }
|
|
|
1294 |
year=getInt(val,i_val,x,y);
|
|
|
1295 |
if (year==null) { return null; }
|
|
|
1296 |
i_val += year.length;
|
|
|
1297 |
if (year.length==2)
|
|
|
1298 |
{
|
|
|
1299 |
if (year > 70) { year=1900+(year-0); }
|
|
|
1300 |
else { year=2000+(year-0); }
|
|
|
1301 |
}
|
|
|
1302 |
}
|
|
|
1303 |
|
|
|
1304 |
else if (token=="MM"||token=="M")
|
|
|
1305 |
{
|
|
|
1306 |
month=getInt(val,i_val,token.length,2);
|
|
|
1307 |
if(month==null||(month<1)||(month>12)){return null;}
|
|
|
1308 |
i_val+=month.length;
|
|
|
1309 |
}
|
|
|
1310 |
else if (token=="dd"||token=="d")
|
|
|
1311 |
{
|
|
|
1312 |
date=getInt(val,i_val,token.length,2);
|
|
|
1313 |
if(date==null||(date<1)||(date>31)){return null;}
|
|
|
1314 |
i_val+=date.length;
|
|
|
1315 |
}
|
|
|
1316 |
else
|
|
|
1317 |
{
|
|
|
1318 |
if (val.substring(i_val,i_val+token.length)!=token) {return null;}
|
|
|
1319 |
else {i_val+=token.length;}
|
|
|
1320 |
}
|
|
|
1321 |
}
|
|
|
1322 |
|
|
|
1323 |
// If there are any trailing characters left in the value, it doesn't match
|
|
|
1324 |
if (i_val != val.length) { return null; }
|
|
|
1325 |
|
|
|
1326 |
// Is date valid for month?
|
|
|
1327 |
if (month==2)
|
|
|
1328 |
{
|
|
|
1329 |
// Check for leap year
|
|
|
1330 |
if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
|
|
|
1331 |
if (date > 29){ return null; }
|
|
|
1332 |
}
|
|
|
1333 |
else { if (date > 28) { return null; } }
|
|
|
1334 |
}
|
|
|
1335 |
|
|
|
1336 |
if ((month==4)||(month==6)||(month==9)||(month==11))
|
|
|
1337 |
{
|
|
|
1338 |
if (date > 30) { return null; }
|
|
|
1339 |
}
|
|
|
1340 |
|
|
|
1341 |
var newdate=new Date(year,month-1,date, 0, 0, 0);
|
|
|
1342 |
return newdate;
|
|
|
1343 |
}
|
|
|
1344 |
});
|
|
|
1345 |
|
|
|
1346 |
/**
|
|
|
1347 |
* Prado utilities for effects.
|
|
|
1348 |
* @object Prado.Effect
|
|
|
1349 |
*/
|
|
|
1350 |
Prado.Effect =
|
|
|
1351 |
{
|
|
|
1352 |
/**
|
|
|
1353 |
* Highlights an element
|
|
|
1354 |
* @function ?
|
|
|
1355 |
* @param {element} element - DOM element to highlight
|
|
|
1356 |
* @param {optional object} options - Highlight options
|
|
|
1357 |
*/
|
|
|
1358 |
Highlight : function (element,options)
|
|
|
1359 |
{
|
|
|
1360 |
new Effect.Highlight(element,options);
|
|
|
1361 |
}
|
|
|
1362 |
};
|