📄 class.js
字号:
} // start globals capture isc.globalsSnapshot = []; }, _globalEvalWithCaptureEnd : function (error) { // restore any conflicting globals and undefine any evalVars we set on the window object var undef, evalVars = this._globalEvalVars; if (evalVars) { for (var evalVar in evalVars) { var globalValue = this._restoreGlobals[evalVar]; if (globalValue !== undef) window[evalVar] = this._restoreGlobals[evalVar]; else window[evalVar] = undef; // can't delete window[evalVar] in IE! } } var callback = this._globalEvalCallback; var globals = isc.globalsSnapshot; isc.globalsSnapshot = this._globalEvalCallback = this._globalEvalVars = this._restoreGlobals = null; this.fireCallback(callback, ["globals","error"], [globals, error]); }, // _notifyFunctionComplete // Static method called when the notification function for some observed method completes. _notifyFunctionComplete : function (object, methodName, queue) { // Decrement the 'notifyStack' flag. // This flag tracks whether the observed function is currently being run. We implement // this as a number indicating the depth of stacked calls to this method. queue._notifyStack -=1; // if the notifyStack is greater than zero the top level notificationFunction hasn't // yet exited, so don't proceed to modify observers. if (queue._notifyStack) return; var rebuildNotifyFunction = false; for (var i = 0; i < queue.length; i++) { // Clear any items that were 'ignored' while the notification function was running if (queue[i]._removedWhileNotificationRunning) { rebuildNotifyFunction = true; queue.removeItem(i); i--; continue; } // Clear any temp flags denoting observations set up while the notification function // was firing. if (queue[i]._addedWhileNotificationRunning) { delete queue[i]._addedWhileNotificationRunning; rebuildNotifyFunction = true; } } // If any observations were set up or cleared while the notify function was running, // rebuild the notification function now. if (rebuildNotifyFunction) { // If every observer has been cleared, restore the original function. if (queue.length == 0) { var saveMethodName = isc._obsPrefix+methodName; object[methodName] = object[saveMethodName]; // and clear the notification function slot. delete object[saveMethodName]; } else { // Rebuild the notification function to fire the new set of observers object[methodName] = object._makeNotifyFunction(methodName, queue); } } }, // Arrays of definitions (TabBar tabs, Layout members, SectionStack sections, Wizard pages..) // --------------------------------------------------------------------------------------- _$ID : "ID", getArrayItem : function (id, array, idProperty) { if (array == null) return null; // String: assume id property of section descriptor object if (isc.isA.String(id)) return array.find(idProperty || this._$ID, id); // Object: return unchanged if (isc.isAn.Object(id)) return id; // Number: assume index if (isc.isA.Number(id)) return array[id]; // otherwise invalid return null; }, getArrayItemIndex : function (id, array, idProperty) { if (isc.isA.Number(id)) return id; var item = isc.Class.getArrayItem(id, array, idProperty); return array.indexOf(item); }, // Getting DOM objects (going through these APIs makes cross-frame installation possible) // --------------------------------------------------------------------------------------- getWindow : ( isc.Browser.isSafari ? function () { return window; } : function () { return this.ns._window; } ), getDocument : ( isc.Browser.isSafari ? function () { return window.document; } : function () { return this.ns._document; } ), getDocumentBody : function (suppressDocElement) { var getDocElement = (!suppressDocElement && isc.Browser.isIE && isc.Browser.isStrict); var body = (getDocElement ? this.ns._documentElement : this.ns._documentBody); if (body != null) return body; var doc = this.getDocument(); if (getDocElement) { this.ns._documentElement = doc.documentElement; return this.ns._documentElement; } if (isc.Browser.isIE) { body = doc.body; } else { if (doc.body != null) body = doc.body; else { // XHTML: body not available via document.body (at least in FF 1.5) // Using the documentElement namespace future proofs us against future XHTML // versions var documentNS = doc.documentElement.namespaceURI; body = doc.getElementsByTagNameNS(documentNS, "body")[0]; if (body == null) { // XHTML: body not available via getElementsByTagNameNS() before page load // in FF 1.5 (possibly others), but is available via DOM navigation body = doc.documentElement.childNodes[1]; if (body != null && body.tagName != "body") body = null; } //this.logWarn("fetching body element: " + body); // don't cache failure to retrieve body, it should be available later until the // document is completely hosed if (!body) return null; } } this.ns._documentBody = body; return body; }, getActiveElement : function () { try { return this.getDocument().activeElement; } catch (e) { this.logWarn("error accessing activeElement: " + e.message); } return null; } }); // END addClassMethods(isc.Class)isc.Class.addClassMethods({ // synonym for backwards compatibility newInstance : isc.Class.create});// make the isc namespace available on all Class objectsisc.Class.ns = isc;// retrofit the ClassFactoryisc.addProperties(isc.ClassFactory, { ns : isc, getWindow : isc.Class.getWindow, getDocument : isc.Class.getDocument});//// add methods to all instances of any Class or subclass//isc.Class.addMethods({ //> @method class.init() (A) // // Initialize a new instance of this Class. This method is called automatically by // +link{Class.create()}. // <p> // Override this method to provide initialization logic for your class. If your class is // a subclass of a UI component (i.e. descendant of +link{Canvas}), override // +link{canvas.initWidget()} instead. // // @param [arguments 0-N] (any) All arguments initially passed to +link{Class.create()} // // @visibility external //< init : function () {}, // not generally required, but provided for consistency so that developers can call // destroy() without checking for it. destroy : function () { }, //> @attr class.addPropertiesOnCreate (Boolean : undefined : A) // // Set this instance property to <code>false</code> on your class to prevent // +link{Class.create()} from requiring Object arguments and auto-applying all // properties from those arguments to the newly created class. // <P> // // <p> // Regardless of the setting for addPropertiesOnCreate property, all arguments passed to // +link{Class.create()} are still passed on to +link{Class.init()}. // <P> // Note that it is not valid to set <code>addPropertiesOnCreate</code> to false for any // subclass of +link{Canvas} (Canvas relies on this property). // <p> // Note: You must set this property on the class instance as part of the class definition // via +link{Class.addProperties()} so that it takes effect before +link{Class.create()} is // called. // // @visibility external //< completeCreation : function (A,B,C,D,E,F,G,H,I,J,K,L,M) { if (this.addPropertiesOnCreate != false) { //>EditMode capture clean initialization data, and don't construct the actual // instance. This is used to load a set of components for editing. NOTE: // currently only applies to classes that addPropertiesOnCreate (which includes // all Canvas subclasses) if (isc.captureInitData) { var component = { className : this.Class, defaults : isc.addProperties({}, A,B,C,D,E,F,G,H,I,J,K,L,M) } if (!isc.capturedComponents) isc.capturedComponents = []; isc.capturedComponents.add(component); if (component.defaults.ID) { isc.ClassFactory.addGlobalID(component, component.defaults.ID); //isc.Log.logWarn("adding global component: " + component.defaults.ID); } return component; } //<EditMode isc.addProperties(this, A,B,C,D,E,F,G,H,I,J,K,L,M); } // call the init() routine on the new instance this.init(A,B,C,D,E,F,G,H,I,J,K,L,M); return this; }, //> @method class.getUniqueProperties // // Gets all non-internal properties that are the different between this object and its // prototype and returns a new object with those properties. // // NOTE: this will also skip an object ID (object.ID) // if it starts with our auto-generated ID string ("isc_OID_") // // NOTE: if your object points to some complex object, the clone will pick that up... :-( // // @param [returnProperties] (object) If passed in, properties will be added to this object. // If not passed, a new object will be created. // @return (Object) unique properties for this object //< // NOTE: not external because lots of random state is picked up, and lots of important // state is discarded. getUniqueProperties : function (returnProperties) { if (returnProperties == null) returnProperties = {}; var proto = this.getPrototype(); for (var property in this) { // ignore internal properties if (property.startsWith("_")) continue; // ignore the namespace pointer installed on every instance if (property == "ns") continue; // ignore ID if it's auto-generated if (property == "ID" && this.ID.startsWith("isc_OID_")) continue; var value = this[property]; // don't pick up functions (NOTE: we probably don't want to try to serialize // functions in general, or at least, that would be a very advanced and separate // serialization system. Also, note that if we don't ignore functions, we'd pick // up observations since observations replace the original function) if (isc.isA.Function(value)) continue; // if the property still has the default value for the class, ignore it if (value != proto[property]) { /* if (proto[property] != null) { this.logWarn("property: " + property + ": value " + this.echoLeaf(this[property]) + " !== proto value " + this.echoLeaf(proto[property])); } */ returnProperties[property] = this[property]; } } return returnProperties; }, //> @method class.clone // // Make a clone of this instance. // Gets all non-internal properties that are the different between this object and its // prototype and creates a new instance with those properties // // NOTE: if your object points to some complex object, the clone will pick that up... :-( // // @return (Class) clone of this class //< // NOT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -