MDL-16784 Adding missing files to 1.9

This commit is contained in:
nicolasconnault
2008-10-08 08:12:11 +00:00
parent 1c6ec70112
commit 92e0ed3ca3
16 changed files with 40793 additions and 10 deletions
+10 -10
View File
@@ -21,15 +21,15 @@ function ajax_get_lib($libname) {
'yui_calendar' => '/lib/yui/calendar/calendar-min.js',
'yui_charts' => '/lib/yui/charts/charts-experimental-min.js',
'yui_colorpicker' => '/lib/yui/colorpicker/colorpicker-min.js',
'yui_cookie' => '/lib/yui/cookie/cookie-beta-min.js',
'yui_connection' => '/lib/yui/connection/connection-min.js',
'yui_container' => '/lib/yui/container/container-min.js',
'yui_datasource' => '/lib/yui/datasource/datasource-beta-min.js',
'yui_datatable' => '/lib/yui/datatable/datatable-beta-min.js',
'yui_cookie' => '/lib/yui/cookie/cookie-min.js',
'yui_datasource' => '/lib/yui/datasource/datasource-min.js',
'yui_datatable' => '/lib/yui/datatable/datatable-min.js',
'yui_dom' => '/lib/yui/dom/dom-min.js',
'yui_dom-event' => '/lib/yui/yahoo-dom-event/yahoo-dom-event.js',
'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop-min.js',
'yui_editor' => '/lib/yui/editor/editor-beta-min.js',
'yui_editor' => '/lib/yui/editor/editor-min.js',
'yui_element' => '/lib/yui/element/element-beta-min.js',
'yui_event' => '/lib/yui/event/event-min.js',
'yui_get' => '/lib/yui/get/get-min.js',
@@ -37,21 +37,21 @@ function ajax_get_lib($libname) {
'yui_imagecropper' => '/lib/yui/imagecropper/imagecropper-beta-min.js',
'yui_imageloader' => '/lib/yui/imageloader/imageloader-min.js',
'yui_json' => '/lib/yui/json/json-min.js',
'yui_layout' => '/lib/yui/layout/layout-beta-min.js',
'yui_layout' => '/lib/yui/layout/layout-min.js',
'yui_logger' => '/lib/yui/logger/logger-min.js',
'yui_menu' => '/lib/yui/menu/menu-min.js',
'yui_profiler' => '/lib/yui/profiler/profiler-beta-min.js',
'yui_profiler' => '/lib/yui/profiler/profiler-min.js',
'yui_profilerviewer' => '/lib/yui/profilerviewer/profilerviewer-beta-min.js',
'yui_resize' => '/lib/yui/resize/resize-beta-min.js',
'yui_resize' => '/lib/yui/resize/resize-min.js',
'yui_selector' => '/lib/yui/selector/selector-beta-min.js',
'yui_simpleeditor' => '/lib/yui/editor/simpleeditor-beta-min.js',
'yui_simpleeditor' => '/lib/yui/editor/simpleeditor-min.js',
'yui_slider' => '/lib/yui/slider/slider-min.js',
'yui_tabview' => '/lib/yui/tabview/tabview-min.js',
'yui_treeview' => '/lib/yui/treeview/treeview-min.js',
'yui_uploader' => '/lib/yui/uploader/uploader-experimental-min.js',
'yui_utilities' => '/lib/yui/utilities/utilities.js',
'yui_yuiloader' => '/lib/yui/yuiloader/yuiloader-beta-min.js',
'yui_yuitest' => '/lib/yui/yuitest/yuitest-beta-min.js',
'yui_yuiloader' => '/lib/yui/yuiloader/yuiloader-min.js',
'yui_yuitest' => '/lib/yui/yuitest/yuitest-min.js',
'ajaxcourse_blocks' => '/lib/ajax/block_classes.js',
'ajaxcourse_sections' => '/lib/ajax/section_classes.js',
'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
+424
View File
@@ -0,0 +1,424 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
/**
* Utilities for cookie management
* @namespace YAHOO.util
* @module cookie
*/
YAHOO.namespace("util");
/**
* Cookie utility.
* @class Cookie
* @static
*/
YAHOO.util.Cookie = {
//-------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------
/**
* Creates a cookie string that can be assigned into document.cookie.
* @param {String} name The name of the cookie.
* @param {String} value The value of the cookie.
* @param {encodeValue} encodeValue True to encode the value, false to leave as-is.
* @param {Object} options (Optional) Options for the cookie.
* @return {String} The formatted cookie string.
* @method _createCookieString
* @private
* @static
*/
_createCookieString : function (name /*:String*/, value /*:Variant*/, encodeValue /*:Boolean*/, options /*:Object*/) /*:String*/ {
//shortcut
var lang = YAHOO.lang;
var text /*:String*/ = encodeURIComponent(name) + "=" + (encodeValue ? encodeURIComponent(value) : value);
if (lang.isObject(options)){
//expiration date
if (options.expires instanceof Date){
text += "; expires=" + options.expires.toGMTString();
}
//path
if (lang.isString(options.path) && options.path != ""){
text += "; path=" + options.path;
}
//domain
if (lang.isString(options.domain) && options.domain != ""){
text += "; domain=" + options.domain;
}
//secure
if (options.secure === true){
text += "; secure";
}
}
return text;
},
/**
* Formats a cookie value for an object containing multiple values.
* @param {Object} hash An object of key-value pairs to create a string for.
* @return {String} A string suitable for use as a cookie value.
* @method _createCookieHash
* @private
* @static
*/
_createCookieHashString : function (hash /*:Object*/) /*:String*/ {
//shortcuts
var lang = YAHOO.lang;
if (!lang.isObject(hash)){
throw new TypeError("Cookie._createCookieHashString(): Argument must be an object.");
}
var text /*:Array*/ = new Array();
for (var key in hash){
if (lang.hasOwnProperty(hash, key) && !lang.isFunction(hash[key]) && !lang.isUndefined(hash[key])){
text.push(encodeURIComponent(key) + "=" + encodeURIComponent(String(hash[key])));
}
}
return text.join("&");
},
/**
* Parses a cookie hash string into an object.
* @param {String} text The cookie hash string to parse. The string should already be URL-decoded.
* @return {Object} An object containing entries for each cookie value.
* @method _parseCookieHash
* @private
* @static
*/
_parseCookieHash : function (text /*:String*/) /*:Object*/ {
var hashParts /*:Array*/ = text.split("&"),
hashPart /*:Array*/ = null,
hash /*:Object*/ = new Object();
if (text.length > 0){
for (var i=0, len=hashParts.length; i < len; i++){
hashPart = hashParts[i].split("=");
hash[decodeURIComponent(hashPart[0])] = decodeURIComponent(hashPart[1]);
}
}
return hash;
},
/**
* Parses a cookie string into an object representing all accessible cookies.
* @param {String} text The cookie string to parse.
* @param {Boolean} decode (Optional) Indicates if the cookie values should be decoded or not. Default is true.
* @return {Object} An object containing entries for each accessible cookie.
* @method _parseCookieString
* @private
* @static
*/
_parseCookieString : function (text /*:String*/, decode /*:Boolean*/) /*:Object*/ {
var cookies /*:Object*/ = new Object();
if (YAHOO.lang.isString(text) && text.length > 0) {
var decodeValue = (decode === false ? function(s){return s;} : decodeURIComponent);
if (/[^=]+=[^=;]?(?:; [^=]+=[^=]?)?/.test(text)){
var cookieParts /*:Array*/ = text.split(/;\s/g);
var cookieName /*:String*/ = null;
var cookieValue /*:String*/ = null;
var cookieNameValue /*:Array*/ = null;
for (var i=0, len=cookieParts.length; i < len; i++){
//check for normally-formatted cookie (name-value)
cookieNameValue = cookieParts[i].match(/([^=]+)=/i);
if (cookieNameValue instanceof Array){
cookieName = decodeURIComponent(cookieNameValue[1]);
cookieValue = decodeValue(cookieParts[i].substring(cookieNameValue[1].length+1));
} else {
//means the cookie does not have an "=", so treat it as a boolean flag
cookieName = decodeURIComponent(cookieParts[i]);
cookieValue = cookieName;
}
cookies[cookieName] = cookieValue;
}
}
}
return cookies;
},
//-------------------------------------------------------------------------
// Public Methods
//-------------------------------------------------------------------------
/**
* Returns the cookie value for the given name.
* @param {String} name The name of the cookie to retrieve.
* @param {Function} converter (Optional) A function to run on the value before returning
* it. The function is not used if the cookie doesn't exist.
* @return {Variant} If no converter is specified, returns a string or null if
* the cookie doesn't exist. If the converter is specified, returns the value
* returned from the converter or null if the cookie doesn't exist.
* @method get
* @static
*/
get : function (name /*:String*/, converter /*:Function*/) /*:Variant*/{
var lang = YAHOO.lang;
var cookies /*:Object*/ = this._parseCookieString(document.cookie);
if (!lang.isString(name) || name === ""){
throw new TypeError("Cookie.get(): Cookie name must be a non-empty string.");
}
if (lang.isUndefined(cookies[name])) {
return null;
}
if (!lang.isFunction(converter)){
return cookies[name];
} else {
return converter(cookies[name]);
}
},
/**
* Returns the value of a subcookie.
* @param {String} name The name of the cookie to retrieve.
* @param {String} subName The name of the subcookie to retrieve.
* @param {Function} converter (Optional) A function to run on the value before returning
* it. The function is not used if the cookie doesn't exist.
* @return {Variant} If the cookie doesn't exist, null is returned. If the subcookie
* doesn't exist, null if also returned. If no converter is specified and the
* subcookie exists, a string is returned. If a converter is specified and the
* subcookie exists, the value returned from the converter is returned.
* @method getSub
* @static
*/
getSub : function (name /*:String*/, subName /*:String*/, converter /*:Function*/) /*:Variant*/ {
var lang = YAHOO.lang;
var hash /*:Variant*/ = this.getSubs(name);
if (hash !== null) {
if (!lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.getSub(): Subcookie name must be a non-empty string.");
}
if (lang.isUndefined(hash[subName])){
return null;
}
if (!lang.isFunction(converter)){
return hash[subName];
} else {
return converter(hash[subName]);
}
} else {
return null;
}
},
/**
* Returns an object containing name-value pairs stored in the cookie with the given name.
* @param {String} name The name of the cookie to retrieve.
* @return {Object} An object of name-value pairs if the cookie with the given name
* exists, null if it does not.
* @method getHash
* @static
*/
getSubs : function (name /*:String*/) /*:Object*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.getSubs(): Cookie name must be a non-empty string.");
}
var cookies = this._parseCookieString(document.cookie, false);
if (YAHOO.lang.isString(cookies[name])){
return this._parseCookieHash(cookies[name]);
}
return null;
},
/**
* Removes a cookie from the machine by setting its expiration date to
* sometime in the past.
* @param {String} name The name of the cookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string),
* and secure (true/false). The expires option will be overwritten
* by the method.
* @return {String} The created cookie string.
* @method remove
* @static
*/
remove : function (name /*:String*/, options /*:Object*/) /*:String*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.remove(): Cookie name must be a non-empty string.");
}
//set options
options = options || {};
options.expires = new Date(0);
//set cookie
return this.set(name, "", options);
},
/**
* Removes a sub cookie with a given name.
* @param {String} name The name of the cookie in which the subcookie exists.
* @param {String} subName The name of the subcookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false). This must be the same settings as the original
* subcookie.
* @return {String} The created cookie string.
* @method removeSub
* @static
*/
removeSub : function(name /*:String*/, subName /*:String*/, options /*:Object*/) /*:String*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.removeSub(): Cookie name must be a non-empty string.");
}
//check subcookie name
if (!YAHOO.lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.removeSub(): Subcookie name must be a non-empty string.");
}
//get all subcookies for this cookie
var subs = this.getSubs(name);
//delete the indicated subcookie
if (YAHOO.lang.isObject(subs) && YAHOO.lang.hasOwnProperty(subs, subName)){
delete subs[subName];
//reset the cookie
return this.setSubs(name, subs, options);
} else {
return "";
}
},
/**
* Sets a cookie with a given name and value.
* @param {String} name The name of the cookie to set.
* @param {Variant} value The value to set for the cookie.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method set
* @static
*/
set : function (name /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name)){
throw new TypeError("Cookie.set(): Cookie name must be a string.");
}
if (lang.isUndefined(value)){
throw new TypeError("Cookie.set(): Value cannot be undefined.");
}
var text /*:String*/ = this._createCookieString(name, value, true, options);
document.cookie = text;
return text;
},
/**
* Sets a sub cookie with a given name to a particular value.
* @param {String} name The name of the cookie to set.
* @param {String} subName The name of the subcookie to set.
* @param {Variant} value The value to set.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSub
* @static
*/
setSub : function (name /*:String*/, subName /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name) || name === ""){
throw new TypeError("Cookie.setSub(): Cookie name must be a non-empty string.");
}
if (!lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.setSub(): Subcookie name must be a non-empty string.");
}
if (lang.isUndefined(value)){
throw new TypeError("Cookie.setSub(): Subcookie value cannot be undefined.");
}
var hash /*:Object*/ = this.getSubs(name);
if (!lang.isObject(hash)){
hash = new Object();
}
hash[subName] = value;
return this.setSubs(name, hash, options);
},
/**
* Sets a cookie with a given name to contain a hash of name-value pairs.
* @param {String} name The name of the cookie to set.
* @param {Object} value An object containing name-value pairs.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSubs
* @static
*/
setSubs : function (name /*:String*/, value /*:Object*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name)){
throw new TypeError("Cookie.setSubs(): Cookie name must be a string.");
}
if (!lang.isObject(value)){
throw new TypeError("Cookie.setSubs(): Cookie value must be an object.");
}
var text /*:String*/ = this._createCookieString(name, this._createCookieHashString(value), false, options);
document.cookie = text;
return text;
}
};
YAHOO.register("cookie", YAHOO.util.Cookie, {version: "2.6.0", build: "1321"});
+7
View File
@@ -0,0 +1,7 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
YAHOO.namespace("util");YAHOO.util.Cookie={_createCookieString:function(B,D,C,A){var F=YAHOO.lang;var E=encodeURIComponent(B)+"="+(C?encodeURIComponent(D):D);if(F.isObject(A)){if(A.expires instanceof Date){E+="; expires="+A.expires.toGMTString();}if(F.isString(A.path)&&A.path!=""){E+="; path="+A.path;}if(F.isString(A.domain)&&A.domain!=""){E+="; domain="+A.domain;}if(A.secure===true){E+="; secure";}}return E;},_createCookieHashString:function(B){var D=YAHOO.lang;if(!D.isObject(B)){throw new TypeError("Cookie._createCookieHashString(): Argument must be an object.");}var C=new Array();for(var A in B){if(D.hasOwnProperty(B,A)&&!D.isFunction(B[A])&&!D.isUndefined(B[A])){C.push(encodeURIComponent(A)+"="+encodeURIComponent(String(B[A])));}}return C.join("&");},_parseCookieHash:function(E){var D=E.split("&"),F=null,C=new Object();if(E.length>0){for(var B=0,A=D.length;B<A;B++){F=D[B].split("=");C[decodeURIComponent(F[0])]=decodeURIComponent(F[1]);}}return C;},_parseCookieString:function(I,A){var J=new Object();if(YAHOO.lang.isString(I)&&I.length>0){var B=(A===false?function(K){return K;}:decodeURIComponent);if(/[^=]+=[^=;]?(?:; [^=]+=[^=]?)?/.test(I)){var G=I.split(/;\s/g);var H=null;var C=null;var E=null;for(var D=0,F=G.length;D<F;D++){E=G[D].match(/([^=]+)=/i);if(E instanceof Array){H=decodeURIComponent(E[1]);C=B(G[D].substring(E[1].length+1));}else{H=decodeURIComponent(G[D]);C=H;}J[H]=C;}}}return J;},get:function(A,B){var D=YAHOO.lang;var C=this._parseCookieString(document.cookie);if(!D.isString(A)||A===""){throw new TypeError("Cookie.get(): Cookie name must be a non-empty string.");}if(D.isUndefined(C[A])){return null;}if(!D.isFunction(B)){return C[A];}else{return B(C[A]);}},getSub:function(A,C,B){var E=YAHOO.lang;var D=this.getSubs(A);if(D!==null){if(!E.isString(C)||C===""){throw new TypeError("Cookie.getSub(): Subcookie name must be a non-empty string.");}if(E.isUndefined(D[C])){return null;}if(!E.isFunction(B)){return D[C];}else{return B(D[C]);}}else{return null;}},getSubs:function(A){if(!YAHOO.lang.isString(A)||A===""){throw new TypeError("Cookie.getSubs(): Cookie name must be a non-empty string.");}var B=this._parseCookieString(document.cookie,false);if(YAHOO.lang.isString(B[A])){return this._parseCookieHash(B[A]);}return null;},remove:function(B,A){if(!YAHOO.lang.isString(B)||B===""){throw new TypeError("Cookie.remove(): Cookie name must be a non-empty string.");}A=A||{};A.expires=new Date(0);return this.set(B,"",A);},removeSub:function(B,D,A){if(!YAHOO.lang.isString(B)||B===""){throw new TypeError("Cookie.removeSub(): Cookie name must be a non-empty string.");}if(!YAHOO.lang.isString(D)||D===""){throw new TypeError("Cookie.removeSub(): Subcookie name must be a non-empty string.");}var C=this.getSubs(B);if(YAHOO.lang.isObject(C)&&YAHOO.lang.hasOwnProperty(C,D)){delete C[D];return this.setSubs(B,C,A);}else{return"";}},set:function(B,C,A){var E=YAHOO.lang;if(!E.isString(B)){throw new TypeError("Cookie.set(): Cookie name must be a string.");}if(E.isUndefined(C)){throw new TypeError("Cookie.set(): Value cannot be undefined.");}var D=this._createCookieString(B,C,true,A);document.cookie=D;return D;},setSub:function(B,D,C,A){var F=YAHOO.lang;if(!F.isString(B)||B===""){throw new TypeError("Cookie.setSub(): Cookie name must be a non-empty string.");}if(!F.isString(D)||D===""){throw new TypeError("Cookie.setSub(): Subcookie name must be a non-empty string.");}if(F.isUndefined(C)){throw new TypeError("Cookie.setSub(): Subcookie value cannot be undefined.");}var E=this.getSubs(B);if(!F.isObject(E)){E=new Object();}E[D]=C;return this.setSubs(B,E,A);},setSubs:function(B,C,A){var E=YAHOO.lang;if(!E.isString(B)){throw new TypeError("Cookie.setSubs(): Cookie name must be a string.");}if(!E.isObject(C)){throw new TypeError("Cookie.setSubs(): Cookie value must be an object.");}var D=this._createCookieString(B,this._createCookieHashString(C),false,A);document.cookie=D;return D;}};YAHOO.register("cookie",YAHOO.util.Cookie,{version:"2.6.0",build:"1321"});
+424
View File
@@ -0,0 +1,424 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
/**
* Utilities for cookie management
* @namespace YAHOO.util
* @module cookie
*/
YAHOO.namespace("util");
/**
* Cookie utility.
* @class Cookie
* @static
*/
YAHOO.util.Cookie = {
//-------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------
/**
* Creates a cookie string that can be assigned into document.cookie.
* @param {String} name The name of the cookie.
* @param {String} value The value of the cookie.
* @param {encodeValue} encodeValue True to encode the value, false to leave as-is.
* @param {Object} options (Optional) Options for the cookie.
* @return {String} The formatted cookie string.
* @method _createCookieString
* @private
* @static
*/
_createCookieString : function (name /*:String*/, value /*:Variant*/, encodeValue /*:Boolean*/, options /*:Object*/) /*:String*/ {
//shortcut
var lang = YAHOO.lang;
var text /*:String*/ = encodeURIComponent(name) + "=" + (encodeValue ? encodeURIComponent(value) : value);
if (lang.isObject(options)){
//expiration date
if (options.expires instanceof Date){
text += "; expires=" + options.expires.toGMTString();
}
//path
if (lang.isString(options.path) && options.path != ""){
text += "; path=" + options.path;
}
//domain
if (lang.isString(options.domain) && options.domain != ""){
text += "; domain=" + options.domain;
}
//secure
if (options.secure === true){
text += "; secure";
}
}
return text;
},
/**
* Formats a cookie value for an object containing multiple values.
* @param {Object} hash An object of key-value pairs to create a string for.
* @return {String} A string suitable for use as a cookie value.
* @method _createCookieHash
* @private
* @static
*/
_createCookieHashString : function (hash /*:Object*/) /*:String*/ {
//shortcuts
var lang = YAHOO.lang;
if (!lang.isObject(hash)){
throw new TypeError("Cookie._createCookieHashString(): Argument must be an object.");
}
var text /*:Array*/ = new Array();
for (var key in hash){
if (lang.hasOwnProperty(hash, key) && !lang.isFunction(hash[key]) && !lang.isUndefined(hash[key])){
text.push(encodeURIComponent(key) + "=" + encodeURIComponent(String(hash[key])));
}
}
return text.join("&");
},
/**
* Parses a cookie hash string into an object.
* @param {String} text The cookie hash string to parse. The string should already be URL-decoded.
* @return {Object} An object containing entries for each cookie value.
* @method _parseCookieHash
* @private
* @static
*/
_parseCookieHash : function (text /*:String*/) /*:Object*/ {
var hashParts /*:Array*/ = text.split("&"),
hashPart /*:Array*/ = null,
hash /*:Object*/ = new Object();
if (text.length > 0){
for (var i=0, len=hashParts.length; i < len; i++){
hashPart = hashParts[i].split("=");
hash[decodeURIComponent(hashPart[0])] = decodeURIComponent(hashPart[1]);
}
}
return hash;
},
/**
* Parses a cookie string into an object representing all accessible cookies.
* @param {String} text The cookie string to parse.
* @param {Boolean} decode (Optional) Indicates if the cookie values should be decoded or not. Default is true.
* @return {Object} An object containing entries for each accessible cookie.
* @method _parseCookieString
* @private
* @static
*/
_parseCookieString : function (text /*:String*/, decode /*:Boolean*/) /*:Object*/ {
var cookies /*:Object*/ = new Object();
if (YAHOO.lang.isString(text) && text.length > 0) {
var decodeValue = (decode === false ? function(s){return s;} : decodeURIComponent);
if (/[^=]+=[^=;]?(?:; [^=]+=[^=]?)?/.test(text)){
var cookieParts /*:Array*/ = text.split(/;\s/g);
var cookieName /*:String*/ = null;
var cookieValue /*:String*/ = null;
var cookieNameValue /*:Array*/ = null;
for (var i=0, len=cookieParts.length; i < len; i++){
//check for normally-formatted cookie (name-value)
cookieNameValue = cookieParts[i].match(/([^=]+)=/i);
if (cookieNameValue instanceof Array){
cookieName = decodeURIComponent(cookieNameValue[1]);
cookieValue = decodeValue(cookieParts[i].substring(cookieNameValue[1].length+1));
} else {
//means the cookie does not have an "=", so treat it as a boolean flag
cookieName = decodeURIComponent(cookieParts[i]);
cookieValue = cookieName;
}
cookies[cookieName] = cookieValue;
}
}
}
return cookies;
},
//-------------------------------------------------------------------------
// Public Methods
//-------------------------------------------------------------------------
/**
* Returns the cookie value for the given name.
* @param {String} name The name of the cookie to retrieve.
* @param {Function} converter (Optional) A function to run on the value before returning
* it. The function is not used if the cookie doesn't exist.
* @return {Variant} If no converter is specified, returns a string or null if
* the cookie doesn't exist. If the converter is specified, returns the value
* returned from the converter or null if the cookie doesn't exist.
* @method get
* @static
*/
get : function (name /*:String*/, converter /*:Function*/) /*:Variant*/{
var lang = YAHOO.lang;
var cookies /*:Object*/ = this._parseCookieString(document.cookie);
if (!lang.isString(name) || name === ""){
throw new TypeError("Cookie.get(): Cookie name must be a non-empty string.");
}
if (lang.isUndefined(cookies[name])) {
return null;
}
if (!lang.isFunction(converter)){
return cookies[name];
} else {
return converter(cookies[name]);
}
},
/**
* Returns the value of a subcookie.
* @param {String} name The name of the cookie to retrieve.
* @param {String} subName The name of the subcookie to retrieve.
* @param {Function} converter (Optional) A function to run on the value before returning
* it. The function is not used if the cookie doesn't exist.
* @return {Variant} If the cookie doesn't exist, null is returned. If the subcookie
* doesn't exist, null if also returned. If no converter is specified and the
* subcookie exists, a string is returned. If a converter is specified and the
* subcookie exists, the value returned from the converter is returned.
* @method getSub
* @static
*/
getSub : function (name /*:String*/, subName /*:String*/, converter /*:Function*/) /*:Variant*/ {
var lang = YAHOO.lang;
var hash /*:Variant*/ = this.getSubs(name);
if (hash !== null) {
if (!lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.getSub(): Subcookie name must be a non-empty string.");
}
if (lang.isUndefined(hash[subName])){
return null;
}
if (!lang.isFunction(converter)){
return hash[subName];
} else {
return converter(hash[subName]);
}
} else {
return null;
}
},
/**
* Returns an object containing name-value pairs stored in the cookie with the given name.
* @param {String} name The name of the cookie to retrieve.
* @return {Object} An object of name-value pairs if the cookie with the given name
* exists, null if it does not.
* @method getHash
* @static
*/
getSubs : function (name /*:String*/) /*:Object*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.getSubs(): Cookie name must be a non-empty string.");
}
var cookies = this._parseCookieString(document.cookie, false);
if (YAHOO.lang.isString(cookies[name])){
return this._parseCookieHash(cookies[name]);
}
return null;
},
/**
* Removes a cookie from the machine by setting its expiration date to
* sometime in the past.
* @param {String} name The name of the cookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string),
* and secure (true/false). The expires option will be overwritten
* by the method.
* @return {String} The created cookie string.
* @method remove
* @static
*/
remove : function (name /*:String*/, options /*:Object*/) /*:String*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.remove(): Cookie name must be a non-empty string.");
}
//set options
options = options || {};
options.expires = new Date(0);
//set cookie
return this.set(name, "", options);
},
/**
* Removes a sub cookie with a given name.
* @param {String} name The name of the cookie in which the subcookie exists.
* @param {String} subName The name of the subcookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false). This must be the same settings as the original
* subcookie.
* @return {String} The created cookie string.
* @method removeSub
* @static
*/
removeSub : function(name /*:String*/, subName /*:String*/, options /*:Object*/) /*:String*/ {
//check cookie name
if (!YAHOO.lang.isString(name) || name === ""){
throw new TypeError("Cookie.removeSub(): Cookie name must be a non-empty string.");
}
//check subcookie name
if (!YAHOO.lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.removeSub(): Subcookie name must be a non-empty string.");
}
//get all subcookies for this cookie
var subs = this.getSubs(name);
//delete the indicated subcookie
if (YAHOO.lang.isObject(subs) && YAHOO.lang.hasOwnProperty(subs, subName)){
delete subs[subName];
//reset the cookie
return this.setSubs(name, subs, options);
} else {
return "";
}
},
/**
* Sets a cookie with a given name and value.
* @param {String} name The name of the cookie to set.
* @param {Variant} value The value to set for the cookie.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method set
* @static
*/
set : function (name /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name)){
throw new TypeError("Cookie.set(): Cookie name must be a string.");
}
if (lang.isUndefined(value)){
throw new TypeError("Cookie.set(): Value cannot be undefined.");
}
var text /*:String*/ = this._createCookieString(name, value, true, options);
document.cookie = text;
return text;
},
/**
* Sets a sub cookie with a given name to a particular value.
* @param {String} name The name of the cookie to set.
* @param {String} subName The name of the subcookie to set.
* @param {Variant} value The value to set.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSub
* @static
*/
setSub : function (name /*:String*/, subName /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name) || name === ""){
throw new TypeError("Cookie.setSub(): Cookie name must be a non-empty string.");
}
if (!lang.isString(subName) || subName === ""){
throw new TypeError("Cookie.setSub(): Subcookie name must be a non-empty string.");
}
if (lang.isUndefined(value)){
throw new TypeError("Cookie.setSub(): Subcookie value cannot be undefined.");
}
var hash /*:Object*/ = this.getSubs(name);
if (!lang.isObject(hash)){
hash = new Object();
}
hash[subName] = value;
return this.setSubs(name, hash, options);
},
/**
* Sets a cookie with a given name to contain a hash of name-value pairs.
* @param {String} name The name of the cookie to set.
* @param {Object} value An object containing name-value pairs.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSubs
* @static
*/
setSubs : function (name /*:String*/, value /*:Object*/, options /*:Object*/) /*:String*/ {
var lang = YAHOO.lang;
if (!lang.isString(name)){
throw new TypeError("Cookie.setSubs(): Cookie name must be a string.");
}
if (!lang.isObject(value)){
throw new TypeError("Cookie.setSubs(): Cookie value must be an object.");
}
var text /*:String*/ = this._createCookieString(name, this._createCookieHashString(value), false, options);
document.cookie = text;
return text;
}
};
YAHOO.register("cookie", YAHOO.util.Cookie, {version: "2.6.0", build: "1321"});
+8994
View File
File diff suppressed because it is too large Load Diff
+28
View File
File diff suppressed because one or more lines are too long
+8891
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+6890
View File
File diff suppressed because it is too large Load Diff
+380
View File
@@ -0,0 +1,380 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
YAHOO.namespace("tool");
/**
* The YUI JavaScript profiler.
* @module profiler
* @namespace YAHOO.tool
* @requires yahoo
*/
/**
* Profiles functions in JavaScript.
* @namespace YAHOO.tool
* @class Profiler
* @static
*/
YAHOO.tool.Profiler = {
//-------------------------------------------------------------------------
// Private Properties
//-------------------------------------------------------------------------
/**
* Container object on which to put the original unprofiled methods.
* @type Object
* @private
* @static
* @property _container
*/
_container : new Object(),
/**
* Call information for functions.
* @type Object
* @private
* @static
* @property _report
*/
_report : new Object(),
//-------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------
/**
* Called when a method ends execution. Marks the start and end time of the
* method so it can calculate how long the function took to execute. Also
* updates min/max/avg calculations for the function.
* @param {String} name The name of the function to mark as stopped.
* @param {int} duration The number of milliseconds it took the function to
* execute.
* @return {Void}
* @private
* @static
*/
_saveData : function (name /*:String*/, duration /*:int*/){
//get the function data
var functionData /*:Object*/ = this._report[name];
//increment the calls
functionData.calls++;
functionData.points.push(duration);
//if it's already been called at least once, do more complex calculations
if (functionData.calls > 1) {
functionData.avg = ((functionData.avg*(functionData.calls-1))+duration)/functionData.calls;
functionData.min = Math.min(functionData.min, duration);
functionData.max = Math.max(functionData.max, duration);
} else {
functionData.avg = duration;
functionData.min = duration;
functionData.max = duration;
}
},
//-------------------------------------------------------------------------
// Reporting Methods
//-------------------------------------------------------------------------
/**
* Returns the average amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The average time it takes the function to execute.
* @static
*/
getAverage : function (name /*:String*/) /*:float*/ {
return this._report[name].avg;
},
/**
* Returns the number of times that the given function has been called.
* @param {String} name The name of the function whose data should be returned.
* @return {int} The number of times the function was called.
* @static
*/
getCallCount : function (name /*:String*/) /*:int*/ {
return this._report[name].calls;
},
/**
* Returns the maximum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The maximum time it takes the function to execute.
*/
getMax : function (name /*:String*/) /*:int*/ {
return this._report[name].max;
},
/**
* Returns the minimum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The minimum time it takes the function to execute.
*/
getMin : function (name /*:String*/) /*:int*/ {
return this._report[name].min;
},
/**
* Returns an object containing profiling data for a single function.
* The object has an entry for min, max, avg, calls, and points).
* @return {Object} An object containing profile data for a given function.
* @static
*/
getFunctionReport : function (name /*:String*/) /*:Object*/ {
return this._report[name];
},
/**
* Returns an object containing profiling data for all of the functions
* that were profiled. The object has an entry for each function and
* returns all information (min, max, average, calls, etc.) for each
* function.
* @return {Object} An object containing all profile data.
* @static
*/
getFullReport : function (filter /*:Function*/) /*:Object*/ {
filter = filter || function(){return true;};
if (YAHOO.lang.isFunction(filter)) {
var report = {};
for (var name in this._report){
if (filter(this._report[name])){
report[name] = this._report[name];
}
}
return report;
}
},
//-------------------------------------------------------------------------
// Profiling Methods
//-------------------------------------------------------------------------
/**
* Sets up a constructor for profiling, including all properties and methods on the prototype.
* @param {string} name The fully-qualified name of the function including namespace information.
* @param {Object} owner (Optional) The object that owns the function (namespace or containing object).
* @return {Void}
* @static
*/
registerConstructor : function (name /*:String*/, owner /*:Object*/) /*:Void*/ {
this.registerFunction(name, owner, true);
},
/**
* Sets up a function for profiling. It essentially overwrites the function with one
* that has instrumentation data. This method also creates an entry for the function
* in the profile report. The original function is stored on the _container object.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @param {Object} owner (Optional) The object that owns the function. If the function
* isn't global then this argument is required. This could be the namespace that
* the function belongs to, such as YAHOO.util.Dom, or the object on which it's
* a method.
* @return {Void}
* @method registerFunction
*/
registerFunction : function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{
//figure out the function name without namespacing
var funcName /*:String*/ = (name.indexOf(".") > -1 ? name.substring(name.lastIndexOf(".")+1) : name);
if (!YAHOO.lang.isObject(owner)){
owner = eval(name.substring(0, name.lastIndexOf(".")));
}
//get the method and prototype
var method /*:Function*/ = owner[funcName];
var prototype /*:Object*/ = method.prototype;
//see if the method has already been registered
if (YAHOO.lang.isFunction(method) && !method.__yuiProfiled){
//create a new slot for the original method
this._container[name] = method;
//replace the function with the profiling one
owner[funcName] = function () {
var start = new Date();
var retval = method.apply(this, arguments);
var stop = new Date();
YAHOO.tool.Profiler._saveData(name, stop-start);
return retval;
};
//copy the function properties over
YAHOO.lang.augmentObject(owner[funcName], method);
owner[funcName].__yuiProfiled = true;
owner[funcName].prototype = prototype;
this._container[name].__yuiOwner = owner;
this._container[name].__yuiFuncName = funcName;
//register prototype if necessary
if (registerPrototype) {
this.registerObject(name + ".prototype", prototype);
}
//store function information
this._report[name] = {
calls: 0,
max: 0,
min: 0,
avg: 0,
points: []
};
}
return method;
},
/**
* Sets up an object for profiling. It takes the object and looks for functions.
* When a function is found, registerMethod() is called on it. If set to recrusive
* mode, it will also setup objects found inside of this object for profiling,
* using the same methodology.
* @param {String} name The name of the object to profile (shows up in report).
* @param {Object} owner (Optional) The object represented by the name.
* @param {Boolean} recurse (Optional) Determines if subobject methods are also profiled.
* @return {Void}
* @static
*/
registerObject : function (name /*:String*/, object /*:Object*/, recurse /*:Boolean*/) /*:Void*/{
//get the object
object = (YAHOO.lang.isObject(object) ? object : eval(name));
//save the object
this._container[name] = object;
for (var prop in object) {
if (typeof object[prop] == "function"){
if (prop != "constructor" && prop != "superclass"){ //don't do constructor or superclass, it's recursive
this.registerFunction(name + "." + prop, object);
}
} else if (typeof object[prop] == "object" && recurse){
this.registerObject(name + "." + prop, object[prop], recurse);
}
}
},
/**
* Removes a constructor function from profiling. Reverses the registerConstructor() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
*/
unregisterConstructor : function(name /*:String*/) /*:Void*/{
//see if the method has been registered
if (YAHOO.lang.isFunction(this._container[name])){
//get original data
//var owner /*:Object*/ = this._container[name].__yuiOwner;
//var funcName /*:String*/ = this._container[name].__yuiFuncName;
//delete this._container[name].__yuiOwner;
//delete this._container[name].__yuiFuncName;
//replace instrumented function
//owner[funcName] = this._container[name];
//delete this._container[name];
this.unregisterFunction(name, true);
}
},
/**
* Removes function from profiling. Reverses the registerFunction() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
*/
unregisterFunction : function(name /*:String*/, unregisterPrototype /*:Boolean*/) /*:Void*/{
//see if the method has been registered
if (YAHOO.lang.isFunction(this._container[name])){
//check to see if you should unregister the prototype
if (unregisterPrototype){
this.unregisterObject(name + ".prototype", this._container[name].prototype);
}
//get original data
var owner /*:Object*/ = this._container[name].__yuiOwner;
var funcName /*:String*/ = this._container[name].__yuiFuncName;
delete this._container[name].__yuiOwner;
delete this._container[name].__yuiFuncName;
//replace instrumented function
owner[funcName] = this._container[name];
//delete supporting information
delete this._container[name];
delete this._report[name];
}
},
/**
* Unregisters an object for profiling. It takes the object and looks for functions.
* When a function is found, unregisterMethod() is called on it. If set to recrusive
* mode, it will also unregister objects found inside of this object,
* using the same methodology.
* @param {String} name The name of the object to unregister.
* @param {Boolean} recurse (Optional) Determines if subobject methods should also be
* unregistered.
* @return {Void}
* @static
*/
unregisterObject : function (name /*:String*/, recurse /*:Boolean*/) /*:Void*/{
//get the object
if (YAHOO.lang.isObject(this._container[name])){
var object = this._container[name];
for (var prop in object) {
if (typeof object[prop] == "function"){
this.unregisterFunction(name + "." + prop);
} else if (typeof object[prop] == "object" && recurse){
this.unregisterObject(name + "." + prop, recurse);
}
}
delete this._container[name];
}
}
};
YAHOO.register("profiler", YAHOO.tool.Profiler, {version: "2.6.0", build: "1321"});
+7
View File
@@ -0,0 +1,7 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
YAHOO.namespace("tool");YAHOO.tool.Profiler={_container:new Object(),_report:new Object(),_saveData:function(B,C){var A=this._report[B];A.calls++;A.points.push(C);if(A.calls>1){A.avg=((A.avg*(A.calls-1))+C)/A.calls;A.min=Math.min(A.min,C);A.max=Math.max(A.max,C);}else{A.avg=C;A.min=C;A.max=C;}},getAverage:function(A){return this._report[A].avg;},getCallCount:function(A){return this._report[A].calls;},getMax:function(A){return this._report[A].max;},getMin:function(A){return this._report[A].min;},getFunctionReport:function(A){return this._report[A];},getFullReport:function(C){C=C||function(){return true;};if(YAHOO.lang.isFunction(C)){var A={};for(var B in this._report){if(C(this._report[B])){A[B]=this._report[B];}}return A;}},registerConstructor:function(B,A){this.registerFunction(B,A,true);},registerFunction:function(name,owner,registerPrototype){var funcName=(name.indexOf(".")>-1?name.substring(name.lastIndexOf(".")+1):name);if(!YAHOO.lang.isObject(owner)){owner=eval(name.substring(0,name.lastIndexOf(".")));}var method=owner[funcName];var prototype=method.prototype;if(YAHOO.lang.isFunction(method)&&!method.__yuiProfiled){this._container[name]=method;owner[funcName]=function(){var start=new Date();var retval=method.apply(this,arguments);var stop=new Date();YAHOO.tool.Profiler._saveData(name,stop-start);return retval;};YAHOO.lang.augmentObject(owner[funcName],method);owner[funcName].__yuiProfiled=true;owner[funcName].prototype=prototype;this._container[name].__yuiOwner=owner;this._container[name].__yuiFuncName=funcName;if(registerPrototype){this.registerObject(name+".prototype",prototype);}this._report[name]={calls:0,max:0,min:0,avg:0,points:[]};}return method;},registerObject:function(name,object,recurse){object=(YAHOO.lang.isObject(object)?object:eval(name));this._container[name]=object;for(var prop in object){if(typeof object[prop]=="function"){if(prop!="constructor"&&prop!="superclass"){this.registerFunction(name+"."+prop,object);}}else{if(typeof object[prop]=="object"&&recurse){this.registerObject(name+"."+prop,object[prop],recurse);}}}},unregisterConstructor:function(A){if(YAHOO.lang.isFunction(this._container[A])){this.unregisterFunction(A,true);}},unregisterFunction:function(B,C){if(YAHOO.lang.isFunction(this._container[B])){if(C){this.unregisterObject(B+".prototype",this._container[B].prototype);}var A=this._container[B].__yuiOwner;var D=this._container[B].__yuiFuncName;delete this._container[B].__yuiOwner;delete this._container[B].__yuiFuncName;A[D]=this._container[B];delete this._container[B];delete this._report[B];}},unregisterObject:function(B,C){if(YAHOO.lang.isObject(this._container[B])){var A=this._container[B];for(var D in A){if(typeof A[D]=="function"){this.unregisterFunction(B+"."+D);}else{if(typeof A[D]=="object"&&C){this.unregisterObject(B+"."+D,C);}}}delete this._container[B];}}};YAHOO.register("profiler",YAHOO.tool.Profiler,{version:"2.6.0",build:"1321"});
+380
View File
@@ -0,0 +1,380 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
*/
YAHOO.namespace("tool");
/**
* The YUI JavaScript profiler.
* @module profiler
* @namespace YAHOO.tool
* @requires yahoo
*/
/**
* Profiles functions in JavaScript.
* @namespace YAHOO.tool
* @class Profiler
* @static
*/
YAHOO.tool.Profiler = {
//-------------------------------------------------------------------------
// Private Properties
//-------------------------------------------------------------------------
/**
* Container object on which to put the original unprofiled methods.
* @type Object
* @private
* @static
* @property _container
*/
_container : new Object(),
/**
* Call information for functions.
* @type Object
* @private
* @static
* @property _report
*/
_report : new Object(),
//-------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------
/**
* Called when a method ends execution. Marks the start and end time of the
* method so it can calculate how long the function took to execute. Also
* updates min/max/avg calculations for the function.
* @param {String} name The name of the function to mark as stopped.
* @param {int} duration The number of milliseconds it took the function to
* execute.
* @return {Void}
* @private
* @static
*/
_saveData : function (name /*:String*/, duration /*:int*/){
//get the function data
var functionData /*:Object*/ = this._report[name];
//increment the calls
functionData.calls++;
functionData.points.push(duration);
//if it's already been called at least once, do more complex calculations
if (functionData.calls > 1) {
functionData.avg = ((functionData.avg*(functionData.calls-1))+duration)/functionData.calls;
functionData.min = Math.min(functionData.min, duration);
functionData.max = Math.max(functionData.max, duration);
} else {
functionData.avg = duration;
functionData.min = duration;
functionData.max = duration;
}
},
//-------------------------------------------------------------------------
// Reporting Methods
//-------------------------------------------------------------------------
/**
* Returns the average amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The average time it takes the function to execute.
* @static
*/
getAverage : function (name /*:String*/) /*:float*/ {
return this._report[name].avg;
},
/**
* Returns the number of times that the given function has been called.
* @param {String} name The name of the function whose data should be returned.
* @return {int} The number of times the function was called.
* @static
*/
getCallCount : function (name /*:String*/) /*:int*/ {
return this._report[name].calls;
},
/**
* Returns the maximum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The maximum time it takes the function to execute.
*/
getMax : function (name /*:String*/) /*:int*/ {
return this._report[name].max;
},
/**
* Returns the minimum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The minimum time it takes the function to execute.
*/
getMin : function (name /*:String*/) /*:int*/ {
return this._report[name].min;
},
/**
* Returns an object containing profiling data for a single function.
* The object has an entry for min, max, avg, calls, and points).
* @return {Object} An object containing profile data for a given function.
* @static
*/
getFunctionReport : function (name /*:String*/) /*:Object*/ {
return this._report[name];
},
/**
* Returns an object containing profiling data for all of the functions
* that were profiled. The object has an entry for each function and
* returns all information (min, max, average, calls, etc.) for each
* function.
* @return {Object} An object containing all profile data.
* @static
*/
getFullReport : function (filter /*:Function*/) /*:Object*/ {
filter = filter || function(){return true;};
if (YAHOO.lang.isFunction(filter)) {
var report = {};
for (var name in this._report){
if (filter(this._report[name])){
report[name] = this._report[name];
}
}
return report;
}
},
//-------------------------------------------------------------------------
// Profiling Methods
//-------------------------------------------------------------------------
/**
* Sets up a constructor for profiling, including all properties and methods on the prototype.
* @param {string} name The fully-qualified name of the function including namespace information.
* @param {Object} owner (Optional) The object that owns the function (namespace or containing object).
* @return {Void}
* @static
*/
registerConstructor : function (name /*:String*/, owner /*:Object*/) /*:Void*/ {
this.registerFunction(name, owner, true);
},
/**
* Sets up a function for profiling. It essentially overwrites the function with one
* that has instrumentation data. This method also creates an entry for the function
* in the profile report. The original function is stored on the _container object.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @param {Object} owner (Optional) The object that owns the function. If the function
* isn't global then this argument is required. This could be the namespace that
* the function belongs to, such as YAHOO.util.Dom, or the object on which it's
* a method.
* @return {Void}
* @method registerFunction
*/
registerFunction : function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{
//figure out the function name without namespacing
var funcName /*:String*/ = (name.indexOf(".") > -1 ? name.substring(name.lastIndexOf(".")+1) : name);
if (!YAHOO.lang.isObject(owner)){
owner = eval(name.substring(0, name.lastIndexOf(".")));
}
//get the method and prototype
var method /*:Function*/ = owner[funcName];
var prototype /*:Object*/ = method.prototype;
//see if the method has already been registered
if (YAHOO.lang.isFunction(method) && !method.__yuiProfiled){
//create a new slot for the original method
this._container[name] = method;
//replace the function with the profiling one
owner[funcName] = function () {
var start = new Date();
var retval = method.apply(this, arguments);
var stop = new Date();
YAHOO.tool.Profiler._saveData(name, stop-start);
return retval;
};
//copy the function properties over
YAHOO.lang.augmentObject(owner[funcName], method);
owner[funcName].__yuiProfiled = true;
owner[funcName].prototype = prototype;
this._container[name].__yuiOwner = owner;
this._container[name].__yuiFuncName = funcName;
//register prototype if necessary
if (registerPrototype) {
this.registerObject(name + ".prototype", prototype);
}
//store function information
this._report[name] = {
calls: 0,
max: 0,
min: 0,
avg: 0,
points: []
};
}
return method;
},
/**
* Sets up an object for profiling. It takes the object and looks for functions.
* When a function is found, registerMethod() is called on it. If set to recrusive
* mode, it will also setup objects found inside of this object for profiling,
* using the same methodology.
* @param {String} name The name of the object to profile (shows up in report).
* @param {Object} owner (Optional) The object represented by the name.
* @param {Boolean} recurse (Optional) Determines if subobject methods are also profiled.
* @return {Void}
* @static
*/
registerObject : function (name /*:String*/, object /*:Object*/, recurse /*:Boolean*/) /*:Void*/{
//get the object
object = (YAHOO.lang.isObject(object) ? object : eval(name));
//save the object
this._container[name] = object;
for (var prop in object) {
if (typeof object[prop] == "function"){
if (prop != "constructor" && prop != "superclass"){ //don't do constructor or superclass, it's recursive
this.registerFunction(name + "." + prop, object);
}
} else if (typeof object[prop] == "object" && recurse){
this.registerObject(name + "." + prop, object[prop], recurse);
}
}
},
/**
* Removes a constructor function from profiling. Reverses the registerConstructor() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
*/
unregisterConstructor : function(name /*:String*/) /*:Void*/{
//see if the method has been registered
if (YAHOO.lang.isFunction(this._container[name])){
//get original data
//var owner /*:Object*/ = this._container[name].__yuiOwner;
//var funcName /*:String*/ = this._container[name].__yuiFuncName;
//delete this._container[name].__yuiOwner;
//delete this._container[name].__yuiFuncName;
//replace instrumented function
//owner[funcName] = this._container[name];
//delete this._container[name];
this.unregisterFunction(name, true);
}
},
/**
* Removes function from profiling. Reverses the registerFunction() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
*/
unregisterFunction : function(name /*:String*/, unregisterPrototype /*:Boolean*/) /*:Void*/{
//see if the method has been registered
if (YAHOO.lang.isFunction(this._container[name])){
//check to see if you should unregister the prototype
if (unregisterPrototype){
this.unregisterObject(name + ".prototype", this._container[name].prototype);
}
//get original data
var owner /*:Object*/ = this._container[name].__yuiOwner;
var funcName /*:String*/ = this._container[name].__yuiFuncName;
delete this._container[name].__yuiOwner;
delete this._container[name].__yuiFuncName;
//replace instrumented function
owner[funcName] = this._container[name];
//delete supporting information
delete this._container[name];
delete this._report[name];
}
},
/**
* Unregisters an object for profiling. It takes the object and looks for functions.
* When a function is found, unregisterMethod() is called on it. If set to recrusive
* mode, it will also unregister objects found inside of this object,
* using the same methodology.
* @param {String} name The name of the object to unregister.
* @param {Boolean} recurse (Optional) Determines if subobject methods should also be
* unregistered.
* @return {Void}
* @static
*/
unregisterObject : function (name /*:String*/, recurse /*:Boolean*/) /*:Void*/{
//get the object
if (YAHOO.lang.isObject(this._container[name])){
var object = this._container[name];
for (var prop in object) {
if (typeof object[prop] == "function"){
this.unregisterFunction(name + "." + prop);
} else if (typeof object[prop] == "object" && recurse){
this.unregisterObject(name + "." + prop, recurse);
}
}
delete this._container[name];
}
}
};
YAHOO.register("profiler", YAHOO.tool.Profiler, {version: "2.6.0", build: "1321"});
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+3677
View File
File diff suppressed because it is too large Load Diff