Permalink
Browse files

A version of the browser which can detect location changes and loadin…

…g state of child iFrames cross-origin. Depends on jlebar's patch tracked here https://bugzilla.mozilla.org/show_bug.cgi?id=710231
  • Loading branch information...
1 parent 4f54902 commit 638d6be0004cdf06b42f26d387dc94c3de909be0 @benfrancis benfrancis committed Dec 23, 2011
Showing with 25 additions and 7 deletions.
  1. +25 −7 apps/browser/js/browser.js
View
@@ -28,16 +28,20 @@ var Browser = {
},
init: function() {
-
this.address.addEventListener('submit', (function submitHandler(evt) {
var url = this.urlBar.value;
- MockHistory.pushState(null, '', url);
this.navigate(url);
evt.preventDefault();
}).bind(this));
- this.iframe.addEventListener('load', (function loadedHandler(evt) {
- this.urlBar.classList.remove('loading');
+ iframe = this.iframe;
+
+ iframe.mozAddContentStateListener('load', (function loadHandler(evt) {
+ this.loadStateChange(evt);
+ }).bind(this));
+
+ iframe.mozAddContentStateListener('location', (function locationHandler(evt) {
+ this.locationChange(evt);
}).bind(this));
this.backButton.addEventListener('click', (function backHandler(evt) {
@@ -52,18 +56,32 @@ var Browser = {
});
var url = this.urlBar.value;
- MockHistory.pushState(null, '', url);
this.navigate(url);
+ this.updateHistory(url);
},
navigate: function(url) {
- this.urlBar.value = url;
this.content.setAttribute('src', url);
- this.urlBar.classList.add('loading');
+ },
+
+ updateHistory: function(url) {
+ MockHistory.pushState(null, '', url);
if (MockHistory.backLength())
this.backButton.src = 'style/images/back.png';
else
this.backButton.src = 'style/images/back-disabled.png';
+ },
+
+ loadStateChange: function(state) {
+ if (state == 'start')
+ this.urlBar.classList.add('loading');
+ else if (state == 'stop')
+ this.urlBar.classList.remove('loading');
+ },
+
+ locationChange: function(url) {
+ this.urlBar.value = url;
+ this.updateHistory(url);
}
};

0 comments on commit 638d6be

Please sign in to comment.