📄 log.js
字号:
// if "logWarn" exists, use it so the object identifies itself, otherwise, // toString() the object as part of the log message template[1] = (object.logWarn ? methodName : methodName + " on " + this.echoLeaf(object)); template[3] = callTime.toFixed(3); var message = template.join(isc.emptyString); if (object.logMessage) object.logWarn(message); else isc.Log.logWarn(message); }, // check whether method "method" on "obj" can be observed. "obj" can be a string expression // that evaluates to an object validObservation : function (obj, method) { // Check that both fields are defined if (isc.isAn.emptyString(obj) || isc.isAn.emptyString(method)) return false; var object = obj; if (isc.isA.String(obj)) { // assume an expression (including a simple global ID) object = isc.Class.evaluate(obj); if (!object) { this.logWarn("MethodTimer: " + obj + " is not an object."); return false; } } // If the method was specifed with parentheses, remove them: if (method.indexOf("(") != -1) { method = method.slice(0, method.indexOf("(")); } // If the object is a class, then we check whether there's a static method or an instance // method with the given name on the class. if (isc.isA.ClassObject(object)) { var theProto = object.getPrototype(); // look for an instance method first and return the instance prototype if an // instance method was found if (isc.isA.Function(theProto[method])) return theProto; if (!object[method]) { this.logWarn("MethodTimer: " + method + " could not be found as a static or instance property on " + obj); return false; } // not a class object, check that the method exists on it. } else if (!object[method]) { this.logWarn("MethodTimer: " + method + " is undefined or null on " + obj); return false; } // Check that the method is in fact a function, and not some other type of object if (!isc.Func.convertToMethod(object, method)) { this.logWarn("MethodTimer: " + method + " is not a method on " + obj); return false; } // Passed all the checks, return the object return object; }, // Hiliting a Canvas // -------------------------------------------------------------------------------------------- hiliteCanvas : function (name) { var canvas = name; if (isc.isA.String(name)) canvas = window[name]; if (!isc.isA.Canvas(canvas)) { //>DEBUG this.logWarn("Unable to find specified canvas '" + name + "'."); //<DEBUG return; } this.showHiliteCanvas(canvas.getPageRect()); }, hiliteElement : function (name) { var element = name || this.elementToHilite; if (isc.isA.String(name)) element = isc.Element.get(name); if (element == null) { //>DEBUG this.logWarn("Unable to find specified element '" + name + "'."); //<DEBUG return; } this.showHiliteCanvas(isc.Element.getElementRect(element)); this.elementToHilite = null; }, showHiliteCanvas : function (rect) { // flash an outline around the canvas var hiliteCanvas = this._hiliteCanvas; if (!hiliteCanvas) { hiliteCanvas = this._hiliteCanvas = isc.Canvas.create({ ID:"logHiliteCanvas", autoDraw:false, overflow:"hidden", hide : function () { this.Super("hide", arguments); this.resizeTo(1,1); this.setTop(-20); }, border1:"2px dotted red", border2:"2px dotted white" }) } hiliteCanvas.setPageRect(rect); isc.Page.setEvent("click", hiliteCanvas.getID() + ".hide()"); hiliteCanvas.setBorder(hiliteCanvas.border1); hiliteCanvas.bringToFront(); hiliteCanvas.show(); // Flash the border a few times this._flashHiliteCanvas() }, hideHiliteCanvas : function () { if (this._hiliteCanvas) this._hiliteCanvas.hide(); }, _flashHiliteCanvas : function () { // a function to set the hilite canvas to flash on a timer a few times var borders = [this._hiliteCanvas.border1,this._hiliteCanvas.border2]; for (var i=0; i<7; i++) { isc.Timer.setTimeout({ target:this._hiliteCanvas, methodName:"setBorder", args:[borders[i%2]] }, (500*i) ) } } });// LogViewer -- simple log viewer -- use to display the log visually.// ---------------------------------------------------------------------------------------// Automatically updates whenever the log is added to.isc.ClassFactory.defineClass("LogViewer");isc.LogViewer.addClassMethods({ // the GlobalLogCookie stores Log window sizing info that's required to be at path / to // work. getGlobalLogCookie : function () { var globalLogCookie = isc.Cookie.get("GLog"); if (!globalLogCookie) return null; try { var fn = new Function("return " + globalLogCookie); return fn(); } catch (e) { this.logWarn("bad log cookie: " + globalLogCookie + this.getStackTrace()); } }, // The LogCookie is stored at /isomorphic/system/helpers so as not to pollute the / HTTP // header space. This cookie contains everything except what the GlobalLogCookie has getLogCookie : function () { var logCookie = isc.Cookie.get("Log"); if (!logCookie) return null; try { var fn = new Function("return " + logCookie); return fn(); } catch (e) { this.logWarn("bad log cookie: " + logCookie + this.getStackTrace()); } }});isc.LogViewer.addMethods({ // whether the log window is loaded and ready to be accessed logWindowLoaded : function () { // We get bizarre errors in IE (typically: "trying to execute a freed script") if we // try to access elements of the logWindow page from the main frame if the log window // is being loaded, and replacing an existing log window. // This is probably due to window.open() returning a handle that is in an invalid state // until the new log window finished loading. // Therefore we wait for the log window to actually call back to the main frame and set // a flag telling us it has loaded. return (this._logWindowLoaded && this._logWindow != null && !this._logWindow.closed ); }, // Note: multiple-monitors: the log window position that's saved doesn't work properly // unless the log window is in the primary monitor. Also, negative coordinates will mean // that the window will be displayed at (0, 0) instead. showLog : function (loading, logWindow, dontSaveState) { // allow a log window to be passed in. This allows the log window to reconnect to the // opener after the opener has been navigated to a new ISC page. if (logWindow) this._logWindow = logWindow; //alert("showLog called: loading: " + loading + ", logWindow: " + this._logWindow + // ", form: " + (this._logWindow ? this._logWindow.resultsForm : null)); // if the _logWindow property is set up, it's a pointer to a log window we previously // opened. If we can get into its form, just replace the form contents which is much // faster. if (this.logWindowLoaded()) { this._logWindow.setResultsValue(isc.Log.getMessages().join("\r")); this._logWindow.focus(); return; } // Assume that this is the only logViewer instance running - make sure it's available // as Log.logViewer if (!isc.Log.logViewer) isc.Log.logViewer = this; // if we have a log window, and it's not closed, we're done // (Note - if it is in the process of loading, we will rightly leave it alone) if (this._logWindow && !this._logWindow.closed) { return; } var rect = {}, globalLogCookie = (dontSaveState ? null : isc.LogViewer.getGlobalLogCookie()); if (globalLogCookie != null) { rect = globalLogCookie; // Commented out; in a multi-mon config coordinates could be reset even if they // weren't off-screen /* // make sure the log window doesn't end up off the screen rect.left = rect.left > screen.availWidth ? 0 : rect.left; rect.top = rect.top > screen.availHeight ? 0 : rect.top; */ } else { rect.left = 100; rect.top = 100; rect.width = 640; rect.height = 480; } var windowSettings = "RESIZABLE,WIDTH=" + rect.width + ",HEIGHT=" + rect.height; if (globalLogCookie) { if (isc.Browser.isIE) { windowSettings += ",left=" + rect.left + ",top=" + rect.top; } else { windowSettings += ",screenX=" + rect.left + ",screenY=" + rect.top; } if (globalLogCookie.evals) this._currentEval = globalLogCookie.evals.length - 1; } // if this window is a satellite window opened by a window with isc in it, then if we // want a log window for the satellite window, we need to name it something different to // avoid clobbering the main window's Log window. This allows us to use a Log window to // debug a datePicker, IFRAME, or the Log window itself. var subWindow = (window.opener && window.opener.isc); this._logWindow = window.open(isc.Page.getIsomorphicClientDir() + "helpers/Log.html", (subWindow ? "_subWindowLog" : "_simpleLog") // avoid log window name collisions between Devenv and released // versions of ISC. NOTE: we'd use the version number, but // IE only is unhappy with a window name of eg "log5.5". + (isc.version.contains("version") ? "Dev" : "") , windowSettings); this._initLogWindow(dontSaveState); }, _logWindowPollInterval: 25, _initLogWindow : function (dontSaveState) { if (isc.Browser.isIE) { // if we've set document.domain, then attempting to immediately set a property on // the new window, before it can adjust its document.domain automatically, results // in an 'Access denied' error, so poll. try { this._logWindow._accessTest = true; } catch (e) { this.delayCall("_initLogWindow", [dontSaveState], this._logWindowPollInterval); return; } } // In IE, set up a pointer to this window in the newly opened log window // This is necessary as IE will not replace the 'window.opener' property to point // to this window, if the above call replaced the contents of an already open // log window. if (isc.Browser.isIE) { this._logWindow.launchWindow = window; } // If we don't want the log window to attempt to save / retrieve state from cookies // set a flag on it if (dontSaveState) this._logWindow.dontSaveState = true; // focus in the log window we just opened, to bring it in front of whatever other windows // might be occluding it (WinAmp et al). // Do this on an idle. Otherwise some browsers will focus in the log window, then // as code continues to execute in the main window, focus back in the main window. // (Mac Moz is a specific e
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -