gecko/browser/base/content/browser-social.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
let SocialUI = {
// Called on delayed startup to initialize UI
init: function SocialUI_init() {
Services.obs.addObserver(this, "social:pref-changed", false);
Social.init(this._providerReady.bind(this));
},
// Called on window unload
uninit: function SocialUI_uninit() {
Services.obs.removeObserver(this, "social:pref-changed");
},
// Called when the social.enabled pref is changed
observe: function SocialUI_observe(aSubject, aTopic, aData) {
SocialShareButton.updateButtonEnabledState();
},
// Called once Social.jsm's provider has been set
_providerReady: function SocialUI_providerReady() {
SocialShareButton.init();
}
}
let SocialShareButton = {
init: function SSB_init() {
this.sharePopup.hidden = false;
this.updateButtonEnabledState();
},
get shareButton() {
return document.getElementById("share-button");
},
get sharePopup() {
return document.getElementById("editSharePopup");
},
dismissSharePopup: function SSB_dismissSharePopup() {
this.sharePopup.hidePopup();
},
updateButtonEnabledState: function SSB_updateButtonEnabledState() {
let shareButton = this.shareButton;
if (shareButton)
shareButton.hidden = !Social.provider || !Social.provider.enabled ||
!Social.provider.port;
},
onClick: function SSB_onClick(aEvent) {
if (aEvent.button != 0)
return;
// Don't bubble to the textbox, to avoid unwanted selection of the address.
aEvent.stopPropagation();
this.sharePage();
},
panelShown: function SSB_panelShown(aEvent) {
let sharePopupOkButton = document.getElementById("editSharePopupOkButton");
if (sharePopupOkButton)
sharePopupOkButton.focus();
},
sharePage: function SSB_sharePage() {
let uri = gBrowser.currentURI;
if (!Social.isPageShared(uri)) {
Social.sharePage(uri);
this.updateShareState();
} else {
this.sharePopup.openPopup(this.shareButton, "bottomcenter topright");
}
},
unsharePage: function SSB_unsharePage() {
Social.unsharePage(gBrowser.currentURI);
this.updateShareState();
this.dismissSharePopup();
},
updateShareState: function SSB_updateShareState() {
let currentPageShared = Social.isPageShared(gBrowser.currentURI);
// Provide a11y-friendly notification of share.
let status = document.getElementById("share-button-status");
if (status) {
let statusString = currentPageShared ?
gNavigatorBundle.getString("social.pageShared.label") : "";
status.setAttribute("value", statusString);
}
// Update the share button, if present
let shareButton = this.shareButton;
if (!shareButton)
return;
if (currentPageShared) {
shareButton.setAttribute("shared", "true");
shareButton.setAttribute("tooltiptext", gNavigatorBundle.getString("social.shareButton.sharedtooltip"));
} else {
shareButton.removeAttribute("shared");
shareButton.setAttribute("tooltiptext", gNavigatorBundle.getString("social.shareButton.tooltip"));
}
}
};