home *** CD-ROM | disk | FTP | other *** search
/ Clickx 65 / Clickx 65.iso / software / internet / xmarks / xmarks-3.1.1.xpi / chrome / content / foxmarks-overlay.js < prev    next >
Encoding:
JavaScript  |  2009-05-05  |  2.5 KB  |  90 lines

  1. /* 
  2.  Copyright 2005-2007 Foxmarks Inc.
  3.  
  4.  foxmarks-overlay.js: implement the foxmarks overlay into the main browser
  5.  window
  6.  */
  7.  
  8. var foxmarksObserver = {
  9.     observe: function(subject, topic, data) {
  10.         var result = eval(data);
  11.         //ignore component finish messages
  12.         if(result.status == 3)
  13.             return;
  14.         var status = result.status;
  15.         var msg = result.msg || "";
  16.         var complete = status != 1;
  17.  
  18.         window.XULBrowserWindow.setJSStatus("Xmarks: " + msg);
  19.  
  20.         if (complete) {
  21.             setTimeout(foxmarksObserver.clearStatus, status != 0 ? 5000: 1000);
  22.         }
  23.     },
  24.     clearStatus: function() {
  25.         window.XULBrowserWindow.setJSStatus("");
  26.      }
  27. }
  28.  
  29. var foxmarksPopupObserver = {
  30.     observe: function(subject, topic, data) {
  31.         var JSON = Cc["@mozilla.org/dom/json;1"].
  32.             createInstance(Ci.nsIJSON);
  33.         FoxmarksNewUserPopup(JSON.decode(data));
  34.     }
  35. }
  36. function FoxmarksSetKeyboardShortcut(id, key) {
  37.     var element = document.getElementById(id);
  38.     element.setAttribute("key", key);
  39.     element.setAttribute("disabled", key ? false : true);
  40. }
  41.  
  42. function FoxmarksBrowserLoad() {
  43.     var os = Cc["@mozilla.org/observer-service;1"].
  44.         getService(Ci.nsIObserverService);
  45.     os.addObserver(foxmarksObserver, "foxmarks-service", false);
  46.     os.addObserver(foxmarksPopupObserver, "foxmarks-newpopup", false);
  47.  
  48.     FoxmarksSetKeyboardShortcut("SyncNow", gSettings.syncShortcutKey);
  49.     FoxmarksSetKeyboardShortcut("OpenFoxmarksDialog",
  50.         gSettings.openSettingsDialogShortcutKey);
  51.     FoxmarksSetKeyboardShortcut("FoxmarksSimSiteKey",
  52.         gSettings.siteinfoDialogShortcutKey);
  53.  
  54.     // Load SERP
  55.     FoxmarksSERP.init();
  56.  
  57.     // Load similiar sites
  58.     FoxmarksSimSites.init();
  59. }
  60.  
  61. function FoxmarksOnPopupShowing() {
  62.     if (gSettings.hideStatusIcon) {
  63.         document.getElementById("foxmarks-showstatusicon").
  64.             removeAttribute("checked");
  65.     } else {
  66.         document.getElementById("foxmarks-showstatusicon").
  67.             setAttribute("checked", "true");
  68.     }
  69.     return true;
  70. }
  71.  
  72. function FoxmarksToggleIcon(event) {
  73.     gSettings.hideStatusIcon = !gSettings.hideStatusIcon;
  74. }
  75.  
  76. function FoxmarksBrowserUnload() {
  77.     var os = Cc["@mozilla.org/observer-service;1"].
  78.         getService(Ci.nsIObserverService);
  79.  
  80.     try {
  81.         os.removeObserver(foxmarksObserver, "foxmarks-service");
  82.     } catch (e) {
  83.         LogWrite("Warning: removeObserver failed.");
  84.     }
  85. }
  86.  
  87. window.addEventListener("load", FoxmarksBrowserLoad, false);
  88. window.addEventListener("unload", FoxmarksBrowserUnload, false);
  89.  
  90.