Author: max
Date: 2007-09-12 13:37:42 -0700 (Wed, 12 Sep 2007)
New Revision: 6444
Modified:
openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js
Log:
Change 20070907-maxcarlson-8 by [EMAIL PROTECTED] on 2007-09-07 19:19:48 PDT
in /Users/maxcarlson/openlaszlo/wafflecone
for http://svn.openlaszlo.org/openlaszlo/branches/wafflecone
Summary: Add history support for Safari
New Features:
Bugs Fixed: LPP-4655 (partial) - History mechanism not working
Technical Reviewer: jcrowley
QA Reviewer: promanik
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details: Track history state for Safari. Cache _iframe for IE. Refactor IE
history retrieval to get(). Call setCanvasAttribute in Lz instead of this.
Tests: http://localhost:8080/wafflecone/test/history/history.lzx now works in
Safari. Note that it doesn't work in DHTML yet, because query string args
aren't preserved by safari. IE and Firefox work as before.
Modified: openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js
===================================================================
--- openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js
2007-09-12 20:27:12 UTC (rev 6443)
+++ openlaszlo/branches/wafflecone/lps/includes/source/lzhistory.js
2007-09-12 20:37:42 UTC (rev 6444)
@@ -1,5 +1,11 @@
-// Copyright 2007 Laszlo Systems, Inc. All Rights Reserved. Use is
-// subject to license terms.
+/**
+ * @topic Browser
+ * @subtopic Integration
+ * @access public
+ * @copyright Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved.
+ * Use is subject to license terms.
+ */
+
Lz.history = {
_currentstate: null
,init: function() {
@@ -9,23 +15,35 @@
// must track state ourselves...
Lz.history._historylength = history.length;
Lz.history._history = [];
- Lz.history._update = false;
+ for (var i = 1; i < Lz.history._historylength; i++) {
+ Lz.history._history.push('');
+ }
+ Lz.history._history.push(Lz.history._currentstate);
+ var form = document.createElement('form');
+ form.method = 'get';
+ document.body.appendChild(form);
+ Lz.history._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(',');
+ }
} else if (Lz.__BrowserDetect.isIE) {
// use an iframe;
- Lz.history._title = document.title;
var i = document.createElement('iframe');
i.setAttribute('id', 'lzHistory');
i.setAttribute('style', 'display:none;left:-9999px');
document.body.appendChild(i);
- var iframe = document.getElementById('lzHistory');
- var doc = iframe.contentWindow.document;
+ Lz.history._iframe = document.getElementById('lzHistory');
+ var doc = Lz.history._iframe.contentWindow.document;
doc.open();
doc.close();
if (Lz.history._currentstate != '') doc.location.hash = '#' +
Lz.history._currentstate;
}
if (Lz.history._currentstate != '')
Lz.history._parse(Lz.history._currentstate)
//alert('init');
- setInterval('Lz.history._checklocationhash()', 300)
+ setInterval('Lz.history._checklocationhash()', 100)
}
,/** @access private */
@@ -42,50 +60,77 @@
,/** @access private */
_checklocationhash: function() {
if (Lz.__BrowserDetect.isSafari) {
- if (!this.skip) {
+ var h = this._history[this._historylength - 1];
+ if (h == '') h = '#0';
+ if (!this._skip && this._historylength != history.length) {
+ this._historylength = history.length;
+ if (typeof h != 'undefined') {
+ h = h.substring(1)
+ this._currentstate = h;
+ this._parse(h);
+ }
+ //alert('back or forward' + h);
+ } else {
+ this._parse(h.substring(1));
}
- } else if (Lz.__BrowserDetect.isIE) {
- // check location of iframe
- var iframe = document.getElementById('lzHistory');
- var doc = iframe.contentDocument || iframe.contentWindow.document;
- var h = doc.location.hash;
- var index = h.indexOf('#');
- if (index != -1) {
- h = h.substring(index + 1);
- }
+ } else {
+ var h = Lz.history.get();
+ // Make sure initial history event is sent even if the hash is
empty
if (h == '') h = '0';
- if (h != this._currentstate) {
- top.location.hash = '#' + h;
+ if (Lz.__BrowserDetect.isIE) {
+ if (h != this._currentstate) {
+ top.location.hash = '#' + h;
+ this._currentstate = h;
+ this._parse(h);
+ }
+ } else {
this._currentstate = h;
this._parse(h);
}
- } else {
- var h = this.get();
- // Make sure initial history event is sent even if the hash is
empty
- if (h == '') h = '0';
- // TODO: send events to all apps
- if (h != this.__lasthash && h.length > 0) {
- this._parse(h);
- }
}
}
,/** */
set: function(s) {
+ if (s == null) s = '';
+ if (this._currentstate == s) return;
this._currentstate = s;
- top.location.hash = '#' + s;
+
+ var hash = '#' + s;
+
if (Lz.__BrowserDetect.isIE) {
- Lz.history._iframe = document.getElementById('lzHistory');
+ top.location.hash = hash;
var doc = Lz.history._iframe.contentWindow.document;
doc.open();
doc.close();
- doc.location.hash = '#' + s;
+ doc.location.hash = hash;
this._parse(s + '');
+ } else if (Lz.__BrowserDetect.isSafari) {
+ // can't preserve query strings :(
+ this._form.action = hash;
+ top.document.location.lzaddr.history = this._history.toString();
+ this._skip = true;
+ this._history[history.length] = hash;
+ this._historylength = history.length + 1;
+ this._form.submit()
+ this._skip = false;
+ } else {
+ top.location.hash = hash;
+ this._parse(s + '');
}
}
,/** */
get: function() {
- var h = top.location.href;
+ var h = '';
+ if (Lz.__BrowserDetect.isIE) {
+ if (Lz.history._iframe) {
+ var doc = Lz.history._iframe.contentDocument ||
Lz.history._iframe.contentWindow.document;
+ h = doc.location.hash;
+ }
+ } else {
+ h = top.location.href;
+ }
+ //alert(h);
var index = h.indexOf('#');
if (index != -1) {
return h.substring(index + 1);
@@ -94,11 +139,12 @@
}
,/** @access private */
_parse: function(h) {
- if (! h) return;
- //console.log('_parse', h);
+ // TODO: send events to all apps
+ if (h.length == 0 || h == this._lasthash) return;
+ //alert('_parse '+ h);
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++) {
@@ -106,19 +152,19 @@
var i = v.indexOf('=');
var name = unescape(v.substring(0, i));
var val = unescape(v.substring(i + 1));
- this.setCanvasAttribute(name, val);
+ Lz.setCanvasAttribute(name, val);
if (window['canvas']) canvas.setAttribute(name, val);
}
} else {
//history id
if (Lz.history._historyEvent(h)) {
// if successful, don't send again
- this.__lasthash = h;
+ this._lasthash = h;
}
if (Lz.__dhtmlhistoryready && LzHistory &&
LzHistory['receiveHistory']) {
//alert(h);
LzHistory.receiveHistory(h);
- this.__lasthash = h;
+ this._lasthash = h;
}
}
}
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins