upgraded yui to 2.2.2 and yui-ext to 1.0.1a
This commit is contained in:
parent
4d9af2c691
commit
547ced6500
1992 changed files with 645731 additions and 0 deletions
158
www/extras/yui-ext/source/util/CSS.js
vendored
Normal file
158
www/extras/yui-ext/source/util/CSS.js
vendored
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.CSS
|
||||
* Utility class for manipulating CSS rules
|
||||
* @singleton
|
||||
*/
|
||||
Ext.util.CSS = function(){
|
||||
var rules = null;
|
||||
var doc = document;
|
||||
|
||||
var camelRe = /(-[a-z])/gi;
|
||||
var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
|
||||
|
||||
return {
|
||||
/**
|
||||
* Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
|
||||
* tag and appended to the HEAD of the document.
|
||||
* @param {String} cssText The text containing the css rules
|
||||
* @return {StyleSheet}
|
||||
*/
|
||||
createStyleSheet : function(cssText){
|
||||
var ss;
|
||||
if(Ext.isIE){
|
||||
ss = doc.createStyleSheet();
|
||||
ss.cssText = cssText;
|
||||
}else{
|
||||
var head = doc.getElementsByTagName("head")[0];
|
||||
var rules = doc.createElement("style");
|
||||
rules.setAttribute("type", "text/css");
|
||||
try{
|
||||
rules.appendChild(doc.createTextNode(cssText));
|
||||
}catch(e){
|
||||
rules.cssText = cssText;
|
||||
}
|
||||
head.appendChild(rules);
|
||||
ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
|
||||
}
|
||||
this.cacheStyleSheet(ss);
|
||||
return ss;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a style or link tag by id
|
||||
* @param {String} id The id of the tag
|
||||
*/
|
||||
removeStyleSheet : function(id){
|
||||
var existing = doc.getElementById(id);
|
||||
if(existing){
|
||||
existing.parentNode.removeChild(existing);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Dynamically swaps an existing stylesheet reference for a new one
|
||||
* @param {String} id The id of an existing link tag to remove
|
||||
* @param {String} url The href of the new stylesheet to include
|
||||
*/
|
||||
swapStyleSheet : function(id, url){
|
||||
this.removeStyleSheet(id);
|
||||
var ss = doc.createElement("link");
|
||||
ss.setAttribute("rel", "stylesheet");
|
||||
ss.setAttribute("type", "text/css");
|
||||
ss.setAttribute("id", id);
|
||||
ss.setAttribute("href", url);
|
||||
doc.getElementsByTagName("head")[0].appendChild(ss);
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh the rule cache if you have dynamically added stylesheets
|
||||
* @return {Object} An object (hash) of rules indexed by selector
|
||||
*/
|
||||
refreshCache : function(){
|
||||
return this.getRules(true);
|
||||
},
|
||||
|
||||
// private
|
||||
cacheStyleSheet : function(ss){
|
||||
if(!rules){
|
||||
rules = {};
|
||||
}
|
||||
try{// try catch for cross domain access issue
|
||||
var ssRules = ss.cssRules || ss.rules;
|
||||
for(var j = ssRules.length-1; j >= 0; --j){
|
||||
rules[ssRules[j].selectorText] = ssRules[j];
|
||||
}
|
||||
}catch(e){}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets all css rules for the document
|
||||
* @param {Boolean} refreshCache true to refresh the internal cache
|
||||
* @return {Object} An object (hash) of rules indexed by selector
|
||||
*/
|
||||
getRules : function(refreshCache){
|
||||
if(rules == null || refreshCache){
|
||||
rules = {};
|
||||
var ds = doc.styleSheets;
|
||||
for(var i =0, len = ds.length; i < len; i++){
|
||||
try{
|
||||
this.cacheStyleSheet(ds[i]);
|
||||
}catch(e){}
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets an an individual CSS rule by selector(s)
|
||||
* @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
|
||||
* @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
|
||||
* @return {CSSRule} The CSS rule or null if one is not found
|
||||
*/
|
||||
getRule : function(selector, refreshCache){
|
||||
var rs = this.getRules(refreshCache);
|
||||
if(!(selector instanceof Array)){
|
||||
return rs[selector];
|
||||
}
|
||||
for(var i = 0; i < selector.length; i++){
|
||||
if(rs[selector[i]]){
|
||||
return rs[selector[i]];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Updates a rule property
|
||||
* @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
|
||||
* @param {String} property The css property
|
||||
* @param {String} value The new value for the property
|
||||
* @return {Boolean} true If a rule was found and updated
|
||||
*/
|
||||
updateRule : function(selector, property, value){
|
||||
if(!(selector instanceof Array)){
|
||||
var rule = this.getRule(selector);
|
||||
if(rule){
|
||||
rule.style[property.replace(camelRe, camelFn)] = value;
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
for(var i = 0; i < selector.length; i++){
|
||||
if(this.updateRule(selector[i], property, value)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}();
|
||||
170
www/extras/yui-ext/source/util/ClickRepeater.js
vendored
Normal file
170
www/extras/yui-ext/source/util/ClickRepeater.js
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
@class Ext.util.ClickRepeater
|
||||
@extends Ext.util.Observable
|
||||
|
||||
A wrapper class which can be applied to any element. Fires a "click" event while the
|
||||
mouse is pressed. The interval between firings may be specified in the config but
|
||||
defaults to 10 milliseconds.
|
||||
|
||||
Optionally, a CSS class may be applied to the element during the time it is pressed.
|
||||
|
||||
@cfg {String/HTMLElement/Element} el The element to act as a button.
|
||||
@cfg {Number} delay The initial delay before the repeating event begins firing.
|
||||
Similar to an autorepeat key delay.
|
||||
@cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
|
||||
@cfg {String} pressClass A CSS class name to be applied to the element while pressed.
|
||||
@cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
|
||||
"interval" and "delay" are ignored. "immediate" is honored.
|
||||
@cfg {Boolean} preventDefault True to prevent the default click event
|
||||
@cfg {Boolean} stopDefault True to stop the default click event
|
||||
|
||||
@history
|
||||
2007-02-02 jvs Original code contributed by Nige "Animal" White
|
||||
2007-02-02 jvs Renamed to ClickRepeater
|
||||
2007-02-03 jvs Modifications for FF Mac and Safari
|
||||
|
||||
@constructor
|
||||
@param {String/HTMLElement/Element} el The element to listen on
|
||||
@param {Object} config
|
||||
*/
|
||||
Ext.util.ClickRepeater = function(el, config)
|
||||
{
|
||||
this.el = Ext.get(el);
|
||||
this.el.unselectable();
|
||||
|
||||
Ext.apply(this, config);
|
||||
|
||||
this.addEvents({
|
||||
/**
|
||||
* @event mousedown
|
||||
* Fires when the mouse button is depressed.
|
||||
* @param {Ext.util.ClickRepeater} this
|
||||
*/
|
||||
"mousedown" : true,
|
||||
/**
|
||||
* @event click
|
||||
* Fires on a specified interval during the time the element is pressed.
|
||||
* @param {Ext.util.ClickRepeater} this
|
||||
*/
|
||||
"click" : true,
|
||||
/**
|
||||
* @event mouseup
|
||||
* Fires when the mouse key is released.
|
||||
* @param {Ext.util.ClickRepeater} this
|
||||
*/
|
||||
"mouseup" : true
|
||||
});
|
||||
|
||||
this.el.on("mousedown", this.handleMouseDown, this);
|
||||
if(this.preventDefault || this.stopDefault){
|
||||
this.el.on("click", function(e){
|
||||
if(this.preventDefault){
|
||||
e.preventDefault();
|
||||
}
|
||||
if(this.stopDefault){
|
||||
e.stopEvent();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
// allow inline handler
|
||||
if(this.handler){
|
||||
this.on("click", this.handler, this.scope || this);
|
||||
}
|
||||
|
||||
Ext.util.ClickRepeater.superclass.constructor.call(this);
|
||||
};
|
||||
|
||||
Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
|
||||
interval : 20,
|
||||
delay: 250,
|
||||
preventDefault : true,
|
||||
stopDefault : false,
|
||||
timer : 0,
|
||||
docEl : Ext.get(document),
|
||||
|
||||
// private
|
||||
handleMouseDown : function(){
|
||||
clearTimeout(this.timer);
|
||||
this.el.blur();
|
||||
if(this.pressClass){
|
||||
this.el.addClass(this.pressClass);
|
||||
}
|
||||
this.mousedownTime = new Date();
|
||||
|
||||
this.docEl.on("mouseup", this.handleMouseUp, this);
|
||||
this.el.on("mouseout", this.handleMouseOut, this);
|
||||
|
||||
this.fireEvent("mousedown", this);
|
||||
this.fireEvent("click", this);
|
||||
|
||||
this.timer = this.click.defer(this.delay || this.interval, this);
|
||||
},
|
||||
|
||||
// private
|
||||
click : function(){
|
||||
this.fireEvent("click", this);
|
||||
this.timer = this.click.defer(this.getInterval(), this);
|
||||
},
|
||||
|
||||
// private
|
||||
getInterval: function(){
|
||||
if(!this.accelerate){
|
||||
return this.interval;
|
||||
}
|
||||
var pressTime = this.mousedownTime.getElapsed();
|
||||
if(pressTime < 500){
|
||||
return 400;
|
||||
}else if(pressTime < 1700){
|
||||
return 320;
|
||||
}else if(pressTime < 2600){
|
||||
return 250;
|
||||
}else if(pressTime < 3500){
|
||||
return 180;
|
||||
}else if(pressTime < 4400){
|
||||
return 140;
|
||||
}else if(pressTime < 5300){
|
||||
return 80;
|
||||
}else if(pressTime < 6200){
|
||||
return 50;
|
||||
}else{
|
||||
return 10;
|
||||
}
|
||||
},
|
||||
|
||||
// private
|
||||
handleMouseOut : function(){
|
||||
clearTimeout(this.timer);
|
||||
if(this.pressClass){
|
||||
this.el.removeClass(this.pressClass);
|
||||
}
|
||||
this.el.on("mouseover", this.handleMouseReturn, this);
|
||||
},
|
||||
|
||||
// private
|
||||
handleMouseReturn : function(){
|
||||
this.el.un("mouseover", this.handleMouseReturn);
|
||||
if(this.pressClass){
|
||||
this.el.addClass(this.pressClass);
|
||||
}
|
||||
this.click();
|
||||
},
|
||||
|
||||
// private
|
||||
handleMouseUp : function(){
|
||||
clearTimeout(this.timer);
|
||||
this.el.un("mouseover", this.handleMouseReturn);
|
||||
this.el.un("mouseout", this.handleMouseOut);
|
||||
this.docEl.un("mouseup", this.handleMouseUp);
|
||||
this.el.removeClass(this.pressClass);
|
||||
this.fireEvent("mouseup", this);
|
||||
}
|
||||
});
|
||||
711
www/extras/yui-ext/source/util/Date.js
vendored
Normal file
711
www/extras/yui-ext/source/util/Date.js
vendored
Normal file
|
|
@ -0,0 +1,711 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Date
|
||||
*
|
||||
* The date parsing and format syntax is a subset of
|
||||
* <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
|
||||
* supported will provide results equivalent to their PHP versions.
|
||||
*
|
||||
* Following is the list of all currently supported formats:
|
||||
*<pre>
|
||||
Sample date:
|
||||
'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
|
||||
|
||||
Format Output Description
|
||||
------ ---------- --------------------------------------------------------------
|
||||
d 10 Day of the month, 2 digits with leading zeros
|
||||
D Wed A textual representation of a day, three letters
|
||||
j 10 Day of the month without leading zeros
|
||||
l Wednesday A full textual representation of the day of the week
|
||||
S th English ordinal day of month suffix, 2 chars (use with j)
|
||||
w 3 Numeric representation of the day of the week
|
||||
z 9 The julian date, or day of the year (0-365)
|
||||
W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
|
||||
F January A full textual representation of the month
|
||||
m 01 Numeric representation of a month, with leading zeros
|
||||
M Jan Month name abbreviation, three letters
|
||||
n 1 Numeric representation of a month, without leading zeros
|
||||
t 31 Number of days in the given month
|
||||
L 0 Whether it's a leap year (1 if it is a leap year, else 0)
|
||||
Y 2007 A full numeric representation of a year, 4 digits
|
||||
y 07 A two digit representation of a year
|
||||
a pm Lowercase Ante meridiem and Post meridiem
|
||||
A PM Uppercase Ante meridiem and Post meridiem
|
||||
g 3 12-hour format of an hour without leading zeros
|
||||
G 15 24-hour format of an hour without leading zeros
|
||||
h 03 12-hour format of an hour with leading zeros
|
||||
H 15 24-hour format of an hour with leading zeros
|
||||
i 05 Minutes with leading zeros
|
||||
s 01 Seconds, with leading zeros
|
||||
O -0600 Difference to Greenwich time (GMT) in hours
|
||||
T CST Timezone setting of the machine running the code
|
||||
Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
|
||||
</pre>
|
||||
*
|
||||
* Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
|
||||
* <pre><code>
|
||||
var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
|
||||
document.write(dt.format('Y-m-d')); //2007-01-10
|
||||
document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
|
||||
document.write(dt.format('l, \\t\\he dS of F Y h:i:s A')); //Wednesday, the 10th of January 2007 03:05:01 PM
|
||||
</code></pre>
|
||||
*
|
||||
* Here are some standard date/time patterns that you might find helpful. They
|
||||
* are not part of the source of Date.js, but to use them you can simply copy this
|
||||
* block of code into any script that is included after Date.js and they will also become
|
||||
* globally available on the Date object. Feel free to add or remove patterns as needed in your code.
|
||||
* <pre><code>
|
||||
Date.patterns = {
|
||||
ISO8601Long:"Y-m-d H:i:s",
|
||||
ISO8601Short:"Y-m-d",
|
||||
ShortDate: "n/j/Y",
|
||||
LongDate: "l, F d, Y",
|
||||
FullDateTime: "l, F d, Y g:i:s A",
|
||||
MonthDay: "F d",
|
||||
ShortTime: "g:i A",
|
||||
LongTime: "g:i:s A",
|
||||
SortableDateTime: "Y-m-d\\TH:i:s",
|
||||
UniversalSortableDateTime: "Y-m-d H:i:sO",
|
||||
YearMonth: "F, Y"
|
||||
};
|
||||
</code></pre>
|
||||
*
|
||||
* Example usage:
|
||||
* <pre><code>
|
||||
var dt = new Date();
|
||||
document.write(dt.format(Date.patterns.ShortDate));
|
||||
</code></pre>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Most of the date-formatting functions below are the excellent work of Baron Schwartz.
|
||||
* They generate precompiled functions from date formats instead of parsing and
|
||||
* processing the pattern every time you format a date. These functions are available
|
||||
* on every Date object (any javascript function).
|
||||
*
|
||||
* The original article and download are here:
|
||||
* http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
|
||||
*
|
||||
*/
|
||||
|
||||
// private
|
||||
Date.parseFunctions = {count:0};
|
||||
// private
|
||||
Date.parseRegexes = [];
|
||||
// private
|
||||
Date.formatFunctions = {count:0};
|
||||
|
||||
// private
|
||||
Date.prototype.dateFormat = function(format) {
|
||||
if (Date.formatFunctions[format] == null) {
|
||||
Date.createNewFormat(format);
|
||||
}
|
||||
var func = Date.formatFunctions[format];
|
||||
return this[func]();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Formats a date given the supplied format string
|
||||
* @param {String} format The format string
|
||||
* @return {String} The formatted date
|
||||
* @method
|
||||
*/
|
||||
Date.prototype.format = Date.prototype.dateFormat;
|
||||
|
||||
// private
|
||||
Date.createNewFormat = function(format) {
|
||||
var funcName = "format" + Date.formatFunctions.count++;
|
||||
Date.formatFunctions[format] = funcName;
|
||||
var code = "Date.prototype." + funcName + " = function(){return ";
|
||||
var special = false;
|
||||
var ch = '';
|
||||
for (var i = 0; i < format.length; ++i) {
|
||||
ch = format.charAt(i);
|
||||
if (!special && ch == "\\") {
|
||||
special = true;
|
||||
}
|
||||
else if (special) {
|
||||
special = false;
|
||||
code += "'" + String.escape(ch) + "' + ";
|
||||
}
|
||||
else {
|
||||
code += Date.getFormatCode(ch);
|
||||
}
|
||||
}
|
||||
eval(code.substring(0, code.length - 3) + ";}");
|
||||
};
|
||||
|
||||
// private
|
||||
Date.getFormatCode = function(character) {
|
||||
switch (character) {
|
||||
case "d":
|
||||
return "String.leftPad(this.getDate(), 2, '0') + ";
|
||||
case "D":
|
||||
return "Date.dayNames[this.getDay()].substring(0, 3) + ";
|
||||
case "j":
|
||||
return "this.getDate() + ";
|
||||
case "l":
|
||||
return "Date.dayNames[this.getDay()] + ";
|
||||
case "S":
|
||||
return "this.getSuffix() + ";
|
||||
case "w":
|
||||
return "this.getDay() + ";
|
||||
case "z":
|
||||
return "this.getDayOfYear() + ";
|
||||
case "W":
|
||||
return "this.getWeekOfYear() + ";
|
||||
case "F":
|
||||
return "Date.monthNames[this.getMonth()] + ";
|
||||
case "m":
|
||||
return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
|
||||
case "M":
|
||||
return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
|
||||
case "n":
|
||||
return "(this.getMonth() + 1) + ";
|
||||
case "t":
|
||||
return "this.getDaysInMonth() + ";
|
||||
case "L":
|
||||
return "(this.isLeapYear() ? 1 : 0) + ";
|
||||
case "Y":
|
||||
return "this.getFullYear() + ";
|
||||
case "y":
|
||||
return "('' + this.getFullYear()).substring(2, 4) + ";
|
||||
case "a":
|
||||
return "(this.getHours() < 12 ? 'am' : 'pm') + ";
|
||||
case "A":
|
||||
return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
|
||||
case "g":
|
||||
return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
|
||||
case "G":
|
||||
return "this.getHours() + ";
|
||||
case "h":
|
||||
return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
|
||||
case "H":
|
||||
return "String.leftPad(this.getHours(), 2, '0') + ";
|
||||
case "i":
|
||||
return "String.leftPad(this.getMinutes(), 2, '0') + ";
|
||||
case "s":
|
||||
return "String.leftPad(this.getSeconds(), 2, '0') + ";
|
||||
case "O":
|
||||
return "this.getGMTOffset() + ";
|
||||
case "T":
|
||||
return "this.getTimezone() + ";
|
||||
case "Z":
|
||||
return "(this.getTimezoneOffset() * -60) + ";
|
||||
default:
|
||||
return "'" + String.escape(character) + "' + ";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses the passed string using the specified format. Example Usage:
|
||||
<pre><code>
|
||||
var date = Date.parseDate('2006-12-25', 'Y-m-d');
|
||||
</code></pre>
|
||||
* @param {String} input The unparsed date as a string
|
||||
* @param {String} format The format the date is in
|
||||
* @return {Date} The parsed date
|
||||
* @static
|
||||
*/
|
||||
Date.parseDate = function(input, format) {
|
||||
if (Date.parseFunctions[format] == null) {
|
||||
Date.createParser(format);
|
||||
}
|
||||
var func = Date.parseFunctions[format];
|
||||
return Date[func](input);
|
||||
};
|
||||
|
||||
// private
|
||||
Date.createParser = function(format) {
|
||||
var funcName = "parse" + Date.parseFunctions.count++;
|
||||
var regexNum = Date.parseRegexes.length;
|
||||
var currentGroup = 1;
|
||||
Date.parseFunctions[format] = funcName;
|
||||
|
||||
var code = "Date." + funcName + " = function(input){\n"
|
||||
+ "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"
|
||||
+ "var d = new Date();\n"
|
||||
+ "y = d.getFullYear();\n"
|
||||
+ "m = d.getMonth();\n"
|
||||
+ "d = d.getDate();\n"
|
||||
+ "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
|
||||
+ "if (results && results.length > 0) {";
|
||||
var regex = "";
|
||||
|
||||
var special = false;
|
||||
var ch = '';
|
||||
for (var i = 0; i < format.length; ++i) {
|
||||
ch = format.charAt(i);
|
||||
if (!special && ch == "\\") {
|
||||
special = true;
|
||||
}
|
||||
else if (special) {
|
||||
special = false;
|
||||
regex += String.escape(ch);
|
||||
}
|
||||
else {
|
||||
var obj = Date.formatCodeToRegex(ch, currentGroup);
|
||||
currentGroup += obj.g;
|
||||
regex += obj.s;
|
||||
if (obj.g && obj.c) {
|
||||
code += obj.c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
|
||||
+ "{return new Date(y, m, d, h, i, s);}\n"
|
||||
+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
|
||||
+ "{return new Date(y, m, d, h, i);}\n"
|
||||
+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"
|
||||
+ "{return new Date(y, m, d, h);}\n"
|
||||
+ "else if (y > 0 && m >= 0 && d > 0)\n"
|
||||
+ "{return new Date(y, m, d);}\n"
|
||||
+ "else if (y > 0 && m >= 0)\n"
|
||||
+ "{return new Date(y, m);}\n"
|
||||
+ "else if (y > 0)\n"
|
||||
+ "{return new Date(y);}\n"
|
||||
+ "}return null;}";
|
||||
|
||||
Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
|
||||
eval(code);
|
||||
};
|
||||
|
||||
// private
|
||||
Date.formatCodeToRegex = function(character, currentGroup) {
|
||||
switch (character) {
|
||||
case "D":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
|
||||
case "j":
|
||||
case "d":
|
||||
return {g:1,
|
||||
c:"d = parseInt(results[" + currentGroup + "], 10);\n",
|
||||
s:"(\\d{1,2})"};
|
||||
case "l":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:" + Date.dayNames.join("|") + ")"};
|
||||
case "S":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:st|nd|rd|th)"};
|
||||
case "w":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"\\d"};
|
||||
case "z":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:\\d{1,3})"};
|
||||
case "W":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:\\d{2})"};
|
||||
case "F":
|
||||
return {g:1,
|
||||
c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
|
||||
s:"(" + Date.monthNames.join("|") + ")"};
|
||||
case "M":
|
||||
return {g:1,
|
||||
c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
|
||||
s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
|
||||
case "n":
|
||||
case "m":
|
||||
return {g:1,
|
||||
c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
|
||||
s:"(\\d{1,2})"};
|
||||
case "t":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"\\d{1,2}"};
|
||||
case "L":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"(?:1|0)"};
|
||||
case "Y":
|
||||
return {g:1,
|
||||
c:"y = parseInt(results[" + currentGroup + "], 10);\n",
|
||||
s:"(\\d{4})"};
|
||||
case "y":
|
||||
return {g:1,
|
||||
c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
|
||||
+ "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
|
||||
s:"(\\d{1,2})"};
|
||||
case "a":
|
||||
return {g:1,
|
||||
c:"if (results[" + currentGroup + "] == 'am') {\n"
|
||||
+ "if (h == 12) { h = 0; }\n"
|
||||
+ "} else { if (h < 12) { h += 12; }}",
|
||||
s:"(am|pm)"};
|
||||
case "A":
|
||||
return {g:1,
|
||||
c:"if (results[" + currentGroup + "] == 'AM') {\n"
|
||||
+ "if (h == 12) { h = 0; }\n"
|
||||
+ "} else { if (h < 12) { h += 12; }}",
|
||||
s:"(AM|PM)"};
|
||||
case "g":
|
||||
case "G":
|
||||
case "h":
|
||||
case "H":
|
||||
return {g:1,
|
||||
c:"h = parseInt(results[" + currentGroup + "], 10);\n",
|
||||
s:"(\\d{1,2})"};
|
||||
case "i":
|
||||
return {g:1,
|
||||
c:"i = parseInt(results[" + currentGroup + "], 10);\n",
|
||||
s:"(\\d{2})"};
|
||||
case "s":
|
||||
return {g:1,
|
||||
c:"s = parseInt(results[" + currentGroup + "], 10);\n",
|
||||
s:"(\\d{2})"};
|
||||
case "O":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"[+-]\\d{4}"};
|
||||
case "T":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"[A-Z]{3}"};
|
||||
case "Z":
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:"[+-]\\d{1,5}"};
|
||||
default:
|
||||
return {g:0,
|
||||
c:null,
|
||||
s:String.escape(character)};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
|
||||
* @return {String} The abbreviated timezone name (e.g. 'CST')
|
||||
*/
|
||||
Date.prototype.getTimezone = function() {
|
||||
return this.toString().replace(
|
||||
/^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace(
|
||||
/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the offset from GMT of the current date (equivalent to the format specifier 'O').
|
||||
* @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
|
||||
*/
|
||||
Date.prototype.getGMTOffset = function() {
|
||||
return (this.getTimezoneOffset() > 0 ? "-" : "+")
|
||||
+ String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0")
|
||||
+ String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the numeric day number of the year, adjusted for leap year.
|
||||
* @return {Number} 0 through 365 (366 in leap years)
|
||||
*/
|
||||
Date.prototype.getDayOfYear = function() {
|
||||
var num = 0;
|
||||
Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
|
||||
for (var i = 0; i < this.getMonth(); ++i) {
|
||||
num += Date.daysInMonth[i];
|
||||
}
|
||||
return num + this.getDate() - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the string representation of the numeric week number of the year
|
||||
* (equivalent to the format specifier 'W').
|
||||
* @return {String} '00' through '52'
|
||||
*/
|
||||
Date.prototype.getWeekOfYear = function() {
|
||||
// Skip to Thursday of this week
|
||||
var now = this.getDayOfYear() + (4 - this.getDay());
|
||||
// Find the first Thursday of the year
|
||||
var jan1 = new Date(this.getFullYear(), 0, 1);
|
||||
var then = (7 - jan1.getDay() + 4);
|
||||
return String.leftPad(((now - then) / 7) + 1, 2, "0");
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether or not the current date is in a leap year.
|
||||
* @return {Boolean} True if the current date is in a leap year, else false
|
||||
*/
|
||||
Date.prototype.isLeapYear = function() {
|
||||
var year = this.getFullYear();
|
||||
return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the first day of the current month, adjusted for leap year. The returned value
|
||||
* is the numeric day index within the week (0-6) which can be used in conjunction with
|
||||
* the {@link #monthNames} array to retrieve the textual day name.
|
||||
* Example:
|
||||
*<pre><code>
|
||||
var dt = new Date('1/10/2007');
|
||||
document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
|
||||
</code></pre>
|
||||
* @return {Number} The day number (0-6)
|
||||
*/
|
||||
Date.prototype.getFirstDayOfMonth = function() {
|
||||
var day = (this.getDay() - (this.getDate() - 1)) % 7;
|
||||
return (day < 0) ? (day + 7) : day;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the last day of the current month, adjusted for leap year. The returned value
|
||||
* is the numeric day index within the week (0-6) which can be used in conjunction with
|
||||
* the {@link #monthNames} array to retrieve the textual day name.
|
||||
* Example:
|
||||
*<pre><code>
|
||||
var dt = new Date('1/10/2007');
|
||||
document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
|
||||
</code></pre>
|
||||
* @return {Number} The day number (0-6)
|
||||
*/
|
||||
Date.prototype.getLastDayOfMonth = function() {
|
||||
var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
|
||||
return (day < 0) ? (day + 7) : day;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get a Date of the first day of this date's month
|
||||
* @return {Date}
|
||||
*/
|
||||
Date.prototype.getFirstDateOfMonth = function() {
|
||||
return new Date(this.getFullYear(), this.getMonth(), 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a Date of the late day of this date's month
|
||||
* @return {Date}
|
||||
*/
|
||||
Date.prototype.getLastDateOfMonth = function() {
|
||||
return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
|
||||
};
|
||||
/**
|
||||
* Get the number of days in the current month, adjusted for leap year.
|
||||
* @return {Number} The number of days in the month
|
||||
*/
|
||||
Date.prototype.getDaysInMonth = function() {
|
||||
Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
|
||||
return Date.daysInMonth[this.getMonth()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
|
||||
* @return {String} 'st, 'nd', 'rd' or 'th'
|
||||
*/
|
||||
Date.prototype.getSuffix = function() {
|
||||
switch (this.getDate()) {
|
||||
case 1:
|
||||
case 21:
|
||||
case 31:
|
||||
return "st";
|
||||
case 2:
|
||||
case 22:
|
||||
return "nd";
|
||||
case 3:
|
||||
case 23:
|
||||
return "rd";
|
||||
default:
|
||||
return "th";
|
||||
}
|
||||
};
|
||||
|
||||
// private
|
||||
Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
|
||||
|
||||
/**
|
||||
* An array of textual month names.
|
||||
* Override these values for international dates, for example...
|
||||
* Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
|
||||
* @type Array
|
||||
* @static
|
||||
*/
|
||||
Date.monthNames =
|
||||
["January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"];
|
||||
|
||||
/**
|
||||
* An array of textual day names.
|
||||
* Override these values for international dates, for example...
|
||||
* Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
|
||||
* @type Array
|
||||
* @static
|
||||
*/
|
||||
Date.dayNames =
|
||||
["Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"];
|
||||
|
||||
// private
|
||||
Date.y2kYear = 50;
|
||||
// private
|
||||
Date.monthNumbers = {
|
||||
Jan:0,
|
||||
Feb:1,
|
||||
Mar:2,
|
||||
Apr:3,
|
||||
May:4,
|
||||
Jun:5,
|
||||
Jul:6,
|
||||
Aug:7,
|
||||
Sep:8,
|
||||
Oct:9,
|
||||
Nov:10,
|
||||
Dec:11};
|
||||
|
||||
/**
|
||||
* Creates and returns a new Date instance with the exact same date value as the called instance.
|
||||
* Dates are copied and passed by reference, so if a copied date variable is modified later, the original
|
||||
* variable will also be changed. When the intention is to create a new variable that will not
|
||||
* modify the original instance, you should create a clone.
|
||||
*
|
||||
* Example of correctly cloning a date:
|
||||
* <pre><code>
|
||||
//wrong way:
|
||||
var orig = new Date('10/1/2006');
|
||||
var copy = orig;
|
||||
copy.setDate(5);
|
||||
document.write(orig); //returns 'Thu Oct 05 2006'!
|
||||
|
||||
//correct way:
|
||||
var orig = new Date('10/1/2006');
|
||||
var copy = orig.clone();
|
||||
copy.setDate(5);
|
||||
document.write(orig); //returns 'Thu Oct 01 2006'
|
||||
</code></pre>
|
||||
* @return {Date} The new Date instance
|
||||
*/
|
||||
Date.prototype.clone = function() {
|
||||
return new Date(this.getTime());
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears any time information from this date
|
||||
@param {Boolean} clone true to create a clone of this date, clear the time and return it
|
||||
@return {Date} this or the clone
|
||||
*/
|
||||
Date.prototype.clearTime = function(clone){
|
||||
if(clone){
|
||||
return this.clone().clearTime();
|
||||
}
|
||||
this.setHours(0);
|
||||
this.setMinutes(0);
|
||||
this.setSeconds(0);
|
||||
this.setMilliseconds(0);
|
||||
return this;
|
||||
};
|
||||
|
||||
// private
|
||||
// safari setMonth is broken
|
||||
if(Ext.isSafari){
|
||||
Date.brokenSetMonth = Date.prototype.setMonth;
|
||||
Date.prototype.setMonth = function(num){
|
||||
if(num <= -1){
|
||||
var n = Math.ceil(-num);
|
||||
var back_year = Math.ceil(n/12);
|
||||
var month = (n % 12) ? 12 - n % 12 : 0 ;
|
||||
this.setFullYear(this.getFullYear() - back_year);
|
||||
return Date.brokenSetMonth.call(this, month);
|
||||
} else {
|
||||
return Date.brokenSetMonth.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Date interval constant @static @type String */
|
||||
Date.MILLI = "ms";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.SECOND = "s";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.MINUTE = "mi";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.HOUR = "h";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.DAY = "d";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.MONTH = "mo";
|
||||
/** Date interval constant @static @type String */
|
||||
Date.YEAR = "y";
|
||||
|
||||
/**
|
||||
* Provides a convenient method of performing basic date arithmetic. This method
|
||||
* does not modify the Date instance being called - it creates and returns
|
||||
* a new Date instance containing the resulting date value.
|
||||
*
|
||||
* Examples:
|
||||
* <pre><code>
|
||||
//Basic usage:
|
||||
var dt = new Date('10/29/2006').add(Date.DAY, 5);
|
||||
document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
|
||||
|
||||
//Negative values will subtract correctly:
|
||||
var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
|
||||
document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
|
||||
|
||||
//You can even chain several calls together in one line!
|
||||
var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
|
||||
document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
|
||||
</code></pre>
|
||||
*
|
||||
* @param {String} interval A valid date interval enum value
|
||||
* @param {Number} value The amount to add to the current date
|
||||
* @return {Date} The new Date instance
|
||||
*/
|
||||
Date.prototype.add = function(interval, value){
|
||||
var d = this.clone();
|
||||
if (!interval || value === 0) return d;
|
||||
switch(interval.toLowerCase()){
|
||||
case Date.MILLI:
|
||||
d.setMilliseconds(this.getMilliseconds() + value);
|
||||
break;
|
||||
case Date.SECOND:
|
||||
d.setSeconds(this.getSeconds() + value);
|
||||
break;
|
||||
case Date.MINUTE:
|
||||
d.setMinutes(this.getMinutes() + value);
|
||||
break;
|
||||
case Date.HOUR:
|
||||
d.setHours(this.getHours() + value);
|
||||
break;
|
||||
case Date.DAY:
|
||||
d.setDate(this.getDate() + value);
|
||||
break;
|
||||
case Date.MONTH:
|
||||
var day = this.getDate();
|
||||
if(day > 28){
|
||||
day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
|
||||
}
|
||||
d.setDate(day);
|
||||
d.setMonth(this.getMonth() + value);
|
||||
break;
|
||||
case Date.YEAR:
|
||||
d.setFullYear(this.getFullYear() + value);
|
||||
break;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
62
www/extras/yui-ext/source/util/DelayedTask.js
vendored
Normal file
62
www/extras/yui-ext/source/util/DelayedTask.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.DelayedTask
|
||||
* Provides a convenient method of performing setTimeout where a new
|
||||
* timeout cancels the old timeout. An example would be performing validation on a keypress.
|
||||
* You can use this class to buffer
|
||||
* the keypress events for a certain number of milliseconds, and perform only if they stop
|
||||
* for that amount of time.
|
||||
* @constructor The parameters to this constructor serve as defaults and are not required.
|
||||
* @param {Function} fn (optional) The default function to timeout
|
||||
* @param {Object} scope (optional) The default scope of that timeout
|
||||
* @param {Array} args (optional) The default Array of arguments
|
||||
*/
|
||||
Ext.util.DelayedTask = function(fn, scope, args){
|
||||
var id = null, d, t;
|
||||
|
||||
var call = function(){
|
||||
var now = new Date().getTime();
|
||||
if(now - t >= d){
|
||||
clearInterval(id);
|
||||
id = null;
|
||||
fn.apply(scope, args || []);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Cancels any pending timeout and queues a new one
|
||||
* @param {Number} delay The milliseconds to delay
|
||||
* @param {Function} newFn (optional) Overrides function passed to constructor
|
||||
* @param {Object} newScope (optional) Overrides scope passed to constructor
|
||||
* @param {Array} newArgs (optional) Overrides args passed to constructor
|
||||
*/
|
||||
this.delay = function(delay, newFn, newScope, newArgs){
|
||||
if(id && delay != d){
|
||||
this.cancel();
|
||||
}
|
||||
d = delay;
|
||||
t = new Date().getTime();
|
||||
fn = newFn || fn;
|
||||
scope = newScope || scope;
|
||||
args = newArgs || args;
|
||||
if(!id){
|
||||
id = setInterval(call, d);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel the last queued timeout
|
||||
*/
|
||||
this.cancel = function(){
|
||||
if(id){
|
||||
clearInterval(id);
|
||||
id = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
156
www/extras/yui-ext/source/util/Format.js
vendored
Normal file
156
www/extras/yui-ext/source/util/Format.js
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.Format
|
||||
* Reusable data formatting functions
|
||||
* @singleton
|
||||
*/
|
||||
Ext.util.Format = function(){
|
||||
var trimRe = /^\s+|\s+$/g;
|
||||
return {
|
||||
/**
|
||||
* Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
|
||||
* @param {String} value The string to truncate
|
||||
* @param {Number} length The maximum length to allow before truncating
|
||||
* @return {String} The converted text
|
||||
*/
|
||||
ellipsis : function(value, len){
|
||||
if(value && value.length > len){
|
||||
return value.substr(0, len-3)+"...";
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks a reference and converts it to empty string if it is undefined
|
||||
* @param {Mixed} value Reference to check
|
||||
* @return {Mixed} Empty string if converted, otherwise the original value
|
||||
*/
|
||||
undef : function(value){
|
||||
return typeof value != "undefined" ? value : "";
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
|
||||
* @param {String} value The string to encode
|
||||
* @return {String} The encoded text
|
||||
*/
|
||||
htmlEncode : function(value){
|
||||
return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
|
||||
},
|
||||
|
||||
/**
|
||||
* Trims any whitespace from either side of a string
|
||||
* @param {String} value The text to trim
|
||||
* @return {String} The trimmed text
|
||||
*/
|
||||
trim : function(value){
|
||||
return String(value).replace(trimRe, "");
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a substring from within an original string
|
||||
* @param {String} value The original text
|
||||
* @param {Number} start The start index of the substring
|
||||
* @param {Number} length The length of the substring
|
||||
* @return {String} The substring
|
||||
*/
|
||||
substr : function(value, start, length){
|
||||
return String(value).substr(start, length);
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a string to all lower case letters
|
||||
* @param {String} value The text to convert
|
||||
* @return {String} The converted text
|
||||
*/
|
||||
lowercase : function(value){
|
||||
return String(value).toLowerCase();
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a string to all upper case letters
|
||||
* @param {String} value The text to convert
|
||||
* @return {String} The converted text
|
||||
*/
|
||||
uppercase : function(value){
|
||||
return String(value).toUpperCase();
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the first character only of a string to upper case
|
||||
* @param {String} value The text to convert
|
||||
* @return {String} The converted text
|
||||
*/
|
||||
capitalize : function(value){
|
||||
return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
|
||||
},
|
||||
|
||||
// private
|
||||
call : function(value, fn){
|
||||
if(arguments.length > 2){
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
args.unshift(value);
|
||||
return eval(fn).apply(window, args);
|
||||
}else{
|
||||
return eval(fn).call(window, value);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Format a number as US currency
|
||||
* @param {Number/String} value The numeric value to format
|
||||
* @return {String} The formatted currency string
|
||||
*/
|
||||
usMoney : function(v){
|
||||
v = (Math.round((v-0)*100))/100;
|
||||
v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
|
||||
return "$" + v ;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse a value into a formatted date using the specified format pattern.
|
||||
* @param {Mixed} value The value to format
|
||||
* @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
|
||||
* @return {String} The formatted date string
|
||||
*/
|
||||
date : function(v, format){
|
||||
if(!v){
|
||||
return "";
|
||||
}
|
||||
if(!(v instanceof Date)){
|
||||
v = new Date(Date.parse(v));
|
||||
}
|
||||
return v.dateFormat(format || "m/d/Y");
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a date rendering function that can be reused to apply a date format multiple times efficiently
|
||||
* @param {String} format Any valid date format string
|
||||
* @return {Function} The date formatting function
|
||||
*/
|
||||
dateRenderer : function(format){
|
||||
return function(v){
|
||||
return Ext.util.Format.date(v, format);
|
||||
};
|
||||
},
|
||||
|
||||
// private
|
||||
stripTagsRE : /<\/?[^>]+>/gi,
|
||||
|
||||
/**
|
||||
* Strips all HTML tags
|
||||
* @param {Mixed} value The text from which to strip tags
|
||||
* @return {String} The stripped text
|
||||
*/
|
||||
stripTags : function(v){
|
||||
return !v ? v : String(v).replace(this.stripTagsRE, "");
|
||||
}
|
||||
};
|
||||
}();
|
||||
143
www/extras/yui-ext/source/util/JSON.js
vendored
Normal file
143
www/extras/yui-ext/source/util/JSON.js
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.JSON
|
||||
* Modified version of Douglas Crockford"s json.js that doesn"t
|
||||
* mess with the Object prototype
|
||||
* http://www.json.org/js.html
|
||||
* @singleton
|
||||
*/
|
||||
Ext.util.JSON = new (function(){
|
||||
var useHasOwn = {}.hasOwnProperty ? true : false;
|
||||
|
||||
// crashes Safari in some instances
|
||||
//var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
|
||||
|
||||
var pad = function(n) {
|
||||
return n < 10 ? "0" + n : n;
|
||||
};
|
||||
|
||||
var m = {
|
||||
"\b": '\\b',
|
||||
"\t": '\\t',
|
||||
"\n": '\\n',
|
||||
"\f": '\\f',
|
||||
"\r": '\\r',
|
||||
'"' : '\\"',
|
||||
"\\": '\\\\'
|
||||
};
|
||||
|
||||
var encodeString = function(s){
|
||||
if (/["\\\x00-\x1f]/.test(s)) {
|
||||
return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
|
||||
var c = m[b];
|
||||
if(c){
|
||||
return c;
|
||||
}
|
||||
c = b.charCodeAt();
|
||||
return "\\u00" +
|
||||
Math.floor(c / 16).toString(16) +
|
||||
(c % 16).toString(16);
|
||||
}) + '"';
|
||||
}
|
||||
return '"' + s + '"';
|
||||
};
|
||||
|
||||
var encodeArray = function(o){
|
||||
var a = ["["], b, i, l = o.length, v;
|
||||
for (i = 0; i < l; i += 1) {
|
||||
v = o[i];
|
||||
switch (typeof v) {
|
||||
case "undefined":
|
||||
case "function":
|
||||
case "unknown":
|
||||
break;
|
||||
default:
|
||||
if (b) {
|
||||
a.push(',');
|
||||
}
|
||||
a.push(v === null ? "null" : Ext.util.JSON.encode(v));
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
a.push("]");
|
||||
return a.join("");
|
||||
};
|
||||
|
||||
var encodeDate = function(o){
|
||||
return '"' + o.getFullYear() + "-" +
|
||||
pad(o.getMonth() + 1) + "-" +
|
||||
pad(o.getDate()) + "T" +
|
||||
pad(o.getHours()) + ":" +
|
||||
pad(o.getMinutes()) + ":" +
|
||||
pad(o.getSeconds()) + '"';
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes an Object, Array or other value
|
||||
* @param {Mixed} o The variable to encode
|
||||
* @return {String} The JSON string
|
||||
*/
|
||||
this.encode = function(o){
|
||||
if(typeof o == "undefined" || o === null){
|
||||
return "null";
|
||||
}else if(o instanceof Array){
|
||||
return encodeArray(o);
|
||||
}else if(o instanceof Date){
|
||||
return encodeDate(o);
|
||||
}else if(typeof o == "string"){
|
||||
return encodeString(o);
|
||||
}else if(typeof o == "number"){
|
||||
return isFinite(o) ? String(o) : "null";
|
||||
}else if(typeof o == "boolean"){
|
||||
return String(o);
|
||||
}else {
|
||||
var a = ["{"], b, i, v;
|
||||
for (i in o) {
|
||||
if(!useHasOwn || o.hasOwnProperty(i)) {
|
||||
v = o[i];
|
||||
switch (typeof v) {
|
||||
case "undefined":
|
||||
case "function":
|
||||
case "unknown":
|
||||
break;
|
||||
default:
|
||||
if(b){
|
||||
a.push(',');
|
||||
}
|
||||
a.push(this.encode(i), ":",
|
||||
v === null ? "null" : this.encode(v));
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
a.push("}");
|
||||
return a.join("");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
|
||||
* @param {String} json The JSON string
|
||||
* @return {Object} The resulting object
|
||||
*/
|
||||
this.decode = function(json){
|
||||
return eval("(" + json + ')');
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* Shorthand for {@link Ext.util.JSON#encode}
|
||||
* @member Ext encode
|
||||
* @method */
|
||||
Ext.encode = Ext.util.JSON.encode;
|
||||
/**
|
||||
* Shorthand for {@link Ext.util.JSON#decode}
|
||||
* @member Ext decode
|
||||
* @method */
|
||||
Ext.decode = Ext.util.JSON.decode;
|
||||
189
www/extras/yui-ext/source/util/KeyMap.js
vendored
Normal file
189
www/extras/yui-ext/source/util/KeyMap.js
vendored
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.KeyMap
|
||||
* Handles mapping keys to actions for an element. One key map can be used for multiple actions.
|
||||
* The constructor accepts the same config object as defined by {@link #addBinding}.
|
||||
* If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
|
||||
* combination it will call the function with this signature (if the match is a multi-key
|
||||
* combination the callback will still be called only once): (String key, Ext.EventObject e)
|
||||
* A KeyMap can also handle a string representation of keys.<br />
|
||||
* Usage:
|
||||
<pre><code>
|
||||
// map one key by key code
|
||||
var map = new Ext.KeyMap("my-element", {
|
||||
key: 13, // or Ext.EventObject.ENTER
|
||||
fn: myHandler,
|
||||
scope: myObject
|
||||
});
|
||||
|
||||
// map multiple keys to one action by string
|
||||
var map = new Ext.KeyMap("my-element", {
|
||||
key: "a\r\n\t",
|
||||
fn: myHandler,
|
||||
scope: myObject
|
||||
});
|
||||
|
||||
// map multiple keys to multiple actions by strings and array of codes
|
||||
var map = new Ext.KeyMap("my-element", [
|
||||
{
|
||||
key: [10,13],
|
||||
fn: function(){ alert("Return was pressed"); }
|
||||
}, {
|
||||
key: "abc",
|
||||
fn: function(){ alert('a, b or c was pressed'); }
|
||||
}, {
|
||||
key: "\t",
|
||||
ctrl:true,
|
||||
shift:true,
|
||||
fn: function(){ alert('Control + shift + tab was pressed.'); }
|
||||
}
|
||||
]);
|
||||
</code></pre>
|
||||
* <b>Note: A KepMap starts enabled</b>
|
||||
* @constructor
|
||||
* @param {String/HTMLElement/Ext.Element} el The element to bind to
|
||||
* @param {Object} config The config
|
||||
* @param {String} eventName (optional) The event to bind to (defaults to "keydown")
|
||||
*/
|
||||
Ext.KeyMap = function(el, config, eventName){
|
||||
this.el = Ext.get(el);
|
||||
this.eventName = eventName || "keydown";
|
||||
this.bindings = [];
|
||||
if(config instanceof Array){
|
||||
for(var i = 0, len = config.length; i < len; i++){
|
||||
this.addBinding(config[i]);
|
||||
}
|
||||
}else{
|
||||
this.addBinding(config);
|
||||
}
|
||||
this.keyDownDelegate = Ext.EventManager.wrap(this.handleKeyDown, this, true);
|
||||
this.enable();
|
||||
};
|
||||
|
||||
Ext.KeyMap.prototype = {
|
||||
/**
|
||||
* True to stop the event from bubbling and prevent the default browser action if the
|
||||
* key was handled by the KeyMap (defaults to false)
|
||||
* @type Boolean
|
||||
*/
|
||||
stopEvent : false,
|
||||
|
||||
/**
|
||||
* Add a new binding to this KeyMap. The following config object properties are supported:
|
||||
* <pre>
|
||||
Property Type Description
|
||||
---------- --------------- ----------------------------------------------------------------------
|
||||
key String/Array A single keycode or an array of keycodes to handle
|
||||
shift Boolean True to handle key only when shift is pressed (defaults to false)
|
||||
ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
|
||||
alt Boolean True to handle key only when alt is pressed (defaults to false)
|
||||
fn Function The function to call when KeyMap finds the expected key combination
|
||||
scope Object The scope of the callback function
|
||||
</pre>
|
||||
*
|
||||
* Usage:
|
||||
* <pre><code>
|
||||
// Create a KeyMap
|
||||
var map = new Ext.KeyMap(document, {
|
||||
key: Ext.EventObject.ENTER,
|
||||
fn: handleKey,
|
||||
scope: this
|
||||
});
|
||||
|
||||
//Add a new binding to the existing KeyMap later
|
||||
map.addBinding({
|
||||
key: 'abc',
|
||||
shift: true,
|
||||
fn: handleKey,
|
||||
scope: this
|
||||
});
|
||||
</code></pre>
|
||||
* @param {Object} config A single KeyMap config
|
||||
*/
|
||||
addBinding : function(config){
|
||||
var keyCode = config.key,
|
||||
shift = config.shift,
|
||||
ctrl = config.ctrl,
|
||||
alt = config.alt,
|
||||
fn = config.fn,
|
||||
scope = config.scope;
|
||||
if(typeof keyCode == "string"){
|
||||
var ks = [];
|
||||
var keyString = keyCode.toUpperCase();
|
||||
for(var j = 0, len = keyString.length; j < len; j++){
|
||||
ks.push(keyString.charCodeAt(j));
|
||||
}
|
||||
keyCode = ks;
|
||||
}
|
||||
var keyArray = keyCode instanceof Array;
|
||||
var handler = function(e){
|
||||
if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
|
||||
var k = e.getKey();
|
||||
if(keyArray){
|
||||
for(var i = 0, len = keyCode.length; i < len; i++){
|
||||
if(keyCode[i] == k){
|
||||
if(this.stopEvent){
|
||||
e.stopEvent();
|
||||
}
|
||||
fn.call(scope || window, k, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(k == keyCode){
|
||||
if(this.stopEvent){
|
||||
e.stopEvent();
|
||||
}
|
||||
fn.call(scope || window, k, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.bindings.push(handler);
|
||||
},
|
||||
|
||||
// private
|
||||
handleKeyDown : function(e){
|
||||
if(this.enabled){ //just in case
|
||||
var b = this.bindings;
|
||||
for(var i = 0, len = b.length; i < len; i++){
|
||||
b[i].call(this, e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if this KepMap is enabled
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isEnabled : function(){
|
||||
return this.enabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable this KeyMap
|
||||
*/
|
||||
enable: function(){
|
||||
if(!this.enabled){
|
||||
this.el.on(this.eventName, this.keyDownDelegate);
|
||||
this.enabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable this KeyMap
|
||||
*/
|
||||
disable: function(){
|
||||
if(this.enabled){
|
||||
this.el.removeListener(this.eventName, this.keyDownDelegate);
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
131
www/extras/yui-ext/source/util/KeyNav.js
vendored
Normal file
131
www/extras/yui-ext/source/util/KeyNav.js
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.KeyNav
|
||||
* Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
|
||||
* navigation keys to function calls that will get called when the keys are pressed.
|
||||
* <br />Usage:
|
||||
<pre><code>
|
||||
var nav = new Ext.KeyNav("my-element", {
|
||||
"left" : function(e){
|
||||
this.moveLeft(e.ctrlKey);
|
||||
},
|
||||
"right" : function(e){
|
||||
this.moveRight(e.ctrlKey);
|
||||
},
|
||||
"enter" : function(e){
|
||||
this.save();
|
||||
},
|
||||
scope : this
|
||||
});
|
||||
</code></pre>
|
||||
* @constructor
|
||||
* @param {String/HTMLElement/Ext.Element} el The element to bind to
|
||||
* @param {Object} config The config
|
||||
*/
|
||||
Ext.KeyNav = function(el, config){
|
||||
this.el = Ext.get(el);
|
||||
Ext.apply(this, config);
|
||||
if(!this.disabled){
|
||||
this.disabled = true;
|
||||
this.enable();
|
||||
}
|
||||
};
|
||||
|
||||
Ext.KeyNav.prototype = {
|
||||
disabled : false,
|
||||
defaultEventAction: "stopEvent",
|
||||
|
||||
prepareEvent : function(e){
|
||||
var k = e.getKey();
|
||||
var h = this.keyToHandler[k];
|
||||
//if(h && this[h]){
|
||||
// e.stopPropagation();
|
||||
//}
|
||||
if(Ext.isSafari && h && k >= 37 && k <= 40){
|
||||
e.stopEvent();
|
||||
}
|
||||
},
|
||||
|
||||
relay : function(e){
|
||||
var k = e.getKey();
|
||||
var h = this.keyToHandler[k];
|
||||
if(h && this[h]){
|
||||
if(this.doRelay(e, this[h], h) !== true){
|
||||
e[this.defaultEventAction]();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
doRelay : function(e, h, hname){
|
||||
return h.call(this.scope || this, e);
|
||||
},
|
||||
|
||||
// possible handlers
|
||||
enter : false,
|
||||
left : false,
|
||||
right : false,
|
||||
up : false,
|
||||
down : false,
|
||||
tab : false,
|
||||
esc : false,
|
||||
pageUp : false,
|
||||
pageDown : false,
|
||||
del : false,
|
||||
home : false,
|
||||
end : false,
|
||||
|
||||
// quick lookup hash
|
||||
keyToHandler : {
|
||||
37 : "left",
|
||||
39 : "right",
|
||||
38 : "up",
|
||||
40 : "down",
|
||||
33 : "pageUp",
|
||||
34 : "pageDown",
|
||||
46 : "del",
|
||||
36 : "home",
|
||||
35 : "end",
|
||||
13 : "enter",
|
||||
27 : "esc",
|
||||
9 : "tab"
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable this KeyNav
|
||||
*/
|
||||
enable: function(){
|
||||
if(this.disabled){
|
||||
// ie won't do special keys on keypress, no one else will repeat keys with keydown
|
||||
// the EventObject will normalize Safari automatically
|
||||
if(Ext.isIE){
|
||||
this.el.on("keydown", this.relay, this);
|
||||
}else{
|
||||
this.el.on("keydown", this.prepareEvent, this);
|
||||
this.el.on("keypress", this.relay, this);
|
||||
}
|
||||
this.disabled = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable this KeyNav
|
||||
*/
|
||||
disable: function(){
|
||||
if(!this.disabled){
|
||||
if(Ext.isIE){
|
||||
this.el.un("keydown", this.relay);
|
||||
}else{
|
||||
this.el.un("keydown", this.prepareEvent);
|
||||
this.el.un("keypress", this.relay);
|
||||
}
|
||||
this.disabled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
510
www/extras/yui-ext/source/util/MixedCollection.js
vendored
Normal file
510
www/extras/yui-ext/source/util/MixedCollection.js
vendored
Normal file
|
|
@ -0,0 +1,510 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.MixedCollection
|
||||
* @extends Ext.util.Observable
|
||||
* A Collection class that maintains both numeric indexes and keys and exposes events.
|
||||
* @constructor
|
||||
* @param {Boolean} allowFunctions True if the addAll function should add function references to the
|
||||
* collection (defaults to false)
|
||||
* @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
|
||||
* and return the key value for that item. This is used when available to look up the key on items that
|
||||
* were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
|
||||
* equivalent to providing an implementation for the {@link #getKey} method.
|
||||
*/
|
||||
Ext.util.MixedCollection = function(allowFunctions, keyFn){
|
||||
this.items = [];
|
||||
this.map = {};
|
||||
this.keys = [];
|
||||
this.length = 0;
|
||||
this.addEvents({
|
||||
/**
|
||||
* @event clear
|
||||
* Fires when the collection is cleared.
|
||||
*/
|
||||
"clear" : true,
|
||||
/**
|
||||
* @event add
|
||||
* Fires when an item is added to the collection.
|
||||
* @param {Number} index The index at which the item was added.
|
||||
* @param {Object} o The item added.
|
||||
* @param {String} key The key associated with the added item.
|
||||
*/
|
||||
"add" : true,
|
||||
/**
|
||||
* @event replace
|
||||
* Fires when an item is replaced in the collection.
|
||||
* @param {String} key he key associated with the new added.
|
||||
* @param {Object} old The item being replaced.
|
||||
* @param {Object} new The new item.
|
||||
*/
|
||||
"replace" : true,
|
||||
/**
|
||||
* @event remove
|
||||
* Fires when an item is removed from the collection.
|
||||
* @param {Object} o The item being removed.
|
||||
* @param {String} key (optional) The key associated with the removed item.
|
||||
*/
|
||||
"remove" : true,
|
||||
"sort" : true
|
||||
});
|
||||
this.allowFunctions = allowFunctions === true;
|
||||
if(keyFn){
|
||||
this.getKey = keyFn;
|
||||
}
|
||||
Ext.util.MixedCollection.superclass.constructor.call(this);
|
||||
};
|
||||
|
||||
Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
|
||||
allowFunctions : false,
|
||||
|
||||
/**
|
||||
* Adds an item to the collection.
|
||||
* @param {String} key The key to associate with the item
|
||||
* @param {Object} o The item to add.
|
||||
* @return {Object} The item added.
|
||||
*/
|
||||
add : function(key, o){
|
||||
if(arguments.length == 1){
|
||||
o = arguments[0];
|
||||
key = this.getKey(o);
|
||||
}
|
||||
if(typeof key == "undefined" || key === null){
|
||||
this.length++;
|
||||
this.items.push(o);
|
||||
this.keys.push(null);
|
||||
}else{
|
||||
var old = this.map[key];
|
||||
if(old){
|
||||
return this.replace(key, o);
|
||||
}
|
||||
this.length++;
|
||||
this.items.push(o);
|
||||
this.map[key] = o;
|
||||
this.keys.push(key);
|
||||
}
|
||||
this.fireEvent("add", this.length-1, o, key);
|
||||
return o;
|
||||
},
|
||||
|
||||
/**
|
||||
* MixedCollection has a generic way to fetch keys if you implement getKey.
|
||||
<pre><code>
|
||||
// normal way
|
||||
var mc = new Ext.util.MixedCollection();
|
||||
mc.add(someEl.dom.id, someEl);
|
||||
mc.add(otherEl.dom.id, otherEl);
|
||||
//and so on
|
||||
|
||||
// using getKey
|
||||
var mc = new Ext.util.MixedCollection();
|
||||
mc.getKey = function(el){
|
||||
return el.dom.id;
|
||||
}
|
||||
mc.add(someEl);
|
||||
mc.add(otherEl);
|
||||
// etc
|
||||
</code>
|
||||
* @param o {Object} The item for which to find the key.
|
||||
* @return {Object} The key for the passed item.
|
||||
*/
|
||||
getKey : function(o){
|
||||
return o.id;
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces an item in the collection.
|
||||
* @param {String} key The key associated with the item to replace, or the item to replace.
|
||||
* @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
|
||||
* @return {Object} The new item.
|
||||
*/
|
||||
replace : function(key, o){
|
||||
if(arguments.length == 1){
|
||||
o = arguments[0];
|
||||
key = this.getKey(o);
|
||||
}
|
||||
var old = this.item(key);
|
||||
if(typeof key == "undefined" || key === null || typeof old == "undefined"){
|
||||
return this.add(key, o);
|
||||
}
|
||||
var index = this.indexOfKey(key);
|
||||
this.items[index] = o;
|
||||
this.map[key] = o;
|
||||
this.fireEvent("replace", key, old, o);
|
||||
return o;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds all elements of an Array or an Object to the collection.
|
||||
* @param {Object/Array} objs An Object containing properties which will be added to the collection, or
|
||||
* an Array of values, each of which are added to the collection.
|
||||
*/
|
||||
addAll : function(objs){
|
||||
if(arguments.length > 1 || objs instanceof Array){
|
||||
var args = arguments.length > 1 ? arguments : objs;
|
||||
for(var i = 0, len = args.length; i < len; i++){
|
||||
this.add(args[i]);
|
||||
}
|
||||
}else{
|
||||
for(var key in objs){
|
||||
if(this.allowFunctions || typeof objs[key] != "function"){
|
||||
this.add(objs[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the specified function once for every item in the collection, passing each
|
||||
* item as the first and only parameter. returning false from the function will stop the iteration.
|
||||
* @param {Function} fn The function to execute for each item.
|
||||
* @param {Object} scope (optional) The scope in which to execute the function.
|
||||
*/
|
||||
each : function(fn, scope){
|
||||
var items = [].concat(this.items); // each safe for removal
|
||||
for(var i = 0, len = items.length; i < len; i++){
|
||||
if(fn.call(scope || items[i], items[i], i, len) === false){
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the specified function once for every key in the collection, passing each
|
||||
* key, and its associated item as the first two parameters.
|
||||
* @param {Function} fn The function to execute for each item.
|
||||
* @param {Object} scope (optional) The scope in which to execute the function.
|
||||
*/
|
||||
eachKey : function(fn, scope){
|
||||
for(var i = 0, len = this.keys.length; i < len; i++){
|
||||
fn.call(scope || window, this.keys[i], this.items[i], i, len);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the first item in the collection which elicits a true return value from the
|
||||
* passed selection function.
|
||||
* @param {Function} fn The selection function to execute for each item.
|
||||
* @param {Object} scope (optional) The scope in which to execute the function.
|
||||
* @return {Object} The first item in the collection which returned true from the selection function.
|
||||
*/
|
||||
find : function(fn, scope){
|
||||
for(var i = 0, len = this.items.length; i < len; i++){
|
||||
if(fn.call(scope || window, this.items[i], this.keys[i])){
|
||||
return this.items[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Inserts an item at the specified index in the collection.
|
||||
* @param {Number} index The index to insert the item at.
|
||||
* @param {String} key The key to associate with the new item, or the item itself.
|
||||
* @param {Object} o (optional) If the second parameter was a key, the new item.
|
||||
* @return {Object} The item inserted.
|
||||
*/
|
||||
insert : function(index, key, o){
|
||||
if(arguments.length == 2){
|
||||
o = arguments[1];
|
||||
key = this.getKey(o);
|
||||
}
|
||||
if(index >= this.length){
|
||||
return this.add(key, o);
|
||||
}
|
||||
this.length++;
|
||||
this.items.splice(index, 0, o);
|
||||
if(typeof key != "undefined" && key != null){
|
||||
this.map[key] = o;
|
||||
}
|
||||
this.keys.splice(index, 0, key);
|
||||
this.fireEvent("add", index, o, key);
|
||||
return o;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removed an item from the collection.
|
||||
* @param {Object} o The item to remove.
|
||||
* @return {Object} The item removed.
|
||||
*/
|
||||
remove : function(o){
|
||||
return this.removeAt(this.indexOf(o));
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove an item from a specified index in the collection.
|
||||
* @param {Number} index The index within the collection of the item to remove.
|
||||
*/
|
||||
removeAt : function(index){
|
||||
if(index < this.length && index >= 0){
|
||||
this.length--;
|
||||
var o = this.items[index];
|
||||
this.items.splice(index, 1);
|
||||
var key = this.keys[index];
|
||||
if(typeof key != "undefined"){
|
||||
delete this.map[key];
|
||||
}
|
||||
this.keys.splice(index, 1);
|
||||
this.fireEvent("remove", o, key);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Removed an item associated with the passed key fom the collection.
|
||||
* @param {String} key The key of the item to remove.
|
||||
*/
|
||||
removeKey : function(key){
|
||||
return this.removeAt(this.indexOfKey(key));
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the number of items in the collection.
|
||||
* @return {Number} the number of items in the collection.
|
||||
*/
|
||||
getCount : function(){
|
||||
return this.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns index within the collection of the passed Object.
|
||||
* @param {Object} o The item to find the index of.
|
||||
* @return {Number} index of the item.
|
||||
*/
|
||||
indexOf : function(o){
|
||||
if(!this.items.indexOf){
|
||||
for(var i = 0, len = this.items.length; i < len; i++){
|
||||
if(this.items[i] == o) return i;
|
||||
}
|
||||
return -1;
|
||||
}else{
|
||||
return this.items.indexOf(o);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns index within the collection of the passed key.
|
||||
* @param {String} key The key to find the index of.
|
||||
* @return {Number} index of the key.
|
||||
*/
|
||||
indexOfKey : function(key){
|
||||
if(!this.keys.indexOf){
|
||||
for(var i = 0, len = this.keys.length; i < len; i++){
|
||||
if(this.keys[i] == key) return i;
|
||||
}
|
||||
return -1;
|
||||
}else{
|
||||
return this.keys.indexOf(key);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the item associated with the passed key OR index. Key has priority over index.
|
||||
* @param {String/Number} key The key or index of the item.
|
||||
* @return {Object} The item associated with the passed key.
|
||||
*/
|
||||
item : function(key){
|
||||
var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
|
||||
return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the item at the specified index.
|
||||
* @param {Number} index The index of the item.
|
||||
* @return {Object}
|
||||
*/
|
||||
itemAt : function(index){
|
||||
return this.items[index];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the item associated with the passed key.
|
||||
* @param {String/Number} key The key of the item.
|
||||
* @return {Object} The item associated with the passed key.
|
||||
*/
|
||||
key : function(key){
|
||||
return this.map[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the collection contains the passed Object as an item.
|
||||
* @param {Object} o The Object to look for in the collection.
|
||||
* @return {Boolean} True if the collection contains the Object as an item.
|
||||
*/
|
||||
contains : function(o){
|
||||
return this.indexOf(o) != -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the collection contains the passed Object as a key.
|
||||
* @param {String} key The key to look for in the collection.
|
||||
* @return {Boolean} True if the collection contains the Object as a key.
|
||||
*/
|
||||
containsKey : function(key){
|
||||
return typeof this.map[key] != "undefined";
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all items from the collection.
|
||||
*/
|
||||
clear : function(){
|
||||
this.length = 0;
|
||||
this.items = [];
|
||||
this.keys = [];
|
||||
this.map = {};
|
||||
this.fireEvent("clear");
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the first item in the collection.
|
||||
* @return {Object} the first item in the collection..
|
||||
*/
|
||||
first : function(){
|
||||
return this.items[0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the last item in the collection.
|
||||
* @return {Object} the last item in the collection..
|
||||
*/
|
||||
last : function(){
|
||||
return this.items[this.length-1];
|
||||
},
|
||||
|
||||
_sort : function(property, dir, fn){
|
||||
var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
|
||||
fn = fn || function(a, b){
|
||||
return a-b;
|
||||
};
|
||||
var c = [], k = this.keys, items = this.items;
|
||||
for(var i = 0, len = items.length; i < len; i++){
|
||||
c[c.length] = {key: k[i], value: items[i], index: i};
|
||||
}
|
||||
c.sort(function(a, b){
|
||||
var v = fn(a[property], b[property]) * dsc;
|
||||
if(v == 0){
|
||||
v = (a.index < b.index ? -1 : 1);
|
||||
}
|
||||
return v;
|
||||
});
|
||||
for(var i = 0, len = c.length; i < len; i++){
|
||||
items[i] = c[i].value;
|
||||
k[i] = c[i].key;
|
||||
}
|
||||
this.fireEvent("sort", this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sorts this collection with the passed comparison function
|
||||
* @param {String} direction (optional) "ASC" or "DESC"
|
||||
* @param {Function} fn (optional) comparison function
|
||||
*/
|
||||
sort : function(dir, fn){
|
||||
this._sort("value", dir, fn);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sorts this collection by keys
|
||||
* @param {String} direction (optional) "ASC" or "DESC"
|
||||
* @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
|
||||
*/
|
||||
keySort : function(dir, fn){
|
||||
this._sort("key", dir, fn || function(a, b){
|
||||
return String(a).toUpperCase()-String(b).toUpperCase();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a range of items in this collection
|
||||
* @param {Number} startIndex (optional) defaults to 0
|
||||
* @param {Number} endIndex (optional) default to the last item
|
||||
* @return {Array} An array of items
|
||||
*/
|
||||
getRange : function(start, end){
|
||||
var items = this.items;
|
||||
if(items.length < 1){
|
||||
return [];
|
||||
}
|
||||
start = start || 0;
|
||||
end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
|
||||
var r = [];
|
||||
if(start <= end){
|
||||
for(var i = start; i <= end; i++) {
|
||||
r[r.length] = items[i];
|
||||
}
|
||||
}else{
|
||||
for(var i = start; i >= end; i--) {
|
||||
r[r.length] = items[i];
|
||||
}
|
||||
}
|
||||
return r;
|
||||
},
|
||||
|
||||
/**
|
||||
* Filter the <i>objects</i> in this collection by a specific property.
|
||||
* Returns a new collection that has been filtered.
|
||||
* @param {String} property A property on your objects
|
||||
* @param {String/RegExp} value Either string that the property values
|
||||
* should start with or a RegExp to test against the property
|
||||
* @return {MixedCollection} The new filtered collection
|
||||
*/
|
||||
filter : function(property, value){
|
||||
if(!value.exec){ // not a regex
|
||||
value = String(value);
|
||||
if(value.length == 0){
|
||||
return this.clone();
|
||||
}
|
||||
value = new RegExp("^" + Ext.escapeRe(value), "i");
|
||||
}
|
||||
return this.filterBy(function(o){
|
||||
return o && value.test(o[property]);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Filter by a function. * Returns a new collection that has been filtered.
|
||||
* The passed function will be called with each
|
||||
* object in the collection. If the function returns true, the value is included
|
||||
* otherwise it is filtered.
|
||||
* @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
|
||||
* @param {Object} scope (optional) The scope of the function (defaults to this)
|
||||
* @return {MixedCollection} The new filtered collection
|
||||
*/
|
||||
filterBy : function(fn, scope){
|
||||
var r = new Ext.util.MixedCollection();
|
||||
r.getKey = this.getKey;
|
||||
var k = this.keys, it = this.items;
|
||||
for(var i = 0, len = it.length; i < len; i++){
|
||||
if(fn.call(scope||this, it[i], k[i])){
|
||||
r.add(k[i], it[i]);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a duplicate of this collection
|
||||
* @return {MixedCollection}
|
||||
*/
|
||||
clone : function(){
|
||||
var r = new Ext.util.MixedCollection();
|
||||
var k = this.keys, it = this.items;
|
||||
for(var i = 0, len = it.length; i < len; i++){
|
||||
r.add(k[i], it[i]);
|
||||
}
|
||||
r.getKey = this.getKey;
|
||||
return r;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Returns the item associated with the passed key or index.
|
||||
* @method
|
||||
* @param {String/Number} key The key or index of the item.
|
||||
* @return {Object} The item associated with the passed key.
|
||||
*/
|
||||
Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item;
|
||||
348
www/extras/yui-ext/source/util/Observable.js
vendored
Normal file
348
www/extras/yui-ext/source/util/Observable.js
vendored
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @class Ext.util.Observable
|
||||
* Abstract base class that provides a common interface for publishing events. Subclasses are expected to
|
||||
* to have a property "events" with all the events defined.<br>
|
||||
* For example:
|
||||
* <pre><code>
|
||||
Employee = function(name){
|
||||
this.name = name;
|
||||
this.events = {
|
||||
"fired" : true,
|
||||
"quit" : true
|
||||
}
|
||||
}
|
||||
Ext.extend(Employee, Ext.util.Observable);
|
||||
</code></pre>
|
||||
*/
|
||||
Ext.util.Observable = function(){
|
||||
if(this.listeners){
|
||||
this.on(this.listeners);
|
||||
delete this.listeners;
|
||||
}
|
||||
};
|
||||
Ext.util.Observable.prototype = {
|
||||
/**
|
||||
* Fires the specified event with the passed parameters (minus the event name).
|
||||
* @param {String} eventName
|
||||
* @param {Object...} args Variable number of parameters are passed to handlers
|
||||
* @return {Boolean} returns false if any of the handlers return false otherwise it returns true
|
||||
*/
|
||||
fireEvent : function(){
|
||||
var ce = this.events[arguments[0].toLowerCase()];
|
||||
if(typeof ce == "object"){
|
||||
return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
// private
|
||||
filterOptRe : /^(?:scope|delay|buffer|single)$/,
|
||||
|
||||
/**
|
||||
* Appends an event handler to this component
|
||||
* @param {String} eventName The type of event to listen for
|
||||
* @param {Function} handler The method the event invokes
|
||||
* @param {Object} scope (optional) The scope in which to execute the handler
|
||||
* function. The handler function's "this" context.
|
||||
* @param {Object} options (optional) An object containing handler configuration
|
||||
* properties. This may contain any of the following properties:<ul>
|
||||
* <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
|
||||
* <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
|
||||
* <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
|
||||
* <li>preventDefault {Boolean} True to prevent the default action</li>
|
||||
* <li>stopPropagation {Boolean} True to prevent event propagation</li>
|
||||
* <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Ext.EventObject</li>
|
||||
* <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
|
||||
* <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
|
||||
* <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
|
||||
* by the specified number of milliseconds. If the event fires again within that time, the original
|
||||
* handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* <b>Combining Options</b><br>
|
||||
* Using the options argument, it is possible to combine different types of listeners:<br>
|
||||
* <br>
|
||||
* A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
|
||||
* Code:
|
||||
* <pre><code>el.on('click', this.onClick, this, {
|
||||
* single: true,
|
||||
* delay: 100,
|
||||
* stopEvent : true,
|
||||
* forumId: 4
|
||||
* });</pre>
|
||||
* <p>
|
||||
* The method also allows for a single argument to be passed which is a config object containing properties
|
||||
* which specify multiple handlers.
|
||||
* <p>
|
||||
* <b>Attaching multiple handlers in 1 call</b><br>
|
||||
* Code:
|
||||
* <pre><code>el.on({
|
||||
* 'click' : {
|
||||
* fn: this.onClick
|
||||
* scope: this,
|
||||
* delay: 100
|
||||
* },
|
||||
* 'mouseover' : {
|
||||
* fn: this.onMouseOver
|
||||
* scope: this
|
||||
* },
|
||||
* 'mouseout' : {
|
||||
* fn: this.onMouseOut
|
||||
* scope: this
|
||||
* }
|
||||
* });</pre>
|
||||
* <p>
|
||||
* Or a shorthand syntax:<br>
|
||||
* Code:
|
||||
* <pre><code>el.on({
|
||||
* 'click' : this.onClick,
|
||||
* 'mouseover' : this.onMouseOver,
|
||||
* 'mouseout' : this.onMouseOut
|
||||
* scope: this
|
||||
* });</pre>
|
||||
*/
|
||||
addListener : function(eventName, fn, scope, o){
|
||||
if(typeof eventName == "object"){
|
||||
o = eventName;
|
||||
for(var e in o){
|
||||
if(this.filterOptRe.test(e)){
|
||||
continue;
|
||||
}
|
||||
if(typeof o[e] == "function"){
|
||||
// shared options
|
||||
this.addListener(e, o[e], o.scope, o);
|
||||
}else{
|
||||
// individual options
|
||||
this.addListener(e, o[e].fn, o[e].scope, o[e]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
o = (!o || typeof o == "boolean") ? {} : o;
|
||||
eventName = eventName.toLowerCase();
|
||||
var ce = this.events[eventName] || true;
|
||||
if(typeof ce == "boolean"){
|
||||
ce = new Ext.util.Event(this, eventName);
|
||||
this.events[eventName] = ce;
|
||||
}
|
||||
ce.addListener(fn, scope, o);
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a listener
|
||||
* @param {String} eventName The type of event to listen for
|
||||
* @param {Function} handler The handler to remove
|
||||
* @param {Object} scope (optional) The scope (this object) for the handler
|
||||
*/
|
||||
removeListener : function(eventName, fn, scope){
|
||||
var ce = this.events[eventName.toLowerCase()];
|
||||
if(typeof ce == "object"){
|
||||
ce.removeListener(fn, scope);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all listeners for this object
|
||||
*/
|
||||
purgeListeners : function(){
|
||||
for(var evt in this.events){
|
||||
if(typeof this.events[evt] == "object"){
|
||||
this.events[evt].clearListeners();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
relayEvents : function(o, events){
|
||||
var createHandler = function(ename){
|
||||
return function(){
|
||||
return this.fireEvent.apply(this, Ext.combine(ename, Array.prototype.slice.call(arguments, 0)));
|
||||
};
|
||||
};
|
||||
for(var i = 0, len = events.length; i < len; i++){
|
||||
var ename = events[i];
|
||||
if(!this.events[ename]){ this.events[ename] = true; };
|
||||
o.on(ename, createHandler(ename), this);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies any events from the passed object onto this object if they do not already exist. The passed object
|
||||
* must also inherit from Observable for this method to have any effect.
|
||||
* @param {Object} object The object from which to copy events
|
||||
*/
|
||||
addEvents : function(o){
|
||||
if(!this.events){
|
||||
this.events = {};
|
||||
}
|
||||
Ext.applyIf(this.events, o);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if this object is currently listening for a specified event
|
||||
* @param {String} eventName The name of the event to check for
|
||||
* @return {Boolean} True if the event is being listened for, else false
|
||||
*/
|
||||
hasListener : function(eventName){
|
||||
var e = this.events[eventName];
|
||||
return typeof e == "object" && e.listeners.length > 0;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Appends an event handler to this element (shorthand for addListener)
|
||||
* @param {String} eventName The type of event to listen for
|
||||
* @param {Function} handler The method the event invokes
|
||||
* @param {Object} options (optional)
|
||||
* @method
|
||||
*/
|
||||
Ext.util.Observable.prototype.on = Ext.util.Observable.prototype.addListener;
|
||||
/**
|
||||
* Removes a listener (shorthand for removeListener)
|
||||
* @param {String} eventName The type of event to listen for
|
||||
* @param {Function} handler The handler to remove
|
||||
* @param {Object} scope (optional) The scope (this object) for the handler
|
||||
* @method
|
||||
*/
|
||||
Ext.util.Observable.prototype.un = Ext.util.Observable.prototype.removeListener;
|
||||
|
||||
/**
|
||||
* Starts capture on the specified Observable. All events will be passed
|
||||
* to the supplied function with the event name + standard signature of the event
|
||||
* <b>before</b> the event is fired. If the supplied function returns false,
|
||||
* the event will not fire.
|
||||
* @param {Observable} o The Observable to capture
|
||||
* @param {Function} fn The function to call
|
||||
* @param {Object} scope (optional) The scope (this object) for the fn
|
||||
* @static
|
||||
*/
|
||||
Ext.util.Observable.capture = function(o, fn, scope){
|
||||
o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes <b>all</b> added captures from the Observable.
|
||||
* @param {Observable} o The Observable to release
|
||||
* @static
|
||||
*/
|
||||
Ext.util.Observable.releaseCapture = function(o){
|
||||
o.fireEvent = Ext.util.Observable.prototype.fireEvent;
|
||||
};
|
||||
|
||||
(function(){
|
||||
|
||||
var createBuffered = function(h, o, scope){
|
||||
var task = new Ext.util.DelayedTask();
|
||||
return function(){
|
||||
task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
|
||||
};
|
||||
};
|
||||
|
||||
var createSingle = function(h, e, fn, scope){
|
||||
return function(){
|
||||
e.removeListener(fn, scope);
|
||||
return h.apply(scope, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
var createDelayed = function(h, o, scope){
|
||||
return function(){
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
setTimeout(function(){
|
||||
h.apply(scope, args);
|
||||
}, o.delay || 10);
|
||||
};
|
||||
};
|
||||
|
||||
Ext.util.Event = function(obj, name){
|
||||
this.name = name;
|
||||
this.obj = obj;
|
||||
this.listeners = [];
|
||||
};
|
||||
|
||||
Ext.util.Event.prototype = {
|
||||
addListener : function(fn, scope, options){
|
||||
var o = options || {};
|
||||
scope = scope || this.obj;
|
||||
if(!this.isListening(fn, scope)){
|
||||
var l = {fn: fn, scope: scope, options: o};
|
||||
var h = fn;
|
||||
if(o.delay){
|
||||
h = createDelayed(h, o, scope);
|
||||
}
|
||||
if(o.single){
|
||||
h = createSingle(h, this, fn, scope);
|
||||
}
|
||||
if(o.buffer){
|
||||
h = createBuffered(h, o, scope);
|
||||
}
|
||||
l.fireFn = h;
|
||||
if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
|
||||
this.listeners.push(l);
|
||||
}else{
|
||||
this.listeners = this.listeners.slice(0);
|
||||
this.listeners.push(l);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
findListener : function(fn, scope){
|
||||
scope = scope || this.obj;
|
||||
var ls = this.listeners;
|
||||
for(var i = 0, len = ls.length; i < len; i++){
|
||||
var l = ls[i];
|
||||
if(l.fn == fn && l.scope == scope){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
|
||||
isListening : function(fn, scope){
|
||||
return this.findListener(fn, scope) != -1;
|
||||
},
|
||||
|
||||
removeListener : function(fn, scope){
|
||||
var index;
|
||||
if((index = this.findListener(fn, scope)) != -1){
|
||||
if(!this.firing){
|
||||
this.listeners.splice(index, 1);
|
||||
}else{
|
||||
this.listeners = this.listeners.slice(0);
|
||||
this.listeners.splice(index, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
clearListeners : function(){
|
||||
this.listeners = [];
|
||||
},
|
||||
|
||||
fire : function(){
|
||||
var ls = this.listeners, scope, len = ls.length;
|
||||
if(len > 0){
|
||||
this.firing = true;
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
for(var i = 0; i < len; i++){
|
||||
var l = ls[i];
|
||||
if(l.fireFn.apply(l.scope, arguments) === false){
|
||||
this.firing = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.firing = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
})();
|
||||
94
www/extras/yui-ext/source/util/TaskMgr.js
vendored
Normal file
94
www/extras/yui-ext/source/util/TaskMgr.js
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
Ext.util.TaskRunner = function(interval){
|
||||
interval = interval || 10;
|
||||
var tasks = [], removeQueue = [];
|
||||
var id = 0;
|
||||
var running = false;
|
||||
|
||||
var stopThread = function(){
|
||||
running = false;
|
||||
clearInterval(id);
|
||||
id = 0;
|
||||
};
|
||||
|
||||
var startThread = function(){
|
||||
if(!running){
|
||||
running = true;
|
||||
id = setInterval(runTasks, interval);
|
||||
}
|
||||
};
|
||||
|
||||
var removeTask = function(task){
|
||||
removeQueue.push(task);
|
||||
if(task.onStop){
|
||||
task.onStop();
|
||||
}
|
||||
};
|
||||
|
||||
var runTasks = function(){
|
||||
if(removeQueue.length > 0){
|
||||
for(var i = 0, len = removeQueue.length; i < len; i++){
|
||||
tasks.remove(removeQueue[i]);
|
||||
}
|
||||
removeQueue = [];
|
||||
if(tasks.length < 1){
|
||||
stopThread();
|
||||
return;
|
||||
}
|
||||
}
|
||||
var now = new Date().getTime();
|
||||
for(var i = 0, len = tasks.length; i < len; ++i){
|
||||
var t = tasks[i];
|
||||
var itime = now - t.taskRunTime;
|
||||
if(t.interval <= itime){
|
||||
var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
|
||||
t.taskRunTime = now;
|
||||
if(rt === false || t.taskRunCount === t.repeat){
|
||||
removeTask(t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(t.duration && t.duration <= (now - t.taskStartTime)){
|
||||
removeTask(t);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Queues a new task.
|
||||
* @param {Object} task
|
||||
*/
|
||||
this.start = function(task){
|
||||
tasks.push(task);
|
||||
task.taskStartTime = new Date().getTime();
|
||||
task.taskRunTime = 0;
|
||||
task.taskRunCount = 0;
|
||||
startThread();
|
||||
return task;
|
||||
};
|
||||
|
||||
this.stop = function(task){
|
||||
removeTask(task);
|
||||
return task;
|
||||
};
|
||||
|
||||
this.stopAll = function(){
|
||||
stopThread();
|
||||
for(var i = 0, len = tasks.length; i < len; i++){
|
||||
if(tasks[i].onStop){
|
||||
tasks[i].onStop();
|
||||
}
|
||||
}
|
||||
tasks = [];
|
||||
removeQueue = [];
|
||||
};
|
||||
};
|
||||
|
||||
Ext.TaskMgr = new Ext.util.TaskRunner();
|
||||
121
www/extras/yui-ext/source/util/TextMetrics.js
vendored
Normal file
121
www/extras/yui-ext/source/util/TextMetrics.js
vendored
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Ext JS Library 1.0.1
|
||||
* Copyright(c) 2006-2007, Ext JS, LLC.
|
||||
* licensing@extjs.com
|
||||
*
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Ext.util.TextMetrics
|
||||
* Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
|
||||
* wide, in pixels, a given block of text will be.
|
||||
* @singleton
|
||||
*/
|
||||
Ext.util.TextMetrics = function(){
|
||||
var shared;
|
||||
return {
|
||||
/**
|
||||
* Measures the size of the specified text
|
||||
* @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
|
||||
* that can affect the size of the rendered text
|
||||
* @param {String} text The text to measure
|
||||
* @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
|
||||
* in order to accurately measure the text height
|
||||
* @return {Object} An object containing the text's size {width: (width), height: (height)}
|
||||
*/
|
||||
measure : function(el, text, fixedWidth){
|
||||
if(!shared){
|
||||
shared = Ext.util.TextMetrics.Instance(el, fixedWidth);
|
||||
}
|
||||
shared.bind(el);
|
||||
shared.setFixedWidth(fixedWidth || 'auto');
|
||||
return shared.getSize(text);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
|
||||
* the overhead of multiple calls to initialize the style properties on each measurement.
|
||||
* @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
|
||||
* @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
|
||||
* in order to accurately measure the text height
|
||||
* @return {Ext.util.TextMetrics.Instance} instance The new instance
|
||||
*/
|
||||
createInstance : function(el, fixedWidth){
|
||||
return Ext.util.TextMetrics.Instance(el, fixedWidth);
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
Ext.util.TextMetrics.Instance = function(bindTo, fixedWidth){
|
||||
var ml = new Ext.Element(document.createElement('div'));
|
||||
document.body.appendChild(ml.dom);
|
||||
ml.position('absolute');
|
||||
ml.setLeftTop(-1000, -1000);
|
||||
ml.hide();
|
||||
|
||||
if(fixedWidth){
|
||||
mi.setWidth(fixedWidth);
|
||||
}
|
||||
|
||||
var instance = {
|
||||
/**
|
||||
* Returns the size of the specified text based on the internal element's style and width properties
|
||||
* @param {String} text The text to measure
|
||||
* @return {Object} An object containing the text's size {width: (width), height: (height)}
|
||||
*/
|
||||
getSize : function(text){
|
||||
ml.update(text);
|
||||
var s = ml.getSize();
|
||||
ml.update('');
|
||||
return s;
|
||||
},
|
||||
|
||||
/**
|
||||
* Binds this TextMetrics instance to an element from which to copy existing CSS styles
|
||||
* that can affect the size of the rendered text
|
||||
* @param {String/HTMLElement} el The element, dom node or id
|
||||
*/
|
||||
bind : function(el){
|
||||
ml.setStyle(
|
||||
Ext.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a fixed width on the internal measurement element. If the text will be multiline, you have
|
||||
* to set a fixed width in order to accurately measure the text height.
|
||||
* @param {Number} width The width to set on the element
|
||||
*/
|
||||
setFixedWidth : function(width){
|
||||
ml.setWidth(width);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the measured width of the specified text
|
||||
* @param {String} text The text to measure
|
||||
* @return {Number} width The width in pixels
|
||||
*/
|
||||
getWidth : function(text){
|
||||
ml.dom.style.width = 'auto';
|
||||
return this.getSize(text).width;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the measured height of the specified text. For multiline text, be sure to call
|
||||
* {@link #setFixedWidth} if necessary.
|
||||
* @param {String} text The text to measure
|
||||
* @return {Number} height The height in pixels
|
||||
*/
|
||||
getHeight : function(text){
|
||||
return this.getSize(text).height;
|
||||
}
|
||||
};
|
||||
|
||||
instance.bind(bindTo);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
// backwards compat
|
||||
Ext.Element.measureText = Ext.util.TextMetrics.measure;
|
||||
Loading…
Add table
Add a link
Reference in a new issue