📄 airintrospector.js
字号:
prevent(htmlLoader.stage, runtime.flash.events.MouseEvent.MOUSE_UP); prevent(htmlLoader.stage, runtime.flash.events.MouseEvent.DOUBLE_CLICK); check(htmlLoader.stage, runtime.flash.events.MouseEvent.MOUSE_MOVE); check(nativeWindow, runtime.flash.events.Event.ACTIVATE); labelMover(htmlLoader.stage, runtime.flash.events.MouseEvent.MOUSE_MOVE); window.htmlLoader.stage.addChild(sprite); air.Introspector.highlightSprite = sprite; air.Introspector.highlightText = new runtime.flash.display.Sprite(); window.htmlLoader.stage.addChild(air.Introspector.highlightText); air.Introspector.highlightText.graphics.beginFill(0xeeeeee, 0.8); air.Introspector.highlightText.graphics.lineStyle(1, 0xeeeeee, 0.9, false); air.Introspector.highlightText.graphics.drawRect(0, 0, 250, 40); air.Introspector.highlightText.visible = false; air.Introspector.highlightLine1 = air.Introspector.createTextField(air.Introspector.highlightText, 16, true); air.Introspector.highlightLine2 = air.Introspector.createTextField(air.Introspector.highlightText, 10, false); }else{ //should not be here } }, /** * @function addEventListener * @description Add a listener and stores it for future cleanup */ addEventListener: function(obj, eventName, listener, capture, priority){ eventListeners.push([obj, eventName, listener, capture]); obj.addEventListener(eventName, listener, capture, priority); }, /** * @function removeEventListener * @description Removes listener */ removeEventListener: function(obj, eventName, listener, capture){ for(var i=eventListeners.length-1;i>=0;i--){ var l = eventListeners[i]; if(l[0]==obj && l[1]==eventName && l[2]==listener && l[3]==capture) { eventListeners.splice(i, 1); break; } } obj.removeEventListener(eventName, listener, capture); }, /** * @function drawRect * @description Draw a rectangle using ActionScript, also use tagName to find out which color to use * @see air.Introspector.highlightBgColors */ drawRect: function (rect, tagName){ var htmlLoaderBounds = htmlLoader.getBounds(htmlLoader.stage); rect.x += htmlLoaderBounds.x; rect.y += htmlLoaderBounds.y; rect.scaleX = 1; rect.scaleY = 1; air.Introspector.showHighlight(rect); air.Introspector.highlightSprite.graphics.clear(); var bgColor = air.Introspector.highlightBgColors[tagName.toLowerCase()]; if(typeof bgColor=='undefined') bgColor = air.Introspector.highlightBgColors['default']; air.Introspector.highlightSprite.graphics.beginFill(bgColor, 0.2); air.Introspector.highlightSprite.graphics.lineStyle(3, bgColor, 0.9, false); air.Introspector.highlightSprite.graphics.drawRect(0, 0, rect.width, rect.height); }, /** * @function highlightElement * @description Highlight element e. Get its bounding box and send it directly or over the bridge to air.Introspector.drawRect * @also air.Introspector.drawRect */ highlightElement: function(e, callback){ var rect = air.Introspector.getBorderBox(e); if(rect==false) return; if(isAppSandbox){ air.Introspector.drawRect(rect, e.tagName); }else{ setTimeout(function(){ try{ if(!isNaN(rect.width)&&!isNaN(rect.x)){ air.Introspector.noBridge(function(){ parentSandboxBridge.air_Introspector_drawRect(rect, e.tagName); }); } }catch(e){ air.Introspector.Console.error(e); } if(typeof callback!='undefined') callback(); }, 0); } }, /** * @function addKeyboardEvents * @description Registers events on every window that includes AIRDebug.js. * * By default F11 enables the inspect tool * F12 pops up the debug tool */ addKeyboardEvents: function(sprite){ air.Introspector.addEventListener(sprite, runtime.flash.events.KeyboardEvent.KEY_DOWN, function(e){ if(e.keyCode==air.Introspector.config.introspectorKey){ //F11 key pressed if(typeof air.Introspector.lastElement!='undefined'&&(air.Introspector.lastElement.nodeName=='IFRAME'||air.Introspector.lastElement.nodeName=='FRAME')){ try{ var contentWindow = air.Introspector.lastElement.contentWindow; if(typeof contentWindow.childSandboxBridge!='undefined'&& typeof contentWindow.childSandboxBridge.air_Introspector_isDebugOpen!='undefined'&& typeof contentWindow.childSandboxBridge.air_Introspector_toggleInspect!='undefined') { if(contentWindow.childSandboxBridge.air_Introspector_isDebugOpen()){ contentWindow.childSandboxBridge.air_Introspector_toggleInspect(); e.preventDefault(); e.stopPropagation(); return; } } }catch(e){ //it looks like no debugger in that iframe. go ahead with app sandbox debugger } } air.Introspector.init(false, true, function(){ air.Introspector.debugWindow.toggleInspect(); }); e.preventDefault(); e.stopPropagation(); }else if(e.keyCode==air.Introspector.config.debuggerKey){ //F12 key pressed air.Introspector.toggleWindow(); e.preventDefault(); e.stopPropagation(); }else if(e.keyCode==27&&air.Introspector.inspect){ air.Introspector.debugWindow.finishInspect(); air.Introspector.hideHighlight(); e.preventDefault(); e.stopPropagation(); }else if(e.ctrlKey==true&&e.altKey==false){ var tab = null; switch(e.keyCode){ case runtime.flash.ui.Keyboard.NUMBER_1: tab = 0; break; case runtime.flash.ui.Keyboard.NUMBER_2: tab = 1; break; case runtime.flash.ui.Keyboard.NUMBER_3: tab = 2; break; case runtime.flash.ui.Keyboard.NUMBER_4: tab = 3; break; case runtime.flash.ui.Keyboard.NUMBER_5: tab = 4; break; case runtime.flash.ui.Keyboard.NUMBER_6: tab = 5; break; } if(tab!=null){ air.Introspector.init(false, true, function(){ air.Introspector.debugWindow.setTab(tab); }); e.preventDefault(); e.stopPropagation(); } } }, true, 1000000); }, /** * @function showHighlightLabels * @description Make the tooltip labels near the highlighting box appear and tell the id/tag name/outer HTML */ showHighlightLabels: function(id, nodeName, outerHTML){ if(typeof id!='undefined'&&id.length!=0){ air.Introspector.highlightLine1.text = nodeName+' - '+id; }else{ air.Introspector.highlightLine1.text = nodeName; } if(air.Introspector.canClick){ air.Introspector.highlightLine2.text = outerHTML.substr(0, 40).replace(/\n/g, '\\n')+'...'; }else{ air.Introspector.highlightLine2.text = 'Click to activate window'; window.clearTimeout(air.Introspector.clickToActivateTimeout); air.Introspector.clickToActivateTimeout = setTimeout(function(){ air.Introspector.highlightLine2.text = outerHTML.substr(0, 40).replace(/\n/g, '\\n')+'...'; }, 400) } air.Introspector.highlightText.visible = true; }, /** * @function registerUncaughtExceptionListener * @description Catches all uncaught exceptions from javascript and shows them in the console */ registerUncaughtExceptionListener: function(){ air.Introspector.addEventListener(window.htmlLoader, runtime.flash.events.HTMLUncaughtScriptExceptionEvent.UNCAUGHT_SCRIPT_EXCEPTION , function(e){ if(e.exceptionValue && e.exceptionValue.air_Introspector_setParentSandboxBridge == true && e.exceptionValue.air_Introspector_version == air.Introspector.version) { air.Introspector.registerFramesParentSandboxBridge(); e.preventDefault(); return; } air.Introspector.logError(e.exceptionValue, {htmlLoader:window.htmlLoader}); // e.preventDefault(); }); }, /** * @function registerCloseEventListener * @description */ registerCloseEventListener: function(){ air.Introspector.addEventListener(window.nativeWindow, air.Introspector.runtime.Event.CLOSE, function(){ var debugWindow = air.Introspector.findDebugWindow(); if(debugWindow!=null){ debugWindow.closedWindow(window.htmlLoader); } }); }, /** * @function registerCompleteEventLisener * @description Make the Introspector window knwo that we are complete. Register parentSandboxBridge on every frame */ registerCompleteEventListener: function(){ air.Introspector.addEventListener(window.htmlLoader, air.Introspector.runtime.Event.COMPLETE, function(){ air.Introspector.removeEventListener(window.htmlLoader, air.Introspector.runtime.Event.COMPLETE, arguments.callee); try{ //announce the debugWindow to refresh DOM and assets var debugWindow = air.Introspector.findDebugWindow(); if(debugWindow!=null){ if(debugWindow.isLoaded){ debugWindow.completeWindow(window.htmlLoader); } } air.Introspector.registerFramesParentSandboxBridge(); }catch(e){ runtime.trace(e); runtime.trace(e.line); air.Introspector.Console.log(e); } }); }, /** * @function registerFramesParentSandboxBridge * @description All frames should know about us - registering parentSandboxBridge */ registerFramesParentSandboxBridge: function(){ //var modified = false; var iframes = document.getElementsByTagName('iframe'); for(var i=iframes.length-1;i>=0;i--){ air.Introspector.registerFrame(iframes[i]); } var frames = document.getElementsByTagName('frame'); for(var i=frames.length-1;i>=0;i--){ air.Introspector.registerFrame(frames[i]); } //return modified; }, /** * @function registerDeactivateEventLisener * @description Hides the highlighting rectangle and deactivates inspect-clicking for this window */ registerDeactivateEventListener: function(){ air.Introspector.addEventListener(window.nativeWindow, air.Introspector.runtime.Event.DEACTIVATE, function(){ air.Introspector.hideHighlight(); air.Introspector.canClick =false; }); }, /** * @function registerChildSandboxBridge * @description Register childSandboxBridge for current iframe */ registerChildSandboxBridge: function(){ if(typeof childSandboxBridge=='undefined') childSandboxBridge={}; try{ childSandboxBridge.air_Introspector_remoteClick = function (){ try{ air.Introspector.remoteClick(); }catch(e){ alert(e+' '+e.line); } } childSandboxBridge.air_Introspector_isDebugOpen = function(){ return typeof air.Introspector.debugWindow!='undefined'; } childSandboxBridge.air_Introspector_toggleInspect = function (){ air.Introspector.init(false, true, function() { air.Introspector.debugWindow.toggleInspect(); }); } childSandboxBridge.air_Introspector_bridgeLoaded = function(){ var l = air.Introspector.bridgeCallbacks; for(var i=0;i<l;i++){ try{ air.Introspector.bridgeCallbacks[i](); }catch(e){ air.Introspector.logError(e); } } air.Introspector.bridgeCallbacks = []; } } catch(e){} }, /** * @function createOpenConsoleButton * @description Creates a button on the top-right corent of the iframe that will open the introspector */ createOpenConsoleButton: function(){ var consoleButton = document.createElement('input'); consoleButton.onclick = function(){ air.Introspector.init(true, true, function(){ }); } consoleButton.style.zIndex = 1000000; consoleButton.style.position = 'fixed'; consoleButton.style.right = '10px'; consoleButton.style.top = '10px'; consoleButton.type = 'button'; consoleButton.value = 'Open Introspector'; document.body.appendChild(consoleButton); }, /** * @function registerDOMEventListeners * @description Registers DOMSubtreeModified, DOMCharacterDataModified, mouseover */ registerDOMEventListeners: function(){ var hoverTimeout = null; //debugWindow should know about any dom change document.addEventListener('DOMSubtreeModified', function(e){ var debugWindow = air.Introspector.findDebugWindow(); if(debugWindow!=null&&debugWindow.isLoaded){ debugWindow.dom3Event(e); } }); document.addEventListener('DOMCharacterDataModified', function(e){ var debugWindow = air.Introspector.findDebugWindow(); if(debugWindow!=null&&debugWindow.isLoaded){ debugWindow.dom3Event(e); } }); document.body.addEventListener('mouseover', function(e){ if(air.Introspector.inspect){ setTimeout(function(){ if(isAppSandbox){ if(!nativeWindow.active) nativeWindow.activate(); } if(e.srcElement){ if(isAppSandbox){ air.Introspector.highlightElement(e.srcElement); air.Introspector.showHighlightLabels(e.srcElement.id, e.srcElement.nodeName, e.srcElement.outerHTML); }else{ air.Introspector.highlightElement(e.srcElement, function(){ air.Introspector.noBridge(function(){ parentSandboxBridge.air_Introspector_showHighlightLabels(e.srcElement.id, e.srcElement.nodeName, e.srcElement.outerHTML); }); }); } if(hoverTimeout) clearTimeout(hoverTimeout); hoverTimeout = setTimeout(function(){ air.Introspector.init(false, true, function (){ air.Introspector.debugWindow.setInspectElement(e.srcElement); }); }, 100); }else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -