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
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"
1394 "o = results[", currentGroup, "];\n",
1395 "var sn = o.substring(0,1);\n",
1396 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
1397 "var mn = o.substring(4,6) % 60;\n",
1398 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
1399 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1405 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1408 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1409 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1410 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1414 s:String.escape(character)};
1419 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1420 * @return {String} The abbreviated timezone name (e.g. 'CST')
1422 Date.prototype.getTimezone = function() {
1423 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1427 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1428 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1430 Date.prototype.getGMTOffset = function() {
1431 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1432 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1433 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1437 * Get the offset from GMT of the current date (equivalent to the format specifier 'P').
1438 * @return {String} 2-characters representing hours and 2-characters representing minutes
1439 * seperated by a colon and prefixed with + or - (e.g. '-06:00')
1441 Date.prototype.getGMTColonOffset = function() {
1442 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1443 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1445 + String.leftPad(this.getTimezoneOffset() %60, 2, "0");
1449 * Get the numeric day number of the year, adjusted for leap year.
1450 * @return {Number} 0 through 364 (365 in leap years)
1452 Date.prototype.getDayOfYear = function() {
1454 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1455 for (var i = 0; i < this.getMonth(); ++i) {
1456 num += Date.daysInMonth[i];
1458 return num + this.getDate() - 1;
1462 * Get the string representation of the numeric week number of the year
1463 * (equivalent to the format specifier 'W').
1464 * @return {String} '00' through '52'
1466 Date.prototype.getWeekOfYear = function() {
1467 // Skip to Thursday of this week
1468 var now = this.getDayOfYear() + (4 - this.getDay());
1469 // Find the first Thursday of the year
1470 var jan1 = new Date(this.getFullYear(), 0, 1);
1471 var then = (7 - jan1.getDay() + 4);
1472 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1476 * Whether or not the current date is in a leap year.
1477 * @return {Boolean} True if the current date is in a leap year, else false
1479 Date.prototype.isLeapYear = function() {
1480 var year = this.getFullYear();
1481 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1485 * Get the first day of the current month, adjusted for leap year. The returned value
1486 * is the numeric day index within the week (0-6) which can be used in conjunction with
1487 * the {@link #monthNames} array to retrieve the textual day name.
1490 var dt = new Date('1/10/2007');
1491 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1493 * @return {Number} The day number (0-6)
1495 Date.prototype.getFirstDayOfMonth = function() {
1496 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1497 return (day < 0) ? (day + 7) : day;
1501 * Get the last day of the current month, adjusted for leap year. The returned value
1502 * is the numeric day index within the week (0-6) which can be used in conjunction with
1503 * the {@link #monthNames} array to retrieve the textual day name.
1506 var dt = new Date('1/10/2007');
1507 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1509 * @return {Number} The day number (0-6)
1511 Date.prototype.getLastDayOfMonth = function() {
1512 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1513 return (day < 0) ? (day + 7) : day;
1518 * Get the first date of this date's month
1521 Date.prototype.getFirstDateOfMonth = function() {
1522 return new Date(this.getFullYear(), this.getMonth(), 1);
1526 * Get the last date of this date's month
1529 Date.prototype.getLastDateOfMonth = function() {
1530 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1533 * Get the number of days in the current month, adjusted for leap year.
1534 * @return {Number} The number of days in the month
1536 Date.prototype.getDaysInMonth = function() {
1537 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1538 return Date.daysInMonth[this.getMonth()];
1542 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1543 * @return {String} 'st, 'nd', 'rd' or 'th'
1545 Date.prototype.getSuffix = function() {
1546 switch (this.getDate()) {
1563 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1566 * An array of textual month names.
1567 * Override these values for international dates, for example...
1568 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1587 * An array of textual day names.
1588 * Override these values for international dates, for example...
1589 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1605 Date.monthNumbers = {
1620 * Creates and returns a new Date instance with the exact same date value as the called instance.
1621 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1622 * variable will also be changed. When the intention is to create a new variable that will not
1623 * modify the original instance, you should create a clone.
1625 * Example of correctly cloning a date:
1628 var orig = new Date('10/1/2006');
1631 document.write(orig); //returns 'Thu Oct 05 2006'!
1634 var orig = new Date('10/1/2006');
1635 var copy = orig.clone();
1637 document.write(orig); //returns 'Thu Oct 01 2006'
1639 * @return {Date} The new Date instance
1641 Date.prototype.clone = function() {
1642 return new Date(this.getTime());
1646 * Clears any time information from this date
1647 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1648 @return {Date} this or the clone
1650 Date.prototype.clearTime = function(clone){
1652 return this.clone().clearTime();
1657 this.setMilliseconds(0);
1662 // safari setMonth is broken
1664 Date.brokenSetMonth = Date.prototype.setMonth;
1665 Date.prototype.setMonth = function(num){
1667 var n = Math.ceil(-num);
1668 var back_year = Math.ceil(n/12);
1669 var month = (n % 12) ? 12 - n % 12 : 0 ;
1670 this.setFullYear(this.getFullYear() - back_year);
1671 return Date.brokenSetMonth.call(this, month);
1673 return Date.brokenSetMonth.apply(this, arguments);
1678 /** Date interval constant
1682 /** Date interval constant
1686 /** Date interval constant
1690 /** Date interval constant
1694 /** Date interval constant
1698 /** Date interval constant
1702 /** Date interval constant
1708 * Provides a convenient method of performing basic date arithmetic. This method
1709 * does not modify the Date instance being called - it creates and returns
1710 * a new Date instance containing the resulting date value.
1715 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1716 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1718 //Negative values will subtract correctly:
1719 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1720 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1722 //You can even chain several calls together in one line!
1723 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1724 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1727 * @param {String} interval A valid date interval enum value
1728 * @param {Number} value The amount to add to the current date
1729 * @return {Date} The new Date instance
1731 Date.prototype.add = function(interval, value){
1732 var d = this.clone();
1733 if (!interval || value === 0) return d;
1734 switch(interval.toLowerCase()){
1736 d.setMilliseconds(this.getMilliseconds() + value);
1739 d.setSeconds(this.getSeconds() + value);
1742 d.setMinutes(this.getMinutes() + value);
1745 d.setHours(this.getHours() + value);
1748 d.setDate(this.getDate() + value);
1751 var day = this.getDate();
1753 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1756 d.setMonth(this.getMonth() + value);
1759 d.setFullYear(this.getFullYear() + value);
1766 * Ext JS Library 1.1.1
1767 * Copyright(c) 2006-2007, Ext JS, LLC.
1769 * Originally Released Under LGPL - original licence link has changed is not relivant.
1772 * <script type="text/javascript">
1776 getViewWidth : function(full) {
1777 return full ? this.getDocumentWidth() : this.getViewportWidth();
1780 getViewHeight : function(full) {
1781 return full ? this.getDocumentHeight() : this.getViewportHeight();
1784 getDocumentHeight: function() {
1785 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1786 return Math.max(scrollHeight, this.getViewportHeight());
1789 getDocumentWidth: function() {
1790 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1791 return Math.max(scrollWidth, this.getViewportWidth());
1794 getViewportHeight: function() {
1795 var height = self.innerHeight;
1796 var mode = document.compatMode;
1798 if ((mode || Roo.isIE) && !Roo.isOpera) {
1799 height = (mode == "CSS1Compat") ?
1800 document.documentElement.clientHeight :
1801 document.body.clientHeight;
1807 getViewportWidth: function() {
1808 var width = self.innerWidth;
1809 var mode = document.compatMode;
1811 if (mode || Roo.isIE) {
1812 width = (mode == "CSS1Compat") ?
1813 document.documentElement.clientWidth :
1814 document.body.clientWidth;
1819 isAncestor : function(p, c) {
1826 if (p.contains && !Roo.isSafari) {
1827 return p.contains(c);
1828 } else if (p.compareDocumentPosition) {
1829 return !!(p.compareDocumentPosition(c) & 16);
1831 var parent = c.parentNode;
1836 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1839 parent = parent.parentNode;
1845 getRegion : function(el) {
1846 return Roo.lib.Region.getRegion(el);
1849 getY : function(el) {
1850 return this.getXY(el)[1];
1853 getX : function(el) {
1854 return this.getXY(el)[0];
1857 getXY : function(el) {
1858 var p, pe, b, scroll, bd = document.body;
1859 el = Roo.getDom(el);
1860 var fly = Roo.lib.AnimBase.fly;
1861 if (el.getBoundingClientRect) {
1862 b = el.getBoundingClientRect();
1863 scroll = fly(document).getScroll();
1864 return [b.left + scroll.left, b.top + scroll.top];
1870 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1877 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1884 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1885 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1892 if (p != el && pe.getStyle('overflow') != 'visible') {
1900 if (Roo.isSafari && hasAbsolute) {
1905 if (Roo.isGecko && !hasAbsolute) {
1907 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1908 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1912 while (p && p != bd) {
1913 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1925 setXY : function(el, xy) {
1926 el = Roo.fly(el, '_setXY');
1928 var pts = el.translatePoints(xy);
1929 if (xy[0] !== false) {
1930 el.dom.style.left = pts.left + "px";
1932 if (xy[1] !== false) {
1933 el.dom.style.top = pts.top + "px";
1937 setX : function(el, x) {
1938 this.setXY(el, [x, false]);
1941 setY : function(el, y) {
1942 this.setXY(el, [false, y]);
1946 * Portions of this file are based on pieces of Yahoo User Interface Library
1947 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
1948 * YUI licensed under the BSD License:
1949 * http://developer.yahoo.net/yui/license.txt
1950 * <script type="text/javascript">
1954 Roo.lib.Event = function() {
1955 var loadComplete = false;
1957 var unloadListeners = [];
1959 var onAvailStack = [];
1961 var lastError = null;
1974 startInterval: function() {
1975 if (!this._interval) {
1977 var callback = function() {
1978 self._tryPreloadAttach();
1980 this._interval = setInterval(callback, this.POLL_INTERVAL);
1985 onAvailable: function(p_id, p_fn, p_obj, p_override) {
1986 onAvailStack.push({ id: p_id,
1989 override: p_override,
1990 checkReady: false });
1992 retryCount = this.POLL_RETRYS;
1993 this.startInterval();
1997 addListener: function(el, eventName, fn) {
1998 el = Roo.getDom(el);
2003 if ("unload" == eventName) {
2004 unloadListeners[unloadListeners.length] =
2005 [el, eventName, fn];
2009 var wrappedFn = function(e) {
2010 return fn(Roo.lib.Event.getEvent(e));
2013 var li = [el, eventName, fn, wrappedFn];
2015 var index = listeners.length;
2016 listeners[index] = li;
2018 this.doAdd(el, eventName, wrappedFn, false);
2024 removeListener: function(el, eventName, fn) {
2027 el = Roo.getDom(el);
2030 return this.purgeElement(el, false, eventName);
2034 if ("unload" == eventName) {
2036 for (i = 0,len = unloadListeners.length; i < len; i++) {
2037 var li = unloadListeners[i];
2040 li[1] == eventName &&
2042 unloadListeners.splice(i, 1);
2050 var cacheItem = null;
2053 var index = arguments[3];
2055 if ("undefined" == typeof index) {
2056 index = this._getCacheIndex(el, eventName, fn);
2060 cacheItem = listeners[index];
2063 if (!el || !cacheItem) {
2067 this.doRemove(el, eventName, cacheItem[this.WFN], false);
2069 delete listeners[index][this.WFN];
2070 delete listeners[index][this.FN];
2071 listeners.splice(index, 1);
2078 getTarget: function(ev, resolveTextNode) {
2079 ev = ev.browserEvent || ev;
2080 var t = ev.target || ev.srcElement;
2081 return this.resolveTextNode(t);
2085 resolveTextNode: function(node) {
2086 if (Roo.isSafari && node && 3 == node.nodeType) {
2087 return node.parentNode;
2094 getPageX: function(ev) {
2095 ev = ev.browserEvent || ev;
2097 if (!x && 0 !== x) {
2098 x = ev.clientX || 0;
2101 x += this.getScroll()[1];
2109 getPageY: function(ev) {
2110 ev = ev.browserEvent || ev;
2112 if (!y && 0 !== y) {
2113 y = ev.clientY || 0;
2116 y += this.getScroll()[0];
2125 getXY: function(ev) {
2126 ev = ev.browserEvent || ev;
2127 return [this.getPageX(ev), this.getPageY(ev)];
2131 getRelatedTarget: function(ev) {
2132 ev = ev.browserEvent || ev;
2133 var t = ev.relatedTarget;
2135 if (ev.type == "mouseout") {
2137 } else if (ev.type == "mouseover") {
2142 return this.resolveTextNode(t);
2146 getTime: function(ev) {
2147 ev = ev.browserEvent || ev;
2149 var t = new Date().getTime();
2153 this.lastError = ex;
2162 stopEvent: function(ev) {
2163 this.stopPropagation(ev);
2164 this.preventDefault(ev);
2168 stopPropagation: function(ev) {
2169 ev = ev.browserEvent || ev;
2170 if (ev.stopPropagation) {
2171 ev.stopPropagation();
2173 ev.cancelBubble = true;
2178 preventDefault: function(ev) {
2179 ev = ev.browserEvent || ev;
2180 if(ev.preventDefault) {
2181 ev.preventDefault();
2183 ev.returnValue = false;
2188 getEvent: function(e) {
2189 var ev = e || window.event;
2191 var c = this.getEvent.caller;
2193 ev = c.arguments[0];
2194 if (ev && Event == ev.constructor) {
2204 getCharCode: function(ev) {
2205 ev = ev.browserEvent || ev;
2206 return ev.charCode || ev.keyCode || 0;
2210 _getCacheIndex: function(el, eventName, fn) {
2211 for (var i = 0,len = listeners.length; i < len; ++i) {
2212 var li = listeners[i];
2214 li[this.FN] == fn &&
2215 li[this.EL] == el &&
2216 li[this.TYPE] == eventName) {
2228 getEl: function(id) {
2229 return document.getElementById(id);
2233 clearCache: function() {
2237 _load: function(e) {
2238 loadComplete = true;
2239 var EU = Roo.lib.Event;
2243 EU.doRemove(window, "load", EU._load);
2248 _tryPreloadAttach: function() {
2257 var tryAgain = !loadComplete;
2259 tryAgain = (retryCount > 0);
2264 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2265 var item = onAvailStack[i];
2267 var el = this.getEl(item.id);
2270 if (!item.checkReady ||
2273 (document && document.body)) {
2276 if (item.override) {
2277 if (item.override === true) {
2280 scope = item.override;
2283 item.fn.call(scope, item.obj);
2284 onAvailStack[i] = null;
2287 notAvail.push(item);
2292 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2296 this.startInterval();
2298 clearInterval(this._interval);
2299 this._interval = null;
2302 this.locked = false;
2309 purgeElement: function(el, recurse, eventName) {
2310 var elListeners = this.getListeners(el, eventName);
2312 for (var i = 0,len = elListeners.length; i < len; ++i) {
2313 var l = elListeners[i];
2314 this.removeListener(el, l.type, l.fn);
2318 if (recurse && el && el.childNodes) {
2319 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2320 this.purgeElement(el.childNodes[i], recurse, eventName);
2326 getListeners: function(el, eventName) {
2327 var results = [], searchLists;
2329 searchLists = [listeners, unloadListeners];
2330 } else if (eventName == "unload") {
2331 searchLists = [unloadListeners];
2333 searchLists = [listeners];
2336 for (var j = 0; j < searchLists.length; ++j) {
2337 var searchList = searchLists[j];
2338 if (searchList && searchList.length > 0) {
2339 for (var i = 0,len = searchList.length; i < len; ++i) {
2340 var l = searchList[i];
2341 if (l && l[this.EL] === el &&
2342 (!eventName || eventName === l[this.TYPE])) {
2347 adjust: l[this.ADJ_SCOPE],
2355 return (results.length) ? results : null;
2359 _unload: function(e) {
2361 var EU = Roo.lib.Event, i, j, l, len, index;
2363 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2364 l = unloadListeners[i];
2367 if (l[EU.ADJ_SCOPE]) {
2368 if (l[EU.ADJ_SCOPE] === true) {
2371 scope = l[EU.ADJ_SCOPE];
2374 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2375 unloadListeners[i] = null;
2381 unloadListeners = null;
2383 if (listeners && listeners.length > 0) {
2384 j = listeners.length;
2387 l = listeners[index];
2389 EU.removeListener(l[EU.EL], l[EU.TYPE],
2399 EU.doRemove(window, "unload", EU._unload);
2404 getScroll: function() {
2405 var dd = document.documentElement, db = document.body;
2406 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2407 return [dd.scrollTop, dd.scrollLeft];
2409 return [db.scrollTop, db.scrollLeft];
2416 doAdd: function () {
2417 if (window.addEventListener) {
2418 return function(el, eventName, fn, capture) {
2419 el.addEventListener(eventName, fn, (capture));
2421 } else if (window.attachEvent) {
2422 return function(el, eventName, fn, capture) {
2423 el.attachEvent("on" + eventName, fn);
2432 doRemove: function() {
2433 if (window.removeEventListener) {
2434 return function (el, eventName, fn, capture) {
2435 el.removeEventListener(eventName, fn, (capture));
2437 } else if (window.detachEvent) {
2438 return function (el, eventName, fn) {
2439 el.detachEvent("on" + eventName, fn);
2451 var E = Roo.lib.Event;
2452 E.on = E.addListener;
2453 E.un = E.removeListener;
2455 if (document && document.body) {
2458 E.doAdd(window, "load", E._load);
2460 E.doAdd(window, "unload", E._unload);
2461 E._tryPreloadAttach();
2465 * Portions of this file are based on pieces of Yahoo User Interface Library
2466 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2467 * YUI licensed under the BSD License:
2468 * http://developer.yahoo.net/yui/license.txt
2469 * <script type="text/javascript">
2475 * @class Roo.lib.Ajax
2482 request : function(method, uri, cb, data, options) {
2484 var hs = options.headers;
2487 if(hs.hasOwnProperty(h)){
2488 this.initHeader(h, hs[h], false);
2492 if(options.xmlData){
2493 this.initHeader('Content-Type', 'text/xml', false);
2495 data = options.xmlData;
2499 return this.asyncRequest(method, uri, cb, data);
2502 serializeForm : function(form) {
2503 if(typeof form == 'string') {
2504 form = (document.getElementById(form) || document.forms[form]);
2507 var el, name, val, disabled, data = '', hasSubmit = false;
2508 for (var i = 0; i < form.elements.length; i++) {
2509 el = form.elements[i];
2510 disabled = form.elements[i].disabled;
2511 name = form.elements[i].name;
2512 val = form.elements[i].value;
2514 if (!disabled && name){
2518 case 'select-multiple':
2519 for (var j = 0; j < el.options.length; j++) {
2520 if (el.options[j].selected) {
2522 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2525 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2533 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2546 if(hasSubmit == false) {
2547 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2552 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2557 data = data.substr(0, data.length - 1);
2565 useDefaultHeader:true,
2567 defaultPostHeader:'application/x-www-form-urlencoded',
2569 useDefaultXhrHeader:true,
2571 defaultXhrHeader:'XMLHttpRequest',
2573 hasDefaultHeaders:true,
2585 setProgId:function(id)
2587 this.activeX.unshift(id);
2590 setDefaultPostHeader:function(b)
2592 this.useDefaultHeader = b;
2595 setDefaultXhrHeader:function(b)
2597 this.useDefaultXhrHeader = b;
2600 setPollingInterval:function(i)
2602 if (typeof i == 'number' && isFinite(i)) {
2603 this.pollInterval = i;
2607 createXhrObject:function(transactionId)
2613 http = new XMLHttpRequest();
2615 obj = { conn:http, tId:transactionId };
2619 for (var i = 0; i < this.activeX.length; ++i) {
2623 http = new ActiveXObject(this.activeX[i]);
2625 obj = { conn:http, tId:transactionId };
2638 getConnectionObject:function()
2641 var tId = this.transactionId;
2645 o = this.createXhrObject(tId);
2647 this.transactionId++;
2658 asyncRequest:function(method, uri, callback, postData)
2660 var o = this.getConnectionObject();
2666 o.conn.open(method, uri, true);
2668 if (this.useDefaultXhrHeader) {
2669 if (!this.defaultHeaders['X-Requested-With']) {
2670 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2674 if(postData && this.useDefaultHeader){
2675 this.initHeader('Content-Type', this.defaultPostHeader);
2678 if (this.hasDefaultHeaders || this.hasHeaders) {
2682 this.handleReadyState(o, callback);
2683 o.conn.send(postData || null);
2689 handleReadyState:function(o, callback)
2693 if (callback && callback.timeout) {
2694 this.timeout[o.tId] = window.setTimeout(function() {
2695 oConn.abort(o, callback, true);
2696 }, callback.timeout);
2699 this.poll[o.tId] = window.setInterval(
2701 if (o.conn && o.conn.readyState == 4) {
2702 window.clearInterval(oConn.poll[o.tId]);
2703 delete oConn.poll[o.tId];
2705 if(callback && callback.timeout) {
2706 window.clearTimeout(oConn.timeout[o.tId]);
2707 delete oConn.timeout[o.tId];
2710 oConn.handleTransactionResponse(o, callback);
2713 , this.pollInterval);
2716 handleTransactionResponse:function(o, callback, isAbort)
2720 this.releaseObject(o);
2724 var httpStatus, responseObject;
2728 if (o.conn.status !== undefined && o.conn.status != 0) {
2729 httpStatus = o.conn.status;
2741 if (httpStatus >= 200 && httpStatus < 300) {
2742 responseObject = this.createResponseObject(o, callback.argument);
2743 if (callback.success) {
2744 if (!callback.scope) {
2745 callback.success(responseObject);
2750 callback.success.apply(callback.scope, [responseObject]);
2755 switch (httpStatus) {
2763 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2764 if (callback.failure) {
2765 if (!callback.scope) {
2766 callback.failure(responseObject);
2769 callback.failure.apply(callback.scope, [responseObject]);
2774 responseObject = this.createResponseObject(o, callback.argument);
2775 if (callback.failure) {
2776 if (!callback.scope) {
2777 callback.failure(responseObject);
2780 callback.failure.apply(callback.scope, [responseObject]);
2786 this.releaseObject(o);
2787 responseObject = null;
2790 createResponseObject:function(o, callbackArg)
2797 var headerStr = o.conn.getAllResponseHeaders();
2798 var header = headerStr.split('\n');
2799 for (var i = 0; i < header.length; i++) {
2800 var delimitPos = header[i].indexOf(':');
2801 if (delimitPos != -1) {
2802 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2810 obj.status = o.conn.status;
2811 obj.statusText = o.conn.statusText;
2812 obj.getResponseHeader = headerObj;
2813 obj.getAllResponseHeaders = headerStr;
2814 obj.responseText = o.conn.responseText;
2815 obj.responseXML = o.conn.responseXML;
2817 if (typeof callbackArg !== undefined) {
2818 obj.argument = callbackArg;
2824 createExceptionObject:function(tId, callbackArg, isAbort)
2827 var COMM_ERROR = 'communication failure';
2828 var ABORT_CODE = -1;
2829 var ABORT_ERROR = 'transaction aborted';
2835 obj.status = ABORT_CODE;
2836 obj.statusText = ABORT_ERROR;
2839 obj.status = COMM_CODE;
2840 obj.statusText = COMM_ERROR;
2844 obj.argument = callbackArg;
2850 initHeader:function(label, value, isDefault)
2852 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2854 if (headerObj[label] === undefined) {
2855 headerObj[label] = value;
2860 headerObj[label] = value + "," + headerObj[label];
2864 this.hasDefaultHeaders = true;
2867 this.hasHeaders = true;
2872 setHeader:function(o)
2874 if (this.hasDefaultHeaders) {
2875 for (var prop in this.defaultHeaders) {
2876 if (this.defaultHeaders.hasOwnProperty(prop)) {
2877 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2882 if (this.hasHeaders) {
2883 for (var prop in this.headers) {
2884 if (this.headers.hasOwnProperty(prop)) {
2885 o.conn.setRequestHeader(prop, this.headers[prop]);
2889 this.hasHeaders = false;
2893 resetDefaultHeaders:function() {
2894 delete this.defaultHeaders;
2895 this.defaultHeaders = {};
2896 this.hasDefaultHeaders = false;
2899 abort:function(o, callback, isTimeout)
2901 if(this.isCallInProgress(o)) {
2903 window.clearInterval(this.poll[o.tId]);
2904 delete this.poll[o.tId];
2906 delete this.timeout[o.tId];
2909 this.handleTransactionResponse(o, callback, true);
2919 isCallInProgress:function(o)
2922 return o.conn.readyState != 4 && o.conn.readyState != 0;
2931 releaseObject:function(o)
2940 'MSXML2.XMLHTTP.3.0',
2948 * Portions of this file are based on pieces of Yahoo User Interface Library
2949 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2950 * YUI licensed under the BSD License:
2951 * http://developer.yahoo.net/yui/license.txt
2952 * <script type="text/javascript">
2956 Roo.lib.Region = function(t, r, b, l) {
2966 Roo.lib.Region.prototype = {
2967 contains : function(region) {
2968 return ( region.left >= this.left &&
2969 region.right <= this.right &&
2970 region.top >= this.top &&
2971 region.bottom <= this.bottom );
2975 getArea : function() {
2976 return ( (this.bottom - this.top) * (this.right - this.left) );
2979 intersect : function(region) {
2980 var t = Math.max(this.top, region.top);
2981 var r = Math.min(this.right, region.right);
2982 var b = Math.min(this.bottom, region.bottom);
2983 var l = Math.max(this.left, region.left);
2985 if (b >= t && r >= l) {
2986 return new Roo.lib.Region(t, r, b, l);
2991 union : function(region) {
2992 var t = Math.min(this.top, region.top);
2993 var r = Math.max(this.right, region.right);
2994 var b = Math.max(this.bottom, region.bottom);
2995 var l = Math.min(this.left, region.left);
2997 return new Roo.lib.Region(t, r, b, l);
3000 adjust : function(t, l, b, r) {
3009 Roo.lib.Region.getRegion = function(el) {
3010 var p = Roo.lib.Dom.getXY(el);
3013 var r = p[0] + el.offsetWidth;
3014 var b = p[1] + el.offsetHeight;
3017 return new Roo.lib.Region(t, r, b, l);
3020 * Portions of this file are based on pieces of Yahoo User Interface Library
3021 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3022 * YUI licensed under the BSD License:
3023 * http://developer.yahoo.net/yui/license.txt
3024 * <script type="text/javascript">
3027 //@@dep Roo.lib.Region
3030 Roo.lib.Point = function(x, y) {
3031 if (x instanceof Array) {
3035 this.x = this.right = this.left = this[0] = x;
3036 this.y = this.top = this.bottom = this[1] = y;
3039 Roo.lib.Point.prototype = new Roo.lib.Region();
3041 * Portions of this file are based on pieces of Yahoo User Interface Library
3042 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3043 * YUI licensed under the BSD License:
3044 * http://developer.yahoo.net/yui/license.txt
3045 * <script type="text/javascript">
3052 scroll : function(el, args, duration, easing, cb, scope) {
3053 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
3056 motion : function(el, args, duration, easing, cb, scope) {
3057 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
3060 color : function(el, args, duration, easing, cb, scope) {
3061 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
3064 run : function(el, args, duration, easing, cb, scope, type) {
3065 type = type || Roo.lib.AnimBase;
3066 if (typeof easing == "string") {
3067 easing = Roo.lib.Easing[easing];
3069 var anim = new type(el, args, duration, easing);
3070 anim.animateX(function() {
3071 Roo.callback(cb, scope);
3077 * Portions of this file are based on pieces of Yahoo User Interface Library
3078 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3079 * YUI licensed under the BSD License:
3080 * http://developer.yahoo.net/yui/license.txt
3081 * <script type="text/javascript">
3089 if (!libFlyweight) {
3090 libFlyweight = new Roo.Element.Flyweight();
3092 libFlyweight.dom = el;
3093 return libFlyweight;
3096 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
3100 Roo.lib.AnimBase = function(el, attributes, duration, method) {
3102 this.init(el, attributes, duration, method);
3106 Roo.lib.AnimBase.fly = fly;
3110 Roo.lib.AnimBase.prototype = {
3112 toString: function() {
3113 var el = this.getEl();
3114 var id = el.id || el.tagName;
3115 return ("Anim " + id);
3119 noNegatives: /width|height|opacity|padding/i,
3120 offsetAttribute: /^((width|height)|(top|left))$/,
3121 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3122 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3126 doMethod: function(attr, start, end) {
3127 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3131 setAttribute: function(attr, val, unit) {
3132 if (this.patterns.noNegatives.test(attr)) {
3133 val = (val > 0) ? val : 0;
3136 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3140 getAttribute: function(attr) {
3141 var el = this.getEl();
3142 var val = fly(el).getStyle(attr);
3144 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3145 return parseFloat(val);
3148 var a = this.patterns.offsetAttribute.exec(attr) || [];
3149 var pos = !!( a[3] );
3150 var box = !!( a[2] );
3153 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3154 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3163 getDefaultUnit: function(attr) {
3164 if (this.patterns.defaultUnit.test(attr)) {
3171 animateX : function(callback, scope) {
3172 var f = function() {
3173 this.onComplete.removeListener(f);
3174 if (typeof callback == "function") {
3175 callback.call(scope || this, this);
3178 this.onComplete.addListener(f, this);
3183 setRuntimeAttribute: function(attr) {
3186 var attributes = this.attributes;
3188 this.runtimeAttributes[attr] = {};
3190 var isset = function(prop) {
3191 return (typeof prop !== 'undefined');
3194 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3198 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3201 if (isset(attributes[attr]['to'])) {
3202 end = attributes[attr]['to'];
3203 } else if (isset(attributes[attr]['by'])) {
3204 if (start.constructor == Array) {
3206 for (var i = 0, len = start.length; i < len; ++i) {
3207 end[i] = start[i] + attributes[attr]['by'][i];
3210 end = start + attributes[attr]['by'];
3214 this.runtimeAttributes[attr].start = start;
3215 this.runtimeAttributes[attr].end = end;
3218 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3222 init: function(el, attributes, duration, method) {
3224 var isAnimated = false;
3227 var startTime = null;
3230 var actualFrames = 0;
3233 el = Roo.getDom(el);
3236 this.attributes = attributes || {};
3239 this.duration = duration || 1;
3242 this.method = method || Roo.lib.Easing.easeNone;
3245 this.useSeconds = true;
3248 this.currentFrame = 0;
3251 this.totalFrames = Roo.lib.AnimMgr.fps;
3254 this.getEl = function() {
3259 this.isAnimated = function() {
3264 this.getStartTime = function() {
3268 this.runtimeAttributes = {};
3271 this.animate = function() {
3272 if (this.isAnimated()) {
3276 this.currentFrame = 0;
3278 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3280 Roo.lib.AnimMgr.registerElement(this);
3284 this.stop = function(finish) {
3286 this.currentFrame = this.totalFrames;
3287 this._onTween.fire();
3289 Roo.lib.AnimMgr.stop(this);
3292 var onStart = function() {
3293 this.onStart.fire();
3295 this.runtimeAttributes = {};
3296 for (var attr in this.attributes) {
3297 this.setRuntimeAttribute(attr);
3302 startTime = new Date();
3306 var onTween = function() {
3308 duration: new Date() - this.getStartTime(),
3309 currentFrame: this.currentFrame
3312 data.toString = function() {
3314 'duration: ' + data.duration +
3315 ', currentFrame: ' + data.currentFrame
3319 this.onTween.fire(data);
3321 var runtimeAttributes = this.runtimeAttributes;
3323 for (var attr in runtimeAttributes) {
3324 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3330 var onComplete = function() {
3331 var actual_duration = (new Date() - startTime) / 1000 ;
3334 duration: actual_duration,
3335 frames: actualFrames,
3336 fps: actualFrames / actual_duration
3339 data.toString = function() {
3341 'duration: ' + data.duration +
3342 ', frames: ' + data.frames +
3343 ', fps: ' + data.fps
3349 this.onComplete.fire(data);
3353 this._onStart = new Roo.util.Event(this);
3354 this.onStart = new Roo.util.Event(this);
3355 this.onTween = new Roo.util.Event(this);
3356 this._onTween = new Roo.util.Event(this);
3357 this.onComplete = new Roo.util.Event(this);
3358 this._onComplete = new Roo.util.Event(this);
3359 this._onStart.addListener(onStart);
3360 this._onTween.addListener(onTween);
3361 this._onComplete.addListener(onComplete);
3366 * Portions of this file are based on pieces of Yahoo User Interface Library
3367 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3368 * YUI licensed under the BSD License:
3369 * http://developer.yahoo.net/yui/license.txt
3370 * <script type="text/javascript">
3374 Roo.lib.AnimMgr = new function() {
3391 this.registerElement = function(tween) {
3392 queue[queue.length] = tween;
3394 tween._onStart.fire();
3399 this.unRegister = function(tween, index) {
3400 tween._onComplete.fire();
3401 index = index || getIndex(tween);
3403 queue.splice(index, 1);
3407 if (tweenCount <= 0) {
3413 this.start = function() {
3414 if (thread === null) {
3415 thread = setInterval(this.run, this.delay);
3420 this.stop = function(tween) {
3422 clearInterval(thread);
3424 for (var i = 0, len = queue.length; i < len; ++i) {
3425 if (queue[0].isAnimated()) {
3426 this.unRegister(queue[0], 0);
3435 this.unRegister(tween);
3440 this.run = function() {
3441 for (var i = 0, len = queue.length; i < len; ++i) {
3442 var tween = queue[i];
3443 if (!tween || !tween.isAnimated()) {
3447 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3449 tween.currentFrame += 1;
3451 if (tween.useSeconds) {
3452 correctFrame(tween);
3454 tween._onTween.fire();
3457 Roo.lib.AnimMgr.stop(tween, i);
3462 var getIndex = function(anim) {
3463 for (var i = 0, len = queue.length; i < len; ++i) {
3464 if (queue[i] == anim) {
3472 var correctFrame = function(tween) {
3473 var frames = tween.totalFrames;
3474 var frame = tween.currentFrame;
3475 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3476 var elapsed = (new Date() - tween.getStartTime());
3479 if (elapsed < tween.duration * 1000) {
3480 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3482 tweak = frames - (frame + 1);
3484 if (tweak > 0 && isFinite(tweak)) {
3485 if (tween.currentFrame + tweak >= frames) {
3486 tweak = frames - (frame + 1);
3489 tween.currentFrame += tweak;
3493 * Portions of this file are based on pieces of Yahoo User Interface Library
3494 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3495 * YUI licensed under the BSD License:
3496 * http://developer.yahoo.net/yui/license.txt
3497 * <script type="text/javascript">
3500 Roo.lib.Bezier = new function() {
3502 this.getPosition = function(points, t) {
3503 var n = points.length;
3506 for (var i = 0; i < n; ++i) {
3507 tmp[i] = [points[i][0], points[i][1]];
3510 for (var j = 1; j < n; ++j) {
3511 for (i = 0; i < n - j; ++i) {
3512 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3513 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3517 return [ tmp[0][0], tmp[0][1] ];
3521 * Portions of this file are based on pieces of Yahoo User Interface Library
3522 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3523 * YUI licensed under the BSD License:
3524 * http://developer.yahoo.net/yui/license.txt
3525 * <script type="text/javascript">
3530 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3531 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3534 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3536 var fly = Roo.lib.AnimBase.fly;
3538 var superclass = Y.ColorAnim.superclass;
3539 var proto = Y.ColorAnim.prototype;
3541 proto.toString = function() {
3542 var el = this.getEl();
3543 var id = el.id || el.tagName;
3544 return ("ColorAnim " + id);
3547 proto.patterns.color = /color$/i;
3548 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3549 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3550 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3551 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3554 proto.parseColor = function(s) {
3555 if (s.length == 3) {
3559 var c = this.patterns.hex.exec(s);
3560 if (c && c.length == 4) {
3561 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3564 c = this.patterns.rgb.exec(s);
3565 if (c && c.length == 4) {
3566 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3569 c = this.patterns.hex3.exec(s);
3570 if (c && c.length == 4) {
3571 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3576 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3577 proto.getAttribute = function(attr) {
3578 var el = this.getEl();
3579 if (this.patterns.color.test(attr)) {
3580 var val = fly(el).getStyle(attr);
3582 if (this.patterns.transparent.test(val)) {
3583 var parent = el.parentNode;
3584 val = fly(parent).getStyle(attr);
3586 while (parent && this.patterns.transparent.test(val)) {
3587 parent = parent.parentNode;
3588 val = fly(parent).getStyle(attr);
3589 if (parent.tagName.toUpperCase() == 'HTML') {
3595 val = superclass.getAttribute.call(this, attr);
3600 proto.getAttribute = function(attr) {
3601 var el = this.getEl();
3602 if (this.patterns.color.test(attr)) {
3603 var val = fly(el).getStyle(attr);
3605 if (this.patterns.transparent.test(val)) {
3606 var parent = el.parentNode;
3607 val = fly(parent).getStyle(attr);
3609 while (parent && this.patterns.transparent.test(val)) {
3610 parent = parent.parentNode;
3611 val = fly(parent).getStyle(attr);
3612 if (parent.tagName.toUpperCase() == 'HTML') {
3618 val = superclass.getAttribute.call(this, attr);
3624 proto.doMethod = function(attr, start, end) {
3627 if (this.patterns.color.test(attr)) {
3629 for (var i = 0, len = start.length; i < len; ++i) {
3630 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3633 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3636 val = superclass.doMethod.call(this, attr, start, end);
3642 proto.setRuntimeAttribute = function(attr) {
3643 superclass.setRuntimeAttribute.call(this, attr);
3645 if (this.patterns.color.test(attr)) {
3646 var attributes = this.attributes;
3647 var start = this.parseColor(this.runtimeAttributes[attr].start);
3648 var end = this.parseColor(this.runtimeAttributes[attr].end);
3650 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3651 end = this.parseColor(attributes[attr].by);
3653 for (var i = 0, len = start.length; i < len; ++i) {
3654 end[i] = start[i] + end[i];
3658 this.runtimeAttributes[attr].start = start;
3659 this.runtimeAttributes[attr].end = end;
3665 * Portions of this file are based on pieces of Yahoo User Interface Library
3666 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3667 * YUI licensed under the BSD License:
3668 * http://developer.yahoo.net/yui/license.txt
3669 * <script type="text/javascript">
3675 easeNone: function (t, b, c, d) {
3676 return c * t / d + b;
3680 easeIn: function (t, b, c, d) {
3681 return c * (t /= d) * t + b;
3685 easeOut: function (t, b, c, d) {
3686 return -c * (t /= d) * (t - 2) + b;
3690 easeBoth: function (t, b, c, d) {
3691 if ((t /= d / 2) < 1) {
3692 return c / 2 * t * t + b;
3695 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3699 easeInStrong: function (t, b, c, d) {
3700 return c * (t /= d) * t * t * t + b;
3704 easeOutStrong: function (t, b, c, d) {
3705 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3709 easeBothStrong: function (t, b, c, d) {
3710 if ((t /= d / 2) < 1) {
3711 return c / 2 * t * t * t * t + b;
3714 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3719 elasticIn: function (t, b, c, d, a, p) {
3723 if ((t /= d) == 1) {
3730 if (!a || a < Math.abs(c)) {
3735 var s = p / (2 * Math.PI) * Math.asin(c / a);
3738 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3742 elasticOut: function (t, b, c, d, a, p) {
3746 if ((t /= d) == 1) {
3753 if (!a || a < Math.abs(c)) {
3758 var s = p / (2 * Math.PI) * Math.asin(c / a);
3761 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3765 elasticBoth: function (t, b, c, d, a, p) {
3770 if ((t /= d / 2) == 2) {
3778 if (!a || a < Math.abs(c)) {
3783 var s = p / (2 * Math.PI) * Math.asin(c / a);
3787 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3788 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3790 return a * Math.pow(2, -10 * (t -= 1)) *
3791 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3796 backIn: function (t, b, c, d, s) {
3797 if (typeof s == 'undefined') {
3800 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3804 backOut: function (t, b, c, d, s) {
3805 if (typeof s == 'undefined') {
3808 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3812 backBoth: function (t, b, c, d, s) {
3813 if (typeof s == 'undefined') {
3817 if ((t /= d / 2 ) < 1) {
3818 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3820 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3824 bounceIn: function (t, b, c, d) {
3825 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3829 bounceOut: function (t, b, c, d) {
3830 if ((t /= d) < (1 / 2.75)) {
3831 return c * (7.5625 * t * t) + b;
3832 } else if (t < (2 / 2.75)) {
3833 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3834 } else if (t < (2.5 / 2.75)) {
3835 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3837 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3841 bounceBoth: function (t, b, c, d) {
3843 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3845 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3848 * Portions of this file are based on pieces of Yahoo User Interface Library
3849 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3850 * YUI licensed under the BSD License:
3851 * http://developer.yahoo.net/yui/license.txt
3852 * <script type="text/javascript">
3856 Roo.lib.Motion = function(el, attributes, duration, method) {
3858 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3862 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3866 var superclass = Y.Motion.superclass;
3867 var proto = Y.Motion.prototype;
3869 proto.toString = function() {
3870 var el = this.getEl();
3871 var id = el.id || el.tagName;
3872 return ("Motion " + id);
3875 proto.patterns.points = /^points$/i;
3877 proto.setAttribute = function(attr, val, unit) {
3878 if (this.patterns.points.test(attr)) {
3879 unit = unit || 'px';
3880 superclass.setAttribute.call(this, 'left', val[0], unit);
3881 superclass.setAttribute.call(this, 'top', val[1], unit);
3883 superclass.setAttribute.call(this, attr, val, unit);
3887 proto.getAttribute = function(attr) {
3888 if (this.patterns.points.test(attr)) {
3890 superclass.getAttribute.call(this, 'left'),
3891 superclass.getAttribute.call(this, 'top')
3894 val = superclass.getAttribute.call(this, attr);
3900 proto.doMethod = function(attr, start, end) {
3903 if (this.patterns.points.test(attr)) {
3904 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3905 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3907 val = superclass.doMethod.call(this, attr, start, end);
3912 proto.setRuntimeAttribute = function(attr) {
3913 if (this.patterns.points.test(attr)) {
3914 var el = this.getEl();
3915 var attributes = this.attributes;
3917 var control = attributes['points']['control'] || [];
3921 if (control.length > 0 && !(control[0] instanceof Array)) {
3922 control = [control];
3925 for (i = 0,len = control.length; i < len; ++i) {
3926 tmp[i] = control[i];
3931 Roo.fly(el).position();
3933 if (isset(attributes['points']['from'])) {
3934 Roo.lib.Dom.setXY(el, attributes['points']['from']);
3937 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3940 start = this.getAttribute('points');
3943 if (isset(attributes['points']['to'])) {
3944 end = translateValues.call(this, attributes['points']['to'], start);
3946 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3947 for (i = 0,len = control.length; i < len; ++i) {
3948 control[i] = translateValues.call(this, control[i], start);
3952 } else if (isset(attributes['points']['by'])) {
3953 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
3955 for (i = 0,len = control.length; i < len; ++i) {
3956 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
3960 this.runtimeAttributes[attr] = [start];
3962 if (control.length > 0) {
3963 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
3966 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
3969 superclass.setRuntimeAttribute.call(this, attr);
3973 var translateValues = function(val, start) {
3974 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3975 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
3980 var isset = function(prop) {
3981 return (typeof prop !== 'undefined');
3985 * Portions of this file are based on pieces of Yahoo User Interface Library
3986 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3987 * YUI licensed under the BSD License:
3988 * http://developer.yahoo.net/yui/license.txt
3989 * <script type="text/javascript">
3993 Roo.lib.Scroll = function(el, attributes, duration, method) {
3995 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
3999 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
4003 var superclass = Y.Scroll.superclass;
4004 var proto = Y.Scroll.prototype;
4006 proto.toString = function() {
4007 var el = this.getEl();
4008 var id = el.id || el.tagName;
4009 return ("Scroll " + id);
4012 proto.doMethod = function(attr, start, end) {
4015 if (attr == 'scroll') {
4017 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
4018 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
4022 val = superclass.doMethod.call(this, attr, start, end);
4027 proto.getAttribute = function(attr) {
4029 var el = this.getEl();
4031 if (attr == 'scroll') {
4032 val = [ el.scrollLeft, el.scrollTop ];
4034 val = superclass.getAttribute.call(this, attr);
4040 proto.setAttribute = function(attr, val, unit) {
4041 var el = this.getEl();
4043 if (attr == 'scroll') {
4044 el.scrollLeft = val[0];
4045 el.scrollTop = val[1];
4047 superclass.setAttribute.call(this, attr, val, unit);
4053 * Ext JS Library 1.1.1
4054 * Copyright(c) 2006-2007, Ext JS, LLC.
4056 * Originally Released Under LGPL - original licence link has changed is not relivant.
4059 * <script type="text/javascript">
4063 // nasty IE9 hack - what a pile of crap that is..
4065 if (typeof Range != "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
4066 Range.prototype.createContextualFragment = function (html) {
4067 var doc = window.document;
4068 var container = doc.createElement("div");
4069 container.innerHTML = html;
4070 var frag = doc.createDocumentFragment(), n;
4071 while ((n = container.firstChild)) {
4072 frag.appendChild(n);
4079 * @class Roo.DomHelper
4080 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
4081 * For more information see <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>.
4084 Roo.DomHelper = function(){
4085 var tempTableEl = null;
4086 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
4087 var tableRe = /^table|tbody|tr|td$/i;
4089 // build as innerHTML where available
4091 var createHtml = function(o){
4092 if(typeof o == 'string'){
4101 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue;
4102 if(attr == "style"){
4104 if(typeof s == "function"){
4107 if(typeof s == "string"){
4108 b += ' style="' + s + '"';
4109 }else if(typeof s == "object"){
4112 if(typeof s[key] != "function"){
4113 b += key + ":" + s[key] + ";";
4120 b += ' class="' + o["cls"] + '"';
4121 }else if(attr == "htmlFor"){
4122 b += ' for="' + o["htmlFor"] + '"';
4124 b += " " + attr + '="' + o[attr] + '"';
4128 if(emptyTags.test(o.tag)){
4132 var cn = o.children || o.cn;
4134 //http://bugs.kde.org/show_bug.cgi?id=71506
4135 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4136 for(var i = 0, len = cn.length; i < len; i++) {
4137 b += createHtml(cn[i], b);
4140 b += createHtml(cn, b);
4146 b += "</" + o.tag + ">";
4153 var createDom = function(o, parentNode){
4155 // defininition craeted..
4157 if (o.ns && o.ns != 'html') {
4159 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4160 xmlns[o.ns] = o.xmlns;
4163 if (typeof(xmlns[o.ns]) == 'undefined') {
4164 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4170 if (typeof(o) == 'string') {
4171 return parentNode.appendChild(document.createTextNode(o));
4173 o.tag = o.tag || div;
4174 if (o.ns && Roo.isIE) {
4176 o.tag = o.ns + ':' + o.tag;
4179 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4180 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4183 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4184 attr == "style" || typeof o[attr] == "function") continue;
4186 if(attr=="cls" && Roo.isIE){
4187 el.className = o["cls"];
4189 if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
4190 else el[attr] = o[attr];
4193 Roo.DomHelper.applyStyles(el, o.style);
4194 var cn = o.children || o.cn;
4196 //http://bugs.kde.org/show_bug.cgi?id=71506
4197 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4198 for(var i = 0, len = cn.length; i < len; i++) {
4199 createDom(cn[i], el);
4206 el.innerHTML = o.html;
4209 parentNode.appendChild(el);
4214 var ieTable = function(depth, s, h, e){
4215 tempTableEl.innerHTML = [s, h, e].join('');
4216 var i = -1, el = tempTableEl;
4223 // kill repeat to save bytes
4227 tbe = '</tbody>'+te,
4233 * Nasty code for IE's broken table implementation
4235 var insertIntoTable = function(tag, where, el, html){
4237 tempTableEl = document.createElement('div');
4242 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4245 if(where == 'beforebegin'){
4249 before = el.nextSibling;
4252 node = ieTable(4, trs, html, tre);
4254 else if(tag == 'tr'){
4255 if(where == 'beforebegin'){
4258 node = ieTable(3, tbs, html, tbe);
4259 } else if(where == 'afterend'){
4260 before = el.nextSibling;
4262 node = ieTable(3, tbs, html, tbe);
4263 } else{ // INTO a TR
4264 if(where == 'afterbegin'){
4265 before = el.firstChild;
4267 node = ieTable(4, trs, html, tre);
4269 } else if(tag == 'tbody'){
4270 if(where == 'beforebegin'){
4273 node = ieTable(2, ts, html, te);
4274 } else if(where == 'afterend'){
4275 before = el.nextSibling;
4277 node = ieTable(2, ts, html, te);
4279 if(where == 'afterbegin'){
4280 before = el.firstChild;
4282 node = ieTable(3, tbs, html, tbe);
4285 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4288 if(where == 'afterbegin'){
4289 before = el.firstChild;
4291 node = ieTable(2, ts, html, te);
4293 el.insertBefore(node, before);
4298 /** True to force the use of DOM instead of html fragments @type Boolean */
4302 * Returns the markup for the passed Element(s) config
4303 * @param {Object} o The Dom object spec (and children)
4306 markup : function(o){
4307 return createHtml(o);
4311 * Applies a style specification to an element
4312 * @param {String/HTMLElement} el The element to apply styles to
4313 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4314 * a function which returns such a specification.
4316 applyStyles : function(el, styles){
4319 if(typeof styles == "string"){
4320 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4322 while ((matches = re.exec(styles)) != null){
4323 el.setStyle(matches[1], matches[2]);
4325 }else if (typeof styles == "object"){
4326 for (var style in styles){
4327 el.setStyle(style, styles[style]);
4329 }else if (typeof styles == "function"){
4330 Roo.DomHelper.applyStyles(el, styles.call());
4336 * Inserts an HTML fragment into the Dom
4337 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4338 * @param {HTMLElement} el The context element
4339 * @param {String} html The HTML fragmenet
4340 * @return {HTMLElement} The new node
4342 insertHtml : function(where, el, html){
4343 where = where.toLowerCase();
4344 if(el.insertAdjacentHTML){
4345 if(tableRe.test(el.tagName)){
4347 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4353 el.insertAdjacentHTML('BeforeBegin', html);
4354 return el.previousSibling;
4356 el.insertAdjacentHTML('AfterBegin', html);
4357 return el.firstChild;
4359 el.insertAdjacentHTML('BeforeEnd', html);
4360 return el.lastChild;
4362 el.insertAdjacentHTML('AfterEnd', html);
4363 return el.nextSibling;
4365 throw 'Illegal insertion point -> "' + where + '"';
4367 var range = el.ownerDocument.createRange();
4371 range.setStartBefore(el);
4372 frag = range.createContextualFragment(html);
4373 el.parentNode.insertBefore(frag, el);
4374 return el.previousSibling;
4377 range.setStartBefore(el.firstChild);
4378 frag = range.createContextualFragment(html);
4379 el.insertBefore(frag, el.firstChild);
4380 return el.firstChild;
4382 el.innerHTML = html;
4383 return el.firstChild;
4387 range.setStartAfter(el.lastChild);
4388 frag = range.createContextualFragment(html);
4389 el.appendChild(frag);
4390 return el.lastChild;
4392 el.innerHTML = html;
4393 return el.lastChild;
4396 range.setStartAfter(el);
4397 frag = range.createContextualFragment(html);
4398 el.parentNode.insertBefore(frag, el.nextSibling);
4399 return el.nextSibling;
4401 throw 'Illegal insertion point -> "' + where + '"';
4405 * Creates new Dom element(s) and inserts them before el
4406 * @param {String/HTMLElement/Element} el The context element
4407 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4408 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4409 * @return {HTMLElement/Roo.Element} The new node
4411 insertBefore : function(el, o, returnElement){
4412 return this.doInsert(el, o, returnElement, "beforeBegin");
4416 * Creates new Dom element(s) and inserts them after el
4417 * @param {String/HTMLElement/Element} el The context element
4418 * @param {Object} o The Dom object spec (and children)
4419 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4420 * @return {HTMLElement/Roo.Element} The new node
4422 insertAfter : function(el, o, returnElement){
4423 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4427 * Creates new Dom element(s) and inserts them as the first child of el
4428 * @param {String/HTMLElement/Element} el The context element
4429 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4430 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4431 * @return {HTMLElement/Roo.Element} The new node
4433 insertFirst : function(el, o, returnElement){
4434 return this.doInsert(el, o, returnElement, "afterBegin");
4438 doInsert : function(el, o, returnElement, pos, sibling){
4439 el = Roo.getDom(el);
4441 if(this.useDom || o.ns){
4442 newNode = createDom(o, null);
4443 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4445 var html = createHtml(o);
4446 newNode = this.insertHtml(pos, el, html);
4448 return returnElement ? Roo.get(newNode, true) : newNode;
4452 * Creates new Dom element(s) and appends them to el
4453 * @param {String/HTMLElement/Element} el The context element
4454 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4455 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4456 * @return {HTMLElement/Roo.Element} The new node
4458 append : function(el, o, returnElement){
4459 el = Roo.getDom(el);
4461 if(this.useDom || o.ns){
4462 newNode = createDom(o, null);
4463 el.appendChild(newNode);
4465 var html = createHtml(o);
4466 newNode = this.insertHtml("beforeEnd", el, html);
4468 return returnElement ? Roo.get(newNode, true) : newNode;
4472 * Creates new Dom element(s) and overwrites the contents of el with them
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 overwrite : function(el, o, returnElement){
4479 el = Roo.getDom(el);
4482 while (el.childNodes.length) {
4483 el.removeChild(el.firstChild);
4487 el.innerHTML = createHtml(o);
4490 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4494 * Creates a new Roo.DomHelper.Template from the Dom object spec
4495 * @param {Object} o The Dom object spec (and children)
4496 * @return {Roo.DomHelper.Template} The new template
4498 createTemplate : function(o){
4499 var html = createHtml(o);
4500 return new Roo.Template(html);
4506 * Ext JS Library 1.1.1
4507 * Copyright(c) 2006-2007, Ext JS, LLC.
4509 * Originally Released Under LGPL - original licence link has changed is not relivant.
4512 * <script type="text/javascript">
4516 * @class Roo.Template
4517 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4518 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4521 var t = new Roo.Template({
4522 html : '<div name="{id}">' +
4523 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4525 myformat: function (value, allValues) {
4526 return 'XX' + value;
4529 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4531 * For more information see this blog post with examples: <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">DomHelper - Create Elements using DOM, HTML fragments and Templates</a>.
4533 * @param {Object} cfg - Configuration object.
4535 Roo.Template = function(cfg){
4537 if(cfg instanceof Array){
4539 }else if(arguments.length > 1){
4540 cfg = Array.prototype.join.call(arguments, "");
4544 if (typeof(cfg) == 'object') {
4553 Roo.Template.prototype = {
4556 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4560 * Returns an HTML fragment of this template with the specified values applied.
4561 * @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'})
4562 * @return {String} The HTML fragment
4564 applyTemplate : function(values){
4568 return this.compiled(values);
4570 var useF = this.disableFormats !== true;
4571 var fm = Roo.util.Format, tpl = this;
4572 var fn = function(m, name, format, args){
4574 if(format.substr(0, 5) == "this."){
4575 return tpl.call(format.substr(5), values[name], values);
4578 // quoted values are required for strings in compiled templates,
4579 // but for non compiled we need to strip them
4580 // quoted reversed for jsmin
4581 var re = /^\s*['"](.*)["']\s*$/;
4582 args = args.split(',');
4583 for(var i = 0, len = args.length; i < len; i++){
4584 args[i] = args[i].replace(re, "$1");
4586 args = [values[name]].concat(args);
4588 args = [values[name]];
4590 return fm[format].apply(fm, args);
4593 return values[name] !== undefined ? values[name] : "";
4596 return this.html.replace(this.re, fn);
4605 * Sets the HTML used as the template and optionally compiles it.
4606 * @param {String} html
4607 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4608 * @return {Roo.Template} this
4610 set : function(html, compile){
4612 this.compiled = null;
4620 * True to disable format functions (defaults to false)
4623 disableFormats : false,
4626 * The regular expression used to match template variables
4630 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4633 * Compiles the template into an internal function, eliminating the RegEx overhead.
4634 * @return {Roo.Template} this
4636 compile : function(){
4637 var fm = Roo.util.Format;
4638 var useF = this.disableFormats !== true;
4639 var sep = Roo.isGecko ? "+" : ",";
4640 var fn = function(m, name, format, args){
4642 args = args ? ',' + args : "";
4643 if(format.substr(0, 5) != "this."){
4644 format = "fm." + format + '(';
4646 format = 'this.call("'+ format.substr(5) + '", ';
4650 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4652 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4655 // branched to use + in gecko and [].join() in others
4657 body = "this.compiled = function(values){ return '" +
4658 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4661 body = ["this.compiled = function(values){ return ['"];
4662 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4663 body.push("'].join('');};");
4664 body = body.join('');
4674 // private function used to call members
4675 call : function(fnName, value, allValues){
4676 return this[fnName](value, allValues);
4680 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4681 * @param {String/HTMLElement/Roo.Element} el The context element
4682 * @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'})
4683 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4684 * @return {HTMLElement/Roo.Element} The new node or Element
4686 insertFirst: function(el, values, returnElement){
4687 return this.doInsert('afterBegin', el, values, returnElement);
4691 * Applies the supplied values to the template and inserts the new node(s) before el.
4692 * @param {String/HTMLElement/Roo.Element} el The context element
4693 * @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'})
4694 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4695 * @return {HTMLElement/Roo.Element} The new node or Element
4697 insertBefore: function(el, values, returnElement){
4698 return this.doInsert('beforeBegin', el, values, returnElement);
4702 * Applies the supplied values to the template and inserts the new node(s) after el.
4703 * @param {String/HTMLElement/Roo.Element} el The context element
4704 * @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'})
4705 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4706 * @return {HTMLElement/Roo.Element} The new node or Element
4708 insertAfter : function(el, values, returnElement){
4709 return this.doInsert('afterEnd', el, values, returnElement);
4713 * Applies the supplied values to the template and appends the new node(s) to el.
4714 * @param {String/HTMLElement/Roo.Element} el The context element
4715 * @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'})
4716 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4717 * @return {HTMLElement/Roo.Element} The new node or Element
4719 append : function(el, values, returnElement){
4720 return this.doInsert('beforeEnd', el, values, returnElement);
4723 doInsert : function(where, el, values, returnEl){
4724 el = Roo.getDom(el);
4725 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4726 return returnEl ? Roo.get(newNode, true) : newNode;
4730 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4731 * @param {String/HTMLElement/Roo.Element} el The context element
4732 * @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'})
4733 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4734 * @return {HTMLElement/Roo.Element} The new node or Element
4736 overwrite : function(el, values, returnElement){
4737 el = Roo.getDom(el);
4738 el.innerHTML = this.applyTemplate(values);
4739 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4743 * Alias for {@link #applyTemplate}
4746 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4749 Roo.DomHelper.Template = Roo.Template;
4752 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4753 * @param {String/HTMLElement} el A DOM element or its id
4754 * @returns {Roo.Template} The created template
4757 Roo.Template.from = function(el){
4758 el = Roo.getDom(el);
4759 return new Roo.Template(el.value || el.innerHTML);
4762 * Ext JS Library 1.1.1
4763 * Copyright(c) 2006-2007, Ext JS, LLC.
4765 * Originally Released Under LGPL - original licence link has changed is not relivant.
4768 * <script type="text/javascript">
4773 * This is code is also distributed under MIT license for use
4774 * with jQuery and prototype JavaScript libraries.
4777 * @class Roo.DomQuery
4778 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).
4780 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>
4783 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.
4785 <h4>Element Selectors:</h4>
4787 <li> <b>*</b> any element</li>
4788 <li> <b>E</b> an element with the tag E</li>
4789 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4790 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4791 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4792 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4794 <h4>Attribute Selectors:</h4>
4795 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4797 <li> <b>E[foo]</b> has an attribute "foo"</li>
4798 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4799 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4800 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4801 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4802 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4803 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4805 <h4>Pseudo Classes:</h4>
4807 <li> <b>E:first-child</b> E is the first child of its parent</li>
4808 <li> <b>E:last-child</b> E is the last child of its parent</li>
4809 <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>
4810 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4811 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4812 <li> <b>E:only-child</b> E is the only child of its parent</li>
4813 <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>
4814 <li> <b>E:first</b> the first E in the resultset</li>
4815 <li> <b>E:last</b> the last E in the resultset</li>
4816 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4817 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4818 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4819 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4820 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4821 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4822 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4823 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4824 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4826 <h4>CSS Value Selectors:</h4>
4828 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4829 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4830 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4831 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4832 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4833 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4837 Roo.DomQuery = function(){
4838 var cache = {}, simpleCache = {}, valueCache = {};
4839 var nonSpace = /\S/;
4840 var trimRe = /^\s+|\s+$/g;
4841 var tplRe = /\{(\d+)\}/g;
4842 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4843 var tagTokenRe = /^(#)?([\w-\*]+)/;
4844 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4846 function child(p, index){
4848 var n = p.firstChild;
4850 if(n.nodeType == 1){
4861 while((n = n.nextSibling) && n.nodeType != 1);
4866 while((n = n.previousSibling) && n.nodeType != 1);
4870 function children(d){
4871 var n = d.firstChild, ni = -1;
4873 var nx = n.nextSibling;
4874 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4884 function byClassName(c, a, v){
4888 var r = [], ri = -1, cn;
4889 for(var i = 0, ci; ci = c[i]; i++){
4890 if((' '+ci.className+' ').indexOf(v) != -1){
4897 function attrValue(n, attr){
4898 if(!n.tagName && typeof n.length != "undefined"){
4907 if(attr == "class" || attr == "className"){
4910 return n.getAttribute(attr) || n[attr];
4914 function getNodes(ns, mode, tagName){
4915 var result = [], ri = -1, cs;
4919 tagName = tagName || "*";
4920 if(typeof ns.getElementsByTagName != "undefined"){
4924 for(var i = 0, ni; ni = ns[i]; i++){
4925 cs = ni.getElementsByTagName(tagName);
4926 for(var j = 0, ci; ci = cs[j]; j++){
4930 }else if(mode == "/" || mode == ">"){
4931 var utag = tagName.toUpperCase();
4932 for(var i = 0, ni, cn; ni = ns[i]; i++){
4933 cn = ni.children || ni.childNodes;
4934 for(var j = 0, cj; cj = cn[j]; j++){
4935 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
4940 }else if(mode == "+"){
4941 var utag = tagName.toUpperCase();
4942 for(var i = 0, n; n = ns[i]; i++){
4943 while((n = n.nextSibling) && n.nodeType != 1);
4944 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
4948 }else if(mode == "~"){
4949 for(var i = 0, n; n = ns[i]; i++){
4950 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
4959 function concat(a, b){
4963 for(var i = 0, l = b.length; i < l; i++){
4969 function byTag(cs, tagName){
4970 if(cs.tagName || cs == document){
4976 var r = [], ri = -1;
4977 tagName = tagName.toLowerCase();
4978 for(var i = 0, ci; ci = cs[i]; i++){
4979 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
4986 function byId(cs, attr, id){
4987 if(cs.tagName || cs == document){
4993 var r = [], ri = -1;
4994 for(var i = 0,ci; ci = cs[i]; i++){
4995 if(ci && ci.id == id){
5003 function byAttribute(cs, attr, value, op, custom){
5004 var r = [], ri = -1, st = custom=="{";
5005 var f = Roo.DomQuery.operators[op];
5006 for(var i = 0, ci; ci = cs[i]; i++){
5009 a = Roo.DomQuery.getStyle(ci, attr);
5011 else if(attr == "class" || attr == "className"){
5013 }else if(attr == "for"){
5015 }else if(attr == "href"){
5016 a = ci.getAttribute("href", 2);
5018 a = ci.getAttribute(attr);
5020 if((f && f(a, value)) || (!f && a)){
5027 function byPseudo(cs, name, value){
5028 return Roo.DomQuery.pseudos[name](cs, value);
5031 // This is for IE MSXML which does not support expandos.
5032 // IE runs the same speed using setAttribute, however FF slows way down
5033 // and Safari completely fails so they need to continue to use expandos.
5034 var isIE = window.ActiveXObject ? true : false;
5036 // this eval is stop the compressor from
5037 // renaming the variable to something shorter
5039 /** eval:var:batch */
5044 function nodupIEXml(cs){
5046 cs[0].setAttribute("_nodup", d);
5048 for(var i = 1, len = cs.length; i < len; i++){
5050 if(!c.getAttribute("_nodup") != d){
5051 c.setAttribute("_nodup", d);
5055 for(var i = 0, len = cs.length; i < len; i++){
5056 cs[i].removeAttribute("_nodup");
5065 var len = cs.length, c, i, r = cs, cj, ri = -1;
5066 if(!len || typeof cs.nodeType != "undefined" || len == 1){
5069 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
5070 return nodupIEXml(cs);
5074 for(i = 1; c = cs[i]; i++){
5079 for(var j = 0; j < i; j++){
5082 for(j = i+1; cj = cs[j]; j++){
5094 function quickDiffIEXml(c1, c2){
5096 for(var i = 0, len = c1.length; i < len; i++){
5097 c1[i].setAttribute("_qdiff", d);
5100 for(var i = 0, len = c2.length; i < len; i++){
5101 if(c2[i].getAttribute("_qdiff") != d){
5102 r[r.length] = c2[i];
5105 for(var i = 0, len = c1.length; i < len; i++){
5106 c1[i].removeAttribute("_qdiff");
5111 function quickDiff(c1, c2){
5112 var len1 = c1.length;
5116 if(isIE && c1[0].selectSingleNode){
5117 return quickDiffIEXml(c1, c2);
5120 for(var i = 0; i < len1; i++){
5124 for(var i = 0, len = c2.length; i < len; i++){
5125 if(c2[i]._qdiff != d){
5126 r[r.length] = c2[i];
5132 function quickId(ns, mode, root, id){
5134 var d = root.ownerDocument || root;
5135 return d.getElementById(id);
5137 ns = getNodes(ns, mode, "*");
5138 return byId(ns, null, id);
5142 getStyle : function(el, name){
5143 return Roo.fly(el).getStyle(name);
5146 * Compiles a selector/xpath query into a reusable function. The returned function
5147 * takes one parameter "root" (optional), which is the context node from where the query should start.
5148 * @param {String} selector The selector/xpath query
5149 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5150 * @return {Function}
5152 compile : function(path, type){
5153 type = type || "select";
5155 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5156 var q = path, mode, lq;
5157 var tk = Roo.DomQuery.matchers;
5158 var tklen = tk.length;
5161 // accept leading mode switch
5162 var lmode = q.match(modeRe);
5163 if(lmode && lmode[1]){
5164 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5165 q = q.replace(lmode[1], "");
5167 // strip leading slashes
5168 while(path.substr(0, 1)=="/"){
5169 path = path.substr(1);
5172 while(q && lq != q){
5174 var tm = q.match(tagTokenRe);
5175 if(type == "select"){
5178 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5180 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5182 q = q.replace(tm[0], "");
5183 }else if(q.substr(0, 1) != '@'){
5184 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5189 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5191 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5193 q = q.replace(tm[0], "");
5196 while(!(mm = q.match(modeRe))){
5197 var matched = false;
5198 for(var j = 0; j < tklen; j++){
5200 var m = q.match(t.re);
5202 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5205 q = q.replace(m[0], "");
5210 // prevent infinite loop on bad selector
5212 throw 'Error parsing selector, parsing failed at "' + q + '"';
5216 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5217 q = q.replace(mm[1], "");
5220 fn[fn.length] = "return nodup(n);\n}";
5223 * list of variables that need from compression as they are used by eval.
5233 * eval:var:byClassName
5235 * eval:var:byAttribute
5236 * eval:var:attrValue
5244 * Selects a group of elements.
5245 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5246 * @param {Node} root (optional) The start of the query (defaults to document).
5249 select : function(path, root, type){
5250 if(!root || root == document){
5253 if(typeof root == "string"){
5254 root = document.getElementById(root);
5256 var paths = path.split(",");
5258 for(var i = 0, len = paths.length; i < len; i++){
5259 var p = paths[i].replace(trimRe, "");
5261 cache[p] = Roo.DomQuery.compile(p);
5263 throw p + " is not a valid selector";
5266 var result = cache[p](root);
5267 if(result && result != document){
5268 results = results.concat(result);
5271 if(paths.length > 1){
5272 return nodup(results);
5278 * Selects a single element.
5279 * @param {String} selector The selector/xpath query
5280 * @param {Node} root (optional) The start of the query (defaults to document).
5283 selectNode : function(path, root){
5284 return Roo.DomQuery.select(path, root)[0];
5288 * Selects the value of a node, optionally replacing null with the defaultValue.
5289 * @param {String} selector The selector/xpath query
5290 * @param {Node} root (optional) The start of the query (defaults to document).
5291 * @param {String} defaultValue
5293 selectValue : function(path, root, defaultValue){
5294 path = path.replace(trimRe, "");
5295 if(!valueCache[path]){
5296 valueCache[path] = Roo.DomQuery.compile(path, "select");
5298 var n = valueCache[path](root);
5299 n = n[0] ? n[0] : n;
5300 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5301 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5305 * Selects the value of a node, parsing integers and floats.
5306 * @param {String} selector The selector/xpath query
5307 * @param {Node} root (optional) The start of the query (defaults to document).
5308 * @param {Number} defaultValue
5311 selectNumber : function(path, root, defaultValue){
5312 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5313 return parseFloat(v);
5317 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5318 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5319 * @param {String} selector The simple selector to test
5322 is : function(el, ss){
5323 if(typeof el == "string"){
5324 el = document.getElementById(el);
5326 var isArray = (el instanceof Array);
5327 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5328 return isArray ? (result.length == el.length) : (result.length > 0);
5332 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5333 * @param {Array} el An array of elements to filter
5334 * @param {String} selector The simple selector to test
5335 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5336 * the selector instead of the ones that match
5339 filter : function(els, ss, nonMatches){
5340 ss = ss.replace(trimRe, "");
5341 if(!simpleCache[ss]){
5342 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5344 var result = simpleCache[ss](els);
5345 return nonMatches ? quickDiff(result, els) : result;
5349 * Collection of matching regular expressions and code snippets.
5353 select: 'n = byClassName(n, null, " {1} ");'
5355 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5356 select: 'n = byPseudo(n, "{1}", "{2}");'
5358 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5359 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5362 select: 'n = byId(n, null, "{1}");'
5365 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5370 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5371 * 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, > <.
5374 "=" : function(a, v){
5377 "!=" : function(a, v){
5380 "^=" : function(a, v){
5381 return a && a.substr(0, v.length) == v;
5383 "$=" : function(a, v){
5384 return a && a.substr(a.length-v.length) == v;
5386 "*=" : function(a, v){
5387 return a && a.indexOf(v) !== -1;
5389 "%=" : function(a, v){
5390 return (a % v) == 0;
5392 "|=" : function(a, v){
5393 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5395 "~=" : function(a, v){
5396 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5401 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5402 * and the argument (if any) supplied in the selector.
5405 "first-child" : function(c){
5406 var r = [], ri = -1, n;
5407 for(var i = 0, ci; ci = n = c[i]; i++){
5408 while((n = n.previousSibling) && n.nodeType != 1);
5416 "last-child" : function(c){
5417 var r = [], ri = -1, n;
5418 for(var i = 0, ci; ci = n = c[i]; i++){
5419 while((n = n.nextSibling) && n.nodeType != 1);
5427 "nth-child" : function(c, a) {
5428 var r = [], ri = -1;
5429 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5430 var f = (m[1] || 1) - 0, l = m[2] - 0;
5431 for(var i = 0, n; n = c[i]; i++){
5432 var pn = n.parentNode;
5433 if (batch != pn._batch) {
5435 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5436 if(cn.nodeType == 1){
5443 if (l == 0 || n.nodeIndex == l){
5446 } else if ((n.nodeIndex + l) % f == 0){
5454 "only-child" : function(c){
5455 var r = [], ri = -1;;
5456 for(var i = 0, ci; ci = c[i]; i++){
5457 if(!prev(ci) && !next(ci)){
5464 "empty" : function(c){
5465 var r = [], ri = -1;
5466 for(var i = 0, ci; ci = c[i]; i++){
5467 var cns = ci.childNodes, j = 0, cn, empty = true;
5470 if(cn.nodeType == 1 || cn.nodeType == 3){
5482 "contains" : function(c, v){
5483 var r = [], ri = -1;
5484 for(var i = 0, ci; ci = c[i]; i++){
5485 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5492 "nodeValue" : function(c, v){
5493 var r = [], ri = -1;
5494 for(var i = 0, ci; ci = c[i]; i++){
5495 if(ci.firstChild && ci.firstChild.nodeValue == v){
5502 "checked" : function(c){
5503 var r = [], ri = -1;
5504 for(var i = 0, ci; ci = c[i]; i++){
5505 if(ci.checked == true){
5512 "not" : function(c, ss){
5513 return Roo.DomQuery.filter(c, ss, true);
5516 "odd" : function(c){
5517 return this["nth-child"](c, "odd");
5520 "even" : function(c){
5521 return this["nth-child"](c, "even");
5524 "nth" : function(c, a){
5525 return c[a-1] || [];
5528 "first" : function(c){
5532 "last" : function(c){
5533 return c[c.length-1] || [];
5536 "has" : function(c, ss){
5537 var s = Roo.DomQuery.select;
5538 var r = [], ri = -1;
5539 for(var i = 0, ci; ci = c[i]; i++){
5540 if(s(ss, ci).length > 0){
5547 "next" : function(c, ss){
5548 var is = Roo.DomQuery.is;
5549 var r = [], ri = -1;
5550 for(var i = 0, ci; ci = c[i]; i++){
5559 "prev" : function(c, ss){
5560 var is = Roo.DomQuery.is;
5561 var r = [], ri = -1;
5562 for(var i = 0, ci; ci = c[i]; i++){
5575 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5576 * @param {String} path The selector/xpath query
5577 * @param {Node} root (optional) The start of the query (defaults to document).
5582 Roo.query = Roo.DomQuery.select;
5585 * Ext JS Library 1.1.1
5586 * Copyright(c) 2006-2007, Ext JS, LLC.
5588 * Originally Released Under LGPL - original licence link has changed is not relivant.
5591 * <script type="text/javascript">
5595 * @class Roo.util.Observable
5596 * Base class that provides a common interface for publishing events. Subclasses are expected to
5597 * to have a property "events" with all the events defined.<br>
5600 Employee = function(name){
5607 Roo.extend(Employee, Roo.util.Observable);
5609 * @param {Object} config properties to use (incuding events / listeners)
5612 Roo.util.Observable = function(cfg){
5615 this.addEvents(cfg.events || {});
5617 delete cfg.events; // make sure
5620 Roo.apply(this, cfg);
5623 this.on(this.listeners);
5624 delete this.listeners;
5627 Roo.util.Observable.prototype = {
5629 * @cfg {Object} listeners list of events and functions to call for this object,
5633 'click' : function(e) {
5643 * Fires the specified event with the passed parameters (minus the event name).
5644 * @param {String} eventName
5645 * @param {Object...} args Variable number of parameters are passed to handlers
5646 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5648 fireEvent : function(){
5649 var ce = this.events[arguments[0].toLowerCase()];
5650 if(typeof ce == "object"){
5651 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5658 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5661 * Appends an event handler to this component
5662 * @param {String} eventName The type of event to listen for
5663 * @param {Function} handler The method the event invokes
5664 * @param {Object} scope (optional) The scope in which to execute the handler
5665 * function. The handler function's "this" context.
5666 * @param {Object} options (optional) An object containing handler configuration
5667 * properties. This may contain any of the following properties:<ul>
5668 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5669 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5670 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5671 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5672 * by the specified number of milliseconds. If the event fires again within that time, the original
5673 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5676 * <b>Combining Options</b><br>
5677 * Using the options argument, it is possible to combine different types of listeners:<br>
5679 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5681 el.on('click', this.onClick, this, {
5688 * <b>Attaching multiple handlers in 1 call</b><br>
5689 * The method also allows for a single argument to be passed which is a config object containing properties
5690 * which specify multiple handlers.
5699 fn: this.onMouseOver,
5703 fn: this.onMouseOut,
5709 * Or a shorthand syntax which passes the same scope object to all handlers:
5712 'click': this.onClick,
5713 'mouseover': this.onMouseOver,
5714 'mouseout': this.onMouseOut,
5719 addListener : function(eventName, fn, scope, o){
5720 if(typeof eventName == "object"){
5723 if(this.filterOptRe.test(e)){
5726 if(typeof o[e] == "function"){
5728 this.addListener(e, o[e], o.scope, o);
5730 // individual options
5731 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5736 o = (!o || typeof o == "boolean") ? {} : o;
5737 eventName = eventName.toLowerCase();
5738 var ce = this.events[eventName] || true;
5739 if(typeof ce == "boolean"){
5740 ce = new Roo.util.Event(this, eventName);
5741 this.events[eventName] = ce;
5743 ce.addListener(fn, scope, o);
5747 * Removes a listener
5748 * @param {String} eventName The type of event to listen for
5749 * @param {Function} handler The handler to remove
5750 * @param {Object} scope (optional) The scope (this object) for the handler
5752 removeListener : function(eventName, fn, scope){
5753 var ce = this.events[eventName.toLowerCase()];
5754 if(typeof ce == "object"){
5755 ce.removeListener(fn, scope);
5760 * Removes all listeners for this object
5762 purgeListeners : function(){
5763 for(var evt in this.events){
5764 if(typeof this.events[evt] == "object"){
5765 this.events[evt].clearListeners();
5770 relayEvents : function(o, events){
5771 var createHandler = function(ename){
5773 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5776 for(var i = 0, len = events.length; i < len; i++){
5777 var ename = events[i];
5778 if(!this.events[ename]){ this.events[ename] = true; };
5779 o.on(ename, createHandler(ename), this);
5784 * Used to define events on this Observable
5785 * @param {Object} object The object with the events defined
5787 addEvents : function(o){
5791 Roo.applyIf(this.events, o);
5795 * Checks to see if this object has any listeners for a specified event
5796 * @param {String} eventName The name of the event to check for
5797 * @return {Boolean} True if the event is being listened for, else false
5799 hasListener : function(eventName){
5800 var e = this.events[eventName];
5801 return typeof e == "object" && e.listeners.length > 0;
5805 * Appends an event handler to this element (shorthand for addListener)
5806 * @param {String} eventName The type of event to listen for
5807 * @param {Function} handler The method the event invokes
5808 * @param {Object} scope (optional) The scope in which to execute the handler
5809 * function. The handler function's "this" context.
5810 * @param {Object} options (optional)
5813 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5815 * Removes a listener (shorthand for removeListener)
5816 * @param {String} eventName The type of event to listen for
5817 * @param {Function} handler The handler to remove
5818 * @param {Object} scope (optional) The scope (this object) for the handler
5821 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5824 * Starts capture on the specified Observable. All events will be passed
5825 * to the supplied function with the event name + standard signature of the event
5826 * <b>before</b> the event is fired. If the supplied function returns false,
5827 * the event will not fire.
5828 * @param {Observable} o The Observable to capture
5829 * @param {Function} fn The function to call
5830 * @param {Object} scope (optional) The scope (this object) for the fn
5833 Roo.util.Observable.capture = function(o, fn, scope){
5834 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5838 * Removes <b>all</b> added captures from the Observable.
5839 * @param {Observable} o The Observable to release
5842 Roo.util.Observable.releaseCapture = function(o){
5843 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5848 var createBuffered = function(h, o, scope){
5849 var task = new Roo.util.DelayedTask();
5851 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5855 var createSingle = function(h, e, fn, scope){
5857 e.removeListener(fn, scope);
5858 return h.apply(scope, arguments);
5862 var createDelayed = function(h, o, scope){
5864 var args = Array.prototype.slice.call(arguments, 0);
5865 setTimeout(function(){
5866 h.apply(scope, args);
5871 Roo.util.Event = function(obj, name){
5874 this.listeners = [];
5877 Roo.util.Event.prototype = {
5878 addListener : function(fn, scope, options){
5879 var o = options || {};
5880 scope = scope || this.obj;
5881 if(!this.isListening(fn, scope)){
5882 var l = {fn: fn, scope: scope, options: o};
5885 h = createDelayed(h, o, scope);
5888 h = createSingle(h, this, fn, scope);
5891 h = createBuffered(h, o, scope);
5894 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
5895 this.listeners.push(l);
5897 this.listeners = this.listeners.slice(0);
5898 this.listeners.push(l);
5903 findListener : function(fn, scope){
5904 scope = scope || this.obj;
5905 var ls = this.listeners;
5906 for(var i = 0, len = ls.length; i < len; i++){
5908 if(l.fn == fn && l.scope == scope){
5915 isListening : function(fn, scope){
5916 return this.findListener(fn, scope) != -1;
5919 removeListener : function(fn, scope){
5921 if((index = this.findListener(fn, scope)) != -1){
5923 this.listeners.splice(index, 1);
5925 this.listeners = this.listeners.slice(0);
5926 this.listeners.splice(index, 1);
5933 clearListeners : function(){
5934 this.listeners = [];
5938 var ls = this.listeners, scope, len = ls.length;
5941 var args = Array.prototype.slice.call(arguments, 0);
5942 for(var i = 0; i < len; i++){
5944 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
5945 this.firing = false;
5949 this.firing = false;
5956 * Ext JS Library 1.1.1
5957 * Copyright(c) 2006-2007, Ext JS, LLC.
5959 * Originally Released Under LGPL - original licence link has changed is not relivant.
5962 * <script type="text/javascript">
5966 * @class Roo.EventManager
5967 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
5968 * several useful events directly.
5969 * See {@link Roo.EventObject} for more details on normalized event objects.
5972 Roo.EventManager = function(){
5973 var docReadyEvent, docReadyProcId, docReadyState = false;
5974 var resizeEvent, resizeTask, textEvent, textSize;
5975 var E = Roo.lib.Event;
5976 var D = Roo.lib.Dom;
5979 var fireDocReady = function(){
5981 docReadyState = true;
5984 clearInterval(docReadyProcId);
5986 if(Roo.isGecko || Roo.isOpera) {
5987 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
5990 var defer = document.getElementById("ie-deferred-loader");
5992 defer.onreadystatechange = null;
5993 defer.parentNode.removeChild(defer);
5997 docReadyEvent.fire();
5998 docReadyEvent.clearListeners();
6003 var initDocReady = function(){
6004 docReadyEvent = new Roo.util.Event();
6005 if(Roo.isGecko || Roo.isOpera) {
6006 document.addEventListener("DOMContentLoaded", fireDocReady, false);
6008 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
6009 var defer = document.getElementById("ie-deferred-loader");
6010 defer.onreadystatechange = function(){
6011 if(this.readyState == "complete"){
6015 }else if(Roo.isSafari){
6016 docReadyProcId = setInterval(function(){
6017 var rs = document.readyState;
6018 if(rs == "complete") {
6023 // no matter what, make sure it fires on load
6024 E.on(window, "load", fireDocReady);
6027 var createBuffered = function(h, o){
6028 var task = new Roo.util.DelayedTask(h);
6030 // create new event object impl so new events don't wipe out properties
6031 e = new Roo.EventObjectImpl(e);
6032 task.delay(o.buffer, h, null, [e]);
6036 var createSingle = function(h, el, ename, fn){
6038 Roo.EventManager.removeListener(el, ename, fn);
6043 var createDelayed = function(h, o){
6045 // create new event object impl so new events don't wipe out properties
6046 e = new Roo.EventObjectImpl(e);
6047 setTimeout(function(){
6053 var listen = function(element, ename, opt, fn, scope){
6054 var o = (!opt || typeof opt == "boolean") ? {} : opt;
6055 fn = fn || o.fn; scope = scope || o.scope;
6056 var el = Roo.getDom(element);
6058 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
6060 var h = function(e){
6061 e = Roo.EventObject.setEvent(e);
6064 t = e.getTarget(o.delegate, el);
6071 if(o.stopEvent === true){
6074 if(o.preventDefault === true){
6077 if(o.stopPropagation === true){
6078 e.stopPropagation();
6081 if(o.normalized === false){
6085 fn.call(scope || el, e, t, o);
6088 h = createDelayed(h, o);
6091 h = createSingle(h, el, ename, fn);
6094 h = createBuffered(h, o);
6096 fn._handlers = fn._handlers || [];
6097 fn._handlers.push([Roo.id(el), ename, h]);
6100 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
6101 el.addEventListener("DOMMouseScroll", h, false);
6102 E.on(window, 'unload', function(){
6103 el.removeEventListener("DOMMouseScroll", h, false);
6106 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6107 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
6112 var stopListening = function(el, ename, fn){
6113 var id = Roo.id(el), hds = fn._handlers, hd = fn;
6115 for(var i = 0, len = hds.length; i < len; i++){
6117 if(h[0] == id && h[1] == ename){
6124 E.un(el, ename, hd);
6125 el = Roo.getDom(el);
6126 if(ename == "mousewheel" && el.addEventListener){
6127 el.removeEventListener("DOMMouseScroll", hd, false);
6129 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6130 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6134 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6141 * @scope Roo.EventManager
6146 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6147 * object with a Roo.EventObject
6148 * @param {Function} fn The method the event invokes
6149 * @param {Object} scope An object that becomes the scope of the handler
6150 * @param {boolean} override If true, the obj passed in becomes
6151 * the execution scope of the listener
6152 * @return {Function} The wrapped function
6155 wrap : function(fn, scope, override){
6157 Roo.EventObject.setEvent(e);
6158 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6163 * Appends an event handler to an element (shorthand for addListener)
6164 * @param {String/HTMLElement} element The html element or id to assign the
6165 * @param {String} eventName The type of event to listen for
6166 * @param {Function} handler The method the event invokes
6167 * @param {Object} scope (optional) The scope in which to execute the handler
6168 * function. The handler function's "this" context.
6169 * @param {Object} options (optional) An object containing handler configuration
6170 * properties. This may contain any of the following properties:<ul>
6171 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6172 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6173 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6174 * <li>preventDefault {Boolean} True to prevent the default action</li>
6175 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6176 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6177 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6178 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6179 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6180 * by the specified number of milliseconds. If the event fires again within that time, the original
6181 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6184 * <b>Combining Options</b><br>
6185 * Using the options argument, it is possible to combine different types of listeners:<br>
6187 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6189 el.on('click', this.onClick, this, {
6196 * <b>Attaching multiple handlers in 1 call</b><br>
6197 * The method also allows for a single argument to be passed which is a config object containing properties
6198 * which specify multiple handlers.
6208 fn: this.onMouseOver
6217 * Or a shorthand syntax:<br>
6220 'click' : this.onClick,
6221 'mouseover' : this.onMouseOver,
6222 'mouseout' : this.onMouseOut
6226 addListener : function(element, eventName, fn, scope, options){
6227 if(typeof eventName == "object"){
6233 if(typeof o[e] == "function"){
6235 listen(element, e, o, o[e], o.scope);
6237 // individual options
6238 listen(element, e, o[e]);
6243 return listen(element, eventName, options, fn, scope);
6247 * Removes an event handler
6249 * @param {String/HTMLElement} element The id or html element to remove the
6251 * @param {String} eventName The type of event
6252 * @param {Function} fn
6253 * @return {Boolean} True if a listener was actually removed
6255 removeListener : function(element, eventName, fn){
6256 return stopListening(element, eventName, fn);
6260 * Fires when the document is ready (before onload and before images are loaded). Can be
6261 * accessed shorthanded Roo.onReady().
6262 * @param {Function} fn The method the event invokes
6263 * @param {Object} scope An object that becomes the scope of the handler
6264 * @param {boolean} options
6266 onDocumentReady : function(fn, scope, options){
6267 if(docReadyState){ // if it already fired
6268 docReadyEvent.addListener(fn, scope, options);
6269 docReadyEvent.fire();
6270 docReadyEvent.clearListeners();
6276 docReadyEvent.addListener(fn, scope, options);
6280 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6281 * @param {Function} fn The method the event invokes
6282 * @param {Object} scope An object that becomes the scope of the handler
6283 * @param {boolean} options
6285 onWindowResize : function(fn, scope, options){
6287 resizeEvent = new Roo.util.Event();
6288 resizeTask = new Roo.util.DelayedTask(function(){
6289 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6291 E.on(window, "resize", function(){
6293 resizeTask.delay(50);
6295 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6299 resizeEvent.addListener(fn, scope, options);
6303 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6304 * @param {Function} fn The method the event invokes
6305 * @param {Object} scope An object that becomes the scope of the handler
6306 * @param {boolean} options
6308 onTextResize : function(fn, scope, options){
6310 textEvent = new Roo.util.Event();
6311 var textEl = new Roo.Element(document.createElement('div'));
6312 textEl.dom.className = 'x-text-resize';
6313 textEl.dom.innerHTML = 'X';
6314 textEl.appendTo(document.body);
6315 textSize = textEl.dom.offsetHeight;
6316 setInterval(function(){
6317 if(textEl.dom.offsetHeight != textSize){
6318 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6320 }, this.textResizeInterval);
6322 textEvent.addListener(fn, scope, options);
6326 * Removes the passed window resize listener.
6327 * @param {Function} fn The method the event invokes
6328 * @param {Object} scope The scope of handler
6330 removeResizeListener : function(fn, scope){
6332 resizeEvent.removeListener(fn, scope);
6337 fireResize : function(){
6339 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6343 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6347 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6349 textResizeInterval : 50
6354 * @scopeAlias pub=Roo.EventManager
6358 * Appends an event handler to an element (shorthand for addListener)
6359 * @param {String/HTMLElement} element The html element or id to assign the
6360 * @param {String} eventName The type of event to listen for
6361 * @param {Function} handler The method the event invokes
6362 * @param {Object} scope (optional) The scope in which to execute the handler
6363 * function. The handler function's "this" context.
6364 * @param {Object} options (optional) An object containing handler configuration
6365 * properties. This may contain any of the following properties:<ul>
6366 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6367 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6368 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6369 * <li>preventDefault {Boolean} True to prevent the default action</li>
6370 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6371 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6372 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6373 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6374 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6375 * by the specified number of milliseconds. If the event fires again within that time, the original
6376 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6379 * <b>Combining Options</b><br>
6380 * Using the options argument, it is possible to combine different types of listeners:<br>
6382 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6384 el.on('click', this.onClick, this, {
6391 * <b>Attaching multiple handlers in 1 call</b><br>
6392 * The method also allows for a single argument to be passed which is a config object containing properties
6393 * which specify multiple handlers.
6403 fn: this.onMouseOver
6412 * Or a shorthand syntax:<br>
6415 'click' : this.onClick,
6416 'mouseover' : this.onMouseOver,
6417 'mouseout' : this.onMouseOut
6421 pub.on = pub.addListener;
6422 pub.un = pub.removeListener;
6424 pub.stoppedMouseDownEvent = new Roo.util.Event();
6428 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6429 * @param {Function} fn The method the event invokes
6430 * @param {Object} scope An object that becomes the scope of the handler
6431 * @param {boolean} override If true, the obj passed in becomes
6432 * the execution scope of the listener
6436 Roo.onReady = Roo.EventManager.onDocumentReady;
6438 Roo.onReady(function(){
6439 var bd = Roo.get(document.body);
6444 : Roo.isGecko ? "roo-gecko"
6445 : Roo.isOpera ? "roo-opera"
6446 : Roo.isSafari ? "roo-safari" : ""];
6449 cls.push("roo-mac");
6452 cls.push("roo-linux");
6454 if(Roo.isBorderBox){
6455 cls.push('roo-border-box');
6457 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6458 var p = bd.dom.parentNode;
6460 p.className += ' roo-strict';
6463 bd.addClass(cls.join(' '));
6467 * @class Roo.EventObject
6468 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6469 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6472 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6474 var target = e.getTarget();
6477 var myDiv = Roo.get("myDiv");
6478 myDiv.on("click", handleClick);
6480 Roo.EventManager.on("myDiv", 'click', handleClick);
6481 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6485 Roo.EventObject = function(){
6487 var E = Roo.lib.Event;
6489 // safari keypress events for special keys return bad keycodes
6492 63235 : 39, // right
6495 63276 : 33, // page up
6496 63277 : 34, // page down
6497 63272 : 46, // delete
6502 // normalize button clicks
6503 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6504 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6506 Roo.EventObjectImpl = function(e){
6508 this.setEvent(e.browserEvent || e);
6511 Roo.EventObjectImpl.prototype = {
6513 * Used to fix doc tools.
6514 * @scope Roo.EventObject.prototype
6520 /** The normal browser event */
6521 browserEvent : null,
6522 /** The button pressed in a mouse event */
6524 /** True if the shift key was down during the event */
6526 /** True if the control key was down during the event */
6528 /** True if the alt key was down during the event */
6587 setEvent : function(e){
6588 if(e == this || (e && e.browserEvent)){ // already wrapped
6591 this.browserEvent = e;
6593 // normalize buttons
6594 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6595 if(e.type == 'click' && this.button == -1){
6599 this.shiftKey = e.shiftKey;
6600 // mac metaKey behaves like ctrlKey
6601 this.ctrlKey = e.ctrlKey || e.metaKey;
6602 this.altKey = e.altKey;
6603 // in getKey these will be normalized for the mac
6604 this.keyCode = e.keyCode;
6605 // keyup warnings on firefox.
6606 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6607 // cache the target for the delayed and or buffered events
6608 this.target = E.getTarget(e);
6610 this.xy = E.getXY(e);
6613 this.shiftKey = false;
6614 this.ctrlKey = false;
6615 this.altKey = false;
6625 * Stop the event (preventDefault and stopPropagation)
6627 stopEvent : function(){
6628 if(this.browserEvent){
6629 if(this.browserEvent.type == 'mousedown'){
6630 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6632 E.stopEvent(this.browserEvent);
6637 * Prevents the browsers default handling of the event.
6639 preventDefault : function(){
6640 if(this.browserEvent){
6641 E.preventDefault(this.browserEvent);
6646 isNavKeyPress : function(){
6647 var k = this.keyCode;
6648 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6649 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6652 isSpecialKey : function(){
6653 var k = this.keyCode;
6654 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6655 (k == 16) || (k == 17) ||
6656 (k >= 18 && k <= 20) ||
6657 (k >= 33 && k <= 35) ||
6658 (k >= 36 && k <= 39) ||
6659 (k >= 44 && k <= 45);
6662 * Cancels bubbling of the event.
6664 stopPropagation : function(){
6665 if(this.browserEvent){
6666 if(this.type == 'mousedown'){
6667 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6669 E.stopPropagation(this.browserEvent);
6674 * Gets the key code for the event.
6677 getCharCode : function(){
6678 return this.charCode || this.keyCode;
6682 * Returns a normalized keyCode for the event.
6683 * @return {Number} The key code
6685 getKey : function(){
6686 var k = this.keyCode || this.charCode;
6687 return Roo.isSafari ? (safariKeys[k] || k) : k;
6691 * Gets the x coordinate of the event.
6694 getPageX : function(){
6699 * Gets the y coordinate of the event.
6702 getPageY : function(){
6707 * Gets the time of the event.
6710 getTime : function(){
6711 if(this.browserEvent){
6712 return E.getTime(this.browserEvent);
6718 * Gets the page coordinates of the event.
6719 * @return {Array} The xy values like [x, y]
6726 * Gets the target for the event.
6727 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6728 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6729 search as a number or element (defaults to 10 || document.body)
6730 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6731 * @return {HTMLelement}
6733 getTarget : function(selector, maxDepth, returnEl){
6734 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6737 * Gets the related target.
6738 * @return {HTMLElement}
6740 getRelatedTarget : function(){
6741 if(this.browserEvent){
6742 return E.getRelatedTarget(this.browserEvent);
6748 * Normalizes mouse wheel delta across browsers
6749 * @return {Number} The delta
6751 getWheelDelta : function(){
6752 var e = this.browserEvent;
6754 if(e.wheelDelta){ /* IE/Opera. */
6755 delta = e.wheelDelta/120;
6756 }else if(e.detail){ /* Mozilla case. */
6757 delta = -e.detail/3;
6763 * Returns true if the control, meta, shift or alt key was pressed during this event.
6766 hasModifier : function(){
6767 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6771 * Returns true if the target of this event equals el or is a child of el
6772 * @param {String/HTMLElement/Element} el
6773 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6776 within : function(el, related){
6777 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6778 return t && Roo.fly(el).contains(t);
6781 getPoint : function(){
6782 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6786 return new Roo.EventObjectImpl();
6791 * Ext JS Library 1.1.1
6792 * Copyright(c) 2006-2007, Ext JS, LLC.
6794 * Originally Released Under LGPL - original licence link has changed is not relivant.
6797 * <script type="text/javascript">
6801 // was in Composite Element!??!?!
6804 var D = Roo.lib.Dom;
6805 var E = Roo.lib.Event;
6806 var A = Roo.lib.Anim;
6808 // local style camelizing for speed
6810 var camelRe = /(-[a-z])/gi;
6811 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
6812 var view = document.defaultView;
6815 * @class Roo.Element
6816 * Represents an Element in the DOM.<br><br>
6819 var el = Roo.get("my-div");
6822 var el = getEl("my-div");
6824 // or with a DOM element
6825 var el = Roo.get(myDivElement);
6827 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
6828 * each call instead of constructing a new one.<br><br>
6829 * <b>Animations</b><br />
6830 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
6831 * should either be a boolean (true) or an object literal with animation options. The animation options are:
6833 Option Default Description
6834 --------- -------- ---------------------------------------------
6835 duration .35 The duration of the animation in seconds
6836 easing easeOut The YUI easing method
6837 callback none A function to execute when the anim completes
6838 scope this The scope (this) of the callback function
6840 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
6841 * manipulate the animation. Here's an example:
6843 var el = Roo.get("my-div");
6848 // default animation
6849 el.setWidth(100, true);
6851 // animation with some options set
6858 // using the "anim" property to get the Anim object
6864 el.setWidth(100, opt);
6866 if(opt.anim.isAnimated()){
6870 * <b> Composite (Collections of) Elements</b><br />
6871 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
6872 * @constructor Create a new Element directly.
6873 * @param {String/HTMLElement} element
6874 * @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).
6876 Roo.Element = function(element, forceNew){
6877 var dom = typeof element == "string" ?
6878 document.getElementById(element) : element;
6879 if(!dom){ // invalid id/element
6883 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
6884 return Roo.Element.cache[id];
6894 * The DOM element ID
6897 this.id = id || Roo.id(dom);
6900 var El = Roo.Element;
6904 * The element's default display mode (defaults to "")
6907 originalDisplay : "",
6911 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
6916 * Sets the element's visibility mode. When setVisible() is called it
6917 * will use this to determine whether to set the visibility or the display property.
6918 * @param visMode Element.VISIBILITY or Element.DISPLAY
6919 * @return {Roo.Element} this
6921 setVisibilityMode : function(visMode){
6922 this.visibilityMode = visMode;
6926 * Convenience method for setVisibilityMode(Element.DISPLAY)
6927 * @param {String} display (optional) What to set display to when visible
6928 * @return {Roo.Element} this
6930 enableDisplayMode : function(display){
6931 this.setVisibilityMode(El.DISPLAY);
6932 if(typeof display != "undefined") this.originalDisplay = display;
6937 * 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)
6938 * @param {String} selector The simple selector to test
6939 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6940 search as a number or element (defaults to 10 || document.body)
6941 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6942 * @return {HTMLElement} The matching DOM node (or null if no match was found)
6944 findParent : function(simpleSelector, maxDepth, returnEl){
6945 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
6946 maxDepth = maxDepth || 50;
6947 if(typeof maxDepth != "number"){
6948 stopEl = Roo.getDom(maxDepth);
6951 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
6952 if(dq.is(p, simpleSelector)){
6953 return returnEl ? Roo.get(p) : p;
6963 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
6964 * @param {String} selector The simple selector to test
6965 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6966 search as a number or element (defaults to 10 || document.body)
6967 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6968 * @return {HTMLElement} The matching DOM node (or null if no match was found)
6970 findParentNode : function(simpleSelector, maxDepth, returnEl){
6971 var p = Roo.fly(this.dom.parentNode, '_internal');
6972 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
6976 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
6977 * This is a shortcut for findParentNode() that always returns an Roo.Element.
6978 * @param {String} selector The simple selector to test
6979 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6980 search as a number or element (defaults to 10 || document.body)
6981 * @return {Roo.Element} The matching DOM node (or null if no match was found)
6983 up : function(simpleSelector, maxDepth){
6984 return this.findParentNode(simpleSelector, maxDepth, true);
6990 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
6991 * @param {String} selector The simple selector to test
6992 * @return {Boolean} True if this element matches the selector, else false
6994 is : function(simpleSelector){
6995 return Roo.DomQuery.is(this.dom, simpleSelector);
6999 * Perform animation on this element.
7000 * @param {Object} args The YUI animation control args
7001 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
7002 * @param {Function} onComplete (optional) Function to call when animation completes
7003 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
7004 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
7005 * @return {Roo.Element} this
7007 animate : function(args, duration, onComplete, easing, animType){
7008 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
7013 * @private Internal animation call
7015 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
7016 animType = animType || 'run';
7018 var anim = Roo.lib.Anim[animType](
7020 (opt.duration || defaultDur) || .35,
7021 (opt.easing || defaultEase) || 'easeOut',
7023 Roo.callback(cb, this);
7024 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
7032 // private legacy anim prep
7033 preanim : function(a, i){
7034 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
7038 * Removes worthless text nodes
7039 * @param {Boolean} forceReclean (optional) By default the element
7040 * keeps track if it has been cleaned already so
7041 * you can call this over and over. However, if you update the element and
7042 * need to force a reclean, you can pass true.
7044 clean : function(forceReclean){
7045 if(this.isCleaned && forceReclean !== true){
7049 var d = this.dom, n = d.firstChild, ni = -1;
7051 var nx = n.nextSibling;
7052 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
7059 this.isCleaned = true;
7064 calcOffsetsTo : function(el){
7067 var restorePos = false;
7068 if(el.getStyle('position') == 'static'){
7069 el.position('relative');
7074 while(op && op != d && op.tagName != 'HTML'){
7077 op = op.offsetParent;
7080 el.position('static');
7086 * Scrolls this element into view within the passed container.
7087 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
7088 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
7089 * @return {Roo.Element} this
7091 scrollIntoView : function(container, hscroll){
7092 var c = Roo.getDom(container) || document.body;
7095 var o = this.calcOffsetsTo(c),
7098 b = t+el.offsetHeight,
7099 r = l+el.offsetWidth;
7101 var ch = c.clientHeight;
7102 var ct = parseInt(c.scrollTop, 10);
7103 var cl = parseInt(c.scrollLeft, 10);
7105 var cr = cl + c.clientWidth;
7113 if(hscroll !== false){
7117 c.scrollLeft = r-c.clientWidth;
7124 scrollChildIntoView : function(child, hscroll){
7125 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7129 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7130 * the new height may not be available immediately.
7131 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7132 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7133 * @param {Function} onComplete (optional) Function to call when animation completes
7134 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7135 * @return {Roo.Element} this
7137 autoHeight : function(animate, duration, onComplete, easing){
7138 var oldHeight = this.getHeight();
7140 this.setHeight(1); // force clipping
7141 setTimeout(function(){
7142 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7144 this.setHeight(height);
7146 if(typeof onComplete == "function"){
7150 this.setHeight(oldHeight); // restore original height
7151 this.setHeight(height, animate, duration, function(){
7153 if(typeof onComplete == "function") onComplete();
7154 }.createDelegate(this), easing);
7156 }.createDelegate(this), 0);
7161 * Returns true if this element is an ancestor of the passed element
7162 * @param {HTMLElement/String} el The element to check
7163 * @return {Boolean} True if this element is an ancestor of el, else false
7165 contains : function(el){
7166 if(!el){return false;}
7167 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7171 * Checks whether the element is currently visible using both visibility and display properties.
7172 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7173 * @return {Boolean} True if the element is currently visible, else false
7175 isVisible : function(deep) {
7176 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7177 if(deep !== true || !vis){
7180 var p = this.dom.parentNode;
7181 while(p && p.tagName.toLowerCase() != "body"){
7182 if(!Roo.fly(p, '_isVisible').isVisible()){
7191 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7192 * @param {String} selector The CSS selector
7193 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7194 * @return {CompositeElement/CompositeElementLite} The composite element
7196 select : function(selector, unique){
7197 return El.select(selector, unique, this.dom);
7201 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7202 * @param {String} selector The CSS selector
7203 * @return {Array} An array of the matched nodes
7205 query : function(selector, unique){
7206 return Roo.DomQuery.select(selector, this.dom);
7210 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7211 * @param {String} selector The CSS selector
7212 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7213 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7215 child : function(selector, returnDom){
7216 var n = Roo.DomQuery.selectNode(selector, this.dom);
7217 return returnDom ? n : Roo.get(n);
7221 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7222 * @param {String} selector The CSS selector
7223 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7224 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7226 down : function(selector, returnDom){
7227 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7228 return returnDom ? n : Roo.get(n);
7232 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7233 * @param {String} group The group the DD object is member of
7234 * @param {Object} config The DD config object
7235 * @param {Object} overrides An object containing methods to override/implement on the DD object
7236 * @return {Roo.dd.DD} The DD object
7238 initDD : function(group, config, overrides){
7239 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7240 return Roo.apply(dd, overrides);
7244 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7245 * @param {String} group The group the DDProxy object is member of
7246 * @param {Object} config The DDProxy config object
7247 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7248 * @return {Roo.dd.DDProxy} The DDProxy object
7250 initDDProxy : function(group, config, overrides){
7251 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7252 return Roo.apply(dd, overrides);
7256 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7257 * @param {String} group The group the DDTarget object is member of
7258 * @param {Object} config The DDTarget config object
7259 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7260 * @return {Roo.dd.DDTarget} The DDTarget object
7262 initDDTarget : function(group, config, overrides){
7263 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7264 return Roo.apply(dd, overrides);
7268 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7269 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7270 * @param {Boolean} visible Whether the element is visible
7271 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7272 * @return {Roo.Element} this
7274 setVisible : function(visible, animate){
7276 if(this.visibilityMode == El.DISPLAY){
7277 this.setDisplayed(visible);
7280 this.dom.style.visibility = visible ? "visible" : "hidden";
7283 // closure for composites
7285 var visMode = this.visibilityMode;
7287 this.setOpacity(.01);
7288 this.setVisible(true);
7290 this.anim({opacity: { to: (visible?1:0) }},
7291 this.preanim(arguments, 1),
7292 null, .35, 'easeIn', function(){
7294 if(visMode == El.DISPLAY){
7295 dom.style.display = "none";
7297 dom.style.visibility = "hidden";
7299 Roo.get(dom).setOpacity(1);
7307 * Returns true if display is not "none"
7310 isDisplayed : function() {
7311 return this.getStyle("display") != "none";
7315 * Toggles the element's visibility or display, depending on visibility mode.
7316 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7317 * @return {Roo.Element} this
7319 toggle : function(animate){
7320 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7325 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7326 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7327 * @return {Roo.Element} this
7329 setDisplayed : function(value) {
7330 if(typeof value == "boolean"){
7331 value = value ? this.originalDisplay : "none";
7333 this.setStyle("display", value);
7338 * Tries to focus the element. Any exceptions are caught and ignored.
7339 * @return {Roo.Element} this
7341 focus : function() {
7349 * Tries to blur the element. Any exceptions are caught and ignored.
7350 * @return {Roo.Element} this
7360 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7361 * @param {String/Array} className The CSS class to add, or an array of classes
7362 * @return {Roo.Element} this
7364 addClass : function(className){
7365 if(className instanceof Array){
7366 for(var i = 0, len = className.length; i < len; i++) {
7367 this.addClass(className[i]);
7370 if(className && !this.hasClass(className)){
7371 this.dom.className = this.dom.className + " " + className;
7378 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7379 * @param {String/Array} className The CSS class to add, or an array of classes
7380 * @return {Roo.Element} this
7382 radioClass : function(className){
7383 var siblings = this.dom.parentNode.childNodes;
7384 for(var i = 0; i < siblings.length; i++) {
7385 var s = siblings[i];
7386 if(s.nodeType == 1){
7387 Roo.get(s).removeClass(className);
7390 this.addClass(className);
7395 * Removes one or more CSS classes from the element.
7396 * @param {String/Array} className The CSS class to remove, or an array of classes
7397 * @return {Roo.Element} this
7399 removeClass : function(className){
7400 if(!className || !this.dom.className){
7403 if(className instanceof Array){
7404 for(var i = 0, len = className.length; i < len; i++) {
7405 this.removeClass(className[i]);
7408 if(this.hasClass(className)){
7409 var re = this.classReCache[className];
7411 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7412 this.classReCache[className] = re;
7414 this.dom.className =
7415 this.dom.className.replace(re, " ");
7425 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7426 * @param {String} className The CSS class to toggle
7427 * @return {Roo.Element} this
7429 toggleClass : function(className){
7430 if(this.hasClass(className)){
7431 this.removeClass(className);
7433 this.addClass(className);
7439 * Checks if the specified CSS class exists on this element's DOM node.
7440 * @param {String} className The CSS class to check for
7441 * @return {Boolean} True if the class exists, else false
7443 hasClass : function(className){
7444 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7448 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7449 * @param {String} oldClassName The CSS class to replace
7450 * @param {String} newClassName The replacement CSS class
7451 * @return {Roo.Element} this
7453 replaceClass : function(oldClassName, newClassName){
7454 this.removeClass(oldClassName);
7455 this.addClass(newClassName);
7460 * Returns an object with properties matching the styles requested.
7461 * For example, el.getStyles('color', 'font-size', 'width') might return
7462 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7463 * @param {String} style1 A style name
7464 * @param {String} style2 A style name
7465 * @param {String} etc.
7466 * @return {Object} The style object
7468 getStyles : function(){
7469 var a = arguments, len = a.length, r = {};
7470 for(var i = 0; i < len; i++){
7471 r[a[i]] = this.getStyle(a[i]);
7477 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7478 * @param {String} property The style property whose value is returned.
7479 * @return {String} The current value of the style property for this element.
7481 getStyle : function(){
7482 return view && view.getComputedStyle ?
7484 var el = this.dom, v, cs, camel;
7485 if(prop == 'float'){
7488 if(el.style && (v = el.style[prop])){
7491 if(cs = view.getComputedStyle(el, "")){
7492 if(!(camel = propCache[prop])){
7493 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7500 var el = this.dom, v, cs, camel;
7501 if(prop == 'opacity'){
7502 if(typeof el.style.filter == 'string'){
7503 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7505 var fv = parseFloat(m[1]);
7507 return fv ? fv / 100 : 0;
7512 }else if(prop == 'float'){
7513 prop = "styleFloat";
7515 if(!(camel = propCache[prop])){
7516 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7518 if(v = el.style[camel]){
7521 if(cs = el.currentStyle){
7529 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7530 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7531 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7532 * @return {Roo.Element} this
7534 setStyle : function(prop, value){
7535 if(typeof prop == "string"){
7537 if (prop == 'float') {
7538 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7543 if(!(camel = propCache[prop])){
7544 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7547 if(camel == 'opacity') {
7548 this.setOpacity(value);
7550 this.dom.style[camel] = value;
7553 for(var style in prop){
7554 if(typeof prop[style] != "function"){
7555 this.setStyle(style, prop[style]);
7563 * More flexible version of {@link #setStyle} for setting style properties.
7564 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7565 * a function which returns such a specification.
7566 * @return {Roo.Element} this
7568 applyStyles : function(style){
7569 Roo.DomHelper.applyStyles(this.dom, style);
7574 * 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).
7575 * @return {Number} The X position of the element
7578 return D.getX(this.dom);
7582 * 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).
7583 * @return {Number} The Y position of the element
7586 return D.getY(this.dom);
7590 * 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).
7591 * @return {Array} The XY position of the element
7594 return D.getXY(this.dom);
7598 * 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).
7599 * @param {Number} The X position of the element
7600 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7601 * @return {Roo.Element} this
7603 setX : function(x, animate){
7605 D.setX(this.dom, x);
7607 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7613 * 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).
7614 * @param {Number} The Y position of the element
7615 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7616 * @return {Roo.Element} this
7618 setY : function(y, animate){
7620 D.setY(this.dom, y);
7622 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7628 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7629 * @param {String} left The left CSS property value
7630 * @return {Roo.Element} this
7632 setLeft : function(left){
7633 this.setStyle("left", this.addUnits(left));
7638 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7639 * @param {String} top The top CSS property value
7640 * @return {Roo.Element} this
7642 setTop : function(top){
7643 this.setStyle("top", this.addUnits(top));
7648 * Sets the element's CSS right style.
7649 * @param {String} right The right CSS property value
7650 * @return {Roo.Element} this
7652 setRight : function(right){
7653 this.setStyle("right", this.addUnits(right));
7658 * Sets the element's CSS bottom style.
7659 * @param {String} bottom The bottom CSS property value
7660 * @return {Roo.Element} this
7662 setBottom : function(bottom){
7663 this.setStyle("bottom", this.addUnits(bottom));
7668 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7669 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7670 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7671 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7672 * @return {Roo.Element} this
7674 setXY : function(pos, animate){
7676 D.setXY(this.dom, pos);
7678 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7684 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7685 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7686 * @param {Number} x X value for new position (coordinates are page-based)
7687 * @param {Number} y Y value for new position (coordinates are page-based)
7688 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7689 * @return {Roo.Element} this
7691 setLocation : function(x, y, animate){
7692 this.setXY([x, y], this.preanim(arguments, 2));
7697 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7698 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7699 * @param {Number} x X value for new position (coordinates are page-based)
7700 * @param {Number} y Y value for new position (coordinates are page-based)
7701 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7702 * @return {Roo.Element} this
7704 moveTo : function(x, y, animate){
7705 this.setXY([x, y], this.preanim(arguments, 2));
7710 * Returns the region of the given element.
7711 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7712 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7714 getRegion : function(){
7715 return D.getRegion(this.dom);
7719 * Returns the offset height of the element
7720 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7721 * @return {Number} The element's height
7723 getHeight : function(contentHeight){
7724 var h = this.dom.offsetHeight || 0;
7725 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7729 * Returns the offset width of the element
7730 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7731 * @return {Number} The element's width
7733 getWidth : function(contentWidth){
7734 var w = this.dom.offsetWidth || 0;
7735 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7739 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7740 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7741 * if a height has not been set using CSS.
7744 getComputedHeight : function(){
7745 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7747 h = parseInt(this.getStyle('height'), 10) || 0;
7748 if(!this.isBorderBox()){
7749 h += this.getFrameWidth('tb');
7756 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7757 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7758 * if a width has not been set using CSS.
7761 getComputedWidth : function(){
7762 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7764 w = parseInt(this.getStyle('width'), 10) || 0;
7765 if(!this.isBorderBox()){
7766 w += this.getFrameWidth('lr');
7773 * Returns the size of the element.
7774 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
7775 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
7777 getSize : function(contentSize){
7778 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
7782 * Returns the width and height of the viewport.
7783 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
7785 getViewSize : function(){
7786 var d = this.dom, doc = document, aw = 0, ah = 0;
7787 if(d == doc || d == doc.body){
7788 return {width : D.getViewWidth(), height: D.getViewHeight()};
7791 width : d.clientWidth,
7792 height: d.clientHeight
7798 * Returns the value of the "value" attribute
7799 * @param {Boolean} asNumber true to parse the value as a number
7800 * @return {String/Number}
7802 getValue : function(asNumber){
7803 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
7807 adjustWidth : function(width){
7808 if(typeof width == "number"){
7809 if(this.autoBoxAdjust && !this.isBorderBox()){
7810 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7820 adjustHeight : function(height){
7821 if(typeof height == "number"){
7822 if(this.autoBoxAdjust && !this.isBorderBox()){
7823 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7833 * Set the width of the element
7834 * @param {Number} width The new width
7835 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7836 * @return {Roo.Element} this
7838 setWidth : function(width, animate){
7839 width = this.adjustWidth(width);
7841 this.dom.style.width = this.addUnits(width);
7843 this.anim({width: {to: width}}, this.preanim(arguments, 1));
7849 * Set the height of the element
7850 * @param {Number} height The new height
7851 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7852 * @return {Roo.Element} this
7854 setHeight : function(height, animate){
7855 height = this.adjustHeight(height);
7857 this.dom.style.height = this.addUnits(height);
7859 this.anim({height: {to: height}}, this.preanim(arguments, 1));
7865 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
7866 * @param {Number} width The new width
7867 * @param {Number} height The new height
7868 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7869 * @return {Roo.Element} this
7871 setSize : function(width, height, animate){
7872 if(typeof width == "object"){ // in case of object from getSize()
7873 height = width.height; width = width.width;
7875 width = this.adjustWidth(width); height = this.adjustHeight(height);
7877 this.dom.style.width = this.addUnits(width);
7878 this.dom.style.height = this.addUnits(height);
7880 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
7886 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
7887 * @param {Number} x X value for new position (coordinates are page-based)
7888 * @param {Number} y Y value for new position (coordinates are page-based)
7889 * @param {Number} width The new width
7890 * @param {Number} height The new height
7891 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7892 * @return {Roo.Element} this
7894 setBounds : function(x, y, width, height, animate){
7896 this.setSize(width, height);
7897 this.setLocation(x, y);
7899 width = this.adjustWidth(width); height = this.adjustHeight(height);
7900 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
7901 this.preanim(arguments, 4), 'motion');
7907 * 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.
7908 * @param {Roo.lib.Region} region The region to fill
7909 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7910 * @return {Roo.Element} this
7912 setRegion : function(region, animate){
7913 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
7918 * Appends an event handler
7920 * @param {String} eventName The type of event to append
7921 * @param {Function} fn The method the event invokes
7922 * @param {Object} scope (optional) The scope (this object) of the fn
7923 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
7925 addListener : function(eventName, fn, scope, options){
7927 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
7932 * Removes an event handler from this element
7933 * @param {String} eventName the type of event to remove
7934 * @param {Function} fn the method the event invokes
7935 * @return {Roo.Element} this
7937 removeListener : function(eventName, fn){
7938 Roo.EventManager.removeListener(this.dom, eventName, fn);
7943 * Removes all previous added listeners from this element
7944 * @return {Roo.Element} this
7946 removeAllListeners : function(){
7947 E.purgeElement(this.dom);
7951 relayEvent : function(eventName, observable){
7952 this.on(eventName, function(e){
7953 observable.fireEvent(eventName, e);
7958 * Set the opacity of the element
7959 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
7960 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7961 * @return {Roo.Element} this
7963 setOpacity : function(opacity, animate){
7965 var s = this.dom.style;
7968 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
7969 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
7971 s.opacity = opacity;
7974 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
7980 * Gets the left X coordinate
7981 * @param {Boolean} local True to get the local css position instead of page coordinate
7984 getLeft : function(local){
7988 return parseInt(this.getStyle("left"), 10) || 0;
7993 * Gets the right X coordinate of the element (element X position + element width)
7994 * @param {Boolean} local True to get the local css position instead of page coordinate
7997 getRight : function(local){
7999 return this.getX() + this.getWidth();
8001 return (this.getLeft(true) + this.getWidth()) || 0;
8006 * Gets the top Y coordinate
8007 * @param {Boolean} local True to get the local css position instead of page coordinate
8010 getTop : function(local) {
8014 return parseInt(this.getStyle("top"), 10) || 0;
8019 * Gets the bottom Y coordinate of the element (element Y position + element height)
8020 * @param {Boolean} local True to get the local css position instead of page coordinate
8023 getBottom : function(local){
8025 return this.getY() + this.getHeight();
8027 return (this.getTop(true) + this.getHeight()) || 0;
8032 * Initializes positioning on this element. If a desired position is not passed, it will make the
8033 * the element positioned relative IF it is not already positioned.
8034 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
8035 * @param {Number} zIndex (optional) The zIndex to apply
8036 * @param {Number} x (optional) Set the page X position
8037 * @param {Number} y (optional) Set the page Y position
8039 position : function(pos, zIndex, x, y){
8041 if(this.getStyle('position') == 'static'){
8042 this.setStyle('position', 'relative');
8045 this.setStyle("position", pos);
8048 this.setStyle("z-index", zIndex);
8050 if(x !== undefined && y !== undefined){
8052 }else if(x !== undefined){
8054 }else if(y !== undefined){
8060 * Clear positioning back to the default when the document was loaded
8061 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
8062 * @return {Roo.Element} this
8064 clearPositioning : function(value){
8072 "position" : "static"
8078 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
8079 * snapshot before performing an update and then restoring the element.
8082 getPositioning : function(){
8083 var l = this.getStyle("left");
8084 var t = this.getStyle("top");
8086 "position" : this.getStyle("position"),
8088 "right" : l ? "" : this.getStyle("right"),
8090 "bottom" : t ? "" : this.getStyle("bottom"),
8091 "z-index" : this.getStyle("z-index")
8096 * Gets the width of the border(s) for the specified side(s)
8097 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8098 * passing lr would get the border (l)eft width + the border (r)ight width.
8099 * @return {Number} The width of the sides passed added together
8101 getBorderWidth : function(side){
8102 return this.addStyles(side, El.borders);
8106 * Gets the width of the padding(s) for the specified side(s)
8107 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8108 * passing lr would get the padding (l)eft + the padding (r)ight.
8109 * @return {Number} The padding of the sides passed added together
8111 getPadding : function(side){
8112 return this.addStyles(side, El.paddings);
8116 * Set positioning with an object returned by getPositioning().
8117 * @param {Object} posCfg
8118 * @return {Roo.Element} this
8120 setPositioning : function(pc){
8121 this.applyStyles(pc);
8122 if(pc.right == "auto"){
8123 this.dom.style.right = "";
8125 if(pc.bottom == "auto"){
8126 this.dom.style.bottom = "";
8132 fixDisplay : function(){
8133 if(this.getStyle("display") == "none"){
8134 this.setStyle("visibility", "hidden");
8135 this.setStyle("display", this.originalDisplay); // first try reverting to default
8136 if(this.getStyle("display") == "none"){ // if that fails, default to block
8137 this.setStyle("display", "block");
8143 * Quick set left and top adding default units
8144 * @param {String} left The left CSS property value
8145 * @param {String} top The top CSS property value
8146 * @return {Roo.Element} this
8148 setLeftTop : function(left, top){
8149 this.dom.style.left = this.addUnits(left);
8150 this.dom.style.top = this.addUnits(top);
8155 * Move this element relative to its current position.
8156 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8157 * @param {Number} distance How far to move the element in pixels
8158 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8159 * @return {Roo.Element} this
8161 move : function(direction, distance, animate){
8162 var xy = this.getXY();
8163 direction = direction.toLowerCase();
8167 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8171 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8176 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8181 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8188 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8189 * @return {Roo.Element} this
8192 if(!this.isClipped){
8193 this.isClipped = true;
8194 this.originalClip = {
8195 "o": this.getStyle("overflow"),
8196 "x": this.getStyle("overflow-x"),
8197 "y": this.getStyle("overflow-y")
8199 this.setStyle("overflow", "hidden");
8200 this.setStyle("overflow-x", "hidden");
8201 this.setStyle("overflow-y", "hidden");
8207 * Return clipping (overflow) to original clipping before clip() was called
8208 * @return {Roo.Element} this
8210 unclip : function(){
8212 this.isClipped = false;
8213 var o = this.originalClip;
8214 if(o.o){this.setStyle("overflow", o.o);}
8215 if(o.x){this.setStyle("overflow-x", o.x);}
8216 if(o.y){this.setStyle("overflow-y", o.y);}
8223 * Gets the x,y coordinates specified by the anchor position on the element.
8224 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8225 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8226 * {width: (target width), height: (target height)} (defaults to the element's current size)
8227 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8228 * @return {Array} [x, y] An array containing the element's x and y coordinates
8230 getAnchorXY : function(anchor, local, s){
8231 //Passing a different size is useful for pre-calculating anchors,
8232 //especially for anchored animations that change the el size.
8234 var w, h, vp = false;
8237 if(d == document.body || d == document){
8239 w = D.getViewWidth(); h = D.getViewHeight();
8241 w = this.getWidth(); h = this.getHeight();
8244 w = s.width; h = s.height;
8246 var x = 0, y = 0, r = Math.round;
8247 switch((anchor || "tl").toLowerCase()){
8289 var sc = this.getScroll();
8290 return [x + sc.left, y + sc.top];
8292 //Add the element's offset xy
8293 var o = this.getXY();
8294 return [x+o[0], y+o[1]];
8298 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8299 * supported position values.
8300 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8301 * @param {String} position The position to align to.
8302 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8303 * @return {Array} [x, y]
8305 getAlignToXY : function(el, p, o){
8309 throw "Element.alignTo with an element that doesn't exist";
8311 var c = false; //constrain to viewport
8312 var p1 = "", p2 = "";
8319 }else if(p.indexOf("-") == -1){
8322 p = p.toLowerCase();
8323 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8325 throw "Element.alignTo with an invalid alignment " + p;
8327 p1 = m[1]; p2 = m[2]; c = !!m[3];
8329 //Subtract the aligned el's internal xy from the target's offset xy
8330 //plus custom offset to get the aligned el's new offset xy
8331 var a1 = this.getAnchorXY(p1, true);
8332 var a2 = el.getAnchorXY(p2, false);
8333 var x = a2[0] - a1[0] + o[0];
8334 var y = a2[1] - a1[1] + o[1];
8336 //constrain the aligned el to viewport if necessary
8337 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8338 // 5px of margin for ie
8339 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8341 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8342 //perpendicular to the vp border, allow the aligned el to slide on that border,
8343 //otherwise swap the aligned el to the opposite border of the target.
8344 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8345 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8346 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8347 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8350 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8351 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8353 if((x+w) > dw + scrollX){
8354 x = swapX ? r.left-w : dw+scrollX-w;
8357 x = swapX ? r.right : scrollX;
8359 if((y+h) > dh + scrollY){
8360 y = swapY ? r.top-h : dh+scrollY-h;
8363 y = swapY ? r.bottom : scrollY;
8370 getConstrainToXY : function(){
8371 var os = {top:0, left:0, bottom:0, right: 0};
8373 return function(el, local, offsets, proposedXY){
8375 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8377 var vw, vh, vx = 0, vy = 0;
8378 if(el.dom == document.body || el.dom == document){
8379 vw = Roo.lib.Dom.getViewWidth();
8380 vh = Roo.lib.Dom.getViewHeight();
8382 vw = el.dom.clientWidth;
8383 vh = el.dom.clientHeight;
8385 var vxy = el.getXY();
8391 var s = el.getScroll();
8393 vx += offsets.left + s.left;
8394 vy += offsets.top + s.top;
8396 vw -= offsets.right;
8397 vh -= offsets.bottom;
8402 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8403 var x = xy[0], y = xy[1];
8404 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8406 // only move it if it needs it
8409 // first validate right/bottom
8418 // then make sure top/left isn't negative
8427 return moved ? [x, y] : false;
8432 adjustForConstraints : function(xy, parent, offsets){
8433 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8437 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8438 * document it aligns it to the viewport.
8439 * The position parameter is optional, and can be specified in any one of the following formats:
8441 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8442 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8443 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8444 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8445 * <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
8446 * element's anchor point, and the second value is used as the target's anchor point.</li>
8448 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8449 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8450 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8451 * that specified in order to enforce the viewport constraints.
8452 * Following are all of the supported anchor positions:
8455 ----- -----------------------------
8456 tl The top left corner (default)
8457 t The center of the top edge
8458 tr The top right corner
8459 l The center of the left edge
8460 c In the center of the element
8461 r The center of the right edge
8462 bl The bottom left corner
8463 b The center of the bottom edge
8464 br The bottom right corner
8468 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8469 el.alignTo("other-el");
8471 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8472 el.alignTo("other-el", "tr?");
8474 // align the bottom right corner of el with the center left edge of other-el
8475 el.alignTo("other-el", "br-l?");
8477 // align the center of el with the bottom left corner of other-el and
8478 // adjust the x position by -6 pixels (and the y position by 0)
8479 el.alignTo("other-el", "c-bl", [-6, 0]);
8481 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8482 * @param {String} position The position to align to.
8483 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8484 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8485 * @return {Roo.Element} this
8487 alignTo : function(element, position, offsets, animate){
8488 var xy = this.getAlignToXY(element, position, offsets);
8489 this.setXY(xy, this.preanim(arguments, 3));
8494 * Anchors an element to another element and realigns it when the window is resized.
8495 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8496 * @param {String} position The position to align to.
8497 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8498 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8499 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8500 * is a number, it is used as the buffer delay (defaults to 50ms).
8501 * @param {Function} callback The function to call after the animation finishes
8502 * @return {Roo.Element} this
8504 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8505 var action = function(){
8506 this.alignTo(el, alignment, offsets, animate);
8507 Roo.callback(callback, this);
8509 Roo.EventManager.onWindowResize(action, this);
8510 var tm = typeof monitorScroll;
8511 if(tm != 'undefined'){
8512 Roo.EventManager.on(window, 'scroll', action, this,
8513 {buffer: tm == 'number' ? monitorScroll : 50});
8515 action.call(this); // align immediately
8519 * Clears any opacity settings from this element. Required in some cases for IE.
8520 * @return {Roo.Element} this
8522 clearOpacity : function(){
8523 if (window.ActiveXObject) {
8524 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8525 this.dom.style.filter = "";
8528 this.dom.style.opacity = "";
8529 this.dom.style["-moz-opacity"] = "";
8530 this.dom.style["-khtml-opacity"] = "";
8536 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8537 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8538 * @return {Roo.Element} this
8540 hide : function(animate){
8541 this.setVisible(false, this.preanim(arguments, 0));
8546 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8547 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8548 * @return {Roo.Element} this
8550 show : function(animate){
8551 this.setVisible(true, this.preanim(arguments, 0));
8556 * @private Test if size has a unit, otherwise appends the default
8558 addUnits : function(size){
8559 return Roo.Element.addUnits(size, this.defaultUnit);
8563 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8564 * @return {Roo.Element} this
8566 beginMeasure : function(){
8568 if(el.offsetWidth || el.offsetHeight){
8569 return this; // offsets work already
8572 var p = this.dom, b = document.body; // start with this element
8573 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8574 var pe = Roo.get(p);
8575 if(pe.getStyle('display') == 'none'){
8576 changed.push({el: p, visibility: pe.getStyle("visibility")});
8577 p.style.visibility = "hidden";
8578 p.style.display = "block";
8582 this._measureChanged = changed;
8588 * Restores displays to before beginMeasure was called
8589 * @return {Roo.Element} this
8591 endMeasure : function(){
8592 var changed = this._measureChanged;
8594 for(var i = 0, len = changed.length; i < len; i++) {
8596 r.el.style.visibility = r.visibility;
8597 r.el.style.display = "none";
8599 this._measureChanged = null;
8605 * Update the innerHTML of this element, optionally searching for and processing scripts
8606 * @param {String} html The new HTML
8607 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8608 * @param {Function} callback For async script loading you can be noticed when the update completes
8609 * @return {Roo.Element} this
8611 update : function(html, loadScripts, callback){
8612 if(typeof html == "undefined"){
8615 if(loadScripts !== true){
8616 this.dom.innerHTML = html;
8617 if(typeof callback == "function"){
8625 html += '<span id="' + id + '"></span>';
8627 E.onAvailable(id, function(){
8628 var hd = document.getElementsByTagName("head")[0];
8629 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8630 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8631 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8634 while(match = re.exec(html)){
8635 var attrs = match[1];
8636 var srcMatch = attrs ? attrs.match(srcRe) : false;
8637 if(srcMatch && srcMatch[2]){
8638 var s = document.createElement("script");
8639 s.src = srcMatch[2];
8640 var typeMatch = attrs.match(typeRe);
8641 if(typeMatch && typeMatch[2]){
8642 s.type = typeMatch[2];
8645 }else if(match[2] && match[2].length > 0){
8646 if(window.execScript) {
8647 window.execScript(match[2]);
8655 window.eval(match[2]);
8659 var el = document.getElementById(id);
8660 if(el){el.parentNode.removeChild(el);}
8661 if(typeof callback == "function"){
8665 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8670 * Direct access to the UpdateManager update() method (takes the same parameters).
8671 * @param {String/Function} url The url for this request or a function to call to get the url
8672 * @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}
8673 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8674 * @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.
8675 * @return {Roo.Element} this
8678 var um = this.getUpdateManager();
8679 um.update.apply(um, arguments);
8684 * Gets this element's UpdateManager
8685 * @return {Roo.UpdateManager} The UpdateManager
8687 getUpdateManager : function(){
8688 if(!this.updateManager){
8689 this.updateManager = new Roo.UpdateManager(this);
8691 return this.updateManager;
8695 * Disables text selection for this element (normalized across browsers)
8696 * @return {Roo.Element} this
8698 unselectable : function(){
8699 this.dom.unselectable = "on";
8700 this.swallowEvent("selectstart", true);
8701 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8702 this.addClass("x-unselectable");
8707 * Calculates the x, y to center this element on the screen
8708 * @return {Array} The x, y values [x, y]
8710 getCenterXY : function(){
8711 return this.getAlignToXY(document, 'c-c');
8715 * Centers the Element in either the viewport, or another Element.
8716 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8718 center : function(centerIn){
8719 this.alignTo(centerIn || document, 'c-c');
8724 * Tests various css rules/browsers to determine if this element uses a border box
8727 isBorderBox : function(){
8728 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8732 * Return a box {x, y, width, height} that can be used to set another elements
8733 * size/location to match this element.
8734 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8735 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8736 * @return {Object} box An object in the format {x, y, width, height}
8738 getBox : function(contentBox, local){
8743 var left = parseInt(this.getStyle("left"), 10) || 0;
8744 var top = parseInt(this.getStyle("top"), 10) || 0;
8747 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8749 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8751 var l = this.getBorderWidth("l")+this.getPadding("l");
8752 var r = this.getBorderWidth("r")+this.getPadding("r");
8753 var t = this.getBorderWidth("t")+this.getPadding("t");
8754 var b = this.getBorderWidth("b")+this.getPadding("b");
8755 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)};
8757 bx.right = bx.x + bx.width;
8758 bx.bottom = bx.y + bx.height;
8763 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8764 for more information about the sides.
8765 * @param {String} sides
8768 getFrameWidth : function(sides, onlyContentBox){
8769 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
8773 * 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.
8774 * @param {Object} box The box to fill {x, y, width, height}
8775 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
8776 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8777 * @return {Roo.Element} this
8779 setBox : function(box, adjust, animate){
8780 var w = box.width, h = box.height;
8781 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
8782 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8783 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8785 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
8790 * Forces the browser to repaint this element
8791 * @return {Roo.Element} this
8793 repaint : function(){
8795 this.addClass("x-repaint");
8796 setTimeout(function(){
8797 Roo.get(dom).removeClass("x-repaint");
8803 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
8804 * then it returns the calculated width of the sides (see getPadding)
8805 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
8806 * @return {Object/Number}
8808 getMargins : function(side){
8811 top: parseInt(this.getStyle("margin-top"), 10) || 0,
8812 left: parseInt(this.getStyle("margin-left"), 10) || 0,
8813 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
8814 right: parseInt(this.getStyle("margin-right"), 10) || 0
8817 return this.addStyles(side, El.margins);
8822 addStyles : function(sides, styles){
8824 for(var i = 0, len = sides.length; i < len; i++){
8825 v = this.getStyle(styles[sides.charAt(i)]);
8827 w = parseInt(v, 10);
8835 * Creates a proxy element of this element
8836 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
8837 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
8838 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
8839 * @return {Roo.Element} The new proxy element
8841 createProxy : function(config, renderTo, matchBox){
8843 renderTo = Roo.getDom(renderTo);
8845 renderTo = document.body;
8847 config = typeof config == "object" ?
8848 config : {tag : "div", cls: config};
8849 var proxy = Roo.DomHelper.append(renderTo, config, true);
8851 proxy.setBox(this.getBox());
8857 * Puts a mask over this element to disable user interaction. Requires core.css.
8858 * This method can only be applied to elements which accept child nodes.
8859 * @param {String} msg (optional) A message to display in the mask
8860 * @param {String} msgCls (optional) A css class to apply to the msg element
8861 * @return {Element} The mask element
8863 mask : function(msg, msgCls)
8865 if(this.getStyle("position") == "static"){
8866 this.setStyle("position", "relative");
8869 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
8871 this.addClass("x-masked");
8872 this._mask.setDisplayed(true);
8877 while (dom && dom.style) {
8878 if (!isNaN(parseInt(dom.style.zIndex))) {
8879 z = Math.max(z, parseInt(dom.style.zIndex));
8881 dom = dom.parentNode;
8885 if(typeof msg == 'string'){
8887 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
8889 var mm = this._maskMsg;
8890 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
8891 mm.dom.firstChild.innerHTML = msg;
8892 mm.setDisplayed(true);
8894 mm.setStyle('z-index', z + 102);
8896 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
8897 this._mask.setHeight(this.getHeight());
8899 this._mask.setStyle('z-index', z + 100);
8905 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
8906 * it is cached for reuse.
8908 unmask : function(removeEl){
8910 if(removeEl === true){
8911 this._mask.remove();
8914 this._maskMsg.remove();
8915 delete this._maskMsg;
8918 this._mask.setDisplayed(false);
8920 this._maskMsg.setDisplayed(false);
8924 this.removeClass("x-masked");
8928 * Returns true if this element is masked
8931 isMasked : function(){
8932 return this._mask && this._mask.isVisible();
8936 * Creates an iframe shim for this element to keep selects and other windowed objects from
8938 * @return {Roo.Element} The new shim element
8940 createShim : function(){
8941 var el = document.createElement('iframe');
8942 el.frameBorder = 'no';
8943 el.className = 'roo-shim';
8944 if(Roo.isIE && Roo.isSecure){
8945 el.src = Roo.SSL_SECURE_URL;
8947 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
8948 shim.autoBoxAdjust = false;
8953 * Removes this element from the DOM and deletes it from the cache
8955 remove : function(){
8956 if(this.dom.parentNode){
8957 this.dom.parentNode.removeChild(this.dom);
8959 delete El.cache[this.dom.id];
8963 * Sets up event handlers to add and remove a css class when the mouse is over this element
8964 * @param {String} className
8965 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
8966 * mouseout events for children elements
8967 * @return {Roo.Element} this
8969 addClassOnOver : function(className, preventFlicker){
8970 this.on("mouseover", function(){
8971 Roo.fly(this, '_internal').addClass(className);
8973 var removeFn = function(e){
8974 if(preventFlicker !== true || !e.within(this, true)){
8975 Roo.fly(this, '_internal').removeClass(className);
8978 this.on("mouseout", removeFn, this.dom);
8983 * Sets up event handlers to add and remove a css class when this element has the focus
8984 * @param {String} className
8985 * @return {Roo.Element} this
8987 addClassOnFocus : function(className){
8988 this.on("focus", function(){
8989 Roo.fly(this, '_internal').addClass(className);
8991 this.on("blur", function(){
8992 Roo.fly(this, '_internal').removeClass(className);
8997 * 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)
8998 * @param {String} className
8999 * @return {Roo.Element} this
9001 addClassOnClick : function(className){
9003 this.on("mousedown", function(){
9004 Roo.fly(dom, '_internal').addClass(className);
9005 var d = Roo.get(document);
9006 var fn = function(){
9007 Roo.fly(dom, '_internal').removeClass(className);
9008 d.removeListener("mouseup", fn);
9010 d.on("mouseup", fn);
9016 * Stops the specified event from bubbling and optionally prevents the default action
9017 * @param {String} eventName
9018 * @param {Boolean} preventDefault (optional) true to prevent the default action too
9019 * @return {Roo.Element} this
9021 swallowEvent : function(eventName, preventDefault){
9022 var fn = function(e){
9023 e.stopPropagation();
9028 if(eventName instanceof Array){
9029 for(var i = 0, len = eventName.length; i < len; i++){
9030 this.on(eventName[i], fn);
9034 this.on(eventName, fn);
9041 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
9044 * Sizes this element to its parent element's dimensions performing
9045 * neccessary box adjustments.
9046 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
9047 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
9048 * @return {Roo.Element} this
9050 fitToParent : function(monitorResize, targetParent) {
9051 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
9052 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
9053 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
9056 var p = Roo.get(targetParent || this.dom.parentNode);
9057 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
9058 if (monitorResize === true) {
9059 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
9060 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
9066 * Gets the next sibling, skipping text nodes
9067 * @return {HTMLElement} The next sibling or null
9069 getNextSibling : function(){
9070 var n = this.dom.nextSibling;
9071 while(n && n.nodeType != 1){
9078 * Gets the previous sibling, skipping text nodes
9079 * @return {HTMLElement} The previous sibling or null
9081 getPrevSibling : function(){
9082 var n = this.dom.previousSibling;
9083 while(n && n.nodeType != 1){
9084 n = n.previousSibling;
9091 * Appends the passed element(s) to this element
9092 * @param {String/HTMLElement/Array/Element/CompositeElement} el
9093 * @return {Roo.Element} this
9095 appendChild: function(el){
9102 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
9103 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
9104 * automatically generated with the specified attributes.
9105 * @param {HTMLElement} insertBefore (optional) a child element of this element
9106 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
9107 * @return {Roo.Element} The new child element
9109 createChild: function(config, insertBefore, returnDom){
9110 config = config || {tag:'div'};
9112 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
9114 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
9118 * Appends this element to the passed element
9119 * @param {String/HTMLElement/Element} el The new parent element
9120 * @return {Roo.Element} this
9122 appendTo: function(el){
9123 el = Roo.getDom(el);
9124 el.appendChild(this.dom);
9129 * Inserts this element before the passed element in the DOM
9130 * @param {String/HTMLElement/Element} el The element to insert before
9131 * @return {Roo.Element} this
9133 insertBefore: function(el){
9134 el = Roo.getDom(el);
9135 el.parentNode.insertBefore(this.dom, el);
9140 * Inserts this element after the passed element in the DOM
9141 * @param {String/HTMLElement/Element} el The element to insert after
9142 * @return {Roo.Element} this
9144 insertAfter: function(el){
9145 el = Roo.getDom(el);
9146 el.parentNode.insertBefore(this.dom, el.nextSibling);
9151 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9152 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9153 * @return {Roo.Element} The new child
9155 insertFirst: function(el, returnDom){
9157 if(typeof el == 'object' && !el.nodeType){ // dh config
9158 return this.createChild(el, this.dom.firstChild, returnDom);
9160 el = Roo.getDom(el);
9161 this.dom.insertBefore(el, this.dom.firstChild);
9162 return !returnDom ? Roo.get(el) : el;
9167 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9168 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9169 * @param {String} where (optional) 'before' or 'after' defaults to before
9170 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9171 * @return {Roo.Element} the inserted Element
9173 insertSibling: function(el, where, returnDom){
9174 where = where ? where.toLowerCase() : 'before';
9176 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9178 if(typeof el == 'object' && !el.nodeType){ // dh config
9179 if(where == 'after' && !this.dom.nextSibling){
9180 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9182 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9186 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9187 where == 'before' ? this.dom : this.dom.nextSibling);
9196 * Creates and wraps this element with another element
9197 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9198 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9199 * @return {HTMLElement/Element} The newly created wrapper element
9201 wrap: function(config, returnDom){
9203 config = {tag: "div"};
9205 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9206 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9211 * Replaces the passed element with this element
9212 * @param {String/HTMLElement/Element} el The element to replace
9213 * @return {Roo.Element} this
9215 replace: function(el){
9217 this.insertBefore(el);
9223 * Inserts an html fragment into this element
9224 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9225 * @param {String} html The HTML fragment
9226 * @param {Boolean} returnEl True to return an Roo.Element
9227 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9229 insertHtml : function(where, html, returnEl){
9230 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9231 return returnEl ? Roo.get(el) : el;
9235 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9236 * @param {Object} o The object with the attributes
9237 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9238 * @return {Roo.Element} this
9240 set : function(o, useSet){
9242 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9244 if(attr == "style" || typeof o[attr] == "function") continue;
9246 el.className = o["cls"];
9248 if(useSet) el.setAttribute(attr, o[attr]);
9249 else el[attr] = o[attr];
9253 Roo.DomHelper.applyStyles(el, o.style);
9259 * Convenience method for constructing a KeyMap
9260 * @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:
9261 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9262 * @param {Function} fn The function to call
9263 * @param {Object} scope (optional) The scope of the function
9264 * @return {Roo.KeyMap} The KeyMap created
9266 addKeyListener : function(key, fn, scope){
9268 if(typeof key != "object" || key instanceof Array){
9284 return new Roo.KeyMap(this, config);
9288 * Creates a KeyMap for this element
9289 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9290 * @return {Roo.KeyMap} The KeyMap created
9292 addKeyMap : function(config){
9293 return new Roo.KeyMap(this, config);
9297 * Returns true if this element is scrollable.
9300 isScrollable : function(){
9302 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9306 * 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().
9307 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9308 * @param {Number} value The new scroll value
9309 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9310 * @return {Element} this
9313 scrollTo : function(side, value, animate){
9314 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9316 this.dom[prop] = value;
9318 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9319 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9325 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9326 * within this element's scrollable range.
9327 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9328 * @param {Number} distance How far to scroll the element in pixels
9329 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9330 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9331 * was scrolled as far as it could go.
9333 scroll : function(direction, distance, animate){
9334 if(!this.isScrollable()){
9338 var l = el.scrollLeft, t = el.scrollTop;
9339 var w = el.scrollWidth, h = el.scrollHeight;
9340 var cw = el.clientWidth, ch = el.clientHeight;
9341 direction = direction.toLowerCase();
9342 var scrolled = false;
9343 var a = this.preanim(arguments, 2);
9348 var v = Math.min(l + distance, w-cw);
9349 this.scrollTo("left", v, a);
9356 var v = Math.max(l - distance, 0);
9357 this.scrollTo("left", v, a);
9365 var v = Math.max(t - distance, 0);
9366 this.scrollTo("top", v, a);
9374 var v = Math.min(t + distance, h-ch);
9375 this.scrollTo("top", v, a);
9384 * Translates the passed page coordinates into left/top css values for this element
9385 * @param {Number/Array} x The page x or an array containing [x, y]
9386 * @param {Number} y The page y
9387 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9389 translatePoints : function(x, y){
9390 if(typeof x == 'object' || x instanceof Array){
9393 var p = this.getStyle('position');
9394 var o = this.getXY();
9396 var l = parseInt(this.getStyle('left'), 10);
9397 var t = parseInt(this.getStyle('top'), 10);
9400 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9403 t = (p == "relative") ? 0 : this.dom.offsetTop;
9406 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9410 * Returns the current scroll position of the element.
9411 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9413 getScroll : function(){
9414 var d = this.dom, doc = document;
9415 if(d == doc || d == doc.body){
9416 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9417 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9418 return {left: l, top: t};
9420 return {left: d.scrollLeft, top: d.scrollTop};
9425 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9426 * are convert to standard 6 digit hex color.
9427 * @param {String} attr The css attribute
9428 * @param {String} defaultValue The default value to use when a valid color isn't found
9429 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9432 getColor : function(attr, defaultValue, prefix){
9433 var v = this.getStyle(attr);
9434 if(!v || v == "transparent" || v == "inherit") {
9435 return defaultValue;
9437 var color = typeof prefix == "undefined" ? "#" : prefix;
9438 if(v.substr(0, 4) == "rgb("){
9439 var rvs = v.slice(4, v.length -1).split(",");
9440 for(var i = 0; i < 3; i++){
9441 var h = parseInt(rvs[i]).toString(16);
9448 if(v.substr(0, 1) == "#"){
9450 for(var i = 1; i < 4; i++){
9451 var c = v.charAt(i);
9454 }else if(v.length == 7){
9455 color += v.substr(1);
9459 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9463 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9464 * gradient background, rounded corners and a 4-way shadow.
9465 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9466 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9467 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9468 * @return {Roo.Element} this
9470 boxWrap : function(cls){
9471 cls = cls || 'x-box';
9472 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9473 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9478 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9479 * @param {String} namespace The namespace in which to look for the attribute
9480 * @param {String} name The attribute name
9481 * @return {String} The attribute value
9483 getAttributeNS : Roo.isIE ? function(ns, name){
9485 var type = typeof d[ns+":"+name];
9486 if(type != 'undefined' && type != 'unknown'){
9487 return d[ns+":"+name];
9490 } : function(ns, name){
9492 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9496 var ep = El.prototype;
9499 * Appends an event handler (Shorthand for addListener)
9500 * @param {String} eventName The type of event to append
9501 * @param {Function} fn The method the event invokes
9502 * @param {Object} scope (optional) The scope (this object) of the fn
9503 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9506 ep.on = ep.addListener;
9508 ep.mon = ep.addListener;
9511 * Removes an event handler from this element (shorthand for removeListener)
9512 * @param {String} eventName the type of event to remove
9513 * @param {Function} fn the method the event invokes
9514 * @return {Roo.Element} this
9517 ep.un = ep.removeListener;
9520 * true to automatically adjust width and height settings for box-model issues (default to true)
9522 ep.autoBoxAdjust = true;
9525 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9528 El.addUnits = function(v, defaultUnit){
9529 if(v === "" || v == "auto"){
9532 if(v === undefined){
9535 if(typeof v == "number" || !El.unitPattern.test(v)){
9536 return v + (defaultUnit || 'px');
9541 // special markup used throughout Roo when box wrapping elements
9542 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>';
9544 * Visibility mode constant - Use visibility to hide element
9550 * Visibility mode constant - Use display to hide element
9556 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9557 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9558 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9570 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9571 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9572 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9573 * @return {Element} The Element object
9576 El.get = function(el){
9578 if(!el){ return null; }
9579 if(typeof el == "string"){ // element id
9580 if(!(elm = document.getElementById(el))){
9583 if(ex = El.cache[el]){
9586 ex = El.cache[el] = new El(elm);
9589 }else if(el.tagName){ // dom element
9593 if(ex = El.cache[id]){
9596 ex = El.cache[id] = new El(el);
9599 }else if(el instanceof El){
9601 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9602 // catch case where it hasn't been appended
9603 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9606 }else if(el.isComposite){
9608 }else if(el instanceof Array){
9609 return El.select(el);
9610 }else if(el == document){
9611 // create a bogus element object representing the document object
9613 var f = function(){};
9614 f.prototype = El.prototype;
9616 docEl.dom = document;
9624 El.uncache = function(el){
9625 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9627 delete El.cache[a[i].id || a[i]];
9633 // Garbage collection - uncache elements/purge listeners on orphaned elements
9634 // so we don't hold a reference and cause the browser to retain them
9635 El.garbageCollect = function(){
9636 if(!Roo.enableGarbageCollector){
9637 clearInterval(El.collectorThread);
9640 for(var eid in El.cache){
9641 var el = El.cache[eid], d = el.dom;
9642 // -------------------------------------------------------
9643 // Determining what is garbage:
9644 // -------------------------------------------------------
9646 // dom node is null, definitely garbage
9647 // -------------------------------------------------------
9649 // no parentNode == direct orphan, definitely garbage
9650 // -------------------------------------------------------
9651 // !d.offsetParent && !document.getElementById(eid)
9652 // display none elements have no offsetParent so we will
9653 // also try to look it up by it's id. However, check
9654 // offsetParent first so we don't do unneeded lookups.
9655 // This enables collection of elements that are not orphans
9656 // directly, but somewhere up the line they have an orphan
9658 // -------------------------------------------------------
9659 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9660 delete El.cache[eid];
9661 if(d && Roo.enableListenerCollection){
9667 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9671 El.Flyweight = function(dom){
9674 El.Flyweight.prototype = El.prototype;
9676 El._flyweights = {};
9678 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9679 * the dom node can be overwritten by other code.
9680 * @param {String/HTMLElement} el The dom node or id
9681 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9682 * prevent conflicts (e.g. internally Roo uses "_internal")
9684 * @return {Element} The shared Element object
9686 El.fly = function(el, named){
9687 named = named || '_global';
9688 el = Roo.getDom(el);
9692 if(!El._flyweights[named]){
9693 El._flyweights[named] = new El.Flyweight();
9695 El._flyweights[named].dom = el;
9696 return El._flyweights[named];
9700 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9701 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9702 * Shorthand of {@link Roo.Element#get}
9703 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9704 * @return {Element} The Element object
9710 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9711 * the dom node can be overwritten by other code.
9712 * Shorthand of {@link Roo.Element#fly}
9713 * @param {String/HTMLElement} el The dom node or id
9714 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9715 * prevent conflicts (e.g. internally Roo uses "_internal")
9717 * @return {Element} The shared Element object
9723 // speedy lookup for elements never to box adjust
9724 var noBoxAdjust = Roo.isStrict ? {
9727 input:1, select:1, textarea:1
9729 if(Roo.isIE || Roo.isGecko){
9730 noBoxAdjust['button'] = 1;
9734 Roo.EventManager.on(window, 'unload', function(){
9736 delete El._flyweights;
9744 Roo.Element.selectorFunction = Roo.DomQuery.select;
9747 Roo.Element.select = function(selector, unique, root){
9749 if(typeof selector == "string"){
9750 els = Roo.Element.selectorFunction(selector, root);
9751 }else if(selector.length !== undefined){
9754 throw "Invalid selector";
9756 if(unique === true){
9757 return new Roo.CompositeElement(els);
9759 return new Roo.CompositeElementLite(els);
9763 * Selects elements based on the passed CSS selector to enable working on them as 1.
9764 * @param {String/Array} selector The CSS selector or an array of elements
9765 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
9766 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
9767 * @return {CompositeElementLite/CompositeElement}
9771 Roo.select = Roo.Element.select;