Skip to content

Commit

Permalink
Add preference and code for showing Reader View button in URL bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ascrod committed Jan 19, 2018
1 parent 8e75317 commit 2d11a9a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 15 deletions.
30 changes: 25 additions & 5 deletions chrome/content/readerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,30 @@ var AboutReaderListener = {
}
},

//Get preference value for showing the reader button
get showInUrlbar() {
delete this.uiPref;

Services.prefs.addObserver("extensions.reader.location.urlbar", this.UIPrefObserver, false);
return this.uiPref = Services.prefs.getBoolPref("extensions.reader.location.urlbar");
},

//Observe UI preference value change
UIPrefObserver: {
observe(aMessage, aTopic, aData) {
if (aTopic != "nsPref:changed" || aData != "extensions.reader.location.urlbar") {
return;
}

console.log(this);
ReaderParent.updateReaderButton(gBrowser.selectedBrowser, AboutReaderListener.showInUrlbar);
}
},

//Updates the reader button on change of the URL.
browserWindowListener: {
onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
ReaderParent.updateReaderButton(gBrowser.selectedBrowser);
ReaderParent.updateReaderButton(gBrowser.selectedBrowser, AboutReaderListener.showInUrlbar);
}
},

Expand All @@ -69,7 +89,7 @@ var AboutReaderListener = {

//Updates the reader button after customization.
onCustomizeEnd(aEvent) {
ReaderParent.updateReaderButton(gBrowser.selectedBrowser);
ReaderParent.updateReaderButton(gBrowser.selectedBrowser, AboutReaderListener.showInUrlbar);
},

//Begins restoring the scroll position after tab restore
Expand Down Expand Up @@ -130,7 +150,7 @@ var AboutReaderListener = {

if (browser.contentWindow.document.body) {
// Update the toolbar icon to show the "reader active" icon.
ReaderParent.updateReaderButton(browser);
ReaderParent.updateReaderButton(browser, this.showInUrlbar);
new AboutReader(browser.contentWindow, browser._articlePromise);
delete browser._articlePromise;
}
Expand Down Expand Up @@ -158,7 +178,7 @@ var AboutReaderListener = {
// visible in the location bar when transitioning from reader-mode page
// back to the readable source page.
browser.isArticle = browser._isLeavingReaderableReaderMode;
ReaderParent.updateReaderButton(browser);
ReaderParent.updateReaderButton(browser, this.showInUrlbar);
if (browser._isLeavingReaderableReaderMode) {
delete browser._isLeavingReaderableReaderMode;
}
Expand Down Expand Up @@ -228,7 +248,7 @@ var AboutReaderListener = {
} else if (forceNonArticle) {
browser.isArticle = false;
}
ReaderParent.updateReaderButton(browser);
ReaderParent.updateReaderButton(browser, this.showInUrlbar);
}
};

Expand Down
15 changes: 15 additions & 0 deletions chrome/content/readerMain.xul
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
oncommand="ReaderParent.buttonClick(event);"
/>
</toolbarpalette>

<toolbar id="nav-bar">
<toolbaritem id="urlbar-container">
<textbox id="urlbar">
<hbox id="urlbar-icons">
<image id="reader-mode-button-fixed"
position="1"
class="urlbar-icon"
hidden="true"
onclick="ReaderParent.buttonClick(event);"
/>
</hbox>
</textbox>
</toolbaritem>
</toolbar>

<commandset id="mainCommandSet">
<command id="View:ReaderView"
Expand Down
15 changes: 15 additions & 0 deletions chrome/skin/button/readerButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@
-moz-image-region: rect(0, 48px, 16px, 32px);
}

#reader-mode-button-fixed {
list-style-image: url("chrome://readerview/skin/button/readerMode.svg");
-moz-image-region: rect(0, 16px, 16px, 0);
}

#reader-mode-button-fixed:hover,
#reader-mode-button-fixed[state="enabled"]:hover {
-moz-image-region: rect(0, 32px, 16px, 16px);
}

#reader-mode-button-fixed:hover:active,
#reader-mode-button-fixed[state="active"] {
-moz-image-region: rect(0, 48px, 16px, 32px);
}

1 change: 1 addition & 0 deletions defaults/preferences/readerview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pref("extensions.reader.parse-node-limit", 0);
pref("extensions.reader.parse-on-load.enabled", true);
pref("extensions.reader.parse-on-load.force-enabled", false);
pref("extensions.reader.toolbar.vertical", true);
pref("extensions.reader.location.urlbar", false);
31 changes: 21 additions & 10 deletions modules/ReaderParent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,43 @@ XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://readerview/Rea
const gStringBundle = Services.strings.createBundle("chrome://readerview/locale/aboutReader.properties");

var ReaderParent = {
updateReaderButton: function(browser) {
updateReaderButton: function(browser, showInUrlbar) {
let win = browser.ownerGlobal;
if (browser != win.gBrowser.selectedBrowser) {
return;
}

let button = win.document.getElementById("reader-mode-button");
let buttonFloat = win.document.getElementById("reader-mode-button");
let buttonFixed = win.document.getElementById("reader-mode-button-fixed");
let command = win.document.getElementById("View:ReaderView");
let key = win.document.getElementById("key_toggleReaderMode");
if (browser.currentURI.spec.startsWith("about:reader")) {
let closeText = gStringBundle.GetStringFromName("readerView.close");
if (button) {
button.setAttribute("state", "active");
button.disabled = false;
button.setAttribute("tooltiptext", closeText);
if (buttonFloat) {
buttonFloat.setAttribute("state", "active");
buttonFloat.disabled = false;
buttonFloat.setAttribute("tooltiptext", closeText);
buttonFloat.hidden = showInUrlbar;
} if (buttonFixed) {
buttonFixed.setAttribute("state", "active");
buttonFixed.hidden = !showInUrlbar;
buttonFixed.setAttribute("tooltiptext", closeText);
}
command.setAttribute("label", closeText);
command.setAttribute("hidden", false);
command.setAttribute("accesskey", gStringBundle.GetStringFromName("readerView.close.accesskey"));
key.setAttribute("disabled", false);
} else {
let enterText = gStringBundle.GetStringFromName((browser.isArticle ? "readerView.enter" : "readerView.disabled"));
if (button) {
button.setAttribute("state", (browser.isArticle ? "enabled" : "disabled"));
button.disabled = !browser.isArticle;
button.setAttribute("tooltiptext", enterText);
if (buttonFloat) {
buttonFloat.setAttribute("state", (browser.isArticle ? "enabled" : "disabled"));
buttonFloat.disabled = !browser.isArticle;
buttonFloat.setAttribute("tooltiptext", enterText);
buttonFloat.hidden = showInUrlbar;
} if (buttonFixed) {
buttonFixed.setAttribute("state", (browser.isArticle ? "enabled" : "disabled"));
buttonFixed.hidden = !(showInUrlbar && browser.isArticle);
buttonFixed.setAttribute("tooltiptext", enterText);
}
command.setAttribute("label", enterText);
command.setAttribute("hidden", !browser.isArticle);
Expand Down

0 comments on commit 2d11a9a

Please sign in to comment.