Skip to content
Browse files

move more dom generation code to xul overlay, add dtd support

  • Loading branch information...
1 parent 0ffcc36 commit 727796d40bdd3989d8f7817c3c2a03d2ec6d121e @mixedpuppy mixedpuppy committed Apr 2, 2012
Showing with 60 additions and 84 deletions.
  1. +21 −4 content/overlay.xul
  2. +35 −80 content/toolbarButtonWidget.js
  3. +4 −0 locale/en-US/social.dtd
View
25 content/overlay.xul
@@ -1,4 +1,8 @@
<?xml version="1.0"?>
+<!DOCTYPE overlay [
+<!ENTITY % socialDTD SYSTEM "chrome://socialdev/locale/social.dtd">
+%socialDTD;
+]>
<?xml-stylesheet href="resource://socialdev/skin/browser.css" type="text/css"?>
@@ -26,29 +30,42 @@
<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()"/>
</commandset>
<keyset id="mainKeyset">
<key id="key_socialRecommend" keycode="VK_F2" command="cmd_socialRecommend"/>
+ <!--<key id="key_socialBrowsingToggle" keycode="VK_F2" command="cmd_socialBrowsingToggle"/>-->
+ <!--<key id="key_socialToolbarToggle" keycode="VK_F2" command="cmd_socialToolbarToggle"/>-->
</keyset>
<toolbarpalette id="BrowserToolbarPalette">
<toolbaritem
id="social-button-container"
class= "chromeclass-toolbar-additional"
removable="true"
- title="Social">
+ title="&socialdev.label;">
<toolbarbutton
id="socialdev-button"
class="toolbarbutton-1"
type="menu-button"
- tooltiptext="Social Browsing"
+ tooltiptext="&socialdev.toolbartext;"
removable="true"
- oncommand="social.toolbarButton.oncommand(event);">
+ command="cmd_socialToolbarToggle">
<menupopup id="social-toolbar-menu"
onpopupshown="social.toolbarButton.onpopupshown(event)"
onpopupshowing="social.toolbarButton.onpopupshowing(event)"
- onpopuphidden="social.toolbarButton.onpopuphidden(event)"/>
+ onpopuphidden="social.toolbarButton.onpopuphidden(event)">
+ <menuitem id="social-socialtoolbar-menu" label="Minimize/Show Social Sidebar" command="cmd_socialToolbarToggle"/>
+ <menuitem id="social-socialbrowsing-menu" label="Enable/Disable Social Browsing" 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>
</toolbarpalette>
View
115 content/toolbarButtonWidget.js
@@ -36,24 +36,40 @@ SocialToolbarButton.prototype = {
let socialpanel = aWindow.document.getElementById("social-toolbar-menu");
buildSocialPopupContents(aWindow, socialpanel);
},
- oncommand: function(event) {
- if (event.target.getAttribute("id") != "socialdev-button")
- return;
- let aWindow = event.target.ownerDocument.defaultView;
+ onToggleEnabled: function() {
+ if (window.social.sidebar.visibility != "hidden") {
+ Services.obs.notifyObservers(null, "social-browsing-disabled", null);
+ }
+ else {
+ Services.obs.notifyObservers(null, "social-browsing-enabled", null);
+ }
+ },
+ onToggleVisible: function() {
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 = aWindow.social.sidebar;
+ let sidebar = window.social.sidebar;
if (sidebar.visibility == 'hidden') {
Services.obs.notifyObservers(null, "social-browsing-enabled", null);
}
else {
sidebar.visibility = (sidebar.visibility=="open" ? "minimized" : "open");
}
}
+ },
+
+ 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"
+ });
}
}
@@ -86,7 +102,7 @@ function buildSocialPopupContents(window, socialpanel)
return row;
}
- function renderProviderMenuitem(service, container) {
+ function renderProviderMenuitem(service, container, before) {
let menuitem = window.document.createElementNS(XUL_NS, "menuitem");
menuitem.setAttribute("label", service.name);
@@ -103,7 +119,7 @@ function buildSocialPopupContents(window, socialpanel)
registry.currentProvider = service;
});
}
- container.appendChild(menuitem);
+ container.insertBefore(menuitem, before);
// render notifications...
for (let i in service.notifications) {
@@ -115,82 +131,21 @@ function buildSocialPopupContents(window, socialpanel)
let menuitem;
let disabled = window.social.sidebar.disabled;
try {
- while (socialpanel.firstChild) socialpanel.removeChild(socialpanel.lastChild);
+ 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 (registry.currentProvider) {
- if (!disabled) {
- menuitem = window.document.createElementNS(XUL_NS, "menuitem");
- if (window.social.sidebar.visibility == "open") {
- menuitem.setAttribute("label", "Minimize social sidebar");
- menuitem.addEventListener("click", function(event) {
- // open about:social
- window.social.sidebar.visibility = "minimized";
- });
- }
- else {
- menuitem.setAttribute("label", "Show social sidebar");
- menuitem.addEventListener("click", function(event) {
- // open about:social
- window.social.sidebar.visibility = "open";
- });
- }
- socialpanel.appendChild(menuitem);
- }
-
- menuitem = window.document.createElementNS(XUL_NS, "menuitem");
- if (window.social.sidebar.visibility != "hidden") {
- menuitem.setAttribute("label", "Disable social browsing");
- menuitem.addEventListener("click", function(event) {
- // open about:social
- Services.obs.notifyObservers(null, "social-browsing-disabled", null);
- });
- }
- else {
- menuitem.setAttribute("label", "Enable social browsing");
- menuitem.addEventListener("click", function(event) {
- // open about:social
- Services.obs.notifyObservers(null, "social-browsing-enabled", null);
- });
- }
- socialpanel.appendChild(menuitem);
-
- if (!disabled) {
- socialpanel.appendChild(window.document.createElementNS(XUL_NS, "menuseparator"));
-
- // Create network rows...
- registry.each(function(service) {
- if (service.enabled)
- renderProviderMenuitem(service, socialpanel);
- });
-
- // Add some demo stuff
- socialpanel.appendChild(window.document.createElementNS(XUL_NS, "menuseparator"));
- menuitem= window.document.createElementNS(XUL_NS, "menuitem");
- menuitem.setAttribute("label", "Fire a demo notification");
- menuitem.addEventListener("click", 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"
- });
- });
- socialpanel.appendChild(menuitem);
- }
-
- socialpanel.appendChild(window.document.createElementNS(XUL_NS, "menuseparator"));
+ if (!disabled && registry.currentProvider) {
+ // Create network rows...
+ registry.each(function(service) {
+ if (service.enabled)
+ renderProviderMenuitem(service, socialpanel, providerSep);
+ });
}
- menuitem = window.document.createElementNS(XUL_NS, "menuitem");
- menuitem.setAttribute("label", "Preferences");
- menuitem.addEventListener("click", function(event) {
- // open about:social
- window.gBrowser.selectedTab = window.gBrowser.addTab("about:social");
- });
- socialpanel.appendChild(menuitem);
-
}
catch (e) {
Cu.reportError("Error creating socialpopupcontents: " + e);
View
4 locale/en-US/social.dtd
@@ -0,0 +1,4 @@
+<!ENTITY socialdev.label "Social">
+<!ENTITY socialdev.accesskey "F2">
+<!ENTITY socialdev.toolbartext "Social Browsing">
+<!ENTITY socialdev.prefslabel "Preferences...">

0 comments on commit 727796d

Please sign in to comment.
Something went wrong with that request. Please try again.