summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/extended
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/extended')
-rw-r--r--framework/Web/Javascripts/extended/event.js137
-rw-r--r--framework/Web/Javascripts/extended/string.js60
-rw-r--r--framework/Web/Javascripts/extended/util.js4
3 files changed, 169 insertions, 32 deletions
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js
index b6dccf3b..fc1c447b 100644
--- a/framework/Web/Javascripts/extended/event.js
+++ b/framework/Web/Javascripts/extended/event.js
@@ -1,45 +1,137 @@
-Object.extend(Event, {
- OnLoad : function (fn) {
+/**
+ * @class Event extensions.
+ */
+Object.extend(Event,
+{
+ /**
+ * Register a function to be executed when the page is loaded.
+ * Note that the page is only loaded if all resources (e.g. images)
+ * are loaded.
+ *
+ * Example: Show an alert box with message "Page Loaded!" when the
+ * page finished loading.
+ * <code>
+ * Event.OnLoad(function(){ alert("Page Loaded!"); });
+ * </code>
+ *
+ * @param {Function} function to execute when page is loaded.
+ */
+ OnLoad : function (fn)
+ {
// opera onload is in document, not window
- var w = document.addEventListener && !window.addEventListener ? document : window;
+ var w = document.addEventListener &&
+ !window.addEventListener ? document : window;
Event.__observe(w,'load',fn);
},
- observe: function(elements, name, observer, useCapture) {
- if(!isList(elements))
- return this.__observe(elements, name, observer, useCapture);
- for(var i=0; i<elements.length; i++)
- this.__observe(elements[i], name, observer, useCapture);
- },
- __observe: function(element, name, observer, useCapture) {
- var element = $(element);
- useCapture = useCapture || false;
+
+ /**
+ * Adds the specified event listener function to the set of
+ * listeners registered on given element to handle events of the
+ * specified type. If <tt>useCapture</tt> is <tt>true</tt>, the
+ * listener is registered as a capturing event listener. If
+ * <tt>useCapture</tt> is <tt>false</tt>, it is registered as a
+ * normal event listener.
+ *
+ * <tt>Event.observe</tt> may be called multiple times to register
+ * multiple event handlers for the same type of event on the
+ * same nodes. Note, however, that the DOM makes no guarantees
+ * about the order in which multiple event handlers will be invoked.
+ *
+ * Example: Show an alert box with message "Clicked!" when a link
+ * with ID "link1" is clicked.
+ * <code>
+ * var link1_clicked = function()
+ * {
+ * alert("Clicked!");
+ * };
+ * Event.observe("link1", "click", link1_clicked);
+ * </code>
+ *
+ * @param {Object} element id string, DOM Element, or an Array
+ * of element ids or elements.
+ * @param {String} The type of event for which the event listener
+ * is to be invoked. For example, "load", "click", or "mousedown".
+ * @param {Function} The event listener function that will be
+ * invoked when an event of the specified type is dispatched to
+ * this Document node.
+ * @param {Boolean} If true, the specified listener is to be
+ * invoked only during the capturing phase of event propagation.
+ * The more common value of <tt>false</tt> means that the listener
+ * will not be invoked during the capturing phase but instead will
+ * be invoked when this node is the actual event target or when the
+ * event bubbles up to this node from its original target.
+ */
+ observe: function(elements, name, observer, useCapture)
+ {
+ if(!isList(elements))
+ return this.__observe(elements, name, observer, useCapture);
+ for(var i=0; i<elements.length; i++)
+ this.__observe(elements[i], name, observer, useCapture);
+ },
+
+ /**
+ * Register event listeners.
+ * @private
+ */
+ __observe: function(element, name, observer, useCapture)
+ {
+ var element = $(element);
+ useCapture = useCapture || false;
- if (name == 'keypress' &&
- ((navigator.appVersion.indexOf('AppleWebKit') > 0)
- || element.attachEvent))
- name = 'keydown';
+ if (name == 'keypress' &&
+ ((navigator.appVersion.indexOf('AppleWebKit') > 0)
+ || element.attachEvent))
+ name = 'keydown';
- this._observeAndCache(element, name, observer, useCapture);
- },
- keyCode : function(e)
+ this._observeAndCache(element, name, observer, useCapture);
+ },
+
+ /**
+ * @param {Event} a keyboard event
+ * @return {Number} the Unicode character code generated by the key
+ * that was struck.
+ */
+ keyCode : function(e)
{
return e.keyCode != null ? e.keyCode : e.charCode
},
+ /**
+ * @param {String} event type or event name.
+ * @return {Boolean} true if event type is of HTMLEvent, false
+ * otherwise
+ */
isHTMLEvent : function(type)
{
- var events = ['abort', 'blur', 'change', 'error', 'focus', 'load', 'reset', 'resize', 'scroll', 'select', 'submit', 'unload'];
+ var events = ['abort', 'blur', 'change', 'error', 'focus',
+ 'load', 'reset', 'resize', 'scroll', 'select',
+ 'submit', 'unload'];
return events.include(type);
},
+ /**
+ * @param {String} event type or event name
+ * @return {Boolean} true if event type is of MouseEvent,
+ * false otherwise
+ */
isMouseEvent : function(type)
{
- var events = ['click', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup'];
+ var events = ['click', 'mousedown', 'mousemove', 'mouseout',
+ 'mouseover', 'mouseup'];
return events.include(type);
},
+ /**
+ * Dispatch the DOM event of a given <tt>type</tt> on a DOM
+ * <tt>element</tt>. Only HTMLEvent and MouseEvent can be
+ * dispatched, keyboard events or UIEvent can not be dispatch
+ * via javascript.
+ * @param {Object} element id string or a DOM element.
+ * @param {String} event type to dispatch.
+ */
fireEvent : function(element,type)
{
+ element = $(element);
if(document.createEvent)
{
if(Event.isHTMLEvent(type))
@@ -51,7 +143,8 @@ Object.extend(Event, {
{
var event = document.createEvent('MouseEvents');
event.initMouseEvent(type,true,true,
- document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
+ document.defaultView, 1, 0, 0, 0, 0, false,
+ false, false, false, 0, null);
}
else
{
diff --git a/framework/Web/Javascripts/extended/string.js b/framework/Web/Javascripts/extended/string.js
index e265edf4..46274256 100644
--- a/framework/Web/Javascripts/extended/string.js
+++ b/framework/Web/Javascripts/extended/string.js
@@ -1,4 +1,14 @@
+/**
+ * @class String extensions
+ */
Object.extend(String.prototype, {
+ /**
+ * @param {String} "left" to pad the string on the left, "right" to pad right.
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the left or right to satisfy minimum string length
+ */
+
pad : function(side, len, chr) {
if (!chr) chr = ' ';
var s = this;
@@ -7,26 +17,49 @@ Object.extend(String.prototype, {
return s;
},
+ /**
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the left to satisfy minimum string length
+ */
padLeft : function(len, chr) {
return this.pad('left',len,chr);
},
+ /**
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the right to satisfy minimum string length
+ */
padRight : function(len, chr) {
return this.pad('right',len,chr);
},
+ /**
+ * @param {Number} minimum string length.
+ * @return {String} append zeros to the left to satisfy minimum string length.
+ */
zerofill : function(len) {
return this.padLeft(len,'0');
},
+ /**
+ * @return {String} removed white spaces from both ends.
+ */
trim : function() {
return this.replace(/^\s+|\s+$/g,'');
},
+ /**
+ * @return {String} removed white spaces from the left end.
+ */
trimLeft : function() {
return this.replace(/^\s+/,'');
},
+ /**
+ * @return {String} removed white spaces from the right end.
+ */
trimRight : function() {
return this.replace(/\s+$/,'');
},
@@ -35,7 +68,7 @@ Object.extend(String.prototype, {
* Convert period separated function names into a function reference.
* e.g. "Prado.AJAX.Callback.Action.setValue".toFunction() will return
* the actual function Prado.AJAX.Callback.Action.setValue()
- * @return Function the corresponding function represented by the string.
+ * @return {Function} the corresponding function represented by the string.
*/
toFunction : function()
{
@@ -58,7 +91,7 @@ Object.extend(String.prototype, {
/**
* Convert a string into integer, returns null if not integer.
- * @return {integer|null} null if string does not represent an integer.
+ * @return {Number} null if string does not represent an integer.
*/
toInteger : function()
{
@@ -72,8 +105,8 @@ Object.extend(String.prototype, {
/**
* Convert a string into a double/float value. <b>Internationalization
* is not supported</b>
- * @param {string} the decimal character
- * @return {float|null} null if string does not represent a float value
+ * @param {String} the decimal character
+ * @return {Double} null if string does not represent a float value
*/
toDouble : function(decimalchar)
{
@@ -93,10 +126,10 @@ Object.extend(String.prototype, {
* of dicimal digits, grouping and decimal characters can be specified.
* <i>The currency input format is <b>very</b> strict, null will be returned if
* the pattern does not match</i>.
- * @param {string} the grouping character, default is ","
- * @param {int} number of decimal digits
- * @param {string} the decimal character, default is "."
- * @type {float|null} the currency value as float.
+ * @param {String} the grouping character, default is ","
+ * @param {Number} number of decimal digits
+ * @param {String} the decimal character, default is "."
+ * @type {Double} the currency value as float.
*/
toCurrency : function(groupchar, digits, decimalchar)
{
@@ -116,5 +149,16 @@ Object.extend(String.prototype, {
+ ((digits > 0) ? "." + m[7] : "");
var num = parseFloat(cleanInput);
return (isNaN(num) ? null : num);
+ },
+
+ /**
+ * Converts the string to a date by finding values that matches the
+ * date format pattern.
+ * @param string date format pattern, e.g. MM-dd-yyyy
+ * @return {Date} the date extracted from the string
+ */
+ toDate : function(format)
+ {
+ return Date.SimpleParse(this, format);
}
});
diff --git a/framework/Web/Javascripts/extended/util.js b/framework/Web/Javascripts/extended/util.js
index fc5ec844..86f2ae90 100644
--- a/framework/Web/Javascripts/extended/util.js
+++ b/framework/Web/Javascripts/extended/util.js
@@ -1,10 +1,10 @@
/**
- * Test if it is an object and has no constructors.
+ * @return {Boolean} true if is an object and has no constructors.
*/
function isAlien(a) { return isObject(a) && typeof a.constructor != 'function' }
/**
- * isArray?
+ * @return {Boolean}
*/
function isArray(a) { return isObject(a) && a.constructor == Array }