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 isFirefox = ua.indexOf("firefox") > -1,
57 isIE = ua.indexOf("msie") > -1,
58 isIE7 = ua.indexOf("msie 7") > -1,
59 isIE11 = /trident.*rv\:11\./.test(ua),
60 isGecko = !isSafari && ua.indexOf("gecko") > -1,
61 isBorderBox = isIE && !isStrict,
62 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
63 isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
64 isLinux = (ua.indexOf("linux") != -1),
65 isSecure = window.location.href.toLowerCase().indexOf("https") === 0,
66 isIOS = /iPhone|iPad\./.test(ua),
67 isTouch = (function() {
69 document.createEvent("TouchEvent");
76 // remove css image flicker
79 document.execCommand("BackgroundImageCache", false, true);
85 * True if the browser is in strict mode
90 * True if the page is running over SSL
95 * True when the document is fully initialized and ready for action
100 * Turn on debugging output (currently only the factory uses this)
107 * True to automatically uncache orphaned Roo.Elements periodically (defaults to true)
110 enableGarbageCollector : true,
113 * True to automatically purge event listeners after uncaching an element (defaults to false).
114 * Note: this only happens if enableGarbageCollector is true.
117 enableListenerCollection:false,
120 * URL to a blank file used by Roo when in secure mode for iframe src and onReady src to prevent
121 * the IE insecure content warning (defaults to javascript:false).
124 SSL_SECURE_URL : "javascript:false",
127 * URL to a 1x1 transparent gif image used by Roo to create inline icons with CSS background images. (Defaults to
128 * "http://Roojs.com/s.gif" and you should change this to a URL on your server).
131 BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
133 emptyFn : function(){},
136 * Copies all the properties of config to obj if they don't already exist.
137 * @param {Object} obj The receiver of the properties
138 * @param {Object} config The source of the properties
139 * @return {Object} returns obj
141 applyIf : function(o, c){
144 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
151 * Applies event listeners to elements by selectors when the document is ready.
152 * The event name is specified with an @ suffix.
155 // add a listener for click on all anchors in element with id foo
156 '#foo a@click' : function(e, t){
160 // add the same listener to multiple selectors (separated by comma BEFORE the @)
161 '#foo a, #bar span.some-class@mouseover' : function(){
166 * @param {Object} obj The list of behaviors to apply
168 addBehaviors : function(o){
170 Roo.onReady(function(){
175 var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
177 var parts = b.split('@');
178 if(parts[1]){ // for Object prototype breakers
181 cache[s] = Roo.select(s);
183 cache[s].on(parts[1], o[b]);
190 * Generates unique ids. If the element already has an id, it is unchanged
191 * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
192 * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
193 * @return {String} The generated Id.
195 id : function(el, prefix){
196 prefix = prefix || "roo-gen";
198 var id = prefix + (++idSeed);
199 return el ? (el.id ? el.id : (el.id = id)) : id;
204 * Extends one class with another class and optionally overrides members with the passed literal. This class
205 * also adds the function "override()" to the class that can be used to override
206 * members on an instance.
207 * @param {Object} subclass The class inheriting the functionality
208 * @param {Object} superclass The class being extended
209 * @param {Object} overrides (optional) A literal with members
214 var io = function(o){
219 return function(sb, sp, overrides){
220 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
223 sb = function(){sp.apply(this, arguments);};
225 var F = function(){}, sbp, spp = sp.prototype;
227 sbp = sb.prototype = new F();
231 if(spp.constructor == Object.prototype.constructor){
236 sb.override = function(o){
240 Roo.override(sb, overrides);
246 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
248 Roo.override(MyClass, {
249 newMethod1: function(){
252 newMethod2: function(foo){
257 * @param {Object} origclass The class to override
258 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
259 * containing one or more methods.
262 override : function(origclass, overrides){
264 var p = origclass.prototype;
265 for(var method in overrides){
266 p[method] = overrides[method];
271 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
273 Roo.namespace('Company', 'Company.data');
274 Company.Widget = function() { ... }
275 Company.data.CustomStore = function(config) { ... }
277 * @param {String} namespace1
278 * @param {String} namespace2
279 * @param {String} etc
282 namespace : function(){
283 var a=arguments, o=null, i, j, d, rt;
284 for (i=0; i<a.length; ++i) {
288 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
289 for (j=1; j<d.length; ++j) {
290 o[d[j]]=o[d[j]] || {};
296 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
298 Roo.factory({ xns: Roo.data, xtype : 'Store', .....});
299 Roo.factory(conf, Roo.data);
301 * @param {String} classname
302 * @param {String} namespace (optional)
306 factory : function(c, ns)
308 // no xtype, no ns or c.xns - or forced off by c.xns
309 if (!c.xtype || (!ns && !c.xns) || (c.xns === false)) { // not enough info...
312 ns = c.xns ? c.xns : ns; // if c.xns is set, then use that..
313 if (c.constructor == ns[c.xtype]) {// already created...
317 if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")");
318 var ret = new ns[c.xtype](c);
322 c.xns = false; // prevent recursion..
326 * Logs to console if it can.
328 * @param {String|Object} string
333 if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
340 * 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.
344 urlEncode : function(o){
350 var ov = o[key], k = Roo.encodeURIComponent(key);
351 var type = typeof ov;
352 if(type == 'undefined'){
354 }else if(type != "function" && type != "object"){
355 buf.push(k, "=", Roo.encodeURIComponent(ov), "&");
356 }else if(ov instanceof Array){
358 for(var i = 0, len = ov.length; i < len; i++) {
359 buf.push(k, "=", Roo.encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
370 * Safe version of encodeURIComponent
371 * @param {String} data
375 encodeURIComponent : function (data)
378 return encodeURIComponent(data);
379 } catch(e) {} // should be an uri encode error.
381 if (data == '' || data == null){
384 // http://stackoverflow.com/questions/2596483/unicode-and-uri-encoding-decoding-and-escaping-in-javascript
385 function nibble_to_hex(nibble){
386 var chars = '0123456789ABCDEF';
387 return chars.charAt(nibble);
389 data = data.toString();
391 for(var i=0; i<data.length; i++){
392 var c = data.charCodeAt(i);
393 var bs = new Array();
396 bs[0] = 0xF0 | ((c & 0x1C0000) >>> 18);
397 bs[1] = 0x80 | ((c & 0x3F000) >>> 12);
398 bs[2] = 0x80 | ((c & 0xFC0) >>> 6);
399 bs[3] = 0x80 | (c & 0x3F);
400 }else if (c > 0x800){
402 bs[0] = 0xE0 | ((c & 0xF000) >>> 12);
403 bs[1] = 0x80 | ((c & 0xFC0) >>> 6);
404 bs[2] = 0x80 | (c & 0x3F);
407 bs[0] = 0xC0 | ((c & 0x7C0) >>> 6);
408 bs[1] = 0x80 | (c & 0x3F);
413 for(var j=0; j<bs.length; j++){
415 var hex = nibble_to_hex((b & 0xF0) >>> 4)
416 + nibble_to_hex(b &0x0F);
425 * 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]}.
426 * @param {String} string
427 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
428 * @return {Object} A literal with members
430 urlDecode : function(string, overwrite){
431 if(!string || !string.length){
435 var pairs = string.split('&');
436 var pair, name, value;
437 for(var i = 0, len = pairs.length; i < len; i++){
438 pair = pairs[i].split('=');
439 name = decodeURIComponent(pair[0]);
440 value = decodeURIComponent(pair[1]);
441 if(overwrite !== true){
442 if(typeof obj[name] == "undefined"){
444 }else if(typeof obj[name] == "string"){
445 obj[name] = [obj[name]];
446 obj[name].push(value);
448 obj[name].push(value);
458 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
459 * passed array is not really an array, your function is called once with it.
460 * The supplied function is called with (Object item, Number index, Array allItems).
461 * @param {Array/NodeList/Mixed} array
462 * @param {Function} fn
463 * @param {Object} scope
465 each : function(array, fn, scope){
466 if(typeof array.length == "undefined" || typeof array == "string"){
469 for(var i = 0, len = array.length; i < len; i++){
470 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
475 combine : function(){
476 var as = arguments, l = as.length, r = [];
477 for(var i = 0; i < l; i++){
479 if(a instanceof Array){
481 }else if(a.length !== undefined && !a.substr){
482 r = r.concat(Array.prototype.slice.call(a, 0));
491 * Escapes the passed string for use in a regular expression
492 * @param {String} str
495 escapeRe : function(s) {
496 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
500 callback : function(cb, scope, args, delay){
501 if(typeof cb == "function"){
503 cb.defer(delay, scope, args || []);
505 cb.apply(scope, args || []);
511 * Return the dom node for the passed string (id), dom node, or Roo.Element
512 * @param {String/HTMLElement/Roo.Element} el
513 * @return HTMLElement
515 getDom : function(el){
519 return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
523 * Shorthand for {@link Roo.ComponentMgr#get}
525 * @return Roo.Component
527 getCmp : function(id){
528 return Roo.ComponentMgr.get(id);
531 num : function(v, defaultValue){
532 if(typeof v != 'number'){
538 destroy : function(){
539 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
543 as.removeAllListeners();
547 if(typeof as.purgeListeners == 'function'){
550 if(typeof as.destroy == 'function'){
557 // inpired by a similar function in mootools library
559 * Returns the type of object that is passed in. If the object passed in is null or undefined it
560 * return false otherwise it returns one of the following values:<ul>
561 * <li><b>string</b>: If the object passed is a string</li>
562 * <li><b>number</b>: If the object passed is a number</li>
563 * <li><b>boolean</b>: If the object passed is a boolean value</li>
564 * <li><b>function</b>: If the object passed is a function reference</li>
565 * <li><b>object</b>: If the object passed is an object</li>
566 * <li><b>array</b>: If the object passed is an array</li>
567 * <li><b>regexp</b>: If the object passed is a regular expression</li>
568 * <li><b>element</b>: If the object passed is a DOM Element</li>
569 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
570 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
571 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
572 * @param {Mixed} object
576 if(o === undefined || o === null){
583 if(t == 'object' && o.nodeName) {
585 case 1: return 'element';
586 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
589 if(t == 'object' || t == 'function') {
590 switch(o.constructor) {
591 case Array: return 'array';
592 case RegExp: return 'regexp';
594 if(typeof o.length == 'number' && typeof o.item == 'function') {
602 * Returns true if the passed value is null, undefined or an empty string (optional).
603 * @param {Mixed} value The value to test
604 * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
607 isEmpty : function(v, allowBlank){
608 return v === null || v === undefined || (!allowBlank ? v === '' : false);
616 isFirefox : isFirefox,
626 isBorderBox : isBorderBox,
628 isWindows : isWindows,
637 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
638 * you may want to set this to true.
641 useShims : ((isIE && !isIE7) || (isGecko && isMac)),
646 * Selects a single element as a Roo Element
647 * This is about as close as you can get to jQuery's $('do crazy stuff')
648 * @param {String} selector The selector/xpath query
649 * @param {Node} root (optional) The start of the query (defaults to document).
650 * @return {Roo.Element}
652 selectNode : function(selector, root)
654 var node = Roo.DomQuery.selectNode(selector,root);
655 return node ? Roo.get(node) : new Roo.Element(false);
663 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
664 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout",
667 "Roo.bootstrap.dash");
670 * Ext JS Library 1.1.1
671 * Copyright(c) 2006-2007, Ext JS, LLC.
673 * Originally Released Under LGPL - original licence link has changed is not relivant.
676 * <script type="text/javascript">
680 // wrappedn so fnCleanup is not in global scope...
682 function fnCleanUp() {
683 var p = Function.prototype;
684 delete p.createSequence;
686 delete p.createDelegate;
687 delete p.createCallback;
688 delete p.createInterceptor;
690 window.detachEvent("onunload", fnCleanUp);
692 window.attachEvent("onunload", fnCleanUp);
699 * These functions are available on every Function object (any JavaScript function).
701 Roo.apply(Function.prototype, {
703 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
704 * Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
705 * Will create a function that is bound to those 2 args.
706 * @return {Function} The new function
708 createCallback : function(/*args...*/){
709 // make args available, in function below
710 var args = arguments;
713 return method.apply(window, args);
718 * Creates a delegate (callback) that sets the scope to obj.
719 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
720 * Will create a function that is automatically scoped to this.
721 * @param {Object} obj (optional) The object for which the scope is set
722 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
723 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
724 * if a number the args are inserted at the specified position
725 * @return {Function} The new function
727 createDelegate : function(obj, args, appendArgs){
730 var callArgs = args || arguments;
731 if(appendArgs === true){
732 callArgs = Array.prototype.slice.call(arguments, 0);
733 callArgs = callArgs.concat(args);
734 }else if(typeof appendArgs == "number"){
735 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
736 var applyArgs = [appendArgs, 0].concat(args); // create method call params
737 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
739 return method.apply(obj || window, callArgs);
744 * Calls this function after the number of millseconds specified.
745 * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
746 * @param {Object} obj (optional) The object for which the scope is set
747 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
748 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
749 * if a number the args are inserted at the specified position
750 * @return {Number} The timeout id that can be used with clearTimeout
752 defer : function(millis, obj, args, appendArgs){
753 var fn = this.createDelegate(obj, args, appendArgs);
755 return setTimeout(fn, millis);
761 * Create a combined function call sequence of the original function + the passed function.
762 * The resulting function returns the results of the original function.
763 * The passed fcn is called with the parameters of the original function
764 * @param {Function} fcn The function to sequence
765 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
766 * @return {Function} The new function
768 createSequence : function(fcn, scope){
769 if(typeof fcn != "function"){
774 var retval = method.apply(this || window, arguments);
775 fcn.apply(scope || this || window, arguments);
781 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
782 * The resulting function returns the results of the original function.
783 * The passed fcn is called with the parameters of the original function.
785 * @param {Function} fcn The function to call before the original
786 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
787 * @return {Function} The new function
789 createInterceptor : function(fcn, scope){
790 if(typeof fcn != "function"){
797 if(fcn.apply(scope || this || window, arguments) === false){
800 return method.apply(this || window, arguments);
806 * Ext JS Library 1.1.1
807 * Copyright(c) 2006-2007, Ext JS, LLC.
809 * Originally Released Under LGPL - original licence link has changed is not relivant.
812 * <script type="text/javascript">
815 Roo.applyIf(String, {
820 * Escapes the passed string for ' and \
821 * @param {String} string The string to escape
822 * @return {String} The escaped string
825 escape : function(string) {
826 return string.replace(/('|\\)/g, "\\$1");
830 * Pads the left side of a string with a specified character. This is especially useful
831 * for normalizing number and date strings. Example usage:
833 var s = String.leftPad('123', 5, '0');
834 // s now contains the string: '00123'
836 * @param {String} string The original string
837 * @param {Number} size The total length of the output string
838 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
839 * @return {String} The padded string
842 leftPad : function (val, size, ch) {
843 var result = new String(val);
844 if(ch === null || ch === undefined || ch === '') {
847 while (result.length < size) {
848 result = ch + result;
854 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
855 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
857 var cls = 'my-class', text = 'Some text';
858 var s = String.format('<div class="{0}">{1}</div>', cls, text);
859 // s now contains the string: '<div class="my-class">Some text</div>'
861 * @param {String} string The tokenized string to be formatted
862 * @param {String} value1 The value to replace token {0}
863 * @param {String} value2 Etc...
864 * @return {String} The formatted string
867 format : function(format){
868 var args = Array.prototype.slice.call(arguments, 1);
869 return format.replace(/\{(\d+)\}/g, function(m, i){
870 return Roo.util.Format.htmlEncode(args[i]);
876 * Utility function that allows you to easily switch a string between two alternating values. The passed value
877 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
878 * they are already different, the first value passed in is returned. Note that this method returns the new value
879 * but does not change the current string.
881 // alternate sort directions
882 sort = sort.toggle('ASC', 'DESC');
884 // instead of conditional logic:
885 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
887 * @param {String} value The value to compare to the current string
888 * @param {String} other The new value to use if the string already equals the first value passed in
889 * @return {String} The new value
892 String.prototype.toggle = function(value, other){
893 return this == value ? other : value;
896 * Ext JS Library 1.1.1
897 * Copyright(c) 2006-2007, Ext JS, LLC.
899 * Originally Released Under LGPL - original licence link has changed is not relivant.
902 * <script type="text/javascript">
908 Roo.applyIf(Number.prototype, {
910 * Checks whether or not the current number is within a desired range. If the number is already within the
911 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
912 * exceeded. Note that this method returns the constrained value but does not change the current number.
913 * @param {Number} min The minimum number in the range
914 * @param {Number} max The maximum number in the range
915 * @return {Number} The constrained value if outside the range, otherwise the current value
917 constrain : function(min, max){
918 return Math.min(Math.max(this, min), max);
922 * Ext JS Library 1.1.1
923 * Copyright(c) 2006-2007, Ext JS, LLC.
925 * Originally Released Under LGPL - original licence link has changed is not relivant.
928 * <script type="text/javascript">
933 Roo.applyIf(Array.prototype, {
936 * Checks whether or not the specified object exists in the array.
937 * @param {Object} o The object to check for
938 * @return {Number} The index of o in the array (or -1 if it is not found)
940 indexOf : function(o){
941 for (var i = 0, len = this.length; i < len; i++){
942 if(this[i] == o) return i;
948 * Removes the specified object from the array. If the object is not found nothing happens.
949 * @param {Object} o The object to remove
951 remove : function(o){
952 var index = this.indexOf(o);
954 this.splice(index, 1);
958 * Map (JS 1.6 compatibility)
959 * @param {Function} function to call
963 var len = this.length >>> 0;
964 if (typeof fun != "function")
965 throw new TypeError();
967 var res = new Array(len);
968 var thisp = arguments[1];
969 for (var i = 0; i < len; i++)
972 res[i] = fun.call(thisp, this[i], i, this);
983 * Ext JS Library 1.1.1
984 * Copyright(c) 2006-2007, Ext JS, LLC.
986 * Originally Released Under LGPL - original licence link has changed is not relivant.
989 * <script type="text/javascript">
995 * The date parsing and format syntax is a subset of
996 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
997 * supported will provide results equivalent to their PHP versions.
999 * Following is the list of all currently supported formats:
1002 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
1004 Format Output Description
1005 ------ ---------- --------------------------------------------------------------
1006 d 10 Day of the month, 2 digits with leading zeros
1007 D Wed A textual representation of a day, three letters
1008 j 10 Day of the month without leading zeros
1009 l Wednesday A full textual representation of the day of the week
1010 S th English ordinal day of month suffix, 2 chars (use with j)
1011 w 3 Numeric representation of the day of the week
1012 z 9 The julian date, or day of the year (0-365)
1013 W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
1014 F January A full textual representation of the month
1015 m 01 Numeric representation of a month, with leading zeros
1016 M Jan Month name abbreviation, three letters
1017 n 1 Numeric representation of a month, without leading zeros
1018 t 31 Number of days in the given month
1019 L 0 Whether it's a leap year (1 if it is a leap year, else 0)
1020 Y 2007 A full numeric representation of a year, 4 digits
1021 y 07 A two digit representation of a year
1022 a pm Lowercase Ante meridiem and Post meridiem
1023 A PM Uppercase Ante meridiem and Post meridiem
1024 g 3 12-hour format of an hour without leading zeros
1025 G 15 24-hour format of an hour without leading zeros
1026 h 03 12-hour format of an hour with leading zeros
1027 H 15 24-hour format of an hour with leading zeros
1028 i 05 Minutes with leading zeros
1029 s 01 Seconds, with leading zeros
1030 O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes)
1031 P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes
1032 T CST Timezone setting of the machine running the code
1033 Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
1036 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
1038 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
1039 document.write(dt.format('Y-m-d')); //2007-01-10
1040 document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
1041 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
1044 * Here are some standard date/time patterns that you might find helpful. They
1045 * are not part of the source of Date.js, but to use them you can simply copy this
1046 * block of code into any script that is included after Date.js and they will also become
1047 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
1050 ISO8601Long:"Y-m-d H:i:s",
1051 ISO8601Short:"Y-m-d",
1053 LongDate: "l, F d, Y",
1054 FullDateTime: "l, F d, Y g:i:s A",
1057 LongTime: "g:i:s A",
1058 SortableDateTime: "Y-m-d\\TH:i:s",
1059 UniversalSortableDateTime: "Y-m-d H:i:sO",
1066 var dt = new Date();
1067 document.write(dt.format(Date.patterns.ShortDate));
1072 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
1073 * They generate precompiled functions from date formats instead of parsing and
1074 * processing the pattern every time you format a date. These functions are available
1075 * on every Date object (any javascript function).
1077 * The original article and download are here:
1078 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1085 Returns the number of milliseconds between this date and date
1086 @param {Date} date (optional) Defaults to now
1087 @return {Number} The diff in milliseconds
1088 @member Date getElapsed
1090 Date.prototype.getElapsed = function(date) {
1091 return Math.abs((date || new Date()).getTime()-this.getTime());
1093 // was in date file..
1097 Date.parseFunctions = {count:0};
1099 Date.parseRegexes = [];
1101 Date.formatFunctions = {count:0};
1104 Date.prototype.dateFormat = function(format) {
1105 if (Date.formatFunctions[format] == null) {
1106 Date.createNewFormat(format);
1108 var func = Date.formatFunctions[format];
1109 return this[func]();
1114 * Formats a date given the supplied format string
1115 * @param {String} format The format string
1116 * @return {String} The formatted date
1119 Date.prototype.format = Date.prototype.dateFormat;
1122 Date.createNewFormat = function(format) {
1123 var funcName = "format" + Date.formatFunctions.count++;
1124 Date.formatFunctions[format] = funcName;
1125 var code = "Date.prototype." + funcName + " = function(){return ";
1126 var special = false;
1128 for (var i = 0; i < format.length; ++i) {
1129 ch = format.charAt(i);
1130 if (!special && ch == "\\") {
1135 code += "'" + String.escape(ch) + "' + ";
1138 code += Date.getFormatCode(ch);
1141 /** eval:var:zzzzzzzzzzzzz */
1142 eval(code.substring(0, code.length - 3) + ";}");
1146 Date.getFormatCode = function(character) {
1147 switch (character) {
1149 return "String.leftPad(this.getDate(), 2, '0') + ";
1151 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
1153 return "this.getDate() + ";
1155 return "Date.dayNames[this.getDay()] + ";
1157 return "this.getSuffix() + ";
1159 return "this.getDay() + ";
1161 return "this.getDayOfYear() + ";
1163 return "this.getWeekOfYear() + ";
1165 return "Date.monthNames[this.getMonth()] + ";
1167 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
1169 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
1171 return "(this.getMonth() + 1) + ";
1173 return "this.getDaysInMonth() + ";
1175 return "(this.isLeapYear() ? 1 : 0) + ";
1177 return "this.getFullYear() + ";
1179 return "('' + this.getFullYear()).substring(2, 4) + ";
1181 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
1183 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
1185 return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
1187 return "this.getHours() + ";
1189 return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
1191 return "String.leftPad(this.getHours(), 2, '0') + ";
1193 return "String.leftPad(this.getMinutes(), 2, '0') + ";
1195 return "String.leftPad(this.getSeconds(), 2, '0') + ";
1197 return "this.getGMTOffset() + ";
1199 return "this.getGMTColonOffset() + ";
1201 return "this.getTimezone() + ";
1203 return "(this.getTimezoneOffset() * -60) + ";
1205 return "'" + String.escape(character) + "' + ";
1210 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
1211 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
1212 * the date format that is not specified will default to the current date value for that part. Time parts can also
1213 * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
1214 * string or the parse operation will fail.
1217 //dt = Fri May 25 2007 (current date)
1218 var dt = new Date();
1220 //dt = Thu May 25 2006 (today's month/day in 2006)
1221 dt = Date.parseDate("2006", "Y");
1223 //dt = Sun Jan 15 2006 (all date parts specified)
1224 dt = Date.parseDate("2006-1-15", "Y-m-d");
1226 //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
1227 dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i:s A" );
1229 * @param {String} input The unparsed date as a string
1230 * @param {String} format The format the date is in
1231 * @return {Date} The parsed date
1234 Date.parseDate = function(input, format) {
1235 if (Date.parseFunctions[format] == null) {
1236 Date.createParser(format);
1238 var func = Date.parseFunctions[format];
1239 return Date[func](input);
1245 Date.createParser = function(format) {
1246 var funcName = "parse" + Date.parseFunctions.count++;
1247 var regexNum = Date.parseRegexes.length;
1248 var currentGroup = 1;
1249 Date.parseFunctions[format] = funcName;
1251 var code = "Date." + funcName + " = function(input){\n"
1252 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
1253 + "var d = new Date();\n"
1254 + "y = d.getFullYear();\n"
1255 + "m = d.getMonth();\n"
1256 + "d = d.getDate();\n"
1257 + "if (typeof(input) !== 'string') { input = input.toString(); }\n"
1258 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
1259 + "if (results && results.length > 0) {";
1262 var special = false;
1264 for (var i = 0; i < format.length; ++i) {
1265 ch = format.charAt(i);
1266 if (!special && ch == "\\") {
1271 regex += String.escape(ch);
1274 var obj = Date.formatCodeToRegex(ch, currentGroup);
1275 currentGroup += obj.g;
1277 if (obj.g && obj.c) {
1283 code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
1284 + "{v = new Date(y, m, d, h, i, s);}\n"
1285 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
1286 + "{v = new Date(y, m, d, h, i);}\n"
1287 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
1288 + "{v = new Date(y, m, d, h);}\n"
1289 + "else if (y >= 0 && m >= 0 && d > 0)\n"
1290 + "{v = new Date(y, m, d);}\n"
1291 + "else if (y >= 0 && m >= 0)\n"
1292 + "{v = new Date(y, m);}\n"
1293 + "else if (y >= 0)\n"
1294 + "{v = new Date(y);}\n"
1295 + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
1296 + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
1297 + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
1300 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
1301 /** eval:var:zzzzzzzzzzzzz */
1306 Date.formatCodeToRegex = function(character, currentGroup) {
1307 switch (character) {
1311 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
1314 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1315 s:"(\\d{1,2})"}; // day of month without leading zeroes
1318 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1319 s:"(\\d{2})"}; // day of month with leading zeroes
1323 s:"(?:" + Date.dayNames.join("|") + ")"};
1327 s:"(?:st|nd|rd|th)"};
1342 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
1343 s:"(" + Date.monthNames.join("|") + ")"};
1346 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
1347 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
1350 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1351 s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros
1354 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1355 s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros
1366 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
1370 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
1371 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
1375 c:"if (results[" + currentGroup + "] == 'am') {\n"
1376 + "if (h == 12) { h = 0; }\n"
1377 + "} else { if (h < 12) { h += 12; }}",
1381 c:"if (results[" + currentGroup + "] == 'AM') {\n"
1382 + "if (h == 12) { h = 0; }\n"
1383 + "} else { if (h < 12) { h += 12; }}",
1388 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1389 s:"(\\d{1,2})"}; // 12/24-hr format format of an hour without leading zeroes
1393 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1394 s:"(\\d{2})"}; // 12/24-hr format format of an hour with leading zeroes
1397 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
1401 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
1406 "o = results[", currentGroup, "];\n",
1407 "var sn = o.substring(0,1);\n", // get + / - sign
1408 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also)
1409 "var mn = o.substring(3,5) % 60;\n", // get minutes
1410 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
1411 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1413 s:"([+\-]\\d{2,4})"};
1419 "o = results[", currentGroup, "];\n",
1420 "var sn = o.substring(0,1);\n",
1421 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
1422 "var mn = o.substring(4,6) % 60;\n",
1423 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
1424 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1430 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1433 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1434 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1435 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1439 s:String.escape(character)};
1444 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1445 * @return {String} The abbreviated timezone name (e.g. 'CST')
1447 Date.prototype.getTimezone = function() {
1448 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1452 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1453 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1455 Date.prototype.getGMTOffset = function() {
1456 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1457 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1458 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1462 * Get the offset from GMT of the current date (equivalent to the format specifier 'P').
1463 * @return {String} 2-characters representing hours and 2-characters representing minutes
1464 * seperated by a colon and prefixed with + or - (e.g. '-06:00')
1466 Date.prototype.getGMTColonOffset = function() {
1467 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1468 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1470 + String.leftPad(this.getTimezoneOffset() %60, 2, "0");
1474 * Get the numeric day number of the year, adjusted for leap year.
1475 * @return {Number} 0 through 364 (365 in leap years)
1477 Date.prototype.getDayOfYear = function() {
1479 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1480 for (var i = 0; i < this.getMonth(); ++i) {
1481 num += Date.daysInMonth[i];
1483 return num + this.getDate() - 1;
1487 * Get the string representation of the numeric week number of the year
1488 * (equivalent to the format specifier 'W').
1489 * @return {String} '00' through '52'
1491 Date.prototype.getWeekOfYear = function() {
1492 // Skip to Thursday of this week
1493 var now = this.getDayOfYear() + (4 - this.getDay());
1494 // Find the first Thursday of the year
1495 var jan1 = new Date(this.getFullYear(), 0, 1);
1496 var then = (7 - jan1.getDay() + 4);
1497 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1501 * Whether or not the current date is in a leap year.
1502 * @return {Boolean} True if the current date is in a leap year, else false
1504 Date.prototype.isLeapYear = function() {
1505 var year = this.getFullYear();
1506 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1510 * Get the first day of the current month, adjusted for leap year. The returned value
1511 * is the numeric day index within the week (0-6) which can be used in conjunction with
1512 * the {@link #monthNames} array to retrieve the textual day name.
1515 var dt = new Date('1/10/2007');
1516 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1518 * @return {Number} The day number (0-6)
1520 Date.prototype.getFirstDayOfMonth = function() {
1521 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1522 return (day < 0) ? (day + 7) : day;
1526 * Get the last day of the current month, adjusted for leap year. The returned value
1527 * is the numeric day index within the week (0-6) which can be used in conjunction with
1528 * the {@link #monthNames} array to retrieve the textual day name.
1531 var dt = new Date('1/10/2007');
1532 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1534 * @return {Number} The day number (0-6)
1536 Date.prototype.getLastDayOfMonth = function() {
1537 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1538 return (day < 0) ? (day + 7) : day;
1543 * Get the first date of this date's month
1546 Date.prototype.getFirstDateOfMonth = function() {
1547 return new Date(this.getFullYear(), this.getMonth(), 1);
1551 * Get the last date of this date's month
1554 Date.prototype.getLastDateOfMonth = function() {
1555 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1558 * Get the number of days in the current month, adjusted for leap year.
1559 * @return {Number} The number of days in the month
1561 Date.prototype.getDaysInMonth = function() {
1562 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1563 return Date.daysInMonth[this.getMonth()];
1567 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1568 * @return {String} 'st, 'nd', 'rd' or 'th'
1570 Date.prototype.getSuffix = function() {
1571 switch (this.getDate()) {
1588 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1591 * An array of textual month names.
1592 * Override these values for international dates, for example...
1593 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1612 * An array of textual day names.
1613 * Override these values for international dates, for example...
1614 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1630 Date.monthNumbers = {
1645 * Creates and returns a new Date instance with the exact same date value as the called instance.
1646 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1647 * variable will also be changed. When the intention is to create a new variable that will not
1648 * modify the original instance, you should create a clone.
1650 * Example of correctly cloning a date:
1653 var orig = new Date('10/1/2006');
1656 document.write(orig); //returns 'Thu Oct 05 2006'!
1659 var orig = new Date('10/1/2006');
1660 var copy = orig.clone();
1662 document.write(orig); //returns 'Thu Oct 01 2006'
1664 * @return {Date} The new Date instance
1666 Date.prototype.clone = function() {
1667 return new Date(this.getTime());
1671 * Clears any time information from this date
1672 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1673 @return {Date} this or the clone
1675 Date.prototype.clearTime = function(clone){
1677 return this.clone().clearTime();
1682 this.setMilliseconds(0);
1687 // safari setMonth is broken
1689 Date.brokenSetMonth = Date.prototype.setMonth;
1690 Date.prototype.setMonth = function(num){
1692 var n = Math.ceil(-num);
1693 var back_year = Math.ceil(n/12);
1694 var month = (n % 12) ? 12 - n % 12 : 0 ;
1695 this.setFullYear(this.getFullYear() - back_year);
1696 return Date.brokenSetMonth.call(this, month);
1698 return Date.brokenSetMonth.apply(this, arguments);
1703 /** Date interval constant
1707 /** Date interval constant
1711 /** Date interval constant
1715 /** Date interval constant
1719 /** Date interval constant
1723 /** Date interval constant
1727 /** Date interval constant
1733 * Provides a convenient method of performing basic date arithmetic. This method
1734 * does not modify the Date instance being called - it creates and returns
1735 * a new Date instance containing the resulting date value.
1740 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1741 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1743 //Negative values will subtract correctly:
1744 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1745 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1747 //You can even chain several calls together in one line!
1748 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1749 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1752 * @param {String} interval A valid date interval enum value
1753 * @param {Number} value The amount to add to the current date
1754 * @return {Date} The new Date instance
1756 Date.prototype.add = function(interval, value){
1757 var d = this.clone();
1758 if (!interval || value === 0) return d;
1759 switch(interval.toLowerCase()){
1761 d.setMilliseconds(this.getMilliseconds() + value);
1764 d.setSeconds(this.getSeconds() + value);
1767 d.setMinutes(this.getMinutes() + value);
1770 d.setHours(this.getHours() + value);
1773 d.setDate(this.getDate() + value);
1776 var day = this.getDate();
1778 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1781 d.setMonth(this.getMonth() + value);
1784 d.setFullYear(this.getFullYear() + value);
1791 * Ext JS Library 1.1.1
1792 * Copyright(c) 2006-2007, Ext JS, LLC.
1794 * Originally Released Under LGPL - original licence link has changed is not relivant.
1797 * <script type="text/javascript">
1801 * @class Roo.lib.Dom
1804 * Dom utils (from YIU afaik)
1809 * Get the view width
1810 * @param {Boolean} full True will get the full document, otherwise it's the view width
1811 * @return {Number} The width
1814 getViewWidth : function(full) {
1815 return full ? this.getDocumentWidth() : this.getViewportWidth();
1818 * Get the view height
1819 * @param {Boolean} full True will get the full document, otherwise it's the view height
1820 * @return {Number} The height
1822 getViewHeight : function(full) {
1823 return full ? this.getDocumentHeight() : this.getViewportHeight();
1826 getDocumentHeight: function() {
1827 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1828 return Math.max(scrollHeight, this.getViewportHeight());
1831 getDocumentWidth: function() {
1832 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1833 return Math.max(scrollWidth, this.getViewportWidth());
1836 getViewportHeight: function() {
1837 var height = self.innerHeight;
1838 var mode = document.compatMode;
1840 if ((mode || Roo.isIE) && !Roo.isOpera) {
1841 height = (mode == "CSS1Compat") ?
1842 document.documentElement.clientHeight :
1843 document.body.clientHeight;
1849 getViewportWidth: function() {
1850 var width = self.innerWidth;
1851 var mode = document.compatMode;
1853 if (mode || Roo.isIE) {
1854 width = (mode == "CSS1Compat") ?
1855 document.documentElement.clientWidth :
1856 document.body.clientWidth;
1861 isAncestor : function(p, c) {
1868 if (p.contains && !Roo.isSafari) {
1869 return p.contains(c);
1870 } else if (p.compareDocumentPosition) {
1871 return !!(p.compareDocumentPosition(c) & 16);
1873 var parent = c.parentNode;
1878 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1881 parent = parent.parentNode;
1887 getRegion : function(el) {
1888 return Roo.lib.Region.getRegion(el);
1891 getY : function(el) {
1892 return this.getXY(el)[1];
1895 getX : function(el) {
1896 return this.getXY(el)[0];
1899 getXY : function(el) {
1900 var p, pe, b, scroll, bd = document.body;
1901 el = Roo.getDom(el);
1902 var fly = Roo.lib.AnimBase.fly;
1903 if (el.getBoundingClientRect) {
1904 b = el.getBoundingClientRect();
1905 scroll = fly(document).getScroll();
1906 return [b.left + scroll.left, b.top + scroll.top];
1912 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1919 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1926 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1927 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1934 if (p != el && pe.getStyle('overflow') != 'visible') {
1942 if (Roo.isSafari && hasAbsolute) {
1947 if (Roo.isGecko && !hasAbsolute) {
1949 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1950 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1954 while (p && p != bd) {
1955 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1967 setXY : function(el, xy) {
1968 el = Roo.fly(el, '_setXY');
1970 var pts = el.translatePoints(xy);
1971 if (xy[0] !== false) {
1972 el.dom.style.left = pts.left + "px";
1974 if (xy[1] !== false) {
1975 el.dom.style.top = pts.top + "px";
1979 setX : function(el, x) {
1980 this.setXY(el, [x, false]);
1983 setY : function(el, y) {
1984 this.setXY(el, [false, y]);
1988 * Portions of this file are based on pieces of Yahoo User Interface Library
1989 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
1990 * YUI licensed under the BSD License:
1991 * http://developer.yahoo.net/yui/license.txt
1992 * <script type="text/javascript">
1996 Roo.lib.Event = function() {
1997 var loadComplete = false;
1999 var unloadListeners = [];
2001 var onAvailStack = [];
2003 var lastError = null;
2016 startInterval: function() {
2017 if (!this._interval) {
2019 var callback = function() {
2020 self._tryPreloadAttach();
2022 this._interval = setInterval(callback, this.POLL_INTERVAL);
2027 onAvailable: function(p_id, p_fn, p_obj, p_override) {
2028 onAvailStack.push({ id: p_id,
2031 override: p_override,
2032 checkReady: false });
2034 retryCount = this.POLL_RETRYS;
2035 this.startInterval();
2039 addListener: function(el, eventName, fn) {
2040 el = Roo.getDom(el);
2045 if ("unload" == eventName) {
2046 unloadListeners[unloadListeners.length] =
2047 [el, eventName, fn];
2051 var wrappedFn = function(e) {
2052 return fn(Roo.lib.Event.getEvent(e));
2055 var li = [el, eventName, fn, wrappedFn];
2057 var index = listeners.length;
2058 listeners[index] = li;
2060 this.doAdd(el, eventName, wrappedFn, false);
2066 removeListener: function(el, eventName, fn) {
2069 el = Roo.getDom(el);
2072 return this.purgeElement(el, false, eventName);
2076 if ("unload" == eventName) {
2078 for (i = 0,len = unloadListeners.length; i < len; i++) {
2079 var li = unloadListeners[i];
2082 li[1] == eventName &&
2084 unloadListeners.splice(i, 1);
2092 var cacheItem = null;
2095 var index = arguments[3];
2097 if ("undefined" == typeof index) {
2098 index = this._getCacheIndex(el, eventName, fn);
2102 cacheItem = listeners[index];
2105 if (!el || !cacheItem) {
2109 this.doRemove(el, eventName, cacheItem[this.WFN], false);
2111 delete listeners[index][this.WFN];
2112 delete listeners[index][this.FN];
2113 listeners.splice(index, 1);
2120 getTarget: function(ev, resolveTextNode) {
2121 ev = ev.browserEvent || ev;
2122 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2123 var t = ev.target || ev.srcElement;
2124 return this.resolveTextNode(t);
2128 resolveTextNode: function(node) {
2129 if (Roo.isSafari && node && 3 == node.nodeType) {
2130 return node.parentNode;
2137 getPageX: function(ev) {
2138 ev = ev.browserEvent || ev;
2139 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2141 if (!x && 0 !== x) {
2142 x = ev.clientX || 0;
2145 x += this.getScroll()[1];
2153 getPageY: function(ev) {
2154 ev = ev.browserEvent || ev;
2155 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2157 if (!y && 0 !== y) {
2158 y = ev.clientY || 0;
2161 y += this.getScroll()[0];
2170 getXY: function(ev) {
2171 ev = ev.browserEvent || ev;
2172 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2173 return [this.getPageX(ev), this.getPageY(ev)];
2177 getRelatedTarget: function(ev) {
2178 ev = ev.browserEvent || ev;
2179 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2180 var t = ev.relatedTarget;
2182 if (ev.type == "mouseout") {
2184 } else if (ev.type == "mouseover") {
2189 return this.resolveTextNode(t);
2193 getTime: function(ev) {
2194 ev = ev.browserEvent || ev;
2195 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2197 var t = new Date().getTime();
2201 this.lastError = ex;
2210 stopEvent: function(ev) {
2211 this.stopPropagation(ev);
2212 this.preventDefault(ev);
2216 stopPropagation: function(ev) {
2217 ev = ev.browserEvent || ev;
2218 if (ev.stopPropagation) {
2219 ev.stopPropagation();
2221 ev.cancelBubble = true;
2226 preventDefault: function(ev) {
2227 ev = ev.browserEvent || ev;
2228 if(ev.preventDefault) {
2229 ev.preventDefault();
2231 ev.returnValue = false;
2236 getEvent: function(e) {
2237 var ev = e || window.event;
2239 var c = this.getEvent.caller;
2241 ev = c.arguments[0];
2242 if (ev && Event == ev.constructor) {
2252 getCharCode: function(ev) {
2253 ev = ev.browserEvent || ev;
2254 return ev.charCode || ev.keyCode || 0;
2258 _getCacheIndex: function(el, eventName, fn) {
2259 for (var i = 0,len = listeners.length; i < len; ++i) {
2260 var li = listeners[i];
2262 li[this.FN] == fn &&
2263 li[this.EL] == el &&
2264 li[this.TYPE] == eventName) {
2276 getEl: function(id) {
2277 return document.getElementById(id);
2281 clearCache: function() {
2285 _load: function(e) {
2286 loadComplete = true;
2287 var EU = Roo.lib.Event;
2291 EU.doRemove(window, "load", EU._load);
2296 _tryPreloadAttach: function() {
2305 var tryAgain = !loadComplete;
2307 tryAgain = (retryCount > 0);
2312 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2313 var item = onAvailStack[i];
2315 var el = this.getEl(item.id);
2318 if (!item.checkReady ||
2321 (document && document.body)) {
2324 if (item.override) {
2325 if (item.override === true) {
2328 scope = item.override;
2331 item.fn.call(scope, item.obj);
2332 onAvailStack[i] = null;
2335 notAvail.push(item);
2340 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2344 this.startInterval();
2346 clearInterval(this._interval);
2347 this._interval = null;
2350 this.locked = false;
2357 purgeElement: function(el, recurse, eventName) {
2358 var elListeners = this.getListeners(el, eventName);
2360 for (var i = 0,len = elListeners.length; i < len; ++i) {
2361 var l = elListeners[i];
2362 this.removeListener(el, l.type, l.fn);
2366 if (recurse && el && el.childNodes) {
2367 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2368 this.purgeElement(el.childNodes[i], recurse, eventName);
2374 getListeners: function(el, eventName) {
2375 var results = [], searchLists;
2377 searchLists = [listeners, unloadListeners];
2378 } else if (eventName == "unload") {
2379 searchLists = [unloadListeners];
2381 searchLists = [listeners];
2384 for (var j = 0; j < searchLists.length; ++j) {
2385 var searchList = searchLists[j];
2386 if (searchList && searchList.length > 0) {
2387 for (var i = 0,len = searchList.length; i < len; ++i) {
2388 var l = searchList[i];
2389 if (l && l[this.EL] === el &&
2390 (!eventName || eventName === l[this.TYPE])) {
2395 adjust: l[this.ADJ_SCOPE],
2403 return (results.length) ? results : null;
2407 _unload: function(e) {
2409 var EU = Roo.lib.Event, i, j, l, len, index;
2411 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2412 l = unloadListeners[i];
2415 if (l[EU.ADJ_SCOPE]) {
2416 if (l[EU.ADJ_SCOPE] === true) {
2419 scope = l[EU.ADJ_SCOPE];
2422 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2423 unloadListeners[i] = null;
2429 unloadListeners = null;
2431 if (listeners && listeners.length > 0) {
2432 j = listeners.length;
2435 l = listeners[index];
2437 EU.removeListener(l[EU.EL], l[EU.TYPE],
2447 EU.doRemove(window, "unload", EU._unload);
2452 getScroll: function() {
2453 var dd = document.documentElement, db = document.body;
2454 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2455 return [dd.scrollTop, dd.scrollLeft];
2457 return [db.scrollTop, db.scrollLeft];
2464 doAdd: function () {
2465 if (window.addEventListener) {
2466 return function(el, eventName, fn, capture) {
2467 el.addEventListener(eventName, fn, (capture));
2469 } else if (window.attachEvent) {
2470 return function(el, eventName, fn, capture) {
2471 el.attachEvent("on" + eventName, fn);
2480 doRemove: function() {
2481 if (window.removeEventListener) {
2482 return function (el, eventName, fn, capture) {
2483 el.removeEventListener(eventName, fn, (capture));
2485 } else if (window.detachEvent) {
2486 return function (el, eventName, fn) {
2487 el.detachEvent("on" + eventName, fn);
2499 var E = Roo.lib.Event;
2500 E.on = E.addListener;
2501 E.un = E.removeListener;
2503 if (document && document.body) {
2506 E.doAdd(window, "load", E._load);
2508 E.doAdd(window, "unload", E._unload);
2509 E._tryPreloadAttach();
2513 * Portions of this file are based on pieces of Yahoo User Interface Library
2514 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2515 * YUI licensed under the BSD License:
2516 * http://developer.yahoo.net/yui/license.txt
2517 * <script type="text/javascript">
2523 * @class Roo.lib.Ajax
2530 request : function(method, uri, cb, data, options) {
2532 var hs = options.headers;
2535 if(hs.hasOwnProperty(h)){
2536 this.initHeader(h, hs[h], false);
2540 if(options.xmlData){
2541 this.initHeader('Content-Type', 'text/xml', false);
2543 data = options.xmlData;
2547 return this.asyncRequest(method, uri, cb, data);
2550 serializeForm : function(form) {
2551 if(typeof form == 'string') {
2552 form = (document.getElementById(form) || document.forms[form]);
2555 var el, name, val, disabled, data = '', hasSubmit = false;
2556 for (var i = 0; i < form.elements.length; i++) {
2557 el = form.elements[i];
2558 disabled = form.elements[i].disabled;
2559 name = form.elements[i].name;
2560 val = form.elements[i].value;
2562 if (!disabled && name){
2566 case 'select-multiple':
2567 for (var j = 0; j < el.options.length; j++) {
2568 if (el.options[j].selected) {
2570 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2573 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2581 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2594 if(hasSubmit == false) {
2595 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2600 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2605 data = data.substr(0, data.length - 1);
2613 useDefaultHeader:true,
2615 defaultPostHeader:'application/x-www-form-urlencoded',
2617 useDefaultXhrHeader:true,
2619 defaultXhrHeader:'XMLHttpRequest',
2621 hasDefaultHeaders:true,
2633 setProgId:function(id)
2635 this.activeX.unshift(id);
2638 setDefaultPostHeader:function(b)
2640 this.useDefaultHeader = b;
2643 setDefaultXhrHeader:function(b)
2645 this.useDefaultXhrHeader = b;
2648 setPollingInterval:function(i)
2650 if (typeof i == 'number' && isFinite(i)) {
2651 this.pollInterval = i;
2655 createXhrObject:function(transactionId)
2661 http = new XMLHttpRequest();
2663 obj = { conn:http, tId:transactionId };
2667 for (var i = 0; i < this.activeX.length; ++i) {
2671 http = new ActiveXObject(this.activeX[i]);
2673 obj = { conn:http, tId:transactionId };
2686 getConnectionObject:function()
2689 var tId = this.transactionId;
2693 o = this.createXhrObject(tId);
2695 this.transactionId++;
2706 asyncRequest:function(method, uri, callback, postData)
2708 var o = this.getConnectionObject();
2714 o.conn.open(method, uri, true);
2716 if (this.useDefaultXhrHeader) {
2717 if (!this.defaultHeaders['X-Requested-With']) {
2718 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2722 if(postData && this.useDefaultHeader){
2723 this.initHeader('Content-Type', this.defaultPostHeader);
2726 if (this.hasDefaultHeaders || this.hasHeaders) {
2730 this.handleReadyState(o, callback);
2731 o.conn.send(postData || null);
2737 handleReadyState:function(o, callback)
2741 if (callback && callback.timeout) {
2743 this.timeout[o.tId] = window.setTimeout(function() {
2744 oConn.abort(o, callback, true);
2745 }, callback.timeout);
2748 this.poll[o.tId] = window.setInterval(
2750 if (o.conn && o.conn.readyState == 4) {
2751 window.clearInterval(oConn.poll[o.tId]);
2752 delete oConn.poll[o.tId];
2754 if(callback && callback.timeout) {
2755 window.clearTimeout(oConn.timeout[o.tId]);
2756 delete oConn.timeout[o.tId];
2759 oConn.handleTransactionResponse(o, callback);
2762 , this.pollInterval);
2765 handleTransactionResponse:function(o, callback, isAbort)
2769 this.releaseObject(o);
2773 var httpStatus, responseObject;
2777 if (o.conn.status !== undefined && o.conn.status != 0) {
2778 httpStatus = o.conn.status;
2790 if (httpStatus >= 200 && httpStatus < 300) {
2791 responseObject = this.createResponseObject(o, callback.argument);
2792 if (callback.success) {
2793 if (!callback.scope) {
2794 callback.success(responseObject);
2799 callback.success.apply(callback.scope, [responseObject]);
2804 switch (httpStatus) {
2812 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2813 if (callback.failure) {
2814 if (!callback.scope) {
2815 callback.failure(responseObject);
2818 callback.failure.apply(callback.scope, [responseObject]);
2823 responseObject = this.createResponseObject(o, callback.argument);
2824 if (callback.failure) {
2825 if (!callback.scope) {
2826 callback.failure(responseObject);
2829 callback.failure.apply(callback.scope, [responseObject]);
2835 this.releaseObject(o);
2836 responseObject = null;
2839 createResponseObject:function(o, callbackArg)
2846 var headerStr = o.conn.getAllResponseHeaders();
2847 var header = headerStr.split('\n');
2848 for (var i = 0; i < header.length; i++) {
2849 var delimitPos = header[i].indexOf(':');
2850 if (delimitPos != -1) {
2851 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2859 obj.status = o.conn.status;
2860 obj.statusText = o.conn.statusText;
2861 obj.getResponseHeader = headerObj;
2862 obj.getAllResponseHeaders = headerStr;
2863 obj.responseText = o.conn.responseText;
2864 obj.responseXML = o.conn.responseXML;
2866 if (typeof callbackArg !== undefined) {
2867 obj.argument = callbackArg;
2873 createExceptionObject:function(tId, callbackArg, isAbort)
2876 var COMM_ERROR = 'communication failure';
2877 var ABORT_CODE = -1;
2878 var ABORT_ERROR = 'transaction aborted';
2884 obj.status = ABORT_CODE;
2885 obj.statusText = ABORT_ERROR;
2888 obj.status = COMM_CODE;
2889 obj.statusText = COMM_ERROR;
2893 obj.argument = callbackArg;
2899 initHeader:function(label, value, isDefault)
2901 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2903 if (headerObj[label] === undefined) {
2904 headerObj[label] = value;
2909 headerObj[label] = value + "," + headerObj[label];
2913 this.hasDefaultHeaders = true;
2916 this.hasHeaders = true;
2921 setHeader:function(o)
2923 if (this.hasDefaultHeaders) {
2924 for (var prop in this.defaultHeaders) {
2925 if (this.defaultHeaders.hasOwnProperty(prop)) {
2926 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2931 if (this.hasHeaders) {
2932 for (var prop in this.headers) {
2933 if (this.headers.hasOwnProperty(prop)) {
2934 o.conn.setRequestHeader(prop, this.headers[prop]);
2938 this.hasHeaders = false;
2942 resetDefaultHeaders:function() {
2943 delete this.defaultHeaders;
2944 this.defaultHeaders = {};
2945 this.hasDefaultHeaders = false;
2948 abort:function(o, callback, isTimeout)
2950 if(this.isCallInProgress(o)) {
2952 window.clearInterval(this.poll[o.tId]);
2953 delete this.poll[o.tId];
2955 delete this.timeout[o.tId];
2958 this.handleTransactionResponse(o, callback, true);
2968 isCallInProgress:function(o)
2971 return o.conn.readyState != 4 && o.conn.readyState != 0;
2980 releaseObject:function(o)
2989 'MSXML2.XMLHTTP.3.0',
2997 * Portions of this file are based on pieces of Yahoo User Interface Library
2998 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2999 * YUI licensed under the BSD License:
3000 * http://developer.yahoo.net/yui/license.txt
3001 * <script type="text/javascript">
3005 Roo.lib.Region = function(t, r, b, l) {
3015 Roo.lib.Region.prototype = {
3016 contains : function(region) {
3017 return ( region.left >= this.left &&
3018 region.right <= this.right &&
3019 region.top >= this.top &&
3020 region.bottom <= this.bottom );
3024 getArea : function() {
3025 return ( (this.bottom - this.top) * (this.right - this.left) );
3028 intersect : function(region) {
3029 var t = Math.max(this.top, region.top);
3030 var r = Math.min(this.right, region.right);
3031 var b = Math.min(this.bottom, region.bottom);
3032 var l = Math.max(this.left, region.left);
3034 if (b >= t && r >= l) {
3035 return new Roo.lib.Region(t, r, b, l);
3040 union : function(region) {
3041 var t = Math.min(this.top, region.top);
3042 var r = Math.max(this.right, region.right);
3043 var b = Math.max(this.bottom, region.bottom);
3044 var l = Math.min(this.left, region.left);
3046 return new Roo.lib.Region(t, r, b, l);
3049 adjust : function(t, l, b, r) {
3058 Roo.lib.Region.getRegion = function(el) {
3059 var p = Roo.lib.Dom.getXY(el);
3062 var r = p[0] + el.offsetWidth;
3063 var b = p[1] + el.offsetHeight;
3066 return new Roo.lib.Region(t, r, b, l);
3069 * Portions of this file are based on pieces of Yahoo User Interface Library
3070 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3071 * YUI licensed under the BSD License:
3072 * http://developer.yahoo.net/yui/license.txt
3073 * <script type="text/javascript">
3076 //@@dep Roo.lib.Region
3079 Roo.lib.Point = function(x, y) {
3080 if (x instanceof Array) {
3084 this.x = this.right = this.left = this[0] = x;
3085 this.y = this.top = this.bottom = this[1] = y;
3088 Roo.lib.Point.prototype = new Roo.lib.Region();
3090 * Portions of this file are based on pieces of Yahoo User Interface Library
3091 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3092 * YUI licensed under the BSD License:
3093 * http://developer.yahoo.net/yui/license.txt
3094 * <script type="text/javascript">
3101 scroll : function(el, args, duration, easing, cb, scope) {
3102 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
3105 motion : function(el, args, duration, easing, cb, scope) {
3106 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
3109 color : function(el, args, duration, easing, cb, scope) {
3110 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
3113 run : function(el, args, duration, easing, cb, scope, type) {
3114 type = type || Roo.lib.AnimBase;
3115 if (typeof easing == "string") {
3116 easing = Roo.lib.Easing[easing];
3118 var anim = new type(el, args, duration, easing);
3119 anim.animateX(function() {
3120 Roo.callback(cb, scope);
3126 * Portions of this file are based on pieces of Yahoo User Interface Library
3127 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3128 * YUI licensed under the BSD License:
3129 * http://developer.yahoo.net/yui/license.txt
3130 * <script type="text/javascript">
3138 if (!libFlyweight) {
3139 libFlyweight = new Roo.Element.Flyweight();
3141 libFlyweight.dom = el;
3142 return libFlyweight;
3145 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
3149 Roo.lib.AnimBase = function(el, attributes, duration, method) {
3151 this.init(el, attributes, duration, method);
3155 Roo.lib.AnimBase.fly = fly;
3159 Roo.lib.AnimBase.prototype = {
3161 toString: function() {
3162 var el = this.getEl();
3163 var id = el.id || el.tagName;
3164 return ("Anim " + id);
3168 noNegatives: /width|height|opacity|padding/i,
3169 offsetAttribute: /^((width|height)|(top|left))$/,
3170 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3171 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3175 doMethod: function(attr, start, end) {
3176 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3180 setAttribute: function(attr, val, unit) {
3181 if (this.patterns.noNegatives.test(attr)) {
3182 val = (val > 0) ? val : 0;
3185 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3189 getAttribute: function(attr) {
3190 var el = this.getEl();
3191 var val = fly(el).getStyle(attr);
3193 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3194 return parseFloat(val);
3197 var a = this.patterns.offsetAttribute.exec(attr) || [];
3198 var pos = !!( a[3] );
3199 var box = !!( a[2] );
3202 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3203 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3212 getDefaultUnit: function(attr) {
3213 if (this.patterns.defaultUnit.test(attr)) {
3220 animateX : function(callback, scope) {
3221 var f = function() {
3222 this.onComplete.removeListener(f);
3223 if (typeof callback == "function") {
3224 callback.call(scope || this, this);
3227 this.onComplete.addListener(f, this);
3232 setRuntimeAttribute: function(attr) {
3235 var attributes = this.attributes;
3237 this.runtimeAttributes[attr] = {};
3239 var isset = function(prop) {
3240 return (typeof prop !== 'undefined');
3243 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3247 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3250 if (isset(attributes[attr]['to'])) {
3251 end = attributes[attr]['to'];
3252 } else if (isset(attributes[attr]['by'])) {
3253 if (start.constructor == Array) {
3255 for (var i = 0, len = start.length; i < len; ++i) {
3256 end[i] = start[i] + attributes[attr]['by'][i];
3259 end = start + attributes[attr]['by'];
3263 this.runtimeAttributes[attr].start = start;
3264 this.runtimeAttributes[attr].end = end;
3267 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3271 init: function(el, attributes, duration, method) {
3273 var isAnimated = false;
3276 var startTime = null;
3279 var actualFrames = 0;
3282 el = Roo.getDom(el);
3285 this.attributes = attributes || {};
3288 this.duration = duration || 1;
3291 this.method = method || Roo.lib.Easing.easeNone;
3294 this.useSeconds = true;
3297 this.currentFrame = 0;
3300 this.totalFrames = Roo.lib.AnimMgr.fps;
3303 this.getEl = function() {
3308 this.isAnimated = function() {
3313 this.getStartTime = function() {
3317 this.runtimeAttributes = {};
3320 this.animate = function() {
3321 if (this.isAnimated()) {
3325 this.currentFrame = 0;
3327 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3329 Roo.lib.AnimMgr.registerElement(this);
3333 this.stop = function(finish) {
3335 this.currentFrame = this.totalFrames;
3336 this._onTween.fire();
3338 Roo.lib.AnimMgr.stop(this);
3341 var onStart = function() {
3342 this.onStart.fire();
3344 this.runtimeAttributes = {};
3345 for (var attr in this.attributes) {
3346 this.setRuntimeAttribute(attr);
3351 startTime = new Date();
3355 var onTween = function() {
3357 duration: new Date() - this.getStartTime(),
3358 currentFrame: this.currentFrame
3361 data.toString = function() {
3363 'duration: ' + data.duration +
3364 ', currentFrame: ' + data.currentFrame
3368 this.onTween.fire(data);
3370 var runtimeAttributes = this.runtimeAttributes;
3372 for (var attr in runtimeAttributes) {
3373 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3379 var onComplete = function() {
3380 var actual_duration = (new Date() - startTime) / 1000 ;
3383 duration: actual_duration,
3384 frames: actualFrames,
3385 fps: actualFrames / actual_duration
3388 data.toString = function() {
3390 'duration: ' + data.duration +
3391 ', frames: ' + data.frames +
3392 ', fps: ' + data.fps
3398 this.onComplete.fire(data);
3402 this._onStart = new Roo.util.Event(this);
3403 this.onStart = new Roo.util.Event(this);
3404 this.onTween = new Roo.util.Event(this);
3405 this._onTween = new Roo.util.Event(this);
3406 this.onComplete = new Roo.util.Event(this);
3407 this._onComplete = new Roo.util.Event(this);
3408 this._onStart.addListener(onStart);
3409 this._onTween.addListener(onTween);
3410 this._onComplete.addListener(onComplete);
3415 * Portions of this file are based on pieces of Yahoo User Interface Library
3416 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3417 * YUI licensed under the BSD License:
3418 * http://developer.yahoo.net/yui/license.txt
3419 * <script type="text/javascript">
3423 Roo.lib.AnimMgr = new function() {
3440 this.registerElement = function(tween) {
3441 queue[queue.length] = tween;
3443 tween._onStart.fire();
3448 this.unRegister = function(tween, index) {
3449 tween._onComplete.fire();
3450 index = index || getIndex(tween);
3452 queue.splice(index, 1);
3456 if (tweenCount <= 0) {
3462 this.start = function() {
3463 if (thread === null) {
3464 thread = setInterval(this.run, this.delay);
3469 this.stop = function(tween) {
3471 clearInterval(thread);
3473 for (var i = 0, len = queue.length; i < len; ++i) {
3474 if (queue[0].isAnimated()) {
3475 this.unRegister(queue[0], 0);
3484 this.unRegister(tween);
3489 this.run = function() {
3490 for (var i = 0, len = queue.length; i < len; ++i) {
3491 var tween = queue[i];
3492 if (!tween || !tween.isAnimated()) {
3496 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3498 tween.currentFrame += 1;
3500 if (tween.useSeconds) {
3501 correctFrame(tween);
3503 tween._onTween.fire();
3506 Roo.lib.AnimMgr.stop(tween, i);
3511 var getIndex = function(anim) {
3512 for (var i = 0, len = queue.length; i < len; ++i) {
3513 if (queue[i] == anim) {
3521 var correctFrame = function(tween) {
3522 var frames = tween.totalFrames;
3523 var frame = tween.currentFrame;
3524 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3525 var elapsed = (new Date() - tween.getStartTime());
3528 if (elapsed < tween.duration * 1000) {
3529 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3531 tweak = frames - (frame + 1);
3533 if (tweak > 0 && isFinite(tweak)) {
3534 if (tween.currentFrame + tweak >= frames) {
3535 tweak = frames - (frame + 1);
3538 tween.currentFrame += tweak;
3544 * Portions of this file are based on pieces of Yahoo User Interface Library
3545 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3546 * YUI licensed under the BSD License:
3547 * http://developer.yahoo.net/yui/license.txt
3548 * <script type="text/javascript">
3551 Roo.lib.Bezier = new function() {
3553 this.getPosition = function(points, t) {
3554 var n = points.length;
3557 for (var i = 0; i < n; ++i) {
3558 tmp[i] = [points[i][0], points[i][1]];
3561 for (var j = 1; j < n; ++j) {
3562 for (i = 0; i < n - j; ++i) {
3563 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3564 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3568 return [ tmp[0][0], tmp[0][1] ];
3572 * Portions of this file are based on pieces of Yahoo User Interface Library
3573 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3574 * YUI licensed under the BSD License:
3575 * http://developer.yahoo.net/yui/license.txt
3576 * <script type="text/javascript">
3581 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3582 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3585 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3587 var fly = Roo.lib.AnimBase.fly;
3589 var superclass = Y.ColorAnim.superclass;
3590 var proto = Y.ColorAnim.prototype;
3592 proto.toString = function() {
3593 var el = this.getEl();
3594 var id = el.id || el.tagName;
3595 return ("ColorAnim " + id);
3598 proto.patterns.color = /color$/i;
3599 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3600 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3601 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3602 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3605 proto.parseColor = function(s) {
3606 if (s.length == 3) {
3610 var c = this.patterns.hex.exec(s);
3611 if (c && c.length == 4) {
3612 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3615 c = this.patterns.rgb.exec(s);
3616 if (c && c.length == 4) {
3617 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3620 c = this.patterns.hex3.exec(s);
3621 if (c && c.length == 4) {
3622 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3627 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3628 proto.getAttribute = function(attr) {
3629 var el = this.getEl();
3630 if (this.patterns.color.test(attr)) {
3631 var val = fly(el).getStyle(attr);
3633 if (this.patterns.transparent.test(val)) {
3634 var parent = el.parentNode;
3635 val = fly(parent).getStyle(attr);
3637 while (parent && this.patterns.transparent.test(val)) {
3638 parent = parent.parentNode;
3639 val = fly(parent).getStyle(attr);
3640 if (parent.tagName.toUpperCase() == 'HTML') {
3646 val = superclass.getAttribute.call(this, attr);
3651 proto.getAttribute = function(attr) {
3652 var el = this.getEl();
3653 if (this.patterns.color.test(attr)) {
3654 var val = fly(el).getStyle(attr);
3656 if (this.patterns.transparent.test(val)) {
3657 var parent = el.parentNode;
3658 val = fly(parent).getStyle(attr);
3660 while (parent && this.patterns.transparent.test(val)) {
3661 parent = parent.parentNode;
3662 val = fly(parent).getStyle(attr);
3663 if (parent.tagName.toUpperCase() == 'HTML') {
3669 val = superclass.getAttribute.call(this, attr);
3675 proto.doMethod = function(attr, start, end) {
3678 if (this.patterns.color.test(attr)) {
3680 for (var i = 0, len = start.length; i < len; ++i) {
3681 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3684 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3687 val = superclass.doMethod.call(this, attr, start, end);
3693 proto.setRuntimeAttribute = function(attr) {
3694 superclass.setRuntimeAttribute.call(this, attr);
3696 if (this.patterns.color.test(attr)) {
3697 var attributes = this.attributes;
3698 var start = this.parseColor(this.runtimeAttributes[attr].start);
3699 var end = this.parseColor(this.runtimeAttributes[attr].end);
3701 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3702 end = this.parseColor(attributes[attr].by);
3704 for (var i = 0, len = start.length; i < len; ++i) {
3705 end[i] = start[i] + end[i];
3709 this.runtimeAttributes[attr].start = start;
3710 this.runtimeAttributes[attr].end = end;
3716 * Portions of this file are based on pieces of Yahoo User Interface Library
3717 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3718 * YUI licensed under the BSD License:
3719 * http://developer.yahoo.net/yui/license.txt
3720 * <script type="text/javascript">
3726 easeNone: function (t, b, c, d) {
3727 return c * t / d + b;
3731 easeIn: function (t, b, c, d) {
3732 return c * (t /= d) * t + b;
3736 easeOut: function (t, b, c, d) {
3737 return -c * (t /= d) * (t - 2) + b;
3741 easeBoth: function (t, b, c, d) {
3742 if ((t /= d / 2) < 1) {
3743 return c / 2 * t * t + b;
3746 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3750 easeInStrong: function (t, b, c, d) {
3751 return c * (t /= d) * t * t * t + b;
3755 easeOutStrong: function (t, b, c, d) {
3756 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3760 easeBothStrong: function (t, b, c, d) {
3761 if ((t /= d / 2) < 1) {
3762 return c / 2 * t * t * t * t + b;
3765 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3770 elasticIn: function (t, b, c, d, a, p) {
3774 if ((t /= d) == 1) {
3781 if (!a || a < Math.abs(c)) {
3786 var s = p / (2 * Math.PI) * Math.asin(c / a);
3789 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3793 elasticOut: function (t, b, c, d, a, p) {
3797 if ((t /= d) == 1) {
3804 if (!a || a < Math.abs(c)) {
3809 var s = p / (2 * Math.PI) * Math.asin(c / a);
3812 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3816 elasticBoth: function (t, b, c, d, a, p) {
3821 if ((t /= d / 2) == 2) {
3829 if (!a || a < Math.abs(c)) {
3834 var s = p / (2 * Math.PI) * Math.asin(c / a);
3838 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3839 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3841 return a * Math.pow(2, -10 * (t -= 1)) *
3842 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3847 backIn: function (t, b, c, d, s) {
3848 if (typeof s == 'undefined') {
3851 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3855 backOut: function (t, b, c, d, s) {
3856 if (typeof s == 'undefined') {
3859 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3863 backBoth: function (t, b, c, d, s) {
3864 if (typeof s == 'undefined') {
3868 if ((t /= d / 2 ) < 1) {
3869 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3871 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3875 bounceIn: function (t, b, c, d) {
3876 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3880 bounceOut: function (t, b, c, d) {
3881 if ((t /= d) < (1 / 2.75)) {
3882 return c * (7.5625 * t * t) + b;
3883 } else if (t < (2 / 2.75)) {
3884 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3885 } else if (t < (2.5 / 2.75)) {
3886 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3888 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3892 bounceBoth: function (t, b, c, d) {
3894 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3896 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3899 * Portions of this file are based on pieces of Yahoo User Interface Library
3900 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3901 * YUI licensed under the BSD License:
3902 * http://developer.yahoo.net/yui/license.txt
3903 * <script type="text/javascript">
3907 Roo.lib.Motion = function(el, attributes, duration, method) {
3909 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3913 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3917 var superclass = Y.Motion.superclass;
3918 var proto = Y.Motion.prototype;
3920 proto.toString = function() {
3921 var el = this.getEl();
3922 var id = el.id || el.tagName;
3923 return ("Motion " + id);
3926 proto.patterns.points = /^points$/i;
3928 proto.setAttribute = function(attr, val, unit) {
3929 if (this.patterns.points.test(attr)) {
3930 unit = unit || 'px';
3931 superclass.setAttribute.call(this, 'left', val[0], unit);
3932 superclass.setAttribute.call(this, 'top', val[1], unit);
3934 superclass.setAttribute.call(this, attr, val, unit);
3938 proto.getAttribute = function(attr) {
3939 if (this.patterns.points.test(attr)) {
3941 superclass.getAttribute.call(this, 'left'),
3942 superclass.getAttribute.call(this, 'top')
3945 val = superclass.getAttribute.call(this, attr);
3951 proto.doMethod = function(attr, start, end) {
3954 if (this.patterns.points.test(attr)) {
3955 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3956 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3958 val = superclass.doMethod.call(this, attr, start, end);
3963 proto.setRuntimeAttribute = function(attr) {
3964 if (this.patterns.points.test(attr)) {
3965 var el = this.getEl();
3966 var attributes = this.attributes;
3968 var control = attributes['points']['control'] || [];
3972 if (control.length > 0 && !(control[0] instanceof Array)) {
3973 control = [control];
3976 for (i = 0,len = control.length; i < len; ++i) {
3977 tmp[i] = control[i];
3982 Roo.fly(el).position();
3984 if (isset(attributes['points']['from'])) {
3985 Roo.lib.Dom.setXY(el, attributes['points']['from']);
3988 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3991 start = this.getAttribute('points');
3994 if (isset(attributes['points']['to'])) {
3995 end = translateValues.call(this, attributes['points']['to'], start);
3997 var pageXY = Roo.lib.Dom.getXY(this.getEl());
3998 for (i = 0,len = control.length; i < len; ++i) {
3999 control[i] = translateValues.call(this, control[i], start);
4003 } else if (isset(attributes['points']['by'])) {
4004 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
4006 for (i = 0,len = control.length; i < len; ++i) {
4007 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
4011 this.runtimeAttributes[attr] = [start];
4013 if (control.length > 0) {
4014 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
4017 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
4020 superclass.setRuntimeAttribute.call(this, attr);
4024 var translateValues = function(val, start) {
4025 var pageXY = Roo.lib.Dom.getXY(this.getEl());
4026 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
4031 var isset = function(prop) {
4032 return (typeof prop !== 'undefined');
4036 * Portions of this file are based on pieces of Yahoo User Interface Library
4037 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4038 * YUI licensed under the BSD License:
4039 * http://developer.yahoo.net/yui/license.txt
4040 * <script type="text/javascript">
4044 Roo.lib.Scroll = function(el, attributes, duration, method) {
4046 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
4050 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
4054 var superclass = Y.Scroll.superclass;
4055 var proto = Y.Scroll.prototype;
4057 proto.toString = function() {
4058 var el = this.getEl();
4059 var id = el.id || el.tagName;
4060 return ("Scroll " + id);
4063 proto.doMethod = function(attr, start, end) {
4066 if (attr == 'scroll') {
4068 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
4069 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
4073 val = superclass.doMethod.call(this, attr, start, end);
4078 proto.getAttribute = function(attr) {
4080 var el = this.getEl();
4082 if (attr == 'scroll') {
4083 val = [ el.scrollLeft, el.scrollTop ];
4085 val = superclass.getAttribute.call(this, attr);
4091 proto.setAttribute = function(attr, val, unit) {
4092 var el = this.getEl();
4094 if (attr == 'scroll') {
4095 el.scrollLeft = val[0];
4096 el.scrollTop = val[1];
4098 superclass.setAttribute.call(this, attr, val, unit);
4104 * Ext JS Library 1.1.1
4105 * Copyright(c) 2006-2007, Ext JS, LLC.
4107 * Originally Released Under LGPL - original licence link has changed is not relivant.
4110 * <script type="text/javascript">
4114 // nasty IE9 hack - what a pile of crap that is..
4116 if (typeof Range != "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
4117 Range.prototype.createContextualFragment = function (html) {
4118 var doc = window.document;
4119 var container = doc.createElement("div");
4120 container.innerHTML = html;
4121 var frag = doc.createDocumentFragment(), n;
4122 while ((n = container.firstChild)) {
4123 frag.appendChild(n);
4130 * @class Roo.DomHelper
4131 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
4132 * For more information see <a href="http://web.archive.org/web/20071221063734/http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>.
4135 Roo.DomHelper = function(){
4136 var tempTableEl = null;
4137 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
4138 var tableRe = /^table|tbody|tr|td$/i;
4140 // build as innerHTML where available
4142 var createHtml = function(o){
4143 if(typeof o == 'string'){
4152 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue;
4153 if(attr == "style"){
4155 if(typeof s == "function"){
4158 if(typeof s == "string"){
4159 b += ' style="' + s + '"';
4160 }else if(typeof s == "object"){
4163 if(typeof s[key] != "function"){
4164 b += key + ":" + s[key] + ";";
4171 b += ' class="' + o["cls"] + '"';
4172 }else if(attr == "htmlFor"){
4173 b += ' for="' + o["htmlFor"] + '"';
4175 b += " " + attr + '="' + o[attr] + '"';
4179 if(emptyTags.test(o.tag)){
4183 var cn = o.children || o.cn;
4185 //http://bugs.kde.org/show_bug.cgi?id=71506
4186 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4187 for(var i = 0, len = cn.length; i < len; i++) {
4188 b += createHtml(cn[i], b);
4191 b += createHtml(cn, b);
4197 b += "</" + o.tag + ">";
4204 var createDom = function(o, parentNode){
4206 // defininition craeted..
4208 if (o.ns && o.ns != 'html') {
4210 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4211 xmlns[o.ns] = o.xmlns;
4214 if (typeof(xmlns[o.ns]) == 'undefined') {
4215 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4221 if (typeof(o) == 'string') {
4222 return parentNode.appendChild(document.createTextNode(o));
4224 o.tag = o.tag || div;
4225 if (o.ns && Roo.isIE) {
4227 o.tag = o.ns + ':' + o.tag;
4230 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4231 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4234 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4235 attr == "style" || typeof o[attr] == "function") continue;
4237 if(attr=="cls" && Roo.isIE){
4238 el.className = o["cls"];
4240 if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
4241 else el[attr] = o[attr];
4244 Roo.DomHelper.applyStyles(el, o.style);
4245 var cn = o.children || o.cn;
4247 //http://bugs.kde.org/show_bug.cgi?id=71506
4248 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4249 for(var i = 0, len = cn.length; i < len; i++) {
4250 createDom(cn[i], el);
4257 el.innerHTML = o.html;
4260 parentNode.appendChild(el);
4265 var ieTable = function(depth, s, h, e){
4266 tempTableEl.innerHTML = [s, h, e].join('');
4267 var i = -1, el = tempTableEl;
4274 // kill repeat to save bytes
4278 tbe = '</tbody>'+te,
4284 * Nasty code for IE's broken table implementation
4286 var insertIntoTable = function(tag, where, el, html){
4288 tempTableEl = document.createElement('div');
4293 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4296 if(where == 'beforebegin'){
4300 before = el.nextSibling;
4303 node = ieTable(4, trs, html, tre);
4305 else if(tag == 'tr'){
4306 if(where == 'beforebegin'){
4309 node = ieTable(3, tbs, html, tbe);
4310 } else if(where == 'afterend'){
4311 before = el.nextSibling;
4313 node = ieTable(3, tbs, html, tbe);
4314 } else{ // INTO a TR
4315 if(where == 'afterbegin'){
4316 before = el.firstChild;
4318 node = ieTable(4, trs, html, tre);
4320 } else if(tag == 'tbody'){
4321 if(where == 'beforebegin'){
4324 node = ieTable(2, ts, html, te);
4325 } else if(where == 'afterend'){
4326 before = el.nextSibling;
4328 node = ieTable(2, ts, html, te);
4330 if(where == 'afterbegin'){
4331 before = el.firstChild;
4333 node = ieTable(3, tbs, html, tbe);
4336 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4339 if(where == 'afterbegin'){
4340 before = el.firstChild;
4342 node = ieTable(2, ts, html, te);
4344 el.insertBefore(node, before);
4349 /** True to force the use of DOM instead of html fragments @type Boolean */
4353 * Returns the markup for the passed Element(s) config
4354 * @param {Object} o The Dom object spec (and children)
4357 markup : function(o){
4358 return createHtml(o);
4362 * Applies a style specification to an element
4363 * @param {String/HTMLElement} el The element to apply styles to
4364 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4365 * a function which returns such a specification.
4367 applyStyles : function(el, styles){
4370 if(typeof styles == "string"){
4371 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4373 while ((matches = re.exec(styles)) != null){
4374 el.setStyle(matches[1], matches[2]);
4376 }else if (typeof styles == "object"){
4377 for (var style in styles){
4378 el.setStyle(style, styles[style]);
4380 }else if (typeof styles == "function"){
4381 Roo.DomHelper.applyStyles(el, styles.call());
4387 * Inserts an HTML fragment into the Dom
4388 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4389 * @param {HTMLElement} el The context element
4390 * @param {String} html The HTML fragmenet
4391 * @return {HTMLElement} The new node
4393 insertHtml : function(where, el, html){
4394 where = where.toLowerCase();
4395 if(el.insertAdjacentHTML){
4396 if(tableRe.test(el.tagName)){
4398 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4404 el.insertAdjacentHTML('BeforeBegin', html);
4405 return el.previousSibling;
4407 el.insertAdjacentHTML('AfterBegin', html);
4408 return el.firstChild;
4410 el.insertAdjacentHTML('BeforeEnd', html);
4411 return el.lastChild;
4413 el.insertAdjacentHTML('AfterEnd', html);
4414 return el.nextSibling;
4416 throw 'Illegal insertion point -> "' + where + '"';
4418 var range = el.ownerDocument.createRange();
4422 range.setStartBefore(el);
4423 frag = range.createContextualFragment(html);
4424 el.parentNode.insertBefore(frag, el);
4425 return el.previousSibling;
4428 range.setStartBefore(el.firstChild);
4429 frag = range.createContextualFragment(html);
4430 el.insertBefore(frag, el.firstChild);
4431 return el.firstChild;
4433 el.innerHTML = html;
4434 return el.firstChild;
4438 range.setStartAfter(el.lastChild);
4439 frag = range.createContextualFragment(html);
4440 el.appendChild(frag);
4441 return el.lastChild;
4443 el.innerHTML = html;
4444 return el.lastChild;
4447 range.setStartAfter(el);
4448 frag = range.createContextualFragment(html);
4449 el.parentNode.insertBefore(frag, el.nextSibling);
4450 return el.nextSibling;
4452 throw 'Illegal insertion point -> "' + where + '"';
4456 * Creates new Dom element(s) and inserts them before el
4457 * @param {String/HTMLElement/Element} el The context element
4458 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4459 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4460 * @return {HTMLElement/Roo.Element} The new node
4462 insertBefore : function(el, o, returnElement){
4463 return this.doInsert(el, o, returnElement, "beforeBegin");
4467 * Creates new Dom element(s) and inserts them after el
4468 * @param {String/HTMLElement/Element} el The context element
4469 * @param {Object} o The Dom object spec (and children)
4470 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4471 * @return {HTMLElement/Roo.Element} The new node
4473 insertAfter : function(el, o, returnElement){
4474 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4478 * Creates new Dom element(s) and inserts them as the first child of el
4479 * @param {String/HTMLElement/Element} el The context element
4480 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4481 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4482 * @return {HTMLElement/Roo.Element} The new node
4484 insertFirst : function(el, o, returnElement){
4485 return this.doInsert(el, o, returnElement, "afterBegin");
4489 doInsert : function(el, o, returnElement, pos, sibling){
4490 el = Roo.getDom(el);
4492 if(this.useDom || o.ns){
4493 newNode = createDom(o, null);
4494 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4496 var html = createHtml(o);
4497 newNode = this.insertHtml(pos, el, html);
4499 return returnElement ? Roo.get(newNode, true) : newNode;
4503 * Creates new Dom element(s) and appends them to el
4504 * @param {String/HTMLElement/Element} el The context element
4505 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4506 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4507 * @return {HTMLElement/Roo.Element} The new node
4509 append : function(el, o, returnElement){
4510 el = Roo.getDom(el);
4512 if(this.useDom || o.ns){
4513 newNode = createDom(o, null);
4514 el.appendChild(newNode);
4516 var html = createHtml(o);
4517 newNode = this.insertHtml("beforeEnd", el, html);
4519 return returnElement ? Roo.get(newNode, true) : newNode;
4523 * Creates new Dom element(s) and overwrites the contents of el with them
4524 * @param {String/HTMLElement/Element} el The context element
4525 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4526 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4527 * @return {HTMLElement/Roo.Element} The new node
4529 overwrite : function(el, o, returnElement){
4530 el = Roo.getDom(el);
4533 while (el.childNodes.length) {
4534 el.removeChild(el.firstChild);
4538 el.innerHTML = createHtml(o);
4541 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4545 * Creates a new Roo.DomHelper.Template from the Dom object spec
4546 * @param {Object} o The Dom object spec (and children)
4547 * @return {Roo.DomHelper.Template} The new template
4549 createTemplate : function(o){
4550 var html = createHtml(o);
4551 return new Roo.Template(html);
4557 * Ext JS Library 1.1.1
4558 * Copyright(c) 2006-2007, Ext JS, LLC.
4560 * Originally Released Under LGPL - original licence link has changed is not relivant.
4563 * <script type="text/javascript">
4567 * @class Roo.Template
4568 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4569 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4572 var t = new Roo.Template({
4573 html : '<div name="{id}">' +
4574 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4576 myformat: function (value, allValues) {
4577 return 'XX' + value;
4580 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4582 * For more information see this blog post with examples:
4583 * <a href="http://www.cnitblog.com/seeyeah/archive/2011/12/30/38728.html/">DomHelper
4584 - Create Elements using DOM, HTML fragments and Templates</a>.
4586 * @param {Object} cfg - Configuration object.
4588 Roo.Template = function(cfg){
4590 if(cfg instanceof Array){
4592 }else if(arguments.length > 1){
4593 cfg = Array.prototype.join.call(arguments, "");
4597 if (typeof(cfg) == 'object') {
4608 Roo.Template.prototype = {
4611 * @cfg {String} url The Url to load the template from. beware if you are loading from a url, the data may not be ready if you use it instantly..
4612 * it should be fixed so that template is observable...
4616 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4620 * Returns an HTML fragment of this template with the specified values applied.
4621 * @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'})
4622 * @return {String} The HTML fragment
4624 applyTemplate : function(values){
4628 return this.compiled(values);
4630 var useF = this.disableFormats !== true;
4631 var fm = Roo.util.Format, tpl = this;
4632 var fn = function(m, name, format, args){
4634 if(format.substr(0, 5) == "this."){
4635 return tpl.call(format.substr(5), values[name], values);
4638 // quoted values are required for strings in compiled templates,
4639 // but for non compiled we need to strip them
4640 // quoted reversed for jsmin
4641 var re = /^\s*['"](.*)["']\s*$/;
4642 args = args.split(',');
4643 for(var i = 0, len = args.length; i < len; i++){
4644 args[i] = args[i].replace(re, "$1");
4646 args = [values[name]].concat(args);
4648 args = [values[name]];
4650 return fm[format].apply(fm, args);
4653 return values[name] !== undefined ? values[name] : "";
4656 return this.html.replace(this.re, fn);
4674 this.loading = true;
4675 this.compiled = false;
4677 var cx = new Roo.data.Connection();
4681 success : function (response) {
4683 _t.html = response.responseText;
4687 failure : function(response) {
4688 Roo.log("Template failed to load from " + _t.url);
4695 * Sets the HTML used as the template and optionally compiles it.
4696 * @param {String} html
4697 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4698 * @return {Roo.Template} this
4700 set : function(html, compile){
4702 this.compiled = null;
4710 * True to disable format functions (defaults to false)
4713 disableFormats : false,
4716 * The regular expression used to match template variables
4720 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4723 * Compiles the template into an internal function, eliminating the RegEx overhead.
4724 * @return {Roo.Template} this
4726 compile : function(){
4727 var fm = Roo.util.Format;
4728 var useF = this.disableFormats !== true;
4729 var sep = Roo.isGecko ? "+" : ",";
4730 var fn = function(m, name, format, args){
4732 args = args ? ',' + args : "";
4733 if(format.substr(0, 5) != "this."){
4734 format = "fm." + format + '(';
4736 format = 'this.call("'+ format.substr(5) + '", ';
4740 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4742 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4745 // branched to use + in gecko and [].join() in others
4747 body = "this.compiled = function(values){ return '" +
4748 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4751 body = ["this.compiled = function(values){ return ['"];
4752 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4753 body.push("'].join('');};");
4754 body = body.join('');
4764 // private function used to call members
4765 call : function(fnName, value, allValues){
4766 return this[fnName](value, allValues);
4770 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4771 * @param {String/HTMLElement/Roo.Element} el The context element
4772 * @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'})
4773 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4774 * @return {HTMLElement/Roo.Element} The new node or Element
4776 insertFirst: function(el, values, returnElement){
4777 return this.doInsert('afterBegin', el, values, returnElement);
4781 * Applies the supplied values to the template and inserts the new node(s) before el.
4782 * @param {String/HTMLElement/Roo.Element} el The context element
4783 * @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'})
4784 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4785 * @return {HTMLElement/Roo.Element} The new node or Element
4787 insertBefore: function(el, values, returnElement){
4788 return this.doInsert('beforeBegin', el, values, returnElement);
4792 * Applies the supplied values to the template and inserts the new node(s) after el.
4793 * @param {String/HTMLElement/Roo.Element} el The context element
4794 * @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'})
4795 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4796 * @return {HTMLElement/Roo.Element} The new node or Element
4798 insertAfter : function(el, values, returnElement){
4799 return this.doInsert('afterEnd', el, values, returnElement);
4803 * Applies the supplied values to the template and appends the new node(s) to el.
4804 * @param {String/HTMLElement/Roo.Element} el The context element
4805 * @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'})
4806 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4807 * @return {HTMLElement/Roo.Element} The new node or Element
4809 append : function(el, values, returnElement){
4810 return this.doInsert('beforeEnd', el, values, returnElement);
4813 doInsert : function(where, el, values, returnEl){
4814 el = Roo.getDom(el);
4815 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4816 return returnEl ? Roo.get(newNode, true) : newNode;
4820 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4821 * @param {String/HTMLElement/Roo.Element} el The context element
4822 * @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'})
4823 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4824 * @return {HTMLElement/Roo.Element} The new node or Element
4826 overwrite : function(el, values, returnElement){
4827 el = Roo.getDom(el);
4828 el.innerHTML = this.applyTemplate(values);
4829 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4833 * Alias for {@link #applyTemplate}
4836 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4839 Roo.DomHelper.Template = Roo.Template;
4842 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4843 * @param {String/HTMLElement} el A DOM element or its id
4844 * @returns {Roo.Template} The created template
4847 Roo.Template.from = function(el){
4848 el = Roo.getDom(el);
4849 return new Roo.Template(el.value || el.innerHTML);
4852 * Ext JS Library 1.1.1
4853 * Copyright(c) 2006-2007, Ext JS, LLC.
4855 * Originally Released Under LGPL - original licence link has changed is not relivant.
4858 * <script type="text/javascript">
4863 * This is code is also distributed under MIT license for use
4864 * with jQuery and prototype JavaScript libraries.
4867 * @class Roo.DomQuery
4868 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).
4870 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>
4873 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.
4875 <h4>Element Selectors:</h4>
4877 <li> <b>*</b> any element</li>
4878 <li> <b>E</b> an element with the tag E</li>
4879 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4880 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4881 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4882 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4884 <h4>Attribute Selectors:</h4>
4885 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4887 <li> <b>E[foo]</b> has an attribute "foo"</li>
4888 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4889 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4890 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4891 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4892 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4893 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4895 <h4>Pseudo Classes:</h4>
4897 <li> <b>E:first-child</b> E is the first child of its parent</li>
4898 <li> <b>E:last-child</b> E is the last child of its parent</li>
4899 <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>
4900 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4901 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4902 <li> <b>E:only-child</b> E is the only child of its parent</li>
4903 <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>
4904 <li> <b>E:first</b> the first E in the resultset</li>
4905 <li> <b>E:last</b> the last E in the resultset</li>
4906 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4907 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4908 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4909 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4910 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4911 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4912 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4913 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4914 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4916 <h4>CSS Value Selectors:</h4>
4918 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4919 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4920 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4921 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4922 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4923 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4927 Roo.DomQuery = function(){
4928 var cache = {}, simpleCache = {}, valueCache = {};
4929 var nonSpace = /\S/;
4930 var trimRe = /^\s+|\s+$/g;
4931 var tplRe = /\{(\d+)\}/g;
4932 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4933 var tagTokenRe = /^(#)?([\w-\*]+)/;
4934 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4936 function child(p, index){
4938 var n = p.firstChild;
4940 if(n.nodeType == 1){
4951 while((n = n.nextSibling) && n.nodeType != 1);
4956 while((n = n.previousSibling) && n.nodeType != 1);
4960 function children(d){
4961 var n = d.firstChild, ni = -1;
4963 var nx = n.nextSibling;
4964 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4974 function byClassName(c, a, v){
4978 var r = [], ri = -1, cn;
4979 for(var i = 0, ci; ci = c[i]; i++){
4980 if((' '+ci.className+' ').indexOf(v) != -1){
4987 function attrValue(n, attr){
4988 if(!n.tagName && typeof n.length != "undefined"){
4997 if(attr == "class" || attr == "className"){
5000 return n.getAttribute(attr) || n[attr];
5004 function getNodes(ns, mode, tagName){
5005 var result = [], ri = -1, cs;
5009 tagName = tagName || "*";
5010 if(typeof ns.getElementsByTagName != "undefined"){
5014 for(var i = 0, ni; ni = ns[i]; i++){
5015 cs = ni.getElementsByTagName(tagName);
5016 for(var j = 0, ci; ci = cs[j]; j++){
5020 }else if(mode == "/" || mode == ">"){
5021 var utag = tagName.toUpperCase();
5022 for(var i = 0, ni, cn; ni = ns[i]; i++){
5023 cn = ni.children || ni.childNodes;
5024 for(var j = 0, cj; cj = cn[j]; j++){
5025 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
5030 }else if(mode == "+"){
5031 var utag = tagName.toUpperCase();
5032 for(var i = 0, n; n = ns[i]; i++){
5033 while((n = n.nextSibling) && n.nodeType != 1);
5034 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
5038 }else if(mode == "~"){
5039 for(var i = 0, n; n = ns[i]; i++){
5040 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
5049 function concat(a, b){
5053 for(var i = 0, l = b.length; i < l; i++){
5059 function byTag(cs, tagName){
5060 if(cs.tagName || cs == document){
5066 var r = [], ri = -1;
5067 tagName = tagName.toLowerCase();
5068 for(var i = 0, ci; ci = cs[i]; i++){
5069 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
5076 function byId(cs, attr, id){
5077 if(cs.tagName || cs == document){
5083 var r = [], ri = -1;
5084 for(var i = 0,ci; ci = cs[i]; i++){
5085 if(ci && ci.id == id){
5093 function byAttribute(cs, attr, value, op, custom){
5094 var r = [], ri = -1, st = custom=="{";
5095 var f = Roo.DomQuery.operators[op];
5096 for(var i = 0, ci; ci = cs[i]; i++){
5099 a = Roo.DomQuery.getStyle(ci, attr);
5101 else if(attr == "class" || attr == "className"){
5103 }else if(attr == "for"){
5105 }else if(attr == "href"){
5106 a = ci.getAttribute("href", 2);
5108 a = ci.getAttribute(attr);
5110 if((f && f(a, value)) || (!f && a)){
5117 function byPseudo(cs, name, value){
5118 return Roo.DomQuery.pseudos[name](cs, value);
5121 // This is for IE MSXML which does not support expandos.
5122 // IE runs the same speed using setAttribute, however FF slows way down
5123 // and Safari completely fails so they need to continue to use expandos.
5124 var isIE = window.ActiveXObject ? true : false;
5126 // this eval is stop the compressor from
5127 // renaming the variable to something shorter
5129 /** eval:var:batch */
5134 function nodupIEXml(cs){
5136 cs[0].setAttribute("_nodup", d);
5138 for(var i = 1, len = cs.length; i < len; i++){
5140 if(!c.getAttribute("_nodup") != d){
5141 c.setAttribute("_nodup", d);
5145 for(var i = 0, len = cs.length; i < len; i++){
5146 cs[i].removeAttribute("_nodup");
5155 var len = cs.length, c, i, r = cs, cj, ri = -1;
5156 if(!len || typeof cs.nodeType != "undefined" || len == 1){
5159 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
5160 return nodupIEXml(cs);
5164 for(i = 1; c = cs[i]; i++){
5169 for(var j = 0; j < i; j++){
5172 for(j = i+1; cj = cs[j]; j++){
5184 function quickDiffIEXml(c1, c2){
5186 for(var i = 0, len = c1.length; i < len; i++){
5187 c1[i].setAttribute("_qdiff", d);
5190 for(var i = 0, len = c2.length; i < len; i++){
5191 if(c2[i].getAttribute("_qdiff") != d){
5192 r[r.length] = c2[i];
5195 for(var i = 0, len = c1.length; i < len; i++){
5196 c1[i].removeAttribute("_qdiff");
5201 function quickDiff(c1, c2){
5202 var len1 = c1.length;
5206 if(isIE && c1[0].selectSingleNode){
5207 return quickDiffIEXml(c1, c2);
5210 for(var i = 0; i < len1; i++){
5214 for(var i = 0, len = c2.length; i < len; i++){
5215 if(c2[i]._qdiff != d){
5216 r[r.length] = c2[i];
5222 function quickId(ns, mode, root, id){
5224 var d = root.ownerDocument || root;
5225 return d.getElementById(id);
5227 ns = getNodes(ns, mode, "*");
5228 return byId(ns, null, id);
5232 getStyle : function(el, name){
5233 return Roo.fly(el).getStyle(name);
5236 * Compiles a selector/xpath query into a reusable function. The returned function
5237 * takes one parameter "root" (optional), which is the context node from where the query should start.
5238 * @param {String} selector The selector/xpath query
5239 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5240 * @return {Function}
5242 compile : function(path, type){
5243 type = type || "select";
5245 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5246 var q = path, mode, lq;
5247 var tk = Roo.DomQuery.matchers;
5248 var tklen = tk.length;
5251 // accept leading mode switch
5252 var lmode = q.match(modeRe);
5253 if(lmode && lmode[1]){
5254 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5255 q = q.replace(lmode[1], "");
5257 // strip leading slashes
5258 while(path.substr(0, 1)=="/"){
5259 path = path.substr(1);
5262 while(q && lq != q){
5264 var tm = q.match(tagTokenRe);
5265 if(type == "select"){
5268 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5270 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5272 q = q.replace(tm[0], "");
5273 }else if(q.substr(0, 1) != '@'){
5274 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5279 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5281 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5283 q = q.replace(tm[0], "");
5286 while(!(mm = q.match(modeRe))){
5287 var matched = false;
5288 for(var j = 0; j < tklen; j++){
5290 var m = q.match(t.re);
5292 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5295 q = q.replace(m[0], "");
5300 // prevent infinite loop on bad selector
5302 throw 'Error parsing selector, parsing failed at "' + q + '"';
5306 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5307 q = q.replace(mm[1], "");
5310 fn[fn.length] = "return nodup(n);\n}";
5313 * list of variables that need from compression as they are used by eval.
5323 * eval:var:byClassName
5325 * eval:var:byAttribute
5326 * eval:var:attrValue
5334 * Selects a group of elements.
5335 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5336 * @param {Node} root (optional) The start of the query (defaults to document).
5339 select : function(path, root, type){
5340 if(!root || root == document){
5343 if(typeof root == "string"){
5344 root = document.getElementById(root);
5346 var paths = path.split(",");
5348 for(var i = 0, len = paths.length; i < len; i++){
5349 var p = paths[i].replace(trimRe, "");
5351 cache[p] = Roo.DomQuery.compile(p);
5353 throw p + " is not a valid selector";
5356 var result = cache[p](root);
5357 if(result && result != document){
5358 results = results.concat(result);
5361 if(paths.length > 1){
5362 return nodup(results);
5368 * Selects a single element.
5369 * @param {String} selector The selector/xpath query
5370 * @param {Node} root (optional) The start of the query (defaults to document).
5373 selectNode : function(path, root){
5374 return Roo.DomQuery.select(path, root)[0];
5378 * Selects the value of a node, optionally replacing null with the defaultValue.
5379 * @param {String} selector The selector/xpath query
5380 * @param {Node} root (optional) The start of the query (defaults to document).
5381 * @param {String} defaultValue
5383 selectValue : function(path, root, defaultValue){
5384 path = path.replace(trimRe, "");
5385 if(!valueCache[path]){
5386 valueCache[path] = Roo.DomQuery.compile(path, "select");
5388 var n = valueCache[path](root);
5389 n = n[0] ? n[0] : n;
5390 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5391 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5395 * Selects the value of a node, parsing integers and floats.
5396 * @param {String} selector The selector/xpath query
5397 * @param {Node} root (optional) The start of the query (defaults to document).
5398 * @param {Number} defaultValue
5401 selectNumber : function(path, root, defaultValue){
5402 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5403 return parseFloat(v);
5407 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5408 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5409 * @param {String} selector The simple selector to test
5412 is : function(el, ss){
5413 if(typeof el == "string"){
5414 el = document.getElementById(el);
5416 var isArray = (el instanceof Array);
5417 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5418 return isArray ? (result.length == el.length) : (result.length > 0);
5422 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5423 * @param {Array} el An array of elements to filter
5424 * @param {String} selector The simple selector to test
5425 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5426 * the selector instead of the ones that match
5429 filter : function(els, ss, nonMatches){
5430 ss = ss.replace(trimRe, "");
5431 if(!simpleCache[ss]){
5432 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5434 var result = simpleCache[ss](els);
5435 return nonMatches ? quickDiff(result, els) : result;
5439 * Collection of matching regular expressions and code snippets.
5443 select: 'n = byClassName(n, null, " {1} ");'
5445 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5446 select: 'n = byPseudo(n, "{1}", "{2}");'
5448 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5449 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5452 select: 'n = byId(n, null, "{1}");'
5455 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5460 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5461 * 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, > <.
5464 "=" : function(a, v){
5467 "!=" : function(a, v){
5470 "^=" : function(a, v){
5471 return a && a.substr(0, v.length) == v;
5473 "$=" : function(a, v){
5474 return a && a.substr(a.length-v.length) == v;
5476 "*=" : function(a, v){
5477 return a && a.indexOf(v) !== -1;
5479 "%=" : function(a, v){
5480 return (a % v) == 0;
5482 "|=" : function(a, v){
5483 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5485 "~=" : function(a, v){
5486 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5491 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5492 * and the argument (if any) supplied in the selector.
5495 "first-child" : function(c){
5496 var r = [], ri = -1, n;
5497 for(var i = 0, ci; ci = n = c[i]; i++){
5498 while((n = n.previousSibling) && n.nodeType != 1);
5506 "last-child" : function(c){
5507 var r = [], ri = -1, n;
5508 for(var i = 0, ci; ci = n = c[i]; i++){
5509 while((n = n.nextSibling) && n.nodeType != 1);
5517 "nth-child" : function(c, a) {
5518 var r = [], ri = -1;
5519 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5520 var f = (m[1] || 1) - 0, l = m[2] - 0;
5521 for(var i = 0, n; n = c[i]; i++){
5522 var pn = n.parentNode;
5523 if (batch != pn._batch) {
5525 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5526 if(cn.nodeType == 1){
5533 if (l == 0 || n.nodeIndex == l){
5536 } else if ((n.nodeIndex + l) % f == 0){
5544 "only-child" : function(c){
5545 var r = [], ri = -1;;
5546 for(var i = 0, ci; ci = c[i]; i++){
5547 if(!prev(ci) && !next(ci)){
5554 "empty" : function(c){
5555 var r = [], ri = -1;
5556 for(var i = 0, ci; ci = c[i]; i++){
5557 var cns = ci.childNodes, j = 0, cn, empty = true;
5560 if(cn.nodeType == 1 || cn.nodeType == 3){
5572 "contains" : function(c, v){
5573 var r = [], ri = -1;
5574 for(var i = 0, ci; ci = c[i]; i++){
5575 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5582 "nodeValue" : function(c, v){
5583 var r = [], ri = -1;
5584 for(var i = 0, ci; ci = c[i]; i++){
5585 if(ci.firstChild && ci.firstChild.nodeValue == v){
5592 "checked" : function(c){
5593 var r = [], ri = -1;
5594 for(var i = 0, ci; ci = c[i]; i++){
5595 if(ci.checked == true){
5602 "not" : function(c, ss){
5603 return Roo.DomQuery.filter(c, ss, true);
5606 "odd" : function(c){
5607 return this["nth-child"](c, "odd");
5610 "even" : function(c){
5611 return this["nth-child"](c, "even");
5614 "nth" : function(c, a){
5615 return c[a-1] || [];
5618 "first" : function(c){
5622 "last" : function(c){
5623 return c[c.length-1] || [];
5626 "has" : function(c, ss){
5627 var s = Roo.DomQuery.select;
5628 var r = [], ri = -1;
5629 for(var i = 0, ci; ci = c[i]; i++){
5630 if(s(ss, ci).length > 0){
5637 "next" : function(c, ss){
5638 var is = Roo.DomQuery.is;
5639 var r = [], ri = -1;
5640 for(var i = 0, ci; ci = c[i]; i++){
5649 "prev" : function(c, ss){
5650 var is = Roo.DomQuery.is;
5651 var r = [], ri = -1;
5652 for(var i = 0, ci; ci = c[i]; i++){
5665 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5666 * @param {String} path The selector/xpath query
5667 * @param {Node} root (optional) The start of the query (defaults to document).
5672 Roo.query = Roo.DomQuery.select;
5675 * Ext JS Library 1.1.1
5676 * Copyright(c) 2006-2007, Ext JS, LLC.
5678 * Originally Released Under LGPL - original licence link has changed is not relivant.
5681 * <script type="text/javascript">
5685 * @class Roo.util.Observable
5686 * Base class that provides a common interface for publishing events. Subclasses are expected to
5687 * to have a property "events" with all the events defined.<br>
5690 Employee = function(name){
5697 Roo.extend(Employee, Roo.util.Observable);
5699 * @param {Object} config properties to use (incuding events / listeners)
5702 Roo.util.Observable = function(cfg){
5705 this.addEvents(cfg.events || {});
5707 delete cfg.events; // make sure
5710 Roo.apply(this, cfg);
5713 this.on(this.listeners);
5714 delete this.listeners;
5717 Roo.util.Observable.prototype = {
5719 * @cfg {Object} listeners list of events and functions to call for this object,
5723 'click' : function(e) {
5733 * Fires the specified event with the passed parameters (minus the event name).
5734 * @param {String} eventName
5735 * @param {Object...} args Variable number of parameters are passed to handlers
5736 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5738 fireEvent : function(){
5739 var ce = this.events[arguments[0].toLowerCase()];
5740 if(typeof ce == "object"){
5741 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5748 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5751 * Appends an event handler to this component
5752 * @param {String} eventName The type of event to listen for
5753 * @param {Function} handler The method the event invokes
5754 * @param {Object} scope (optional) The scope in which to execute the handler
5755 * function. The handler function's "this" context.
5756 * @param {Object} options (optional) An object containing handler configuration
5757 * properties. This may contain any of the following properties:<ul>
5758 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5759 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5760 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5761 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5762 * by the specified number of milliseconds. If the event fires again within that time, the original
5763 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5766 * <b>Combining Options</b><br>
5767 * Using the options argument, it is possible to combine different types of listeners:<br>
5769 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5771 el.on('click', this.onClick, this, {
5778 * <b>Attaching multiple handlers in 1 call</b><br>
5779 * The method also allows for a single argument to be passed which is a config object containing properties
5780 * which specify multiple handlers.
5789 fn: this.onMouseOver,
5793 fn: this.onMouseOut,
5799 * Or a shorthand syntax which passes the same scope object to all handlers:
5802 'click': this.onClick,
5803 'mouseover': this.onMouseOver,
5804 'mouseout': this.onMouseOut,
5809 addListener : function(eventName, fn, scope, o){
5810 if(typeof eventName == "object"){
5813 if(this.filterOptRe.test(e)){
5816 if(typeof o[e] == "function"){
5818 this.addListener(e, o[e], o.scope, o);
5820 // individual options
5821 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5826 o = (!o || typeof o == "boolean") ? {} : o;
5827 eventName = eventName.toLowerCase();
5828 var ce = this.events[eventName] || true;
5829 if(typeof ce == "boolean"){
5830 ce = new Roo.util.Event(this, eventName);
5831 this.events[eventName] = ce;
5833 ce.addListener(fn, scope, o);
5837 * Removes a listener
5838 * @param {String} eventName The type of event to listen for
5839 * @param {Function} handler The handler to remove
5840 * @param {Object} scope (optional) The scope (this object) for the handler
5842 removeListener : function(eventName, fn, scope){
5843 var ce = this.events[eventName.toLowerCase()];
5844 if(typeof ce == "object"){
5845 ce.removeListener(fn, scope);
5850 * Removes all listeners for this object
5852 purgeListeners : function(){
5853 for(var evt in this.events){
5854 if(typeof this.events[evt] == "object"){
5855 this.events[evt].clearListeners();
5860 relayEvents : function(o, events){
5861 var createHandler = function(ename){
5863 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5866 for(var i = 0, len = events.length; i < len; i++){
5867 var ename = events[i];
5868 if(!this.events[ename]){ this.events[ename] = true; };
5869 o.on(ename, createHandler(ename), this);
5874 * Used to define events on this Observable
5875 * @param {Object} object The object with the events defined
5877 addEvents : function(o){
5881 Roo.applyIf(this.events, o);
5885 * Checks to see if this object has any listeners for a specified event
5886 * @param {String} eventName The name of the event to check for
5887 * @return {Boolean} True if the event is being listened for, else false
5889 hasListener : function(eventName){
5890 var e = this.events[eventName];
5891 return typeof e == "object" && e.listeners.length > 0;
5895 * Appends an event handler to this element (shorthand for addListener)
5896 * @param {String} eventName The type of event to listen for
5897 * @param {Function} handler The method the event invokes
5898 * @param {Object} scope (optional) The scope in which to execute the handler
5899 * function. The handler function's "this" context.
5900 * @param {Object} options (optional)
5903 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5905 * Removes a listener (shorthand for removeListener)
5906 * @param {String} eventName The type of event to listen for
5907 * @param {Function} handler The handler to remove
5908 * @param {Object} scope (optional) The scope (this object) for the handler
5911 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5914 * Starts capture on the specified Observable. All events will be passed
5915 * to the supplied function with the event name + standard signature of the event
5916 * <b>before</b> the event is fired. If the supplied function returns false,
5917 * the event will not fire.
5918 * @param {Observable} o The Observable to capture
5919 * @param {Function} fn The function to call
5920 * @param {Object} scope (optional) The scope (this object) for the fn
5923 Roo.util.Observable.capture = function(o, fn, scope){
5924 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5928 * Removes <b>all</b> added captures from the Observable.
5929 * @param {Observable} o The Observable to release
5932 Roo.util.Observable.releaseCapture = function(o){
5933 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5938 var createBuffered = function(h, o, scope){
5939 var task = new Roo.util.DelayedTask();
5941 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5945 var createSingle = function(h, e, fn, scope){
5947 e.removeListener(fn, scope);
5948 return h.apply(scope, arguments);
5952 var createDelayed = function(h, o, scope){
5954 var args = Array.prototype.slice.call(arguments, 0);
5955 setTimeout(function(){
5956 h.apply(scope, args);
5961 Roo.util.Event = function(obj, name){
5964 this.listeners = [];
5967 Roo.util.Event.prototype = {
5968 addListener : function(fn, scope, options){
5969 var o = options || {};
5970 scope = scope || this.obj;
5971 if(!this.isListening(fn, scope)){
5972 var l = {fn: fn, scope: scope, options: o};
5975 h = createDelayed(h, o, scope);
5978 h = createSingle(h, this, fn, scope);
5981 h = createBuffered(h, o, scope);
5984 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
5985 this.listeners.push(l);
5987 this.listeners = this.listeners.slice(0);
5988 this.listeners.push(l);
5993 findListener : function(fn, scope){
5994 scope = scope || this.obj;
5995 var ls = this.listeners;
5996 for(var i = 0, len = ls.length; i < len; i++){
5998 if(l.fn == fn && l.scope == scope){
6005 isListening : function(fn, scope){
6006 return this.findListener(fn, scope) != -1;
6009 removeListener : function(fn, scope){
6011 if((index = this.findListener(fn, scope)) != -1){
6013 this.listeners.splice(index, 1);
6015 this.listeners = this.listeners.slice(0);
6016 this.listeners.splice(index, 1);
6023 clearListeners : function(){
6024 this.listeners = [];
6028 var ls = this.listeners, scope, len = ls.length;
6031 var args = Array.prototype.slice.call(arguments, 0);
6032 for(var i = 0; i < len; i++){
6034 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
6035 this.firing = false;
6039 this.firing = false;
6046 * Ext JS Library 1.1.1
6047 * Copyright(c) 2006-2007, Ext JS, LLC.
6049 * Originally Released Under LGPL - original licence link has changed is not relivant.
6052 * <script type="text/javascript">
6056 * @class Roo.EventManager
6057 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
6058 * several useful events directly.
6059 * See {@link Roo.EventObject} for more details on normalized event objects.
6062 Roo.EventManager = function(){
6063 var docReadyEvent, docReadyProcId, docReadyState = false;
6064 var resizeEvent, resizeTask, textEvent, textSize;
6065 var E = Roo.lib.Event;
6066 var D = Roo.lib.Dom;
6071 var fireDocReady = function(){
6073 docReadyState = true;
6076 clearInterval(docReadyProcId);
6078 if(Roo.isGecko || Roo.isOpera) {
6079 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
6082 var defer = document.getElementById("ie-deferred-loader");
6084 defer.onreadystatechange = null;
6085 defer.parentNode.removeChild(defer);
6089 docReadyEvent.fire();
6090 docReadyEvent.clearListeners();
6095 var initDocReady = function(){
6096 docReadyEvent = new Roo.util.Event();
6097 if(Roo.isGecko || Roo.isOpera) {
6098 document.addEventListener("DOMContentLoaded", fireDocReady, false);
6100 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
6101 var defer = document.getElementById("ie-deferred-loader");
6102 defer.onreadystatechange = function(){
6103 if(this.readyState == "complete"){
6107 }else if(Roo.isSafari){
6108 docReadyProcId = setInterval(function(){
6109 var rs = document.readyState;
6110 if(rs == "complete") {
6115 // no matter what, make sure it fires on load
6116 E.on(window, "load", fireDocReady);
6119 var createBuffered = function(h, o){
6120 var task = new Roo.util.DelayedTask(h);
6122 // create new event object impl so new events don't wipe out properties
6123 e = new Roo.EventObjectImpl(e);
6124 task.delay(o.buffer, h, null, [e]);
6128 var createSingle = function(h, el, ename, fn){
6130 Roo.EventManager.removeListener(el, ename, fn);
6135 var createDelayed = function(h, o){
6137 // create new event object impl so new events don't wipe out properties
6138 e = new Roo.EventObjectImpl(e);
6139 setTimeout(function(){
6144 var transitionEndVal = false;
6146 var transitionEnd = function()
6148 if (transitionEndVal) {
6149 return transitionEndVal;
6151 var el = document.createElement('div');
6153 var transEndEventNames = {
6154 WebkitTransition : 'webkitTransitionEnd',
6155 MozTransition : 'transitionend',
6156 OTransition : 'oTransitionEnd otransitionend',
6157 transition : 'transitionend'
6160 for (var name in transEndEventNames) {
6161 if (el.style[name] !== undefined) {
6162 transitionEndVal = transEndEventNames[name];
6163 return transitionEndVal ;
6169 var listen = function(element, ename, opt, fn, scope){
6170 var o = (!opt || typeof opt == "boolean") ? {} : opt;
6171 fn = fn || o.fn; scope = scope || o.scope;
6172 var el = Roo.getDom(element);
6176 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
6179 if (ename == 'transitionend') {
6180 ename = transitionEnd();
6182 var h = function(e){
6183 e = Roo.EventObject.setEvent(e);
6186 t = e.getTarget(o.delegate, el);
6193 if(o.stopEvent === true){
6196 if(o.preventDefault === true){
6199 if(o.stopPropagation === true){
6200 e.stopPropagation();
6203 if(o.normalized === false){
6207 fn.call(scope || el, e, t, o);
6210 h = createDelayed(h, o);
6213 h = createSingle(h, el, ename, fn);
6216 h = createBuffered(h, o);
6218 fn._handlers = fn._handlers || [];
6221 fn._handlers.push([Roo.id(el), ename, h]);
6226 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
6227 el.addEventListener("DOMMouseScroll", h, false);
6228 E.on(window, 'unload', function(){
6229 el.removeEventListener("DOMMouseScroll", h, false);
6232 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6233 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
6238 var stopListening = function(el, ename, fn){
6239 var id = Roo.id(el), hds = fn._handlers, hd = fn;
6241 for(var i = 0, len = hds.length; i < len; i++){
6243 if(h[0] == id && h[1] == ename){
6250 E.un(el, ename, hd);
6251 el = Roo.getDom(el);
6252 if(ename == "mousewheel" && el.addEventListener){
6253 el.removeEventListener("DOMMouseScroll", hd, false);
6255 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6256 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6260 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6267 * @scope Roo.EventManager
6272 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6273 * object with a Roo.EventObject
6274 * @param {Function} fn The method the event invokes
6275 * @param {Object} scope An object that becomes the scope of the handler
6276 * @param {boolean} override If true, the obj passed in becomes
6277 * the execution scope of the listener
6278 * @return {Function} The wrapped function
6281 wrap : function(fn, scope, override){
6283 Roo.EventObject.setEvent(e);
6284 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6289 * Appends an event handler to an element (shorthand for addListener)
6290 * @param {String/HTMLElement} element The html element or id to assign the
6291 * @param {String} eventName The type of event to listen for
6292 * @param {Function} handler The method the event invokes
6293 * @param {Object} scope (optional) The scope in which to execute the handler
6294 * function. The handler function's "this" context.
6295 * @param {Object} options (optional) An object containing handler configuration
6296 * properties. This may contain any of the following properties:<ul>
6297 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6298 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6299 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6300 * <li>preventDefault {Boolean} True to prevent the default action</li>
6301 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6302 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6303 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6304 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6305 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6306 * by the specified number of milliseconds. If the event fires again within that time, the original
6307 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6310 * <b>Combining Options</b><br>
6311 * Using the options argument, it is possible to combine different types of listeners:<br>
6313 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6315 el.on('click', this.onClick, this, {
6322 * <b>Attaching multiple handlers in 1 call</b><br>
6323 * The method also allows for a single argument to be passed which is a config object containing properties
6324 * which specify multiple handlers.
6334 fn: this.onMouseOver
6343 * Or a shorthand syntax:<br>
6346 'click' : this.onClick,
6347 'mouseover' : this.onMouseOver,
6348 'mouseout' : this.onMouseOut
6352 addListener : function(element, eventName, fn, scope, options){
6353 if(typeof eventName == "object"){
6359 if(typeof o[e] == "function"){
6361 listen(element, e, o, o[e], o.scope);
6363 // individual options
6364 listen(element, e, o[e]);
6369 return listen(element, eventName, options, fn, scope);
6373 * Removes an event handler
6375 * @param {String/HTMLElement} element The id or html element to remove the
6377 * @param {String} eventName The type of event
6378 * @param {Function} fn
6379 * @return {Boolean} True if a listener was actually removed
6381 removeListener : function(element, eventName, fn){
6382 return stopListening(element, eventName, fn);
6386 * Fires when the document is ready (before onload and before images are loaded). Can be
6387 * accessed shorthanded Roo.onReady().
6388 * @param {Function} fn The method the event invokes
6389 * @param {Object} scope An object that becomes the scope of the handler
6390 * @param {boolean} options
6392 onDocumentReady : function(fn, scope, options){
6393 if(docReadyState){ // if it already fired
6394 docReadyEvent.addListener(fn, scope, options);
6395 docReadyEvent.fire();
6396 docReadyEvent.clearListeners();
6402 docReadyEvent.addListener(fn, scope, options);
6406 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6407 * @param {Function} fn The method the event invokes
6408 * @param {Object} scope An object that becomes the scope of the handler
6409 * @param {boolean} options
6411 onWindowResize : function(fn, scope, options){
6413 resizeEvent = new Roo.util.Event();
6414 resizeTask = new Roo.util.DelayedTask(function(){
6415 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6417 E.on(window, "resize", function(){
6419 resizeTask.delay(50);
6421 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6425 resizeEvent.addListener(fn, scope, options);
6429 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6430 * @param {Function} fn The method the event invokes
6431 * @param {Object} scope An object that becomes the scope of the handler
6432 * @param {boolean} options
6434 onTextResize : function(fn, scope, options){
6436 textEvent = new Roo.util.Event();
6437 var textEl = new Roo.Element(document.createElement('div'));
6438 textEl.dom.className = 'x-text-resize';
6439 textEl.dom.innerHTML = 'X';
6440 textEl.appendTo(document.body);
6441 textSize = textEl.dom.offsetHeight;
6442 setInterval(function(){
6443 if(textEl.dom.offsetHeight != textSize){
6444 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6446 }, this.textResizeInterval);
6448 textEvent.addListener(fn, scope, options);
6452 * Removes the passed window resize listener.
6453 * @param {Function} fn The method the event invokes
6454 * @param {Object} scope The scope of handler
6456 removeResizeListener : function(fn, scope){
6458 resizeEvent.removeListener(fn, scope);
6463 fireResize : function(){
6465 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6469 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6473 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6475 textResizeInterval : 50
6480 * @scopeAlias pub=Roo.EventManager
6484 * Appends an event handler to an element (shorthand for addListener)
6485 * @param {String/HTMLElement} element The html element or id to assign the
6486 * @param {String} eventName The type of event to listen for
6487 * @param {Function} handler The method the event invokes
6488 * @param {Object} scope (optional) The scope in which to execute the handler
6489 * function. The handler function's "this" context.
6490 * @param {Object} options (optional) An object containing handler configuration
6491 * properties. This may contain any of the following properties:<ul>
6492 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6493 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6494 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6495 * <li>preventDefault {Boolean} True to prevent the default action</li>
6496 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6497 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6498 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6499 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6500 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6501 * by the specified number of milliseconds. If the event fires again within that time, the original
6502 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6505 * <b>Combining Options</b><br>
6506 * Using the options argument, it is possible to combine different types of listeners:<br>
6508 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6510 el.on('click', this.onClick, this, {
6517 * <b>Attaching multiple handlers in 1 call</b><br>
6518 * The method also allows for a single argument to be passed which is a config object containing properties
6519 * which specify multiple handlers.
6529 fn: this.onMouseOver
6538 * Or a shorthand syntax:<br>
6541 'click' : this.onClick,
6542 'mouseover' : this.onMouseOver,
6543 'mouseout' : this.onMouseOut
6547 pub.on = pub.addListener;
6548 pub.un = pub.removeListener;
6550 pub.stoppedMouseDownEvent = new Roo.util.Event();
6554 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6555 * @param {Function} fn The method the event invokes
6556 * @param {Object} scope An object that becomes the scope of the handler
6557 * @param {boolean} override If true, the obj passed in becomes
6558 * the execution scope of the listener
6562 Roo.onReady = Roo.EventManager.onDocumentReady;
6564 Roo.onReady(function(){
6565 var bd = Roo.get(document.body);
6570 : Roo.isGecko ? "roo-gecko"
6571 : Roo.isOpera ? "roo-opera"
6572 : Roo.isSafari ? "roo-safari" : ""];
6575 cls.push("roo-mac");
6578 cls.push("roo-linux");
6581 cls.push("roo-ios");
6583 if(Roo.isBorderBox){
6584 cls.push('roo-border-box');
6586 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6587 var p = bd.dom.parentNode;
6589 p.className += ' roo-strict';
6592 bd.addClass(cls.join(' '));
6596 * @class Roo.EventObject
6597 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6598 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6601 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6603 var target = e.getTarget();
6606 var myDiv = Roo.get("myDiv");
6607 myDiv.on("click", handleClick);
6609 Roo.EventManager.on("myDiv", 'click', handleClick);
6610 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6614 Roo.EventObject = function(){
6616 var E = Roo.lib.Event;
6618 // safari keypress events for special keys return bad keycodes
6621 63235 : 39, // right
6624 63276 : 33, // page up
6625 63277 : 34, // page down
6626 63272 : 46, // delete
6631 // normalize button clicks
6632 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6633 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6635 Roo.EventObjectImpl = function(e){
6637 this.setEvent(e.browserEvent || e);
6640 Roo.EventObjectImpl.prototype = {
6642 * Used to fix doc tools.
6643 * @scope Roo.EventObject.prototype
6649 /** The normal browser event */
6650 browserEvent : null,
6651 /** The button pressed in a mouse event */
6653 /** True if the shift key was down during the event */
6655 /** True if the control key was down during the event */
6657 /** True if the alt key was down during the event */
6716 setEvent : function(e){
6717 if(e == this || (e && e.browserEvent)){ // already wrapped
6720 this.browserEvent = e;
6722 // normalize buttons
6723 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6724 if(e.type == 'click' && this.button == -1){
6728 this.shiftKey = e.shiftKey;
6729 // mac metaKey behaves like ctrlKey
6730 this.ctrlKey = e.ctrlKey || e.metaKey;
6731 this.altKey = e.altKey;
6732 // in getKey these will be normalized for the mac
6733 this.keyCode = e.keyCode;
6734 // keyup warnings on firefox.
6735 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6736 // cache the target for the delayed and or buffered events
6737 this.target = E.getTarget(e);
6739 this.xy = E.getXY(e);
6742 this.shiftKey = false;
6743 this.ctrlKey = false;
6744 this.altKey = false;
6754 * Stop the event (preventDefault and stopPropagation)
6756 stopEvent : function(){
6757 if(this.browserEvent){
6758 if(this.browserEvent.type == 'mousedown'){
6759 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6761 E.stopEvent(this.browserEvent);
6766 * Prevents the browsers default handling of the event.
6768 preventDefault : function(){
6769 if(this.browserEvent){
6770 E.preventDefault(this.browserEvent);
6775 isNavKeyPress : function(){
6776 var k = this.keyCode;
6777 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6778 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6781 isSpecialKey : function(){
6782 var k = this.keyCode;
6783 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6784 (k == 16) || (k == 17) ||
6785 (k >= 18 && k <= 20) ||
6786 (k >= 33 && k <= 35) ||
6787 (k >= 36 && k <= 39) ||
6788 (k >= 44 && k <= 45);
6791 * Cancels bubbling of the event.
6793 stopPropagation : function(){
6794 if(this.browserEvent){
6795 if(this.type == 'mousedown'){
6796 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6798 E.stopPropagation(this.browserEvent);
6803 * Gets the key code for the event.
6806 getCharCode : function(){
6807 return this.charCode || this.keyCode;
6811 * Returns a normalized keyCode for the event.
6812 * @return {Number} The key code
6814 getKey : function(){
6815 var k = this.keyCode || this.charCode;
6816 return Roo.isSafari ? (safariKeys[k] || k) : k;
6820 * Gets the x coordinate of the event.
6823 getPageX : function(){
6828 * Gets the y coordinate of the event.
6831 getPageY : function(){
6836 * Gets the time of the event.
6839 getTime : function(){
6840 if(this.browserEvent){
6841 return E.getTime(this.browserEvent);
6847 * Gets the page coordinates of the event.
6848 * @return {Array} The xy values like [x, y]
6855 * Gets the target for the event.
6856 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6857 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6858 search as a number or element (defaults to 10 || document.body)
6859 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6860 * @return {HTMLelement}
6862 getTarget : function(selector, maxDepth, returnEl){
6863 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6866 * Gets the related target.
6867 * @return {HTMLElement}
6869 getRelatedTarget : function(){
6870 if(this.browserEvent){
6871 return E.getRelatedTarget(this.browserEvent);
6877 * Normalizes mouse wheel delta across browsers
6878 * @return {Number} The delta
6880 getWheelDelta : function(){
6881 var e = this.browserEvent;
6883 if(e.wheelDelta){ /* IE/Opera. */
6884 delta = e.wheelDelta/120;
6885 }else if(e.detail){ /* Mozilla case. */
6886 delta = -e.detail/3;
6892 * Returns true if the control, meta, shift or alt key was pressed during this event.
6895 hasModifier : function(){
6896 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6900 * Returns true if the target of this event equals el or is a child of el
6901 * @param {String/HTMLElement/Element} el
6902 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6905 within : function(el, related){
6906 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6907 return t && Roo.fly(el).contains(t);
6910 getPoint : function(){
6911 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6915 return new Roo.EventObjectImpl();
6920 * Ext JS Library 1.1.1
6921 * Copyright(c) 2006-2007, Ext JS, LLC.
6923 * Originally Released Under LGPL - original licence link has changed is not relivant.
6926 * <script type="text/javascript">
6930 // was in Composite Element!??!?!
6933 var D = Roo.lib.Dom;
6934 var E = Roo.lib.Event;
6935 var A = Roo.lib.Anim;
6937 // local style camelizing for speed
6939 var camelRe = /(-[a-z])/gi;
6940 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
6941 var view = document.defaultView;
6944 * @class Roo.Element
6945 * Represents an Element in the DOM.<br><br>
6948 var el = Roo.get("my-div");
6951 var el = getEl("my-div");
6953 // or with a DOM element
6954 var el = Roo.get(myDivElement);
6956 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
6957 * each call instead of constructing a new one.<br><br>
6958 * <b>Animations</b><br />
6959 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
6960 * should either be a boolean (true) or an object literal with animation options. The animation options are:
6962 Option Default Description
6963 --------- -------- ---------------------------------------------
6964 duration .35 The duration of the animation in seconds
6965 easing easeOut The YUI easing method
6966 callback none A function to execute when the anim completes
6967 scope this The scope (this) of the callback function
6969 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
6970 * manipulate the animation. Here's an example:
6972 var el = Roo.get("my-div");
6977 // default animation
6978 el.setWidth(100, true);
6980 // animation with some options set
6987 // using the "anim" property to get the Anim object
6993 el.setWidth(100, opt);
6995 if(opt.anim.isAnimated()){
6999 * <b> Composite (Collections of) Elements</b><br />
7000 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
7001 * @constructor Create a new Element directly.
7002 * @param {String/HTMLElement} element
7003 * @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).
7005 Roo.Element = function(element, forceNew){
7006 var dom = typeof element == "string" ?
7007 document.getElementById(element) : element;
7008 if(!dom){ // invalid id/element
7012 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
7013 return Roo.Element.cache[id];
7023 * The DOM element ID
7026 this.id = id || Roo.id(dom);
7029 var El = Roo.Element;
7033 * The element's default display mode (defaults to "")
7036 originalDisplay : "",
7040 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
7045 * Sets the element's visibility mode. When setVisible() is called it
7046 * will use this to determine whether to set the visibility or the display property.
7047 * @param visMode Element.VISIBILITY or Element.DISPLAY
7048 * @return {Roo.Element} this
7050 setVisibilityMode : function(visMode){
7051 this.visibilityMode = visMode;
7055 * Convenience method for setVisibilityMode(Element.DISPLAY)
7056 * @param {String} display (optional) What to set display to when visible
7057 * @return {Roo.Element} this
7059 enableDisplayMode : function(display){
7060 this.setVisibilityMode(El.DISPLAY);
7061 if(typeof display != "undefined") this.originalDisplay = display;
7066 * 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)
7067 * @param {String} selector The simple selector to test
7068 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7069 search as a number or element (defaults to 10 || document.body)
7070 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7071 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7073 findParent : function(simpleSelector, maxDepth, returnEl){
7074 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
7075 maxDepth = maxDepth || 50;
7076 if(typeof maxDepth != "number"){
7077 stopEl = Roo.getDom(maxDepth);
7080 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
7081 if(dq.is(p, simpleSelector)){
7082 return returnEl ? Roo.get(p) : p;
7092 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
7093 * @param {String} selector The simple selector to test
7094 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7095 search as a number or element (defaults to 10 || document.body)
7096 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7097 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7099 findParentNode : function(simpleSelector, maxDepth, returnEl){
7100 var p = Roo.fly(this.dom.parentNode, '_internal');
7101 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
7105 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
7106 * This is a shortcut for findParentNode() that always returns an Roo.Element.
7107 * @param {String} selector The simple selector to test
7108 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7109 search as a number or element (defaults to 10 || document.body)
7110 * @return {Roo.Element} The matching DOM node (or null if no match was found)
7112 up : function(simpleSelector, maxDepth){
7113 return this.findParentNode(simpleSelector, maxDepth, true);
7119 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
7120 * @param {String} selector The simple selector to test
7121 * @return {Boolean} True if this element matches the selector, else false
7123 is : function(simpleSelector){
7124 return Roo.DomQuery.is(this.dom, simpleSelector);
7128 * Perform animation on this element.
7129 * @param {Object} args The YUI animation control args
7130 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
7131 * @param {Function} onComplete (optional) Function to call when animation completes
7132 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
7133 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
7134 * @return {Roo.Element} this
7136 animate : function(args, duration, onComplete, easing, animType){
7137 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
7142 * @private Internal animation call
7144 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
7145 animType = animType || 'run';
7147 var anim = Roo.lib.Anim[animType](
7149 (opt.duration || defaultDur) || .35,
7150 (opt.easing || defaultEase) || 'easeOut',
7152 Roo.callback(cb, this);
7153 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
7161 // private legacy anim prep
7162 preanim : function(a, i){
7163 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
7167 * Removes worthless text nodes
7168 * @param {Boolean} forceReclean (optional) By default the element
7169 * keeps track if it has been cleaned already so
7170 * you can call this over and over. However, if you update the element and
7171 * need to force a reclean, you can pass true.
7173 clean : function(forceReclean){
7174 if(this.isCleaned && forceReclean !== true){
7178 var d = this.dom, n = d.firstChild, ni = -1;
7180 var nx = n.nextSibling;
7181 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
7188 this.isCleaned = true;
7193 calcOffsetsTo : function(el){
7196 var restorePos = false;
7197 if(el.getStyle('position') == 'static'){
7198 el.position('relative');
7203 while(op && op != d && op.tagName != 'HTML'){
7206 op = op.offsetParent;
7209 el.position('static');
7215 * Scrolls this element into view within the passed container.
7216 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
7217 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
7218 * @return {Roo.Element} this
7220 scrollIntoView : function(container, hscroll){
7221 var c = Roo.getDom(container) || document.body;
7224 var o = this.calcOffsetsTo(c),
7227 b = t+el.offsetHeight,
7228 r = l+el.offsetWidth;
7230 var ch = c.clientHeight;
7231 var ct = parseInt(c.scrollTop, 10);
7232 var cl = parseInt(c.scrollLeft, 10);
7234 var cr = cl + c.clientWidth;
7242 if(hscroll !== false){
7246 c.scrollLeft = r-c.clientWidth;
7253 scrollChildIntoView : function(child, hscroll){
7254 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7258 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7259 * the new height may not be available immediately.
7260 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7261 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7262 * @param {Function} onComplete (optional) Function to call when animation completes
7263 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7264 * @return {Roo.Element} this
7266 autoHeight : function(animate, duration, onComplete, easing){
7267 var oldHeight = this.getHeight();
7269 this.setHeight(1); // force clipping
7270 setTimeout(function(){
7271 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7273 this.setHeight(height);
7275 if(typeof onComplete == "function"){
7279 this.setHeight(oldHeight); // restore original height
7280 this.setHeight(height, animate, duration, function(){
7282 if(typeof onComplete == "function") onComplete();
7283 }.createDelegate(this), easing);
7285 }.createDelegate(this), 0);
7290 * Returns true if this element is an ancestor of the passed element
7291 * @param {HTMLElement/String} el The element to check
7292 * @return {Boolean} True if this element is an ancestor of el, else false
7294 contains : function(el){
7295 if(!el){return false;}
7296 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7300 * Checks whether the element is currently visible using both visibility and display properties.
7301 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7302 * @return {Boolean} True if the element is currently visible, else false
7304 isVisible : function(deep) {
7305 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7306 if(deep !== true || !vis){
7309 var p = this.dom.parentNode;
7310 while(p && p.tagName.toLowerCase() != "body"){
7311 if(!Roo.fly(p, '_isVisible').isVisible()){
7320 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7321 * @param {String} selector The CSS selector
7322 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7323 * @return {CompositeElement/CompositeElementLite} The composite element
7325 select : function(selector, unique){
7326 return El.select(selector, unique, this.dom);
7330 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7331 * @param {String} selector The CSS selector
7332 * @return {Array} An array of the matched nodes
7334 query : function(selector, unique){
7335 return Roo.DomQuery.select(selector, this.dom);
7339 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7340 * @param {String} selector The CSS selector
7341 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7342 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7344 child : function(selector, returnDom){
7345 var n = Roo.DomQuery.selectNode(selector, this.dom);
7346 return returnDom ? n : Roo.get(n);
7350 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7351 * @param {String} selector The CSS selector
7352 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7353 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7355 down : function(selector, returnDom){
7356 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7357 return returnDom ? n : Roo.get(n);
7361 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7362 * @param {String} group The group the DD object is member of
7363 * @param {Object} config The DD config object
7364 * @param {Object} overrides An object containing methods to override/implement on the DD object
7365 * @return {Roo.dd.DD} The DD object
7367 initDD : function(group, config, overrides){
7368 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7369 return Roo.apply(dd, overrides);
7373 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7374 * @param {String} group The group the DDProxy object is member of
7375 * @param {Object} config The DDProxy config object
7376 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7377 * @return {Roo.dd.DDProxy} The DDProxy object
7379 initDDProxy : function(group, config, overrides){
7380 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7381 return Roo.apply(dd, overrides);
7385 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7386 * @param {String} group The group the DDTarget object is member of
7387 * @param {Object} config The DDTarget config object
7388 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7389 * @return {Roo.dd.DDTarget} The DDTarget object
7391 initDDTarget : function(group, config, overrides){
7392 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7393 return Roo.apply(dd, overrides);
7397 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7398 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7399 * @param {Boolean} visible Whether the element is visible
7400 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7401 * @return {Roo.Element} this
7403 setVisible : function(visible, animate){
7405 if(this.visibilityMode == El.DISPLAY){
7406 this.setDisplayed(visible);
7409 this.dom.style.visibility = visible ? "visible" : "hidden";
7412 // closure for composites
7414 var visMode = this.visibilityMode;
7416 this.setOpacity(.01);
7417 this.setVisible(true);
7419 this.anim({opacity: { to: (visible?1:0) }},
7420 this.preanim(arguments, 1),
7421 null, .35, 'easeIn', function(){
7423 if(visMode == El.DISPLAY){
7424 dom.style.display = "none";
7426 dom.style.visibility = "hidden";
7428 Roo.get(dom).setOpacity(1);
7436 * Returns true if display is not "none"
7439 isDisplayed : function() {
7440 return this.getStyle("display") != "none";
7444 * Toggles the element's visibility or display, depending on visibility mode.
7445 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7446 * @return {Roo.Element} this
7448 toggle : function(animate){
7449 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7454 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7455 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7456 * @return {Roo.Element} this
7458 setDisplayed : function(value) {
7459 if(typeof value == "boolean"){
7460 value = value ? this.originalDisplay : "none";
7462 this.setStyle("display", value);
7467 * Tries to focus the element. Any exceptions are caught and ignored.
7468 * @return {Roo.Element} this
7470 focus : function() {
7478 * Tries to blur the element. Any exceptions are caught and ignored.
7479 * @return {Roo.Element} this
7489 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7490 * @param {String/Array} className The CSS class to add, or an array of classes
7491 * @return {Roo.Element} this
7493 addClass : function(className){
7494 if(className instanceof Array){
7495 for(var i = 0, len = className.length; i < len; i++) {
7496 this.addClass(className[i]);
7499 if(className && !this.hasClass(className)){
7500 this.dom.className = this.dom.className + " " + className;
7507 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7508 * @param {String/Array} className The CSS class to add, or an array of classes
7509 * @return {Roo.Element} this
7511 radioClass : function(className){
7512 var siblings = this.dom.parentNode.childNodes;
7513 for(var i = 0; i < siblings.length; i++) {
7514 var s = siblings[i];
7515 if(s.nodeType == 1){
7516 Roo.get(s).removeClass(className);
7519 this.addClass(className);
7524 * Removes one or more CSS classes from the element.
7525 * @param {String/Array} className The CSS class to remove, or an array of classes
7526 * @return {Roo.Element} this
7528 removeClass : function(className){
7529 if(!className || !this.dom.className){
7532 if(className instanceof Array){
7533 for(var i = 0, len = className.length; i < len; i++) {
7534 this.removeClass(className[i]);
7537 if(this.hasClass(className)){
7538 var re = this.classReCache[className];
7540 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7541 this.classReCache[className] = re;
7543 this.dom.className =
7544 this.dom.className.replace(re, " ");
7554 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7555 * @param {String} className The CSS class to toggle
7556 * @return {Roo.Element} this
7558 toggleClass : function(className){
7559 if(this.hasClass(className)){
7560 this.removeClass(className);
7562 this.addClass(className);
7568 * Checks if the specified CSS class exists on this element's DOM node.
7569 * @param {String} className The CSS class to check for
7570 * @return {Boolean} True if the class exists, else false
7572 hasClass : function(className){
7573 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7577 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7578 * @param {String} oldClassName The CSS class to replace
7579 * @param {String} newClassName The replacement CSS class
7580 * @return {Roo.Element} this
7582 replaceClass : function(oldClassName, newClassName){
7583 this.removeClass(oldClassName);
7584 this.addClass(newClassName);
7589 * Returns an object with properties matching the styles requested.
7590 * For example, el.getStyles('color', 'font-size', 'width') might return
7591 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7592 * @param {String} style1 A style name
7593 * @param {String} style2 A style name
7594 * @param {String} etc.
7595 * @return {Object} The style object
7597 getStyles : function(){
7598 var a = arguments, len = a.length, r = {};
7599 for(var i = 0; i < len; i++){
7600 r[a[i]] = this.getStyle(a[i]);
7606 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7607 * @param {String} property The style property whose value is returned.
7608 * @return {String} The current value of the style property for this element.
7610 getStyle : function(){
7611 return view && view.getComputedStyle ?
7613 var el = this.dom, v, cs, camel;
7614 if(prop == 'float'){
7617 if(el.style && (v = el.style[prop])){
7620 if(cs = view.getComputedStyle(el, "")){
7621 if(!(camel = propCache[prop])){
7622 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7629 var el = this.dom, v, cs, camel;
7630 if(prop == 'opacity'){
7631 if(typeof el.style.filter == 'string'){
7632 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7634 var fv = parseFloat(m[1]);
7636 return fv ? fv / 100 : 0;
7641 }else if(prop == 'float'){
7642 prop = "styleFloat";
7644 if(!(camel = propCache[prop])){
7645 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7647 if(v = el.style[camel]){
7650 if(cs = el.currentStyle){
7658 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7659 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7660 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7661 * @return {Roo.Element} this
7663 setStyle : function(prop, value){
7664 if(typeof prop == "string"){
7666 if (prop == 'float') {
7667 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7672 if(!(camel = propCache[prop])){
7673 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7676 if(camel == 'opacity') {
7677 this.setOpacity(value);
7679 this.dom.style[camel] = value;
7682 for(var style in prop){
7683 if(typeof prop[style] != "function"){
7684 this.setStyle(style, prop[style]);
7692 * More flexible version of {@link #setStyle} for setting style properties.
7693 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7694 * a function which returns such a specification.
7695 * @return {Roo.Element} this
7697 applyStyles : function(style){
7698 Roo.DomHelper.applyStyles(this.dom, style);
7703 * 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).
7704 * @return {Number} The X position of the element
7707 return D.getX(this.dom);
7711 * 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).
7712 * @return {Number} The Y position of the element
7715 return D.getY(this.dom);
7719 * 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).
7720 * @return {Array} The XY position of the element
7723 return D.getXY(this.dom);
7727 * 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).
7728 * @param {Number} The X position of the element
7729 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7730 * @return {Roo.Element} this
7732 setX : function(x, animate){
7734 D.setX(this.dom, x);
7736 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7742 * 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).
7743 * @param {Number} The Y position of the element
7744 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7745 * @return {Roo.Element} this
7747 setY : function(y, animate){
7749 D.setY(this.dom, y);
7751 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7757 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7758 * @param {String} left The left CSS property value
7759 * @return {Roo.Element} this
7761 setLeft : function(left){
7762 this.setStyle("left", this.addUnits(left));
7767 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7768 * @param {String} top The top CSS property value
7769 * @return {Roo.Element} this
7771 setTop : function(top){
7772 this.setStyle("top", this.addUnits(top));
7777 * Sets the element's CSS right style.
7778 * @param {String} right The right CSS property value
7779 * @return {Roo.Element} this
7781 setRight : function(right){
7782 this.setStyle("right", this.addUnits(right));
7787 * Sets the element's CSS bottom style.
7788 * @param {String} bottom The bottom CSS property value
7789 * @return {Roo.Element} this
7791 setBottom : function(bottom){
7792 this.setStyle("bottom", this.addUnits(bottom));
7797 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7798 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7799 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7800 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7801 * @return {Roo.Element} this
7803 setXY : function(pos, animate){
7805 D.setXY(this.dom, pos);
7807 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7813 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7814 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7815 * @param {Number} x X value for new position (coordinates are page-based)
7816 * @param {Number} y Y value for new position (coordinates are page-based)
7817 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7818 * @return {Roo.Element} this
7820 setLocation : function(x, y, animate){
7821 this.setXY([x, y], this.preanim(arguments, 2));
7826 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7827 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7828 * @param {Number} x X value for new position (coordinates are page-based)
7829 * @param {Number} y Y value for new position (coordinates are page-based)
7830 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7831 * @return {Roo.Element} this
7833 moveTo : function(x, y, animate){
7834 this.setXY([x, y], this.preanim(arguments, 2));
7839 * Returns the region of the given element.
7840 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7841 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7843 getRegion : function(){
7844 return D.getRegion(this.dom);
7848 * Returns the offset height of the element
7849 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7850 * @return {Number} The element's height
7852 getHeight : function(contentHeight){
7853 var h = this.dom.offsetHeight || 0;
7854 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7858 * Returns the offset width of the element
7859 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7860 * @return {Number} The element's width
7862 getWidth : function(contentWidth){
7863 var w = this.dom.offsetWidth || 0;
7864 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7868 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7869 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7870 * if a height has not been set using CSS.
7873 getComputedHeight : function(){
7874 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7876 h = parseInt(this.getStyle('height'), 10) || 0;
7877 if(!this.isBorderBox()){
7878 h += this.getFrameWidth('tb');
7885 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7886 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7887 * if a width has not been set using CSS.
7890 getComputedWidth : function(){
7891 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7893 w = parseInt(this.getStyle('width'), 10) || 0;
7894 if(!this.isBorderBox()){
7895 w += this.getFrameWidth('lr');
7902 * Returns the size of the element.
7903 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
7904 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
7906 getSize : function(contentSize){
7907 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
7911 * Returns the width and height of the viewport.
7912 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
7914 getViewSize : function(){
7915 var d = this.dom, doc = document, aw = 0, ah = 0;
7916 if(d == doc || d == doc.body){
7917 return {width : D.getViewWidth(), height: D.getViewHeight()};
7920 width : d.clientWidth,
7921 height: d.clientHeight
7927 * Returns the value of the "value" attribute
7928 * @param {Boolean} asNumber true to parse the value as a number
7929 * @return {String/Number}
7931 getValue : function(asNumber){
7932 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
7936 adjustWidth : function(width){
7937 if(typeof width == "number"){
7938 if(this.autoBoxAdjust && !this.isBorderBox()){
7939 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7949 adjustHeight : function(height){
7950 if(typeof height == "number"){
7951 if(this.autoBoxAdjust && !this.isBorderBox()){
7952 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7962 * Set the width of the element
7963 * @param {Number} width The new width
7964 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7965 * @return {Roo.Element} this
7967 setWidth : function(width, animate){
7968 width = this.adjustWidth(width);
7970 this.dom.style.width = this.addUnits(width);
7972 this.anim({width: {to: width}}, this.preanim(arguments, 1));
7978 * Set the height of the element
7979 * @param {Number} height The new height
7980 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7981 * @return {Roo.Element} this
7983 setHeight : function(height, animate){
7984 height = this.adjustHeight(height);
7986 this.dom.style.height = this.addUnits(height);
7988 this.anim({height: {to: height}}, this.preanim(arguments, 1));
7994 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
7995 * @param {Number} width The new width
7996 * @param {Number} height The new height
7997 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
7998 * @return {Roo.Element} this
8000 setSize : function(width, height, animate){
8001 if(typeof width == "object"){ // in case of object from getSize()
8002 height = width.height; width = width.width;
8004 width = this.adjustWidth(width); height = this.adjustHeight(height);
8006 this.dom.style.width = this.addUnits(width);
8007 this.dom.style.height = this.addUnits(height);
8009 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
8015 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
8016 * @param {Number} x X value for new position (coordinates are page-based)
8017 * @param {Number} y Y value for new position (coordinates are page-based)
8018 * @param {Number} width The new width
8019 * @param {Number} height The new height
8020 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8021 * @return {Roo.Element} this
8023 setBounds : function(x, y, width, height, animate){
8025 this.setSize(width, height);
8026 this.setLocation(x, y);
8028 width = this.adjustWidth(width); height = this.adjustHeight(height);
8029 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
8030 this.preanim(arguments, 4), 'motion');
8036 * 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.
8037 * @param {Roo.lib.Region} region The region to fill
8038 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8039 * @return {Roo.Element} this
8041 setRegion : function(region, animate){
8042 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
8047 * Appends an event handler
8049 * @param {String} eventName The type of event to append
8050 * @param {Function} fn The method the event invokes
8051 * @param {Object} scope (optional) The scope (this object) of the fn
8052 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
8054 addListener : function(eventName, fn, scope, options){
8056 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
8061 * Removes an event handler from this element
8062 * @param {String} eventName the type of event to remove
8063 * @param {Function} fn the method the event invokes
8064 * @return {Roo.Element} this
8066 removeListener : function(eventName, fn){
8067 Roo.EventManager.removeListener(this.dom, eventName, fn);
8072 * Removes all previous added listeners from this element
8073 * @return {Roo.Element} this
8075 removeAllListeners : function(){
8076 E.purgeElement(this.dom);
8080 relayEvent : function(eventName, observable){
8081 this.on(eventName, function(e){
8082 observable.fireEvent(eventName, e);
8087 * Set the opacity of the element
8088 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
8089 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8090 * @return {Roo.Element} this
8092 setOpacity : function(opacity, animate){
8094 var s = this.dom.style;
8097 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
8098 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
8100 s.opacity = opacity;
8103 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
8109 * Gets the left X coordinate
8110 * @param {Boolean} local True to get the local css position instead of page coordinate
8113 getLeft : function(local){
8117 return parseInt(this.getStyle("left"), 10) || 0;
8122 * Gets the right X coordinate of the element (element X position + element width)
8123 * @param {Boolean} local True to get the local css position instead of page coordinate
8126 getRight : function(local){
8128 return this.getX() + this.getWidth();
8130 return (this.getLeft(true) + this.getWidth()) || 0;
8135 * Gets the top Y coordinate
8136 * @param {Boolean} local True to get the local css position instead of page coordinate
8139 getTop : function(local) {
8143 return parseInt(this.getStyle("top"), 10) || 0;
8148 * Gets the bottom Y coordinate of the element (element Y position + element height)
8149 * @param {Boolean} local True to get the local css position instead of page coordinate
8152 getBottom : function(local){
8154 return this.getY() + this.getHeight();
8156 return (this.getTop(true) + this.getHeight()) || 0;
8161 * Initializes positioning on this element. If a desired position is not passed, it will make the
8162 * the element positioned relative IF it is not already positioned.
8163 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
8164 * @param {Number} zIndex (optional) The zIndex to apply
8165 * @param {Number} x (optional) Set the page X position
8166 * @param {Number} y (optional) Set the page Y position
8168 position : function(pos, zIndex, x, y){
8170 if(this.getStyle('position') == 'static'){
8171 this.setStyle('position', 'relative');
8174 this.setStyle("position", pos);
8177 this.setStyle("z-index", zIndex);
8179 if(x !== undefined && y !== undefined){
8181 }else if(x !== undefined){
8183 }else if(y !== undefined){
8189 * Clear positioning back to the default when the document was loaded
8190 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
8191 * @return {Roo.Element} this
8193 clearPositioning : function(value){
8201 "position" : "static"
8207 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
8208 * snapshot before performing an update and then restoring the element.
8211 getPositioning : function(){
8212 var l = this.getStyle("left");
8213 var t = this.getStyle("top");
8215 "position" : this.getStyle("position"),
8217 "right" : l ? "" : this.getStyle("right"),
8219 "bottom" : t ? "" : this.getStyle("bottom"),
8220 "z-index" : this.getStyle("z-index")
8225 * Gets the width of the border(s) for the specified side(s)
8226 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8227 * passing lr would get the border (l)eft width + the border (r)ight width.
8228 * @return {Number} The width of the sides passed added together
8230 getBorderWidth : function(side){
8231 return this.addStyles(side, El.borders);
8235 * Gets the width of the padding(s) for the specified side(s)
8236 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8237 * passing lr would get the padding (l)eft + the padding (r)ight.
8238 * @return {Number} The padding of the sides passed added together
8240 getPadding : function(side){
8241 return this.addStyles(side, El.paddings);
8245 * Set positioning with an object returned by getPositioning().
8246 * @param {Object} posCfg
8247 * @return {Roo.Element} this
8249 setPositioning : function(pc){
8250 this.applyStyles(pc);
8251 if(pc.right == "auto"){
8252 this.dom.style.right = "";
8254 if(pc.bottom == "auto"){
8255 this.dom.style.bottom = "";
8261 fixDisplay : function(){
8262 if(this.getStyle("display") == "none"){
8263 this.setStyle("visibility", "hidden");
8264 this.setStyle("display", this.originalDisplay); // first try reverting to default
8265 if(this.getStyle("display") == "none"){ // if that fails, default to block
8266 this.setStyle("display", "block");
8272 * Quick set left and top adding default units
8273 * @param {String} left The left CSS property value
8274 * @param {String} top The top CSS property value
8275 * @return {Roo.Element} this
8277 setLeftTop : function(left, top){
8278 this.dom.style.left = this.addUnits(left);
8279 this.dom.style.top = this.addUnits(top);
8284 * Move this element relative to its current position.
8285 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8286 * @param {Number} distance How far to move the element in pixels
8287 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8288 * @return {Roo.Element} this
8290 move : function(direction, distance, animate){
8291 var xy = this.getXY();
8292 direction = direction.toLowerCase();
8296 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8300 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8305 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8310 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8317 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8318 * @return {Roo.Element} this
8321 if(!this.isClipped){
8322 this.isClipped = true;
8323 this.originalClip = {
8324 "o": this.getStyle("overflow"),
8325 "x": this.getStyle("overflow-x"),
8326 "y": this.getStyle("overflow-y")
8328 this.setStyle("overflow", "hidden");
8329 this.setStyle("overflow-x", "hidden");
8330 this.setStyle("overflow-y", "hidden");
8336 * Return clipping (overflow) to original clipping before clip() was called
8337 * @return {Roo.Element} this
8339 unclip : function(){
8341 this.isClipped = false;
8342 var o = this.originalClip;
8343 if(o.o){this.setStyle("overflow", o.o);}
8344 if(o.x){this.setStyle("overflow-x", o.x);}
8345 if(o.y){this.setStyle("overflow-y", o.y);}
8352 * Gets the x,y coordinates specified by the anchor position on the element.
8353 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8354 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8355 * {width: (target width), height: (target height)} (defaults to the element's current size)
8356 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8357 * @return {Array} [x, y] An array containing the element's x and y coordinates
8359 getAnchorXY : function(anchor, local, s){
8360 //Passing a different size is useful for pre-calculating anchors,
8361 //especially for anchored animations that change the el size.
8363 var w, h, vp = false;
8366 if(d == document.body || d == document){
8368 w = D.getViewWidth(); h = D.getViewHeight();
8370 w = this.getWidth(); h = this.getHeight();
8373 w = s.width; h = s.height;
8375 var x = 0, y = 0, r = Math.round;
8376 switch((anchor || "tl").toLowerCase()){
8418 var sc = this.getScroll();
8419 return [x + sc.left, y + sc.top];
8421 //Add the element's offset xy
8422 var o = this.getXY();
8423 return [x+o[0], y+o[1]];
8427 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8428 * supported position values.
8429 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8430 * @param {String} position The position to align to.
8431 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8432 * @return {Array} [x, y]
8434 getAlignToXY : function(el, p, o){
8438 throw "Element.alignTo with an element that doesn't exist";
8440 var c = false; //constrain to viewport
8441 var p1 = "", p2 = "";
8448 }else if(p.indexOf("-") == -1){
8451 p = p.toLowerCase();
8452 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8454 throw "Element.alignTo with an invalid alignment " + p;
8456 p1 = m[1]; p2 = m[2]; c = !!m[3];
8458 //Subtract the aligned el's internal xy from the target's offset xy
8459 //plus custom offset to get the aligned el's new offset xy
8460 var a1 = this.getAnchorXY(p1, true);
8461 var a2 = el.getAnchorXY(p2, false);
8462 var x = a2[0] - a1[0] + o[0];
8463 var y = a2[1] - a1[1] + o[1];
8465 //constrain the aligned el to viewport if necessary
8466 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8467 // 5px of margin for ie
8468 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8470 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8471 //perpendicular to the vp border, allow the aligned el to slide on that border,
8472 //otherwise swap the aligned el to the opposite border of the target.
8473 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8474 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8475 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8476 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8479 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8480 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8482 if((x+w) > dw + scrollX){
8483 x = swapX ? r.left-w : dw+scrollX-w;
8486 x = swapX ? r.right : scrollX;
8488 if((y+h) > dh + scrollY){
8489 y = swapY ? r.top-h : dh+scrollY-h;
8492 y = swapY ? r.bottom : scrollY;
8499 getConstrainToXY : function(){
8500 var os = {top:0, left:0, bottom:0, right: 0};
8502 return function(el, local, offsets, proposedXY){
8504 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8506 var vw, vh, vx = 0, vy = 0;
8507 if(el.dom == document.body || el.dom == document){
8508 vw = Roo.lib.Dom.getViewWidth();
8509 vh = Roo.lib.Dom.getViewHeight();
8511 vw = el.dom.clientWidth;
8512 vh = el.dom.clientHeight;
8514 var vxy = el.getXY();
8520 var s = el.getScroll();
8522 vx += offsets.left + s.left;
8523 vy += offsets.top + s.top;
8525 vw -= offsets.right;
8526 vh -= offsets.bottom;
8531 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8532 var x = xy[0], y = xy[1];
8533 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8535 // only move it if it needs it
8538 // first validate right/bottom
8547 // then make sure top/left isn't negative
8556 return moved ? [x, y] : false;
8561 adjustForConstraints : function(xy, parent, offsets){
8562 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8566 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8567 * document it aligns it to the viewport.
8568 * The position parameter is optional, and can be specified in any one of the following formats:
8570 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8571 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8572 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8573 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8574 * <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
8575 * element's anchor point, and the second value is used as the target's anchor point.</li>
8577 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8578 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8579 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8580 * that specified in order to enforce the viewport constraints.
8581 * Following are all of the supported anchor positions:
8584 ----- -----------------------------
8585 tl The top left corner (default)
8586 t The center of the top edge
8587 tr The top right corner
8588 l The center of the left edge
8589 c In the center of the element
8590 r The center of the right edge
8591 bl The bottom left corner
8592 b The center of the bottom edge
8593 br The bottom right corner
8597 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8598 el.alignTo("other-el");
8600 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8601 el.alignTo("other-el", "tr?");
8603 // align the bottom right corner of el with the center left edge of other-el
8604 el.alignTo("other-el", "br-l?");
8606 // align the center of el with the bottom left corner of other-el and
8607 // adjust the x position by -6 pixels (and the y position by 0)
8608 el.alignTo("other-el", "c-bl", [-6, 0]);
8610 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8611 * @param {String} position The position to align to.
8612 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8613 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8614 * @return {Roo.Element} this
8616 alignTo : function(element, position, offsets, animate){
8617 var xy = this.getAlignToXY(element, position, offsets);
8618 this.setXY(xy, this.preanim(arguments, 3));
8623 * Anchors an element to another element and realigns it when the window is resized.
8624 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8625 * @param {String} position The position to align to.
8626 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8627 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8628 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8629 * is a number, it is used as the buffer delay (defaults to 50ms).
8630 * @param {Function} callback The function to call after the animation finishes
8631 * @return {Roo.Element} this
8633 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8634 var action = function(){
8635 this.alignTo(el, alignment, offsets, animate);
8636 Roo.callback(callback, this);
8638 Roo.EventManager.onWindowResize(action, this);
8639 var tm = typeof monitorScroll;
8640 if(tm != 'undefined'){
8641 Roo.EventManager.on(window, 'scroll', action, this,
8642 {buffer: tm == 'number' ? monitorScroll : 50});
8644 action.call(this); // align immediately
8648 * Clears any opacity settings from this element. Required in some cases for IE.
8649 * @return {Roo.Element} this
8651 clearOpacity : function(){
8652 if (window.ActiveXObject) {
8653 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8654 this.dom.style.filter = "";
8657 this.dom.style.opacity = "";
8658 this.dom.style["-moz-opacity"] = "";
8659 this.dom.style["-khtml-opacity"] = "";
8665 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8666 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8667 * @return {Roo.Element} this
8669 hide : function(animate){
8670 this.setVisible(false, this.preanim(arguments, 0));
8675 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8676 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8677 * @return {Roo.Element} this
8679 show : function(animate){
8680 this.setVisible(true, this.preanim(arguments, 0));
8685 * @private Test if size has a unit, otherwise appends the default
8687 addUnits : function(size){
8688 return Roo.Element.addUnits(size, this.defaultUnit);
8692 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8693 * @return {Roo.Element} this
8695 beginMeasure : function(){
8697 if(el.offsetWidth || el.offsetHeight){
8698 return this; // offsets work already
8701 var p = this.dom, b = document.body; // start with this element
8702 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8703 var pe = Roo.get(p);
8704 if(pe.getStyle('display') == 'none'){
8705 changed.push({el: p, visibility: pe.getStyle("visibility")});
8706 p.style.visibility = "hidden";
8707 p.style.display = "block";
8711 this._measureChanged = changed;
8717 * Restores displays to before beginMeasure was called
8718 * @return {Roo.Element} this
8720 endMeasure : function(){
8721 var changed = this._measureChanged;
8723 for(var i = 0, len = changed.length; i < len; i++) {
8725 r.el.style.visibility = r.visibility;
8726 r.el.style.display = "none";
8728 this._measureChanged = null;
8734 * Update the innerHTML of this element, optionally searching for and processing scripts
8735 * @param {String} html The new HTML
8736 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8737 * @param {Function} callback For async script loading you can be noticed when the update completes
8738 * @return {Roo.Element} this
8740 update : function(html, loadScripts, callback){
8741 if(typeof html == "undefined"){
8744 if(loadScripts !== true){
8745 this.dom.innerHTML = html;
8746 if(typeof callback == "function"){
8754 html += '<span id="' + id + '"></span>';
8756 E.onAvailable(id, function(){
8757 var hd = document.getElementsByTagName("head")[0];
8758 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8759 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8760 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8763 while(match = re.exec(html)){
8764 var attrs = match[1];
8765 var srcMatch = attrs ? attrs.match(srcRe) : false;
8766 if(srcMatch && srcMatch[2]){
8767 var s = document.createElement("script");
8768 s.src = srcMatch[2];
8769 var typeMatch = attrs.match(typeRe);
8770 if(typeMatch && typeMatch[2]){
8771 s.type = typeMatch[2];
8774 }else if(match[2] && match[2].length > 0){
8775 if(window.execScript) {
8776 window.execScript(match[2]);
8784 window.eval(match[2]);
8788 var el = document.getElementById(id);
8789 if(el){el.parentNode.removeChild(el);}
8790 if(typeof callback == "function"){
8794 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8799 * Direct access to the UpdateManager update() method (takes the same parameters).
8800 * @param {String/Function} url The url for this request or a function to call to get the url
8801 * @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}
8802 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8803 * @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.
8804 * @return {Roo.Element} this
8807 var um = this.getUpdateManager();
8808 um.update.apply(um, arguments);
8813 * Gets this element's UpdateManager
8814 * @return {Roo.UpdateManager} The UpdateManager
8816 getUpdateManager : function(){
8817 if(!this.updateManager){
8818 this.updateManager = new Roo.UpdateManager(this);
8820 return this.updateManager;
8824 * Disables text selection for this element (normalized across browsers)
8825 * @return {Roo.Element} this
8827 unselectable : function(){
8828 this.dom.unselectable = "on";
8829 this.swallowEvent("selectstart", true);
8830 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8831 this.addClass("x-unselectable");
8836 * Calculates the x, y to center this element on the screen
8837 * @return {Array} The x, y values [x, y]
8839 getCenterXY : function(){
8840 return this.getAlignToXY(document, 'c-c');
8844 * Centers the Element in either the viewport, or another Element.
8845 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8847 center : function(centerIn){
8848 this.alignTo(centerIn || document, 'c-c');
8853 * Tests various css rules/browsers to determine if this element uses a border box
8856 isBorderBox : function(){
8857 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8861 * Return a box {x, y, width, height} that can be used to set another elements
8862 * size/location to match this element.
8863 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8864 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8865 * @return {Object} box An object in the format {x, y, width, height}
8867 getBox : function(contentBox, local){
8872 var left = parseInt(this.getStyle("left"), 10) || 0;
8873 var top = parseInt(this.getStyle("top"), 10) || 0;
8876 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8878 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8880 var l = this.getBorderWidth("l")+this.getPadding("l");
8881 var r = this.getBorderWidth("r")+this.getPadding("r");
8882 var t = this.getBorderWidth("t")+this.getPadding("t");
8883 var b = this.getBorderWidth("b")+this.getPadding("b");
8884 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)};
8886 bx.right = bx.x + bx.width;
8887 bx.bottom = bx.y + bx.height;
8892 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8893 for more information about the sides.
8894 * @param {String} sides
8897 getFrameWidth : function(sides, onlyContentBox){
8898 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
8902 * 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.
8903 * @param {Object} box The box to fill {x, y, width, height}
8904 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
8905 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8906 * @return {Roo.Element} this
8908 setBox : function(box, adjust, animate){
8909 var w = box.width, h = box.height;
8910 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
8911 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8912 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8914 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
8919 * Forces the browser to repaint this element
8920 * @return {Roo.Element} this
8922 repaint : function(){
8924 this.addClass("x-repaint");
8925 setTimeout(function(){
8926 Roo.get(dom).removeClass("x-repaint");
8932 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
8933 * then it returns the calculated width of the sides (see getPadding)
8934 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
8935 * @return {Object/Number}
8937 getMargins : function(side){
8940 top: parseInt(this.getStyle("margin-top"), 10) || 0,
8941 left: parseInt(this.getStyle("margin-left"), 10) || 0,
8942 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
8943 right: parseInt(this.getStyle("margin-right"), 10) || 0
8946 return this.addStyles(side, El.margins);
8951 addStyles : function(sides, styles){
8953 for(var i = 0, len = sides.length; i < len; i++){
8954 v = this.getStyle(styles[sides.charAt(i)]);
8956 w = parseInt(v, 10);
8964 * Creates a proxy element of this element
8965 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
8966 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
8967 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
8968 * @return {Roo.Element} The new proxy element
8970 createProxy : function(config, renderTo, matchBox){
8972 renderTo = Roo.getDom(renderTo);
8974 renderTo = document.body;
8976 config = typeof config == "object" ?
8977 config : {tag : "div", cls: config};
8978 var proxy = Roo.DomHelper.append(renderTo, config, true);
8980 proxy.setBox(this.getBox());
8986 * Puts a mask over this element to disable user interaction. Requires core.css.
8987 * This method can only be applied to elements which accept child nodes.
8988 * @param {String} msg (optional) A message to display in the mask
8989 * @param {String} msgCls (optional) A css class to apply to the msg element
8990 * @return {Element} The mask element
8992 mask : function(msg, msgCls)
8994 if(this.getStyle("position") == "static" && this.dom.tagName !== 'BODY'){
8995 this.setStyle("position", "relative");
8998 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
9000 this.addClass("x-masked");
9001 this._mask.setDisplayed(true);
9006 while (dom && dom.style) {
9007 if (!isNaN(parseInt(dom.style.zIndex))) {
9008 z = Math.max(z, parseInt(dom.style.zIndex));
9010 dom = dom.parentNode;
9012 // if we are masking the body - then it hides everything..
9013 if (this.dom == document.body) {
9015 this._mask.setWidth(Roo.lib.Dom.getDocumentWidth());
9016 this._mask.setHeight(Roo.lib.Dom.getDocumentHeight());
9019 if(typeof msg == 'string'){
9021 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
9023 var mm = this._maskMsg;
9024 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
9025 if (mm.dom.firstChild) { // weird IE issue?
9026 mm.dom.firstChild.innerHTML = msg;
9028 mm.setDisplayed(true);
9030 mm.setStyle('z-index', z + 102);
9032 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
9033 this._mask.setHeight(this.getHeight());
9035 this._mask.setStyle('z-index', z + 100);
9041 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
9042 * it is cached for reuse.
9044 unmask : function(removeEl){
9046 if(removeEl === true){
9047 this._mask.remove();
9050 this._maskMsg.remove();
9051 delete this._maskMsg;
9054 this._mask.setDisplayed(false);
9056 this._maskMsg.setDisplayed(false);
9060 this.removeClass("x-masked");
9064 * Returns true if this element is masked
9067 isMasked : function(){
9068 return this._mask && this._mask.isVisible();
9072 * Creates an iframe shim for this element to keep selects and other windowed objects from
9074 * @return {Roo.Element} The new shim element
9076 createShim : function(){
9077 var el = document.createElement('iframe');
9078 el.frameBorder = 'no';
9079 el.className = 'roo-shim';
9080 if(Roo.isIE && Roo.isSecure){
9081 el.src = Roo.SSL_SECURE_URL;
9083 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
9084 shim.autoBoxAdjust = false;
9089 * Removes this element from the DOM and deletes it from the cache
9091 remove : function(){
9092 if(this.dom.parentNode){
9093 this.dom.parentNode.removeChild(this.dom);
9095 delete El.cache[this.dom.id];
9099 * Sets up event handlers to add and remove a css class when the mouse is over this element
9100 * @param {String} className
9101 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
9102 * mouseout events for children elements
9103 * @return {Roo.Element} this
9105 addClassOnOver : function(className, preventFlicker){
9106 this.on("mouseover", function(){
9107 Roo.fly(this, '_internal').addClass(className);
9109 var removeFn = function(e){
9110 if(preventFlicker !== true || !e.within(this, true)){
9111 Roo.fly(this, '_internal').removeClass(className);
9114 this.on("mouseout", removeFn, this.dom);
9119 * Sets up event handlers to add and remove a css class when this element has the focus
9120 * @param {String} className
9121 * @return {Roo.Element} this
9123 addClassOnFocus : function(className){
9124 this.on("focus", function(){
9125 Roo.fly(this, '_internal').addClass(className);
9127 this.on("blur", function(){
9128 Roo.fly(this, '_internal').removeClass(className);
9133 * 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)
9134 * @param {String} className
9135 * @return {Roo.Element} this
9137 addClassOnClick : function(className){
9139 this.on("mousedown", function(){
9140 Roo.fly(dom, '_internal').addClass(className);
9141 var d = Roo.get(document);
9142 var fn = function(){
9143 Roo.fly(dom, '_internal').removeClass(className);
9144 d.removeListener("mouseup", fn);
9146 d.on("mouseup", fn);
9152 * Stops the specified event from bubbling and optionally prevents the default action
9153 * @param {String} eventName
9154 * @param {Boolean} preventDefault (optional) true to prevent the default action too
9155 * @return {Roo.Element} this
9157 swallowEvent : function(eventName, preventDefault){
9158 var fn = function(e){
9159 e.stopPropagation();
9164 if(eventName instanceof Array){
9165 for(var i = 0, len = eventName.length; i < len; i++){
9166 this.on(eventName[i], fn);
9170 this.on(eventName, fn);
9177 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
9180 * Sizes this element to its parent element's dimensions performing
9181 * neccessary box adjustments.
9182 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
9183 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
9184 * @return {Roo.Element} this
9186 fitToParent : function(monitorResize, targetParent) {
9187 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
9188 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
9189 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
9192 var p = Roo.get(targetParent || this.dom.parentNode);
9193 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
9194 if (monitorResize === true) {
9195 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
9196 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
9202 * Gets the next sibling, skipping text nodes
9203 * @return {HTMLElement} The next sibling or null
9205 getNextSibling : function(){
9206 var n = this.dom.nextSibling;
9207 while(n && n.nodeType != 1){
9214 * Gets the previous sibling, skipping text nodes
9215 * @return {HTMLElement} The previous sibling or null
9217 getPrevSibling : function(){
9218 var n = this.dom.previousSibling;
9219 while(n && n.nodeType != 1){
9220 n = n.previousSibling;
9227 * Appends the passed element(s) to this element
9228 * @param {String/HTMLElement/Array/Element/CompositeElement} el
9229 * @return {Roo.Element} this
9231 appendChild: function(el){
9238 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
9239 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
9240 * automatically generated with the specified attributes.
9241 * @param {HTMLElement} insertBefore (optional) a child element of this element
9242 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
9243 * @return {Roo.Element} The new child element
9245 createChild: function(config, insertBefore, returnDom){
9246 config = config || {tag:'div'};
9248 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
9250 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
9254 * Appends this element to the passed element
9255 * @param {String/HTMLElement/Element} el The new parent element
9256 * @return {Roo.Element} this
9258 appendTo: function(el){
9259 el = Roo.getDom(el);
9260 el.appendChild(this.dom);
9265 * Inserts this element before the passed element in the DOM
9266 * @param {String/HTMLElement/Element} el The element to insert before
9267 * @return {Roo.Element} this
9269 insertBefore: function(el){
9270 el = Roo.getDom(el);
9271 el.parentNode.insertBefore(this.dom, el);
9276 * Inserts this element after the passed element in the DOM
9277 * @param {String/HTMLElement/Element} el The element to insert after
9278 * @return {Roo.Element} this
9280 insertAfter: function(el){
9281 el = Roo.getDom(el);
9282 el.parentNode.insertBefore(this.dom, el.nextSibling);
9287 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9288 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9289 * @return {Roo.Element} The new child
9291 insertFirst: function(el, returnDom){
9293 if(typeof el == 'object' && !el.nodeType){ // dh config
9294 return this.createChild(el, this.dom.firstChild, returnDom);
9296 el = Roo.getDom(el);
9297 this.dom.insertBefore(el, this.dom.firstChild);
9298 return !returnDom ? Roo.get(el) : el;
9303 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9304 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9305 * @param {String} where (optional) 'before' or 'after' defaults to before
9306 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9307 * @return {Roo.Element} the inserted Element
9309 insertSibling: function(el, where, returnDom){
9310 where = where ? where.toLowerCase() : 'before';
9312 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9314 if(typeof el == 'object' && !el.nodeType){ // dh config
9315 if(where == 'after' && !this.dom.nextSibling){
9316 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9318 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9322 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9323 where == 'before' ? this.dom : this.dom.nextSibling);
9332 * Creates and wraps this element with another element
9333 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9334 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9335 * @return {HTMLElement/Element} The newly created wrapper element
9337 wrap: function(config, returnDom){
9339 config = {tag: "div"};
9341 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9342 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9347 * Replaces the passed element with this element
9348 * @param {String/HTMLElement/Element} el The element to replace
9349 * @return {Roo.Element} this
9351 replace: function(el){
9353 this.insertBefore(el);
9359 * Inserts an html fragment into this element
9360 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9361 * @param {String} html The HTML fragment
9362 * @param {Boolean} returnEl True to return an Roo.Element
9363 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9365 insertHtml : function(where, html, returnEl){
9366 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9367 return returnEl ? Roo.get(el) : el;
9371 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9372 * @param {Object} o The object with the attributes
9373 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9374 * @return {Roo.Element} this
9376 set : function(o, useSet){
9378 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9380 if(attr == "style" || typeof o[attr] == "function") continue;
9382 el.className = o["cls"];
9384 if(useSet) el.setAttribute(attr, o[attr]);
9385 else el[attr] = o[attr];
9389 Roo.DomHelper.applyStyles(el, o.style);
9395 * Convenience method for constructing a KeyMap
9396 * @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:
9397 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9398 * @param {Function} fn The function to call
9399 * @param {Object} scope (optional) The scope of the function
9400 * @return {Roo.KeyMap} The KeyMap created
9402 addKeyListener : function(key, fn, scope){
9404 if(typeof key != "object" || key instanceof Array){
9420 return new Roo.KeyMap(this, config);
9424 * Creates a KeyMap for this element
9425 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9426 * @return {Roo.KeyMap} The KeyMap created
9428 addKeyMap : function(config){
9429 return new Roo.KeyMap(this, config);
9433 * Returns true if this element is scrollable.
9436 isScrollable : function(){
9438 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9442 * 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().
9443 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9444 * @param {Number} value The new scroll value
9445 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9446 * @return {Element} this
9449 scrollTo : function(side, value, animate){
9450 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9452 this.dom[prop] = value;
9454 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9455 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9461 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9462 * within this element's scrollable range.
9463 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9464 * @param {Number} distance How far to scroll the element in pixels
9465 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9466 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9467 * was scrolled as far as it could go.
9469 scroll : function(direction, distance, animate){
9470 if(!this.isScrollable()){
9474 var l = el.scrollLeft, t = el.scrollTop;
9475 var w = el.scrollWidth, h = el.scrollHeight;
9476 var cw = el.clientWidth, ch = el.clientHeight;
9477 direction = direction.toLowerCase();
9478 var scrolled = false;
9479 var a = this.preanim(arguments, 2);
9484 var v = Math.min(l + distance, w-cw);
9485 this.scrollTo("left", v, a);
9492 var v = Math.max(l - distance, 0);
9493 this.scrollTo("left", v, a);
9501 var v = Math.max(t - distance, 0);
9502 this.scrollTo("top", v, a);
9510 var v = Math.min(t + distance, h-ch);
9511 this.scrollTo("top", v, a);
9520 * Translates the passed page coordinates into left/top css values for this element
9521 * @param {Number/Array} x The page x or an array containing [x, y]
9522 * @param {Number} y The page y
9523 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9525 translatePoints : function(x, y){
9526 if(typeof x == 'object' || x instanceof Array){
9529 var p = this.getStyle('position');
9530 var o = this.getXY();
9532 var l = parseInt(this.getStyle('left'), 10);
9533 var t = parseInt(this.getStyle('top'), 10);
9536 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9539 t = (p == "relative") ? 0 : this.dom.offsetTop;
9542 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9546 * Returns the current scroll position of the element.
9547 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9549 getScroll : function(){
9550 var d = this.dom, doc = document;
9551 if(d == doc || d == doc.body){
9552 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9553 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9554 return {left: l, top: t};
9556 return {left: d.scrollLeft, top: d.scrollTop};
9561 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9562 * are convert to standard 6 digit hex color.
9563 * @param {String} attr The css attribute
9564 * @param {String} defaultValue The default value to use when a valid color isn't found
9565 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9568 getColor : function(attr, defaultValue, prefix){
9569 var v = this.getStyle(attr);
9570 if(!v || v == "transparent" || v == "inherit") {
9571 return defaultValue;
9573 var color = typeof prefix == "undefined" ? "#" : prefix;
9574 if(v.substr(0, 4) == "rgb("){
9575 var rvs = v.slice(4, v.length -1).split(",");
9576 for(var i = 0; i < 3; i++){
9577 var h = parseInt(rvs[i]).toString(16);
9584 if(v.substr(0, 1) == "#"){
9586 for(var i = 1; i < 4; i++){
9587 var c = v.charAt(i);
9590 }else if(v.length == 7){
9591 color += v.substr(1);
9595 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9599 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9600 * gradient background, rounded corners and a 4-way shadow.
9601 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9602 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9603 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9604 * @return {Roo.Element} this
9606 boxWrap : function(cls){
9607 cls = cls || 'x-box';
9608 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9609 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9614 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9615 * @param {String} namespace The namespace in which to look for the attribute
9616 * @param {String} name The attribute name
9617 * @return {String} The attribute value
9619 getAttributeNS : Roo.isIE ? function(ns, name){
9621 var type = typeof d[ns+":"+name];
9622 if(type != 'undefined' && type != 'unknown'){
9623 return d[ns+":"+name];
9626 } : function(ns, name){
9628 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9633 * Sets or Returns the value the dom attribute value
9634 * @param {String|Object} name The attribute name (or object to set multiple attributes)
9635 * @param {String} value (optional) The value to set the attribute to
9636 * @return {String} The attribute value
9638 attr : function(name){
9639 if (arguments.length > 1) {
9640 this.dom.setAttribute(name, arguments[1]);
9641 return arguments[1];
9643 if (typeof(name) == 'object') {
9644 for(var i in name) {
9645 this.attr(i, name[i]);
9651 if (!this.dom.hasAttribute(name)) {
9654 return this.dom.getAttribute(name);
9661 var ep = El.prototype;
9664 * Appends an event handler (Shorthand for addListener)
9665 * @param {String} eventName The type of event to append
9666 * @param {Function} fn The method the event invokes
9667 * @param {Object} scope (optional) The scope (this object) of the fn
9668 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9671 ep.on = ep.addListener;
9673 ep.mon = ep.addListener;
9676 * Removes an event handler from this element (shorthand for removeListener)
9677 * @param {String} eventName the type of event to remove
9678 * @param {Function} fn the method the event invokes
9679 * @return {Roo.Element} this
9682 ep.un = ep.removeListener;
9685 * true to automatically adjust width and height settings for box-model issues (default to true)
9687 ep.autoBoxAdjust = true;
9690 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9693 El.addUnits = function(v, defaultUnit){
9694 if(v === "" || v == "auto"){
9697 if(v === undefined){
9700 if(typeof v == "number" || !El.unitPattern.test(v)){
9701 return v + (defaultUnit || 'px');
9706 // special markup used throughout Roo when box wrapping elements
9707 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>';
9709 * Visibility mode constant - Use visibility to hide element
9715 * Visibility mode constant - Use display to hide element
9721 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9722 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9723 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9735 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9736 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9737 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9738 * @return {Element} The Element object
9741 El.get = function(el){
9743 if(!el){ return null; }
9744 if(typeof el == "string"){ // element id
9745 if(!(elm = document.getElementById(el))){
9748 if(ex = El.cache[el]){
9751 ex = El.cache[el] = new El(elm);
9754 }else if(el.tagName){ // dom element
9758 if(ex = El.cache[id]){
9761 ex = El.cache[id] = new El(el);
9764 }else if(el instanceof El){
9766 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9767 // catch case where it hasn't been appended
9768 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9771 }else if(el.isComposite){
9773 }else if(el instanceof Array){
9774 return El.select(el);
9775 }else if(el == document){
9776 // create a bogus element object representing the document object
9778 var f = function(){};
9779 f.prototype = El.prototype;
9781 docEl.dom = document;
9789 El.uncache = function(el){
9790 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9792 delete El.cache[a[i].id || a[i]];
9798 // Garbage collection - uncache elements/purge listeners on orphaned elements
9799 // so we don't hold a reference and cause the browser to retain them
9800 El.garbageCollect = function(){
9801 if(!Roo.enableGarbageCollector){
9802 clearInterval(El.collectorThread);
9805 for(var eid in El.cache){
9806 var el = El.cache[eid], d = el.dom;
9807 // -------------------------------------------------------
9808 // Determining what is garbage:
9809 // -------------------------------------------------------
9811 // dom node is null, definitely garbage
9812 // -------------------------------------------------------
9814 // no parentNode == direct orphan, definitely garbage
9815 // -------------------------------------------------------
9816 // !d.offsetParent && !document.getElementById(eid)
9817 // display none elements have no offsetParent so we will
9818 // also try to look it up by it's id. However, check
9819 // offsetParent first so we don't do unneeded lookups.
9820 // This enables collection of elements that are not orphans
9821 // directly, but somewhere up the line they have an orphan
9823 // -------------------------------------------------------
9824 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9825 delete El.cache[eid];
9826 if(d && Roo.enableListenerCollection){
9832 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9836 El.Flyweight = function(dom){
9839 El.Flyweight.prototype = El.prototype;
9841 El._flyweights = {};
9843 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9844 * the dom node can be overwritten by other code.
9845 * @param {String/HTMLElement} el The dom node or id
9846 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9847 * prevent conflicts (e.g. internally Roo uses "_internal")
9849 * @return {Element} The shared Element object
9851 El.fly = function(el, named){
9852 named = named || '_global';
9853 el = Roo.getDom(el);
9857 if(!El._flyweights[named]){
9858 El._flyweights[named] = new El.Flyweight();
9860 El._flyweights[named].dom = el;
9861 return El._flyweights[named];
9865 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9866 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9867 * Shorthand of {@link Roo.Element#get}
9868 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9869 * @return {Element} The Element object
9875 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9876 * the dom node can be overwritten by other code.
9877 * Shorthand of {@link Roo.Element#fly}
9878 * @param {String/HTMLElement} el The dom node or id
9879 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9880 * prevent conflicts (e.g. internally Roo uses "_internal")
9882 * @return {Element} The shared Element object
9888 // speedy lookup for elements never to box adjust
9889 var noBoxAdjust = Roo.isStrict ? {
9892 input:1, select:1, textarea:1
9894 if(Roo.isIE || Roo.isGecko){
9895 noBoxAdjust['button'] = 1;
9899 Roo.EventManager.on(window, 'unload', function(){
9901 delete El._flyweights;
9909 Roo.Element.selectorFunction = Roo.DomQuery.select;
9912 Roo.Element.select = function(selector, unique, root){
9914 if(typeof selector == "string"){
9915 els = Roo.Element.selectorFunction(selector, root);
9916 }else if(selector.length !== undefined){
9919 throw "Invalid selector";
9921 if(unique === true){
9922 return new Roo.CompositeElement(els);
9924 return new Roo.CompositeElementLite(els);
9928 * Selects elements based on the passed CSS selector to enable working on them as 1.
9929 * @param {String/Array} selector The CSS selector or an array of elements
9930 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
9931 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
9932 * @return {CompositeElementLite/CompositeElement}
9936 Roo.select = Roo.Element.select;
9953 * Ext JS Library 1.1.1
9954 * Copyright(c) 2006-2007, Ext JS, LLC.
9956 * Originally Released Under LGPL - original licence link has changed is not relivant.
9959 * <script type="text/javascript">
9964 //Notifies Element that fx methods are available
9965 Roo.enableFx = true;
9969 * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
9970 * to the {@link Roo.Element} interface when included, so all effects calls should be performed via Element.
9971 * Conversely, since the effects are not actually defined in Element, Roo.Fx <b>must</b> be included in order for the
9972 * Element effects to work.</p><br/>
9974 * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
9975 * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
9976 * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
9977 * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
9978 * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
9979 * expected results and should be done with care.</p><br/>
9981 * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
9982 * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
9985 ----- -----------------------------
9986 tl The top left corner
9987 t The center of the top edge
9988 tr The top right corner
9989 l The center of the left edge
9990 r The center of the right edge
9991 bl The bottom left corner
9992 b The center of the bottom edge
9993 br The bottom right corner
9995 * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section
9996 * below are common options that can be passed to any Fx method.</b>
9997 * @cfg {Function} callback A function called when the effect is finished
9998 * @cfg {Object} scope The scope of the effect function
9999 * @cfg {String} easing A valid Easing value for the effect
10000 * @cfg {String} afterCls A css class to apply after the effect
10001 * @cfg {Number} duration The length of time (in seconds) that the effect should last
10002 * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
10003 * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
10004 * effects that end with the element being visually hidden, ignored otherwise)
10005 * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or
10006 * a function which returns such a specification that will be applied to the Element after the effect finishes
10007 * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
10008 * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence
10009 * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes
10013 * Slides the element into view. An anchor point can be optionally passed to set the point of
10014 * origin for the slide effect. This function automatically handles wrapping the element with
10015 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10018 // default: slide the element in from the top
10021 // custom: slide the element in from the right with a 2-second duration
10022 el.slideIn('r', { duration: 2 });
10024 // common config options shown with default values
10030 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10031 * @param {Object} options (optional) Object literal with any of the Fx config options
10032 * @return {Roo.Element} The Element
10034 slideIn : function(anchor, o){
10035 var el = this.getFxEl();
10038 el.queueFx(o, function(){
10040 anchor = anchor || "t";
10042 // fix display to visibility
10045 // restore values after effect
10046 var r = this.getFxRestore();
10047 var b = this.getBox();
10048 // fixed size for slide
10052 var wrap = this.fxWrap(r.pos, o, "hidden");
10054 var st = this.dom.style;
10055 st.visibility = "visible";
10056 st.position = "absolute";
10058 // clear out temp styles after slide and unwrap
10059 var after = function(){
10060 el.fxUnwrap(wrap, r.pos, o);
10061 st.width = r.width;
10062 st.height = r.height;
10065 // time to calc the positions
10066 var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
10068 switch(anchor.toLowerCase()){
10070 wrap.setSize(b.width, 0);
10071 st.left = st.bottom = "0";
10075 wrap.setSize(0, b.height);
10076 st.right = st.top = "0";
10080 wrap.setSize(0, b.height);
10081 wrap.setX(b.right);
10082 st.left = st.top = "0";
10083 a = {width: bw, points: pt};
10086 wrap.setSize(b.width, 0);
10087 wrap.setY(b.bottom);
10088 st.left = st.top = "0";
10089 a = {height: bh, points: pt};
10092 wrap.setSize(0, 0);
10093 st.right = st.bottom = "0";
10094 a = {width: bw, height: bh};
10097 wrap.setSize(0, 0);
10098 wrap.setY(b.y+b.height);
10099 st.right = st.top = "0";
10100 a = {width: bw, height: bh, points: pt};
10103 wrap.setSize(0, 0);
10104 wrap.setXY([b.right, b.bottom]);
10105 st.left = st.top = "0";
10106 a = {width: bw, height: bh, points: pt};
10109 wrap.setSize(0, 0);
10110 wrap.setX(b.x+b.width);
10111 st.left = st.bottom = "0";
10112 a = {width: bw, height: bh, points: pt};
10115 this.dom.style.visibility = "visible";
10118 arguments.callee.anim = wrap.fxanim(a,
10128 * Slides the element out of view. An anchor point can be optionally passed to set the end point
10129 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
10130 * 'hidden') but block elements will still take up space in the document. The element must be removed
10131 * from the DOM using the 'remove' config option if desired. This function automatically handles
10132 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10135 // default: slide the element out to the top
10138 // custom: slide the element out to the right with a 2-second duration
10139 el.slideOut('r', { duration: 2 });
10141 // common config options shown with default values
10149 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10150 * @param {Object} options (optional) Object literal with any of the Fx config options
10151 * @return {Roo.Element} The Element
10153 slideOut : function(anchor, o){
10154 var el = this.getFxEl();
10157 el.queueFx(o, function(){
10159 anchor = anchor || "t";
10161 // restore values after effect
10162 var r = this.getFxRestore();
10164 var b = this.getBox();
10165 // fixed size for slide
10169 var wrap = this.fxWrap(r.pos, o, "visible");
10171 var st = this.dom.style;
10172 st.visibility = "visible";
10173 st.position = "absolute";
10177 var after = function(){
10179 el.setDisplayed(false);
10184 el.fxUnwrap(wrap, r.pos, o);
10186 st.width = r.width;
10187 st.height = r.height;
10192 var a, zero = {to: 0};
10193 switch(anchor.toLowerCase()){
10195 st.left = st.bottom = "0";
10196 a = {height: zero};
10199 st.right = st.top = "0";
10203 st.left = st.top = "0";
10204 a = {width: zero, points: {to:[b.right, b.y]}};
10207 st.left = st.top = "0";
10208 a = {height: zero, points: {to:[b.x, b.bottom]}};
10211 st.right = st.bottom = "0";
10212 a = {width: zero, height: zero};
10215 st.right = st.top = "0";
10216 a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}};
10219 st.left = st.top = "0";
10220 a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}};
10223 st.left = st.bottom = "0";
10224 a = {width: zero, height: zero, points: {to:[b.right, b.y]}};
10228 arguments.callee.anim = wrap.fxanim(a,
10238 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
10239 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
10240 * The element must be removed from the DOM using the 'remove' config option if desired.
10246 // common config options shown with default values
10254 * @param {Object} options (optional) Object literal with any of the Fx config options
10255 * @return {Roo.Element} The Element
10257 puff : function(o){
10258 var el = this.getFxEl();
10261 el.queueFx(o, function(){
10262 this.clearOpacity();
10265 // restore values after effect
10266 var r = this.getFxRestore();
10267 var st = this.dom.style;
10269 var after = function(){
10271 el.setDisplayed(false);
10278 el.setPositioning(r.pos);
10279 st.width = r.width;
10280 st.height = r.height;
10285 var width = this.getWidth();
10286 var height = this.getHeight();
10288 arguments.callee.anim = this.fxanim({
10289 width : {to: this.adjustWidth(width * 2)},
10290 height : {to: this.adjustHeight(height * 2)},
10291 points : {by: [-(width * .5), -(height * .5)]},
10293 fontSize: {to:200, unit: "%"}
10304 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
10305 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
10306 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
10312 // all config options shown with default values
10320 * @param {Object} options (optional) Object literal with any of the Fx config options
10321 * @return {Roo.Element} The Element
10323 switchOff : function(o){
10324 var el = this.getFxEl();
10327 el.queueFx(o, function(){
10328 this.clearOpacity();
10331 // restore values after effect
10332 var r = this.getFxRestore();
10333 var st = this.dom.style;
10335 var after = function(){
10337 el.setDisplayed(false);
10343 el.setPositioning(r.pos);
10344 st.width = r.width;
10345 st.height = r.height;
10350 this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
10351 this.clearOpacity();
10355 points:{by:[0, this.getHeight() * .5]}
10356 }, o, 'motion', 0.3, 'easeIn', after);
10357 }).defer(100, this);
10364 * Highlights the Element by setting a color (applies to the background-color by default, but can be
10365 * changed using the "attr" config option) and then fading back to the original color. If no original
10366 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
10369 // default: highlight background to yellow
10372 // custom: highlight foreground text to blue for 2 seconds
10373 el.highlight("0000ff", { attr: 'color', duration: 2 });
10375 // common config options shown with default values
10376 el.highlight("ffff9c", {
10377 attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
10378 endColor: (current color) or "ffffff",
10383 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
10384 * @param {Object} options (optional) Object literal with any of the Fx config options
10385 * @return {Roo.Element} The Element
10387 highlight : function(color, o){
10388 var el = this.getFxEl();
10391 el.queueFx(o, function(){
10392 color = color || "ffff9c";
10393 attr = o.attr || "backgroundColor";
10395 this.clearOpacity();
10398 var origColor = this.getColor(attr);
10399 var restoreColor = this.dom.style[attr];
10400 endColor = (o.endColor || origColor) || "ffffff";
10402 var after = function(){
10403 el.dom.style[attr] = restoreColor;
10408 a[attr] = {from: color, to: endColor};
10409 arguments.callee.anim = this.fxanim(a,
10419 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
10422 // default: a single light blue ripple
10425 // custom: 3 red ripples lasting 3 seconds total
10426 el.frame("ff0000", 3, { duration: 3 });
10428 // common config options shown with default values
10429 el.frame("C3DAF9", 1, {
10430 duration: 1 //duration of entire animation (not each individual ripple)
10431 // Note: Easing is not configurable and will be ignored if included
10434 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
10435 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
10436 * @param {Object} options (optional) Object literal with any of the Fx config options
10437 * @return {Roo.Element} The Element
10439 frame : function(color, count, o){
10440 var el = this.getFxEl();
10443 el.queueFx(o, function(){
10444 color = color || "#C3DAF9";
10445 if(color.length == 6){
10446 color = "#" + color;
10448 count = count || 1;
10449 duration = o.duration || 1;
10452 var b = this.getBox();
10453 var animFn = function(){
10454 var proxy = this.createProxy({
10457 visbility:"hidden",
10458 position:"absolute",
10459 "z-index":"35000", // yee haw
10460 border:"0px solid " + color
10463 var scale = Roo.isBorderBox ? 2 : 1;
10465 top:{from:b.y, to:b.y - 20},
10466 left:{from:b.x, to:b.x - 20},
10467 borderWidth:{from:0, to:10},
10468 opacity:{from:1, to:0},
10469 height:{from:b.height, to:(b.height + (20*scale))},
10470 width:{from:b.width, to:(b.width + (20*scale))}
10471 }, duration, function(){
10475 animFn.defer((duration/2)*1000, this);
10486 * Creates a pause before any subsequent queued effects begin. If there are
10487 * no effects queued after the pause it will have no effect.
10492 * @param {Number} seconds The length of time to pause (in seconds)
10493 * @return {Roo.Element} The Element
10495 pause : function(seconds){
10496 var el = this.getFxEl();
10499 el.queueFx(o, function(){
10500 setTimeout(function(){
10502 }, seconds * 1000);
10508 * Fade an element in (from transparent to opaque). The ending opacity can be specified
10509 * using the "endOpacity" config option.
10512 // default: fade in from opacity 0 to 100%
10515 // custom: fade in from opacity 0 to 75% over 2 seconds
10516 el.fadeIn({ endOpacity: .75, duration: 2});
10518 // common config options shown with default values
10520 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
10525 * @param {Object} options (optional) Object literal with any of the Fx config options
10526 * @return {Roo.Element} The Element
10528 fadeIn : function(o){
10529 var el = this.getFxEl();
10531 el.queueFx(o, function(){
10532 this.setOpacity(0);
10534 this.dom.style.visibility = 'visible';
10535 var to = o.endOpacity || 1;
10536 arguments.callee.anim = this.fxanim({opacity:{to:to}},
10537 o, null, .5, "easeOut", function(){
10539 this.clearOpacity();
10548 * Fade an element out (from opaque to transparent). The ending opacity can be specified
10549 * using the "endOpacity" config option.
10552 // default: fade out from the element's current opacity to 0
10555 // custom: fade out from the element's current opacity to 25% over 2 seconds
10556 el.fadeOut({ endOpacity: .25, duration: 2});
10558 // common config options shown with default values
10560 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
10567 * @param {Object} options (optional) Object literal with any of the Fx config options
10568 * @return {Roo.Element} The Element
10570 fadeOut : function(o){
10571 var el = this.getFxEl();
10573 el.queueFx(o, function(){
10574 arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
10575 o, null, .5, "easeOut", function(){
10576 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
10577 this.dom.style.display = "none";
10579 this.dom.style.visibility = "hidden";
10581 this.clearOpacity();
10589 * Animates the transition of an element's dimensions from a starting height/width
10590 * to an ending height/width.
10593 // change height and width to 100x100 pixels
10594 el.scale(100, 100);
10596 // common config options shown with default values. The height and width will default to
10597 // the element's existing values if passed as null.
10600 [element's height], {
10605 * @param {Number} width The new width (pass undefined to keep the original width)
10606 * @param {Number} height The new height (pass undefined to keep the original height)
10607 * @param {Object} options (optional) Object literal with any of the Fx config options
10608 * @return {Roo.Element} The Element
10610 scale : function(w, h, o){
10611 this.shift(Roo.apply({}, o, {
10619 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
10620 * Any of these properties not specified in the config object will not be changed. This effect
10621 * requires that at least one new dimension, position or opacity setting must be passed in on
10622 * the config object in order for the function to have any effect.
10625 // slide the element horizontally to x position 200 while changing the height and opacity
10626 el.shift({ x: 200, height: 50, opacity: .8 });
10628 // common config options shown with default values.
10630 width: [element's width],
10631 height: [element's height],
10632 x: [element's x position],
10633 y: [element's y position],
10634 opacity: [element's opacity],
10639 * @param {Object} options Object literal with any of the Fx config options
10640 * @return {Roo.Element} The Element
10642 shift : function(o){
10643 var el = this.getFxEl();
10645 el.queueFx(o, function(){
10646 var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity;
10647 if(w !== undefined){
10648 a.width = {to: this.adjustWidth(w)};
10650 if(h !== undefined){
10651 a.height = {to: this.adjustHeight(h)};
10653 if(x !== undefined || y !== undefined){
10655 x !== undefined ? x : this.getX(),
10656 y !== undefined ? y : this.getY()
10659 if(op !== undefined){
10660 a.opacity = {to: op};
10662 if(o.xy !== undefined){
10663 a.points = {to: o.xy};
10665 arguments.callee.anim = this.fxanim(a,
10666 o, 'motion', .35, "easeOut", function(){
10674 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
10675 * ending point of the effect.
10678 // default: slide the element downward while fading out
10681 // custom: slide the element out to the right with a 2-second duration
10682 el.ghost('r', { duration: 2 });
10684 // common config options shown with default values
10692 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
10693 * @param {Object} options (optional) Object literal with any of the Fx config options
10694 * @return {Roo.Element} The Element
10696 ghost : function(anchor, o){
10697 var el = this.getFxEl();
10700 el.queueFx(o, function(){
10701 anchor = anchor || "b";
10703 // restore values after effect
10704 var r = this.getFxRestore();
10705 var w = this.getWidth(),
10706 h = this.getHeight();
10708 var st = this.dom.style;
10710 var after = function(){
10712 el.setDisplayed(false);
10718 el.setPositioning(r.pos);
10719 st.width = r.width;
10720 st.height = r.height;
10725 var a = {opacity: {to: 0}, points: {}}, pt = a.points;
10726 switch(anchor.toLowerCase()){
10753 arguments.callee.anim = this.fxanim(a,
10763 * Ensures that all effects queued after syncFx is called on the element are
10764 * run concurrently. This is the opposite of {@link #sequenceFx}.
10765 * @return {Roo.Element} The Element
10767 syncFx : function(){
10768 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10777 * Ensures that all effects queued after sequenceFx is called on the element are
10778 * run in sequence. This is the opposite of {@link #syncFx}.
10779 * @return {Roo.Element} The Element
10781 sequenceFx : function(){
10782 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10784 concurrent : false,
10791 nextFx : function(){
10792 var ef = this.fxQueue[0];
10799 * Returns true if the element has any effects actively running or queued, else returns false.
10800 * @return {Boolean} True if element has active effects, else false
10802 hasActiveFx : function(){
10803 return this.fxQueue && this.fxQueue[0];
10807 * Stops any running effects and clears the element's internal effects queue if it contains
10808 * any additional effects that haven't started yet.
10809 * @return {Roo.Element} The Element
10811 stopFx : function(){
10812 if(this.hasActiveFx()){
10813 var cur = this.fxQueue[0];
10814 if(cur && cur.anim && cur.anim.isAnimated()){
10815 this.fxQueue = [cur]; // clear out others
10816 cur.anim.stop(true);
10823 beforeFx : function(o){
10824 if(this.hasActiveFx() && !o.concurrent){
10835 * Returns true if the element is currently blocking so that no other effect can be queued
10836 * until this effect is finished, else returns false if blocking is not set. This is commonly
10837 * used to ensure that an effect initiated by a user action runs to completion prior to the
10838 * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
10839 * @return {Boolean} True if blocking, else false
10841 hasFxBlock : function(){
10842 var q = this.fxQueue;
10843 return q && q[0] && q[0].block;
10847 queueFx : function(o, fn){
10851 if(!this.hasFxBlock()){
10852 Roo.applyIf(o, this.fxDefaults);
10854 var run = this.beforeFx(o);
10855 fn.block = o.block;
10856 this.fxQueue.push(fn);
10868 fxWrap : function(pos, o, vis){
10870 if(!o.wrap || !(wrap = Roo.get(o.wrap))){
10873 wrapXY = this.getXY();
10875 var div = document.createElement("div");
10876 div.style.visibility = vis;
10877 wrap = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
10878 wrap.setPositioning(pos);
10879 if(wrap.getStyle("position") == "static"){
10880 wrap.position("relative");
10882 this.clearPositioning('auto');
10884 wrap.dom.appendChild(this.dom);
10886 wrap.setXY(wrapXY);
10893 fxUnwrap : function(wrap, pos, o){
10894 this.clearPositioning();
10895 this.setPositioning(pos);
10897 wrap.dom.parentNode.insertBefore(this.dom, wrap.dom);
10903 getFxRestore : function(){
10904 var st = this.dom.style;
10905 return {pos: this.getPositioning(), width: st.width, height : st.height};
10909 afterFx : function(o){
10911 this.applyStyles(o.afterStyle);
10914 this.addClass(o.afterCls);
10916 if(o.remove === true){
10919 Roo.callback(o.callback, o.scope, [this]);
10921 this.fxQueue.shift();
10927 getFxEl : function(){ // support for composite element fx
10928 return Roo.get(this.dom);
10932 fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
10933 animType = animType || 'run';
10935 var anim = Roo.lib.Anim[animType](
10937 (opt.duration || defaultDur) || .35,
10938 (opt.easing || defaultEase) || 'easeOut',
10940 Roo.callback(cb, this);
10949 // backwords compat
10950 Roo.Fx.resize = Roo.Fx.scale;
10952 //When included, Roo.Fx is automatically applied to Element so that all basic
10953 //effects are available directly via the Element API
10954 Roo.apply(Roo.Element.prototype, Roo.Fx);/*
10956 * Ext JS Library 1.1.1
10957 * Copyright(c) 2006-2007, Ext JS, LLC.
10959 * Originally Released Under LGPL - original licence link has changed is not relivant.
10962 * <script type="text/javascript">
10967 * @class Roo.CompositeElement
10968 * Standard composite class. Creates a Roo.Element for every element in the collection.
10970 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
10971 * actions will be performed on all the elements in this collection.</b>
10973 * All methods return <i>this</i> and can be chained.
10975 var els = Roo.select("#some-el div.some-class", true);
10976 // or select directly from an existing element
10977 var el = Roo.get('some-el');
10978 el.select('div.some-class', true);
10980 els.setWidth(100); // all elements become 100 width
10981 els.hide(true); // all elements fade out and hide
10983 els.setWidth(100).hide(true);
10986 Roo.CompositeElement = function(els){
10987 this.elements = [];
10988 this.addElements(els);
10990 Roo.CompositeElement.prototype = {
10992 addElements : function(els){
10993 if(!els) return this;
10994 if(typeof els == "string"){
10995 els = Roo.Element.selectorFunction(els);
10997 var yels = this.elements;
10998 var index = yels.length-1;
10999 for(var i = 0, len = els.length; i < len; i++) {
11000 yels[++index] = Roo.get(els[i]);
11006 * Clears this composite and adds the elements returned by the passed selector.
11007 * @param {String/Array} els A string CSS selector, an array of elements or an element
11008 * @return {CompositeElement} this
11010 fill : function(els){
11011 this.elements = [];
11017 * Filters this composite to only elements that match the passed selector.
11018 * @param {String} selector A string CSS selector
11019 * @param {Boolean} inverse return inverse filter (not matches)
11020 * @return {CompositeElement} this
11022 filter : function(selector, inverse){
11024 inverse = inverse || false;
11025 this.each(function(el){
11026 var match = inverse ? !el.is(selector) : el.is(selector);
11028 els[els.length] = el.dom;
11035 invoke : function(fn, args){
11036 var els = this.elements;
11037 for(var i = 0, len = els.length; i < len; i++) {
11038 Roo.Element.prototype[fn].apply(els[i], args);
11043 * Adds elements to this composite.
11044 * @param {String/Array} els A string CSS selector, an array of elements or an element
11045 * @return {CompositeElement} this
11047 add : function(els){
11048 if(typeof els == "string"){
11049 this.addElements(Roo.Element.selectorFunction(els));
11050 }else if(els.length !== undefined){
11051 this.addElements(els);
11053 this.addElements([els]);
11058 * Calls the passed function passing (el, this, index) for each element in this composite.
11059 * @param {Function} fn The function to call
11060 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11061 * @return {CompositeElement} this
11063 each : function(fn, scope){
11064 var els = this.elements;
11065 for(var i = 0, len = els.length; i < len; i++){
11066 if(fn.call(scope || els[i], els[i], this, i) === false) {
11074 * Returns the Element object at the specified index
11075 * @param {Number} index
11076 * @return {Roo.Element}
11078 item : function(index){
11079 return this.elements[index] || null;
11083 * Returns the first Element
11084 * @return {Roo.Element}
11086 first : function(){
11087 return this.item(0);
11091 * Returns the last Element
11092 * @return {Roo.Element}
11095 return this.item(this.elements.length-1);
11099 * Returns the number of elements in this composite
11102 getCount : function(){
11103 return this.elements.length;
11107 * Returns true if this composite contains the passed element
11110 contains : function(el){
11111 return this.indexOf(el) !== -1;
11115 * Returns true if this composite contains the passed element
11118 indexOf : function(el){
11119 return this.elements.indexOf(Roo.get(el));
11124 * Removes the specified element(s).
11125 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
11126 * or an array of any of those.
11127 * @param {Boolean} removeDom (optional) True to also remove the element from the document
11128 * @return {CompositeElement} this
11130 removeElement : function(el, removeDom){
11131 if(el instanceof Array){
11132 for(var i = 0, len = el.length; i < len; i++){
11133 this.removeElement(el[i]);
11137 var index = typeof el == 'number' ? el : this.indexOf(el);
11140 var d = this.elements[index];
11144 d.parentNode.removeChild(d);
11147 this.elements.splice(index, 1);
11153 * Replaces the specified element with the passed element.
11154 * @param {String/HTMLElement/Element/Number} el The id of an element, the Element itself, the index of the element in this composite
11156 * @param {String/HTMLElement/Element} replacement The id of an element or the Element itself.
11157 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
11158 * @return {CompositeElement} this
11160 replaceElement : function(el, replacement, domReplace){
11161 var index = typeof el == 'number' ? el : this.indexOf(el);
11164 this.elements[index].replaceWith(replacement);
11166 this.elements.splice(index, 1, Roo.get(replacement))
11173 * Removes all elements.
11175 clear : function(){
11176 this.elements = [];
11180 Roo.CompositeElement.createCall = function(proto, fnName){
11181 if(!proto[fnName]){
11182 proto[fnName] = function(){
11183 return this.invoke(fnName, arguments);
11187 for(var fnName in Roo.Element.prototype){
11188 if(typeof Roo.Element.prototype[fnName] == "function"){
11189 Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
11195 * Ext JS Library 1.1.1
11196 * Copyright(c) 2006-2007, Ext JS, LLC.
11198 * Originally Released Under LGPL - original licence link has changed is not relivant.
11201 * <script type="text/javascript">
11205 * @class Roo.CompositeElementLite
11206 * @extends Roo.CompositeElement
11207 * Flyweight composite class. Reuses the same Roo.Element for element operations.
11209 var els = Roo.select("#some-el div.some-class");
11210 // or select directly from an existing element
11211 var el = Roo.get('some-el');
11212 el.select('div.some-class');
11214 els.setWidth(100); // all elements become 100 width
11215 els.hide(true); // all elements fade out and hide
11217 els.setWidth(100).hide(true);
11218 </code></pre><br><br>
11219 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
11220 * actions will be performed on all the elements in this collection.</b>
11222 Roo.CompositeElementLite = function(els){
11223 Roo.CompositeElementLite.superclass.constructor.call(this, els);
11224 this.el = new Roo.Element.Flyweight();
11226 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
11227 addElements : function(els){
11229 if(els instanceof Array){
11230 this.elements = this.elements.concat(els);
11232 var yels = this.elements;
11233 var index = yels.length-1;
11234 for(var i = 0, len = els.length; i < len; i++) {
11235 yels[++index] = els[i];
11241 invoke : function(fn, args){
11242 var els = this.elements;
11244 for(var i = 0, len = els.length; i < len; i++) {
11246 Roo.Element.prototype[fn].apply(el, args);
11251 * Returns a flyweight Element of the dom element object at the specified index
11252 * @param {Number} index
11253 * @return {Roo.Element}
11255 item : function(index){
11256 if(!this.elements[index]){
11259 this.el.dom = this.elements[index];
11263 // fixes scope with flyweight
11264 addListener : function(eventName, handler, scope, opt){
11265 var els = this.elements;
11266 for(var i = 0, len = els.length; i < len; i++) {
11267 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
11273 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
11274 * passed is the flyweight (shared) Roo.Element instance, so if you require a
11275 * a reference to the dom node, use el.dom.</b>
11276 * @param {Function} fn The function to call
11277 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11278 * @return {CompositeElement} this
11280 each : function(fn, scope){
11281 var els = this.elements;
11283 for(var i = 0, len = els.length; i < len; i++){
11285 if(fn.call(scope || el, el, this, i) === false){
11292 indexOf : function(el){
11293 return this.elements.indexOf(Roo.getDom(el));
11296 replaceElement : function(el, replacement, domReplace){
11297 var index = typeof el == 'number' ? el : this.indexOf(el);
11299 replacement = Roo.getDom(replacement);
11301 var d = this.elements[index];
11302 d.parentNode.insertBefore(replacement, d);
11303 d.parentNode.removeChild(d);
11305 this.elements.splice(index, 1, replacement);
11310 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
11314 * Ext JS Library 1.1.1
11315 * Copyright(c) 2006-2007, Ext JS, LLC.
11317 * Originally Released Under LGPL - original licence link has changed is not relivant.
11320 * <script type="text/javascript">
11326 * @class Roo.data.Connection
11327 * @extends Roo.util.Observable
11328 * The class encapsulates a connection to the page's originating domain, allowing requests to be made
11329 * either to a configured URL, or to a URL specified at request time.<br><br>
11331 * Requests made by this class are asynchronous, and will return immediately. No data from
11332 * the server will be available to the statement immediately following the {@link #request} call.
11333 * To process returned data, use a callback in the request options object, or an event listener.</p><br>
11335 * Note: If you are doing a file upload, you will not get a normal response object sent back to
11336 * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest.
11337 * The response object is created using the innerHTML of the IFRAME's document as the responseText
11338 * property and, if present, the IFRAME's XML document as the responseXML property.</p><br>
11339 * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested
11340 * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText
11341 * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using
11342 * standard DOM methods.
11344 * @param {Object} config a configuration object.
11346 Roo.data.Connection = function(config){
11347 Roo.apply(this, config);
11350 * @event beforerequest
11351 * Fires before a network request is made to retrieve a data object.
11352 * @param {Connection} conn This Connection object.
11353 * @param {Object} options The options config object passed to the {@link #request} method.
11355 "beforerequest" : true,
11357 * @event requestcomplete
11358 * Fires if the request was successfully completed.
11359 * @param {Connection} conn This Connection object.
11360 * @param {Object} response The XHR object containing the response data.
11361 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11362 * @param {Object} options The options config object passed to the {@link #request} method.
11364 "requestcomplete" : true,
11366 * @event requestexception
11367 * Fires if an error HTTP status was returned from the server.
11368 * See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
11369 * @param {Connection} conn This Connection object.
11370 * @param {Object} response The XHR object containing the response data.
11371 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11372 * @param {Object} options The options config object passed to the {@link #request} method.
11374 "requestexception" : true
11376 Roo.data.Connection.superclass.constructor.call(this);
11379 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
11381 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11384 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11385 * extra parameters to each request made by this object. (defaults to undefined)
11388 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11389 * to each request made by this object. (defaults to undefined)
11392 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11395 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11399 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11405 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11408 disableCaching: true,
11411 * Sends an HTTP request to a remote server.
11412 * @param {Object} options An object which may contain the following properties:<ul>
11413 * <li><b>url</b> {String} (Optional) The URL to which to send the request. Defaults to configured URL</li>
11414 * <li><b>params</b> {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
11415 * request, a url encoded string or a function to call to get either.</li>
11416 * <li><b>method</b> {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or
11417 * if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.</li>
11418 * <li><b>callback</b> {Function} (Optional) The function to be called upon receipt of the HTTP response.
11419 * The callback is called regardless of success or failure and is passed the following parameters:<ul>
11420 * <li>options {Object} The parameter to the request call.</li>
11421 * <li>success {Boolean} True if the request succeeded.</li>
11422 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11424 * <li><b>success</b> {Function} (Optional) The function to be called upon success of the request.
11425 * The callback is passed the following parameters:<ul>
11426 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11427 * <li>options {Object} The parameter to the request call.</li>
11429 * <li><b>failure</b> {Function} (Optional) The function to be called upon failure of the request.
11430 * The callback is passed the following parameters:<ul>
11431 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11432 * <li>options {Object} The parameter to the request call.</li>
11434 * <li><b>scope</b> {Object} (Optional) The scope in which to execute the callbacks: The "this" object
11435 * for the callback function. Defaults to the browser window.</li>
11436 * <li><b>form</b> {Object/String} (Optional) A form object or id to pull parameters from.</li>
11437 * <li><b>isUpload</b> {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).</li>
11438 * <li><b>headers</b> {Object} (Optional) Request headers to set for the request.</li>
11439 * <li><b>xmlData</b> {Object} (Optional) XML document to use for the post. Note: This will be used instead of
11440 * params for the post data. Any params will be appended to the URL.</li>
11441 * <li><b>disableCaching</b> {Boolean} (Optional) True to add a unique cache-buster param to GET requests.</li>
11443 * @return {Number} transactionId
11445 request : function(o){
11446 if(this.fireEvent("beforerequest", this, o) !== false){
11449 if(typeof p == "function"){
11450 p = p.call(o.scope||window, o);
11452 if(typeof p == "object"){
11453 p = Roo.urlEncode(o.params);
11455 if(this.extraParams){
11456 var extras = Roo.urlEncode(this.extraParams);
11457 p = p ? (p + '&' + extras) : extras;
11460 var url = o.url || this.url;
11461 if(typeof url == 'function'){
11462 url = url.call(o.scope||window, o);
11466 var form = Roo.getDom(o.form);
11467 url = url || form.action;
11469 var enctype = form.getAttribute("enctype");
11470 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
11471 return this.doFormUpload(o, p, url);
11473 var f = Roo.lib.Ajax.serializeForm(form);
11474 p = p ? (p + '&' + f) : f;
11477 var hs = o.headers;
11478 if(this.defaultHeaders){
11479 hs = Roo.apply(hs || {}, this.defaultHeaders);
11486 success: this.handleResponse,
11487 failure: this.handleFailure,
11489 argument: {options: o},
11490 timeout : o.timeout || this.timeout
11493 var method = o.method||this.method||(p ? "POST" : "GET");
11495 if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
11496 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
11499 if(typeof o.autoAbort == 'boolean'){ // options gets top priority
11503 }else if(this.autoAbort !== false){
11507 if((method == 'GET' && p) || o.xmlData){
11508 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11511 this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
11512 return this.transId;
11514 Roo.callback(o.callback, o.scope, [o, null, null]);
11520 * Determine whether this object has a request outstanding.
11521 * @param {Number} transactionId (Optional) defaults to the last transaction
11522 * @return {Boolean} True if there is an outstanding request.
11524 isLoading : function(transId){
11526 return Roo.lib.Ajax.isCallInProgress(transId);
11528 return this.transId ? true : false;
11533 * Aborts any outstanding request.
11534 * @param {Number} transactionId (Optional) defaults to the last transaction
11536 abort : function(transId){
11537 if(transId || this.isLoading()){
11538 Roo.lib.Ajax.abort(transId || this.transId);
11543 handleResponse : function(response){
11544 this.transId = false;
11545 var options = response.argument.options;
11546 response.argument = options ? options.argument : null;
11547 this.fireEvent("requestcomplete", this, response, options);
11548 Roo.callback(options.success, options.scope, [response, options]);
11549 Roo.callback(options.callback, options.scope, [options, true, response]);
11553 handleFailure : function(response, e){
11554 this.transId = false;
11555 var options = response.argument.options;
11556 response.argument = options ? options.argument : null;
11557 this.fireEvent("requestexception", this, response, options, e);
11558 Roo.callback(options.failure, options.scope, [response, options]);
11559 Roo.callback(options.callback, options.scope, [options, false, response]);
11563 doFormUpload : function(o, ps, url){
11565 var frame = document.createElement('iframe');
11568 frame.className = 'x-hidden';
11570 frame.src = Roo.SSL_SECURE_URL;
11572 document.body.appendChild(frame);
11575 document.frames[id].name = id;
11578 var form = Roo.getDom(o.form);
11580 form.method = 'POST';
11581 form.enctype = form.encoding = 'multipart/form-data';
11587 if(ps){ // add dynamic params
11589 ps = Roo.urlDecode(ps, false);
11591 if(ps.hasOwnProperty(k)){
11592 hd = document.createElement('input');
11593 hd.type = 'hidden';
11596 form.appendChild(hd);
11603 var r = { // bogus response object
11608 r.argument = o ? o.argument : null;
11613 doc = frame.contentWindow.document;
11615 doc = (frame.contentDocument || window.frames[id].document);
11617 if(doc && doc.body){
11618 r.responseText = doc.body.innerHTML;
11620 if(doc && doc.XMLDocument){
11621 r.responseXML = doc.XMLDocument;
11623 r.responseXML = doc;
11630 Roo.EventManager.removeListener(frame, 'load', cb, this);
11632 this.fireEvent("requestcomplete", this, r, o);
11633 Roo.callback(o.success, o.scope, [r, o]);
11634 Roo.callback(o.callback, o.scope, [o, true, r]);
11636 setTimeout(function(){document.body.removeChild(frame);}, 100);
11639 Roo.EventManager.on(frame, 'load', cb, this);
11642 if(hiddens){ // remove dynamic params
11643 for(var i = 0, len = hiddens.length; i < len; i++){
11644 form.removeChild(hiddens[i]);
11651 * Ext JS Library 1.1.1
11652 * Copyright(c) 2006-2007, Ext JS, LLC.
11654 * Originally Released Under LGPL - original licence link has changed is not relivant.
11657 * <script type="text/javascript">
11661 * Global Ajax request class.
11664 * @extends Roo.data.Connection
11667 * @cfg {String} url The default URL to be used for requests to the server. (defaults to undefined)
11668 * @cfg {Object} extraParams An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
11669 * @cfg {Object} defaultHeaders An object containing request headers which are added to each request made by this object. (defaults to undefined)
11670 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11671 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11672 * @cfg {Boolean} autoAbort (Optional) Whether a new request should abort any pending requests. (defaults to false)
11673 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11675 Roo.Ajax = new Roo.data.Connection({
11684 * Serialize the passed form into a url encoded string
11686 * @param {String/HTMLElement} form
11689 serializeForm : function(form){
11690 return Roo.lib.Ajax.serializeForm(form);
11694 * Ext JS Library 1.1.1
11695 * Copyright(c) 2006-2007, Ext JS, LLC.
11697 * Originally Released Under LGPL - original licence link has changed is not relivant.
11700 * <script type="text/javascript">
11705 * @class Roo.UpdateManager
11706 * @extends Roo.util.Observable
11707 * Provides AJAX-style update for Element object.<br><br>
11710 * // Get it from a Roo.Element object
11711 * var el = Roo.get("foo");
11712 * var mgr = el.getUpdateManager();
11713 * mgr.update("http://myserver.com/index.php", "param1=1&param2=2");
11715 * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
11717 * // or directly (returns the same UpdateManager instance)
11718 * var mgr = new Roo.UpdateManager("myElementId");
11719 * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
11720 * mgr.on("update", myFcnNeedsToKnow);
11722 // short handed call directly from the element object
11723 Roo.get("foo").load({
11727 text: "Loading Foo..."
11731 * Create new UpdateManager directly.
11732 * @param {String/HTMLElement/Roo.Element} el The element to update
11733 * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already has an UpdateManager and if it does it returns the same instance. This will skip that check (useful for extending this class).
11735 Roo.UpdateManager = function(el, forceNew){
11737 if(!forceNew && el.updateManager){
11738 return el.updateManager;
11741 * The Element object
11742 * @type Roo.Element
11746 * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
11749 this.defaultUrl = null;
11753 * @event beforeupdate
11754 * Fired before an update is made, return false from your handler and the update is cancelled.
11755 * @param {Roo.Element} el
11756 * @param {String/Object/Function} url
11757 * @param {String/Object} params
11759 "beforeupdate": true,
11762 * Fired after successful update is made.
11763 * @param {Roo.Element} el
11764 * @param {Object} oResponseObject The response Object
11769 * Fired on update failure.
11770 * @param {Roo.Element} el
11771 * @param {Object} oResponseObject The response Object
11775 var d = Roo.UpdateManager.defaults;
11777 * Blank page URL to use with SSL file uploads (Defaults to Roo.UpdateManager.defaults.sslBlankUrl or "about:blank").
11780 this.sslBlankUrl = d.sslBlankUrl;
11782 * Whether to append unique parameter on get request to disable caching (Defaults to Roo.UpdateManager.defaults.disableCaching or false).
11785 this.disableCaching = d.disableCaching;
11787 * Text for loading indicator (Defaults to Roo.UpdateManager.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>').
11790 this.indicatorText = d.indicatorText;
11792 * Whether to show indicatorText when loading (Defaults to Roo.UpdateManager.defaults.showLoadIndicator or true).
11795 this.showLoadIndicator = d.showLoadIndicator;
11797 * Timeout for requests or form posts in seconds (Defaults to Roo.UpdateManager.defaults.timeout or 30 seconds).
11800 this.timeout = d.timeout;
11803 * True to process scripts in the output (Defaults to Roo.UpdateManager.defaults.loadScripts (false)).
11806 this.loadScripts = d.loadScripts;
11809 * Transaction object of current executing transaction
11811 this.transaction = null;
11816 this.autoRefreshProcId = null;
11818 * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
11821 this.refreshDelegate = this.refresh.createDelegate(this);
11823 * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
11826 this.updateDelegate = this.update.createDelegate(this);
11828 * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
11831 this.formUpdateDelegate = this.formUpdate.createDelegate(this);
11835 this.successDelegate = this.processSuccess.createDelegate(this);
11839 this.failureDelegate = this.processFailure.createDelegate(this);
11841 if(!this.renderer){
11843 * The renderer for this UpdateManager. Defaults to {@link Roo.UpdateManager.BasicRenderer}.
11845 this.renderer = new Roo.UpdateManager.BasicRenderer();
11848 Roo.UpdateManager.superclass.constructor.call(this);
11851 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
11853 * Get the Element this UpdateManager is bound to
11854 * @return {Roo.Element} The element
11856 getEl : function(){
11860 * Performs an async request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
11861 * @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
11864 url: "your-url.php",<br/>
11865 params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
11866 callback: yourFunction,<br/>
11867 scope: yourObject, //(optional scope) <br/>
11868 discardUrl: false, <br/>
11869 nocache: false,<br/>
11870 text: "Loading...",<br/>
11872 scripts: false<br/>
11875 * The only required property is url. The optional properties nocache, text and scripts
11876 * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this UpdateManager instance.
11877 * @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}
11878 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11879 * @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.
11881 update : function(url, params, callback, discardUrl){
11882 if(this.fireEvent("beforeupdate", this.el, url, params) !== false){
11883 var method = this.method,
11885 if(typeof url == "object"){ // must be config object
11888 params = params || cfg.params;
11889 callback = callback || cfg.callback;
11890 discardUrl = discardUrl || cfg.discardUrl;
11891 if(callback && cfg.scope){
11892 callback = callback.createDelegate(cfg.scope);
11894 if(typeof cfg.method != "undefined"){method = cfg.method;};
11895 if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
11896 if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
11897 if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
11898 if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
11900 this.showLoading();
11902 this.defaultUrl = url;
11904 if(typeof url == "function"){
11905 url = url.call(this);
11908 method = method || (params ? "POST" : "GET");
11909 if(method == "GET"){
11910 url = this.prepareUrl(url);
11913 var o = Roo.apply(cfg ||{}, {
11916 success: this.successDelegate,
11917 failure: this.failureDelegate,
11918 callback: undefined,
11919 timeout: (this.timeout*1000),
11920 argument: {"url": url, "form": null, "callback": callback, "params": params}
11922 Roo.log("updated manager called with timeout of " + o.timeout);
11923 this.transaction = Roo.Ajax.request(o);
11928 * Performs an async form post, updating this element with the response. If the form has the attribute enctype="multipart/form-data", it assumes it's a file upload.
11929 * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.
11930 * @param {String/HTMLElement} form The form Id or form element
11931 * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
11932 * @param {Boolean} reset (optional) Whether to try to reset the form after the update
11933 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11935 formUpdate : function(form, url, reset, callback){
11936 if(this.fireEvent("beforeupdate", this.el, form, url) !== false){
11937 if(typeof url == "function"){
11938 url = url.call(this);
11940 form = Roo.getDom(form);
11941 this.transaction = Roo.Ajax.request({
11944 success: this.successDelegate,
11945 failure: this.failureDelegate,
11946 timeout: (this.timeout*1000),
11947 argument: {"url": url, "form": form, "callback": callback, "reset": reset}
11949 this.showLoading.defer(1, this);
11954 * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
11955 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11957 refresh : function(callback){
11958 if(this.defaultUrl == null){
11961 this.update(this.defaultUrl, null, callback, true);
11965 * Set this element to auto refresh.
11966 * @param {Number} interval How often to update (in seconds).
11967 * @param {String/Function} url (optional) The url for this request or a function to call to get the url (Defaults to the last used url)
11968 * @param {String/Object} params (optional) The parameters to pass as either a url encoded string "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2}
11969 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
11970 * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
11972 startAutoRefresh : function(interval, url, params, callback, refreshNow){
11974 this.update(url || this.defaultUrl, params, callback, true);
11976 if(this.autoRefreshProcId){
11977 clearInterval(this.autoRefreshProcId);
11979 this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);
11983 * Stop auto refresh on this element.
11985 stopAutoRefresh : function(){
11986 if(this.autoRefreshProcId){
11987 clearInterval(this.autoRefreshProcId);
11988 delete this.autoRefreshProcId;
11992 isAutoRefreshing : function(){
11993 return this.autoRefreshProcId ? true : false;
11996 * Called to update the element to "Loading" state. Override to perform custom action.
11998 showLoading : function(){
11999 if(this.showLoadIndicator){
12000 this.el.update(this.indicatorText);
12005 * Adds unique parameter to query string if disableCaching = true
12008 prepareUrl : function(url){
12009 if(this.disableCaching){
12010 var append = "_dc=" + (new Date().getTime());
12011 if(url.indexOf("?") !== -1){
12012 url += "&" + append;
12014 url += "?" + append;
12023 processSuccess : function(response){
12024 this.transaction = null;
12025 if(response.argument.form && response.argument.reset){
12026 try{ // put in try/catch since some older FF releases had problems with this
12027 response.argument.form.reset();
12030 if(this.loadScripts){
12031 this.renderer.render(this.el, response, this,
12032 this.updateComplete.createDelegate(this, [response]));
12034 this.renderer.render(this.el, response, this);
12035 this.updateComplete(response);
12039 updateComplete : function(response){
12040 this.fireEvent("update", this.el, response);
12041 if(typeof response.argument.callback == "function"){
12042 response.argument.callback(this.el, true, response);
12049 processFailure : function(response){
12050 this.transaction = null;
12051 this.fireEvent("failure", this.el, response);
12052 if(typeof response.argument.callback == "function"){
12053 response.argument.callback(this.el, false, response);
12058 * Set the content renderer for this UpdateManager. See {@link Roo.UpdateManager.BasicRenderer#render} for more details.
12059 * @param {Object} renderer The object implementing the render() method
12061 setRenderer : function(renderer){
12062 this.renderer = renderer;
12065 getRenderer : function(){
12066 return this.renderer;
12070 * Set the defaultUrl used for updates
12071 * @param {String/Function} defaultUrl The url or a function to call to get the url
12073 setDefaultUrl : function(defaultUrl){
12074 this.defaultUrl = defaultUrl;
12078 * Aborts the executing transaction
12080 abort : function(){
12081 if(this.transaction){
12082 Roo.Ajax.abort(this.transaction);
12087 * Returns true if an update is in progress
12088 * @return {Boolean}
12090 isUpdating : function(){
12091 if(this.transaction){
12092 return Roo.Ajax.isLoading(this.transaction);
12099 * @class Roo.UpdateManager.defaults
12100 * @static (not really - but it helps the doc tool)
12101 * The defaults collection enables customizing the default properties of UpdateManager
12103 Roo.UpdateManager.defaults = {
12105 * Timeout for requests or form posts in seconds (Defaults 30 seconds).
12111 * True to process scripts by default (Defaults to false).
12114 loadScripts : false,
12117 * Blank page URL to use with SSL file uploads (Defaults to "javascript:false").
12120 sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
12122 * Whether to append unique parameter on get request to disable caching (Defaults to false).
12125 disableCaching : false,
12127 * Whether to show indicatorText when loading (Defaults to true).
12130 showLoadIndicator : true,
12132 * Text for loading indicator (Defaults to '<div class="loading-indicator">Loading...</div>').
12135 indicatorText : '<div class="loading-indicator">Loading...</div>'
12139 * Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}).
12141 * <pre><code>Roo.UpdateManager.updateElement("my-div", "stuff.php");</code></pre>
12142 * @param {String/HTMLElement/Roo.Element} el The element to update
12143 * @param {String} url The url
12144 * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
12145 * @param {Object} options (optional) A config object with any of the UpdateManager properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}
12148 * @member Roo.UpdateManager
12150 Roo.UpdateManager.updateElement = function(el, url, params, options){
12151 var um = Roo.get(el, true).getUpdateManager();
12152 Roo.apply(um, options);
12153 um.update(url, params, options ? options.callback : null);
12155 // alias for backwards compat
12156 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
12158 * @class Roo.UpdateManager.BasicRenderer
12159 * Default Content renderer. Updates the elements innerHTML with the responseText.
12161 Roo.UpdateManager.BasicRenderer = function(){};
12163 Roo.UpdateManager.BasicRenderer.prototype = {
12165 * This is called when the transaction is completed and it's time to update the element - The BasicRenderer
12166 * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),
12167 * create an object with a "render(el, response)" method and pass it to setRenderer on the UpdateManager.
12168 * @param {Roo.Element} el The element being rendered
12169 * @param {Object} response The YUI Connect response object
12170 * @param {UpdateManager} updateManager The calling update manager
12171 * @param {Function} callback A callback that will need to be called if loadScripts is true on the UpdateManager
12173 render : function(el, response, updateManager, callback){
12174 el.update(response.responseText, updateManager.loadScripts, callback);
12180 * (c)) Alan Knowles
12186 * @class Roo.DomTemplate
12187 * @extends Roo.Template
12188 * An effort at a dom based template engine..
12190 * Similar to XTemplate, except it uses dom parsing to create the template..
12192 * Supported features:
12197 {a_variable} - output encoded.
12198 {a_variable.format:("Y-m-d")} - call a method on the variable
12199 {a_variable:raw} - unencoded output
12200 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
12201 {a_variable:this.method_on_template(...)} - call a method on the template object.
12206 <div roo-for="a_variable or condition.."></div>
12207 <div roo-if="a_variable or condition"></div>
12208 <div roo-exec="some javascript"></div>
12209 <div roo-name="named_template"></div>
12214 Roo.DomTemplate = function()
12216 Roo.DomTemplate.superclass.constructor.apply(this, arguments);
12223 Roo.extend(Roo.DomTemplate, Roo.Template, {
12225 * id counter for sub templates.
12229 * flag to indicate if dom parser is inside a pre,
12230 * it will strip whitespace if not.
12235 * The various sub templates
12243 * basic tag replacing syntax
12246 * // you can fake an object call by doing this
12250 re : /(\{|\%7B)([\w-\.]+)(?:\:([\w\.]*)(?:\(([^)]*?)?\))?)?(\}|\%7D)/g,
12251 //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
12253 iterChild : function (node, method) {
12255 var oldPre = this.inPre;
12256 if (node.tagName == 'PRE') {
12259 for( var i = 0; i < node.childNodes.length; i++) {
12260 method.call(this, node.childNodes[i]);
12262 this.inPre = oldPre;
12268 * compile the template
12270 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
12273 compile: function()
12277 // covert the html into DOM...
12281 doc = document.implementation.createHTMLDocument("");
12282 doc.documentElement.innerHTML = this.html ;
12283 div = doc.documentElement;
12285 // old IE... - nasty -- it causes all sorts of issues.. with
12286 // images getting pulled from server..
12287 div = document.createElement('div');
12288 div.innerHTML = this.html;
12290 //doc.documentElement.innerHTML = htmlBody
12296 this.iterChild(div, function(n) {_t.compileNode(n, true); });
12298 var tpls = this.tpls;
12300 // create a top level template from the snippet..
12302 //Roo.log(div.innerHTML);
12309 body : div.innerHTML,
12322 Roo.each(tpls, function(tp){
12323 this.compileTpl(tp);
12324 this.tpls[tp.id] = tp;
12327 this.master = tpls[0];
12333 compileNode : function(node, istop) {
12338 // skip anything not a tag..
12339 if (node.nodeType != 1) {
12340 if (node.nodeType == 3 && !this.inPre) {
12341 // reduce white space..
12342 node.nodeValue = node.nodeValue.replace(/\s+/g, ' ');
12365 case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
12366 case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
12367 case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
12368 case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
12374 // just itterate children..
12375 this.iterChild(node,this.compileNode);
12378 tpl.uid = this.id++;
12379 tpl.value = node.getAttribute('roo-' + tpl.attr);
12380 node.removeAttribute('roo-'+ tpl.attr);
12381 if (tpl.attr != 'name') {
12382 var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
12383 node.parentNode.replaceChild(placeholder, node);
12386 var placeholder = document.createElement('span');
12387 placeholder.className = 'roo-tpl-' + tpl.value;
12388 node.parentNode.replaceChild(placeholder, node);
12391 // parent now sees '{domtplXXXX}
12392 this.iterChild(node,this.compileNode);
12394 // we should now have node body...
12395 var div = document.createElement('div');
12396 div.appendChild(node);
12398 // this has the unfortunate side effect of converting tagged attributes
12399 // eg. href="{...}" into %7C...%7D
12400 // this has been fixed by searching for those combo's although it's a bit hacky..
12403 tpl.body = div.innerHTML;
12410 switch (tpl.value) {
12411 case '.': tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
12412 case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
12413 default: tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
12418 tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12422 tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12426 tpl.id = tpl.value; // replace non characters???
12432 this.tpls.push(tpl);
12442 * Compile a segment of the template into a 'sub-template'
12448 compileTpl : function(tpl)
12450 var fm = Roo.util.Format;
12451 var useF = this.disableFormats !== true;
12453 var sep = Roo.isGecko ? "+\n" : ",\n";
12455 var undef = function(str) {
12456 Roo.debug && Roo.log("Property not found :" + str);
12460 //Roo.log(tpl.body);
12464 var fn = function(m, lbrace, name, format, args)
12467 //Roo.log(arguments);
12468 args = args ? args.replace(/\\'/g,"'") : args;
12469 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
12470 if (typeof(format) == 'undefined') {
12471 format = 'htmlEncode';
12473 if (format == 'raw' ) {
12477 if(name.substr(0, 6) == 'domtpl'){
12478 return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
12481 // build an array of options to determine if value is undefined..
12483 // basically get 'xxxx.yyyy' then do
12484 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
12485 // (function () { Roo.log("Property not found"); return ''; })() :
12490 Roo.each(name.split('.'), function(st) {
12491 lookfor += (lookfor.length ? '.': '') + st;
12492 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
12495 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
12498 if(format && useF){
12500 args = args ? ',' + args : "";
12502 if(format.substr(0, 5) != "this."){
12503 format = "fm." + format + '(';
12505 format = 'this.call("'+ format.substr(5) + '", ';
12509 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
12512 if (args && args.length) {
12513 // called with xxyx.yuu:(test,test)
12515 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
12517 // raw.. - :raw modifier..
12518 return "'"+ sep + udef_st + name + ")"+sep+"'";
12522 // branched to use + in gecko and [].join() in others
12524 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
12525 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
12528 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
12529 body.push(tpl.body.replace(/(\r\n|\n)/g,
12530 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
12531 body.push("'].join('');};};");
12532 body = body.join('');
12535 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
12537 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
12544 * same as applyTemplate, except it's done to one of the subTemplates
12545 * when using named templates, you can do:
12547 * var str = pl.applySubTemplate('your-name', values);
12550 * @param {Number} id of the template
12551 * @param {Object} values to apply to template
12552 * @param {Object} parent (normaly the instance of this object)
12554 applySubTemplate : function(id, values, parent)
12558 var t = this.tpls[id];
12562 if(t.ifCall && !t.ifCall.call(this, values, parent)){
12563 Roo.debug && Roo.log('if call on ' + t.value + ' return false');
12567 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
12574 if(t.execCall && t.execCall.call(this, values, parent)){
12578 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12584 var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
12585 parent = t.target ? values : parent;
12586 if(t.forCall && vs instanceof Array){
12588 for(var i = 0, len = vs.length; i < len; i++){
12590 buf[buf.length] = t.compiled.call(this, vs[i], parent);
12592 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12594 //Roo.log(t.compiled);
12598 return buf.join('');
12601 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12606 return t.compiled.call(this, vs, parent);
12608 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12610 //Roo.log(t.compiled);
12618 applyTemplate : function(values){
12619 return this.master.compiled.call(this, values, {});
12620 //var s = this.subs;
12623 apply : function(){
12624 return this.applyTemplate.apply(this, arguments);
12629 Roo.DomTemplate.from = function(el){
12630 el = Roo.getDom(el);
12631 return new Roo.Domtemplate(el.value || el.innerHTML);
12634 * Ext JS Library 1.1.1
12635 * Copyright(c) 2006-2007, Ext JS, LLC.
12637 * Originally Released Under LGPL - original licence link has changed is not relivant.
12640 * <script type="text/javascript">
12644 * @class Roo.util.DelayedTask
12645 * Provides a convenient method of performing setTimeout where a new
12646 * timeout cancels the old timeout. An example would be performing validation on a keypress.
12647 * You can use this class to buffer
12648 * the keypress events for a certain number of milliseconds, and perform only if they stop
12649 * for that amount of time.
12650 * @constructor The parameters to this constructor serve as defaults and are not required.
12651 * @param {Function} fn (optional) The default function to timeout
12652 * @param {Object} scope (optional) The default scope of that timeout
12653 * @param {Array} args (optional) The default Array of arguments
12655 Roo.util.DelayedTask = function(fn, scope, args){
12656 var id = null, d, t;
12658 var call = function(){
12659 var now = new Date().getTime();
12663 fn.apply(scope, args || []);
12667 * Cancels any pending timeout and queues a new one
12668 * @param {Number} delay The milliseconds to delay
12669 * @param {Function} newFn (optional) Overrides function passed to constructor
12670 * @param {Object} newScope (optional) Overrides scope passed to constructor
12671 * @param {Array} newArgs (optional) Overrides args passed to constructor
12673 this.delay = function(delay, newFn, newScope, newArgs){
12674 if(id && delay != d){
12678 t = new Date().getTime();
12680 scope = newScope || scope;
12681 args = newArgs || args;
12683 id = setInterval(call, d);
12688 * Cancel the last queued timeout
12690 this.cancel = function(){
12698 * Ext JS Library 1.1.1
12699 * Copyright(c) 2006-2007, Ext JS, LLC.
12701 * Originally Released Under LGPL - original licence link has changed is not relivant.
12704 * <script type="text/javascript">
12708 Roo.util.TaskRunner = function(interval){
12709 interval = interval || 10;
12710 var tasks = [], removeQueue = [];
12712 var running = false;
12714 var stopThread = function(){
12720 var startThread = function(){
12723 id = setInterval(runTasks, interval);
12727 var removeTask = function(task){
12728 removeQueue.push(task);
12734 var runTasks = function(){
12735 if(removeQueue.length > 0){
12736 for(var i = 0, len = removeQueue.length; i < len; i++){
12737 tasks.remove(removeQueue[i]);
12740 if(tasks.length < 1){
12745 var now = new Date().getTime();
12746 for(var i = 0, len = tasks.length; i < len; ++i){
12748 var itime = now - t.taskRunTime;
12749 if(t.interval <= itime){
12750 var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
12751 t.taskRunTime = now;
12752 if(rt === false || t.taskRunCount === t.repeat){
12757 if(t.duration && t.duration <= (now - t.taskStartTime)){
12764 * Queues a new task.
12765 * @param {Object} task
12767 this.start = function(task){
12769 task.taskStartTime = new Date().getTime();
12770 task.taskRunTime = 0;
12771 task.taskRunCount = 0;
12776 this.stop = function(task){
12781 this.stopAll = function(){
12783 for(var i = 0, len = tasks.length; i < len; i++){
12784 if(tasks[i].onStop){
12793 Roo.TaskMgr = new Roo.util.TaskRunner();/*
12795 * Ext JS Library 1.1.1
12796 * Copyright(c) 2006-2007, Ext JS, LLC.
12798 * Originally Released Under LGPL - original licence link has changed is not relivant.
12801 * <script type="text/javascript">
12806 * @class Roo.util.MixedCollection
12807 * @extends Roo.util.Observable
12808 * A Collection class that maintains both numeric indexes and keys and exposes events.
12810 * @param {Boolean} allowFunctions True if the addAll function should add function references to the
12811 * collection (defaults to false)
12812 * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
12813 * and return the key value for that item. This is used when available to look up the key on items that
12814 * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
12815 * equivalent to providing an implementation for the {@link #getKey} method.
12817 Roo.util.MixedCollection = function(allowFunctions, keyFn){
12825 * Fires when the collection is cleared.
12830 * Fires when an item is added to the collection.
12831 * @param {Number} index The index at which the item was added.
12832 * @param {Object} o The item added.
12833 * @param {String} key The key associated with the added item.
12838 * Fires when an item is replaced in the collection.
12839 * @param {String} key he key associated with the new added.
12840 * @param {Object} old The item being replaced.
12841 * @param {Object} new The new item.
12846 * Fires when an item is removed from the collection.
12847 * @param {Object} o The item being removed.
12848 * @param {String} key (optional) The key associated with the removed item.
12853 this.allowFunctions = allowFunctions === true;
12855 this.getKey = keyFn;
12857 Roo.util.MixedCollection.superclass.constructor.call(this);
12860 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
12861 allowFunctions : false,
12864 * Adds an item to the collection.
12865 * @param {String} key The key to associate with the item
12866 * @param {Object} o The item to add.
12867 * @return {Object} The item added.
12869 add : function(key, o){
12870 if(arguments.length == 1){
12872 key = this.getKey(o);
12874 if(typeof key == "undefined" || key === null){
12876 this.items.push(o);
12877 this.keys.push(null);
12879 var old = this.map[key];
12881 return this.replace(key, o);
12884 this.items.push(o);
12886 this.keys.push(key);
12888 this.fireEvent("add", this.length-1, o, key);
12893 * MixedCollection has a generic way to fetch keys if you implement getKey.
12896 var mc = new Roo.util.MixedCollection();
12897 mc.add(someEl.dom.id, someEl);
12898 mc.add(otherEl.dom.id, otherEl);
12902 var mc = new Roo.util.MixedCollection();
12903 mc.getKey = function(el){
12909 // or via the constructor
12910 var mc = new Roo.util.MixedCollection(false, function(el){
12916 * @param o {Object} The item for which to find the key.
12917 * @return {Object} The key for the passed item.
12919 getKey : function(o){
12924 * Replaces an item in the collection.
12925 * @param {String} key The key associated with the item to replace, or the item to replace.
12926 * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
12927 * @return {Object} The new item.
12929 replace : function(key, o){
12930 if(arguments.length == 1){
12932 key = this.getKey(o);
12934 var old = this.item(key);
12935 if(typeof key == "undefined" || key === null || typeof old == "undefined"){
12936 return this.add(key, o);
12938 var index = this.indexOfKey(key);
12939 this.items[index] = o;
12941 this.fireEvent("replace", key, old, o);
12946 * Adds all elements of an Array or an Object to the collection.
12947 * @param {Object/Array} objs An Object containing properties which will be added to the collection, or
12948 * an Array of values, each of which are added to the collection.
12950 addAll : function(objs){
12951 if(arguments.length > 1 || objs instanceof Array){
12952 var args = arguments.length > 1 ? arguments : objs;
12953 for(var i = 0, len = args.length; i < len; i++){
12957 for(var key in objs){
12958 if(this.allowFunctions || typeof objs[key] != "function"){
12959 this.add(key, objs[key]);
12966 * Executes the specified function once for every item in the collection, passing each
12967 * item as the first and only parameter. returning false from the function will stop the iteration.
12968 * @param {Function} fn The function to execute for each item.
12969 * @param {Object} scope (optional) The scope in which to execute the function.
12971 each : function(fn, scope){
12972 var items = [].concat(this.items); // each safe for removal
12973 for(var i = 0, len = items.length; i < len; i++){
12974 if(fn.call(scope || items[i], items[i], i, len) === false){
12981 * Executes the specified function once for every key in the collection, passing each
12982 * key, and its associated item as the first two parameters.
12983 * @param {Function} fn The function to execute for each item.
12984 * @param {Object} scope (optional) The scope in which to execute the function.
12986 eachKey : function(fn, scope){
12987 for(var i = 0, len = this.keys.length; i < len; i++){
12988 fn.call(scope || window, this.keys[i], this.items[i], i, len);
12993 * Returns the first item in the collection which elicits a true return value from the
12994 * passed selection function.
12995 * @param {Function} fn The selection function to execute for each item.
12996 * @param {Object} scope (optional) The scope in which to execute the function.
12997 * @return {Object} The first item in the collection which returned true from the selection function.
12999 find : function(fn, scope){
13000 for(var i = 0, len = this.items.length; i < len; i++){
13001 if(fn.call(scope || window, this.items[i], this.keys[i])){
13002 return this.items[i];
13009 * Inserts an item at the specified index in the collection.
13010 * @param {Number} index The index to insert the item at.
13011 * @param {String} key The key to associate with the new item, or the item itself.
13012 * @param {Object} o (optional) If the second parameter was a key, the new item.
13013 * @return {Object} The item inserted.
13015 insert : function(index, key, o){
13016 if(arguments.length == 2){
13018 key = this.getKey(o);
13020 if(index >= this.length){
13021 return this.add(key, o);
13024 this.items.splice(index, 0, o);
13025 if(typeof key != "undefined" && key != null){
13028 this.keys.splice(index, 0, key);
13029 this.fireEvent("add", index, o, key);
13034 * Removed an item from the collection.
13035 * @param {Object} o The item to remove.
13036 * @return {Object} The item removed.
13038 remove : function(o){
13039 return this.removeAt(this.indexOf(o));
13043 * Remove an item from a specified index in the collection.
13044 * @param {Number} index The index within the collection of the item to remove.
13046 removeAt : function(index){
13047 if(index < this.length && index >= 0){
13049 var o = this.items[index];
13050 this.items.splice(index, 1);
13051 var key = this.keys[index];
13052 if(typeof key != "undefined"){
13053 delete this.map[key];
13055 this.keys.splice(index, 1);
13056 this.fireEvent("remove", o, key);
13061 * Removed an item associated with the passed key fom the collection.
13062 * @param {String} key The key of the item to remove.
13064 removeKey : function(key){
13065 return this.removeAt(this.indexOfKey(key));
13069 * Returns the number of items in the collection.
13070 * @return {Number} the number of items in the collection.
13072 getCount : function(){
13073 return this.length;
13077 * Returns index within the collection of the passed Object.
13078 * @param {Object} o The item to find the index of.
13079 * @return {Number} index of the item.
13081 indexOf : function(o){
13082 if(!this.items.indexOf){
13083 for(var i = 0, len = this.items.length; i < len; i++){
13084 if(this.items[i] == o) return i;
13088 return this.items.indexOf(o);
13093 * Returns index within the collection of the passed key.
13094 * @param {String} key The key to find the index of.
13095 * @return {Number} index of the key.
13097 indexOfKey : function(key){
13098 if(!this.keys.indexOf){
13099 for(var i = 0, len = this.keys.length; i < len; i++){
13100 if(this.keys[i] == key) return i;
13104 return this.keys.indexOf(key);
13109 * Returns the item associated with the passed key OR index. Key has priority over index.
13110 * @param {String/Number} key The key or index of the item.
13111 * @return {Object} The item associated with the passed key.
13113 item : function(key){
13114 var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
13115 return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
13119 * Returns the item at the specified index.
13120 * @param {Number} index The index of the item.
13123 itemAt : function(index){
13124 return this.items[index];
13128 * Returns the item associated with the passed key.
13129 * @param {String/Number} key The key of the item.
13130 * @return {Object} The item associated with the passed key.
13132 key : function(key){
13133 return this.map[key];
13137 * Returns true if the collection contains the passed Object as an item.
13138 * @param {Object} o The Object to look for in the collection.
13139 * @return {Boolean} True if the collection contains the Object as an item.
13141 contains : function(o){
13142 return this.indexOf(o) != -1;
13146 * Returns true if the collection contains the passed Object as a key.
13147 * @param {String} key The key to look for in the collection.
13148 * @return {Boolean} True if the collection contains the Object as a key.
13150 containsKey : function(key){
13151 return typeof this.map[key] != "undefined";
13155 * Removes all items from the collection.
13157 clear : function(){
13162 this.fireEvent("clear");
13166 * Returns the first item in the collection.
13167 * @return {Object} the first item in the collection..
13169 first : function(){
13170 return this.items[0];
13174 * Returns the last item in the collection.
13175 * @return {Object} the last item in the collection..
13178 return this.items[this.length-1];
13181 _sort : function(property, dir, fn){
13182 var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
13183 fn = fn || function(a, b){
13186 var c = [], k = this.keys, items = this.items;
13187 for(var i = 0, len = items.length; i < len; i++){
13188 c[c.length] = {key: k[i], value: items[i], index: i};
13190 c.sort(function(a, b){
13191 var v = fn(a[property], b[property]) * dsc;
13193 v = (a.index < b.index ? -1 : 1);
13197 for(var i = 0, len = c.length; i < len; i++){
13198 items[i] = c[i].value;
13201 this.fireEvent("sort", this);
13205 * Sorts this collection with the passed comparison function
13206 * @param {String} direction (optional) "ASC" or "DESC"
13207 * @param {Function} fn (optional) comparison function
13209 sort : function(dir, fn){
13210 this._sort("value", dir, fn);
13214 * Sorts this collection by keys
13215 * @param {String} direction (optional) "ASC" or "DESC"
13216 * @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
13218 keySort : function(dir, fn){
13219 this._sort("key", dir, fn || function(a, b){
13220 return String(a).toUpperCase()-String(b).toUpperCase();
13225 * Returns a range of items in this collection
13226 * @param {Number} startIndex (optional) defaults to 0
13227 * @param {Number} endIndex (optional) default to the last item
13228 * @return {Array} An array of items
13230 getRange : function(start, end){
13231 var items = this.items;
13232 if(items.length < 1){
13235 start = start || 0;
13236 end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
13239 for(var i = start; i <= end; i++) {
13240 r[r.length] = items[i];
13243 for(var i = start; i >= end; i--) {
13244 r[r.length] = items[i];
13251 * Filter the <i>objects</i> in this collection by a specific property.
13252 * Returns a new collection that has been filtered.
13253 * @param {String} property A property on your objects
13254 * @param {String/RegExp} value Either string that the property values
13255 * should start with or a RegExp to test against the property
13256 * @return {MixedCollection} The new filtered collection
13258 filter : function(property, value){
13259 if(!value.exec){ // not a regex
13260 value = String(value);
13261 if(value.length == 0){
13262 return this.clone();
13264 value = new RegExp("^" + Roo.escapeRe(value), "i");
13266 return this.filterBy(function(o){
13267 return o && value.test(o[property]);
13272 * Filter by a function. * Returns a new collection that has been filtered.
13273 * The passed function will be called with each
13274 * object in the collection. If the function returns true, the value is included
13275 * otherwise it is filtered.
13276 * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
13277 * @param {Object} scope (optional) The scope of the function (defaults to this)
13278 * @return {MixedCollection} The new filtered collection
13280 filterBy : function(fn, scope){
13281 var r = new Roo.util.MixedCollection();
13282 r.getKey = this.getKey;
13283 var k = this.keys, it = this.items;
13284 for(var i = 0, len = it.length; i < len; i++){
13285 if(fn.call(scope||this, it[i], k[i])){
13286 r.add(k[i], it[i]);
13293 * Creates a duplicate of this collection
13294 * @return {MixedCollection}
13296 clone : function(){
13297 var r = new Roo.util.MixedCollection();
13298 var k = this.keys, it = this.items;
13299 for(var i = 0, len = it.length; i < len; i++){
13300 r.add(k[i], it[i]);
13302 r.getKey = this.getKey;
13307 * Returns the item associated with the passed key or index.
13309 * @param {String/Number} key The key or index of the item.
13310 * @return {Object} The item associated with the passed key.
13312 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;/*
13314 * Ext JS Library 1.1.1
13315 * Copyright(c) 2006-2007, Ext JS, LLC.
13317 * Originally Released Under LGPL - original licence link has changed is not relivant.
13320 * <script type="text/javascript">
13323 * @class Roo.util.JSON
13324 * Modified version of Douglas Crockford"s json.js that doesn"t
13325 * mess with the Object prototype
13326 * http://www.json.org/js.html
13329 Roo.util.JSON = new (function(){
13330 var useHasOwn = {}.hasOwnProperty ? true : false;
13332 // crashes Safari in some instances
13333 //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
13335 var pad = function(n) {
13336 return n < 10 ? "0" + n : n;
13349 var encodeString = function(s){
13350 if (/["\\\x00-\x1f]/.test(s)) {
13351 return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
13356 c = b.charCodeAt();
13358 Math.floor(c / 16).toString(16) +
13359 (c % 16).toString(16);
13362 return '"' + s + '"';
13365 var encodeArray = function(o){
13366 var a = ["["], b, i, l = o.length, v;
13367 for (i = 0; i < l; i += 1) {
13369 switch (typeof v) {
13378 a.push(v === null ? "null" : Roo.util.JSON.encode(v));
13386 var encodeDate = function(o){
13387 return '"' + o.getFullYear() + "-" +
13388 pad(o.getMonth() + 1) + "-" +
13389 pad(o.getDate()) + "T" +
13390 pad(o.getHours()) + ":" +
13391 pad(o.getMinutes()) + ":" +
13392 pad(o.getSeconds()) + '"';
13396 * Encodes an Object, Array or other value
13397 * @param {Mixed} o The variable to encode
13398 * @return {String} The JSON string
13400 this.encode = function(o)
13402 // should this be extended to fully wrap stringify..
13404 if(typeof o == "undefined" || o === null){
13406 }else if(o instanceof Array){
13407 return encodeArray(o);
13408 }else if(o instanceof Date){
13409 return encodeDate(o);
13410 }else if(typeof o == "string"){
13411 return encodeString(o);
13412 }else if(typeof o == "number"){
13413 return isFinite(o) ? String(o) : "null";
13414 }else if(typeof o == "boolean"){
13417 var a = ["{"], b, i, v;
13419 if(!useHasOwn || o.hasOwnProperty(i)) {
13421 switch (typeof v) {
13430 a.push(this.encode(i), ":",
13431 v === null ? "null" : this.encode(v));
13442 * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
13443 * @param {String} json The JSON string
13444 * @return {Object} The resulting object
13446 this.decode = function(json){
13448 return /** eval:var:json */ eval("(" + json + ')');
13452 * Shorthand for {@link Roo.util.JSON#encode}
13453 * @member Roo encode
13455 Roo.encode = typeof(JSON) != 'undefined' && JSON.stringify ? JSON.stringify : Roo.util.JSON.encode;
13457 * Shorthand for {@link Roo.util.JSON#decode}
13458 * @member Roo decode
13460 Roo.decode = typeof(JSON) != 'undefined' && JSON.parse ? JSON.parse : Roo.util.JSON.decode;
13463 * Ext JS Library 1.1.1
13464 * Copyright(c) 2006-2007, Ext JS, LLC.
13466 * Originally Released Under LGPL - original licence link has changed is not relivant.
13469 * <script type="text/javascript">
13473 * @class Roo.util.Format
13474 * Reusable data formatting functions
13477 Roo.util.Format = function(){
13478 var trimRe = /^\s+|\s+$/g;
13481 * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
13482 * @param {String} value The string to truncate
13483 * @param {Number} length The maximum length to allow before truncating
13484 * @return {String} The converted text
13486 ellipsis : function(value, len){
13487 if(value && value.length > len){
13488 return value.substr(0, len-3)+"...";
13494 * Checks a reference and converts it to empty string if it is undefined
13495 * @param {Mixed} value Reference to check
13496 * @return {Mixed} Empty string if converted, otherwise the original value
13498 undef : function(value){
13499 return typeof value != "undefined" ? value : "";
13503 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
13504 * @param {String} value The string to encode
13505 * @return {String} The encoded text
13507 htmlEncode : function(value){
13508 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
13512 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
13513 * @param {String} value The string to decode
13514 * @return {String} The decoded text
13516 htmlDecode : function(value){
13517 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
13521 * Trims any whitespace from either side of a string
13522 * @param {String} value The text to trim
13523 * @return {String} The trimmed text
13525 trim : function(value){
13526 return String(value).replace(trimRe, "");
13530 * Returns a substring from within an original string
13531 * @param {String} value The original text
13532 * @param {Number} start The start index of the substring
13533 * @param {Number} length The length of the substring
13534 * @return {String} The substring
13536 substr : function(value, start, length){
13537 return String(value).substr(start, length);
13541 * Converts a string to all lower case letters
13542 * @param {String} value The text to convert
13543 * @return {String} The converted text
13545 lowercase : function(value){
13546 return String(value).toLowerCase();
13550 * Converts a string to all upper case letters
13551 * @param {String} value The text to convert
13552 * @return {String} The converted text
13554 uppercase : function(value){
13555 return String(value).toUpperCase();
13559 * Converts the first character only of a string to upper case
13560 * @param {String} value The text to convert
13561 * @return {String} The converted text
13563 capitalize : function(value){
13564 return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
13568 call : function(value, fn){
13569 if(arguments.length > 2){
13570 var args = Array.prototype.slice.call(arguments, 2);
13571 args.unshift(value);
13573 return /** eval:var:value */ eval(fn).apply(window, args);
13575 /** eval:var:value */
13576 return /** eval:var:value */ eval(fn).call(window, value);
13582 * safer version of Math.toFixed..??/
13583 * @param {Number/String} value The numeric value to format
13584 * @param {Number/String} value Decimal places
13585 * @return {String} The formatted currency string
13587 toFixed : function(v, n)
13589 // why not use to fixed - precision is buggered???
13591 return Math.round(v-0);
13593 var fact = Math.pow(10,n+1);
13594 v = (Math.round((v-0)*fact))/fact;
13595 var z = (''+fact).substring(2);
13596 if (v == Math.floor(v)) {
13597 return Math.floor(v) + '.' + z;
13600 // now just padd decimals..
13601 var ps = String(v).split('.');
13602 var fd = (ps[1] + z);
13603 var r = fd.substring(0,n);
13604 var rm = fd.substring(n);
13606 return ps[0] + '.' + r;
13608 r*=1; // turn it into a number;
13610 if (String(r).length != n) {
13613 r = String(r).substring(1); // chop the end off.
13616 return ps[0] + '.' + r;
13621 * Format a number as US currency
13622 * @param {Number/String} value The numeric value to format
13623 * @return {String} The formatted currency string
13625 usMoney : function(v){
13626 return '$' + Roo.util.Format.number(v);
13631 * eventually this should probably emulate php's number_format
13632 * @param {Number/String} value The numeric value to format
13633 * @param {Number} decimals number of decimal places
13634 * @return {String} The formatted currency string
13636 number : function(v,decimals)
13638 // multiply and round.
13639 decimals = typeof(decimals) == 'undefined' ? 2 : decimals;
13640 var mul = Math.pow(10, decimals);
13641 var zero = String(mul).substring(1);
13642 v = (Math.round((v-0)*mul))/mul;
13644 // if it's '0' number.. then
13646 //v = (v == Math.floor(v)) ? v + "." + zero : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
13648 var ps = v.split('.');
13652 var r = /(\d+)(\d{3})/;
13654 while (r.test(whole)) {
13655 whole = whole.replace(r, '$1' + ',' + '$2');
13661 (decimals ? ('.'+ ps[1] + zero.substring(ps[1].length)) : '') :
13662 // does not have decimals
13663 (decimals ? ('.' + zero) : '');
13666 return whole + sub ;
13670 * Parse a value into a formatted date using the specified format pattern.
13671 * @param {Mixed} value The value to format
13672 * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
13673 * @return {String} The formatted date string
13675 date : function(v, format){
13679 if(!(v instanceof Date)){
13680 v = new Date(Date.parse(v));
13682 return v.dateFormat(format || Roo.util.Format.defaults.date);
13686 * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
13687 * @param {String} format Any valid date format string
13688 * @return {Function} The date formatting function
13690 dateRenderer : function(format){
13691 return function(v){
13692 return Roo.util.Format.date(v, format);
13697 stripTagsRE : /<\/?[^>]+>/gi,
13700 * Strips all HTML tags
13701 * @param {Mixed} value The text from which to strip tags
13702 * @return {String} The stripped text
13704 stripTags : function(v){
13705 return !v ? v : String(v).replace(this.stripTagsRE, "");
13709 Roo.util.Format.defaults = {
13713 * Ext JS Library 1.1.1
13714 * Copyright(c) 2006-2007, Ext JS, LLC.
13716 * Originally Released Under LGPL - original licence link has changed is not relivant.
13719 * <script type="text/javascript">
13726 * @class Roo.MasterTemplate
13727 * @extends Roo.Template
13728 * Provides a template that can have child templates. The syntax is:
13730 var t = new Roo.MasterTemplate(
13731 '<select name="{name}">',
13732 '<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
13735 t.add('options', {value: 'foo', text: 'bar'});
13736 // or you can add multiple child elements in one shot
13737 t.addAll('options', [
13738 {value: 'foo', text: 'bar'},
13739 {value: 'foo2', text: 'bar2'},
13740 {value: 'foo3', text: 'bar3'}
13742 // then append, applying the master template values
13743 t.append('my-form', {name: 'my-select'});
13745 * A name attribute for the child template is not required if you have only one child
13746 * template or you want to refer to them by index.
13748 Roo.MasterTemplate = function(){
13749 Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
13750 this.originalHtml = this.html;
13752 var m, re = this.subTemplateRe;
13755 while(m = re.exec(this.html)){
13756 var name = m[1], content = m[2];
13761 tpl : new Roo.Template(content)
13764 st[name] = st[subIndex];
13766 st[subIndex].tpl.compile();
13767 st[subIndex].tpl.call = this.call.createDelegate(this);
13770 this.subCount = subIndex;
13773 Roo.extend(Roo.MasterTemplate, Roo.Template, {
13775 * The regular expression used to match sub templates
13779 subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
13782 * Applies the passed values to a child template.
13783 * @param {String/Number} name (optional) The name or index of the child template
13784 * @param {Array/Object} values The values to be applied to the template
13785 * @return {MasterTemplate} this
13787 add : function(name, values){
13788 if(arguments.length == 1){
13789 values = arguments[0];
13792 var s = this.subs[name];
13793 s.buffer[s.buffer.length] = s.tpl.apply(values);
13798 * Applies all the passed values to a child template.
13799 * @param {String/Number} name (optional) The name or index of the child template
13800 * @param {Array} values The values to be applied to the template, this should be an array of objects.
13801 * @param {Boolean} reset (optional) True to reset the template first
13802 * @return {MasterTemplate} this
13804 fill : function(name, values, reset){
13806 if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
13814 for(var i = 0, len = values.length; i < len; i++){
13815 this.add(name, values[i]);
13821 * Resets the template for reuse
13822 * @return {MasterTemplate} this
13824 reset : function(){
13826 for(var i = 0; i < this.subCount; i++){
13832 applyTemplate : function(values){
13834 var replaceIndex = -1;
13835 this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
13836 return s[++replaceIndex].buffer.join("");
13838 return Roo.MasterTemplate.superclass.applyTemplate.call(this, values);
13841 apply : function(){
13842 return this.applyTemplate.apply(this, arguments);
13845 compile : function(){return this;}
13849 * Alias for fill().
13852 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
13854 * Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
13855 * var tpl = Roo.MasterTemplate.from('element-id');
13856 * @param {String/HTMLElement} el
13857 * @param {Object} config
13860 Roo.MasterTemplate.from = function(el, config){
13861 el = Roo.getDom(el);
13862 return new Roo.MasterTemplate(el.value || el.innerHTML, config || '');
13865 * Ext JS Library 1.1.1
13866 * Copyright(c) 2006-2007, Ext JS, LLC.
13868 * Originally Released Under LGPL - original licence link has changed is not relivant.
13871 * <script type="text/javascript">
13876 * @class Roo.util.CSS
13877 * Utility class for manipulating CSS rules
13880 Roo.util.CSS = function(){
13882 var doc = document;
13884 var camelRe = /(-[a-z])/gi;
13885 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
13889 * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
13890 * tag and appended to the HEAD of the document.
13891 * @param {String|Object} cssText The text containing the css rules
13892 * @param {String} id An id to add to the stylesheet for later removal
13893 * @return {StyleSheet}
13895 createStyleSheet : function(cssText, id){
13897 var head = doc.getElementsByTagName("head")[0];
13898 var nrules = doc.createElement("style");
13899 nrules.setAttribute("type", "text/css");
13901 nrules.setAttribute("id", id);
13903 if (typeof(cssText) != 'string') {
13904 // support object maps..
13905 // not sure if this a good idea..
13906 // perhaps it should be merged with the general css handling
13907 // and handle js style props.
13908 var cssTextNew = [];
13909 for(var n in cssText) {
13911 for(var k in cssText[n]) {
13912 citems.push( k + ' : ' +cssText[n][k] + ';' );
13914 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
13917 cssText = cssTextNew.join("\n");
13923 head.appendChild(nrules);
13924 ss = nrules.styleSheet;
13925 ss.cssText = cssText;
13928 nrules.appendChild(doc.createTextNode(cssText));
13930 nrules.cssText = cssText;
13932 head.appendChild(nrules);
13933 ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
13935 this.cacheStyleSheet(ss);
13940 * Removes a style or link tag by id
13941 * @param {String} id The id of the tag
13943 removeStyleSheet : function(id){
13944 var existing = doc.getElementById(id);
13946 existing.parentNode.removeChild(existing);
13951 * Dynamically swaps an existing stylesheet reference for a new one
13952 * @param {String} id The id of an existing link tag to remove
13953 * @param {String} url The href of the new stylesheet to include
13955 swapStyleSheet : function(id, url){
13956 this.removeStyleSheet(id);
13957 var ss = doc.createElement("link");
13958 ss.setAttribute("rel", "stylesheet");
13959 ss.setAttribute("type", "text/css");
13960 ss.setAttribute("id", id);
13961 ss.setAttribute("href", url);
13962 doc.getElementsByTagName("head")[0].appendChild(ss);
13966 * Refresh the rule cache if you have dynamically added stylesheets
13967 * @return {Object} An object (hash) of rules indexed by selector
13969 refreshCache : function(){
13970 return this.getRules(true);
13974 cacheStyleSheet : function(stylesheet){
13978 try{// try catch for cross domain access issue
13979 var ssRules = stylesheet.cssRules || stylesheet.rules;
13980 for(var j = ssRules.length-1; j >= 0; --j){
13981 rules[ssRules[j].selectorText] = ssRules[j];
13987 * Gets all css rules for the document
13988 * @param {Boolean} refreshCache true to refresh the internal cache
13989 * @return {Object} An object (hash) of rules indexed by selector
13991 getRules : function(refreshCache){
13992 if(rules == null || refreshCache){
13994 var ds = doc.styleSheets;
13995 for(var i =0, len = ds.length; i < len; i++){
13997 this.cacheStyleSheet(ds[i]);
14005 * Gets an an individual CSS rule by selector(s)
14006 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
14007 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
14008 * @return {CSSRule} The CSS rule or null if one is not found
14010 getRule : function(selector, refreshCache){
14011 var rs = this.getRules(refreshCache);
14012 if(!(selector instanceof Array)){
14013 return rs[selector];
14015 for(var i = 0; i < selector.length; i++){
14016 if(rs[selector[i]]){
14017 return rs[selector[i]];
14025 * Updates a rule property
14026 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
14027 * @param {String} property The css property
14028 * @param {String} value The new value for the property
14029 * @return {Boolean} true If a rule was found and updated
14031 updateRule : function(selector, property, value){
14032 if(!(selector instanceof Array)){
14033 var rule = this.getRule(selector);
14035 rule.style[property.replace(camelRe, camelFn)] = value;
14039 for(var i = 0; i < selector.length; i++){
14040 if(this.updateRule(selector[i], property, value)){
14050 * Ext JS Library 1.1.1
14051 * Copyright(c) 2006-2007, Ext JS, LLC.
14053 * Originally Released Under LGPL - original licence link has changed is not relivant.
14056 * <script type="text/javascript">
14062 * @class Roo.util.ClickRepeater
14063 * @extends Roo.util.Observable
14065 * A wrapper class which can be applied to any element. Fires a "click" event while the
14066 * mouse is pressed. The interval between firings may be specified in the config but
14067 * defaults to 10 milliseconds.
14069 * Optionally, a CSS class may be applied to the element during the time it is pressed.
14071 * @cfg {String/HTMLElement/Element} el The element to act as a button.
14072 * @cfg {Number} delay The initial delay before the repeating event begins firing.
14073 * Similar to an autorepeat key delay.
14074 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
14075 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
14076 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
14077 * "interval" and "delay" are ignored. "immediate" is honored.
14078 * @cfg {Boolean} preventDefault True to prevent the default click event
14079 * @cfg {Boolean} stopDefault True to stop the default click event
14082 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
14083 * 2007-02-02 jvs Renamed to ClickRepeater
14084 * 2007-02-03 jvs Modifications for FF Mac and Safari
14087 * @param {String/HTMLElement/Element} el The element to listen on
14088 * @param {Object} config
14090 Roo.util.ClickRepeater = function(el, config)
14092 this.el = Roo.get(el);
14093 this.el.unselectable();
14095 Roo.apply(this, config);
14100 * Fires when the mouse button is depressed.
14101 * @param {Roo.util.ClickRepeater} this
14103 "mousedown" : true,
14106 * Fires on a specified interval during the time the element is pressed.
14107 * @param {Roo.util.ClickRepeater} this
14112 * Fires when the mouse key is released.
14113 * @param {Roo.util.ClickRepeater} this
14118 this.el.on("mousedown", this.handleMouseDown, this);
14119 if(this.preventDefault || this.stopDefault){
14120 this.el.on("click", function(e){
14121 if(this.preventDefault){
14122 e.preventDefault();
14124 if(this.stopDefault){
14130 // allow inline handler
14132 this.on("click", this.handler, this.scope || this);
14135 Roo.util.ClickRepeater.superclass.constructor.call(this);
14138 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
14141 preventDefault : true,
14142 stopDefault : false,
14146 handleMouseDown : function(){
14147 clearTimeout(this.timer);
14149 if(this.pressClass){
14150 this.el.addClass(this.pressClass);
14152 this.mousedownTime = new Date();
14154 Roo.get(document).on("mouseup", this.handleMouseUp, this);
14155 this.el.on("mouseout", this.handleMouseOut, this);
14157 this.fireEvent("mousedown", this);
14158 this.fireEvent("click", this);
14160 this.timer = this.click.defer(this.delay || this.interval, this);
14164 click : function(){
14165 this.fireEvent("click", this);
14166 this.timer = this.click.defer(this.getInterval(), this);
14170 getInterval: function(){
14171 if(!this.accelerate){
14172 return this.interval;
14174 var pressTime = this.mousedownTime.getElapsed();
14175 if(pressTime < 500){
14177 }else if(pressTime < 1700){
14179 }else if(pressTime < 2600){
14181 }else if(pressTime < 3500){
14183 }else if(pressTime < 4400){
14185 }else if(pressTime < 5300){
14187 }else if(pressTime < 6200){
14195 handleMouseOut : function(){
14196 clearTimeout(this.timer);
14197 if(this.pressClass){
14198 this.el.removeClass(this.pressClass);
14200 this.el.on("mouseover", this.handleMouseReturn, this);
14204 handleMouseReturn : function(){
14205 this.el.un("mouseover", this.handleMouseReturn);
14206 if(this.pressClass){
14207 this.el.addClass(this.pressClass);
14213 handleMouseUp : function(){
14214 clearTimeout(this.timer);
14215 this.el.un("mouseover", this.handleMouseReturn);
14216 this.el.un("mouseout", this.handleMouseOut);
14217 Roo.get(document).un("mouseup", this.handleMouseUp);
14218 this.el.removeClass(this.pressClass);
14219 this.fireEvent("mouseup", this);
14223 * Ext JS Library 1.1.1
14224 * Copyright(c) 2006-2007, Ext JS, LLC.
14226 * Originally Released Under LGPL - original licence link has changed is not relivant.
14229 * <script type="text/javascript">
14234 * @class Roo.KeyNav
14235 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
14236 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
14237 * way to implement custom navigation schemes for any UI component.</p>
14238 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
14239 * pageUp, pageDown, del, home, end. Usage:</p>
14241 var nav = new Roo.KeyNav("my-element", {
14242 "left" : function(e){
14243 this.moveLeft(e.ctrlKey);
14245 "right" : function(e){
14246 this.moveRight(e.ctrlKey);
14248 "enter" : function(e){
14255 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14256 * @param {Object} config The config
14258 Roo.KeyNav = function(el, config){
14259 this.el = Roo.get(el);
14260 Roo.apply(this, config);
14261 if(!this.disabled){
14262 this.disabled = true;
14267 Roo.KeyNav.prototype = {
14269 * @cfg {Boolean} disabled
14270 * True to disable this KeyNav instance (defaults to false)
14274 * @cfg {String} defaultEventAction
14275 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
14276 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
14277 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
14279 defaultEventAction: "stopEvent",
14281 * @cfg {Boolean} forceKeyDown
14282 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
14283 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
14284 * handle keydown instead of keypress.
14286 forceKeyDown : false,
14289 prepareEvent : function(e){
14290 var k = e.getKey();
14291 var h = this.keyToHandler[k];
14292 //if(h && this[h]){
14293 // e.stopPropagation();
14295 if(Roo.isSafari && h && k >= 37 && k <= 40){
14301 relay : function(e){
14302 var k = e.getKey();
14303 var h = this.keyToHandler[k];
14305 if(this.doRelay(e, this[h], h) !== true){
14306 e[this.defaultEventAction]();
14312 doRelay : function(e, h, hname){
14313 return h.call(this.scope || this, e);
14316 // possible handlers
14330 // quick lookup hash
14347 * Enable this KeyNav
14349 enable: function(){
14351 // ie won't do special keys on keypress, no one else will repeat keys with keydown
14352 // the EventObject will normalize Safari automatically
14353 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14354 this.el.on("keydown", this.relay, this);
14356 this.el.on("keydown", this.prepareEvent, this);
14357 this.el.on("keypress", this.relay, this);
14359 this.disabled = false;
14364 * Disable this KeyNav
14366 disable: function(){
14367 if(!this.disabled){
14368 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14369 this.el.un("keydown", this.relay);
14371 this.el.un("keydown", this.prepareEvent);
14372 this.el.un("keypress", this.relay);
14374 this.disabled = true;
14379 * Ext JS Library 1.1.1
14380 * Copyright(c) 2006-2007, Ext JS, LLC.
14382 * Originally Released Under LGPL - original licence link has changed is not relivant.
14385 * <script type="text/javascript">
14390 * @class Roo.KeyMap
14391 * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
14392 * The constructor accepts the same config object as defined by {@link #addBinding}.
14393 * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
14394 * combination it will call the function with this signature (if the match is a multi-key
14395 * combination the callback will still be called only once): (String key, Roo.EventObject e)
14396 * A KeyMap can also handle a string representation of keys.<br />
14399 // map one key by key code
14400 var map = new Roo.KeyMap("my-element", {
14401 key: 13, // or Roo.EventObject.ENTER
14406 // map multiple keys to one action by string
14407 var map = new Roo.KeyMap("my-element", {
14413 // map multiple keys to multiple actions by strings and array of codes
14414 var map = new Roo.KeyMap("my-element", [
14417 fn: function(){ alert("Return was pressed"); }
14420 fn: function(){ alert('a, b or c was pressed'); }
14425 fn: function(){ alert('Control + shift + tab was pressed.'); }
14429 * <b>Note: A KeyMap starts enabled</b>
14431 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14432 * @param {Object} config The config (see {@link #addBinding})
14433 * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
14435 Roo.KeyMap = function(el, config, eventName){
14436 this.el = Roo.get(el);
14437 this.eventName = eventName || "keydown";
14438 this.bindings = [];
14440 this.addBinding(config);
14445 Roo.KeyMap.prototype = {
14447 * True to stop the event from bubbling and prevent the default browser action if the
14448 * key was handled by the KeyMap (defaults to false)
14454 * Add a new binding to this KeyMap. The following config object properties are supported:
14456 Property Type Description
14457 ---------- --------------- ----------------------------------------------------------------------
14458 key String/Array A single keycode or an array of keycodes to handle
14459 shift Boolean True to handle key only when shift is pressed (defaults to false)
14460 ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
14461 alt Boolean True to handle key only when alt is pressed (defaults to false)
14462 fn Function The function to call when KeyMap finds the expected key combination
14463 scope Object The scope of the callback function
14469 var map = new Roo.KeyMap(document, {
14470 key: Roo.EventObject.ENTER,
14475 //Add a new binding to the existing KeyMap later
14483 * @param {Object/Array} config A single KeyMap config or an array of configs
14485 addBinding : function(config){
14486 if(config instanceof Array){
14487 for(var i = 0, len = config.length; i < len; i++){
14488 this.addBinding(config[i]);
14492 var keyCode = config.key,
14493 shift = config.shift,
14494 ctrl = config.ctrl,
14497 scope = config.scope;
14498 if(typeof keyCode == "string"){
14500 var keyString = keyCode.toUpperCase();
14501 for(var j = 0, len = keyString.length; j < len; j++){
14502 ks.push(keyString.charCodeAt(j));
14506 var keyArray = keyCode instanceof Array;
14507 var handler = function(e){
14508 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14509 var k = e.getKey();
14511 for(var i = 0, len = keyCode.length; i < len; i++){
14512 if(keyCode[i] == k){
14513 if(this.stopEvent){
14516 fn.call(scope || window, k, e);
14522 if(this.stopEvent){
14525 fn.call(scope || window, k, e);
14530 this.bindings.push(handler);
14534 * Shorthand for adding a single key listener
14535 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
14536 * following options:
14537 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14538 * @param {Function} fn The function to call
14539 * @param {Object} scope (optional) The scope of the function
14541 on : function(key, fn, scope){
14542 var keyCode, shift, ctrl, alt;
14543 if(typeof key == "object" && !(key instanceof Array)){
14562 handleKeyDown : function(e){
14563 if(this.enabled){ //just in case
14564 var b = this.bindings;
14565 for(var i = 0, len = b.length; i < len; i++){
14566 b[i].call(this, e);
14572 * Returns true if this KeyMap is enabled
14573 * @return {Boolean}
14575 isEnabled : function(){
14576 return this.enabled;
14580 * Enables this KeyMap
14582 enable: function(){
14584 this.el.on(this.eventName, this.handleKeyDown, this);
14585 this.enabled = true;
14590 * Disable this KeyMap
14592 disable: function(){
14594 this.el.removeListener(this.eventName, this.handleKeyDown, this);
14595 this.enabled = false;
14600 * Ext JS Library 1.1.1
14601 * Copyright(c) 2006-2007, Ext JS, LLC.
14603 * Originally Released Under LGPL - original licence link has changed is not relivant.
14606 * <script type="text/javascript">
14611 * @class Roo.util.TextMetrics
14612 * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
14613 * wide, in pixels, a given block of text will be.
14616 Roo.util.TextMetrics = function(){
14620 * Measures the size of the specified text
14621 * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
14622 * that can affect the size of the rendered text
14623 * @param {String} text The text to measure
14624 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14625 * in order to accurately measure the text height
14626 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14628 measure : function(el, text, fixedWidth){
14630 shared = Roo.util.TextMetrics.Instance(el, fixedWidth);
14633 shared.setFixedWidth(fixedWidth || 'auto');
14634 return shared.getSize(text);
14638 * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
14639 * the overhead of multiple calls to initialize the style properties on each measurement.
14640 * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
14641 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14642 * in order to accurately measure the text height
14643 * @return {Roo.util.TextMetrics.Instance} instance The new instance
14645 createInstance : function(el, fixedWidth){
14646 return Roo.util.TextMetrics.Instance(el, fixedWidth);
14653 Roo.util.TextMetrics.Instance = function(bindTo, fixedWidth){
14654 var ml = new Roo.Element(document.createElement('div'));
14655 document.body.appendChild(ml.dom);
14656 ml.position('absolute');
14657 ml.setLeftTop(-1000, -1000);
14661 ml.setWidth(fixedWidth);
14666 * Returns the size of the specified text based on the internal element's style and width properties
14667 * @memberOf Roo.util.TextMetrics.Instance#
14668 * @param {String} text The text to measure
14669 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14671 getSize : function(text){
14673 var s = ml.getSize();
14679 * Binds this TextMetrics instance to an element from which to copy existing CSS styles
14680 * that can affect the size of the rendered text
14681 * @memberOf Roo.util.TextMetrics.Instance#
14682 * @param {String/HTMLElement} el The element, dom node or id
14684 bind : function(el){
14686 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
14691 * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
14692 * to set a fixed width in order to accurately measure the text height.
14693 * @memberOf Roo.util.TextMetrics.Instance#
14694 * @param {Number} width The width to set on the element
14696 setFixedWidth : function(width){
14697 ml.setWidth(width);
14701 * Returns the measured width of the specified text
14702 * @memberOf Roo.util.TextMetrics.Instance#
14703 * @param {String} text The text to measure
14704 * @return {Number} width The width in pixels
14706 getWidth : function(text){
14707 ml.dom.style.width = 'auto';
14708 return this.getSize(text).width;
14712 * Returns the measured height of the specified text. For multiline text, be sure to call
14713 * {@link #setFixedWidth} if necessary.
14714 * @memberOf Roo.util.TextMetrics.Instance#
14715 * @param {String} text The text to measure
14716 * @return {Number} height The height in pixels
14718 getHeight : function(text){
14719 return this.getSize(text).height;
14723 instance.bind(bindTo);
14728 // backwards compat
14729 Roo.Element.measureText = Roo.util.TextMetrics.measure;/*
14731 * Ext JS Library 1.1.1
14732 * Copyright(c) 2006-2007, Ext JS, LLC.
14734 * Originally Released Under LGPL - original licence link has changed is not relivant.
14737 * <script type="text/javascript">
14741 * @class Roo.state.Provider
14742 * Abstract base class for state provider implementations. This class provides methods
14743 * for encoding and decoding <b>typed</b> variables including dates and defines the
14744 * Provider interface.
14746 Roo.state.Provider = function(){
14748 * @event statechange
14749 * Fires when a state change occurs.
14750 * @param {Provider} this This state provider
14751 * @param {String} key The state key which was changed
14752 * @param {String} value The encoded value for the state
14755 "statechange": true
14758 Roo.state.Provider.superclass.constructor.call(this);
14760 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
14762 * Returns the current value for a key
14763 * @param {String} name The key name
14764 * @param {Mixed} defaultValue A default value to return if the key's value is not found
14765 * @return {Mixed} The state data
14767 get : function(name, defaultValue){
14768 return typeof this.state[name] == "undefined" ?
14769 defaultValue : this.state[name];
14773 * Clears a value from the state
14774 * @param {String} name The key name
14776 clear : function(name){
14777 delete this.state[name];
14778 this.fireEvent("statechange", this, name, null);
14782 * Sets the value for a key
14783 * @param {String} name The key name
14784 * @param {Mixed} value The value to set
14786 set : function(name, value){
14787 this.state[name] = value;
14788 this.fireEvent("statechange", this, name, value);
14792 * Decodes a string previously encoded with {@link #encodeValue}.
14793 * @param {String} value The value to decode
14794 * @return {Mixed} The decoded value
14796 decodeValue : function(cookie){
14797 var re = /^(a|n|d|b|s|o)\:(.*)$/;
14798 var matches = re.exec(unescape(cookie));
14799 if(!matches || !matches[1]) return; // non state cookie
14800 var type = matches[1];
14801 var v = matches[2];
14804 return parseFloat(v);
14806 return new Date(Date.parse(v));
14811 var values = v.split("^");
14812 for(var i = 0, len = values.length; i < len; i++){
14813 all.push(this.decodeValue(values[i]));
14818 var values = v.split("^");
14819 for(var i = 0, len = values.length; i < len; i++){
14820 var kv = values[i].split("=");
14821 all[kv[0]] = this.decodeValue(kv[1]);
14830 * Encodes a value including type information. Decode with {@link #decodeValue}.
14831 * @param {Mixed} value The value to encode
14832 * @return {String} The encoded value
14834 encodeValue : function(v){
14836 if(typeof v == "number"){
14838 }else if(typeof v == "boolean"){
14839 enc = "b:" + (v ? "1" : "0");
14840 }else if(v instanceof Date){
14841 enc = "d:" + v.toGMTString();
14842 }else if(v instanceof Array){
14844 for(var i = 0, len = v.length; i < len; i++){
14845 flat += this.encodeValue(v[i]);
14846 if(i != len-1) flat += "^";
14849 }else if(typeof v == "object"){
14852 if(typeof v[key] != "function"){
14853 flat += key + "=" + this.encodeValue(v[key]) + "^";
14856 enc = "o:" + flat.substring(0, flat.length-1);
14860 return escape(enc);
14866 * Ext JS Library 1.1.1
14867 * Copyright(c) 2006-2007, Ext JS, LLC.
14869 * Originally Released Under LGPL - original licence link has changed is not relivant.
14872 * <script type="text/javascript">
14875 * @class Roo.state.Manager
14876 * This is the global state manager. By default all components that are "state aware" check this class
14877 * for state information if you don't pass them a custom state provider. In order for this class
14878 * to be useful, it must be initialized with a provider when your application initializes.
14880 // in your initialization function
14882 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
14884 // supposed you have a {@link Roo.BorderLayout}
14885 var layout = new Roo.BorderLayout(...);
14886 layout.restoreState();
14887 // or a {Roo.BasicDialog}
14888 var dialog = new Roo.BasicDialog(...);
14889 dialog.restoreState();
14893 Roo.state.Manager = function(){
14894 var provider = new Roo.state.Provider();
14898 * Configures the default state provider for your application
14899 * @param {Provider} stateProvider The state provider to set
14901 setProvider : function(stateProvider){
14902 provider = stateProvider;
14906 * Returns the current value for a key
14907 * @param {String} name The key name
14908 * @param {Mixed} defaultValue The default value to return if the key lookup does not match
14909 * @return {Mixed} The state data
14911 get : function(key, defaultValue){
14912 return provider.get(key, defaultValue);
14916 * Sets the value for a key
14917 * @param {String} name The key name
14918 * @param {Mixed} value The state data
14920 set : function(key, value){
14921 provider.set(key, value);
14925 * Clears a value from the state
14926 * @param {String} name The key name
14928 clear : function(key){
14929 provider.clear(key);
14933 * Gets the currently configured state provider
14934 * @return {Provider} The state provider
14936 getProvider : function(){
14943 * Ext JS Library 1.1.1
14944 * Copyright(c) 2006-2007, Ext JS, LLC.
14946 * Originally Released Under LGPL - original licence link has changed is not relivant.
14949 * <script type="text/javascript">
14952 * @class Roo.state.CookieProvider
14953 * @extends Roo.state.Provider
14954 * The default Provider implementation which saves state via cookies.
14957 var cp = new Roo.state.CookieProvider({
14959 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
14960 domain: "roojs.com"
14962 Roo.state.Manager.setProvider(cp);
14964 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
14965 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
14966 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
14967 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
14968 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
14969 * domain the page is running on including the 'www' like 'www.roojs.com')
14970 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
14972 * Create a new CookieProvider
14973 * @param {Object} config The configuration object
14975 Roo.state.CookieProvider = function(config){
14976 Roo.state.CookieProvider.superclass.constructor.call(this);
14978 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
14979 this.domain = null;
14980 this.secure = false;
14981 Roo.apply(this, config);
14982 this.state = this.readCookies();
14985 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
14987 set : function(name, value){
14988 if(typeof value == "undefined" || value === null){
14992 this.setCookie(name, value);
14993 Roo.state.CookieProvider.superclass.set.call(this, name, value);
14997 clear : function(name){
14998 this.clearCookie(name);
14999 Roo.state.CookieProvider.superclass.clear.call(this, name);
15003 readCookies : function(){
15005 var c = document.cookie + ";";
15006 var re = /\s?(.*?)=(.*?);/g;
15008 while((matches = re.exec(c)) != null){
15009 var name = matches[1];
15010 var value = matches[2];
15011 if(name && name.substring(0,3) == "ys-"){
15012 cookies[name.substr(3)] = this.decodeValue(value);
15019 setCookie : function(name, value){
15020 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
15021 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
15022 ((this.path == null) ? "" : ("; path=" + this.path)) +
15023 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15024 ((this.secure == true) ? "; secure" : "");
15028 clearCookie : function(name){
15029 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
15030 ((this.path == null) ? "" : ("; path=" + this.path)) +
15031 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15032 ((this.secure == true) ? "; secure" : "");
15036 * Ext JS Library 1.1.1
15037 * Copyright(c) 2006-2007, Ext JS, LLC.
15039 * Originally Released Under LGPL - original licence link has changed is not relivant.
15042 * <script type="text/javascript">
15047 * @class Roo.ComponentMgr
15048 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
15051 Roo.ComponentMgr = function(){
15052 var all = new Roo.util.MixedCollection();
15056 * Registers a component.
15057 * @param {Roo.Component} c The component
15059 register : function(c){
15064 * Unregisters a component.
15065 * @param {Roo.Component} c The component
15067 unregister : function(c){
15072 * Returns a component by id
15073 * @param {String} id The component id
15075 get : function(id){
15076 return all.get(id);
15080 * Registers a function that will be called when a specified component is added to ComponentMgr
15081 * @param {String} id The component id
15082 * @param {Funtction} fn The callback function
15083 * @param {Object} scope The scope of the callback
15085 onAvailable : function(id, fn, scope){
15086 all.on("add", function(index, o){
15088 fn.call(scope || o, o);
15089 all.un("add", fn, scope);
15096 * Ext JS Library 1.1.1
15097 * Copyright(c) 2006-2007, Ext JS, LLC.
15099 * Originally Released Under LGPL - original licence link has changed is not relivant.
15102 * <script type="text/javascript">
15106 * @class Roo.Component
15107 * @extends Roo.util.Observable
15108 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
15109 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
15110 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
15111 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
15112 * All visual components (widgets) that require rendering into a layout should subclass Component.
15114 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
15115 * element and its id used as the component id. If a string is passed, it is assumed to be the id of an existing element
15116 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
15118 Roo.Component = function(config){
15119 config = config || {};
15120 if(config.tagName || config.dom || typeof config == "string"){ // element object
15121 config = {el: config, id: config.id || config};
15123 this.initialConfig = config;
15125 Roo.apply(this, config);
15129 * Fires after the component is disabled.
15130 * @param {Roo.Component} this
15135 * Fires after the component is enabled.
15136 * @param {Roo.Component} this
15140 * @event beforeshow
15141 * Fires before the component is shown. Return false to stop the show.
15142 * @param {Roo.Component} this
15147 * Fires after the component is shown.
15148 * @param {Roo.Component} this
15152 * @event beforehide
15153 * Fires before the component is hidden. Return false to stop the hide.
15154 * @param {Roo.Component} this
15159 * Fires after the component is hidden.
15160 * @param {Roo.Component} this
15164 * @event beforerender
15165 * Fires before the component is rendered. Return false to stop the render.
15166 * @param {Roo.Component} this
15168 beforerender : true,
15171 * Fires after the component is rendered.
15172 * @param {Roo.Component} this
15176 * @event beforedestroy
15177 * Fires before the component is destroyed. Return false to stop the destroy.
15178 * @param {Roo.Component} this
15180 beforedestroy : true,
15183 * Fires after the component is destroyed.
15184 * @param {Roo.Component} this
15189 this.id = "roo-comp-" + (++Roo.Component.AUTO_ID);
15191 Roo.ComponentMgr.register(this);
15192 Roo.Component.superclass.constructor.call(this);
15193 this.initComponent();
15194 if(this.renderTo){ // not supported by all components yet. use at your own risk!
15195 this.render(this.renderTo);
15196 delete this.renderTo;
15201 Roo.Component.AUTO_ID = 1000;
15203 Roo.extend(Roo.Component, Roo.util.Observable, {
15205 * @scope Roo.Component.prototype
15207 * true if this component is hidden. Read-only.
15212 * true if this component is disabled. Read-only.
15217 * true if this component has been rendered. Read-only.
15221 /** @cfg {String} disableClass
15222 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
15224 disabledClass : "x-item-disabled",
15225 /** @cfg {Boolean} allowDomMove
15226 * Whether the component can move the Dom node when rendering (defaults to true).
15228 allowDomMove : true,
15229 /** @cfg {String} hideMode (display|visibility)
15230 * How this component should hidden. Supported values are
15231 * "visibility" (css visibility), "offsets" (negative offset position) and
15232 * "display" (css display) - defaults to "display".
15234 hideMode: 'display',
15237 ctype : "Roo.Component",
15240 * @cfg {String} actionMode
15241 * which property holds the element that used for hide() / show() / disable() / enable()
15247 getActionEl : function(){
15248 return this[this.actionMode];
15251 initComponent : Roo.emptyFn,
15253 * If this is a lazy rendering component, render it to its container element.
15254 * @param {String/HTMLElement/Element} container (optional) The element this component should be rendered into. If it is being applied to existing markup, this should be left off.
15256 render : function(container, position){
15257 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
15258 if(!container && this.el){
15259 this.el = Roo.get(this.el);
15260 container = this.el.dom.parentNode;
15261 this.allowDomMove = false;
15263 this.container = Roo.get(container);
15264 this.rendered = true;
15265 if(position !== undefined){
15266 if(typeof position == 'number'){
15267 position = this.container.dom.childNodes[position];
15269 position = Roo.getDom(position);
15272 this.onRender(this.container, position || null);
15274 this.el.addClass(this.cls);
15278 this.el.applyStyles(this.style);
15281 this.fireEvent("render", this);
15282 this.afterRender(this.container);
15294 // default function is not really useful
15295 onRender : function(ct, position){
15297 this.el = Roo.get(this.el);
15298 if(this.allowDomMove !== false){
15299 ct.dom.insertBefore(this.el.dom, position);
15305 getAutoCreate : function(){
15306 var cfg = typeof this.autoCreate == "object" ?
15307 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
15308 if(this.id && !cfg.id){
15315 afterRender : Roo.emptyFn,
15318 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
15319 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
15321 destroy : function(){
15322 if(this.fireEvent("beforedestroy", this) !== false){
15323 this.purgeListeners();
15324 this.beforeDestroy();
15326 this.el.removeAllListeners();
15328 if(this.actionMode == "container"){
15329 this.container.remove();
15333 Roo.ComponentMgr.unregister(this);
15334 this.fireEvent("destroy", this);
15339 beforeDestroy : function(){
15344 onDestroy : function(){
15349 * Returns the underlying {@link Roo.Element}.
15350 * @return {Roo.Element} The element
15352 getEl : function(){
15357 * Returns the id of this component.
15360 getId : function(){
15365 * Try to focus this component.
15366 * @param {Boolean} selectText True to also select the text in this component (if applicable)
15367 * @return {Roo.Component} this
15369 focus : function(selectText){
15372 if(selectText === true){
15373 this.el.dom.select();
15388 * Disable this component.
15389 * @return {Roo.Component} this
15391 disable : function(){
15395 this.disabled = true;
15396 this.fireEvent("disable", this);
15401 onDisable : function(){
15402 this.getActionEl().addClass(this.disabledClass);
15403 this.el.dom.disabled = true;
15407 * Enable this component.
15408 * @return {Roo.Component} this
15410 enable : function(){
15414 this.disabled = false;
15415 this.fireEvent("enable", this);
15420 onEnable : function(){
15421 this.getActionEl().removeClass(this.disabledClass);
15422 this.el.dom.disabled = false;
15426 * Convenience function for setting disabled/enabled by boolean.
15427 * @param {Boolean} disabled
15429 setDisabled : function(disabled){
15430 this[disabled ? "disable" : "enable"]();
15434 * Show this component.
15435 * @return {Roo.Component} this
15438 if(this.fireEvent("beforeshow", this) !== false){
15439 this.hidden = false;
15443 this.fireEvent("show", this);
15449 onShow : function(){
15450 var ae = this.getActionEl();
15451 if(this.hideMode == 'visibility'){
15452 ae.dom.style.visibility = "visible";
15453 }else if(this.hideMode == 'offsets'){
15454 ae.removeClass('x-hidden');
15456 ae.dom.style.display = "";
15461 * Hide this component.
15462 * @return {Roo.Component} this
15465 if(this.fireEvent("beforehide", this) !== false){
15466 this.hidden = true;
15470 this.fireEvent("hide", this);
15476 onHide : function(){
15477 var ae = this.getActionEl();
15478 if(this.hideMode == 'visibility'){
15479 ae.dom.style.visibility = "hidden";
15480 }else if(this.hideMode == 'offsets'){
15481 ae.addClass('x-hidden');
15483 ae.dom.style.display = "none";
15488 * Convenience function to hide or show this component by boolean.
15489 * @param {Boolean} visible True to show, false to hide
15490 * @return {Roo.Component} this
15492 setVisible: function(visible){
15502 * Returns true if this component is visible.
15504 isVisible : function(){
15505 return this.getActionEl().isVisible();
15508 cloneConfig : function(overrides){
15509 overrides = overrides || {};
15510 var id = overrides.id || Roo.id();
15511 var cfg = Roo.applyIf(overrides, this.initialConfig);
15512 cfg.id = id; // prevent dup id
15513 return new this.constructor(cfg);
15517 * Ext JS Library 1.1.1
15518 * Copyright(c) 2006-2007, Ext JS, LLC.
15520 * Originally Released Under LGPL - original licence link has changed is not relivant.
15523 * <script type="text/javascript">
15527 * @class Roo.BoxComponent
15528 * @extends Roo.Component
15529 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
15530 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
15531 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
15532 * layout containers.
15534 * @param {Roo.Element/String/Object} config The configuration options.
15536 Roo.BoxComponent = function(config){
15537 Roo.Component.call(this, config);
15541 * Fires after the component is resized.
15542 * @param {Roo.Component} this
15543 * @param {Number} adjWidth The box-adjusted width that was set
15544 * @param {Number} adjHeight The box-adjusted height that was set
15545 * @param {Number} rawWidth The width that was originally specified
15546 * @param {Number} rawHeight The height that was originally specified
15551 * Fires after the component is moved.
15552 * @param {Roo.Component} this
15553 * @param {Number} x The new x position
15554 * @param {Number} y The new y position
15560 Roo.extend(Roo.BoxComponent, Roo.Component, {
15561 // private, set in afterRender to signify that the component has been rendered
15563 // private, used to defer height settings to subclasses
15564 deferHeight: false,
15565 /** @cfg {Number} width
15566 * width (optional) size of component
15568 /** @cfg {Number} height
15569 * height (optional) size of component
15573 * Sets the width and height of the component. This method fires the resize event. This method can accept
15574 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
15575 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
15576 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
15577 * @return {Roo.BoxComponent} this
15579 setSize : function(w, h){
15580 // support for standard size objects
15581 if(typeof w == 'object'){
15586 if(!this.boxReady){
15592 // prevent recalcs when not needed
15593 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
15596 this.lastSize = {width: w, height: h};
15598 var adj = this.adjustSize(w, h);
15599 var aw = adj.width, ah = adj.height;
15600 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
15601 var rz = this.getResizeEl();
15602 if(!this.deferHeight && aw !== undefined && ah !== undefined){
15603 rz.setSize(aw, ah);
15604 }else if(!this.deferHeight && ah !== undefined){
15606 }else if(aw !== undefined){
15609 this.onResize(aw, ah, w, h);
15610 this.fireEvent('resize', this, aw, ah, w, h);
15616 * Gets the current size of the component's underlying element.
15617 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
15619 getSize : function(){
15620 return this.el.getSize();
15624 * Gets the current XY position of the component's underlying element.
15625 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15626 * @return {Array} The XY position of the element (e.g., [100, 200])
15628 getPosition : function(local){
15629 if(local === true){
15630 return [this.el.getLeft(true), this.el.getTop(true)];
15632 return this.xy || this.el.getXY();
15636 * Gets the current box measurements of the component's underlying element.
15637 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15638 * @returns {Object} box An object in the format {x, y, width, height}
15640 getBox : function(local){
15641 var s = this.el.getSize();
15643 s.x = this.el.getLeft(true);
15644 s.y = this.el.getTop(true);
15646 var xy = this.xy || this.el.getXY();
15654 * Sets the current box measurements of the component's underlying element.
15655 * @param {Object} box An object in the format {x, y, width, height}
15656 * @returns {Roo.BoxComponent} this
15658 updateBox : function(box){
15659 this.setSize(box.width, box.height);
15660 this.setPagePosition(box.x, box.y);
15665 getResizeEl : function(){
15666 return this.resizeEl || this.el;
15670 getPositionEl : function(){
15671 return this.positionEl || this.el;
15675 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
15676 * This method fires the move event.
15677 * @param {Number} left The new left
15678 * @param {Number} top The new top
15679 * @returns {Roo.BoxComponent} this
15681 setPosition : function(x, y){
15684 if(!this.boxReady){
15687 var adj = this.adjustPosition(x, y);
15688 var ax = adj.x, ay = adj.y;
15690 var el = this.getPositionEl();
15691 if(ax !== undefined || ay !== undefined){
15692 if(ax !== undefined && ay !== undefined){
15693 el.setLeftTop(ax, ay);
15694 }else if(ax !== undefined){
15696 }else if(ay !== undefined){
15699 this.onPosition(ax, ay);
15700 this.fireEvent('move', this, ax, ay);
15706 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
15707 * This method fires the move event.
15708 * @param {Number} x The new x position
15709 * @param {Number} y The new y position
15710 * @returns {Roo.BoxComponent} this
15712 setPagePosition : function(x, y){
15715 if(!this.boxReady){
15718 if(x === undefined || y === undefined){ // cannot translate undefined points
15721 var p = this.el.translatePoints(x, y);
15722 this.setPosition(p.left, p.top);
15727 onRender : function(ct, position){
15728 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
15730 this.resizeEl = Roo.get(this.resizeEl);
15732 if(this.positionEl){
15733 this.positionEl = Roo.get(this.positionEl);
15738 afterRender : function(){
15739 Roo.BoxComponent.superclass.afterRender.call(this);
15740 this.boxReady = true;
15741 this.setSize(this.width, this.height);
15742 if(this.x || this.y){
15743 this.setPosition(this.x, this.y);
15745 if(this.pageX || this.pageY){
15746 this.setPagePosition(this.pageX, this.pageY);
15751 * Force the component's size to recalculate based on the underlying element's current height and width.
15752 * @returns {Roo.BoxComponent} this
15754 syncSize : function(){
15755 delete this.lastSize;
15756 this.setSize(this.el.getWidth(), this.el.getHeight());
15761 * Called after the component is resized, this method is empty by default but can be implemented by any
15762 * subclass that needs to perform custom logic after a resize occurs.
15763 * @param {Number} adjWidth The box-adjusted width that was set
15764 * @param {Number} adjHeight The box-adjusted height that was set
15765 * @param {Number} rawWidth The width that was originally specified
15766 * @param {Number} rawHeight The height that was originally specified
15768 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
15773 * Called after the component is moved, this method is empty by default but can be implemented by any
15774 * subclass that needs to perform custom logic after a move occurs.
15775 * @param {Number} x The new x position
15776 * @param {Number} y The new y position
15778 onPosition : function(x, y){
15783 adjustSize : function(w, h){
15784 if(this.autoWidth){
15787 if(this.autoHeight){
15790 return {width : w, height: h};
15794 adjustPosition : function(x, y){
15795 return {x : x, y: y};
15798 * Original code for Roojs - LGPL
15799 * <script type="text/javascript">
15803 * @class Roo.XComponent
15804 * A delayed Element creator...
15805 * Or a way to group chunks of interface together.
15806 * technically this is a wrapper around a tree of Roo elements (which defines a 'module'),
15807 * used in conjunction with XComponent.build() it will create an instance of each element,
15808 * then call addxtype() to build the User interface.
15810 * Mypart.xyx = new Roo.XComponent({
15812 parent : 'Mypart.xyz', // empty == document.element.!!
15816 disabled : function() {}
15818 tree : function() { // return an tree of xtype declared components
15822 xtype : 'NestedLayoutPanel',
15829 * It can be used to build a big heiracy, with parent etc.
15830 * or you can just use this to render a single compoent to a dom element
15831 * MYPART.render(Roo.Element | String(id) | dom_element )
15838 * Roo is designed primarily as a single page application, so the UI build for a standard interface will
15839 * expect a single 'TOP' level module normally indicated by the 'parent' of the XComponent definition being defined as false.
15841 * Each sub module is expected to have a parent pointing to the class name of it's parent module.
15843 * When the top level is false, a 'Roo.BorderLayout' is created and the element is flagged as 'topModule'
15844 * - if mulitple topModules exist, the last one is defined as the top module.
15848 * When the top level or multiple modules are to embedded into a existing HTML page,
15849 * the parent element can container '#id' of the element where the module will be drawn.
15853 * Unlike classic Roo, the bootstrap tends not to be used as a single page.
15854 * it relies more on a include mechanism, where sub modules are included into an outer page.
15855 * This is normally managed by the builder tools using Roo.apply( options, Included.Sub.Module )
15857 * Bootstrap Roo Included elements
15859 * Our builder application needs the ability to preview these sub compoennts. They will normally have parent=false set,
15860 * hence confusing the component builder as it thinks there are multiple top level elements.
15864 * @extends Roo.util.Observable
15866 * @param cfg {Object} configuration of component
15869 Roo.XComponent = function(cfg) {
15870 Roo.apply(this, cfg);
15874 * Fires when this the componnt is built
15875 * @param {Roo.XComponent} c the component
15880 this.region = this.region || 'center'; // default..
15881 Roo.XComponent.register(this);
15882 this.modules = false;
15883 this.el = false; // where the layout goes..
15887 Roo.extend(Roo.XComponent, Roo.util.Observable, {
15890 * The created element (with Roo.factory())
15891 * @type {Roo.Layout}
15897 * for BC - use el in new code
15898 * @type {Roo.Layout}
15904 * for BC - use el in new code
15905 * @type {Roo.Layout}
15910 * @cfg {Function|boolean} disabled
15911 * If this module is disabled by some rule, return true from the funtion
15916 * @cfg {String} parent
15917 * Name of parent element which it get xtype added to..
15922 * @cfg {String} order
15923 * Used to set the order in which elements are created (usefull for multiple tabs)
15928 * @cfg {String} name
15929 * String to display while loading.
15933 * @cfg {String} region
15934 * Region to render component to (defaults to center)
15939 * @cfg {Array} items
15940 * A single item array - the first element is the root of the tree..
15941 * It's done this way to stay compatible with the Xtype system...
15947 * The method that retuns the tree of parts that make up this compoennt
15954 * render element to dom or tree
15955 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
15958 render : function(el)
15962 var hp = this.parent ? 1 : 0;
15963 Roo.debug && Roo.log(this);
15965 if (!el && typeof(this.parent) == 'string' && this.parent.substring(0,1) == '#') {
15966 // if parent is a '#.....' string, then let's use that..
15967 var ename = this.parent.substr(1);
15968 this.parent = false;
15969 Roo.debug && Roo.log(ename);
15971 case 'bootstrap-body' :
15972 if (typeof(Roo.bootstrap.Body) != 'undefined') {
15973 this.parent = { el : new Roo.bootstrap.Body() };
15974 Roo.debug && Roo.log("setting el to doc body");
15977 throw "Container is bootstrap body, but Roo.bootstrap.Body is not defined";
15981 this.parent = { el : true};
15984 el = Roo.get(ename);
15989 if (!el && !this.parent) {
15990 Roo.debug && Roo.log("Warning - element can not be found :#" + ename );
15994 Roo.debug && Roo.log("EL:");
15995 Roo.debug && Roo.log(el);
15996 Roo.debug && Roo.log("this.parent.el:");
15997 Roo.debug && Roo.log(this.parent.el);
15999 var tree = this._tree ? this._tree() : this.tree();
16001 // altertive root elements ??? - we need a better way to indicate these.
16002 var is_alt = (typeof(Roo.bootstrap) != 'undefined' && tree.xns == Roo.bootstrap) ||
16003 (typeof(Roo.mailer) != 'undefined' && tree.xns == Roo.mailer) ;
16005 if (!this.parent && is_alt) {
16006 //el = Roo.get(document.body);
16007 this.parent = { el : true };
16012 if (!this.parent) {
16014 Roo.debug && Roo.log("no parent - creating one");
16016 el = el ? Roo.get(el) : false;
16018 // it's a top level one..
16020 el : new Roo.BorderLayout(el || document.body, {
16026 tabPosition: 'top',
16027 //resizeTabs: true,
16028 alwaysShowTabs: el && hp? false : true,
16029 hideTabs: el || !hp ? true : false,
16036 if (!this.parent.el) {
16037 // probably an old style ctor, which has been disabled.
16041 // The 'tree' method is '_tree now'
16043 tree.region = tree.region || this.region;
16045 if (this.parent.el === true) {
16046 // bootstrap... - body..
16047 this.parent.el = Roo.factory(tree);
16050 this.el = this.parent.el.addxtype(tree);
16051 this.fireEvent('built', this);
16053 this.panel = this.el;
16054 this.layout = this.panel.layout;
16055 this.parentLayout = this.parent.layout || false;
16061 Roo.apply(Roo.XComponent, {
16063 * @property hideProgress
16064 * true to disable the building progress bar.. usefull on single page renders.
16067 hideProgress : false,
16069 * @property buildCompleted
16070 * True when the builder has completed building the interface.
16073 buildCompleted : false,
16076 * @property topModule
16077 * the upper most module - uses document.element as it's constructor.
16084 * @property modules
16085 * array of modules to be created by registration system.
16086 * @type {Array} of Roo.XComponent
16091 * @property elmodules
16092 * array of modules to be created by which use #ID
16093 * @type {Array} of Roo.XComponent
16099 * @property build_from_html
16100 * Build elements from html - used by bootstrap HTML stuff
16101 * - this is cleared after build is completed
16102 * @type {boolean} true (default false)
16105 build_from_html : false,
16108 * Register components to be built later.
16110 * This solves the following issues
16111 * - Building is not done on page load, but after an authentication process has occured.
16112 * - Interface elements are registered on page load
16113 * - Parent Interface elements may not be loaded before child, so this handles that..
16120 module : 'Pman.Tab.projectMgr',
16122 parent : 'Pman.layout',
16123 disabled : false, // or use a function..
16126 * * @param {Object} details about module
16128 register : function(obj) {
16130 Roo.XComponent.event.fireEvent('register', obj);
16131 switch(typeof(obj.disabled) ) {
16137 if ( obj.disabled() ) {
16143 if (obj.disabled) {
16149 this.modules.push(obj);
16153 * convert a string to an object..
16154 * eg. 'AAA.BBB' -> finds AAA.BBB
16158 toObject : function(str)
16160 if (!str || typeof(str) == 'object') {
16163 if (str.substring(0,1) == '#') {
16167 var ar = str.split('.');
16172 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
16174 throw "Module not found : " + str;
16178 throw "Module not found : " + str;
16180 Roo.each(ar, function(e) {
16181 if (typeof(o[e]) == 'undefined') {
16182 throw "Module not found : " + str;
16193 * move modules into their correct place in the tree..
16196 preBuild : function ()
16199 Roo.each(this.modules , function (obj)
16201 Roo.XComponent.event.fireEvent('beforebuild', obj);
16203 var opar = obj.parent;
16205 obj.parent = this.toObject(opar);
16207 Roo.debug && Roo.log("parent:toObject failed: " + e.toString());
16212 Roo.debug && Roo.log("GOT top level module");
16213 Roo.debug && Roo.log(obj);
16214 obj.modules = new Roo.util.MixedCollection(false,
16215 function(o) { return o.order + '' }
16217 this.topModule = obj;
16220 // parent is a string (usually a dom element name..)
16221 if (typeof(obj.parent) == 'string') {
16222 this.elmodules.push(obj);
16225 if (obj.parent.constructor != Roo.XComponent) {
16226 Roo.debug && Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name)
16228 if (!obj.parent.modules) {
16229 obj.parent.modules = new Roo.util.MixedCollection(false,
16230 function(o) { return o.order + '' }
16233 if (obj.parent.disabled) {
16234 obj.disabled = true;
16236 obj.parent.modules.add(obj);
16241 * make a list of modules to build.
16242 * @return {Array} list of modules.
16245 buildOrder : function()
16248 var cmp = function(a,b) {
16249 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
16251 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
16252 throw "No top level modules to build";
16255 // make a flat list in order of modules to build.
16256 var mods = this.topModule ? [ this.topModule ] : [];
16259 // elmodules (is a list of DOM based modules )
16260 Roo.each(this.elmodules, function(e) {
16262 if (!this.topModule &&
16263 typeof(e.parent) == 'string' &&
16264 e.parent.substring(0,1) == '#' &&
16265 Roo.get(e.parent.substr(1))
16268 _this.topModule = e;
16274 // add modules to their parents..
16275 var addMod = function(m) {
16276 Roo.debug && Roo.log("build Order: add: " + m.name);
16279 if (m.modules && !m.disabled) {
16280 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules");
16281 m.modules.keySort('ASC', cmp );
16282 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules (after sort)");
16284 m.modules.each(addMod);
16286 Roo.debug && Roo.log("build Order: no child modules");
16288 // not sure if this is used any more..
16290 m.finalize.name = m.name + " (clean up) ";
16291 mods.push(m.finalize);
16295 if (this.topModule && this.topModule.modules) {
16296 this.topModule.modules.keySort('ASC', cmp );
16297 this.topModule.modules.each(addMod);
16303 * Build the registered modules.
16304 * @param {Object} parent element.
16305 * @param {Function} optional method to call after module has been added.
16309 build : function(opts)
16312 if (typeof(opts) != 'undefined') {
16313 Roo.apply(this,opts);
16317 var mods = this.buildOrder();
16319 //this.allmods = mods;
16320 //Roo.debug && Roo.log(mods);
16322 if (!mods.length) { // should not happen
16323 throw "NO modules!!!";
16327 var msg = "Building Interface...";
16328 // flash it up as modal - so we store the mask!?
16329 if (!this.hideProgress && Roo.MessageBox) {
16330 Roo.MessageBox.show({ title: 'loading' });
16331 Roo.MessageBox.show({
16332 title: "Please wait...",
16341 var total = mods.length;
16344 var progressRun = function() {
16345 if (!mods.length) {
16346 Roo.debug && Roo.log('hide?');
16347 if (!this.hideProgress && Roo.MessageBox) {
16348 Roo.MessageBox.hide();
16350 Roo.XComponent.build_from_html = false; // reset, so dialogs will be build from javascript
16352 Roo.XComponent.event.fireEvent('buildcomplete', _this.topModule);
16358 var m = mods.shift();
16361 Roo.debug && Roo.log(m);
16362 // not sure if this is supported any more.. - modules that are are just function
16363 if (typeof(m) == 'function') {
16365 return progressRun.defer(10, _this);
16369 msg = "Building Interface " + (total - mods.length) +
16371 (m.name ? (' - ' + m.name) : '');
16372 Roo.debug && Roo.log(msg);
16373 if (!this.hideProgress && Roo.MessageBox) {
16374 Roo.MessageBox.updateProgress( (total - mods.length)/total, msg );
16378 // is the module disabled?
16379 var disabled = (typeof(m.disabled) == 'function') ?
16380 m.disabled.call(m.module.disabled) : m.disabled;
16384 return progressRun(); // we do not update the display!
16392 // it's 10 on top level, and 1 on others??? why...
16393 return progressRun.defer(10, _this);
16396 progressRun.defer(1, _this);
16410 * wrapper for event.on - aliased later..
16411 * Typically use to register a event handler for register:
16413 * eg. Roo.XComponent.on('register', function(comp) { comp.disable = true } );
16422 Roo.XComponent.event = new Roo.util.Observable({
16426 * Fires when an Component is registered,
16427 * set the disable property on the Component to stop registration.
16428 * @param {Roo.XComponent} c the component being registerd.
16433 * @event beforebuild
16434 * Fires before each Component is built
16435 * can be used to apply permissions.
16436 * @param {Roo.XComponent} c the component being registerd.
16439 'beforebuild' : true,
16441 * @event buildcomplete
16442 * Fires on the top level element when all elements have been built
16443 * @param {Roo.XComponent} the top level component.
16445 'buildcomplete' : true
16450 Roo.XComponent.on = Roo.XComponent.event.on.createDelegate(Roo.XComponent.event);