3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.debug = {};
14 function createConsole(){
16 var scriptPanel = new Ext.debug.ScriptsPanel();
17 var logView = new Ext.debug.LogPanel();
18 var tree = new Ext.debug.DomTree();
19 var compInspector = new Ext.debug.ComponentInspector();
20 var compInfoPanel = new Ext.debug.ComponentInfoPanel();
21 var storeInspector = new Ext.debug.StoreInspector();
22 var objInspector = new Ext.debug.ObjectInspector();
24 var tabs = new Ext.TabPanel({
27 tabPosition: 'bottom',
29 title: 'Debug Console',
31 items: [logView, scriptPanel]
33 title: 'HTML Inspector',
37 title: 'Component Inspector',
39 items: [compInspector,compInfoPanel]
41 title: 'Object Inspector',
47 items: [storeInspector]
52 id: 'x-debug-browser',
56 style: 'position:absolute;left:0;bottom:0;z-index:101',
66 Ext.EventManager.removeResizeListener(handleResize);
73 cp.render(Ext.getBody());
75 cp.resizer = new Ext.Resizable(cp.el, {
80 resizeElement : function(){
81 var box = this.proxy.getBox();
83 cp.setHeight(box.height);
88 // function handleResize(){
89 // cp.setWidth(Ext.getBody().getViewSize().width);
91 // Ext.EventManager.onWindowResize(handleResize);
95 function handleResize(){
97 var size = b.getViewSize();
98 if(size.height < b.dom.scrollHeight) {
101 cp.setWidth(size.width);
103 Ext.EventManager.onWindowResize(handleResize);
113 cp.logView.log.apply(cp.logView, arguments);
116 logf : function(format, arg1, arg2, etc){
117 Ext.log(String.format.apply(String, arguments));
121 if(typeof o == 'string' || typeof o == 'number' || typeof o == 'undefined' || Ext.isDate(o)){
125 }else if(typeof o != "object"){
126 Ext.log('Unknown return type');
127 }else if(Ext.isArray(o)){
128 Ext.log('['+o.join(',')+']');
132 var to = typeof o[key];
133 if(to != "function" && to != "object"){
134 b.push(String.format(" {0}: {1},\n", key, o[key]));
139 s = s.substr(0, s.length-2);
147 time : function(name){
148 name = name || "def";
149 Ext._timers[name] = new Date().getTime();
152 timeEnd : function(name, printResults){
153 var t = new Date().getTime();
154 name = name || "def";
155 var v = String.format("{0} ms", t-Ext._timers[name]);
156 Ext._timers[name] = new Date().getTime();
157 if(printResults !== false){
158 Ext.log('Timer ' + (name == "def" ? v : name + ": " + v));
167 Ext.debug.ScriptsPanel = Ext.extend(Ext.Panel, {
168 id:'x-debug-scripts',
175 style:'border-width:0 0 0 1px;',
177 initComponent : function(){
179 this.scriptField = new Ext.form.TextArea({
181 style:'border-width:0;'
184 this.trapBox = new Ext.form.Checkbox({
186 boxLabel: 'Trap Errors',
190 this.toolbar = new Ext.Toolbar([{
193 handler: this.evalScript
204 this.items = [this.toolbar, this.scriptField];
206 Ext.debug.ScriptsPanel.superclass.initComponent.call(this);
209 evalScript : function(){
210 var s = this.scriptField.getValue();
211 if(this.trapBox.getValue()){
214 Ext.dump(rt === undefined? '(no return)' : rt);
216 Ext.log(e.message || e.descript);
220 Ext.dump(rt === undefined? '(no return)' : rt);
225 this.scriptField.setValue('');
226 this.scriptField.focus();
231 Ext.debug.LogPanel = Ext.extend(Ext.Panel, {
235 style:'border-width:0 1px 0 0',
238 var markup = [ '<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
239 Ext.util.Format.htmlEncode(Array.prototype.join.call(arguments, ', ')).replace(/\n/g, '<br />').replace(/\s/g, ' '),
242 this.body.insertHtml('beforeend', markup);
243 this.body.scrollTo('top', 100000);
247 this.body.update('');
248 this.body.dom.scrollTop = 0;
252 Ext.debug.DomTree = Ext.extend(Ext.tree.TreePanel, {
262 initComponent : function(){
265 Ext.debug.DomTree.superclass.initComponent.call(this);
267 // tree related stuff
268 var styles = false, hnode;
269 var nonSpace = /^\s*$/;
270 var html = Ext.util.Format.htmlEncode;
271 var ellipsis = Ext.util.Format.ellipsis;
272 var styleRe = /\s?([a-z\-]*)\:([^;]*)(?:[;\s\n\r]*)/gi;
274 function findNode(n){
275 if(!n || n.nodeType != 1 || n == document.body || n == document){
279 while((p = p.parentNode) && p.nodeType == 1 && p.tagName.toUpperCase() != 'HTML'){
283 for(var i = 0, len = pn.length; i < len; i++){
285 cn = cn.findChild('htmlNode', pn[i]);
286 if(!cn){ // in this dialog?
291 var a = cn.ui.anchor;
292 treeEl.dom.scrollTop = Math.max(0 ,a.offsetTop-10);
293 //treeEl.dom.scrollLeft = Math.max(0 ,a.offsetLeft-10); no likey
298 function nodeTitle(n){
302 }else if(n.className){
303 s += '.'+n.className;
308 function onNodeSelect(t, n, last){
310 if(last && last.unframe){
322 reload.setDisabled(n.leaf);
323 var dom = n.htmlNode;
324 stylePanel.setTitle(nodeTitle(dom));
325 if(styles && !showAll.pressed){
326 var s = dom.style ? dom.style.cssText : '';
329 while ((m = styleRe.exec(s)) != null){
330 props[m[1].toLowerCase()] = m[2];
334 var cl = Ext.debug.cssList;
335 var s = dom.style, fly = Ext.fly(dom);
337 for(var i = 0, len = cl.length; i<len; i++){
339 var v = s[st] || fly.getStyle(st);
340 if(v != undefined && v !== null && v !== ''){
348 if((isNaN(a+10)) && v != undefined && v !== null && v !== '' && !(Ext.isGecko && a[0] == a[0].toUpperCase())){
360 stylesGrid.setSource(props);
361 stylesGrid.treeNode = n;
362 stylesGrid.view.fitColumns();
365 this.loader = new Ext.tree.TreeLoader();
366 this.loader.load = function(n, cb){
367 var isBody = n.htmlNode == document.body;
368 var cn = n.htmlNode.childNodes;
369 for(var i = 0, c; c = cn[i]; i++){
370 if(isBody && c.id == 'x-debug-browser'){
374 n.appendChild(new Ext.debug.HtmlNode(c));
375 }else if(c.nodeType == 3 && !nonSpace.test(c.nodeValue)){
376 n.appendChild(new Ext.tree.TreeNode({
377 text:'<em>' + ellipsis(html(String(c.nodeValue)), 35) + '</em>',
385 //tree.getSelectionModel().on('selectionchange', onNodeSelect, null, {buffer:250});
387 this.root = this.setRootNode(new Ext.tree.TreeNode('Ext'));
389 hnode = this.root.appendChild(new Ext.debug.HtmlNode(
390 document.getElementsByTagName('html')[0]
396 Ext.debug.ComponentNodeUI = Ext.extend(Ext.tree.TreeNodeUI,{
397 onOver : function(e){
398 Ext.debug.ComponentNodeUI.superclass.onOver.call(this);
399 var cmp = this.node.attributes.component;
400 if (cmp.el && cmp.el.mask && cmp.id !='x-debug-browser') {
401 try { // Oddly bombs on some elements in IE, gets any we care about though
408 Ext.debug.ComponentNodeUI.superclass.onOut.call(this);
409 var cmp = this.node.attributes.component;
410 if (cmp.el && cmp.el.unmask && cmp.id !='x-debug-browser') {
418 Ext.debug.ComponentInspector = Ext.extend(Ext.tree.TreePanel, {
428 initComponent : function(){
429 this.loader = new Ext.tree.TreeLoader();
430 this.bbar = new Ext.Toolbar([{
432 handler: this.refresh,
435 Ext.debug.ComponentInspector.superclass.initComponent.call(this);
437 this.root = this.setRootNode(new Ext.tree.TreeNode({
438 text: 'Ext Components',
439 component: Ext.ComponentMgr.all,
442 this.parseRootNode();
444 this.on('click', this.onClick, this);
447 createNode: function(n,c) {
448 var leaf = (c.items && c.items.length > 0);
449 return n.appendChild(new Ext.tree.TreeNode({
450 text: c.id + (c.getXType() ? ' [ ' + c.getXType() + ' ]': '' ),
452 uiProvider:Ext.debug.ComponentNodeUI,
457 parseChildItems: function(n) {
458 var cn = n.attributes.component.items;
460 for (var i = 0;i < cn.length; i++) {
462 if (c.id != this.id && c.id != this.bottomToolbar.id) {
463 var newNode = this.createNode(n,c);
465 this.parseChildItems(newNode)
472 parseRootNode: function() {
474 var cn = n.attributes.component.items;
475 for (var i = 0,c;c = cn[i];i++) {
476 if (c.id != this.id && c.id != this.bottomToolbar.id) {
478 var newNode = this.createNode(n,c);
480 this.parseChildItems(newNode);
487 onClick: function(node, e) {
488 var oi = Ext.getCmp('x-debug-objinspector');
489 oi.refreshNodes(node.attributes.component);
493 refresh: function() {
494 while (this.root.firstChild) {
495 this.root.removeChild(this.root.firstChild);
497 this.parseRootNode();
498 var ci = Ext.getCmp('x-debug-compinfo');
500 ci.message('refreshed component tree - '+Ext.ComponentMgr.all.length)
505 Ext.debug.ComponentInfoPanel = Ext.extend(Ext.Panel,{
506 id:'x-debug-compinfo',
514 style:'border-width:0 0 0 1px;',
516 initComponent: function() {
517 this.watchBox = new Ext.form.Checkbox({
518 id: 'x-debug-watchcomp',
519 boxLabel: 'Watch ComponentMgr',
521 check: function(cb, val) {
523 Ext.ComponentMgr.all.on('add', this.onAdd, this);
524 Ext.ComponentMgr.all.on('remove', this.onRemove, this);
526 Ext.ComponentMgr.all.un('add', this.onAdd, this);
527 Ext.ComponentMgr.all.un('remove', this.onRemove, this);
534 this.tbar = new Ext.Toolbar([{
540 Ext.debug.ComponentInfoPanel.superclass.initComponent.call(this);
543 onAdd: function(i, o, key) {
544 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
547 this.insertMarkup(markup);
550 onRemove: function(o, key) {
551 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
554 this.insertMarkup(markup);
557 message: function(msg) {
558 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
561 this.insertMarkup(markup);
563 insertMarkup: function(markup) {
564 this.body.insertHtml('beforeend', markup);
565 this.body.scrollTo('top', 100000);
568 this.body.update('');
569 this.body.dom.scrollTop = 0;
573 Ext.debug.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
574 focus: Ext.emptyFn, // prevent odd scrolling behavior
576 renderElements : function(n, a, targetNode, bulkRender){
577 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
579 var t = n.getOwnerTree();
580 var cols = t.columns;
581 var bw = t.borderWidth;
585 '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
586 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
587 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
588 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
589 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
590 '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
591 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
592 '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
594 for(var i = 1, len = cols.length; i < len; i++){
597 buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
598 '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
602 '<div class="x-clear"></div></div>',
603 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
606 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
607 this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
608 n.nextSibling.ui.getEl(), buf.join(""));
610 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
613 this.elNode = this.wrap.childNodes[0];
614 this.ctNode = this.wrap.childNodes[1];
615 var cs = this.elNode.firstChild.childNodes;
616 this.indentNode = cs[0];
618 this.iconNode = cs[2];
620 this.textNode = cs[3].firstChild;
624 Ext.debug.ObjectInspector = Ext.extend(Ext.tree.TreePanel, {
625 id: 'x-debug-objinspector',
635 borderWidth: Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
638 initComponent : function(){
639 this.showFunc = false;
640 this.toggleFunc = function() {
641 this.showFunc = !this.showFunc;
642 this.refreshNodes(this.currentObject);
644 this.bbar = new Ext.Toolbar([{
645 text: 'Show Functions',
648 handler: this.toggleFunc,
654 loader: new Ext.tree.TreeLoader(),
666 Ext.debug.ObjectInspector.superclass.initComponent.call(this);
668 this.root = this.setRootNode(new Ext.tree.TreeNode({
673 if (this.currentObject) {
678 refreshNodes: function(newObj) {
679 this.currentObject = newObj;
680 var node = this.root;
681 while(node.firstChild){
682 node.removeChild(node.firstChild);
687 parseNodes: function() {
688 for (var o in this.currentObject) {
689 if (!this.showFunc) {
690 if (Ext.isFunction(this.currentObject[o])) {
698 createNode: function(o) {
699 return this.root.appendChild(new Ext.tree.TreeNode({
701 value: this.currentObject[o],
702 uiProvider:Ext.debug.ColumnNodeUI,
703 iconCls: 'x-debug-node',
708 onRender : function(){
709 Ext.debug.ObjectInspector.superclass.onRender.apply(this, arguments);
710 this.headers = this.header.createChild({cls:'x-tree-headers'});
712 var cols = this.columns, c;
715 for(var i = 0, len = cols.length; i < len; i++){
717 totalWidth += c.width;
718 this.headers.createChild({
719 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
721 cls:'x-tree-hd-text',
724 style:'width:'+(c.width-this.borderWidth)+'px;'
727 this.headers.createChild({cls:'x-clear'});
728 // prevent floats from wrapping when clipped
729 this.headers.setWidth(totalWidth);
730 this.innerCt.setWidth(totalWidth);
735 Ext.debug.StoreInspector = Ext.extend(Ext.tree.TreePanel, {
745 initComponent: function() {
746 this.bbar = new Ext.Toolbar([{
748 handler: this.refresh,
751 Ext.debug.StoreInspector.superclass.initComponent.call(this);
753 this.root = this.setRootNode(new Ext.tree.TreeNode({
757 this.on('click', this.onClick, this);
762 parseStores: function() {
763 var cn = Ext.StoreMgr.items;
764 for (var i = 0,c;c = cn[i];i++) {
765 this.root.appendChild({
766 text: c.storeId + ' - ' + c.totalLength + ' records',
773 onClick: function(node, e) {
774 var oi = Ext.getCmp('x-debug-objinspector');
775 oi.refreshNodes(node.attributes.component);
779 refresh: function() {
780 while (this.root.firstChild) {
781 this.root.removeChild(this.root.firstChild);
787 // highly unusual class declaration
788 Ext.debug.HtmlNode = function(){
789 var html = Ext.util.Format.htmlEncode;
790 var ellipsis = Ext.util.Format.ellipsis;
791 var nonSpace = /^\s*$/;
795 {n: 'className', v: 'class'},
796 {n: 'name', v: 'name'},
797 {n: 'type', v: 'type'},
798 {n: 'src', v: 'src'},
799 {n: 'href', v: 'href'}
802 function hasChild(n){
803 for(var i = 0, c; c = n.childNodes[i]; i++){
811 function renderNode(n, leaf){
812 var tag = n.tagName.toLowerCase();
813 var s = '<' + tag;
814 for(var i = 0, len = attrs.length; i < len; i++){
817 if(v && !nonSpace.test(v)){
818 s += ' ' + a.v + '="<i>' + html(v) +'</i>"';
821 var style = n.style ? n.style.cssText : '';
823 s += ' style="<i>' + html(style.toLowerCase()) +'</i>"';
825 if(leaf && n.childNodes.length > 0){
826 s+='><em>' + ellipsis(html(String(n.innerHTML)), 35) + '</em></'+tag+'>';
835 var HtmlNode = function(n){
836 var leaf = !hasChild(n);
838 this.tagName = n.tagName.toLowerCase();
840 text : renderNode(n, leaf),
844 HtmlNode.superclass.constructor.call(this, attr);
845 this.attributes.htmlNode = n; // for searching
847 this.on('expand', this.onExpand, this);
848 this.on('collapse', this.onCollapse, this);
853 Ext.extend(HtmlNode, Ext.tree.AsyncTreeNode, {
854 cls: 'x-tree-noicon',
855 preventHScroll: true,
856 refresh : function(highlight){
857 var leaf = !hasChild(this.htmlNode);
858 this.setText(renderNode(this.htmlNode, leaf));
860 Ext.fly(this.ui.textNode).highlight();
864 onExpand : function(){
865 if(!this.closeNode && this.parentNode){
866 this.closeNode = this.parentNode.insertBefore(new Ext.tree.TreeNode({
867 text:'</' + this.tagName + '>',
869 }), this.nextSibling);
870 }else if(this.closeNode){
871 this.closeNode.ui.show();
875 onCollapse : function(){
877 this.closeNode.ui.hide();
881 render : function(bulkRender){
882 HtmlNode.superclass.render.call(this, bulkRender);
885 highlightNode : function(){
886 //Ext.fly(this.htmlNode).highlight();
889 highlight : function(){
890 //Ext.fly(this.ui.textNode).highlight();
894 this.htmlNode.style.border = '1px solid #0000ff';
895 //this.highlightNode();
898 unframe : function(){
899 //Ext.fly(this.htmlNode).removeClass('x-debug-frame');
900 this.htmlNode.style.border = '';