Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 26 → Rev 27

/trunk/www/org.tela_botanica.cel2/js/ext/source/util/MixedCollection.js
New file
0,0 → 1,567
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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",
/**
* @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",
/**
* @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",
/**
* @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",
"sort"
);
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. Fires the {@link #add} event when complete.
* @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. The default implementation
* simply returns <tt style="font-weight:bold;">item.id</tt> but you can provide your own implementation
* to return a different value as in the following examples:
<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);
 
// or via the constructor
var mc = new Ext.util.MixedCollection(false, function(el){
return el.dom.id;
});
mc.add(someEl);
mc.add(otherEl);
</code></pre>
* @param {Object} item 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. Fires the {@link #replace} event when complete.
* @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 || Ext.isArray(objs)){
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(key, objs[key]);
}
}
}
},
 
/**
* Executes the specified function once for every item in the collection, passing the following arguments:
* <div class="mdetail-params"><ul>
* <li><b>item</b> : Mixed<p class="sub-desc">The collection item</p></li>
* <li><b>index</b> : Number<p class="sub-desc">The item's index</p></li>
* <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
* </ul></div>
* The function should return a boolean value. 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. Fires the {@link #add} event when complete.
* @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 or false if no item was removed.
*/
remove : function(o){
return this.removeAt(this.indexOf(o));
},
 
/**
* Remove an item from a specified index in the collection. Fires the {@link #remove} event when complete.
* @param {Number} index The index within the collection of the item to remove.
* @return {Object} The item removed or false if no item was removed.
*/
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);
return o;
}
return false;
},
 
/**
* Removed an item associated with the passed key fom the collection.
* @param {String} key The key of the item to remove.
* @return {Object} The item removed or false if no item was removed.
*/
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){
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){
return this.keys.indexOf(key);
},
 
/**
* Returns the item associated with the passed key OR index. Key has priority over index. This is the equivalent
* of calling {@link #key} first, then if nothing matched calling {@link #itemAt}.
* @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} The item at the specified index.
*/
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. Fires the {@link #clear} event when complete.
*/
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];
},
 
// private
_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
* @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
* @param {Boolean} caseSensitive (optional) True for case sensitive comparison (defaults to False).
* @return {MixedCollection} The new filtered collection
*/
filter : function(property, value, anyMatch, caseSensitive){
if(Ext.isEmpty(value, false)){
return this.clone();
}
value = this.createValueMatcher(value, anyMatch, caseSensitive);
return this.filterBy(function(o){
return o && value.test(o[property]);
});
},
 
/**
* Filter by a function. Returns a <i>new</i> 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;
},
 
/**
* Finds the index of the first matching object in this collection by a specific property/value.
* @param {String} property The name of a property on your objects.
* @param {String/RegExp} value A string that the property values
* should start with or a RegExp to test against the property.
* @param {Number} start (optional) The index to start searching at (defaults to 0).
* @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning.
* @param {Boolean} caseSensitive (optional) True for case sensitive comparison.
* @return {Number} The matched index or -1
*/
findIndex : function(property, value, start, anyMatch, caseSensitive){
if(Ext.isEmpty(value, false)){
return -1;
}
value = this.createValueMatcher(value, anyMatch, caseSensitive);
return this.findIndexBy(function(o){
return o && value.test(o[property]);
}, null, start);
},
 
/**
* Find the index of the first matching object in this collection by a function.
* If the function returns <i>true</i> it is considered a match.
* @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).
* @param {Number} start (optional) The index to start searching at (defaults to 0).
* @return {Number} The matched index or -1
*/
findIndexBy : function(fn, scope, start){
var k = this.keys, it = this.items;
for(var i = (start||0), len = it.length; i < len; i++){
if(fn.call(scope||this, it[i], k[i])){
return i;
}
}
if(typeof start == 'number' && start > 0){
for(var i = 0; i < start; i++){
if(fn.call(scope||this, it[i], k[i])){
return i;
}
}
}
return -1;
},
 
// private
createValueMatcher : function(value, anyMatch, caseSensitive){
if(!value.exec){ // not a regex
value = String(value);
value = new RegExp((anyMatch === true ? '' : '^') + Ext.escapeRe(value), caseSensitive ? '' : 'i');
}
return value;
},
 
/**
* 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;
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/XTemplate.js
New file
0,0 → 1,354
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
 
/**
* @class Ext.XTemplate
* @extends Ext.Template
* <p>A template class that supports advanced functionality like autofilling arrays, conditional processing with
* basic comparison operators, sub-templates, basic math function support, special built-in template variables,
* inline code execution and more. XTemplate also provides the templating mechanism built into {@link Ext.DataView}.</p>
* <p>XTemplate supports many special tags and built-in operators that aren't defined as part of the API, but are
* supported in the templates that can be created. The following examples demonstrate all of the supported features.
* This is the data object used for reference in each code example:</p>
* <pre><code>
var data = {
name: 'Jack Slocum',
title: 'Lead Developer',
company: 'Ext JS, LLC',
email: 'jack@extjs.com',
address: '4 Red Bulls Drive',
city: 'Cleveland',
state: 'Ohio',
zip: '44102',
drinks: ['Red Bull', 'Coffee', 'Water'],
kids: [{
name: 'Sara Grace',
age:3
},{
name: 'Zachary',
age:2
},{
name: 'John James',
age:0
}]
};
</code></pre>
* <p><b>Auto filling of arrays and scope switching</b><br/>Using the <tt>tpl</tt> tag and the <tt>for</tt> operator,
* you can switch to the scope of the object specified by <tt>for</tt> and access its members to populate the teamplte.
* If the variable in <tt>for</tt> is an array, it will auto-fill, repeating the template block inside the <tt>tpl</tt>
* tag for each item in the array:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Title: {title}&lt;/p>',
'&lt;p>Company: {company}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;p>{name}&lt;/p>',
'&lt;/tpl>&lt;/p>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Access to parent object from within sub-template scope</b><br/>When processing a sub-template, for example while
* looping through a child array, you can access the parent object's members via the <tt>parent</tt> object:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;tpl if="age &gt; 1">',
'&lt;p>{name}&lt;/p>',
'&lt;p>Dad: {parent.name}&lt;/p>',
'&lt;/tpl>',
'&lt;/tpl>&lt;/p>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Array item index and basic math support</b> <br/>While processing an array, the special variable <tt>{#}</tt>
* will provide the current array index + 1 (starts at 1, not 0). Templates also support the basic math operators
* + - * and / that can be applied directly on numeric data values:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;tpl if="age &gt; 1">',
'&lt;p>{#}: {name}&lt;/p>', // <-- Auto-number each item
'&lt;p>In 5 Years: {age+5}&lt;/p>', // <-- Basic math
'&lt;p>Dad: {parent.name}&lt;/p>',
'&lt;/tpl>',
'&lt;/tpl>&lt;/p>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Auto-rendering of flat arrays</b> <br/>Flat arrays that contain values (and not objects) can be auto-rendered
* using the special <tt>{.}</tt> variable inside a loop. This variable will represent the value of
* the array at the current index:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>{name}\'s favorite beverages:&lt;/p>',
'&lt;tpl for="drinks">',
'&lt;div> - {.}&lt;/div>',
'&lt;/tpl>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Basic conditional logic</b> <br/>Using the <tt>tpl</tt> tag and the <tt>if</tt>
* operator you can provide conditional checks for deciding whether or not to render specific parts of the template.
* Note that there is no <tt>else</tt> operator &mdash; if needed, you should use two opposite <tt>if</tt> statements.
* Properly-encoded attributes are required as seen in the following example:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;tpl if="age &amp;gt; 1">', // <-- Note that the &gt; is encoded
'&lt;p>{name}&lt;/p>',
'&lt;/tpl>',
'&lt;/tpl>&lt;/p>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Ability to execute arbitrary inline code</b> <br/>In an XTemplate, anything between {[ ... ]} is considered
* code to be executed in the scope of the template. There are some special variables available in that code:
* <ul>
* <li><b><tt>values</tt></b>: The values in the current scope. If you are using scope changing sub-templates, you
* can change what <tt>values</tt> is.</li>
* <li><b><tt>parent</tt></b>: The scope (values) of the ancestor template.</li>
* <li><b><tt>xindex</tt></b>: If you are in a looping template, the index of the loop you are in (1-based).</li>
* <li><b><tt>xcount</tt></b>: If you are in a looping template, the total length of the array you are looping.</li>
* <li><b><tt>fm</tt></b>: An alias for <tt>Ext.util.Format</tt>.</li>
* </ul>
* This example demonstrates basic row striping using an inline code block and the <tt>xindex</tt> variable:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Company: {[company.toUpperCase() + ', ' + title]}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;div class="{[xindex % 2 === 0 ? "even" : "odd"]}">,
'{name}',
'&lt;/div>',
'&lt;/tpl>&lt;/p>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* <p><b>Template member functions</b> <br/>One or more member functions can be defined directly on the config
* object passed into the XTemplate constructor for more complex processing:</p>
* <pre><code>
var tpl = new Ext.XTemplate(
'&lt;p>Name: {name}&lt;/p>',
'&lt;p>Kids: ',
'&lt;tpl for="kids">',
'&lt;tpl if="this.isGirl(name)">',
'&lt;p>Girl: {name} - {age}&lt;/p>',
'&lt;/tpl>',
'&lt;tpl if="this.isGirl(name) == false">',
'&lt;p>Boy: {name} - {age}&lt;/p>',
'&lt;/tpl>',
'&lt;tpl if="this.isBaby(age)">',
'&lt;p>{name} is a baby!&lt;/p>',
'&lt;/tpl>',
'&lt;/tpl>&lt;/p>', {
isGirl: function(name){
return name == 'Sara Grace';
},
isBaby: function(age){
return age < 1;
}
});
tpl.overwrite(panel.body, data);
</code></pre>
* @constructor
* @param {String/Array/Object} parts The HTML fragment or an array of fragments to join(""), or multiple arguments
* to join("") that can also include a config object
*/
Ext.XTemplate = function(){
Ext.XTemplate.superclass.constructor.apply(this, arguments);
var s = this.html;
 
s = ['<tpl>', s, '</tpl>'].join('');
 
var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;
 
var nameRe = /^<tpl\b[^>]*?for="(.*?)"/;
var ifRe = /^<tpl\b[^>]*?if="(.*?)"/;
var execRe = /^<tpl\b[^>]*?exec="(.*?)"/;
var m, id = 0;
var tpls = [];
 
while(m = s.match(re)){
var m2 = m[0].match(nameRe);
var m3 = m[0].match(ifRe);
var m4 = m[0].match(execRe);
var exp = null, fn = null, exec = null;
var name = m2 && m2[1] ? m2[1] : '';
if(m3){
exp = m3 && m3[1] ? m3[1] : null;
if(exp){
fn = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ return '+(Ext.util.Format.htmlDecode(exp))+'; }');
}
}
if(m4){
exp = m4 && m4[1] ? m4[1] : null;
if(exp){
exec = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ '+(Ext.util.Format.htmlDecode(exp))+'; }');
}
}
if(name){
switch(name){
case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
}
}
tpls.push({
id: id,
target: name,
exec: exec,
test: fn,
body: m[1]||''
});
s = s.replace(m[0], '{xtpl'+ id + '}');
++id;
}
for(var i = tpls.length-1; i >= 0; --i){
this.compileTpl(tpls[i]);
}
this.master = tpls[tpls.length-1];
this.tpls = tpls;
};
Ext.extend(Ext.XTemplate, Ext.Template, {
// private
re : /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g,
// private
codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g,
 
// private
applySubTemplate : function(id, values, parent, xindex, xcount){
var t = this.tpls[id];
if(t.test && !t.test.call(this, values, parent, xindex, xcount)){
return '';
}
if(t.exec && t.exec.call(this, values, parent, xindex, xcount)){
return '';
}
var vs = t.target ? t.target.call(this, values, parent) : values;
parent = t.target ? values : parent;
if(t.target && Ext.isArray(vs)){
var buf = [];
for(var i = 0, len = vs.length; i < len; i++){
buf[buf.length] = t.compiled.call(this, vs[i], parent, i+1, len);
}
return buf.join('');
}
return t.compiled.call(this, vs, parent, xindex, xcount);
},
 
// private
compileTpl : function(tpl){
var fm = Ext.util.Format;
var useF = this.disableFormats !== true;
var sep = Ext.isGecko ? "+" : ",";
var fn = function(m, name, format, args, math){
if(name.substr(0, 4) == 'xtpl'){
return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'";
}
var v;
if(name === '.'){
v = 'values';
}else if(name === '#'){
v = 'xindex';
}else if(name.indexOf('.') != -1){
v = name;
}else{
v = "values['" + name + "']";
}
if(math){
v = '(' + v + math + ')';
}
if(format && useF){
args = args ? ',' + args : "";
if(format.substr(0, 5) != "this."){
format = "fm." + format + '(';
}else{
format = 'this.call("'+ format.substr(5) + '", ';
args = ", values";
}
}else{
args= ''; format = "("+v+" === undefined ? '' : ";
}
return "'"+ sep + format + v + args + ")"+sep+"'";
};
var codeFn = function(m, code){
return "'"+ sep +'('+code+')'+sep+"'";
};
 
var body;
// branched to use + in gecko and [].join() in others
if(Ext.isGecko){
body = "tpl.compiled = function(values, parent, xindex, xcount){ return '" +
tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn) +
"';};";
}else{
body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"];
body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn));
body.push("'].join('');};");
body = body.join('');
}
eval(body);
return this;
},
 
/**
* Alias of {@link #applyTemplate}.
*/
apply : function(values){
return this.master.compiled.call(this, values, {}, 1, 1);
},
 
/**
* Returns an HTML fragment of this template with the specified values applied.
* @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
* @return {String} The HTML fragment
*/
applyTemplate : function(values){
return this.master.compiled.call(this, values, {}, 1, 1);
},
 
/**
* Compile the template to a function for optimized performance. Recommended if the template will be used frequently.
* @return {Function} The compiled function
*/
compile : function(){return this;}
 
/**
* @property re
* @hide
*/
/**
* @property disableFormats
* @hide
*/
/**
* @method set
* @hide
*/
});
 
/**
* Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
* @param {String/HTMLElement} el A DOM element or its id
* @return {Ext.Template} The created template
* @static
*/
Ext.XTemplate.from = function(el){
el = Ext.getDom(el);
return new Ext.XTemplate(el.value || el.innerHTML);
};
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/Observable.js
New file
0,0 → 1,470
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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.addEvents({
"fired" : true,
"quit" : true
});
}
Ext.extend(Employee, Ext.util.Observable);
</code></pre>
*/
Ext.util.Observable = function(){
/**
* @cfg {Object} listeners A config object containing one or more event handlers to be added to this
* object during initialization. This should be a valid listeners config object as specified in the
* {@link #addListener} example for attaching multiple handlers at once.
*/
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(){
if(this.eventsSuspended !== true){
var ce = this.events[arguments[0].toLowerCase()];
if(typeof ce == "object"){
return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
}
}
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><b>scope</b> : Object<p class="sub-desc">The scope in which to execute the handler function. The handler function's "this" context.</p></li>
* <li><b>delay</b> : Number<p class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</p></li>
* <li><b>single</b> : Boolean<p class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</p></li>
* <li><b>buffer</b> : Number<p class="sub-desc">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.</p></li>
* </ul><br>
* <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)
* <pre><code>
el.on('click', this.onClick, this, {
single: true,
delay: 100,
forumId: 4
});</code></pre>
* <p>
* <b>Attaching multiple handlers in 1 call</b><br>
* The method also allows for a single argument to be passed which is a config object containing properties
* which specify multiple handlers.
* <p>
* <pre><code>
foo.on({
'click' : {
fn: this.onClick,
scope: this,
delay: 100
},
'mouseover' : {
fn: this.onMouseOver,
scope: this
},
'mouseout' : {
fn: this.onMouseOut,
scope: this
}
});</code></pre>
* <p>
* Or a shorthand syntax:<br>
* <pre><code>
foo.on({
'click' : this.onClick,
'mouseover' : this.onMouseOver,
'mouseout' : this.onMouseOut,
scope: this
});</code></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);
}
},
 
/**
* Used to define events on this Observable
* @param {Object} object The object with the events defined
*/
addEvents : function(o){
if(!this.events){
this.events = {};
}
if(typeof o == 'string'){
for(var i = 0, a = arguments, v; v = a[i]; i++){
if(!this.events[a[i]]){
o[a[i]] = true;
}
}
}else{
Ext.applyIf(this.events, o);
}
},
 
/**
* Checks to see if this object has any listeners 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;
},
 
/**
* Suspend the firing of all events. (see {@link #resumeEvents})
*/
suspendEvents : function(){
this.eventsSuspended = true;
},
 
/**
* Resume firing events. (see {@link #suspendEvents})
*/
resumeEvents : function(){
this.eventsSuspended = false;
},
 
// these are considered experimental
// allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
// private
getMethodEvent : function(method){
if(!this.methodEvents){
this.methodEvents = {};
}
var e = this.methodEvents[method];
if(!e){
e = {};
this.methodEvents[method] = e;
 
e.originalFn = this[method];
e.methodName = method;
e.before = [];
e.after = [];
 
 
var returnValue, v, cancel;
var obj = this;
 
var makeCall = function(fn, scope, args){
if((v = fn.apply(scope || obj, args)) !== undefined){
if(typeof v === 'object'){
if(v.returnValue !== undefined){
returnValue = v.returnValue;
}else{
returnValue = v;
}
if(v.cancel === true){
cancel = true;
}
}else if(v === false){
cancel = true;
}else {
returnValue = v;
}
}
}
 
this[method] = function(){
returnValue = v = undefined; cancel = false;
var args = Array.prototype.slice.call(arguments, 0);
for(var i = 0, len = e.before.length; i < len; i++){
makeCall(e.before[i].fn, e.before[i].scope, args);
if(cancel){
return returnValue;
}
}
 
if((v = e.originalFn.apply(obj, args)) !== undefined){
returnValue = v;
}
 
for(var i = 0, len = e.after.length; i < len; i++){
makeCall(e.after[i].fn, e.after[i].scope, args);
if(cancel){
return returnValue;
}
}
return returnValue;
};
}
return e;
},
 
// adds an "interceptor" called before the original method
beforeMethod : function(method, fn, scope){
var e = this.getMethodEvent(method);
e.before.push({fn: fn, scope: scope});
},
 
// adds a "sequence" called after the original method
afterMethod : function(method, fn, scope){
var e = this.getMethodEvent(method);
e.after.push({fn: fn, scope: scope});
},
 
removeMethodListener : function(method, fn, scope){
var e = this.getMethodEvent(method);
for(var i = 0, len = e.before.length; i < len; i++){
if(e.before[i].fn == fn && e.before[i].scope == scope){
e.before.splice(i, 1);
return;
}
}
for(var i = 0, len = e.after.length; i < len; i++){
if(e.after[i].fn == fn && e.after[i].scope == scope){
e.after.splice(i, 1);
return;
}
}
}
};
/**
* 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} scope (optional) The scope in which to execute the handler
* function. The handler function's "this" context.
* @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){
scope = scope || this.obj;
if(!this.isListening(fn, scope)){
var l = this.createListener(fn, scope, options);
if(!this.firing){
this.listeners.push(l);
}else{ // if we are currently firing this event, don't disturb the listener loop
this.listeners = this.listeners.slice(0);
this.listeners.push(l);
}
}
},
 
createListener : function(fn, scope, o){
o = o || {};
scope = scope || this.obj;
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;
return 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||this.obj||window, arguments) === false){
this.firing = false;
return false;
}
}
this.firing = false;
}
return true;
}
};
})();
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/KeyMap.js
New file
0,0 → 1,221
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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 KeyMap starts enabled</b>
* @constructor
* @param {Mixed} el The element to bind to
* @param {Object} config The config (see {@link #addBinding})
* @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){
this.addBinding(config);
}
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)
handler Function The function to call when KeyMap finds the expected key combination
fn Function Alias of handler (for backwards-compatibility)
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/Array} config A single KeyMap config or an array of configs
*/
addBinding : function(config){
if(Ext.isArray(config)){
for(var i = 0, len = config.length; i < len; i++){
this.addBinding(config[i]);
}
return;
}
var keyCode = config.key,
shift = config.shift,
ctrl = config.ctrl,
alt = config.alt,
fn = config.fn || config.handler,
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 = Ext.isArray(keyCode);
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);
},
 
/**
* Shorthand for adding a single key listener
* @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
* following options:
* {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
* @param {Function} fn The function to call
* @param {Object} scope (optional) The scope of the function
*/
on : function(key, fn, scope){
var keyCode, shift, ctrl, alt;
if(typeof key == "object" && !Ext.isArray(key)){
keyCode = key.key;
shift = key.shift;
ctrl = key.ctrl;
alt = key.alt;
}else{
keyCode = key;
}
this.addBinding({
key: keyCode,
shift: shift,
ctrl: ctrl,
alt: alt,
fn: fn,
scope: scope
})
},
 
// 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 KeyMap is enabled
* @return {Boolean}
*/
isEnabled : function(){
return this.enabled;
},
 
/**
* Enables this KeyMap
*/
enable: function(){
if(!this.enabled){
this.el.on(this.eventName, this.handleKeyDown, this);
this.enabled = true;
}
},
 
/**
* Disable this KeyMap
*/
disable: function(){
if(this.enabled){
this.el.removeListener(this.eventName, this.handleKeyDown, this);
this.enabled = false;
}
}
};
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/CSS.js
New file
0,0 → 1,163
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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 {
/**
* Creates a stylesheet from a text blob of rules.
* These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
* @param {String} cssText The text containing the css rules
* @param {String} id An id to add to the stylesheet for later removal
* @return {StyleSheet}
*/
createStyleSheet : function(cssText, id){
var ss;
var head = doc.getElementsByTagName("head")[0];
var rules = doc.createElement("style");
rules.setAttribute("type", "text/css");
if(id){
rules.setAttribute("id", id);
}
if(Ext.isIE){
head.appendChild(rules);
ss = rules.styleSheet;
ss.cssText = cssText;
}else{
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(!Ext.isArray(selector)){
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(!Ext.isArray(selector)){
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;
}
};
}();
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/Format.js
New file
0,0 → 1,223
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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 value !== undefined ? value : "";
},
 
/**
* Checks a reference and converts it to the default value if it's empty
* @param {Mixed} value Reference to check
* @param {String} defaultValue The value to insert of it's undefined (defaults to "")
* @return {String}
*/
defaultValue : function(value, defaultValue){
return value !== undefined && value !== '' ? value : defaultValue;
},
 
/**
* 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, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
},
 
/**
* Convert certain characters (&, <, >, and ') from their HTML character equivalents.
* @param {String} value The string to decode
* @return {String} The decoded text
*/
htmlDecode : function(value){
return !value ? value : String(value).replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/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);
v = String(v);
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.'+ ps[1] : '.00';
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if(v.charAt(0) == '-'){
return '-$' + v.substr(1);
}
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(!Ext.isDate(v)){
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, "");
},
 
stripScriptsRe : /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
 
/**
* Strips all script tags
* @param {Mixed} value The text from which to strip script tags
* @return {String} The stripped text
*/
stripScripts : function(v){
return !v ? v : String(v).replace(this.stripScriptsRe, "");
},
 
/**
* Simple format for a file size (xxx bytes, xxx KB, xxx MB)
* @param {Number/String} size The numeric value to format
* @return {String} The formatted file size
*/
fileSize : function(size){
if(size < 1024) {
return size + " bytes";
} else if(size < 1048576) {
return (Math.round(((size*10) / 1024))/10) + " KB";
} else {
return (Math.round(((size*10) / 1048576))/10) + " MB";
}
},
 
math : function(){
var fns = {};
return function(v, a){
if(!fns[a]){
fns[a] = new Function('v', 'return v ' + a + ';');
}
return fns[a](v);
}
}()
};
}();
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/TaskMgr.js
New file
0,0 → 1,157
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
 
/**
* @class Ext.util.TaskRunner
* Provides the ability to execute one or more arbitrary tasks in a multithreaded manner. Generally, you can use
* the singleton {@link Ext.TaskMgr} instead, but if needed, you can create separate instances of TaskRunner. Any
* number of separate tasks can be started at any time and will run independently of each other. Example usage:
* <pre><code>
// Start a simple clock task that updates a div once per second
var task = {
run: function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
},
interval: 1000 //1 second
}
var runner = new Ext.util.TaskRunner();
runner.start(task);
</code></pre>
* @constructor
* @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
* (defaults to 10)
*/
Ext.util.TaskRunner = function(interval){
interval = interval || 10;
var tasks = [], removeQueue = [];
var id = 0;
var running = false;
 
// private
var stopThread = function(){
running = false;
clearInterval(id);
id = 0;
};
 
// private
var startThread = function(){
if(!running){
running = true;
id = setInterval(runTasks, interval);
}
};
 
// private
var removeTask = function(t){
removeQueue.push(t);
if(t.onStop){
t.onStop.apply(t.scope || t);
}
};
 
// private
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);
}
}
};
 
/**
* Starts a new task.
* @param {Object} task A config object that supports the following properties:<ul>
* <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The
* function will be called at each interval and passed the <code>args</code> argument if specified. If a
* particular scope is required, be sure to specify it using the <code>scope</scope> argument.</div></li>
* <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
* should be executed.</div></li>
* <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
* specified by <code>run</code>.</div></li>
* <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope in which to execute the
* <code>run</code> function.</div></li>
* <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute
* the task before stopping automatically (defaults to indefinite).</div></li>
* <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before
* stopping automatically (defaults to indefinite).</div></li>
* </ul>
* @return {Object} The task
*/
this.start = function(task){
tasks.push(task);
task.taskStartTime = new Date().getTime();
task.taskRunTime = 0;
task.taskRunCount = 0;
startThread();
return task;
};
 
/**
* Stops an existing running task.
* @param {Object} task The task to stop
* @return {Object} The task
*/
this.stop = function(task){
removeTask(task);
return task;
};
 
/**
* Stops all tasks that are currently running.
*/
this.stopAll = function(){
stopThread();
for(var i = 0, len = tasks.length; i < len; i++){
if(tasks[i].onStop){
tasks[i].onStop();
}
}
tasks = [];
removeQueue = [];
};
};
 
/**
* @class Ext.TaskMgr
* A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
* {@link Ext.util.TaskRunner} for supported methods and task config properties.
* <pre><code>
// Start a simple clock task that updates a div once per second
var task = {
run: function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
},
interval: 1000 //1 second
}
Ext.TaskMgr.start(task);
</code></pre>
* @singleton
*/
Ext.TaskMgr = new Ext.util.TaskRunner();
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/JSON.js
New file
0,0 → 1,143
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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(Ext.isArray(o)){
return encodeArray(o);
}else if(Ext.isDate(o)){
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;
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/DelayedTask.js
New file
0,0 → 1,62
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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;
}
};
};
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/TextMetrics.js
New file
0,0 → 1,121
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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){
ml.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;
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/ClickRepeater.js
New file
0,0 → 1,157
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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 20 milliseconds.
 
Optionally, a CSS class may be applied to the element during the time it is pressed.
 
@cfg {Mixed} 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 20 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.
@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 {Mixed} 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",
/**
* @event click
* Fires on a specified interval during the time the element is pressed.
* @param {Ext.util.ClickRepeater} this
*/
"click",
/**
* @event mouseup
* Fires when the mouse key is released.
* @param {Ext.util.ClickRepeater} this
*/
"mouseup"
);
 
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,
 
// private
handleMouseDown : function(){
clearTimeout(this.timer);
this.el.blur();
if(this.pressClass){
this.el.addClass(this.pressClass);
}
this.mousedownTime = new Date();
 
Ext.getDoc().on("mouseup", this.handleMouseUp, this);
this.el.on("mouseout", this.handleMouseOut, this);
 
this.fireEvent("mousedown", this);
this.fireEvent("click", this);
 
// Do not honor delay or interval if acceleration wanted.
if (this.accelerate) {
this.delay = 400;
}
this.timer = this.click.defer(this.delay || this.interval, this);
},
 
// private
click : function(){
this.fireEvent("click", this);
this.timer = this.click.defer(this.accelerate ?
this.easeOutExpo(this.mousedownTime.getElapsed(),
400,
-390,
12000) :
this.interval, this);
},
 
easeOutExpo : function (t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
 
// 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);
Ext.getDoc().un("mouseup", this.handleMouseUp);
this.el.removeClass(this.pressClass);
this.fireEvent("mouseup", this);
}
});
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/Date.js
New file
0,0 → 1,886
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://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.
*
* The following is a list of all currently supported formats:
*<pre>
Format Description Example returned values
------ ----------------------------------------------------------------------- -----------------------
d Day of the month, 2 digits with leading zeros 01 to 31
D A short textual representation of the day of the week Mon to Sun
j Day of the month without leading zeros 1 to 31
l A full textual representation of the day of the week Sunday to Saturday
N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
z The day of the year (starting from 0) 0 to 364 (365 in leap years)
W ISO-8601 week number of year, weeks starting on Monday 01 to 53
F A full textual representation of a month, such as January or March January to December
m Numeric representation of a month, with leading zeros 01 to 12
M A short textual representation of a month Jan to Dec
n Numeric representation of a month, without leading zeros 1 to 12
t Number of days in the given month 28 to 31
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
belongs to the previous or next year, that year is used instead)
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y A two digit representation of a year Examples: 99 or 03
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
g 12-hour format of an hour without leading zeros 1 to 12
G 24-hour format of an hour without leading zeros 0 to 23
h 12-hour format of an hour with leading zeros 01 to 12
H 24-hour format of an hour with leading zeros 00 to 23
i Minutes, with leading zeros 00 to 59
s Seconds, with leading zeros 00 to 59
u Milliseconds, with leading zeros 001 to 999
O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
c ISO 8601 date 2007-04-17T15:19:21+08:00
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
</pre>
*
* Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
* <pre><code>
// Sample date:
// 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
 
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 jS 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.getShortDayName(this.getDay()) + "; // get L10n short day name
case "j":
return "this.getDate() + ";
case "l":
return "Date.dayNames[this.getDay()] + ";
case "N":
return "(this.getDay() ? this.getDay() : 7) + ";
case "S":
return "this.getSuffix() + ";
case "w":
return "this.getDay() + ";
case "z":
return "this.getDayOfYear() + ";
case "W":
return "String.leftPad(this.getWeekOfYear(), 2, '0') + ";
case "F":
return "Date.monthNames[this.getMonth()] + ";
case "m":
return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
case "M":
return "Date.getShortMonthName(this.getMonth()) + "; // get L10n short month name
case "n":
return "(this.getMonth() + 1) + ";
case "t":
return "this.getDaysInMonth() + ";
case "L":
return "(this.isLeapYear() ? 1 : 0) + ";
case "o":
return "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -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 "u":
return "String.leftPad(this.getMilliseconds(), 3, '0') + ";
case "O":
return "this.getGMTOffset() + ";
case "P":
return "this.getGMTOffset(true) + ";
case "T":
return "this.getTimezone() + ";
case "Z":
return "(this.getTimezoneOffset() * -60) + ";
case "c":
for (var df = Date.getFormatCode, c = "Y-m-dTH:i:sP", code = "", i = 0, l = c.length; i < l; ++i) {
var e = c.charAt(i);
code += e == "T" ? "'T' + " : df(e); // treat T as a literal
}
return code;
case "U":
return "Math.round(this.getTime() / 1000) + ";
default:
return "'" + String.escape(character) + "' + ";
}
};
 
/**
* Parses the passed string using the specified format. Note that this function expects dates in normal calendar
* format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
* the date format that is not specified will default to the current date value for that part. Time parts can also
* be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
* string or the parse operation will fail.
* Example Usage:
<pre><code>
//dt = Fri May 25 2007 (current date)
var dt = new Date();
 
//dt = Thu May 25 2006 (today's month/day in 2006)
dt = Date.parseDate("2006", "Y");
 
//dt = Sun Jan 15 2006 (all date parts specified)
dt = Date.parseDate("2006-01-15", "Y-m-d");
 
//dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
dt = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d h:i:s A" );
</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, ms = -1, o, z, u, v;\n"
+ "input = String(input);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 (u)\n"
+ "{v = new Date(u * 1000);}" // give top priority to UNIX time
+ "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0 && ms >= 0)\n"
+ "{v = new Date(y, m, d, h, i, s, ms);}\n"
+ "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
+ "{v = new Date(y, m, d, h, i, s);}\n"
+ "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
+ "{v = new Date(y, m, d, h, i);}\n"
+ "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
+ "{v = new Date(y, m, d, h);}\n"
+ "else if (y >= 0 && m >= 0 && d > 0)\n"
+ "{v = new Date(y, m, d);}\n"
+ "else if (y >= 0 && m >= 0)\n"
+ "{v = new Date(y, m);}\n"
+ "else if (y >= 0)\n"
+ "{v = new Date(y);}\n"
+ "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
+ " (z ? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
+ " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
+ ";}";
 
Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$", "i");
eval(code);
};
 
// private
Date.formatCodeToRegex = function(character, currentGroup) {
/*
* currentGroup = position in regex result array
* g = calculation group (0 or 1. only group 1 contributes to date calculations.)
* c = calculation method (required for group 1. null for group 0.)
* s = regex string
*/
switch (character) {
case "d":
return {g:1,
c:"d = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"}; // day of month with leading zeroes (01 - 31)
case "D":
for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); // get L10n short day names
return {g:0,
c:null,
s:"(?:" + a.join("|") +")"};
case "j":
return {g:1,
c:"d = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{1,2})"}; // day of month without leading zeroes (1 - 31)
case "l":
return {g:0,
c:null,
s:"(?:" + Date.dayNames.join("|") + ")"};
case "N":
return {g:0,
c:null,
s:"[1-7]"}; // ISO-8601 day number (1 (monday) - 7 (sunday))
case "S":
return {g:0,
c:null,
s:"(?:st|nd|rd|th)"};
case "w":
return {g:0,
c:null,
s:"[0-6]"}; // javascript day number (0 (sunday) - 6 (saturday))
case "z":
return {g:0,
c:null,
s:"(?:\\d{1,3}"}; // day of the year (0 - 364 (365 in leap years))
case "W":
return {g:0,
c:null,
s:"(?:\\d{2})"}; // ISO-8601 week number (with leading zero)
case "F":
return {g:1,
c:"m = parseInt(Date.getMonthNumber(results[" + currentGroup + "]), 10);\n", // get L10n month number
s:"(" + Date.monthNames.join("|") + ")"};
case "m":
return {g:1,
c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
s:"(\\d{2})"}; // month number with leading zeros (01 - 12)
case "M":
for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get L10n short month names
return {g:1,
c:"m = parseInt(Date.getMonthNumber(results[" + currentGroup + "]), 10);\n", // get L10n month number
s:"(" + a.join("|") + ")"};
case "n":
return {g:1,
c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
s:"(\\d{1,2})"}; // month number without leading zeros (1 - 12)
case "t":
return {g:0,
c:null,
s:"(?:\\d{2})"}; // no. of days in the month (28 - 31)
case "L":
return {g:0,
c:null,
s:"(?:1|0)"};
case "o":
case "Y":
return {g:1,
c:"y = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{4})"}; // 4-digit year
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})"}; // 2-digit year
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":
return {g:1,
c:"h = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{1,2})"}; // 24-hr format of an hour without leading zeroes (0 - 23)
case "h":
case "H":
return {g:1,
c:"h = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"}; // 24-hr format of an hour with leading zeroes (00 - 23)
case "i":
return {g:1,
c:"i = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"}; // minutes with leading zeros (00 - 59)
case "s":
return {g:1,
c:"s = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"}; // seconds with leading zeros (00 - 59)
case "u":
return {g:1,
c:"ms = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{3})"}; // milliseconds with leading zeros (000 - 999)
case "O":
return {g:1,
c:[
"o = results[", currentGroup, "];\n",
"var sn = o.substring(0,1);\n", // get + / - sign
"var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also, just in case)
"var mn = o.substring(3,5) % 60;\n", // get minutes
"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
" (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n"
].join(""),
s: "([+\-]\\d{4})"}; // GMT offset in hrs and mins
case "P":
return {g:1,
c:[
"o = results[", currentGroup, "];\n",
"var sn = o.substring(0,1);\n", // get + / - sign
"var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n", // get hours (performs minutes-to-hour conversion also, just in case)
"var mn = o.substring(4,6) % 60;\n", // get minutes
"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
" (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n"
].join(""),
s: "([+\-]\\d{2}:\\d{2})"}; // GMT offset in hrs and mins (with colon separator)
case "T":
return {g:0,
c:null,
s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
case "Z":
return {g:1,
c:"z = results[" + currentGroup + "] * 1;\n" // -43200 <= UTC offset <= 50400
+ "z = (-43200 <= z && z <= 50400)? z : null;\n",
s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
case "c":
var df = Date.formatCodeToRegex, calc = [];
var arr = [df("Y", 1), df("m", 2), df("d", 3), df("h", 4), df("i", 5), df("s", 6), df("P", 7)];
for (var i = 0, l = arr.length; i < l; ++i) {
calc.push(arr[i].c);
}
return {g:1,
c:calc.join(""),
s:arr[0].s + "-" + arr[1].s + "-" + arr[2].s + "T" + arr[3].s + ":" + arr[4].s + ":" + arr[5].s + arr[6].s};
case "U":
return {g:1,
c:"u = parseInt(results[" + currentGroup + "], 10);\n",
s:"(-?\\d+)"}; // leading minus sign indicates seconds before UNIX epoch
default:
return {g:0,
c:null,
s:Ext.escapeRe(character)};
}
};
 
/**
* Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
*
* Note: The date string returned by the javascript Date object's toString() method varies
* between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
* For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
* getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
* (which may or may not be present), failing which it proceeds to get the timezone abbreviation
* from the GMT offset portion of the date string.
* @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
*/
Date.prototype.getTimezone = function() {
// the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
//
// Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
// Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
// FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
// IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
// IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
//
// this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
// step 1: (?:\((.*)\) -- find timezone in parentheses
// step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
// step 3: remove all non uppercase characters found in step 1 and 2
return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
};
 
/**
* Get the offset from GMT of the current date (equivalent to the format specifier 'O').
* @param {Boolean} colon true to separate the hours and minutes with a colon (defaults to false).
* @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
*/
Date.prototype.getGMTOffset = function(colon) {
return (this.getTimezoneOffset() > 0 ? "-" : "+")
+ String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
+ (colon ? ":" : "")
+ String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
};
 
/**
* Get the numeric day number of the year, adjusted for leap year.
* @return {Number} 0 to 364 (365 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 numeric ISO-8601 week number of the year.
* (equivalent to the format specifier 'W', but without a leading zero).
* @return {Number} 1 to 53
*/
Date.prototype.getWeekOfYear = function() {
// adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
var ms1d = 864e5; // milliseconds in a day
var ms7d = 7 * ms1d; // milliseconds in a week
var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d; // an Absolute Day Number
var AWN = Math.floor(DC3 / 7); // an Absolute Week Number
var Wyr = new Date(AWN * ms7d).getUTCFullYear();
return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
};
 
/**
* 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 the date of the first day of the month in which this date resides.
* @return {Date}
*/
Date.prototype.getFirstDateOfMonth = function() {
return new Date(this.getFullYear(), this.getMonth(), 1);
};
 
/**
* Get the date of the last day of the month in which this date resides.
* @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"];
 
/**
* Get the short month name for the given month number.
* Override this function for international dates.
* @param {Number} month A zero-based javascript month number.
* @return {String} The short month name.
* @static
*/
Date.getShortMonthName = function(month) {
return Date.monthNames[month].substring(0, 3);
}
 
/**
* 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"];
 
/**
* Get the short day name for the given day number.
* Override this function for international dates.
* @param {Number} day A zero-based javascript day number.
* @return {String} The short day name.
* @static
*/
Date.getShortDayName = function(day) {
return Date.dayNames[day].substring(0, 3);
}
 
// private
Date.y2kYear = 50;
 
/**
* An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
* Override these values for international dates, for example...
* Date.monthNumbers = {'ShortJanNameInYourLang':0, 'ShortFebNameInYourLang':1, ...};
* @type Object
* @static
*/
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};
 
/**
* Get the zero-based javascript month number for the given short/full month name.
* Override this function for international dates.
* @param {String} name The short/full month name.
* @return {Number} The zero-based javascript month number.
* @static
*/
Date.getMonthNumber = function(name) {
// handle camel casing for english month names (since the keys for the Date.monthNumbers hash are case sensitive)
return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
}
 
/**
* 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 (defaults to false).
@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;
};
 
/**
* Checks if this date falls on or between the given start and end dates.
* @param {Date} start Start date
* @param {Date} end End date
* @return {Boolean} true if this date falls on or between the given start and end dates.
*/
Date.prototype.between = function(start, end){
var t = this.getTime();
return start.getTime() <= t && t <= end.getTime();
}
/trunk/www/org.tela_botanica.cel2/js/ext/source/util/KeyNav.js
New file
0,0 → 1,153
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
 
/**
* @class Ext.KeyNav
* <p>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, providing an easy
* way to implement custom navigation schemes for any UI component.</p>
* <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
* pageUp, pageDown, del, home, end. Usage:</p>
<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 {Mixed} 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 = {
/**
* @cfg {Boolean} disabled
* True to disable this KeyNav instance (defaults to false)
*/
disabled : false,
/**
* @cfg {String} defaultEventAction
* The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
* {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
* {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
*/
defaultEventAction: "stopEvent",
/**
* @cfg {Boolean} forceKeyDown
* Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
* IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
* handle keydown instead of keypress.
*/
forceKeyDown : false,
 
// private
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();
}
},
 
// private
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]();
}
}
},
 
// private
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(this.forceKeyDown || Ext.isIE || Ext.isAir){
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(this.forceKeyDown || Ext.isIE || Ext.isAir){
this.el.un("keydown", this.relay);
}else{
this.el.un("keydown", this.prepareEvent);
this.el.un("keypress", this.relay);
}
this.disabled = true;
}
}
};