home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8614 / 8614.xpi / chrome / extension.jar / content / application / Application.js next >
Encoding:
Text File  |  2010-02-10  |  5.2 KB  |  147 lines

  1. Glydo.App = Prototype.Class.create({
  2.     initialize: function() {
  3.         Glydo.Prefs.subscribe("",this.onPrefChanged);
  4.         this.window = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  5.                                   .getInterface(Components.interfaces.nsIWebNavigation)
  6.                                   .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
  7.                                   .rootTreeItem
  8.                                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  9.                                   .getInterface(Components.interfaces.nsIDOMWindow);
  10.         this.browserBridge = new Glydo.BrowserBridge();
  11.         this.browserBridge.addListener(this);
  12.     },
  13.  
  14.     onPrefChanged: function(pref,value) {
  15.         Glydo.LOGGING_DB.logUserEvent("application.prefs." + pref,"change",null,value);
  16.     },
  17.     
  18.     onWindowLoaded: function(theWindow) {
  19.         if (!this.window.menubar.visible || !this.window.toolbar.visible) {
  20.             
  21.             var sbp = this.window.document.getElementById("glydo-statusbarpanel");
  22.             if (sbp) {
  23.                 sbp.hidden = true;
  24.             }
  25.             this.enabled = false;
  26.             return;
  27.         }
  28.         this.enabled = true;
  29.         this.documentManager = new Glydo.DocumentManager();
  30.         this.statusbar = new Glydo.Statusbar(this);
  31.         this.detachedPopupsManager = new Glydo.DetachedPopupsManager(this);
  32.         this.teasersManager = new Glydo.TeasersManager(this);
  33.         this.sharing = new Glydo.Sharing(this);
  34.         this.browserBridge.addListener(this.documentManager);
  35.         this.documentManager.addListener(this.statusbar);
  36.         this.documentManager.addListener(this.detachedPopupsManager);
  37.         this.documentManager.addListener(this.teasersManager);
  38.         this.detachedPopupsManager.addListener(this.statusbar);
  39.         this.detachedPopupsManager.addListener(this.teasersManager);
  40.         this.documentManager.onTabSelect(this.window.getBrowser().selectedBrowser);
  41.         Glydo.LOGGING_DB.logUserEvent("browser.window","new",null,null);
  42.         // Register recommendation events
  43.         Glydo.VERSIONS_MANAGER.showWelcomePageIfNecessary(this.window);
  44.     },
  45.  
  46.     onWindowUnloaded: function(theWindow) {
  47.         Glydo.LOGGING_DB.logUserEvent("browser.window","close",null,null);
  48.     },
  49.     
  50.     openSettingsDialog: function() {
  51.         var features = 'resizable=no, chrome=yes, centerscreen=yes';
  52.         
  53.         window.open('chrome://glydo/content/ui/settings/settings.xul', '', features);
  54.     },
  55.     
  56.     openAboutDialog: function() {
  57.         var features = 'resizable=no, chrome=yes, centerscreen=yes';
  58.         window.open('chrome://glydo/content/ui/about/about.xul', '', features);
  59.     },
  60.     
  61.     openFeedbackPage: function() {
  62.         Glydo.WindowUtils.goToURL(window,'http://www.glydo.com/feedback.php?client_id='+encodeURIComponent(Glydo.CLIENT_INFO.clientId) + '&client_time=' + encodeURIComponent(Glydo.Utils.toISO8601DateString(new Date())),'new-tab');
  63.     },
  64.     
  65.     followRecommendation: function(rec,mode,url,re_kind,re_position) {
  66.         if (!rec) {
  67.             return;
  68.         }
  69.         url = url || rec.url;
  70.         var dest = Glydo.WindowUtils.goToURL(window,url,mode);
  71.         if (rec.documentEntry && 
  72.                 (rec.documentEntry.resultSource === "server") && 
  73.                 rec.documentEntry.requestTime &&
  74.                 rec.documentEntry.responseTime) {
  75.             Glydo.LOGGING_DB.logRecAction(rec.recSetId,rec.id,"OPEN",dest,re_kind,re_position);
  76.         }
  77.     },
  78.  
  79.     
  80.     openRecommendationFeedback: function(rec) {
  81.         if (rec) {
  82.             var features = 'resizable=yes, chrome=yes, centerscreen=yes';
  83.             window.openDialog('chrome://glydo/content/ui/feedback/recommendation_feedback.xul', '', features, rec, Prototype.F.bind(this.onRecommendationFeedbackSend,this));
  84.         }
  85.     },
  86.  
  87.     onRecommendationFeedbackSend: function(rec) {
  88.         
  89.         var f = new Glydo.Feedback(rec);
  90.         f.send();
  91.     },
  92.  
  93.     getContextRecommendationLink: function() {
  94.         var popupNode = document.popupNode;
  95.         for (; popupNode && (!popupNode.rec || !popupNode.href); popupNode = popupNode.parentNode) {
  96.         }
  97.         return popupNode;
  98.     },
  99.     
  100.     onRecommendationContextMenu: function(event) {
  101.         var popupNode = this.getContextRecommendationLink();
  102.         var menu = event.target;
  103.         if (menu) {
  104.             if (popupNode) {
  105.                 Prototype.E.removeClassName(menu,"glydo-no-recommendation-context");
  106.             } else {
  107.                 Prototype.E.addClassName(menu,"glydo-no-recommendation-context");
  108.             }                
  109.         }
  110.         return this.detachedPopupsManager.onContextMenu(event);
  111.     },
  112.     
  113.     openContextRecommendation: function(mode) {
  114.         var popupNode = this.getContextRecommendationLink();
  115.         if (!popupNode) {
  116.             return;
  117.         }
  118.         this.followRecommendation(popupNode.rec,mode,popupNode.href,popupNode.realEstateKind,popupNode.realEstatePosition);
  119.     },
  120.     
  121.     openContextRecommendationFeedback: function() {
  122.         var popupNode = this.getContextRecommendationLink();
  123.         if (!popupNode) {
  124.             return;
  125.         }
  126.         this.openRecommendationFeedback(popupNode.rec);
  127.     },
  128.  
  129.     generateThumbnailServiceURL: function(rec) {
  130.         var s = Glydo.App.GIRAFA_SIGNATURE_KEY + rec.url;
  131.         var sig = Glydo.Utils.md5(s);
  132.         sig = sig.substring(sig.length-16);
  133.         var gurl = Glydo.App.GIRAFA_SITE_THUMBNAIL_URL_TEMPLATE.evaluate({
  134.             clientId: encodeURIComponent(Glydo.App.GIRAFA_CLIENT_ID),
  135.             signature: encodeURIComponent(sig),
  136.             url: encodeURIComponent(rec.url)
  137.         });
  138.         return gurl;
  139.     },
  140.  
  141.     
  142. });
  143.  
  144. Glydo.App.GIRAFA_CLIENT_ID = "sc0102142";
  145. Glydo.App.GIRAFA_SIGNATURE_KEY = "glydokey";
  146. Glydo.App.GIRAFA_SITE_THUMBNAIL_URL_TEMPLATE = new Prototype.Template("http://scst.srv.girafa.com/srv/i?i=#{clientId}&s=#{signature}&r=#{url}");
  147.