6 * @license MIT License
\r
7 * @author Harald Kirschner <mail [at] digitarald.de>
\r
8 * @copyright 2008 Author
\r
11 var History = $extend(history, {
\r
13 implement: function(obj) {
\r
14 return $extend(this, obj);
\r
19 History.implement(new Events($empty));
\r
26 if (this.started) return this;
\r
27 this.state = this.getHash();
\r
28 if (Browser.Engine.trident) {
\r
29 var iframe = new Element('iframe', {
\r
30 'src': "javascript:'<html></html>'",
\r
32 'position': 'absolute',
\r
35 }).inject(document.body).contentWindow;
\r
36 var writeState = function(state) {
\r
37 iframe.document.write('<html><body onload="top.History.$listener(\'', encodeURIComponent(state) ,'\');">Moo!</body></html>');
\r
38 iframe.document.close();
\r
41 '$listener': function(state) {
\r
42 state = decodeURIComponent(state);
\r
43 if (this.state != state) this.setHash(state).changeState(state);
\r
45 'setState': function(state, force) {
\r
46 if (this.state != state || force) {
\r
47 if (!force) this.setHash(state).changeState(state, true);
\r
52 'trace': function() {
\r
53 var state = this.getHash();
\r
54 if (state != this.state) writeState(state);
\r
57 var check = (function() {
\r
58 if (iframe.document && iframe.document.body) {
\r
59 check = $clear(check);
\r
60 if (!iframe.document.body.innerHTML) this.setState(this.state);
\r
62 }).periodical(50, this);
\r
64 if (Browser.Engine.presto915) {
\r
65 new Element('img', {
\r
66 'src': "javascript:location.href='javascript:History.trace();';",
\r
68 'position': 'absolute',
\r
71 }).inject(document.body);
\r
74 this.trace.periodical(150, this);
\r
75 this.started = true;
\r
79 changeState: function(state, manual) {
\r
80 var stateOld = this.state;
\r
82 this.fireEvent('changed', [state, stateOld, manual]);
\r
86 var state = this.getHash();
\r
87 if (state != this.state) this.changeState(state);
\r
90 getHash: function() {
\r
91 var href = location.href, pos = href.indexOf('#') + 1;
\r
92 return (pos) ? href.substr(pos) : '';
\r
95 setHash: function(state) {
\r
96 location.hash = '#' + state;
\r
100 setState: function(state) {
\r
101 if (this.state !== state) this.setHash(state).changeState(state, true);
\r
105 getState: function() {
\r