ambnews-firefox
changeset 13:fe30d1d71ee5
Fixed the race-condition bug for selecting the about:news URL text, and also probably prevented about:news from loading in places that it wasn't supposed to.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Sat Aug 23 09:15:27 2008 -0700 (3 years ago) |
| parents | f7c72b3d2bfb |
| children | 2f58ecd38d7a |
| files | ambnews/content/ambnews.js ambnews/content/browser.xul |
line diff
1.1 --- a/ambnews/content/ambnews.js Fri Aug 22 11:10:27 2008 -0700
1.2 +++ b/ambnews/content/ambnews.js Sat Aug 23 09:15:27 2008 -0700
1.3 @@ -131,15 +131,28 @@
1.4 feed.spec, 0, annSvc.EXPIRE_WEEKS);
1.5 }
1.6 },
1.7 - onLoad: function AmbNews_onLoad(aEvent) {
1.8 - if (aEvent.target.baseURI == "about:blank") {
1.9 - var doc = aEvent.target;
1.10 - doc.defaultView.location = "about:news";
1.11 - // TODO: The delay here only works most of the time;
1.12 - // its effectiveness is a race condition and we should
1.13 - // figure out what even to listen for to actually select
1.14 - // the URL bar text consistently
1.15 - window.setTimeout(function() { gURLBar.select(); }, 50);
1.16 + initBrowser: function AmbNews_initBrowser() {
1.17 + // Listen for the addition of new <link> elements on pages.
1.18 + window.addEventListener("DOMLinkAdded", AmbNews.onLinkAdded, false);
1.19 +
1.20 + // Whenever the user opens a new tab, have it point to
1.21 + // about:news by default, and select the URL.
1.22 +
1.23 + // The following code was taken from the "New Tab Homepage 0.4"
1.24 + // extension's 'chrome/content/tabhomepage.js' file. Thanks,
1.25 + // Ben Basson, for figuring this out for me.
1.26 + gBrowser.removeEventListener("NewTab", BrowserOpenTab, false);
1.27 + function onOpenTab(aEvent) {
1.28 + var newTab = gBrowser.addTab("about:news");
1.29 + gBrowser.selectedTab = newTab;
1.30 + if (gURLBar)
1.31 + setTimeout(function() { gURLBar.select(); }, 0);
1.32 + if (aEvent)
1.33 + aEvent.stopPropagation();
1.34 +
1.35 + return newTab;
1.36 }
1.37 + window.BrowserOpenTab = onOpenTab;
1.38 + gBrowser.addEventListener("NewTab", onOpenTab, false);
1.39 }
1.40 };
2.1 --- a/ambnews/content/browser.xul Fri Aug 22 11:10:27 2008 -0700
2.2 +++ b/ambnews/content/browser.xul Sat Aug 23 09:15:27 2008 -0700
2.3 @@ -4,11 +4,6 @@
2.4 <script type="application/javascript;version=1.7"
2.5 src="chrome://ambnews/content/ambnews.js"/>
2.6 <script>
2.7 - window.document.getElementById("content").addEventListener(
2.8 - "DOMContentLoaded",
2.9 - AmbNews.onLoad,
2.10 - false
2.11 - );
2.12 - window.addEventListener("DOMLinkAdded", AmbNews.onLinkAdded, false);
2.13 + window.addEventListener("load", AmbNews.initBrowser, false);
2.14 </script>
2.15 </overlay>
