2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
15 function createConsole(){
\r
17 var scriptPanel = new Ext.debug.ScriptsPanel();
\r
18 var logView = new Ext.debug.LogPanel();
\r
19 var tree = new Ext.debug.DomTree();
\r
21 var tabs = new Ext.TabPanel({
\r
24 tabPosition: 'bottom',
\r
26 title: 'Debug Console',
\r
28 items: [logView, scriptPanel]
\r
30 title: 'DOM Inspector',
\r
36 cp = new Ext.Panel({
\r
37 id: 'x-debug-browser',
\r
40 animCollapse: false,
\r
41 style: 'position:absolute;left:0;bottom:0;',
\r
48 handler: function(){
\r
51 Ext.EventManager.removeResizeListener(handleResize);
\r
58 cp.render(document.body);
\r
60 cp.resizer = new Ext.Resizable(cp.el, {
\r
65 resizeElement : function(){
\r
66 var box = this.proxy.getBox();
\r
68 cp.setHeight(box.height);
\r
73 function handleResize(){
\r
74 cp.setWidth(Ext.getBody().getViewSize().width);
\r
76 Ext.EventManager.onWindowResize(handleResize);
\r
87 cp.logView.log.apply(cp.logView, arguments);
\r
90 logf : function(format, arg1, arg2, etc){
\r
91 Ext.log(String.format.apply(String, arguments));
\r
95 if(typeof o == 'string' || typeof o == 'number' || typeof o == 'undefined' || Ext.isDate(o)){
\r
99 }else if(typeof o != "object"){
\r
100 Ext.log('Unknown return type');
\r
101 }else if(Ext.isArray(o)){
\r
102 Ext.log('['+o.join(',')+']');
\r
106 var to = typeof o[key];
\r
107 if(to != "function" && to != "object"){
\r
108 b.push(String.format(" {0}: {1},\n", key, o[key]));
\r
111 var s = b.join("");
\r
113 s = s.substr(0, s.length-2);
\r
115 Ext.log(s + "\n}");
\r
121 time : function(name){
\r
122 name = name || "def";
\r
123 Ext._timers[name] = new Date().getTime();
\r
126 timeEnd : function(name, printResults){
\r
127 var t = new Date().getTime();
\r
128 name = name || "def";
\r
129 var v = String.format("{0} ms", t-Ext._timers[name]);
\r
130 Ext._timers[name] = new Date().getTime();
\r
131 if(printResults !== false){
\r
132 Ext.log('Timer ' + (name == "def" ? v : name + ": " + v));
\r
141 Ext.debug.ScriptsPanel = Ext.extend(Ext.Panel, {
\r
142 id:'x-debug-scripts',
\r
149 style:'border-width:0 0 0 1px;',
\r
151 initComponent : function(){
\r
153 this.scriptField = new Ext.form.TextArea({
\r
154 anchor: '100% -26',
\r
155 style:'border-width:0;'
\r
158 this.trapBox = new Ext.form.Checkbox({
\r
159 id: 'console-trap',
\r
160 boxLabel: 'Trap Errors',
\r
164 this.toolbar = new Ext.Toolbar([{
\r
167 handler: this.evalScript
\r
171 handler: this.clear
\r
178 this.items = [this.toolbar, this.scriptField];
\r
180 Ext.debug.ScriptsPanel.superclass.initComponent.call(this);
\r
183 evalScript : function(){
\r
184 var s = this.scriptField.getValue();
\r
185 if(this.trapBox.getValue()){
\r
188 Ext.dump(rt === undefined? '(no return)' : rt);
\r
190 Ext.log(e.message || e.descript);
\r
194 Ext.dump(rt === undefined? '(no return)' : rt);
\r
198 clear : function(){
\r
199 this.scriptField.setValue('');
\r
200 this.scriptField.focus();
\r
205 Ext.debug.LogPanel = Ext.extend(Ext.Panel, {
\r
209 style:'border-width:0 1px 0 0',
\r
212 var markup = [ '<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
\r
213 Ext.util.Format.htmlEncode(Array.prototype.join.call(arguments, ', ')).replace(/\n/g, '<br />').replace(/\s/g, ' '),
\r
214 '</div>'].join('');
\r
216 this.body.insertHtml('beforeend', markup);
\r
217 this.body.scrollTo('top', 100000);
\r
220 clear : function(){
\r
221 this.body.update('');
\r
222 this.body.dom.scrollTop = 0;
\r
226 Ext.debug.DomTree = Ext.extend(Ext.tree.TreePanel, {
\r
236 initComponent : function(){
\r
239 Ext.debug.DomTree.superclass.initComponent.call(this);
\r
241 // tree related stuff
\r
242 var styles = false, hnode;
\r
243 var nonSpace = /^\s*$/;
\r
244 var html = Ext.util.Format.htmlEncode;
\r
245 var ellipsis = Ext.util.Format.ellipsis;
\r
246 var styleRe = /\s?([a-z\-]*)\:([^;]*)(?:[;\s\n\r]*)/gi;
\r
248 function findNode(n){
\r
249 if(!n || n.nodeType != 1 || n == document.body || n == document){
\r
252 var pn = [n], p = n;
\r
253 while((p = p.parentNode) && p.nodeType == 1 && p.tagName.toUpperCase() != 'HTML'){
\r
257 for(var i = 0, len = pn.length; i < len; i++){
\r
259 cn = cn.findChild('htmlNode', pn[i]);
\r
260 if(!cn){ // in this dialog?
\r
265 var a = cn.ui.anchor;
\r
266 treeEl.dom.scrollTop = Math.max(0 ,a.offsetTop-10);
\r
267 //treeEl.dom.scrollLeft = Math.max(0 ,a.offsetLeft-10); no likey
\r
272 function nodeTitle(n){
\r
276 }else if(n.className){
\r
277 s += '.'+n.className;
\r
282 function onNodeSelect(t, n, last){
\r
284 if(last && last.unframe){
\r
288 if(n && n.htmlNode){
\r
289 if(frameEl.pressed){
\r
296 reload.setDisabled(n.leaf);
\r
297 var dom = n.htmlNode;
\r
298 stylePanel.setTitle(nodeTitle(dom));
\r
299 if(styles && !showAll.pressed){
\r
300 var s = dom.style ? dom.style.cssText : '';
\r
303 while ((m = styleRe.exec(s)) != null){
\r
304 props[m[1].toLowerCase()] = m[2];
\r
308 var cl = Ext.debug.cssList;
\r
309 var s = dom.style, fly = Ext.fly(dom);
\r
311 for(var i = 0, len = cl.length; i<len; i++){
\r
313 var v = s[st] || fly.getStyle(st);
\r
314 if(v != undefined && v !== null && v !== ''){
\r
322 if((isNaN(a+10)) && v != undefined && v !== null && v !== '' && !(Ext.isGecko && a[0] == a[0].toUpperCase())){
\r
331 addStyle.disable();
\r
334 stylesGrid.setSource(props);
\r
335 stylesGrid.treeNode = n;
\r
336 stylesGrid.view.fitColumns();
\r
339 this.loader = new Ext.tree.TreeLoader();
\r
340 this.loader.load = function(n, cb){
\r
341 var isBody = n.htmlNode == document.body;
\r
342 var cn = n.htmlNode.childNodes;
\r
343 for(var i = 0, c; c = cn[i]; i++){
\r
344 if(isBody && c.id == 'x-debug-browser'){
\r
347 if(c.nodeType == 1){
\r
348 n.appendChild(new Ext.debug.HtmlNode(c));
\r
349 }else if(c.nodeType == 3 && !nonSpace.test(c.nodeValue)){
\r
350 n.appendChild(new Ext.tree.TreeNode({
\r
351 text:'<em>' + ellipsis(html(String(c.nodeValue)), 35) + '</em>',
\r
352 cls: 'x-tree-noicon'
\r
359 //tree.getSelectionModel().on('selectionchange', onNodeSelect, null, {buffer:250});
\r
361 this.root = this.setRootNode(new Ext.tree.TreeNode('Ext'));
\r
363 hnode = this.root.appendChild(new Ext.debug.HtmlNode(
\r
364 document.getElementsByTagName('html')[0]
\r
371 // highly unusual class declaration
\r
372 Ext.debug.HtmlNode = function(){
\r
373 var html = Ext.util.Format.htmlEncode;
\r
374 var ellipsis = Ext.util.Format.ellipsis;
\r
375 var nonSpace = /^\s*$/;
\r
378 {n: 'id', v: 'id'},
\r
379 {n: 'className', v: 'class'},
\r
380 {n: 'name', v: 'name'},
\r
381 {n: 'type', v: 'type'},
\r
382 {n: 'src', v: 'src'},
\r
383 {n: 'href', v: 'href'}
\r
386 function hasChild(n){
\r
387 for(var i = 0, c; c = n.childNodes[i]; i++){
\r
388 if(c.nodeType == 1){
\r
395 function renderNode(n, leaf){
\r
396 var tag = n.tagName.toLowerCase();
\r
397 var s = '<' + tag;
\r
398 for(var i = 0, len = attrs.length; i < len; i++){
\r
401 if(v && !nonSpace.test(v)){
\r
402 s += ' ' + a.v + '="<i>' + html(v) +'</i>"';
\r
405 var style = n.style ? n.style.cssText : '';
\r
407 s += ' style="<i>' + html(style.toLowerCase()) +'</i>"';
\r
409 if(leaf && n.childNodes.length > 0){
\r
410 s+='><em>' + ellipsis(html(String(n.innerHTML)), 35) + '</em></'+tag+'>';
\r
419 var HtmlNode = function(n){
\r
420 var leaf = !hasChild(n);
\r
422 this.tagName = n.tagName.toLowerCase();
\r
424 text : renderNode(n, leaf),
\r
426 cls: 'x-tree-noicon'
\r
428 HtmlNode.superclass.constructor.call(this, attr);
\r
429 this.attributes.htmlNode = n; // for searching
\r
431 this.on('expand', this.onExpand, this);
\r
432 this.on('collapse', this.onCollapse, this);
\r
437 Ext.extend(HtmlNode, Ext.tree.AsyncTreeNode, {
\r
438 cls: 'x-tree-noicon',
\r
439 preventHScroll: true,
\r
440 refresh : function(highlight){
\r
441 var leaf = !hasChild(this.htmlNode);
\r
442 this.setText(renderNode(this.htmlNode, leaf));
\r
444 Ext.fly(this.ui.textNode).highlight();
\r
448 onExpand : function(){
\r
449 if(!this.closeNode && this.parentNode){
\r
450 this.closeNode = this.parentNode.insertBefore(new Ext.tree.TreeNode({
\r
451 text:'</' + this.tagName + '>',
\r
452 cls: 'x-tree-noicon'
\r
453 }), this.nextSibling);
\r
454 }else if(this.closeNode){
\r
455 this.closeNode.ui.show();
\r
459 onCollapse : function(){
\r
460 if(this.closeNode){
\r
461 this.closeNode.ui.hide();
\r
465 render : function(bulkRender){
\r
466 HtmlNode.superclass.render.call(this, bulkRender);
\r
469 highlightNode : function(){
\r
470 //Ext.fly(this.htmlNode).highlight();
\r
473 highlight : function(){
\r
474 //Ext.fly(this.ui.textNode).highlight();
\r
477 frame : function(){
\r
478 this.htmlNode.style.border = '1px solid #0000ff';
\r
479 //this.highlightNode();
\r
482 unframe : function(){
\r
483 //Ext.fly(this.htmlNode).removeClass('x-debug-frame');
\r
484 this.htmlNode.style.border = '';
\r