|
|
|
Author: max
Date: 2007-09-27 22:30:20 -0700 (Thu, 27 Sep 2007) New Revision: 6661 Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/dhtml/LzHistory.js openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzBrowser.as openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzHistory.as openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/views/LaszloCanvas.lzs openlaszlo/branches/wafflecone/lps/includes/source/embednew.js openlaszlo/branches/wafflecone/lps/includes/source/flash.js openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js Log: Change 20070927-maxcarlson-6 by maxcarlson@plastik on 2007-09-27 18:44:35 PDT in /Users/maxcarlson/openlaszlo/wafflecone for http://svn.openlaszlo.org/openlaszlo/branches/wafflecone Summary: UPDATED: Fix history in swf7/8 and dhtml New Features: Bugs Fixed: Technical Reviewer: promanik QA Reviewer: lhenrywilkins@laszlosystems.com Doc Reviewer: (pending) Documentation: Release Notes: Details: LzSprite.js - Do callback to _ready when canvas initializes. LzHistory.as - Use correct syntax for LzBrowser.callJS(). Clear out old __lzloading code. LzBrowser.as - Reset __jscallback to null when there is no callback. LzHistory.js - Clear out old __lzloading code. LaszloCanvas.lzs - Rely on browser history event callbacks to initialize history state instead of explicit call at canvas init time. embednew.js - Hand merge changes related to onloaded from trunk. lzhistory.js - Store and reset the document title in IE to keep the window title from changing. flash.js - Ensure callback methods are executed in the proper scope for flash < 8. Tests: http://localhost:8080/trunk/test/history/history.lzx in dhtml, swf7 and 8 in Firefox mac, IE 6/7 and Safari 2. Also tested webtop and verified that both bugs are fixed in future/lzmail/main.lzx - I used r11 of uicontroller.lzx to bring back the history functionality. Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js =================================================================== --- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js 2007-09-28 05:30:20 UTC (rev 6661) @@ -24,6 +24,9 @@ if (p.bgcolor) div.style.backgroundColor = p.bgcolor; if (p.width) div.style.width = p.width; if (p.height) div.style.height = p.height; + if (p.id) { + this._id = p.id; + } if (this.quirks.canvas_div_cannot_be_clipped == false && p.width && p.width.indexOf('%') == -1 && p.height && p.height.indexOf('%') == -1 ) { div.style.clip = 'rect(0px ' + p.width + ' ' + p.height + ' 0px)'; div.style.overflow = 'hidden'; @@ -358,6 +361,7 @@ var s = document.getElementById('lzsplash'); if (s) LzSprite.prototype.__discardElement(s); + if (this._id) Lz[this._id]._ready(); } } Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/dhtml/LzHistory.js =================================================================== --- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/dhtml/LzHistory.js 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/dhtml/LzHistory.js 2007-09-28 05:30:20 UTC (rev 6661) @@ -37,7 +37,6 @@ LzHistory.setHistory = function(s) { //Debug.write('setHistory', s); Lz.history.set(s); - this.__lzloading = true; } /** @@ -54,12 +53,6 @@ LzHistory.__lzhistq = []; /** @access private */ LzHistory.__lzcurrstate = {}; -/** @access private */ -LzHistory.__lzloading = false; -/** @access private */ -LzHistory.__lzloadcache = {}; -/** @access private */ -LzHistory.__loadcacheused = false; DeclareEvent(LzHistory, 'onoffset' ); @@ -81,23 +74,6 @@ //Debug.write('restoring state ', global[o.c], o.c, o.n, o.v); global[o.c].setAttribute(o.n, o.v); } - - - // copy values cached during load - if (this.__loadcacheused) { - var out = this.__lzhistq[this.offset]; - if (out == null) out = {}; - var u; - for (u in this.__lzloadcache) { - //Debug.write('restoring', o, this.__lzloadcache[u]); - out[u] = this.__lzloadcache[u]; - } - this.__lzhistq[this.offset] = out; - this.__lzloadcache = {}; - this.__loadcacheused = false; - } - - this.__lzloading = false; } /** @@ -137,16 +113,9 @@ LzHistory.save = function(who, prop, val) { // strip off __ so keys can be listed if (val == null) val = global[who][prop]; - if (this.__lzloading) { - //Debug.write('caching'); - // cache values until load finishes - this.__lzloadcache[who] = {c: who, n: prop, v: val}; - this.__loadcacheused = true; - } else { - //Debug.write('set state of ',u,' to ', this.__lzcurrstate); - this.__lzcurrstate[who] = {c: who, n: prop, v: val}; - this.__lzdirty = true; - } + //Debug.write('set state of ',u,' to ', this.__lzcurrstate); + this.__lzcurrstate[who] = {c: who, n: prop, v: val}; + this.__lzdirty = true; } /** Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzBrowser.as =================================================================== --- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzBrowser.as 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzBrowser.as 2007-09-28 05:30:20 UTC (rev 6661) @@ -87,6 +87,8 @@ if (typeof callback == 'function') { this.__jscallback = callback; + } else { + this.__jscallback = null; } var args = [].slice.call(arguments, 2); args.unshift(js, LzBrowser.callJSReturn); Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzHistory.as =================================================================== --- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzHistory.as 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/platform/swf/LzHistory.as 2007-09-28 05:30:20 UTC (rev 6661) @@ -37,8 +37,7 @@ LzHistory.__setHistory = function(s) { //Debug.write('__setHistory', s); LzBrowser._jsreset(); - LzBrowser.callJS('Lz.history.set("' + s + '")', false); - this.__lzloading = true; + LzBrowser.callJS('Lz.history.set', null, s); } /** @@ -58,50 +57,31 @@ LzHistory.__lzhistq = []; /** @access private */ LzHistory.__lzcurrstate = {}; -/** @access private */ -LzHistory.__lzloading = false; -/** @access private */ -LzHistory.__lzloadcache = {}; -/** @access private */ -LzHistory.__loadcacheused = false; DeclareEvent(LzHistory, 'onoffset' ); - /** * @access private */ LzHistory.receiveHistory = function(o){ - //Debug.write('onhistory ', o, this.__lzhistq); + var l = this.__lzhistq.length; o *= 1; - if (! o) o = 0; - if (o > this.__lzhistq.length - 1) o = this.__lzhistq.length; - this.offset = o; - if (this.onoffset.ready) this.onoffset.sendEvent(o); - + if (! o) { + o = 0; + } else if (o > l - 1) { + o = l; + } + var h = this.__lzhistq[o]; for (var u in h) { - var o = h[u]; - //Debug.write('restoring state ', global[o.c], o.c, o.n, o.v); - global[o.c].setAttribute(o.n, o.v); + var obj = h[u]; + //Debug.write('restoring state ', global[obj], obj, obj.n, obj.v); + global[u].setAttribute(obj.n, obj.v); } - - - // copy values cached during load - if (this.__loadcacheused) { - var out = this.__lzhistq[this.offset]; - if (out == null) out = {}; - var u; - for (u in this.__lzloadcache) { - //Debug.write('restoring', o, this.__lzloadcache[u]); - out[u] = this.__lzloadcache[u]; - } - this.__lzhistq[this.offset] = out; - this.__lzloadcache = {}; - this.__loadcacheused = false; - } - - this.__lzloading = false; + + this.offset = o; + //Debug.write('onhistory ', o, this.__lzhistq); + if (this.onoffset.ready) this.onoffset.sendEvent(o); } /** @@ -197,16 +177,9 @@ } // strip off __ so keys can be listed if (val == null) val = global[who][prop]; - if (this.__lzloading) { - //Debug.write('caching'); - // cache values until load finishes - this.__lzloadcache[who] = {c: who, n: prop, v: val}; - this.__loadcacheused = true; - } else { - this.__lzcurrstate[who] = {c: who, n: prop, v: val}; - this.__lzdirty = true; - //Debug.write('set state of ',who,' to ', this.__lzcurrstate); - } + this.__lzcurrstate[who] = {n: prop, v: val}; + this.__lzdirty = true; + //Debug.write('set state of ',who,' to ', this.__lzcurrstate); } /** @@ -268,12 +241,6 @@ this.move(-1); } -/** get history from local object - * @access private - */ -LzHistory.__restorehistory = function() { - this.receiveHistory(this.offset); -} /** @access private */ LzHistory.__initPersist = function() { if (this.persist) { Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/views/LaszloCanvas.lzs =================================================================== --- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/views/LaszloCanvas.lzs 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/views/LaszloCanvas.lzs 2007-09-28 05:30:20 UTC (rev 6661) @@ -484,10 +484,6 @@ this.init(); this.sprite.init(true); - if ($dhtml) { - } else { - LzHistory.__restorehistory(); - } if (this.oninit.ready) this.oninit.sendEvent( this ); if (this.datapath && this.datapath.__LZApplyDataOnInit) { this.datapath.__LZApplyDataOnInit(); Modified: openlaszlo/branches/wafflecone/lps/includes/source/embednew.js =================================================================== --- openlaszlo/branches/wafflecone/lps/includes/source/embednew.js 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/lps/includes/source/embednew.js 2007-09-28 05:30:20 UTC (rev 6661) @@ -109,13 +109,15 @@ ,setCanvasAttribute: Lz._setCanvasAttributeSWF ,getCanvasAttribute: Lz._getCanvasAttributeSWF ,callMethod: Lz._callMethodSWF - ,_loaded: Lz._loaded + ,_ready: Lz._ready + ,loaded: false ,_setCanvasAttributeDequeue: Lz._setCanvasAttributeDequeue } + // for callbacks onload + Lz._swfid = properties.id; + dojo.flash.addLoadedListener(Lz._loaded); if (! Lz['setCanvasAttribute']) { Lz.setCanvasAttribute = Lz[properties.id].setCanvasAttribute; - // for queuing - Lz._id = properties.id; } if (! Lz['getCanvasAttribute']) Lz.getCanvasAttribute = Lz[properties.id].getCanvasAttribute; if (! Lz['callMethod']) Lz.callMethod = Lz[properties.id].callMethod; @@ -191,6 +193,8 @@ Lz[properties.id] = { runtime: 'dhtml' ,_id: properties.id + ,_ready: Lz._ready + ,loaded: false ,setCanvasAttribute: Lz._setCanvasAttributeDHTML ,getCanvasAttribute: Lz._getCanvasAttributeDHTML } @@ -330,7 +334,7 @@ * @param hist:Boolean value - if true, add a history event. */ _setCanvasAttributeSWF: function (name, value, hist) { - if (dojo.flash.ready) { + if (this.loaded) { if (hist) { Lz.history._store(name, value); } else { @@ -342,7 +346,6 @@ } else { this._setCanvasAttributeQ.push([name, value, hist]); } - dojo.flash.addLoadedListener(this._loaded); } } ,/** @@ -366,18 +369,29 @@ _loaded: function () { if (dojo.flash.info.commVersion == 8) { // wait a bit longer for Flash to init - setTimeout('Lz["'+Lz._id +'"]._setCanvasAttributeDequeue()', 100); + setTimeout('Lz["'+Lz._swfid +'"]._ready.call(Lz["'+Lz._swfid+'"])', 100); } else { - Lz[Lz._id]._setCanvasAttributeDequeue(); + Lz[Lz._swfid]._ready.call(Lz[Lz._swfid]); } } ,/** @access private */ _setCanvasAttributeDequeue: function () { - while (Lz._setCanvasAttributeQ.length > 0) { - var a = Lz._setCanvasAttributeQ.pop(); - Lz.setCanvasAttribute(a[0], a[1], a[2]); + while (this._setCanvasAttributeQ.length > 0) { + var a = this._setCanvasAttributeQ.pop(); + this.setCanvasAttribute(a[0], a[1], a[2]); } } + ,/** @access private */ + _ready: function () { + this.loaded = true; + Lz.loaded = true; + if (this._setCanvasAttributeQ) { + this._setCanvasAttributeDequeue(); + } + if (this.onload && typeof this.onload == 'function') { + this.onload(); + } + } ,/** * Reads an attribute from the canvas of an embedded SWF application and @@ -386,10 +400,10 @@ * @param name:String name of the property to read */ _getCanvasAttributeSWF: function (name) { - if (dojo.flash.ready) { + if (this.loaded) { return dojo.flash.comm.getCanvasAttribute(name); } else { - alert('dojo.flash is not ready: getCanvasAttribute' + name); + alert('Flash is not ready: getCanvasAttribute' + name); } } @@ -529,8 +543,13 @@ * @param js:String javascript to call in the form 'foo.bar.methodcall(arg1,arg2,...)' */ _callMethodSWF: function (js) { - if (dojo.flash.comm) { + if (this.loaded) { return dojo.flash.comm.callMethod(js); + } else { + this._lastjs = function() { + dojo.flash.comm.callMethod(js); + }; + dojo.flash.addLoadedListener(this._lastjs); } } ,/** @access private */ Modified: openlaszlo/branches/wafflecone/lps/includes/source/flash.js =================================================================== --- openlaszlo/branches/wafflecone/lps/includes/source/flash.js 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/lps/includes/source/flash.js 2007-09-28 05:30:20 UTC (rev 6661) @@ -1012,17 +1012,19 @@ // the method name has a dot in it, such as "dojo.flash.loaded", we // eval it so that the method gets run against an instance var runMe; + var scope = window; if(functionName.indexOf(".") == -1){ // global function runMe = window[functionName]; }else{ // instance function runMe = eval(functionName); + scope = eval(functionName.substring(0, functionName.lastIndexOf("."))); } // make the call and get the results var results = null; if(runMe != null){ - results = runMe.apply(null, flashArgs); + results = runMe.apply(scope, flashArgs); } results += ''; Modified: openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js =================================================================== --- openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js 2007-09-28 05:26:45 UTC (rev 6660) +++ openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js 2007-09-28 05:30:20 UTC (rev 6661) @@ -9,25 +9,27 @@ Lz.history = { _currentstate: null ,init: function() { + var _this = Lz.history; + _this._title = top.document.title; Lz.__BrowserDetect.init(); - Lz.history._currentstate = Lz.history.get(); + _this._currentstate = _this.get(); if (Lz.__BrowserDetect.isSafari) { // must track state ourselves... - Lz.history._historylength = history.length; - Lz.history._history = []; - for (var i = 1; i < Lz.history._historylength; i++) { - Lz.history._history.push(''); + _this._historylength = history.length; + _this._history = []; + for (var i = 1; i < _this._historylength; i++) { + _this._history.push(''); } - Lz.history._history.push(Lz.history._currentstate); + _this._history.push(_this._currentstate); var form = document.createElement('form'); form.method = 'get'; document.body.appendChild(form); - Lz.history._form = form; + _this._form = form; if (! top.document.location.lzaddr) { top.document.location.lzaddr = {}; } if (top.document.location.lzaddr.history) { - Lz.history._history = top.document.location.lzaddr.history.split(','); + _this._history = top.document.location.lzaddr.history.split(','); } } else if (Lz.__BrowserDetect.isIE) { // use an iframe; @@ -38,25 +40,23 @@ i.style.position = 'absolute'; i.style.display = 'none'; i.style.left = '-1000px'; - Lz.history._iframe = document.getElementById('lzHistory'); - var doc = Lz.history._iframe.contentWindow.document; + _this._iframe = document.getElementById('lzHistory'); + var doc = _this._iframe.contentWindow.document; doc.open(); doc.close(); - if (Lz.history._currentstate != '') doc.location.hash = '#' + Lz.history._currentstate; + if (_this._currentstate != '') doc.location.hash = '#' + _this._currentstate; } - if (Lz.history._currentstate != '') Lz.history._parse(Lz.history._currentstate) + if (_this._currentstate != '') _this._parse(_this._currentstate) //alert('init'); setInterval('Lz.history._checklocationhash()', 100) } ,/** @access private */ _historyEvent: function (value) { - if (dojo.flash.ready) { + if (Lz.loaded) { //alert(value); dojo.flash.comm.receiveHistory(value + ''); return true; - } else { - //alert('dojo.flash is not ready: _historyEvent' + value); } } @@ -65,7 +65,7 @@ if (dojo.flash && dojo.flash.info && dojo.flash.info.installing) return; if (Lz.__BrowserDetect.isSafari) { var h = this._history[this._historylength - 1]; - if (h == '') h = '#0'; + if (h == '' || h == '#') h = '#0'; if (!this._skip && this._historylength != history.length) { this._historylength = history.length; if (typeof h != 'undefined') { @@ -88,6 +88,9 @@ this._currentstate = h; this._parse(h); } + if (top.document.title != this._title) { + top.document.title = this._title; + } } else { this._currentstate = h; this._parse(h); @@ -144,12 +147,12 @@ } ,/** @access private */ _parse: function(h) { + var _this = Lz.history; // TODO: send events to all apps - if (h.length == 0 || h == this._lasthash) return; - //alert('_parse '+ h); + if (h.length == 0 || h == _this._lasthash) return; if (h.indexOf('_lz') != -1) { // TODO: use rison - this._lasthash = h; + _this._lasthash = h; h = h.substring(3); var a = h.split(','); for (var j = 0; j < a.length; j++) { @@ -162,14 +165,15 @@ } } else { //history id - if (Lz.history._historyEvent(h)) { + if (_this._historyEvent(h)) { // if successful, don't send again - this._lasthash = h; + _this._lasthash = h; + //alert('_parse '+ h + ', ' + _this._lasthash); } if (Lz.__dhtmlhistoryready && LzHistory && LzHistory['receiveHistory']) { //alert(h); LzHistory.receiveHistory(h); - this._lasthash = h; + _this._lasthash = h; } } } _______________________________________________ Laszlo-checkins mailing list Laszlo-checkins@openlaszlo.org http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins This is verified as per Lorien Henry-Wilkins.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Date: September 19, 2007 11:48:39 AM PDT
Subject: Re: [Diamond] Fwd: For Review: Change 20070919-maxcarlson-Z Summary: Fix history for swf7
I no longer get javascript errors, but the history mechanism is still not working properly in Firefox - when I open up the mail app it warns me about leaving the page. Is there something new I need to add to my code to make this work? I still see the problem in swf7 and swf8.
Also, in firefox I frequently lose my ability to type into the address bar - it seems like the swf retains focus even after I've clicked into the address bar, and I can't type any characters. I don't know if this is related to the history issue.
Lorien