4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
17 window["undefined"] = window["undefined"];
21 * Roo core utilities and functions.
26 * Copies all the properties of config to obj.
27 * @param {Object} obj The receiver of the properties
28 * @param {Object} config The source of the properties
29 * @param {Object} defaults A different object that will also be applied for default values
30 * @return {Object} returns obj
35 Roo.apply = function(o, c, defaults){
37 // no "this" reference for friendly out of scope calls
38 Roo.apply(o, defaults);
40 if(o && c && typeof c == 'object'){
51 var ua = navigator.userAgent.toLowerCase();
53 var isStrict = document.compatMode == "CSS1Compat",
54 isOpera = ua.indexOf("opera") > -1,
55 isSafari = (/webkit|khtml/).test(ua),
56 isIE = ua.indexOf("msie") > -1,
57 isIE7 = ua.indexOf("msie 7") > -1,
58 isGecko = !isSafari && ua.indexOf("gecko") > -1,
59 isBorderBox = isIE && !isStrict,
60 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
61 isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
62 isLinux = (ua.indexOf("linux") != -1),
63 isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
65 // remove css image flicker
68 document.execCommand("BackgroundImageCache", false, true);
74 * True if the browser is in strict mode
79 * True if the page is running over SSL
84 * True when the document is fully initialized and ready for action
89 * Turn on debugging output (currently only the factory uses this)
96 * True to automatically uncache orphaned Roo.Elements periodically (defaults to true)
99 enableGarbageCollector : true,
102 * True to automatically purge event listeners after uncaching an element (defaults to false).
103 * Note: this only happens if enableGarbageCollector is true.
106 enableListenerCollection:false,
109 * URL to a blank file used by Roo when in secure mode for iframe src and onReady src to prevent
110 * the IE insecure content warning (defaults to javascript:false).
113 SSL_SECURE_URL : "javascript:false",
116 * URL to a 1x1 transparent gif image used by Roo to create inline icons with CSS background images. (Defaults to
117 * "http://Roojs.com/s.gif" and you should change this to a URL on your server).
120 BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
122 emptyFn : function(){},
125 * Copies all the properties of config to obj if they don't already exist.
126 * @param {Object} obj The receiver of the properties
127 * @param {Object} config The source of the properties
128 * @return {Object} returns obj
130 applyIf : function(o, c){
133 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
140 * Applies event listeners to elements by selectors when the document is ready.
141 * The event name is specified with an @ suffix.
144 // add a listener for click on all anchors in element with id foo
145 '#foo a@click' : function(e, t){
149 // add the same listener to multiple selectors (separated by comma BEFORE the @)
150 '#foo a, #bar span.some-class@mouseover' : function(){
155 * @param {Object} obj The list of behaviors to apply
157 addBehaviors : function(o){
159 Roo.onReady(function(){
164 var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
166 var parts = b.split('@');
167 if(parts[1]){ // for Object prototype breakers
170 cache[s] = Roo.select(s);
172 cache[s].on(parts[1], o[b]);
179 * Generates unique ids. If the element already has an id, it is unchanged
180 * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
181 * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
182 * @return {String} The generated Id.
184 id : function(el, prefix){
185 prefix = prefix || "roo-gen";
187 var id = prefix + (++idSeed);
188 return el ? (el.id ? el.id : (el.id = id)) : id;
193 * Extends one class with another class and optionally overrides members with the passed literal. This class
194 * also adds the function "override()" to the class that can be used to override
195 * members on an instance.
196 * @param {Object} subclass The class inheriting the functionality
197 * @param {Object} superclass The class being extended
198 * @param {Object} overrides (optional) A literal with members
203 var io = function(o){
208 return function(sb, sp, overrides){
209 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
212 sb = function(){sp.apply(this, arguments);};
214 var F = function(){}, sbp, spp = sp.prototype;
216 sbp = sb.prototype = new F();
220 if(spp.constructor == Object.prototype.constructor){
225 sb.override = function(o){
229 Roo.override(sb, overrides);
235 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
237 Roo.override(MyClass, {
238 newMethod1: function(){
241 newMethod2: function(foo){
246 * @param {Object} origclass The class to override
247 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
248 * containing one or more methods.
251 override : function(origclass, overrides){
253 var p = origclass.prototype;
254 for(var method in overrides){
255 p[method] = overrides[method];
260 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
262 Roo.namespace('Company', 'Company.data');
263 Company.Widget = function() { ... }
264 Company.data.CustomStore = function(config) { ... }
266 * @param {String} namespace1
267 * @param {String} namespace2
268 * @param {String} etc
271 namespace : function(){
272 var a=arguments, o=null, i, j, d, rt;
273 for (i=0; i<a.length; ++i) {
277 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
278 for (j=1; j<d.length; ++j) {
279 o[d[j]]=o[d[j]] || {};
285 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
287 Roo.factory({ xns: Roo.data, xtype : 'Store', .....});
288 Roo.factory(conf, Roo.data);
290 * @param {String} classname
291 * @param {String} namespace (optional)
295 factory : function(c, ns)
297 // no xtype, no ns or c.xns - or forced off by c.xns
298 if (!c.xtype || (!ns && !c.xns) || (c.xns === false)) { // not enough info...
301 ns = c.xns ? c.xns : ns; // if c.xns is set, then use that..
302 if (c.constructor == ns[c.xtype]) {// already created...
306 if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")");
307 var ret = new ns[c.xtype](c);
311 c.xns = false; // prevent recursion..
315 * Logs to console if it can.
317 * @param {String|Object} string
322 if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
329 * Takes an object and converts it to an encoded URL. e.g. Roo.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
333 urlEncode : function(o){
339 var ov = o[key], k = Roo.encodeURIComponent(key);
340 var type = typeof ov;
341 if(type == 'undefined'){
343 }else if(type != "function" && type != "object"){
344 buf.push(k, "=", Roo.encodeURIComponent(ov), "&");
345 }else if(ov instanceof Array){
347 for(var i = 0, len = ov.length; i < len; i++) {
348 buf.push(k, "=", Roo.encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
359 * Safe version of encodeURIComponent
360 * @param {String} data
364 encodeURIComponent : function (data)
367 return encodeURIComponent(data);
368 } catch(e) {} // should be an uri encode error.
370 if (data == '' || data == null){
373 // http://stackoverflow.com/questions/2596483/unicode-and-uri-encoding-decoding-and-escaping-in-javascript
374 function nibble_to_hex(nibble){
375 var chars = '0123456789ABCDEF';
376 return chars.charAt(nibble);
378 data = data.toString();
380 for(var i=0; i<data.length; i++){
381 var c = data.charCodeAt(i);
382 var bs = new Array();
385 bs[0] = 0xF0 | ((c & 0x1C0000) >>> 18);
386 bs[1] = 0x80 | ((c & 0x3F000) >>> 12);
387 bs[2] = 0x80 | ((c & 0xFC0) >>> 6);
388 bs[3] = 0x80 | (c & 0x3F);
389 }else if (c > 0x800){
391 bs[0] = 0xE0 | ((c & 0xF000) >>> 12);
392 bs[1] = 0x80 | ((c & 0xFC0) >>> 6);
393 bs[2] = 0x80 | (c & 0x3F);
396 bs[0] = 0xC0 | ((c & 0x7C0) >>> 6);
397 bs[1] = 0x80 | (c & 0x3F);
402 for(var j=0; j<bs.length; j++){
404 var hex = nibble_to_hex((b & 0xF0) >>> 4)
405 + nibble_to_hex(b &0x0F);
414 * Takes an encoded URL and and converts it to an object. e.g. Roo.urlDecode("foo=1&bar=2"); would return {foo: 1, bar: 2} or Roo.urlDecode("foo=1&bar=2&bar=3&bar=4", true); would return {foo: 1, bar: [2, 3, 4]}.
415 * @param {String} string
416 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
417 * @return {Object} A literal with members
419 urlDecode : function(string, overwrite){
420 if(!string || !string.length){
424 var pairs = string.split('&');
425 var pair, name, value;
426 for(var i = 0, len = pairs.length; i < len; i++){
427 pair = pairs[i].split('=');
428 name = decodeURIComponent(pair[0]);
429 value = decodeURIComponent(pair[1]);
430 if(overwrite !== true){
431 if(typeof obj[name] == "undefined"){
433 }else if(typeof obj[name] == "string"){
434 obj[name] = [obj[name]];
435 obj[name].push(value);
437 obj[name].push(value);
447 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
448 * passed array is not really an array, your function is called once with it.
449 * The supplied function is called with (Object item, Number index, Array allItems).
450 * @param {Array/NodeList/Mixed} array
451 * @param {Function} fn
452 * @param {Object} scope
454 each : function(array, fn, scope){
455 if(typeof array.length == "undefined" || typeof array == "string"){
458 for(var i = 0, len = array.length; i < len; i++){
459 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
464 combine : function(){
465 var as = arguments, l = as.length, r = [];
466 for(var i = 0; i < l; i++){
468 if(a instanceof Array){
470 }else if(a.length !== undefined && !a.substr){
471 r = r.concat(Array.prototype.slice.call(a, 0));
480 * Escapes the passed string for use in a regular expression
481 * @param {String} str
484 escapeRe : function(s) {
485 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
489 callback : function(cb, scope, args, delay){
490 if(typeof cb == "function"){
492 cb.defer(delay, scope, args || []);
494 cb.apply(scope, args || []);
500 * Return the dom node for the passed string (id), dom node, or Roo.Element
501 * @param {String/HTMLElement/Roo.Element} el
502 * @return HTMLElement
504 getDom : function(el){
508 return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
512 * Shorthand for {@link Roo.ComponentMgr#get}
514 * @return Roo.Component
516 getCmp : function(id){
517 return Roo.ComponentMgr.get(id);
520 num : function(v, defaultValue){
521 if(typeof v != 'number'){
527 destroy : function(){
528 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
532 as.removeAllListeners();
536 if(typeof as.purgeListeners == 'function'){
539 if(typeof as.destroy == 'function'){
546 // inpired by a similar function in mootools library
548 * Returns the type of object that is passed in. If the object passed in is null or undefined it
549 * return false otherwise it returns one of the following values:<ul>
550 * <li><b>string</b>: If the object passed is a string</li>
551 * <li><b>number</b>: If the object passed is a number</li>
552 * <li><b>boolean</b>: If the object passed is a boolean value</li>
553 * <li><b>function</b>: If the object passed is a function reference</li>
554 * <li><b>object</b>: If the object passed is an object</li>
555 * <li><b>array</b>: If the object passed is an array</li>
556 * <li><b>regexp</b>: If the object passed is a regular expression</li>
557 * <li><b>element</b>: If the object passed is a DOM Element</li>
558 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
559 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
560 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
561 * @param {Mixed} object
565 if(o === undefined || o === null){
572 if(t == 'object' && o.nodeName) {
574 case 1: return 'element';
575 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
578 if(t == 'object' || t == 'function') {
579 switch(o.constructor) {
580 case Array: return 'array';
581 case RegExp: return 'regexp';
583 if(typeof o.length == 'number' && typeof o.item == 'function') {
591 * Returns true if the passed value is null, undefined or an empty string (optional).
592 * @param {Mixed} value The value to test
593 * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
596 isEmpty : function(v, allowBlank){
597 return v === null || v === undefined || (!allowBlank ? v === '' : false);
611 isBorderBox : isBorderBox,
613 isWindows : isWindows,
620 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
621 * you may want to set this to true.
624 useShims : ((isIE && !isIE7) || (isGecko && isMac)),
629 * Selects a single element as a Roo Element
630 * This is about as close as you can get to jQuery's $('do crazy stuff')
631 * @param {String} selector The selector/xpath query
632 * @param {Node} root (optional) The start of the query (defaults to document).
633 * @return {Roo.Element}
635 selectNode : function(selector, root)
637 var node = Roo.DomQuery.selectNode(selector,root);
638 return node ? Roo.get(node) : new Roo.Element(false);
646 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
647 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", "Roo.app", "Roo.ux");
650 * Ext JS Library 1.1.1
651 * Copyright(c) 2006-2007, Ext JS, LLC.
653 * Originally Released Under LGPL - original licence link has changed is not relivant.
656 * <script type="text/javascript">
660 // wrappedn so fnCleanup is not in global scope...
662 function fnCleanUp() {
663 var p = Function.prototype;
664 delete p.createSequence;
666 delete p.createDelegate;
667 delete p.createCallback;
668 delete p.createInterceptor;
670 window.detachEvent("onunload", fnCleanUp);
672 window.attachEvent("onunload", fnCleanUp);
679 * These functions are available on every Function object (any JavaScript function).
681 Roo.apply(Function.prototype, {
683 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
684 * Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
685 * Will create a function that is bound to those 2 args.
686 * @return {Function} The new function
688 createCallback : function(/*args...*/){
689 // make args available, in function below
690 var args = arguments;
693 return method.apply(window, args);
698 * Creates a delegate (callback) that sets the scope to obj.
699 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
700 * Will create a function that is automatically scoped to this.
701 * @param {Object} obj (optional) The object for which the scope is set
702 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
703 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
704 * if a number the args are inserted at the specified position
705 * @return {Function} The new function
707 createDelegate : function(obj, args, appendArgs){
710 var callArgs = args || arguments;
711 if(appendArgs === true){
712 callArgs = Array.prototype.slice.call(arguments, 0);
713 callArgs = callArgs.concat(args);
714 }else if(typeof appendArgs == "number"){
715 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
716 var applyArgs = [appendArgs, 0].concat(args); // create method call params
717 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
719 return method.apply(obj || window, callArgs);
724 * Calls this function after the number of millseconds specified.
725 * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
726 * @param {Object} obj (optional) The object for which the scope is set
727 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
728 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
729 * if a number the args are inserted at the specified position
730 * @return {Number} The timeout id that can be used with clearTimeout
732 defer : function(millis, obj, args, appendArgs){
733 var fn = this.createDelegate(obj, args, appendArgs);
735 return setTimeout(fn, millis);
741 * Create a combined function call sequence of the original function + the passed function.
742 * The resulting function returns the results of the original function.
743 * The passed fcn is called with the parameters of the original function
744 * @param {Function} fcn The function to sequence
745 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
746 * @return {Function} The new function
748 createSequence : function(fcn, scope){
749 if(typeof fcn != "function"){
754 var retval = method.apply(this || window, arguments);
755 fcn.apply(scope || this || window, arguments);
761 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
762 * The resulting function returns the results of the original function.
763 * The passed fcn is called with the parameters of the original function.
765 * @param {Function} fcn The function to call before the original
766 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
767 * @return {Function} The new function
769 createInterceptor : function(fcn, scope){
770 if(typeof fcn != "function"){
777 if(fcn.apply(scope || this || window, arguments) === false){
780 return method.apply(this || window, arguments);
786 * Ext JS Library 1.1.1
787 * Copyright(c) 2006-2007, Ext JS, LLC.
789 * Originally Released Under LGPL - original licence link has changed is not relivant.
792 * <script type="text/javascript">
795 Roo.applyIf(String, {
800 * Escapes the passed string for ' and \
801 * @param {String} string The string to escape
802 * @return {String} The escaped string
805 escape : function(string) {
806 return string.replace(/('|\\)/g, "\\$1");
810 * Pads the left side of a string with a specified character. This is especially useful
811 * for normalizing number and date strings. Example usage:
813 var s = String.leftPad('123', 5, '0');
814 // s now contains the string: '00123'
816 * @param {String} string The original string
817 * @param {Number} size The total length of the output string
818 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
819 * @return {String} The padded string
822 leftPad : function (val, size, ch) {
823 var result = new String(val);
824 if(ch === null || ch === undefined || ch === '') {
827 while (result.length < size) {
828 result = ch + result;
834 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
835 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
837 var cls = 'my-class', text = 'Some text';
838 var s = String.format('<div class="{0}">{1}</div>', cls, text);
839 // s now contains the string: '<div class="my-class">Some text</div>'
841 * @param {String} string The tokenized string to be formatted
842 * @param {String} value1 The value to replace token {0}
843 * @param {String} value2 Etc...
844 * @return {String} The formatted string
847 format : function(format){
848 var args = Array.prototype.slice.call(arguments, 1);
849 return format.replace(/\{(\d+)\}/g, function(m, i){
850 return Roo.util.Format.htmlEncode(args[i]);
856 * Utility function that allows you to easily switch a string between two alternating values. The passed value
857 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
858 * they are already different, the first value passed in is returned. Note that this method returns the new value
859 * but does not change the current string.
861 // alternate sort directions
862 sort = sort.toggle('ASC', 'DESC');
864 // instead of conditional logic:
865 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
867 * @param {String} value The value to compare to the current string
868 * @param {String} other The new value to use if the string already equals the first value passed in
869 * @return {String} The new value
872 String.prototype.toggle = function(value, other){
873 return this == value ? other : value;
876 * Ext JS Library 1.1.1
877 * Copyright(c) 2006-2007, Ext JS, LLC.
879 * Originally Released Under LGPL - original licence link has changed is not relivant.
882 * <script type="text/javascript">
888 Roo.applyIf(Number.prototype, {
890 * Checks whether or not the current number is within a desired range. If the number is already within the
891 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
892 * exceeded. Note that this method returns the constrained value but does not change the current number.
893 * @param {Number} min The minimum number in the range
894 * @param {Number} max The maximum number in the range
895 * @return {Number} The constrained value if outside the range, otherwise the current value
897 constrain : function(min, max){
898 return Math.min(Math.max(this, min), max);
902 * Ext JS Library 1.1.1
903 * Copyright(c) 2006-2007, Ext JS, LLC.
905 * Originally Released Under LGPL - original licence link has changed is not relivant.
908 * <script type="text/javascript">
913 Roo.applyIf(Array.prototype, {
915 * Checks whether or not the specified object exists in the array.
916 * @param {Object} o The object to check for
917 * @return {Number} The index of o in the array (or -1 if it is not found)
919 indexOf : function(o){
920 for (var i = 0, len = this.length; i < len; i++){
921 if(this[i] == o) return i;
927 * Removes the specified object from the array. If the object is not found nothing happens.
928 * @param {Object} o The object to remove
930 remove : function(o){
931 var index = this.indexOf(o);
933 this.splice(index, 1);
937 * Map (JS 1.6 compatibility)
938 * @param {Function} function to call
942 var len = this.length >>> 0;
943 if (typeof fun != "function")
944 throw new TypeError();
946 var res = new Array(len);
947 var thisp = arguments[1];
948 for (var i = 0; i < len; i++)
951 res[i] = fun.call(thisp, this[i], i, this);
962 * Ext JS Library 1.1.1
963 * Copyright(c) 2006-2007, Ext JS, LLC.
965 * Originally Released Under LGPL - original licence link has changed is not relivant.
968 * <script type="text/javascript">
974 * The date parsing and format syntax is a subset of
975 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
976 * supported will provide results equivalent to their PHP versions.
978 * Following is the list of all currently supported formats:
981 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
983 Format Output Description
984 ------ ---------- --------------------------------------------------------------
985 d 10 Day of the month, 2 digits with leading zeros
986 D Wed A textual representation of a day, three letters
987 j 10 Day of the month without leading zeros
988 l Wednesday A full textual representation of the day of the week
989 S th English ordinal day of month suffix, 2 chars (use with j)
990 w 3 Numeric representation of the day of the week
991 z 9 The julian date, or day of the year (0-365)
992 W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
993 F January A full textual representation of the month
994 m 01 Numeric representation of a month, with leading zeros
995 M Jan Month name abbreviation, three letters
996 n 1 Numeric representation of a month, without leading zeros
997 t 31 Number of days in the given month
998 L 0 Whether it's a leap year (1 if it is a leap year, else 0)
999 Y 2007 A full numeric representation of a year, 4 digits
1000 y 07 A two digit representation of a year
1001 a pm Lowercase Ante meridiem and Post meridiem
1002 A PM Uppercase Ante meridiem and Post meridiem
1003 g 3 12-hour format of an hour without leading zeros
1004 G 15 24-hour format of an hour without leading zeros
1005 h 03 12-hour format of an hour with leading zeros
1006 H 15 24-hour format of an hour with leading zeros
1007 i 05 Minutes with leading zeros
1008 s 01 Seconds, with leading zeros
1009 O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes)
1010 P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes
1011 T CST Timezone setting of the machine running the code
1012 Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
1015 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
1017 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
1018 document.write(dt.format('Y-m-d')); //2007-01-10
1019 document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
1020 document.write(dt.format('l, \\t\\he dS of F Y h:i:s A')); //Wednesday, the 10th of January 2007 03:05:01 PM
1023 * Here are some standard date/time patterns that you might find helpful. They
1024 * are not part of the source of Date.js, but to use them you can simply copy this
1025 * block of code into any script that is included after Date.js and they will also become
1026 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
1029 ISO8601Long:"Y-m-d H:i:s",
1030 ISO8601Short:"Y-m-d",
1032 LongDate: "l, F d, Y",
1033 FullDateTime: "l, F d, Y g:i:s A",
1036 LongTime: "g:i:s A",
1037 SortableDateTime: "Y-m-d\\TH:i:s",
1038 UniversalSortableDateTime: "Y-m-d H:i:sO",
1045 var dt = new Date();
1046 document.write(dt.format(Date.patterns.ShortDate));
1051 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
1052 * They generate precompiled functions from date formats instead of parsing and
1053 * processing the pattern every time you format a date. These functions are available
1054 * on every Date object (any javascript function).
1056 * The original article and download are here:
1057 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1064 Returns the number of milliseconds between this date and date
1065 @param {Date} date (optional) Defaults to now
1066 @return {Number} The diff in milliseconds
1067 @member Date getElapsed
1069 Date.prototype.getElapsed = function(date) {
1070 return Math.abs((date || new Date()).getTime()-this.getTime());
1072 // was in date file..
1076 Date.parseFunctions = {count:0};
1078 Date.parseRegexes = [];
1080 Date.formatFunctions = {count:0};
1083 Date.prototype.dateFormat = function(format) {
1084 if (Date.formatFunctions[format] == null) {
1085 Date.createNewFormat(format);
1087 var func = Date.formatFunctions[format];
1088 return this[func]();
1093 * Formats a date given the supplied format string
1094 * @param {String} format The format string
1095 * @return {String} The formatted date
1098 Date.prototype.format = Date.prototype.dateFormat;
1101 Date.createNewFormat = function(format) {
1102 var funcName = "format" + Date.formatFunctions.count++;
1103 Date.formatFunctions[format] = funcName;
1104 var code = "Date.prototype." + funcName + " = function(){return ";
1105 var special = false;
1107 for (var i = 0; i < format.length; ++i) {
1108 ch = format.charAt(i);
1109 if (!special && ch == "\\") {
1114 code += "'" + String.escape(ch) + "' + ";
1117 code += Date.getFormatCode(ch);
1120 /** eval:var:zzzzzzzzzzzzz */
1121 eval(code.substring(0, code.length - 3) + ";}");
1125 Date.getFormatCode = function(character) {
1126 switch (character) {
1128 return "String.leftPad(this.getDate(), 2, '0') + ";
1130 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
1132 return "this.getDate() + ";
1134 return "Date.dayNames[this.getDay()] + ";
1136 return "this.getSuffix() + ";
1138 return "this.getDay() + ";
1140 return "this.getDayOfYear() + ";
1142 return "this.getWeekOfYear() + ";
1144 return "Date.monthNames[this.getMonth()] + ";
1146 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
1148 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
1150 return "(this.getMonth() + 1) + ";
1152 return "this.getDaysInMonth() + ";
1154 return "(this.isLeapYear() ? 1 : 0) + ";
1156 return "this.getFullYear() + ";
1158 return "('' + this.getFullYear()).substring(2, 4) + ";
1160 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
1162 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
1164 return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
1166 return "this.getHours() + ";
1168 return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
1170 return "String.leftPad(this.getHours(), 2, '0') + ";
1172 return "String.leftPad(this.getMinutes(), 2, '0') + ";
1174 return "String.leftPad(this.getSeconds(), 2, '0') + ";
1176 return "this.getGMTOffset() + ";
1178 return "this.getGMTColonOffset() + ";
1180 return "this.getTimezone() + ";
1182 return "(this.getTimezoneOffset() * -60) + ";
1184 return "'" + String.escape(character) + "' + ";
1189 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
1190 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
1191 * the date format that is not specified will default to the current date value for that part. Time parts can also
1192 * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
1193 * string or the parse operation will fail.
1196 //dt = Fri May 25 2007 (current date)
1197 var dt = new Date();
1199 //dt = Thu May 25 2006 (today's month/day in 2006)
1200 dt = Date.parseDate("2006", "Y");
1202 //dt = Sun Jan 15 2006 (all date parts specified)
1203 dt = Date.parseDate("2006-1-15", "Y-m-d");
1205 //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
1206 dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i:s A" );
1208 * @param {String} input The unparsed date as a string
1209 * @param {String} format The format the date is in
1210 * @return {Date} The parsed date
1213 Date.parseDate = function(input, format) {
1214 if (Date.parseFunctions[format] == null) {
1215 Date.createParser(format);
1217 var func = Date.parseFunctions[format];
1218 return Date[func](input);
1223 Date.createParser = function(format) {
1224 var funcName = "parse" + Date.parseFunctions.count++;
1225 var regexNum = Date.parseRegexes.length;
1226 var currentGroup = 1;
1227 Date.parseFunctions[format] = funcName;
1229 var code = "Date." + funcName + " = function(input){\n"
1230 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
1231 + "var d = new Date();\n"
1232 + "y = d.getFullYear();\n"
1233 + "m = d.getMonth();\n"
1234 + "d = d.getDate();\n"
1235 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
1236 + "if (results && results.length > 0) {";
1239 var special = false;
1241 for (var i = 0; i < format.length; ++i) {
1242 ch = format.charAt(i);
1243 if (!special && ch == "\\") {
1248 regex += String.escape(ch);
1251 var obj = Date.formatCodeToRegex(ch, currentGroup);
1252 currentGroup += obj.g;
1254 if (obj.g && obj.c) {
1260 code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
1261 + "{v = new Date(y, m, d, h, i, s);}\n"
1262 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
1263 + "{v = new Date(y, m, d, h, i);}\n"
1264 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
1265 + "{v = new Date(y, m, d, h);}\n"
1266 + "else if (y >= 0 && m >= 0 && d > 0)\n"
1267 + "{v = new Date(y, m, d);}\n"
1268 + "else if (y >= 0 && m >= 0)\n"
1269 + "{v = new Date(y, m);}\n"
1270 + "else if (y >= 0)\n"
1271 + "{v = new Date(y);}\n"
1272 + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
1273 + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
1274 + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
1277 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
1278 /** eval:var:zzzzzzzzzzzzz */
1283 Date.formatCodeToRegex = function(character, currentGroup) {
1284 switch (character) {
1288 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
1291 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1292 s:"(\\d{1,2})"}; // day of month without leading zeroes
1295 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1296 s:"(\\d{2})"}; // day of month with leading zeroes
1300 s:"(?:" + Date.dayNames.join("|") + ")"};
1304 s:"(?:st|nd|rd|th)"};
1319 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
1320 s:"(" + Date.monthNames.join("|") + ")"};
1323 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
1324 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
1327 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1328 s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros
1331 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1332 s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros
1343 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
1347 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
1348 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
1352 c:"if (results[" + currentGroup + "] == 'am') {\n"
1353 + "if (h == 12) { h = 0; }\n"
1354 + "} else { if (h < 12) { h += 12; }}",
1358 c:"if (results[" + currentGroup + "] == 'AM') {\n"
1359 + "if (h == 12) { h = 0; }\n"
1360 + "} else { if (h < 12) { h += 12; }}",
1365 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1366 s:"(\\d{1,2})"}; // 12/24-hr format format of an hour without leading zeroes
1370 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1371 s:"(\\d{2})"}; // 12/24-hr format format of an hour with leading zeroes
1374 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
1378 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
1383 "o = results[", currentGroup, "];\n",
1384 "var sn = o.substring(0,1);\n", // get + / - sign
1385 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also)
1386 "var mn = o.substring(3,5) % 60;\n", // get minutes
1387 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
1388 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1390 s:"([+\-]\\d{2,4})"};
1396 "o = results[", currentGroup, "];\n",
1397 "var sn = o.substring(0,1);\n",
1398 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
1399 "var mn = o.substring(4,6) % 60;\n",
1400 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
1401 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1407 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1410 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1411 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1412 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1416 s:String.escape(character)};
1421 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1422 * @return {String} The abbreviated timezone name (e.g. 'CST')
1424 Date.prototype.getTimezone = function() {
1425 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1429 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1430 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1432 Date.prototype.getGMTOffset = function() {
1433 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1434 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1435 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1439 * Get the offset from GMT of the current date (equivalent to the format specifier 'P').
1440 * @return {String} 2-characters representing hours and 2-characters representing minutes
1441 * seperated by a colon and prefixed with + or - (e.g. '-06:00')
1443 Date.prototype.getGMTColonOffset = function() {
1444 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1445 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1447 + String.leftPad(this.getTimezoneOffset() %60, 2, "0");
1451 * Get the numeric day number of the year, adjusted for leap year.
1452 * @return {Number} 0 through 364 (365 in leap years)
1454 Date.prototype.getDayOfYear = function() {
1456 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1457 for (var i = 0; i < this.getMonth(); ++i) {
1458 num += Date.daysInMonth[i];
1460 return num + this.getDate() - 1;
1464 * Get the string representation of the numeric week number of the year
1465 * (equivalent to the format specifier 'W').
1466 * @return {String} '00' through '52'
1468 Date.prototype.getWeekOfYear = function() {
1469 // Skip to Thursday of this week
1470 var now = this.getDayOfYear() + (4 - this.getDay());
1471 // Find the first Thursday of the year
1472 var jan1 = new Date(this.getFullYear(), 0, 1);
1473 var then = (7 - jan1.getDay() + 4);
1474 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1478 * Whether or not the current date is in a leap year.
1479 * @return {Boolean} True if the current date is in a leap year, else false
1481 Date.prototype.isLeapYear = function() {
1482 var year = this.getFullYear();
1483 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1487 * Get the first day of the current month, adjusted for leap year. The returned value
1488 * is the numeric day index within the week (0-6) which can be used in conjunction with
1489 * the {@link #monthNames} array to retrieve the textual day name.
1492 var dt = new Date('1/10/2007');
1493 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1495 * @return {Number} The day number (0-6)
1497 Date.prototype.getFirstDayOfMonth = function() {
1498 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1499 return (day < 0) ? (day + 7) : day;
1503 * Get the last day of the current month, adjusted for leap year. The returned value
1504 * is the numeric day index within the week (0-6) which can be used in conjunction with
1505 * the {@link #monthNames} array to retrieve the textual day name.
1508 var dt = new Date('1/10/2007');
1509 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1511 * @return {Number} The day number (0-6)
1513 Date.prototype.getLastDayOfMonth = function() {
1514 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1515 return (day < 0) ? (day + 7) : day;
1520 * Get the first date of this date's month
1523 Date.prototype.getFirstDateOfMonth = function() {
1524 return new Date(this.getFullYear(), this.getMonth(), 1);
1528 * Get the last date of this date's month
1531 Date.prototype.getLastDateOfMonth = function() {
1532 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1535 * Get the number of days in the current month, adjusted for leap year.
1536 * @return {Number} The number of days in the month
1538 Date.prototype.getDaysInMonth = function() {
1539 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1540 return Date.daysInMonth[this.getMonth()];
1544 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1545 * @return {String} 'st, 'nd', 'rd' or 'th'
1547 Date.prototype.getSuffix = function() {
1548 switch (this.getDate()) {
1565 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1568 * An array of textual month names.
1569 * Override these values for international dates, for example...
1570 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1589 * An array of textual day names.
1590 * Override these values for international dates, for example...
1591 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1607 Date.monthNumbers = {
1622 * Creates and returns a new Date instance with the exact same date value as the called instance.
1623 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1624 * variable will also be changed. When the intention is to create a new variable that will not
1625 * modify the original instance, you should create a clone.
1627 * Example of correctly cloning a date:
1630 var orig = new Date('10/1/2006');
1633 document.write(orig); //returns 'Thu Oct 05 2006'!
1636 var orig = new Date('10/1/2006');
1637 var copy = orig.clone();
1639 document.write(orig); //returns 'Thu Oct 01 2006'
1641 * @return {Date} The new Date instance
1643 Date.prototype.clone = function() {
1644 return new Date(this.getTime());
1648 * Clears any time information from this date
1649 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1650 @return {Date} this or the clone
1652 Date.prototype.clearTime = function(clone){
1654 return this.clone().clearTime();
1659 this.setMilliseconds(0);
1664 // safari setMonth is broken
1666 Date.brokenSetMonth = Date.prototype.setMonth;
1667 Date.prototype.setMonth = function(num){
1669 var n = Math.ceil(-num);
1670 var back_year = Math.ceil(n/12);
1671 var month = (n % 12) ? 12 - n % 12 : 0 ;
1672 this.setFullYear(this.getFullYear() - back_year);
1673 return Date.brokenSetMonth.call(this, month);
1675 return Date.brokenSetMonth.apply(this, arguments);
1680 /** Date interval constant
1684 /** Date interval constant
1688 /** Date interval constant
1692 /** Date interval constant
1696 /** Date interval constant
1700 /** Date interval constant
1704 /** Date interval constant
1710 * Provides a convenient method of performing basic date arithmetic. This method
1711 * does not modify the Date instance being called - it creates and returns
1712 * a new Date instance containing the resulting date value.
1717 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1718 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1720 //Negative values will subtract correctly:
1721 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1722 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1724 //You can even chain several calls together in one line!
1725 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1726 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1729 * @param {String} interval A valid date interval enum value
1730 * @param {Number} value The amount to add to the current date
1731 * @return {Date} The new Date instance
1733 Date.prototype.add = function(interval, value){
1734 var d = this.clone();
1735 if (!interval || value === 0) return d;
1736 switch(interval.toLowerCase()){
1738 d.setMilliseconds(this.getMilliseconds() + value);
1741 d.setSeconds(this.getSeconds() + value);
1744 d.setMinutes(this.getMinutes() + value);
1747 d.setHours(this.getHours() + value);
1750 d.setDate(this.getDate() + value);
1753 var day = this.getDate();
1755 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1758 d.setMonth(this.getMonth() + value);
1761 d.setFullYear(this.getFullYear() + value);
1768 * Ext JS Library 1.1.1
1769 * Copyright(c) 2006-2007, Ext JS, LLC.
1771 * Originally Released Under LGPL - original licence link has changed is not relivant.
1774 * <script type="text/javascript">
1778 * @class Roo.lib.Dom
1781 * Dom utils (from YIU afaik)
1786 * Get the view width
1787 * @param {Boolean} full True will get the full document, otherwise it's the view width
1788 * @return {Number} The width
1791 getViewWidth : function(full) {
1792 return full ? this.getDocumentWidth() : this.getViewportWidth();
1795 * Get the view height
1796 * @param {Boolean} full True will get the full document, otherwise it's the view height
1797 * @return {Number} The height
1799 getViewHeight : function(full) {
1800 return full ? this.getDocumentHeight() : this.getViewportHeight();
1803 getDocumentHeight: function() {
1804 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1805 return Math.max(scrollHeight, this.getViewportHeight());
1808 getDocumentWidth: function() {
1809 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1810 return Math.max(scrollWidth, this.getViewportWidth());
1813 getViewportHeight: function() {
1814 var height = self.innerHeight;
1815 var mode = document.compatMode;
1817 if ((mode || Roo.isIE) && !Roo.isOpera) {
1818 height = (mode == "CSS1Compat") ?
1819 document.documentElement.clientHeight :
1820 document.body.clientHeight;
1826 getViewportWidth: function() {
1827 var width = self.innerWidth;
1828 var mode = document.compatMode;
1830 if (mode || Roo.isIE) {
1831 width = (mode == "CSS1Compat") ?
1832 document.documentElement.clientWidth :
1833 document.body.clientWidth;
1838 isAncestor : function(p, c) {
1845 if (p.contains && !Roo.isSafari) {
1846 return p.contains(c);
1847 } else if (p.compareDocumentPosition) {
1848 return !!(p.compareDocumentPosition(c) & 16);
1850 var parent = c.parentNode;
1855 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1858 parent = parent.parentNode;
1864 getRegion : function(el) {
1865 return Roo.lib.Region.getRegion(el);
1868 getY : function(el) {
1869 return this.getXY(el)[1];
1872 getX : function(el) {
1873 return this.getXY(el)[0];
1876 getXY : function(el) {
1877 var p, pe, b, scroll, bd = document.body;
1878 el = Roo.getDom(el);
1879 var fly = Roo.lib.AnimBase.fly;
1880 if (el.getBoundingClientRect) {
1881 b = el.getBoundingClientRect();
1882 scroll = fly(document).getScroll();
1883 return [b.left + scroll.left, b.top + scroll.top];
1889 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1896 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1903 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1904 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1911 if (p != el && pe.getStyle('overflow') != 'visible') {
1919 if (Roo.isSafari && hasAbsolute) {
1924 if (Roo.isGecko && !hasAbsolute) {
1926 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1927 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1931 while (p && p != bd) {
1932 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1944 setXY : function(el, xy) {
1945 el = Roo.fly(el, '_setXY');
1947 var pts = el.translatePoints(xy);
1948 if (xy[0] !== false) {
1949 el.dom.style.left = pts.left + "px";
1951 if (xy[1] !== false) {
1952 el.dom.style.top = pts.top + "px";
1956 setX : function(el, x) {
1957 this.setXY(el, [x, false]);
1960 setY : function(el, y) {
1961 this.setXY(el, [false, y]);
1965 * Portions of this file are based on pieces of Yahoo User Interface Library
1966 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
1967 * YUI licensed under the BSD License:
1968 * http://developer.yahoo.net/yui/license.txt
1969 * <script type="text/javascript">
1973 Roo.lib.Event = function() {
1974 var loadComplete = false;
1976 var unloadListeners = [];
1978 var onAvailStack = [];
1980 var lastError = null;
1993 startInterval: function() {
1994 if (!this._interval) {
1996 var callback = function() {
1997 self._tryPreloadAttach();
1999 this._interval = setInterval(callback, this.POLL_INTERVAL);
2004 onAvailable: function(p_id, p_fn, p_obj, p_override) {
2005 onAvailStack.push({ id: p_id,
2008 override: p_override,
2009 checkReady: false });
2011 retryCount = this.POLL_RETRYS;
2012 this.startInterval();
2016 addListener: function(el, eventName, fn) {
2017 el = Roo.getDom(el);
2022 if ("unload" == eventName) {
2023 unloadListeners[unloadListeners.length] =
2024 [el, eventName, fn];
2028 var wrappedFn = function(e) {
2029 return fn(Roo.lib.Event.getEvent(e));
2032 var li = [el, eventName, fn, wrappedFn];
2034 var index = listeners.length;
2035 listeners[index] = li;
2037 this.doAdd(el, eventName, wrappedFn, false);
2043 removeListener: function(el, eventName, fn) {
2046 el = Roo.getDom(el);
2049 return this.purgeElement(el, false, eventName);
2053 if ("unload" == eventName) {
2055 for (i = 0,len = unloadListeners.length; i < len; i++) {
2056 var li = unloadListeners[i];
2059 li[1] == eventName &&
2061 unloadListeners.splice(i, 1);
2069 var cacheItem = null;
2072 var index = arguments[3];
2074 if ("undefined" == typeof index) {
2075 index = this._getCacheIndex(el, eventName, fn);
2079 cacheItem = listeners[index];
2082 if (!el || !cacheItem) {
2086 this.doRemove(el, eventName, cacheItem[this.WFN], false);
2088 delete listeners[index][this.WFN];
2089 delete listeners[index][this.FN];
2090 listeners.splice(index, 1);
2097 getTarget: function(ev, resolveTextNode) {
2098 ev = ev.browserEvent || ev;
2099 var t = ev.target || ev.srcElement;
2100 return this.resolveTextNode(t);
2104 resolveTextNode: function(node) {
2105 if (Roo.isSafari && node && 3 == node.nodeType) {
2106 return node.parentNode;
2113 getPageX: function(ev) {
2114 ev = ev.browserEvent || ev;
2116 if (!x && 0 !== x) {
2117 x = ev.clientX || 0;
2120 x += this.getScroll()[1];
2128 getPageY: function(ev) {
2129 ev = ev.browserEvent || ev;
2131 if (!y && 0 !== y) {
2132 y = ev.clientY || 0;
2135 y += this.getScroll()[0];
2144 getXY: function(ev) {
2145 ev = ev.browserEvent || ev;
2146 return [this.getPageX(ev), this.getPageY(ev)];
2150 getRelatedTarget: function(ev) {
2151 ev = ev.browserEvent || ev;
2152 var t = ev.relatedTarget;
2154 if (ev.type == "mouseout") {
2156 } else if (ev.type == "mouseover") {
2161 return this.resolveTextNode(t);
2165 getTime: function(ev) {
2166 ev = ev.browserEvent || ev;
2168 var t = new Date().getTime();
2172 this.lastError = ex;
2181 stopEvent: function(ev) {
2182 this.stopPropagation(ev);
2183 this.preventDefault(ev);
2187 stopPropagation: function(ev) {
2188 ev = ev.browserEvent || ev;
2189 if (ev.stopPropagation) {
2190 ev.stopPropagation();
2192 ev.cancelBubble = true;
2197 preventDefault: function(ev) {
2198 ev = ev.browserEvent || ev;
2199 if(ev.preventDefault) {
2200 ev.preventDefault();
2202 ev.returnValue = false;
2207 getEvent: function(e) {
2208 var ev = e || window.event;
2210 var c = this.getEvent.caller;
2212 ev = c.arguments[0];
2213 if (ev && Event == ev.constructor) {
2223 getCharCode: function(ev) {
2224 ev = ev.browserEvent || ev;
2225 return ev.charCode || ev.keyCode || 0;
2229 _getCacheIndex: function(el, eventName, fn) {
2230 for (var i = 0,len = listeners.length; i < len; ++i) {
2231 var li = listeners[i];
2233 li[this.FN] == fn &&
2234 li[this.EL] == el &&
2235 li[this.TYPE] == eventName) {
2247 getEl: function(id) {
2248 return document.getElementById(id);
2252 clearCache: function() {
2256 _load: function(e) {
2257 loadComplete = true;
2258 var EU = Roo.lib.Event;
2262 EU.doRemove(window, "load", EU._load);
2267 _tryPreloadAttach: function() {
2276 var tryAgain = !loadComplete;
2278 tryAgain = (retryCount > 0);
2283 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2284 var item = onAvailStack[i];
2286 var el = this.getEl(item.id);
2289 if (!item.checkReady ||
2292 (document && document.body)) {
2295 if (item.override) {
2296 if (item.override === true) {
2299 scope = item.override;
2302 item.fn.call(scope, item.obj);
2303 onAvailStack[i] = null;
2306 notAvail.push(item);
2311 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2315 this.startInterval();
2317 clearInterval(this._interval);
2318 this._interval = null;
2321 this.locked = false;
2328 purgeElement: function(el, recurse, eventName) {
2329 var elListeners = this.getListeners(el, eventName);
2331 for (var i = 0,len = elListeners.length; i < len; ++i) {
2332 var l = elListeners[i];
2333 this.removeListener(el, l.type, l.fn);
2337 if (recurse && el && el.childNodes) {
2338 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2339 this.purgeElement(el.childNodes[i], recurse, eventName);
2345 getListeners: function(el, eventName) {
2346 var results = [], searchLists;
2348 searchLists = [listeners, unloadListeners];
2349 } else if (eventName == "unload") {
2350 searchLists = [unloadListeners];
2352 searchLists = [listeners];
2355 for (var j = 0; j < searchLists.length; ++j) {
2356 var searchList = searchLists[j];
2357 if (searchList && searchList.length > 0) {
2358 for (var i = 0,len = searchList.length; i < len; ++i) {
2359 var l = searchList[i];
2360 if (l && l[this.EL] === el &&
2361 (!eventName || eventName === l[this.TYPE])) {
2366 adjust: l[this.ADJ_SCOPE],
2374 return (results.length) ? results : null;
2378 _unload: function(e) {
2380 var EU = Roo.lib.Event, i, j, l, len, index;
2382 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2383 l = unloadListeners[i];
2386 if (l[EU.ADJ_SCOPE]) {
2387 if (l[EU.ADJ_SCOPE] === true) {
2390 scope = l[EU.ADJ_SCOPE];
2393 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2394 unloadListeners[i] = null;
2400 unloadListeners = null;
2402 if (listeners && listeners.length > 0) {
2403 j = listeners.length;
2406 l = listeners[index];
2408 EU.removeListener(l[EU.EL], l[EU.TYPE],
2418 EU.doRemove(window, "unload", EU._unload);
2423 getScroll: function() {
2424 var dd = document.documentElement, db = document.body;
2425 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2426 return [dd.scrollTop, dd.scrollLeft];
2428 return [db.scrollTop, db.scrollLeft];
2435 doAdd: function () {
2436 if (window.addEventListener) {
2437 return function(el, eventName, fn, capture) {
2438 el.addEventListener(eventName, fn, (capture));
2440 } else if (window.attachEvent) {
2441 return function(el, eventName, fn, capture) {
2442 el.attachEvent("on" + eventName, fn);
2451 doRemove: function() {
2452 if (window.removeEventListener) {
2453 return function (el, eventName, fn, capture) {
2454 el.removeEventListener(eventName, fn, (capture));
2456 } else if (window.detachEvent) {
2457 return function (el, eventName, fn) {
2458 el.detachEvent("on" + eventName, fn);
2470 var E = Roo.lib.Event;
2471 E.on = E.addListener;
2472 E.un = E.removeListener;
2474 if (document && document.body) {
2477 E.doAdd(window, "load", E._load);
2479 E.doAdd(window, "unload", E._unload);
2480 E._tryPreloadAttach();
2484 * Portions of this file are based on pieces of Yahoo User Interface Library
2485 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2486 * YUI licensed under the BSD License:
2487 * http://developer.yahoo.net/yui/license.txt
2488 * <script type="text/javascript">
2494 * @class Roo.lib.Ajax
2501 request : function(method, uri, cb, data, options) {
2503 var hs = options.headers;
2506 if(hs.hasOwnProperty(h)){
2507 this.initHeader(h, hs[h], false);
2511 if(options.xmlData){
2512 this.initHeader('Content-Type', 'text/xml', false);
2514 data = options.xmlData;
2518 return this.asyncRequest(method, uri, cb, data);
2521 serializeForm : function(form) {
2522 if(typeof form == 'string') {
2523 form = (document.getElementById(form) || document.forms[form]);
2526 var el, name, val, disabled, data = '', hasSubmit = false;
2527 for (var i = 0; i < form.elements.length; i++) {
2528 el = form.elements[i];
2529 disabled = form.elements[i].disabled;
2530 name = form.elements[i].name;
2531 val = form.elements[i].value;
2533 if (!disabled && name){
2537 case 'select-multiple':
2538 for (var j = 0; j < el.options.length; j++) {
2539 if (el.options[j].selected) {
2541 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2544 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2552 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2565 if(hasSubmit == false) {
2566 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2571 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2576 data = data.substr(0, data.length - 1);
2584 useDefaultHeader:true,
2586 defaultPostHeader:'application/x-www-form-urlencoded',
2588 useDefaultXhrHeader:true,
2590 defaultXhrHeader:'XMLHttpRequest',
2592 hasDefaultHeaders:true,
2604 setProgId:function(id)
2606 this.activeX.unshift(id);
2609 setDefaultPostHeader:function(b)
2611 this.useDefaultHeader = b;
2614 setDefaultXhrHeader:function(b)
2616 this.useDefaultXhrHeader = b;
2619 setPollingInterval:function(i)
2621 if (typeof i == 'number' && isFinite(i)) {
2622 this.pollInterval = i;
2626 createXhrObject:function(transactionId)
2632 http = new XMLHttpRequest();
2634 obj = { conn:http, tId:transactionId };
2638 for (var i = 0; i < this.activeX.length; ++i) {
2642 http = new ActiveXObject(this.activeX[i]);
2644 obj = { conn:http, tId:transactionId };
2657 getConnectionObject:function()
2660 var tId = this.transactionId;
2664 o = this.createXhrObject(tId);
2666 this.transactionId++;
2677 asyncRequest:function(method, uri, callback, postData)
2679 var o = this.getConnectionObject();
2685 o.conn.open(method, uri, true);
2687 if (this.useDefaultXhrHeader) {
2688 if (!this.defaultHeaders['X-Requested-With']) {
2689 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2693 if(postData && this.useDefaultHeader){
2694 this.initHeader('Content-Type', this.defaultPostHeader);
2697 if (this.hasDefaultHeaders || this.hasHeaders) {
2701 this.handleReadyState(o, callback);
2702 o.conn.send(postData || null);
2708 handleReadyState:function(o, callback)
2712 if (callback && callback.timeout) {
2714 this.timeout[o.tId] = window.setTimeout(function() {
2715 oConn.abort(o, callback, true);
2716 }, callback.timeout);
2719 this.poll[o.tId] = window.setInterval(
2721 if (o.conn && o.conn.readyState == 4) {
2722 window.clearInterval(oConn.poll[o.tId]);
2723 delete oConn.poll[o.tId];
2725 if(callback && callback.timeout) {
2726 window.clearTimeout(oConn.timeout[o.tId]);
2727 delete oConn.timeout[o.tId];
2730 oConn.handleTransactionResponse(o, callback);
2733 , this.pollInterval);
2736 handleTransactionResponse:function(o, callback, isAbort)
2740 this.releaseObject(o);
2744 var httpStatus, responseObject;
2748 if (o.conn.status !== undefined && o.conn.status != 0) {
2749 httpStatus = o.conn.status;
2761 if (httpStatus >= 200 && httpStatus < 300) {
2762 responseObject = this.createResponseObject(o, callback.argument);
2763 if (callback.success) {
2764 if (!callback.scope) {
2765 callback.success(responseObject);
2770 callback.success.apply(callback.scope, [responseObject]);
2775 switch (httpStatus) {
2783 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2784 if (callback.failure) {
2785 if (!callback.scope) {
2786 callback.failure(responseObject);
2789 callback.failure.apply(callback.scope, [responseObject]);
2794 responseObject = this.createResponseObject(o, callback.argument);
2795 if (callback.failure) {
2796 if (!callback.scope) {
2797 callback.failure(responseObject);
2800 callback.failure.apply(callback.scope, [responseObject]);
2806 this.releaseObject(o);
2807 responseObject = null;
2810 createResponseObject:function(o, callbackArg)
2817 var headerStr = o.conn.getAllResponseHeaders();
2818 var header = headerStr.split('\n');
2819 for (var i = 0; i < header.length; i++) {
2820 var delimitPos = header[i].indexOf(':');
2821 if (delimitPos != -1) {
2822 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2830 obj.status = o.conn.status;
2831 obj.statusText = o.conn.statusText;
2832 obj.getResponseHeader = headerObj;
2833 obj.getAllResponseHeaders = headerStr;
2834 obj.responseText = o.conn.responseText;
2835 obj.responseXML = o.conn.responseXML;
2837 if (typeof callbackArg !== undefined) {
2838 obj.argument = callbackArg;
2844 createExceptionObject:function(tId, callbackArg, isAbort)
2847 var COMM_ERROR = 'communication failure';
2848 var ABORT_CODE = -1;
2849 var ABORT_ERROR = 'transaction aborted';
2855 obj.status = ABORT_CODE;
2856 obj.statusText = ABORT_ERROR;
2859 obj.status = COMM_CODE;
2860 obj.statusText = COMM_ERROR;
2864 obj.argument = callbackArg;
2870 initHeader:function(label, value, isDefault)
2872 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2874 if (headerObj[label] === undefined) {
2875 headerObj[label] = value;
2880 headerObj[label] = value + "," + headerObj[label];
2884 this.hasDefaultHeaders = true;
2887 this.hasHeaders = true;
2892 setHeader:function(o)
2894 if (this.hasDefaultHeaders) {
2895 for (var prop in this.defaultHeaders) {
2896 if (this.defaultHeaders.hasOwnProperty(prop)) {
2897 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2902 if (this.hasHeaders) {
2903 for (var prop in this.headers) {
2904 if (this.headers.hasOwnProperty(prop)) {
2905 o.conn.setRequestHeader(prop, this.headers[prop]);
2909 this.hasHeaders = false;
2913 resetDefaultHeaders:function() {
2914 delete this.defaultHeaders;
2915 this.defaultHeaders = {};
2916 this.hasDefaultHeaders = false;
2919 abort:function(o, callback, isTimeout)
2921 if(this.isCallInProgress(o)) {
2923 window.clearInterval(this.poll[o.tId]);
2924 delete this.poll[o.tId];
2926 delete this.timeout[o.tId];
2929 this.handleTransactionResponse(o, callback, true);
2939 isCallInProgress:function(o)
2942 return o.conn.readyState != 4 && o.conn.readyState != 0;
2951 releaseObject:function(o)
2960 'MSXML2.XMLHTTP.3.0',
2968 * Portions of this file are based on pieces of Yahoo User Interface Library
2969 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2970 * YUI licensed under the BSD License:
2971 * http://developer.yahoo.net/yui/license.txt
2972 * <script type="text/javascript">
2976 Roo.lib.Region = function(t, r, b, l) {
2986 Roo.lib.Region.prototype = {
2987 contains : function(region) {
2988 return ( region.left >= this.left &&
2989 region.right <= this.right &&
2990 region.top >= this.top &&
2991 region.bottom <= this.bottom );
2995 getArea : function() {
2996 return ( (this.bottom - this.top) * (this.right - this.left) );
2999 intersect : function(region) {
3000 var t = Math.max(this.top, region.top);
3001 var r = Math.min(this.right, region.right);
3002 var b = Math.min(this.bottom, region.bottom);
3003 var l = Math.max(this.left, region.left);
3005 if (b >= t && r >= l) {
3006 return new Roo.lib.Region(t, r, b, l);
3011 union : function(region) {
3012 var t = Math.min(this.top, region.top);
3013 var r = Math.max(this.right, region.right);
3014 var b = Math.max(this.bottom, region.bottom);
3015 var l = Math.min(this.left, region.left);
3017 return new Roo.lib.Region(t, r, b, l);
3020 adjust : function(t, l, b, r) {
3029 Roo.lib.Region.getRegion = function(el) {
3030 var p = Roo.lib.Dom.getXY(el);
3033 var r = p[0] + el.offsetWidth;
3034 var b = p[1] + el.offsetHeight;
3037 return new Roo.lib.Region(t, r, b, l);
3040 * Portions of this file are based on pieces of Yahoo User Interface Library
3041 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3042 * YUI licensed under the BSD License:
3043 * http://developer.yahoo.net/yui/license.txt
3044 * <script type="text/javascript">
3047 //@@dep Roo.lib.Region
3050 Roo.lib.Point = function(x, y) {
3051 if (x instanceof Array) {
3055 this.x = this.right = this.left = this[0] = x;
3056 this.y = this.top = this.bottom = this[1] = y;
3059 Roo.lib.Point.prototype = new Roo.lib.Region();
3061 * Portions of this file are based on pieces of Yahoo User Interface Library
3062 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3063 * YUI licensed under the BSD License:
3064 * http://developer.yahoo.net/yui/license.txt
3065 * <script type="text/javascript">
3072 scroll : function(el, args, duration, easing, cb, scope) {
3073 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
3076 motion : function(el, args, duration, easing, cb, scope) {
3077 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
3080 color : function(el, args, duration, easing, cb, scope) {
3081 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
3084 run : function(el, args, duration, easing, cb, scope, type) {
3085 type = type || Roo.lib.AnimBase;
3086 if (typeof easing == "string") {
3087 easing = Roo.lib.Easing[easing];
3089 var anim = new type(el, args, duration, easing);
3090 anim.animateX(function() {
3091 Roo.callback(cb, scope);
3097 * Portions of this file are based on pieces of Yahoo User Interface Library
3098 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3099 * YUI licensed under the BSD License:
3100 * http://developer.yahoo.net/yui/license.txt
3101 * <script type="text/javascript">
3109 if (!libFlyweight) {
3110 libFlyweight = new Roo.Element.Flyweight();
3112 libFlyweight.dom = el;
3113 return libFlyweight;
3116 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
3120 Roo.lib.AnimBase = function(el, attributes, duration, method) {
3122 this.init(el, attributes, duration, method);
3126 Roo.lib.AnimBase.fly = fly;
3130 Roo.lib.AnimBase.prototype = {
3132 toString: function() {
3133 var el = this.getEl();
3134 var id = el.id || el.tagName;
3135 return ("Anim " + id);
3139 noNegatives: /width|height|opacity|padding/i,
3140 offsetAttribute: /^((width|height)|(top|left))$/,
3141 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3142 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3146 doMethod: function(attr, start, end) {
3147 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3151 setAttribute: function(attr, val, unit) {
3152 if (this.patterns.noNegatives.test(attr)) {
3153 val = (val > 0) ? val : 0;
3156 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3160 getAttribute: function(attr) {
3161 var el = this.getEl();
3162 var val = fly(el).getStyle(attr);
3164 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3165 return parseFloat(val);
3168 var a = this.patterns.offsetAttribute.exec(attr) || [];
3169 var pos = !!( a[3] );
3170 var box = !!( a[2] );
3173 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3174 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3183 getDefaultUnit: function(attr) {
3184 if (this.patterns.defaultUnit.test(attr)) {
3191 animateX : function(callback, scope) {
3192 var f = function() {
3193 this.onComplete.removeListener(f);
3194 if (typeof callback == "function") {
3195 callback.call(scope || this, this);
3198 this.onComplete.addListener(f, this);
3203 setRuntimeAttribute: function(attr) {
3206 var attributes = this.attributes;
3208 this.runtimeAttributes[attr] = {};
3210 var isset = function(prop) {
3211 return (typeof prop !== 'undefined');
3214 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3218 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3221 if (isset(attributes[attr]['to'])) {
3222 end = attributes[attr]['to'];
3223 } else if (isset(attributes[attr]['by'])) {
3224 if (start.constructor == Array) {
3226 for (var i = 0, len = start.length; i < len; ++i) {
3227 end[i] = start[i] + attributes[attr]['by'][i];
3230 end = start + attributes[attr]['by'];
3234 this.runtimeAttributes[attr].start = start;
3235 this.runtimeAttributes[attr].end = end;
3238 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3242 init: function(el, attributes, duration, method) {
3244 var isAnimated = false;
3247 var startTime = null;
3250 var actualFrames = 0;
3253 el = Roo.getDom(el);
3256 this.attributes = attributes || {};
3259 this.duration = duration || 1;
3262 this.method = method || Roo.lib.Easing.easeNone;
3265 this.useSeconds = true;
3268 this.currentFrame = 0;
3271 this.totalFrames = Roo.lib.AnimMgr.fps;
3274 this.getEl = function() {
3279 this.isAnimated = function() {
3284 this.getStartTime = function() {
3288 this.runtimeAttributes = {};
3291 this.animate = function() {
3292 if (this.isAnimated()) {
3296 this.currentFrame = 0;
3298 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3300 Roo.lib.AnimMgr.registerElement(this);
3304 this.stop = function(finish) {
3306 this.currentFrame = this.totalFrames;
3307 this._onTween.fire();
3309 Roo.lib.AnimMgr.stop(this);
3312 var onStart = function() {
3313 this.onStart.fire();
3315 this.runtimeAttributes = {};
3316 for (var attr in this.attributes) {
3317 this.setRuntimeAttribute(attr);
3322 startTime = new Date();
3326 var onTween = function() {
3328 duration: new Date() - this.getStartTime(),
3329 currentFrame: this.currentFrame
3332 data.toString = function() {
3334 'duration: ' + data.duration +
3335 ', currentFrame: ' + data.currentFrame
3339 this.onTween.fire(data);
3341 var runtimeAttributes = this.runtimeAttributes;
3343 for (var attr in runtimeAttributes) {
3344 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3350 var onComplete = function() {
3351 var actual_duration = (new Date() - startTime) / 1000 ;
3354 duration: actual_duration,
3355 frames: actualFrames,
3356 fps: actualFrames / actual_duration
3359 data.toString = function() {
3361 'duration: ' + data.duration +
3362 ', frames: ' + data.frames +
3363 ', fps: ' + data.fps
3369 this.onComplete.fire(data);
3373 this._onStart = new Roo.util.Event(this);
3374 this.onStart = new Roo.util.Event(this);
3375 this.onTween = new Roo.util.Event(this);
3376 this._onTween = new Roo.util.Event(this);
3377 this.onComplete = new Roo.util.Event(this);
3378 this._onComplete = new Roo.util.Event(this);
3379 this._onStart.addListener(onStart);
3380 this._onTween.addListener(onTween);
3381 this._onComplete.addListener(onComplete);
3386 * Portions of this file are based on pieces of Yahoo User Interface Library
3387 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3388 * YUI licensed under the BSD License:
3389 * http://developer.yahoo.net/yui/license.txt
3390 * <script type="text/javascript">
3394 Roo.lib.AnimMgr = new function() {
3411 this.registerElement = function(tween) {
3412 queue[queue.length] = tween;
3414 tween._onStart.fire();
3419 this.unRegister = function(tween, index) {
3420 tween._onComplete.fire();
3421 index = index || getIndex(tween);
3423 queue.splice(index, 1);
3427 if (tweenCount <= 0) {
3433 this.start = function() {
3434 if (thread === null) {
3435 thread = setInterval(this.run, this.delay);
3440 this.stop = function(tween) {
3442 clearInterval(thread);
3444 for (var i = 0, len = queue.length; i < len; ++i) {
3445 if (queue[0].isAnimated()) {
3446 this.unRegister(queue[0], 0);
3455 this.unRegister(tween);
3460 this.run = function() {
3461 for (var i = 0, len = queue.length; i < len; ++i) {
3462 var tween = queue[i];
3463 if (!tween || !tween.isAnimated()) {
3467 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3469 tween.currentFrame += 1;
3471 if (tween.useSeconds) {
3472 correctFrame(tween);
3474 tween._onTween.fire();
3477 Roo.lib.AnimMgr.stop(tween, i);
3482 var getIndex = function(anim) {
3483 for (var i = 0, len = queue.length; i < len; ++i) {
3484 if (queue[i] == anim) {
3492 var correctFrame = function(tween) {
3493 var frames = tween.totalFrames;
3494 var frame = tween.currentFrame;
3495 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3496 var elapsed = (new Date() - tween.getStartTime());
3499 if (elapsed < tween.duration * 1000) {
3500 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3502 tweak = frames - (frame + 1);
3504 if (tweak > 0 && isFinite(tweak)) {
3505 if (tween.currentFrame + tweak >= frames) {
3506 tweak = frames - (frame + 1);
3509 tween.currentFrame += tweak;
3513 * Portions of this file are based on pieces of Yahoo User Interface Library
3514 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3515 * YUI licensed under the BSD License:
3516 * http://developer.yahoo.net/yui/license.txt
3517 * <script type="text/javascript">
3520 Roo.lib.Bezier = new function() {
3522 this.getPosition = function(points, t) {
3523 var n = points.length;
3526 for (var i = 0; i < n; ++i) {
3527 tmp[i] = [points[i][0], points[i][1]];
3530 for (var j = 1; j < n; ++j) {
3531 for (i = 0; i < n - j; ++i) {
3532 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3533 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3537 return [ tmp[0][0], tmp[0][1] ];
3541 * Portions of this file are based on pieces of Yahoo User Interface Library
3542 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3543 * YUI licensed under the BSD License:
3544 * http://developer.yahoo.net/yui/license.txt
3545 * <script type="text/javascript">
3550 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3551 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3554 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3556 var fly = Roo.lib.AnimBase.fly;
3558 var superclass = Y.ColorAnim.superclass;
3559 var proto = Y.ColorAnim.prototype;
3561 proto.toString = function() {
3562 var el = this.getEl();
3563 var id = el.id || el.tagName;
3564 return ("ColorAnim " + id);
3567 proto.patterns.color = /color$/i;
3568 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3569 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3570 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3571 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3574 proto.parseColor = function(s) {
3575 if (s.length == 3) {
3579 var c = this.patterns.hex.exec(s);
3580 if (c && c.length == 4) {
3581 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3584 c = this.patterns.rgb.exec(s);
3585 if (c && c.length == 4) {
3586 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3589 c = this.patterns.hex3.exec(s);
3590 if (c && c.length == 4) {
3591 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3596 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3597 proto.getAttribute = function(attr) {
3598 var el = this.getEl();
3599 if (this.patterns.color.test(attr)) {
3600 var val = fly(el).getStyle(attr);
3602 if (this.patterns.transparent.test(val)) {
3603 var parent = el.parentNode;
3604 val = fly(parent).getStyle(attr);
3606 while (parent && this.patterns.transparent.test(val)) {
3607 parent = parent.parentNode;
3608 val = fly(parent).getStyle(attr);
3609 if (parent.tagName.toUpperCase() == 'HTML') {
3615 val = superclass.getAttribute.call(this, attr);
3620 proto.getAttribute = function(attr) {
3621 var el = this.getEl();
3622 if (this.patterns.color.test(attr)) {
3623 var val = fly(el).getStyle(attr);
3625 if (this.patterns.transparent.test(val)) {
3626 var parent = el.parentNode;
3627 val = fly(parent).getStyle(attr);
3629 while (parent && this.patterns.transparent.test(val)) {
3630 parent = parent.parentNode;
3631 val = fly(parent).getStyle(attr);
3632 if (parent.tagName.toUpperCase() == 'HTML') {
3638 val = superclass.getAttribute.call(this, attr);
3644 proto.doMethod = function(attr, start, end) {
3647 if (this.patterns.color.test(attr)) {
3649 for (var i = 0, len = start.length; i < len; ++i) {
3650 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3653 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3656 val = superclass.doMethod.call(this, attr, start, end);
3662 proto.setRuntimeAttribute = function(attr) {
3663 superclass.setRuntimeAttribute.call(this, attr);
3665 if (this.patterns.color.test(attr)) {
3666 var attributes = this.attributes;
3667 var start = this.parseColor(this.runtimeAttributes[attr].start);
3668 var end = this.parseColor(this.runtimeAttributes[attr].end);
3670 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3671 end = this.parseColor(attributes[attr].by);
3673 for (var i = 0, len = start.length; i < len; ++i) {
3674 end[i] = start[i] + end[i];
3678 this.runtimeAttributes[attr].start = start;
3679 this.runtimeAttributes[attr].end = end;
3685 * Portions of this file are based on pieces of Yahoo User Interface Library
3686 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3687 * YUI licensed under the BSD License:
3688 * http://developer.yahoo.net/yui/license.txt
3689 * <script type="text/javascript">
3695 easeNone: function (t, b, c, d) {
3696 return c * t / d + b;
3700 easeIn: function (t, b, c, d) {
3701 return c * (t /= d) * t + b;
3705 easeOut: function (t, b, c, d) {
3706 return -c * (t /= d) * (t - 2) + b;
3710 easeBoth: function (t, b, c, d) {
3711 if ((t /= d / 2) < 1) {
3712 return c / 2 * t * t + b;
3715 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3719 easeInStrong: function (t, b, c, d) {
3720 return c * (t /= d) * t * t * t + b;
3724 easeOutStrong: function (t, b, c, d) {
3725 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3729 easeBothStrong: function (t, b, c, d) {
3730 if ((t /= d / 2) < 1) {
3731 return c / 2 * t * t * t * t + b;
3734 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3739 elasticIn: function (t, b, c, d, a, p) {
3743 if ((t /= d) == 1) {
3750 if (!a || a < Math.abs(c)) {
3755 var s = p / (2 * Math.PI) * Math.asin(c / a);
3758 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3762 elasticOut: function (t, b, c, d, a, p) {
3766 if ((t /= d) == 1) {
3773 if (!a || a < Math.abs(c)) {
3778 var s = p / (2 * Math.PI) * Math.asin(c / a);
3781 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3785 elasticBoth: function (t, b, c, d, a, p) {
3790 if ((t /= d / 2) == 2) {
3798 if (!a || a < Math.abs(c)) {
3803 var s = p / (2 * Math.PI) * Math.asin(c / a);
3807 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3808 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3810 return a * Math.pow(2, -10 * (t -= 1)) *
3811 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3816 backIn: function (t, b, c, d, s) {
3817 if (typeof s == 'undefined') {
3820 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3824 backOut: function (t, b, c, d, s) {
3825 if (typeof s == 'undefined') {
3828 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3832 backBoth: function (t, b, c, d, s) {
3833 if (typeof s == 'undefined') {
3837 if ((t /= d / 2 ) < 1) {
3838 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3840 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3844 bounceIn: function (t, b, c, d) {
3845 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3849 bounceOut: function (t, b, c, d) {
3850 if ((t /= d) < (1 / 2.75)) {
3851 return c * (7.5625 * t * t) + b;
3852 } else if (t < (2 / 2.75)) {
3853 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3854 } else if (t < (2.5 / 2.75)) {
3855 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3857 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3861 bounceBoth: function (t, b, c, d) {
3863 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3865 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3868 * Portions of this file are based on pieces of Yahoo User Interface Library
3869 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3870 * YUI licensed under the BSD License:
3871 * http://developer.yahoo.net/yui/license.txt
3872 * <script type="text/javascript">
3876 Roo.lib.Motion = function(el, attributes, duration, method) {
3878 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3882 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3886 var superclass = Y.Motion.superclass;
3887 var proto = Y.Motion.prototype;
3889 proto.toString = function() {
3890 var el = this.getEl();
3891 var id = el.id || el.tagName;
3892 return ("Motion " + id);
3895 proto.patterns.points = /^points$/i;
3897 proto.setAttribute = function(attr, val, unit) {
3898 if (this.patterns.points.test(attr)) {
3899 unit = unit || 'px';
3900 superclass.setAttribute.call(this, 'left', val[0], unit);
3901 superclass.setAttribute.call(this, 'top', val[1], unit);
3903 superclass.setAttribute.call(this, attr, val, unit);
3907 proto.getAttribute = function(attr) {
3908 if (this.patterns.points.test(attr)) {
3910 superclass.getAttribute.call(this, 'left'),
3911 superclass.getAttribute.call(this, 'top')
3914 val = superclass.getAttribute.call(this, attr);
3920 proto.doMethod = function(attr, start, end) {
3923 if (this.patterns.points.test(attr)) {
3924 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3925 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3927 val = superclass.doMethod.call(this, attr, start, end);
3932 proto.setRuntimeAttribute = function(attr) {
3933 if (this.patterns.points.test(attr)) {
3934 var el = this.getEl();
3935 var attributes = this.attributes;
3937 var control = attributes['points']['control'] || [];
3941 if (control.length > 0 && !(control[0] instanceof Array)) {
3942 control = [control];
3945 for (i = 0,len = control.length; i < len; ++i) {
3946 tmp[i] = control[i];
3951 Roo.fly(el).position();
3953 if (isset(attributes['points']['from'])) {
3954 Roo.lib.Dom.setXY(el, attributes['points']['from']);
3957 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3960 start = this.getAttribute('points');
3963 if (isset(attributes['points']['to'])) {
3964 end = translateValues.call(this, attributes['points']['to'], start);
3966 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3967 for (i = 0,len = control.length; i < len; ++i) {
3968 control[i] = translateValues.call(this, control[i], start);
3972 } else if (isset(attributes['points']['by'])) {
3973 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
3975 for (i = 0,len = control.length; i < len; ++i) {
3976 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
3980 this.runtimeAttributes[attr] = [start];
3982 if (control.length > 0) {
3983 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
3986 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
3989 superclass.setRuntimeAttribute.call(this, attr);
3993 var translateValues = function(val, start) {
3994 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3995 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
4000 var isset = function(prop) {
4001 return (typeof prop !== 'undefined');
4005 * Portions of this file are based on pieces of Yahoo User Interface Library
4006 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4007 * YUI licensed under the BSD License:
4008 * http://developer.yahoo.net/yui/license.txt
4009 * <script type="text/javascript">
4013 Roo.lib.Scroll = function(el, attributes, duration, method) {
4015 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
4019 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
4023 var superclass = Y.Scroll.superclass;
4024 var proto = Y.Scroll.prototype;
4026 proto.toString = function() {
4027 var el = this.getEl();
4028 var id = el.id || el.tagName;
4029 return ("Scroll " + id);
4032 proto.doMethod = function(attr, start, end) {
4035 if (attr == 'scroll') {
4037 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
4038 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
4042 val = superclass.doMethod.call(this, attr, start, end);
4047 proto.getAttribute = function(attr) {
4049 var el = this.getEl();
4051 if (attr == 'scroll') {
4052 val = [ el.scrollLeft, el.scrollTop ];
4054 val = superclass.getAttribute.call(this, attr);
4060 proto.setAttribute = function(attr, val, unit) {
4061 var el = this.getEl();
4063 if (attr == 'scroll') {
4064 el.scrollLeft = val[0];
4065 el.scrollTop = val[1];
4067 superclass.setAttribute.call(this, attr, val, unit);
4073 * Ext JS Library 1.1.1
4074 * Copyright(c) 2006-2007, Ext JS, LLC.
4076 * Originally Released Under LGPL - original licence link has changed is not relivant.
4079 * <script type="text/javascript">
4083 // nasty IE9 hack - what a pile of crap that is..
4085 if (typeof Range != "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
4086 Range.prototype.createContextualFragment = function (html) {
4087 var doc = window.document;
4088 var container = doc.createElement("div");
4089 container.innerHTML = html;
4090 var frag = doc.createDocumentFragment(), n;
4091 while ((n = container.firstChild)) {
4092 frag.appendChild(n);
4099 * @class Roo.DomHelper
4100 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
4101 * For more information see <a href="http://web.archive.org/web/20071221063734/http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>.
4104 Roo.DomHelper = function(){
4105 var tempTableEl = null;
4106 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
4107 var tableRe = /^table|tbody|tr|td$/i;
4109 // build as innerHTML where available
4111 var createHtml = function(o){
4112 if(typeof o == 'string'){
4121 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue;
4122 if(attr == "style"){
4124 if(typeof s == "function"){
4127 if(typeof s == "string"){
4128 b += ' style="' + s + '"';
4129 }else if(typeof s == "object"){
4132 if(typeof s[key] != "function"){
4133 b += key + ":" + s[key] + ";";
4140 b += ' class="' + o["cls"] + '"';
4141 }else if(attr == "htmlFor"){
4142 b += ' for="' + o["htmlFor"] + '"';
4144 b += " " + attr + '="' + o[attr] + '"';
4148 if(emptyTags.test(o.tag)){
4152 var cn = o.children || o.cn;
4154 //http://bugs.kde.org/show_bug.cgi?id=71506
4155 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4156 for(var i = 0, len = cn.length; i < len; i++) {
4157 b += createHtml(cn[i], b);
4160 b += createHtml(cn, b);
4166 b += "</" + o.tag + ">";
4173 var createDom = function(o, parentNode){
4175 // defininition craeted..
4177 if (o.ns && o.ns != 'html') {
4179 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4180 xmlns[o.ns] = o.xmlns;
4183 if (typeof(xmlns[o.ns]) == 'undefined') {
4184 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4190 if (typeof(o) == 'string') {
4191 return parentNode.appendChild(document.createTextNode(o));
4193 o.tag = o.tag || div;
4194 if (o.ns && Roo.isIE) {
4196 o.tag = o.ns + ':' + o.tag;
4199 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4200 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4203 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4204 attr == "style" || typeof o[attr] == "function") continue;
4206 if(attr=="cls" && Roo.isIE){
4207 el.className = o["cls"];
4209 if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
4210 else el[attr] = o[attr];
4213 Roo.DomHelper.applyStyles(el, o.style);
4214 var cn = o.children || o.cn;
4216 //http://bugs.kde.org/show_bug.cgi?id=71506
4217 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4218 for(var i = 0, len = cn.length; i < len; i++) {
4219 createDom(cn[i], el);
4226 el.innerHTML = o.html;
4229 parentNode.appendChild(el);
4234 var ieTable = function(depth, s, h, e){
4235 tempTableEl.innerHTML = [s, h, e].join('');
4236 var i = -1, el = tempTableEl;
4243 // kill repeat to save bytes
4247 tbe = '</tbody>'+te,
4253 * Nasty code for IE's broken table implementation
4255 var insertIntoTable = function(tag, where, el, html){
4257 tempTableEl = document.createElement('div');
4262 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4265 if(where == 'beforebegin'){
4269 before = el.nextSibling;
4272 node = ieTable(4, trs, html, tre);
4274 else if(tag == 'tr'){
4275 if(where == 'beforebegin'){
4278 node = ieTable(3, tbs, html, tbe);
4279 } else if(where == 'afterend'){
4280 before = el.nextSibling;
4282 node = ieTable(3, tbs, html, tbe);
4283 } else{ // INTO a TR
4284 if(where == 'afterbegin'){
4285 before = el.firstChild;
4287 node = ieTable(4, trs, html, tre);
4289 } else if(tag == 'tbody'){
4290 if(where == 'beforebegin'){
4293 node = ieTable(2, ts, html, te);
4294 } else if(where == 'afterend'){
4295 before = el.nextSibling;
4297 node = ieTable(2, ts, html, te);
4299 if(where == 'afterbegin'){
4300 before = el.firstChild;
4302 node = ieTable(3, tbs, html, tbe);
4305 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4308 if(where == 'afterbegin'){
4309 before = el.firstChild;
4311 node = ieTable(2, ts, html, te);
4313 el.insertBefore(node, before);
4318 /** True to force the use of DOM instead of html fragments @type Boolean */
4322 * Returns the markup for the passed Element(s) config
4323 * @param {Object} o The Dom object spec (and children)
4326 markup : function(o){
4327 return createHtml(o);
4331 * Applies a style specification to an element
4332 * @param {String/HTMLElement} el The element to apply styles to
4333 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4334 * a function which returns such a specification.
4336 applyStyles : function(el, styles){
4339 if(typeof styles == "string"){
4340 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4342 while ((matches = re.exec(styles)) != null){
4343 el.setStyle(matches[1], matches[2]);
4345 }else if (typeof styles == "object"){
4346 for (var style in styles){
4347 el.setStyle(style, styles[style]);
4349 }else if (typeof styles == "function"){
4350 Roo.DomHelper.applyStyles(el, styles.call());
4356 * Inserts an HTML fragment into the Dom
4357 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4358 * @param {HTMLElement} el The context element
4359 * @param {String} html The HTML fragmenet
4360 * @return {HTMLElement} The new node
4362 insertHtml : function(where, el, html){
4363 where = where.toLowerCase();
4364 if(el.insertAdjacentHTML){
4365 if(tableRe.test(el.tagName)){
4367 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4373 el.insertAdjacentHTML('BeforeBegin', html);
4374 return el.previousSibling;
4376 el.insertAdjacentHTML('AfterBegin', html);
4377 return el.firstChild;
4379 el.insertAdjacentHTML('BeforeEnd', html);
4380 return el.lastChild;
4382 el.insertAdjacentHTML('AfterEnd', html);
4383 return el.nextSibling;
4385 throw 'Illegal insertion point -> "' + where + '"';
4387 var range = el.ownerDocument.createRange();
4391 range.setStartBefore(el);
4392 frag = range.createContextualFragment(html);
4393 el.parentNode.insertBefore(frag, el);
4394 return el.previousSibling;
4397 range.setStartBefore(el.firstChild);
4398 frag = range.createContextualFragment(html);
4399 el.insertBefore(frag, el.firstChild);
4400 return el.firstChild;
4402 el.innerHTML = html;
4403 return el.firstChild;
4407 range.setStartAfter(el.lastChild);
4408 frag = range.createContextualFragment(html);
4409 el.appendChild(frag);
4410 return el.lastChild;
4412 el.innerHTML = html;
4413 return el.lastChild;
4416 range.setStartAfter(el);
4417 frag = range.createContextualFragment(html);
4418 el.parentNode.insertBefore(frag, el.nextSibling);
4419 return el.nextSibling;
4421 throw 'Illegal insertion point -> "' + where + '"';
4425 * Creates new Dom element(s) and inserts them before el
4426 * @param {String/HTMLElement/Element} el The context element
4427 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4428 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4429 * @return {HTMLElement/Roo.Element} The new node
4431 insertBefore : function(el, o, returnElement){
4432 return this.doInsert(el, o, returnElement, "beforeBegin");
4436 * Creates new Dom element(s) and inserts them after el
4437 * @param {String/HTMLElement/Element} el The context element
4438 * @param {Object} o The Dom object spec (and children)
4439 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4440 * @return {HTMLElement/Roo.Element} The new node
4442 insertAfter : function(el, o, returnElement){
4443 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4447 * Creates new Dom element(s) and inserts them as the first child of el
4448 * @param {String/HTMLElement/Element} el The context element
4449 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4450 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4451 * @return {HTMLElement/Roo.Element} The new node
4453 insertFirst : function(el, o, returnElement){
4454 return this.doInsert(el, o, returnElement, "afterBegin");
4458 doInsert : function(el, o, returnElement, pos, sibling){
4459 el = Roo.getDom(el);
4461 if(this.useDom || o.ns){
4462 newNode = createDom(o, null);
4463 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4465 var html = createHtml(o);
4466 newNode = this.insertHtml(pos, el, html);
4468 return returnElement ? Roo.get(newNode, true) : newNode;
4472 * Creates new Dom element(s) and appends them to el
4473 * @param {String/HTMLElement/Element} el The context element
4474 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4475 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4476 * @return {HTMLElement/Roo.Element} The new node
4478 append : function(el, o, returnElement){
4479 el = Roo.getDom(el);
4481 if(this.useDom || o.ns){
4482 newNode = createDom(o, null);
4483 el.appendChild(newNode);
4485 var html = createHtml(o);
4486 newNode = this.insertHtml("beforeEnd", el, html);
4488 return returnElement ? Roo.get(newNode, true) : newNode;
4492 * Creates new Dom element(s) and overwrites the contents of el with them
4493 * @param {String/HTMLElement/Element} el The context element
4494 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4495 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4496 * @return {HTMLElement/Roo.Element} The new node
4498 overwrite : function(el, o, returnElement){
4499 el = Roo.getDom(el);
4502 while (el.childNodes.length) {
4503 el.removeChild(el.firstChild);
4507 el.innerHTML = createHtml(o);
4510 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4514 * Creates a new Roo.DomHelper.Template from the Dom object spec
4515 * @param {Object} o The Dom object spec (and children)
4516 * @return {Roo.DomHelper.Template} The new template
4518 createTemplate : function(o){
4519 var html = createHtml(o);
4520 return new Roo.Template(html);
4526 * Ext JS Library 1.1.1
4527 * Copyright(c) 2006-2007, Ext JS, LLC.
4529 * Originally Released Under LGPL - original licence link has changed is not relivant.
4532 * <script type="text/javascript">
4536 * @class Roo.Template
4537 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4538 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4541 var t = new Roo.Template({
4542 html : '<div name="{id}">' +
4543 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4545 myformat: function (value, allValues) {
4546 return 'XX' + value;
4549 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4551 * For more information see this blog post with examples:
4552 * <a href="http://www.cnitblog.com/seeyeah/archive/2011/12/30/38728.html/">DomHelper
4553 - Create Elements using DOM, HTML fragments and Templates</a>.
4555 * @param {Object} cfg - Configuration object.
4557 Roo.Template = function(cfg){
4559 if(cfg instanceof Array){
4561 }else if(arguments.length > 1){
4562 cfg = Array.prototype.join.call(arguments, "");
4566 if (typeof(cfg) == 'object') {
4577 Roo.Template.prototype = {
4580 * @cfg {String} url The Url to load the template from. beware if you are loading from a url, the data may not be ready if you use it instantly..
4581 * it should be fixed so that template is observable...
4585 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4589 * Returns an HTML fragment of this template with the specified values applied.
4590 * @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'})
4591 * @return {String} The HTML fragment
4593 applyTemplate : function(values){
4597 return this.compiled(values);
4599 var useF = this.disableFormats !== true;
4600 var fm = Roo.util.Format, tpl = this;
4601 var fn = function(m, name, format, args){
4603 if(format.substr(0, 5) == "this."){
4604 return tpl.call(format.substr(5), values[name], values);
4607 // quoted values are required for strings in compiled templates,
4608 // but for non compiled we need to strip them
4609 // quoted reversed for jsmin
4610 var re = /^\s*['"](.*)["']\s*$/;
4611 args = args.split(',');
4612 for(var i = 0, len = args.length; i < len; i++){
4613 args[i] = args[i].replace(re, "$1");
4615 args = [values[name]].concat(args);
4617 args = [values[name]];
4619 return fm[format].apply(fm, args);
4622 return values[name] !== undefined ? values[name] : "";
4625 return this.html.replace(this.re, fn);
4643 this.loading = true;
4644 this.compiled = false;
4646 var cx = new Roo.data.Connection();
4650 success : function (response) {
4652 _t.html = response.responseText;
4656 failure : function(response) {
4657 Roo.log("Template failed to load from " + _t.url);
4664 * Sets the HTML used as the template and optionally compiles it.
4665 * @param {String} html
4666 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4667 * @return {Roo.Template} this
4669 set : function(html, compile){
4671 this.compiled = null;
4679 * True to disable format functions (defaults to false)
4682 disableFormats : false,
4685 * The regular expression used to match template variables
4689 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4692 * Compiles the template into an internal function, eliminating the RegEx overhead.
4693 * @return {Roo.Template} this
4695 compile : function(){
4696 var fm = Roo.util.Format;
4697 var useF = this.disableFormats !== true;
4698 var sep = Roo.isGecko ? "+" : ",";
4699 var fn = function(m, name, format, args){
4701 args = args ? ',' + args : "";
4702 if(format.substr(0, 5) != "this."){
4703 format = "fm." + format + '(';
4705 format = 'this.call("'+ format.substr(5) + '", ';
4709 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4711 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4714 // branched to use + in gecko and [].join() in others
4716 body = "this.compiled = function(values){ return '" +
4717 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4720 body = ["this.compiled = function(values){ return ['"];
4721 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4722 body.push("'].join('');};");
4723 body = body.join('');
4733 // private function used to call members
4734 call : function(fnName, value, allValues){
4735 return this[fnName](value, allValues);
4739 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4740 * @param {String/HTMLElement/Roo.Element} el The context element
4741 * @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'})
4742 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4743 * @return {HTMLElement/Roo.Element} The new node or Element
4745 insertFirst: function(el, values, returnElement){
4746 return this.doInsert('afterBegin', el, values, returnElement);
4750 * Applies the supplied values to the template and inserts the new node(s) before el.
4751 * @param {String/HTMLElement/Roo.Element} el The context element
4752 * @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'})
4753 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4754 * @return {HTMLElement/Roo.Element} The new node or Element
4756 insertBefore: function(el, values, returnElement){
4757 return this.doInsert('beforeBegin', el, values, returnElement);
4761 * Applies the supplied values to the template and inserts the new node(s) after el.
4762 * @param {String/HTMLElement/Roo.Element} el The context element
4763 * @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'})
4764 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4765 * @return {HTMLElement/Roo.Element} The new node or Element
4767 insertAfter : function(el, values, returnElement){
4768 return this.doInsert('afterEnd', el, values, returnElement);
4772 * Applies the supplied values to the template and appends the new node(s) to el.
4773 * @param {String/HTMLElement/Roo.Element} el The context element
4774 * @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'})
4775 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4776 * @return {HTMLElement/Roo.Element} The new node or Element
4778 append : function(el, values, returnElement){
4779 return this.doInsert('beforeEnd', el, values, returnElement);
4782 doInsert : function(where, el, values, returnEl){
4783 el = Roo.getDom(el);
4784 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4785 return returnEl ? Roo.get(newNode, true) : newNode;
4789 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4790 * @param {String/HTMLElement/Roo.Element} el The context element
4791 * @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'})
4792 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4793 * @return {HTMLElement/Roo.Element} The new node or Element
4795 overwrite : function(el, values, returnElement){
4796 el = Roo.getDom(el);
4797 el.innerHTML = this.applyTemplate(values);
4798 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4802 * Alias for {@link #applyTemplate}
4805 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4808 Roo.DomHelper.Template = Roo.Template;
4811 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4812 * @param {String/HTMLElement} el A DOM element or its id
4813 * @returns {Roo.Template} The created template
4816 Roo.Template.from = function(el){
4817 el = Roo.getDom(el);
4818 return new Roo.Template(el.value || el.innerHTML);
4821 * Ext JS Library 1.1.1
4822 * Copyright(c) 2006-2007, Ext JS, LLC.
4824 * Originally Released Under LGPL - original licence link has changed is not relivant.
4827 * <script type="text/javascript">
4832 * This is code is also distributed under MIT license for use
4833 * with jQuery and prototype JavaScript libraries.
4836 * @class Roo.DomQuery
4837 Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
4839 DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
4842 All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
4844 <h4>Element Selectors:</h4>
4846 <li> <b>*</b> any element</li>
4847 <li> <b>E</b> an element with the tag E</li>
4848 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4849 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4850 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4851 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4853 <h4>Attribute Selectors:</h4>
4854 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4856 <li> <b>E[foo]</b> has an attribute "foo"</li>
4857 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4858 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4859 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4860 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4861 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4862 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4864 <h4>Pseudo Classes:</h4>
4866 <li> <b>E:first-child</b> E is the first child of its parent</li>
4867 <li> <b>E:last-child</b> E is the last child of its parent</li>
4868 <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
4869 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4870 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4871 <li> <b>E:only-child</b> E is the only child of its parent</li>
4872 <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
4873 <li> <b>E:first</b> the first E in the resultset</li>
4874 <li> <b>E:last</b> the last E in the resultset</li>
4875 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4876 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4877 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4878 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4879 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4880 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4881 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4882 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4883 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4885 <h4>CSS Value Selectors:</h4>
4887 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4888 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4889 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4890 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4891 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4892 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4896 Roo.DomQuery = function(){
4897 var cache = {}, simpleCache = {}, valueCache = {};
4898 var nonSpace = /\S/;
4899 var trimRe = /^\s+|\s+$/g;
4900 var tplRe = /\{(\d+)\}/g;
4901 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4902 var tagTokenRe = /^(#)?([\w-\*]+)/;
4903 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4905 function child(p, index){
4907 var n = p.firstChild;
4909 if(n.nodeType == 1){
4920 while((n = n.nextSibling) && n.nodeType != 1);
4925 while((n = n.previousSibling) && n.nodeType != 1);
4929 function children(d){
4930 var n = d.firstChild, ni = -1;
4932 var nx = n.nextSibling;
4933 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4943 function byClassName(c, a, v){
4947 var r = [], ri = -1, cn;
4948 for(var i = 0, ci; ci = c[i]; i++){
4949 if((' '+ci.className+' ').indexOf(v) != -1){
4956 function attrValue(n, attr){
4957 if(!n.tagName && typeof n.length != "undefined"){
4966 if(attr == "class" || attr == "className"){
4969 return n.getAttribute(attr) || n[attr];
4973 function getNodes(ns, mode, tagName){
4974 var result = [], ri = -1, cs;
4978 tagName = tagName || "*";
4979 if(typeof ns.getElementsByTagName != "undefined"){
4983 for(var i = 0, ni; ni = ns[i]; i++){
4984 cs = ni.getElementsByTagName(tagName);
4985 for(var j = 0, ci; ci = cs[j]; j++){
4989 }else if(mode == "/" || mode == ">"){
4990 var utag = tagName.toUpperCase();
4991 for(var i = 0, ni, cn; ni = ns[i]; i++){
4992 cn = ni.children || ni.childNodes;
4993 for(var j = 0, cj; cj = cn[j]; j++){
4994 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
4999 }else if(mode == "+"){
5000 var utag = tagName.toUpperCase();
5001 for(var i = 0, n; n = ns[i]; i++){
5002 while((n = n.nextSibling) && n.nodeType != 1);
5003 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
5007 }else if(mode == "~"){
5008 for(var i = 0, n; n = ns[i]; i++){
5009 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
5018 function concat(a, b){
5022 for(var i = 0, l = b.length; i < l; i++){
5028 function byTag(cs, tagName){
5029 if(cs.tagName || cs == document){
5035 var r = [], ri = -1;
5036 tagName = tagName.toLowerCase();
5037 for(var i = 0, ci; ci = cs[i]; i++){
5038 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
5045 function byId(cs, attr, id){
5046 if(cs.tagName || cs == document){
5052 var r = [], ri = -1;
5053 for(var i = 0,ci; ci = cs[i]; i++){
5054 if(ci && ci.id == id){
5062 function byAttribute(cs, attr, value, op, custom){
5063 var r = [], ri = -1, st = custom=="{";
5064 var f = Roo.DomQuery.operators[op];
5065 for(var i = 0, ci; ci = cs[i]; i++){
5068 a = Roo.DomQuery.getStyle(ci, attr);
5070 else if(attr == "class" || attr == "className"){
5072 }else if(attr == "for"){
5074 }else if(attr == "href"){
5075 a = ci.getAttribute("href", 2);
5077 a = ci.getAttribute(attr);
5079 if((f && f(a, value)) || (!f && a)){
5086 function byPseudo(cs, name, value){
5087 return Roo.DomQuery.pseudos[name](cs, value);
5090 // This is for IE MSXML which does not support expandos.
5091 // IE runs the same speed using setAttribute, however FF slows way down
5092 // and Safari completely fails so they need to continue to use expandos.
5093 var isIE = window.ActiveXObject ? true : false;
5095 // this eval is stop the compressor from
5096 // renaming the variable to something shorter
5098 /** eval:var:batch */
5103 function nodupIEXml(cs){
5105 cs[0].setAttribute("_nodup", d);
5107 for(var i = 1, len = cs.length; i < len; i++){
5109 if(!c.getAttribute("_nodup") != d){
5110 c.setAttribute("_nodup", d);
5114 for(var i = 0, len = cs.length; i < len; i++){
5115 cs[i].removeAttribute("_nodup");
5124 var len = cs.length, c, i, r = cs, cj, ri = -1;
5125 if(!len || typeof cs.nodeType != "undefined" || len == 1){
5128 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
5129 return nodupIEXml(cs);
5133 for(i = 1; c = cs[i]; i++){
5138 for(var j = 0; j < i; j++){
5141 for(j = i+1; cj = cs[j]; j++){
5153 function quickDiffIEXml(c1, c2){
5155 for(var i = 0, len = c1.length; i < len; i++){
5156 c1[i].setAttribute("_qdiff", d);
5159 for(var i = 0, len = c2.length; i < len; i++){
5160 if(c2[i].getAttribute("_qdiff") != d){
5161 r[r.length] = c2[i];
5164 for(var i = 0, len = c1.length; i < len; i++){
5165 c1[i].removeAttribute("_qdiff");
5170 function quickDiff(c1, c2){
5171 var len1 = c1.length;
5175 if(isIE && c1[0].selectSingleNode){
5176 return quickDiffIEXml(c1, c2);
5179 for(var i = 0; i < len1; i++){
5183 for(var i = 0, len = c2.length; i < len; i++){
5184 if(c2[i]._qdiff != d){
5185 r[r.length] = c2[i];
5191 function quickId(ns, mode, root, id){
5193 var d = root.ownerDocument || root;
5194 return d.getElementById(id);
5196 ns = getNodes(ns, mode, "*");
5197 return byId(ns, null, id);
5201 getStyle : function(el, name){
5202 return Roo.fly(el).getStyle(name);
5205 * Compiles a selector/xpath query into a reusable function. The returned function
5206 * takes one parameter "root" (optional), which is the context node from where the query should start.
5207 * @param {String} selector The selector/xpath query
5208 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5209 * @return {Function}
5211 compile : function(path, type){
5212 type = type || "select";
5214 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5215 var q = path, mode, lq;
5216 var tk = Roo.DomQuery.matchers;
5217 var tklen = tk.length;
5220 // accept leading mode switch
5221 var lmode = q.match(modeRe);
5222 if(lmode && lmode[1]){
5223 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5224 q = q.replace(lmode[1], "");
5226 // strip leading slashes
5227 while(path.substr(0, 1)=="/"){
5228 path = path.substr(1);
5231 while(q && lq != q){
5233 var tm = q.match(tagTokenRe);
5234 if(type == "select"){
5237 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5239 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5241 q = q.replace(tm[0], "");
5242 }else if(q.substr(0, 1) != '@'){
5243 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5248 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5250 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5252 q = q.replace(tm[0], "");
5255 while(!(mm = q.match(modeRe))){
5256 var matched = false;
5257 for(var j = 0; j < tklen; j++){
5259 var m = q.match(t.re);
5261 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5264 q = q.replace(m[0], "");
5269 // prevent infinite loop on bad selector
5271 throw 'Error parsing selector, parsing failed at "' + q + '"';
5275 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5276 q = q.replace(mm[1], "");
5279 fn[fn.length] = "return nodup(n);\n}";
5282 * list of variables that need from compression as they are used by eval.
5292 * eval:var:byClassName
5294 * eval:var:byAttribute
5295 * eval:var:attrValue
5303 * Selects a group of elements.
5304 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5305 * @param {Node} root (optional) The start of the query (defaults to document).
5308 select : function(path, root, type){
5309 if(!root || root == document){
5312 if(typeof root == "string"){
5313 root = document.getElementById(root);
5315 var paths = path.split(",");
5317 for(var i = 0, len = paths.length; i < len; i++){
5318 var p = paths[i].replace(trimRe, "");
5320 cache[p] = Roo.DomQuery.compile(p);
5322 throw p + " is not a valid selector";
5325 var result = cache[p](root);
5326 if(result && result != document){
5327 results = results.concat(result);
5330 if(paths.length > 1){
5331 return nodup(results);
5337 * Selects a single element.
5338 * @param {String} selector The selector/xpath query
5339 * @param {Node} root (optional) The start of the query (defaults to document).
5342 selectNode : function(path, root){
5343 return Roo.DomQuery.select(path, root)[0];
5347 * Selects the value of a node, optionally replacing null with the defaultValue.
5348 * @param {String} selector The selector/xpath query
5349 * @param {Node} root (optional) The start of the query (defaults to document).
5350 * @param {String} defaultValue
5352 selectValue : function(path, root, defaultValue){
5353 path = path.replace(trimRe, "");
5354 if(!valueCache[path]){
5355 valueCache[path] = Roo.DomQuery.compile(path, "select");
5357 var n = valueCache[path](root);
5358 n = n[0] ? n[0] : n;
5359 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5360 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5364 * Selects the value of a node, parsing integers and floats.
5365 * @param {String} selector The selector/xpath query
5366 * @param {Node} root (optional) The start of the query (defaults to document).
5367 * @param {Number} defaultValue
5370 selectNumber : function(path, root, defaultValue){
5371 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5372 return parseFloat(v);
5376 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5377 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5378 * @param {String} selector The simple selector to test
5381 is : function(el, ss){
5382 if(typeof el == "string"){
5383 el = document.getElementById(el);
5385 var isArray = (el instanceof Array);
5386 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5387 return isArray ? (result.length == el.length) : (result.length > 0);
5391 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5392 * @param {Array} el An array of elements to filter
5393 * @param {String} selector The simple selector to test
5394 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5395 * the selector instead of the ones that match
5398 filter : function(els, ss, nonMatches){
5399 ss = ss.replace(trimRe, "");
5400 if(!simpleCache[ss]){
5401 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5403 var result = simpleCache[ss](els);
5404 return nonMatches ? quickDiff(result, els) : result;
5408 * Collection of matching regular expressions and code snippets.
5412 select: 'n = byClassName(n, null, " {1} ");'
5414 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5415 select: 'n = byPseudo(n, "{1}", "{2}");'
5417 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5418 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5421 select: 'n = byId(n, null, "{1}");'
5424 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5429 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5430 * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <.
5433 "=" : function(a, v){
5436 "!=" : function(a, v){
5439 "^=" : function(a, v){
5440 return a && a.substr(0, v.length) == v;
5442 "$=" : function(a, v){
5443 return a && a.substr(a.length-v.length) == v;
5445 "*=" : function(a, v){
5446 return a && a.indexOf(v) !== -1;
5448 "%=" : function(a, v){
5449 return (a % v) == 0;
5451 "|=" : function(a, v){
5452 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5454 "~=" : function(a, v){
5455 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5460 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5461 * and the argument (if any) supplied in the selector.
5464 "first-child" : function(c){
5465 var r = [], ri = -1, n;
5466 for(var i = 0, ci; ci = n = c[i]; i++){
5467 while((n = n.previousSibling) && n.nodeType != 1);
5475 "last-child" : function(c){
5476 var r = [], ri = -1, n;
5477 for(var i = 0, ci; ci = n = c[i]; i++){
5478 while((n = n.nextSibling) && n.nodeType != 1);
5486 "nth-child" : function(c, a) {
5487 var r = [], ri = -1;
5488 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5489 var f = (m[1] || 1) - 0, l = m[2] - 0;
5490 for(var i = 0, n; n = c[i]; i++){
5491 var pn = n.parentNode;
5492 if (batch != pn._batch) {
5494 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5495 if(cn.nodeType == 1){
5502 if (l == 0 || n.nodeIndex == l){
5505 } else if ((n.nodeIndex + l) % f == 0){
5513 "only-child" : function(c){
5514 var r = [], ri = -1;;
5515 for(var i = 0, ci; ci = c[i]; i++){
5516 if(!prev(ci) && !next(ci)){
5523 "empty" : function(c){
5524 var r = [], ri = -1;
5525 for(var i = 0, ci; ci = c[i]; i++){
5526 var cns = ci.childNodes, j = 0, cn, empty = true;
5529 if(cn.nodeType == 1 || cn.nodeType == 3){
5541 "contains" : function(c, v){
5542 var r = [], ri = -1;
5543 for(var i = 0, ci; ci = c[i]; i++){
5544 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5551 "nodeValue" : function(c, v){
5552 var r = [], ri = -1;
5553 for(var i = 0, ci; ci = c[i]; i++){
5554 if(ci.firstChild && ci.firstChild.nodeValue == v){
5561 "checked" : function(c){
5562 var r = [], ri = -1;
5563 for(var i = 0, ci; ci = c[i]; i++){
5564 if(ci.checked == true){
5571 "not" : function(c, ss){
5572 return Roo.DomQuery.filter(c, ss, true);
5575 "odd" : function(c){
5576 return this["nth-child"](c, "odd");
5579 "even" : function(c){
5580 return this["nth-child"](c, "even");
5583 "nth" : function(c, a){
5584 return c[a-1] || [];
5587 "first" : function(c){
5591 "last" : function(c){
5592 return c[c.length-1] || [];
5595 "has" : function(c, ss){
5596 var s = Roo.DomQuery.select;
5597 var r = [], ri = -1;
5598 for(var i = 0, ci; ci = c[i]; i++){
5599 if(s(ss, ci).length > 0){
5606 "next" : function(c, ss){
5607 var is = Roo.DomQuery.is;
5608 var r = [], ri = -1;
5609 for(var i = 0, ci; ci = c[i]; i++){
5618 "prev" : function(c, ss){
5619 var is = Roo.DomQuery.is;
5620 var r = [], ri = -1;
5621 for(var i = 0, ci; ci = c[i]; i++){
5634 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5635 * @param {String} path The selector/xpath query
5636 * @param {Node} root (optional) The start of the query (defaults to document).
5641 Roo.query = Roo.DomQuery.select;
5644 * Ext JS Library 1.1.1
5645 * Copyright(c) 2006-2007, Ext JS, LLC.
5647 * Originally Released Under LGPL - original licence link has changed is not relivant.
5650 * <script type="text/javascript">
5654 * @class Roo.util.Observable
5655 * Base class that provides a common interface for publishing events. Subclasses are expected to
5656 * to have a property "events" with all the events defined.<br>
5659 Employee = function(name){
5666 Roo.extend(Employee, Roo.util.Observable);
5668 * @param {Object} config properties to use (incuding events / listeners)
5671 Roo.util.Observable = function(cfg){
5674 this.addEvents(cfg.events || {});
5676 delete cfg.events; // make sure
5679 Roo.apply(this, cfg);
5682 this.on(this.listeners);
5683 delete this.listeners;
5686 Roo.util.Observable.prototype = {
5688 * @cfg {Object} listeners list of events and functions to call for this object,
5692 'click' : function(e) {
5702 * Fires the specified event with the passed parameters (minus the event name).
5703 * @param {String} eventName
5704 * @param {Object...} args Variable number of parameters are passed to handlers
5705 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5707 fireEvent : function(){
5708 var ce = this.events[arguments[0].toLowerCase()];
5709 if(typeof ce == "object"){
5710 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5717 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5720 * Appends an event handler to this component
5721 * @param {String} eventName The type of event to listen for
5722 * @param {Function} handler The method the event invokes
5723 * @param {Object} scope (optional) The scope in which to execute the handler
5724 * function. The handler function's "this" context.
5725 * @param {Object} options (optional) An object containing handler configuration
5726 * properties. This may contain any of the following properties:<ul>
5727 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5728 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5729 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5730 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5731 * by the specified number of milliseconds. If the event fires again within that time, the original
5732 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5735 * <b>Combining Options</b><br>
5736 * Using the options argument, it is possible to combine different types of listeners:<br>
5738 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5740 el.on('click', this.onClick, this, {
5747 * <b>Attaching multiple handlers in 1 call</b><br>
5748 * The method also allows for a single argument to be passed which is a config object containing properties
5749 * which specify multiple handlers.
5758 fn: this.onMouseOver,
5762 fn: this.onMouseOut,
5768 * Or a shorthand syntax which passes the same scope object to all handlers:
5771 'click': this.onClick,
5772 'mouseover': this.onMouseOver,
5773 'mouseout': this.onMouseOut,
5778 addListener : function(eventName, fn, scope, o){
5779 if(typeof eventName == "object"){
5782 if(this.filterOptRe.test(e)){
5785 if(typeof o[e] == "function"){
5787 this.addListener(e, o[e], o.scope, o);
5789 // individual options
5790 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5795 o = (!o || typeof o == "boolean") ? {} : o;
5796 eventName = eventName.toLowerCase();
5797 var ce = this.events[eventName] || true;
5798 if(typeof ce == "boolean"){
5799 ce = new Roo.util.Event(this, eventName);
5800 this.events[eventName] = ce;
5802 ce.addListener(fn, scope, o);
5806 * Removes a listener
5807 * @param {String} eventName The type of event to listen for
5808 * @param {Function} handler The handler to remove
5809 * @param {Object} scope (optional) The scope (this object) for the handler
5811 removeListener : function(eventName, fn, scope){
5812 var ce = this.events[eventName.toLowerCase()];
5813 if(typeof ce == "object"){
5814 ce.removeListener(fn, scope);
5819 * Removes all listeners for this object
5821 purgeListeners : function(){
5822 for(var evt in this.events){
5823 if(typeof this.events[evt] == "object"){
5824 this.events[evt].clearListeners();
5829 relayEvents : function(o, events){
5830 var createHandler = function(ename){
5832 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5835 for(var i = 0, len = events.length; i < len; i++){
5836 var ename = events[i];
5837 if(!this.events[ename]){ this.events[ename] = true; };
5838 o.on(ename, createHandler(ename), this);
5843 * Used to define events on this Observable
5844 * @param {Object} object The object with the events defined
5846 addEvents : function(o){
5850 Roo.applyIf(this.events, o);
5854 * Checks to see if this object has any listeners for a specified event
5855 * @param {String} eventName The name of the event to check for
5856 * @return {Boolean} True if the event is being listened for, else false
5858 hasListener : function(eventName){
5859 var e = this.events[eventName];
5860 return typeof e == "object" && e.listeners.length > 0;
5864 * Appends an event handler to this element (shorthand for addListener)
5865 * @param {String} eventName The type of event to listen for
5866 * @param {Function} handler The method the event invokes
5867 * @param {Object} scope (optional) The scope in which to execute the handler
5868 * function. The handler function's "this" context.
5869 * @param {Object} options (optional)
5872 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5874 * Removes a listener (shorthand for removeListener)
5875 * @param {String} eventName The type of event to listen for
5876 * @param {Function} handler The handler to remove
5877 * @param {Object} scope (optional) The scope (this object) for the handler
5880 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5883 * Starts capture on the specified Observable. All events will be passed
5884 * to the supplied function with the event name + standard signature of the event
5885 * <b>before</b> the event is fired. If the supplied function returns false,
5886 * the event will not fire.
5887 * @param {Observable} o The Observable to capture
5888 * @param {Function} fn The function to call
5889 * @param {Object} scope (optional) The scope (this object) for the fn
5892 Roo.util.Observable.capture = function(o, fn, scope){
5893 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5897 * Removes <b>all</b> added captures from the Observable.
5898 * @param {Observable} o The Observable to release
5901 Roo.util.Observable.releaseCapture = function(o){
5902 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5907 var createBuffered = function(h, o, scope){
5908 var task = new Roo.util.DelayedTask();
5910 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5914 var createSingle = function(h, e, fn, scope){
5916 e.removeListener(fn, scope);
5917 return h.apply(scope, arguments);
5921 var createDelayed = function(h, o, scope){
5923 var args = Array.prototype.slice.call(arguments, 0);
5924 setTimeout(function(){
5925 h.apply(scope, args);
5930 Roo.util.Event = function(obj, name){
5933 this.listeners = [];
5936 Roo.util.Event.prototype = {
5937 addListener : function(fn, scope, options){
5938 var o = options || {};
5939 scope = scope || this.obj;
5940 if(!this.isListening(fn, scope)){
5941 var l = {fn: fn, scope: scope, options: o};
5944 h = createDelayed(h, o, scope);
5947 h = createSingle(h, this, fn, scope);
5950 h = createBuffered(h, o, scope);
5953 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
5954 this.listeners.push(l);
5956 this.listeners = this.listeners.slice(0);
5957 this.listeners.push(l);
5962 findListener : function(fn, scope){
5963 scope = scope || this.obj;
5964 var ls = this.listeners;
5965 for(var i = 0, len = ls.length; i < len; i++){
5967 if(l.fn == fn && l.scope == scope){
5974 isListening : function(fn, scope){
5975 return this.findListener(fn, scope) != -1;
5978 removeListener : function(fn, scope){
5980 if((index = this.findListener(fn, scope)) != -1){
5982 this.listeners.splice(index, 1);
5984 this.listeners = this.listeners.slice(0);
5985 this.listeners.splice(index, 1);
5992 clearListeners : function(){
5993 this.listeners = [];
5997 var ls = this.listeners, scope, len = ls.length;
6000 var args = Array.prototype.slice.call(arguments, 0);
6001 for(var i = 0; i < len; i++){
6003 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
6004 this.firing = false;
6008 this.firing = false;
6015 * Ext JS Library 1.1.1
6016 * Copyright(c) 2006-2007, Ext JS, LLC.
6018 * Originally Released Under LGPL - original licence link has changed is not relivant.
6021 * <script type="text/javascript">
6025 * @class Roo.EventManager
6026 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
6027 * several useful events directly.
6028 * See {@link Roo.EventObject} for more details on normalized event objects.
6031 Roo.EventManager = function(){
6032 var docReadyEvent, docReadyProcId, docReadyState = false;
6033 var resizeEvent, resizeTask, textEvent, textSize;
6034 var E = Roo.lib.Event;
6035 var D = Roo.lib.Dom;
6038 var fireDocReady = function(){
6040 docReadyState = true;
6043 clearInterval(docReadyProcId);
6045 if(Roo.isGecko || Roo.isOpera) {
6046 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
6049 var defer = document.getElementById("ie-deferred-loader");
6051 defer.onreadystatechange = null;
6052 defer.parentNode.removeChild(defer);
6056 docReadyEvent.fire();
6057 docReadyEvent.clearListeners();
6062 var initDocReady = function(){
6063 docReadyEvent = new Roo.util.Event();
6064 if(Roo.isGecko || Roo.isOpera) {
6065 document.addEventListener("DOMContentLoaded", fireDocReady, false);
6067 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
6068 var defer = document.getElementById("ie-deferred-loader");
6069 defer.onreadystatechange = function(){
6070 if(this.readyState == "complete"){
6074 }else if(Roo.isSafari){
6075 docReadyProcId = setInterval(function(){
6076 var rs = document.readyState;
6077 if(rs == "complete") {
6082 // no matter what, make sure it fires on load
6083 E.on(window, "load", fireDocReady);
6086 var createBuffered = function(h, o){
6087 var task = new Roo.util.DelayedTask(h);
6089 // create new event object impl so new events don't wipe out properties
6090 e = new Roo.EventObjectImpl(e);
6091 task.delay(o.buffer, h, null, [e]);
6095 var createSingle = function(h, el, ename, fn){
6097 Roo.EventManager.removeListener(el, ename, fn);
6102 var createDelayed = function(h, o){
6104 // create new event object impl so new events don't wipe out properties
6105 e = new Roo.EventObjectImpl(e);
6106 setTimeout(function(){
6112 var listen = function(element, ename, opt, fn, scope){
6113 var o = (!opt || typeof opt == "boolean") ? {} : opt;
6114 fn = fn || o.fn; scope = scope || o.scope;
6115 var el = Roo.getDom(element);
6117 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
6119 var h = function(e){
6120 e = Roo.EventObject.setEvent(e);
6123 t = e.getTarget(o.delegate, el);
6130 if(o.stopEvent === true){
6133 if(o.preventDefault === true){
6136 if(o.stopPropagation === true){
6137 e.stopPropagation();
6140 if(o.normalized === false){
6144 fn.call(scope || el, e, t, o);
6147 h = createDelayed(h, o);
6150 h = createSingle(h, el, ename, fn);
6153 h = createBuffered(h, o);
6155 fn._handlers = fn._handlers || [];
6156 fn._handlers.push([Roo.id(el), ename, h]);
6159 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
6160 el.addEventListener("DOMMouseScroll", h, false);
6161 E.on(window, 'unload', function(){
6162 el.removeEventListener("DOMMouseScroll", h, false);
6165 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6166 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
6171 var stopListening = function(el, ename, fn){
6172 var id = Roo.id(el), hds = fn._handlers, hd = fn;
6174 for(var i = 0, len = hds.length; i < len; i++){
6176 if(h[0] == id && h[1] == ename){
6183 E.un(el, ename, hd);
6184 el = Roo.getDom(el);
6185 if(ename == "mousewheel" && el.addEventListener){
6186 el.removeEventListener("DOMMouseScroll", hd, false);
6188 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6189 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6193 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6200 * @scope Roo.EventManager
6205 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6206 * object with a Roo.EventObject
6207 * @param {Function} fn The method the event invokes
6208 * @param {Object} scope An object that becomes the scope of the handler
6209 * @param {boolean} override If true, the obj passed in becomes
6210 * the execution scope of the listener
6211 * @return {Function} The wrapped function
6214 wrap : function(fn, scope, override){
6216 Roo.EventObject.setEvent(e);
6217 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6222 * Appends an event handler to an element (shorthand for addListener)
6223 * @param {String/HTMLElement} element The html element or id to assign the
6224 * @param {String} eventName The type of event to listen for
6225 * @param {Function} handler The method the event invokes
6226 * @param {Object} scope (optional) The scope in which to execute the handler
6227 * function. The handler function's "this" context.
6228 * @param {Object} options (optional) An object containing handler configuration
6229 * properties. This may contain any of the following properties:<ul>
6230 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6231 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6232 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6233 * <li>preventDefault {Boolean} True to prevent the default action</li>
6234 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6235 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6236 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6237 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6238 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6239 * by the specified number of milliseconds. If the event fires again within that time, the original
6240 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6243 * <b>Combining Options</b><br>
6244 * Using the options argument, it is possible to combine different types of listeners:<br>
6246 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6248 el.on('click', this.onClick, this, {
6255 * <b>Attaching multiple handlers in 1 call</b><br>
6256 * The method also allows for a single argument to be passed which is a config object containing properties
6257 * which specify multiple handlers.
6267 fn: this.onMouseOver
6276 * Or a shorthand syntax:<br>
6279 'click' : this.onClick,
6280 'mouseover' : this.onMouseOver,
6281 'mouseout' : this.onMouseOut
6285 addListener : function(element, eventName, fn, scope, options){
6286 if(typeof eventName == "object"){
6292 if(typeof o[e] == "function"){
6294 listen(element, e, o, o[e], o.scope);
6296 // individual options
6297 listen(element, e, o[e]);
6302 return listen(element, eventName, options, fn, scope);
6306 * Removes an event handler
6308 * @param {String/HTMLElement} element The id or html element to remove the
6310 * @param {String} eventName The type of event
6311 * @param {Function} fn
6312 * @return {Boolean} True if a listener was actually removed
6314 removeListener : function(element, eventName, fn){
6315 return stopListening(element, eventName, fn);
6319 * Fires when the document is ready (before onload and before images are loaded). Can be
6320 * accessed shorthanded Roo.onReady().
6321 * @param {Function} fn The method the event invokes
6322 * @param {Object} scope An object that becomes the scope of the handler
6323 * @param {boolean} options
6325 onDocumentReady : function(fn, scope, options){
6326 if(docReadyState){ // if it already fired
6327 docReadyEvent.addListener(fn, scope, options);
6328 docReadyEvent.fire();
6329 docReadyEvent.clearListeners();
6335 docReadyEvent.addListener(fn, scope, options);
6339 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6340 * @param {Function} fn The method the event invokes
6341 * @param {Object} scope An object that becomes the scope of the handler
6342 * @param {boolean} options
6344 onWindowResize : function(fn, scope, options){
6346 resizeEvent = new Roo.util.Event();
6347 resizeTask = new Roo.util.DelayedTask(function(){
6348 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6350 E.on(window, "resize", function(){
6352 resizeTask.delay(50);
6354 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6358 resizeEvent.addListener(fn, scope, options);
6362 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6363 * @param {Function} fn The method the event invokes
6364 * @param {Object} scope An object that becomes the scope of the handler
6365 * @param {boolean} options
6367 onTextResize : function(fn, scope, options){
6369 textEvent = new Roo.util.Event();
6370 var textEl = new Roo.Element(document.createElement('div'));
6371 textEl.dom.className = 'x-text-resize';
6372 textEl.dom.innerHTML = 'X';
6373 textEl.appendTo(document.body);
6374 textSize = textEl.dom.offsetHeight;
6375 setInterval(function(){
6376 if(textEl.dom.offsetHeight != textSize){
6377 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6379 }, this.textResizeInterval);
6381 textEvent.addListener(fn, scope, options);
6385 * Removes the passed window resize listener.
6386 * @param {Function} fn The method the event invokes
6387 * @param {Object} scope The scope of handler
6389 removeResizeListener : function(fn, scope){
6391 resizeEvent.removeListener(fn, scope);
6396 fireResize : function(){
6398 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6402 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6406 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6408 textResizeInterval : 50
6413 * @scopeAlias pub=Roo.EventManager
6417 * Appends an event handler to an element (shorthand for addListener)
6418 * @param {String/HTMLElement} element The html element or id to assign the
6419 * @param {String} eventName The type of event to listen for
6420 * @param {Function} handler The method the event invokes
6421 * @param {Object} scope (optional) The scope in which to execute the handler
6422 * function. The handler function's "this" context.
6423 * @param {Object} options (optional) An object containing handler configuration
6424 * properties. This may contain any of the following properties:<ul>
6425 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6426 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6427 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6428 * <li>preventDefault {Boolean} True to prevent the default action</li>
6429 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6430 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6431 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6432 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6433 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6434 * by the specified number of milliseconds. If the event fires again within that time, the original
6435 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6438 * <b>Combining Options</b><br>
6439 * Using the options argument, it is possible to combine different types of listeners:<br>
6441 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6443 el.on('click', this.onClick, this, {
6450 * <b>Attaching multiple handlers in 1 call</b><br>
6451 * The method also allows for a single argument to be passed which is a config object containing properties
6452 * which specify multiple handlers.
6462 fn: this.onMouseOver
6471 * Or a shorthand syntax:<br>
6474 'click' : this.onClick,
6475 'mouseover' : this.onMouseOver,
6476 'mouseout' : this.onMouseOut
6480 pub.on = pub.addListener;
6481 pub.un = pub.removeListener;
6483 pub.stoppedMouseDownEvent = new Roo.util.Event();
6487 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6488 * @param {Function} fn The method the event invokes
6489 * @param {Object} scope An object that becomes the scope of the handler
6490 * @param {boolean} override If true, the obj passed in becomes
6491 * the execution scope of the listener
6495 Roo.onReady = Roo.EventManager.onDocumentReady;
6497 Roo.onReady(function(){
6498 var bd = Roo.get(document.body);
6503 : Roo.isGecko ? "roo-gecko"
6504 : Roo.isOpera ? "roo-opera"
6505 : Roo.isSafari ? "roo-safari" : ""];
6508 cls.push("roo-mac");
6511 cls.push("roo-linux");
6513 if(Roo.isBorderBox){
6514 cls.push('roo-border-box');
6516 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6517 var p = bd.dom.parentNode;
6519 p.className += ' roo-strict';
6522 bd.addClass(cls.join(' '));
6526 * @class Roo.EventObject
6527 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6528 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6531 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6533 var target = e.getTarget();
6536 var myDiv = Roo.get("myDiv");
6537 myDiv.on("click", handleClick);
6539 Roo.EventManager.on("myDiv", 'click', handleClick);
6540 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6544 Roo.EventObject = function(){
6546 var E = Roo.lib.Event;
6548 // safari keypress events for special keys return bad keycodes
6551 63235 : 39, // right
6554 63276 : 33, // page up
6555 63277 : 34, // page down
6556 63272 : 46, // delete
6561 // normalize button clicks
6562 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6563 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6565 Roo.EventObjectImpl = function(e){
6567 this.setEvent(e.browserEvent || e);
6570 Roo.EventObjectImpl.prototype = {
6572 * Used to fix doc tools.
6573 * @scope Roo.EventObject.prototype
6579 /** The normal browser event */
6580 browserEvent : null,
6581 /** The button pressed in a mouse event */
6583 /** True if the shift key was down during the event */
6585 /** True if the control key was down during the event */
6587 /** True if the alt key was down during the event */
6646 setEvent : function(e){
6647 if(e == this || (e && e.browserEvent)){ // already wrapped
6650 this.browserEvent = e;
6652 // normalize buttons
6653 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6654 if(e.type == 'click' && this.button == -1){
6658 this.shiftKey = e.shiftKey;
6659 // mac metaKey behaves like ctrlKey
6660 this.ctrlKey = e.ctrlKey || e.metaKey;
6661 this.altKey = e.altKey;
6662 // in getKey these will be normalized for the mac
6663 this.keyCode = e.keyCode;
6664 // keyup warnings on firefox.
6665 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6666 // cache the target for the delayed and or buffered events
6667 this.target = E.getTarget(e);
6669 this.xy = E.getXY(e);
6672 this.shiftKey = false;
6673 this.ctrlKey = false;
6674 this.altKey = false;
6684 * Stop the event (preventDefault and stopPropagation)
6686 stopEvent : function(){
6687 if(this.browserEvent){
6688 if(this.browserEvent.type == 'mousedown'){
6689 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6691 E.stopEvent(this.browserEvent);
6696 * Prevents the browsers default handling of the event.
6698 preventDefault : function(){
6699 if(this.browserEvent){
6700 E.preventDefault(this.browserEvent);
6705 isNavKeyPress : function(){
6706 var k = this.keyCode;
6707 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6708 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6711 isSpecialKey : function(){
6712 var k = this.keyCode;
6713 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6714 (k == 16) || (k == 17) ||
6715 (k >= 18 && k <= 20) ||
6716 (k >= 33 && k <= 35) ||
6717 (k >= 36 && k <= 39) ||
6718 (k >= 44 && k <= 45);
6721 * Cancels bubbling of the event.
6723 stopPropagation : function(){
6724 if(this.browserEvent){
6725 if(this.type == 'mousedown'){
6726 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6728 E.stopPropagation(this.browserEvent);
6733 * Gets the key code for the event.
6736 getCharCode : function(){
6737 return this.charCode || this.keyCode;
6741 * Returns a normalized keyCode for the event.
6742 * @return {Number} The key code
6744 getKey : function(){
6745 var k = this.keyCode || this.charCode;
6746 return Roo.isSafari ? (safariKeys[k] || k) : k;
6750 * Gets the x coordinate of the event.
6753 getPageX : function(){
6758 * Gets the y coordinate of the event.
6761 getPageY : function(){
6766 * Gets the time of the event.
6769 getTime : function(){
6770 if(this.browserEvent){
6771 return E.getTime(this.browserEvent);
6777 * Gets the page coordinates of the event.
6778 * @return {Array} The xy values like [x, y]
6785 * Gets the target for the event.
6786 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6787 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6788 search as a number or element (defaults to 10 || document.body)
6789 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6790 * @return {HTMLelement}
6792 getTarget : function(selector, maxDepth, returnEl){
6793 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6796 * Gets the related target.
6797 * @return {HTMLElement}
6799 getRelatedTarget : function(){
6800 if(this.browserEvent){
6801 return E.getRelatedTarget(this.browserEvent);
6807 * Normalizes mouse wheel delta across browsers
6808 * @return {Number} The delta
6810 getWheelDelta : function(){
6811 var e = this.browserEvent;
6813 if(e.wheelDelta){ /* IE/Opera. */
6814 delta = e.wheelDelta/120;
6815 }else if(e.detail){ /* Mozilla case. */
6816 delta = -e.detail/3;
6822 * Returns true if the control, meta, shift or alt key was pressed during this event.
6825 hasModifier : function(){
6826 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6830 * Returns true if the target of this event equals el or is a child of el
6831 * @param {String/HTMLElement/Element} el
6832 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6835 within : function(el, related){
6836 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6837 return t && Roo.fly(el).contains(t);
6840 getPoint : function(){
6841 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6845 return new Roo.EventObjectImpl();
6850 * Ext JS Library 1.1.1
6851 * Copyright(c) 2006-2007, Ext JS, LLC.
6853 * Originally Released Under LGPL - original licence link has changed is not relivant.
6856 * <script type="text/javascript">
6860 // was in Composite Element!??!?!
6863 var D = Roo.lib.Dom;
6864 var E = Roo.lib.Event;
6865 var A = Roo.lib.Anim;
6867 // local style camelizing for speed
6869 var camelRe = /(-[a-z])/gi;
6870 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
6871 var view = document.defaultView;
6874 * @class Roo.Element
6875 * Represents an Element in the DOM.<br><br>
6878 var el = Roo.get("my-div");
6881 var el = getEl("my-div");
6883 // or with a DOM element
6884 var el = Roo.get(myDivElement);
6886 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
6887 * each call instead of constructing a new one.<br><br>
6888 * <b>Animations</b><br />
6889 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
6890 * should either be a boolean (true) or an object literal with animation options. The animation options are:
6892 Option Default Description
6893 --------- -------- ---------------------------------------------
6894 duration .35 The duration of the animation in seconds
6895 easing easeOut The YUI easing method
6896 callback none A function to execute when the anim completes
6897 scope this The scope (this) of the callback function
6899 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
6900 * manipulate the animation. Here's an example:
6902 var el = Roo.get("my-div");
6907 // default animation
6908 el.setWidth(100, true);
6910 // animation with some options set
6917 // using the "anim" property to get the Anim object
6923 el.setWidth(100, opt);
6925 if(opt.anim.isAnimated()){
6929 * <b> Composite (Collections of) Elements</b><br />
6930 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
6931 * @constructor Create a new Element directly.
6932 * @param {String/HTMLElement} element
6933 * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
6935 Roo.Element = function(element, forceNew){
6936 var dom = typeof element == "string" ?
6937 document.getElementById(element) : element;
6938 if(!dom){ // invalid id/element
6942 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
6943 return Roo.Element.cache[id];
6953 * The DOM element ID
6956 this.id = id || Roo.id(dom);
6959 var El = Roo.Element;
6963 * The element's default display mode (defaults to "")
6966 originalDisplay : "",
6970 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
6975 * Sets the element's visibility mode. When setVisible() is called it
6976 * will use this to determine whether to set the visibility or the display property.
6977 * @param visMode Element.VISIBILITY or Element.DISPLAY
6978 * @return {Roo.Element} this
6980 setVisibilityMode : function(visMode){
6981 this.visibilityMode = visMode;
6985 * Convenience method for setVisibilityMode(Element.DISPLAY)
6986 * @param {String} display (optional) What to set display to when visible
6987 * @return {Roo.Element} this
6989 enableDisplayMode : function(display){
6990 this.setVisibilityMode(El.DISPLAY);
6991 if(typeof display != "undefined") this.originalDisplay = display;
6996 * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
6997 * @param {String} selector The simple selector to test
6998 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6999 search as a number or element (defaults to 10 || document.body)
7000 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7001 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7003 findParent : function(simpleSelector, maxDepth, returnEl){
7004 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
7005 maxDepth = maxDepth || 50;
7006 if(typeof maxDepth != "number"){
7007 stopEl = Roo.getDom(maxDepth);
7010 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
7011 if(dq.is(p, simpleSelector)){
7012 return returnEl ? Roo.get(p) : p;
7022 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
7023 * @param {String} selector The simple selector to test
7024 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7025 search as a number or element (defaults to 10 || document.body)
7026 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7027 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7029 findParentNode : function(simpleSelector, maxDepth, returnEl){
7030 var p = Roo.fly(this.dom.parentNode, '_internal');
7031 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
7035 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
7036 * This is a shortcut for findParentNode() that always returns an Roo.Element.
7037 * @param {String} selector The simple selector to test
7038 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7039 search as a number or element (defaults to 10 || document.body)
7040 * @return {Roo.Element} The matching DOM node (or null if no match was found)
7042 up : function(simpleSelector, maxDepth){
7043 return this.findParentNode(simpleSelector, maxDepth, true);
7049 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
7050 * @param {String} selector The simple selector to test
7051 * @return {Boolean} True if this element matches the selector, else false
7053 is : function(simpleSelector){
7054 return Roo.DomQuery.is(this.dom, simpleSelector);
7058 * Perform animation on this element.
7059 * @param {Object} args The YUI animation control args
7060 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
7061 * @param {Function} onComplete (optional) Function to call when animation completes
7062 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
7063 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
7064 * @return {Roo.Element} this
7066 animate : function(args, duration, onComplete, easing, animType){
7067 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
7072 * @private Internal animation call
7074 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
7075 animType = animType || 'run';
7077 var anim = Roo.lib.Anim[animType](
7079 (opt.duration || defaultDur) || .35,
7080 (opt.easing || defaultEase) || 'easeOut',
7082 Roo.callback(cb, this);
7083 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
7091 // private legacy anim prep
7092 preanim : function(a, i){
7093 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
7097 * Removes worthless text nodes
7098 * @param {Boolean} forceReclean (optional) By default the element
7099 * keeps track if it has been cleaned already so
7100 * you can call this over and over. However, if you update the element and
7101 * need to force a reclean, you can pass true.
7103 clean : function(forceReclean){
7104 if(this.isCleaned && forceReclean !== true){
7108 var d = this.dom, n = d.firstChild, ni = -1;
7110 var nx = n.nextSibling;
7111 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
7118 this.isCleaned = true;
7123 calcOffsetsTo : function(el){
7126 var restorePos = false;
7127 if(el.getStyle('position') == 'static'){
7128 el.position('relative');
7133 while(op && op != d && op.tagName != 'HTML'){
7136 op = op.offsetParent;
7139 el.position('static');
7145 * Scrolls this element into view within the passed container.
7146 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
7147 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
7148 * @return {Roo.Element} this
7150 scrollIntoView : function(container, hscroll){
7151 var c = Roo.getDom(container) || document.body;
7154 var o = this.calcOffsetsTo(c),
7157 b = t+el.offsetHeight,
7158 r = l+el.offsetWidth;
7160 var ch = c.clientHeight;
7161 var ct = parseInt(c.scrollTop, 10);
7162 var cl = parseInt(c.scrollLeft, 10);
7164 var cr = cl + c.clientWidth;
7172 if(hscroll !== false){
7176 c.scrollLeft = r-c.clientWidth;
7183 scrollChildIntoView : function(child, hscroll){
7184 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7188 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7189 * the new height may not be available immediately.
7190 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7191 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7192 * @param {Function} onComplete (optional) Function to call when animation completes
7193 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7194 * @return {Roo.Element} this
7196 autoHeight : function(animate, duration, onComplete, easing){
7197 var oldHeight = this.getHeight();
7199 this.setHeight(1); // force clipping
7200 setTimeout(function(){
7201 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7203 this.setHeight(height);
7205 if(typeof onComplete == "function"){
7209 this.setHeight(oldHeight); // restore original height
7210 this.setHeight(height, animate, duration, function(){
7212 if(typeof onComplete == "function") onComplete();
7213 }.createDelegate(this), easing);
7215 }.createDelegate(this), 0);
7220 * Returns true if this element is an ancestor of the passed element
7221 * @param {HTMLElement/String} el The element to check
7222 * @return {Boolean} True if this element is an ancestor of el, else false
7224 contains : function(el){
7225 if(!el){return false;}
7226 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7230 * Checks whether the element is currently visible using both visibility and display properties.
7231 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7232 * @return {Boolean} True if the element is currently visible, else false
7234 isVisible : function(deep) {
7235 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7236 if(deep !== true || !vis){
7239 var p = this.dom.parentNode;
7240 while(p && p.tagName.toLowerCase() != "body"){
7241 if(!Roo.fly(p, '_isVisible').isVisible()){
7250 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7251 * @param {String} selector The CSS selector
7252 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7253 * @return {CompositeElement/CompositeElementLite} The composite element
7255 select : function(selector, unique){
7256 return El.select(selector, unique, this.dom);
7260 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7261 * @param {String} selector The CSS selector
7262 * @return {Array} An array of the matched nodes
7264 query : function(selector, unique){
7265 return Roo.DomQuery.select(selector, this.dom);
7269 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7270 * @param {String} selector The CSS selector
7271 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7272 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7274 child : function(selector, returnDom){
7275 var n = Roo.DomQuery.selectNode(selector, this.dom);
7276 return returnDom ? n : Roo.get(n);
7280 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7281 * @param {String} selector The CSS selector
7282 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7283 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7285 down : function(selector, returnDom){
7286 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7287 return returnDom ? n : Roo.get(n);
7291 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7292 * @param {String} group The group the DD object is member of
7293 * @param {Object} config The DD config object
7294 * @param {Object} overrides An object containing methods to override/implement on the DD object
7295 * @return {Roo.dd.DD} The DD object
7297 initDD : function(group, config, overrides){
7298 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7299 return Roo.apply(dd, overrides);
7303 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7304 * @param {String} group The group the DDProxy object is member of
7305 * @param {Object} config The DDProxy config object
7306 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7307 * @return {Roo.dd.DDProxy} The DDProxy object
7309 initDDProxy : function(group, config, overrides){
7310 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7311 return Roo.apply(dd, overrides);
7315 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7316 * @param {String} group The group the DDTarget object is member of
7317 * @param {Object} config The DDTarget config object
7318 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7319 * @return {Roo.dd.DDTarget} The DDTarget object
7321 initDDTarget : function(group, config, overrides){
7322 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7323 return Roo.apply(dd, overrides);
7327 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7328 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7329 * @param {Boolean} visible Whether the element is visible
7330 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7331 * @return {Roo.Element} this
7333 setVisible : function(visible, animate){
7335 if(this.visibilityMode == El.DISPLAY){
7336 this.setDisplayed(visible);
7339 this.dom.style.visibility = visible ? "visible" : "hidden";
7342 // closure for composites
7344 var visMode = this.visibilityMode;
7346 this.setOpacity(.01);
7347 this.setVisible(true);
7349 this.anim({opacity: { to: (visible?1:0) }},
7350 this.preanim(arguments, 1),
7351 null, .35, 'easeIn', function(){
7353 if(visMode == El.DISPLAY){
7354 dom.style.display = "none";
7356 dom.style.visibility = "hidden";
7358 Roo.get(dom).setOpacity(1);
7366 * Returns true if display is not "none"
7369 isDisplayed : function() {
7370 return this.getStyle("display") != "none";
7374 * Toggles the element's visibility or display, depending on visibility mode.
7375 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7376 * @return {Roo.Element} this
7378 toggle : function(animate){
7379 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7384 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7385 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7386 * @return {Roo.Element} this
7388 setDisplayed : function(value) {
7389 if(typeof value == "boolean"){
7390 value = value ? this.originalDisplay : "none";
7392 this.setStyle("display", value);
7397 * Tries to focus the element. Any exceptions are caught and ignored.
7398 * @return {Roo.Element} this
7400 focus : function() {
7408 * Tries to blur the element. Any exceptions are caught and ignored.
7409 * @return {Roo.Element} this
7419 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7420 * @param {String/Array} className The CSS class to add, or an array of classes
7421 * @return {Roo.Element} this
7423 addClass : function(className){
7424 if(className instanceof Array){
7425 for(var i = 0, len = className.length; i < len; i++) {
7426 this.addClass(className[i]);
7429 if(className && !this.hasClass(className)){
7430 this.dom.className = this.dom.className + " " + className;
7437 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7438 * @param {String/Array} className The CSS class to add, or an array of classes
7439 * @return {Roo.Element} this
7441 radioClass : function(className){
7442 var siblings = this.dom.parentNode.childNodes;
7443 for(var i = 0; i < siblings.length; i++) {
7444 var s = siblings[i];
7445 if(s.nodeType == 1){
7446 Roo.get(s).removeClass(className);
7449 this.addClass(className);
7454 * Removes one or more CSS classes from the element.
7455 * @param {String/Array} className The CSS class to remove, or an array of classes
7456 * @return {Roo.Element} this
7458 removeClass : function(className){
7459 if(!className || !this.dom.className){
7462 if(className instanceof Array){
7463 for(var i = 0, len = className.length; i < len; i++) {
7464 this.removeClass(className[i]);
7467 if(this.hasClass(className)){
7468 var re = this.classReCache[className];
7470 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7471 this.classReCache[className] = re;
7473 this.dom.className =
7474 this.dom.className.replace(re, " ");
7484 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7485 * @param {String} className The CSS class to toggle
7486 * @return {Roo.Element} this
7488 toggleClass : function(className){
7489 if(this.hasClass(className)){
7490 this.removeClass(className);
7492 this.addClass(className);
7498 * Checks if the specified CSS class exists on this element's DOM node.
7499 * @param {String} className The CSS class to check for
7500 * @return {Boolean} True if the class exists, else false
7502 hasClass : function(className){
7503 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7507 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7508 * @param {String} oldClassName The CSS class to replace
7509 * @param {String} newClassName The replacement CSS class
7510 * @return {Roo.Element} this
7512 replaceClass : function(oldClassName, newClassName){
7513 this.removeClass(oldClassName);
7514 this.addClass(newClassName);
7519 * Returns an object with properties matching the styles requested.
7520 * For example, el.getStyles('color', 'font-size', 'width') might return
7521 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7522 * @param {String} style1 A style name
7523 * @param {String} style2 A style name
7524 * @param {String} etc.
7525 * @return {Object} The style object
7527 getStyles : function(){
7528 var a = arguments, len = a.length, r = {};
7529 for(var i = 0; i < len; i++){
7530 r[a[i]] = this.getStyle(a[i]);
7536 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7537 * @param {String} property The style property whose value is returned.
7538 * @return {String} The current value of the style property for this element.
7540 getStyle : function(){
7541 return view && view.getComputedStyle ?
7543 var el = this.dom, v, cs, camel;
7544 if(prop == 'float'){
7547 if(el.style && (v = el.style[prop])){
7550 if(cs = view.getComputedStyle(el, "")){
7551 if(!(camel = propCache[prop])){
7552 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7559 var el = this.dom, v, cs, camel;
7560 if(prop == 'opacity'){
7561 if(typeof el.style.filter == 'string'){
7562 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7564 var fv = parseFloat(m[1]);
7566 return fv ? fv / 100 : 0;
7571 }else if(prop == 'float'){
7572 prop = "styleFloat";
7574 if(!(camel = propCache[prop])){
7575 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7577 if(v = el.style[camel]){
7580 if(cs = el.currentStyle){
7588 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7589 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7590 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7591 * @return {Roo.Element} this
7593 setStyle : function(prop, value){
7594 if(typeof prop == "string"){
7596 if (prop == 'float') {
7597 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7602 if(!(camel = propCache[prop])){
7603 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7606 if(camel == 'opacity') {
7607 this.setOpacity(value);
7609 this.dom.style[camel] = value;
7612 for(var style in prop){
7613 if(typeof prop[style] != "function"){
7614 this.setStyle(style, prop[style]);
7622 * More flexible version of {@link #setStyle} for setting style properties.
7623 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7624 * a function which returns such a specification.
7625 * @return {Roo.Element} this
7627 applyStyles : function(style){
7628 Roo.DomHelper.applyStyles(this.dom, style);
7633 * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7634 * @return {Number} The X position of the element
7637 return D.getX(this.dom);
7641 * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7642 * @return {Number} The Y position of the element
7645 return D.getY(this.dom);
7649 * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7650 * @return {Array} The XY position of the element
7653 return D.getXY(this.dom);
7657 * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7658 * @param {Number} The X position of the element
7659 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7660 * @return {Roo.Element} this
7662 setX : function(x, animate){
7664 D.setX(this.dom, x);
7666 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7672 * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7673 * @param {Number} The Y position of the element
7674 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7675 * @return {Roo.Element} this
7677 setY : function(y, animate){
7679 D.setY(this.dom, y);
7681 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7687 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7688 * @param {String} left The left CSS property value
7689 * @return {Roo.Element} this
7691 setLeft : function(left){
7692 this.setStyle("left", this.addUnits(left));
7697 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7698 * @param {String} top The top CSS property value
7699 * @return {Roo.Element} this
7701 setTop : function(top){
7702 this.setStyle("top", this.addUnits(top));
7707 * Sets the element's CSS right style.
7708 * @param {String} right The right CSS property value
7709 * @return {Roo.Element} this
7711 setRight : function(right){
7712 this.setStyle("right", this.addUnits(right));
7717 * Sets the element's CSS bottom style.
7718 * @param {String} bottom The bottom CSS property value
7719 * @return {Roo.Element} this
7721 setBottom : function(bottom){
7722 this.setStyle("bottom", this.addUnits(bottom));
7727 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7728 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7729 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7730 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7731 * @return {Roo.Element} this
7733 setXY : function(pos, animate){
7735 D.setXY(this.dom, pos);
7737 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7743 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7744 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7745 * @param {Number} x X value for new position (coordinates are page-based)
7746 * @param {Number} y Y value for new position (coordinates are page-based)
7747 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7748 * @return {Roo.Element} this
7750 setLocation : function(x, y, animate){
7751 this.setXY([x, y], this.preanim(arguments, 2));
7756 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7757 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7758 * @param {Number} x X value for new position (coordinates are page-based)
7759 * @param {Number} y Y value for new position (coordinates are page-based)
7760 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7761 * @return {Roo.Element} this
7763 moveTo : function(x, y, animate){
7764 this.setXY([x, y], this.preanim(arguments, 2));
7769 * Returns the region of the given element.
7770 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7771 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7773 getRegion : function(){
7774 return D.getRegion(this.dom);
7778 * Returns the offset height of the element
7779 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7780 * @return {Number} The element's height
7782 getHeight : function(contentHeight){
7783 var h = this.dom.offsetHeight || 0;
7784 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7788 * Returns the offset width of the element
7789 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7790 * @return {Number} The element's width
7792 getWidth : function(contentWidth){
7793 var w = this.dom.offsetWidth || 0;
7794 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7798 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7799 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7800 * if a height has not been set using CSS.
7803 getComputedHeight : function(){
7804 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7806 h = parseInt(this.getStyle('height'), 10) || 0;
7807 if(!this.isBorderBox()){
7808 h += this.getFrameWidth('tb');
7815 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7816 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7817 * if a width has not been set using CSS.
7820 getComputedWidth : function(){
7821 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7823 w = parseInt(this.getStyle('width'), 10) || 0;
7824 if(!this.isBorderBox()){
7825 w += this.getFrameWidth('lr');
7832 * Returns the size of the element.
7833 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
7834 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
7836 getSize : function(contentSize){
7837 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
7841 * Returns the width and height of the viewport.
7842 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
7844 getViewSize : function(){
7845 var d = this.dom, doc = document, aw = 0, ah = 0;
7846 if(d == doc || d == doc.body){
7847 return {width : D.getViewWidth(), height: D.getViewHeight()};
7850 width : d.clientWidth,
7851 height: d.clientHeight
7857 * Returns the value of the "value" attribute
7858 * @param {Boolean} asNumber true to parse the value as a number
7859 * @return {String/Number}
7861 getValue : function(asNumber){
7862 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
7866 adjustWidth : function(width){
7867 if(typeof width == "number"){
7868 if(this.autoBoxAdjust && !this.isBorderBox()){
7869 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7879 adjustHeight : function(height){
7880 if(typeof height == "number"){
7881 if(this.autoBoxAdjust && !this.isBorderBox()){
7882 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7892 * Set the width of the element
7893 * @param {Number} width The new width
7894 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7895 * @return {Roo.Element} this
7897 setWidth : function(width, animate){
7898 width = this.adjustWidth(width);
7900 this.dom.style.width = this.addUnits(width);
7902 this.anim({width: {to: width}}, this.preanim(arguments, 1));
7908 * Set the height of the element
7909 * @param {Number} height The new height
7910 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7911 * @return {Roo.Element} this
7913 setHeight : function(height, animate){
7914 height = this.adjustHeight(height);
7916 this.dom.style.height = this.addUnits(height);
7918 this.anim({height: {to: height}}, this.preanim(arguments, 1));
7924 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
7925 * @param {Number} width The new width
7926 * @param {Number} height The new height
7927 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7928 * @return {Roo.Element} this
7930 setSize : function(width, height, animate){
7931 if(typeof width == "object"){ // in case of object from getSize()
7932 height = width.height; width = width.width;
7934 width = this.adjustWidth(width); height = this.adjustHeight(height);
7936 this.dom.style.width = this.addUnits(width);
7937 this.dom.style.height = this.addUnits(height);
7939 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
7945 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
7946 * @param {Number} x X value for new position (coordinates are page-based)
7947 * @param {Number} y Y value for new position (coordinates are page-based)
7948 * @param {Number} width The new width
7949 * @param {Number} height The new height
7950 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7951 * @return {Roo.Element} this
7953 setBounds : function(x, y, width, height, animate){
7955 this.setSize(width, height);
7956 this.setLocation(x, y);
7958 width = this.adjustWidth(width); height = this.adjustHeight(height);
7959 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
7960 this.preanim(arguments, 4), 'motion');
7966 * Sets the element's position and size the the specified region. If animation is true then width, height, x and y will be animated concurrently.
7967 * @param {Roo.lib.Region} region The region to fill
7968 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7969 * @return {Roo.Element} this
7971 setRegion : function(region, animate){
7972 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
7977 * Appends an event handler
7979 * @param {String} eventName The type of event to append
7980 * @param {Function} fn The method the event invokes
7981 * @param {Object} scope (optional) The scope (this object) of the fn
7982 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
7984 addListener : function(eventName, fn, scope, options){
7986 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
7991 * Removes an event handler from this element
7992 * @param {String} eventName the type of event to remove
7993 * @param {Function} fn the method the event invokes
7994 * @return {Roo.Element} this
7996 removeListener : function(eventName, fn){
7997 Roo.EventManager.removeListener(this.dom, eventName, fn);
8002 * Removes all previous added listeners from this element
8003 * @return {Roo.Element} this
8005 removeAllListeners : function(){
8006 E.purgeElement(this.dom);
8010 relayEvent : function(eventName, observable){
8011 this.on(eventName, function(e){
8012 observable.fireEvent(eventName, e);
8017 * Set the opacity of the element
8018 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
8019 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8020 * @return {Roo.Element} this
8022 setOpacity : function(opacity, animate){
8024 var s = this.dom.style;
8027 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
8028 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
8030 s.opacity = opacity;
8033 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
8039 * Gets the left X coordinate
8040 * @param {Boolean} local True to get the local css position instead of page coordinate
8043 getLeft : function(local){
8047 return parseInt(this.getStyle("left"), 10) || 0;
8052 * Gets the right X coordinate of the element (element X position + element width)
8053 * @param {Boolean} local True to get the local css position instead of page coordinate
8056 getRight : function(local){
8058 return this.getX() + this.getWidth();
8060 return (this.getLeft(true) + this.getWidth()) || 0;
8065 * Gets the top Y coordinate
8066 * @param {Boolean} local True to get the local css position instead of page coordinate
8069 getTop : function(local) {
8073 return parseInt(this.getStyle("top"), 10) || 0;
8078 * Gets the bottom Y coordinate of the element (element Y position + element height)
8079 * @param {Boolean} local True to get the local css position instead of page coordinate
8082 getBottom : function(local){
8084 return this.getY() + this.getHeight();
8086 return (this.getTop(true) + this.getHeight()) || 0;
8091 * Initializes positioning on this element. If a desired position is not passed, it will make the
8092 * the element positioned relative IF it is not already positioned.
8093 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
8094 * @param {Number} zIndex (optional) The zIndex to apply
8095 * @param {Number} x (optional) Set the page X position
8096 * @param {Number} y (optional) Set the page Y position
8098 position : function(pos, zIndex, x, y){
8100 if(this.getStyle('position') == 'static'){
8101 this.setStyle('position', 'relative');
8104 this.setStyle("position", pos);
8107 this.setStyle("z-index", zIndex);
8109 if(x !== undefined && y !== undefined){
8111 }else if(x !== undefined){
8113 }else if(y !== undefined){
8119 * Clear positioning back to the default when the document was loaded
8120 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
8121 * @return {Roo.Element} this
8123 clearPositioning : function(value){
8131 "position" : "static"
8137 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
8138 * snapshot before performing an update and then restoring the element.
8141 getPositioning : function(){
8142 var l = this.getStyle("left");
8143 var t = this.getStyle("top");
8145 "position" : this.getStyle("position"),
8147 "right" : l ? "" : this.getStyle("right"),
8149 "bottom" : t ? "" : this.getStyle("bottom"),
8150 "z-index" : this.getStyle("z-index")
8155 * Gets the width of the border(s) for the specified side(s)
8156 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8157 * passing lr would get the border (l)eft width + the border (r)ight width.
8158 * @return {Number} The width of the sides passed added together
8160 getBorderWidth : function(side){
8161 return this.addStyles(side, El.borders);
8165 * Gets the width of the padding(s) for the specified side(s)
8166 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8167 * passing lr would get the padding (l)eft + the padding (r)ight.
8168 * @return {Number} The padding of the sides passed added together
8170 getPadding : function(side){
8171 return this.addStyles(side, El.paddings);
8175 * Set positioning with an object returned by getPositioning().
8176 * @param {Object} posCfg
8177 * @return {Roo.Element} this
8179 setPositioning : function(pc){
8180 this.applyStyles(pc);
8181 if(pc.right == "auto"){
8182 this.dom.style.right = "";
8184 if(pc.bottom == "auto"){
8185 this.dom.style.bottom = "";
8191 fixDisplay : function(){
8192 if(this.getStyle("display") == "none"){
8193 this.setStyle("visibility", "hidden");
8194 this.setStyle("display", this.originalDisplay); // first try reverting to default
8195 if(this.getStyle("display") == "none"){ // if that fails, default to block
8196 this.setStyle("display", "block");
8202 * Quick set left and top adding default units
8203 * @param {String} left The left CSS property value
8204 * @param {String} top The top CSS property value
8205 * @return {Roo.Element} this
8207 setLeftTop : function(left, top){
8208 this.dom.style.left = this.addUnits(left);
8209 this.dom.style.top = this.addUnits(top);
8214 * Move this element relative to its current position.
8215 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8216 * @param {Number} distance How far to move the element in pixels
8217 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8218 * @return {Roo.Element} this
8220 move : function(direction, distance, animate){
8221 var xy = this.getXY();
8222 direction = direction.toLowerCase();
8226 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8230 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8235 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8240 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8247 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8248 * @return {Roo.Element} this
8251 if(!this.isClipped){
8252 this.isClipped = true;
8253 this.originalClip = {
8254 "o": this.getStyle("overflow"),
8255 "x": this.getStyle("overflow-x"),
8256 "y": this.getStyle("overflow-y")
8258 this.setStyle("overflow", "hidden");
8259 this.setStyle("overflow-x", "hidden");
8260 this.setStyle("overflow-y", "hidden");
8266 * Return clipping (overflow) to original clipping before clip() was called
8267 * @return {Roo.Element} this
8269 unclip : function(){
8271 this.isClipped = false;
8272 var o = this.originalClip;
8273 if(o.o){this.setStyle("overflow", o.o);}
8274 if(o.x){this.setStyle("overflow-x", o.x);}
8275 if(o.y){this.setStyle("overflow-y", o.y);}
8282 * Gets the x,y coordinates specified by the anchor position on the element.
8283 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8284 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8285 * {width: (target width), height: (target height)} (defaults to the element's current size)
8286 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8287 * @return {Array} [x, y] An array containing the element's x and y coordinates
8289 getAnchorXY : function(anchor, local, s){
8290 //Passing a different size is useful for pre-calculating anchors,
8291 //especially for anchored animations that change the el size.
8293 var w, h, vp = false;
8296 if(d == document.body || d == document){
8298 w = D.getViewWidth(); h = D.getViewHeight();
8300 w = this.getWidth(); h = this.getHeight();
8303 w = s.width; h = s.height;
8305 var x = 0, y = 0, r = Math.round;
8306 switch((anchor || "tl").toLowerCase()){
8348 var sc = this.getScroll();
8349 return [x + sc.left, y + sc.top];
8351 //Add the element's offset xy
8352 var o = this.getXY();
8353 return [x+o[0], y+o[1]];
8357 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8358 * supported position values.
8359 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8360 * @param {String} position The position to align to.
8361 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8362 * @return {Array} [x, y]
8364 getAlignToXY : function(el, p, o){
8368 throw "Element.alignTo with an element that doesn't exist";
8370 var c = false; //constrain to viewport
8371 var p1 = "", p2 = "";
8378 }else if(p.indexOf("-") == -1){
8381 p = p.toLowerCase();
8382 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8384 throw "Element.alignTo with an invalid alignment " + p;
8386 p1 = m[1]; p2 = m[2]; c = !!m[3];
8388 //Subtract the aligned el's internal xy from the target's offset xy
8389 //plus custom offset to get the aligned el's new offset xy
8390 var a1 = this.getAnchorXY(p1, true);
8391 var a2 = el.getAnchorXY(p2, false);
8392 var x = a2[0] - a1[0] + o[0];
8393 var y = a2[1] - a1[1] + o[1];
8395 //constrain the aligned el to viewport if necessary
8396 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8397 // 5px of margin for ie
8398 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8400 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8401 //perpendicular to the vp border, allow the aligned el to slide on that border,
8402 //otherwise swap the aligned el to the opposite border of the target.
8403 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8404 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8405 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8406 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8409 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8410 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8412 if((x+w) > dw + scrollX){
8413 x = swapX ? r.left-w : dw+scrollX-w;
8416 x = swapX ? r.right : scrollX;
8418 if((y+h) > dh + scrollY){
8419 y = swapY ? r.top-h : dh+scrollY-h;
8422 y = swapY ? r.bottom : scrollY;
8429 getConstrainToXY : function(){
8430 var os = {top:0, left:0, bottom:0, right: 0};
8432 return function(el, local, offsets, proposedXY){
8434 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8436 var vw, vh, vx = 0, vy = 0;
8437 if(el.dom == document.body || el.dom == document){
8438 vw = Roo.lib.Dom.getViewWidth();
8439 vh = Roo.lib.Dom.getViewHeight();
8441 vw = el.dom.clientWidth;
8442 vh = el.dom.clientHeight;
8444 var vxy = el.getXY();
8450 var s = el.getScroll();
8452 vx += offsets.left + s.left;
8453 vy += offsets.top + s.top;
8455 vw -= offsets.right;
8456 vh -= offsets.bottom;
8461 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8462 var x = xy[0], y = xy[1];
8463 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8465 // only move it if it needs it
8468 // first validate right/bottom
8477 // then make sure top/left isn't negative
8486 return moved ? [x, y] : false;
8491 adjustForConstraints : function(xy, parent, offsets){
8492 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8496 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8497 * document it aligns it to the viewport.
8498 * The position parameter is optional, and can be specified in any one of the following formats:
8500 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8501 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8502 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8503 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8504 * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
8505 * element's anchor point, and the second value is used as the target's anchor point.</li>
8507 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8508 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8509 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8510 * that specified in order to enforce the viewport constraints.
8511 * Following are all of the supported anchor positions:
8514 ----- -----------------------------
8515 tl The top left corner (default)
8516 t The center of the top edge
8517 tr The top right corner
8518 l The center of the left edge
8519 c In the center of the element
8520 r The center of the right edge
8521 bl The bottom left corner
8522 b The center of the bottom edge
8523 br The bottom right corner
8527 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8528 el.alignTo("other-el");
8530 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8531 el.alignTo("other-el", "tr?");
8533 // align the bottom right corner of el with the center left edge of other-el
8534 el.alignTo("other-el", "br-l?");
8536 // align the center of el with the bottom left corner of other-el and
8537 // adjust the x position by -6 pixels (and the y position by 0)
8538 el.alignTo("other-el", "c-bl", [-6, 0]);
8540 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8541 * @param {String} position The position to align to.
8542 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8543 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8544 * @return {Roo.Element} this
8546 alignTo : function(element, position, offsets, animate){
8547 var xy = this.getAlignToXY(element, position, offsets);
8548 this.setXY(xy, this.preanim(arguments, 3));
8553 * Anchors an element to another element and realigns it when the window is resized.
8554 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8555 * @param {String} position The position to align to.
8556 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8557 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8558 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8559 * is a number, it is used as the buffer delay (defaults to 50ms).
8560 * @param {Function} callback The function to call after the animation finishes
8561 * @return {Roo.Element} this
8563 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8564 var action = function(){
8565 this.alignTo(el, alignment, offsets, animate);
8566 Roo.callback(callback, this);
8568 Roo.EventManager.onWindowResize(action, this);
8569 var tm = typeof monitorScroll;
8570 if(tm != 'undefined'){
8571 Roo.EventManager.on(window, 'scroll', action, this,
8572 {buffer: tm == 'number' ? monitorScroll : 50});
8574 action.call(this); // align immediately
8578 * Clears any opacity settings from this element. Required in some cases for IE.
8579 * @return {Roo.Element} this
8581 clearOpacity : function(){
8582 if (window.ActiveXObject) {
8583 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8584 this.dom.style.filter = "";
8587 this.dom.style.opacity = "";
8588 this.dom.style["-moz-opacity"] = "";
8589 this.dom.style["-khtml-opacity"] = "";
8595 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8596 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8597 * @return {Roo.Element} this
8599 hide : function(animate){
8600 this.setVisible(false, this.preanim(arguments, 0));
8605 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8606 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8607 * @return {Roo.Element} this
8609 show : function(animate){
8610 this.setVisible(true, this.preanim(arguments, 0));
8615 * @private Test if size has a unit, otherwise appends the default
8617 addUnits : function(size){
8618 return Roo.Element.addUnits(size, this.defaultUnit);
8622 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8623 * @return {Roo.Element} this
8625 beginMeasure : function(){
8627 if(el.offsetWidth || el.offsetHeight){
8628 return this; // offsets work already
8631 var p = this.dom, b = document.body; // start with this element
8632 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8633 var pe = Roo.get(p);
8634 if(pe.getStyle('display') == 'none'){
8635 changed.push({el: p, visibility: pe.getStyle("visibility")});
8636 p.style.visibility = "hidden";
8637 p.style.display = "block";
8641 this._measureChanged = changed;
8647 * Restores displays to before beginMeasure was called
8648 * @return {Roo.Element} this
8650 endMeasure : function(){
8651 var changed = this._measureChanged;
8653 for(var i = 0, len = changed.length; i < len; i++) {
8655 r.el.style.visibility = r.visibility;
8656 r.el.style.display = "none";
8658 this._measureChanged = null;
8664 * Update the innerHTML of this element, optionally searching for and processing scripts
8665 * @param {String} html The new HTML
8666 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8667 * @param {Function} callback For async script loading you can be noticed when the update completes
8668 * @return {Roo.Element} this
8670 update : function(html, loadScripts, callback){
8671 if(typeof html == "undefined"){
8674 if(loadScripts !== true){
8675 this.dom.innerHTML = html;
8676 if(typeof callback == "function"){
8684 html += '<span id="' + id + '"></span>';
8686 E.onAvailable(id, function(){
8687 var hd = document.getElementsByTagName("head")[0];
8688 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8689 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8690 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8693 while(match = re.exec(html)){
8694 var attrs = match[1];
8695 var srcMatch = attrs ? attrs.match(srcRe) : false;
8696 if(srcMatch && srcMatch[2]){
8697 var s = document.createElement("script");
8698 s.src = srcMatch[2];
8699 var typeMatch = attrs.match(typeRe);
8700 if(typeMatch && typeMatch[2]){
8701 s.type = typeMatch[2];
8704 }else if(match[2] && match[2].length > 0){
8705 if(window.execScript) {
8706 window.execScript(match[2]);
8714 window.eval(match[2]);
8718 var el = document.getElementById(id);
8719 if(el){el.parentNode.removeChild(el);}
8720 if(typeof callback == "function"){
8724 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8729 * Direct access to the UpdateManager update() method (takes the same parameters).
8730 * @param {String/Function} url The url for this request or a function to call to get the url
8731 * @param {String/Object} params (optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
8732 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8733 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
8734 * @return {Roo.Element} this
8737 var um = this.getUpdateManager();
8738 um.update.apply(um, arguments);
8743 * Gets this element's UpdateManager
8744 * @return {Roo.UpdateManager} The UpdateManager
8746 getUpdateManager : function(){
8747 if(!this.updateManager){
8748 this.updateManager = new Roo.UpdateManager(this);
8750 return this.updateManager;
8754 * Disables text selection for this element (normalized across browsers)
8755 * @return {Roo.Element} this
8757 unselectable : function(){
8758 this.dom.unselectable = "on";
8759 this.swallowEvent("selectstart", true);
8760 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8761 this.addClass("x-unselectable");
8766 * Calculates the x, y to center this element on the screen
8767 * @return {Array} The x, y values [x, y]
8769 getCenterXY : function(){
8770 return this.getAlignToXY(document, 'c-c');
8774 * Centers the Element in either the viewport, or another Element.
8775 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8777 center : function(centerIn){
8778 this.alignTo(centerIn || document, 'c-c');
8783 * Tests various css rules/browsers to determine if this element uses a border box
8786 isBorderBox : function(){
8787 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8791 * Return a box {x, y, width, height} that can be used to set another elements
8792 * size/location to match this element.
8793 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8794 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8795 * @return {Object} box An object in the format {x, y, width, height}
8797 getBox : function(contentBox, local){
8802 var left = parseInt(this.getStyle("left"), 10) || 0;
8803 var top = parseInt(this.getStyle("top"), 10) || 0;
8806 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8808 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8810 var l = this.getBorderWidth("l")+this.getPadding("l");
8811 var r = this.getBorderWidth("r")+this.getPadding("r");
8812 var t = this.getBorderWidth("t")+this.getPadding("t");
8813 var b = this.getBorderWidth("b")+this.getPadding("b");
8814 bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
8816 bx.right = bx.x + bx.width;
8817 bx.bottom = bx.y + bx.height;
8822 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8823 for more information about the sides.
8824 * @param {String} sides
8827 getFrameWidth : function(sides, onlyContentBox){
8828 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
8832 * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
8833 * @param {Object} box The box to fill {x, y, width, height}
8834 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
8835 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8836 * @return {Roo.Element} this
8838 setBox : function(box, adjust, animate){
8839 var w = box.width, h = box.height;
8840 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
8841 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8842 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8844 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
8849 * Forces the browser to repaint this element
8850 * @return {Roo.Element} this
8852 repaint : function(){
8854 this.addClass("x-repaint");
8855 setTimeout(function(){
8856 Roo.get(dom).removeClass("x-repaint");
8862 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
8863 * then it returns the calculated width of the sides (see getPadding)
8864 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
8865 * @return {Object/Number}
8867 getMargins : function(side){
8870 top: parseInt(this.getStyle("margin-top"), 10) || 0,
8871 left: parseInt(this.getStyle("margin-left"), 10) || 0,
8872 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
8873 right: parseInt(this.getStyle("margin-right"), 10) || 0
8876 return this.addStyles(side, El.margins);
8881 addStyles : function(sides, styles){
8883 for(var i = 0, len = sides.length; i < len; i++){
8884 v = this.getStyle(styles[sides.charAt(i)]);
8886 w = parseInt(v, 10);
8894 * Creates a proxy element of this element
8895 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
8896 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
8897 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
8898 * @return {Roo.Element} The new proxy element
8900 createProxy : function(config, renderTo, matchBox){
8902 renderTo = Roo.getDom(renderTo);
8904 renderTo = document.body;
8906 config = typeof config == "object" ?
8907 config : {tag : "div", cls: config};
8908 var proxy = Roo.DomHelper.append(renderTo, config, true);
8910 proxy.setBox(this.getBox());
8916 * Puts a mask over this element to disable user interaction. Requires core.css.
8917 * This method can only be applied to elements which accept child nodes.
8918 * @param {String} msg (optional) A message to display in the mask
8919 * @param {String} msgCls (optional) A css class to apply to the msg element
8920 * @return {Element} The mask element
8922 mask : function(msg, msgCls)
8924 if(this.getStyle("position") == "static"){
8925 this.setStyle("position", "relative");
8928 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
8930 this.addClass("x-masked");
8931 this._mask.setDisplayed(true);
8936 while (dom && dom.style) {
8937 if (!isNaN(parseInt(dom.style.zIndex))) {
8938 z = Math.max(z, parseInt(dom.style.zIndex));
8940 dom = dom.parentNode;
8942 // if we are masking the body - then it hides everything..
8943 if (this.dom == document.body) {
8945 this._mask.setWidth(Roo.lib.Dom.getDocumentWidth());
8946 this._mask.setHeight(Roo.lib.Dom.getDocumentHeight());
8949 if(typeof msg == 'string'){
8951 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
8953 var mm = this._maskMsg;
8954 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
8955 mm.dom.firstChild.innerHTML = msg;
8956 mm.setDisplayed(true);
8958 mm.setStyle('z-index', z + 102);
8960 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
8961 this._mask.setHeight(this.getHeight());
8963 this._mask.setStyle('z-index', z + 100);
8969 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
8970 * it is cached for reuse.
8972 unmask : function(removeEl){
8974 if(removeEl === true){
8975 this._mask.remove();
8978 this._maskMsg.remove();
8979 delete this._maskMsg;
8982 this._mask.setDisplayed(false);
8984 this._maskMsg.setDisplayed(false);
8988 this.removeClass("x-masked");
8992 * Returns true if this element is masked
8995 isMasked : function(){
8996 return this._mask && this._mask.isVisible();
9000 * Creates an iframe shim for this element to keep selects and other windowed objects from
9002 * @return {Roo.Element} The new shim element
9004 createShim : function(){
9005 var el = document.createElement('iframe');
9006 el.frameBorder = 'no';
9007 el.className = 'roo-shim';
9008 if(Roo.isIE && Roo.isSecure){
9009 el.src = Roo.SSL_SECURE_URL;
9011 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
9012 shim.autoBoxAdjust = false;
9017 * Removes this element from the DOM and deletes it from the cache
9019 remove : function(){
9020 if(this.dom.parentNode){
9021 this.dom.parentNode.removeChild(this.dom);
9023 delete El.cache[this.dom.id];
9027 * Sets up event handlers to add and remove a css class when the mouse is over this element
9028 * @param {String} className
9029 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
9030 * mouseout events for children elements
9031 * @return {Roo.Element} this
9033 addClassOnOver : function(className, preventFlicker){
9034 this.on("mouseover", function(){
9035 Roo.fly(this, '_internal').addClass(className);
9037 var removeFn = function(e){
9038 if(preventFlicker !== true || !e.within(this, true)){
9039 Roo.fly(this, '_internal').removeClass(className);
9042 this.on("mouseout", removeFn, this.dom);
9047 * Sets up event handlers to add and remove a css class when this element has the focus
9048 * @param {String} className
9049 * @return {Roo.Element} this
9051 addClassOnFocus : function(className){
9052 this.on("focus", function(){
9053 Roo.fly(this, '_internal').addClass(className);
9055 this.on("blur", function(){
9056 Roo.fly(this, '_internal').removeClass(className);
9061 * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
9062 * @param {String} className
9063 * @return {Roo.Element} this
9065 addClassOnClick : function(className){
9067 this.on("mousedown", function(){
9068 Roo.fly(dom, '_internal').addClass(className);
9069 var d = Roo.get(document);
9070 var fn = function(){
9071 Roo.fly(dom, '_internal').removeClass(className);
9072 d.removeListener("mouseup", fn);
9074 d.on("mouseup", fn);
9080 * Stops the specified event from bubbling and optionally prevents the default action
9081 * @param {String} eventName
9082 * @param {Boolean} preventDefault (optional) true to prevent the default action too
9083 * @return {Roo.Element} this
9085 swallowEvent : function(eventName, preventDefault){
9086 var fn = function(e){
9087 e.stopPropagation();
9092 if(eventName instanceof Array){
9093 for(var i = 0, len = eventName.length; i < len; i++){
9094 this.on(eventName[i], fn);
9098 this.on(eventName, fn);
9105 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
9108 * Sizes this element to its parent element's dimensions performing
9109 * neccessary box adjustments.
9110 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
9111 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
9112 * @return {Roo.Element} this
9114 fitToParent : function(monitorResize, targetParent) {
9115 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
9116 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
9117 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
9120 var p = Roo.get(targetParent || this.dom.parentNode);
9121 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
9122 if (monitorResize === true) {
9123 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
9124 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
9130 * Gets the next sibling, skipping text nodes
9131 * @return {HTMLElement} The next sibling or null
9133 getNextSibling : function(){
9134 var n = this.dom.nextSibling;
9135 while(n && n.nodeType != 1){
9142 * Gets the previous sibling, skipping text nodes
9143 * @return {HTMLElement} The previous sibling or null
9145 getPrevSibling : function(){
9146 var n = this.dom.previousSibling;
9147 while(n && n.nodeType != 1){
9148 n = n.previousSibling;
9155 * Appends the passed element(s) to this element
9156 * @param {String/HTMLElement/Array/Element/CompositeElement} el
9157 * @return {Roo.Element} this
9159 appendChild: function(el){
9166 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
9167 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
9168 * automatically generated with the specified attributes.
9169 * @param {HTMLElement} insertBefore (optional) a child element of this element
9170 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
9171 * @return {Roo.Element} The new child element
9173 createChild: function(config, insertBefore, returnDom){
9174 config = config || {tag:'div'};
9176 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
9178 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
9182 * Appends this element to the passed element
9183 * @param {String/HTMLElement/Element} el The new parent element
9184 * @return {Roo.Element} this
9186 appendTo: function(el){
9187 el = Roo.getDom(el);
9188 el.appendChild(this.dom);
9193 * Inserts this element before the passed element in the DOM
9194 * @param {String/HTMLElement/Element} el The element to insert before
9195 * @return {Roo.Element} this
9197 insertBefore: function(el){
9198 el = Roo.getDom(el);
9199 el.parentNode.insertBefore(this.dom, el);
9204 * Inserts this element after the passed element in the DOM
9205 * @param {String/HTMLElement/Element} el The element to insert after
9206 * @return {Roo.Element} this
9208 insertAfter: function(el){
9209 el = Roo.getDom(el);
9210 el.parentNode.insertBefore(this.dom, el.nextSibling);
9215 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9216 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9217 * @return {Roo.Element} The new child
9219 insertFirst: function(el, returnDom){
9221 if(typeof el == 'object' && !el.nodeType){ // dh config
9222 return this.createChild(el, this.dom.firstChild, returnDom);
9224 el = Roo.getDom(el);
9225 this.dom.insertBefore(el, this.dom.firstChild);
9226 return !returnDom ? Roo.get(el) : el;
9231 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9232 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9233 * @param {String} where (optional) 'before' or 'after' defaults to before
9234 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9235 * @return {Roo.Element} the inserted Element
9237 insertSibling: function(el, where, returnDom){
9238 where = where ? where.toLowerCase() : 'before';
9240 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9242 if(typeof el == 'object' && !el.nodeType){ // dh config
9243 if(where == 'after' && !this.dom.nextSibling){
9244 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9246 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9250 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9251 where == 'before' ? this.dom : this.dom.nextSibling);
9260 * Creates and wraps this element with another element
9261 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9262 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9263 * @return {HTMLElement/Element} The newly created wrapper element
9265 wrap: function(config, returnDom){
9267 config = {tag: "div"};
9269 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9270 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9275 * Replaces the passed element with this element
9276 * @param {String/HTMLElement/Element} el The element to replace
9277 * @return {Roo.Element} this
9279 replace: function(el){
9281 this.insertBefore(el);
9287 * Inserts an html fragment into this element
9288 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9289 * @param {String} html The HTML fragment
9290 * @param {Boolean} returnEl True to return an Roo.Element
9291 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9293 insertHtml : function(where, html, returnEl){
9294 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9295 return returnEl ? Roo.get(el) : el;
9299 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9300 * @param {Object} o The object with the attributes
9301 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9302 * @return {Roo.Element} this
9304 set : function(o, useSet){
9306 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9308 if(attr == "style" || typeof o[attr] == "function") continue;
9310 el.className = o["cls"];
9312 if(useSet) el.setAttribute(attr, o[attr]);
9313 else el[attr] = o[attr];
9317 Roo.DomHelper.applyStyles(el, o.style);
9323 * Convenience method for constructing a KeyMap
9324 * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
9325 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9326 * @param {Function} fn The function to call
9327 * @param {Object} scope (optional) The scope of the function
9328 * @return {Roo.KeyMap} The KeyMap created
9330 addKeyListener : function(key, fn, scope){
9332 if(typeof key != "object" || key instanceof Array){
9348 return new Roo.KeyMap(this, config);
9352 * Creates a KeyMap for this element
9353 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9354 * @return {Roo.KeyMap} The KeyMap created
9356 addKeyMap : function(config){
9357 return new Roo.KeyMap(this, config);
9361 * Returns true if this element is scrollable.
9364 isScrollable : function(){
9366 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9370 * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
9371 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9372 * @param {Number} value The new scroll value
9373 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9374 * @return {Element} this
9377 scrollTo : function(side, value, animate){
9378 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9380 this.dom[prop] = value;
9382 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9383 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9389 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9390 * within this element's scrollable range.
9391 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9392 * @param {Number} distance How far to scroll the element in pixels
9393 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9394 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9395 * was scrolled as far as it could go.
9397 scroll : function(direction, distance, animate){
9398 if(!this.isScrollable()){
9402 var l = el.scrollLeft, t = el.scrollTop;
9403 var w = el.scrollWidth, h = el.scrollHeight;
9404 var cw = el.clientWidth, ch = el.clientHeight;
9405 direction = direction.toLowerCase();
9406 var scrolled = false;
9407 var a = this.preanim(arguments, 2);
9412 var v = Math.min(l + distance, w-cw);
9413 this.scrollTo("left", v, a);
9420 var v = Math.max(l - distance, 0);
9421 this.scrollTo("left", v, a);
9429 var v = Math.max(t - distance, 0);
9430 this.scrollTo("top", v, a);
9438 var v = Math.min(t + distance, h-ch);
9439 this.scrollTo("top", v, a);
9448 * Translates the passed page coordinates into left/top css values for this element
9449 * @param {Number/Array} x The page x or an array containing [x, y]
9450 * @param {Number} y The page y
9451 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9453 translatePoints : function(x, y){
9454 if(typeof x == 'object' || x instanceof Array){
9457 var p = this.getStyle('position');
9458 var o = this.getXY();
9460 var l = parseInt(this.getStyle('left'), 10);
9461 var t = parseInt(this.getStyle('top'), 10);
9464 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9467 t = (p == "relative") ? 0 : this.dom.offsetTop;
9470 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9474 * Returns the current scroll position of the element.
9475 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9477 getScroll : function(){
9478 var d = this.dom, doc = document;
9479 if(d == doc || d == doc.body){
9480 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9481 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9482 return {left: l, top: t};
9484 return {left: d.scrollLeft, top: d.scrollTop};
9489 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9490 * are convert to standard 6 digit hex color.
9491 * @param {String} attr The css attribute
9492 * @param {String} defaultValue The default value to use when a valid color isn't found
9493 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9496 getColor : function(attr, defaultValue, prefix){
9497 var v = this.getStyle(attr);
9498 if(!v || v == "transparent" || v == "inherit") {
9499 return defaultValue;
9501 var color = typeof prefix == "undefined" ? "#" : prefix;
9502 if(v.substr(0, 4) == "rgb("){
9503 var rvs = v.slice(4, v.length -1).split(",");
9504 for(var i = 0; i < 3; i++){
9505 var h = parseInt(rvs[i]).toString(16);
9512 if(v.substr(0, 1) == "#"){
9514 for(var i = 1; i < 4; i++){
9515 var c = v.charAt(i);
9518 }else if(v.length == 7){
9519 color += v.substr(1);
9523 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9527 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9528 * gradient background, rounded corners and a 4-way shadow.
9529 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9530 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9531 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9532 * @return {Roo.Element} this
9534 boxWrap : function(cls){
9535 cls = cls || 'x-box';
9536 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9537 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9542 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9543 * @param {String} namespace The namespace in which to look for the attribute
9544 * @param {String} name The attribute name
9545 * @return {String} The attribute value
9547 getAttributeNS : Roo.isIE ? function(ns, name){
9549 var type = typeof d[ns+":"+name];
9550 if(type != 'undefined' && type != 'unknown'){
9551 return d[ns+":"+name];
9554 } : function(ns, name){
9556 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9561 * Sets or Returns the value the dom attribute value
9562 * @param {String} name The attribute name
9563 * @param {String} value (optional) The value to set the attribute to
9564 * @return {String} The attribute value
9566 attr : function(name){
9567 if (arguments.length > 1) {
9568 this.dom.setAttribute(name, arguments[1]);
9569 return arguments[1];
9571 if (!this.dom.hasAttribute(name)) {
9574 return this.dom.getAttribute(name);
9581 var ep = El.prototype;
9584 * Appends an event handler (Shorthand for addListener)
9585 * @param {String} eventName The type of event to append
9586 * @param {Function} fn The method the event invokes
9587 * @param {Object} scope (optional) The scope (this object) of the fn
9588 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9591 ep.on = ep.addListener;
9593 ep.mon = ep.addListener;
9596 * Removes an event handler from this element (shorthand for removeListener)
9597 * @param {String} eventName the type of event to remove
9598 * @param {Function} fn the method the event invokes
9599 * @return {Roo.Element} this
9602 ep.un = ep.removeListener;
9605 * true to automatically adjust width and height settings for box-model issues (default to true)
9607 ep.autoBoxAdjust = true;
9610 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9613 El.addUnits = function(v, defaultUnit){
9614 if(v === "" || v == "auto"){
9617 if(v === undefined){
9620 if(typeof v == "number" || !El.unitPattern.test(v)){
9621 return v + (defaultUnit || 'px');
9626 // special markup used throughout Roo when box wrapping elements
9627 El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
9629 * Visibility mode constant - Use visibility to hide element
9635 * Visibility mode constant - Use display to hide element
9641 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9642 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9643 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9655 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9656 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9657 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9658 * @return {Element} The Element object
9661 El.get = function(el){
9663 if(!el){ return null; }
9664 if(typeof el == "string"){ // element id
9665 if(!(elm = document.getElementById(el))){
9668 if(ex = El.cache[el]){
9671 ex = El.cache[el] = new El(elm);
9674 }else if(el.tagName){ // dom element
9678 if(ex = El.cache[id]){
9681 ex = El.cache[id] = new El(el);
9684 }else if(el instanceof El){
9686 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9687 // catch case where it hasn't been appended
9688 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9691 }else if(el.isComposite){
9693 }else if(el instanceof Array){
9694 return El.select(el);
9695 }else if(el == document){
9696 // create a bogus element object representing the document object
9698 var f = function(){};
9699 f.prototype = El.prototype;
9701 docEl.dom = document;
9709 El.uncache = function(el){
9710 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9712 delete El.cache[a[i].id || a[i]];
9718 // Garbage collection - uncache elements/purge listeners on orphaned elements
9719 // so we don't hold a reference and cause the browser to retain them
9720 El.garbageCollect = function(){
9721 if(!Roo.enableGarbageCollector){
9722 clearInterval(El.collectorThread);
9725 for(var eid in El.cache){
9726 var el = El.cache[eid], d = el.dom;
9727 // -------------------------------------------------------
9728 // Determining what is garbage:
9729 // -------------------------------------------------------
9731 // dom node is null, definitely garbage
9732 // -------------------------------------------------------
9734 // no parentNode == direct orphan, definitely garbage
9735 // -------------------------------------------------------
9736 // !d.offsetParent && !document.getElementById(eid)
9737 // display none elements have no offsetParent so we will
9738 // also try to look it up by it's id. However, check
9739 // offsetParent first so we don't do unneeded lookups.
9740 // This enables collection of elements that are not orphans
9741 // directly, but somewhere up the line they have an orphan
9743 // -------------------------------------------------------
9744 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9745 delete El.cache[eid];
9746 if(d && Roo.enableListenerCollection){
9752 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9756 El.Flyweight = function(dom){
9759 El.Flyweight.prototype = El.prototype;
9761 El._flyweights = {};
9763 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9764 * the dom node can be overwritten by other code.
9765 * @param {String/HTMLElement} el The dom node or id
9766 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9767 * prevent conflicts (e.g. internally Roo uses "_internal")
9769 * @return {Element} The shared Element object
9771 El.fly = function(el, named){
9772 named = named || '_global';
9773 el = Roo.getDom(el);
9777 if(!El._flyweights[named]){
9778 El._flyweights[named] = new El.Flyweight();
9780 El._flyweights[named].dom = el;
9781 return El._flyweights[named];
9785 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9786 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9787 * Shorthand of {@link Roo.Element#get}
9788 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9789 * @return {Element} The Element object
9795 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9796 * the dom node can be overwritten by other code.
9797 * Shorthand of {@link Roo.Element#fly}
9798 * @param {String/HTMLElement} el The dom node or id
9799 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9800 * prevent conflicts (e.g. internally Roo uses "_internal")
9802 * @return {Element} The shared Element object
9808 // speedy lookup for elements never to box adjust
9809 var noBoxAdjust = Roo.isStrict ? {
9812 input:1, select:1, textarea:1
9814 if(Roo.isIE || Roo.isGecko){
9815 noBoxAdjust['button'] = 1;
9819 Roo.EventManager.on(window, 'unload', function(){
9821 delete El._flyweights;
9829 Roo.Element.selectorFunction = Roo.DomQuery.select;
9832 Roo.Element.select = function(selector, unique, root){
9834 if(typeof selector == "string"){
9835 els = Roo.Element.selectorFunction(selector, root);
9836 }else if(selector.length !== undefined){
9839 throw "Invalid selector";
9841 if(unique === true){
9842 return new Roo.CompositeElement(els);
9844 return new Roo.CompositeElementLite(els);
9848 * Selects elements based on the passed CSS selector to enable working on them as 1.
9849 * @param {String/Array} selector The CSS selector or an array of elements
9850 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
9851 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
9852 * @return {CompositeElementLite/CompositeElement}
9856 Roo.select = Roo.Element.select;
9873 * Ext JS Library 1.1.1
9874 * Copyright(c) 2006-2007, Ext JS, LLC.
9876 * Originally Released Under LGPL - original licence link has changed is not relivant.
9879 * <script type="text/javascript">
9884 //Notifies Element that fx methods are available
9885 Roo.enableFx = true;
9889 * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
9890 * to the {@link Roo.Element} interface when included, so all effects calls should be performed via Element.
9891 * Conversely, since the effects are not actually defined in Element, Roo.Fx <b>must</b> be included in order for the
9892 * Element effects to work.</p><br/>
9894 * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
9895 * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
9896 * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
9897 * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
9898 * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
9899 * expected results and should be done with care.</p><br/>
9901 * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
9902 * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
9905 ----- -----------------------------
9906 tl The top left corner
9907 t The center of the top edge
9908 tr The top right corner
9909 l The center of the left edge
9910 r The center of the right edge
9911 bl The bottom left corner
9912 b The center of the bottom edge
9913 br The bottom right corner
9915 * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section
9916 * below are common options that can be passed to any Fx method.</b>
9917 * @cfg {Function} callback A function called when the effect is finished
9918 * @cfg {Object} scope The scope of the effect function
9919 * @cfg {String} easing A valid Easing value for the effect
9920 * @cfg {String} afterCls A css class to apply after the effect
9921 * @cfg {Number} duration The length of time (in seconds) that the effect should last
9922 * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
9923 * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
9924 * effects that end with the element being visually hidden, ignored otherwise)
9925 * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or
9926 * a function which returns such a specification that will be applied to the Element after the effect finishes
9927 * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
9928 * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence
9929 * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes
9933 * Slides the element into view. An anchor point can be optionally passed to set the point of
9934 * origin for the slide effect. This function automatically handles wrapping the element with
9935 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
9938 // default: slide the element in from the top
9941 // custom: slide the element in from the right with a 2-second duration
9942 el.slideIn('r', { duration: 2 });
9944 // common config options shown with default values
9950 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
9951 * @param {Object} options (optional) Object literal with any of the Fx config options
9952 * @return {Roo.Element} The Element
9954 slideIn : function(anchor, o){
9955 var el = this.getFxEl();
9958 el.queueFx(o, function(){
9960 anchor = anchor || "t";
9962 // fix display to visibility
9965 // restore values after effect
9966 var r = this.getFxRestore();
9967 var b = this.getBox();
9968 // fixed size for slide
9972 var wrap = this.fxWrap(r.pos, o, "hidden");
9974 var st = this.dom.style;
9975 st.visibility = "visible";
9976 st.position = "absolute";
9978 // clear out temp styles after slide and unwrap
9979 var after = function(){
9980 el.fxUnwrap(wrap, r.pos, o);
9982 st.height = r.height;
9985 // time to calc the positions
9986 var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
9988 switch(anchor.toLowerCase()){
9990 wrap.setSize(b.width, 0);
9991 st.left = st.bottom = "0";
9995 wrap.setSize(0, b.height);
9996 st.right = st.top = "0";
10000 wrap.setSize(0, b.height);
10001 wrap.setX(b.right);
10002 st.left = st.top = "0";
10003 a = {width: bw, points: pt};
10006 wrap.setSize(b.width, 0);
10007 wrap.setY(b.bottom);
10008 st.left = st.top = "0";
10009 a = {height: bh, points: pt};
10012 wrap.setSize(0, 0);
10013 st.right = st.bottom = "0";
10014 a = {width: bw, height: bh};
10017 wrap.setSize(0, 0);
10018 wrap.setY(b.y+b.height);
10019 st.right = st.top = "0";
10020 a = {width: bw, height: bh, points: pt};
10023 wrap.setSize(0, 0);
10024 wrap.setXY([b.right, b.bottom]);
10025 st.left = st.top = "0";
10026 a = {width: bw, height: bh, points: pt};
10029 wrap.setSize(0, 0);
10030 wrap.setX(b.x+b.width);
10031 st.left = st.bottom = "0";
10032 a = {width: bw, height: bh, points: pt};
10035 this.dom.style.visibility = "visible";
10038 arguments.callee.anim = wrap.fxanim(a,
10048 * Slides the element out of view. An anchor point can be optionally passed to set the end point
10049 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
10050 * 'hidden') but block elements will still take up space in the document. The element must be removed
10051 * from the DOM using the 'remove' config option if desired. This function automatically handles
10052 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10055 // default: slide the element out to the top
10058 // custom: slide the element out to the right with a 2-second duration
10059 el.slideOut('r', { duration: 2 });
10061 // common config options shown with default values
10069 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10070 * @param {Object} options (optional) Object literal with any of the Fx config options
10071 * @return {Roo.Element} The Element
10073 slideOut : function(anchor, o){
10074 var el = this.getFxEl();
10077 el.queueFx(o, function(){
10079 anchor = anchor || "t";
10081 // restore values after effect
10082 var r = this.getFxRestore();
10084 var b = this.getBox();
10085 // fixed size for slide
10089 var wrap = this.fxWrap(r.pos, o, "visible");
10091 var st = this.dom.style;
10092 st.visibility = "visible";
10093 st.position = "absolute";
10097 var after = function(){
10099 el.setDisplayed(false);
10104 el.fxUnwrap(wrap, r.pos, o);
10106 st.width = r.width;
10107 st.height = r.height;
10112 var a, zero = {to: 0};
10113 switch(anchor.toLowerCase()){
10115 st.left = st.bottom = "0";
10116 a = {height: zero};
10119 st.right = st.top = "0";
10123 st.left = st.top = "0";
10124 a = {width: zero, points: {to:[b.right, b.y]}};
10127 st.left = st.top = "0";
10128 a = {height: zero, points: {to:[b.x, b.bottom]}};
10131 st.right = st.bottom = "0";
10132 a = {width: zero, height: zero};
10135 st.right = st.top = "0";
10136 a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}};
10139 st.left = st.top = "0";
10140 a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}};
10143 st.left = st.bottom = "0";
10144 a = {width: zero, height: zero, points: {to:[b.right, b.y]}};
10148 arguments.callee.anim = wrap.fxanim(a,
10158 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
10159 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
10160 * The element must be removed from the DOM using the 'remove' config option if desired.
10166 // common config options shown with default values
10174 * @param {Object} options (optional) Object literal with any of the Fx config options
10175 * @return {Roo.Element} The Element
10177 puff : function(o){
10178 var el = this.getFxEl();
10181 el.queueFx(o, function(){
10182 this.clearOpacity();
10185 // restore values after effect
10186 var r = this.getFxRestore();
10187 var st = this.dom.style;
10189 var after = function(){
10191 el.setDisplayed(false);
10198 el.setPositioning(r.pos);
10199 st.width = r.width;
10200 st.height = r.height;
10205 var width = this.getWidth();
10206 var height = this.getHeight();
10208 arguments.callee.anim = this.fxanim({
10209 width : {to: this.adjustWidth(width * 2)},
10210 height : {to: this.adjustHeight(height * 2)},
10211 points : {by: [-(width * .5), -(height * .5)]},
10213 fontSize: {to:200, unit: "%"}
10224 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
10225 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
10226 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
10232 // all config options shown with default values
10240 * @param {Object} options (optional) Object literal with any of the Fx config options
10241 * @return {Roo.Element} The Element
10243 switchOff : function(o){
10244 var el = this.getFxEl();
10247 el.queueFx(o, function(){
10248 this.clearOpacity();
10251 // restore values after effect
10252 var r = this.getFxRestore();
10253 var st = this.dom.style;
10255 var after = function(){
10257 el.setDisplayed(false);
10263 el.setPositioning(r.pos);
10264 st.width = r.width;
10265 st.height = r.height;
10270 this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
10271 this.clearOpacity();
10275 points:{by:[0, this.getHeight() * .5]}
10276 }, o, 'motion', 0.3, 'easeIn', after);
10277 }).defer(100, this);
10284 * Highlights the Element by setting a color (applies to the background-color by default, but can be
10285 * changed using the "attr" config option) and then fading back to the original color. If no original
10286 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
10289 // default: highlight background to yellow
10292 // custom: highlight foreground text to blue for 2 seconds
10293 el.highlight("0000ff", { attr: 'color', duration: 2 });
10295 // common config options shown with default values
10296 el.highlight("ffff9c", {
10297 attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
10298 endColor: (current color) or "ffffff",
10303 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
10304 * @param {Object} options (optional) Object literal with any of the Fx config options
10305 * @return {Roo.Element} The Element
10307 highlight : function(color, o){
10308 var el = this.getFxEl();
10311 el.queueFx(o, function(){
10312 color = color || "ffff9c";
10313 attr = o.attr || "backgroundColor";
10315 this.clearOpacity();
10318 var origColor = this.getColor(attr);
10319 var restoreColor = this.dom.style[attr];
10320 endColor = (o.endColor || origColor) || "ffffff";
10322 var after = function(){
10323 el.dom.style[attr] = restoreColor;
10328 a[attr] = {from: color, to: endColor};
10329 arguments.callee.anim = this.fxanim(a,
10339 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
10342 // default: a single light blue ripple
10345 // custom: 3 red ripples lasting 3 seconds total
10346 el.frame("ff0000", 3, { duration: 3 });
10348 // common config options shown with default values
10349 el.frame("C3DAF9", 1, {
10350 duration: 1 //duration of entire animation (not each individual ripple)
10351 // Note: Easing is not configurable and will be ignored if included
10354 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
10355 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
10356 * @param {Object} options (optional) Object literal with any of the Fx config options
10357 * @return {Roo.Element} The Element
10359 frame : function(color, count, o){
10360 var el = this.getFxEl();
10363 el.queueFx(o, function(){
10364 color = color || "#C3DAF9";
10365 if(color.length == 6){
10366 color = "#" + color;
10368 count = count || 1;
10369 duration = o.duration || 1;
10372 var b = this.getBox();
10373 var animFn = function(){
10374 var proxy = this.createProxy({
10377 visbility:"hidden",
10378 position:"absolute",
10379 "z-index":"35000", // yee haw
10380 border:"0px solid " + color
10383 var scale = Roo.isBorderBox ? 2 : 1;
10385 top:{from:b.y, to:b.y - 20},
10386 left:{from:b.x, to:b.x - 20},
10387 borderWidth:{from:0, to:10},
10388 opacity:{from:1, to:0},
10389 height:{from:b.height, to:(b.height + (20*scale))},
10390 width:{from:b.width, to:(b.width + (20*scale))}
10391 }, duration, function(){
10395 animFn.defer((duration/2)*1000, this);
10406 * Creates a pause before any subsequent queued effects begin. If there are
10407 * no effects queued after the pause it will have no effect.
10412 * @param {Number} seconds The length of time to pause (in seconds)
10413 * @return {Roo.Element} The Element
10415 pause : function(seconds){
10416 var el = this.getFxEl();
10419 el.queueFx(o, function(){
10420 setTimeout(function(){
10422 }, seconds * 1000);
10428 * Fade an element in (from transparent to opaque). The ending opacity can be specified
10429 * using the "endOpacity" config option.
10432 // default: fade in from opacity 0 to 100%
10435 // custom: fade in from opacity 0 to 75% over 2 seconds
10436 el.fadeIn({ endOpacity: .75, duration: 2});
10438 // common config options shown with default values
10440 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
10445 * @param {Object} options (optional) Object literal with any of the Fx config options
10446 * @return {Roo.Element} The Element
10448 fadeIn : function(o){
10449 var el = this.getFxEl();
10451 el.queueFx(o, function(){
10452 this.setOpacity(0);
10454 this.dom.style.visibility = 'visible';
10455 var to = o.endOpacity || 1;
10456 arguments.callee.anim = this.fxanim({opacity:{to:to}},
10457 o, null, .5, "easeOut", function(){
10459 this.clearOpacity();
10468 * Fade an element out (from opaque to transparent). The ending opacity can be specified
10469 * using the "endOpacity" config option.
10472 // default: fade out from the element's current opacity to 0
10475 // custom: fade out from the element's current opacity to 25% over 2 seconds
10476 el.fadeOut({ endOpacity: .25, duration: 2});
10478 // common config options shown with default values
10480 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
10487 * @param {Object} options (optional) Object literal with any of the Fx config options
10488 * @return {Roo.Element} The Element
10490 fadeOut : function(o){
10491 var el = this.getFxEl();
10493 el.queueFx(o, function(){
10494 arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
10495 o, null, .5, "easeOut", function(){
10496 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
10497 this.dom.style.display = "none";
10499 this.dom.style.visibility = "hidden";
10501 this.clearOpacity();
10509 * Animates the transition of an element's dimensions from a starting height/width
10510 * to an ending height/width.
10513 // change height and width to 100x100 pixels
10514 el.scale(100, 100);
10516 // common config options shown with default values. The height and width will default to
10517 // the element's existing values if passed as null.
10520 [element's height], {
10525 * @param {Number} width The new width (pass undefined to keep the original width)
10526 * @param {Number} height The new height (pass undefined to keep the original height)
10527 * @param {Object} options (optional) Object literal with any of the Fx config options
10528 * @return {Roo.Element} The Element
10530 scale : function(w, h, o){
10531 this.shift(Roo.apply({}, o, {
10539 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
10540 * Any of these properties not specified in the config object will not be changed. This effect
10541 * requires that at least one new dimension, position or opacity setting must be passed in on
10542 * the config object in order for the function to have any effect.
10545 // slide the element horizontally to x position 200 while changing the height and opacity
10546 el.shift({ x: 200, height: 50, opacity: .8 });
10548 // common config options shown with default values.
10550 width: [element's width],
10551 height: [element's height],
10552 x: [element's x position],
10553 y: [element's y position],
10554 opacity: [element's opacity],
10559 * @param {Object} options Object literal with any of the Fx config options
10560 * @return {Roo.Element} The Element
10562 shift : function(o){
10563 var el = this.getFxEl();
10565 el.queueFx(o, function(){
10566 var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity;
10567 if(w !== undefined){
10568 a.width = {to: this.adjustWidth(w)};
10570 if(h !== undefined){
10571 a.height = {to: this.adjustHeight(h)};
10573 if(x !== undefined || y !== undefined){
10575 x !== undefined ? x : this.getX(),
10576 y !== undefined ? y : this.getY()
10579 if(op !== undefined){
10580 a.opacity = {to: op};
10582 if(o.xy !== undefined){
10583 a.points = {to: o.xy};
10585 arguments.callee.anim = this.fxanim(a,
10586 o, 'motion', .35, "easeOut", function(){
10594 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
10595 * ending point of the effect.
10598 // default: slide the element downward while fading out
10601 // custom: slide the element out to the right with a 2-second duration
10602 el.ghost('r', { duration: 2 });
10604 // common config options shown with default values
10612 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
10613 * @param {Object} options (optional) Object literal with any of the Fx config options
10614 * @return {Roo.Element} The Element
10616 ghost : function(anchor, o){
10617 var el = this.getFxEl();
10620 el.queueFx(o, function(){
10621 anchor = anchor || "b";
10623 // restore values after effect
10624 var r = this.getFxRestore();
10625 var w = this.getWidth(),
10626 h = this.getHeight();
10628 var st = this.dom.style;
10630 var after = function(){
10632 el.setDisplayed(false);
10638 el.setPositioning(r.pos);
10639 st.width = r.width;
10640 st.height = r.height;
10645 var a = {opacity: {to: 0}, points: {}}, pt = a.points;
10646 switch(anchor.toLowerCase()){
10673 arguments.callee.anim = this.fxanim(a,
10683 * Ensures that all effects queued after syncFx is called on the element are
10684 * run concurrently. This is the opposite of {@link #sequenceFx}.
10685 * @return {Roo.Element} The Element
10687 syncFx : function(){
10688 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10697 * Ensures that all effects queued after sequenceFx is called on the element are
10698 * run in sequence. This is the opposite of {@link #syncFx}.
10699 * @return {Roo.Element} The Element
10701 sequenceFx : function(){
10702 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10704 concurrent : false,
10711 nextFx : function(){
10712 var ef = this.fxQueue[0];
10719 * Returns true if the element has any effects actively running or queued, else returns false.
10720 * @return {Boolean} True if element has active effects, else false
10722 hasActiveFx : function(){
10723 return this.fxQueue && this.fxQueue[0];
10727 * Stops any running effects and clears the element's internal effects queue if it contains
10728 * any additional effects that haven't started yet.
10729 * @return {Roo.Element} The Element
10731 stopFx : function(){
10732 if(this.hasActiveFx()){
10733 var cur = this.fxQueue[0];
10734 if(cur && cur.anim && cur.anim.isAnimated()){
10735 this.fxQueue = [cur]; // clear out others
10736 cur.anim.stop(true);
10743 beforeFx : function(o){
10744 if(this.hasActiveFx() && !o.concurrent){
10755 * Returns true if the element is currently blocking so that no other effect can be queued
10756 * until this effect is finished, else returns false if blocking is not set. This is commonly
10757 * used to ensure that an effect initiated by a user action runs to completion prior to the
10758 * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
10759 * @return {Boolean} True if blocking, else false
10761 hasFxBlock : function(){
10762 var q = this.fxQueue;
10763 return q && q[0] && q[0].block;
10767 queueFx : function(o, fn){
10771 if(!this.hasFxBlock()){
10772 Roo.applyIf(o, this.fxDefaults);
10774 var run = this.beforeFx(o);
10775 fn.block = o.block;
10776 this.fxQueue.push(fn);
10788 fxWrap : function(pos, o, vis){
10790 if(!o.wrap || !(wrap = Roo.get(o.wrap))){
10793 wrapXY = this.getXY();
10795 var div = document.createElement("div");
10796 div.style.visibility = vis;
10797 wrap = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
10798 wrap.setPositioning(pos);
10799 if(wrap.getStyle("position") == "static"){
10800 wrap.position("relative");
10802 this.clearPositioning('auto');
10804 wrap.dom.appendChild(this.dom);
10806 wrap.setXY(wrapXY);
10813 fxUnwrap : function(wrap, pos, o){
10814 this.clearPositioning();
10815 this.setPositioning(pos);
10817 wrap.dom.parentNode.insertBefore(this.dom, wrap.dom);
10823 getFxRestore : function(){
10824 var st = this.dom.style;
10825 return {pos: this.getPositioning(), width: st.width, height : st.height};
10829 afterFx : function(o){
10831 this.applyStyles(o.afterStyle);
10834 this.addClass(o.afterCls);
10836 if(o.remove === true){
10839 Roo.callback(o.callback, o.scope, [this]);
10841 this.fxQueue.shift();
10847 getFxEl : function(){ // support for composite element fx
10848 return Roo.get(this.dom);
10852 fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
10853 animType = animType || 'run';
10855 var anim = Roo.lib.Anim[animType](
10857 (opt.duration || defaultDur) || .35,
10858 (opt.easing || defaultEase) || 'easeOut',
10860 Roo.callback(cb, this);
10869 // backwords compat
10870 Roo.Fx.resize = Roo.Fx.scale;
10872 //When included, Roo.Fx is automatically applied to Element so that all basic
10873 //effects are available directly via the Element API
10874 Roo.apply(Roo.Element.prototype, Roo.Fx);/*
10876 * Ext JS Library 1.1.1
10877 * Copyright(c) 2006-2007, Ext JS, LLC.
10879 * Originally Released Under LGPL - original licence link has changed is not relivant.
10882 * <script type="text/javascript">
10887 * @class Roo.CompositeElement
10888 * Standard composite class. Creates a Roo.Element for every element in the collection.
10890 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
10891 * actions will be performed on all the elements in this collection.</b>
10893 * All methods return <i>this</i> and can be chained.
10895 var els = Roo.select("#some-el div.some-class", true);
10896 // or select directly from an existing element
10897 var el = Roo.get('some-el');
10898 el.select('div.some-class', true);
10900 els.setWidth(100); // all elements become 100 width
10901 els.hide(true); // all elements fade out and hide
10903 els.setWidth(100).hide(true);
10906 Roo.CompositeElement = function(els){
10907 this.elements = [];
10908 this.addElements(els);
10910 Roo.CompositeElement.prototype = {
10912 addElements : function(els){
10913 if(!els) return this;
10914 if(typeof els == "string"){
10915 els = Roo.Element.selectorFunction(els);
10917 var yels = this.elements;
10918 var index = yels.length-1;
10919 for(var i = 0, len = els.length; i < len; i++) {
10920 yels[++index] = Roo.get(els[i]);
10926 * Clears this composite and adds the elements returned by the passed selector.
10927 * @param {String/Array} els A string CSS selector, an array of elements or an element
10928 * @return {CompositeElement} this
10930 fill : function(els){
10931 this.elements = [];
10937 * Filters this composite to only elements that match the passed selector.
10938 * @param {String} selector A string CSS selector
10939 * @return {CompositeElement} this
10941 filter : function(selector){
10943 this.each(function(el){
10944 if(el.is(selector)){
10945 els[els.length] = el.dom;
10952 invoke : function(fn, args){
10953 var els = this.elements;
10954 for(var i = 0, len = els.length; i < len; i++) {
10955 Roo.Element.prototype[fn].apply(els[i], args);
10960 * Adds elements to this composite.
10961 * @param {String/Array} els A string CSS selector, an array of elements or an element
10962 * @return {CompositeElement} this
10964 add : function(els){
10965 if(typeof els == "string"){
10966 this.addElements(Roo.Element.selectorFunction(els));
10967 }else if(els.length !== undefined){
10968 this.addElements(els);
10970 this.addElements([els]);
10975 * Calls the passed function passing (el, this, index) for each element in this composite.
10976 * @param {Function} fn The function to call
10977 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
10978 * @return {CompositeElement} this
10980 each : function(fn, scope){
10981 var els = this.elements;
10982 for(var i = 0, len = els.length; i < len; i++){
10983 if(fn.call(scope || els[i], els[i], this, i) === false) {
10991 * Returns the Element object at the specified index
10992 * @param {Number} index
10993 * @return {Roo.Element}
10995 item : function(index){
10996 return this.elements[index] || null;
11000 * Returns the first Element
11001 * @return {Roo.Element}
11003 first : function(){
11004 return this.item(0);
11008 * Returns the last Element
11009 * @return {Roo.Element}
11012 return this.item(this.elements.length-1);
11016 * Returns the number of elements in this composite
11019 getCount : function(){
11020 return this.elements.length;
11024 * Returns true if this composite contains the passed element
11027 contains : function(el){
11028 return this.indexOf(el) !== -1;
11032 * Returns true if this composite contains the passed element
11035 indexOf : function(el){
11036 return this.elements.indexOf(Roo.get(el));
11041 * Removes the specified element(s).
11042 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
11043 * or an array of any of those.
11044 * @param {Boolean} removeDom (optional) True to also remove the element from the document
11045 * @return {CompositeElement} this
11047 removeElement : function(el, removeDom){
11048 if(el instanceof Array){
11049 for(var i = 0, len = el.length; i < len; i++){
11050 this.removeElement(el[i]);
11054 var index = typeof el == 'number' ? el : this.indexOf(el);
11057 var d = this.elements[index];
11061 d.parentNode.removeChild(d);
11064 this.elements.splice(index, 1);
11070 * Replaces the specified element with the passed element.
11071 * @param {String/HTMLElement/Element/Number} el The id of an element, the Element itself, the index of the element in this composite
11073 * @param {String/HTMLElement/Element} replacement The id of an element or the Element itself.
11074 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
11075 * @return {CompositeElement} this
11077 replaceElement : function(el, replacement, domReplace){
11078 var index = typeof el == 'number' ? el : this.indexOf(el);
11081 this.elements[index].replaceWith(replacement);
11083 this.elements.splice(index, 1, Roo.get(replacement))
11090 * Removes all elements.
11092 clear : function(){
11093 this.elements = [];
11097 Roo.CompositeElement.createCall = function(proto, fnName){
11098 if(!proto[fnName]){
11099 proto[fnName] = function(){
11100 return this.invoke(fnName, arguments);
11104 for(var fnName in Roo.Element.prototype){
11105 if(typeof Roo.Element.prototype[fnName] == "function"){
11106 Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
11112 * Ext JS Library 1.1.1
11113 * Copyright(c) 2006-2007, Ext JS, LLC.
11115 * Originally Released Under LGPL - original licence link has changed is not relivant.
11118 * <script type="text/javascript">
11122 * @class Roo.CompositeElementLite
11123 * @extends Roo.CompositeElement
11124 * Flyweight composite class. Reuses the same Roo.Element for element operations.
11126 var els = Roo.select("#some-el div.some-class");
11127 // or select directly from an existing element
11128 var el = Roo.get('some-el');
11129 el.select('div.some-class');
11131 els.setWidth(100); // all elements become 100 width
11132 els.hide(true); // all elements fade out and hide
11134 els.setWidth(100).hide(true);
11135 </code></pre><br><br>
11136 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
11137 * actions will be performed on all the elements in this collection.</b>
11139 Roo.CompositeElementLite = function(els){
11140 Roo.CompositeElementLite.superclass.constructor.call(this, els);
11141 this.el = new Roo.Element.Flyweight();
11143 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
11144 addElements : function(els){
11146 if(els instanceof Array){
11147 this.elements = this.elements.concat(els);
11149 var yels = this.elements;
11150 var index = yels.length-1;
11151 for(var i = 0, len = els.length; i < len; i++) {
11152 yels[++index] = els[i];
11158 invoke : function(fn, args){
11159 var els = this.elements;
11161 for(var i = 0, len = els.length; i < len; i++) {
11163 Roo.Element.prototype[fn].apply(el, args);
11168 * Returns a flyweight Element of the dom element object at the specified index
11169 * @param {Number} index
11170 * @return {Roo.Element}
11172 item : function(index){
11173 if(!this.elements[index]){
11176 this.el.dom = this.elements[index];
11180 // fixes scope with flyweight
11181 addListener : function(eventName, handler, scope, opt){
11182 var els = this.elements;
11183 for(var i = 0, len = els.length; i < len; i++) {
11184 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
11190 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
11191 * passed is the flyweight (shared) Roo.Element instance, so if you require a
11192 * a reference to the dom node, use el.dom.</b>
11193 * @param {Function} fn The function to call
11194 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11195 * @return {CompositeElement} this
11197 each : function(fn, scope){
11198 var els = this.elements;
11200 for(var i = 0, len = els.length; i < len; i++){
11202 if(fn.call(scope || el, el, this, i) === false){
11209 indexOf : function(el){
11210 return this.elements.indexOf(Roo.getDom(el));
11213 replaceElement : function(el, replacement, domReplace){
11214 var index = typeof el == 'number' ? el : this.indexOf(el);
11216 replacement = Roo.getDom(replacement);
11218 var d = this.elements[index];
11219 d.parentNode.insertBefore(replacement, d);
11220 d.parentNode.removeChild(d);
11222 this.elements.splice(index, 1, replacement);
11227 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
11231 * Ext JS Library 1.1.1
11232 * Copyright(c) 2006-2007, Ext JS, LLC.
11234 * Originally Released Under LGPL - original licence link has changed is not relivant.
11237 * <script type="text/javascript">
11243 * @class Roo.data.Connection
11244 * @extends Roo.util.Observable
11245 * The class encapsulates a connection to the page's originating domain, allowing requests to be made
11246 * either to a configured URL, or to a URL specified at request time.<br><br>
11248 * Requests made by this class are asynchronous, and will return immediately. No data from
11249 * the server will be available to the statement immediately following the {@link #request} call.
11250 * To process returned data, use a callback in the request options object, or an event listener.</p><br>
11252 * Note: If you are doing a file upload, you will not get a normal response object sent back to
11253 * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest.
11254 * The response object is created using the innerHTML of the IFRAME's document as the responseText
11255 * property and, if present, the IFRAME's XML document as the responseXML property.</p><br>
11256 * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested
11257 * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText
11258 * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using
11259 * standard DOM methods.
11261 * @param {Object} config a configuration object.
11263 Roo.data.Connection = function(config){
11264 Roo.apply(this, config);
11267 * @event beforerequest
11268 * Fires before a network request is made to retrieve a data object.
11269 * @param {Connection} conn This Connection object.
11270 * @param {Object} options The options config object passed to the {@link #request} method.
11272 "beforerequest" : true,
11274 * @event requestcomplete
11275 * Fires if the request was successfully completed.
11276 * @param {Connection} conn This Connection object.
11277 * @param {Object} response The XHR object containing the response data.
11278 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11279 * @param {Object} options The options config object passed to the {@link #request} method.
11281 "requestcomplete" : true,
11283 * @event requestexception
11284 * Fires if an error HTTP status was returned from the server.
11285 * See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
11286 * @param {Connection} conn This Connection object.
11287 * @param {Object} response The XHR object containing the response data.
11288 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11289 * @param {Object} options The options config object passed to the {@link #request} method.
11291 "requestexception" : true
11293 Roo.data.Connection.superclass.constructor.call(this);
11296 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
11298 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11301 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11302 * extra parameters to each request made by this object. (defaults to undefined)
11305 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11306 * to each request made by this object. (defaults to undefined)
11309 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11312 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11316 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11322 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11325 disableCaching: true,
11328 * Sends an HTTP request to a remote server.
11329 * @param {Object} options An object which may contain the following properties:<ul>
11330 * <li><b>url</b> {String} (Optional) The URL to which to send the request. Defaults to configured URL</li>
11331 * <li><b>params</b> {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
11332 * request, a url encoded string or a function to call to get either.</li>
11333 * <li><b>method</b> {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or
11334 * if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.</li>
11335 * <li><b>callback</b> {Function} (Optional) The function to be called upon receipt of the HTTP response.
11336 * The callback is called regardless of success or failure and is passed the following parameters:<ul>
11337 * <li>options {Object} The parameter to the request call.</li>
11338 * <li>success {Boolean} True if the request succeeded.</li>
11339 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11341 * <li><b>success</b> {Function} (Optional) The function to be called upon success of the request.
11342 * The callback is passed the following parameters:<ul>
11343 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11344 * <li>options {Object} The parameter to the request call.</li>
11346 * <li><b>failure</b> {Function} (Optional) The function to be called upon failure of the request.
11347 * The callback is passed the following parameters:<ul>
11348 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11349 * <li>options {Object} The parameter to the request call.</li>
11351 * <li><b>scope</b> {Object} (Optional) The scope in which to execute the callbacks: The "this" object
11352 * for the callback function. Defaults to the browser window.</li>
11353 * <li><b>form</b> {Object/String} (Optional) A form object or id to pull parameters from.</li>
11354 * <li><b>isUpload</b> {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).</li>
11355 * <li><b>headers</b> {Object} (Optional) Request headers to set for the request.</li>
11356 * <li><b>xmlData</b> {Object} (Optional) XML document to use for the post. Note: This will be used instead of
11357 * params for the post data. Any params will be appended to the URL.</li>
11358 * <li><b>disableCaching</b> {Boolean} (Optional) True to add a unique cache-buster param to GET requests.</li>
11360 * @return {Number} transactionId
11362 request : function(o){
11363 if(this.fireEvent("beforerequest", this, o) !== false){
11366 if(typeof p == "function"){
11367 p = p.call(o.scope||window, o);
11369 if(typeof p == "object"){
11370 p = Roo.urlEncode(o.params);
11372 if(this.extraParams){
11373 var extras = Roo.urlEncode(this.extraParams);
11374 p = p ? (p + '&' + extras) : extras;
11377 var url = o.url || this.url;
11378 if(typeof url == 'function'){
11379 url = url.call(o.scope||window, o);
11383 var form = Roo.getDom(o.form);
11384 url = url || form.action;
11386 var enctype = form.getAttribute("enctype");
11387 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
11388 return this.doFormUpload(o, p, url);
11390 var f = Roo.lib.Ajax.serializeForm(form);
11391 p = p ? (p + '&' + f) : f;
11394 var hs = o.headers;
11395 if(this.defaultHeaders){
11396 hs = Roo.apply(hs || {}, this.defaultHeaders);
11403 success: this.handleResponse,
11404 failure: this.handleFailure,
11406 argument: {options: o},
11407 timeout : o.timeout || this.timeout
11410 var method = o.method||this.method||(p ? "POST" : "GET");
11412 if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
11413 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
11416 if(typeof o.autoAbort == 'boolean'){ // options gets top priority
11420 }else if(this.autoAbort !== false){
11424 if((method == 'GET' && p) || o.xmlData){
11425 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11428 this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
11429 return this.transId;
11431 Roo.callback(o.callback, o.scope, [o, null, null]);
11437 * Determine whether this object has a request outstanding.
11438 * @param {Number} transactionId (Optional) defaults to the last transaction
11439 * @return {Boolean} True if there is an outstanding request.
11441 isLoading : function(transId){
11443 return Roo.lib.Ajax.isCallInProgress(transId);
11445 return this.transId ? true : false;
11450 * Aborts any outstanding request.
11451 * @param {Number} transactionId (Optional) defaults to the last transaction
11453 abort : function(transId){
11454 if(transId || this.isLoading()){
11455 Roo.lib.Ajax.abort(transId || this.transId);
11460 handleResponse : function(response){
11461 this.transId = false;
11462 var options = response.argument.options;
11463 response.argument = options ? options.argument : null;
11464 this.fireEvent("requestcomplete", this, response, options);
11465 Roo.callback(options.success, options.scope, [response, options]);
11466 Roo.callback(options.callback, options.scope, [options, true, response]);
11470 handleFailure : function(response, e){
11471 this.transId = false;
11472 var options = response.argument.options;
11473 response.argument = options ? options.argument : null;
11474 this.fireEvent("requestexception", this, response, options, e);
11475 Roo.callback(options.failure, options.scope, [response, options]);
11476 Roo.callback(options.callback, options.scope, [options, false, response]);
11480 doFormUpload : function(o, ps, url){
11482 var frame = document.createElement('iframe');
11485 frame.className = 'x-hidden';
11487 frame.src = Roo.SSL_SECURE_URL;
11489 document.body.appendChild(frame);
11492 document.frames[id].name = id;
11495 var form = Roo.getDom(o.form);
11497 form.method = 'POST';
11498 form.enctype = form.encoding = 'multipart/form-data';
11504 if(ps){ // add dynamic params
11506 ps = Roo.urlDecode(ps, false);
11508 if(ps.hasOwnProperty(k)){
11509 hd = document.createElement('input');
11510 hd.type = 'hidden';
11513 form.appendChild(hd);
11520 var r = { // bogus response object
11525 r.argument = o ? o.argument : null;
11530 doc = frame.contentWindow.document;
11532 doc = (frame.contentDocument || window.frames[id].document);
11534 if(doc && doc.body){
11535 r.responseText = doc.body.innerHTML;
11537 if(doc && doc.XMLDocument){
11538 r.responseXML = doc.XMLDocument;
11540 r.responseXML = doc;
11547 Roo.EventManager.removeListener(frame, 'load', cb, this);
11549 this.fireEvent("requestcomplete", this, r, o);
11550 Roo.callback(o.success, o.scope, [r, o]);
11551 Roo.callback(o.callback, o.scope, [o, true, r]);
11553 setTimeout(function(){document.body.removeChild(frame);}, 100);
11556 Roo.EventManager.on(frame, 'load', cb, this);
11559 if(hiddens){ // remove dynamic params
11560 for(var i = 0, len = hiddens.length; i < len; i++){
11561 form.removeChild(hiddens[i]);
11568 * Ext JS Library 1.1.1
11569 * Copyright(c) 2006-2007, Ext JS, LLC.
11571 * Originally Released Under LGPL - original licence link has changed is not relivant.
11574 * <script type="text/javascript">
11578 * Global Ajax request class.
11581 * @extends Roo.data.Connection
11584 * @cfg {String} url The default URL to be used for requests to the server. (defaults to undefined)
11585 * @cfg {Object} extraParams An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
11586 * @cfg {Object} defaultHeaders An object containing request headers which are added to each request made by this object. (defaults to undefined)
11587 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11588 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11589 * @cfg {Boolean} autoAbort (Optional) Whether a new request should abort any pending requests. (defaults to false)
11590 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11592 Roo.Ajax = new Roo.data.Connection({
11601 * Serialize the passed form into a url encoded string
11603 * @param {String/HTMLElement} form
11606 serializeForm : function(form){
11607 return Roo.lib.Ajax.serializeForm(form);
11611 * Ext JS Library 1.1.1
11612 * Copyright(c) 2006-2007, Ext JS, LLC.
11614 * Originally Released Under LGPL - original licence link has changed is not relivant.
11617 * <script type="text/javascript">
11622 * @class Roo.UpdateManager
11623 * @extends Roo.util.Observable
11624 * Provides AJAX-style update for Element object.<br><br>
11627 * // Get it from a Roo.Element object
11628 * var el = Roo.get("foo");
11629 * var mgr = el.getUpdateManager();
11630 * mgr.update("http://myserver.com/index.php", "param1=1&param2=2");
11632 * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
11634 * // or directly (returns the same UpdateManager instance)
11635 * var mgr = new Roo.UpdateManager("myElementId");
11636 * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
11637 * mgr.on("update", myFcnNeedsToKnow);
11639 // short handed call directly from the element object
11640 Roo.get("foo").load({
11644 text: "Loading Foo..."
11648 * Create new UpdateManager directly.
11649 * @param {String/HTMLElement/Roo.Element} el The element to update
11650 * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already has an UpdateManager and if it does it returns the same instance. This will skip that check (useful for extending this class).
11652 Roo.UpdateManager = function(el, forceNew){
11654 if(!forceNew && el.updateManager){
11655 return el.updateManager;
11658 * The Element object
11659 * @type Roo.Element
11663 * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
11666 this.defaultUrl = null;
11670 * @event beforeupdate
11671 * Fired before an update is made, return false from your handler and the update is cancelled.
11672 * @param {Roo.Element} el
11673 * @param {String/Object/Function} url
11674 * @param {String/Object} params
11676 "beforeupdate": true,
11679 * Fired after successful update is made.
11680 * @param {Roo.Element} el
11681 * @param {Object} oResponseObject The response Object
11686 * Fired on update failure.
11687 * @param {Roo.Element} el
11688 * @param {Object} oResponseObject The response Object
11692 var d = Roo.UpdateManager.defaults;
11694 * Blank page URL to use with SSL file uploads (Defaults to Roo.UpdateManager.defaults.sslBlankUrl or "about:blank").
11697 this.sslBlankUrl = d.sslBlankUrl;
11699 * Whether to append unique parameter on get request to disable caching (Defaults to Roo.UpdateManager.defaults.disableCaching or false).
11702 this.disableCaching = d.disableCaching;
11704 * Text for loading indicator (Defaults to Roo.UpdateManager.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>').
11707 this.indicatorText = d.indicatorText;
11709 * Whether to show indicatorText when loading (Defaults to Roo.UpdateManager.defaults.showLoadIndicator or true).
11712 this.showLoadIndicator = d.showLoadIndicator;
11714 * Timeout for requests or form posts in seconds (Defaults to Roo.UpdateManager.defaults.timeout or 30 seconds).
11717 this.timeout = d.timeout;
11720 * True to process scripts in the output (Defaults to Roo.UpdateManager.defaults.loadScripts (false)).
11723 this.loadScripts = d.loadScripts;
11726 * Transaction object of current executing transaction
11728 this.transaction = null;
11733 this.autoRefreshProcId = null;
11735 * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
11738 this.refreshDelegate = this.refresh.createDelegate(this);
11740 * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
11743 this.updateDelegate = this.update.createDelegate(this);
11745 * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
11748 this.formUpdateDelegate = this.formUpdate.createDelegate(this);
11752 this.successDelegate = this.processSuccess.createDelegate(this);
11756 this.failureDelegate = this.processFailure.createDelegate(this);
11758 if(!this.renderer){
11760 * The renderer for this UpdateManager. Defaults to {@link Roo.UpdateManager.BasicRenderer}.
11762 this.renderer = new Roo.UpdateManager.BasicRenderer();
11765 Roo.UpdateManager.superclass.constructor.call(this);
11768 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
11770 * Get the Element this UpdateManager is bound to
11771 * @return {Roo.Element} The element
11773 getEl : function(){
11777 * Performs an async request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
11778 * @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
11781 url: "your-url.php",<br/>
11782 params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
11783 callback: yourFunction,<br/>
11784 scope: yourObject, //(optional scope) <br/>
11785 discardUrl: false, <br/>
11786 nocache: false,<br/>
11787 text: "Loading...",<br/>
11789 scripts: false<br/>
11792 * The only required property is url. The optional properties nocache, text and scripts
11793 * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this UpdateManager instance.
11794 * @param {String/Object} params (optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
11795 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11796 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
11798 update : function(url, params, callback, discardUrl){
11799 if(this.fireEvent("beforeupdate", this.el, url, params) !== false){
11800 var method = this.method,
11802 if(typeof url == "object"){ // must be config object
11805 params = params || cfg.params;
11806 callback = callback || cfg.callback;
11807 discardUrl = discardUrl || cfg.discardUrl;
11808 if(callback && cfg.scope){
11809 callback = callback.createDelegate(cfg.scope);
11811 if(typeof cfg.method != "undefined"){method = cfg.method;};
11812 if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
11813 if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
11814 if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
11815 if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
11817 this.showLoading();
11819 this.defaultUrl = url;
11821 if(typeof url == "function"){
11822 url = url.call(this);
11825 method = method || (params ? "POST" : "GET");
11826 if(method == "GET"){
11827 url = this.prepareUrl(url);
11830 var o = Roo.apply(cfg ||{}, {
11833 success: this.successDelegate,
11834 failure: this.failureDelegate,
11835 callback: undefined,
11836 timeout: (this.timeout*1000),
11837 argument: {"url": url, "form": null, "callback": callback, "params": params}
11839 Roo.log("updated manager called with timeout of " + o.timeout);
11840 this.transaction = Roo.Ajax.request(o);
11845 * Performs an async form post, updating this element with the response. If the form has the attribute enctype="multipart/form-data", it assumes it's a file upload.
11846 * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.
11847 * @param {String/HTMLElement} form The form Id or form element
11848 * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
11849 * @param {Boolean} reset (optional) Whether to try to reset the form after the update
11850 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11852 formUpdate : function(form, url, reset, callback){
11853 if(this.fireEvent("beforeupdate", this.el, form, url) !== false){
11854 if(typeof url == "function"){
11855 url = url.call(this);
11857 form = Roo.getDom(form);
11858 this.transaction = Roo.Ajax.request({
11861 success: this.successDelegate,
11862 failure: this.failureDelegate,
11863 timeout: (this.timeout*1000),
11864 argument: {"url": url, "form": form, "callback": callback, "reset": reset}
11866 this.showLoading.defer(1, this);
11871 * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
11872 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11874 refresh : function(callback){
11875 if(this.defaultUrl == null){
11878 this.update(this.defaultUrl, null, callback, true);
11882 * Set this element to auto refresh.
11883 * @param {Number} interval How often to update (in seconds).
11884 * @param {String/Function} url (optional) The url for this request or a function to call to get the url (Defaults to the last used url)
11885 * @param {String/Object} params (optional) The parameters to pass as either a url encoded string "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2}
11886 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11887 * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
11889 startAutoRefresh : function(interval, url, params, callback, refreshNow){
11891 this.update(url || this.defaultUrl, params, callback, true);
11893 if(this.autoRefreshProcId){
11894 clearInterval(this.autoRefreshProcId);
11896 this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);
11900 * Stop auto refresh on this element.
11902 stopAutoRefresh : function(){
11903 if(this.autoRefreshProcId){
11904 clearInterval(this.autoRefreshProcId);
11905 delete this.autoRefreshProcId;
11909 isAutoRefreshing : function(){
11910 return this.autoRefreshProcId ? true : false;
11913 * Called to update the element to "Loading" state. Override to perform custom action.
11915 showLoading : function(){
11916 if(this.showLoadIndicator){
11917 this.el.update(this.indicatorText);
11922 * Adds unique parameter to query string if disableCaching = true
11925 prepareUrl : function(url){
11926 if(this.disableCaching){
11927 var append = "_dc=" + (new Date().getTime());
11928 if(url.indexOf("?") !== -1){
11929 url += "&" + append;
11931 url += "?" + append;
11940 processSuccess : function(response){
11941 this.transaction = null;
11942 if(response.argument.form && response.argument.reset){
11943 try{ // put in try/catch since some older FF releases had problems with this
11944 response.argument.form.reset();
11947 if(this.loadScripts){
11948 this.renderer.render(this.el, response, this,
11949 this.updateComplete.createDelegate(this, [response]));
11951 this.renderer.render(this.el, response, this);
11952 this.updateComplete(response);
11956 updateComplete : function(response){
11957 this.fireEvent("update", this.el, response);
11958 if(typeof response.argument.callback == "function"){
11959 response.argument.callback(this.el, true, response);
11966 processFailure : function(response){
11967 this.transaction = null;
11968 this.fireEvent("failure", this.el, response);
11969 if(typeof response.argument.callback == "function"){
11970 response.argument.callback(this.el, false, response);
11975 * Set the content renderer for this UpdateManager. See {@link Roo.UpdateManager.BasicRenderer#render} for more details.
11976 * @param {Object} renderer The object implementing the render() method
11978 setRenderer : function(renderer){
11979 this.renderer = renderer;
11982 getRenderer : function(){
11983 return this.renderer;
11987 * Set the defaultUrl used for updates
11988 * @param {String/Function} defaultUrl The url or a function to call to get the url
11990 setDefaultUrl : function(defaultUrl){
11991 this.defaultUrl = defaultUrl;
11995 * Aborts the executing transaction
11997 abort : function(){
11998 if(this.transaction){
11999 Roo.Ajax.abort(this.transaction);
12004 * Returns true if an update is in progress
12005 * @return {Boolean}
12007 isUpdating : function(){
12008 if(this.transaction){
12009 return Roo.Ajax.isLoading(this.transaction);
12016 * @class Roo.UpdateManager.defaults
12017 * @static (not really - but it helps the doc tool)
12018 * The defaults collection enables customizing the default properties of UpdateManager
12020 Roo.UpdateManager.defaults = {
12022 * Timeout for requests or form posts in seconds (Defaults 30 seconds).
12028 * True to process scripts by default (Defaults to false).
12031 loadScripts : false,
12034 * Blank page URL to use with SSL file uploads (Defaults to "javascript:false").
12037 sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
12039 * Whether to append unique parameter on get request to disable caching (Defaults to false).
12042 disableCaching : false,
12044 * Whether to show indicatorText when loading (Defaults to true).
12047 showLoadIndicator : true,
12049 * Text for loading indicator (Defaults to '<div class="loading-indicator">Loading...</div>').
12052 indicatorText : '<div class="loading-indicator">Loading...</div>'
12056 * Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}).
12058 * <pre><code>Roo.UpdateManager.updateElement("my-div", "stuff.php");</code></pre>
12059 * @param {String/HTMLElement/Roo.Element} el The element to update
12060 * @param {String} url The url
12061 * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
12062 * @param {Object} options (optional) A config object with any of the UpdateManager properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}
12065 * @member Roo.UpdateManager
12067 Roo.UpdateManager.updateElement = function(el, url, params, options){
12068 var um = Roo.get(el, true).getUpdateManager();
12069 Roo.apply(um, options);
12070 um.update(url, params, options ? options.callback : null);
12072 // alias for backwards compat
12073 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
12075 * @class Roo.UpdateManager.BasicRenderer
12076 * Default Content renderer. Updates the elements innerHTML with the responseText.
12078 Roo.UpdateManager.BasicRenderer = function(){};
12080 Roo.UpdateManager.BasicRenderer.prototype = {
12082 * This is called when the transaction is completed and it's time to update the element - The BasicRenderer
12083 * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),
12084 * create an object with a "render(el, response)" method and pass it to setRenderer on the UpdateManager.
12085 * @param {Roo.Element} el The element being rendered
12086 * @param {Object} response The YUI Connect response object
12087 * @param {UpdateManager} updateManager The calling update manager
12088 * @param {Function} callback A callback that will need to be called if loadScripts is true on the UpdateManager
12090 render : function(el, response, updateManager, callback){
12091 el.update(response.responseText, updateManager.loadScripts, callback);
12097 * (c)) Alan Knowles
12103 * @class Roo.DomTemplate
12104 * @extends Roo.Template
12105 * An effort at a dom based template engine..
12107 * Similar to XTemplate, except it uses dom parsing to create the template..
12109 * Supported features:
12114 {a_variable} - output encoded.
12115 {a_variable.format:("Y-m-d")} - call a method on the variable
12116 {a_variable:raw} - unencoded output
12117 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
12118 {a_variable:this.method_on_template(...)} - call a method on the template object.
12123 <div roo-for="a_variable or condition.."></div>
12124 <div roo-if="a_variable or condition"></div>
12125 <div roo-exec="some javascript"></div>
12126 <div roo-name="named_template"></div>
12131 Roo.DomTemplate = function()
12133 Roo.DomTemplate.superclass.constructor.apply(this, arguments);
12140 Roo.extend(Roo.DomTemplate, Roo.Template, {
12142 * id counter for sub templates.
12146 * flag to indicate if dom parser is inside a pre,
12147 * it will strip whitespace if not.
12152 * The various sub templates
12160 * basic tag replacing syntax
12163 * // you can fake an object call by doing this
12167 re : /(\{|\%7B)([\w-\.]+)(?:\:([\w\.]*)(?:\(([^)]*?)?\))?)?(\}|\%7D)/g,
12168 //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
12170 iterChild : function (node, method) {
12172 var oldPre = this.inPre;
12173 if (node.tagName == 'PRE') {
12176 for( var i = 0; i < node.childNodes.length; i++) {
12177 method.call(this, node.childNodes[i]);
12179 this.inPre = oldPre;
12185 * compile the template
12187 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
12190 compile: function()
12194 // covert the html into DOM...
12198 doc = document.implementation.createHTMLDocument("");
12199 doc.documentElement.innerHTML = this.html ;
12200 div = doc.documentElement;
12202 // old IE... - nasty -- it causes all sorts of issues.. with
12203 // images getting pulled from server..
12204 div = document.createElement('div');
12205 div.innerHTML = this.html;
12207 //doc.documentElement.innerHTML = htmlBody
12213 this.iterChild(div, function(n) {_t.compileNode(n, true); });
12215 var tpls = this.tpls;
12217 // create a top level template from the snippet..
12219 //Roo.log(div.innerHTML);
12226 body : div.innerHTML,
12239 Roo.each(tpls, function(tp){
12240 this.compileTpl(tp);
12241 this.tpls[tp.id] = tp;
12244 this.master = tpls[0];
12250 compileNode : function(node, istop) {
12255 // skip anything not a tag..
12256 if (node.nodeType != 1) {
12257 if (node.nodeType == 3 && !this.inPre) {
12258 // reduce white space..
12259 node.nodeValue = node.nodeValue.replace(/\s+/g, ' ');
12282 case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
12283 case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
12284 case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
12285 case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
12291 // just itterate children..
12292 this.iterChild(node,this.compileNode);
12295 tpl.uid = this.id++;
12296 tpl.value = node.getAttribute('roo-' + tpl.attr);
12297 node.removeAttribute('roo-'+ tpl.attr);
12298 if (tpl.attr != 'name') {
12299 var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
12300 node.parentNode.replaceChild(placeholder, node);
12303 var placeholder = document.createElement('span');
12304 placeholder.className = 'roo-tpl-' + tpl.value;
12305 node.parentNode.replaceChild(placeholder, node);
12308 // parent now sees '{domtplXXXX}
12309 this.iterChild(node,this.compileNode);
12311 // we should now have node body...
12312 var div = document.createElement('div');
12313 div.appendChild(node);
12315 // this has the unfortunate side effect of converting tagged attributes
12316 // eg. href="{...}" into %7C...%7D
12317 // this has been fixed by searching for those combo's although it's a bit hacky..
12320 tpl.body = div.innerHTML;
12327 switch (tpl.value) {
12328 case '.': tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
12329 case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
12330 default: tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
12335 tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12339 tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12343 tpl.id = tpl.value; // replace non characters???
12349 this.tpls.push(tpl);
12359 * Compile a segment of the template into a 'sub-template'
12365 compileTpl : function(tpl)
12367 var fm = Roo.util.Format;
12368 var useF = this.disableFormats !== true;
12370 var sep = Roo.isGecko ? "+\n" : ",\n";
12372 var undef = function(str) {
12373 Roo.debug && Roo.log("Property not found :" + str);
12377 //Roo.log(tpl.body);
12381 var fn = function(m, lbrace, name, format, args)
12384 //Roo.log(arguments);
12385 args = args ? args.replace(/\\'/g,"'") : args;
12386 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
12387 if (typeof(format) == 'undefined') {
12388 format = 'htmlEncode';
12390 if (format == 'raw' ) {
12394 if(name.substr(0, 6) == 'domtpl'){
12395 return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
12398 // build an array of options to determine if value is undefined..
12400 // basically get 'xxxx.yyyy' then do
12401 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
12402 // (function () { Roo.log("Property not found"); return ''; })() :
12407 Roo.each(name.split('.'), function(st) {
12408 lookfor += (lookfor.length ? '.': '') + st;
12409 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
12412 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
12415 if(format && useF){
12417 args = args ? ',' + args : "";
12419 if(format.substr(0, 5) != "this."){
12420 format = "fm." + format + '(';
12422 format = 'this.call("'+ format.substr(5) + '", ';
12426 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
12429 if (args && args.length) {
12430 // called with xxyx.yuu:(test,test)
12432 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
12434 // raw.. - :raw modifier..
12435 return "'"+ sep + udef_st + name + ")"+sep+"'";
12439 // branched to use + in gecko and [].join() in others
12441 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
12442 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
12445 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
12446 body.push(tpl.body.replace(/(\r\n|\n)/g,
12447 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
12448 body.push("'].join('');};};");
12449 body = body.join('');
12452 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
12454 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
12461 * same as applyTemplate, except it's done to one of the subTemplates
12462 * when using named templates, you can do:
12464 * var str = pl.applySubTemplate('your-name', values);
12467 * @param {Number} id of the template
12468 * @param {Object} values to apply to template
12469 * @param {Object} parent (normaly the instance of this object)
12471 applySubTemplate : function(id, values, parent)
12475 var t = this.tpls[id];
12479 if(t.ifCall && !t.ifCall.call(this, values, parent)){
12480 Roo.debug && Roo.log('if call on ' + t.value + ' return false');
12484 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
12491 if(t.execCall && t.execCall.call(this, values, parent)){
12495 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12501 var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
12502 parent = t.target ? values : parent;
12503 if(t.forCall && vs instanceof Array){
12505 for(var i = 0, len = vs.length; i < len; i++){
12507 buf[buf.length] = t.compiled.call(this, vs[i], parent);
12509 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12511 //Roo.log(t.compiled);
12515 return buf.join('');
12518 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12523 return t.compiled.call(this, vs, parent);
12525 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12527 //Roo.log(t.compiled);
12535 applyTemplate : function(values){
12536 return this.master.compiled.call(this, values, {});
12537 //var s = this.subs;
12540 apply : function(){
12541 return this.applyTemplate.apply(this, arguments);
12546 Roo.DomTemplate.from = function(el){
12547 el = Roo.getDom(el);
12548 return new Roo.Domtemplate(el.value || el.innerHTML);
12551 * Ext JS Library 1.1.1
12552 * Copyright(c) 2006-2007, Ext JS, LLC.
12554 * Originally Released Under LGPL - original licence link has changed is not relivant.
12557 * <script type="text/javascript">
12561 * @class Roo.util.DelayedTask
12562 * Provides a convenient method of performing setTimeout where a new
12563 * timeout cancels the old timeout. An example would be performing validation on a keypress.
12564 * You can use this class to buffer
12565 * the keypress events for a certain number of milliseconds, and perform only if they stop
12566 * for that amount of time.
12567 * @constructor The parameters to this constructor serve as defaults and are not required.
12568 * @param {Function} fn (optional) The default function to timeout
12569 * @param {Object} scope (optional) The default scope of that timeout
12570 * @param {Array} args (optional) The default Array of arguments
12572 Roo.util.DelayedTask = function(fn, scope, args){
12573 var id = null, d, t;
12575 var call = function(){
12576 var now = new Date().getTime();
12580 fn.apply(scope, args || []);
12584 * Cancels any pending timeout and queues a new one
12585 * @param {Number} delay The milliseconds to delay
12586 * @param {Function} newFn (optional) Overrides function passed to constructor
12587 * @param {Object} newScope (optional) Overrides scope passed to constructor
12588 * @param {Array} newArgs (optional) Overrides args passed to constructor
12590 this.delay = function(delay, newFn, newScope, newArgs){
12591 if(id && delay != d){
12595 t = new Date().getTime();
12597 scope = newScope || scope;
12598 args = newArgs || args;
12600 id = setInterval(call, d);
12605 * Cancel the last queued timeout
12607 this.cancel = function(){
12615 * Ext JS Library 1.1.1
12616 * Copyright(c) 2006-2007, Ext JS, LLC.
12618 * Originally Released Under LGPL - original licence link has changed is not relivant.
12621 * <script type="text/javascript">
12625 Roo.util.TaskRunner = function(interval){
12626 interval = interval || 10;
12627 var tasks = [], removeQueue = [];
12629 var running = false;
12631 var stopThread = function(){
12637 var startThread = function(){
12640 id = setInterval(runTasks, interval);
12644 var removeTask = function(task){
12645 removeQueue.push(task);
12651 var runTasks = function(){
12652 if(removeQueue.length > 0){
12653 for(var i = 0, len = removeQueue.length; i < len; i++){
12654 tasks.remove(removeQueue[i]);
12657 if(tasks.length < 1){
12662 var now = new Date().getTime();
12663 for(var i = 0, len = tasks.length; i < len; ++i){
12665 var itime = now - t.taskRunTime;
12666 if(t.interval <= itime){
12667 var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
12668 t.taskRunTime = now;
12669 if(rt === false || t.taskRunCount === t.repeat){
12674 if(t.duration && t.duration <= (now - t.taskStartTime)){
12681 * Queues a new task.
12682 * @param {Object} task
12684 this.start = function(task){
12686 task.taskStartTime = new Date().getTime();
12687 task.taskRunTime = 0;
12688 task.taskRunCount = 0;
12693 this.stop = function(task){
12698 this.stopAll = function(){
12700 for(var i = 0, len = tasks.length; i < len; i++){
12701 if(tasks[i].onStop){
12710 Roo.TaskMgr = new Roo.util.TaskRunner();/*
12712 * Ext JS Library 1.1.1
12713 * Copyright(c) 2006-2007, Ext JS, LLC.
12715 * Originally Released Under LGPL - original licence link has changed is not relivant.
12718 * <script type="text/javascript">
12723 * @class Roo.util.MixedCollection
12724 * @extends Roo.util.Observable
12725 * A Collection class that maintains both numeric indexes and keys and exposes events.
12727 * @param {Boolean} allowFunctions True if the addAll function should add function references to the
12728 * collection (defaults to false)
12729 * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
12730 * and return the key value for that item. This is used when available to look up the key on items that
12731 * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
12732 * equivalent to providing an implementation for the {@link #getKey} method.
12734 Roo.util.MixedCollection = function(allowFunctions, keyFn){
12742 * Fires when the collection is cleared.
12747 * Fires when an item is added to the collection.
12748 * @param {Number} index The index at which the item was added.
12749 * @param {Object} o The item added.
12750 * @param {String} key The key associated with the added item.
12755 * Fires when an item is replaced in the collection.
12756 * @param {String} key he key associated with the new added.
12757 * @param {Object} old The item being replaced.
12758 * @param {Object} new The new item.
12763 * Fires when an item is removed from the collection.
12764 * @param {Object} o The item being removed.
12765 * @param {String} key (optional) The key associated with the removed item.
12770 this.allowFunctions = allowFunctions === true;
12772 this.getKey = keyFn;
12774 Roo.util.MixedCollection.superclass.constructor.call(this);
12777 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
12778 allowFunctions : false,
12781 * Adds an item to the collection.
12782 * @param {String} key The key to associate with the item
12783 * @param {Object} o The item to add.
12784 * @return {Object} The item added.
12786 add : function(key, o){
12787 if(arguments.length == 1){
12789 key = this.getKey(o);
12791 if(typeof key == "undefined" || key === null){
12793 this.items.push(o);
12794 this.keys.push(null);
12796 var old = this.map[key];
12798 return this.replace(key, o);
12801 this.items.push(o);
12803 this.keys.push(key);
12805 this.fireEvent("add", this.length-1, o, key);
12810 * MixedCollection has a generic way to fetch keys if you implement getKey.
12813 var mc = new Roo.util.MixedCollection();
12814 mc.add(someEl.dom.id, someEl);
12815 mc.add(otherEl.dom.id, otherEl);
12819 var mc = new Roo.util.MixedCollection();
12820 mc.getKey = function(el){
12826 // or via the constructor
12827 var mc = new Roo.util.MixedCollection(false, function(el){
12833 * @param o {Object} The item for which to find the key.
12834 * @return {Object} The key for the passed item.
12836 getKey : function(o){
12841 * Replaces an item in the collection.
12842 * @param {String} key The key associated with the item to replace, or the item to replace.
12843 * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
12844 * @return {Object} The new item.
12846 replace : function(key, o){
12847 if(arguments.length == 1){
12849 key = this.getKey(o);
12851 var old = this.item(key);
12852 if(typeof key == "undefined" || key === null || typeof old == "undefined"){
12853 return this.add(key, o);
12855 var index = this.indexOfKey(key);
12856 this.items[index] = o;
12858 this.fireEvent("replace", key, old, o);
12863 * Adds all elements of an Array or an Object to the collection.
12864 * @param {Object/Array} objs An Object containing properties which will be added to the collection, or
12865 * an Array of values, each of which are added to the collection.
12867 addAll : function(objs){
12868 if(arguments.length > 1 || objs instanceof Array){
12869 var args = arguments.length > 1 ? arguments : objs;
12870 for(var i = 0, len = args.length; i < len; i++){
12874 for(var key in objs){
12875 if(this.allowFunctions || typeof objs[key] != "function"){
12876 this.add(key, objs[key]);
12883 * Executes the specified function once for every item in the collection, passing each
12884 * item as the first and only parameter. returning false from the function will stop the iteration.
12885 * @param {Function} fn The function to execute for each item.
12886 * @param {Object} scope (optional) The scope in which to execute the function.
12888 each : function(fn, scope){
12889 var items = [].concat(this.items); // each safe for removal
12890 for(var i = 0, len = items.length; i < len; i++){
12891 if(fn.call(scope || items[i], items[i], i, len) === false){
12898 * Executes the specified function once for every key in the collection, passing each
12899 * key, and its associated item as the first two parameters.
12900 * @param {Function} fn The function to execute for each item.
12901 * @param {Object} scope (optional) The scope in which to execute the function.
12903 eachKey : function(fn, scope){
12904 for(var i = 0, len = this.keys.length; i < len; i++){
12905 fn.call(scope || window, this.keys[i], this.items[i], i, len);
12910 * Returns the first item in the collection which elicits a true return value from the
12911 * passed selection function.
12912 * @param {Function} fn The selection function to execute for each item.
12913 * @param {Object} scope (optional) The scope in which to execute the function.
12914 * @return {Object} The first item in the collection which returned true from the selection function.
12916 find : function(fn, scope){
12917 for(var i = 0, len = this.items.length; i < len; i++){
12918 if(fn.call(scope || window, this.items[i], this.keys[i])){
12919 return this.items[i];
12926 * Inserts an item at the specified index in the collection.
12927 * @param {Number} index The index to insert the item at.
12928 * @param {String} key The key to associate with the new item, or the item itself.
12929 * @param {Object} o (optional) If the second parameter was a key, the new item.
12930 * @return {Object} The item inserted.
12932 insert : function(index, key, o){
12933 if(arguments.length == 2){
12935 key = this.getKey(o);
12937 if(index >= this.length){
12938 return this.add(key, o);
12941 this.items.splice(index, 0, o);
12942 if(typeof key != "undefined" && key != null){
12945 this.keys.splice(index, 0, key);
12946 this.fireEvent("add", index, o, key);
12951 * Removed an item from the collection.
12952 * @param {Object} o The item to remove.
12953 * @return {Object} The item removed.
12955 remove : function(o){
12956 return this.removeAt(this.indexOf(o));
12960 * Remove an item from a specified index in the collection.
12961 * @param {Number} index The index within the collection of the item to remove.
12963 removeAt : function(index){
12964 if(index < this.length && index >= 0){
12966 var o = this.items[index];
12967 this.items.splice(index, 1);
12968 var key = this.keys[index];
12969 if(typeof key != "undefined"){
12970 delete this.map[key];
12972 this.keys.splice(index, 1);
12973 this.fireEvent("remove", o, key);
12978 * Removed an item associated with the passed key fom the collection.
12979 * @param {String} key The key of the item to remove.
12981 removeKey : function(key){
12982 return this.removeAt(this.indexOfKey(key));
12986 * Returns the number of items in the collection.
12987 * @return {Number} the number of items in the collection.
12989 getCount : function(){
12990 return this.length;
12994 * Returns index within the collection of the passed Object.
12995 * @param {Object} o The item to find the index of.
12996 * @return {Number} index of the item.
12998 indexOf : function(o){
12999 if(!this.items.indexOf){
13000 for(var i = 0, len = this.items.length; i < len; i++){
13001 if(this.items[i] == o) return i;
13005 return this.items.indexOf(o);
13010 * Returns index within the collection of the passed key.
13011 * @param {String} key The key to find the index of.
13012 * @return {Number} index of the key.
13014 indexOfKey : function(key){
13015 if(!this.keys.indexOf){
13016 for(var i = 0, len = this.keys.length; i < len; i++){
13017 if(this.keys[i] == key) return i;
13021 return this.keys.indexOf(key);
13026 * Returns the item associated with the passed key OR index. Key has priority over index.
13027 * @param {String/Number} key The key or index of the item.
13028 * @return {Object} The item associated with the passed key.
13030 item : function(key){
13031 var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
13032 return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
13036 * Returns the item at the specified index.
13037 * @param {Number} index The index of the item.
13040 itemAt : function(index){
13041 return this.items[index];
13045 * Returns the item associated with the passed key.
13046 * @param {String/Number} key The key of the item.
13047 * @return {Object} The item associated with the passed key.
13049 key : function(key){
13050 return this.map[key];
13054 * Returns true if the collection contains the passed Object as an item.
13055 * @param {Object} o The Object to look for in the collection.
13056 * @return {Boolean} True if the collection contains the Object as an item.
13058 contains : function(o){
13059 return this.indexOf(o) != -1;
13063 * Returns true if the collection contains the passed Object as a key.
13064 * @param {String} key The key to look for in the collection.
13065 * @return {Boolean} True if the collection contains the Object as a key.
13067 containsKey : function(key){
13068 return typeof this.map[key] != "undefined";
13072 * Removes all items from the collection.
13074 clear : function(){
13079 this.fireEvent("clear");
13083 * Returns the first item in the collection.
13084 * @return {Object} the first item in the collection..
13086 first : function(){
13087 return this.items[0];
13091 * Returns the last item in the collection.
13092 * @return {Object} the last item in the collection..
13095 return this.items[this.length-1];
13098 _sort : function(property, dir, fn){
13099 var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
13100 fn = fn || function(a, b){
13103 var c = [], k = this.keys, items = this.items;
13104 for(var i = 0, len = items.length; i < len; i++){
13105 c[c.length] = {key: k[i], value: items[i], index: i};
13107 c.sort(function(a, b){
13108 var v = fn(a[property], b[property]) * dsc;
13110 v = (a.index < b.index ? -1 : 1);
13114 for(var i = 0, len = c.length; i < len; i++){
13115 items[i] = c[i].value;
13118 this.fireEvent("sort", this);
13122 * Sorts this collection with the passed comparison function
13123 * @param {String} direction (optional) "ASC" or "DESC"
13124 * @param {Function} fn (optional) comparison function
13126 sort : function(dir, fn){
13127 this._sort("value", dir, fn);
13131 * Sorts this collection by keys
13132 * @param {String} direction (optional) "ASC" or "DESC"
13133 * @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
13135 keySort : function(dir, fn){
13136 this._sort("key", dir, fn || function(a, b){
13137 return String(a).toUpperCase()-String(b).toUpperCase();
13142 * Returns a range of items in this collection
13143 * @param {Number} startIndex (optional) defaults to 0
13144 * @param {Number} endIndex (optional) default to the last item
13145 * @return {Array} An array of items
13147 getRange : function(start, end){
13148 var items = this.items;
13149 if(items.length < 1){
13152 start = start || 0;
13153 end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
13156 for(var i = start; i <= end; i++) {
13157 r[r.length] = items[i];
13160 for(var i = start; i >= end; i--) {
13161 r[r.length] = items[i];
13168 * Filter the <i>objects</i> in this collection by a specific property.
13169 * Returns a new collection that has been filtered.
13170 * @param {String} property A property on your objects
13171 * @param {String/RegExp} value Either string that the property values
13172 * should start with or a RegExp to test against the property
13173 * @return {MixedCollection} The new filtered collection
13175 filter : function(property, value){
13176 if(!value.exec){ // not a regex
13177 value = String(value);
13178 if(value.length == 0){
13179 return this.clone();
13181 value = new RegExp("^" + Roo.escapeRe(value), "i");
13183 return this.filterBy(function(o){
13184 return o && value.test(o[property]);
13189 * Filter by a function. * Returns a new collection that has been filtered.
13190 * The passed function will be called with each
13191 * object in the collection. If the function returns true, the value is included
13192 * otherwise it is filtered.
13193 * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
13194 * @param {Object} scope (optional) The scope of the function (defaults to this)
13195 * @return {MixedCollection} The new filtered collection
13197 filterBy : function(fn, scope){
13198 var r = new Roo.util.MixedCollection();
13199 r.getKey = this.getKey;
13200 var k = this.keys, it = this.items;
13201 for(var i = 0, len = it.length; i < len; i++){
13202 if(fn.call(scope||this, it[i], k[i])){
13203 r.add(k[i], it[i]);
13210 * Creates a duplicate of this collection
13211 * @return {MixedCollection}
13213 clone : function(){
13214 var r = new Roo.util.MixedCollection();
13215 var k = this.keys, it = this.items;
13216 for(var i = 0, len = it.length; i < len; i++){
13217 r.add(k[i], it[i]);
13219 r.getKey = this.getKey;
13224 * Returns the item associated with the passed key or index.
13226 * @param {String/Number} key The key or index of the item.
13227 * @return {Object} The item associated with the passed key.
13229 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;/*
13231 * Ext JS Library 1.1.1
13232 * Copyright(c) 2006-2007, Ext JS, LLC.
13234 * Originally Released Under LGPL - original licence link has changed is not relivant.
13237 * <script type="text/javascript">
13240 * @class Roo.util.JSON
13241 * Modified version of Douglas Crockford"s json.js that doesn"t
13242 * mess with the Object prototype
13243 * http://www.json.org/js.html
13246 Roo.util.JSON = new (function(){
13247 var useHasOwn = {}.hasOwnProperty ? true : false;
13249 // crashes Safari in some instances
13250 //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
13252 var pad = function(n) {
13253 return n < 10 ? "0" + n : n;
13266 var encodeString = function(s){
13267 if (/["\\\x00-\x1f]/.test(s)) {
13268 return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
13273 c = b.charCodeAt();
13275 Math.floor(c / 16).toString(16) +
13276 (c % 16).toString(16);
13279 return '"' + s + '"';
13282 var encodeArray = function(o){
13283 var a = ["["], b, i, l = o.length, v;
13284 for (i = 0; i < l; i += 1) {
13286 switch (typeof v) {
13295 a.push(v === null ? "null" : Roo.util.JSON.encode(v));
13303 var encodeDate = function(o){
13304 return '"' + o.getFullYear() + "-" +
13305 pad(o.getMonth() + 1) + "-" +
13306 pad(o.getDate()) + "T" +
13307 pad(o.getHours()) + ":" +
13308 pad(o.getMinutes()) + ":" +
13309 pad(o.getSeconds()) + '"';
13313 * Encodes an Object, Array or other value
13314 * @param {Mixed} o The variable to encode
13315 * @return {String} The JSON string
13317 this.encode = function(o)
13319 // should this be extended to fully wrap stringify..
13321 if(typeof o == "undefined" || o === null){
13323 }else if(o instanceof Array){
13324 return encodeArray(o);
13325 }else if(o instanceof Date){
13326 return encodeDate(o);
13327 }else if(typeof o == "string"){
13328 return encodeString(o);
13329 }else if(typeof o == "number"){
13330 return isFinite(o) ? String(o) : "null";
13331 }else if(typeof o == "boolean"){
13334 var a = ["{"], b, i, v;
13336 if(!useHasOwn || o.hasOwnProperty(i)) {
13338 switch (typeof v) {
13347 a.push(this.encode(i), ":",
13348 v === null ? "null" : this.encode(v));
13359 * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
13360 * @param {String} json The JSON string
13361 * @return {Object} The resulting object
13363 this.decode = function(json){
13365 return /** eval:var:json */ eval("(" + json + ')');
13369 * Shorthand for {@link Roo.util.JSON#encode}
13370 * @member Roo encode
13372 Roo.encode = typeof(JSON) != 'undefined' && JSON.stringify ? JSON.stringify : Roo.util.JSON.encode;
13374 * Shorthand for {@link Roo.util.JSON#decode}
13375 * @member Roo decode
13377 Roo.decode = typeof(JSON) != 'undefined' && JSON.parse ? JSON.parse : Roo.util.JSON.decode;
13380 * Ext JS Library 1.1.1
13381 * Copyright(c) 2006-2007, Ext JS, LLC.
13383 * Originally Released Under LGPL - original licence link has changed is not relivant.
13386 * <script type="text/javascript">
13390 * @class Roo.util.Format
13391 * Reusable data formatting functions
13394 Roo.util.Format = function(){
13395 var trimRe = /^\s+|\s+$/g;
13398 * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
13399 * @param {String} value The string to truncate
13400 * @param {Number} length The maximum length to allow before truncating
13401 * @return {String} The converted text
13403 ellipsis : function(value, len){
13404 if(value && value.length > len){
13405 return value.substr(0, len-3)+"...";
13411 * Checks a reference and converts it to empty string if it is undefined
13412 * @param {Mixed} value Reference to check
13413 * @return {Mixed} Empty string if converted, otherwise the original value
13415 undef : function(value){
13416 return typeof value != "undefined" ? value : "";
13420 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
13421 * @param {String} value The string to encode
13422 * @return {String} The encoded text
13424 htmlEncode : function(value){
13425 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
13429 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
13430 * @param {String} value The string to decode
13431 * @return {String} The decoded text
13433 htmlDecode : function(value){
13434 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
13438 * Trims any whitespace from either side of a string
13439 * @param {String} value The text to trim
13440 * @return {String} The trimmed text
13442 trim : function(value){
13443 return String(value).replace(trimRe, "");
13447 * Returns a substring from within an original string
13448 * @param {String} value The original text
13449 * @param {Number} start The start index of the substring
13450 * @param {Number} length The length of the substring
13451 * @return {String} The substring
13453 substr : function(value, start, length){
13454 return String(value).substr(start, length);
13458 * Converts a string to all lower case letters
13459 * @param {String} value The text to convert
13460 * @return {String} The converted text
13462 lowercase : function(value){
13463 return String(value).toLowerCase();
13467 * Converts a string to all upper case letters
13468 * @param {String} value The text to convert
13469 * @return {String} The converted text
13471 uppercase : function(value){
13472 return String(value).toUpperCase();
13476 * Converts the first character only of a string to upper case
13477 * @param {String} value The text to convert
13478 * @return {String} The converted text
13480 capitalize : function(value){
13481 return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
13485 call : function(value, fn){
13486 if(arguments.length > 2){
13487 var args = Array.prototype.slice.call(arguments, 2);
13488 args.unshift(value);
13490 return /** eval:var:value */ eval(fn).apply(window, args);
13492 /** eval:var:value */
13493 return /** eval:var:value */ eval(fn).call(window, value);
13499 * safer version of Math.toFixed..??/
13500 * @param {Number/String} value The numeric value to format
13501 * @param {Number/String} value Decimal places
13502 * @return {String} The formatted currency string
13504 toFixed : function(v, n)
13506 // why not use to fixed - precision is buggered???
13508 return Math.round(v-0);
13510 var fact = Math.pow(10,n+1);
13511 v = (Math.round((v-0)*fact))/fact;
13512 var z = (''+fact).substring(2);
13513 if (v == Math.floor(v)) {
13514 return Math.floor(v) + '.' + z;
13517 // now just padd decimals..
13518 var ps = String(v).split('.');
13519 var fd = (ps[1] + z);
13520 var r = fd.substring(0,n);
13521 var rm = fd.substring(n);
13523 return ps[0] + '.' + r;
13525 r*=1; // turn it into a number;
13527 if (String(r).length != n) {
13530 r = String(r).substring(1); // chop the end off.
13533 return ps[0] + '.' + r;
13538 * Format a number as US currency
13539 * @param {Number/String} value The numeric value to format
13540 * @return {String} The formatted currency string
13542 usMoney : function(v){
13543 return '$' + Roo.util.Format.number(v);
13548 * eventually this should probably emulate php's number_format
13549 * @param {Number/String} value The numeric value to format
13550 * @param {Number} decimals number of decimal places
13551 * @return {String} The formatted currency string
13553 number : function(v,decimals)
13555 // multiply and round.
13556 decimals = typeof(decimals) == 'undefined' ? 2 : decimals;
13557 var mul = Math.pow(10, decimals);
13558 var zero = String(mul).substring(1);
13559 v = (Math.round((v-0)*mul))/mul;
13561 // if it's '0' number.. then
13563 //v = (v == Math.floor(v)) ? v + "." + zero : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
13565 var ps = v.split('.');
13569 var r = /(\d+)(\d{3})/;
13571 while (r.test(whole)) {
13572 whole = whole.replace(r, '$1' + ',' + '$2');
13578 (decimals ? ('.'+ ps[1] + zero.substring(ps[1].length)) : '') :
13579 // does not have decimals
13580 (decimals ? ('.' + zero) : '');
13583 return whole + sub ;
13587 * Parse a value into a formatted date using the specified format pattern.
13588 * @param {Mixed} value The value to format
13589 * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
13590 * @return {String} The formatted date string
13592 date : function(v, format){
13596 if(!(v instanceof Date)){
13597 v = new Date(Date.parse(v));
13599 return v.dateFormat(format || "m/d/Y");
13603 * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
13604 * @param {String} format Any valid date format string
13605 * @return {Function} The date formatting function
13607 dateRenderer : function(format){
13608 return function(v){
13609 return Roo.util.Format.date(v, format);
13614 stripTagsRE : /<\/?[^>]+>/gi,
13617 * Strips all HTML tags
13618 * @param {Mixed} value The text from which to strip tags
13619 * @return {String} The stripped text
13621 stripTags : function(v){
13622 return !v ? v : String(v).replace(this.stripTagsRE, "");
13627 * Ext JS Library 1.1.1
13628 * Copyright(c) 2006-2007, Ext JS, LLC.
13630 * Originally Released Under LGPL - original licence link has changed is not relivant.
13633 * <script type="text/javascript">
13640 * @class Roo.MasterTemplate
13641 * @extends Roo.Template
13642 * Provides a template that can have child templates. The syntax is:
13644 var t = new Roo.MasterTemplate(
13645 '<select name="{name}">',
13646 '<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
13649 t.add('options', {value: 'foo', text: 'bar'});
13650 // or you can add multiple child elements in one shot
13651 t.addAll('options', [
13652 {value: 'foo', text: 'bar'},
13653 {value: 'foo2', text: 'bar2'},
13654 {value: 'foo3', text: 'bar3'}
13656 // then append, applying the master template values
13657 t.append('my-form', {name: 'my-select'});
13659 * A name attribute for the child template is not required if you have only one child
13660 * template or you want to refer to them by index.
13662 Roo.MasterTemplate = function(){
13663 Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
13664 this.originalHtml = this.html;
13666 var m, re = this.subTemplateRe;
13669 while(m = re.exec(this.html)){
13670 var name = m[1], content = m[2];
13675 tpl : new Roo.Template(content)
13678 st[name] = st[subIndex];
13680 st[subIndex].tpl.compile();
13681 st[subIndex].tpl.call = this.call.createDelegate(this);
13684 this.subCount = subIndex;
13687 Roo.extend(Roo.MasterTemplate, Roo.Template, {
13689 * The regular expression used to match sub templates
13693 subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
13696 * Applies the passed values to a child template.
13697 * @param {String/Number} name (optional) The name or index of the child template
13698 * @param {Array/Object} values The values to be applied to the template
13699 * @return {MasterTemplate} this
13701 add : function(name, values){
13702 if(arguments.length == 1){
13703 values = arguments[0];
13706 var s = this.subs[name];
13707 s.buffer[s.buffer.length] = s.tpl.apply(values);
13712 * Applies all the passed values to a child template.
13713 * @param {String/Number} name (optional) The name or index of the child template
13714 * @param {Array} values The values to be applied to the template, this should be an array of objects.
13715 * @param {Boolean} reset (optional) True to reset the template first
13716 * @return {MasterTemplate} this
13718 fill : function(name, values, reset){
13720 if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
13728 for(var i = 0, len = values.length; i < len; i++){
13729 this.add(name, values[i]);
13735 * Resets the template for reuse
13736 * @return {MasterTemplate} this
13738 reset : function(){
13740 for(var i = 0; i < this.subCount; i++){
13746 applyTemplate : function(values){
13748 var replaceIndex = -1;
13749 this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
13750 return s[++replaceIndex].buffer.join("");
13752 return Roo.MasterTemplate.superclass.applyTemplate.call(this, values);
13755 apply : function(){
13756 return this.applyTemplate.apply(this, arguments);
13759 compile : function(){return this;}
13763 * Alias for fill().
13766 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
13768 * Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
13769 * var tpl = Roo.MasterTemplate.from('element-id');
13770 * @param {String/HTMLElement} el
13771 * @param {Object} config
13774 Roo.MasterTemplate.from = function(el, config){
13775 el = Roo.getDom(el);
13776 return new Roo.MasterTemplate(el.value || el.innerHTML, config || '');
13779 * Ext JS Library 1.1.1
13780 * Copyright(c) 2006-2007, Ext JS, LLC.
13782 * Originally Released Under LGPL - original licence link has changed is not relivant.
13785 * <script type="text/javascript">
13790 * @class Roo.util.CSS
13791 * Utility class for manipulating CSS rules
13794 Roo.util.CSS = function(){
13796 var doc = document;
13798 var camelRe = /(-[a-z])/gi;
13799 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
13803 * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
13804 * tag and appended to the HEAD of the document.
13805 * @param {String|Object} cssText The text containing the css rules
13806 * @param {String} id An id to add to the stylesheet for later removal
13807 * @return {StyleSheet}
13809 createStyleSheet : function(cssText, id){
13811 var head = doc.getElementsByTagName("head")[0];
13812 var nrules = doc.createElement("style");
13813 nrules.setAttribute("type", "text/css");
13815 nrules.setAttribute("id", id);
13817 if (typeof(cssText) != 'string') {
13818 // support object maps..
13819 // not sure if this a good idea..
13820 // perhaps it should be merged with the general css handling
13821 // and handle js style props.
13822 var cssTextNew = [];
13823 for(var n in cssText) {
13825 for(var k in cssText[n]) {
13826 citems.push( k + ' : ' +cssText[n][k] + ';' );
13828 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
13831 cssText = cssTextNew.join("\n");
13837 head.appendChild(nrules);
13838 ss = nrules.styleSheet;
13839 ss.cssText = cssText;
13842 nrules.appendChild(doc.createTextNode(cssText));
13844 nrules.cssText = cssText;
13846 head.appendChild(nrules);
13847 ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
13849 this.cacheStyleSheet(ss);
13854 * Removes a style or link tag by id
13855 * @param {String} id The id of the tag
13857 removeStyleSheet : function(id){
13858 var existing = doc.getElementById(id);
13860 existing.parentNode.removeChild(existing);
13865 * Dynamically swaps an existing stylesheet reference for a new one
13866 * @param {String} id The id of an existing link tag to remove
13867 * @param {String} url The href of the new stylesheet to include
13869 swapStyleSheet : function(id, url){
13870 this.removeStyleSheet(id);
13871 var ss = doc.createElement("link");
13872 ss.setAttribute("rel", "stylesheet");
13873 ss.setAttribute("type", "text/css");
13874 ss.setAttribute("id", id);
13875 ss.setAttribute("href", url);
13876 doc.getElementsByTagName("head")[0].appendChild(ss);
13880 * Refresh the rule cache if you have dynamically added stylesheets
13881 * @return {Object} An object (hash) of rules indexed by selector
13883 refreshCache : function(){
13884 return this.getRules(true);
13888 cacheStyleSheet : function(stylesheet){
13892 try{// try catch for cross domain access issue
13893 var ssRules = stylesheet.cssRules || stylesheet.rules;
13894 for(var j = ssRules.length-1; j >= 0; --j){
13895 rules[ssRules[j].selectorText] = ssRules[j];
13901 * Gets all css rules for the document
13902 * @param {Boolean} refreshCache true to refresh the internal cache
13903 * @return {Object} An object (hash) of rules indexed by selector
13905 getRules : function(refreshCache){
13906 if(rules == null || refreshCache){
13908 var ds = doc.styleSheets;
13909 for(var i =0, len = ds.length; i < len; i++){
13911 this.cacheStyleSheet(ds[i]);
13919 * Gets an an individual CSS rule by selector(s)
13920 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
13921 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
13922 * @return {CSSRule} The CSS rule or null if one is not found
13924 getRule : function(selector, refreshCache){
13925 var rs = this.getRules(refreshCache);
13926 if(!(selector instanceof Array)){
13927 return rs[selector];
13929 for(var i = 0; i < selector.length; i++){
13930 if(rs[selector[i]]){
13931 return rs[selector[i]];
13939 * Updates a rule property
13940 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
13941 * @param {String} property The css property
13942 * @param {String} value The new value for the property
13943 * @return {Boolean} true If a rule was found and updated
13945 updateRule : function(selector, property, value){
13946 if(!(selector instanceof Array)){
13947 var rule = this.getRule(selector);
13949 rule.style[property.replace(camelRe, camelFn)] = value;
13953 for(var i = 0; i < selector.length; i++){
13954 if(this.updateRule(selector[i], property, value)){
13964 * Ext JS Library 1.1.1
13965 * Copyright(c) 2006-2007, Ext JS, LLC.
13967 * Originally Released Under LGPL - original licence link has changed is not relivant.
13970 * <script type="text/javascript">
13976 * @class Roo.util.ClickRepeater
13977 * @extends Roo.util.Observable
13979 * A wrapper class which can be applied to any element. Fires a "click" event while the
13980 * mouse is pressed. The interval between firings may be specified in the config but
13981 * defaults to 10 milliseconds.
13983 * Optionally, a CSS class may be applied to the element during the time it is pressed.
13985 * @cfg {String/HTMLElement/Element} el The element to act as a button.
13986 * @cfg {Number} delay The initial delay before the repeating event begins firing.
13987 * Similar to an autorepeat key delay.
13988 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
13989 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
13990 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
13991 * "interval" and "delay" are ignored. "immediate" is honored.
13992 * @cfg {Boolean} preventDefault True to prevent the default click event
13993 * @cfg {Boolean} stopDefault True to stop the default click event
13996 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
13997 * 2007-02-02 jvs Renamed to ClickRepeater
13998 * 2007-02-03 jvs Modifications for FF Mac and Safari
14001 * @param {String/HTMLElement/Element} el The element to listen on
14002 * @param {Object} config
14004 Roo.util.ClickRepeater = function(el, config)
14006 this.el = Roo.get(el);
14007 this.el.unselectable();
14009 Roo.apply(this, config);
14014 * Fires when the mouse button is depressed.
14015 * @param {Roo.util.ClickRepeater} this
14017 "mousedown" : true,
14020 * Fires on a specified interval during the time the element is pressed.
14021 * @param {Roo.util.ClickRepeater} this
14026 * Fires when the mouse key is released.
14027 * @param {Roo.util.ClickRepeater} this
14032 this.el.on("mousedown", this.handleMouseDown, this);
14033 if(this.preventDefault || this.stopDefault){
14034 this.el.on("click", function(e){
14035 if(this.preventDefault){
14036 e.preventDefault();
14038 if(this.stopDefault){
14044 // allow inline handler
14046 this.on("click", this.handler, this.scope || this);
14049 Roo.util.ClickRepeater.superclass.constructor.call(this);
14052 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
14055 preventDefault : true,
14056 stopDefault : false,
14060 handleMouseDown : function(){
14061 clearTimeout(this.timer);
14063 if(this.pressClass){
14064 this.el.addClass(this.pressClass);
14066 this.mousedownTime = new Date();
14068 Roo.get(document).on("mouseup", this.handleMouseUp, this);
14069 this.el.on("mouseout", this.handleMouseOut, this);
14071 this.fireEvent("mousedown", this);
14072 this.fireEvent("click", this);
14074 this.timer = this.click.defer(this.delay || this.interval, this);
14078 click : function(){
14079 this.fireEvent("click", this);
14080 this.timer = this.click.defer(this.getInterval(), this);
14084 getInterval: function(){
14085 if(!this.accelerate){
14086 return this.interval;
14088 var pressTime = this.mousedownTime.getElapsed();
14089 if(pressTime < 500){
14091 }else if(pressTime < 1700){
14093 }else if(pressTime < 2600){
14095 }else if(pressTime < 3500){
14097 }else if(pressTime < 4400){
14099 }else if(pressTime < 5300){
14101 }else if(pressTime < 6200){
14109 handleMouseOut : function(){
14110 clearTimeout(this.timer);
14111 if(this.pressClass){
14112 this.el.removeClass(this.pressClass);
14114 this.el.on("mouseover", this.handleMouseReturn, this);
14118 handleMouseReturn : function(){
14119 this.el.un("mouseover", this.handleMouseReturn);
14120 if(this.pressClass){
14121 this.el.addClass(this.pressClass);
14127 handleMouseUp : function(){
14128 clearTimeout(this.timer);
14129 this.el.un("mouseover", this.handleMouseReturn);
14130 this.el.un("mouseout", this.handleMouseOut);
14131 Roo.get(document).un("mouseup", this.handleMouseUp);
14132 this.el.removeClass(this.pressClass);
14133 this.fireEvent("mouseup", this);
14137 * Ext JS Library 1.1.1
14138 * Copyright(c) 2006-2007, Ext JS, LLC.
14140 * Originally Released Under LGPL - original licence link has changed is not relivant.
14143 * <script type="text/javascript">
14148 * @class Roo.KeyNav
14149 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
14150 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
14151 * way to implement custom navigation schemes for any UI component.</p>
14152 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
14153 * pageUp, pageDown, del, home, end. Usage:</p>
14155 var nav = new Roo.KeyNav("my-element", {
14156 "left" : function(e){
14157 this.moveLeft(e.ctrlKey);
14159 "right" : function(e){
14160 this.moveRight(e.ctrlKey);
14162 "enter" : function(e){
14169 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14170 * @param {Object} config The config
14172 Roo.KeyNav = function(el, config){
14173 this.el = Roo.get(el);
14174 Roo.apply(this, config);
14175 if(!this.disabled){
14176 this.disabled = true;
14181 Roo.KeyNav.prototype = {
14183 * @cfg {Boolean} disabled
14184 * True to disable this KeyNav instance (defaults to false)
14188 * @cfg {String} defaultEventAction
14189 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
14190 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
14191 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
14193 defaultEventAction: "stopEvent",
14195 * @cfg {Boolean} forceKeyDown
14196 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
14197 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
14198 * handle keydown instead of keypress.
14200 forceKeyDown : false,
14203 prepareEvent : function(e){
14204 var k = e.getKey();
14205 var h = this.keyToHandler[k];
14206 //if(h && this[h]){
14207 // e.stopPropagation();
14209 if(Roo.isSafari && h && k >= 37 && k <= 40){
14215 relay : function(e){
14216 var k = e.getKey();
14217 var h = this.keyToHandler[k];
14219 if(this.doRelay(e, this[h], h) !== true){
14220 e[this.defaultEventAction]();
14226 doRelay : function(e, h, hname){
14227 return h.call(this.scope || this, e);
14230 // possible handlers
14244 // quick lookup hash
14261 * Enable this KeyNav
14263 enable: function(){
14265 // ie won't do special keys on keypress, no one else will repeat keys with keydown
14266 // the EventObject will normalize Safari automatically
14267 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14268 this.el.on("keydown", this.relay, this);
14270 this.el.on("keydown", this.prepareEvent, this);
14271 this.el.on("keypress", this.relay, this);
14273 this.disabled = false;
14278 * Disable this KeyNav
14280 disable: function(){
14281 if(!this.disabled){
14282 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14283 this.el.un("keydown", this.relay);
14285 this.el.un("keydown", this.prepareEvent);
14286 this.el.un("keypress", this.relay);
14288 this.disabled = true;
14293 * Ext JS Library 1.1.1
14294 * Copyright(c) 2006-2007, Ext JS, LLC.
14296 * Originally Released Under LGPL - original licence link has changed is not relivant.
14299 * <script type="text/javascript">
14304 * @class Roo.KeyMap
14305 * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
14306 * The constructor accepts the same config object as defined by {@link #addBinding}.
14307 * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
14308 * combination it will call the function with this signature (if the match is a multi-key
14309 * combination the callback will still be called only once): (String key, Roo.EventObject e)
14310 * A KeyMap can also handle a string representation of keys.<br />
14313 // map one key by key code
14314 var map = new Roo.KeyMap("my-element", {
14315 key: 13, // or Roo.EventObject.ENTER
14320 // map multiple keys to one action by string
14321 var map = new Roo.KeyMap("my-element", {
14327 // map multiple keys to multiple actions by strings and array of codes
14328 var map = new Roo.KeyMap("my-element", [
14331 fn: function(){ alert("Return was pressed"); }
14334 fn: function(){ alert('a, b or c was pressed'); }
14339 fn: function(){ alert('Control + shift + tab was pressed.'); }
14343 * <b>Note: A KeyMap starts enabled</b>
14345 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14346 * @param {Object} config The config (see {@link #addBinding})
14347 * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
14349 Roo.KeyMap = function(el, config, eventName){
14350 this.el = Roo.get(el);
14351 this.eventName = eventName || "keydown";
14352 this.bindings = [];
14354 this.addBinding(config);
14359 Roo.KeyMap.prototype = {
14361 * True to stop the event from bubbling and prevent the default browser action if the
14362 * key was handled by the KeyMap (defaults to false)
14368 * Add a new binding to this KeyMap. The following config object properties are supported:
14370 Property Type Description
14371 ---------- --------------- ----------------------------------------------------------------------
14372 key String/Array A single keycode or an array of keycodes to handle
14373 shift Boolean True to handle key only when shift is pressed (defaults to false)
14374 ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
14375 alt Boolean True to handle key only when alt is pressed (defaults to false)
14376 fn Function The function to call when KeyMap finds the expected key combination
14377 scope Object The scope of the callback function
14383 var map = new Roo.KeyMap(document, {
14384 key: Roo.EventObject.ENTER,
14389 //Add a new binding to the existing KeyMap later
14397 * @param {Object/Array} config A single KeyMap config or an array of configs
14399 addBinding : function(config){
14400 if(config instanceof Array){
14401 for(var i = 0, len = config.length; i < len; i++){
14402 this.addBinding(config[i]);
14406 var keyCode = config.key,
14407 shift = config.shift,
14408 ctrl = config.ctrl,
14411 scope = config.scope;
14412 if(typeof keyCode == "string"){
14414 var keyString = keyCode.toUpperCase();
14415 for(var j = 0, len = keyString.length; j < len; j++){
14416 ks.push(keyString.charCodeAt(j));
14420 var keyArray = keyCode instanceof Array;
14421 var handler = function(e){
14422 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14423 var k = e.getKey();
14425 for(var i = 0, len = keyCode.length; i < len; i++){
14426 if(keyCode[i] == k){
14427 if(this.stopEvent){
14430 fn.call(scope || window, k, e);
14436 if(this.stopEvent){
14439 fn.call(scope || window, k, e);
14444 this.bindings.push(handler);
14448 * Shorthand for adding a single key listener
14449 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
14450 * following options:
14451 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14452 * @param {Function} fn The function to call
14453 * @param {Object} scope (optional) The scope of the function
14455 on : function(key, fn, scope){
14456 var keyCode, shift, ctrl, alt;
14457 if(typeof key == "object" && !(key instanceof Array)){
14476 handleKeyDown : function(e){
14477 if(this.enabled){ //just in case
14478 var b = this.bindings;
14479 for(var i = 0, len = b.length; i < len; i++){
14480 b[i].call(this, e);
14486 * Returns true if this KeyMap is enabled
14487 * @return {Boolean}
14489 isEnabled : function(){
14490 return this.enabled;
14494 * Enables this KeyMap
14496 enable: function(){
14498 this.el.on(this.eventName, this.handleKeyDown, this);
14499 this.enabled = true;
14504 * Disable this KeyMap
14506 disable: function(){
14508 this.el.removeListener(this.eventName, this.handleKeyDown, this);
14509 this.enabled = false;
14514 * Ext JS Library 1.1.1
14515 * Copyright(c) 2006-2007, Ext JS, LLC.
14517 * Originally Released Under LGPL - original licence link has changed is not relivant.
14520 * <script type="text/javascript">
14525 * @class Roo.util.TextMetrics
14526 * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
14527 * wide, in pixels, a given block of text will be.
14530 Roo.util.TextMetrics = function(){
14534 * Measures the size of the specified text
14535 * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
14536 * that can affect the size of the rendered text
14537 * @param {String} text The text to measure
14538 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14539 * in order to accurately measure the text height
14540 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14542 measure : function(el, text, fixedWidth){
14544 shared = Roo.util.TextMetrics.Instance(el, fixedWidth);
14547 shared.setFixedWidth(fixedWidth || 'auto');
14548 return shared.getSize(text);
14552 * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
14553 * the overhead of multiple calls to initialize the style properties on each measurement.
14554 * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
14555 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14556 * in order to accurately measure the text height
14557 * @return {Roo.util.TextMetrics.Instance} instance The new instance
14559 createInstance : function(el, fixedWidth){
14560 return Roo.util.TextMetrics.Instance(el, fixedWidth);
14567 Roo.util.TextMetrics.Instance = function(bindTo, fixedWidth){
14568 var ml = new Roo.Element(document.createElement('div'));
14569 document.body.appendChild(ml.dom);
14570 ml.position('absolute');
14571 ml.setLeftTop(-1000, -1000);
14575 ml.setWidth(fixedWidth);
14580 * Returns the size of the specified text based on the internal element's style and width properties
14581 * @memberOf Roo.util.TextMetrics.Instance#
14582 * @param {String} text The text to measure
14583 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14585 getSize : function(text){
14587 var s = ml.getSize();
14593 * Binds this TextMetrics instance to an element from which to copy existing CSS styles
14594 * that can affect the size of the rendered text
14595 * @memberOf Roo.util.TextMetrics.Instance#
14596 * @param {String/HTMLElement} el The element, dom node or id
14598 bind : function(el){
14600 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
14605 * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
14606 * to set a fixed width in order to accurately measure the text height.
14607 * @memberOf Roo.util.TextMetrics.Instance#
14608 * @param {Number} width The width to set on the element
14610 setFixedWidth : function(width){
14611 ml.setWidth(width);
14615 * Returns the measured width of the specified text
14616 * @memberOf Roo.util.TextMetrics.Instance#
14617 * @param {String} text The text to measure
14618 * @return {Number} width The width in pixels
14620 getWidth : function(text){
14621 ml.dom.style.width = 'auto';
14622 return this.getSize(text).width;
14626 * Returns the measured height of the specified text. For multiline text, be sure to call
14627 * {@link #setFixedWidth} if necessary.
14628 * @memberOf Roo.util.TextMetrics.Instance#
14629 * @param {String} text The text to measure
14630 * @return {Number} height The height in pixels
14632 getHeight : function(text){
14633 return this.getSize(text).height;
14637 instance.bind(bindTo);
14642 // backwards compat
14643 Roo.Element.measureText = Roo.util.TextMetrics.measure;/*
14645 * Ext JS Library 1.1.1
14646 * Copyright(c) 2006-2007, Ext JS, LLC.
14648 * Originally Released Under LGPL - original licence link has changed is not relivant.
14651 * <script type="text/javascript">
14655 * @class Roo.state.Provider
14656 * Abstract base class for state provider implementations. This class provides methods
14657 * for encoding and decoding <b>typed</b> variables including dates and defines the
14658 * Provider interface.
14660 Roo.state.Provider = function(){
14662 * @event statechange
14663 * Fires when a state change occurs.
14664 * @param {Provider} this This state provider
14665 * @param {String} key The state key which was changed
14666 * @param {String} value The encoded value for the state
14669 "statechange": true
14672 Roo.state.Provider.superclass.constructor.call(this);
14674 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
14676 * Returns the current value for a key
14677 * @param {String} name The key name
14678 * @param {Mixed} defaultValue A default value to return if the key's value is not found
14679 * @return {Mixed} The state data
14681 get : function(name, defaultValue){
14682 return typeof this.state[name] == "undefined" ?
14683 defaultValue : this.state[name];
14687 * Clears a value from the state
14688 * @param {String} name The key name
14690 clear : function(name){
14691 delete this.state[name];
14692 this.fireEvent("statechange", this, name, null);
14696 * Sets the value for a key
14697 * @param {String} name The key name
14698 * @param {Mixed} value The value to set
14700 set : function(name, value){
14701 this.state[name] = value;
14702 this.fireEvent("statechange", this, name, value);
14706 * Decodes a string previously encoded with {@link #encodeValue}.
14707 * @param {String} value The value to decode
14708 * @return {Mixed} The decoded value
14710 decodeValue : function(cookie){
14711 var re = /^(a|n|d|b|s|o)\:(.*)$/;
14712 var matches = re.exec(unescape(cookie));
14713 if(!matches || !matches[1]) return; // non state cookie
14714 var type = matches[1];
14715 var v = matches[2];
14718 return parseFloat(v);
14720 return new Date(Date.parse(v));
14725 var values = v.split("^");
14726 for(var i = 0, len = values.length; i < len; i++){
14727 all.push(this.decodeValue(values[i]));
14732 var values = v.split("^");
14733 for(var i = 0, len = values.length; i < len; i++){
14734 var kv = values[i].split("=");
14735 all[kv[0]] = this.decodeValue(kv[1]);
14744 * Encodes a value including type information. Decode with {@link #decodeValue}.
14745 * @param {Mixed} value The value to encode
14746 * @return {String} The encoded value
14748 encodeValue : function(v){
14750 if(typeof v == "number"){
14752 }else if(typeof v == "boolean"){
14753 enc = "b:" + (v ? "1" : "0");
14754 }else if(v instanceof Date){
14755 enc = "d:" + v.toGMTString();
14756 }else if(v instanceof Array){
14758 for(var i = 0, len = v.length; i < len; i++){
14759 flat += this.encodeValue(v[i]);
14760 if(i != len-1) flat += "^";
14763 }else if(typeof v == "object"){
14766 if(typeof v[key] != "function"){
14767 flat += key + "=" + this.encodeValue(v[key]) + "^";
14770 enc = "o:" + flat.substring(0, flat.length-1);
14774 return escape(enc);
14780 * Ext JS Library 1.1.1
14781 * Copyright(c) 2006-2007, Ext JS, LLC.
14783 * Originally Released Under LGPL - original licence link has changed is not relivant.
14786 * <script type="text/javascript">
14789 * @class Roo.state.Manager
14790 * This is the global state manager. By default all components that are "state aware" check this class
14791 * for state information if you don't pass them a custom state provider. In order for this class
14792 * to be useful, it must be initialized with a provider when your application initializes.
14794 // in your initialization function
14796 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
14798 // supposed you have a {@link Roo.BorderLayout}
14799 var layout = new Roo.BorderLayout(...);
14800 layout.restoreState();
14801 // or a {Roo.BasicDialog}
14802 var dialog = new Roo.BasicDialog(...);
14803 dialog.restoreState();
14807 Roo.state.Manager = function(){
14808 var provider = new Roo.state.Provider();
14812 * Configures the default state provider for your application
14813 * @param {Provider} stateProvider The state provider to set
14815 setProvider : function(stateProvider){
14816 provider = stateProvider;
14820 * Returns the current value for a key
14821 * @param {String} name The key name
14822 * @param {Mixed} defaultValue The default value to return if the key lookup does not match
14823 * @return {Mixed} The state data
14825 get : function(key, defaultValue){
14826 return provider.get(key, defaultValue);
14830 * Sets the value for a key
14831 * @param {String} name The key name
14832 * @param {Mixed} value The state data
14834 set : function(key, value){
14835 provider.set(key, value);
14839 * Clears a value from the state
14840 * @param {String} name The key name
14842 clear : function(key){
14843 provider.clear(key);
14847 * Gets the currently configured state provider
14848 * @return {Provider} The state provider
14850 getProvider : function(){
14857 * Ext JS Library 1.1.1
14858 * Copyright(c) 2006-2007, Ext JS, LLC.
14860 * Originally Released Under LGPL - original licence link has changed is not relivant.
14863 * <script type="text/javascript">
14866 * @class Roo.state.CookieProvider
14867 * @extends Roo.state.Provider
14868 * The default Provider implementation which saves state via cookies.
14871 var cp = new Roo.state.CookieProvider({
14873 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
14874 domain: "roojs.com"
14876 Roo.state.Manager.setProvider(cp);
14878 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
14879 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
14880 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
14881 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
14882 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
14883 * domain the page is running on including the 'www' like 'www.roojs.com')
14884 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
14886 * Create a new CookieProvider
14887 * @param {Object} config The configuration object
14889 Roo.state.CookieProvider = function(config){
14890 Roo.state.CookieProvider.superclass.constructor.call(this);
14892 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
14893 this.domain = null;
14894 this.secure = false;
14895 Roo.apply(this, config);
14896 this.state = this.readCookies();
14899 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
14901 set : function(name, value){
14902 if(typeof value == "undefined" || value === null){
14906 this.setCookie(name, value);
14907 Roo.state.CookieProvider.superclass.set.call(this, name, value);
14911 clear : function(name){
14912 this.clearCookie(name);
14913 Roo.state.CookieProvider.superclass.clear.call(this, name);
14917 readCookies : function(){
14919 var c = document.cookie + ";";
14920 var re = /\s?(.*?)=(.*?);/g;
14922 while((matches = re.exec(c)) != null){
14923 var name = matches[1];
14924 var value = matches[2];
14925 if(name && name.substring(0,3) == "ys-"){
14926 cookies[name.substr(3)] = this.decodeValue(value);
14933 setCookie : function(name, value){
14934 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
14935 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
14936 ((this.path == null) ? "" : ("; path=" + this.path)) +
14937 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
14938 ((this.secure == true) ? "; secure" : "");
14942 clearCookie : function(name){
14943 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
14944 ((this.path == null) ? "" : ("; path=" + this.path)) +
14945 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
14946 ((this.secure == true) ? "; secure" : "");