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 isEdge = ua.indexOf("edge") > -1,
61 isGecko = !isSafari && ua.indexOf("gecko") > -1,
62 isBorderBox = isIE && !isStrict,
63 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
64 isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
65 isLinux = (ua.indexOf("linux") != -1),
66 isSecure = window.location.href.toLowerCase().indexOf("https") === 0,
67 isIOS = /iphone|ipad/.test(ua),
68 isAndroid = /android/.test(ua),
69 isTouch = (function() {
71 if (ua.indexOf('chrome') != -1 && ua.indexOf('android') == -1) {
72 window.addEventListener('touchstart', function __set_has_touch__ () {
74 window.removeEventListener('touchstart', __set_has_touch__);
76 return false; // no touch on chrome!?
78 document.createEvent("TouchEvent");
85 // remove css image flicker
88 document.execCommand("BackgroundImageCache", false, true);
94 * True if the browser is in strict mode
99 * True if the page is running over SSL
104 * True when the document is fully initialized and ready for action
109 * Turn on debugging output (currently only the factory uses this)
116 * True to automatically uncache orphaned Roo.Elements periodically (defaults to true)
119 enableGarbageCollector : true,
122 * True to automatically purge event listeners after uncaching an element (defaults to false).
123 * Note: this only happens if enableGarbageCollector is true.
126 enableListenerCollection:false,
129 * URL to a blank file used by Roo when in secure mode for iframe src and onReady src to prevent
130 * the IE insecure content warning (defaults to javascript:false).
133 SSL_SECURE_URL : "javascript:false",
136 * URL to a 1x1 transparent gif image used by Roo to create inline icons with CSS background images. (Defaults to
137 * "http://Roojs.com/s.gif" and you should change this to a URL on your server).
140 BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
142 emptyFn : function(){},
145 * Copies all the properties of config to obj if they don't already exist.
146 * @param {Object} obj The receiver of the properties
147 * @param {Object} config The source of the properties
148 * @return {Object} returns obj
150 applyIf : function(o, c){
153 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
160 * Applies event listeners to elements by selectors when the document is ready.
161 * The event name is specified with an @ suffix.
164 // add a listener for click on all anchors in element with id foo
165 '#foo a@click' : function(e, t){
169 // add the same listener to multiple selectors (separated by comma BEFORE the @)
170 '#foo a, #bar span.some-class@mouseover' : function(){
175 * @param {Object} obj The list of behaviors to apply
177 addBehaviors : function(o){
179 Roo.onReady(function(){
184 var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
186 var parts = b.split('@');
187 if(parts[1]){ // for Object prototype breakers
190 cache[s] = Roo.select(s);
192 cache[s].on(parts[1], o[b]);
199 * Generates unique ids. If the element already has an id, it is unchanged
200 * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
201 * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
202 * @return {String} The generated Id.
204 id : function(el, prefix){
205 prefix = prefix || "roo-gen";
207 var id = prefix + (++idSeed);
208 return el ? (el.id ? el.id : (el.id = id)) : id;
213 * Extends one class with another class and optionally overrides members with the passed literal. This class
214 * also adds the function "override()" to the class that can be used to override
215 * members on an instance.
216 * @param {Object} subclass The class inheriting the functionality
217 * @param {Object} superclass The class being extended
218 * @param {Object} overrides (optional) A literal with members
223 var io = function(o){
228 return function(sb, sp, overrides){
229 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
232 sb = function(){sp.apply(this, arguments);};
234 var F = function(){}, sbp, spp = sp.prototype;
236 sbp = sb.prototype = new F();
240 if(spp.constructor == Object.prototype.constructor){
245 sb.override = function(o){
249 Roo.override(sb, overrides);
255 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
257 Roo.override(MyClass, {
258 newMethod1: function(){
261 newMethod2: function(foo){
266 * @param {Object} origclass The class to override
267 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
268 * containing one or more methods.
271 override : function(origclass, overrides){
273 var p = origclass.prototype;
274 for(var method in overrides){
275 p[method] = overrides[method];
280 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
282 Roo.namespace('Company', 'Company.data');
283 Company.Widget = function() { ... }
284 Company.data.CustomStore = function(config) { ... }
286 * @param {String} namespace1
287 * @param {String} namespace2
288 * @param {String} etc
291 namespace : function(){
292 var a=arguments, o=null, i, j, d, rt;
293 for (i=0; i<a.length; ++i) {
297 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
298 for (j=1; j<d.length; ++j) {
299 o[d[j]]=o[d[j]] || {};
305 * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
307 Roo.factory({ xns: Roo.data, xtype : 'Store', .....});
308 Roo.factory(conf, Roo.data);
310 * @param {String} classname
311 * @param {String} namespace (optional)
315 factory : function(c, ns)
317 // no xtype, no ns or c.xns - or forced off by c.xns
318 if (!c.xtype || (!ns && !c.xns) || (c.xns === false)) { // not enough info...
321 ns = c.xns ? c.xns : ns; // if c.xns is set, then use that..
322 if (c.constructor == ns[c.xtype]) {// already created...
326 if (Roo.debug) { Roo.log("Roo.Factory(" + c.xtype + ")"); }
327 var ret = new ns[c.xtype](c);
331 c.xns = false; // prevent recursion..
335 * Logs to console if it can.
337 * @param {String|Object} string
342 if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
349 * 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.
353 urlEncode : function(o){
359 var ov = o[key], k = Roo.encodeURIComponent(key);
360 var type = typeof ov;
361 if(type == 'undefined'){
363 }else if(type != "function" && type != "object"){
364 buf.push(k, "=", Roo.encodeURIComponent(ov), "&");
365 }else if(ov instanceof Array){
367 for(var i = 0, len = ov.length; i < len; i++) {
368 buf.push(k, "=", Roo.encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
379 * Safe version of encodeURIComponent
380 * @param {String} data
384 encodeURIComponent : function (data)
387 return encodeURIComponent(data);
388 } catch(e) {} // should be an uri encode error.
390 if (data == '' || data == null){
393 // http://stackoverflow.com/questions/2596483/unicode-and-uri-encoding-decoding-and-escaping-in-javascript
394 function nibble_to_hex(nibble){
395 var chars = '0123456789ABCDEF';
396 return chars.charAt(nibble);
398 data = data.toString();
400 for(var i=0; i<data.length; i++){
401 var c = data.charCodeAt(i);
402 var bs = new Array();
405 bs[0] = 0xF0 | ((c & 0x1C0000) >>> 18);
406 bs[1] = 0x80 | ((c & 0x3F000) >>> 12);
407 bs[2] = 0x80 | ((c & 0xFC0) >>> 6);
408 bs[3] = 0x80 | (c & 0x3F);
409 }else if (c > 0x800){
411 bs[0] = 0xE0 | ((c & 0xF000) >>> 12);
412 bs[1] = 0x80 | ((c & 0xFC0) >>> 6);
413 bs[2] = 0x80 | (c & 0x3F);
416 bs[0] = 0xC0 | ((c & 0x7C0) >>> 6);
417 bs[1] = 0x80 | (c & 0x3F);
422 for(var j=0; j<bs.length; j++){
424 var hex = nibble_to_hex((b & 0xF0) >>> 4)
425 + nibble_to_hex(b &0x0F);
434 * 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]}.
435 * @param {String} string
436 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
437 * @return {Object} A literal with members
439 urlDecode : function(string, overwrite){
440 if(!string || !string.length){
444 var pairs = string.split('&');
445 var pair, name, value;
446 for(var i = 0, len = pairs.length; i < len; i++){
447 pair = pairs[i].split('=');
448 name = decodeURIComponent(pair[0]);
449 value = decodeURIComponent(pair[1]);
450 if(overwrite !== true){
451 if(typeof obj[name] == "undefined"){
453 }else if(typeof obj[name] == "string"){
454 obj[name] = [obj[name]];
455 obj[name].push(value);
457 obj[name].push(value);
467 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
468 * passed array is not really an array, your function is called once with it.
469 * The supplied function is called with (Object item, Number index, Array allItems).
470 * @param {Array/NodeList/Mixed} array
471 * @param {Function} fn
472 * @param {Object} scope
474 each : function(array, fn, scope){
475 if(typeof array.length == "undefined" || typeof array == "string"){
478 for(var i = 0, len = array.length; i < len; i++){
479 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
484 combine : function(){
485 var as = arguments, l = as.length, r = [];
486 for(var i = 0; i < l; i++){
488 if(a instanceof Array){
490 }else if(a.length !== undefined && !a.substr){
491 r = r.concat(Array.prototype.slice.call(a, 0));
500 * Escapes the passed string for use in a regular expression
501 * @param {String} str
504 escapeRe : function(s) {
505 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
509 callback : function(cb, scope, args, delay){
510 if(typeof cb == "function"){
512 cb.defer(delay, scope, args || []);
514 cb.apply(scope, args || []);
520 * Return the dom node for the passed string (id), dom node, or Roo.Element
521 * @param {String/HTMLElement/Roo.Element} el
522 * @return HTMLElement
524 getDom : function(el){
528 return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
532 * Shorthand for {@link Roo.ComponentMgr#get}
534 * @return Roo.Component
536 getCmp : function(id){
537 return Roo.ComponentMgr.get(id);
540 num : function(v, defaultValue){
541 if(typeof v != 'number'){
547 destroy : function(){
548 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
552 as.removeAllListeners();
556 if(typeof as.purgeListeners == 'function'){
559 if(typeof as.destroy == 'function'){
566 // inpired by a similar function in mootools library
568 * Returns the type of object that is passed in. If the object passed in is null or undefined it
569 * return false otherwise it returns one of the following values:<ul>
570 * <li><b>string</b>: If the object passed is a string</li>
571 * <li><b>number</b>: If the object passed is a number</li>
572 * <li><b>boolean</b>: If the object passed is a boolean value</li>
573 * <li><b>function</b>: If the object passed is a function reference</li>
574 * <li><b>object</b>: If the object passed is an object</li>
575 * <li><b>array</b>: If the object passed is an array</li>
576 * <li><b>regexp</b>: If the object passed is a regular expression</li>
577 * <li><b>element</b>: If the object passed is a DOM Element</li>
578 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
579 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
580 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
581 * @param {Mixed} object
585 if(o === undefined || o === null){
592 if(t == 'object' && o.nodeName) {
594 case 1: return 'element';
595 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
598 if(t == 'object' || t == 'function') {
599 switch(o.constructor) {
600 case Array: return 'array';
601 case RegExp: return 'regexp';
603 if(typeof o.length == 'number' && typeof o.item == 'function') {
611 * Returns true if the passed value is null, undefined or an empty string (optional).
612 * @param {Mixed} value The value to test
613 * @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
616 isEmpty : function(v, allowBlank){
617 return v === null || v === undefined || (!allowBlank ? v === '' : false);
625 isFirefox : isFirefox,
637 isBorderBox : isBorderBox,
639 isWindows : isWindows,
647 isAndroid : isAndroid,
652 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
653 * you may want to set this to true.
656 useShims : ((isIE && !isIE7) || (isGecko && isMac)),
661 * Selects a single element as a Roo Element
662 * This is about as close as you can get to jQuery's $('do crazy stuff')
663 * @param {String} selector The selector/xpath query
664 * @param {Node} root (optional) The start of the query (defaults to document).
665 * @return {Roo.Element}
667 selectNode : function(selector, root)
669 var node = Roo.DomQuery.selectNode(selector,root);
670 return node ? Roo.get(node) : new Roo.Element(false);
678 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
679 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout",
682 "Roo.bootstrap.dash");
685 * Ext JS Library 1.1.1
686 * Copyright(c) 2006-2007, Ext JS, LLC.
688 * Originally Released Under LGPL - original licence link has changed is not relivant.
691 * <script type="text/javascript">
695 // wrappedn so fnCleanup is not in global scope...
697 function fnCleanUp() {
698 var p = Function.prototype;
699 delete p.createSequence;
701 delete p.createDelegate;
702 delete p.createCallback;
703 delete p.createInterceptor;
705 window.detachEvent("onunload", fnCleanUp);
707 window.attachEvent("onunload", fnCleanUp);
714 * These functions are available on every Function object (any JavaScript function).
716 Roo.apply(Function.prototype, {
718 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
719 * Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
720 * Will create a function that is bound to those 2 args.
721 * @return {Function} The new function
723 createCallback : function(/*args...*/){
724 // make args available, in function below
725 var args = arguments;
728 return method.apply(window, args);
733 * Creates a delegate (callback) that sets the scope to obj.
734 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
735 * Will create a function that is automatically scoped to this.
736 * @param {Object} obj (optional) The object for which the scope is set
737 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
738 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
739 * if a number the args are inserted at the specified position
740 * @return {Function} The new function
742 createDelegate : function(obj, args, appendArgs){
745 var callArgs = args || arguments;
746 if(appendArgs === true){
747 callArgs = Array.prototype.slice.call(arguments, 0);
748 callArgs = callArgs.concat(args);
749 }else if(typeof appendArgs == "number"){
750 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
751 var applyArgs = [appendArgs, 0].concat(args); // create method call params
752 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
754 return method.apply(obj || window, callArgs);
759 * Calls this function after the number of millseconds specified.
760 * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
761 * @param {Object} obj (optional) The object for which the scope is set
762 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
763 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
764 * if a number the args are inserted at the specified position
765 * @return {Number} The timeout id that can be used with clearTimeout
767 defer : function(millis, obj, args, appendArgs){
768 var fn = this.createDelegate(obj, args, appendArgs);
770 return setTimeout(fn, millis);
776 * Create a combined function call sequence of the original function + the passed function.
777 * The resulting function returns the results of the original function.
778 * The passed fcn is called with the parameters of the original function
779 * @param {Function} fcn The function to sequence
780 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
781 * @return {Function} The new function
783 createSequence : function(fcn, scope){
784 if(typeof fcn != "function"){
789 var retval = method.apply(this || window, arguments);
790 fcn.apply(scope || this || window, arguments);
796 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
797 * The resulting function returns the results of the original function.
798 * The passed fcn is called with the parameters of the original function.
800 * @param {Function} fcn The function to call before the original
801 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
802 * @return {Function} The new function
804 createInterceptor : function(fcn, scope){
805 if(typeof fcn != "function"){
812 if(fcn.apply(scope || this || window, arguments) === false){
815 return method.apply(this || window, arguments);
821 * Ext JS Library 1.1.1
822 * Copyright(c) 2006-2007, Ext JS, LLC.
824 * Originally Released Under LGPL - original licence link has changed is not relivant.
827 * <script type="text/javascript">
830 Roo.applyIf(String, {
835 * Escapes the passed string for ' and \
836 * @param {String} string The string to escape
837 * @return {String} The escaped string
840 escape : function(string) {
841 return string.replace(/('|\\)/g, "\\$1");
845 * Pads the left side of a string with a specified character. This is especially useful
846 * for normalizing number and date strings. Example usage:
848 var s = String.leftPad('123', 5, '0');
849 // s now contains the string: '00123'
851 * @param {String} string The original string
852 * @param {Number} size The total length of the output string
853 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
854 * @return {String} The padded string
857 leftPad : function (val, size, ch) {
858 var result = new String(val);
859 if(ch === null || ch === undefined || ch === '') {
862 while (result.length < size) {
863 result = ch + result;
869 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
870 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
872 var cls = 'my-class', text = 'Some text';
873 var s = String.format('<div class="{0}">{1}</div>', cls, text);
874 // s now contains the string: '<div class="my-class">Some text</div>'
876 * @param {String} string The tokenized string to be formatted
877 * @param {String} value1 The value to replace token {0}
878 * @param {String} value2 Etc...
879 * @return {String} The formatted string
882 format : function(format){
883 var args = Array.prototype.slice.call(arguments, 1);
884 return format.replace(/\{(\d+)\}/g, function(m, i){
885 return Roo.util.Format.htmlEncode(args[i]);
891 * Utility function that allows you to easily switch a string between two alternating values. The passed value
892 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
893 * they are already different, the first value passed in is returned. Note that this method returns the new value
894 * but does not change the current string.
896 // alternate sort directions
897 sort = sort.toggle('ASC', 'DESC');
899 // instead of conditional logic:
900 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
902 * @param {String} value The value to compare to the current string
903 * @param {String} other The new value to use if the string already equals the first value passed in
904 * @return {String} The new value
907 String.prototype.toggle = function(value, other){
908 return this == value ? other : value;
911 * Ext JS Library 1.1.1
912 * Copyright(c) 2006-2007, Ext JS, LLC.
914 * Originally Released Under LGPL - original licence link has changed is not relivant.
917 * <script type="text/javascript">
923 Roo.applyIf(Number.prototype, {
925 * Checks whether or not the current number is within a desired range. If the number is already within the
926 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
927 * exceeded. Note that this method returns the constrained value but does not change the current number.
928 * @param {Number} min The minimum number in the range
929 * @param {Number} max The maximum number in the range
930 * @return {Number} The constrained value if outside the range, otherwise the current value
932 constrain : function(min, max){
933 return Math.min(Math.max(this, min), max);
937 * Ext JS Library 1.1.1
938 * Copyright(c) 2006-2007, Ext JS, LLC.
940 * Originally Released Under LGPL - original licence link has changed is not relivant.
943 * <script type="text/javascript">
948 Roo.applyIf(Array.prototype, {
951 * Checks whether or not the specified object exists in the array.
952 * @param {Object} o The object to check for
953 * @return {Number} The index of o in the array (or -1 if it is not found)
955 indexOf : function(o){
956 for (var i = 0, len = this.length; i < len; i++){
957 if(this[i] == o) { return i; }
963 * Removes the specified object from the array. If the object is not found nothing happens.
964 * @param {Object} o The object to remove
966 remove : function(o){
967 var index = this.indexOf(o);
969 this.splice(index, 1);
973 * Map (JS 1.6 compatibility)
974 * @param {Function} function to call
978 var len = this.length >>> 0;
979 if (typeof fun != "function") {
980 throw new TypeError();
982 var res = new Array(len);
983 var thisp = arguments[1];
984 for (var i = 0; i < len; i++)
987 res[i] = fun.call(thisp, this[i], i, this);
1000 * Ext JS Library 1.1.1
1001 * Copyright(c) 2006-2007, Ext JS, LLC.
1003 * Originally Released Under LGPL - original licence link has changed is not relivant.
1006 * <script type="text/javascript">
1012 * The date parsing and format syntax is a subset of
1013 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
1014 * supported will provide results equivalent to their PHP versions.
1016 * Following is the list of all currently supported formats:
1019 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
1021 Format Output Description
1022 ------ ---------- --------------------------------------------------------------
1023 d 10 Day of the month, 2 digits with leading zeros
1024 D Wed A textual representation of a day, three letters
1025 j 10 Day of the month without leading zeros
1026 l Wednesday A full textual representation of the day of the week
1027 S th English ordinal day of month suffix, 2 chars (use with j)
1028 w 3 Numeric representation of the day of the week
1029 z 9 The julian date, or day of the year (0-365)
1030 W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
1031 F January A full textual representation of the month
1032 m 01 Numeric representation of a month, with leading zeros
1033 M Jan Month name abbreviation, three letters
1034 n 1 Numeric representation of a month, without leading zeros
1035 t 31 Number of days in the given month
1036 L 0 Whether it's a leap year (1 if it is a leap year, else 0)
1037 Y 2007 A full numeric representation of a year, 4 digits
1038 y 07 A two digit representation of a year
1039 a pm Lowercase Ante meridiem and Post meridiem
1040 A PM Uppercase Ante meridiem and Post meridiem
1041 g 3 12-hour format of an hour without leading zeros
1042 G 15 24-hour format of an hour without leading zeros
1043 h 03 12-hour format of an hour with leading zeros
1044 H 15 24-hour format of an hour with leading zeros
1045 i 05 Minutes with leading zeros
1046 s 01 Seconds, with leading zeros
1047 O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes)
1048 P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes
1049 T CST Timezone setting of the machine running the code
1050 Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
1053 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
1055 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
1056 document.write(dt.format('Y-m-d')); //2007-01-10
1057 document.write(dt.format('F j, Y, g:i a')); //January 10, 2007, 3:05 pm
1058 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
1061 * Here are some standard date/time patterns that you might find helpful. They
1062 * are not part of the source of Date.js, but to use them you can simply copy this
1063 * block of code into any script that is included after Date.js and they will also become
1064 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
1067 ISO8601Long:"Y-m-d H:i:s",
1068 ISO8601Short:"Y-m-d",
1070 LongDate: "l, F d, Y",
1071 FullDateTime: "l, F d, Y g:i:s A",
1074 LongTime: "g:i:s A",
1075 SortableDateTime: "Y-m-d\\TH:i:s",
1076 UniversalSortableDateTime: "Y-m-d H:i:sO",
1083 var dt = new Date();
1084 document.write(dt.format(Date.patterns.ShortDate));
1089 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
1090 * They generate precompiled functions from date formats instead of parsing and
1091 * processing the pattern every time you format a date. These functions are available
1092 * on every Date object (any javascript function).
1094 * The original article and download are here:
1095 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1102 Returns the number of milliseconds between this date and date
1103 @param {Date} date (optional) Defaults to now
1104 @return {Number} The diff in milliseconds
1105 @member Date getElapsed
1107 Date.prototype.getElapsed = function(date) {
1108 return Math.abs((date || new Date()).getTime()-this.getTime());
1110 // was in date file..
1114 Date.parseFunctions = {count:0};
1116 Date.parseRegexes = [];
1118 Date.formatFunctions = {count:0};
1121 Date.prototype.dateFormat = function(format) {
1122 if (Date.formatFunctions[format] == null) {
1123 Date.createNewFormat(format);
1125 var func = Date.formatFunctions[format];
1126 return this[func]();
1131 * Formats a date given the supplied format string
1132 * @param {String} format The format string
1133 * @return {String} The formatted date
1136 Date.prototype.format = Date.prototype.dateFormat;
1139 Date.createNewFormat = function(format) {
1140 var funcName = "format" + Date.formatFunctions.count++;
1141 Date.formatFunctions[format] = funcName;
1142 var code = "Date.prototype." + funcName + " = function(){return ";
1143 var special = false;
1145 for (var i = 0; i < format.length; ++i) {
1146 ch = format.charAt(i);
1147 if (!special && ch == "\\") {
1152 code += "'" + String.escape(ch) + "' + ";
1155 code += Date.getFormatCode(ch);
1158 /** eval:var:zzzzzzzzzzzzz */
1159 eval(code.substring(0, code.length - 3) + ";}");
1163 Date.getFormatCode = function(character) {
1164 switch (character) {
1166 return "String.leftPad(this.getDate(), 2, '0') + ";
1168 return "Date.dayNames[this.getDay()].substring(0, 3) + ";
1170 return "this.getDate() + ";
1172 return "Date.dayNames[this.getDay()] + ";
1174 return "this.getSuffix() + ";
1176 return "this.getDay() + ";
1178 return "this.getDayOfYear() + ";
1180 return "this.getWeekOfYear() + ";
1182 return "Date.monthNames[this.getMonth()] + ";
1184 return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
1186 return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
1188 return "(this.getMonth() + 1) + ";
1190 return "this.getDaysInMonth() + ";
1192 return "(this.isLeapYear() ? 1 : 0) + ";
1194 return "this.getFullYear() + ";
1196 return "('' + this.getFullYear()).substring(2, 4) + ";
1198 return "(this.getHours() < 12 ? 'am' : 'pm') + ";
1200 return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
1202 return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
1204 return "this.getHours() + ";
1206 return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
1208 return "String.leftPad(this.getHours(), 2, '0') + ";
1210 return "String.leftPad(this.getMinutes(), 2, '0') + ";
1212 return "String.leftPad(this.getSeconds(), 2, '0') + ";
1214 return "this.getGMTOffset() + ";
1216 return "this.getGMTColonOffset() + ";
1218 return "this.getTimezone() + ";
1220 return "(this.getTimezoneOffset() * -60) + ";
1222 return "'" + String.escape(character) + "' + ";
1227 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
1228 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
1229 * the date format that is not specified will default to the current date value for that part. Time parts can also
1230 * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
1231 * string or the parse operation will fail.
1234 //dt = Fri May 25 2007 (current date)
1235 var dt = new Date();
1237 //dt = Thu May 25 2006 (today's month/day in 2006)
1238 dt = Date.parseDate("2006", "Y");
1240 //dt = Sun Jan 15 2006 (all date parts specified)
1241 dt = Date.parseDate("2006-1-15", "Y-m-d");
1243 //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
1244 dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i:s A" );
1246 * @param {String} input The unparsed date as a string
1247 * @param {String} format The format the date is in
1248 * @return {Date} The parsed date
1251 Date.parseDate = function(input, format) {
1252 if (Date.parseFunctions[format] == null) {
1253 Date.createParser(format);
1255 var func = Date.parseFunctions[format];
1256 return Date[func](input);
1262 Date.createParser = function(format) {
1263 var funcName = "parse" + Date.parseFunctions.count++;
1264 var regexNum = Date.parseRegexes.length;
1265 var currentGroup = 1;
1266 Date.parseFunctions[format] = funcName;
1268 var code = "Date." + funcName + " = function(input){\n"
1269 + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
1270 + "var d = new Date();\n"
1271 + "y = d.getFullYear();\n"
1272 + "m = d.getMonth();\n"
1273 + "d = d.getDate();\n"
1274 + "if (typeof(input) !== 'string') { input = input.toString(); }\n"
1275 + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
1276 + "if (results && results.length > 0) {";
1279 var special = false;
1281 for (var i = 0; i < format.length; ++i) {
1282 ch = format.charAt(i);
1283 if (!special && ch == "\\") {
1288 regex += String.escape(ch);
1291 var obj = Date.formatCodeToRegex(ch, currentGroup);
1292 currentGroup += obj.g;
1294 if (obj.g && obj.c) {
1300 code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
1301 + "{v = new Date(y, m, d, h, i, s);}\n"
1302 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
1303 + "{v = new Date(y, m, d, h, i);}\n"
1304 + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
1305 + "{v = new Date(y, m, d, h);}\n"
1306 + "else if (y >= 0 && m >= 0 && d > 0)\n"
1307 + "{v = new Date(y, m, d);}\n"
1308 + "else if (y >= 0 && m >= 0)\n"
1309 + "{v = new Date(y, m);}\n"
1310 + "else if (y >= 0)\n"
1311 + "{v = new Date(y);}\n"
1312 + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset
1313 + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
1314 + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
1317 Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
1318 /** eval:var:zzzzzzzzzzzzz */
1323 Date.formatCodeToRegex = function(character, currentGroup) {
1324 switch (character) {
1328 s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
1331 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1332 s:"(\\d{1,2})"}; // day of month without leading zeroes
1335 c:"d = parseInt(results[" + currentGroup + "], 10);\n",
1336 s:"(\\d{2})"}; // day of month with leading zeroes
1340 s:"(?:" + Date.dayNames.join("|") + ")"};
1344 s:"(?:st|nd|rd|th)"};
1359 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
1360 s:"(" + Date.monthNames.join("|") + ")"};
1363 c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
1364 s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
1367 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1368 s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros
1371 c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
1372 s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros
1383 c:"y = parseInt(results[" + currentGroup + "], 10);\n",
1387 c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
1388 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
1392 c:"if (results[" + currentGroup + "] == 'am') {\n"
1393 + "if (h == 12) { h = 0; }\n"
1394 + "} else { if (h < 12) { h += 12; }}",
1398 c:"if (results[" + currentGroup + "] == 'AM') {\n"
1399 + "if (h == 12) { h = 0; }\n"
1400 + "} else { if (h < 12) { h += 12; }}",
1405 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1406 s:"(\\d{1,2})"}; // 12/24-hr format format of an hour without leading zeroes
1410 c:"h = parseInt(results[" + currentGroup + "], 10);\n",
1411 s:"(\\d{2})"}; // 12/24-hr format format of an hour with leading zeroes
1414 c:"i = parseInt(results[" + currentGroup + "], 10);\n",
1418 c:"s = parseInt(results[" + currentGroup + "], 10);\n",
1423 "o = results[", currentGroup, "];\n",
1424 "var sn = o.substring(0,1);\n", // get + / - sign
1425 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also)
1426 "var mn = o.substring(3,5) % 60;\n", // get minutes
1427 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
1428 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1430 s:"([+\-]\\d{2,4})"};
1436 "o = results[", currentGroup, "];\n",
1437 "var sn = o.substring(0,1);\n",
1438 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
1439 "var mn = o.substring(4,6) % 60;\n",
1440 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
1441 " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
1447 s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
1450 c:"z = results[" + currentGroup + "];\n" // -43200 <= UTC offset <= 50400
1451 + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
1452 s:"([+\-]?\\d{1,5})"}; // leading '+' sign is optional for UTC offset
1456 s:String.escape(character)};
1461 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1462 * @return {String} The abbreviated timezone name (e.g. 'CST')
1464 Date.prototype.getTimezone = function() {
1465 return this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
1469 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1470 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600')
1472 Date.prototype.getGMTOffset = function() {
1473 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1474 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1475 + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
1479 * Get the offset from GMT of the current date (equivalent to the format specifier 'P').
1480 * @return {String} 2-characters representing hours and 2-characters representing minutes
1481 * seperated by a colon and prefixed with + or - (e.g. '-06:00')
1483 Date.prototype.getGMTColonOffset = function() {
1484 return (this.getTimezoneOffset() > 0 ? "-" : "+")
1485 + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
1487 + String.leftPad(this.getTimezoneOffset() %60, 2, "0");
1491 * Get the numeric day number of the year, adjusted for leap year.
1492 * @return {Number} 0 through 364 (365 in leap years)
1494 Date.prototype.getDayOfYear = function() {
1496 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1497 for (var i = 0; i < this.getMonth(); ++i) {
1498 num += Date.daysInMonth[i];
1500 return num + this.getDate() - 1;
1504 * Get the string representation of the numeric week number of the year
1505 * (equivalent to the format specifier 'W').
1506 * @return {String} '00' through '52'
1508 Date.prototype.getWeekOfYear = function() {
1509 // Skip to Thursday of this week
1510 var now = this.getDayOfYear() + (4 - this.getDay());
1511 // Find the first Thursday of the year
1512 var jan1 = new Date(this.getFullYear(), 0, 1);
1513 var then = (7 - jan1.getDay() + 4);
1514 return String.leftPad(((now - then) / 7) + 1, 2, "0");
1518 * Whether or not the current date is in a leap year.
1519 * @return {Boolean} True if the current date is in a leap year, else false
1521 Date.prototype.isLeapYear = function() {
1522 var year = this.getFullYear();
1523 return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1527 * Get the first day of the current month, adjusted for leap year. The returned value
1528 * is the numeric day index within the week (0-6) which can be used in conjunction with
1529 * the {@link #monthNames} array to retrieve the textual day name.
1532 var dt = new Date('1/10/2007');
1533 document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
1535 * @return {Number} The day number (0-6)
1537 Date.prototype.getFirstDayOfMonth = function() {
1538 var day = (this.getDay() - (this.getDate() - 1)) % 7;
1539 return (day < 0) ? (day + 7) : day;
1543 * Get the last day of the current month, adjusted for leap year. The returned value
1544 * is the numeric day index within the week (0-6) which can be used in conjunction with
1545 * the {@link #monthNames} array to retrieve the textual day name.
1548 var dt = new Date('1/10/2007');
1549 document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
1551 * @return {Number} The day number (0-6)
1553 Date.prototype.getLastDayOfMonth = function() {
1554 var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1555 return (day < 0) ? (day + 7) : day;
1560 * Get the first date of this date's month
1563 Date.prototype.getFirstDateOfMonth = function() {
1564 return new Date(this.getFullYear(), this.getMonth(), 1);
1568 * Get the last date of this date's month
1571 Date.prototype.getLastDateOfMonth = function() {
1572 return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1575 * Get the number of days in the current month, adjusted for leap year.
1576 * @return {Number} The number of days in the month
1578 Date.prototype.getDaysInMonth = function() {
1579 Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1580 return Date.daysInMonth[this.getMonth()];
1584 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1585 * @return {String} 'st, 'nd', 'rd' or 'th'
1587 Date.prototype.getSuffix = function() {
1588 switch (this.getDate()) {
1605 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1608 * An array of textual month names.
1609 * Override these values for international dates, for example...
1610 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
1629 * An array of textual day names.
1630 * Override these values for international dates, for example...
1631 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
1647 Date.monthNumbers = {
1662 * Creates and returns a new Date instance with the exact same date value as the called instance.
1663 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1664 * variable will also be changed. When the intention is to create a new variable that will not
1665 * modify the original instance, you should create a clone.
1667 * Example of correctly cloning a date:
1670 var orig = new Date('10/1/2006');
1673 document.write(orig); //returns 'Thu Oct 05 2006'!
1676 var orig = new Date('10/1/2006');
1677 var copy = orig.clone();
1679 document.write(orig); //returns 'Thu Oct 01 2006'
1681 * @return {Date} The new Date instance
1683 Date.prototype.clone = function() {
1684 return new Date(this.getTime());
1688 * Clears any time information from this date
1689 @param {Boolean} clone true to create a clone of this date, clear the time and return it
1690 @return {Date} this or the clone
1692 Date.prototype.clearTime = function(clone){
1694 return this.clone().clearTime();
1699 this.setMilliseconds(0);
1704 // safari setMonth is broken -- check that this is only donw once...
1705 if(Roo.isSafari && typeof(Date.brokenSetMonth) == 'undefined'){
1706 Date.brokenSetMonth = Date.prototype.setMonth;
1707 Date.prototype.setMonth = function(num){
1709 var n = Math.ceil(-num);
1710 var back_year = Math.ceil(n/12);
1711 var month = (n % 12) ? 12 - n % 12 : 0 ;
1712 this.setFullYear(this.getFullYear() - back_year);
1713 return Date.brokenSetMonth.call(this, month);
1715 return Date.brokenSetMonth.apply(this, arguments);
1720 /** Date interval constant
1724 /** Date interval constant
1728 /** Date interval constant
1732 /** Date interval constant
1736 /** Date interval constant
1740 /** Date interval constant
1744 /** Date interval constant
1750 * Provides a convenient method of performing basic date arithmetic. This method
1751 * does not modify the Date instance being called - it creates and returns
1752 * a new Date instance containing the resulting date value.
1757 var dt = new Date('10/29/2006').add(Date.DAY, 5);
1758 document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'
1760 //Negative values will subtract correctly:
1761 var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
1762 document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1764 //You can even chain several calls together in one line!
1765 var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
1766 document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
1769 * @param {String} interval A valid date interval enum value
1770 * @param {Number} value The amount to add to the current date
1771 * @return {Date} The new Date instance
1773 Date.prototype.add = function(interval, value){
1774 var d = this.clone();
1775 if (!interval || value === 0) { return d; }
1776 switch(interval.toLowerCase()){
1778 d.setMilliseconds(this.getMilliseconds() + value);
1781 d.setSeconds(this.getSeconds() + value);
1784 d.setMinutes(this.getMinutes() + value);
1787 d.setHours(this.getHours() + value);
1790 d.setDate(this.getDate() + value);
1793 var day = this.getDate();
1795 day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
1798 d.setMonth(this.getMonth() + value);
1801 d.setFullYear(this.getFullYear() + value);
1808 * Ext JS Library 1.1.1
1809 * Copyright(c) 2006-2007, Ext JS, LLC.
1811 * Originally Released Under LGPL - original licence link has changed is not relivant.
1814 * <script type="text/javascript">
1818 * @class Roo.lib.Dom
1821 * Dom utils (from YIU afaik)
1826 * Get the view width
1827 * @param {Boolean} full True will get the full document, otherwise it's the view width
1828 * @return {Number} The width
1831 getViewWidth : function(full) {
1832 return full ? this.getDocumentWidth() : this.getViewportWidth();
1835 * Get the view height
1836 * @param {Boolean} full True will get the full document, otherwise it's the view height
1837 * @return {Number} The height
1839 getViewHeight : function(full) {
1840 return full ? this.getDocumentHeight() : this.getViewportHeight();
1843 getDocumentHeight: function() {
1844 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1845 return Math.max(scrollHeight, this.getViewportHeight());
1848 getDocumentWidth: function() {
1849 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1850 return Math.max(scrollWidth, this.getViewportWidth());
1853 getViewportHeight: function() {
1854 var height = self.innerHeight;
1855 var mode = document.compatMode;
1857 if ((mode || Roo.isIE) && !Roo.isOpera) {
1858 height = (mode == "CSS1Compat") ?
1859 document.documentElement.clientHeight :
1860 document.body.clientHeight;
1866 getViewportWidth: function() {
1867 var width = self.innerWidth;
1868 var mode = document.compatMode;
1870 if (mode || Roo.isIE) {
1871 width = (mode == "CSS1Compat") ?
1872 document.documentElement.clientWidth :
1873 document.body.clientWidth;
1878 isAncestor : function(p, c) {
1885 if (p.contains && !Roo.isSafari) {
1886 return p.contains(c);
1887 } else if (p.compareDocumentPosition) {
1888 return !!(p.compareDocumentPosition(c) & 16);
1890 var parent = c.parentNode;
1895 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1898 parent = parent.parentNode;
1904 getRegion : function(el) {
1905 return Roo.lib.Region.getRegion(el);
1908 getY : function(el) {
1909 return this.getXY(el)[1];
1912 getX : function(el) {
1913 return this.getXY(el)[0];
1916 getXY : function(el) {
1917 var p, pe, b, scroll, bd = document.body;
1918 el = Roo.getDom(el);
1919 var fly = Roo.lib.AnimBase.fly;
1920 if (el.getBoundingClientRect) {
1921 b = el.getBoundingClientRect();
1922 scroll = fly(document).getScroll();
1923 return [b.left + scroll.left, b.top + scroll.top];
1929 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1936 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1943 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1944 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1951 if (p != el && pe.getStyle('overflow') != 'visible') {
1959 if (Roo.isSafari && hasAbsolute) {
1964 if (Roo.isGecko && !hasAbsolute) {
1966 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1967 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1971 while (p && p != bd) {
1972 if (!Roo.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1984 setXY : function(el, xy) {
1985 el = Roo.fly(el, '_setXY');
1987 var pts = el.translatePoints(xy);
1988 if (xy[0] !== false) {
1989 el.dom.style.left = pts.left + "px";
1991 if (xy[1] !== false) {
1992 el.dom.style.top = pts.top + "px";
1996 setX : function(el, x) {
1997 this.setXY(el, [x, false]);
2000 setY : function(el, y) {
2001 this.setXY(el, [false, y]);
2005 * Portions of this file are based on pieces of Yahoo User Interface Library
2006 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2007 * YUI licensed under the BSD License:
2008 * http://developer.yahoo.net/yui/license.txt
2009 * <script type="text/javascript">
2013 Roo.lib.Event = function() {
2014 var loadComplete = false;
2016 var unloadListeners = [];
2018 var onAvailStack = [];
2020 var lastError = null;
2033 startInterval: function() {
2034 if (!this._interval) {
2036 var callback = function() {
2037 self._tryPreloadAttach();
2039 this._interval = setInterval(callback, this.POLL_INTERVAL);
2044 onAvailable: function(p_id, p_fn, p_obj, p_override) {
2045 onAvailStack.push({ id: p_id,
2048 override: p_override,
2049 checkReady: false });
2051 retryCount = this.POLL_RETRYS;
2052 this.startInterval();
2056 addListener: function(el, eventName, fn) {
2057 el = Roo.getDom(el);
2062 if ("unload" == eventName) {
2063 unloadListeners[unloadListeners.length] =
2064 [el, eventName, fn];
2068 var wrappedFn = function(e) {
2069 return fn(Roo.lib.Event.getEvent(e));
2072 var li = [el, eventName, fn, wrappedFn];
2074 var index = listeners.length;
2075 listeners[index] = li;
2077 this.doAdd(el, eventName, wrappedFn, false);
2083 removeListener: function(el, eventName, fn) {
2086 el = Roo.getDom(el);
2089 return this.purgeElement(el, false, eventName);
2093 if ("unload" == eventName) {
2095 for (i = 0,len = unloadListeners.length; i < len; i++) {
2096 var li = unloadListeners[i];
2099 li[1] == eventName &&
2101 unloadListeners.splice(i, 1);
2109 var cacheItem = null;
2112 var index = arguments[3];
2114 if ("undefined" == typeof index) {
2115 index = this._getCacheIndex(el, eventName, fn);
2119 cacheItem = listeners[index];
2122 if (!el || !cacheItem) {
2126 this.doRemove(el, eventName, cacheItem[this.WFN], false);
2128 delete listeners[index][this.WFN];
2129 delete listeners[index][this.FN];
2130 listeners.splice(index, 1);
2137 getTarget: function(ev, resolveTextNode) {
2138 ev = ev.browserEvent || ev;
2139 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2140 var t = ev.target || ev.srcElement;
2141 return this.resolveTextNode(t);
2145 resolveTextNode: function(node) {
2146 if (Roo.isSafari && node && 3 == node.nodeType) {
2147 return node.parentNode;
2154 getPageX: function(ev) {
2155 ev = ev.browserEvent || ev;
2156 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2158 if (!x && 0 !== x) {
2159 x = ev.clientX || 0;
2162 x += this.getScroll()[1];
2170 getPageY: function(ev) {
2171 ev = ev.browserEvent || ev;
2172 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2174 if (!y && 0 !== y) {
2175 y = ev.clientY || 0;
2178 y += this.getScroll()[0];
2187 getXY: function(ev) {
2188 ev = ev.browserEvent || ev;
2189 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2190 return [this.getPageX(ev), this.getPageY(ev)];
2194 getRelatedTarget: function(ev) {
2195 ev = ev.browserEvent || ev;
2196 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2197 var t = ev.relatedTarget;
2199 if (ev.type == "mouseout") {
2201 } else if (ev.type == "mouseover") {
2206 return this.resolveTextNode(t);
2210 getTime: function(ev) {
2211 ev = ev.browserEvent || ev;
2212 ev = ev.touches ? (ev.touches[0] || ev.changedTouches[0] || ev ) : ev;
2214 var t = new Date().getTime();
2218 this.lastError = ex;
2227 stopEvent: function(ev) {
2228 this.stopPropagation(ev);
2229 this.preventDefault(ev);
2233 stopPropagation: function(ev) {
2234 ev = ev.browserEvent || ev;
2235 if (ev.stopPropagation) {
2236 ev.stopPropagation();
2238 ev.cancelBubble = true;
2243 preventDefault: function(ev) {
2244 ev = ev.browserEvent || ev;
2245 if(ev.preventDefault) {
2246 ev.preventDefault();
2248 ev.returnValue = false;
2253 getEvent: function(e) {
2254 var ev = e || window.event;
2256 var c = this.getEvent.caller;
2258 ev = c.arguments[0];
2259 if (ev && Event == ev.constructor) {
2269 getCharCode: function(ev) {
2270 ev = ev.browserEvent || ev;
2271 return ev.charCode || ev.keyCode || 0;
2275 _getCacheIndex: function(el, eventName, fn) {
2276 for (var i = 0,len = listeners.length; i < len; ++i) {
2277 var li = listeners[i];
2279 li[this.FN] == fn &&
2280 li[this.EL] == el &&
2281 li[this.TYPE] == eventName) {
2293 getEl: function(id) {
2294 return document.getElementById(id);
2298 clearCache: function() {
2302 _load: function(e) {
2303 loadComplete = true;
2304 var EU = Roo.lib.Event;
2308 EU.doRemove(window, "load", EU._load);
2313 _tryPreloadAttach: function() {
2322 var tryAgain = !loadComplete;
2324 tryAgain = (retryCount > 0);
2329 for (var i = 0,len = onAvailStack.length; i < len; ++i) {
2330 var item = onAvailStack[i];
2332 var el = this.getEl(item.id);
2335 if (!item.checkReady ||
2338 (document && document.body)) {
2341 if (item.override) {
2342 if (item.override === true) {
2345 scope = item.override;
2348 item.fn.call(scope, item.obj);
2349 onAvailStack[i] = null;
2352 notAvail.push(item);
2357 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2361 this.startInterval();
2363 clearInterval(this._interval);
2364 this._interval = null;
2367 this.locked = false;
2374 purgeElement: function(el, recurse, eventName) {
2375 var elListeners = this.getListeners(el, eventName);
2377 for (var i = 0,len = elListeners.length; i < len; ++i) {
2378 var l = elListeners[i];
2379 this.removeListener(el, l.type, l.fn);
2383 if (recurse && el && el.childNodes) {
2384 for (i = 0,len = el.childNodes.length; i < len; ++i) {
2385 this.purgeElement(el.childNodes[i], recurse, eventName);
2391 getListeners: function(el, eventName) {
2392 var results = [], searchLists;
2394 searchLists = [listeners, unloadListeners];
2395 } else if (eventName == "unload") {
2396 searchLists = [unloadListeners];
2398 searchLists = [listeners];
2401 for (var j = 0; j < searchLists.length; ++j) {
2402 var searchList = searchLists[j];
2403 if (searchList && searchList.length > 0) {
2404 for (var i = 0,len = searchList.length; i < len; ++i) {
2405 var l = searchList[i];
2406 if (l && l[this.EL] === el &&
2407 (!eventName || eventName === l[this.TYPE])) {
2412 adjust: l[this.ADJ_SCOPE],
2420 return (results.length) ? results : null;
2424 _unload: function(e) {
2426 var EU = Roo.lib.Event, i, j, l, len, index;
2428 for (i = 0,len = unloadListeners.length; i < len; ++i) {
2429 l = unloadListeners[i];
2432 if (l[EU.ADJ_SCOPE]) {
2433 if (l[EU.ADJ_SCOPE] === true) {
2436 scope = l[EU.ADJ_SCOPE];
2439 l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
2440 unloadListeners[i] = null;
2446 unloadListeners = null;
2448 if (listeners && listeners.length > 0) {
2449 j = listeners.length;
2452 l = listeners[index];
2454 EU.removeListener(l[EU.EL], l[EU.TYPE],
2464 EU.doRemove(window, "unload", EU._unload);
2469 getScroll: function() {
2470 var dd = document.documentElement, db = document.body;
2471 if (dd && (dd.scrollTop || dd.scrollLeft)) {
2472 return [dd.scrollTop, dd.scrollLeft];
2474 return [db.scrollTop, db.scrollLeft];
2481 doAdd: function () {
2482 if (window.addEventListener) {
2483 return function(el, eventName, fn, capture) {
2484 el.addEventListener(eventName, fn, (capture));
2486 } else if (window.attachEvent) {
2487 return function(el, eventName, fn, capture) {
2488 el.attachEvent("on" + eventName, fn);
2497 doRemove: function() {
2498 if (window.removeEventListener) {
2499 return function (el, eventName, fn, capture) {
2500 el.removeEventListener(eventName, fn, (capture));
2502 } else if (window.detachEvent) {
2503 return function (el, eventName, fn) {
2504 el.detachEvent("on" + eventName, fn);
2516 var E = Roo.lib.Event;
2517 E.on = E.addListener;
2518 E.un = E.removeListener;
2520 if (document && document.body) {
2523 E.doAdd(window, "load", E._load);
2525 E.doAdd(window, "unload", E._unload);
2526 E._tryPreloadAttach();
2530 * Portions of this file are based on pieces of Yahoo User Interface Library
2531 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2532 * YUI licensed under the BSD License:
2533 * http://developer.yahoo.net/yui/license.txt
2534 * <script type="text/javascript">
2540 * @class Roo.lib.Ajax
2547 request : function(method, uri, cb, data, options) {
2549 var hs = options.headers;
2552 if(hs.hasOwnProperty(h)){
2553 this.initHeader(h, hs[h], false);
2557 if(options.xmlData){
2558 this.initHeader('Content-Type', 'text/xml', false);
2560 data = options.xmlData;
2564 return this.asyncRequest(method, uri, cb, data);
2567 serializeForm : function(form) {
2568 if(typeof form == 'string') {
2569 form = (document.getElementById(form) || document.forms[form]);
2572 var el, name, val, disabled, data = '', hasSubmit = false;
2573 for (var i = 0; i < form.elements.length; i++) {
2574 el = form.elements[i];
2575 disabled = form.elements[i].disabled;
2576 name = form.elements[i].name;
2577 val = form.elements[i].value;
2579 if (!disabled && name){
2583 case 'select-multiple':
2584 for (var j = 0; j < el.options.length; j++) {
2585 if (el.options[j].selected) {
2587 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
2590 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
2598 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2611 if(hasSubmit == false) {
2612 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2617 data += Roo.encodeURIComponent(name) + '=' + Roo.encodeURIComponent(val) + '&';
2622 data = data.substr(0, data.length - 1);
2630 useDefaultHeader:true,
2632 defaultPostHeader:'application/x-www-form-urlencoded',
2634 useDefaultXhrHeader:true,
2636 defaultXhrHeader:'XMLHttpRequest',
2638 hasDefaultHeaders:true,
2650 setProgId:function(id)
2652 this.activeX.unshift(id);
2655 setDefaultPostHeader:function(b)
2657 this.useDefaultHeader = b;
2660 setDefaultXhrHeader:function(b)
2662 this.useDefaultXhrHeader = b;
2665 setPollingInterval:function(i)
2667 if (typeof i == 'number' && isFinite(i)) {
2668 this.pollInterval = i;
2672 createXhrObject:function(transactionId)
2678 http = new XMLHttpRequest();
2680 obj = { conn:http, tId:transactionId };
2684 for (var i = 0; i < this.activeX.length; ++i) {
2688 http = new ActiveXObject(this.activeX[i]);
2690 obj = { conn:http, tId:transactionId };
2703 getConnectionObject:function()
2706 var tId = this.transactionId;
2710 o = this.createXhrObject(tId);
2712 this.transactionId++;
2723 asyncRequest:function(method, uri, callback, postData)
2725 var o = this.getConnectionObject();
2731 o.conn.open(method, uri, true);
2733 if (this.useDefaultXhrHeader) {
2734 if (!this.defaultHeaders['X-Requested-With']) {
2735 this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2739 if(postData && this.useDefaultHeader){
2740 this.initHeader('Content-Type', this.defaultPostHeader);
2743 if (this.hasDefaultHeaders || this.hasHeaders) {
2747 this.handleReadyState(o, callback);
2748 o.conn.send(postData || null);
2754 handleReadyState:function(o, callback)
2758 if (callback && callback.timeout) {
2760 this.timeout[o.tId] = window.setTimeout(function() {
2761 oConn.abort(o, callback, true);
2762 }, callback.timeout);
2765 this.poll[o.tId] = window.setInterval(
2767 if (o.conn && o.conn.readyState == 4) {
2768 window.clearInterval(oConn.poll[o.tId]);
2769 delete oConn.poll[o.tId];
2771 if(callback && callback.timeout) {
2772 window.clearTimeout(oConn.timeout[o.tId]);
2773 delete oConn.timeout[o.tId];
2776 oConn.handleTransactionResponse(o, callback);
2779 , this.pollInterval);
2782 handleTransactionResponse:function(o, callback, isAbort)
2786 this.releaseObject(o);
2790 var httpStatus, responseObject;
2794 if (o.conn.status !== undefined && o.conn.status != 0) {
2795 httpStatus = o.conn.status;
2807 if (httpStatus >= 200 && httpStatus < 300) {
2808 responseObject = this.createResponseObject(o, callback.argument);
2809 if (callback.success) {
2810 if (!callback.scope) {
2811 callback.success(responseObject);
2816 callback.success.apply(callback.scope, [responseObject]);
2821 switch (httpStatus) {
2829 responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
2830 if (callback.failure) {
2831 if (!callback.scope) {
2832 callback.failure(responseObject);
2835 callback.failure.apply(callback.scope, [responseObject]);
2840 responseObject = this.createResponseObject(o, callback.argument);
2841 if (callback.failure) {
2842 if (!callback.scope) {
2843 callback.failure(responseObject);
2846 callback.failure.apply(callback.scope, [responseObject]);
2852 this.releaseObject(o);
2853 responseObject = null;
2856 createResponseObject:function(o, callbackArg)
2863 var headerStr = o.conn.getAllResponseHeaders();
2864 var header = headerStr.split('\n');
2865 for (var i = 0; i < header.length; i++) {
2866 var delimitPos = header[i].indexOf(':');
2867 if (delimitPos != -1) {
2868 headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2876 obj.status = o.conn.status;
2877 obj.statusText = o.conn.statusText;
2878 obj.getResponseHeader = headerObj;
2879 obj.getAllResponseHeaders = headerStr;
2880 obj.responseText = o.conn.responseText;
2881 obj.responseXML = o.conn.responseXML;
2883 if (typeof callbackArg !== undefined) {
2884 obj.argument = callbackArg;
2890 createExceptionObject:function(tId, callbackArg, isAbort)
2893 var COMM_ERROR = 'communication failure';
2894 var ABORT_CODE = -1;
2895 var ABORT_ERROR = 'transaction aborted';
2901 obj.status = ABORT_CODE;
2902 obj.statusText = ABORT_ERROR;
2905 obj.status = COMM_CODE;
2906 obj.statusText = COMM_ERROR;
2910 obj.argument = callbackArg;
2916 initHeader:function(label, value, isDefault)
2918 var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
2920 if (headerObj[label] === undefined) {
2921 headerObj[label] = value;
2926 headerObj[label] = value + "," + headerObj[label];
2930 this.hasDefaultHeaders = true;
2933 this.hasHeaders = true;
2938 setHeader:function(o)
2940 if (this.hasDefaultHeaders) {
2941 for (var prop in this.defaultHeaders) {
2942 if (this.defaultHeaders.hasOwnProperty(prop)) {
2943 o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2948 if (this.hasHeaders) {
2949 for (var prop in this.headers) {
2950 if (this.headers.hasOwnProperty(prop)) {
2951 o.conn.setRequestHeader(prop, this.headers[prop]);
2955 this.hasHeaders = false;
2959 resetDefaultHeaders:function() {
2960 delete this.defaultHeaders;
2961 this.defaultHeaders = {};
2962 this.hasDefaultHeaders = false;
2965 abort:function(o, callback, isTimeout)
2967 if(this.isCallInProgress(o)) {
2969 window.clearInterval(this.poll[o.tId]);
2970 delete this.poll[o.tId];
2972 delete this.timeout[o.tId];
2975 this.handleTransactionResponse(o, callback, true);
2985 isCallInProgress:function(o)
2988 return o.conn.readyState != 4 && o.conn.readyState != 0;
2997 releaseObject:function(o)
3006 'MSXML2.XMLHTTP.3.0',
3014 * Portions of this file are based on pieces of Yahoo User Interface Library
3015 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3016 * YUI licensed under the BSD License:
3017 * http://developer.yahoo.net/yui/license.txt
3018 * <script type="text/javascript">
3022 Roo.lib.Region = function(t, r, b, l) {
3032 Roo.lib.Region.prototype = {
3033 contains : function(region) {
3034 return ( region.left >= this.left &&
3035 region.right <= this.right &&
3036 region.top >= this.top &&
3037 region.bottom <= this.bottom );
3041 getArea : function() {
3042 return ( (this.bottom - this.top) * (this.right - this.left) );
3045 intersect : function(region) {
3046 var t = Math.max(this.top, region.top);
3047 var r = Math.min(this.right, region.right);
3048 var b = Math.min(this.bottom, region.bottom);
3049 var l = Math.max(this.left, region.left);
3051 if (b >= t && r >= l) {
3052 return new Roo.lib.Region(t, r, b, l);
3057 union : function(region) {
3058 var t = Math.min(this.top, region.top);
3059 var r = Math.max(this.right, region.right);
3060 var b = Math.max(this.bottom, region.bottom);
3061 var l = Math.min(this.left, region.left);
3063 return new Roo.lib.Region(t, r, b, l);
3066 adjust : function(t, l, b, r) {
3075 Roo.lib.Region.getRegion = function(el) {
3076 var p = Roo.lib.Dom.getXY(el);
3079 var r = p[0] + el.offsetWidth;
3080 var b = p[1] + el.offsetHeight;
3083 return new Roo.lib.Region(t, r, b, l);
3086 * Portions of this file are based on pieces of Yahoo User Interface Library
3087 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3088 * YUI licensed under the BSD License:
3089 * http://developer.yahoo.net/yui/license.txt
3090 * <script type="text/javascript">
3093 //@@dep Roo.lib.Region
3096 Roo.lib.Point = function(x, y) {
3097 if (x instanceof Array) {
3101 this.x = this.right = this.left = this[0] = x;
3102 this.y = this.top = this.bottom = this[1] = y;
3105 Roo.lib.Point.prototype = new Roo.lib.Region();
3107 * Portions of this file are based on pieces of Yahoo User Interface Library
3108 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3109 * YUI licensed under the BSD License:
3110 * http://developer.yahoo.net/yui/license.txt
3111 * <script type="text/javascript">
3118 scroll : function(el, args, duration, easing, cb, scope) {
3119 this.run(el, args, duration, easing, cb, scope, Roo.lib.Scroll);
3122 motion : function(el, args, duration, easing, cb, scope) {
3123 this.run(el, args, duration, easing, cb, scope, Roo.lib.Motion);
3126 color : function(el, args, duration, easing, cb, scope) {
3127 this.run(el, args, duration, easing, cb, scope, Roo.lib.ColorAnim);
3130 run : function(el, args, duration, easing, cb, scope, type) {
3131 type = type || Roo.lib.AnimBase;
3132 if (typeof easing == "string") {
3133 easing = Roo.lib.Easing[easing];
3135 var anim = new type(el, args, duration, easing);
3136 anim.animateX(function() {
3137 Roo.callback(cb, scope);
3143 * Portions of this file are based on pieces of Yahoo User Interface Library
3144 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3145 * YUI licensed under the BSD License:
3146 * http://developer.yahoo.net/yui/license.txt
3147 * <script type="text/javascript">
3155 if (!libFlyweight) {
3156 libFlyweight = new Roo.Element.Flyweight();
3158 libFlyweight.dom = el;
3159 return libFlyweight;
3162 // since this uses fly! - it cant be in DOM (which does not have fly yet..)
3166 Roo.lib.AnimBase = function(el, attributes, duration, method) {
3168 this.init(el, attributes, duration, method);
3172 Roo.lib.AnimBase.fly = fly;
3176 Roo.lib.AnimBase.prototype = {
3178 toString: function() {
3179 var el = this.getEl();
3180 var id = el.id || el.tagName;
3181 return ("Anim " + id);
3185 noNegatives: /width|height|opacity|padding/i,
3186 offsetAttribute: /^((width|height)|(top|left))$/,
3187 defaultUnit: /width|height|top$|bottom$|left$|right$/i,
3188 offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
3192 doMethod: function(attr, start, end) {
3193 return this.method(this.currentFrame, start, end - start, this.totalFrames);
3197 setAttribute: function(attr, val, unit) {
3198 if (this.patterns.noNegatives.test(attr)) {
3199 val = (val > 0) ? val : 0;
3202 Roo.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
3206 getAttribute: function(attr) {
3207 var el = this.getEl();
3208 var val = fly(el).getStyle(attr);
3210 if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
3211 return parseFloat(val);
3214 var a = this.patterns.offsetAttribute.exec(attr) || [];
3215 var pos = !!( a[3] );
3216 var box = !!( a[2] );
3219 if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
3220 val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
3229 getDefaultUnit: function(attr) {
3230 if (this.patterns.defaultUnit.test(attr)) {
3237 animateX : function(callback, scope) {
3238 var f = function() {
3239 this.onComplete.removeListener(f);
3240 if (typeof callback == "function") {
3241 callback.call(scope || this, this);
3244 this.onComplete.addListener(f, this);
3249 setRuntimeAttribute: function(attr) {
3252 var attributes = this.attributes;
3254 this.runtimeAttributes[attr] = {};
3256 var isset = function(prop) {
3257 return (typeof prop !== 'undefined');
3260 if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
3264 start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
3267 if (isset(attributes[attr]['to'])) {
3268 end = attributes[attr]['to'];
3269 } else if (isset(attributes[attr]['by'])) {
3270 if (start.constructor == Array) {
3272 for (var i = 0, len = start.length; i < len; ++i) {
3273 end[i] = start[i] + attributes[attr]['by'][i];
3276 end = start + attributes[attr]['by'];
3280 this.runtimeAttributes[attr].start = start;
3281 this.runtimeAttributes[attr].end = end;
3284 this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
3288 init: function(el, attributes, duration, method) {
3290 var isAnimated = false;
3293 var startTime = null;
3296 var actualFrames = 0;
3299 el = Roo.getDom(el);
3302 this.attributes = attributes || {};
3305 this.duration = duration || 1;
3308 this.method = method || Roo.lib.Easing.easeNone;
3311 this.useSeconds = true;
3314 this.currentFrame = 0;
3317 this.totalFrames = Roo.lib.AnimMgr.fps;
3320 this.getEl = function() {
3325 this.isAnimated = function() {
3330 this.getStartTime = function() {
3334 this.runtimeAttributes = {};
3337 this.animate = function() {
3338 if (this.isAnimated()) {
3342 this.currentFrame = 0;
3344 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
3346 Roo.lib.AnimMgr.registerElement(this);
3350 this.stop = function(finish) {
3352 this.currentFrame = this.totalFrames;
3353 this._onTween.fire();
3355 Roo.lib.AnimMgr.stop(this);
3358 var onStart = function() {
3359 this.onStart.fire();
3361 this.runtimeAttributes = {};
3362 for (var attr in this.attributes) {
3363 this.setRuntimeAttribute(attr);
3368 startTime = new Date();
3372 var onTween = function() {
3374 duration: new Date() - this.getStartTime(),
3375 currentFrame: this.currentFrame
3378 data.toString = function() {
3380 'duration: ' + data.duration +
3381 ', currentFrame: ' + data.currentFrame
3385 this.onTween.fire(data);
3387 var runtimeAttributes = this.runtimeAttributes;
3389 for (var attr in runtimeAttributes) {
3390 this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
3396 var onComplete = function() {
3397 var actual_duration = (new Date() - startTime) / 1000 ;
3400 duration: actual_duration,
3401 frames: actualFrames,
3402 fps: actualFrames / actual_duration
3405 data.toString = function() {
3407 'duration: ' + data.duration +
3408 ', frames: ' + data.frames +
3409 ', fps: ' + data.fps
3415 this.onComplete.fire(data);
3419 this._onStart = new Roo.util.Event(this);
3420 this.onStart = new Roo.util.Event(this);
3421 this.onTween = new Roo.util.Event(this);
3422 this._onTween = new Roo.util.Event(this);
3423 this.onComplete = new Roo.util.Event(this);
3424 this._onComplete = new Roo.util.Event(this);
3425 this._onStart.addListener(onStart);
3426 this._onTween.addListener(onTween);
3427 this._onComplete.addListener(onComplete);
3432 * Portions of this file are based on pieces of Yahoo User Interface Library
3433 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3434 * YUI licensed under the BSD License:
3435 * http://developer.yahoo.net/yui/license.txt
3436 * <script type="text/javascript">
3440 Roo.lib.AnimMgr = new function() {
3457 this.registerElement = function(tween) {
3458 queue[queue.length] = tween;
3460 tween._onStart.fire();
3465 this.unRegister = function(tween, index) {
3466 tween._onComplete.fire();
3467 index = index || getIndex(tween);
3469 queue.splice(index, 1);
3473 if (tweenCount <= 0) {
3479 this.start = function() {
3480 if (thread === null) {
3481 thread = setInterval(this.run, this.delay);
3486 this.stop = function(tween) {
3488 clearInterval(thread);
3490 for (var i = 0, len = queue.length; i < len; ++i) {
3491 if (queue[0].isAnimated()) {
3492 this.unRegister(queue[0], 0);
3501 this.unRegister(tween);
3506 this.run = function() {
3507 for (var i = 0, len = queue.length; i < len; ++i) {
3508 var tween = queue[i];
3509 if (!tween || !tween.isAnimated()) {
3513 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
3515 tween.currentFrame += 1;
3517 if (tween.useSeconds) {
3518 correctFrame(tween);
3520 tween._onTween.fire();
3523 Roo.lib.AnimMgr.stop(tween, i);
3528 var getIndex = function(anim) {
3529 for (var i = 0, len = queue.length; i < len; ++i) {
3530 if (queue[i] == anim) {
3538 var correctFrame = function(tween) {
3539 var frames = tween.totalFrames;
3540 var frame = tween.currentFrame;
3541 var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
3542 var elapsed = (new Date() - tween.getStartTime());
3545 if (elapsed < tween.duration * 1000) {
3546 tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
3548 tweak = frames - (frame + 1);
3550 if (tweak > 0 && isFinite(tweak)) {
3551 if (tween.currentFrame + tweak >= frames) {
3552 tweak = frames - (frame + 1);
3555 tween.currentFrame += tweak;
3561 * Portions of this file are based on pieces of Yahoo User Interface Library
3562 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3563 * YUI licensed under the BSD License:
3564 * http://developer.yahoo.net/yui/license.txt
3565 * <script type="text/javascript">
3568 Roo.lib.Bezier = new function() {
3570 this.getPosition = function(points, t) {
3571 var n = points.length;
3574 for (var i = 0; i < n; ++i) {
3575 tmp[i] = [points[i][0], points[i][1]];
3578 for (var j = 1; j < n; ++j) {
3579 for (i = 0; i < n - j; ++i) {
3580 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3581 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3585 return [ tmp[0][0], tmp[0][1] ];
3589 * Portions of this file are based on pieces of Yahoo User Interface Library
3590 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3591 * YUI licensed under the BSD License:
3592 * http://developer.yahoo.net/yui/license.txt
3593 * <script type="text/javascript">
3598 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
3599 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3602 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
3604 var fly = Roo.lib.AnimBase.fly;
3606 var superclass = Y.ColorAnim.superclass;
3607 var proto = Y.ColorAnim.prototype;
3609 proto.toString = function() {
3610 var el = this.getEl();
3611 var id = el.id || el.tagName;
3612 return ("ColorAnim " + id);
3615 proto.patterns.color = /color$/i;
3616 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
3617 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
3618 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
3619 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
3622 proto.parseColor = function(s) {
3623 if (s.length == 3) {
3627 var c = this.patterns.hex.exec(s);
3628 if (c && c.length == 4) {
3629 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
3632 c = this.patterns.rgb.exec(s);
3633 if (c && c.length == 4) {
3634 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
3637 c = this.patterns.hex3.exec(s);
3638 if (c && c.length == 4) {
3639 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
3644 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
3645 proto.getAttribute = function(attr) {
3646 var el = this.getEl();
3647 if (this.patterns.color.test(attr)) {
3648 var val = fly(el).getStyle(attr);
3650 if (this.patterns.transparent.test(val)) {
3651 var parent = el.parentNode;
3652 val = fly(parent).getStyle(attr);
3654 while (parent && this.patterns.transparent.test(val)) {
3655 parent = parent.parentNode;
3656 val = fly(parent).getStyle(attr);
3657 if (parent.tagName.toUpperCase() == 'HTML') {
3663 val = superclass.getAttribute.call(this, attr);
3668 proto.getAttribute = function(attr) {
3669 var el = this.getEl();
3670 if (this.patterns.color.test(attr)) {
3671 var val = fly(el).getStyle(attr);
3673 if (this.patterns.transparent.test(val)) {
3674 var parent = el.parentNode;
3675 val = fly(parent).getStyle(attr);
3677 while (parent && this.patterns.transparent.test(val)) {
3678 parent = parent.parentNode;
3679 val = fly(parent).getStyle(attr);
3680 if (parent.tagName.toUpperCase() == 'HTML') {
3686 val = superclass.getAttribute.call(this, attr);
3692 proto.doMethod = function(attr, start, end) {
3695 if (this.patterns.color.test(attr)) {
3697 for (var i = 0, len = start.length; i < len; ++i) {
3698 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
3701 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
3704 val = superclass.doMethod.call(this, attr, start, end);
3710 proto.setRuntimeAttribute = function(attr) {
3711 superclass.setRuntimeAttribute.call(this, attr);
3713 if (this.patterns.color.test(attr)) {
3714 var attributes = this.attributes;
3715 var start = this.parseColor(this.runtimeAttributes[attr].start);
3716 var end = this.parseColor(this.runtimeAttributes[attr].end);
3718 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
3719 end = this.parseColor(attributes[attr].by);
3721 for (var i = 0, len = start.length; i < len; ++i) {
3722 end[i] = start[i] + end[i];
3726 this.runtimeAttributes[attr].start = start;
3727 this.runtimeAttributes[attr].end = end;
3733 * Portions of this file are based on pieces of Yahoo User Interface Library
3734 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3735 * YUI licensed under the BSD License:
3736 * http://developer.yahoo.net/yui/license.txt
3737 * <script type="text/javascript">
3743 easeNone: function (t, b, c, d) {
3744 return c * t / d + b;
3748 easeIn: function (t, b, c, d) {
3749 return c * (t /= d) * t + b;
3753 easeOut: function (t, b, c, d) {
3754 return -c * (t /= d) * (t - 2) + b;
3758 easeBoth: function (t, b, c, d) {
3759 if ((t /= d / 2) < 1) {
3760 return c / 2 * t * t + b;
3763 return -c / 2 * ((--t) * (t - 2) - 1) + b;
3767 easeInStrong: function (t, b, c, d) {
3768 return c * (t /= d) * t * t * t + b;
3772 easeOutStrong: function (t, b, c, d) {
3773 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3777 easeBothStrong: function (t, b, c, d) {
3778 if ((t /= d / 2) < 1) {
3779 return c / 2 * t * t * t * t + b;
3782 return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3787 elasticIn: function (t, b, c, d, a, p) {
3791 if ((t /= d) == 1) {
3798 if (!a || a < Math.abs(c)) {
3803 var s = p / (2 * Math.PI) * Math.asin(c / a);
3806 return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3810 elasticOut: function (t, b, c, d, a, p) {
3814 if ((t /= d) == 1) {
3821 if (!a || a < Math.abs(c)) {
3826 var s = p / (2 * Math.PI) * Math.asin(c / a);
3829 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3833 elasticBoth: function (t, b, c, d, a, p) {
3838 if ((t /= d / 2) == 2) {
3846 if (!a || a < Math.abs(c)) {
3851 var s = p / (2 * Math.PI) * Math.asin(c / a);
3855 return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3856 Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3858 return a * Math.pow(2, -10 * (t -= 1)) *
3859 Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3864 backIn: function (t, b, c, d, s) {
3865 if (typeof s == 'undefined') {
3868 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3872 backOut: function (t, b, c, d, s) {
3873 if (typeof s == 'undefined') {
3876 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3880 backBoth: function (t, b, c, d, s) {
3881 if (typeof s == 'undefined') {
3885 if ((t /= d / 2 ) < 1) {
3886 return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3888 return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3892 bounceIn: function (t, b, c, d) {
3893 return c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3897 bounceOut: function (t, b, c, d) {
3898 if ((t /= d) < (1 / 2.75)) {
3899 return c * (7.5625 * t * t) + b;
3900 } else if (t < (2 / 2.75)) {
3901 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3902 } else if (t < (2.5 / 2.75)) {
3903 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3905 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3909 bounceBoth: function (t, b, c, d) {
3911 return Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3913 return Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3916 * Portions of this file are based on pieces of Yahoo User Interface Library
3917 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
3918 * YUI licensed under the BSD License:
3919 * http://developer.yahoo.net/yui/license.txt
3920 * <script type="text/javascript">
3924 Roo.lib.Motion = function(el, attributes, duration, method) {
3926 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3930 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3934 var superclass = Y.Motion.superclass;
3935 var proto = Y.Motion.prototype;
3937 proto.toString = function() {
3938 var el = this.getEl();
3939 var id = el.id || el.tagName;
3940 return ("Motion " + id);
3943 proto.patterns.points = /^points$/i;
3945 proto.setAttribute = function(attr, val, unit) {
3946 if (this.patterns.points.test(attr)) {
3947 unit = unit || 'px';
3948 superclass.setAttribute.call(this, 'left', val[0], unit);
3949 superclass.setAttribute.call(this, 'top', val[1], unit);
3951 superclass.setAttribute.call(this, attr, val, unit);
3955 proto.getAttribute = function(attr) {
3956 if (this.patterns.points.test(attr)) {
3958 superclass.getAttribute.call(this, 'left'),
3959 superclass.getAttribute.call(this, 'top')
3962 val = superclass.getAttribute.call(this, attr);
3968 proto.doMethod = function(attr, start, end) {
3971 if (this.patterns.points.test(attr)) {
3972 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3973 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
3975 val = superclass.doMethod.call(this, attr, start, end);
3980 proto.setRuntimeAttribute = function(attr) {
3981 if (this.patterns.points.test(attr)) {
3982 var el = this.getEl();
3983 var attributes = this.attributes;
3985 var control = attributes['points']['control'] || [];
3989 if (control.length > 0 && !(control[0] instanceof Array)) {
3990 control = [control];
3993 for (i = 0,len = control.length; i < len; ++i) {
3994 tmp[i] = control[i];
3999 Roo.fly(el).position();
4001 if (isset(attributes['points']['from'])) {
4002 Roo.lib.Dom.setXY(el, attributes['points']['from']);
4005 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
4008 start = this.getAttribute('points');
4011 if (isset(attributes['points']['to'])) {
4012 end = translateValues.call(this, attributes['points']['to'], start);
4014 var pageXY = Roo.lib.Dom.getXY(this.getEl());
4015 for (i = 0,len = control.length; i < len; ++i) {
4016 control[i] = translateValues.call(this, control[i], start);
4020 } else if (isset(attributes['points']['by'])) {
4021 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
4023 for (i = 0,len = control.length; i < len; ++i) {
4024 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
4028 this.runtimeAttributes[attr] = [start];
4030 if (control.length > 0) {
4031 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
4034 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
4037 superclass.setRuntimeAttribute.call(this, attr);
4041 var translateValues = function(val, start) {
4042 var pageXY = Roo.lib.Dom.getXY(this.getEl());
4043 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
4048 var isset = function(prop) {
4049 return (typeof prop !== 'undefined');
4053 * Portions of this file are based on pieces of Yahoo User Interface Library
4054 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4055 * YUI licensed under the BSD License:
4056 * http://developer.yahoo.net/yui/license.txt
4057 * <script type="text/javascript">
4061 Roo.lib.Scroll = function(el, attributes, duration, method) {
4063 Roo.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
4067 Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
4071 var superclass = Y.Scroll.superclass;
4072 var proto = Y.Scroll.prototype;
4074 proto.toString = function() {
4075 var el = this.getEl();
4076 var id = el.id || el.tagName;
4077 return ("Scroll " + id);
4080 proto.doMethod = function(attr, start, end) {
4083 if (attr == 'scroll') {
4085 this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
4086 this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
4090 val = superclass.doMethod.call(this, attr, start, end);
4095 proto.getAttribute = function(attr) {
4097 var el = this.getEl();
4099 if (attr == 'scroll') {
4100 val = [ el.scrollLeft, el.scrollTop ];
4102 val = superclass.getAttribute.call(this, attr);
4108 proto.setAttribute = function(attr, val, unit) {
4109 var el = this.getEl();
4111 if (attr == 'scroll') {
4112 el.scrollLeft = val[0];
4113 el.scrollTop = val[1];
4115 superclass.setAttribute.call(this, attr, val, unit);
4121 * Ext JS Library 1.1.1
4122 * Copyright(c) 2006-2007, Ext JS, LLC.
4124 * Originally Released Under LGPL - original licence link has changed is not relivant.
4127 * <script type="text/javascript">
4131 // nasty IE9 hack - what a pile of crap that is..
4133 if (typeof Range != "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
4134 Range.prototype.createContextualFragment = function (html) {
4135 var doc = window.document;
4136 var container = doc.createElement("div");
4137 container.innerHTML = html;
4138 var frag = doc.createDocumentFragment(), n;
4139 while ((n = container.firstChild)) {
4140 frag.appendChild(n);
4147 * @class Roo.DomHelper
4148 * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.
4149 * 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>.
4152 Roo.DomHelper = function(){
4153 var tempTableEl = null;
4154 var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
4155 var tableRe = /^table|tbody|tr|td$/i;
4157 // build as innerHTML where available
4159 var createHtml = function(o){
4160 if(typeof o == 'string'){
4169 if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") { continue; }
4170 if(attr == "style"){
4172 if(typeof s == "function"){
4175 if(typeof s == "string"){
4176 b += ' style="' + s + '"';
4177 }else if(typeof s == "object"){
4180 if(typeof s[key] != "function"){
4181 b += key + ":" + s[key] + ";";
4188 b += ' class="' + o["cls"] + '"';
4189 }else if(attr == "htmlFor"){
4190 b += ' for="' + o["htmlFor"] + '"';
4192 b += " " + attr + '="' + o[attr] + '"';
4196 if(emptyTags.test(o.tag)){
4200 var cn = o.children || o.cn;
4202 //http://bugs.kde.org/show_bug.cgi?id=71506
4203 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4204 for(var i = 0, len = cn.length; i < len; i++) {
4205 b += createHtml(cn[i], b);
4208 b += createHtml(cn, b);
4214 b += "</" + o.tag + ">";
4221 var createDom = function(o, parentNode){
4223 // defininition craeted..
4225 if (o.ns && o.ns != 'html') {
4227 if (o.xmlns && typeof(xmlns[o.ns]) == 'undefined') {
4228 xmlns[o.ns] = o.xmlns;
4231 if (typeof(xmlns[o.ns]) == 'undefined') {
4232 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
4238 if (typeof(o) == 'string') {
4239 return parentNode.appendChild(document.createTextNode(o));
4241 o.tag = o.tag || div;
4242 if (o.ns && Roo.isIE) {
4244 o.tag = o.ns + ':' + o.tag;
4247 var el = ns ? document.createElementNS( ns, o.tag||'div') : document.createElement(o.tag||'div');
4248 var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute
4251 if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" ||
4252 attr == "style" || typeof o[attr] == "function") { continue; }
4254 if(attr=="cls" && Roo.isIE){
4255 el.className = o["cls"];
4257 if(useSet) { el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);}
4263 Roo.DomHelper.applyStyles(el, o.style);
4264 var cn = o.children || o.cn;
4266 //http://bugs.kde.org/show_bug.cgi?id=71506
4267 if((cn instanceof Array) || (Roo.isSafari && typeof(cn.join) == "function")){
4268 for(var i = 0, len = cn.length; i < len; i++) {
4269 createDom(cn[i], el);
4276 el.innerHTML = o.html;
4279 parentNode.appendChild(el);
4284 var ieTable = function(depth, s, h, e){
4285 tempTableEl.innerHTML = [s, h, e].join('');
4286 var i = -1, el = tempTableEl;
4293 // kill repeat to save bytes
4297 tbe = '</tbody>'+te,
4303 * Nasty code for IE's broken table implementation
4305 var insertIntoTable = function(tag, where, el, html){
4307 tempTableEl = document.createElement('div');
4312 if(where == 'afterbegin' || where == 'beforeend'){ // INTO a TD
4315 if(where == 'beforebegin'){
4319 before = el.nextSibling;
4322 node = ieTable(4, trs, html, tre);
4324 else if(tag == 'tr'){
4325 if(where == 'beforebegin'){
4328 node = ieTable(3, tbs, html, tbe);
4329 } else if(where == 'afterend'){
4330 before = el.nextSibling;
4332 node = ieTable(3, tbs, html, tbe);
4333 } else{ // INTO a TR
4334 if(where == 'afterbegin'){
4335 before = el.firstChild;
4337 node = ieTable(4, trs, html, tre);
4339 } else if(tag == 'tbody'){
4340 if(where == 'beforebegin'){
4343 node = ieTable(2, ts, html, te);
4344 } else if(where == 'afterend'){
4345 before = el.nextSibling;
4347 node = ieTable(2, ts, html, te);
4349 if(where == 'afterbegin'){
4350 before = el.firstChild;
4352 node = ieTable(3, tbs, html, tbe);
4355 if(where == 'beforebegin' || where == 'afterend'){ // OUTSIDE the table
4358 if(where == 'afterbegin'){
4359 before = el.firstChild;
4361 node = ieTable(2, ts, html, te);
4363 el.insertBefore(node, before);
4368 /** True to force the use of DOM instead of html fragments @type Boolean */
4372 * Returns the markup for the passed Element(s) config
4373 * @param {Object} o The Dom object spec (and children)
4376 markup : function(o){
4377 return createHtml(o);
4381 * Applies a style specification to an element
4382 * @param {String/HTMLElement} el The element to apply styles to
4383 * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or
4384 * a function which returns such a specification.
4386 applyStyles : function(el, styles){
4389 if(typeof styles == "string"){
4390 var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
4392 while ((matches = re.exec(styles)) != null){
4393 el.setStyle(matches[1], matches[2]);
4395 }else if (typeof styles == "object"){
4396 for (var style in styles){
4397 el.setStyle(style, styles[style]);
4399 }else if (typeof styles == "function"){
4400 Roo.DomHelper.applyStyles(el, styles.call());
4406 * Inserts an HTML fragment into the Dom
4407 * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
4408 * @param {HTMLElement} el The context element
4409 * @param {String} html The HTML fragmenet
4410 * @return {HTMLElement} The new node
4412 insertHtml : function(where, el, html){
4413 where = where.toLowerCase();
4414 if(el.insertAdjacentHTML){
4415 if(tableRe.test(el.tagName)){
4417 if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){
4423 el.insertAdjacentHTML('BeforeBegin', html);
4424 return el.previousSibling;
4426 el.insertAdjacentHTML('AfterBegin', html);
4427 return el.firstChild;
4429 el.insertAdjacentHTML('BeforeEnd', html);
4430 return el.lastChild;
4432 el.insertAdjacentHTML('AfterEnd', html);
4433 return el.nextSibling;
4435 throw 'Illegal insertion point -> "' + where + '"';
4437 var range = el.ownerDocument.createRange();
4441 range.setStartBefore(el);
4442 frag = range.createContextualFragment(html);
4443 el.parentNode.insertBefore(frag, el);
4444 return el.previousSibling;
4447 range.setStartBefore(el.firstChild);
4448 frag = range.createContextualFragment(html);
4449 el.insertBefore(frag, el.firstChild);
4450 return el.firstChild;
4452 el.innerHTML = html;
4453 return el.firstChild;
4457 range.setStartAfter(el.lastChild);
4458 frag = range.createContextualFragment(html);
4459 el.appendChild(frag);
4460 return el.lastChild;
4462 el.innerHTML = html;
4463 return el.lastChild;
4466 range.setStartAfter(el);
4467 frag = range.createContextualFragment(html);
4468 el.parentNode.insertBefore(frag, el.nextSibling);
4469 return el.nextSibling;
4471 throw 'Illegal insertion point -> "' + where + '"';
4475 * Creates new Dom element(s) and inserts them before el
4476 * @param {String/HTMLElement/Element} el The context element
4477 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4478 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4479 * @return {HTMLElement/Roo.Element} The new node
4481 insertBefore : function(el, o, returnElement){
4482 return this.doInsert(el, o, returnElement, "beforeBegin");
4486 * Creates new Dom element(s) and inserts them after el
4487 * @param {String/HTMLElement/Element} el The context element
4488 * @param {Object} o The Dom object spec (and children)
4489 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4490 * @return {HTMLElement/Roo.Element} The new node
4492 insertAfter : function(el, o, returnElement){
4493 return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling");
4497 * Creates new Dom element(s) and inserts them as the first child of el
4498 * @param {String/HTMLElement/Element} el The context element
4499 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4500 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4501 * @return {HTMLElement/Roo.Element} The new node
4503 insertFirst : function(el, o, returnElement){
4504 return this.doInsert(el, o, returnElement, "afterBegin");
4508 doInsert : function(el, o, returnElement, pos, sibling){
4509 el = Roo.getDom(el);
4511 if(this.useDom || o.ns){
4512 newNode = createDom(o, null);
4513 el.parentNode.insertBefore(newNode, sibling ? el[sibling] : el);
4515 var html = createHtml(o);
4516 newNode = this.insertHtml(pos, el, html);
4518 return returnElement ? Roo.get(newNode, true) : newNode;
4522 * Creates new Dom element(s) and appends them to el
4523 * @param {String/HTMLElement/Element} el The context element
4524 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4525 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4526 * @return {HTMLElement/Roo.Element} The new node
4528 append : function(el, o, returnElement){
4529 el = Roo.getDom(el);
4531 if(this.useDom || o.ns){
4532 newNode = createDom(o, null);
4533 el.appendChild(newNode);
4535 var html = createHtml(o);
4536 newNode = this.insertHtml("beforeEnd", el, html);
4538 return returnElement ? Roo.get(newNode, true) : newNode;
4542 * Creates new Dom element(s) and overwrites the contents of el with them
4543 * @param {String/HTMLElement/Element} el The context element
4544 * @param {Object/String} o The Dom object spec (and children) or raw HTML blob
4545 * @param {Boolean} returnElement (optional) true to return a Roo.Element
4546 * @return {HTMLElement/Roo.Element} The new node
4548 overwrite : function(el, o, returnElement){
4549 el = Roo.getDom(el);
4552 while (el.childNodes.length) {
4553 el.removeChild(el.firstChild);
4557 el.innerHTML = createHtml(o);
4560 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4564 * Creates a new Roo.DomHelper.Template from the Dom object spec
4565 * @param {Object} o The Dom object spec (and children)
4566 * @return {Roo.DomHelper.Template} The new template
4568 createTemplate : function(o){
4569 var html = createHtml(o);
4570 return new Roo.Template(html);
4576 * Ext JS Library 1.1.1
4577 * Copyright(c) 2006-2007, Ext JS, LLC.
4579 * Originally Released Under LGPL - original licence link has changed is not relivant.
4582 * <script type="text/javascript">
4586 * @class Roo.Template
4587 * Represents an HTML fragment template. Templates can be precompiled for greater performance.
4588 * For a list of available format functions, see {@link Roo.util.Format}.<br />
4591 var t = new Roo.Template({
4592 html : '<div name="{id}">' +
4593 '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
4595 myformat: function (value, allValues) {
4596 return 'XX' + value;
4599 t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
4601 * For more information see this blog post with examples:
4602 * <a href="http://www.cnitblog.com/seeyeah/archive/2011/12/30/38728.html/">DomHelper
4603 - Create Elements using DOM, HTML fragments and Templates</a>.
4605 * @param {Object} cfg - Configuration object.
4607 Roo.Template = function(cfg){
4609 if(cfg instanceof Array){
4611 }else if(arguments.length > 1){
4612 cfg = Array.prototype.join.call(arguments, "");
4616 if (typeof(cfg) == 'object') {
4627 Roo.Template.prototype = {
4630 * @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..
4631 * it should be fixed so that template is observable...
4635 * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
4639 * Returns an HTML fragment of this template with the specified values applied.
4640 * @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'})
4641 * @return {String} The HTML fragment
4643 applyTemplate : function(values){
4647 return this.compiled(values);
4649 var useF = this.disableFormats !== true;
4650 var fm = Roo.util.Format, tpl = this;
4651 var fn = function(m, name, format, args){
4653 if(format.substr(0, 5) == "this."){
4654 return tpl.call(format.substr(5), values[name], values);
4657 // quoted values are required for strings in compiled templates,
4658 // but for non compiled we need to strip them
4659 // quoted reversed for jsmin
4660 var re = /^\s*['"](.*)["']\s*$/;
4661 args = args.split(',');
4662 for(var i = 0, len = args.length; i < len; i++){
4663 args[i] = args[i].replace(re, "$1");
4665 args = [values[name]].concat(args);
4667 args = [values[name]];
4669 return fm[format].apply(fm, args);
4672 return values[name] !== undefined ? values[name] : "";
4675 return this.html.replace(this.re, fn);
4693 this.loading = true;
4694 this.compiled = false;
4696 var cx = new Roo.data.Connection();
4700 success : function (response) {
4702 _t.html = response.responseText;
4706 failure : function(response) {
4707 Roo.log("Template failed to load from " + _t.url);
4714 * Sets the HTML used as the template and optionally compiles it.
4715 * @param {String} html
4716 * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
4717 * @return {Roo.Template} this
4719 set : function(html, compile){
4721 this.compiled = null;
4729 * True to disable format functions (defaults to false)
4732 disableFormats : false,
4735 * The regular expression used to match template variables
4739 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
4742 * Compiles the template into an internal function, eliminating the RegEx overhead.
4743 * @return {Roo.Template} this
4745 compile : function(){
4746 var fm = Roo.util.Format;
4747 var useF = this.disableFormats !== true;
4748 var sep = Roo.isGecko ? "+" : ",";
4749 var fn = function(m, name, format, args){
4751 args = args ? ',' + args : "";
4752 if(format.substr(0, 5) != "this."){
4753 format = "fm." + format + '(';
4755 format = 'this.call("'+ format.substr(5) + '", ';
4759 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
4761 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
4764 // branched to use + in gecko and [].join() in others
4766 body = "this.compiled = function(values){ return '" +
4767 this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
4770 body = ["this.compiled = function(values){ return ['"];
4771 body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
4772 body.push("'].join('');};");
4773 body = body.join('');
4783 // private function used to call members
4784 call : function(fnName, value, allValues){
4785 return this[fnName](value, allValues);
4789 * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
4790 * @param {String/HTMLElement/Roo.Element} el The context element
4791 * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
4792 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4793 * @return {HTMLElement/Roo.Element} The new node or Element
4795 insertFirst: function(el, values, returnElement){
4796 return this.doInsert('afterBegin', el, values, returnElement);
4800 * Applies the supplied values to the template and inserts the new node(s) before el.
4801 * @param {String/HTMLElement/Roo.Element} el The context element
4802 * @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'})
4803 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4804 * @return {HTMLElement/Roo.Element} The new node or Element
4806 insertBefore: function(el, values, returnElement){
4807 return this.doInsert('beforeBegin', el, values, returnElement);
4811 * Applies the supplied values to the template and inserts the new node(s) after el.
4812 * @param {String/HTMLElement/Roo.Element} el The context element
4813 * @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'})
4814 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4815 * @return {HTMLElement/Roo.Element} The new node or Element
4817 insertAfter : function(el, values, returnElement){
4818 return this.doInsert('afterEnd', el, values, returnElement);
4822 * Applies the supplied values to the template and appends the new node(s) to el.
4823 * @param {String/HTMLElement/Roo.Element} el The context element
4824 * @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'})
4825 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4826 * @return {HTMLElement/Roo.Element} The new node or Element
4828 append : function(el, values, returnElement){
4829 return this.doInsert('beforeEnd', el, values, returnElement);
4832 doInsert : function(where, el, values, returnEl){
4833 el = Roo.getDom(el);
4834 var newNode = Roo.DomHelper.insertHtml(where, el, this.applyTemplate(values));
4835 return returnEl ? Roo.get(newNode, true) : newNode;
4839 * Applies the supplied values to the template and overwrites the content of el with the new node(s).
4840 * @param {String/HTMLElement/Roo.Element} el The context element
4841 * @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'})
4842 * @param {Boolean} returnElement (optional) true to return a Roo.Element (defaults to undefined)
4843 * @return {HTMLElement/Roo.Element} The new node or Element
4845 overwrite : function(el, values, returnElement){
4846 el = Roo.getDom(el);
4847 el.innerHTML = this.applyTemplate(values);
4848 return returnElement ? Roo.get(el.firstChild, true) : el.firstChild;
4852 * Alias for {@link #applyTemplate}
4855 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4858 Roo.DomHelper.Template = Roo.Template;
4861 * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
4862 * @param {String/HTMLElement} el A DOM element or its id
4863 * @returns {Roo.Template} The created template
4866 Roo.Template.from = function(el){
4867 el = Roo.getDom(el);
4868 return new Roo.Template(el.value || el.innerHTML);
4871 * Ext JS Library 1.1.1
4872 * Copyright(c) 2006-2007, Ext JS, LLC.
4874 * Originally Released Under LGPL - original licence link has changed is not relivant.
4877 * <script type="text/javascript">
4882 * This is code is also distributed under MIT license for use
4883 * with jQuery and prototype JavaScript libraries.
4886 * @class Roo.DomQuery
4887 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).
4889 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>
4892 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.
4894 <h4>Element Selectors:</h4>
4896 <li> <b>*</b> any element</li>
4897 <li> <b>E</b> an element with the tag E</li>
4898 <li> <b>E F</b> All descendent elements of E that have the tag F</li>
4899 <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
4900 <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
4901 <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
4903 <h4>Attribute Selectors:</h4>
4904 <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
4906 <li> <b>E[foo]</b> has an attribute "foo"</li>
4907 <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
4908 <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
4909 <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
4910 <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
4911 <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
4912 <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
4914 <h4>Pseudo Classes:</h4>
4916 <li> <b>E:first-child</b> E is the first child of its parent</li>
4917 <li> <b>E:last-child</b> E is the last child of its parent</li>
4918 <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>
4919 <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
4920 <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
4921 <li> <b>E:only-child</b> E is the only child of its parent</li>
4922 <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>
4923 <li> <b>E:first</b> the first E in the resultset</li>
4924 <li> <b>E:last</b> the last E in the resultset</li>
4925 <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
4926 <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
4927 <li> <b>E:even</b> shortcut for :nth-child(even)</li>
4928 <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
4929 <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
4930 <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
4931 <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
4932 <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
4933 <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
4935 <h4>CSS Value Selectors:</h4>
4937 <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
4938 <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
4939 <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
4940 <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
4941 <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
4942 <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
4946 Roo.DomQuery = function(){
4947 var cache = {}, simpleCache = {}, valueCache = {};
4948 var nonSpace = /\S/;
4949 var trimRe = /^\s+|\s+$/g;
4950 var tplRe = /\{(\d+)\}/g;
4951 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
4952 var tagTokenRe = /^(#)?([\w-\*]+)/;
4953 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
4955 function child(p, index){
4957 var n = p.firstChild;
4959 if(n.nodeType == 1){
4970 while((n = n.nextSibling) && n.nodeType != 1);
4975 while((n = n.previousSibling) && n.nodeType != 1);
4979 function children(d){
4980 var n = d.firstChild, ni = -1;
4982 var nx = n.nextSibling;
4983 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
4993 function byClassName(c, a, v){
4997 var r = [], ri = -1, cn;
4998 for(var i = 0, ci; ci = c[i]; i++){
4999 if((' '+ci.className+' ').indexOf(v) != -1){
5006 function attrValue(n, attr){
5007 if(!n.tagName && typeof n.length != "undefined"){
5016 if(attr == "class" || attr == "className"){
5019 return n.getAttribute(attr) || n[attr];
5023 function getNodes(ns, mode, tagName){
5024 var result = [], ri = -1, cs;
5028 tagName = tagName || "*";
5029 if(typeof ns.getElementsByTagName != "undefined"){
5033 for(var i = 0, ni; ni = ns[i]; i++){
5034 cs = ni.getElementsByTagName(tagName);
5035 for(var j = 0, ci; ci = cs[j]; j++){
5039 }else if(mode == "/" || mode == ">"){
5040 var utag = tagName.toUpperCase();
5041 for(var i = 0, ni, cn; ni = ns[i]; i++){
5042 cn = ni.children || ni.childNodes;
5043 for(var j = 0, cj; cj = cn[j]; j++){
5044 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
5049 }else if(mode == "+"){
5050 var utag = tagName.toUpperCase();
5051 for(var i = 0, n; n = ns[i]; i++){
5052 while((n = n.nextSibling) && n.nodeType != 1);
5053 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
5057 }else if(mode == "~"){
5058 for(var i = 0, n; n = ns[i]; i++){
5059 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
5068 function concat(a, b){
5072 for(var i = 0, l = b.length; i < l; i++){
5078 function byTag(cs, tagName){
5079 if(cs.tagName || cs == document){
5085 var r = [], ri = -1;
5086 tagName = tagName.toLowerCase();
5087 for(var i = 0, ci; ci = cs[i]; i++){
5088 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
5095 function byId(cs, attr, id){
5096 if(cs.tagName || cs == document){
5102 var r = [], ri = -1;
5103 for(var i = 0,ci; ci = cs[i]; i++){
5104 if(ci && ci.id == id){
5112 function byAttribute(cs, attr, value, op, custom){
5113 var r = [], ri = -1, st = custom=="{";
5114 var f = Roo.DomQuery.operators[op];
5115 for(var i = 0, ci; ci = cs[i]; i++){
5118 a = Roo.DomQuery.getStyle(ci, attr);
5120 else if(attr == "class" || attr == "className"){
5122 }else if(attr == "for"){
5124 }else if(attr == "href"){
5125 a = ci.getAttribute("href", 2);
5127 a = ci.getAttribute(attr);
5129 if((f && f(a, value)) || (!f && a)){
5136 function byPseudo(cs, name, value){
5137 return Roo.DomQuery.pseudos[name](cs, value);
5140 // This is for IE MSXML which does not support expandos.
5141 // IE runs the same speed using setAttribute, however FF slows way down
5142 // and Safari completely fails so they need to continue to use expandos.
5143 var isIE = window.ActiveXObject ? true : false;
5145 // this eval is stop the compressor from
5146 // renaming the variable to something shorter
5148 /** eval:var:batch */
5153 function nodupIEXml(cs){
5155 cs[0].setAttribute("_nodup", d);
5157 for(var i = 1, len = cs.length; i < len; i++){
5159 if(!c.getAttribute("_nodup") != d){
5160 c.setAttribute("_nodup", d);
5164 for(var i = 0, len = cs.length; i < len; i++){
5165 cs[i].removeAttribute("_nodup");
5174 var len = cs.length, c, i, r = cs, cj, ri = -1;
5175 if(!len || typeof cs.nodeType != "undefined" || len == 1){
5178 if(isIE && typeof cs[0].selectSingleNode != "undefined"){
5179 return nodupIEXml(cs);
5183 for(i = 1; c = cs[i]; i++){
5188 for(var j = 0; j < i; j++){
5191 for(j = i+1; cj = cs[j]; j++){
5203 function quickDiffIEXml(c1, c2){
5205 for(var i = 0, len = c1.length; i < len; i++){
5206 c1[i].setAttribute("_qdiff", d);
5209 for(var i = 0, len = c2.length; i < len; i++){
5210 if(c2[i].getAttribute("_qdiff") != d){
5211 r[r.length] = c2[i];
5214 for(var i = 0, len = c1.length; i < len; i++){
5215 c1[i].removeAttribute("_qdiff");
5220 function quickDiff(c1, c2){
5221 var len1 = c1.length;
5225 if(isIE && c1[0].selectSingleNode){
5226 return quickDiffIEXml(c1, c2);
5229 for(var i = 0; i < len1; i++){
5233 for(var i = 0, len = c2.length; i < len; i++){
5234 if(c2[i]._qdiff != d){
5235 r[r.length] = c2[i];
5241 function quickId(ns, mode, root, id){
5243 var d = root.ownerDocument || root;
5244 return d.getElementById(id);
5246 ns = getNodes(ns, mode, "*");
5247 return byId(ns, null, id);
5251 getStyle : function(el, name){
5252 return Roo.fly(el).getStyle(name);
5255 * Compiles a selector/xpath query into a reusable function. The returned function
5256 * takes one parameter "root" (optional), which is the context node from where the query should start.
5257 * @param {String} selector The selector/xpath query
5258 * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
5259 * @return {Function}
5261 compile : function(path, type){
5262 type = type || "select";
5264 var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
5265 var q = path, mode, lq;
5266 var tk = Roo.DomQuery.matchers;
5267 var tklen = tk.length;
5270 // accept leading mode switch
5271 var lmode = q.match(modeRe);
5272 if(lmode && lmode[1]){
5273 fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
5274 q = q.replace(lmode[1], "");
5276 // strip leading slashes
5277 while(path.substr(0, 1)=="/"){
5278 path = path.substr(1);
5281 while(q && lq != q){
5283 var tm = q.match(tagTokenRe);
5284 if(type == "select"){
5287 fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
5289 fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
5291 q = q.replace(tm[0], "");
5292 }else if(q.substr(0, 1) != '@'){
5293 fn[fn.length] = 'n = getNodes(n, mode, "*");';
5298 fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
5300 fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
5302 q = q.replace(tm[0], "");
5305 while(!(mm = q.match(modeRe))){
5306 var matched = false;
5307 for(var j = 0; j < tklen; j++){
5309 var m = q.match(t.re);
5311 fn[fn.length] = t.select.replace(tplRe, function(x, i){
5314 q = q.replace(m[0], "");
5319 // prevent infinite loop on bad selector
5321 throw 'Error parsing selector, parsing failed at "' + q + '"';
5325 fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";';
5326 q = q.replace(mm[1], "");
5329 fn[fn.length] = "return nodup(n);\n}";
5332 * list of variables that need from compression as they are used by eval.
5342 * eval:var:byClassName
5344 * eval:var:byAttribute
5345 * eval:var:attrValue
5353 * Selects a group of elements.
5354 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
5355 * @param {Node} root (optional) The start of the query (defaults to document).
5358 select : function(path, root, type){
5359 if(!root || root == document){
5362 if(typeof root == "string"){
5363 root = document.getElementById(root);
5365 var paths = path.split(",");
5367 for(var i = 0, len = paths.length; i < len; i++){
5368 var p = paths[i].replace(trimRe, "");
5370 cache[p] = Roo.DomQuery.compile(p);
5372 throw p + " is not a valid selector";
5375 var result = cache[p](root);
5376 if(result && result != document){
5377 results = results.concat(result);
5380 if(paths.length > 1){
5381 return nodup(results);
5387 * Selects a single element.
5388 * @param {String} selector The selector/xpath query
5389 * @param {Node} root (optional) The start of the query (defaults to document).
5392 selectNode : function(path, root){
5393 return Roo.DomQuery.select(path, root)[0];
5397 * Selects the value of a node, optionally replacing null with the defaultValue.
5398 * @param {String} selector The selector/xpath query
5399 * @param {Node} root (optional) The start of the query (defaults to document).
5400 * @param {String} defaultValue
5402 selectValue : function(path, root, defaultValue){
5403 path = path.replace(trimRe, "");
5404 if(!valueCache[path]){
5405 valueCache[path] = Roo.DomQuery.compile(path, "select");
5407 var n = valueCache[path](root);
5408 n = n[0] ? n[0] : n;
5409 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
5410 return ((v === null||v === undefined||v==='') ? defaultValue : v);
5414 * Selects the value of a node, parsing integers and floats.
5415 * @param {String} selector The selector/xpath query
5416 * @param {Node} root (optional) The start of the query (defaults to document).
5417 * @param {Number} defaultValue
5420 selectNumber : function(path, root, defaultValue){
5421 var v = Roo.DomQuery.selectValue(path, root, defaultValue || 0);
5422 return parseFloat(v);
5426 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
5427 * @param {String/HTMLElement/Array} el An element id, element or array of elements
5428 * @param {String} selector The simple selector to test
5431 is : function(el, ss){
5432 if(typeof el == "string"){
5433 el = document.getElementById(el);
5435 var isArray = (el instanceof Array);
5436 var result = Roo.DomQuery.filter(isArray ? el : [el], ss);
5437 return isArray ? (result.length == el.length) : (result.length > 0);
5441 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
5442 * @param {Array} el An array of elements to filter
5443 * @param {String} selector The simple selector to test
5444 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
5445 * the selector instead of the ones that match
5448 filter : function(els, ss, nonMatches){
5449 ss = ss.replace(trimRe, "");
5450 if(!simpleCache[ss]){
5451 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
5453 var result = simpleCache[ss](els);
5454 return nonMatches ? quickDiff(result, els) : result;
5458 * Collection of matching regular expressions and code snippets.
5462 select: 'n = byClassName(n, null, " {1} ");'
5464 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
5465 select: 'n = byPseudo(n, "{1}", "{2}");'
5467 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
5468 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
5471 select: 'n = byId(n, null, "{1}");'
5474 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
5479 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
5480 * 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, > <.
5483 "=" : function(a, v){
5486 "!=" : function(a, v){
5489 "^=" : function(a, v){
5490 return a && a.substr(0, v.length) == v;
5492 "$=" : function(a, v){
5493 return a && a.substr(a.length-v.length) == v;
5495 "*=" : function(a, v){
5496 return a && a.indexOf(v) !== -1;
5498 "%=" : function(a, v){
5499 return (a % v) == 0;
5501 "|=" : function(a, v){
5502 return a && (a == v || a.substr(0, v.length+1) == v+'-');
5504 "~=" : function(a, v){
5505 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
5510 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
5511 * and the argument (if any) supplied in the selector.
5514 "first-child" : function(c){
5515 var r = [], ri = -1, n;
5516 for(var i = 0, ci; ci = n = c[i]; i++){
5517 while((n = n.previousSibling) && n.nodeType != 1);
5525 "last-child" : function(c){
5526 var r = [], ri = -1, n;
5527 for(var i = 0, ci; ci = n = c[i]; i++){
5528 while((n = n.nextSibling) && n.nodeType != 1);
5536 "nth-child" : function(c, a) {
5537 var r = [], ri = -1;
5538 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
5539 var f = (m[1] || 1) - 0, l = m[2] - 0;
5540 for(var i = 0, n; n = c[i]; i++){
5541 var pn = n.parentNode;
5542 if (batch != pn._batch) {
5544 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
5545 if(cn.nodeType == 1){
5552 if (l == 0 || n.nodeIndex == l){
5555 } else if ((n.nodeIndex + l) % f == 0){
5563 "only-child" : function(c){
5564 var r = [], ri = -1;;
5565 for(var i = 0, ci; ci = c[i]; i++){
5566 if(!prev(ci) && !next(ci)){
5573 "empty" : function(c){
5574 var r = [], ri = -1;
5575 for(var i = 0, ci; ci = c[i]; i++){
5576 var cns = ci.childNodes, j = 0, cn, empty = true;
5579 if(cn.nodeType == 1 || cn.nodeType == 3){
5591 "contains" : function(c, v){
5592 var r = [], ri = -1;
5593 for(var i = 0, ci; ci = c[i]; i++){
5594 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
5601 "nodeValue" : function(c, v){
5602 var r = [], ri = -1;
5603 for(var i = 0, ci; ci = c[i]; i++){
5604 if(ci.firstChild && ci.firstChild.nodeValue == v){
5611 "checked" : function(c){
5612 var r = [], ri = -1;
5613 for(var i = 0, ci; ci = c[i]; i++){
5614 if(ci.checked == true){
5621 "not" : function(c, ss){
5622 return Roo.DomQuery.filter(c, ss, true);
5625 "odd" : function(c){
5626 return this["nth-child"](c, "odd");
5629 "even" : function(c){
5630 return this["nth-child"](c, "even");
5633 "nth" : function(c, a){
5634 return c[a-1] || [];
5637 "first" : function(c){
5641 "last" : function(c){
5642 return c[c.length-1] || [];
5645 "has" : function(c, ss){
5646 var s = Roo.DomQuery.select;
5647 var r = [], ri = -1;
5648 for(var i = 0, ci; ci = c[i]; i++){
5649 if(s(ss, ci).length > 0){
5656 "next" : function(c, ss){
5657 var is = Roo.DomQuery.is;
5658 var r = [], ri = -1;
5659 for(var i = 0, ci; ci = c[i]; i++){
5668 "prev" : function(c, ss){
5669 var is = Roo.DomQuery.is;
5670 var r = [], ri = -1;
5671 for(var i = 0, ci; ci = c[i]; i++){
5684 * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Roo.DomQuery#select}
5685 * @param {String} path The selector/xpath query
5686 * @param {Node} root (optional) The start of the query (defaults to document).
5691 Roo.query = Roo.DomQuery.select;
5694 * Ext JS Library 1.1.1
5695 * Copyright(c) 2006-2007, Ext JS, LLC.
5697 * Originally Released Under LGPL - original licence link has changed is not relivant.
5700 * <script type="text/javascript">
5704 * @class Roo.util.Observable
5705 * Base class that provides a common interface for publishing events. Subclasses are expected to
5706 * to have a property "events" with all the events defined.<br>
5709 Employee = function(name){
5716 Roo.extend(Employee, Roo.util.Observable);
5718 * @param {Object} config properties to use (incuding events / listeners)
5721 Roo.util.Observable = function(cfg){
5724 this.addEvents(cfg.events || {});
5726 delete cfg.events; // make sure
5729 Roo.apply(this, cfg);
5732 this.on(this.listeners);
5733 delete this.listeners;
5736 Roo.util.Observable.prototype = {
5738 * @cfg {Object} listeners list of events and functions to call for this object,
5742 'click' : function(e) {
5752 * Fires the specified event with the passed parameters (minus the event name).
5753 * @param {String} eventName
5754 * @param {Object...} args Variable number of parameters are passed to handlers
5755 * @return {Boolean} returns false if any of the handlers return false otherwise it returns true
5757 fireEvent : function(){
5758 var ce = this.events[arguments[0].toLowerCase()];
5759 if(typeof ce == "object"){
5760 return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
5767 filterOptRe : /^(?:scope|delay|buffer|single)$/,
5770 * Appends an event handler to this component
5771 * @param {String} eventName The type of event to listen for
5772 * @param {Function} handler The method the event invokes
5773 * @param {Object} scope (optional) The scope in which to execute the handler
5774 * function. The handler function's "this" context.
5775 * @param {Object} options (optional) An object containing handler configuration
5776 * properties. This may contain any of the following properties:<ul>
5777 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
5778 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
5779 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
5780 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
5781 * by the specified number of milliseconds. If the event fires again within that time, the original
5782 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
5785 * <b>Combining Options</b><br>
5786 * Using the options argument, it is possible to combine different types of listeners:<br>
5788 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
5790 el.on('click', this.onClick, this, {
5797 * <b>Attaching multiple handlers in 1 call</b><br>
5798 * The method also allows for a single argument to be passed which is a config object containing properties
5799 * which specify multiple handlers.
5808 fn: this.onMouseOver,
5812 fn: this.onMouseOut,
5818 * Or a shorthand syntax which passes the same scope object to all handlers:
5821 'click': this.onClick,
5822 'mouseover': this.onMouseOver,
5823 'mouseout': this.onMouseOut,
5828 addListener : function(eventName, fn, scope, o){
5829 if(typeof eventName == "object"){
5832 if(this.filterOptRe.test(e)){
5835 if(typeof o[e] == "function"){
5837 this.addListener(e, o[e], o.scope, o);
5839 // individual options
5840 this.addListener(e, o[e].fn, o[e].scope, o[e]);
5845 o = (!o || typeof o == "boolean") ? {} : o;
5846 eventName = eventName.toLowerCase();
5847 var ce = this.events[eventName] || true;
5848 if(typeof ce == "boolean"){
5849 ce = new Roo.util.Event(this, eventName);
5850 this.events[eventName] = ce;
5852 ce.addListener(fn, scope, o);
5856 * Removes a listener
5857 * @param {String} eventName The type of event to listen for
5858 * @param {Function} handler The handler to remove
5859 * @param {Object} scope (optional) The scope (this object) for the handler
5861 removeListener : function(eventName, fn, scope){
5862 var ce = this.events[eventName.toLowerCase()];
5863 if(typeof ce == "object"){
5864 ce.removeListener(fn, scope);
5869 * Removes all listeners for this object
5871 purgeListeners : function(){
5872 for(var evt in this.events){
5873 if(typeof this.events[evt] == "object"){
5874 this.events[evt].clearListeners();
5879 relayEvents : function(o, events){
5880 var createHandler = function(ename){
5882 return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0)));
5885 for(var i = 0, len = events.length; i < len; i++){
5886 var ename = events[i];
5887 if(!this.events[ename]){ this.events[ename] = true; };
5888 o.on(ename, createHandler(ename), this);
5893 * Used to define events on this Observable
5894 * @param {Object} object The object with the events defined
5896 addEvents : function(o){
5900 Roo.applyIf(this.events, o);
5904 * Checks to see if this object has any listeners for a specified event
5905 * @param {String} eventName The name of the event to check for
5906 * @return {Boolean} True if the event is being listened for, else false
5908 hasListener : function(eventName){
5909 var e = this.events[eventName];
5910 return typeof e == "object" && e.listeners.length > 0;
5914 * Appends an event handler to this element (shorthand for addListener)
5915 * @param {String} eventName The type of event to listen for
5916 * @param {Function} handler The method the event invokes
5917 * @param {Object} scope (optional) The scope in which to execute the handler
5918 * function. The handler function's "this" context.
5919 * @param {Object} options (optional)
5922 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
5924 * Removes a listener (shorthand for removeListener)
5925 * @param {String} eventName The type of event to listen for
5926 * @param {Function} handler The handler to remove
5927 * @param {Object} scope (optional) The scope (this object) for the handler
5930 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
5933 * Starts capture on the specified Observable. All events will be passed
5934 * to the supplied function with the event name + standard signature of the event
5935 * <b>before</b> the event is fired. If the supplied function returns false,
5936 * the event will not fire.
5937 * @param {Observable} o The Observable to capture
5938 * @param {Function} fn The function to call
5939 * @param {Object} scope (optional) The scope (this object) for the fn
5942 Roo.util.Observable.capture = function(o, fn, scope){
5943 o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
5947 * Removes <b>all</b> added captures from the Observable.
5948 * @param {Observable} o The Observable to release
5951 Roo.util.Observable.releaseCapture = function(o){
5952 o.fireEvent = Roo.util.Observable.prototype.fireEvent;
5957 var createBuffered = function(h, o, scope){
5958 var task = new Roo.util.DelayedTask();
5960 task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
5964 var createSingle = function(h, e, fn, scope){
5966 e.removeListener(fn, scope);
5967 return h.apply(scope, arguments);
5971 var createDelayed = function(h, o, scope){
5973 var args = Array.prototype.slice.call(arguments, 0);
5974 setTimeout(function(){
5975 h.apply(scope, args);
5980 Roo.util.Event = function(obj, name){
5983 this.listeners = [];
5986 Roo.util.Event.prototype = {
5987 addListener : function(fn, scope, options){
5988 var o = options || {};
5989 scope = scope || this.obj;
5990 if(!this.isListening(fn, scope)){
5991 var l = {fn: fn, scope: scope, options: o};
5994 h = createDelayed(h, o, scope);
5997 h = createSingle(h, this, fn, scope);
6000 h = createBuffered(h, o, scope);
6003 if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop
6004 this.listeners.push(l);
6006 this.listeners = this.listeners.slice(0);
6007 this.listeners.push(l);
6012 findListener : function(fn, scope){
6013 scope = scope || this.obj;
6014 var ls = this.listeners;
6015 for(var i = 0, len = ls.length; i < len; i++){
6017 if(l.fn == fn && l.scope == scope){
6024 isListening : function(fn, scope){
6025 return this.findListener(fn, scope) != -1;
6028 removeListener : function(fn, scope){
6030 if((index = this.findListener(fn, scope)) != -1){
6032 this.listeners.splice(index, 1);
6034 this.listeners = this.listeners.slice(0);
6035 this.listeners.splice(index, 1);
6042 clearListeners : function(){
6043 this.listeners = [];
6047 var ls = this.listeners, scope, len = ls.length;
6050 var args = Array.prototype.slice.call(arguments, 0);
6051 for(var i = 0; i < len; i++){
6053 if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
6054 this.firing = false;
6058 this.firing = false;
6065 * Copyright(c) 2007-2017, Roo J Solutions Ltd
6072 * @class Roo.Document
6073 * @extends Roo.util.Observable
6074 * This is a convience class to wrap up the main document loading code.. , rather than adding Roo.onReady(......)
6076 * @param {Object} config the methods and properties of the 'base' class for the application.
6078 * Generic Page handler - implement this to start your app..
6081 * MyProject = new Roo.Document({
6083 'load' : true // your events..
6086 'ready' : function() {
6087 // fired on Roo.onReady()
6092 Roo.Document = function(cfg) {
6097 Roo.util.Observable.call(this,cfg);
6101 Roo.onReady(function() {
6102 _this.fireEvent('ready');
6108 Roo.extend(Roo.Document, Roo.util.Observable, {});/*
6110 * Ext JS Library 1.1.1
6111 * Copyright(c) 2006-2007, Ext JS, LLC.
6113 * Originally Released Under LGPL - original licence link has changed is not relivant.
6116 * <script type="text/javascript">
6120 * @class Roo.EventManager
6121 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
6122 * several useful events directly.
6123 * See {@link Roo.EventObject} for more details on normalized event objects.
6126 Roo.EventManager = function(){
6127 var docReadyEvent, docReadyProcId, docReadyState = false;
6128 var resizeEvent, resizeTask, textEvent, textSize;
6129 var E = Roo.lib.Event;
6130 var D = Roo.lib.Dom;
6135 var fireDocReady = function(){
6137 docReadyState = true;
6140 clearInterval(docReadyProcId);
6142 if(Roo.isGecko || Roo.isOpera) {
6143 document.removeEventListener("DOMContentLoaded", fireDocReady, false);
6146 var defer = document.getElementById("ie-deferred-loader");
6148 defer.onreadystatechange = null;
6149 defer.parentNode.removeChild(defer);
6153 docReadyEvent.fire();
6154 docReadyEvent.clearListeners();
6159 var initDocReady = function(){
6160 docReadyEvent = new Roo.util.Event();
6161 if(Roo.isGecko || Roo.isOpera) {
6162 document.addEventListener("DOMContentLoaded", fireDocReady, false);
6164 document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
6165 var defer = document.getElementById("ie-deferred-loader");
6166 defer.onreadystatechange = function(){
6167 if(this.readyState == "complete"){
6171 }else if(Roo.isSafari){
6172 docReadyProcId = setInterval(function(){
6173 var rs = document.readyState;
6174 if(rs == "complete") {
6179 // no matter what, make sure it fires on load
6180 E.on(window, "load", fireDocReady);
6183 var createBuffered = function(h, o){
6184 var task = new Roo.util.DelayedTask(h);
6186 // create new event object impl so new events don't wipe out properties
6187 e = new Roo.EventObjectImpl(e);
6188 task.delay(o.buffer, h, null, [e]);
6192 var createSingle = function(h, el, ename, fn){
6194 Roo.EventManager.removeListener(el, ename, fn);
6199 var createDelayed = function(h, o){
6201 // create new event object impl so new events don't wipe out properties
6202 e = new Roo.EventObjectImpl(e);
6203 setTimeout(function(){
6208 var transitionEndVal = false;
6210 var transitionEnd = function()
6212 if (transitionEndVal) {
6213 return transitionEndVal;
6215 var el = document.createElement('div');
6217 var transEndEventNames = {
6218 WebkitTransition : 'webkitTransitionEnd',
6219 MozTransition : 'transitionend',
6220 OTransition : 'oTransitionEnd otransitionend',
6221 transition : 'transitionend'
6224 for (var name in transEndEventNames) {
6225 if (el.style[name] !== undefined) {
6226 transitionEndVal = transEndEventNames[name];
6227 return transitionEndVal ;
6233 var listen = function(element, ename, opt, fn, scope){
6234 var o = (!opt || typeof opt == "boolean") ? {} : opt;
6235 fn = fn || o.fn; scope = scope || o.scope;
6236 var el = Roo.getDom(element);
6240 throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
6243 if (ename == 'transitionend') {
6244 ename = transitionEnd();
6246 var h = function(e){
6247 e = Roo.EventObject.setEvent(e);
6250 t = e.getTarget(o.delegate, el);
6257 if(o.stopEvent === true){
6260 if(o.preventDefault === true){
6263 if(o.stopPropagation === true){
6264 e.stopPropagation();
6267 if(o.normalized === false){
6271 fn.call(scope || el, e, t, o);
6274 h = createDelayed(h, o);
6277 h = createSingle(h, el, ename, fn);
6280 h = createBuffered(h, o);
6283 fn._handlers = fn._handlers || [];
6286 fn._handlers.push([Roo.id(el), ename, h]);
6291 if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
6292 el.addEventListener("DOMMouseScroll", h, false);
6293 E.on(window, 'unload', function(){
6294 el.removeEventListener("DOMMouseScroll", h, false);
6297 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6298 Roo.EventManager.stoppedMouseDownEvent.addListener(h);
6303 var stopListening = function(el, ename, fn){
6304 var id = Roo.id(el), hds = fn._handlers, hd = fn;
6306 for(var i = 0, len = hds.length; i < len; i++){
6308 if(h[0] == id && h[1] == ename){
6315 E.un(el, ename, hd);
6316 el = Roo.getDom(el);
6317 if(ename == "mousewheel" && el.addEventListener){
6318 el.removeEventListener("DOMMouseScroll", hd, false);
6320 if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
6321 Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
6325 var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
6332 * @scope Roo.EventManager
6337 * This is no longer needed and is deprecated. Places a simple wrapper around an event handler to override the browser event
6338 * object with a Roo.EventObject
6339 * @param {Function} fn The method the event invokes
6340 * @param {Object} scope An object that becomes the scope of the handler
6341 * @param {boolean} override If true, the obj passed in becomes
6342 * the execution scope of the listener
6343 * @return {Function} The wrapped function
6346 wrap : function(fn, scope, override){
6348 Roo.EventObject.setEvent(e);
6349 fn.call(override ? scope || window : window, Roo.EventObject, scope);
6354 * Appends an event handler to an element (shorthand for addListener)
6355 * @param {String/HTMLElement} element The html element or id to assign the
6356 * @param {String} eventName The type of event to listen for
6357 * @param {Function} handler The method the event invokes
6358 * @param {Object} scope (optional) The scope in which to execute the handler
6359 * function. The handler function's "this" context.
6360 * @param {Object} options (optional) An object containing handler configuration
6361 * properties. This may contain any of the following properties:<ul>
6362 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6363 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6364 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6365 * <li>preventDefault {Boolean} True to prevent the default action</li>
6366 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6367 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6368 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6369 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6370 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6371 * by the specified number of milliseconds. If the event fires again within that time, the original
6372 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6375 * <b>Combining Options</b><br>
6376 * Using the options argument, it is possible to combine different types of listeners:<br>
6378 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6380 el.on('click', this.onClick, this, {
6387 * <b>Attaching multiple handlers in 1 call</b><br>
6388 * The method also allows for a single argument to be passed which is a config object containing properties
6389 * which specify multiple handlers.
6399 fn: this.onMouseOver
6408 * Or a shorthand syntax:<br>
6411 'click' : this.onClick,
6412 'mouseover' : this.onMouseOver,
6413 'mouseout' : this.onMouseOut
6417 addListener : function(element, eventName, fn, scope, options){
6418 if(typeof eventName == "object"){
6424 if(typeof o[e] == "function"){
6426 listen(element, e, o, o[e], o.scope);
6428 // individual options
6429 listen(element, e, o[e]);
6434 return listen(element, eventName, options, fn, scope);
6438 * Removes an event handler
6440 * @param {String/HTMLElement} element The id or html element to remove the
6442 * @param {String} eventName The type of event
6443 * @param {Function} fn
6444 * @return {Boolean} True if a listener was actually removed
6446 removeListener : function(element, eventName, fn){
6447 return stopListening(element, eventName, fn);
6451 * Fires when the document is ready (before onload and before images are loaded). Can be
6452 * accessed shorthanded Roo.onReady().
6453 * @param {Function} fn The method the event invokes
6454 * @param {Object} scope An object that becomes the scope of the handler
6455 * @param {boolean} options
6457 onDocumentReady : function(fn, scope, options){
6458 if(docReadyState){ // if it already fired
6459 docReadyEvent.addListener(fn, scope, options);
6460 docReadyEvent.fire();
6461 docReadyEvent.clearListeners();
6467 docReadyEvent.addListener(fn, scope, options);
6471 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
6472 * @param {Function} fn The method the event invokes
6473 * @param {Object} scope An object that becomes the scope of the handler
6474 * @param {boolean} options
6476 onWindowResize : function(fn, scope, options){
6478 resizeEvent = new Roo.util.Event();
6479 resizeTask = new Roo.util.DelayedTask(function(){
6480 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6482 E.on(window, "resize", function(){
6484 resizeTask.delay(50);
6486 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6490 resizeEvent.addListener(fn, scope, options);
6494 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
6495 * @param {Function} fn The method the event invokes
6496 * @param {Object} scope An object that becomes the scope of the handler
6497 * @param {boolean} options
6499 onTextResize : function(fn, scope, options){
6501 textEvent = new Roo.util.Event();
6502 var textEl = new Roo.Element(document.createElement('div'));
6503 textEl.dom.className = 'x-text-resize';
6504 textEl.dom.innerHTML = 'X';
6505 textEl.appendTo(document.body);
6506 textSize = textEl.dom.offsetHeight;
6507 setInterval(function(){
6508 if(textEl.dom.offsetHeight != textSize){
6509 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
6511 }, this.textResizeInterval);
6513 textEvent.addListener(fn, scope, options);
6517 * Removes the passed window resize listener.
6518 * @param {Function} fn The method the event invokes
6519 * @param {Object} scope The scope of handler
6521 removeResizeListener : function(fn, scope){
6523 resizeEvent.removeListener(fn, scope);
6528 fireResize : function(){
6530 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
6534 * Url used for onDocumentReady with using SSL (defaults to Roo.SSL_SECURE_URL)
6538 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
6540 textResizeInterval : 50
6545 * @scopeAlias pub=Roo.EventManager
6549 * Appends an event handler to an element (shorthand for addListener)
6550 * @param {String/HTMLElement} element The html element or id to assign the
6551 * @param {String} eventName The type of event to listen for
6552 * @param {Function} handler The method the event invokes
6553 * @param {Object} scope (optional) The scope in which to execute the handler
6554 * function. The handler function's "this" context.
6555 * @param {Object} options (optional) An object containing handler configuration
6556 * properties. This may contain any of the following properties:<ul>
6557 * <li>scope {Object} The scope in which to execute the handler function. The handler function's "this" context.</li>
6558 * <li>delegate {String} A simple selector to filter the target or look for a descendant of the target</li>
6559 * <li>stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.</li>
6560 * <li>preventDefault {Boolean} True to prevent the default action</li>
6561 * <li>stopPropagation {Boolean} True to prevent event propagation</li>
6562 * <li>normalized {Boolean} False to pass a browser event to the handler function instead of an Roo.EventObject</li>
6563 * <li>delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.</li>
6564 * <li>single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.</li>
6565 * <li>buffer {Number} Causes the handler to be scheduled to run in an {@link Roo.util.DelayedTask} delayed
6566 * by the specified number of milliseconds. If the event fires again within that time, the original
6567 * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
6570 * <b>Combining Options</b><br>
6571 * Using the options argument, it is possible to combine different types of listeners:<br>
6573 * A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
6575 el.on('click', this.onClick, this, {
6582 * <b>Attaching multiple handlers in 1 call</b><br>
6583 * The method also allows for a single argument to be passed which is a config object containing properties
6584 * which specify multiple handlers.
6594 fn: this.onMouseOver
6603 * Or a shorthand syntax:<br>
6606 'click' : this.onClick,
6607 'mouseover' : this.onMouseOver,
6608 'mouseout' : this.onMouseOut
6612 pub.on = pub.addListener;
6613 pub.un = pub.removeListener;
6615 pub.stoppedMouseDownEvent = new Roo.util.Event();
6619 * Fires when the document is ready (before onload and before images are loaded). Shorthand of {@link Roo.EventManager#onDocumentReady}.
6620 * @param {Function} fn The method the event invokes
6621 * @param {Object} scope An object that becomes the scope of the handler
6622 * @param {boolean} override If true, the obj passed in becomes
6623 * the execution scope of the listener
6627 Roo.onReady = Roo.EventManager.onDocumentReady;
6629 Roo.onReady(function(){
6630 var bd = Roo.get(document.body);
6635 : Roo.isIE11 ? "roo-ie11"
6636 : Roo.isEdge ? "roo-edge"
6637 : Roo.isGecko ? "roo-gecko"
6638 : Roo.isOpera ? "roo-opera"
6639 : Roo.isSafari ? "roo-safari" : ""];
6642 cls.push("roo-mac");
6645 cls.push("roo-linux");
6648 cls.push("roo-ios");
6651 cls.push("roo-touch");
6653 if(Roo.isBorderBox){
6654 cls.push('roo-border-box');
6656 if(Roo.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
6657 var p = bd.dom.parentNode;
6659 p.className += ' roo-strict';
6662 bd.addClass(cls.join(' '));
6666 * @class Roo.EventObject
6667 * EventObject exposes the Yahoo! UI Event functionality directly on the object
6668 * passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code
6671 function handleClick(e){ // e is not a standard event object, it is a Roo.EventObject
6673 var target = e.getTarget();
6676 var myDiv = Roo.get("myDiv");
6677 myDiv.on("click", handleClick);
6679 Roo.EventManager.on("myDiv", 'click', handleClick);
6680 Roo.EventManager.addListener("myDiv", 'click', handleClick);
6684 Roo.EventObject = function(){
6686 var E = Roo.lib.Event;
6688 // safari keypress events for special keys return bad keycodes
6691 63235 : 39, // right
6694 63276 : 33, // page up
6695 63277 : 34, // page down
6696 63272 : 46, // delete
6701 // normalize button clicks
6702 var btnMap = Roo.isIE ? {1:0,4:1,2:2} :
6703 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
6705 Roo.EventObjectImpl = function(e){
6707 this.setEvent(e.browserEvent || e);
6710 Roo.EventObjectImpl.prototype = {
6712 * Used to fix doc tools.
6713 * @scope Roo.EventObject.prototype
6719 /** The normal browser event */
6720 browserEvent : null,
6721 /** The button pressed in a mouse event */
6723 /** True if the shift key was down during the event */
6725 /** True if the control key was down during the event */
6727 /** True if the alt key was down during the event */
6786 setEvent : function(e){
6787 if(e == this || (e && e.browserEvent)){ // already wrapped
6790 this.browserEvent = e;
6792 // normalize buttons
6793 this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1);
6794 if(e.type == 'click' && this.button == -1){
6798 this.shiftKey = e.shiftKey;
6799 // mac metaKey behaves like ctrlKey
6800 this.ctrlKey = e.ctrlKey || e.metaKey;
6801 this.altKey = e.altKey;
6802 // in getKey these will be normalized for the mac
6803 this.keyCode = e.keyCode;
6804 // keyup warnings on firefox.
6805 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
6806 // cache the target for the delayed and or buffered events
6807 this.target = E.getTarget(e);
6809 this.xy = E.getXY(e);
6812 this.shiftKey = false;
6813 this.ctrlKey = false;
6814 this.altKey = false;
6824 * Stop the event (preventDefault and stopPropagation)
6826 stopEvent : function(){
6827 if(this.browserEvent){
6828 if(this.browserEvent.type == 'mousedown'){
6829 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6831 E.stopEvent(this.browserEvent);
6836 * Prevents the browsers default handling of the event.
6838 preventDefault : function(){
6839 if(this.browserEvent){
6840 E.preventDefault(this.browserEvent);
6845 isNavKeyPress : function(){
6846 var k = this.keyCode;
6847 k = Roo.isSafari ? (safariKeys[k] || k) : k;
6848 return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC;
6851 isSpecialKey : function(){
6852 var k = this.keyCode;
6853 return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 ||
6854 (k == 16) || (k == 17) ||
6855 (k >= 18 && k <= 20) ||
6856 (k >= 33 && k <= 35) ||
6857 (k >= 36 && k <= 39) ||
6858 (k >= 44 && k <= 45);
6861 * Cancels bubbling of the event.
6863 stopPropagation : function(){
6864 if(this.browserEvent){
6865 if(this.type == 'mousedown'){
6866 Roo.EventManager.stoppedMouseDownEvent.fire(this);
6868 E.stopPropagation(this.browserEvent);
6873 * Gets the key code for the event.
6876 getCharCode : function(){
6877 return this.charCode || this.keyCode;
6881 * Returns a normalized keyCode for the event.
6882 * @return {Number} The key code
6884 getKey : function(){
6885 var k = this.keyCode || this.charCode;
6886 return Roo.isSafari ? (safariKeys[k] || k) : k;
6890 * Gets the x coordinate of the event.
6893 getPageX : function(){
6898 * Gets the y coordinate of the event.
6901 getPageY : function(){
6906 * Gets the time of the event.
6909 getTime : function(){
6910 if(this.browserEvent){
6911 return E.getTime(this.browserEvent);
6917 * Gets the page coordinates of the event.
6918 * @return {Array} The xy values like [x, y]
6925 * Gets the target for the event.
6926 * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
6927 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
6928 search as a number or element (defaults to 10 || document.body)
6929 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
6930 * @return {HTMLelement}
6932 getTarget : function(selector, maxDepth, returnEl){
6933 return selector ? Roo.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
6936 * Gets the related target.
6937 * @return {HTMLElement}
6939 getRelatedTarget : function(){
6940 if(this.browserEvent){
6941 return E.getRelatedTarget(this.browserEvent);
6947 * Normalizes mouse wheel delta across browsers
6948 * @return {Number} The delta
6950 getWheelDelta : function(){
6951 var e = this.browserEvent;
6953 if(e.wheelDelta){ /* IE/Opera. */
6954 delta = e.wheelDelta/120;
6955 }else if(e.detail){ /* Mozilla case. */
6956 delta = -e.detail/3;
6962 * Returns true if the control, meta, shift or alt key was pressed during this event.
6965 hasModifier : function(){
6966 return !!((this.ctrlKey || this.altKey) || this.shiftKey);
6970 * Returns true if the target of this event equals el or is a child of el
6971 * @param {String/HTMLElement/Element} el
6972 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
6975 within : function(el, related){
6976 var t = this[related ? "getRelatedTarget" : "getTarget"]();
6977 return t && Roo.fly(el).contains(t);
6980 getPoint : function(){
6981 return new Roo.lib.Point(this.xy[0], this.xy[1]);
6985 return new Roo.EventObjectImpl();
6990 * Ext JS Library 1.1.1
6991 * Copyright(c) 2006-2007, Ext JS, LLC.
6993 * Originally Released Under LGPL - original licence link has changed is not relivant.
6996 * <script type="text/javascript">
7000 // was in Composite Element!??!?!
7003 var D = Roo.lib.Dom;
7004 var E = Roo.lib.Event;
7005 var A = Roo.lib.Anim;
7007 // local style camelizing for speed
7009 var camelRe = /(-[a-z])/gi;
7010 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
7011 var view = document.defaultView;
7014 * @class Roo.Element
7015 * Represents an Element in the DOM.<br><br>
7018 var el = Roo.get("my-div");
7021 var el = getEl("my-div");
7023 // or with a DOM element
7024 var el = Roo.get(myDivElement);
7026 * Using Roo.get() or getEl() instead of calling the constructor directly ensures you get the same object
7027 * each call instead of constructing a new one.<br><br>
7028 * <b>Animations</b><br />
7029 * Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
7030 * should either be a boolean (true) or an object literal with animation options. The animation options are:
7032 Option Default Description
7033 --------- -------- ---------------------------------------------
7034 duration .35 The duration of the animation in seconds
7035 easing easeOut The YUI easing method
7036 callback none A function to execute when the anim completes
7037 scope this The scope (this) of the callback function
7039 * Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
7040 * manipulate the animation. Here's an example:
7042 var el = Roo.get("my-div");
7047 // default animation
7048 el.setWidth(100, true);
7050 // animation with some options set
7057 // using the "anim" property to get the Anim object
7063 el.setWidth(100, opt);
7065 if(opt.anim.isAnimated()){
7069 * <b> Composite (Collections of) Elements</b><br />
7070 * For working with collections of Elements, see <a href="Roo.CompositeElement.html">Roo.CompositeElement</a>
7071 * @constructor Create a new Element directly.
7072 * @param {String/HTMLElement} element
7073 * @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).
7075 Roo.Element = function(element, forceNew){
7076 var dom = typeof element == "string" ?
7077 document.getElementById(element) : element;
7078 if(!dom){ // invalid id/element
7082 if(forceNew !== true && id && Roo.Element.cache[id]){ // element object already exists
7083 return Roo.Element.cache[id];
7093 * The DOM element ID
7096 this.id = id || Roo.id(dom);
7099 var El = Roo.Element;
7103 * The element's default display mode (defaults to "")
7106 originalDisplay : "",
7110 * The default unit to append to CSS values where a unit isn't provided (defaults to px).
7116 * Sets the element's visibility mode. When setVisible() is called it
7117 * will use this to determine whether to set the visibility or the display property.
7118 * @param visMode Element.VISIBILITY or Element.DISPLAY
7119 * @return {Roo.Element} this
7121 setVisibilityMode : function(visMode){
7122 this.visibilityMode = visMode;
7126 * Convenience method for setVisibilityMode(Element.DISPLAY)
7127 * @param {String} display (optional) What to set display to when visible
7128 * @return {Roo.Element} this
7130 enableDisplayMode : function(display){
7131 this.setVisibilityMode(El.DISPLAY);
7132 if(typeof display != "undefined") { this.originalDisplay = display; }
7137 * 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)
7138 * @param {String} selector The simple selector to test
7139 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7140 search as a number or element (defaults to 10 || document.body)
7141 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7142 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7144 findParent : function(simpleSelector, maxDepth, returnEl){
7145 var p = this.dom, b = document.body, depth = 0, dq = Roo.DomQuery, stopEl;
7146 maxDepth = maxDepth || 50;
7147 if(typeof maxDepth != "number"){
7148 stopEl = Roo.getDom(maxDepth);
7151 while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
7152 if(dq.is(p, simpleSelector)){
7153 return returnEl ? Roo.get(p) : p;
7163 * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
7164 * @param {String} selector The simple selector to test
7165 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7166 search as a number or element (defaults to 10 || document.body)
7167 * @param {Boolean} returnEl (optional) True to return a Roo.Element object instead of DOM node
7168 * @return {HTMLElement} The matching DOM node (or null if no match was found)
7170 findParentNode : function(simpleSelector, maxDepth, returnEl){
7171 var p = Roo.fly(this.dom.parentNode, '_internal');
7172 return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
7176 * Looks at the scrollable parent element
7178 findScrollableParent : function()
7180 var overflowRegex = /(auto|scroll)/;
7182 if(this.getStyle('position') === 'fixed'){
7183 return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body);
7186 var excludeStaticParent = this.getStyle('position') === "absolute";
7188 for (var parent = this; (parent = Roo.get(parent.dom.parentNode));){
7190 if (excludeStaticParent && parent.getStyle('position') === "static") {
7194 if (overflowRegex.test(parent.getStyle('overflow') + parent.getStyle('overflow-x') + parent.getStyle('overflow-y'))){
7198 if(parent.dom.nodeName.toLowerCase() == 'body'){
7199 return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body);
7203 return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body);
7207 * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
7208 * This is a shortcut for findParentNode() that always returns an Roo.Element.
7209 * @param {String} selector The simple selector to test
7210 * @param {Number/String/HTMLElement/Element} maxDepth (optional) The max depth to
7211 search as a number or element (defaults to 10 || document.body)
7212 * @return {Roo.Element} The matching DOM node (or null if no match was found)
7214 up : function(simpleSelector, maxDepth){
7215 return this.findParentNode(simpleSelector, maxDepth, true);
7221 * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
7222 * @param {String} selector The simple selector to test
7223 * @return {Boolean} True if this element matches the selector, else false
7225 is : function(simpleSelector){
7226 return Roo.DomQuery.is(this.dom, simpleSelector);
7230 * Perform animation on this element.
7231 * @param {Object} args The YUI animation control args
7232 * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
7233 * @param {Function} onComplete (optional) Function to call when animation completes
7234 * @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
7235 * @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
7236 * @return {Roo.Element} this
7238 animate : function(args, duration, onComplete, easing, animType){
7239 this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
7244 * @private Internal animation call
7246 anim : function(args, opt, animType, defaultDur, defaultEase, cb){
7247 animType = animType || 'run';
7249 var anim = Roo.lib.Anim[animType](
7251 (opt.duration || defaultDur) || .35,
7252 (opt.easing || defaultEase) || 'easeOut',
7254 Roo.callback(cb, this);
7255 Roo.callback(opt.callback, opt.scope || this, [this, opt]);
7263 // private legacy anim prep
7264 preanim : function(a, i){
7265 return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
7269 * Removes worthless text nodes
7270 * @param {Boolean} forceReclean (optional) By default the element
7271 * keeps track if it has been cleaned already so
7272 * you can call this over and over. However, if you update the element and
7273 * need to force a reclean, you can pass true.
7275 clean : function(forceReclean){
7276 if(this.isCleaned && forceReclean !== true){
7280 var d = this.dom, n = d.firstChild, ni = -1;
7282 var nx = n.nextSibling;
7283 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
7290 this.isCleaned = true;
7295 calcOffsetsTo : function(el){
7298 var restorePos = false;
7299 if(el.getStyle('position') == 'static'){
7300 el.position('relative');
7305 while(op && op != d && op.tagName != 'HTML'){
7308 op = op.offsetParent;
7311 el.position('static');
7317 * Scrolls this element into view within the passed container.
7318 * @param {String/HTMLElement/Element} container (optional) The container element to scroll (defaults to document.body)
7319 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
7320 * @return {Roo.Element} this
7322 scrollIntoView : function(container, hscroll){
7323 var c = Roo.getDom(container) || document.body;
7326 var o = this.calcOffsetsTo(c),
7329 b = t+el.offsetHeight,
7330 r = l+el.offsetWidth;
7332 var ch = c.clientHeight;
7333 var ct = parseInt(c.scrollTop, 10);
7334 var cl = parseInt(c.scrollLeft, 10);
7336 var cr = cl + c.clientWidth;
7344 if(hscroll !== false){
7348 c.scrollLeft = r-c.clientWidth;
7355 scrollChildIntoView : function(child, hscroll){
7356 Roo.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
7360 * Measures the element's content height and updates height to match. Note: this function uses setTimeout so
7361 * the new height may not be available immediately.
7362 * @param {Boolean} animate (optional) Animate the transition (defaults to false)
7363 * @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
7364 * @param {Function} onComplete (optional) Function to call when animation completes
7365 * @param {String} easing (optional) Easing method to use (defaults to easeOut)
7366 * @return {Roo.Element} this
7368 autoHeight : function(animate, duration, onComplete, easing){
7369 var oldHeight = this.getHeight();
7371 this.setHeight(1); // force clipping
7372 setTimeout(function(){
7373 var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
7375 this.setHeight(height);
7377 if(typeof onComplete == "function"){
7381 this.setHeight(oldHeight); // restore original height
7382 this.setHeight(height, animate, duration, function(){
7384 if(typeof onComplete == "function") { onComplete(); }
7385 }.createDelegate(this), easing);
7387 }.createDelegate(this), 0);
7392 * Returns true if this element is an ancestor of the passed element
7393 * @param {HTMLElement/String} el The element to check
7394 * @return {Boolean} True if this element is an ancestor of el, else false
7396 contains : function(el){
7397 if(!el){return false;}
7398 return D.isAncestor(this.dom, el.dom ? el.dom : el);
7402 * Checks whether the element is currently visible using both visibility and display properties.
7403 * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
7404 * @return {Boolean} True if the element is currently visible, else false
7406 isVisible : function(deep) {
7407 var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
7408 if(deep !== true || !vis){
7411 var p = this.dom.parentNode;
7412 while(p && p.tagName.toLowerCase() != "body"){
7413 if(!Roo.fly(p, '_isVisible').isVisible()){
7422 * Creates a {@link Roo.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
7423 * @param {String} selector The CSS selector
7424 * @param {Boolean} unique (optional) True to create a unique Roo.Element for each child (defaults to false, which creates a single shared flyweight object)
7425 * @return {CompositeElement/CompositeElementLite} The composite element
7427 select : function(selector, unique){
7428 return El.select(selector, unique, this.dom);
7432 * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
7433 * @param {String} selector The CSS selector
7434 * @return {Array} An array of the matched nodes
7436 query : function(selector, unique){
7437 return Roo.DomQuery.select(selector, this.dom);
7441 * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
7442 * @param {String} selector The CSS selector
7443 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7444 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7446 child : function(selector, returnDom){
7447 var n = Roo.DomQuery.selectNode(selector, this.dom);
7448 return returnDom ? n : Roo.get(n);
7452 * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
7453 * @param {String} selector The CSS selector
7454 * @param {Boolean} returnDom (optional) True to return the DOM node instead of Roo.Element (defaults to false)
7455 * @return {HTMLElement/Roo.Element} The child Roo.Element (or DOM node if returnDom = true)
7457 down : function(selector, returnDom){
7458 var n = Roo.DomQuery.selectNode(" > " + selector, this.dom);
7459 return returnDom ? n : Roo.get(n);
7463 * Initializes a {@link Roo.dd.DD} drag drop object for this element.
7464 * @param {String} group The group the DD object is member of
7465 * @param {Object} config The DD config object
7466 * @param {Object} overrides An object containing methods to override/implement on the DD object
7467 * @return {Roo.dd.DD} The DD object
7469 initDD : function(group, config, overrides){
7470 var dd = new Roo.dd.DD(Roo.id(this.dom), group, config);
7471 return Roo.apply(dd, overrides);
7475 * Initializes a {@link Roo.dd.DDProxy} object for this element.
7476 * @param {String} group The group the DDProxy object is member of
7477 * @param {Object} config The DDProxy config object
7478 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
7479 * @return {Roo.dd.DDProxy} The DDProxy object
7481 initDDProxy : function(group, config, overrides){
7482 var dd = new Roo.dd.DDProxy(Roo.id(this.dom), group, config);
7483 return Roo.apply(dd, overrides);
7487 * Initializes a {@link Roo.dd.DDTarget} object for this element.
7488 * @param {String} group The group the DDTarget object is member of
7489 * @param {Object} config The DDTarget config object
7490 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
7491 * @return {Roo.dd.DDTarget} The DDTarget object
7493 initDDTarget : function(group, config, overrides){
7494 var dd = new Roo.dd.DDTarget(Roo.id(this.dom), group, config);
7495 return Roo.apply(dd, overrides);
7499 * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
7500 * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
7501 * @param {Boolean} visible Whether the element is visible
7502 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7503 * @return {Roo.Element} this
7505 setVisible : function(visible, animate){
7507 if(this.visibilityMode == El.DISPLAY){
7508 this.setDisplayed(visible);
7511 this.dom.style.visibility = visible ? "visible" : "hidden";
7514 // closure for composites
7516 var visMode = this.visibilityMode;
7518 this.setOpacity(.01);
7519 this.setVisible(true);
7521 this.anim({opacity: { to: (visible?1:0) }},
7522 this.preanim(arguments, 1),
7523 null, .35, 'easeIn', function(){
7525 if(visMode == El.DISPLAY){
7526 dom.style.display = "none";
7528 dom.style.visibility = "hidden";
7530 Roo.get(dom).setOpacity(1);
7538 * Returns true if display is not "none"
7541 isDisplayed : function() {
7542 return this.getStyle("display") != "none";
7546 * Toggles the element's visibility or display, depending on visibility mode.
7547 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7548 * @return {Roo.Element} this
7550 toggle : function(animate){
7551 this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
7556 * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
7557 * @param {Boolean} value Boolean value to display the element using its default display, or a string to set the display directly
7558 * @return {Roo.Element} this
7560 setDisplayed : function(value) {
7561 if(typeof value == "boolean"){
7562 value = value ? this.originalDisplay : "none";
7564 this.setStyle("display", value);
7569 * Tries to focus the element. Any exceptions are caught and ignored.
7570 * @return {Roo.Element} this
7572 focus : function() {
7580 * Tries to blur the element. Any exceptions are caught and ignored.
7581 * @return {Roo.Element} this
7591 * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
7592 * @param {String/Array} className The CSS class to add, or an array of classes
7593 * @return {Roo.Element} this
7595 addClass : function(className){
7596 if(className instanceof Array){
7597 for(var i = 0, len = className.length; i < len; i++) {
7598 this.addClass(className[i]);
7601 if(className && !this.hasClass(className)){
7602 this.dom.className = this.dom.className + " " + className;
7609 * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
7610 * @param {String/Array} className The CSS class to add, or an array of classes
7611 * @return {Roo.Element} this
7613 radioClass : function(className){
7614 var siblings = this.dom.parentNode.childNodes;
7615 for(var i = 0; i < siblings.length; i++) {
7616 var s = siblings[i];
7617 if(s.nodeType == 1){
7618 Roo.get(s).removeClass(className);
7621 this.addClass(className);
7626 * Removes one or more CSS classes from the element.
7627 * @param {String/Array} className The CSS class to remove, or an array of classes
7628 * @return {Roo.Element} this
7630 removeClass : function(className){
7631 if(!className || !this.dom.className){
7634 if(className instanceof Array){
7635 for(var i = 0, len = className.length; i < len; i++) {
7636 this.removeClass(className[i]);
7639 if(this.hasClass(className)){
7640 var re = this.classReCache[className];
7642 re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
7643 this.classReCache[className] = re;
7645 this.dom.className =
7646 this.dom.className.replace(re, " ");
7656 * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
7657 * @param {String} className The CSS class to toggle
7658 * @return {Roo.Element} this
7660 toggleClass : function(className){
7661 if(this.hasClass(className)){
7662 this.removeClass(className);
7664 this.addClass(className);
7670 * Checks if the specified CSS class exists on this element's DOM node.
7671 * @param {String} className The CSS class to check for
7672 * @return {Boolean} True if the class exists, else false
7674 hasClass : function(className){
7675 return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
7679 * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
7680 * @param {String} oldClassName The CSS class to replace
7681 * @param {String} newClassName The replacement CSS class
7682 * @return {Roo.Element} this
7684 replaceClass : function(oldClassName, newClassName){
7685 this.removeClass(oldClassName);
7686 this.addClass(newClassName);
7691 * Returns an object with properties matching the styles requested.
7692 * For example, el.getStyles('color', 'font-size', 'width') might return
7693 * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
7694 * @param {String} style1 A style name
7695 * @param {String} style2 A style name
7696 * @param {String} etc.
7697 * @return {Object} The style object
7699 getStyles : function(){
7700 var a = arguments, len = a.length, r = {};
7701 for(var i = 0; i < len; i++){
7702 r[a[i]] = this.getStyle(a[i]);
7708 * Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
7709 * @param {String} property The style property whose value is returned.
7710 * @return {String} The current value of the style property for this element.
7712 getStyle : function(){
7713 return view && view.getComputedStyle ?
7715 var el = this.dom, v, cs, camel;
7716 if(prop == 'float'){
7719 if(el.style && (v = el.style[prop])){
7722 if(cs = view.getComputedStyle(el, "")){
7723 if(!(camel = propCache[prop])){
7724 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7731 var el = this.dom, v, cs, camel;
7732 if(prop == 'opacity'){
7733 if(typeof el.style.filter == 'string'){
7734 var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
7736 var fv = parseFloat(m[1]);
7738 return fv ? fv / 100 : 0;
7743 }else if(prop == 'float'){
7744 prop = "styleFloat";
7746 if(!(camel = propCache[prop])){
7747 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7749 if(v = el.style[camel]){
7752 if(cs = el.currentStyle){
7760 * Wrapper for setting style properties, also takes single object parameter of multiple styles.
7761 * @param {String/Object} property The style property to be set, or an object of multiple styles.
7762 * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
7763 * @return {Roo.Element} this
7765 setStyle : function(prop, value){
7766 if(typeof prop == "string"){
7768 if (prop == 'float') {
7769 this.setStyle(Roo.isIE ? 'styleFloat' : 'cssFloat', value);
7774 if(!(camel = propCache[prop])){
7775 camel = propCache[prop] = prop.replace(camelRe, camelFn);
7778 if(camel == 'opacity') {
7779 this.setOpacity(value);
7781 this.dom.style[camel] = value;
7784 for(var style in prop){
7785 if(typeof prop[style] != "function"){
7786 this.setStyle(style, prop[style]);
7794 * More flexible version of {@link #setStyle} for setting style properties.
7795 * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
7796 * a function which returns such a specification.
7797 * @return {Roo.Element} this
7799 applyStyles : function(style){
7800 Roo.DomHelper.applyStyles(this.dom, style);
7805 * 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).
7806 * @return {Number} The X position of the element
7809 return D.getX(this.dom);
7813 * 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).
7814 * @return {Number} The Y position of the element
7817 return D.getY(this.dom);
7821 * 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).
7822 * @return {Array} The XY position of the element
7825 return D.getXY(this.dom);
7829 * 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).
7830 * @param {Number} The X position of the element
7831 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7832 * @return {Roo.Element} this
7834 setX : function(x, animate){
7836 D.setX(this.dom, x);
7838 this.setXY([x, this.getY()], this.preanim(arguments, 1));
7844 * 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).
7845 * @param {Number} The Y position of the element
7846 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7847 * @return {Roo.Element} this
7849 setY : function(y, animate){
7851 D.setY(this.dom, y);
7853 this.setXY([this.getX(), y], this.preanim(arguments, 1));
7859 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
7860 * @param {String} left The left CSS property value
7861 * @return {Roo.Element} this
7863 setLeft : function(left){
7864 this.setStyle("left", this.addUnits(left));
7869 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
7870 * @param {String} top The top CSS property value
7871 * @return {Roo.Element} this
7873 setTop : function(top){
7874 this.setStyle("top", this.addUnits(top));
7879 * Sets the element's CSS right style.
7880 * @param {String} right The right CSS property value
7881 * @return {Roo.Element} this
7883 setRight : function(right){
7884 this.setStyle("right", this.addUnits(right));
7889 * Sets the element's CSS bottom style.
7890 * @param {String} bottom The bottom CSS property value
7891 * @return {Roo.Element} this
7893 setBottom : function(bottom){
7894 this.setStyle("bottom", this.addUnits(bottom));
7899 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7900 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7901 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
7902 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7903 * @return {Roo.Element} this
7905 setXY : function(pos, animate){
7907 D.setXY(this.dom, pos);
7909 this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
7915 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7916 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7917 * @param {Number} x X value for new position (coordinates are page-based)
7918 * @param {Number} y Y value for new position (coordinates are page-based)
7919 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7920 * @return {Roo.Element} this
7922 setLocation : function(x, y, animate){
7923 this.setXY([x, y], this.preanim(arguments, 2));
7928 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
7929 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
7930 * @param {Number} x X value for new position (coordinates are page-based)
7931 * @param {Number} y Y value for new position (coordinates are page-based)
7932 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
7933 * @return {Roo.Element} this
7935 moveTo : function(x, y, animate){
7936 this.setXY([x, y], this.preanim(arguments, 2));
7941 * Returns the region of the given element.
7942 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
7943 * @return {Region} A Roo.lib.Region containing "top, left, bottom, right" member data.
7945 getRegion : function(){
7946 return D.getRegion(this.dom);
7950 * Returns the offset height of the element
7951 * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
7952 * @return {Number} The element's height
7954 getHeight : function(contentHeight){
7955 var h = this.dom.offsetHeight || 0;
7956 return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
7960 * Returns the offset width of the element
7961 * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
7962 * @return {Number} The element's width
7964 getWidth : function(contentWidth){
7965 var w = this.dom.offsetWidth || 0;
7966 return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
7970 * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
7971 * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
7972 * if a height has not been set using CSS.
7975 getComputedHeight : function(){
7976 var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
7978 h = parseInt(this.getStyle('height'), 10) || 0;
7979 if(!this.isBorderBox()){
7980 h += this.getFrameWidth('tb');
7987 * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
7988 * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
7989 * if a width has not been set using CSS.
7992 getComputedWidth : function(){
7993 var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
7995 w = parseInt(this.getStyle('width'), 10) || 0;
7996 if(!this.isBorderBox()){
7997 w += this.getFrameWidth('lr');
8004 * Returns the size of the element.
8005 * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
8006 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
8008 getSize : function(contentSize){
8009 return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
8013 * Returns the width and height of the viewport.
8014 * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
8016 getViewSize : function(){
8017 var d = this.dom, doc = document, aw = 0, ah = 0;
8018 if(d == doc || d == doc.body){
8019 return {width : D.getViewWidth(), height: D.getViewHeight()};
8022 width : d.clientWidth,
8023 height: d.clientHeight
8029 * Returns the value of the "value" attribute
8030 * @param {Boolean} asNumber true to parse the value as a number
8031 * @return {String/Number}
8033 getValue : function(asNumber){
8034 return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
8038 adjustWidth : function(width){
8039 if(typeof width == "number"){
8040 if(this.autoBoxAdjust && !this.isBorderBox()){
8041 width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
8051 adjustHeight : function(height){
8052 if(typeof height == "number"){
8053 if(this.autoBoxAdjust && !this.isBorderBox()){
8054 height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
8064 * Set the width of the element
8065 * @param {Number} width The new width
8066 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8067 * @return {Roo.Element} this
8069 setWidth : function(width, animate){
8070 width = this.adjustWidth(width);
8072 this.dom.style.width = this.addUnits(width);
8074 this.anim({width: {to: width}}, this.preanim(arguments, 1));
8080 * Set the height of the element
8081 * @param {Number} height The new height
8082 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8083 * @return {Roo.Element} this
8085 setHeight : function(height, animate){
8086 height = this.adjustHeight(height);
8088 this.dom.style.height = this.addUnits(height);
8090 this.anim({height: {to: height}}, this.preanim(arguments, 1));
8096 * Set the size of the element. If animation is true, both width an height will be animated concurrently.
8097 * @param {Number} width The new width
8098 * @param {Number} height The new height
8099 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8100 * @return {Roo.Element} this
8102 setSize : function(width, height, animate){
8103 if(typeof width == "object"){ // in case of object from getSize()
8104 height = width.height; width = width.width;
8106 width = this.adjustWidth(width); height = this.adjustHeight(height);
8108 this.dom.style.width = this.addUnits(width);
8109 this.dom.style.height = this.addUnits(height);
8111 this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
8117 * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
8118 * @param {Number} x X value for new position (coordinates are page-based)
8119 * @param {Number} y Y value for new position (coordinates are page-based)
8120 * @param {Number} width The new width
8121 * @param {Number} height The new height
8122 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8123 * @return {Roo.Element} this
8125 setBounds : function(x, y, width, height, animate){
8127 this.setSize(width, height);
8128 this.setLocation(x, y);
8130 width = this.adjustWidth(width); height = this.adjustHeight(height);
8131 this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
8132 this.preanim(arguments, 4), 'motion');
8138 * 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.
8139 * @param {Roo.lib.Region} region The region to fill
8140 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8141 * @return {Roo.Element} this
8143 setRegion : function(region, animate){
8144 this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
8149 * Appends an event handler
8151 * @param {String} eventName The type of event to append
8152 * @param {Function} fn The method the event invokes
8153 * @param {Object} scope (optional) The scope (this object) of the fn
8154 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
8156 addListener : function(eventName, fn, scope, options){
8158 Roo.EventManager.on(this.dom, eventName, fn, scope || this, options);
8163 * Removes an event handler from this element
8164 * @param {String} eventName the type of event to remove
8165 * @param {Function} fn the method the event invokes
8166 * @return {Roo.Element} this
8168 removeListener : function(eventName, fn){
8169 Roo.EventManager.removeListener(this.dom, eventName, fn);
8174 * Removes all previous added listeners from this element
8175 * @return {Roo.Element} this
8177 removeAllListeners : function(){
8178 E.purgeElement(this.dom);
8182 relayEvent : function(eventName, observable){
8183 this.on(eventName, function(e){
8184 observable.fireEvent(eventName, e);
8189 * Set the opacity of the element
8190 * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
8191 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8192 * @return {Roo.Element} this
8194 setOpacity : function(opacity, animate){
8196 var s = this.dom.style;
8199 s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
8200 (opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
8202 s.opacity = opacity;
8205 this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
8211 * Gets the left X coordinate
8212 * @param {Boolean} local True to get the local css position instead of page coordinate
8215 getLeft : function(local){
8219 return parseInt(this.getStyle("left"), 10) || 0;
8224 * Gets the right X coordinate of the element (element X position + element width)
8225 * @param {Boolean} local True to get the local css position instead of page coordinate
8228 getRight : function(local){
8230 return this.getX() + this.getWidth();
8232 return (this.getLeft(true) + this.getWidth()) || 0;
8237 * Gets the top Y coordinate
8238 * @param {Boolean} local True to get the local css position instead of page coordinate
8241 getTop : function(local) {
8245 return parseInt(this.getStyle("top"), 10) || 0;
8250 * Gets the bottom Y coordinate of the element (element Y position + element height)
8251 * @param {Boolean} local True to get the local css position instead of page coordinate
8254 getBottom : function(local){
8256 return this.getY() + this.getHeight();
8258 return (this.getTop(true) + this.getHeight()) || 0;
8263 * Initializes positioning on this element. If a desired position is not passed, it will make the
8264 * the element positioned relative IF it is not already positioned.
8265 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
8266 * @param {Number} zIndex (optional) The zIndex to apply
8267 * @param {Number} x (optional) Set the page X position
8268 * @param {Number} y (optional) Set the page Y position
8270 position : function(pos, zIndex, x, y){
8272 if(this.getStyle('position') == 'static'){
8273 this.setStyle('position', 'relative');
8276 this.setStyle("position", pos);
8279 this.setStyle("z-index", zIndex);
8281 if(x !== undefined && y !== undefined){
8283 }else if(x !== undefined){
8285 }else if(y !== undefined){
8291 * Clear positioning back to the default when the document was loaded
8292 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
8293 * @return {Roo.Element} this
8295 clearPositioning : function(value){
8303 "position" : "static"
8309 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
8310 * snapshot before performing an update and then restoring the element.
8313 getPositioning : function(){
8314 var l = this.getStyle("left");
8315 var t = this.getStyle("top");
8317 "position" : this.getStyle("position"),
8319 "right" : l ? "" : this.getStyle("right"),
8321 "bottom" : t ? "" : this.getStyle("bottom"),
8322 "z-index" : this.getStyle("z-index")
8327 * Gets the width of the border(s) for the specified side(s)
8328 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8329 * passing lr would get the border (l)eft width + the border (r)ight width.
8330 * @return {Number} The width of the sides passed added together
8332 getBorderWidth : function(side){
8333 return this.addStyles(side, El.borders);
8337 * Gets the width of the padding(s) for the specified side(s)
8338 * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
8339 * passing lr would get the padding (l)eft + the padding (r)ight.
8340 * @return {Number} The padding of the sides passed added together
8342 getPadding : function(side){
8343 return this.addStyles(side, El.paddings);
8347 * Set positioning with an object returned by getPositioning().
8348 * @param {Object} posCfg
8349 * @return {Roo.Element} this
8351 setPositioning : function(pc){
8352 this.applyStyles(pc);
8353 if(pc.right == "auto"){
8354 this.dom.style.right = "";
8356 if(pc.bottom == "auto"){
8357 this.dom.style.bottom = "";
8363 fixDisplay : function(){
8364 if(this.getStyle("display") == "none"){
8365 this.setStyle("visibility", "hidden");
8366 this.setStyle("display", this.originalDisplay); // first try reverting to default
8367 if(this.getStyle("display") == "none"){ // if that fails, default to block
8368 this.setStyle("display", "block");
8374 * Quick set left and top adding default units
8375 * @param {String} left The left CSS property value
8376 * @param {String} top The top CSS property value
8377 * @return {Roo.Element} this
8379 setLeftTop : function(left, top){
8380 this.dom.style.left = this.addUnits(left);
8381 this.dom.style.top = this.addUnits(top);
8386 * Move this element relative to its current position.
8387 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
8388 * @param {Number} distance How far to move the element in pixels
8389 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8390 * @return {Roo.Element} this
8392 move : function(direction, distance, animate){
8393 var xy = this.getXY();
8394 direction = direction.toLowerCase();
8398 this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
8402 this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
8407 this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
8412 this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
8419 * Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
8420 * @return {Roo.Element} this
8423 if(!this.isClipped){
8424 this.isClipped = true;
8425 this.originalClip = {
8426 "o": this.getStyle("overflow"),
8427 "x": this.getStyle("overflow-x"),
8428 "y": this.getStyle("overflow-y")
8430 this.setStyle("overflow", "hidden");
8431 this.setStyle("overflow-x", "hidden");
8432 this.setStyle("overflow-y", "hidden");
8438 * Return clipping (overflow) to original clipping before clip() was called
8439 * @return {Roo.Element} this
8441 unclip : function(){
8443 this.isClipped = false;
8444 var o = this.originalClip;
8445 if(o.o){this.setStyle("overflow", o.o);}
8446 if(o.x){this.setStyle("overflow-x", o.x);}
8447 if(o.y){this.setStyle("overflow-y", o.y);}
8454 * Gets the x,y coordinates specified by the anchor position on the element.
8455 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo} for details on supported anchor positions.
8456 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
8457 * {width: (target width), height: (target height)} (defaults to the element's current size)
8458 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead of page coordinates
8459 * @return {Array} [x, y] An array containing the element's x and y coordinates
8461 getAnchorXY : function(anchor, local, s){
8462 //Passing a different size is useful for pre-calculating anchors,
8463 //especially for anchored animations that change the el size.
8465 var w, h, vp = false;
8468 if(d == document.body || d == document){
8470 w = D.getViewWidth(); h = D.getViewHeight();
8472 w = this.getWidth(); h = this.getHeight();
8475 w = s.width; h = s.height;
8477 var x = 0, y = 0, r = Math.round;
8478 switch((anchor || "tl").toLowerCase()){
8520 var sc = this.getScroll();
8521 return [x + sc.left, y + sc.top];
8523 //Add the element's offset xy
8524 var o = this.getXY();
8525 return [x+o[0], y+o[1]];
8529 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
8530 * supported position values.
8531 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8532 * @param {String} position The position to align to.
8533 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8534 * @return {Array} [x, y]
8536 getAlignToXY : function(el, p, o){
8540 throw "Element.alignTo with an element that doesn't exist";
8542 var c = false; //constrain to viewport
8543 var p1 = "", p2 = "";
8550 }else if(p.indexOf("-") == -1){
8553 p = p.toLowerCase();
8554 var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
8556 throw "Element.alignTo with an invalid alignment " + p;
8558 p1 = m[1]; p2 = m[2]; c = !!m[3];
8560 //Subtract the aligned el's internal xy from the target's offset xy
8561 //plus custom offset to get the aligned el's new offset xy
8562 var a1 = this.getAnchorXY(p1, true);
8563 var a2 = el.getAnchorXY(p2, false);
8564 var x = a2[0] - a1[0] + o[0];
8565 var y = a2[1] - a1[1] + o[1];
8567 //constrain the aligned el to viewport if necessary
8568 var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
8569 // 5px of margin for ie
8570 var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
8572 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
8573 //perpendicular to the vp border, allow the aligned el to slide on that border,
8574 //otherwise swap the aligned el to the opposite border of the target.
8575 var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
8576 var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
8577 var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
8578 var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
8581 var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
8582 var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
8584 if((x+w) > dw + scrollX){
8585 x = swapX ? r.left-w : dw+scrollX-w;
8588 x = swapX ? r.right : scrollX;
8590 if((y+h) > dh + scrollY){
8591 y = swapY ? r.top-h : dh+scrollY-h;
8594 y = swapY ? r.bottom : scrollY;
8601 getConstrainToXY : function(){
8602 var os = {top:0, left:0, bottom:0, right: 0};
8604 return function(el, local, offsets, proposedXY){
8606 offsets = offsets ? Roo.applyIf(offsets, os) : os;
8608 var vw, vh, vx = 0, vy = 0;
8609 if(el.dom == document.body || el.dom == document){
8610 vw = Roo.lib.Dom.getViewWidth();
8611 vh = Roo.lib.Dom.getViewHeight();
8613 vw = el.dom.clientWidth;
8614 vh = el.dom.clientHeight;
8616 var vxy = el.getXY();
8622 var s = el.getScroll();
8624 vx += offsets.left + s.left;
8625 vy += offsets.top + s.top;
8627 vw -= offsets.right;
8628 vh -= offsets.bottom;
8633 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
8634 var x = xy[0], y = xy[1];
8635 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
8637 // only move it if it needs it
8640 // first validate right/bottom
8649 // then make sure top/left isn't negative
8658 return moved ? [x, y] : false;
8663 adjustForConstraints : function(xy, parent, offsets){
8664 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
8668 * Aligns this element with another element relative to the specified anchor points. If the other element is the
8669 * document it aligns it to the viewport.
8670 * The position parameter is optional, and can be specified in any one of the following formats:
8672 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
8673 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
8674 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
8675 * deprecated in favor of the newer two anchor syntax below</i>.</li>
8676 * <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
8677 * element's anchor point, and the second value is used as the target's anchor point.</li>
8679 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
8680 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
8681 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
8682 * that specified in order to enforce the viewport constraints.
8683 * Following are all of the supported anchor positions:
8686 ----- -----------------------------
8687 tl The top left corner (default)
8688 t The center of the top edge
8689 tr The top right corner
8690 l The center of the left edge
8691 c In the center of the element
8692 r The center of the right edge
8693 bl The bottom left corner
8694 b The center of the bottom edge
8695 br The bottom right corner
8699 // align el to other-el using the default positioning ("tl-bl", non-constrained)
8700 el.alignTo("other-el");
8702 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
8703 el.alignTo("other-el", "tr?");
8705 // align the bottom right corner of el with the center left edge of other-el
8706 el.alignTo("other-el", "br-l?");
8708 // align the center of el with the bottom left corner of other-el and
8709 // adjust the x position by -6 pixels (and the y position by 0)
8710 el.alignTo("other-el", "c-bl", [-6, 0]);
8712 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8713 * @param {String} position The position to align to.
8714 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8715 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8716 * @return {Roo.Element} this
8718 alignTo : function(element, position, offsets, animate){
8719 var xy = this.getAlignToXY(element, position, offsets);
8720 this.setXY(xy, this.preanim(arguments, 3));
8725 * Anchors an element to another element and realigns it when the window is resized.
8726 * @param {String/HTMLElement/Roo.Element} element The element to align to.
8727 * @param {String} position The position to align to.
8728 * @param {Array} offsets (optional) Offset the positioning by [x, y]
8729 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
8730 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
8731 * is a number, it is used as the buffer delay (defaults to 50ms).
8732 * @param {Function} callback The function to call after the animation finishes
8733 * @return {Roo.Element} this
8735 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
8736 var action = function(){
8737 this.alignTo(el, alignment, offsets, animate);
8738 Roo.callback(callback, this);
8740 Roo.EventManager.onWindowResize(action, this);
8741 var tm = typeof monitorScroll;
8742 if(tm != 'undefined'){
8743 Roo.EventManager.on(window, 'scroll', action, this,
8744 {buffer: tm == 'number' ? monitorScroll : 50});
8746 action.call(this); // align immediately
8750 * Clears any opacity settings from this element. Required in some cases for IE.
8751 * @return {Roo.Element} this
8753 clearOpacity : function(){
8754 if (window.ActiveXObject) {
8755 if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
8756 this.dom.style.filter = "";
8759 this.dom.style.opacity = "";
8760 this.dom.style["-moz-opacity"] = "";
8761 this.dom.style["-khtml-opacity"] = "";
8767 * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8768 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8769 * @return {Roo.Element} this
8771 hide : function(animate){
8772 this.setVisible(false, this.preanim(arguments, 0));
8777 * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
8778 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
8779 * @return {Roo.Element} this
8781 show : function(animate){
8782 this.setVisible(true, this.preanim(arguments, 0));
8787 * @private Test if size has a unit, otherwise appends the default
8789 addUnits : function(size){
8790 return Roo.Element.addUnits(size, this.defaultUnit);
8794 * Temporarily enables offsets (width,height,x,y) for an element with display:none, use endMeasure() when done.
8795 * @return {Roo.Element} this
8797 beginMeasure : function(){
8799 if(el.offsetWidth || el.offsetHeight){
8800 return this; // offsets work already
8803 var p = this.dom, b = document.body; // start with this element
8804 while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
8805 var pe = Roo.get(p);
8806 if(pe.getStyle('display') == 'none'){
8807 changed.push({el: p, visibility: pe.getStyle("visibility")});
8808 p.style.visibility = "hidden";
8809 p.style.display = "block";
8813 this._measureChanged = changed;
8819 * Restores displays to before beginMeasure was called
8820 * @return {Roo.Element} this
8822 endMeasure : function(){
8823 var changed = this._measureChanged;
8825 for(var i = 0, len = changed.length; i < len; i++) {
8827 r.el.style.visibility = r.visibility;
8828 r.el.style.display = "none";
8830 this._measureChanged = null;
8836 * Update the innerHTML of this element, optionally searching for and processing scripts
8837 * @param {String} html The new HTML
8838 * @param {Boolean} loadScripts (optional) true to look for and process scripts
8839 * @param {Function} callback For async script loading you can be noticed when the update completes
8840 * @return {Roo.Element} this
8842 update : function(html, loadScripts, callback){
8843 if(typeof html == "undefined"){
8846 if(loadScripts !== true){
8847 this.dom.innerHTML = html;
8848 if(typeof callback == "function"){
8856 html += '<span id="' + id + '"></span>';
8858 E.onAvailable(id, function(){
8859 var hd = document.getElementsByTagName("head")[0];
8860 var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
8861 var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
8862 var typeRe = /\stype=([\'\"])(.*?)\1/i;
8865 while(match = re.exec(html)){
8866 var attrs = match[1];
8867 var srcMatch = attrs ? attrs.match(srcRe) : false;
8868 if(srcMatch && srcMatch[2]){
8869 var s = document.createElement("script");
8870 s.src = srcMatch[2];
8871 var typeMatch = attrs.match(typeRe);
8872 if(typeMatch && typeMatch[2]){
8873 s.type = typeMatch[2];
8876 }else if(match[2] && match[2].length > 0){
8877 if(window.execScript) {
8878 window.execScript(match[2]);
8886 window.eval(match[2]);
8890 var el = document.getElementById(id);
8891 if(el){el.parentNode.removeChild(el);}
8892 if(typeof callback == "function"){
8896 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
8901 * Direct access to the UpdateManager update() method (takes the same parameters).
8902 * @param {String/Function} url The url for this request or a function to call to get the url
8903 * @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}
8904 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
8905 * @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.
8906 * @return {Roo.Element} this
8909 var um = this.getUpdateManager();
8910 um.update.apply(um, arguments);
8915 * Gets this element's UpdateManager
8916 * @return {Roo.UpdateManager} The UpdateManager
8918 getUpdateManager : function(){
8919 if(!this.updateManager){
8920 this.updateManager = new Roo.UpdateManager(this);
8922 return this.updateManager;
8926 * Disables text selection for this element (normalized across browsers)
8927 * @return {Roo.Element} this
8929 unselectable : function(){
8930 this.dom.unselectable = "on";
8931 this.swallowEvent("selectstart", true);
8932 this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
8933 this.addClass("x-unselectable");
8938 * Calculates the x, y to center this element on the screen
8939 * @return {Array} The x, y values [x, y]
8941 getCenterXY : function(){
8942 return this.getAlignToXY(document, 'c-c');
8946 * Centers the Element in either the viewport, or another Element.
8947 * @param {String/HTMLElement/Roo.Element} centerIn (optional) The element in which to center the element.
8949 center : function(centerIn){
8950 this.alignTo(centerIn || document, 'c-c');
8955 * Tests various css rules/browsers to determine if this element uses a border box
8958 isBorderBox : function(){
8959 return noBoxAdjust[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
8963 * Return a box {x, y, width, height} that can be used to set another elements
8964 * size/location to match this element.
8965 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
8966 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
8967 * @return {Object} box An object in the format {x, y, width, height}
8969 getBox : function(contentBox, local){
8974 var left = parseInt(this.getStyle("left"), 10) || 0;
8975 var top = parseInt(this.getStyle("top"), 10) || 0;
8978 var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
8980 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
8982 var l = this.getBorderWidth("l")+this.getPadding("l");
8983 var r = this.getBorderWidth("r")+this.getPadding("r");
8984 var t = this.getBorderWidth("t")+this.getPadding("t");
8985 var b = this.getBorderWidth("b")+this.getPadding("b");
8986 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)};
8988 bx.right = bx.x + bx.width;
8989 bx.bottom = bx.y + bx.height;
8994 * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
8995 for more information about the sides.
8996 * @param {String} sides
8999 getFrameWidth : function(sides, onlyContentBox){
9000 return onlyContentBox && Roo.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
9004 * 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.
9005 * @param {Object} box The box to fill {x, y, width, height}
9006 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
9007 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9008 * @return {Roo.Element} this
9010 setBox : function(box, adjust, animate){
9011 var w = box.width, h = box.height;
9012 if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
9013 w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
9014 h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
9016 this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
9021 * Forces the browser to repaint this element
9022 * @return {Roo.Element} this
9024 repaint : function(){
9026 this.addClass("x-repaint");
9027 setTimeout(function(){
9028 Roo.get(dom).removeClass("x-repaint");
9034 * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
9035 * then it returns the calculated width of the sides (see getPadding)
9036 * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
9037 * @return {Object/Number}
9039 getMargins : function(side){
9042 top: parseInt(this.getStyle("margin-top"), 10) || 0,
9043 left: parseInt(this.getStyle("margin-left"), 10) || 0,
9044 bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
9045 right: parseInt(this.getStyle("margin-right"), 10) || 0
9048 return this.addStyles(side, El.margins);
9053 addStyles : function(sides, styles){
9055 for(var i = 0, len = sides.length; i < len; i++){
9056 v = this.getStyle(styles[sides.charAt(i)]);
9058 w = parseInt(v, 10);
9066 * Creates a proxy element of this element
9067 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
9068 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
9069 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
9070 * @return {Roo.Element} The new proxy element
9072 createProxy : function(config, renderTo, matchBox){
9074 renderTo = Roo.getDom(renderTo);
9076 renderTo = document.body;
9078 config = typeof config == "object" ?
9079 config : {tag : "div", cls: config};
9080 var proxy = Roo.DomHelper.append(renderTo, config, true);
9082 proxy.setBox(this.getBox());
9088 * Puts a mask over this element to disable user interaction. Requires core.css.
9089 * This method can only be applied to elements which accept child nodes.
9090 * @param {String} msg (optional) A message to display in the mask
9091 * @param {String} msgCls (optional) A css class to apply to the msg element
9092 * @return {Element} The mask element
9094 mask : function(msg, msgCls)
9096 if(this.getStyle("position") == "static" && this.dom.tagName !== 'BODY'){
9097 this.setStyle("position", "relative");
9100 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
9102 this.addClass("x-masked");
9103 this._mask.setDisplayed(true);
9108 while (dom && dom.style) {
9109 if (!isNaN(parseInt(dom.style.zIndex))) {
9110 z = Math.max(z, parseInt(dom.style.zIndex));
9112 dom = dom.parentNode;
9114 // if we are masking the body - then it hides everything..
9115 if (this.dom == document.body) {
9117 this._mask.setWidth(Roo.lib.Dom.getDocumentWidth());
9118 this._mask.setHeight(Roo.lib.Dom.getDocumentHeight());
9121 if(typeof msg == 'string'){
9123 this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
9125 var mm = this._maskMsg;
9126 mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg";
9127 if (mm.dom.firstChild) { // weird IE issue?
9128 mm.dom.firstChild.innerHTML = msg;
9130 mm.setDisplayed(true);
9132 mm.setStyle('z-index', z + 102);
9134 if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
9135 this._mask.setHeight(this.getHeight());
9137 this._mask.setStyle('z-index', z + 100);
9143 * Removes a previously applied mask. If removeEl is true the mask overlay is destroyed, otherwise
9144 * it is cached for reuse.
9146 unmask : function(removeEl){
9148 if(removeEl === true){
9149 this._mask.remove();
9152 this._maskMsg.remove();
9153 delete this._maskMsg;
9156 this._mask.setDisplayed(false);
9158 this._maskMsg.setDisplayed(false);
9162 this.removeClass("x-masked");
9166 * Returns true if this element is masked
9169 isMasked : function(){
9170 return this._mask && this._mask.isVisible();
9174 * Creates an iframe shim for this element to keep selects and other windowed objects from
9176 * @return {Roo.Element} The new shim element
9178 createShim : function(){
9179 var el = document.createElement('iframe');
9180 el.frameBorder = 'no';
9181 el.className = 'roo-shim';
9182 if(Roo.isIE && Roo.isSecure){
9183 el.src = Roo.SSL_SECURE_URL;
9185 var shim = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
9186 shim.autoBoxAdjust = false;
9191 * Removes this element from the DOM and deletes it from the cache
9193 remove : function(){
9194 if(this.dom.parentNode){
9195 this.dom.parentNode.removeChild(this.dom);
9197 delete El.cache[this.dom.id];
9201 * Sets up event handlers to add and remove a css class when the mouse is over this element
9202 * @param {String} className
9203 * @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
9204 * mouseout events for children elements
9205 * @return {Roo.Element} this
9207 addClassOnOver : function(className, preventFlicker){
9208 this.on("mouseover", function(){
9209 Roo.fly(this, '_internal').addClass(className);
9211 var removeFn = function(e){
9212 if(preventFlicker !== true || !e.within(this, true)){
9213 Roo.fly(this, '_internal').removeClass(className);
9216 this.on("mouseout", removeFn, this.dom);
9221 * Sets up event handlers to add and remove a css class when this element has the focus
9222 * @param {String} className
9223 * @return {Roo.Element} this
9225 addClassOnFocus : function(className){
9226 this.on("focus", function(){
9227 Roo.fly(this, '_internal').addClass(className);
9229 this.on("blur", function(){
9230 Roo.fly(this, '_internal').removeClass(className);
9235 * 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)
9236 * @param {String} className
9237 * @return {Roo.Element} this
9239 addClassOnClick : function(className){
9241 this.on("mousedown", function(){
9242 Roo.fly(dom, '_internal').addClass(className);
9243 var d = Roo.get(document);
9244 var fn = function(){
9245 Roo.fly(dom, '_internal').removeClass(className);
9246 d.removeListener("mouseup", fn);
9248 d.on("mouseup", fn);
9254 * Stops the specified event from bubbling and optionally prevents the default action
9255 * @param {String} eventName
9256 * @param {Boolean} preventDefault (optional) true to prevent the default action too
9257 * @return {Roo.Element} this
9259 swallowEvent : function(eventName, preventDefault){
9260 var fn = function(e){
9261 e.stopPropagation();
9266 if(eventName instanceof Array){
9267 for(var i = 0, len = eventName.length; i < len; i++){
9268 this.on(eventName[i], fn);
9272 this.on(eventName, fn);
9279 fitToParentDelegate : Roo.emptyFn, // keep a reference to the fitToParent delegate
9282 * Sizes this element to its parent element's dimensions performing
9283 * neccessary box adjustments.
9284 * @param {Boolean} monitorResize (optional) If true maintains the fit when the browser window is resized.
9285 * @param {String/HTMLElment/Element} targetParent (optional) The target parent, default to the parentNode.
9286 * @return {Roo.Element} this
9288 fitToParent : function(monitorResize, targetParent) {
9289 Roo.EventManager.removeResizeListener(this.fitToParentDelegate); // always remove previous fitToParent delegate from onWindowResize
9290 this.fitToParentDelegate = Roo.emptyFn; // remove reference to previous delegate
9291 if (monitorResize === true && !this.dom.parentNode) { // check if this Element still exists
9294 var p = Roo.get(targetParent || this.dom.parentNode);
9295 this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
9296 if (monitorResize === true) {
9297 this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, targetParent]);
9298 Roo.EventManager.onWindowResize(this.fitToParentDelegate);
9304 * Gets the next sibling, skipping text nodes
9305 * @return {HTMLElement} The next sibling or null
9307 getNextSibling : function(){
9308 var n = this.dom.nextSibling;
9309 while(n && n.nodeType != 1){
9316 * Gets the previous sibling, skipping text nodes
9317 * @return {HTMLElement} The previous sibling or null
9319 getPrevSibling : function(){
9320 var n = this.dom.previousSibling;
9321 while(n && n.nodeType != 1){
9322 n = n.previousSibling;
9329 * Appends the passed element(s) to this element
9330 * @param {String/HTMLElement/Array/Element/CompositeElement} el
9331 * @return {Roo.Element} this
9333 appendChild: function(el){
9340 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
9341 * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
9342 * automatically generated with the specified attributes.
9343 * @param {HTMLElement} insertBefore (optional) a child element of this element
9344 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
9345 * @return {Roo.Element} The new child element
9347 createChild: function(config, insertBefore, returnDom){
9348 config = config || {tag:'div'};
9350 return Roo.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
9352 return Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
9356 * Appends this element to the passed element
9357 * @param {String/HTMLElement/Element} el The new parent element
9358 * @return {Roo.Element} this
9360 appendTo: function(el){
9361 el = Roo.getDom(el);
9362 el.appendChild(this.dom);
9367 * Inserts this element before the passed element in the DOM
9368 * @param {String/HTMLElement/Element} el The element to insert before
9369 * @return {Roo.Element} this
9371 insertBefore: function(el){
9372 el = Roo.getDom(el);
9373 el.parentNode.insertBefore(this.dom, el);
9378 * Inserts this element after the passed element in the DOM
9379 * @param {String/HTMLElement/Element} el The element to insert after
9380 * @return {Roo.Element} this
9382 insertAfter: function(el){
9383 el = Roo.getDom(el);
9384 el.parentNode.insertBefore(this.dom, el.nextSibling);
9389 * Inserts (or creates) an element (or DomHelper config) as the first child of the this element
9390 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9391 * @return {Roo.Element} The new child
9393 insertFirst: function(el, returnDom){
9395 if(typeof el == 'object' && !el.nodeType){ // dh config
9396 return this.createChild(el, this.dom.firstChild, returnDom);
9398 el = Roo.getDom(el);
9399 this.dom.insertBefore(el, this.dom.firstChild);
9400 return !returnDom ? Roo.get(el) : el;
9405 * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
9406 * @param {String/HTMLElement/Element/Object} el The id or element to insert or a DomHelper config to create and insert
9407 * @param {String} where (optional) 'before' or 'after' defaults to before
9408 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9409 * @return {Roo.Element} the inserted Element
9411 insertSibling: function(el, where, returnDom){
9412 where = where ? where.toLowerCase() : 'before';
9414 var rt, refNode = where == 'before' ? this.dom : this.dom.nextSibling;
9416 if(typeof el == 'object' && !el.nodeType){ // dh config
9417 if(where == 'after' && !this.dom.nextSibling){
9418 rt = Roo.DomHelper.append(this.dom.parentNode, el, !returnDom);
9420 rt = Roo.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
9424 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
9425 where == 'before' ? this.dom : this.dom.nextSibling);
9434 * Creates and wraps this element with another element
9435 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
9436 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Roo.Element
9437 * @return {HTMLElement/Element} The newly created wrapper element
9439 wrap: function(config, returnDom){
9441 config = {tag: "div"};
9443 var newEl = Roo.DomHelper.insertBefore(this.dom, config, !returnDom);
9444 newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
9449 * Replaces the passed element with this element
9450 * @param {String/HTMLElement/Element} el The element to replace
9451 * @return {Roo.Element} this
9453 replace: function(el){
9455 this.insertBefore(el);
9461 * Inserts an html fragment into this element
9462 * @param {String} where Where to insert the html in relation to the this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
9463 * @param {String} html The HTML fragment
9464 * @param {Boolean} returnEl True to return an Roo.Element
9465 * @return {HTMLElement/Roo.Element} The inserted node (or nearest related if more than 1 inserted)
9467 insertHtml : function(where, html, returnEl){
9468 var el = Roo.DomHelper.insertHtml(where, this.dom, html);
9469 return returnEl ? Roo.get(el) : el;
9473 * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
9474 * @param {Object} o The object with the attributes
9475 * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
9476 * @return {Roo.Element} this
9478 set : function(o, useSet){
9480 useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
9482 if(attr == "style" || typeof o[attr] == "function") { continue; }
9484 el.className = o["cls"];
9487 el.setAttribute(attr, o[attr]);
9494 Roo.DomHelper.applyStyles(el, o.style);
9500 * Convenience method for constructing a KeyMap
9501 * @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:
9502 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9503 * @param {Function} fn The function to call
9504 * @param {Object} scope (optional) The scope of the function
9505 * @return {Roo.KeyMap} The KeyMap created
9507 addKeyListener : function(key, fn, scope){
9509 if(typeof key != "object" || key instanceof Array){
9525 return new Roo.KeyMap(this, config);
9529 * Creates a KeyMap for this element
9530 * @param {Object} config The KeyMap config. See {@link Roo.KeyMap} for more details
9531 * @return {Roo.KeyMap} The KeyMap created
9533 addKeyMap : function(config){
9534 return new Roo.KeyMap(this, config);
9538 * Returns true if this element is scrollable.
9541 isScrollable : function(){
9543 return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
9547 * 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().
9548 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
9549 * @param {Number} value The new scroll value
9550 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9551 * @return {Element} this
9554 scrollTo : function(side, value, animate){
9555 var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
9557 this.dom[prop] = value;
9559 var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
9560 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
9566 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
9567 * within this element's scrollable range.
9568 * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
9569 * @param {Number} distance How far to scroll the element in pixels
9570 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
9571 * @return {Boolean} Returns true if a scroll was triggered or false if the element
9572 * was scrolled as far as it could go.
9574 scroll : function(direction, distance, animate){
9575 if(!this.isScrollable()){
9579 var l = el.scrollLeft, t = el.scrollTop;
9580 var w = el.scrollWidth, h = el.scrollHeight;
9581 var cw = el.clientWidth, ch = el.clientHeight;
9582 direction = direction.toLowerCase();
9583 var scrolled = false;
9584 var a = this.preanim(arguments, 2);
9589 var v = Math.min(l + distance, w-cw);
9590 this.scrollTo("left", v, a);
9597 var v = Math.max(l - distance, 0);
9598 this.scrollTo("left", v, a);
9606 var v = Math.max(t - distance, 0);
9607 this.scrollTo("top", v, a);
9615 var v = Math.min(t + distance, h-ch);
9616 this.scrollTo("top", v, a);
9625 * Translates the passed page coordinates into left/top css values for this element
9626 * @param {Number/Array} x The page x or an array containing [x, y]
9627 * @param {Number} y The page y
9628 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
9630 translatePoints : function(x, y){
9631 if(typeof x == 'object' || x instanceof Array){
9634 var p = this.getStyle('position');
9635 var o = this.getXY();
9637 var l = parseInt(this.getStyle('left'), 10);
9638 var t = parseInt(this.getStyle('top'), 10);
9641 l = (p == "relative") ? 0 : this.dom.offsetLeft;
9644 t = (p == "relative") ? 0 : this.dom.offsetTop;
9647 return {left: (x - o[0] + l), top: (y - o[1] + t)};
9651 * Returns the current scroll position of the element.
9652 * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
9654 getScroll : function(){
9655 var d = this.dom, doc = document;
9656 if(d == doc || d == doc.body){
9657 var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
9658 var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
9659 return {left: l, top: t};
9661 return {left: d.scrollLeft, top: d.scrollTop};
9666 * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
9667 * are convert to standard 6 digit hex color.
9668 * @param {String} attr The css attribute
9669 * @param {String} defaultValue The default value to use when a valid color isn't found
9670 * @param {String} prefix (optional) defaults to #. Use an empty string when working with
9673 getColor : function(attr, defaultValue, prefix){
9674 var v = this.getStyle(attr);
9675 if(!v || v == "transparent" || v == "inherit") {
9676 return defaultValue;
9678 var color = typeof prefix == "undefined" ? "#" : prefix;
9679 if(v.substr(0, 4) == "rgb("){
9680 var rvs = v.slice(4, v.length -1).split(",");
9681 for(var i = 0; i < 3; i++){
9682 var h = parseInt(rvs[i]).toString(16);
9689 if(v.substr(0, 1) == "#"){
9691 for(var i = 1; i < 4; i++){
9692 var c = v.charAt(i);
9695 }else if(v.length == 7){
9696 color += v.substr(1);
9700 return(color.length > 5 ? color.toLowerCase() : defaultValue);
9704 * Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
9705 * gradient background, rounded corners and a 4-way shadow.
9706 * @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
9707 * Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
9708 * so if you supply an alternate base class, make sure you also supply all of the necessary rules.
9709 * @return {Roo.Element} this
9711 boxWrap : function(cls){
9712 cls = cls || 'x-box';
9713 var el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
9714 el.child('.'+cls+'-mc').dom.appendChild(this.dom);
9719 * Returns the value of a namespaced attribute from the element's underlying DOM node.
9720 * @param {String} namespace The namespace in which to look for the attribute
9721 * @param {String} name The attribute name
9722 * @return {String} The attribute value
9724 getAttributeNS : Roo.isIE ? function(ns, name){
9726 var type = typeof d[ns+":"+name];
9727 if(type != 'undefined' && type != 'unknown'){
9728 return d[ns+":"+name];
9731 } : function(ns, name){
9733 return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
9738 * Sets or Returns the value the dom attribute value
9739 * @param {String|Object} name The attribute name (or object to set multiple attributes)
9740 * @param {String} value (optional) The value to set the attribute to
9741 * @return {String} The attribute value
9743 attr : function(name){
9744 if (arguments.length > 1) {
9745 this.dom.setAttribute(name, arguments[1]);
9746 return arguments[1];
9748 if (typeof(name) == 'object') {
9749 for(var i in name) {
9750 this.attr(i, name[i]);
9756 if (!this.dom.hasAttribute(name)) {
9759 return this.dom.getAttribute(name);
9766 var ep = El.prototype;
9769 * Appends an event handler (Shorthand for addListener)
9770 * @param {String} eventName The type of event to append
9771 * @param {Function} fn The method the event invokes
9772 * @param {Object} scope (optional) The scope (this object) of the fn
9773 * @param {Object} options (optional)An object with standard {@link Roo.EventManager#addListener} options
9776 ep.on = ep.addListener;
9778 ep.mon = ep.addListener;
9781 * Removes an event handler from this element (shorthand for removeListener)
9782 * @param {String} eventName the type of event to remove
9783 * @param {Function} fn the method the event invokes
9784 * @return {Roo.Element} this
9787 ep.un = ep.removeListener;
9790 * true to automatically adjust width and height settings for box-model issues (default to true)
9792 ep.autoBoxAdjust = true;
9795 El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
9798 El.addUnits = function(v, defaultUnit){
9799 if(v === "" || v == "auto"){
9802 if(v === undefined){
9805 if(typeof v == "number" || !El.unitPattern.test(v)){
9806 return v + (defaultUnit || 'px');
9811 // special markup used throughout Roo when box wrapping elements
9812 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>';
9814 * Visibility mode constant - Use visibility to hide element
9820 * Visibility mode constant - Use display to hide element
9826 El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
9827 El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
9828 El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
9840 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9841 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9842 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9843 * @return {Element} The Element object
9846 El.get = function(el){
9848 if(!el){ return null; }
9849 if(typeof el == "string"){ // element id
9850 if(!(elm = document.getElementById(el))){
9853 if(ex = El.cache[el]){
9856 ex = El.cache[el] = new El(elm);
9859 }else if(el.tagName){ // dom element
9863 if(ex = El.cache[id]){
9866 ex = El.cache[id] = new El(el);
9869 }else if(el instanceof El){
9871 el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
9872 // catch case where it hasn't been appended
9873 El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
9876 }else if(el.isComposite){
9878 }else if(el instanceof Array){
9879 return El.select(el);
9880 }else if(el == document){
9881 // create a bogus element object representing the document object
9883 var f = function(){};
9884 f.prototype = El.prototype;
9886 docEl.dom = document;
9894 El.uncache = function(el){
9895 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
9897 delete El.cache[a[i].id || a[i]];
9903 // Garbage collection - uncache elements/purge listeners on orphaned elements
9904 // so we don't hold a reference and cause the browser to retain them
9905 El.garbageCollect = function(){
9906 if(!Roo.enableGarbageCollector){
9907 clearInterval(El.collectorThread);
9910 for(var eid in El.cache){
9911 var el = El.cache[eid], d = el.dom;
9912 // -------------------------------------------------------
9913 // Determining what is garbage:
9914 // -------------------------------------------------------
9916 // dom node is null, definitely garbage
9917 // -------------------------------------------------------
9919 // no parentNode == direct orphan, definitely garbage
9920 // -------------------------------------------------------
9921 // !d.offsetParent && !document.getElementById(eid)
9922 // display none elements have no offsetParent so we will
9923 // also try to look it up by it's id. However, check
9924 // offsetParent first so we don't do unneeded lookups.
9925 // This enables collection of elements that are not orphans
9926 // directly, but somewhere up the line they have an orphan
9928 // -------------------------------------------------------
9929 if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
9930 delete El.cache[eid];
9931 if(d && Roo.enableListenerCollection){
9937 El.collectorThreadId = setInterval(El.garbageCollect, 30000);
9941 El.Flyweight = function(dom){
9944 El.Flyweight.prototype = El.prototype;
9946 El._flyweights = {};
9948 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9949 * the dom node can be overwritten by other code.
9950 * @param {String/HTMLElement} el The dom node or id
9951 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9952 * prevent conflicts (e.g. internally Roo uses "_internal")
9954 * @return {Element} The shared Element object
9956 El.fly = function(el, named){
9957 named = named || '_global';
9958 el = Roo.getDom(el);
9962 if(!El._flyweights[named]){
9963 El._flyweights[named] = new El.Flyweight();
9965 El._flyweights[named].dom = el;
9966 return El._flyweights[named];
9970 * Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
9971 * Automatically fixes if an object was recreated with the same id via AJAX or DOM.
9972 * Shorthand of {@link Roo.Element#get}
9973 * @param {String/HTMLElement/Element} el The id of the node, a DOM Node or an existing Element.
9974 * @return {Element} The Element object
9980 * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
9981 * the dom node can be overwritten by other code.
9982 * Shorthand of {@link Roo.Element#fly}
9983 * @param {String/HTMLElement} el The dom node or id
9984 * @param {String} named (optional) Allows for creation of named reusable flyweights to
9985 * prevent conflicts (e.g. internally Roo uses "_internal")
9987 * @return {Element} The shared Element object
9993 // speedy lookup for elements never to box adjust
9994 var noBoxAdjust = Roo.isStrict ? {
9997 input:1, select:1, textarea:1
9999 if(Roo.isIE || Roo.isGecko){
10000 noBoxAdjust['button'] = 1;
10004 Roo.EventManager.on(window, 'unload', function(){
10006 delete El._flyweights;
10014 Roo.Element.selectorFunction = Roo.DomQuery.select;
10017 Roo.Element.select = function(selector, unique, root){
10019 if(typeof selector == "string"){
10020 els = Roo.Element.selectorFunction(selector, root);
10021 }else if(selector.length !== undefined){
10024 throw "Invalid selector";
10026 if(unique === true){
10027 return new Roo.CompositeElement(els);
10029 return new Roo.CompositeElementLite(els);
10033 * Selects elements based on the passed CSS selector to enable working on them as 1.
10034 * @param {String/Array} selector The CSS selector or an array of elements
10035 * @param {Boolean} unique (optional) true to create a unique Roo.Element for each element (defaults to a shared flyweight object)
10036 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
10037 * @return {CompositeElementLite/CompositeElement}
10041 Roo.select = Roo.Element.select;
10058 * Ext JS Library 1.1.1
10059 * Copyright(c) 2006-2007, Ext JS, LLC.
10061 * Originally Released Under LGPL - original licence link has changed is not relivant.
10064 * <script type="text/javascript">
10069 //Notifies Element that fx methods are available
10070 Roo.enableFx = true;
10074 * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
10075 * to the {@link Roo.Element} interface when included, so all effects calls should be performed via Element.
10076 * Conversely, since the effects are not actually defined in Element, Roo.Fx <b>must</b> be included in order for the
10077 * Element effects to work.</p><br/>
10079 * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
10080 * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
10081 * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
10082 * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
10083 * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
10084 * expected results and should be done with care.</p><br/>
10086 * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
10087 * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
10090 ----- -----------------------------
10091 tl The top left corner
10092 t The center of the top edge
10093 tr The top right corner
10094 l The center of the left edge
10095 r The center of the right edge
10096 bl The bottom left corner
10097 b The center of the bottom edge
10098 br The bottom right corner
10100 * <b>Although some Fx methods accept specific custom config parameters, the ones shown in the Config Options section
10101 * below are common options that can be passed to any Fx method.</b>
10102 * @cfg {Function} callback A function called when the effect is finished
10103 * @cfg {Object} scope The scope of the effect function
10104 * @cfg {String} easing A valid Easing value for the effect
10105 * @cfg {String} afterCls A css class to apply after the effect
10106 * @cfg {Number} duration The length of time (in seconds) that the effect should last
10107 * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
10108 * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
10109 * effects that end with the element being visually hidden, ignored otherwise)
10110 * @cfg {String/Object/Function} afterStyle A style specification string, e.g. "width:100px", or an object in the form {width:"100px"}, or
10111 * a function which returns such a specification that will be applied to the Element after the effect finishes
10112 * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
10113 * @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
10114 * @cfg {Boolean} stopFx Whether subsequent effects should be stopped and removed after the current effect finishes
10118 * Slides the element into view. An anchor point can be optionally passed to set the point of
10119 * origin for the slide effect. This function automatically handles wrapping the element with
10120 * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10123 // default: slide the element in from the top
10126 // custom: slide the element in from the right with a 2-second duration
10127 el.slideIn('r', { duration: 2 });
10129 // common config options shown with default values
10135 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10136 * @param {Object} options (optional) Object literal with any of the Fx config options
10137 * @return {Roo.Element} The Element
10139 slideIn : function(anchor, o){
10140 var el = this.getFxEl();
10143 el.queueFx(o, function(){
10145 anchor = anchor || "t";
10147 // fix display to visibility
10150 // restore values after effect
10151 var r = this.getFxRestore();
10152 var b = this.getBox();
10153 // fixed size for slide
10157 var wrap = this.fxWrap(r.pos, o, "hidden");
10159 var st = this.dom.style;
10160 st.visibility = "visible";
10161 st.position = "absolute";
10163 // clear out temp styles after slide and unwrap
10164 var after = function(){
10165 el.fxUnwrap(wrap, r.pos, o);
10166 st.width = r.width;
10167 st.height = r.height;
10170 // time to calc the positions
10171 var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
10173 switch(anchor.toLowerCase()){
10175 wrap.setSize(b.width, 0);
10176 st.left = st.bottom = "0";
10180 wrap.setSize(0, b.height);
10181 st.right = st.top = "0";
10185 wrap.setSize(0, b.height);
10186 wrap.setX(b.right);
10187 st.left = st.top = "0";
10188 a = {width: bw, points: pt};
10191 wrap.setSize(b.width, 0);
10192 wrap.setY(b.bottom);
10193 st.left = st.top = "0";
10194 a = {height: bh, points: pt};
10197 wrap.setSize(0, 0);
10198 st.right = st.bottom = "0";
10199 a = {width: bw, height: bh};
10202 wrap.setSize(0, 0);
10203 wrap.setY(b.y+b.height);
10204 st.right = st.top = "0";
10205 a = {width: bw, height: bh, points: pt};
10208 wrap.setSize(0, 0);
10209 wrap.setXY([b.right, b.bottom]);
10210 st.left = st.top = "0";
10211 a = {width: bw, height: bh, points: pt};
10214 wrap.setSize(0, 0);
10215 wrap.setX(b.x+b.width);
10216 st.left = st.bottom = "0";
10217 a = {width: bw, height: bh, points: pt};
10220 this.dom.style.visibility = "visible";
10223 arguments.callee.anim = wrap.fxanim(a,
10233 * Slides the element out of view. An anchor point can be optionally passed to set the end point
10234 * for the slide effect. When the effect is completed, the element will be hidden (visibility =
10235 * 'hidden') but block elements will still take up space in the document. The element must be removed
10236 * from the DOM using the 'remove' config option if desired. This function automatically handles
10237 * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
10240 // default: slide the element out to the top
10243 // custom: slide the element out to the right with a 2-second duration
10244 el.slideOut('r', { duration: 2 });
10246 // common config options shown with default values
10254 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
10255 * @param {Object} options (optional) Object literal with any of the Fx config options
10256 * @return {Roo.Element} The Element
10258 slideOut : function(anchor, o){
10259 var el = this.getFxEl();
10262 el.queueFx(o, function(){
10264 anchor = anchor || "t";
10266 // restore values after effect
10267 var r = this.getFxRestore();
10269 var b = this.getBox();
10270 // fixed size for slide
10274 var wrap = this.fxWrap(r.pos, o, "visible");
10276 var st = this.dom.style;
10277 st.visibility = "visible";
10278 st.position = "absolute";
10282 var after = function(){
10284 el.setDisplayed(false);
10289 el.fxUnwrap(wrap, r.pos, o);
10291 st.width = r.width;
10292 st.height = r.height;
10297 var a, zero = {to: 0};
10298 switch(anchor.toLowerCase()){
10300 st.left = st.bottom = "0";
10301 a = {height: zero};
10304 st.right = st.top = "0";
10308 st.left = st.top = "0";
10309 a = {width: zero, points: {to:[b.right, b.y]}};
10312 st.left = st.top = "0";
10313 a = {height: zero, points: {to:[b.x, b.bottom]}};
10316 st.right = st.bottom = "0";
10317 a = {width: zero, height: zero};
10320 st.right = st.top = "0";
10321 a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}};
10324 st.left = st.top = "0";
10325 a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}};
10328 st.left = st.bottom = "0";
10329 a = {width: zero, height: zero, points: {to:[b.right, b.y]}};
10333 arguments.callee.anim = wrap.fxanim(a,
10343 * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
10344 * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
10345 * The element must be removed from the DOM using the 'remove' config option if desired.
10351 // common config options shown with default values
10359 * @param {Object} options (optional) Object literal with any of the Fx config options
10360 * @return {Roo.Element} The Element
10362 puff : function(o){
10363 var el = this.getFxEl();
10366 el.queueFx(o, function(){
10367 this.clearOpacity();
10370 // restore values after effect
10371 var r = this.getFxRestore();
10372 var st = this.dom.style;
10374 var after = function(){
10376 el.setDisplayed(false);
10383 el.setPositioning(r.pos);
10384 st.width = r.width;
10385 st.height = r.height;
10390 var width = this.getWidth();
10391 var height = this.getHeight();
10393 arguments.callee.anim = this.fxanim({
10394 width : {to: this.adjustWidth(width * 2)},
10395 height : {to: this.adjustHeight(height * 2)},
10396 points : {by: [-(width * .5), -(height * .5)]},
10398 fontSize: {to:200, unit: "%"}
10409 * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
10410 * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
10411 * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
10417 // all config options shown with default values
10425 * @param {Object} options (optional) Object literal with any of the Fx config options
10426 * @return {Roo.Element} The Element
10428 switchOff : function(o){
10429 var el = this.getFxEl();
10432 el.queueFx(o, function(){
10433 this.clearOpacity();
10436 // restore values after effect
10437 var r = this.getFxRestore();
10438 var st = this.dom.style;
10440 var after = function(){
10442 el.setDisplayed(false);
10448 el.setPositioning(r.pos);
10449 st.width = r.width;
10450 st.height = r.height;
10455 this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
10456 this.clearOpacity();
10460 points:{by:[0, this.getHeight() * .5]}
10461 }, o, 'motion', 0.3, 'easeIn', after);
10462 }).defer(100, this);
10469 * Highlights the Element by setting a color (applies to the background-color by default, but can be
10470 * changed using the "attr" config option) and then fading back to the original color. If no original
10471 * color is available, you should provide the "endColor" config option which will be cleared after the animation.
10474 // default: highlight background to yellow
10477 // custom: highlight foreground text to blue for 2 seconds
10478 el.highlight("0000ff", { attr: 'color', duration: 2 });
10480 // common config options shown with default values
10481 el.highlight("ffff9c", {
10482 attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
10483 endColor: (current color) or "ffffff",
10488 * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
10489 * @param {Object} options (optional) Object literal with any of the Fx config options
10490 * @return {Roo.Element} The Element
10492 highlight : function(color, o){
10493 var el = this.getFxEl();
10496 el.queueFx(o, function(){
10497 color = color || "ffff9c";
10498 attr = o.attr || "backgroundColor";
10500 this.clearOpacity();
10503 var origColor = this.getColor(attr);
10504 var restoreColor = this.dom.style[attr];
10505 endColor = (o.endColor || origColor) || "ffffff";
10507 var after = function(){
10508 el.dom.style[attr] = restoreColor;
10513 a[attr] = {from: color, to: endColor};
10514 arguments.callee.anim = this.fxanim(a,
10524 * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
10527 // default: a single light blue ripple
10530 // custom: 3 red ripples lasting 3 seconds total
10531 el.frame("ff0000", 3, { duration: 3 });
10533 // common config options shown with default values
10534 el.frame("C3DAF9", 1, {
10535 duration: 1 //duration of entire animation (not each individual ripple)
10536 // Note: Easing is not configurable and will be ignored if included
10539 * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
10540 * @param {Number} count (optional) The number of ripples to display (defaults to 1)
10541 * @param {Object} options (optional) Object literal with any of the Fx config options
10542 * @return {Roo.Element} The Element
10544 frame : function(color, count, o){
10545 var el = this.getFxEl();
10548 el.queueFx(o, function(){
10549 color = color || "#C3DAF9";
10550 if(color.length == 6){
10551 color = "#" + color;
10553 count = count || 1;
10554 duration = o.duration || 1;
10557 var b = this.getBox();
10558 var animFn = function(){
10559 var proxy = this.createProxy({
10562 visbility:"hidden",
10563 position:"absolute",
10564 "z-index":"35000", // yee haw
10565 border:"0px solid " + color
10568 var scale = Roo.isBorderBox ? 2 : 1;
10570 top:{from:b.y, to:b.y - 20},
10571 left:{from:b.x, to:b.x - 20},
10572 borderWidth:{from:0, to:10},
10573 opacity:{from:1, to:0},
10574 height:{from:b.height, to:(b.height + (20*scale))},
10575 width:{from:b.width, to:(b.width + (20*scale))}
10576 }, duration, function(){
10580 animFn.defer((duration/2)*1000, this);
10591 * Creates a pause before any subsequent queued effects begin. If there are
10592 * no effects queued after the pause it will have no effect.
10597 * @param {Number} seconds The length of time to pause (in seconds)
10598 * @return {Roo.Element} The Element
10600 pause : function(seconds){
10601 var el = this.getFxEl();
10604 el.queueFx(o, function(){
10605 setTimeout(function(){
10607 }, seconds * 1000);
10613 * Fade an element in (from transparent to opaque). The ending opacity can be specified
10614 * using the "endOpacity" config option.
10617 // default: fade in from opacity 0 to 100%
10620 // custom: fade in from opacity 0 to 75% over 2 seconds
10621 el.fadeIn({ endOpacity: .75, duration: 2});
10623 // common config options shown with default values
10625 endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
10630 * @param {Object} options (optional) Object literal with any of the Fx config options
10631 * @return {Roo.Element} The Element
10633 fadeIn : function(o){
10634 var el = this.getFxEl();
10636 el.queueFx(o, function(){
10637 this.setOpacity(0);
10639 this.dom.style.visibility = 'visible';
10640 var to = o.endOpacity || 1;
10641 arguments.callee.anim = this.fxanim({opacity:{to:to}},
10642 o, null, .5, "easeOut", function(){
10644 this.clearOpacity();
10653 * Fade an element out (from opaque to transparent). The ending opacity can be specified
10654 * using the "endOpacity" config option.
10657 // default: fade out from the element's current opacity to 0
10660 // custom: fade out from the element's current opacity to 25% over 2 seconds
10661 el.fadeOut({ endOpacity: .25, duration: 2});
10663 // common config options shown with default values
10665 endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
10672 * @param {Object} options (optional) Object literal with any of the Fx config options
10673 * @return {Roo.Element} The Element
10675 fadeOut : function(o){
10676 var el = this.getFxEl();
10678 el.queueFx(o, function(){
10679 arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
10680 o, null, .5, "easeOut", function(){
10681 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
10682 this.dom.style.display = "none";
10684 this.dom.style.visibility = "hidden";
10686 this.clearOpacity();
10694 * Animates the transition of an element's dimensions from a starting height/width
10695 * to an ending height/width.
10698 // change height and width to 100x100 pixels
10699 el.scale(100, 100);
10701 // common config options shown with default values. The height and width will default to
10702 // the element's existing values if passed as null.
10705 [element's height], {
10710 * @param {Number} width The new width (pass undefined to keep the original width)
10711 * @param {Number} height The new height (pass undefined to keep the original height)
10712 * @param {Object} options (optional) Object literal with any of the Fx config options
10713 * @return {Roo.Element} The Element
10715 scale : function(w, h, o){
10716 this.shift(Roo.apply({}, o, {
10724 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
10725 * Any of these properties not specified in the config object will not be changed. This effect
10726 * requires that at least one new dimension, position or opacity setting must be passed in on
10727 * the config object in order for the function to have any effect.
10730 // slide the element horizontally to x position 200 while changing the height and opacity
10731 el.shift({ x: 200, height: 50, opacity: .8 });
10733 // common config options shown with default values.
10735 width: [element's width],
10736 height: [element's height],
10737 x: [element's x position],
10738 y: [element's y position],
10739 opacity: [element's opacity],
10744 * @param {Object} options Object literal with any of the Fx config options
10745 * @return {Roo.Element} The Element
10747 shift : function(o){
10748 var el = this.getFxEl();
10750 el.queueFx(o, function(){
10751 var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity;
10752 if(w !== undefined){
10753 a.width = {to: this.adjustWidth(w)};
10755 if(h !== undefined){
10756 a.height = {to: this.adjustHeight(h)};
10758 if(x !== undefined || y !== undefined){
10760 x !== undefined ? x : this.getX(),
10761 y !== undefined ? y : this.getY()
10764 if(op !== undefined){
10765 a.opacity = {to: op};
10767 if(o.xy !== undefined){
10768 a.points = {to: o.xy};
10770 arguments.callee.anim = this.fxanim(a,
10771 o, 'motion', .35, "easeOut", function(){
10779 * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
10780 * ending point of the effect.
10783 // default: slide the element downward while fading out
10786 // custom: slide the element out to the right with a 2-second duration
10787 el.ghost('r', { duration: 2 });
10789 // common config options shown with default values
10797 * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
10798 * @param {Object} options (optional) Object literal with any of the Fx config options
10799 * @return {Roo.Element} The Element
10801 ghost : function(anchor, o){
10802 var el = this.getFxEl();
10805 el.queueFx(o, function(){
10806 anchor = anchor || "b";
10808 // restore values after effect
10809 var r = this.getFxRestore();
10810 var w = this.getWidth(),
10811 h = this.getHeight();
10813 var st = this.dom.style;
10815 var after = function(){
10817 el.setDisplayed(false);
10823 el.setPositioning(r.pos);
10824 st.width = r.width;
10825 st.height = r.height;
10830 var a = {opacity: {to: 0}, points: {}}, pt = a.points;
10831 switch(anchor.toLowerCase()){
10858 arguments.callee.anim = this.fxanim(a,
10868 * Ensures that all effects queued after syncFx is called on the element are
10869 * run concurrently. This is the opposite of {@link #sequenceFx}.
10870 * @return {Roo.Element} The Element
10872 syncFx : function(){
10873 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10882 * Ensures that all effects queued after sequenceFx is called on the element are
10883 * run in sequence. This is the opposite of {@link #syncFx}.
10884 * @return {Roo.Element} The Element
10886 sequenceFx : function(){
10887 this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
10889 concurrent : false,
10896 nextFx : function(){
10897 var ef = this.fxQueue[0];
10904 * Returns true if the element has any effects actively running or queued, else returns false.
10905 * @return {Boolean} True if element has active effects, else false
10907 hasActiveFx : function(){
10908 return this.fxQueue && this.fxQueue[0];
10912 * Stops any running effects and clears the element's internal effects queue if it contains
10913 * any additional effects that haven't started yet.
10914 * @return {Roo.Element} The Element
10916 stopFx : function(){
10917 if(this.hasActiveFx()){
10918 var cur = this.fxQueue[0];
10919 if(cur && cur.anim && cur.anim.isAnimated()){
10920 this.fxQueue = [cur]; // clear out others
10921 cur.anim.stop(true);
10928 beforeFx : function(o){
10929 if(this.hasActiveFx() && !o.concurrent){
10940 * Returns true if the element is currently blocking so that no other effect can be queued
10941 * until this effect is finished, else returns false if blocking is not set. This is commonly
10942 * used to ensure that an effect initiated by a user action runs to completion prior to the
10943 * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
10944 * @return {Boolean} True if blocking, else false
10946 hasFxBlock : function(){
10947 var q = this.fxQueue;
10948 return q && q[0] && q[0].block;
10952 queueFx : function(o, fn){
10956 if(!this.hasFxBlock()){
10957 Roo.applyIf(o, this.fxDefaults);
10959 var run = this.beforeFx(o);
10960 fn.block = o.block;
10961 this.fxQueue.push(fn);
10973 fxWrap : function(pos, o, vis){
10975 if(!o.wrap || !(wrap = Roo.get(o.wrap))){
10978 wrapXY = this.getXY();
10980 var div = document.createElement("div");
10981 div.style.visibility = vis;
10982 wrap = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
10983 wrap.setPositioning(pos);
10984 if(wrap.getStyle("position") == "static"){
10985 wrap.position("relative");
10987 this.clearPositioning('auto');
10989 wrap.dom.appendChild(this.dom);
10991 wrap.setXY(wrapXY);
10998 fxUnwrap : function(wrap, pos, o){
10999 this.clearPositioning();
11000 this.setPositioning(pos);
11002 wrap.dom.parentNode.insertBefore(this.dom, wrap.dom);
11008 getFxRestore : function(){
11009 var st = this.dom.style;
11010 return {pos: this.getPositioning(), width: st.width, height : st.height};
11014 afterFx : function(o){
11016 this.applyStyles(o.afterStyle);
11019 this.addClass(o.afterCls);
11021 if(o.remove === true){
11024 Roo.callback(o.callback, o.scope, [this]);
11026 this.fxQueue.shift();
11032 getFxEl : function(){ // support for composite element fx
11033 return Roo.get(this.dom);
11037 fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
11038 animType = animType || 'run';
11040 var anim = Roo.lib.Anim[animType](
11042 (opt.duration || defaultDur) || .35,
11043 (opt.easing || defaultEase) || 'easeOut',
11045 Roo.callback(cb, this);
11054 // backwords compat
11055 Roo.Fx.resize = Roo.Fx.scale;
11057 //When included, Roo.Fx is automatically applied to Element so that all basic
11058 //effects are available directly via the Element API
11059 Roo.apply(Roo.Element.prototype, Roo.Fx);/*
11061 * Ext JS Library 1.1.1
11062 * Copyright(c) 2006-2007, Ext JS, LLC.
11064 * Originally Released Under LGPL - original licence link has changed is not relivant.
11067 * <script type="text/javascript">
11072 * @class Roo.CompositeElement
11073 * Standard composite class. Creates a Roo.Element for every element in the collection.
11075 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
11076 * actions will be performed on all the elements in this collection.</b>
11078 * All methods return <i>this</i> and can be chained.
11080 var els = Roo.select("#some-el div.some-class", true);
11081 // or select directly from an existing element
11082 var el = Roo.get('some-el');
11083 el.select('div.some-class', true);
11085 els.setWidth(100); // all elements become 100 width
11086 els.hide(true); // all elements fade out and hide
11088 els.setWidth(100).hide(true);
11091 Roo.CompositeElement = function(els){
11092 this.elements = [];
11093 this.addElements(els);
11095 Roo.CompositeElement.prototype = {
11097 addElements : function(els){
11101 if(typeof els == "string"){
11102 els = Roo.Element.selectorFunction(els);
11104 var yels = this.elements;
11105 var index = yels.length-1;
11106 for(var i = 0, len = els.length; i < len; i++) {
11107 yels[++index] = Roo.get(els[i]);
11113 * Clears this composite and adds the elements returned by the passed selector.
11114 * @param {String/Array} els A string CSS selector, an array of elements or an element
11115 * @return {CompositeElement} this
11117 fill : function(els){
11118 this.elements = [];
11124 * Filters this composite to only elements that match the passed selector.
11125 * @param {String} selector A string CSS selector
11126 * @param {Boolean} inverse return inverse filter (not matches)
11127 * @return {CompositeElement} this
11129 filter : function(selector, inverse){
11131 inverse = inverse || false;
11132 this.each(function(el){
11133 var match = inverse ? !el.is(selector) : el.is(selector);
11135 els[els.length] = el.dom;
11142 invoke : function(fn, args){
11143 var els = this.elements;
11144 for(var i = 0, len = els.length; i < len; i++) {
11145 Roo.Element.prototype[fn].apply(els[i], args);
11150 * Adds elements to this composite.
11151 * @param {String/Array} els A string CSS selector, an array of elements or an element
11152 * @return {CompositeElement} this
11154 add : function(els){
11155 if(typeof els == "string"){
11156 this.addElements(Roo.Element.selectorFunction(els));
11157 }else if(els.length !== undefined){
11158 this.addElements(els);
11160 this.addElements([els]);
11165 * Calls the passed function passing (el, this, index) for each element in this composite.
11166 * @param {Function} fn The function to call
11167 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11168 * @return {CompositeElement} this
11170 each : function(fn, scope){
11171 var els = this.elements;
11172 for(var i = 0, len = els.length; i < len; i++){
11173 if(fn.call(scope || els[i], els[i], this, i) === false) {
11181 * Returns the Element object at the specified index
11182 * @param {Number} index
11183 * @return {Roo.Element}
11185 item : function(index){
11186 return this.elements[index] || null;
11190 * Returns the first Element
11191 * @return {Roo.Element}
11193 first : function(){
11194 return this.item(0);
11198 * Returns the last Element
11199 * @return {Roo.Element}
11202 return this.item(this.elements.length-1);
11206 * Returns the number of elements in this composite
11209 getCount : function(){
11210 return this.elements.length;
11214 * Returns true if this composite contains the passed element
11217 contains : function(el){
11218 return this.indexOf(el) !== -1;
11222 * Returns true if this composite contains the passed element
11225 indexOf : function(el){
11226 return this.elements.indexOf(Roo.get(el));
11231 * Removes the specified element(s).
11232 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
11233 * or an array of any of those.
11234 * @param {Boolean} removeDom (optional) True to also remove the element from the document
11235 * @return {CompositeElement} this
11237 removeElement : function(el, removeDom){
11238 if(el instanceof Array){
11239 for(var i = 0, len = el.length; i < len; i++){
11240 this.removeElement(el[i]);
11244 var index = typeof el == 'number' ? el : this.indexOf(el);
11247 var d = this.elements[index];
11251 d.parentNode.removeChild(d);
11254 this.elements.splice(index, 1);
11260 * Replaces the specified element with the passed element.
11261 * @param {String/HTMLElement/Element/Number} el The id of an element, the Element itself, the index of the element in this composite
11263 * @param {String/HTMLElement/Element} replacement The id of an element or the Element itself.
11264 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
11265 * @return {CompositeElement} this
11267 replaceElement : function(el, replacement, domReplace){
11268 var index = typeof el == 'number' ? el : this.indexOf(el);
11271 this.elements[index].replaceWith(replacement);
11273 this.elements.splice(index, 1, Roo.get(replacement))
11280 * Removes all elements.
11282 clear : function(){
11283 this.elements = [];
11287 Roo.CompositeElement.createCall = function(proto, fnName){
11288 if(!proto[fnName]){
11289 proto[fnName] = function(){
11290 return this.invoke(fnName, arguments);
11294 for(var fnName in Roo.Element.prototype){
11295 if(typeof Roo.Element.prototype[fnName] == "function"){
11296 Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
11302 * Ext JS Library 1.1.1
11303 * Copyright(c) 2006-2007, Ext JS, LLC.
11305 * Originally Released Under LGPL - original licence link has changed is not relivant.
11308 * <script type="text/javascript">
11312 * @class Roo.CompositeElementLite
11313 * @extends Roo.CompositeElement
11314 * Flyweight composite class. Reuses the same Roo.Element for element operations.
11316 var els = Roo.select("#some-el div.some-class");
11317 // or select directly from an existing element
11318 var el = Roo.get('some-el');
11319 el.select('div.some-class');
11321 els.setWidth(100); // all elements become 100 width
11322 els.hide(true); // all elements fade out and hide
11324 els.setWidth(100).hide(true);
11325 </code></pre><br><br>
11326 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
11327 * actions will be performed on all the elements in this collection.</b>
11329 Roo.CompositeElementLite = function(els){
11330 Roo.CompositeElementLite.superclass.constructor.call(this, els);
11331 this.el = new Roo.Element.Flyweight();
11333 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
11334 addElements : function(els){
11336 if(els instanceof Array){
11337 this.elements = this.elements.concat(els);
11339 var yels = this.elements;
11340 var index = yels.length-1;
11341 for(var i = 0, len = els.length; i < len; i++) {
11342 yels[++index] = els[i];
11348 invoke : function(fn, args){
11349 var els = this.elements;
11351 for(var i = 0, len = els.length; i < len; i++) {
11353 Roo.Element.prototype[fn].apply(el, args);
11358 * Returns a flyweight Element of the dom element object at the specified index
11359 * @param {Number} index
11360 * @return {Roo.Element}
11362 item : function(index){
11363 if(!this.elements[index]){
11366 this.el.dom = this.elements[index];
11370 // fixes scope with flyweight
11371 addListener : function(eventName, handler, scope, opt){
11372 var els = this.elements;
11373 for(var i = 0, len = els.length; i < len; i++) {
11374 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
11380 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
11381 * passed is the flyweight (shared) Roo.Element instance, so if you require a
11382 * a reference to the dom node, use el.dom.</b>
11383 * @param {Function} fn The function to call
11384 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
11385 * @return {CompositeElement} this
11387 each : function(fn, scope){
11388 var els = this.elements;
11390 for(var i = 0, len = els.length; i < len; i++){
11392 if(fn.call(scope || el, el, this, i) === false){
11399 indexOf : function(el){
11400 return this.elements.indexOf(Roo.getDom(el));
11403 replaceElement : function(el, replacement, domReplace){
11404 var index = typeof el == 'number' ? el : this.indexOf(el);
11406 replacement = Roo.getDom(replacement);
11408 var d = this.elements[index];
11409 d.parentNode.insertBefore(replacement, d);
11410 d.parentNode.removeChild(d);
11412 this.elements.splice(index, 1, replacement);
11417 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
11421 * Ext JS Library 1.1.1
11422 * Copyright(c) 2006-2007, Ext JS, LLC.
11424 * Originally Released Under LGPL - original licence link has changed is not relivant.
11427 * <script type="text/javascript">
11433 * @class Roo.data.Connection
11434 * @extends Roo.util.Observable
11435 * The class encapsulates a connection to the page's originating domain, allowing requests to be made
11436 * either to a configured URL, or to a URL specified at request time.<br><br>
11438 * Requests made by this class are asynchronous, and will return immediately. No data from
11439 * the server will be available to the statement immediately following the {@link #request} call.
11440 * To process returned data, use a callback in the request options object, or an event listener.</p><br>
11442 * Note: If you are doing a file upload, you will not get a normal response object sent back to
11443 * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest.
11444 * The response object is created using the innerHTML of the IFRAME's document as the responseText
11445 * property and, if present, the IFRAME's XML document as the responseXML property.</p><br>
11446 * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested
11447 * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText
11448 * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using
11449 * standard DOM methods.
11451 * @param {Object} config a configuration object.
11453 Roo.data.Connection = function(config){
11454 Roo.apply(this, config);
11457 * @event beforerequest
11458 * Fires before a network request is made to retrieve a data object.
11459 * @param {Connection} conn This Connection object.
11460 * @param {Object} options The options config object passed to the {@link #request} method.
11462 "beforerequest" : true,
11464 * @event requestcomplete
11465 * Fires if the request was successfully completed.
11466 * @param {Connection} conn This Connection object.
11467 * @param {Object} response The XHR object containing the response data.
11468 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11469 * @param {Object} options The options config object passed to the {@link #request} method.
11471 "requestcomplete" : true,
11473 * @event requestexception
11474 * Fires if an error HTTP status was returned from the server.
11475 * See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
11476 * @param {Connection} conn This Connection object.
11477 * @param {Object} response The XHR object containing the response data.
11478 * See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
11479 * @param {Object} options The options config object passed to the {@link #request} method.
11481 "requestexception" : true
11483 Roo.data.Connection.superclass.constructor.call(this);
11486 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
11488 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11491 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11492 * extra parameters to each request made by this object. (defaults to undefined)
11495 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11496 * to each request made by this object. (defaults to undefined)
11499 * @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)
11502 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11506 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11512 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11515 disableCaching: true,
11518 * Sends an HTTP request to a remote server.
11519 * @param {Object} options An object which may contain the following properties:<ul>
11520 * <li><b>url</b> {String} (Optional) The URL to which to send the request. Defaults to configured URL</li>
11521 * <li><b>params</b> {Object/String/Function} (Optional) An object containing properties which are used as parameters to the
11522 * request, a url encoded string or a function to call to get either.</li>
11523 * <li><b>method</b> {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or
11524 * if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.</li>
11525 * <li><b>callback</b> {Function} (Optional) The function to be called upon receipt of the HTTP response.
11526 * The callback is called regardless of success or failure and is passed the following parameters:<ul>
11527 * <li>options {Object} The parameter to the request call.</li>
11528 * <li>success {Boolean} True if the request succeeded.</li>
11529 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11531 * <li><b>success</b> {Function} (Optional) The function to be called upon success of the request.
11532 * The callback is passed the following parameters:<ul>
11533 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11534 * <li>options {Object} The parameter to the request call.</li>
11536 * <li><b>failure</b> {Function} (Optional) The function to be called upon failure of the request.
11537 * The callback is passed the following parameters:<ul>
11538 * <li>response {Object} The XMLHttpRequest object containing the response data.</li>
11539 * <li>options {Object} The parameter to the request call.</li>
11541 * <li><b>scope</b> {Object} (Optional) The scope in which to execute the callbacks: The "this" object
11542 * for the callback function. Defaults to the browser window.</li>
11543 * <li><b>form</b> {Object/String} (Optional) A form object or id to pull parameters from.</li>
11544 * <li><b>isUpload</b> {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).</li>
11545 * <li><b>headers</b> {Object} (Optional) Request headers to set for the request.</li>
11546 * <li><b>xmlData</b> {Object} (Optional) XML document to use for the post. Note: This will be used instead of
11547 * params for the post data. Any params will be appended to the URL.</li>
11548 * <li><b>disableCaching</b> {Boolean} (Optional) True to add a unique cache-buster param to GET requests.</li>
11550 * @return {Number} transactionId
11552 request : function(o){
11553 if(this.fireEvent("beforerequest", this, o) !== false){
11556 if(typeof p == "function"){
11557 p = p.call(o.scope||window, o);
11559 if(typeof p == "object"){
11560 p = Roo.urlEncode(o.params);
11562 if(this.extraParams){
11563 var extras = Roo.urlEncode(this.extraParams);
11564 p = p ? (p + '&' + extras) : extras;
11567 var url = o.url || this.url;
11568 if(typeof url == 'function'){
11569 url = url.call(o.scope||window, o);
11573 var form = Roo.getDom(o.form);
11574 url = url || form.action;
11576 var enctype = form.getAttribute("enctype");
11577 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
11578 return this.doFormUpload(o, p, url);
11580 var f = Roo.lib.Ajax.serializeForm(form);
11581 p = p ? (p + '&' + f) : f;
11584 var hs = o.headers;
11585 if(this.defaultHeaders){
11586 hs = Roo.apply(hs || {}, this.defaultHeaders);
11593 success: this.handleResponse,
11594 failure: this.handleFailure,
11596 argument: {options: o},
11597 timeout : o.timeout || this.timeout
11600 var method = o.method||this.method||(p ? "POST" : "GET");
11602 if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
11603 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
11606 if(typeof o.autoAbort == 'boolean'){ // options gets top priority
11610 }else if(this.autoAbort !== false){
11614 if((method == 'GET' && p) || o.xmlData){
11615 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
11618 this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
11619 return this.transId;
11621 Roo.callback(o.callback, o.scope, [o, null, null]);
11627 * Determine whether this object has a request outstanding.
11628 * @param {Number} transactionId (Optional) defaults to the last transaction
11629 * @return {Boolean} True if there is an outstanding request.
11631 isLoading : function(transId){
11633 return Roo.lib.Ajax.isCallInProgress(transId);
11635 return this.transId ? true : false;
11640 * Aborts any outstanding request.
11641 * @param {Number} transactionId (Optional) defaults to the last transaction
11643 abort : function(transId){
11644 if(transId || this.isLoading()){
11645 Roo.lib.Ajax.abort(transId || this.transId);
11650 handleResponse : function(response){
11651 this.transId = false;
11652 var options = response.argument.options;
11653 response.argument = options ? options.argument : null;
11654 this.fireEvent("requestcomplete", this, response, options);
11655 Roo.callback(options.success, options.scope, [response, options]);
11656 Roo.callback(options.callback, options.scope, [options, true, response]);
11660 handleFailure : function(response, e){
11661 this.transId = false;
11662 var options = response.argument.options;
11663 response.argument = options ? options.argument : null;
11664 this.fireEvent("requestexception", this, response, options, e);
11665 Roo.callback(options.failure, options.scope, [response, options]);
11666 Roo.callback(options.callback, options.scope, [options, false, response]);
11670 doFormUpload : function(o, ps, url){
11672 var frame = document.createElement('iframe');
11675 frame.className = 'x-hidden';
11677 frame.src = Roo.SSL_SECURE_URL;
11679 document.body.appendChild(frame);
11682 document.frames[id].name = id;
11685 var form = Roo.getDom(o.form);
11687 form.method = 'POST';
11688 form.enctype = form.encoding = 'multipart/form-data';
11694 if(ps){ // add dynamic params
11696 ps = Roo.urlDecode(ps, false);
11698 if(ps.hasOwnProperty(k)){
11699 hd = document.createElement('input');
11700 hd.type = 'hidden';
11703 form.appendChild(hd);
11710 var r = { // bogus response object
11715 r.argument = o ? o.argument : null;
11720 doc = frame.contentWindow.document;
11722 doc = (frame.contentDocument || window.frames[id].document);
11724 if(doc && doc.body){
11725 r.responseText = doc.body.innerHTML;
11727 if(doc && doc.XMLDocument){
11728 r.responseXML = doc.XMLDocument;
11730 r.responseXML = doc;
11737 Roo.EventManager.removeListener(frame, 'load', cb, this);
11739 this.fireEvent("requestcomplete", this, r, o);
11740 Roo.callback(o.success, o.scope, [r, o]);
11741 Roo.callback(o.callback, o.scope, [o, true, r]);
11743 setTimeout(function(){document.body.removeChild(frame);}, 100);
11746 Roo.EventManager.on(frame, 'load', cb, this);
11749 if(hiddens){ // remove dynamic params
11750 for(var i = 0, len = hiddens.length; i < len; i++){
11751 form.removeChild(hiddens[i]);
11758 * Ext JS Library 1.1.1
11759 * Copyright(c) 2006-2007, Ext JS, LLC.
11761 * Originally Released Under LGPL - original licence link has changed is not relivant.
11764 * <script type="text/javascript">
11768 * Global Ajax request class.
11771 * @extends Roo.data.Connection
11774 * @cfg {String} url The default URL to be used for requests to the server. (defaults to undefined)
11775 * @cfg {Object} extraParams An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
11776 * @cfg {Object} defaultHeaders An object containing request headers which are added to each request made by this object. (defaults to undefined)
11777 * @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)
11778 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11779 * @cfg {Boolean} autoAbort (Optional) Whether a new request should abort any pending requests. (defaults to false)
11780 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11782 Roo.Ajax = new Roo.data.Connection({
11791 * Serialize the passed form into a url encoded string
11793 * @param {String/HTMLElement} form
11796 serializeForm : function(form){
11797 return Roo.lib.Ajax.serializeForm(form);
11801 * Ext JS Library 1.1.1
11802 * Copyright(c) 2006-2007, Ext JS, LLC.
11804 * Originally Released Under LGPL - original licence link has changed is not relivant.
11807 * <script type="text/javascript">
11812 * @class Roo.UpdateManager
11813 * @extends Roo.util.Observable
11814 * Provides AJAX-style update for Element object.<br><br>
11817 * // Get it from a Roo.Element object
11818 * var el = Roo.get("foo");
11819 * var mgr = el.getUpdateManager();
11820 * mgr.update("http://myserver.com/index.php", "param1=1&param2=2");
11822 * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
11824 * // or directly (returns the same UpdateManager instance)
11825 * var mgr = new Roo.UpdateManager("myElementId");
11826 * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
11827 * mgr.on("update", myFcnNeedsToKnow);
11829 // short handed call directly from the element object
11830 Roo.get("foo").load({
11834 text: "Loading Foo..."
11838 * Create new UpdateManager directly.
11839 * @param {String/HTMLElement/Roo.Element} el The element to update
11840 * @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).
11842 Roo.UpdateManager = function(el, forceNew){
11844 if(!forceNew && el.updateManager){
11845 return el.updateManager;
11848 * The Element object
11849 * @type Roo.Element
11853 * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
11856 this.defaultUrl = null;
11860 * @event beforeupdate
11861 * Fired before an update is made, return false from your handler and the update is cancelled.
11862 * @param {Roo.Element} el
11863 * @param {String/Object/Function} url
11864 * @param {String/Object} params
11866 "beforeupdate": true,
11869 * Fired after successful update is made.
11870 * @param {Roo.Element} el
11871 * @param {Object} oResponseObject The response Object
11876 * Fired on update failure.
11877 * @param {Roo.Element} el
11878 * @param {Object} oResponseObject The response Object
11882 var d = Roo.UpdateManager.defaults;
11884 * Blank page URL to use with SSL file uploads (Defaults to Roo.UpdateManager.defaults.sslBlankUrl or "about:blank").
11887 this.sslBlankUrl = d.sslBlankUrl;
11889 * Whether to append unique parameter on get request to disable caching (Defaults to Roo.UpdateManager.defaults.disableCaching or false).
11892 this.disableCaching = d.disableCaching;
11894 * Text for loading indicator (Defaults to Roo.UpdateManager.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>').
11897 this.indicatorText = d.indicatorText;
11899 * Whether to show indicatorText when loading (Defaults to Roo.UpdateManager.defaults.showLoadIndicator or true).
11902 this.showLoadIndicator = d.showLoadIndicator;
11904 * Timeout for requests or form posts in seconds (Defaults to Roo.UpdateManager.defaults.timeout or 30 seconds).
11907 this.timeout = d.timeout;
11910 * True to process scripts in the output (Defaults to Roo.UpdateManager.defaults.loadScripts (false)).
11913 this.loadScripts = d.loadScripts;
11916 * Transaction object of current executing transaction
11918 this.transaction = null;
11923 this.autoRefreshProcId = null;
11925 * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
11928 this.refreshDelegate = this.refresh.createDelegate(this);
11930 * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
11933 this.updateDelegate = this.update.createDelegate(this);
11935 * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
11938 this.formUpdateDelegate = this.formUpdate.createDelegate(this);
11942 this.successDelegate = this.processSuccess.createDelegate(this);
11946 this.failureDelegate = this.processFailure.createDelegate(this);
11948 if(!this.renderer){
11950 * The renderer for this UpdateManager. Defaults to {@link Roo.UpdateManager.BasicRenderer}.
11952 this.renderer = new Roo.UpdateManager.BasicRenderer();
11955 Roo.UpdateManager.superclass.constructor.call(this);
11958 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
11960 * Get the Element this UpdateManager is bound to
11961 * @return {Roo.Element} The element
11963 getEl : function(){
11967 * Performs an async request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET.
11968 * @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:
11971 url: "your-url.php",<br/>
11972 params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
11973 callback: yourFunction,<br/>
11974 scope: yourObject, //(optional scope) <br/>
11975 discardUrl: false, <br/>
11976 nocache: false,<br/>
11977 text: "Loading...",<br/>
11979 scripts: false<br/>
11982 * The only required property is url. The optional properties nocache, text and scripts
11983 * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this UpdateManager instance.
11984 * @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}
11985 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
11986 * @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.
11988 update : function(url, params, callback, discardUrl){
11989 if(this.fireEvent("beforeupdate", this.el, url, params) !== false){
11990 var method = this.method,
11992 if(typeof url == "object"){ // must be config object
11995 params = params || cfg.params;
11996 callback = callback || cfg.callback;
11997 discardUrl = discardUrl || cfg.discardUrl;
11998 if(callback && cfg.scope){
11999 callback = callback.createDelegate(cfg.scope);
12001 if(typeof cfg.method != "undefined"){method = cfg.method;};
12002 if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
12003 if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
12004 if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
12005 if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
12007 this.showLoading();
12009 this.defaultUrl = url;
12011 if(typeof url == "function"){
12012 url = url.call(this);
12015 method = method || (params ? "POST" : "GET");
12016 if(method == "GET"){
12017 url = this.prepareUrl(url);
12020 var o = Roo.apply(cfg ||{}, {
12023 success: this.successDelegate,
12024 failure: this.failureDelegate,
12025 callback: undefined,
12026 timeout: (this.timeout*1000),
12027 argument: {"url": url, "form": null, "callback": callback, "params": params}
12029 Roo.log("updated manager called with timeout of " + o.timeout);
12030 this.transaction = Roo.Ajax.request(o);
12035 * 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.
12036 * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.
12037 * @param {String/HTMLElement} form The form Id or form element
12038 * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
12039 * @param {Boolean} reset (optional) Whether to try to reset the form after the update
12040 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
12042 formUpdate : function(form, url, reset, callback){
12043 if(this.fireEvent("beforeupdate", this.el, form, url) !== false){
12044 if(typeof url == "function"){
12045 url = url.call(this);
12047 form = Roo.getDom(form);
12048 this.transaction = Roo.Ajax.request({
12051 success: this.successDelegate,
12052 failure: this.failureDelegate,
12053 timeout: (this.timeout*1000),
12054 argument: {"url": url, "form": form, "callback": callback, "reset": reset}
12056 this.showLoading.defer(1, this);
12061 * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
12062 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
12064 refresh : function(callback){
12065 if(this.defaultUrl == null){
12068 this.update(this.defaultUrl, null, callback, true);
12072 * Set this element to auto refresh.
12073 * @param {Number} interval How often to update (in seconds).
12074 * @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)
12075 * @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}
12076 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
12077 * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
12079 startAutoRefresh : function(interval, url, params, callback, refreshNow){
12081 this.update(url || this.defaultUrl, params, callback, true);
12083 if(this.autoRefreshProcId){
12084 clearInterval(this.autoRefreshProcId);
12086 this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);
12090 * Stop auto refresh on this element.
12092 stopAutoRefresh : function(){
12093 if(this.autoRefreshProcId){
12094 clearInterval(this.autoRefreshProcId);
12095 delete this.autoRefreshProcId;
12099 isAutoRefreshing : function(){
12100 return this.autoRefreshProcId ? true : false;
12103 * Called to update the element to "Loading" state. Override to perform custom action.
12105 showLoading : function(){
12106 if(this.showLoadIndicator){
12107 this.el.update(this.indicatorText);
12112 * Adds unique parameter to query string if disableCaching = true
12115 prepareUrl : function(url){
12116 if(this.disableCaching){
12117 var append = "_dc=" + (new Date().getTime());
12118 if(url.indexOf("?") !== -1){
12119 url += "&" + append;
12121 url += "?" + append;
12130 processSuccess : function(response){
12131 this.transaction = null;
12132 if(response.argument.form && response.argument.reset){
12133 try{ // put in try/catch since some older FF releases had problems with this
12134 response.argument.form.reset();
12137 if(this.loadScripts){
12138 this.renderer.render(this.el, response, this,
12139 this.updateComplete.createDelegate(this, [response]));
12141 this.renderer.render(this.el, response, this);
12142 this.updateComplete(response);
12146 updateComplete : function(response){
12147 this.fireEvent("update", this.el, response);
12148 if(typeof response.argument.callback == "function"){
12149 response.argument.callback(this.el, true, response);
12156 processFailure : function(response){
12157 this.transaction = null;
12158 this.fireEvent("failure", this.el, response);
12159 if(typeof response.argument.callback == "function"){
12160 response.argument.callback(this.el, false, response);
12165 * Set the content renderer for this UpdateManager. See {@link Roo.UpdateManager.BasicRenderer#render} for more details.
12166 * @param {Object} renderer The object implementing the render() method
12168 setRenderer : function(renderer){
12169 this.renderer = renderer;
12172 getRenderer : function(){
12173 return this.renderer;
12177 * Set the defaultUrl used for updates
12178 * @param {String/Function} defaultUrl The url or a function to call to get the url
12180 setDefaultUrl : function(defaultUrl){
12181 this.defaultUrl = defaultUrl;
12185 * Aborts the executing transaction
12187 abort : function(){
12188 if(this.transaction){
12189 Roo.Ajax.abort(this.transaction);
12194 * Returns true if an update is in progress
12195 * @return {Boolean}
12197 isUpdating : function(){
12198 if(this.transaction){
12199 return Roo.Ajax.isLoading(this.transaction);
12206 * @class Roo.UpdateManager.defaults
12207 * @static (not really - but it helps the doc tool)
12208 * The defaults collection enables customizing the default properties of UpdateManager
12210 Roo.UpdateManager.defaults = {
12212 * Timeout for requests or form posts in seconds (Defaults 30 seconds).
12218 * True to process scripts by default (Defaults to false).
12221 loadScripts : false,
12224 * Blank page URL to use with SSL file uploads (Defaults to "javascript:false").
12227 sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
12229 * Whether to append unique parameter on get request to disable caching (Defaults to false).
12232 disableCaching : false,
12234 * Whether to show indicatorText when loading (Defaults to true).
12237 showLoadIndicator : true,
12239 * Text for loading indicator (Defaults to '<div class="loading-indicator">Loading...</div>').
12242 indicatorText : '<div class="loading-indicator">Loading...</div>'
12246 * Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}).
12248 * <pre><code>Roo.UpdateManager.updateElement("my-div", "stuff.php");</code></pre>
12249 * @param {String/HTMLElement/Roo.Element} el The element to update
12250 * @param {String} url The url
12251 * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
12252 * @param {Object} options (optional) A config object with any of the UpdateManager properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."}
12255 * @member Roo.UpdateManager
12257 Roo.UpdateManager.updateElement = function(el, url, params, options){
12258 var um = Roo.get(el, true).getUpdateManager();
12259 Roo.apply(um, options);
12260 um.update(url, params, options ? options.callback : null);
12262 // alias for backwards compat
12263 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
12265 * @class Roo.UpdateManager.BasicRenderer
12266 * Default Content renderer. Updates the elements innerHTML with the responseText.
12268 Roo.UpdateManager.BasicRenderer = function(){};
12270 Roo.UpdateManager.BasicRenderer.prototype = {
12272 * This is called when the transaction is completed and it's time to update the element - The BasicRenderer
12273 * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),
12274 * create an object with a "render(el, response)" method and pass it to setRenderer on the UpdateManager.
12275 * @param {Roo.Element} el The element being rendered
12276 * @param {Object} response The YUI Connect response object
12277 * @param {UpdateManager} updateManager The calling update manager
12278 * @param {Function} callback A callback that will need to be called if loadScripts is true on the UpdateManager
12280 render : function(el, response, updateManager, callback){
12281 el.update(response.responseText, updateManager.loadScripts, callback);
12287 * (c)) Alan Knowles
12293 * @class Roo.DomTemplate
12294 * @extends Roo.Template
12295 * An effort at a dom based template engine..
12297 * Similar to XTemplate, except it uses dom parsing to create the template..
12299 * Supported features:
12304 {a_variable} - output encoded.
12305 {a_variable.format:("Y-m-d")} - call a method on the variable
12306 {a_variable:raw} - unencoded output
12307 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
12308 {a_variable:this.method_on_template(...)} - call a method on the template object.
12313 <div roo-for="a_variable or condition.."></div>
12314 <div roo-if="a_variable or condition"></div>
12315 <div roo-exec="some javascript"></div>
12316 <div roo-name="named_template"></div>
12321 Roo.DomTemplate = function()
12323 Roo.DomTemplate.superclass.constructor.apply(this, arguments);
12330 Roo.extend(Roo.DomTemplate, Roo.Template, {
12332 * id counter for sub templates.
12336 * flag to indicate if dom parser is inside a pre,
12337 * it will strip whitespace if not.
12342 * The various sub templates
12350 * basic tag replacing syntax
12353 * // you can fake an object call by doing this
12357 re : /(\{|\%7B)([\w-\.]+)(?:\:([\w\.]*)(?:\(([^)]*?)?\))?)?(\}|\%7D)/g,
12358 //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
12360 iterChild : function (node, method) {
12362 var oldPre = this.inPre;
12363 if (node.tagName == 'PRE') {
12366 for( var i = 0; i < node.childNodes.length; i++) {
12367 method.call(this, node.childNodes[i]);
12369 this.inPre = oldPre;
12375 * compile the template
12377 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
12380 compile: function()
12384 // covert the html into DOM...
12388 doc = document.implementation.createHTMLDocument("");
12389 doc.documentElement.innerHTML = this.html ;
12390 div = doc.documentElement;
12392 // old IE... - nasty -- it causes all sorts of issues.. with
12393 // images getting pulled from server..
12394 div = document.createElement('div');
12395 div.innerHTML = this.html;
12397 //doc.documentElement.innerHTML = htmlBody
12403 this.iterChild(div, function(n) {_t.compileNode(n, true); });
12405 var tpls = this.tpls;
12407 // create a top level template from the snippet..
12409 //Roo.log(div.innerHTML);
12416 body : div.innerHTML,
12429 Roo.each(tpls, function(tp){
12430 this.compileTpl(tp);
12431 this.tpls[tp.id] = tp;
12434 this.master = tpls[0];
12440 compileNode : function(node, istop) {
12445 // skip anything not a tag..
12446 if (node.nodeType != 1) {
12447 if (node.nodeType == 3 && !this.inPre) {
12448 // reduce white space..
12449 node.nodeValue = node.nodeValue.replace(/\s+/g, ' ');
12472 case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
12473 case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
12474 case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
12475 case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
12481 // just itterate children..
12482 this.iterChild(node,this.compileNode);
12485 tpl.uid = this.id++;
12486 tpl.value = node.getAttribute('roo-' + tpl.attr);
12487 node.removeAttribute('roo-'+ tpl.attr);
12488 if (tpl.attr != 'name') {
12489 var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
12490 node.parentNode.replaceChild(placeholder, node);
12493 var placeholder = document.createElement('span');
12494 placeholder.className = 'roo-tpl-' + tpl.value;
12495 node.parentNode.replaceChild(placeholder, node);
12498 // parent now sees '{domtplXXXX}
12499 this.iterChild(node,this.compileNode);
12501 // we should now have node body...
12502 var div = document.createElement('div');
12503 div.appendChild(node);
12505 // this has the unfortunate side effect of converting tagged attributes
12506 // eg. href="{...}" into %7C...%7D
12507 // this has been fixed by searching for those combo's although it's a bit hacky..
12510 tpl.body = div.innerHTML;
12517 switch (tpl.value) {
12518 case '.': tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
12519 case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
12520 default: tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
12525 tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12529 tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
12533 tpl.id = tpl.value; // replace non characters???
12539 this.tpls.push(tpl);
12549 * Compile a segment of the template into a 'sub-template'
12555 compileTpl : function(tpl)
12557 var fm = Roo.util.Format;
12558 var useF = this.disableFormats !== true;
12560 var sep = Roo.isGecko ? "+\n" : ",\n";
12562 var undef = function(str) {
12563 Roo.debug && Roo.log("Property not found :" + str);
12567 //Roo.log(tpl.body);
12571 var fn = function(m, lbrace, name, format, args)
12574 //Roo.log(arguments);
12575 args = args ? args.replace(/\\'/g,"'") : args;
12576 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
12577 if (typeof(format) == 'undefined') {
12578 format = 'htmlEncode';
12580 if (format == 'raw' ) {
12584 if(name.substr(0, 6) == 'domtpl'){
12585 return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
12588 // build an array of options to determine if value is undefined..
12590 // basically get 'xxxx.yyyy' then do
12591 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
12592 // (function () { Roo.log("Property not found"); return ''; })() :
12597 Roo.each(name.split('.'), function(st) {
12598 lookfor += (lookfor.length ? '.': '') + st;
12599 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
12602 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
12605 if(format && useF){
12607 args = args ? ',' + args : "";
12609 if(format.substr(0, 5) != "this."){
12610 format = "fm." + format + '(';
12612 format = 'this.call("'+ format.substr(5) + '", ';
12616 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
12619 if (args && args.length) {
12620 // called with xxyx.yuu:(test,test)
12622 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
12624 // raw.. - :raw modifier..
12625 return "'"+ sep + udef_st + name + ")"+sep+"'";
12629 // branched to use + in gecko and [].join() in others
12631 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
12632 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
12635 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
12636 body.push(tpl.body.replace(/(\r\n|\n)/g,
12637 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
12638 body.push("'].join('');};};");
12639 body = body.join('');
12642 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
12644 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
12651 * same as applyTemplate, except it's done to one of the subTemplates
12652 * when using named templates, you can do:
12654 * var str = pl.applySubTemplate('your-name', values);
12657 * @param {Number} id of the template
12658 * @param {Object} values to apply to template
12659 * @param {Object} parent (normaly the instance of this object)
12661 applySubTemplate : function(id, values, parent)
12665 var t = this.tpls[id];
12669 if(t.ifCall && !t.ifCall.call(this, values, parent)){
12670 Roo.debug && Roo.log('if call on ' + t.value + ' return false');
12674 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
12681 if(t.execCall && t.execCall.call(this, values, parent)){
12685 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12691 var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
12692 parent = t.target ? values : parent;
12693 if(t.forCall && vs instanceof Array){
12695 for(var i = 0, len = vs.length; i < len; i++){
12697 buf[buf.length] = t.compiled.call(this, vs[i], parent);
12699 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12701 //Roo.log(t.compiled);
12705 return buf.join('');
12708 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
12713 return t.compiled.call(this, vs, parent);
12715 Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
12717 //Roo.log(t.compiled);
12725 applyTemplate : function(values){
12726 return this.master.compiled.call(this, values, {});
12727 //var s = this.subs;
12730 apply : function(){
12731 return this.applyTemplate.apply(this, arguments);
12736 Roo.DomTemplate.from = function(el){
12737 el = Roo.getDom(el);
12738 return new Roo.Domtemplate(el.value || el.innerHTML);
12741 * Ext JS Library 1.1.1
12742 * Copyright(c) 2006-2007, Ext JS, LLC.
12744 * Originally Released Under LGPL - original licence link has changed is not relivant.
12747 * <script type="text/javascript">
12751 * @class Roo.util.DelayedTask
12752 * Provides a convenient method of performing setTimeout where a new
12753 * timeout cancels the old timeout. An example would be performing validation on a keypress.
12754 * You can use this class to buffer
12755 * the keypress events for a certain number of milliseconds, and perform only if they stop
12756 * for that amount of time.
12757 * @constructor The parameters to this constructor serve as defaults and are not required.
12758 * @param {Function} fn (optional) The default function to timeout
12759 * @param {Object} scope (optional) The default scope of that timeout
12760 * @param {Array} args (optional) The default Array of arguments
12762 Roo.util.DelayedTask = function(fn, scope, args){
12763 var id = null, d, t;
12765 var call = function(){
12766 var now = new Date().getTime();
12770 fn.apply(scope, args || []);
12774 * Cancels any pending timeout and queues a new one
12775 * @param {Number} delay The milliseconds to delay
12776 * @param {Function} newFn (optional) Overrides function passed to constructor
12777 * @param {Object} newScope (optional) Overrides scope passed to constructor
12778 * @param {Array} newArgs (optional) Overrides args passed to constructor
12780 this.delay = function(delay, newFn, newScope, newArgs){
12781 if(id && delay != d){
12785 t = new Date().getTime();
12787 scope = newScope || scope;
12788 args = newArgs || args;
12790 id = setInterval(call, d);
12795 * Cancel the last queued timeout
12797 this.cancel = function(){
12805 * Ext JS Library 1.1.1
12806 * Copyright(c) 2006-2007, Ext JS, LLC.
12808 * Originally Released Under LGPL - original licence link has changed is not relivant.
12811 * <script type="text/javascript">
12815 Roo.util.TaskRunner = function(interval){
12816 interval = interval || 10;
12817 var tasks = [], removeQueue = [];
12819 var running = false;
12821 var stopThread = function(){
12827 var startThread = function(){
12830 id = setInterval(runTasks, interval);
12834 var removeTask = function(task){
12835 removeQueue.push(task);
12841 var runTasks = function(){
12842 if(removeQueue.length > 0){
12843 for(var i = 0, len = removeQueue.length; i < len; i++){
12844 tasks.remove(removeQueue[i]);
12847 if(tasks.length < 1){
12852 var now = new Date().getTime();
12853 for(var i = 0, len = tasks.length; i < len; ++i){
12855 var itime = now - t.taskRunTime;
12856 if(t.interval <= itime){
12857 var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
12858 t.taskRunTime = now;
12859 if(rt === false || t.taskRunCount === t.repeat){
12864 if(t.duration && t.duration <= (now - t.taskStartTime)){
12871 * Queues a new task.
12872 * @param {Object} task
12874 this.start = function(task){
12876 task.taskStartTime = new Date().getTime();
12877 task.taskRunTime = 0;
12878 task.taskRunCount = 0;
12883 this.stop = function(task){
12888 this.stopAll = function(){
12890 for(var i = 0, len = tasks.length; i < len; i++){
12891 if(tasks[i].onStop){
12900 Roo.TaskMgr = new Roo.util.TaskRunner();/*
12902 * Ext JS Library 1.1.1
12903 * Copyright(c) 2006-2007, Ext JS, LLC.
12905 * Originally Released Under LGPL - original licence link has changed is not relivant.
12908 * <script type="text/javascript">
12913 * @class Roo.util.MixedCollection
12914 * @extends Roo.util.Observable
12915 * A Collection class that maintains both numeric indexes and keys and exposes events.
12917 * @param {Boolean} allowFunctions True if the addAll function should add function references to the
12918 * collection (defaults to false)
12919 * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
12920 * and return the key value for that item. This is used when available to look up the key on items that
12921 * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
12922 * equivalent to providing an implementation for the {@link #getKey} method.
12924 Roo.util.MixedCollection = function(allowFunctions, keyFn){
12932 * Fires when the collection is cleared.
12937 * Fires when an item is added to the collection.
12938 * @param {Number} index The index at which the item was added.
12939 * @param {Object} o The item added.
12940 * @param {String} key The key associated with the added item.
12945 * Fires when an item is replaced in the collection.
12946 * @param {String} key he key associated with the new added.
12947 * @param {Object} old The item being replaced.
12948 * @param {Object} new The new item.
12953 * Fires when an item is removed from the collection.
12954 * @param {Object} o The item being removed.
12955 * @param {String} key (optional) The key associated with the removed item.
12960 this.allowFunctions = allowFunctions === true;
12962 this.getKey = keyFn;
12964 Roo.util.MixedCollection.superclass.constructor.call(this);
12967 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
12968 allowFunctions : false,
12971 * Adds an item to the collection.
12972 * @param {String} key The key to associate with the item
12973 * @param {Object} o The item to add.
12974 * @return {Object} The item added.
12976 add : function(key, o){
12977 if(arguments.length == 1){
12979 key = this.getKey(o);
12981 if(typeof key == "undefined" || key === null){
12983 this.items.push(o);
12984 this.keys.push(null);
12986 var old = this.map[key];
12988 return this.replace(key, o);
12991 this.items.push(o);
12993 this.keys.push(key);
12995 this.fireEvent("add", this.length-1, o, key);
13000 * MixedCollection has a generic way to fetch keys if you implement getKey.
13003 var mc = new Roo.util.MixedCollection();
13004 mc.add(someEl.dom.id, someEl);
13005 mc.add(otherEl.dom.id, otherEl);
13009 var mc = new Roo.util.MixedCollection();
13010 mc.getKey = function(el){
13016 // or via the constructor
13017 var mc = new Roo.util.MixedCollection(false, function(el){
13023 * @param o {Object} The item for which to find the key.
13024 * @return {Object} The key for the passed item.
13026 getKey : function(o){
13031 * Replaces an item in the collection.
13032 * @param {String} key The key associated with the item to replace, or the item to replace.
13033 * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate with that key.
13034 * @return {Object} The new item.
13036 replace : function(key, o){
13037 if(arguments.length == 1){
13039 key = this.getKey(o);
13041 var old = this.item(key);
13042 if(typeof key == "undefined" || key === null || typeof old == "undefined"){
13043 return this.add(key, o);
13045 var index = this.indexOfKey(key);
13046 this.items[index] = o;
13048 this.fireEvent("replace", key, old, o);
13053 * Adds all elements of an Array or an Object to the collection.
13054 * @param {Object/Array} objs An Object containing properties which will be added to the collection, or
13055 * an Array of values, each of which are added to the collection.
13057 addAll : function(objs){
13058 if(arguments.length > 1 || objs instanceof Array){
13059 var args = arguments.length > 1 ? arguments : objs;
13060 for(var i = 0, len = args.length; i < len; i++){
13064 for(var key in objs){
13065 if(this.allowFunctions || typeof objs[key] != "function"){
13066 this.add(key, objs[key]);
13073 * Executes the specified function once for every item in the collection, passing each
13074 * item as the first and only parameter. returning false from the function will stop the iteration.
13075 * @param {Function} fn The function to execute for each item.
13076 * @param {Object} scope (optional) The scope in which to execute the function.
13078 each : function(fn, scope){
13079 var items = [].concat(this.items); // each safe for removal
13080 for(var i = 0, len = items.length; i < len; i++){
13081 if(fn.call(scope || items[i], items[i], i, len) === false){
13088 * Executes the specified function once for every key in the collection, passing each
13089 * key, and its associated item as the first two parameters.
13090 * @param {Function} fn The function to execute for each item.
13091 * @param {Object} scope (optional) The scope in which to execute the function.
13093 eachKey : function(fn, scope){
13094 for(var i = 0, len = this.keys.length; i < len; i++){
13095 fn.call(scope || window, this.keys[i], this.items[i], i, len);
13100 * Returns the first item in the collection which elicits a true return value from the
13101 * passed selection function.
13102 * @param {Function} fn The selection function to execute for each item.
13103 * @param {Object} scope (optional) The scope in which to execute the function.
13104 * @return {Object} The first item in the collection which returned true from the selection function.
13106 find : function(fn, scope){
13107 for(var i = 0, len = this.items.length; i < len; i++){
13108 if(fn.call(scope || window, this.items[i], this.keys[i])){
13109 return this.items[i];
13116 * Inserts an item at the specified index in the collection.
13117 * @param {Number} index The index to insert the item at.
13118 * @param {String} key The key to associate with the new item, or the item itself.
13119 * @param {Object} o (optional) If the second parameter was a key, the new item.
13120 * @return {Object} The item inserted.
13122 insert : function(index, key, o){
13123 if(arguments.length == 2){
13125 key = this.getKey(o);
13127 if(index >= this.length){
13128 return this.add(key, o);
13131 this.items.splice(index, 0, o);
13132 if(typeof key != "undefined" && key != null){
13135 this.keys.splice(index, 0, key);
13136 this.fireEvent("add", index, o, key);
13141 * Removed an item from the collection.
13142 * @param {Object} o The item to remove.
13143 * @return {Object} The item removed.
13145 remove : function(o){
13146 return this.removeAt(this.indexOf(o));
13150 * Remove an item from a specified index in the collection.
13151 * @param {Number} index The index within the collection of the item to remove.
13153 removeAt : function(index){
13154 if(index < this.length && index >= 0){
13156 var o = this.items[index];
13157 this.items.splice(index, 1);
13158 var key = this.keys[index];
13159 if(typeof key != "undefined"){
13160 delete this.map[key];
13162 this.keys.splice(index, 1);
13163 this.fireEvent("remove", o, key);
13168 * Removed an item associated with the passed key fom the collection.
13169 * @param {String} key The key of the item to remove.
13171 removeKey : function(key){
13172 return this.removeAt(this.indexOfKey(key));
13176 * Returns the number of items in the collection.
13177 * @return {Number} the number of items in the collection.
13179 getCount : function(){
13180 return this.length;
13184 * Returns index within the collection of the passed Object.
13185 * @param {Object} o The item to find the index of.
13186 * @return {Number} index of the item.
13188 indexOf : function(o){
13189 if(!this.items.indexOf){
13190 for(var i = 0, len = this.items.length; i < len; i++){
13191 if(this.items[i] == o) {
13197 return this.items.indexOf(o);
13202 * Returns index within the collection of the passed key.
13203 * @param {String} key The key to find the index of.
13204 * @return {Number} index of the key.
13206 indexOfKey : function(key){
13207 if(!this.keys.indexOf){
13208 for(var i = 0, len = this.keys.length; i < len; i++){
13209 if(this.keys[i] == key) {
13215 return this.keys.indexOf(key);
13220 * Returns the item associated with the passed key OR index. Key has priority over index.
13221 * @param {String/Number} key The key or index of the item.
13222 * @return {Object} The item associated with the passed key.
13224 item : function(key){
13225 var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key];
13226 return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
13230 * Returns the item at the specified index.
13231 * @param {Number} index The index of the item.
13234 itemAt : function(index){
13235 return this.items[index];
13239 * Returns the item associated with the passed key.
13240 * @param {String/Number} key The key of the item.
13241 * @return {Object} The item associated with the passed key.
13243 key : function(key){
13244 return this.map[key];
13248 * Returns true if the collection contains the passed Object as an item.
13249 * @param {Object} o The Object to look for in the collection.
13250 * @return {Boolean} True if the collection contains the Object as an item.
13252 contains : function(o){
13253 return this.indexOf(o) != -1;
13257 * Returns true if the collection contains the passed Object as a key.
13258 * @param {String} key The key to look for in the collection.
13259 * @return {Boolean} True if the collection contains the Object as a key.
13261 containsKey : function(key){
13262 return typeof this.map[key] != "undefined";
13266 * Removes all items from the collection.
13268 clear : function(){
13273 this.fireEvent("clear");
13277 * Returns the first item in the collection.
13278 * @return {Object} the first item in the collection..
13280 first : function(){
13281 return this.items[0];
13285 * Returns the last item in the collection.
13286 * @return {Object} the last item in the collection..
13289 return this.items[this.length-1];
13292 _sort : function(property, dir, fn){
13293 var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1;
13294 fn = fn || function(a, b){
13297 var c = [], k = this.keys, items = this.items;
13298 for(var i = 0, len = items.length; i < len; i++){
13299 c[c.length] = {key: k[i], value: items[i], index: i};
13301 c.sort(function(a, b){
13302 var v = fn(a[property], b[property]) * dsc;
13304 v = (a.index < b.index ? -1 : 1);
13308 for(var i = 0, len = c.length; i < len; i++){
13309 items[i] = c[i].value;
13312 this.fireEvent("sort", this);
13316 * Sorts this collection with the passed comparison function
13317 * @param {String} direction (optional) "ASC" or "DESC"
13318 * @param {Function} fn (optional) comparison function
13320 sort : function(dir, fn){
13321 this._sort("value", dir, fn);
13325 * Sorts this collection by keys
13326 * @param {String} direction (optional) "ASC" or "DESC"
13327 * @param {Function} fn (optional) a comparison function (defaults to case insensitive string)
13329 keySort : function(dir, fn){
13330 this._sort("key", dir, fn || function(a, b){
13331 return String(a).toUpperCase()-String(b).toUpperCase();
13336 * Returns a range of items in this collection
13337 * @param {Number} startIndex (optional) defaults to 0
13338 * @param {Number} endIndex (optional) default to the last item
13339 * @return {Array} An array of items
13341 getRange : function(start, end){
13342 var items = this.items;
13343 if(items.length < 1){
13346 start = start || 0;
13347 end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1);
13350 for(var i = start; i <= end; i++) {
13351 r[r.length] = items[i];
13354 for(var i = start; i >= end; i--) {
13355 r[r.length] = items[i];
13362 * Filter the <i>objects</i> in this collection by a specific property.
13363 * Returns a new collection that has been filtered.
13364 * @param {String} property A property on your objects
13365 * @param {String/RegExp} value Either string that the property values
13366 * should start with or a RegExp to test against the property
13367 * @return {MixedCollection} The new filtered collection
13369 filter : function(property, value){
13370 if(!value.exec){ // not a regex
13371 value = String(value);
13372 if(value.length == 0){
13373 return this.clone();
13375 value = new RegExp("^" + Roo.escapeRe(value), "i");
13377 return this.filterBy(function(o){
13378 return o && value.test(o[property]);
13383 * Filter by a function. * Returns a new collection that has been filtered.
13384 * The passed function will be called with each
13385 * object in the collection. If the function returns true, the value is included
13386 * otherwise it is filtered.
13387 * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
13388 * @param {Object} scope (optional) The scope of the function (defaults to this)
13389 * @return {MixedCollection} The new filtered collection
13391 filterBy : function(fn, scope){
13392 var r = new Roo.util.MixedCollection();
13393 r.getKey = this.getKey;
13394 var k = this.keys, it = this.items;
13395 for(var i = 0, len = it.length; i < len; i++){
13396 if(fn.call(scope||this, it[i], k[i])){
13397 r.add(k[i], it[i]);
13404 * Creates a duplicate of this collection
13405 * @return {MixedCollection}
13407 clone : function(){
13408 var r = new Roo.util.MixedCollection();
13409 var k = this.keys, it = this.items;
13410 for(var i = 0, len = it.length; i < len; i++){
13411 r.add(k[i], it[i]);
13413 r.getKey = this.getKey;
13418 * Returns the item associated with the passed key or index.
13420 * @param {String/Number} key The key or index of the item.
13421 * @return {Object} The item associated with the passed key.
13423 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;/*
13425 * Ext JS Library 1.1.1
13426 * Copyright(c) 2006-2007, Ext JS, LLC.
13428 * Originally Released Under LGPL - original licence link has changed is not relivant.
13431 * <script type="text/javascript">
13434 * @class Roo.util.JSON
13435 * Modified version of Douglas Crockford"s json.js that doesn"t
13436 * mess with the Object prototype
13437 * http://www.json.org/js.html
13440 Roo.util.JSON = new (function(){
13441 var useHasOwn = {}.hasOwnProperty ? true : false;
13443 // crashes Safari in some instances
13444 //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
13446 var pad = function(n) {
13447 return n < 10 ? "0" + n : n;
13460 var encodeString = function(s){
13461 if (/["\\\x00-\x1f]/.test(s)) {
13462 return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
13467 c = b.charCodeAt();
13469 Math.floor(c / 16).toString(16) +
13470 (c % 16).toString(16);
13473 return '"' + s + '"';
13476 var encodeArray = function(o){
13477 var a = ["["], b, i, l = o.length, v;
13478 for (i = 0; i < l; i += 1) {
13480 switch (typeof v) {
13489 a.push(v === null ? "null" : Roo.util.JSON.encode(v));
13497 var encodeDate = function(o){
13498 return '"' + o.getFullYear() + "-" +
13499 pad(o.getMonth() + 1) + "-" +
13500 pad(o.getDate()) + "T" +
13501 pad(o.getHours()) + ":" +
13502 pad(o.getMinutes()) + ":" +
13503 pad(o.getSeconds()) + '"';
13507 * Encodes an Object, Array or other value
13508 * @param {Mixed} o The variable to encode
13509 * @return {String} The JSON string
13511 this.encode = function(o)
13513 // should this be extended to fully wrap stringify..
13515 if(typeof o == "undefined" || o === null){
13517 }else if(o instanceof Array){
13518 return encodeArray(o);
13519 }else if(o instanceof Date){
13520 return encodeDate(o);
13521 }else if(typeof o == "string"){
13522 return encodeString(o);
13523 }else if(typeof o == "number"){
13524 return isFinite(o) ? String(o) : "null";
13525 }else if(typeof o == "boolean"){
13528 var a = ["{"], b, i, v;
13530 if(!useHasOwn || o.hasOwnProperty(i)) {
13532 switch (typeof v) {
13541 a.push(this.encode(i), ":",
13542 v === null ? "null" : this.encode(v));
13553 * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
13554 * @param {String} json The JSON string
13555 * @return {Object} The resulting object
13557 this.decode = function(json){
13559 return /** eval:var:json */ eval("(" + json + ')');
13563 * Shorthand for {@link Roo.util.JSON#encode}
13564 * @member Roo encode
13566 Roo.encode = typeof(JSON) != 'undefined' && JSON.stringify ? JSON.stringify : Roo.util.JSON.encode;
13568 * Shorthand for {@link Roo.util.JSON#decode}
13569 * @member Roo decode
13571 Roo.decode = typeof(JSON) != 'undefined' && JSON.parse ? JSON.parse : Roo.util.JSON.decode;
13574 * Ext JS Library 1.1.1
13575 * Copyright(c) 2006-2007, Ext JS, LLC.
13577 * Originally Released Under LGPL - original licence link has changed is not relivant.
13580 * <script type="text/javascript">
13584 * @class Roo.util.Format
13585 * Reusable data formatting functions
13588 Roo.util.Format = function(){
13589 var trimRe = /^\s+|\s+$/g;
13592 * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
13593 * @param {String} value The string to truncate
13594 * @param {Number} length The maximum length to allow before truncating
13595 * @return {String} The converted text
13597 ellipsis : function(value, len){
13598 if(value && value.length > len){
13599 return value.substr(0, len-3)+"...";
13605 * Checks a reference and converts it to empty string if it is undefined
13606 * @param {Mixed} value Reference to check
13607 * @return {Mixed} Empty string if converted, otherwise the original value
13609 undef : function(value){
13610 return typeof value != "undefined" ? value : "";
13614 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
13615 * @param {String} value The string to encode
13616 * @return {String} The encoded text
13618 htmlEncode : function(value){
13619 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
13623 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
13624 * @param {String} value The string to decode
13625 * @return {String} The decoded text
13627 htmlDecode : function(value){
13628 return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');
13632 * Trims any whitespace from either side of a string
13633 * @param {String} value The text to trim
13634 * @return {String} The trimmed text
13636 trim : function(value){
13637 return String(value).replace(trimRe, "");
13641 * Returns a substring from within an original string
13642 * @param {String} value The original text
13643 * @param {Number} start The start index of the substring
13644 * @param {Number} length The length of the substring
13645 * @return {String} The substring
13647 substr : function(value, start, length){
13648 return String(value).substr(start, length);
13652 * Converts a string to all lower case letters
13653 * @param {String} value The text to convert
13654 * @return {String} The converted text
13656 lowercase : function(value){
13657 return String(value).toLowerCase();
13661 * Converts a string to all upper case letters
13662 * @param {String} value The text to convert
13663 * @return {String} The converted text
13665 uppercase : function(value){
13666 return String(value).toUpperCase();
13670 * Converts the first character only of a string to upper case
13671 * @param {String} value The text to convert
13672 * @return {String} The converted text
13674 capitalize : function(value){
13675 return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
13679 call : function(value, fn){
13680 if(arguments.length > 2){
13681 var args = Array.prototype.slice.call(arguments, 2);
13682 args.unshift(value);
13684 return /** eval:var:value */ eval(fn).apply(window, args);
13686 /** eval:var:value */
13687 return /** eval:var:value */ eval(fn).call(window, value);
13693 * safer version of Math.toFixed..??/
13694 * @param {Number/String} value The numeric value to format
13695 * @param {Number/String} value Decimal places
13696 * @return {String} The formatted currency string
13698 toFixed : function(v, n)
13700 // why not use to fixed - precision is buggered???
13702 return Math.round(v-0);
13704 var fact = Math.pow(10,n+1);
13705 v = (Math.round((v-0)*fact))/fact;
13706 var z = (''+fact).substring(2);
13707 if (v == Math.floor(v)) {
13708 return Math.floor(v) + '.' + z;
13711 // now just padd decimals..
13712 var ps = String(v).split('.');
13713 var fd = (ps[1] + z);
13714 var r = fd.substring(0,n);
13715 var rm = fd.substring(n);
13717 return ps[0] + '.' + r;
13719 r*=1; // turn it into a number;
13721 if (String(r).length != n) {
13724 r = String(r).substring(1); // chop the end off.
13727 return ps[0] + '.' + r;
13732 * Format a number as US currency
13733 * @param {Number/String} value The numeric value to format
13734 * @return {String} The formatted currency string
13736 usMoney : function(v){
13737 return '$' + Roo.util.Format.number(v);
13742 * eventually this should probably emulate php's number_format
13743 * @param {Number/String} value The numeric value to format
13744 * @param {Number} decimals number of decimal places
13745 * @return {String} The formatted currency string
13747 number : function(v,decimals)
13749 // multiply and round.
13750 decimals = typeof(decimals) == 'undefined' ? 2 : decimals;
13751 var mul = Math.pow(10, decimals);
13752 var zero = String(mul).substring(1);
13753 v = (Math.round((v-0)*mul))/mul;
13755 // if it's '0' number.. then
13757 //v = (v == Math.floor(v)) ? v + "." + zero : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
13759 var ps = v.split('.');
13763 var r = /(\d+)(\d{3})/;
13765 while (r.test(whole)) {
13766 whole = whole.replace(r, '$1' + ',' + '$2');
13772 (decimals ? ('.'+ ps[1] + zero.substring(ps[1].length)) : '') :
13773 // does not have decimals
13774 (decimals ? ('.' + zero) : '');
13777 return whole + sub ;
13781 * Parse a value into a formatted date using the specified format pattern.
13782 * @param {Mixed} value The value to format
13783 * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
13784 * @return {String} The formatted date string
13786 date : function(v, format){
13790 if(!(v instanceof Date)){
13791 v = new Date(Date.parse(v));
13793 return v.dateFormat(format || Roo.util.Format.defaults.date);
13797 * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
13798 * @param {String} format Any valid date format string
13799 * @return {Function} The date formatting function
13801 dateRenderer : function(format){
13802 return function(v){
13803 return Roo.util.Format.date(v, format);
13808 stripTagsRE : /<\/?[^>]+>/gi,
13811 * Strips all HTML tags
13812 * @param {Mixed} value The text from which to strip tags
13813 * @return {String} The stripped text
13815 stripTags : function(v){
13816 return !v ? v : String(v).replace(this.stripTagsRE, "");
13820 Roo.util.Format.defaults = {
13824 * Ext JS Library 1.1.1
13825 * Copyright(c) 2006-2007, Ext JS, LLC.
13827 * Originally Released Under LGPL - original licence link has changed is not relivant.
13830 * <script type="text/javascript">
13837 * @class Roo.MasterTemplate
13838 * @extends Roo.Template
13839 * Provides a template that can have child templates. The syntax is:
13841 var t = new Roo.MasterTemplate(
13842 '<select name="{name}">',
13843 '<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
13846 t.add('options', {value: 'foo', text: 'bar'});
13847 // or you can add multiple child elements in one shot
13848 t.addAll('options', [
13849 {value: 'foo', text: 'bar'},
13850 {value: 'foo2', text: 'bar2'},
13851 {value: 'foo3', text: 'bar3'}
13853 // then append, applying the master template values
13854 t.append('my-form', {name: 'my-select'});
13856 * A name attribute for the child template is not required if you have only one child
13857 * template or you want to refer to them by index.
13859 Roo.MasterTemplate = function(){
13860 Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
13861 this.originalHtml = this.html;
13863 var m, re = this.subTemplateRe;
13866 while(m = re.exec(this.html)){
13867 var name = m[1], content = m[2];
13872 tpl : new Roo.Template(content)
13875 st[name] = st[subIndex];
13877 st[subIndex].tpl.compile();
13878 st[subIndex].tpl.call = this.call.createDelegate(this);
13881 this.subCount = subIndex;
13884 Roo.extend(Roo.MasterTemplate, Roo.Template, {
13886 * The regular expression used to match sub templates
13890 subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
13893 * Applies the passed values to a child template.
13894 * @param {String/Number} name (optional) The name or index of the child template
13895 * @param {Array/Object} values The values to be applied to the template
13896 * @return {MasterTemplate} this
13898 add : function(name, values){
13899 if(arguments.length == 1){
13900 values = arguments[0];
13903 var s = this.subs[name];
13904 s.buffer[s.buffer.length] = s.tpl.apply(values);
13909 * Applies all the passed values to a child template.
13910 * @param {String/Number} name (optional) The name or index of the child template
13911 * @param {Array} values The values to be applied to the template, this should be an array of objects.
13912 * @param {Boolean} reset (optional) True to reset the template first
13913 * @return {MasterTemplate} this
13915 fill : function(name, values, reset){
13917 if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
13925 for(var i = 0, len = values.length; i < len; i++){
13926 this.add(name, values[i]);
13932 * Resets the template for reuse
13933 * @return {MasterTemplate} this
13935 reset : function(){
13937 for(var i = 0; i < this.subCount; i++){
13943 applyTemplate : function(values){
13945 var replaceIndex = -1;
13946 this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
13947 return s[++replaceIndex].buffer.join("");
13949 return Roo.MasterTemplate.superclass.applyTemplate.call(this, values);
13952 apply : function(){
13953 return this.applyTemplate.apply(this, arguments);
13956 compile : function(){return this;}
13960 * Alias for fill().
13963 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
13965 * Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
13966 * var tpl = Roo.MasterTemplate.from('element-id');
13967 * @param {String/HTMLElement} el
13968 * @param {Object} config
13971 Roo.MasterTemplate.from = function(el, config){
13972 el = Roo.getDom(el);
13973 return new Roo.MasterTemplate(el.value || el.innerHTML, config || '');
13976 * Ext JS Library 1.1.1
13977 * Copyright(c) 2006-2007, Ext JS, LLC.
13979 * Originally Released Under LGPL - original licence link has changed is not relivant.
13982 * <script type="text/javascript">
13987 * @class Roo.util.CSS
13988 * Utility class for manipulating CSS rules
13991 Roo.util.CSS = function(){
13993 var doc = document;
13995 var camelRe = /(-[a-z])/gi;
13996 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
14000 * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style
14001 * tag and appended to the HEAD of the document.
14002 * @param {String|Object} cssText The text containing the css rules
14003 * @param {String} id An id to add to the stylesheet for later removal
14004 * @return {StyleSheet}
14006 createStyleSheet : function(cssText, id){
14008 var head = doc.getElementsByTagName("head")[0];
14009 var nrules = doc.createElement("style");
14010 nrules.setAttribute("type", "text/css");
14012 nrules.setAttribute("id", id);
14014 if (typeof(cssText) != 'string') {
14015 // support object maps..
14016 // not sure if this a good idea..
14017 // perhaps it should be merged with the general css handling
14018 // and handle js style props.
14019 var cssTextNew = [];
14020 for(var n in cssText) {
14022 for(var k in cssText[n]) {
14023 citems.push( k + ' : ' +cssText[n][k] + ';' );
14025 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
14028 cssText = cssTextNew.join("\n");
14034 head.appendChild(nrules);
14035 ss = nrules.styleSheet;
14036 ss.cssText = cssText;
14039 nrules.appendChild(doc.createTextNode(cssText));
14041 nrules.cssText = cssText;
14043 head.appendChild(nrules);
14044 ss = nrules.styleSheet ? nrules.styleSheet : (nrules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
14046 this.cacheStyleSheet(ss);
14051 * Removes a style or link tag by id
14052 * @param {String} id The id of the tag
14054 removeStyleSheet : function(id){
14055 var existing = doc.getElementById(id);
14057 existing.parentNode.removeChild(existing);
14062 * Dynamically swaps an existing stylesheet reference for a new one
14063 * @param {String} id The id of an existing link tag to remove
14064 * @param {String} url The href of the new stylesheet to include
14066 swapStyleSheet : function(id, url){
14067 this.removeStyleSheet(id);
14068 var ss = doc.createElement("link");
14069 ss.setAttribute("rel", "stylesheet");
14070 ss.setAttribute("type", "text/css");
14071 ss.setAttribute("id", id);
14072 ss.setAttribute("href", url);
14073 doc.getElementsByTagName("head")[0].appendChild(ss);
14077 * Refresh the rule cache if you have dynamically added stylesheets
14078 * @return {Object} An object (hash) of rules indexed by selector
14080 refreshCache : function(){
14081 return this.getRules(true);
14085 cacheStyleSheet : function(stylesheet){
14089 try{// try catch for cross domain access issue
14090 var ssRules = stylesheet.cssRules || stylesheet.rules;
14091 for(var j = ssRules.length-1; j >= 0; --j){
14092 rules[ssRules[j].selectorText] = ssRules[j];
14098 * Gets all css rules for the document
14099 * @param {Boolean} refreshCache true to refresh the internal cache
14100 * @return {Object} An object (hash) of rules indexed by selector
14102 getRules : function(refreshCache){
14103 if(rules == null || refreshCache){
14105 var ds = doc.styleSheets;
14106 for(var i =0, len = ds.length; i < len; i++){
14108 this.cacheStyleSheet(ds[i]);
14116 * Gets an an individual CSS rule by selector(s)
14117 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
14118 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
14119 * @return {CSSRule} The CSS rule or null if one is not found
14121 getRule : function(selector, refreshCache){
14122 var rs = this.getRules(refreshCache);
14123 if(!(selector instanceof Array)){
14124 return rs[selector];
14126 for(var i = 0; i < selector.length; i++){
14127 if(rs[selector[i]]){
14128 return rs[selector[i]];
14136 * Updates a rule property
14137 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
14138 * @param {String} property The css property
14139 * @param {String} value The new value for the property
14140 * @return {Boolean} true If a rule was found and updated
14142 updateRule : function(selector, property, value){
14143 if(!(selector instanceof Array)){
14144 var rule = this.getRule(selector);
14146 rule.style[property.replace(camelRe, camelFn)] = value;
14150 for(var i = 0; i < selector.length; i++){
14151 if(this.updateRule(selector[i], property, value)){
14161 * Ext JS Library 1.1.1
14162 * Copyright(c) 2006-2007, Ext JS, LLC.
14164 * Originally Released Under LGPL - original licence link has changed is not relivant.
14167 * <script type="text/javascript">
14173 * @class Roo.util.ClickRepeater
14174 * @extends Roo.util.Observable
14176 * A wrapper class which can be applied to any element. Fires a "click" event while the
14177 * mouse is pressed. The interval between firings may be specified in the config but
14178 * defaults to 10 milliseconds.
14180 * Optionally, a CSS class may be applied to the element during the time it is pressed.
14182 * @cfg {String/HTMLElement/Element} el The element to act as a button.
14183 * @cfg {Number} delay The initial delay before the repeating event begins firing.
14184 * Similar to an autorepeat key delay.
14185 * @cfg {Number} interval The interval between firings of the "click" event. Default 10 ms.
14186 * @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
14187 * @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
14188 * "interval" and "delay" are ignored. "immediate" is honored.
14189 * @cfg {Boolean} preventDefault True to prevent the default click event
14190 * @cfg {Boolean} stopDefault True to stop the default click event
14193 * 2007-02-02 jvs Original code contributed by Nige "Animal" White
14194 * 2007-02-02 jvs Renamed to ClickRepeater
14195 * 2007-02-03 jvs Modifications for FF Mac and Safari
14198 * @param {String/HTMLElement/Element} el The element to listen on
14199 * @param {Object} config
14201 Roo.util.ClickRepeater = function(el, config)
14203 this.el = Roo.get(el);
14204 this.el.unselectable();
14206 Roo.apply(this, config);
14211 * Fires when the mouse button is depressed.
14212 * @param {Roo.util.ClickRepeater} this
14214 "mousedown" : true,
14217 * Fires on a specified interval during the time the element is pressed.
14218 * @param {Roo.util.ClickRepeater} this
14223 * Fires when the mouse key is released.
14224 * @param {Roo.util.ClickRepeater} this
14229 this.el.on("mousedown", this.handleMouseDown, this);
14230 if(this.preventDefault || this.stopDefault){
14231 this.el.on("click", function(e){
14232 if(this.preventDefault){
14233 e.preventDefault();
14235 if(this.stopDefault){
14241 // allow inline handler
14243 this.on("click", this.handler, this.scope || this);
14246 Roo.util.ClickRepeater.superclass.constructor.call(this);
14249 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
14252 preventDefault : true,
14253 stopDefault : false,
14257 handleMouseDown : function(){
14258 clearTimeout(this.timer);
14260 if(this.pressClass){
14261 this.el.addClass(this.pressClass);
14263 this.mousedownTime = new Date();
14265 Roo.get(document).on("mouseup", this.handleMouseUp, this);
14266 this.el.on("mouseout", this.handleMouseOut, this);
14268 this.fireEvent("mousedown", this);
14269 this.fireEvent("click", this);
14271 this.timer = this.click.defer(this.delay || this.interval, this);
14275 click : function(){
14276 this.fireEvent("click", this);
14277 this.timer = this.click.defer(this.getInterval(), this);
14281 getInterval: function(){
14282 if(!this.accelerate){
14283 return this.interval;
14285 var pressTime = this.mousedownTime.getElapsed();
14286 if(pressTime < 500){
14288 }else if(pressTime < 1700){
14290 }else if(pressTime < 2600){
14292 }else if(pressTime < 3500){
14294 }else if(pressTime < 4400){
14296 }else if(pressTime < 5300){
14298 }else if(pressTime < 6200){
14306 handleMouseOut : function(){
14307 clearTimeout(this.timer);
14308 if(this.pressClass){
14309 this.el.removeClass(this.pressClass);
14311 this.el.on("mouseover", this.handleMouseReturn, this);
14315 handleMouseReturn : function(){
14316 this.el.un("mouseover", this.handleMouseReturn);
14317 if(this.pressClass){
14318 this.el.addClass(this.pressClass);
14324 handleMouseUp : function(){
14325 clearTimeout(this.timer);
14326 this.el.un("mouseover", this.handleMouseReturn);
14327 this.el.un("mouseout", this.handleMouseOut);
14328 Roo.get(document).un("mouseup", this.handleMouseUp);
14329 this.el.removeClass(this.pressClass);
14330 this.fireEvent("mouseup", this);
14334 * Ext JS Library 1.1.1
14335 * Copyright(c) 2006-2007, Ext JS, LLC.
14337 * Originally Released Under LGPL - original licence link has changed is not relivant.
14340 * <script type="text/javascript">
14345 * @class Roo.KeyNav
14346 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
14347 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
14348 * way to implement custom navigation schemes for any UI component.</p>
14349 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
14350 * pageUp, pageDown, del, home, end. Usage:</p>
14352 var nav = new Roo.KeyNav("my-element", {
14353 "left" : function(e){
14354 this.moveLeft(e.ctrlKey);
14356 "right" : function(e){
14357 this.moveRight(e.ctrlKey);
14359 "enter" : function(e){
14366 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14367 * @param {Object} config The config
14369 Roo.KeyNav = function(el, config){
14370 this.el = Roo.get(el);
14371 Roo.apply(this, config);
14372 if(!this.disabled){
14373 this.disabled = true;
14378 Roo.KeyNav.prototype = {
14380 * @cfg {Boolean} disabled
14381 * True to disable this KeyNav instance (defaults to false)
14385 * @cfg {String} defaultEventAction
14386 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
14387 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
14388 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
14390 defaultEventAction: "stopEvent",
14392 * @cfg {Boolean} forceKeyDown
14393 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
14394 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
14395 * handle keydown instead of keypress.
14397 forceKeyDown : false,
14400 prepareEvent : function(e){
14401 var k = e.getKey();
14402 var h = this.keyToHandler[k];
14403 //if(h && this[h]){
14404 // e.stopPropagation();
14406 if(Roo.isSafari && h && k >= 37 && k <= 40){
14412 relay : function(e){
14413 var k = e.getKey();
14414 var h = this.keyToHandler[k];
14416 if(this.doRelay(e, this[h], h) !== true){
14417 e[this.defaultEventAction]();
14423 doRelay : function(e, h, hname){
14424 return h.call(this.scope || this, e);
14427 // possible handlers
14441 // quick lookup hash
14458 * Enable this KeyNav
14460 enable: function(){
14462 // ie won't do special keys on keypress, no one else will repeat keys with keydown
14463 // the EventObject will normalize Safari automatically
14464 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14465 this.el.on("keydown", this.relay, this);
14467 this.el.on("keydown", this.prepareEvent, this);
14468 this.el.on("keypress", this.relay, this);
14470 this.disabled = false;
14475 * Disable this KeyNav
14477 disable: function(){
14478 if(!this.disabled){
14479 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
14480 this.el.un("keydown", this.relay);
14482 this.el.un("keydown", this.prepareEvent);
14483 this.el.un("keypress", this.relay);
14485 this.disabled = true;
14490 * Ext JS Library 1.1.1
14491 * Copyright(c) 2006-2007, Ext JS, LLC.
14493 * Originally Released Under LGPL - original licence link has changed is not relivant.
14496 * <script type="text/javascript">
14501 * @class Roo.KeyMap
14502 * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
14503 * The constructor accepts the same config object as defined by {@link #addBinding}.
14504 * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
14505 * combination it will call the function with this signature (if the match is a multi-key
14506 * combination the callback will still be called only once): (String key, Roo.EventObject e)
14507 * A KeyMap can also handle a string representation of keys.<br />
14510 // map one key by key code
14511 var map = new Roo.KeyMap("my-element", {
14512 key: 13, // or Roo.EventObject.ENTER
14517 // map multiple keys to one action by string
14518 var map = new Roo.KeyMap("my-element", {
14524 // map multiple keys to multiple actions by strings and array of codes
14525 var map = new Roo.KeyMap("my-element", [
14528 fn: function(){ alert("Return was pressed"); }
14531 fn: function(){ alert('a, b or c was pressed'); }
14536 fn: function(){ alert('Control + shift + tab was pressed.'); }
14540 * <b>Note: A KeyMap starts enabled</b>
14542 * @param {String/HTMLElement/Roo.Element} el The element to bind to
14543 * @param {Object} config The config (see {@link #addBinding})
14544 * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
14546 Roo.KeyMap = function(el, config, eventName){
14547 this.el = Roo.get(el);
14548 this.eventName = eventName || "keydown";
14549 this.bindings = [];
14551 this.addBinding(config);
14556 Roo.KeyMap.prototype = {
14558 * True to stop the event from bubbling and prevent the default browser action if the
14559 * key was handled by the KeyMap (defaults to false)
14565 * Add a new binding to this KeyMap. The following config object properties are supported:
14567 Property Type Description
14568 ---------- --------------- ----------------------------------------------------------------------
14569 key String/Array A single keycode or an array of keycodes to handle
14570 shift Boolean True to handle key only when shift is pressed (defaults to false)
14571 ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
14572 alt Boolean True to handle key only when alt is pressed (defaults to false)
14573 fn Function The function to call when KeyMap finds the expected key combination
14574 scope Object The scope of the callback function
14580 var map = new Roo.KeyMap(document, {
14581 key: Roo.EventObject.ENTER,
14586 //Add a new binding to the existing KeyMap later
14594 * @param {Object/Array} config A single KeyMap config or an array of configs
14596 addBinding : function(config){
14597 if(config instanceof Array){
14598 for(var i = 0, len = config.length; i < len; i++){
14599 this.addBinding(config[i]);
14603 var keyCode = config.key,
14604 shift = config.shift,
14605 ctrl = config.ctrl,
14608 scope = config.scope;
14609 if(typeof keyCode == "string"){
14611 var keyString = keyCode.toUpperCase();
14612 for(var j = 0, len = keyString.length; j < len; j++){
14613 ks.push(keyString.charCodeAt(j));
14617 var keyArray = keyCode instanceof Array;
14618 var handler = function(e){
14619 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14620 var k = e.getKey();
14622 for(var i = 0, len = keyCode.length; i < len; i++){
14623 if(keyCode[i] == k){
14624 if(this.stopEvent){
14627 fn.call(scope || window, k, e);
14633 if(this.stopEvent){
14636 fn.call(scope || window, k, e);
14641 this.bindings.push(handler);
14645 * Shorthand for adding a single key listener
14646 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
14647 * following options:
14648 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14649 * @param {Function} fn The function to call
14650 * @param {Object} scope (optional) The scope of the function
14652 on : function(key, fn, scope){
14653 var keyCode, shift, ctrl, alt;
14654 if(typeof key == "object" && !(key instanceof Array)){
14673 handleKeyDown : function(e){
14674 if(this.enabled){ //just in case
14675 var b = this.bindings;
14676 for(var i = 0, len = b.length; i < len; i++){
14677 b[i].call(this, e);
14683 * Returns true if this KeyMap is enabled
14684 * @return {Boolean}
14686 isEnabled : function(){
14687 return this.enabled;
14691 * Enables this KeyMap
14693 enable: function(){
14695 this.el.on(this.eventName, this.handleKeyDown, this);
14696 this.enabled = true;
14701 * Disable this KeyMap
14703 disable: function(){
14705 this.el.removeListener(this.eventName, this.handleKeyDown, this);
14706 this.enabled = false;
14711 * Ext JS Library 1.1.1
14712 * Copyright(c) 2006-2007, Ext JS, LLC.
14714 * Originally Released Under LGPL - original licence link has changed is not relivant.
14717 * <script type="text/javascript">
14722 * @class Roo.util.TextMetrics
14723 * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
14724 * wide, in pixels, a given block of text will be.
14727 Roo.util.TextMetrics = function(){
14731 * Measures the size of the specified text
14732 * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
14733 * that can affect the size of the rendered text
14734 * @param {String} text The text to measure
14735 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14736 * in order to accurately measure the text height
14737 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14739 measure : function(el, text, fixedWidth){
14741 shared = Roo.util.TextMetrics.Instance(el, fixedWidth);
14744 shared.setFixedWidth(fixedWidth || 'auto');
14745 return shared.getSize(text);
14749 * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
14750 * the overhead of multiple calls to initialize the style properties on each measurement.
14751 * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
14752 * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
14753 * in order to accurately measure the text height
14754 * @return {Roo.util.TextMetrics.Instance} instance The new instance
14756 createInstance : function(el, fixedWidth){
14757 return Roo.util.TextMetrics.Instance(el, fixedWidth);
14764 Roo.util.TextMetrics.Instance = function(bindTo, fixedWidth){
14765 var ml = new Roo.Element(document.createElement('div'));
14766 document.body.appendChild(ml.dom);
14767 ml.position('absolute');
14768 ml.setLeftTop(-1000, -1000);
14772 ml.setWidth(fixedWidth);
14777 * Returns the size of the specified text based on the internal element's style and width properties
14778 * @memberOf Roo.util.TextMetrics.Instance#
14779 * @param {String} text The text to measure
14780 * @return {Object} An object containing the text's size {width: (width), height: (height)}
14782 getSize : function(text){
14784 var s = ml.getSize();
14790 * Binds this TextMetrics instance to an element from which to copy existing CSS styles
14791 * that can affect the size of the rendered text
14792 * @memberOf Roo.util.TextMetrics.Instance#
14793 * @param {String/HTMLElement} el The element, dom node or id
14795 bind : function(el){
14797 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
14802 * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
14803 * to set a fixed width in order to accurately measure the text height.
14804 * @memberOf Roo.util.TextMetrics.Instance#
14805 * @param {Number} width The width to set on the element
14807 setFixedWidth : function(width){
14808 ml.setWidth(width);
14812 * Returns the measured width of the specified text
14813 * @memberOf Roo.util.TextMetrics.Instance#
14814 * @param {String} text The text to measure
14815 * @return {Number} width The width in pixels
14817 getWidth : function(text){
14818 ml.dom.style.width = 'auto';
14819 return this.getSize(text).width;
14823 * Returns the measured height of the specified text. For multiline text, be sure to call
14824 * {@link #setFixedWidth} if necessary.
14825 * @memberOf Roo.util.TextMetrics.Instance#
14826 * @param {String} text The text to measure
14827 * @return {Number} height The height in pixels
14829 getHeight : function(text){
14830 return this.getSize(text).height;
14834 instance.bind(bindTo);
14839 // backwards compat
14840 Roo.Element.measureText = Roo.util.TextMetrics.measure;/*
14842 * Ext JS Library 1.1.1
14843 * Copyright(c) 2006-2007, Ext JS, LLC.
14845 * Originally Released Under LGPL - original licence link has changed is not relivant.
14848 * <script type="text/javascript">
14852 * @class Roo.state.Provider
14853 * Abstract base class for state provider implementations. This class provides methods
14854 * for encoding and decoding <b>typed</b> variables including dates and defines the
14855 * Provider interface.
14857 Roo.state.Provider = function(){
14859 * @event statechange
14860 * Fires when a state change occurs.
14861 * @param {Provider} this This state provider
14862 * @param {String} key The state key which was changed
14863 * @param {String} value The encoded value for the state
14866 "statechange": true
14869 Roo.state.Provider.superclass.constructor.call(this);
14871 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
14873 * Returns the current value for a key
14874 * @param {String} name The key name
14875 * @param {Mixed} defaultValue A default value to return if the key's value is not found
14876 * @return {Mixed} The state data
14878 get : function(name, defaultValue){
14879 return typeof this.state[name] == "undefined" ?
14880 defaultValue : this.state[name];
14884 * Clears a value from the state
14885 * @param {String} name The key name
14887 clear : function(name){
14888 delete this.state[name];
14889 this.fireEvent("statechange", this, name, null);
14893 * Sets the value for a key
14894 * @param {String} name The key name
14895 * @param {Mixed} value The value to set
14897 set : function(name, value){
14898 this.state[name] = value;
14899 this.fireEvent("statechange", this, name, value);
14903 * Decodes a string previously encoded with {@link #encodeValue}.
14904 * @param {String} value The value to decode
14905 * @return {Mixed} The decoded value
14907 decodeValue : function(cookie){
14908 var re = /^(a|n|d|b|s|o)\:(.*)$/;
14909 var matches = re.exec(unescape(cookie));
14910 if(!matches || !matches[1]) {
14911 return; // non state cookie
14913 var type = matches[1];
14914 var v = matches[2];
14917 return parseFloat(v);
14919 return new Date(Date.parse(v));
14924 var values = v.split("^");
14925 for(var i = 0, len = values.length; i < len; i++){
14926 all.push(this.decodeValue(values[i]));
14931 var values = v.split("^");
14932 for(var i = 0, len = values.length; i < len; i++){
14933 var kv = values[i].split("=");
14934 all[kv[0]] = this.decodeValue(kv[1]);
14943 * Encodes a value including type information. Decode with {@link #decodeValue}.
14944 * @param {Mixed} value The value to encode
14945 * @return {String} The encoded value
14947 encodeValue : function(v){
14949 if(typeof v == "number"){
14951 }else if(typeof v == "boolean"){
14952 enc = "b:" + (v ? "1" : "0");
14953 }else if(v instanceof Date){
14954 enc = "d:" + v.toGMTString();
14955 }else if(v instanceof Array){
14957 for(var i = 0, len = v.length; i < len; i++){
14958 flat += this.encodeValue(v[i]);
14964 }else if(typeof v == "object"){
14967 if(typeof v[key] != "function"){
14968 flat += key + "=" + this.encodeValue(v[key]) + "^";
14971 enc = "o:" + flat.substring(0, flat.length-1);
14975 return escape(enc);
14981 * Ext JS Library 1.1.1
14982 * Copyright(c) 2006-2007, Ext JS, LLC.
14984 * Originally Released Under LGPL - original licence link has changed is not relivant.
14987 * <script type="text/javascript">
14990 * @class Roo.state.Manager
14991 * This is the global state manager. By default all components that are "state aware" check this class
14992 * for state information if you don't pass them a custom state provider. In order for this class
14993 * to be useful, it must be initialized with a provider when your application initializes.
14995 // in your initialization function
14997 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
14999 // supposed you have a {@link Roo.BorderLayout}
15000 var layout = new Roo.BorderLayout(...);
15001 layout.restoreState();
15002 // or a {Roo.BasicDialog}
15003 var dialog = new Roo.BasicDialog(...);
15004 dialog.restoreState();
15008 Roo.state.Manager = function(){
15009 var provider = new Roo.state.Provider();
15013 * Configures the default state provider for your application
15014 * @param {Provider} stateProvider The state provider to set
15016 setProvider : function(stateProvider){
15017 provider = stateProvider;
15021 * Returns the current value for a key
15022 * @param {String} name The key name
15023 * @param {Mixed} defaultValue The default value to return if the key lookup does not match
15024 * @return {Mixed} The state data
15026 get : function(key, defaultValue){
15027 return provider.get(key, defaultValue);
15031 * Sets the value for a key
15032 * @param {String} name The key name
15033 * @param {Mixed} value The state data
15035 set : function(key, value){
15036 provider.set(key, value);
15040 * Clears a value from the state
15041 * @param {String} name The key name
15043 clear : function(key){
15044 provider.clear(key);
15048 * Gets the currently configured state provider
15049 * @return {Provider} The state provider
15051 getProvider : function(){
15058 * Ext JS Library 1.1.1
15059 * Copyright(c) 2006-2007, Ext JS, LLC.
15061 * Originally Released Under LGPL - original licence link has changed is not relivant.
15064 * <script type="text/javascript">
15067 * @class Roo.state.CookieProvider
15068 * @extends Roo.state.Provider
15069 * The default Provider implementation which saves state via cookies.
15072 var cp = new Roo.state.CookieProvider({
15074 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
15075 domain: "roojs.com"
15077 Roo.state.Manager.setProvider(cp);
15079 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
15080 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
15081 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
15082 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
15083 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
15084 * domain the page is running on including the 'www' like 'www.roojs.com')
15085 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
15087 * Create a new CookieProvider
15088 * @param {Object} config The configuration object
15090 Roo.state.CookieProvider = function(config){
15091 Roo.state.CookieProvider.superclass.constructor.call(this);
15093 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
15094 this.domain = null;
15095 this.secure = false;
15096 Roo.apply(this, config);
15097 this.state = this.readCookies();
15100 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
15102 set : function(name, value){
15103 if(typeof value == "undefined" || value === null){
15107 this.setCookie(name, value);
15108 Roo.state.CookieProvider.superclass.set.call(this, name, value);
15112 clear : function(name){
15113 this.clearCookie(name);
15114 Roo.state.CookieProvider.superclass.clear.call(this, name);
15118 readCookies : function(){
15120 var c = document.cookie + ";";
15121 var re = /\s?(.*?)=(.*?);/g;
15123 while((matches = re.exec(c)) != null){
15124 var name = matches[1];
15125 var value = matches[2];
15126 if(name && name.substring(0,3) == "ys-"){
15127 cookies[name.substr(3)] = this.decodeValue(value);
15134 setCookie : function(name, value){
15135 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
15136 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
15137 ((this.path == null) ? "" : ("; path=" + this.path)) +
15138 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15139 ((this.secure == true) ? "; secure" : "");
15143 clearCookie : function(name){
15144 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
15145 ((this.path == null) ? "" : ("; path=" + this.path)) +
15146 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
15147 ((this.secure == true) ? "; secure" : "");
15151 * Ext JS Library 1.1.1
15152 * Copyright(c) 2006-2007, Ext JS, LLC.
15154 * Originally Released Under LGPL - original licence link has changed is not relivant.
15157 * <script type="text/javascript">
15162 * @class Roo.ComponentMgr
15163 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
15166 Roo.ComponentMgr = function(){
15167 var all = new Roo.util.MixedCollection();
15171 * Registers a component.
15172 * @param {Roo.Component} c The component
15174 register : function(c){
15179 * Unregisters a component.
15180 * @param {Roo.Component} c The component
15182 unregister : function(c){
15187 * Returns a component by id
15188 * @param {String} id The component id
15190 get : function(id){
15191 return all.get(id);
15195 * Registers a function that will be called when a specified component is added to ComponentMgr
15196 * @param {String} id The component id
15197 * @param {Funtction} fn The callback function
15198 * @param {Object} scope The scope of the callback
15200 onAvailable : function(id, fn, scope){
15201 all.on("add", function(index, o){
15203 fn.call(scope || o, o);
15204 all.un("add", fn, scope);
15211 * Ext JS Library 1.1.1
15212 * Copyright(c) 2006-2007, Ext JS, LLC.
15214 * Originally Released Under LGPL - original licence link has changed is not relivant.
15217 * <script type="text/javascript">
15221 * @class Roo.Component
15222 * @extends Roo.util.Observable
15223 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
15224 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
15225 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
15226 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
15227 * All visual components (widgets) that require rendering into a layout should subclass Component.
15229 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
15230 * 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
15231 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
15233 Roo.Component = function(config){
15234 config = config || {};
15235 if(config.tagName || config.dom || typeof config == "string"){ // element object
15236 config = {el: config, id: config.id || config};
15238 this.initialConfig = config;
15240 Roo.apply(this, config);
15244 * Fires after the component is disabled.
15245 * @param {Roo.Component} this
15250 * Fires after the component is enabled.
15251 * @param {Roo.Component} this
15255 * @event beforeshow
15256 * Fires before the component is shown. Return false to stop the show.
15257 * @param {Roo.Component} this
15262 * Fires after the component is shown.
15263 * @param {Roo.Component} this
15267 * @event beforehide
15268 * Fires before the component is hidden. Return false to stop the hide.
15269 * @param {Roo.Component} this
15274 * Fires after the component is hidden.
15275 * @param {Roo.Component} this
15279 * @event beforerender
15280 * Fires before the component is rendered. Return false to stop the render.
15281 * @param {Roo.Component} this
15283 beforerender : true,
15286 * Fires after the component is rendered.
15287 * @param {Roo.Component} this
15291 * @event beforedestroy
15292 * Fires before the component is destroyed. Return false to stop the destroy.
15293 * @param {Roo.Component} this
15295 beforedestroy : true,
15298 * Fires after the component is destroyed.
15299 * @param {Roo.Component} this
15304 this.id = "roo-comp-" + (++Roo.Component.AUTO_ID);
15306 Roo.ComponentMgr.register(this);
15307 Roo.Component.superclass.constructor.call(this);
15308 this.initComponent();
15309 if(this.renderTo){ // not supported by all components yet. use at your own risk!
15310 this.render(this.renderTo);
15311 delete this.renderTo;
15316 Roo.Component.AUTO_ID = 1000;
15318 Roo.extend(Roo.Component, Roo.util.Observable, {
15320 * @scope Roo.Component.prototype
15322 * true if this component is hidden. Read-only.
15327 * true if this component is disabled. Read-only.
15332 * true if this component has been rendered. Read-only.
15336 /** @cfg {String} disableClass
15337 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
15339 disabledClass : "x-item-disabled",
15340 /** @cfg {Boolean} allowDomMove
15341 * Whether the component can move the Dom node when rendering (defaults to true).
15343 allowDomMove : true,
15344 /** @cfg {String} hideMode (display|visibility)
15345 * How this component should hidden. Supported values are
15346 * "visibility" (css visibility), "offsets" (negative offset position) and
15347 * "display" (css display) - defaults to "display".
15349 hideMode: 'display',
15352 ctype : "Roo.Component",
15355 * @cfg {String} actionMode
15356 * which property holds the element that used for hide() / show() / disable() / enable()
15362 getActionEl : function(){
15363 return this[this.actionMode];
15366 initComponent : Roo.emptyFn,
15368 * If this is a lazy rendering component, render it to its container element.
15369 * @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.
15371 render : function(container, position){
15372 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
15373 if(!container && this.el){
15374 this.el = Roo.get(this.el);
15375 container = this.el.dom.parentNode;
15376 this.allowDomMove = false;
15378 this.container = Roo.get(container);
15379 this.rendered = true;
15380 if(position !== undefined){
15381 if(typeof position == 'number'){
15382 position = this.container.dom.childNodes[position];
15384 position = Roo.getDom(position);
15387 this.onRender(this.container, position || null);
15389 this.el.addClass(this.cls);
15393 this.el.applyStyles(this.style);
15396 this.fireEvent("render", this);
15397 this.afterRender(this.container);
15409 // default function is not really useful
15410 onRender : function(ct, position){
15412 this.el = Roo.get(this.el);
15413 if(this.allowDomMove !== false){
15414 ct.dom.insertBefore(this.el.dom, position);
15420 getAutoCreate : function(){
15421 var cfg = typeof this.autoCreate == "object" ?
15422 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
15423 if(this.id && !cfg.id){
15430 afterRender : Roo.emptyFn,
15433 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
15434 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
15436 destroy : function(){
15437 if(this.fireEvent("beforedestroy", this) !== false){
15438 this.purgeListeners();
15439 this.beforeDestroy();
15441 this.el.removeAllListeners();
15443 if(this.actionMode == "container"){
15444 this.container.remove();
15448 Roo.ComponentMgr.unregister(this);
15449 this.fireEvent("destroy", this);
15454 beforeDestroy : function(){
15459 onDestroy : function(){
15464 * Returns the underlying {@link Roo.Element}.
15465 * @return {Roo.Element} The element
15467 getEl : function(){
15472 * Returns the id of this component.
15475 getId : function(){
15480 * Try to focus this component.
15481 * @param {Boolean} selectText True to also select the text in this component (if applicable)
15482 * @return {Roo.Component} this
15484 focus : function(selectText){
15487 if(selectText === true){
15488 this.el.dom.select();
15503 * Disable this component.
15504 * @return {Roo.Component} this
15506 disable : function(){
15510 this.disabled = true;
15511 this.fireEvent("disable", this);
15516 onDisable : function(){
15517 this.getActionEl().addClass(this.disabledClass);
15518 this.el.dom.disabled = true;
15522 * Enable this component.
15523 * @return {Roo.Component} this
15525 enable : function(){
15529 this.disabled = false;
15530 this.fireEvent("enable", this);
15535 onEnable : function(){
15536 this.getActionEl().removeClass(this.disabledClass);
15537 this.el.dom.disabled = false;
15541 * Convenience function for setting disabled/enabled by boolean.
15542 * @param {Boolean} disabled
15544 setDisabled : function(disabled){
15545 this[disabled ? "disable" : "enable"]();
15549 * Show this component.
15550 * @return {Roo.Component} this
15553 if(this.fireEvent("beforeshow", this) !== false){
15554 this.hidden = false;
15558 this.fireEvent("show", this);
15564 onShow : function(){
15565 var ae = this.getActionEl();
15566 if(this.hideMode == 'visibility'){
15567 ae.dom.style.visibility = "visible";
15568 }else if(this.hideMode == 'offsets'){
15569 ae.removeClass('x-hidden');
15571 ae.dom.style.display = "";
15576 * Hide this component.
15577 * @return {Roo.Component} this
15580 if(this.fireEvent("beforehide", this) !== false){
15581 this.hidden = true;
15585 this.fireEvent("hide", this);
15591 onHide : function(){
15592 var ae = this.getActionEl();
15593 if(this.hideMode == 'visibility'){
15594 ae.dom.style.visibility = "hidden";
15595 }else if(this.hideMode == 'offsets'){
15596 ae.addClass('x-hidden');
15598 ae.dom.style.display = "none";
15603 * Convenience function to hide or show this component by boolean.
15604 * @param {Boolean} visible True to show, false to hide
15605 * @return {Roo.Component} this
15607 setVisible: function(visible){
15617 * Returns true if this component is visible.
15619 isVisible : function(){
15620 return this.getActionEl().isVisible();
15623 cloneConfig : function(overrides){
15624 overrides = overrides || {};
15625 var id = overrides.id || Roo.id();
15626 var cfg = Roo.applyIf(overrides, this.initialConfig);
15627 cfg.id = id; // prevent dup id
15628 return new this.constructor(cfg);
15632 * Ext JS Library 1.1.1
15633 * Copyright(c) 2006-2007, Ext JS, LLC.
15635 * Originally Released Under LGPL - original licence link has changed is not relivant.
15638 * <script type="text/javascript">
15642 * @class Roo.BoxComponent
15643 * @extends Roo.Component
15644 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
15645 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
15646 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
15647 * layout containers.
15649 * @param {Roo.Element/String/Object} config The configuration options.
15651 Roo.BoxComponent = function(config){
15652 Roo.Component.call(this, config);
15656 * Fires after the component is resized.
15657 * @param {Roo.Component} this
15658 * @param {Number} adjWidth The box-adjusted width that was set
15659 * @param {Number} adjHeight The box-adjusted height that was set
15660 * @param {Number} rawWidth The width that was originally specified
15661 * @param {Number} rawHeight The height that was originally specified
15666 * Fires after the component is moved.
15667 * @param {Roo.Component} this
15668 * @param {Number} x The new x position
15669 * @param {Number} y The new y position
15675 Roo.extend(Roo.BoxComponent, Roo.Component, {
15676 // private, set in afterRender to signify that the component has been rendered
15678 // private, used to defer height settings to subclasses
15679 deferHeight: false,
15680 /** @cfg {Number} width
15681 * width (optional) size of component
15683 /** @cfg {Number} height
15684 * height (optional) size of component
15688 * Sets the width and height of the component. This method fires the resize event. This method can accept
15689 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
15690 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
15691 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
15692 * @return {Roo.BoxComponent} this
15694 setSize : function(w, h){
15695 // support for standard size objects
15696 if(typeof w == 'object'){
15701 if(!this.boxReady){
15707 // prevent recalcs when not needed
15708 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
15711 this.lastSize = {width: w, height: h};
15713 var adj = this.adjustSize(w, h);
15714 var aw = adj.width, ah = adj.height;
15715 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
15716 var rz = this.getResizeEl();
15717 if(!this.deferHeight && aw !== undefined && ah !== undefined){
15718 rz.setSize(aw, ah);
15719 }else if(!this.deferHeight && ah !== undefined){
15721 }else if(aw !== undefined){
15724 this.onResize(aw, ah, w, h);
15725 this.fireEvent('resize', this, aw, ah, w, h);
15731 * Gets the current size of the component's underlying element.
15732 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
15734 getSize : function(){
15735 return this.el.getSize();
15739 * Gets the current XY position of the component's underlying element.
15740 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15741 * @return {Array} The XY position of the element (e.g., [100, 200])
15743 getPosition : function(local){
15744 if(local === true){
15745 return [this.el.getLeft(true), this.el.getTop(true)];
15747 return this.xy || this.el.getXY();
15751 * Gets the current box measurements of the component's underlying element.
15752 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
15753 * @returns {Object} box An object in the format {x, y, width, height}
15755 getBox : function(local){
15756 var s = this.el.getSize();
15758 s.x = this.el.getLeft(true);
15759 s.y = this.el.getTop(true);
15761 var xy = this.xy || this.el.getXY();
15769 * Sets the current box measurements of the component's underlying element.
15770 * @param {Object} box An object in the format {x, y, width, height}
15771 * @returns {Roo.BoxComponent} this
15773 updateBox : function(box){
15774 this.setSize(box.width, box.height);
15775 this.setPagePosition(box.x, box.y);
15780 getResizeEl : function(){
15781 return this.resizeEl || this.el;
15785 getPositionEl : function(){
15786 return this.positionEl || this.el;
15790 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
15791 * This method fires the move event.
15792 * @param {Number} left The new left
15793 * @param {Number} top The new top
15794 * @returns {Roo.BoxComponent} this
15796 setPosition : function(x, y){
15799 if(!this.boxReady){
15802 var adj = this.adjustPosition(x, y);
15803 var ax = adj.x, ay = adj.y;
15805 var el = this.getPositionEl();
15806 if(ax !== undefined || ay !== undefined){
15807 if(ax !== undefined && ay !== undefined){
15808 el.setLeftTop(ax, ay);
15809 }else if(ax !== undefined){
15811 }else if(ay !== undefined){
15814 this.onPosition(ax, ay);
15815 this.fireEvent('move', this, ax, ay);
15821 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
15822 * This method fires the move event.
15823 * @param {Number} x The new x position
15824 * @param {Number} y The new y position
15825 * @returns {Roo.BoxComponent} this
15827 setPagePosition : function(x, y){
15830 if(!this.boxReady){
15833 if(x === undefined || y === undefined){ // cannot translate undefined points
15836 var p = this.el.translatePoints(x, y);
15837 this.setPosition(p.left, p.top);
15842 onRender : function(ct, position){
15843 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
15845 this.resizeEl = Roo.get(this.resizeEl);
15847 if(this.positionEl){
15848 this.positionEl = Roo.get(this.positionEl);
15853 afterRender : function(){
15854 Roo.BoxComponent.superclass.afterRender.call(this);
15855 this.boxReady = true;
15856 this.setSize(this.width, this.height);
15857 if(this.x || this.y){
15858 this.setPosition(this.x, this.y);
15860 if(this.pageX || this.pageY){
15861 this.setPagePosition(this.pageX, this.pageY);
15866 * Force the component's size to recalculate based on the underlying element's current height and width.
15867 * @returns {Roo.BoxComponent} this
15869 syncSize : function(){
15870 delete this.lastSize;
15871 this.setSize(this.el.getWidth(), this.el.getHeight());
15876 * Called after the component is resized, this method is empty by default but can be implemented by any
15877 * subclass that needs to perform custom logic after a resize occurs.
15878 * @param {Number} adjWidth The box-adjusted width that was set
15879 * @param {Number} adjHeight The box-adjusted height that was set
15880 * @param {Number} rawWidth The width that was originally specified
15881 * @param {Number} rawHeight The height that was originally specified
15883 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
15888 * Called after the component is moved, this method is empty by default but can be implemented by any
15889 * subclass that needs to perform custom logic after a move occurs.
15890 * @param {Number} x The new x position
15891 * @param {Number} y The new y position
15893 onPosition : function(x, y){
15898 adjustSize : function(w, h){
15899 if(this.autoWidth){
15902 if(this.autoHeight){
15905 return {width : w, height: h};
15909 adjustPosition : function(x, y){
15910 return {x : x, y: y};
15913 * Original code for Roojs - LGPL
15914 * <script type="text/javascript">
15918 * @class Roo.XComponent
15919 * A delayed Element creator...
15920 * Or a way to group chunks of interface together.
15921 * technically this is a wrapper around a tree of Roo elements (which defines a 'module'),
15922 * used in conjunction with XComponent.build() it will create an instance of each element,
15923 * then call addxtype() to build the User interface.
15925 * Mypart.xyx = new Roo.XComponent({
15927 parent : 'Mypart.xyz', // empty == document.element.!!
15931 disabled : function() {}
15933 tree : function() { // return an tree of xtype declared components
15937 xtype : 'NestedLayoutPanel',
15944 * It can be used to build a big heiracy, with parent etc.
15945 * or you can just use this to render a single compoent to a dom element
15946 * MYPART.render(Roo.Element | String(id) | dom_element )
15953 * Roo is designed primarily as a single page application, so the UI build for a standard interface will
15954 * expect a single 'TOP' level module normally indicated by the 'parent' of the XComponent definition being defined as false.
15956 * Each sub module is expected to have a parent pointing to the class name of it's parent module.
15958 * When the top level is false, a 'Roo.BorderLayout' is created and the element is flagged as 'topModule'
15959 * - if mulitple topModules exist, the last one is defined as the top module.
15963 * When the top level or multiple modules are to embedded into a existing HTML page,
15964 * the parent element can container '#id' of the element where the module will be drawn.
15968 * Unlike classic Roo, the bootstrap tends not to be used as a single page.
15969 * it relies more on a include mechanism, where sub modules are included into an outer page.
15970 * This is normally managed by the builder tools using Roo.apply( options, Included.Sub.Module )
15972 * Bootstrap Roo Included elements
15974 * Our builder application needs the ability to preview these sub compoennts. They will normally have parent=false set,
15975 * hence confusing the component builder as it thinks there are multiple top level elements.
15979 * @extends Roo.util.Observable
15981 * @param cfg {Object} configuration of component
15984 Roo.XComponent = function(cfg) {
15985 Roo.apply(this, cfg);
15989 * Fires when this the componnt is built
15990 * @param {Roo.XComponent} c the component
15995 this.region = this.region || 'center'; // default..
15996 Roo.XComponent.register(this);
15997 this.modules = false;
15998 this.el = false; // where the layout goes..
16002 Roo.extend(Roo.XComponent, Roo.util.Observable, {
16005 * The created element (with Roo.factory())
16006 * @type {Roo.Layout}
16012 * for BC - use el in new code
16013 * @type {Roo.Layout}
16019 * for BC - use el in new code
16020 * @type {Roo.Layout}
16025 * @cfg {Function|boolean} disabled
16026 * If this module is disabled by some rule, return true from the funtion
16031 * @cfg {String} parent
16032 * Name of parent element which it get xtype added to..
16037 * @cfg {String} order
16038 * Used to set the order in which elements are created (usefull for multiple tabs)
16043 * @cfg {String} name
16044 * String to display while loading.
16048 * @cfg {String} region
16049 * Region to render component to (defaults to center)
16054 * @cfg {Array} items
16055 * A single item array - the first element is the root of the tree..
16056 * It's done this way to stay compatible with the Xtype system...
16062 * The method that retuns the tree of parts that make up this compoennt
16069 * render element to dom or tree
16070 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
16073 render : function(el)
16077 var hp = this.parent ? 1 : 0;
16078 Roo.debug && Roo.log(this);
16080 var tree = this._tree ? this._tree() : this.tree();
16083 if (!el && typeof(this.parent) == 'string' && this.parent.substring(0,1) == '#') {
16084 // if parent is a '#.....' string, then let's use that..
16085 var ename = this.parent.substr(1);
16086 this.parent = false;
16087 Roo.debug && Roo.log(ename);
16089 case 'bootstrap-body':
16090 if (typeof(tree.el) != 'undefined' && tree.el == document.body) {
16091 // this is the BorderLayout standard?
16092 this.parent = { el : true };
16095 if (["Nest", "Content", "Grid", "Tree"].indexOf(tree.xtype) > -1) {
16096 // need to insert stuff...
16098 el : new Roo.bootstrap.layout.Border({
16099 el : document.body,
16105 tabPosition: 'top',
16106 //resizeTabs: true,
16107 alwaysShowTabs: true,
16117 if (typeof(Roo.bootstrap.Body) != 'undefined' ) {
16118 this.parent = { el : new Roo.bootstrap.Body() };
16119 Roo.debug && Roo.log("setting el to doc body");
16122 throw "Container is bootstrap body, but Roo.bootstrap.Body is not defined";
16126 this.parent = { el : true};
16129 el = Roo.get(ename);
16130 if (typeof(Roo.bootstrap) != 'undefined' && tree['|xns'] == 'Roo.bootstrap') {
16131 this.parent = { el : true};
16138 if (!el && !this.parent) {
16139 Roo.debug && Roo.log("Warning - element can not be found :#" + ename );
16144 Roo.debug && Roo.log("EL:");
16145 Roo.debug && Roo.log(el);
16146 Roo.debug && Roo.log("this.parent.el:");
16147 Roo.debug && Roo.log(this.parent.el);
16150 // altertive root elements ??? - we need a better way to indicate these.
16151 var is_alt = Roo.XComponent.is_alt ||
16152 (typeof(tree.el) != 'undefined' && tree.el == document.body) ||
16153 (typeof(Roo.bootstrap) != 'undefined' && tree.xns == Roo.bootstrap) ||
16154 (typeof(Roo.mailer) != 'undefined' && tree.xns == Roo.mailer) ;
16158 if (!this.parent && is_alt) {
16159 //el = Roo.get(document.body);
16160 this.parent = { el : true };
16165 if (!this.parent) {
16167 Roo.debug && Roo.log("no parent - creating one");
16169 el = el ? Roo.get(el) : false;
16171 if (typeof(Roo.BorderLayout) == 'undefined' ) {
16174 el : new Roo.bootstrap.layout.Border({
16175 el: el || document.body,
16181 tabPosition: 'top',
16182 //resizeTabs: true,
16183 alwaysShowTabs: false,
16186 overflow: 'visible'
16192 // it's a top level one..
16194 el : new Roo.BorderLayout(el || document.body, {
16199 tabPosition: 'top',
16200 //resizeTabs: true,
16201 alwaysShowTabs: el && hp? false : true,
16202 hideTabs: el || !hp ? true : false,
16210 if (!this.parent.el) {
16211 // probably an old style ctor, which has been disabled.
16215 // The 'tree' method is '_tree now'
16217 tree.region = tree.region || this.region;
16218 var is_body = false;
16219 if (this.parent.el === true) {
16220 // bootstrap... - body..
16224 this.parent.el = Roo.factory(tree);
16228 this.el = this.parent.el.addxtype(tree, undefined, is_body);
16229 this.fireEvent('built', this);
16231 this.panel = this.el;
16232 this.layout = this.panel.layout;
16233 this.parentLayout = this.parent.layout || false;
16239 Roo.apply(Roo.XComponent, {
16241 * @property hideProgress
16242 * true to disable the building progress bar.. usefull on single page renders.
16245 hideProgress : false,
16247 * @property buildCompleted
16248 * True when the builder has completed building the interface.
16251 buildCompleted : false,
16254 * @property topModule
16255 * the upper most module - uses document.element as it's constructor.
16262 * @property modules
16263 * array of modules to be created by registration system.
16264 * @type {Array} of Roo.XComponent
16269 * @property elmodules
16270 * array of modules to be created by which use #ID
16271 * @type {Array} of Roo.XComponent
16278 * Is an alternative Root - normally used by bootstrap or other systems,
16279 * where the top element in the tree can wrap 'body'
16280 * @type {boolean} (default false)
16285 * @property build_from_html
16286 * Build elements from html - used by bootstrap HTML stuff
16287 * - this is cleared after build is completed
16288 * @type {boolean} (default false)
16291 build_from_html : false,
16293 * Register components to be built later.
16295 * This solves the following issues
16296 * - Building is not done on page load, but after an authentication process has occured.
16297 * - Interface elements are registered on page load
16298 * - Parent Interface elements may not be loaded before child, so this handles that..
16305 module : 'Pman.Tab.projectMgr',
16307 parent : 'Pman.layout',
16308 disabled : false, // or use a function..
16311 * * @param {Object} details about module
16313 register : function(obj) {
16315 Roo.XComponent.event.fireEvent('register', obj);
16316 switch(typeof(obj.disabled) ) {
16322 if ( obj.disabled() ) {
16328 if (obj.disabled) {
16334 this.modules.push(obj);
16338 * convert a string to an object..
16339 * eg. 'AAA.BBB' -> finds AAA.BBB
16343 toObject : function(str)
16345 if (!str || typeof(str) == 'object') {
16348 if (str.substring(0,1) == '#') {
16352 var ar = str.split('.');
16357 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
16359 throw "Module not found : " + str;
16363 throw "Module not found : " + str;
16365 Roo.each(ar, function(e) {
16366 if (typeof(o[e]) == 'undefined') {
16367 throw "Module not found : " + str;
16378 * move modules into their correct place in the tree..
16381 preBuild : function ()
16384 Roo.each(this.modules , function (obj)
16386 Roo.XComponent.event.fireEvent('beforebuild', obj);
16388 var opar = obj.parent;
16390 obj.parent = this.toObject(opar);
16392 Roo.debug && Roo.log("parent:toObject failed: " + e.toString());
16397 Roo.debug && Roo.log("GOT top level module");
16398 Roo.debug && Roo.log(obj);
16399 obj.modules = new Roo.util.MixedCollection(false,
16400 function(o) { return o.order + '' }
16402 this.topModule = obj;
16405 // parent is a string (usually a dom element name..)
16406 if (typeof(obj.parent) == 'string') {
16407 this.elmodules.push(obj);
16410 if (obj.parent.constructor != Roo.XComponent) {
16411 Roo.debug && Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name)
16413 if (!obj.parent.modules) {
16414 obj.parent.modules = new Roo.util.MixedCollection(false,
16415 function(o) { return o.order + '' }
16418 if (obj.parent.disabled) {
16419 obj.disabled = true;
16421 obj.parent.modules.add(obj);
16426 * make a list of modules to build.
16427 * @return {Array} list of modules.
16430 buildOrder : function()
16433 var cmp = function(a,b) {
16434 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
16436 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
16437 throw "No top level modules to build";
16440 // make a flat list in order of modules to build.
16441 var mods = this.topModule ? [ this.topModule ] : [];
16444 // elmodules (is a list of DOM based modules )
16445 Roo.each(this.elmodules, function(e) {
16447 if (!this.topModule &&
16448 typeof(e.parent) == 'string' &&
16449 e.parent.substring(0,1) == '#' &&
16450 Roo.get(e.parent.substr(1))
16453 _this.topModule = e;
16459 // add modules to their parents..
16460 var addMod = function(m) {
16461 Roo.debug && Roo.log("build Order: add: " + m.name);
16464 if (m.modules && !m.disabled) {
16465 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules");
16466 m.modules.keySort('ASC', cmp );
16467 Roo.debug && Roo.log("build Order: " + m.modules.length + " child modules (after sort)");
16469 m.modules.each(addMod);
16471 Roo.debug && Roo.log("build Order: no child modules");
16473 // not sure if this is used any more..
16475 m.finalize.name = m.name + " (clean up) ";
16476 mods.push(m.finalize);
16480 if (this.topModule && this.topModule.modules) {
16481 this.topModule.modules.keySort('ASC', cmp );
16482 this.topModule.modules.each(addMod);
16488 * Build the registered modules.
16489 * @param {Object} parent element.
16490 * @param {Function} optional method to call after module has been added.
16494 build : function(opts)
16497 if (typeof(opts) != 'undefined') {
16498 Roo.apply(this,opts);
16502 var mods = this.buildOrder();
16504 //this.allmods = mods;
16505 //Roo.debug && Roo.log(mods);
16507 if (!mods.length) { // should not happen
16508 throw "NO modules!!!";
16512 var msg = "Building Interface...";
16513 // flash it up as modal - so we store the mask!?
16514 if (!this.hideProgress && Roo.MessageBox) {
16515 Roo.MessageBox.show({ title: 'loading' });
16516 Roo.MessageBox.show({
16517 title: "Please wait...",
16526 var total = mods.length;
16529 var progressRun = function() {
16530 if (!mods.length) {
16531 Roo.debug && Roo.log('hide?');
16532 if (!this.hideProgress && Roo.MessageBox) {
16533 Roo.MessageBox.hide();
16535 Roo.XComponent.build_from_html = false; // reset, so dialogs will be build from javascript
16537 Roo.XComponent.event.fireEvent('buildcomplete', _this.topModule);
16543 var m = mods.shift();
16546 Roo.debug && Roo.log(m);
16547 // not sure if this is supported any more.. - modules that are are just function
16548 if (typeof(m) == 'function') {
16550 return progressRun.defer(10, _this);
16554 msg = "Building Interface " + (total - mods.length) +
16556 (m.name ? (' - ' + m.name) : '');
16557 Roo.debug && Roo.log(msg);
16558 if (!_this.hideProgress && Roo.MessageBox) {
16559 Roo.MessageBox.updateProgress( (total - mods.length)/total, msg );
16563 // is the module disabled?
16564 var disabled = (typeof(m.disabled) == 'function') ?
16565 m.disabled.call(m.module.disabled) : m.disabled;
16569 return progressRun(); // we do not update the display!
16577 // it's 10 on top level, and 1 on others??? why...
16578 return progressRun.defer(10, _this);
16581 progressRun.defer(1, _this);
16595 * wrapper for event.on - aliased later..
16596 * Typically use to register a event handler for register:
16598 * eg. Roo.XComponent.on('register', function(comp) { comp.disable = true } );
16607 Roo.XComponent.event = new Roo.util.Observable({
16611 * Fires when an Component is registered,
16612 * set the disable property on the Component to stop registration.
16613 * @param {Roo.XComponent} c the component being registerd.
16618 * @event beforebuild
16619 * Fires before each Component is built
16620 * can be used to apply permissions.
16621 * @param {Roo.XComponent} c the component being registerd.
16624 'beforebuild' : true,
16626 * @event buildcomplete
16627 * Fires on the top level element when all elements have been built
16628 * @param {Roo.XComponent} the top level component.
16630 'buildcomplete' : true
16635 Roo.XComponent.on = Roo.XComponent.event.on.createDelegate(Roo.XComponent.event);
16638 * marked - a markdown parser
16639 * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
16640 * https://github.com/chjj/marked
16646 * Roo.Markdown - is a very crude wrapper around marked..
16650 * alert( Roo.Markdown.toHtml("Markdown *rocks*.") );
16652 * Note: move the sample code to the bottom of this
16653 * file before uncommenting it.
16658 Roo.Markdown.toHtml = function(text) {
16660 var c = new Roo.Markdown.marked.setOptions({
16661 renderer: new Roo.Markdown.marked.Renderer(),
16672 text = text.replace(/\\\n/g,' ');
16673 return Roo.Markdown.marked(text);
16678 // Wraps all "globals" so that the only thing
16679 // exposed is makeHtml().
16684 * Block-Level Grammar
16689 code: /^( {4}[^\n]+\n*)+/,
16691 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
16692 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
16694 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
16695 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
16696 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
16697 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
16698 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
16700 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
16704 block.bullet = /(?:[*+-]|\d+\.)/;
16705 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
16706 block.item = replace(block.item, 'gm')
16707 (/bull/g, block.bullet)
16710 block.list = replace(block.list)
16711 (/bull/g, block.bullet)
16712 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
16713 ('def', '\\n+(?=' + block.def.source + ')')
16716 block.blockquote = replace(block.blockquote)
16720 block._tag = '(?!(?:'
16721 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
16722 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
16723 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
16725 block.html = replace(block.html)
16726 ('comment', /<!--[\s\S]*?-->/)
16727 ('closed', /<(tag)[\s\S]+?<\/\1>/)
16728 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
16729 (/tag/g, block._tag)
16732 block.paragraph = replace(block.paragraph)
16734 ('heading', block.heading)
16735 ('lheading', block.lheading)
16736 ('blockquote', block.blockquote)
16737 ('tag', '<' + block._tag)
16742 * Normal Block Grammar
16745 block.normal = merge({}, block);
16748 * GFM Block Grammar
16751 block.gfm = merge({}, block.normal, {
16752 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
16754 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
16757 block.gfm.paragraph = replace(block.paragraph)
16759 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
16760 + block.list.source.replace('\\1', '\\3') + '|')
16764 * GFM + Tables Block Grammar
16767 block.tables = merge({}, block.gfm, {
16768 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
16769 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
16776 function Lexer(options) {
16778 this.tokens.links = {};
16779 this.options = options || marked.defaults;
16780 this.rules = block.normal;
16782 if (this.options.gfm) {
16783 if (this.options.tables) {
16784 this.rules = block.tables;
16786 this.rules = block.gfm;
16792 * Expose Block Rules
16795 Lexer.rules = block;
16798 * Static Lex Method
16801 Lexer.lex = function(src, options) {
16802 var lexer = new Lexer(options);
16803 return lexer.lex(src);
16810 Lexer.prototype.lex = function(src) {
16812 .replace(/\r\n|\r/g, '\n')
16813 .replace(/\t/g, ' ')
16814 .replace(/\u00a0/g, ' ')
16815 .replace(/\u2424/g, '\n');
16817 return this.token(src, true);
16824 Lexer.prototype.token = function(src, top, bq) {
16825 var src = src.replace(/^ +$/gm, '')
16838 if (cap = this.rules.newline.exec(src)) {
16839 src = src.substring(cap[0].length);
16840 if (cap[0].length > 1) {
16848 if (cap = this.rules.code.exec(src)) {
16849 src = src.substring(cap[0].length);
16850 cap = cap[0].replace(/^ {4}/gm, '');
16853 text: !this.options.pedantic
16854 ? cap.replace(/\n+$/, '')
16861 if (cap = this.rules.fences.exec(src)) {
16862 src = src.substring(cap[0].length);
16872 if (cap = this.rules.heading.exec(src)) {
16873 src = src.substring(cap[0].length);
16876 depth: cap[1].length,
16882 // table no leading pipe (gfm)
16883 if (top && (cap = this.rules.nptable.exec(src))) {
16884 src = src.substring(cap[0].length);
16888 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
16889 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
16890 cells: cap[3].replace(/\n$/, '').split('\n')
16893 for (i = 0; i < item.align.length; i++) {
16894 if (/^ *-+: *$/.test(item.align[i])) {
16895 item.align[i] = 'right';
16896 } else if (/^ *:-+: *$/.test(item.align[i])) {
16897 item.align[i] = 'center';
16898 } else if (/^ *:-+ *$/.test(item.align[i])) {
16899 item.align[i] = 'left';
16901 item.align[i] = null;
16905 for (i = 0; i < item.cells.length; i++) {
16906 item.cells[i] = item.cells[i].split(/ *\| */);
16909 this.tokens.push(item);
16915 if (cap = this.rules.lheading.exec(src)) {
16916 src = src.substring(cap[0].length);
16919 depth: cap[2] === '=' ? 1 : 2,
16926 if (cap = this.rules.hr.exec(src)) {
16927 src = src.substring(cap[0].length);
16935 if (cap = this.rules.blockquote.exec(src)) {
16936 src = src.substring(cap[0].length);
16939 type: 'blockquote_start'
16942 cap = cap[0].replace(/^ *> ?/gm, '');
16944 // Pass `top` to keep the current
16945 // "toplevel" state. This is exactly
16946 // how markdown.pl works.
16947 this.token(cap, top, true);
16950 type: 'blockquote_end'
16957 if (cap = this.rules.list.exec(src)) {
16958 src = src.substring(cap[0].length);
16962 type: 'list_start',
16963 ordered: bull.length > 1
16966 // Get each top-level item.
16967 cap = cap[0].match(this.rules.item);
16973 for (; i < l; i++) {
16976 // Remove the list item's bullet
16977 // so it is seen as the next token.
16978 space = item.length;
16979 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
16981 // Outdent whatever the
16982 // list item contains. Hacky.
16983 if (~item.indexOf('\n ')) {
16984 space -= item.length;
16985 item = !this.options.pedantic
16986 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
16987 : item.replace(/^ {1,4}/gm, '');
16990 // Determine whether the next list item belongs here.
16991 // Backpedal if it does not belong in this list.
16992 if (this.options.smartLists && i !== l - 1) {
16993 b = block.bullet.exec(cap[i + 1])[0];
16994 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
16995 src = cap.slice(i + 1).join('\n') + src;
17000 // Determine whether item is loose or not.
17001 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
17002 // for discount behavior.
17003 loose = next || /\n\n(?!\s*$)/.test(item);
17005 next = item.charAt(item.length - 1) === '\n';
17006 if (!loose) { loose = next; }
17011 ? 'loose_item_start'
17012 : 'list_item_start'
17016 this.token(item, false, bq);
17019 type: 'list_item_end'
17031 if (cap = this.rules.html.exec(src)) {
17032 src = src.substring(cap[0].length);
17034 type: this.options.sanitize
17037 pre: !this.options.sanitizer
17038 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
17045 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
17046 src = src.substring(cap[0].length);
17047 this.tokens.links[cap[1].toLowerCase()] = {
17055 if (top && (cap = this.rules.table.exec(src))) {
17056 src = src.substring(cap[0].length);
17060 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
17061 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
17062 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
17065 for (i = 0; i < item.align.length; i++) {
17066 if (/^ *-+: *$/.test(item.align[i])) {
17067 item.align[i] = 'right';
17068 } else if (/^ *:-+: *$/.test(item.align[i])) {
17069 item.align[i] = 'center';
17070 } else if (/^ *:-+ *$/.test(item.align[i])) {
17071 item.align[i] = 'left';
17073 item.align[i] = null;
17077 for (i = 0; i < item.cells.length; i++) {
17078 item.cells[i] = item.cells[i]
17079 .replace(/^ *\| *| *\| *$/g, '')
17083 this.tokens.push(item);
17088 // top-level paragraph
17089 if (top && (cap = this.rules.paragraph.exec(src))) {
17090 src = src.substring(cap[0].length);
17093 text: cap[1].charAt(cap[1].length - 1) === '\n'
17094 ? cap[1].slice(0, -1)
17101 if (cap = this.rules.text.exec(src)) {
17102 // Top-level should never reach here.
17103 src = src.substring(cap[0].length);
17113 Error('Infinite loop on byte: ' + src.charCodeAt(0));
17117 return this.tokens;
17121 * Inline-Level Grammar
17125 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
17126 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
17128 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
17129 link: /^!?\[(inside)\]\(href\)/,
17130 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
17131 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
17132 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
17133 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
17134 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
17135 br: /^ {2,}\n(?!\s*$)/,
17137 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
17140 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
17141 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
17143 inline.link = replace(inline.link)
17144 ('inside', inline._inside)
17145 ('href', inline._href)
17148 inline.reflink = replace(inline.reflink)
17149 ('inside', inline._inside)
17153 * Normal Inline Grammar
17156 inline.normal = merge({}, inline);
17159 * Pedantic Inline Grammar
17162 inline.pedantic = merge({}, inline.normal, {
17163 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
17164 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
17168 * GFM Inline Grammar
17171 inline.gfm = merge({}, inline.normal, {
17172 escape: replace(inline.escape)('])', '~|])')(),
17173 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
17174 del: /^~~(?=\S)([\s\S]*?\S)~~/,
17175 text: replace(inline.text)
17177 ('|', '|https?://|')
17182 * GFM + Line Breaks Inline Grammar
17185 inline.breaks = merge({}, inline.gfm, {
17186 br: replace(inline.br)('{2,}', '*')(),
17187 text: replace(inline.gfm.text)('{2,}', '*')()
17191 * Inline Lexer & Compiler
17194 function InlineLexer(links, options) {
17195 this.options = options || marked.defaults;
17196 this.links = links;
17197 this.rules = inline.normal;
17198 this.renderer = this.options.renderer || new Renderer;
17199 this.renderer.options = this.options;
17203 Error('Tokens array requires a `links` property.');
17206 if (this.options.gfm) {
17207 if (this.options.breaks) {
17208 this.rules = inline.breaks;
17210 this.rules = inline.gfm;
17212 } else if (this.options.pedantic) {
17213 this.rules = inline.pedantic;
17218 * Expose Inline Rules
17221 InlineLexer.rules = inline;
17224 * Static Lexing/Compiling Method
17227 InlineLexer.output = function(src, links, options) {
17228 var inline = new InlineLexer(links, options);
17229 return inline.output(src);
17236 InlineLexer.prototype.output = function(src) {
17245 if (cap = this.rules.escape.exec(src)) {
17246 src = src.substring(cap[0].length);
17252 if (cap = this.rules.autolink.exec(src)) {
17253 src = src.substring(cap[0].length);
17254 if (cap[2] === '@') {
17255 text = cap[1].charAt(6) === ':'
17256 ? this.mangle(cap[1].substring(7))
17257 : this.mangle(cap[1]);
17258 href = this.mangle('mailto:') + text;
17260 text = escape(cap[1]);
17263 out += this.renderer.link(href, null, text);
17268 if (!this.inLink && (cap = this.rules.url.exec(src))) {
17269 src = src.substring(cap[0].length);
17270 text = escape(cap[1]);
17272 out += this.renderer.link(href, null, text);
17277 if (cap = this.rules.tag.exec(src)) {
17278 if (!this.inLink && /^<a /i.test(cap[0])) {
17279 this.inLink = true;
17280 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
17281 this.inLink = false;
17283 src = src.substring(cap[0].length);
17284 out += this.options.sanitize
17285 ? this.options.sanitizer
17286 ? this.options.sanitizer(cap[0])
17293 if (cap = this.rules.link.exec(src)) {
17294 src = src.substring(cap[0].length);
17295 this.inLink = true;
17296 out += this.outputLink(cap, {
17300 this.inLink = false;
17305 if ((cap = this.rules.reflink.exec(src))
17306 || (cap = this.rules.nolink.exec(src))) {
17307 src = src.substring(cap[0].length);
17308 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
17309 link = this.links[link.toLowerCase()];
17310 if (!link || !link.href) {
17311 out += cap[0].charAt(0);
17312 src = cap[0].substring(1) + src;
17315 this.inLink = true;
17316 out += this.outputLink(cap, link);
17317 this.inLink = false;
17322 if (cap = this.rules.strong.exec(src)) {
17323 src = src.substring(cap[0].length);
17324 out += this.renderer.strong(this.output(cap[2] || cap[1]));
17329 if (cap = this.rules.em.exec(src)) {
17330 src = src.substring(cap[0].length);
17331 out += this.renderer.em(this.output(cap[2] || cap[1]));
17336 if (cap = this.rules.code.exec(src)) {
17337 src = src.substring(cap[0].length);
17338 out += this.renderer.codespan(escape(cap[2], true));
17343 if (cap = this.rules.br.exec(src)) {
17344 src = src.substring(cap[0].length);
17345 out += this.renderer.br();
17350 if (cap = this.rules.del.exec(src)) {
17351 src = src.substring(cap[0].length);
17352 out += this.renderer.del(this.output(cap[1]));
17357 if (cap = this.rules.text.exec(src)) {
17358 src = src.substring(cap[0].length);
17359 out += this.renderer.text(escape(this.smartypants(cap[0])));
17365 Error('Infinite loop on byte: ' + src.charCodeAt(0));
17376 InlineLexer.prototype.outputLink = function(cap, link) {
17377 var href = escape(link.href)
17378 , title = link.title ? escape(link.title) : null;
17380 return cap[0].charAt(0) !== '!'
17381 ? this.renderer.link(href, title, this.output(cap[1]))
17382 : this.renderer.image(href, title, escape(cap[1]));
17386 * Smartypants Transformations
17389 InlineLexer.prototype.smartypants = function(text) {
17390 if (!this.options.smartypants) { return text; }
17393 .replace(/---/g, '\u2014')
17395 .replace(/--/g, '\u2013')
17397 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
17398 // closing singles & apostrophes
17399 .replace(/'/g, '\u2019')
17401 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
17403 .replace(/"/g, '\u201d')
17405 .replace(/\.{3}/g, '\u2026');
17412 InlineLexer.prototype.mangle = function(text) {
17413 if (!this.options.mangle) { return text; }
17419 for (; i < l; i++) {
17420 ch = text.charCodeAt(i);
17421 if (Math.random() > 0.5) {
17422 ch = 'x' + ch.toString(16);
17424 out += '&#' + ch + ';';
17434 function Renderer(options) {
17435 this.options = options || {};
17438 Renderer.prototype.code = function(code, lang, escaped) {
17439 if (this.options.highlight) {
17440 var out = this.options.highlight(code, lang);
17441 if (out != null && out !== code) {
17446 // hack!!! - it's already escapeD?
17451 return '<pre><code>'
17452 + (escaped ? code : escape(code, true))
17453 + '\n</code></pre>';
17456 return '<pre><code class="'
17457 + this.options.langPrefix
17458 + escape(lang, true)
17460 + (escaped ? code : escape(code, true))
17461 + '\n</code></pre>\n';
17464 Renderer.prototype.blockquote = function(quote) {
17465 return '<blockquote>\n' + quote + '</blockquote>\n';
17468 Renderer.prototype.html = function(html) {
17472 Renderer.prototype.heading = function(text, level, raw) {
17476 + this.options.headerPrefix
17477 + raw.toLowerCase().replace(/[^\w]+/g, '-')
17485 Renderer.prototype.hr = function() {
17486 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
17489 Renderer.prototype.list = function(body, ordered) {
17490 var type = ordered ? 'ol' : 'ul';
17491 return '<' + type + '>\n' + body + '</' + type + '>\n';
17494 Renderer.prototype.listitem = function(text) {
17495 return '<li>' + text + '</li>\n';
17498 Renderer.prototype.paragraph = function(text) {
17499 return '<p>' + text + '</p>\n';
17502 Renderer.prototype.table = function(header, body) {
17503 return '<table class="table table-striped">\n'
17513 Renderer.prototype.tablerow = function(content) {
17514 return '<tr>\n' + content + '</tr>\n';
17517 Renderer.prototype.tablecell = function(content, flags) {
17518 var type = flags.header ? 'th' : 'td';
17519 var tag = flags.align
17520 ? '<' + type + ' style="text-align:' + flags.align + '">'
17521 : '<' + type + '>';
17522 return tag + content + '</' + type + '>\n';
17525 // span level renderer
17526 Renderer.prototype.strong = function(text) {
17527 return '<strong>' + text + '</strong>';
17530 Renderer.prototype.em = function(text) {
17531 return '<em>' + text + '</em>';
17534 Renderer.prototype.codespan = function(text) {
17535 return '<code>' + text + '</code>';
17538 Renderer.prototype.br = function() {
17539 return this.options.xhtml ? '<br/>' : '<br>';
17542 Renderer.prototype.del = function(text) {
17543 return '<del>' + text + '</del>';
17546 Renderer.prototype.link = function(href, title, text) {
17547 if (this.options.sanitize) {
17549 var prot = decodeURIComponent(unescape(href))
17550 .replace(/[^\w:]/g, '')
17555 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
17559 var out = '<a href="' + href + '"';
17561 out += ' title="' + title + '"';
17563 out += '>' + text + '</a>';
17567 Renderer.prototype.image = function(href, title, text) {
17568 var out = '<img src="' + href + '" alt="' + text + '"';
17570 out += ' title="' + title + '"';
17572 out += this.options.xhtml ? '/>' : '>';
17576 Renderer.prototype.text = function(text) {
17581 * Parsing & Compiling
17584 function Parser(options) {
17587 this.options = options || marked.defaults;
17588 this.options.renderer = this.options.renderer || new Renderer;
17589 this.renderer = this.options.renderer;
17590 this.renderer.options = this.options;
17594 * Static Parse Method
17597 Parser.parse = function(src, options, renderer) {
17598 var parser = new Parser(options, renderer);
17599 return parser.parse(src);
17606 Parser.prototype.parse = function(src) {
17607 this.inline = new InlineLexer(src.links, this.options, this.renderer);
17608 this.tokens = src.reverse();
17611 while (this.next()) {
17622 Parser.prototype.next = function() {
17623 return this.token = this.tokens.pop();
17627 * Preview Next Token
17630 Parser.prototype.peek = function() {
17631 return this.tokens[this.tokens.length - 1] || 0;
17635 * Parse Text Tokens
17638 Parser.prototype.parseText = function() {
17639 var body = this.token.text;
17641 while (this.peek().type === 'text') {
17642 body += '\n' + this.next().text;
17645 return this.inline.output(body);
17649 * Parse Current Token
17652 Parser.prototype.tok = function() {
17653 switch (this.token.type) {
17658 return this.renderer.hr();
17661 return this.renderer.heading(
17662 this.inline.output(this.token.text),
17667 return this.renderer.code(this.token.text,
17669 this.token.escaped);
17682 for (i = 0; i < this.token.header.length; i++) {
17683 flags = { header: true, align: this.token.align[i] };
17684 cell += this.renderer.tablecell(
17685 this.inline.output(this.token.header[i]),
17686 { header: true, align: this.token.align[i] }
17689 header += this.renderer.tablerow(cell);
17691 for (i = 0; i < this.token.cells.length; i++) {
17692 row = this.token.cells[i];
17695 for (j = 0; j < row.length; j++) {
17696 cell += this.renderer.tablecell(
17697 this.inline.output(row[j]),
17698 { header: false, align: this.token.align[j] }
17702 body += this.renderer.tablerow(cell);
17704 return this.renderer.table(header, body);
17706 case 'blockquote_start': {
17709 while (this.next().type !== 'blockquote_end') {
17710 body += this.tok();
17713 return this.renderer.blockquote(body);
17715 case 'list_start': {
17717 , ordered = this.token.ordered;
17719 while (this.next().type !== 'list_end') {
17720 body += this.tok();
17723 return this.renderer.list(body, ordered);
17725 case 'list_item_start': {
17728 while (this.next().type !== 'list_item_end') {
17729 body += this.token.type === 'text'
17734 return this.renderer.listitem(body);
17736 case 'loose_item_start': {
17739 while (this.next().type !== 'list_item_end') {
17740 body += this.tok();
17743 return this.renderer.listitem(body);
17746 var html = !this.token.pre && !this.options.pedantic
17747 ? this.inline.output(this.token.text)
17749 return this.renderer.html(html);
17751 case 'paragraph': {
17752 return this.renderer.paragraph(this.inline.output(this.token.text));
17755 return this.renderer.paragraph(this.parseText());
17764 function escape(html, encode) {
17766 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
17767 .replace(/</g, '<')
17768 .replace(/>/g, '>')
17769 .replace(/"/g, '"')
17770 .replace(/'/g, ''');
17773 function unescape(html) {
17774 // explicitly match decimal, hex, and named HTML entities
17775 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
17776 n = n.toLowerCase();
17777 if (n === 'colon') { return ':'; }
17778 if (n.charAt(0) === '#') {
17779 return n.charAt(1) === 'x'
17780 ? String.fromCharCode(parseInt(n.substring(2), 16))
17781 : String.fromCharCode(+n.substring(1));
17787 function replace(regex, opt) {
17788 regex = regex.source;
17790 return function self(name, val) {
17791 if (!name) { return new RegExp(regex, opt); }
17792 val = val.source || val;
17793 val = val.replace(/(^|[^\[])\^/g, '$1');
17794 regex = regex.replace(name, val);
17802 function merge(obj) {
17807 for (; i < arguments.length; i++) {
17808 target = arguments[i];
17809 for (key in target) {
17810 if (Object.prototype.hasOwnProperty.call(target, key)) {
17811 obj[key] = target[key];
17824 function marked(src, opt, callback) {
17825 if (callback || typeof opt === 'function') {
17831 opt = merge({}, marked.defaults, opt || {});
17833 var highlight = opt.highlight
17839 tokens = Lexer.lex(src, opt)
17841 return callback(e);
17844 pending = tokens.length;
17846 var done = function(err) {
17848 opt.highlight = highlight;
17849 return callback(err);
17855 out = Parser.parse(tokens, opt);
17860 opt.highlight = highlight;
17864 : callback(null, out);
17867 if (!highlight || highlight.length < 3) {
17871 delete opt.highlight;
17873 if (!pending) { return done(); }
17875 for (; i < tokens.length; i++) {
17877 if (token.type !== 'code') {
17878 return --pending || done();
17880 return highlight(token.text, token.lang, function(err, code) {
17881 if (err) { return done(err); }
17882 if (code == null || code === token.text) {
17883 return --pending || done();
17886 token.escaped = true;
17887 --pending || done();
17895 if (opt) { opt = merge({}, marked.defaults, opt); }
17896 return Parser.parse(Lexer.lex(src, opt), opt);
17898 e.message += '\nPlease report this to https://github.com/chjj/marked.';
17899 if ((opt || marked.defaults).silent) {
17900 return '<p>An error occured:</p><pre>'
17901 + escape(e.message + '', true)
17913 marked.setOptions = function(opt) {
17914 merge(marked.defaults, opt);
17918 marked.defaults = {
17929 langPrefix: 'lang-',
17930 smartypants: false,
17932 renderer: new Renderer,
17940 marked.Parser = Parser;
17941 marked.parser = Parser.parse;
17943 marked.Renderer = Renderer;
17945 marked.Lexer = Lexer;
17946 marked.lexer = Lexer.lex;
17948 marked.InlineLexer = InlineLexer;
17949 marked.inlineLexer = InlineLexer.output;
17951 marked.parse = marked;
17953 Roo.Markdown.marked = marked;
17957 * Ext JS Library 1.1.1
17958 * Copyright(c) 2006-2007, Ext JS, LLC.
17960 * Originally Released Under LGPL - original licence link has changed is not relivant.
17963 * <script type="text/javascript">
17969 * These classes are derivatives of the similarly named classes in the YUI Library.
17970 * The original license:
17971 * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
17972 * Code licensed under the BSD License:
17973 * http://developer.yahoo.net/yui/license.txt
17978 var Event=Roo.EventManager;
17979 var Dom=Roo.lib.Dom;
17982 * @class Roo.dd.DragDrop
17983 * @extends Roo.util.Observable
17984 * Defines the interface and base operation of items that that can be
17985 * dragged or can be drop targets. It was designed to be extended, overriding
17986 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
17987 * Up to three html elements can be associated with a DragDrop instance:
17989 * <li>linked element: the element that is passed into the constructor.
17990 * This is the element which defines the boundaries for interaction with
17991 * other DragDrop objects.</li>
17992 * <li>handle element(s): The drag operation only occurs if the element that
17993 * was clicked matches a handle element. By default this is the linked
17994 * element, but there are times that you will want only a portion of the
17995 * linked element to initiate the drag operation, and the setHandleElId()
17996 * method provides a way to define this.</li>
17997 * <li>drag element: this represents the element that would be moved along
17998 * with the cursor during a drag operation. By default, this is the linked
17999 * element itself as in {@link Roo.dd.DD}. setDragElId() lets you define
18000 * a separate element that would be moved, as in {@link Roo.dd.DDProxy}.
18003 * This class should not be instantiated until the onload event to ensure that
18004 * the associated elements are available.
18005 * The following would define a DragDrop obj that would interact with any
18006 * other DragDrop obj in the "group1" group:
18008 * dd = new Roo.dd.DragDrop("div1", "group1");
18010 * Since none of the event handlers have been implemented, nothing would
18011 * actually happen if you were to run the code above. Normally you would
18012 * override this class or one of the default implementations, but you can
18013 * also override the methods you want on an instance of the class...
18015 * dd.onDragDrop = function(e, id) {
18016 * alert("dd was dropped on " + id);
18020 * @param {String} id of the element that is linked to this instance
18021 * @param {String} sGroup the group of related DragDrop objects
18022 * @param {object} config an object containing configurable attributes
18023 * Valid properties for DragDrop:
18024 * padding, isTarget, maintainOffset, primaryButtonOnly
18026 Roo.dd.DragDrop = function(id, sGroup, config) {
18028 this.init(id, sGroup, config);
18033 Roo.extend(Roo.dd.DragDrop, Roo.util.Observable , {
18036 * The id of the element associated with this object. This is what we
18037 * refer to as the "linked element" because the size and position of
18038 * this element is used to determine when the drag and drop objects have
18046 * Configuration attributes passed into the constructor
18053 * The id of the element that will be dragged. By default this is same
18054 * as the linked element , but could be changed to another element. Ex:
18056 * @property dragElId
18063 * the id of the element that initiates the drag operation. By default
18064 * this is the linked element, but could be changed to be a child of this
18065 * element. This lets us do things like only starting the drag when the
18066 * header element within the linked html element is clicked.
18067 * @property handleElId
18074 * An associative array of HTML tags that will be ignored if clicked.
18075 * @property invalidHandleTypes
18076 * @type {string: string}
18078 invalidHandleTypes: null,
18081 * An associative array of ids for elements that will be ignored if clicked
18082 * @property invalidHandleIds
18083 * @type {string: string}
18085 invalidHandleIds: null,
18088 * An indexted array of css class names for elements that will be ignored
18090 * @property invalidHandleClasses
18093 invalidHandleClasses: null,
18096 * The linked element's absolute X position at the time the drag was
18098 * @property startPageX
18105 * The linked element's absolute X position at the time the drag was
18107 * @property startPageY
18114 * The group defines a logical collection of DragDrop objects that are
18115 * related. Instances only get events when interacting with other
18116 * DragDrop object in the same group. This lets us define multiple
18117 * groups using a single DragDrop subclass if we want.
18119 * @type {string: string}
18124 * Individual drag/drop instances can be locked. This will prevent
18125 * onmousedown start drag.
18133 * Lock this instance
18136 lock: function() { this.locked = true; },
18139 * Unlock this instace
18142 unlock: function() { this.locked = false; },
18145 * By default, all insances can be a drop target. This can be disabled by
18146 * setting isTarget to false.
18153 * The padding configured for this drag and drop object for calculating
18154 * the drop zone intersection with this object.
18161 * Cached reference to the linked element
18162 * @property _domRef
18168 * Internal typeof flag
18169 * @property __ygDragDrop
18172 __ygDragDrop: true,
18175 * Set to true when horizontal contraints are applied
18176 * @property constrainX
18183 * Set to true when vertical contraints are applied
18184 * @property constrainY
18191 * The left constraint
18199 * The right constraint
18207 * The up constraint
18216 * The down constraint
18224 * Maintain offsets when we resetconstraints. Set to true when you want
18225 * the position of the element relative to its parent to stay the same
18226 * when the page changes
18228 * @property maintainOffset
18231 maintainOffset: false,
18234 * Array of pixel locations the element will snap to if we specified a
18235 * horizontal graduation/interval. This array is generated automatically
18236 * when you define a tick interval.
18243 * Array of pixel locations the element will snap to if we specified a
18244 * vertical graduation/interval. This array is generated automatically
18245 * when you define a tick interval.
18252 * By default the drag and drop instance will only respond to the primary
18253 * button click (left button for a right-handed mouse). Set to true to
18254 * allow drag and drop to start with any mouse click that is propogated
18256 * @property primaryButtonOnly
18259 primaryButtonOnly: true,
18262 * The availabe property is false until the linked dom element is accessible.
18263 * @property available
18269 * By default, drags can only be initiated if the mousedown occurs in the
18270 * region the linked element is. This is done in part to work around a
18271 * bug in some browsers that mis-report the mousedown if the previous
18272 * mouseup happened outside of the window. This property is set to true
18273 * if outer handles are defined.
18275 * @property hasOuterHandles
18279 hasOuterHandles: false,
18282 * Code that executes immediately before the startDrag event
18283 * @method b4StartDrag
18286 b4StartDrag: function(x, y) { },
18289 * Abstract method called after a drag/drop object is clicked
18290 * and the drag or mousedown time thresholds have beeen met.
18291 * @method startDrag
18292 * @param {int} X click location
18293 * @param {int} Y click location
18295 startDrag: function(x, y) { /* override this */ },
18298 * Code that executes immediately before the onDrag event
18302 b4Drag: function(e) { },
18305 * Abstract method called during the onMouseMove event while dragging an
18308 * @param {Event} e the mousemove event
18310 onDrag: function(e) { /* override this */ },
18313 * Abstract method called when this element fist begins hovering over
18314 * another DragDrop obj
18315 * @method onDragEnter
18316 * @param {Event} e the mousemove event
18317 * @param {String|DragDrop[]} id In POINT mode, the element
18318 * id this is hovering over. In INTERSECT mode, an array of one or more
18319 * dragdrop items being hovered over.
18321 onDragEnter: function(e, id) { /* override this */ },
18324 * Code that executes immediately before the onDragOver event
18325 * @method b4DragOver
18328 b4DragOver: function(e) { },
18331 * Abstract method called when this element is hovering over another
18333 * @method onDragOver
18334 * @param {Event} e the mousemove event
18335 * @param {String|DragDrop[]} id In POINT mode, the element
18336 * id this is hovering over. In INTERSECT mode, an array of dd items
18337 * being hovered over.
18339 onDragOver: function(e, id) { /* override this */ },
18342 * Code that executes immediately before the onDragOut event
18343 * @method b4DragOut
18346 b4DragOut: function(e) { },
18349 * Abstract method called when we are no longer hovering over an element
18350 * @method onDragOut
18351 * @param {Event} e the mousemove event
18352 * @param {String|DragDrop[]} id In POINT mode, the element
18353 * id this was hovering over. In INTERSECT mode, an array of dd items
18354 * that the mouse is no longer over.
18356 onDragOut: function(e, id) { /* override this */ },
18359 * Code that executes immediately before the onDragDrop event
18360 * @method b4DragDrop
18363 b4DragDrop: function(e) { },
18366 * Abstract method called when this item is dropped on another DragDrop
18368 * @method onDragDrop
18369 * @param {Event} e the mouseup event
18370 * @param {String|DragDrop[]} id In POINT mode, the element
18371 * id this was dropped on. In INTERSECT mode, an array of dd items this
18374 onDragDrop: function(e, id) { /* override this */ },
18377 * Abstract method called when this item is dropped on an area with no
18379 * @method onInvalidDrop
18380 * @param {Event} e the mouseup event
18382 onInvalidDrop: function(e) { /* override this */ },
18385 * Code that executes immediately before the endDrag event
18386 * @method b4EndDrag
18389 b4EndDrag: function(e) { },
18392 * Fired when we are done dragging the object
18394 * @param {Event} e the mouseup event
18396 endDrag: function(e) { /* override this */ },
18399 * Code executed immediately before the onMouseDown event
18400 * @method b4MouseDown
18401 * @param {Event} e the mousedown event
18404 b4MouseDown: function(e) { },
18407 * Event handler that fires when a drag/drop obj gets a mousedown
18408 * @method onMouseDown
18409 * @param {Event} e the mousedown event
18411 onMouseDown: function(e) { /* override this */ },
18414 * Event handler that fires when a drag/drop obj gets a mouseup
18415 * @method onMouseUp
18416 * @param {Event} e the mouseup event
18418 onMouseUp: function(e) { /* override this */ },
18421 * Override the onAvailable method to do what is needed after the initial
18422 * position was determined.
18423 * @method onAvailable
18425 onAvailable: function () {
18429 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
18432 defaultPadding : {left:0, right:0, top:0, bottom:0},
18435 * Initializes the drag drop object's constraints to restrict movement to a certain element.
18439 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
18440 { dragElId: "existingProxyDiv" });
18441 dd.startDrag = function(){
18442 this.constrainTo("parent-id");
18445 * Or you can initalize it using the {@link Roo.Element} object:
18447 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
18448 startDrag : function(){
18449 this.constrainTo("parent-id");
18453 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
18454 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
18455 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
18456 * an object containing the sides to pad. For example: {right:10, bottom:10}
18457 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
18459 constrainTo : function(constrainTo, pad, inContent){
18460 if(typeof pad == "number"){
18461 pad = {left: pad, right:pad, top:pad, bottom:pad};
18463 pad = pad || this.defaultPadding;
18464 var b = Roo.get(this.getEl()).getBox();
18465 var ce = Roo.get(constrainTo);
18466 var s = ce.getScroll();
18467 var c, cd = ce.dom;
18468 if(cd == document.body){
18469 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
18472 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
18476 var topSpace = b.y - c.y;
18477 var leftSpace = b.x - c.x;
18479 this.resetConstraints();
18480 this.setXConstraint(leftSpace - (pad.left||0), // left
18481 c.width - leftSpace - b.width - (pad.right||0) //right
18483 this.setYConstraint(topSpace - (pad.top||0), //top
18484 c.height - topSpace - b.height - (pad.bottom||0) //bottom
18489 * Returns a reference to the linked element
18491 * @return {HTMLElement} the html element
18493 getEl: function() {
18494 if (!this._domRef) {
18495 this._domRef = Roo.getDom(this.id);
18498 return this._domRef;
18502 * Returns a reference to the actual element to drag. By default this is
18503 * the same as the html element, but it can be assigned to another
18504 * element. An example of this can be found in Roo.dd.DDProxy
18505 * @method getDragEl
18506 * @return {HTMLElement} the html element
18508 getDragEl: function() {
18509 return Roo.getDom(this.dragElId);
18513 * Sets up the DragDrop object. Must be called in the constructor of any
18514 * Roo.dd.DragDrop subclass
18516 * @param id the id of the linked element
18517 * @param {String} sGroup the group of related items
18518 * @param {object} config configuration attributes
18520 init: function(id, sGroup, config) {
18521 this.initTarget(id, sGroup, config);
18522 if (!Roo.isTouch) {
18523 Event.on(this.id, "mousedown", this.handleMouseDown, this);
18525 Event.on(this.id, "touchstart", this.handleMouseDown, this);
18526 // Event.on(this.id, "selectstart", Event.preventDefault);
18530 * Initializes Targeting functionality only... the object does not
18531 * get a mousedown handler.
18532 * @method initTarget
18533 * @param id the id of the linked element
18534 * @param {String} sGroup the group of related items
18535 * @param {object} config configuration attributes
18537 initTarget: function(id, sGroup, config) {
18539 // configuration attributes
18540 this.config = config || {};
18542 // create a local reference to the drag and drop manager
18543 this.DDM = Roo.dd.DDM;
18544 // initialize the groups array
18547 // assume that we have an element reference instead of an id if the
18548 // parameter is not a string
18549 if (typeof id !== "string") {
18556 // add to an interaction group
18557 this.addToGroup((sGroup) ? sGroup : "default");
18559 // We don't want to register this as the handle with the manager
18560 // so we just set the id rather than calling the setter.
18561 this.handleElId = id;
18563 // the linked element is the element that gets dragged by default
18564 this.setDragElId(id);
18566 // by default, clicked anchors will not start drag operations.
18567 this.invalidHandleTypes = { A: "A" };
18568 this.invalidHandleIds = {};
18569 this.invalidHandleClasses = [];
18571 this.applyConfig();
18573 this.handleOnAvailable();
18577 * Applies the configuration parameters that were passed into the constructor.
18578 * This is supposed to happen at each level through the inheritance chain. So
18579 * a DDProxy implentation will execute apply config on DDProxy, DD, and
18580 * DragDrop in order to get all of the parameters that are available in
18582 * @method applyConfig
18584 applyConfig: function() {
18586 // configurable properties:
18587 // padding, isTarget, maintainOffset, primaryButtonOnly
18588 this.padding = this.config.padding || [0, 0, 0, 0];
18589 this.isTarget = (this.config.isTarget !== false);
18590 this.maintainOffset = (this.config.maintainOffset);
18591 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
18596 * Executed when the linked element is available
18597 * @method handleOnAvailable
18600 handleOnAvailable: function() {
18601 this.available = true;
18602 this.resetConstraints();
18603 this.onAvailable();
18607 * Configures the padding for the target zone in px. Effectively expands
18608 * (or reduces) the virtual object size for targeting calculations.
18609 * Supports css-style shorthand; if only one parameter is passed, all sides
18610 * will have that padding, and if only two are passed, the top and bottom
18611 * will have the first param, the left and right the second.
18612 * @method setPadding
18613 * @param {int} iTop Top pad
18614 * @param {int} iRight Right pad
18615 * @param {int} iBot Bot pad
18616 * @param {int} iLeft Left pad
18618 setPadding: function(iTop, iRight, iBot, iLeft) {
18619 // this.padding = [iLeft, iRight, iTop, iBot];
18620 if (!iRight && 0 !== iRight) {
18621 this.padding = [iTop, iTop, iTop, iTop];
18622 } else if (!iBot && 0 !== iBot) {
18623 this.padding = [iTop, iRight, iTop, iRight];
18625 this.padding = [iTop, iRight, iBot, iLeft];
18630 * Stores the initial placement of the linked element.
18631 * @method setInitialPosition
18632 * @param {int} diffX the X offset, default 0
18633 * @param {int} diffY the Y offset, default 0
18635 setInitPosition: function(diffX, diffY) {
18636 var el = this.getEl();
18638 if (!this.DDM.verifyEl(el)) {
18642 var dx = diffX || 0;
18643 var dy = diffY || 0;
18645 var p = Dom.getXY( el );
18647 this.initPageX = p[0] - dx;
18648 this.initPageY = p[1] - dy;
18650 this.lastPageX = p[0];
18651 this.lastPageY = p[1];
18654 this.setStartPosition(p);
18658 * Sets the start position of the element. This is set when the obj
18659 * is initialized, the reset when a drag is started.
18660 * @method setStartPosition
18661 * @param pos current position (from previous lookup)
18664 setStartPosition: function(pos) {
18665 var p = pos || Dom.getXY( this.getEl() );
18666 this.deltaSetXY = null;
18668 this.startPageX = p[0];
18669 this.startPageY = p[1];
18673 * Add this instance to a group of related drag/drop objects. All
18674 * instances belong to at least one group, and can belong to as many
18675 * groups as needed.
18676 * @method addToGroup
18677 * @param sGroup {string} the name of the group
18679 addToGroup: function(sGroup) {
18680 this.groups[sGroup] = true;
18681 this.DDM.regDragDrop(this, sGroup);
18685 * Remove's this instance from the supplied interaction group
18686 * @method removeFromGroup
18687 * @param {string} sGroup The group to drop
18689 removeFromGroup: function(sGroup) {
18690 if (this.groups[sGroup]) {
18691 delete this.groups[sGroup];
18694 this.DDM.removeDDFromGroup(this, sGroup);
18698 * Allows you to specify that an element other than the linked element
18699 * will be moved with the cursor during a drag
18700 * @method setDragElId
18701 * @param id {string} the id of the element that will be used to initiate the drag
18703 setDragElId: function(id) {
18704 this.dragElId = id;
18708 * Allows you to specify a child of the linked element that should be
18709 * used to initiate the drag operation. An example of this would be if
18710 * you have a content div with text and links. Clicking anywhere in the
18711 * content area would normally start the drag operation. Use this method
18712 * to specify that an element inside of the content div is the element
18713 * that starts the drag operation.
18714 * @method setHandleElId
18715 * @param id {string} the id of the element that will be used to
18716 * initiate the drag.
18718 setHandleElId: function(id) {
18719 if (typeof id !== "string") {
18722 this.handleElId = id;
18723 this.DDM.regHandle(this.id, id);
18727 * Allows you to set an element outside of the linked element as a drag
18729 * @method setOuterHandleElId
18730 * @param id the id of the element that will be used to initiate the drag
18732 setOuterHandleElId: function(id) {
18733 if (typeof id !== "string") {
18736 Event.on(id, "mousedown",
18737 this.handleMouseDown, this);
18738 this.setHandleElId(id);
18740 this.hasOuterHandles = true;
18744 * Remove all drag and drop hooks for this element
18747 unreg: function() {
18748 Event.un(this.id, "mousedown",
18749 this.handleMouseDown);
18750 Event.un(this.id, "touchstart",
18751 this.handleMouseDown);
18752 this._domRef = null;
18753 this.DDM._remove(this);
18756 destroy : function(){
18761 * Returns true if this instance is locked, or the drag drop mgr is locked
18762 * (meaning that all drag/drop is disabled on the page.)
18764 * @return {boolean} true if this obj or all drag/drop is locked, else
18767 isLocked: function() {
18768 return (this.DDM.isLocked() || this.locked);
18772 * Fired when this object is clicked
18773 * @method handleMouseDown
18775 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
18778 handleMouseDown: function(e, oDD){
18780 if (!Roo.isTouch && this.primaryButtonOnly && e.button != 0) {
18781 //Roo.log('not touch/ button !=0');
18784 if (e.browserEvent.touches && e.browserEvent.touches.length != 1) {
18785 return; // double touch..
18789 if (this.isLocked()) {
18790 //Roo.log('locked');
18794 this.DDM.refreshCache(this.groups);
18795 // Roo.log([Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e)]);
18796 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
18797 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
18798 //Roo.log('no outer handes or not over target');
18801 // Roo.log('check validator');
18802 if (this.clickValidator(e)) {
18803 // Roo.log('validate success');
18804 // set the initial element position
18805 this.setStartPosition();
18808 this.b4MouseDown(e);
18809 this.onMouseDown(e);
18811 this.DDM.handleMouseDown(e, this);
18813 this.DDM.stopEvent(e);
18821 clickValidator: function(e) {
18822 var target = e.getTarget();
18823 return ( this.isValidHandleChild(target) &&
18824 (this.id == this.handleElId ||
18825 this.DDM.handleWasClicked(target, this.id)) );
18829 * Allows you to specify a tag name that should not start a drag operation
18830 * when clicked. This is designed to facilitate embedding links within a
18831 * drag handle that do something other than start the drag.
18832 * @method addInvalidHandleType
18833 * @param {string} tagName the type of element to exclude
18835 addInvalidHandleType: function(tagName) {
18836 var type = tagName.toUpperCase();
18837 this.invalidHandleTypes[type] = type;
18841 * Lets you to specify an element id for a child of a drag handle
18842 * that should not initiate a drag
18843 * @method addInvalidHandleId
18844 * @param {string} id the element id of the element you wish to ignore
18846 addInvalidHandleId: function(id) {
18847 if (typeof id !== "string") {
18850 this.invalidHandleIds[id] = id;
18854 * Lets you specify a css class of elements that will not initiate a drag
18855 * @method addInvalidHandleClass
18856 * @param {string} cssClass the class of the elements you wish to ignore
18858 addInvalidHandleClass: function(cssClass) {
18859 this.invalidHandleClasses.push(cssClass);
18863 * Unsets an excluded tag name set by addInvalidHandleType
18864 * @method removeInvalidHandleType
18865 * @param {string} tagName the type of element to unexclude
18867 removeInvalidHandleType: function(tagName) {
18868 var type = tagName.toUpperCase();
18869 // this.invalidHandleTypes[type] = null;
18870 delete this.invalidHandleTypes[type];
18874 * Unsets an invalid handle id
18875 * @method removeInvalidHandleId
18876 * @param {string} id the id of the element to re-enable
18878 removeInvalidHandleId: function(id) {
18879 if (typeof id !== "string") {
18882 delete this.invalidHandleIds[id];
18886 * Unsets an invalid css class
18887 * @method removeInvalidHandleClass
18888 * @param {string} cssClass the class of the element(s) you wish to
18891 removeInvalidHandleClass: function(cssClass) {
18892 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
18893 if (this.invalidHandleClasses[i] == cssClass) {
18894 delete this.invalidHandleClasses[i];
18900 * Checks the tag exclusion list to see if this click should be ignored
18901 * @method isValidHandleChild
18902 * @param {HTMLElement} node the HTMLElement to evaluate
18903 * @return {boolean} true if this is a valid tag type, false if not
18905 isValidHandleChild: function(node) {
18908 // var n = (node.nodeName == "#text") ? node.parentNode : node;
18911 nodeName = node.nodeName.toUpperCase();
18913 nodeName = node.nodeName;
18915 valid = valid && !this.invalidHandleTypes[nodeName];
18916 valid = valid && !this.invalidHandleIds[node.id];
18918 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
18919 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
18928 * Create the array of horizontal tick marks if an interval was specified
18929 * in setXConstraint().
18930 * @method setXTicks
18933 setXTicks: function(iStartX, iTickSize) {
18935 this.xTickSize = iTickSize;
18939 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
18941 this.xTicks[this.xTicks.length] = i;
18946 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
18948 this.xTicks[this.xTicks.length] = i;
18953 this.xTicks.sort(this.DDM.numericSort) ;
18957 * Create the array of vertical tick marks if an interval was specified in
18958 * setYConstraint().
18959 * @method setYTicks
18962 setYTicks: function(iStartY, iTickSize) {
18964 this.yTickSize = iTickSize;
18968 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
18970 this.yTicks[this.yTicks.length] = i;
18975 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
18977 this.yTicks[this.yTicks.length] = i;
18982 this.yTicks.sort(this.DDM.numericSort) ;
18986 * By default, the element can be dragged any place on the screen. Use
18987 * this method to limit the horizontal travel of the element. Pass in
18988 * 0,0 for the parameters if you want to lock the drag to the y axis.
18989 * @method setXConstraint
18990 * @param {int} iLeft the number of pixels the element can move to the left
18991 * @param {int} iRight the number of pixels the element can move to the
18993 * @param {int} iTickSize optional parameter for specifying that the
18995 * should move iTickSize pixels at a time.
18997 setXConstraint: function(iLeft, iRight, iTickSize) {
18998 this.leftConstraint = iLeft;
18999 this.rightConstraint = iRight;
19001 this.minX = this.initPageX - iLeft;
19002 this.maxX = this.initPageX + iRight;
19003 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
19005 this.constrainX = true;
19009 * Clears any constraints applied to this instance. Also clears ticks
19010 * since they can't exist independent of a constraint at this time.
19011 * @method clearConstraints
19013 clearConstraints: function() {
19014 this.constrainX = false;
19015 this.constrainY = false;
19020 * Clears any tick interval defined for this instance
19021 * @method clearTicks
19023 clearTicks: function() {
19024 this.xTicks = null;
19025 this.yTicks = null;
19026 this.xTickSize = 0;
19027 this.yTickSize = 0;
19031 * By default, the element can be dragged any place on the screen. Set
19032 * this to limit the vertical travel of the element. Pass in 0,0 for the
19033 * parameters if you want to lock the drag to the x axis.
19034 * @method setYConstraint
19035 * @param {int} iUp the number of pixels the element can move up
19036 * @param {int} iDown the number of pixels the element can move down
19037 * @param {int} iTickSize optional parameter for specifying that the
19038 * element should move iTickSize pixels at a time.
19040 setYConstraint: function(iUp, iDown, iTickSize) {
19041 this.topConstraint = iUp;
19042 this.bottomConstraint = iDown;
19044 this.minY = this.initPageY - iUp;
19045 this.maxY = this.initPageY + iDown;
19046 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
19048 this.constrainY = true;
19053 * resetConstraints must be called if you manually reposition a dd element.
19054 * @method resetConstraints
19055 * @param {boolean} maintainOffset
19057 resetConstraints: function() {
19060 // Maintain offsets if necessary
19061 if (this.initPageX || this.initPageX === 0) {
19062 // figure out how much this thing has moved
19063 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
19064 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
19066 this.setInitPosition(dx, dy);
19068 // This is the first time we have detected the element's position
19070 this.setInitPosition();
19073 if (this.constrainX) {
19074 this.setXConstraint( this.leftConstraint,
19075 this.rightConstraint,
19079 if (this.constrainY) {
19080 this.setYConstraint( this.topConstraint,
19081 this.bottomConstraint,
19087 * Normally the drag element is moved pixel by pixel, but we can specify
19088 * that it move a number of pixels at a time. This method resolves the
19089 * location when we have it set up like this.
19091 * @param {int} val where we want to place the object
19092 * @param {int[]} tickArray sorted array of valid points
19093 * @return {int} the closest tick
19096 getTick: function(val, tickArray) {
19099 // If tick interval is not defined, it is effectively 1 pixel,
19100 // so we return the value passed to us.
19102 } else if (tickArray[0] >= val) {
19103 // The value is lower than the first tick, so we return the first
19105 return tickArray[0];
19107 for (var i=0, len=tickArray.length; i<len; ++i) {
19109 if (tickArray[next] && tickArray[next] >= val) {
19110 var diff1 = val - tickArray[i];
19111 var diff2 = tickArray[next] - val;
19112 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
19116 // The value is larger than the last tick, so we return the last
19118 return tickArray[tickArray.length - 1];
19125 * @return {string} string representation of the dd obj
19127 toString: function() {
19128 return ("DragDrop " + this.id);
19136 * Ext JS Library 1.1.1
19137 * Copyright(c) 2006-2007, Ext JS, LLC.
19139 * Originally Released Under LGPL - original licence link has changed is not relivant.
19142 * <script type="text/javascript">
19147 * The drag and drop utility provides a framework for building drag and drop
19148 * applications. In addition to enabling drag and drop for specific elements,
19149 * the drag and drop elements are tracked by the manager class, and the
19150 * interactions between the various elements are tracked during the drag and
19151 * the implementing code is notified about these important moments.
19154 // Only load the library once. Rewriting the manager class would orphan
19155 // existing drag and drop instances.
19156 if (!Roo.dd.DragDropMgr) {
19159 * @class Roo.dd.DragDropMgr
19160 * DragDropMgr is a singleton that tracks the element interaction for
19161 * all DragDrop items in the window. Generally, you will not call
19162 * this class directly, but it does have helper methods that could
19163 * be useful in your DragDrop implementations.
19166 Roo.dd.DragDropMgr = function() {
19168 var Event = Roo.EventManager;
19173 * Two dimensional Array of registered DragDrop objects. The first
19174 * dimension is the DragDrop item group, the second the DragDrop
19177 * @type {string: string}
19184 * Array of element ids defined as drag handles. Used to determine
19185 * if the element that generated the mousedown event is actually the
19186 * handle and not the html element itself.
19187 * @property handleIds
19188 * @type {string: string}
19195 * the DragDrop object that is currently being dragged
19196 * @property dragCurrent
19204 * the DragDrop object(s) that are being hovered over
19205 * @property dragOvers
19213 * the X distance between the cursor and the object being dragged
19222 * the Y distance between the cursor and the object being dragged
19231 * Flag to determine if we should prevent the default behavior of the
19232 * events we define. By default this is true, but this can be set to
19233 * false if you need the default behavior (not recommended)
19234 * @property preventDefault
19238 preventDefault: true,
19241 * Flag to determine if we should stop the propagation of the events
19242 * we generate. This is true by default but you may want to set it to
19243 * false if the html element contains other features that require the
19245 * @property stopPropagation
19249 stopPropagation: true,
19252 * Internal flag that is set to true when drag and drop has been
19254 * @property initialized
19261 * All drag and drop can be disabled.
19269 * Called the first time an element is registered.
19275 this.initialized = true;
19279 * In point mode, drag and drop interaction is defined by the
19280 * location of the cursor during the drag/drop
19288 * In intersect mode, drag and drop interactio nis defined by the
19289 * overlap of two or more drag and drop objects.
19290 * @property INTERSECT
19297 * The current drag and drop mode. Default: POINT
19305 * Runs method on all drag and drop objects
19306 * @method _execOnAll
19310 _execOnAll: function(sMethod, args) {
19311 for (var i in this.ids) {
19312 for (var j in this.ids[i]) {
19313 var oDD = this.ids[i][j];
19314 if (! this.isTypeOfDD(oDD)) {
19317 oDD[sMethod].apply(oDD, args);
19323 * Drag and drop initialization. Sets up the global event handlers
19328 _onLoad: function() {
19332 if (!Roo.isTouch) {
19333 Event.on(document, "mouseup", this.handleMouseUp, this, true);
19334 Event.on(document, "mousemove", this.handleMouseMove, this, true);
19336 Event.on(document, "touchend", this.handleMouseUp, this, true);
19337 Event.on(document, "touchmove", this.handleMouseMove, this, true);
19339 Event.on(window, "unload", this._onUnload, this, true);
19340 Event.on(window, "resize", this._onResize, this, true);
19341 // Event.on(window, "mouseout", this._test);
19346 * Reset constraints on all drag and drop objs
19347 * @method _onResize
19351 _onResize: function(e) {
19352 this._execOnAll("resetConstraints", []);
19356 * Lock all drag and drop functionality
19360 lock: function() { this.locked = true; },
19363 * Unlock all drag and drop functionality
19367 unlock: function() { this.locked = false; },
19370 * Is drag and drop locked?
19372 * @return {boolean} True if drag and drop is locked, false otherwise.
19375 isLocked: function() { return this.locked; },
19378 * Location cache that is set for all drag drop objects when a drag is
19379 * initiated, cleared when the drag is finished.
19380 * @property locationCache
19387 * Set useCache to false if you want to force object the lookup of each
19388 * drag and drop linked element constantly during a drag.
19389 * @property useCache
19396 * The number of pixels that the mouse needs to move after the
19397 * mousedown before the drag is initiated. Default=3;
19398 * @property clickPixelThresh
19402 clickPixelThresh: 3,
19405 * The number of milliseconds after the mousedown event to initiate the
19406 * drag if we don't get a mouseup event. Default=1000
19407 * @property clickTimeThresh
19411 clickTimeThresh: 350,
19414 * Flag that indicates that either the drag pixel threshold or the
19415 * mousdown time threshold has been met
19416 * @property dragThreshMet
19421 dragThreshMet: false,
19424 * Timeout used for the click time threshold
19425 * @property clickTimeout
19430 clickTimeout: null,
19433 * The X position of the mousedown event stored for later use when a
19434 * drag threshold is met.
19443 * The Y position of the mousedown event stored for later use when a
19444 * drag threshold is met.
19453 * Each DragDrop instance must be registered with the DragDropMgr.
19454 * This is executed in DragDrop.init()
19455 * @method regDragDrop
19456 * @param {DragDrop} oDD the DragDrop object to register
19457 * @param {String} sGroup the name of the group this element belongs to
19460 regDragDrop: function(oDD, sGroup) {
19461 if (!this.initialized) { this.init(); }
19463 if (!this.ids[sGroup]) {
19464 this.ids[sGroup] = {};
19466 this.ids[sGroup][oDD.id] = oDD;
19470 * Removes the supplied dd instance from the supplied group. Executed
19471 * by DragDrop.removeFromGroup, so don't call this function directly.
19472 * @method removeDDFromGroup
19476 removeDDFromGroup: function(oDD, sGroup) {
19477 if (!this.ids[sGroup]) {
19478 this.ids[sGroup] = {};
19481 var obj = this.ids[sGroup];
19482 if (obj && obj[oDD.id]) {
19483 delete obj[oDD.id];
19488 * Unregisters a drag and drop item. This is executed in
19489 * DragDrop.unreg, use that method instead of calling this directly.
19494 _remove: function(oDD) {
19495 for (var g in oDD.groups) {
19496 if (g && this.ids[g][oDD.id]) {
19497 delete this.ids[g][oDD.id];
19500 delete this.handleIds[oDD.id];
19504 * Each DragDrop handle element must be registered. This is done
19505 * automatically when executing DragDrop.setHandleElId()
19506 * @method regHandle
19507 * @param {String} sDDId the DragDrop id this element is a handle for
19508 * @param {String} sHandleId the id of the element that is the drag
19512 regHandle: function(sDDId, sHandleId) {
19513 if (!this.handleIds[sDDId]) {
19514 this.handleIds[sDDId] = {};
19516 this.handleIds[sDDId][sHandleId] = sHandleId;
19520 * Utility function to determine if a given element has been
19521 * registered as a drag drop item.
19522 * @method isDragDrop
19523 * @param {String} id the element id to check
19524 * @return {boolean} true if this element is a DragDrop item,
19528 isDragDrop: function(id) {
19529 return ( this.getDDById(id) ) ? true : false;
19533 * Returns the drag and drop instances that are in all groups the
19534 * passed in instance belongs to.
19535 * @method getRelated
19536 * @param {DragDrop} p_oDD the obj to get related data for
19537 * @param {boolean} bTargetsOnly if true, only return targetable objs
19538 * @return {DragDrop[]} the related instances
19541 getRelated: function(p_oDD, bTargetsOnly) {
19543 for (var i in p_oDD.groups) {
19544 for (j in this.ids[i]) {
19545 var dd = this.ids[i][j];
19546 if (! this.isTypeOfDD(dd)) {
19549 if (!bTargetsOnly || dd.isTarget) {
19550 oDDs[oDDs.length] = dd;
19559 * Returns true if the specified dd target is a legal target for
19560 * the specifice drag obj
19561 * @method isLegalTarget
19562 * @param {DragDrop} the drag obj
19563 * @param {DragDrop} the target
19564 * @return {boolean} true if the target is a legal target for the
19568 isLegalTarget: function (oDD, oTargetDD) {
19569 var targets = this.getRelated(oDD, true);
19570 for (var i=0, len=targets.length;i<len;++i) {
19571 if (targets[i].id == oTargetDD.id) {
19580 * My goal is to be able to transparently determine if an object is
19581 * typeof DragDrop, and the exact subclass of DragDrop. typeof
19582 * returns "object", oDD.constructor.toString() always returns
19583 * "DragDrop" and not the name of the subclass. So for now it just
19584 * evaluates a well-known variable in DragDrop.
19585 * @method isTypeOfDD
19586 * @param {Object} the object to evaluate
19587 * @return {boolean} true if typeof oDD = DragDrop
19590 isTypeOfDD: function (oDD) {
19591 return (oDD && oDD.__ygDragDrop);
19595 * Utility function to determine if a given element has been
19596 * registered as a drag drop handle for the given Drag Drop object.
19598 * @param {String} id the element id to check
19599 * @return {boolean} true if this element is a DragDrop handle, false
19603 isHandle: function(sDDId, sHandleId) {
19604 return ( this.handleIds[sDDId] &&
19605 this.handleIds[sDDId][sHandleId] );
19609 * Returns the DragDrop instance for a given id
19610 * @method getDDById
19611 * @param {String} id the id of the DragDrop object
19612 * @return {DragDrop} the drag drop object, null if it is not found
19615 getDDById: function(id) {
19616 for (var i in this.ids) {
19617 if (this.ids[i][id]) {
19618 return this.ids[i][id];
19625 * Fired after a registered DragDrop object gets the mousedown event.
19626 * Sets up the events required to track the object being dragged
19627 * @method handleMouseDown
19628 * @param {Event} e the event
19629 * @param oDD the DragDrop object being dragged
19633 handleMouseDown: function(e, oDD) {
19635 Roo.QuickTips.disable();
19637 this.currentTarget = e.getTarget();
19639 this.dragCurrent = oDD;
19641 var el = oDD.getEl();
19643 // track start position
19644 this.startX = e.getPageX();
19645 this.startY = e.getPageY();
19647 this.deltaX = this.startX - el.offsetLeft;
19648 this.deltaY = this.startY - el.offsetTop;
19650 this.dragThreshMet = false;
19652 this.clickTimeout = setTimeout(
19654 var DDM = Roo.dd.DDM;
19655 DDM.startDrag(DDM.startX, DDM.startY);
19657 this.clickTimeThresh );
19661 * Fired when either the drag pixel threshol or the mousedown hold
19662 * time threshold has been met.
19663 * @method startDrag
19664 * @param x {int} the X position of the original mousedown
19665 * @param y {int} the Y position of the original mousedown
19668 startDrag: function(x, y) {
19669 clearTimeout(this.clickTimeout);
19670 if (this.dragCurrent) {
19671 this.dragCurrent.b4StartDrag(x, y);
19672 this.dragCurrent.startDrag(x, y);
19674 this.dragThreshMet = true;
19678 * Internal function to handle the mouseup event. Will be invoked
19679 * from the context of the document.
19680 * @method handleMouseUp
19681 * @param {Event} e the event
19685 handleMouseUp: function(e) {
19688 Roo.QuickTips.enable();
19690 if (! this.dragCurrent) {
19694 clearTimeout(this.clickTimeout);
19696 if (this.dragThreshMet) {
19697 this.fireEvents(e, true);
19707 * Utility to stop event propagation and event default, if these
19708 * features are turned on.
19709 * @method stopEvent
19710 * @param {Event} e the event as returned by this.getEvent()
19713 stopEvent: function(e){
19714 if(this.stopPropagation) {
19715 e.stopPropagation();
19718 if (this.preventDefault) {
19719 e.preventDefault();
19724 * Internal function to clean up event handlers after the drag
19725 * operation is complete
19727 * @param {Event} e the event
19731 stopDrag: function(e) {
19732 // Fire the drag end event for the item that was dragged
19733 if (this.dragCurrent) {
19734 if (this.dragThreshMet) {
19735 this.dragCurrent.b4EndDrag(e);
19736 this.dragCurrent.endDrag(e);
19739 this.dragCurrent.onMouseUp(e);
19742 this.dragCurrent = null;
19743 this.dragOvers = {};
19747 * Internal function to handle the mousemove event. Will be invoked
19748 * from the context of the html element.
19750 * @TODO figure out what we can do about mouse events lost when the
19751 * user drags objects beyond the window boundary. Currently we can
19752 * detect this in internet explorer by verifying that the mouse is
19753 * down during the mousemove event. Firefox doesn't give us the
19754 * button state on the mousemove event.
19755 * @method handleMouseMove
19756 * @param {Event} e the event
19760 handleMouseMove: function(e) {
19761 if (! this.dragCurrent) {
19765 // var button = e.which || e.button;
19767 // check for IE mouseup outside of page boundary
19768 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
19770 return this.handleMouseUp(e);
19773 if (!this.dragThreshMet) {
19774 var diffX = Math.abs(this.startX - e.getPageX());
19775 var diffY = Math.abs(this.startY - e.getPageY());
19776 if (diffX > this.clickPixelThresh ||
19777 diffY > this.clickPixelThresh) {
19778 this.startDrag(this.startX, this.startY);
19782 if (this.dragThreshMet) {
19783 this.dragCurrent.b4Drag(e);
19784 this.dragCurrent.onDrag(e);
19785 if(!this.dragCurrent.moveOnly){
19786 this.fireEvents(e, false);
19796 * Iterates over all of the DragDrop elements to find ones we are
19797 * hovering over or dropping on
19798 * @method fireEvents
19799 * @param {Event} e the event
19800 * @param {boolean} isDrop is this a drop op or a mouseover op?
19804 fireEvents: function(e, isDrop) {
19805 var dc = this.dragCurrent;
19807 // If the user did the mouse up outside of the window, we could
19808 // get here even though we have ended the drag.
19809 if (!dc || dc.isLocked()) {
19813 var pt = e.getPoint();
19815 // cache the previous dragOver array
19821 var enterEvts = [];
19823 // Check to see if the object(s) we were hovering over is no longer
19824 // being hovered over so we can fire the onDragOut event
19825 for (var i in this.dragOvers) {
19827 var ddo = this.dragOvers[i];
19829 if (! this.isTypeOfDD(ddo)) {
19833 if (! this.isOverTarget(pt, ddo, this.mode)) {
19834 outEvts.push( ddo );
19837 oldOvers[i] = true;
19838 delete this.dragOvers[i];
19841 for (var sGroup in dc.groups) {
19843 if ("string" != typeof sGroup) {
19847 for (i in this.ids[sGroup]) {
19848 var oDD = this.ids[sGroup][i];
19849 if (! this.isTypeOfDD(oDD)) {
19853 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
19854 if (this.isOverTarget(pt, oDD, this.mode)) {
19855 // look for drop interactions
19857 dropEvts.push( oDD );
19858 // look for drag enter and drag over interactions
19861 // initial drag over: dragEnter fires
19862 if (!oldOvers[oDD.id]) {
19863 enterEvts.push( oDD );
19864 // subsequent drag overs: dragOver fires
19866 overEvts.push( oDD );
19869 this.dragOvers[oDD.id] = oDD;
19877 if (outEvts.length) {
19878 dc.b4DragOut(e, outEvts);
19879 dc.onDragOut(e, outEvts);
19882 if (enterEvts.length) {
19883 dc.onDragEnter(e, enterEvts);
19886 if (overEvts.length) {
19887 dc.b4DragOver(e, overEvts);
19888 dc.onDragOver(e, overEvts);
19891 if (dropEvts.length) {
19892 dc.b4DragDrop(e, dropEvts);
19893 dc.onDragDrop(e, dropEvts);
19897 // fire dragout events
19899 for (i=0, len=outEvts.length; i<len; ++i) {
19900 dc.b4DragOut(e, outEvts[i].id);
19901 dc.onDragOut(e, outEvts[i].id);
19904 // fire enter events
19905 for (i=0,len=enterEvts.length; i<len; ++i) {
19906 // dc.b4DragEnter(e, oDD.id);
19907 dc.onDragEnter(e, enterEvts[i].id);
19910 // fire over events
19911 for (i=0,len=overEvts.length; i<len; ++i) {
19912 dc.b4DragOver(e, overEvts[i].id);
19913 dc.onDragOver(e, overEvts[i].id);
19916 // fire drop events
19917 for (i=0, len=dropEvts.length; i<len; ++i) {
19918 dc.b4DragDrop(e, dropEvts[i].id);
19919 dc.onDragDrop(e, dropEvts[i].id);
19924 // notify about a drop that did not find a target
19925 if (isDrop && !dropEvts.length) {
19926 dc.onInvalidDrop(e);
19932 * Helper function for getting the best match from the list of drag
19933 * and drop objects returned by the drag and drop events when we are
19934 * in INTERSECT mode. It returns either the first object that the
19935 * cursor is over, or the object that has the greatest overlap with
19936 * the dragged element.
19937 * @method getBestMatch
19938 * @param {DragDrop[]} dds The array of drag and drop objects
19940 * @return {DragDrop} The best single match
19943 getBestMatch: function(dds) {
19945 // Return null if the input is not what we expect
19946 //if (!dds || !dds.length || dds.length == 0) {
19948 // If there is only one item, it wins
19949 //} else if (dds.length == 1) {
19951 var len = dds.length;
19956 // Loop through the targeted items
19957 for (var i=0; i<len; ++i) {
19959 // If the cursor is over the object, it wins. If the
19960 // cursor is over multiple matches, the first one we come
19962 if (dd.cursorIsOver) {
19965 // Otherwise the object with the most overlap wins
19968 winner.overlap.getArea() < dd.overlap.getArea()) {
19979 * Refreshes the cache of the top-left and bottom-right points of the
19980 * drag and drop objects in the specified group(s). This is in the
19981 * format that is stored in the drag and drop instance, so typical
19984 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
19988 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
19990 * @TODO this really should be an indexed array. Alternatively this
19991 * method could accept both.
19992 * @method refreshCache
19993 * @param {Object} groups an associative array of groups to refresh
19996 refreshCache: function(groups) {
19997 for (var sGroup in groups) {
19998 if ("string" != typeof sGroup) {
20001 for (var i in this.ids[sGroup]) {
20002 var oDD = this.ids[sGroup][i];
20004 if (this.isTypeOfDD(oDD)) {
20005 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
20006 var loc = this.getLocation(oDD);
20008 this.locationCache[oDD.id] = loc;
20010 delete this.locationCache[oDD.id];
20011 // this will unregister the drag and drop object if
20012 // the element is not in a usable state
20021 * This checks to make sure an element exists and is in the DOM. The
20022 * main purpose is to handle cases where innerHTML is used to remove
20023 * drag and drop objects from the DOM. IE provides an 'unspecified
20024 * error' when trying to access the offsetParent of such an element
20026 * @param {HTMLElement} el the element to check
20027 * @return {boolean} true if the element looks usable
20030 verifyEl: function(el) {
20035 parent = el.offsetParent;
20038 parent = el.offsetParent;
20049 * Returns a Region object containing the drag and drop element's position
20050 * and size, including the padding configured for it
20051 * @method getLocation
20052 * @param {DragDrop} oDD the drag and drop object to get the
20054 * @return {Roo.lib.Region} a Region object representing the total area
20055 * the element occupies, including any padding
20056 * the instance is configured for.
20059 getLocation: function(oDD) {
20060 if (! this.isTypeOfDD(oDD)) {
20064 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
20067 pos= Roo.lib.Dom.getXY(el);
20075 x2 = x1 + el.offsetWidth;
20077 y2 = y1 + el.offsetHeight;
20079 t = y1 - oDD.padding[0];
20080 r = x2 + oDD.padding[1];
20081 b = y2 + oDD.padding[2];
20082 l = x1 - oDD.padding[3];
20084 return new Roo.lib.Region( t, r, b, l );
20088 * Checks the cursor location to see if it over the target
20089 * @method isOverTarget
20090 * @param {Roo.lib.Point} pt The point to evaluate
20091 * @param {DragDrop} oTarget the DragDrop object we are inspecting
20092 * @return {boolean} true if the mouse is over the target
20096 isOverTarget: function(pt, oTarget, intersect) {
20097 // use cache if available
20098 var loc = this.locationCache[oTarget.id];
20099 if (!loc || !this.useCache) {
20100 loc = this.getLocation(oTarget);
20101 this.locationCache[oTarget.id] = loc;
20109 oTarget.cursorIsOver = loc.contains( pt );
20111 // DragDrop is using this as a sanity check for the initial mousedown
20112 // in this case we are done. In POINT mode, if the drag obj has no
20113 // contraints, we are also done. Otherwise we need to evaluate the
20114 // location of the target as related to the actual location of the
20115 // dragged element.
20116 var dc = this.dragCurrent;
20117 if (!dc || !dc.getTargetCoord ||
20118 (!intersect && !dc.constrainX && !dc.constrainY)) {
20119 return oTarget.cursorIsOver;
20122 oTarget.overlap = null;
20124 // Get the current location of the drag element, this is the
20125 // location of the mouse event less the delta that represents
20126 // where the original mousedown happened on the element. We
20127 // need to consider constraints and ticks as well.
20128 var pos = dc.getTargetCoord(pt.x, pt.y);
20130 var el = dc.getDragEl();
20131 var curRegion = new Roo.lib.Region( pos.y,
20132 pos.x + el.offsetWidth,
20133 pos.y + el.offsetHeight,
20136 var overlap = curRegion.intersect(loc);
20139 oTarget.overlap = overlap;
20140 return (intersect) ? true : oTarget.cursorIsOver;
20147 * unload event handler
20148 * @method _onUnload
20152 _onUnload: function(e, me) {
20153 Roo.dd.DragDropMgr.unregAll();
20157 * Cleans up the drag and drop events and objects.
20162 unregAll: function() {
20164 if (this.dragCurrent) {
20166 this.dragCurrent = null;
20169 this._execOnAll("unreg", []);
20171 for (i in this.elementCache) {
20172 delete this.elementCache[i];
20175 this.elementCache = {};
20180 * A cache of DOM elements
20181 * @property elementCache
20188 * Get the wrapper for the DOM element specified
20189 * @method getElWrapper
20190 * @param {String} id the id of the element to get
20191 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
20193 * @deprecated This wrapper isn't that useful
20196 getElWrapper: function(id) {
20197 var oWrapper = this.elementCache[id];
20198 if (!oWrapper || !oWrapper.el) {
20199 oWrapper = this.elementCache[id] =
20200 new this.ElementWrapper(Roo.getDom(id));
20206 * Returns the actual DOM element
20207 * @method getElement
20208 * @param {String} id the id of the elment to get
20209 * @return {Object} The element
20210 * @deprecated use Roo.getDom instead
20213 getElement: function(id) {
20214 return Roo.getDom(id);
20218 * Returns the style property for the DOM element (i.e.,
20219 * document.getElById(id).style)
20221 * @param {String} id the id of the elment to get
20222 * @return {Object} The style property of the element
20223 * @deprecated use Roo.getDom instead
20226 getCss: function(id) {
20227 var el = Roo.getDom(id);
20228 return (el) ? el.style : null;
20232 * Inner class for cached elements
20233 * @class DragDropMgr.ElementWrapper
20238 ElementWrapper: function(el) {
20243 this.el = el || null;
20248 this.id = this.el && el.id;
20250 * A reference to the style property
20253 this.css = this.el && el.style;
20257 * Returns the X position of an html element
20259 * @param el the element for which to get the position
20260 * @return {int} the X coordinate
20262 * @deprecated use Roo.lib.Dom.getX instead
20265 getPosX: function(el) {
20266 return Roo.lib.Dom.getX(el);
20270 * Returns the Y position of an html element
20272 * @param el the element for which to get the position
20273 * @return {int} the Y coordinate
20274 * @deprecated use Roo.lib.Dom.getY instead
20277 getPosY: function(el) {
20278 return Roo.lib.Dom.getY(el);
20282 * Swap two nodes. In IE, we use the native method, for others we
20283 * emulate the IE behavior
20285 * @param n1 the first node to swap
20286 * @param n2 the other node to swap
20289 swapNode: function(n1, n2) {
20293 var p = n2.parentNode;
20294 var s = n2.nextSibling;
20297 p.insertBefore(n1, n2);
20298 } else if (n2 == n1.nextSibling) {
20299 p.insertBefore(n2, n1);
20301 n1.parentNode.replaceChild(n2, n1);
20302 p.insertBefore(n1, s);
20308 * Returns the current scroll position
20309 * @method getScroll
20313 getScroll: function () {
20314 var t, l, dde=document.documentElement, db=document.body;
20315 if (dde && (dde.scrollTop || dde.scrollLeft)) {
20317 l = dde.scrollLeft;
20324 return { top: t, left: l };
20328 * Returns the specified element style property
20330 * @param {HTMLElement} el the element
20331 * @param {string} styleProp the style property
20332 * @return {string} The value of the style property
20333 * @deprecated use Roo.lib.Dom.getStyle
20336 getStyle: function(el, styleProp) {
20337 return Roo.fly(el).getStyle(styleProp);
20341 * Gets the scrollTop
20342 * @method getScrollTop
20343 * @return {int} the document's scrollTop
20346 getScrollTop: function () { return this.getScroll().top; },
20349 * Gets the scrollLeft
20350 * @method getScrollLeft
20351 * @return {int} the document's scrollTop
20354 getScrollLeft: function () { return this.getScroll().left; },
20357 * Sets the x/y position of an element to the location of the
20360 * @param {HTMLElement} moveEl The element to move
20361 * @param {HTMLElement} targetEl The position reference element
20364 moveToEl: function (moveEl, targetEl) {
20365 var aCoord = Roo.lib.Dom.getXY(targetEl);
20366 Roo.lib.Dom.setXY(moveEl, aCoord);
20370 * Numeric array sort function
20371 * @method numericSort
20374 numericSort: function(a, b) { return (a - b); },
20378 * @property _timeoutCount
20385 * Trying to make the load order less important. Without this we get
20386 * an error if this file is loaded before the Event Utility.
20387 * @method _addListeners
20391 _addListeners: function() {
20392 var DDM = Roo.dd.DDM;
20393 if ( Roo.lib.Event && document ) {
20396 if (DDM._timeoutCount > 2000) {
20398 setTimeout(DDM._addListeners, 10);
20399 if (document && document.body) {
20400 DDM._timeoutCount += 1;
20407 * Recursively searches the immediate parent and all child nodes for
20408 * the handle element in order to determine wheter or not it was
20410 * @method handleWasClicked
20411 * @param node the html element to inspect
20414 handleWasClicked: function(node, id) {
20415 if (this.isHandle(id, node.id)) {
20418 // check to see if this is a text node child of the one we want
20419 var p = node.parentNode;
20422 if (this.isHandle(id, p.id)) {
20437 // shorter alias, save a few bytes
20438 Roo.dd.DDM = Roo.dd.DragDropMgr;
20439 Roo.dd.DDM._addListeners();
20443 * Ext JS Library 1.1.1
20444 * Copyright(c) 2006-2007, Ext JS, LLC.
20446 * Originally Released Under LGPL - original licence link has changed is not relivant.
20449 * <script type="text/javascript">
20454 * A DragDrop implementation where the linked element follows the
20455 * mouse cursor during a drag.
20456 * @extends Roo.dd.DragDrop
20458 * @param {String} id the id of the linked element
20459 * @param {String} sGroup the group of related DragDrop items
20460 * @param {object} config an object containing configurable attributes
20461 * Valid properties for DD:
20464 Roo.dd.DD = function(id, sGroup, config) {
20466 this.init(id, sGroup, config);
20470 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
20473 * When set to true, the utility automatically tries to scroll the browser
20474 * window wehn a drag and drop element is dragged near the viewport boundary.
20475 * Defaults to true.
20482 * Sets the pointer offset to the distance between the linked element's top
20483 * left corner and the location the element was clicked
20484 * @method autoOffset
20485 * @param {int} iPageX the X coordinate of the click
20486 * @param {int} iPageY the Y coordinate of the click
20488 autoOffset: function(iPageX, iPageY) {
20489 var x = iPageX - this.startPageX;
20490 var y = iPageY - this.startPageY;
20491 this.setDelta(x, y);
20495 * Sets the pointer offset. You can call this directly to force the
20496 * offset to be in a particular location (e.g., pass in 0,0 to set it
20497 * to the center of the object)
20499 * @param {int} iDeltaX the distance from the left
20500 * @param {int} iDeltaY the distance from the top
20502 setDelta: function(iDeltaX, iDeltaY) {
20503 this.deltaX = iDeltaX;
20504 this.deltaY = iDeltaY;
20508 * Sets the drag element to the location of the mousedown or click event,
20509 * maintaining the cursor location relative to the location on the element
20510 * that was clicked. Override this if you want to place the element in a
20511 * location other than where the cursor is.
20512 * @method setDragElPos
20513 * @param {int} iPageX the X coordinate of the mousedown or drag event
20514 * @param {int} iPageY the Y coordinate of the mousedown or drag event
20516 setDragElPos: function(iPageX, iPageY) {
20517 // the first time we do this, we are going to check to make sure
20518 // the element has css positioning
20520 var el = this.getDragEl();
20521 this.alignElWithMouse(el, iPageX, iPageY);
20525 * Sets the element to the location of the mousedown or click event,
20526 * maintaining the cursor location relative to the location on the element
20527 * that was clicked. Override this if you want to place the element in a
20528 * location other than where the cursor is.
20529 * @method alignElWithMouse
20530 * @param {HTMLElement} el the element to move
20531 * @param {int} iPageX the X coordinate of the mousedown or drag event
20532 * @param {int} iPageY the Y coordinate of the mousedown or drag event
20534 alignElWithMouse: function(el, iPageX, iPageY) {
20535 var oCoord = this.getTargetCoord(iPageX, iPageY);
20536 var fly = el.dom ? el : Roo.fly(el);
20537 if (!this.deltaSetXY) {
20538 var aCoord = [oCoord.x, oCoord.y];
20540 var newLeft = fly.getLeft(true);
20541 var newTop = fly.getTop(true);
20542 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
20544 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
20547 this.cachePosition(oCoord.x, oCoord.y);
20548 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
20553 * Saves the most recent position so that we can reset the constraints and
20554 * tick marks on-demand. We need to know this so that we can calculate the
20555 * number of pixels the element is offset from its original position.
20556 * @method cachePosition
20557 * @param iPageX the current x position (optional, this just makes it so we
20558 * don't have to look it up again)
20559 * @param iPageY the current y position (optional, this just makes it so we
20560 * don't have to look it up again)
20562 cachePosition: function(iPageX, iPageY) {
20564 this.lastPageX = iPageX;
20565 this.lastPageY = iPageY;
20567 var aCoord = Roo.lib.Dom.getXY(this.getEl());
20568 this.lastPageX = aCoord[0];
20569 this.lastPageY = aCoord[1];
20574 * Auto-scroll the window if the dragged object has been moved beyond the
20575 * visible window boundary.
20576 * @method autoScroll
20577 * @param {int} x the drag element's x position
20578 * @param {int} y the drag element's y position
20579 * @param {int} h the height of the drag element
20580 * @param {int} w the width of the drag element
20583 autoScroll: function(x, y, h, w) {
20586 // The client height
20587 var clientH = Roo.lib.Dom.getViewWidth();
20589 // The client width
20590 var clientW = Roo.lib.Dom.getViewHeight();
20592 // The amt scrolled down
20593 var st = this.DDM.getScrollTop();
20595 // The amt scrolled right
20596 var sl = this.DDM.getScrollLeft();
20598 // Location of the bottom of the element
20601 // Location of the right of the element
20604 // The distance from the cursor to the bottom of the visible area,
20605 // adjusted so that we don't scroll if the cursor is beyond the
20606 // element drag constraints
20607 var toBot = (clientH + st - y - this.deltaY);
20609 // The distance from the cursor to the right of the visible area
20610 var toRight = (clientW + sl - x - this.deltaX);
20613 // How close to the edge the cursor must be before we scroll
20614 // var thresh = (document.all) ? 100 : 40;
20617 // How many pixels to scroll per autoscroll op. This helps to reduce
20618 // clunky scrolling. IE is more sensitive about this ... it needs this
20619 // value to be higher.
20620 var scrAmt = (document.all) ? 80 : 30;
20622 // Scroll down if we are near the bottom of the visible page and the
20623 // obj extends below the crease
20624 if ( bot > clientH && toBot < thresh ) {
20625 window.scrollTo(sl, st + scrAmt);
20628 // Scroll up if the window is scrolled down and the top of the object
20629 // goes above the top border
20630 if ( y < st && st > 0 && y - st < thresh ) {
20631 window.scrollTo(sl, st - scrAmt);
20634 // Scroll right if the obj is beyond the right border and the cursor is
20635 // near the border.
20636 if ( right > clientW && toRight < thresh ) {
20637 window.scrollTo(sl + scrAmt, st);
20640 // Scroll left if the window has been scrolled to the right and the obj
20641 // extends past the left border
20642 if ( x < sl && sl > 0 && x - sl < thresh ) {
20643 window.scrollTo(sl - scrAmt, st);
20649 * Finds the location the element should be placed if we want to move
20650 * it to where the mouse location less the click offset would place us.
20651 * @method getTargetCoord
20652 * @param {int} iPageX the X coordinate of the click
20653 * @param {int} iPageY the Y coordinate of the click
20654 * @return an object that contains the coordinates (Object.x and Object.y)
20657 getTargetCoord: function(iPageX, iPageY) {
20660 var x = iPageX - this.deltaX;
20661 var y = iPageY - this.deltaY;
20663 if (this.constrainX) {
20664 if (x < this.minX) { x = this.minX; }
20665 if (x > this.maxX) { x = this.maxX; }
20668 if (this.constrainY) {
20669 if (y < this.minY) { y = this.minY; }
20670 if (y > this.maxY) { y = this.maxY; }
20673 x = this.getTick(x, this.xTicks);
20674 y = this.getTick(y, this.yTicks);
20681 * Sets up config options specific to this class. Overrides
20682 * Roo.dd.DragDrop, but all versions of this method through the
20683 * inheritance chain are called
20685 applyConfig: function() {
20686 Roo.dd.DD.superclass.applyConfig.call(this);
20687 this.scroll = (this.config.scroll !== false);
20691 * Event that fires prior to the onMouseDown event. Overrides
20694 b4MouseDown: function(e) {
20695 // this.resetConstraints();
20696 this.autoOffset(e.getPageX(),
20701 * Event that fires prior to the onDrag event. Overrides
20704 b4Drag: function(e) {
20705 this.setDragElPos(e.getPageX(),
20709 toString: function() {
20710 return ("DD " + this.id);
20713 //////////////////////////////////////////////////////////////////////////
20714 // Debugging ygDragDrop events that can be overridden
20715 //////////////////////////////////////////////////////////////////////////
20717 startDrag: function(x, y) {
20720 onDrag: function(e) {
20723 onDragEnter: function(e, id) {
20726 onDragOver: function(e, id) {
20729 onDragOut: function(e, id) {
20732 onDragDrop: function(e, id) {
20735 endDrag: function(e) {
20742 * Ext JS Library 1.1.1
20743 * Copyright(c) 2006-2007, Ext JS, LLC.
20745 * Originally Released Under LGPL - original licence link has changed is not relivant.
20748 * <script type="text/javascript">
20752 * @class Roo.dd.DDProxy
20753 * A DragDrop implementation that inserts an empty, bordered div into
20754 * the document that follows the cursor during drag operations. At the time of
20755 * the click, the frame div is resized to the dimensions of the linked html
20756 * element, and moved to the exact location of the linked element.
20758 * References to the "frame" element refer to the single proxy element that
20759 * was created to be dragged in place of all DDProxy elements on the
20762 * @extends Roo.dd.DD
20764 * @param {String} id the id of the linked html element
20765 * @param {String} sGroup the group of related DragDrop objects
20766 * @param {object} config an object containing configurable attributes
20767 * Valid properties for DDProxy in addition to those in DragDrop:
20768 * resizeFrame, centerFrame, dragElId
20770 Roo.dd.DDProxy = function(id, sGroup, config) {
20772 this.init(id, sGroup, config);
20778 * The default drag frame div id
20779 * @property Roo.dd.DDProxy.dragElId
20783 Roo.dd.DDProxy.dragElId = "ygddfdiv";
20785 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
20788 * By default we resize the drag frame to be the same size as the element
20789 * we want to drag (this is to get the frame effect). We can turn it off
20790 * if we want a different behavior.
20791 * @property resizeFrame
20797 * By default the frame is positioned exactly where the drag element is, so
20798 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
20799 * you do not have constraints on the obj is to have the drag frame centered
20800 * around the cursor. Set centerFrame to true for this effect.
20801 * @property centerFrame
20804 centerFrame: false,
20807 * Creates the proxy element if it does not yet exist
20808 * @method createFrame
20810 createFrame: function() {
20812 var body = document.body;
20814 if (!body || !body.firstChild) {
20815 setTimeout( function() { self.createFrame(); }, 50 );
20819 var div = this.getDragEl();
20822 div = document.createElement("div");
20823 div.id = this.dragElId;
20826 s.position = "absolute";
20827 s.visibility = "hidden";
20829 s.border = "2px solid #aaa";
20832 // appendChild can blow up IE if invoked prior to the window load event
20833 // while rendering a table. It is possible there are other scenarios
20834 // that would cause this to happen as well.
20835 body.insertBefore(div, body.firstChild);
20840 * Initialization for the drag frame element. Must be called in the
20841 * constructor of all subclasses
20842 * @method initFrame
20844 initFrame: function() {
20845 this.createFrame();
20848 applyConfig: function() {
20849 Roo.dd.DDProxy.superclass.applyConfig.call(this);
20851 this.resizeFrame = (this.config.resizeFrame !== false);
20852 this.centerFrame = (this.config.centerFrame);
20853 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
20857 * Resizes the drag frame to the dimensions of the clicked object, positions
20858 * it over the object, and finally displays it
20859 * @method showFrame
20860 * @param {int} iPageX X click position
20861 * @param {int} iPageY Y click position
20864 showFrame: function(iPageX, iPageY) {
20865 var el = this.getEl();
20866 var dragEl = this.getDragEl();
20867 var s = dragEl.style;
20869 this._resizeProxy();
20871 if (this.centerFrame) {
20872 this.setDelta( Math.round(parseInt(s.width, 10)/2),
20873 Math.round(parseInt(s.height, 10)/2) );
20876 this.setDragElPos(iPageX, iPageY);
20878 Roo.fly(dragEl).show();
20882 * The proxy is automatically resized to the dimensions of the linked
20883 * element when a drag is initiated, unless resizeFrame is set to false
20884 * @method _resizeProxy
20887 _resizeProxy: function() {
20888 if (this.resizeFrame) {
20889 var el = this.getEl();
20890 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
20894 // overrides Roo.dd.DragDrop
20895 b4MouseDown: function(e) {
20896 var x = e.getPageX();
20897 var y = e.getPageY();
20898 this.autoOffset(x, y);
20899 this.setDragElPos(x, y);
20902 // overrides Roo.dd.DragDrop
20903 b4StartDrag: function(x, y) {
20904 // show the drag frame
20905 this.showFrame(x, y);
20908 // overrides Roo.dd.DragDrop
20909 b4EndDrag: function(e) {
20910 Roo.fly(this.getDragEl()).hide();
20913 // overrides Roo.dd.DragDrop
20914 // By default we try to move the element to the last location of the frame.
20915 // This is so that the default behavior mirrors that of Roo.dd.DD.
20916 endDrag: function(e) {
20918 var lel = this.getEl();
20919 var del = this.getDragEl();
20921 // Show the drag frame briefly so we can get its position
20922 del.style.visibility = "";
20925 // Hide the linked element before the move to get around a Safari
20927 lel.style.visibility = "hidden";
20928 Roo.dd.DDM.moveToEl(lel, del);
20929 del.style.visibility = "hidden";
20930 lel.style.visibility = "";
20935 beforeMove : function(){
20939 afterDrag : function(){
20943 toString: function() {
20944 return ("DDProxy " + this.id);
20950 * Ext JS Library 1.1.1
20951 * Copyright(c) 2006-2007, Ext JS, LLC.
20953 * Originally Released Under LGPL - original licence link has changed is not relivant.
20956 * <script type="text/javascript">
20960 * @class Roo.dd.DDTarget
20961 * A DragDrop implementation that does not move, but can be a drop
20962 * target. You would get the same result by simply omitting implementation
20963 * for the event callbacks, but this way we reduce the processing cost of the
20964 * event listener and the callbacks.
20965 * @extends Roo.dd.DragDrop
20967 * @param {String} id the id of the element that is a drop target
20968 * @param {String} sGroup the group of related DragDrop objects
20969 * @param {object} config an object containing configurable attributes
20970 * Valid properties for DDTarget in addition to those in
20974 Roo.dd.DDTarget = function(id, sGroup, config) {
20976 this.initTarget(id, sGroup, config);
20978 if (config.listeners || config.events) {
20979 Roo.dd.DragDrop.superclass.constructor.call(this, {
20980 listeners : config.listeners || {},
20981 events : config.events || {}
20986 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
20987 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
20988 toString: function() {
20989 return ("DDTarget " + this.id);
20994 * Ext JS Library 1.1.1
20995 * Copyright(c) 2006-2007, Ext JS, LLC.
20997 * Originally Released Under LGPL - original licence link has changed is not relivant.
21000 * <script type="text/javascript">
21005 * @class Roo.dd.ScrollManager
21006 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
21007 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
21010 Roo.dd.ScrollManager = function(){
21011 var ddm = Roo.dd.DragDropMgr;
21018 var onStop = function(e){
21023 var triggerRefresh = function(){
21024 if(ddm.dragCurrent){
21025 ddm.refreshCache(ddm.dragCurrent.groups);
21029 var doScroll = function(){
21030 if(ddm.dragCurrent){
21031 var dds = Roo.dd.ScrollManager;
21033 if(proc.el.scroll(proc.dir, dds.increment)){
21037 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
21042 var clearProc = function(){
21044 clearInterval(proc.id);
21051 var startProc = function(el, dir){
21052 Roo.log('scroll startproc');
21056 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
21059 var onFire = function(e, isDrop){
21061 if(isDrop || !ddm.dragCurrent){ return; }
21062 var dds = Roo.dd.ScrollManager;
21063 if(!dragEl || dragEl != ddm.dragCurrent){
21064 dragEl = ddm.dragCurrent;
21065 // refresh regions on drag start
21066 dds.refreshCache();
21069 var xy = Roo.lib.Event.getXY(e);
21070 var pt = new Roo.lib.Point(xy[0], xy[1]);
21071 for(var id in els){
21072 var el = els[id], r = el._region;
21073 if(r && r.contains(pt) && el.isScrollable()){
21074 if(r.bottom - pt.y <= dds.thresh){
21076 startProc(el, "down");
21079 }else if(r.right - pt.x <= dds.thresh){
21081 startProc(el, "left");
21084 }else if(pt.y - r.top <= dds.thresh){
21086 startProc(el, "up");
21089 }else if(pt.x - r.left <= dds.thresh){
21091 startProc(el, "right");
21100 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
21101 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
21105 * Registers new overflow element(s) to auto scroll
21106 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
21108 register : function(el){
21109 if(el instanceof Array){
21110 for(var i = 0, len = el.length; i < len; i++) {
21111 this.register(el[i]);
21117 Roo.dd.ScrollManager.els = els;
21121 * Unregisters overflow element(s) so they are no longer scrolled
21122 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
21124 unregister : function(el){
21125 if(el instanceof Array){
21126 for(var i = 0, len = el.length; i < len; i++) {
21127 this.unregister(el[i]);
21136 * The number of pixels from the edge of a container the pointer needs to be to
21137 * trigger scrolling (defaults to 25)
21143 * The number of pixels to scroll in each scroll increment (defaults to 50)
21149 * The frequency of scrolls in milliseconds (defaults to 500)
21155 * True to animate the scroll (defaults to true)
21161 * The animation duration in seconds -
21162 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
21168 * Manually trigger a cache refresh.
21170 refreshCache : function(){
21171 for(var id in els){
21172 if(typeof els[id] == 'object'){ // for people extending the object prototype
21173 els[id]._region = els[id].getRegion();
21180 * Ext JS Library 1.1.1
21181 * Copyright(c) 2006-2007, Ext JS, LLC.
21183 * Originally Released Under LGPL - original licence link has changed is not relivant.
21186 * <script type="text/javascript">
21191 * @class Roo.dd.Registry
21192 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
21193 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
21196 Roo.dd.Registry = function(){
21199 var autoIdSeed = 0;
21201 var getId = function(el, autogen){
21202 if(typeof el == "string"){
21206 if(!id && autogen !== false){
21207 id = "roodd-" + (++autoIdSeed);
21215 * Register a drag drop element
21216 * @param {String|HTMLElement} element The id or DOM node to register
21217 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
21218 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
21219 * knows how to interpret, plus there are some specific properties known to the Registry that should be
21220 * populated in the data object (if applicable):
21222 Value Description<br />
21223 --------- ------------------------------------------<br />
21224 handles Array of DOM nodes that trigger dragging<br />
21225 for the element being registered<br />
21226 isHandle True if the element passed in triggers<br />
21227 dragging itself, else false
21230 register : function(el, data){
21232 if(typeof el == "string"){
21233 el = document.getElementById(el);
21236 elements[getId(el)] = data;
21237 if(data.isHandle !== false){
21238 handles[data.ddel.id] = data;
21241 var hs = data.handles;
21242 for(var i = 0, len = hs.length; i < len; i++){
21243 handles[getId(hs[i])] = data;
21249 * Unregister a drag drop element
21250 * @param {String|HTMLElement} element The id or DOM node to unregister
21252 unregister : function(el){
21253 var id = getId(el, false);
21254 var data = elements[id];
21256 delete elements[id];
21258 var hs = data.handles;
21259 for(var i = 0, len = hs.length; i < len; i++){
21260 delete handles[getId(hs[i], false)];
21267 * Returns the handle registered for a DOM Node by id
21268 * @param {String|HTMLElement} id The DOM node or id to look up
21269 * @return {Object} handle The custom handle data
21271 getHandle : function(id){
21272 if(typeof id != "string"){ // must be element?
21275 return handles[id];
21279 * Returns the handle that is registered for the DOM node that is the target of the event
21280 * @param {Event} e The event
21281 * @return {Object} handle The custom handle data
21283 getHandleFromEvent : function(e){
21284 var t = Roo.lib.Event.getTarget(e);
21285 return t ? handles[t.id] : null;
21289 * Returns a custom data object that is registered for a DOM node by id
21290 * @param {String|HTMLElement} id The DOM node or id to look up
21291 * @return {Object} data The custom data
21293 getTarget : function(id){
21294 if(typeof id != "string"){ // must be element?
21297 return elements[id];
21301 * Returns a custom data object that is registered for the DOM node that is the target of the event
21302 * @param {Event} e The event
21303 * @return {Object} data The custom data
21305 getTargetFromEvent : function(e){
21306 var t = Roo.lib.Event.getTarget(e);
21307 return t ? elements[t.id] || handles[t.id] : null;
21312 * Ext JS Library 1.1.1
21313 * Copyright(c) 2006-2007, Ext JS, LLC.
21315 * Originally Released Under LGPL - original licence link has changed is not relivant.
21318 * <script type="text/javascript">
21323 * @class Roo.dd.StatusProxy
21324 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
21325 * default drag proxy used by all Roo.dd components.
21327 * @param {Object} config
21329 Roo.dd.StatusProxy = function(config){
21330 Roo.apply(this, config);
21331 this.id = this.id || Roo.id();
21332 this.el = new Roo.Layer({
21334 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
21335 {tag: "div", cls: "x-dd-drop-icon"},
21336 {tag: "div", cls: "x-dd-drag-ghost"}
21339 shadow: !config || config.shadow !== false
21341 this.ghost = Roo.get(this.el.dom.childNodes[1]);
21342 this.dropStatus = this.dropNotAllowed;
21345 Roo.dd.StatusProxy.prototype = {
21347 * @cfg {String} dropAllowed
21348 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
21350 dropAllowed : "x-dd-drop-ok",
21352 * @cfg {String} dropNotAllowed
21353 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
21355 dropNotAllowed : "x-dd-drop-nodrop",
21358 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
21359 * over the current target element.
21360 * @param {String} cssClass The css class for the new drop status indicator image
21362 setStatus : function(cssClass){
21363 cssClass = cssClass || this.dropNotAllowed;
21364 if(this.dropStatus != cssClass){
21365 this.el.replaceClass(this.dropStatus, cssClass);
21366 this.dropStatus = cssClass;
21371 * Resets the status indicator to the default dropNotAllowed value
21372 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
21374 reset : function(clearGhost){
21375 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
21376 this.dropStatus = this.dropNotAllowed;
21378 this.ghost.update("");
21383 * Updates the contents of the ghost element
21384 * @param {String} html The html that will replace the current innerHTML of the ghost element
21386 update : function(html){
21387 if(typeof html == "string"){
21388 this.ghost.update(html);
21390 this.ghost.update("");
21391 html.style.margin = "0";
21392 this.ghost.dom.appendChild(html);
21394 // ensure float = none set?? cant remember why though.
21395 var el = this.ghost.dom.firstChild;
21397 Roo.fly(el).setStyle('float', 'none');
21402 * Returns the underlying proxy {@link Roo.Layer}
21403 * @return {Roo.Layer} el
21405 getEl : function(){
21410 * Returns the ghost element
21411 * @return {Roo.Element} el
21413 getGhost : function(){
21419 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
21421 hide : function(clear){
21429 * Stops the repair animation if it's currently running
21432 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
21438 * Displays this proxy
21445 * Force the Layer to sync its shadow and shim positions to the element
21452 * Causes the proxy to return to its position of origin via an animation. Should be called after an
21453 * invalid drop operation by the item being dragged.
21454 * @param {Array} xy The XY position of the element ([x, y])
21455 * @param {Function} callback The function to call after the repair is complete
21456 * @param {Object} scope The scope in which to execute the callback
21458 repair : function(xy, callback, scope){
21459 this.callback = callback;
21460 this.scope = scope;
21461 if(xy && this.animRepair !== false){
21462 this.el.addClass("x-dd-drag-repair");
21463 this.el.hideUnders(true);
21464 this.anim = this.el.shift({
21465 duration: this.repairDuration || .5,
21469 callback: this.afterRepair,
21473 this.afterRepair();
21478 afterRepair : function(){
21480 if(typeof this.callback == "function"){
21481 this.callback.call(this.scope || this);
21483 this.callback = null;
21488 * Ext JS Library 1.1.1
21489 * Copyright(c) 2006-2007, Ext JS, LLC.
21491 * Originally Released Under LGPL - original licence link has changed is not relivant.
21494 * <script type="text/javascript">
21498 * @class Roo.dd.DragSource
21499 * @extends Roo.dd.DDProxy
21500 * A simple class that provides the basic implementation needed to make any element draggable.
21502 * @param {String/HTMLElement/Element} el The container element
21503 * @param {Object} config
21505 Roo.dd.DragSource = function(el, config){
21506 this.el = Roo.get(el);
21507 this.dragData = {};
21509 Roo.apply(this, config);
21512 this.proxy = new Roo.dd.StatusProxy();
21515 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
21516 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
21518 this.dragging = false;
21521 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
21523 * @cfg {String} dropAllowed
21524 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
21526 dropAllowed : "x-dd-drop-ok",
21528 * @cfg {String} dropNotAllowed
21529 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
21531 dropNotAllowed : "x-dd-drop-nodrop",
21534 * Returns the data object associated with this drag source
21535 * @return {Object} data An object containing arbitrary data
21537 getDragData : function(e){
21538 return this.dragData;
21542 onDragEnter : function(e, id){
21543 var target = Roo.dd.DragDropMgr.getDDById(id);
21544 this.cachedTarget = target;
21545 if(this.beforeDragEnter(target, e, id) !== false){
21546 if(target.isNotifyTarget){
21547 var status = target.notifyEnter(this, e, this.dragData);
21548 this.proxy.setStatus(status);
21550 this.proxy.setStatus(this.dropAllowed);
21553 if(this.afterDragEnter){
21555 * An empty function by default, but provided so that you can perform a custom action
21556 * when the dragged item enters the drop target by providing an implementation.
21557 * @param {Roo.dd.DragDrop} target The drop target
21558 * @param {Event} e The event object
21559 * @param {String} id The id of the dragged element
21560 * @method afterDragEnter
21562 this.afterDragEnter(target, e, id);
21568 * An empty function by default, but provided so that you can perform a custom action
21569 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
21570 * @param {Roo.dd.DragDrop} target The drop target
21571 * @param {Event} e The event object
21572 * @param {String} id The id of the dragged element
21573 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
21575 beforeDragEnter : function(target, e, id){
21580 alignElWithMouse: function() {
21581 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
21586 onDragOver : function(e, id){
21587 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
21588 if(this.beforeDragOver(target, e, id) !== false){
21589 if(target.isNotifyTarget){
21590 var status = target.notifyOver(this, e, this.dragData);
21591 this.proxy.setStatus(status);
21594 if(this.afterDragOver){
21596 * An empty function by default, but provided so that you can perform a custom action
21597 * while the dragged item is over the drop target by providing an implementation.
21598 * @param {Roo.dd.DragDrop} target The drop target
21599 * @param {Event} e The event object
21600 * @param {String} id The id of the dragged element
21601 * @method afterDragOver
21603 this.afterDragOver(target, e, id);
21609 * An empty function by default, but provided so that you can perform a custom action
21610 * while the dragged item is over the drop target and optionally cancel the onDragOver.
21611 * @param {Roo.dd.DragDrop} target The drop target
21612 * @param {Event} e The event object
21613 * @param {String} id The id of the dragged element
21614 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
21616 beforeDragOver : function(target, e, id){
21621 onDragOut : function(e, id){
21622 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
21623 if(this.beforeDragOut(target, e, id) !== false){
21624 if(target.isNotifyTarget){
21625 target.notifyOut(this, e, this.dragData);
21627 this.proxy.reset();
21628 if(this.afterDragOut){
21630 * An empty function by default, but provided so that you can perform a custom action
21631 * after the dragged item is dragged out of the target without dropping.
21632 * @param {Roo.dd.DragDrop} target The drop target
21633 * @param {Event} e The event object
21634 * @param {String} id The id of the dragged element
21635 * @method afterDragOut
21637 this.afterDragOut(target, e, id);
21640 this.cachedTarget = null;
21644 * An empty function by default, but provided so that you can perform a custom action before the dragged
21645 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
21646 * @param {Roo.dd.DragDrop} target The drop target
21647 * @param {Event} e The event object
21648 * @param {String} id The id of the dragged element
21649 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
21651 beforeDragOut : function(target, e, id){
21656 onDragDrop : function(e, id){
21657 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
21658 if(this.beforeDragDrop(target, e, id) !== false){
21659 if(target.isNotifyTarget){
21660 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
21661 this.onValidDrop(target, e, id);
21663 this.onInvalidDrop(target, e, id);
21666 this.onValidDrop(target, e, id);
21669 if(this.afterDragDrop){
21671 * An empty function by default, but provided so that you can perform a custom action
21672 * after a valid drag drop has occurred by providing an implementation.
21673 * @param {Roo.dd.DragDrop} target The drop target
21674 * @param {Event} e The event object
21675 * @param {String} id The id of the dropped element
21676 * @method afterDragDrop
21678 this.afterDragDrop(target, e, id);
21681 delete this.cachedTarget;
21685 * An empty function by default, but provided so that you can perform a custom action before the dragged
21686 * item is dropped onto the target and optionally cancel the onDragDrop.
21687 * @param {Roo.dd.DragDrop} target The drop target
21688 * @param {Event} e The event object
21689 * @param {String} id The id of the dragged element
21690 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
21692 beforeDragDrop : function(target, e, id){
21697 onValidDrop : function(target, e, id){
21699 if(this.afterValidDrop){
21701 * An empty function by default, but provided so that you can perform a custom action
21702 * after a valid drop has occurred by providing an implementation.
21703 * @param {Object} target The target DD
21704 * @param {Event} e The event object
21705 * @param {String} id The id of the dropped element
21706 * @method afterInvalidDrop
21708 this.afterValidDrop(target, e, id);
21713 getRepairXY : function(e, data){
21714 return this.el.getXY();
21718 onInvalidDrop : function(target, e, id){
21719 this.beforeInvalidDrop(target, e, id);
21720 if(this.cachedTarget){
21721 if(this.cachedTarget.isNotifyTarget){
21722 this.cachedTarget.notifyOut(this, e, this.dragData);
21724 this.cacheTarget = null;
21726 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
21728 if(this.afterInvalidDrop){
21730 * An empty function by default, but provided so that you can perform a custom action
21731 * after an invalid drop has occurred by providing an implementation.
21732 * @param {Event} e The event object
21733 * @param {String} id The id of the dropped element
21734 * @method afterInvalidDrop
21736 this.afterInvalidDrop(e, id);
21741 afterRepair : function(){
21743 this.el.highlight(this.hlColor || "c3daf9");
21745 this.dragging = false;
21749 * An empty function by default, but provided so that you can perform a custom action after an invalid
21750 * drop has occurred.
21751 * @param {Roo.dd.DragDrop} target The drop target
21752 * @param {Event} e The event object
21753 * @param {String} id The id of the dragged element
21754 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
21756 beforeInvalidDrop : function(target, e, id){
21761 handleMouseDown : function(e){
21762 if(this.dragging) {
21765 var data = this.getDragData(e);
21766 if(data && this.onBeforeDrag(data, e) !== false){
21767 this.dragData = data;
21769 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
21774 * An empty function by default, but provided so that you can perform a custom action before the initial
21775 * drag event begins and optionally cancel it.
21776 * @param {Object} data An object containing arbitrary data to be shared with drop targets
21777 * @param {Event} e The event object
21778 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
21780 onBeforeDrag : function(data, e){
21785 * An empty function by default, but provided so that you can perform a custom action once the initial
21786 * drag event has begun. The drag cannot be canceled from this function.
21787 * @param {Number} x The x position of the click on the dragged object
21788 * @param {Number} y The y position of the click on the dragged object
21790 onStartDrag : Roo.emptyFn,
21792 // private - YUI override
21793 startDrag : function(x, y){
21794 this.proxy.reset();
21795 this.dragging = true;
21796 this.proxy.update("");
21797 this.onInitDrag(x, y);
21802 onInitDrag : function(x, y){
21803 var clone = this.el.dom.cloneNode(true);
21804 clone.id = Roo.id(); // prevent duplicate ids
21805 this.proxy.update(clone);
21806 this.onStartDrag(x, y);
21811 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
21812 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
21814 getProxy : function(){
21819 * Hides the drag source's {@link Roo.dd.StatusProxy}
21821 hideProxy : function(){
21823 this.proxy.reset(true);
21824 this.dragging = false;
21828 triggerCacheRefresh : function(){
21829 Roo.dd.DDM.refreshCache(this.groups);
21832 // private - override to prevent hiding
21833 b4EndDrag: function(e) {
21836 // private - override to prevent moving
21837 endDrag : function(e){
21838 this.onEndDrag(this.dragData, e);
21842 onEndDrag : function(data, e){
21845 // private - pin to cursor
21846 autoOffset : function(x, y) {
21847 this.setDelta(-12, -20);
21851 * Ext JS Library 1.1.1
21852 * Copyright(c) 2006-2007, Ext JS, LLC.
21854 * Originally Released Under LGPL - original licence link has changed is not relivant.
21857 * <script type="text/javascript">
21862 * @class Roo.dd.DropTarget
21863 * @extends Roo.dd.DDTarget
21864 * A simple class that provides the basic implementation needed to make any element a drop target that can have
21865 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
21867 * @param {String/HTMLElement/Element} el The container element
21868 * @param {Object} config
21870 Roo.dd.DropTarget = function(el, config){
21871 this.el = Roo.get(el);
21873 var listeners = false; ;
21874 if (config && config.listeners) {
21875 listeners= config.listeners;
21876 delete config.listeners;
21878 Roo.apply(this, config);
21880 if(this.containerScroll){
21881 Roo.dd.ScrollManager.register(this.el);
21885 * @scope Roo.dd.DropTarget
21890 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
21891 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
21892 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
21894 * IMPORTANT : it should set this.overClass and this.dropAllowed
21896 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
21897 * @param {Event} e The event
21898 * @param {Object} data An object containing arbitrary data supplied by the drag source
21904 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
21905 * This method will be called on every mouse movement while the drag source is over the drop target.
21906 * This default implementation simply returns the dropAllowed config value.
21908 * IMPORTANT : it should set this.dropAllowed
21910 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
21911 * @param {Event} e The event
21912 * @param {Object} data An object containing arbitrary data supplied by the drag source
21918 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
21919 * out of the target without dropping. This default implementation simply removes the CSS class specified by
21920 * overClass (if any) from the drop element.
21922 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
21923 * @param {Event} e The event
21924 * @param {Object} data An object containing arbitrary data supplied by the drag source
21930 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
21931 * been dropped on it. This method has no default implementation and returns false, so you must provide an
21932 * implementation that does something to process the drop event and returns true so that the drag source's
21933 * repair action does not run.
21935 * IMPORTANT : it should set this.success
21937 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
21938 * @param {Event} e The event
21939 * @param {Object} data An object containing arbitrary data supplied by the drag source
21945 Roo.dd.DropTarget.superclass.constructor.call( this,
21947 this.ddGroup || this.group,
21950 listeners : listeners || {}
21958 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
21960 * @cfg {String} overClass
21961 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
21964 * @cfg {String} ddGroup
21965 * The drag drop group to handle drop events for
21969 * @cfg {String} dropAllowed
21970 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
21972 dropAllowed : "x-dd-drop-ok",
21974 * @cfg {String} dropNotAllowed
21975 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
21977 dropNotAllowed : "x-dd-drop-nodrop",
21979 * @cfg {boolean} success
21980 * set this after drop listener..
21984 * @cfg {boolean|String} valid true/false or string (ok-add/ok-sub/ok/nodrop)
21985 * if the drop point is valid for over/enter..
21992 isNotifyTarget : true,
21997 notifyEnter : function(dd, e, data)
22000 this.fireEvent('enter', dd, e, data);
22001 if(this.overClass){
22002 this.el.addClass(this.overClass);
22004 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
22005 this.valid ? this.dropAllowed : this.dropNotAllowed
22012 notifyOver : function(dd, e, data)
22015 this.fireEvent('over', dd, e, data);
22016 return typeof(this.valid) == 'string' ? 'x-dd-drop-' + this.valid : (
22017 this.valid ? this.dropAllowed : this.dropNotAllowed
22024 notifyOut : function(dd, e, data)
22026 this.fireEvent('out', dd, e, data);
22027 if(this.overClass){
22028 this.el.removeClass(this.overClass);
22035 notifyDrop : function(dd, e, data)
22037 this.success = false;
22038 this.fireEvent('drop', dd, e, data);
22039 return this.success;
22043 * Ext JS Library 1.1.1
22044 * Copyright(c) 2006-2007, Ext JS, LLC.
22046 * Originally Released Under LGPL - original licence link has changed is not relivant.
22049 * <script type="text/javascript">
22054 * @class Roo.dd.DragZone
22055 * @extends Roo.dd.DragSource
22056 * This class provides a container DD instance that proxies for multiple child node sources.<br />
22057 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
22059 * @param {String/HTMLElement/Element} el The container element
22060 * @param {Object} config
22062 Roo.dd.DragZone = function(el, config){
22063 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
22064 if(this.containerScroll){
22065 Roo.dd.ScrollManager.register(this.el);
22069 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
22071 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
22072 * for auto scrolling during drag operations.
22075 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
22076 * method after a failed drop (defaults to "c3daf9" - light blue)
22080 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
22081 * for a valid target to drag based on the mouse down. Override this method
22082 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
22083 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
22084 * @param {EventObject} e The mouse down event
22085 * @return {Object} The dragData
22087 getDragData : function(e){
22088 return Roo.dd.Registry.getHandleFromEvent(e);
22092 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
22093 * this.dragData.ddel
22094 * @param {Number} x The x position of the click on the dragged object
22095 * @param {Number} y The y position of the click on the dragged object
22096 * @return {Boolean} true to continue the drag, false to cancel
22098 onInitDrag : function(x, y){
22099 this.proxy.update(this.dragData.ddel.cloneNode(true));
22100 this.onStartDrag(x, y);
22105 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
22107 afterRepair : function(){
22109 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
22111 this.dragging = false;
22115 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
22116 * the XY of this.dragData.ddel
22117 * @param {EventObject} e The mouse up event
22118 * @return {Array} The xy location (e.g. [100, 200])
22120 getRepairXY : function(e){
22121 return Roo.Element.fly(this.dragData.ddel).getXY();
22125 * Ext JS Library 1.1.1
22126 * Copyright(c) 2006-2007, Ext JS, LLC.
22128 * Originally Released Under LGPL - original licence link has changed is not relivant.
22131 * <script type="text/javascript">
22134 * @class Roo.dd.DropZone
22135 * @extends Roo.dd.DropTarget
22136 * This class provides a container DD instance that proxies for multiple child node targets.<br />
22137 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
22139 * @param {String/HTMLElement/Element} el The container element
22140 * @param {Object} config
22142 Roo.dd.DropZone = function(el, config){
22143 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
22146 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
22148 * Returns a custom data object associated with the DOM node that is the target of the event. By default
22149 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
22150 * provide your own custom lookup.
22151 * @param {Event} e The event
22152 * @return {Object} data The custom data
22154 getTargetFromEvent : function(e){
22155 return Roo.dd.Registry.getTargetFromEvent(e);
22159 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
22160 * that it has registered. This method has no default implementation and should be overridden to provide
22161 * node-specific processing if necessary.
22162 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
22163 * {@link #getTargetFromEvent} for this node)
22164 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22165 * @param {Event} e The event
22166 * @param {Object} data An object containing arbitrary data supplied by the drag source
22168 onNodeEnter : function(n, dd, e, data){
22173 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
22174 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
22175 * overridden to provide the proper feedback.
22176 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
22177 * {@link #getTargetFromEvent} for this node)
22178 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22179 * @param {Event} e The event
22180 * @param {Object} data An object containing arbitrary data supplied by the drag source
22181 * @return {String} status The CSS class that communicates the drop status back to the source so that the
22182 * underlying {@link Roo.dd.StatusProxy} can be updated
22184 onNodeOver : function(n, dd, e, data){
22185 return this.dropAllowed;
22189 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
22190 * the drop node without dropping. This method has no default implementation and should be overridden to provide
22191 * node-specific processing if necessary.
22192 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
22193 * {@link #getTargetFromEvent} for this node)
22194 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22195 * @param {Event} e The event
22196 * @param {Object} data An object containing arbitrary data supplied by the drag source
22198 onNodeOut : function(n, dd, e, data){
22203 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
22204 * the drop node. The default implementation returns false, so it should be overridden to provide the
22205 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
22206 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
22207 * {@link #getTargetFromEvent} for this node)
22208 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22209 * @param {Event} e The event
22210 * @param {Object} data An object containing arbitrary data supplied by the drag source
22211 * @return {Boolean} True if the drop was valid, else false
22213 onNodeDrop : function(n, dd, e, data){
22218 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
22219 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
22220 * it should be overridden to provide the proper feedback if necessary.
22221 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22222 * @param {Event} e The event
22223 * @param {Object} data An object containing arbitrary data supplied by the drag source
22224 * @return {String} status The CSS class that communicates the drop status back to the source so that the
22225 * underlying {@link Roo.dd.StatusProxy} can be updated
22227 onContainerOver : function(dd, e, data){
22228 return this.dropNotAllowed;
22232 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
22233 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
22234 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
22235 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
22236 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22237 * @param {Event} e The event
22238 * @param {Object} data An object containing arbitrary data supplied by the drag source
22239 * @return {Boolean} True if the drop was valid, else false
22241 onContainerDrop : function(dd, e, data){
22246 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
22247 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
22248 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
22249 * you should override this method and provide a custom implementation.
22250 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22251 * @param {Event} e The event
22252 * @param {Object} data An object containing arbitrary data supplied by the drag source
22253 * @return {String} status The CSS class that communicates the drop status back to the source so that the
22254 * underlying {@link Roo.dd.StatusProxy} can be updated
22256 notifyEnter : function(dd, e, data){
22257 return this.dropNotAllowed;
22261 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
22262 * This method will be called on every mouse movement while the drag source is over the drop zone.
22263 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
22264 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
22265 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
22266 * registered node, it will call {@link #onContainerOver}.
22267 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22268 * @param {Event} e The event
22269 * @param {Object} data An object containing arbitrary data supplied by the drag source
22270 * @return {String} status The CSS class that communicates the drop status back to the source so that the
22271 * underlying {@link Roo.dd.StatusProxy} can be updated
22273 notifyOver : function(dd, e, data){
22274 var n = this.getTargetFromEvent(e);
22275 if(!n){ // not over valid drop target
22276 if(this.lastOverNode){
22277 this.onNodeOut(this.lastOverNode, dd, e, data);
22278 this.lastOverNode = null;
22280 return this.onContainerOver(dd, e, data);
22282 if(this.lastOverNode != n){
22283 if(this.lastOverNode){
22284 this.onNodeOut(this.lastOverNode, dd, e, data);
22286 this.onNodeEnter(n, dd, e, data);
22287 this.lastOverNode = n;
22289 return this.onNodeOver(n, dd, e, data);
22293 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
22294 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
22295 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
22296 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
22297 * @param {Event} e The event
22298 * @param {Object} data An object containing arbitrary data supplied by the drag zone
22300 notifyOut : function(dd, e, data){
22301 if(this.lastOverNode){
22302 this.onNodeOut(this.lastOverNode, dd, e, data);
22303 this.lastOverNode = null;
22308 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
22309 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
22310 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
22311 * otherwise it will call {@link #onContainerDrop}.
22312 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
22313 * @param {Event} e The event
22314 * @param {Object} data An object containing arbitrary data supplied by the drag source
22315 * @return {Boolean} True if the drop was valid, else false
22317 notifyDrop : function(dd, e, data){
22318 if(this.lastOverNode){
22319 this.onNodeOut(this.lastOverNode, dd, e, data);
22320 this.lastOverNode = null;
22322 var n = this.getTargetFromEvent(e);
22324 this.onNodeDrop(n, dd, e, data) :
22325 this.onContainerDrop(dd, e, data);
22329 triggerCacheRefresh : function(){
22330 Roo.dd.DDM.refreshCache(this.groups);