?? airintrospector.js
字號:
/*
* Ext JS Library 0.20
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/* AIRIntrospector.js - Revision: 0.15.88 */
// Copyright 2007-2008. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Adobe Systems Incorporated nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
var air;
(function(){
if(typeof air=='undefined') air = {};
air.Introspector = {};
// Check the runtime.
if(typeof window.runtime!='undefined' && typeof window.nativeWindow!='undefined')
var isAppSandbox = true;
else
var isAppSandbox = false;
//=======================================================================================================================================================
//Introspector.js
//=======================================================================================================================================================
//----------------------------------------------------------------------------------------------------
/**
* @API air.Introspector.Console
* @description Exposes log, warn, info, error, dump to the user
* THIS IS THE ONLY SUPPORTED APIs
*/
air.Introspector.Console = {
log: function(){
air.Introspector.logArguments(arguments,
{htmlLoader:isAppSandbox?window.htmlLoader:null});
},
warn : function(){
air.Introspector.logArguments(arguments,
{htmlLoader:isAppSandbox?window.htmlLoader:null, type:'warn'});
},
info : function(){
air.Introspector.logArguments(arguments,
{htmlLoader:isAppSandbox?window.htmlLoader:null, type:'info'});
},
error : function(){
air.Introspector.logArguments(arguments,
{htmlLoader:isAppSandbox?window.htmlLoader:null, type:'error'});
},
dump : function(obj, level){
air.Introspector.logArguments(air.Introspector.dump(obj, level),
{htmlLoader: isAppSandbox?window.htmlLoader:null, usePre:true});
}
};
//----------------------------------------------------------------------------------------------------
air.Introspector.config = {
showTimestamp: true, //Make the console show time stamps before each line
showSender: true, //Make the console show time stamps
wrapColumns: 2000, //Source files are soft-wrapped at around 2000 columns by default
flashTabLabels: true, //Console and xhr columns can flash whenever something happend to them (eg. logged something). You can turn it off
//by setting this to false
closeIntrospectorOnExit: true, //Makes the inspector window close when the last window closed
debugRuntimeObjects: true, //Also expand ActionScript objects
introspectorKey:122, //Inspect key - by default it is F11 (122)
debuggerKey:123, //Toggle inspectors visibility - by default it is F12 (123)
useAirDebugHtml: false, //Internal only
};
/**
* @module air.Introspector
*/
air.Introspector.extend = function(dst, src){
//Take every property from src and put it in dst
for(var i in src){
dst[i]=src[i];
}
};
// Checking if the user has configured Introspector using global AIRIntrospectorConfig variable
if(typeof AIRIntrospectorConfig!='undefined'){
air.Introspector.extend(air.Introspector.config, AIRIntrospectorConfig);
}
var eventListeners = [];
// Can not expand ActionScript objects from remote sandbox - we can not even access ActionScript from there
// just disabled this feature
if(!isAppSandbox) air.Introspector.config.debugRuntimeObjects = false;
// Made this use g/setters in order to make it easy to send its value over the bridge
air.Introspector.__defineGetter__('inspect', function(){
return air.Introspector._inspect;
});
air.Introspector.__defineSetter__('inspect', function(value){
air.Introspector._inspect=value;
if(!isAppSandbox){
setTimeout(function(){
air.Introspector.noBridge(function(){
parentSandboxBridge.air_Introspector_setInspect(value);
});
}, 0);
}else{
if(!value){
air.Introspector.hideHighlight();
}
}
});
air.Introspector.extend(air.Introspector, {
/**
* Makes it easier to acces runtime packages
* it makes sense only in the application sandbox
*/
runtime: isAppSandbox?{
HTMLLoader : window.runtime.flash.html.HTMLLoader,
Event : window.runtime.flash.events.Event,
IOErrorEvent: window.runtime.flash.events.IOErrorEvent,
NativeApplication: window.runtime.flash.desktop.NativeApplication,
URLLoader : window.runtime.flash.net.URLLoader,
URLRequest : window.runtime.flash.net.URLRequest,
NativeWindowInitOptions : window.runtime.flash.display.NativeWindowInitOptions,
Capabilities: window.runtime.flash.system.Capabilities,
trace : window.runtime.trace,
}:null,
_inspect: false,
remoteInspect: false,
canClick: false,
bridgeCallbacks: [],
/**
* Different coloring styles for tag names, by default 'default' is used
* Undocumented feature
* - you can change the color of elements while inspecting by tag name, check bellow the body: 0x00CC00 line,
* uncomment that line, duplicate and change it with your own colors
*/
highlightBgColors: {
'default': 0xFFCC00,
//body: 0x00CC00,
},
/**
* @function trimRegExp
* @description Trims spaces from a string
* @private
*/
trimRegExp: /^[\s\r\n]*([\s\S]*?)[\s\r\n]*$/g,
trim:function(str){
return str.replace(air.Introspector.trimRegExp, '$1');
},
/**
* @function blockWrap
* @description Wraps a string by air.Introspector.config.wrapColumns columns
*/
blockWrap: function(str){
//used for spliting large lines in <pre>
var cols = air.Introspector.config.wrapColumns;
var lines = str.split(/\n/);
var buffer = [];
var l = lines.length;
var lineNumbers = [];
for(var i=0;i<l;i++){
lineNumbers.push(i+1);
var line = lines[i];
while(line.length>cols){
buffer.push(line.substr(0, cols));
line = line.substr(cols);
lineNumbers.push('');
}
buffer.push(line);
}
lineNumbers.push('EOF');
return [buffer.join('\n'), lineNumbers.join('\n')];
},
/**
* @function getTextFormat
* @description Returns a new flash TextField
*/
createTextField: function(parentSprite, fontSize, fontBold) {
if(isAppSandbox){
var tf = new runtime.flash.text.TextField();
tf.embedFonts = false;
tf.autoSize = runtime.flash.text.TextFieldAutoSize.LEFT;
tf.antiAliasType = runtime.flash.text.AntiAliasType.ADVANCED;
tf.defaultTextFormat = air.Introspector.getTextFormat(fontSize, fontBold);
tf.selectable = false;
tf.mouseEnabled = true;
tf.x = 4;
tf.text = "";
if(parentSprite.numChildren > 0) {
var sibling = parentSprite.getChildAt(parentSprite.numChildren - 1);
tf.y = sibling.y + sibling.height + 15;
}
parentSprite.addChild(tf);
return tf;
}else{
//should not get here
return null;
}
},
/**
* @function getTextFormat
* Returns a new flash TextFormat
* see createTextField
*/
getTextFormat: function(fontSize, fontBold){
if(isAppSandbox){
var format = new runtime.flash.text.TextFormat();
format.size = fontSize;
format.font = "Tahoma";
format.bold = fontBold;
format.color = 0x330066;
return format;
}else{
//should not get here
return null;
}
},
/**
* @function extendRect
* @description Initializes the sprite with values from the rectangle
*/
extendRect: function(sprite, rect){
sprite.x = rect.x;
sprite.y = rect.y;
sprite.width = rect.width;
sprite.height = rect.height;
sprite.scaleX = rect.scaleX;
sprite.scaleY = rect.scaleY;
},
/**
* @function showHighlight
* @description Shows a highlighting flash sprite using coordinates from rectangle
*/
showHighlight: function(rect){
if(isAppSandbox){
//dehilight everyone else
var ownedWindows = air.Introspector.getHtmlWindows();
for(var i=ownedWindows.length-1;i>=0;i--){
try{
ownedWindows[i].htmlLoader.window.air.Introspector.hideHighlight();
}catch(e){
//no air.Introspector
}
}
air.Introspector.extendRect(air.Introspector.highlightSprite, rect);
}else{
setTimeout(function(){
air.Introspector.noBridge(function(){
parentSandboxBridge.air_Introspector_showHighlight(rect);
});
}, 0);
}
},
/**
* @function hideHighlight
* @description Make the higlight box go away
*/
hideHighlight: function(){
if(isAppSandbox){
air.Introspector.extendRect(air.Introspector.highlightSprite, {x:0, y:0, width:0, height:0, scaleX:0, scaleY:0});
air.Introspector.highlightText.visible = false;
}else{
setTimeout(function(){
try{
parentSandboxBridge.air_Introspector_hideHighlight();
}catch(e){
// no bridge yet
}
}, 0);
}
},
/**
* @function remoteClick
* @description Make the remote sandbox know that the inspection finished
*/
remoteClick: function(){
air.Introspector.debugWindow.finishInspect(false);
air.Introspector.hideHighlight();
},
/**
* @function createHighlight
* @description Creates a flash sprite used to higlight elements
* By using this method we are sure that no dom manipulation is done and
* no style is changed in HTML.
*/
createHighlight: function(){
if(isAppSandbox){
var sprite = new runtime.flash.display.Sprite();
sprite.mouseEnabled = false;
sprite.width = 0;
sprite.height = 0;
sprite.buttonMode = true;
var prevent = function(element, event, isClick){
air.Introspector.addEventListener(element, event, function(e){
if((air.Introspector.inspect||air.Introspector.remoteInspect) &&sprite.hitTestPoint(e.stageX, e.stageY)){
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
if(isClick&&air.Introspector.canClick){
if(air.Introspector.remoteInspect){
try{
air.Introspector.inspectFrame.contentWindow.childSandboxBridge.air_Introspector_remoteClick();
}catch(e){ air.Introspector.noChildBridge(air.Introspector.inspectFrame); }
}else{
air.Introspector.debugWindow.finishInspect(false);
air.Introspector.hideHighlight();
}
}
}
}, true, 2000000);
};
var check = function(element, event){
air.Introspector.addEventListener(element, event, function(e){
if((air.Introspector.inspect||air.Introspector.remoteInspect)&&nativeWindow.active){
setTimeout(function(){
air.Introspector.canClick = true;
}, 100);
}
}, true, 200000);
}
var labelMover = function(element, event){
air.Introspector.addEventListener(element, event, function(e){
if((air.Introspector.inspect||air.Introspector.remoteInspect)){
air.Introspector.highlightText.x = e.stageX+15;
air.Introspector.highlightText.y = e.stageY+15;
// air.Introspector.highlightText.visible = true;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -