home *** CD-ROM | disk | FTP | other *** search
- /* layermgr.js
-
- Copyright (c) 1997 Netscape Comunications Corporation,
- All Rights Reserved
-
- Handles layer management in an efficient way
-
- */
-
- // An object which encapsulates the layer loading.
- //
- // layerObj specifies a layer object in which to load the content;
- // null specifies that the layer should be created when it's the layer's
- // turn to load.
- //
- // layerURL gives the URL of source content to load into the layer.
- // null indicates that no special loading should occur (usually only useful
- // if layerObj is also null).
- //
- // container is used only for new layers, to specify the parent layer
- //
- // notifier specifes an object whose layerLoaded function will be called,
- // with the parameter specified in parameter when the layer loads.
- //
- //
-
- function LayerLoadObject(layerObj, url, container, notifier, parameter, external)
- {
- this.layerObj = layerObj;
- this.layerURL = url;
- this.container = container;
- this.notifier = notifier;
- this.parameter = parameter
- this.nextLoad = null;
- this.external = external;
- }
-
-
- // A "stock" notifier to load content into newly created layers.
- // Takes a layerLoadObject.
-
- function LayerMgr_NewLayerAndLoad(layerObj, layerLoadObject) {
- // just re-queue the request.
-
- layerLoadObject.layerObj = layerObj;
-
- window.layerManager.layerLoad(layerLoadObject);
-
- return;
- }
-
- // LayerLoad takes a layer load object and adds it to the pending queue
- // of loading operations.
-
- function LayerMgr_LayerLoad(layerLoadObject)
- {
-
- // Add this entry to the end of the queue (atomically) and then
- // schedule it for loading.
-
- if (this.mgrBusy == true) {
- // java.lang.System.out.println("Deferring load");
- setTimeout(this.layerLoad, 100, layerLoadObject);
- }
-
- this.mgrBusy = true; // used to semaphore the adding to the queue
-
- if ((!this.lastLoad) || (this.lastLoad == null)) {
- // if there's no tail, we assume there's also no head
-
- this.loading = layerLoadObject;
- this.lastLoad = layerLoadObject;
-
- // java.lang.System.out.println("Scheduled a load");
-
- this.mgrBusy = false;
-
- this.startLoad();
- } else {
- // got a tail
-
- // java.lang.System.out.println("Added a load (previous last: " + this.lastLoad.layerObj.name);
-
- this.lastLoad.nextLoad = layerLoadObject;
- /* if (this.lastLoad == null) {
- java.lang.System.out.println("lastLoad was null");
- } else {
- java.lang.System.out.println("lastLoad item was " + this.lastLoad.layerObj);
- }
- */
- this.lastLoad = layerLoadObject;
-
- /* if (this.lastLoad == null) {
- java.lang.System.out.println("lastLoad is null");
- } else {
- java.lang.System.out.println("lastLoad item is " + this.lastLoad.layerObj);
- }
- */
- this.mgrBusy = false;
- }
-
- return;
- }
-
- // StartLoad gets called in order to begin loading of the page
- // currently at the head of the queue.
-
- function LayerMgr_StartNextLoad()
- {
- var loadObject = this.loading;
-
- if (loadObject && (loadObject != null)) {
- // ok, so load this thing.
-
- // for sanity checking
- if (this.isLoading == true) {
- java.lang.System.out.println("Warning: another layer is already loading");
- }
-
- this.isLoading = true;
-
- if (loadObject.layerObj == null) {
- // a request to create a new layer
- var newLayer = this.layerNew(200, loadObject.container);
-
- // if we also need to load a URL
-
- if (loadObject.layerURL != null) {
- window.layerManager.loading.layerObj = newLayer;;
- newLayer.visibility = "show";
- newLayer.src = loadObject.layerURL;
- if(loadObject.external == true) {
- newLayer.__parent__ = null;
- newLayer.initStandardObjects();
- newLayer.Event = Event;
- }
- }
-
- /* if (loadObject.layerURL != null) {
- // it's not null, so we'll queue a new request for
- // this layer.
-
- var newLoadObj = new LayerLoadObject(newLayer,
- loadObject.layerURL, null, loadObject.notifier,
- loadObject.parameter, loadObject.external);
-
- loadObject.layerObj = newLayer;
- loadObject.notifier = LayerMgr_NewLayerAndLoad;
- loadObject.parameter = newLoadObj; */
-
- // java.lang.System.out.println("Created a new layer named " + newLayer.name);
-
- /* this.layerLoad(newLoadObj);
- }*/
- } else {
- // only do the load
-
- // java.lang.System.out.println("Loading " + loadObject.layerURL + " into an existing layer named " + loadObject.layerObj.name);
-
- loadObject.visibility = "show";
- loadObject.layerObj.src = loadObject.layerURL;
- if(loadObject.external == true) {
- loadObject.layerObj.__parent__ = null;
- loadObject.layerObj.initStandardObjects();
- loadObject.layerObj.Event = Event;
- }
- }
-
- this.isLoading = false;
- }
-
- }
-
-
- // CaptureLoad handles the task of synchronizing the load operations,
- // firing off notifications, and generally keeping things in order in
- // the layer manager.
-
- function LayerMgr_CaptureLoad(e)
- {
- // Ok, we've gotten something. Let's figure out if it's what
- // we're currently thinking we're loading
-
- var currentLoad = window.layerManager.loading;
-
- // alert("currentLoad " + currentLoad);
-
- if (currentLoad && (currentLoad != null)) {
- if (currentLoad.layerObj != e.target) {
- // not the load we were waiting for; it's probably one of
- // it's children. In any event, abort and get out.
- //java.lang.System.out.println("Returning, wrong target; wanted: " + currentLoad.layerObj);
- //java.lang.System.out.println("got: " + e.target);
-
- if (e.target != window) {
- //java.lang.System.out.println("Returning, wrong target layer (expecting " + currentLoad.layerObj.name + "; got " + e.target.name);
- // in other words, we're loading a layer
- window.routeEvent(e);
- } else {
- if (window.onLoadHandler && (window.onLoadHandler != null)) {
- window.onLoadHandler(e);
- }
- }
- return;
- }
-
- //java.lang.System.out.println("Got a load capture for " + e.target.name);
-
- // Ok, we've got the call, so do the notification
-
- if (currentLoad.notifier != null && currentLoad.notifier.layerLoaded) {
- currentLoad.notifier.layerLoaded(e.target, currentLoad.parameter);
- }
-
- // And remove from the queue
-
- window.layerManager.loading = window.layerManager.loading.nextLoad;
- if (window.layerManager.loading == null) {
- // java.lang.System.out.println("No more items to process");
- window.layerManager.lastLoad = null;
- }
-
- } else {
- // This is irregular. We don't think we're loading something,
- // but we apparently are...
- }
-
- if (e.target != window) {
- // in other words, we're loading a layer
- window.routeEvent(e);
-
- } else {
- if (window.onLoadHandler && (window.onLoadHandler != null)) {
- window.onLoadHandler(e);
- }
- }
-
- window.layerManager.startLoad();
-
-
- }
-
- // Called to create a new layer or recycle one from a previously used space.
-
- function LayerMgr_NewLayer(width, parent)
- {
- var returnLayer;
- var count;
-
- count = this.layerCount--; // this must be an atomic operation
-
- if (count > 0) {
- returnLayer = this.layerArray[count];
- } else {
- this.layerCount++;
- returnLayer = new Layer(width, parent);
- }
-
- return returnLayer;
- }
-
- // Return a layer to the free store
-
- function LayerMgr_DeleteLayer(thisLayer)
- {
- if (thisLayer && thisLayer != null) {
- thisLayer.src="about:blank"; // clear out any references
-
- var count = this.layerCount++;
-
- this.layerArray[count] = thisLayer;
- }
-
- return;
- }
-
- function LayerManager() {
- this.layerCount = 0;
- this.layerArray = new Array(5);
-
- this.layerDelete = LayerMgr_DeleteLayer;
- this.layerNew = LayerMgr_NewLayer;
-
- this.loading = null;
- this.lastLoad = null;
-
- this.layerLoad = LayerMgr_LayerLoad;
- this.startLoad = LayerMgr_StartNextLoad;
-
- this.mgrBusy = false;
- this.isLoading = false;
-
- //window.captureEvents(Event.LOAD);
- //window.onload = LayerMgr_CaptureLoad;
-
- netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
- window.enableExternalCapture();
-
- document.captureEvents(Event.LOAD);
- document.onload = LayerMgr_CaptureLoad;
-
- window.layerManager = this;
-
- // java.lang.System.out.println("Layer Manager Created");
- }
-
- void(0);
-
-