Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
51 content/overlay.xul
@@ -11,7 +11,6 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://socialdev/content/recommendButtonWidget.js"/>
- <script type="application/x-javascript" src="chrome://socialdev/content/toolbarButtonWidget.js"/>
<script type="application/x-javascript" src="chrome://socialdev/content/toolbarStatusWidget.js"/>
<script type="application/x-javascript" src="chrome://socialdev/content/sidebarWidget.js"/>
<script type="application/x-javascript">
@@ -24,7 +23,6 @@
window.addEventListener('load', function(e) {
social.recommendButton = new SocialRecommendButton(window);
social.sidebar = new SocialSidebar(window);
- social.toolbarButton = new SocialToolbarButton(window);
social.toolbarStatusArea = new SocialToolbarStatusArea(window);
});
}
@@ -38,8 +36,8 @@
<commandset id="mainCommandSet">
<command id="cmd_socialRecommend" oncommand="social.recommendButton.oncommand(event);"/>
<command id="cmd_socialPreferences" oncommand="openUILink('about:social')"/>
- <command id="cmd_socialBrowsingToggle" oncommand="social.toolbarButton.onToggleEnabled()"/>
- <command id="cmd_socialToolbarToggle" oncommand="social.toolbarButton.onToggleVisible()"/>
+ <command id="cmd_socialBrowsingToggle" oncommand="social.toolbarStatusArea.onToggleEnabled()"/>
+ <command id="cmd_socialToolbarToggle" oncommand="social.toolbarStatusArea.onToggleVisible()"/>
</commandset>
<keyset id="mainKeyset">
@@ -50,33 +48,6 @@
<toolbarpalette id="BrowserToolbarPalette">
<toolbaritem
- id="social-button-container"
- class= "chromeclass-toolbar-additional"
- removable="true"
- title="&socialdev.label;">
- <toolbarbutton
- id="socialdev-button"
- class="toolbarbutton-1"
- type="menu-button"
- tooltiptext="&socialdev.toolbartext;"
- removable="true"
- command="cmd_socialToolbarToggle">
- <menupopup id="social-toolbar-menu"
- onpopupshown="social.toolbarButton.onpopupshown(event)"
- onpopupshowing="social.toolbarButton.onpopupshowing(event)"
- onpopuphidden="social.toolbarButton.onpopuphidden(event)">
- <menuitem id="social-socialtoolbar-menu" label="&socialtoobar.label;" command="cmd_socialToolbarToggle"/>
- <menuitem id="social-socialbrowsing-menu" label="&socialenable.label;" command="cmd_socialBrowsingToggle"/>
- <menuseparator/>
- <menuseparator id="social-providers-separator"/>
- <menuitem id="social-demonotification-menu" label="Fire a demo notification" oncommand="social.toolbarButton.fireDemoNotification(event)"/>
- <menuseparator/>
- <menuitem id="social-pref-menu" label="&socialdev.prefslabel;" command="cmd_socialPreferences"/>
- </menupopup>
- </toolbarbutton>
- </toolbaritem>
-
- <toolbaritem
id="social-status-area-container"
class="chromeclass-toolbar-additional social-status-area-container"
removable="true"
@@ -92,13 +63,19 @@
class="social-statusarea-service-image"/>
<image class="social-statusarea-dropmarker-image"/>
- <menupopup class="social-statusarea-popup"
- anonid="social-statusarea-popup">
+ <menupopup
+ class="social-statusarea-popup"
+ id="social-statusarea-popup"
+ anonid="social-statusarea-popup"
+ onpopupshown="social.toolbarStatusArea.onpopupshown(event)"
+ onpopupshowing="social.toolbarStatusArea.onpopupshowing(event)"
+ onpopuphidden="social.toolbarStatusArea.onpopuphidden(event)">
+ <menuitem id="social-statusarea-togglesidebar" command="cmd_socialToolbarToggle"/>
+ <menuitem id="social-statusarea-togglesocial" command="cmd_socialBrowsingToggle"/>
<menuseparator/>
- <menuitem class="open-socialservice-manager"
- anonid="open-socialservice-manager"
- label="Manage Social Services..."
- oncommand="openSocialServiceManager(event);"/>
+ <!-- list of enabled services goes here -->
+ <menuseparator id="social-statusarea-providers-separator"/>
+ <menuitem id="social-pref-menu" label="&socialdev.prefslabel;" command="cmd_socialPreferences"/>
</menupopup>
</button>
</box>
View
235 content/sidebarWidget.js
@@ -7,20 +7,19 @@ Cu.import("resource://socialdev/modules/baseWidget.js");
function SocialSidebar() {
- this._currentAnchorId = null;
this._prefBranch = Services.prefs.getBranch("social.provider.").QueryInterface(Ci.nsIPrefBranch2);
baseWidget.call(this, window);
// watch for when browser disables chrome in tabs, and hide the social sidebar
- let _visibilityBeforeAutoHide = this.visibility;
+ let _visibleBeforeAutoHide = this.visible;
document.addEventListener('DOMAttrModified', function(e) {
if (e.target == document.documentElement && e.attrName == "disablechrome") {
if (e.newValue) {
- _visibilityBeforeAutoHide = this.visibility;
- this.visibility = 'hidden';
+ _visibleBeforeAutoHide = this.visible;
+ this.visible = false;
}
else
- this.visibility = _visibilityBeforeAutoHide;
+ this.visible = _visibleBeforeAutoHide;
}
}.bind(this));
@@ -53,9 +52,6 @@ SocialSidebar.prototype = {
sbrowser.setAttribute("flex", "1");
sbrowser.style.overflow = "hidden";
- // start with the sidebar closed.
- sbrowser._open = false;
-
let after = document.getElementById('appcontent');
let splitter = document.createElementNS(XUL_NS, "splitter");
splitter.setAttribute("id", "social-splitter");
@@ -86,18 +82,6 @@ SocialSidebar.prototype = {
if (e.target == window) self.reflow();
}, true);
- let toolbox = document.getElementById('navigator-toolbox');
- toolbox.addEventListener("DOMAttrModified", function(event) {
- if (event.attrName == "collapsed" || event.attrName == "tabsontop") {
- // so, one of the toolbars changed state. If this means our "anchor"
- // changed then we need to reflow (which will re-anchor).
- let newAnchor = self._findAnchor();
- if (self._currentAnchorId && newAnchor.getAttribute("id") != self._currentAnchorId) {
- self.reflow();
- }
- }
- }, true);
-
// XXX hardcode reflowing for the single sbrowser on initial load for now
sbrowser.addEventListener("DOMContentLoaded", function onLoad() {
sbrowser.removeEventListener("DOMContentLoaded", onLoad);
@@ -105,51 +89,29 @@ SocialSidebar.prototype = {
});
this.attachContextMenu();
- // Automatically open (and keep open) the sidebar if minimized when clicked
- vbox.addEventListener("click", function(event) {
- // ack - this is wrong - ideally we want "command" but it doesn't work.
- // check the button so a right-click doesn't do this *and* show the popup
- if (event.button != 0) {
- return;
- }
- if (sbrowser.visibility != "open") {
- this.visibility = "open";
- }
- }.bind(this));
- Object.defineProperty(sbrowser, "visibility", {
+ Object.defineProperty(sbrowser, "visible", {
get: function() {
- if (vbox.getAttribute("hidden") == "true") {
- return "hidden";
- }
- return sbrowser._open ? "open" : "minimized";
+ return vbox.getAttribute("hidden") != "true";
},
set: function(newVal) {
- let hiddenVal;
- switch (newVal) {
- case "open":
- hiddenVal = false;
- sbrowser._open = true;
- break;
- case "minimized":
- hiddenVal = false;
- sbrowser._open = false;
- break;
- case "hidden":
- hiddenVal = true;
- break;
- default:
- throw "invalid visibility state";
+ if (newVal) {
+ vbox.removeAttribute("hidden");
+ splitter.removeAttribute("hidden");
+ } else {
+ vbox.setAttribute("hidden", "true");
+ splitter.setAttribute("hidden", "true");
}
- vbox.setAttribute("hidden", hiddenVal);
- splitter.setAttribute("hidden", hiddenVal);
self.reflow();
}
});
try {
- this.visibility = this._prefBranch.getBoolPref("enabled") ? this._prefBranch.getCharPref("visibility") : 'hidden';
+ if (this._prefBranch.getBoolPref("enabled")) {
+ this._set_enabled(true);
+ this.visible = this._prefBranch.getBoolPref("visible");
+ }
}
- catch (e) {}
+ catch (e) {Cu.reportError(e);}
},
attachContextMenu: function() {
let {document, gBrowser} = this._widget.ownerDocument.defaultView;
@@ -189,111 +151,36 @@ SocialSidebar.prototype = {
reflow: function() {
let sbrowser = document.getElementById('social-status-sidebar-browser');
- let anchor = this._findAnchor();
- if (this._currentAnchorId && anchor.getAttribute("id") != this._currentAnchorId) {
- // reset the old anchor.
- let old = document.getElementById(this._currentAnchorId);
- old.style.paddingRight = "";
- }
- this._currentAnchorId = anchor.getAttribute("id");
-
- let visibility = sbrowser.visibility;
- if (visibility == "hidden") {
- // just reset the navbar stuff.
- anchor.style.paddingRight = "";
- // anything else?
+ let visible = sbrowser.visible;
+ if (!visible) {
+ // is this class still correct?
+ document.documentElement.classList.remove("social-open");
return;
}
- let open = visibility == "open";
-
- if (open)
- document.documentElement.classList.add("social-open");
- else
- document.documentElement.classList.remove("social-open");
-
+ document.documentElement.classList.add("social-open");
let vbox = document.getElementById('social-vbox');
let cropper = document.getElementById('social-cropper');
// Include the visual border thickness when calculating navbar height
- if (!open) {
- vbox.style.height = 0;
- } else {
- let sideWidth = vbox.getAttribute("width");
- let openHeight = window.gBrowser.boxObject.height;// + navHeight;
-
- //anchor.style.paddingRight = sideWidth + "px";
- cropper.style.height = openHeight + "px";
- sbrowser.style.height = openHeight + "px";
- }
-
- /*
- let isMac = Services.appinfo.OS == "Darwin";
- let navHeight = 0;//anchor.clientHeight + (isMac ? 2 : 1);
- let openHeight = window.gBrowser.boxObject.height;// + navHeight;
let sideWidth = vbox.getAttribute("width");
-
- let targetWindow = sbrowser.contentWindow.wrappedJSObject;
-
- // MRH put it in content
- anchor.style.paddingRight = sideWidth + "px";
- cropper.style.height = (open ? openHeight : 0) + "px";
- vbox.style.marginLeft = 0;//open ? "" : "-" + sideWidth + "px";
- // vbox.style.marginTop = "-" + navHeight + "px";
+ let openHeight = window.gBrowser.boxObject.height;// + navHeight;
+ cropper.style.height = openHeight + "px";
sbrowser.style.height = openHeight + "px";
-
- // TODO XXX Need an API to inform the content page how big to make the header
- var header = targetWindow.document.getElementById("header");
- if (header) {
- var headerStyle = header.style;
- headerStyle.height = navHeight - 1 + "px";
- headerStyle.overflow = "hidden";
-
- // MRH hack:
- headerStyle.display = "none";
- }*/
- },
- _findAnchor: function() {
- // Find the element which is our "anchor" - ie, the bottom toolbar which
- // we overlap and thus adjust its padding.
- // I tried using the "box" model, but failed - boxes can theoretically be
- // traversed in layout order, but:
- // EG: last = document.getElementById('navigator-toolbox').boxObject.lastChild;
- // Now - "last" is an element but doesn't itself have a "boxObject", so it's
- // not clear how to continue traversing back from there in layout order.
- // (and the same basic issue may exist traversing forward)
- // So - just use the bounding rects.
- let anchor = null;
- let lowestBottom = 0;
- let look = document.getElementById('navigator-toolbox').firstChild;
- while (look) {
- if (look.getBoundingClientRect().bottom > lowestBottom) {
- anchor = look;
- lowestBottom = look.getBoundingClientRect().bottom;
- }
- look = look.nextSibling;
- }
- if (!anchor) {
- // should be impossible (but nothing is impossible ;)
- dump("EEEK - failed to find the last toolbar - using nav-bar\n");
- anchor = document.getElementById('nav-bar');
- // throw "failed to find the anchor"
- }
- return anchor;
},
setProvider: function(aService) {
let self = this;
- if (!aService.enabled || this.disabled) {
+ if (!aService.enabled || !this.enabled) {
return;// sanity check
}
// retarget the sidebar
var sbrowser = document.getElementById("social-status-sidebar-browser");
- var make_visible = sbrowser.service && sbrowser.service !== aService;
+ var make_visible = !sbrowser.service || sbrowser.service !== aService;
sbrowser.service = aService;
// XXX when switching providers, always open
if (make_visible)
- sbrowser.visibility = "open";
+ sbrowser.visible = true;
// set up a locationwatcher
try {
@@ -334,51 +221,55 @@ SocialSidebar.prototype = {
}
}, true);
},
- enable: function() {
- this.show();
- let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
- .getService(Ci.mozISocialRegistry);
- this.setProvider(registry.currentProvider);
- },
- disable: function() {
- // this sidebar is displaying this service;
- // turn everything off.
- let sbrowser = this.browser;
- try {
- if (sbrowser.watcher)
- sbrowser.removeProgressListener(sbrowser.watcher);
+ // Sets the enabled property but does *not* change visibility
+ _set_enabled: function(val) {
+ if (val === this.enabled) {
+ return; // nothing to do!
}
- catch(e) {
- Cu.reportError(e);
+ let sbrowser = this.browser;
+ if (val) {
+ let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
+ .getService(Ci.mozISocialRegistry);
+ this.setProvider(registry.currentProvider);
+ } else {
+ // this sidebar is displaying this service;
+ // turn everything off.
+ try {
+ if (sbrowser.watcher)
+ sbrowser.removeProgressListener(sbrowser.watcher);
+ }
+ catch(e) {
+ Cu.reportError(e);
+ }
+ sbrowser.watcher = null;
+ sbrowser.contentWindow.location = "about:blank";
}
- sbrowser.watcher = null;
- sbrowser.contentWindow.location = "about:blank";
- sbrowser.visibility = "hidden";
+ this._prefBranch.setBoolPref("enabled", val);
},
- get disabled() {
- return this.browser.visibility == "hidden";
+ set enabled(val) {
+ this._set_enabled(val);
+ // if it is being enabled, we want it visible (and obviously vice-versa)
+ this.browser.visible = val;
},
- get visibility() {
- return this.browser.visibility;
+ get enabled() {
+ return this._prefBranch.getBoolPref("enabled")
},
- set visibility(val) {
- this.browser.visibility = val;
- this._prefBranch.setCharPref("visibility", val);
+ get visible() {
+ return this.browser.visible;
+ },
+ set visible(val) {
+ this.browser.visible = val;
+ this._prefBranch.setBoolPref("visible", val);
},
show: function() {
- this.visibility = this.browser._open ? "open" : "minimized";
+ this.visible = true;
},
hide: function() {
- this.visibility = "hidden";
+ this.visible = false;
},
remove: function() {
this._widget.parentNode.removeChild(this._widget.previousSibling); // remove splitter
this._widget.parentNode.removeChild(this._widget);
- // restore the toolbar style stuff we mangled.
- if (this._currentAnchorId) {
- let anchor = document.getElementById(this._currentAnchorId);
- anchor.style.paddingRight = "";
- }
}
}
View
174 content/toolbarButtonWidget.js
@@ -1,174 +0,0 @@
-"use strict";
-
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://socialdev/modules/baseWidget.js");
-
-
-function SocialToolbarButton() {
- baseWidget.call(this, window);
-
- // we need to make our button appear on first install, for now we always
- // ensure that it is in the toolbar, even if the user removes it
- var navbar = window.document.getElementById("nav-bar");
- var newset = navbar.currentSet + ",social-button-container";
- navbar.currentSet = newset;
- navbar.setAttribute("currentset", newset );
- window.document.persist("nav-bar", "currentset");
-
- // XXX i think we can use broadcasters for this state
- let sidebar = window.social.sidebar;
- let str = document.getElementById("socialdev-strings");
- let label = (sidebar.visibility == "hidden" ? "browserEnable.label" : "browserDisable.label")
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString(label));
- label = (sidebar.visibility == "open" ? "minimizeSidebar.label" : "showSidebar.label")
- document.getElementById('social-socialtoolbar-menu').
- setAttribute('label', str.getString(label));
-}
-SocialToolbarButton.prototype = {
- __proto__: baseWidget.prototype,
- create: function(aWindow) {
- },
- remove: function() {
- },
- onpopupshown: function(event) {
- let aWindow = event.target.ownerDocument.defaultView;
- var sbrowser = aWindow.document.getElementById("social-status-sidebar-browser");
- sbrowser.style.opacity = 0.3;
- },
- onpopuphidden: function(event) {
- let aWindow = event.target.ownerDocument.defaultView;
- var sbrowser = aWindow.document.getElementById("social-status-sidebar-browser");
- sbrowser.style.opacity = 1;
- },
- onpopupshowing: function(event) {
- let aWindow = event.target.ownerDocument.defaultView;
- let socialpanel = aWindow.document.getElementById("social-toolbar-menu");
- buildSocialPopupContents(aWindow, socialpanel);
- },
- onToggleEnabled: function() {
- var str = document.getElementById("socialdev-strings");
- if (window.social.sidebar.visibility != "hidden") {
- Services.obs.notifyObservers(null, "social-browsing-disabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserEnable.label"));
- }
- else {
- Services.obs.notifyObservers(null, "social-browsing-enabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserDisable.label"));
- }
- },
- onToggleVisible: function() {
- var str = document.getElementById("socialdev-strings");
- let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
- .getService(Ci.mozISocialRegistry);
- if (!registry.currentProvider || !registry.currentProvider.enabled) {
- Services.console.logStringMessage("no service is enabled, so not opening the socialbar!")
- }
- else {
- let sidebar = window.social.sidebar;
- if (sidebar.visibility == 'hidden') {
- Services.obs.notifyObservers(null, "social-browsing-enabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserDisable.label"));
- }
- else {
- sidebar.visibility = (sidebar.visibility=="open" ? "hidden" : "open");
- let label = (sidebar.visibility == "open" ? "minimizeSidebar.label" : "showSidebar.label")
- document.getElementById('social-socialtoolbar-menu').
- setAttribute('label', str.getString(label));
- }
- }
- },
-
- fireDemoNotification: function(event) {
- // cannot fire a notification from inside an event, setTimeout is our friend
- let notification = {};
- Cu.import("resource://socialdev/modules/notification.js", notification);
- window.setTimeout(notification.addNotification, 0, {
- "_iconUrl": "http://1.gravatar.com/userimage/13041757/99cac03c3909baf0cd2f2a5e1cf1deed?size=36",
- "_title": "Michael Hanson",
- "_body" : "has demoed a Firefox feature"
- });
- }
-}
-
-
-const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
-function buildSocialPopupContents(window, socialpanel)
-{
- let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
- .getService(Ci.mozISocialRegistry);
-
- function renderNotificationRow(img, title, text) {
- let row = window.document.createElementNS(HTML_NS, "div");
- row.setAttribute("style", "clear:all;cursor:pointer;margin-left:8px;height:32px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:-moz-system-font;border-right:");
-
- let imgElem = window.document.createElementNS(HTML_NS, "img");
- imgElem.setAttribute("src", img);
- imgElem.setAttribute("style", "width:28px;height:28px;margin-right:8px;float:left");
-
- let titleElem = window.document.createElementNS(HTML_NS, "span");
- titleElem.appendChild(window.document.createTextNode(title));
- titleElem.setAttribute("style", "font-weight:bold");
-
- let textElem = window.document.createElementNS(HTML_NS, "span");
- textElem.appendChild(window.document.createTextNode(((text.length > 0 && text[0] != ' ') ? " " : "")+ text));
-
- row.appendChild(imgElem);
- row.appendChild(titleElem);
- row.appendChild(textElem);
- return row;
- }
-
- function renderProviderMenuitem(service, container, before) {
-
- let menuitem = window.document.createElementNS(XUL_NS, "menuitem");
- menuitem.setAttribute("label", service.name);
- menuitem.setAttribute("class", "menuitem-iconic");
- menuitem.setAttribute("image", service.iconURL);
- menuitem.setAttribute("type", "radio");
- menuitem.setAttribute("name", "socialprovider");
- if (service == registry.currentProvider) {
- // no need for a click handler if we're selected
- menuitem.setAttribute("checked", true);
- }
- else {
- menuitem.addEventListener("click", function(event) {
- registry.currentProvider = service;
- });
- }
- container.insertBefore(menuitem, before);
-
- // render notifications...
- for (let i in service.notifications) {
- let aNotif = service.notifications[i];
- container.appendChild(renderNotificationRow(aNotif[0], aNotif[1], aNotif[2]));
- }
- }
-
- let menuitem;
- let disabled = window.social.sidebar.disabled;
- try {
- let providerSep = document.getElementById('social-providers-separator');
- let fc = providerSep.previousSibling;
- while (fc.localName != 'menuseparator') {
- socialpanel.removeChild(fc);
- fc = providerSep.previousSibling;
- }
- // Create top-level items
- if (!disabled && registry.currentProvider) {
- // Create network rows...
- registry.each(function(service) {
- if (service.enabled)
- renderProviderMenuitem(service, socialpanel, providerSep);
- });
- }
-
- }
- catch (e) {
- Cu.reportError("Error creating socialpopupcontents: " + e);
- }
-}
View
141 content/toolbarStatusWidget.js
@@ -14,8 +14,9 @@ function SocialToolbarStatusArea() {
navbar.setAttribute("currentset", newset );
window.document.persist("nav-bar", "currentset");
-
Services.obs.addObserver(this, 'social-browsing-ambient-notification-changed', false);
+
+ this.renderPopupFromCurrentState();
}
SocialToolbarStatusArea.prototype = {
@@ -170,31 +171,54 @@ SocialToolbarStatusArea.prototype = {
},
onpopupshown: function(event) {
let aWindow = event.target.ownerDocument.defaultView;
- var sbrowser = aWindow.document.getElementById("social-status-sidebar-browser");
+ var sbrowser = aWindow.social.sidebar.browser;
sbrowser.style.opacity = 0.3;
},
onpopuphidden: function(event) {
let aWindow = event.target.ownerDocument.defaultView;
- var sbrowser = aWindow.document.getElementById("social-status-sidebar-browser");
+ var sbrowser = aWindow.social.sidebar.browser;
sbrowser.style.opacity = 1;
},
onpopupshowing: function(event) {
let aWindow = event.target.ownerDocument.defaultView;
- //let socialpanel = aWindow.document.getElementById("social-toolbar-menu");
- //buildSocialPopupContents(aWindow, socialpanel);
+ let popup = aWindow.document.getElementById("social-statusarea-popup");
+ buildSocialPopupContents(aWindow, popup);
+ },
+
+ renderPopupFromCurrentState: function() {
+ var str = document.getElementById("socialdev-strings");
+ let uieltSocial = document.getElementById('social-statusarea-togglesocial');
+ let uieltSidebar = document.getElementById('social-statusarea-togglesidebar');
+ if (window.social.sidebar.enabled) {
+ uieltSidebar.removeAttribute("hidden");
+ uieltSocial.setAttribute('label', str.getString("browserDisable.label"));
+ // is it visible?
+ let label = window.social.sidebar.visible ? "hideSidebar.label" : "showSidebar.label";
+ uieltSidebar.setAttribute('label', str.getString(label));
+ } else {
+ uieltSocial.setAttribute('label', str.getString("browserEnable.label"));
+ // Hide the disabled items.
+ uieltSidebar.setAttribute("hidden", "true");
+ // XXX - other items???
+ }
},
+
onToggleEnabled: function() {
var str = document.getElementById("socialdev-strings");
- if (window.social.sidebar.visibility != "hidden") {
- Services.obs.notifyObservers(null, "social-browsing-disabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserEnable.label"));
+ let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
+ .getService(Ci.mozISocialRegistry);
+ if (!registry.currentProvider || !registry.currentProvider.enabled) {
+ Services.console.logStringMessage("no service is enabled, so not opening the socialbar!")
+ return;
}
- else {
+
+ window.social.sidebar.enabled = !window.social.sidebar.enabled;
+ if (window.social.sidebar.enabled) {
Services.obs.notifyObservers(null, "social-browsing-enabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserDisable.label"));
+ } else {
+ Services.obs.notifyObservers(null, "social-browsing-disabled", null);
}
+ this.renderPopupFromCurrentState();
},
onToggleVisible: function() {
var str = document.getElementById("socialdev-strings");
@@ -202,21 +226,11 @@ SocialToolbarStatusArea.prototype = {
.getService(Ci.mozISocialRegistry);
if (!registry.currentProvider || !registry.currentProvider.enabled) {
Services.console.logStringMessage("no service is enabled, so not opening the socialbar!")
+ return;
}
- else {
- let sidebar = window.social.sidebar;
- if (sidebar.visibility == 'hidden') {
- Services.obs.notifyObservers(null, "social-browsing-enabled", null);
- document.getElementById('social-socialbrowsing-menu').
- setAttribute('label', str.getString("browserDisable.label"));
- }
- else {
- sidebar.visibility = (sidebar.visibility=="open" ? "minimized" : "open");
- let label = (sidebar.visibility == "open" ? "minimizeSidebar.label" : "showSidebar.label")
- document.getElementById('social-socialtoolbar-menu').
- setAttribute('label', str.getString(label));
- }
- }
+ let sidebar = window.social.sidebar;
+ sidebar.visible = !sidebar.visible;
+ this.renderPopupFromCurrentState();
},
ambientNotificationChanged: function() {
@@ -225,3 +239,78 @@ SocialToolbarStatusArea.prototype = {
}
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+
+function buildSocialPopupContents(window, socialpanel)
+{
+ let registry = Cc["@mozilla.org/socialProviderRegistry;1"]
+ .getService(Ci.mozISocialRegistry);
+
+ function renderNotificationRow(img, title, text) {
+ let row = window.document.createElementNS(HTML_NS, "div");
+ row.setAttribute("style", "clear:all;cursor:pointer;margin-left:8px;height:32px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:-moz-system-font;border-right:");
+
+ let imgElem = window.document.createElementNS(HTML_NS, "img");
+ imgElem.setAttribute("src", img);
+ imgElem.setAttribute("style", "width:28px;height:28px;margin-right:8px;float:left");
+
+ let titleElem = window.document.createElementNS(HTML_NS, "span");
+ titleElem.appendChild(window.document.createTextNode(title));
+ titleElem.setAttribute("style", "font-weight:bold");
+
+ let textElem = window.document.createElementNS(HTML_NS, "span");
+ textElem.appendChild(window.document.createTextNode(((text.length > 0 && text[0] != ' ') ? " " : "")+ text));
+
+ row.appendChild(imgElem);
+ row.appendChild(titleElem);
+ row.appendChild(textElem);
+ return row;
+ }
+
+ function renderProviderMenuitem(service, container, before) {
+
+ let menuitem = window.document.createElementNS(XUL_NS, "menuitem");
+ menuitem.setAttribute("label", service.name);
+ menuitem.setAttribute("class", "menuitem-iconic");
+ menuitem.setAttribute("image", service.iconURL);
+ menuitem.setAttribute("type", "radio");
+ menuitem.setAttribute("name", "socialprovider");
+ if (service == registry.currentProvider) {
+ // no need for a click handler if we're selected
+ menuitem.setAttribute("checked", true);
+ }
+ else {
+ menuitem.addEventListener("click", function(event) {
+ registry.currentProvider = service;
+ });
+ }
+ container.insertBefore(menuitem, before);
+ }
+
+ try {
+ let menuitem;
+ let disabled = !window.social.sidebar.enabled;
+ let providerSep = document.getElementById('social-statusarea-providers-separator');
+ let fc = providerSep.previousSibling;
+ while (fc.localName != 'menuseparator') {
+ socialpanel.removeChild(fc);
+ fc = providerSep.previousSibling;
+ }
+ // if we are disabled we don't want the list of providers nor the separators
+ if (disabled) {
+ fc.setAttribute("hidden", "true");
+ providerSep.setAttribute("hidden", "true");
+ } else {
+ fc.removeAttribute("hidden");
+ providerSep.removeAttribute("hidden");
+ // Create top-level items
+ registry.each(function(service) {
+ if (service.enabled)
+ renderProviderMenuitem(service, socialpanel, providerSep);
+ });
+ }
+ }
+ catch (e) {
+ Cu.reportError("Error creating socialpopupcontents: " + e);
+ }
+}
View
2  locale/en-US/social.properties
@@ -1,4 +1,4 @@
browserEnable.label=Enable Social Browsing
browserDisable.label=Disable Social Browsing
-minimizeSidebar.label=Minimize Social sidebar
+hideSidebar.label=Hide Social sidebar
showSidebar.label=Show Social sidebar

No commit comments for this range

Something went wrong with that request. Please try again.