topical media & game development

talk show tell print

professional-web-01-v4-panels.js / js



  YAHOO.buzzWatch.panels = {};
  
  function initPanels() {
  
    // 1) Quotes 
    
    // Create a buzzWatch panel
     YAHOO.buzzWatch.panels["yahoofinance.quotes"] = new BuzzWatchPanel(
       "yahoofinance.quotes", 
       10, 
       290, 
       "220px",
       function() {
         return YAHOO.buzzWatch.config.symbol == ""? undefined : "../../company/" + YAHOO.buzzWatch.config.symbol + "/yahoo/finance/quotes.xml";
       }
     );
     
    if (document.getElementById('yahoofinance.quotes.title').firstChild.nodeType!=8) {
      // 8 = Node.COMMENT_NODE
      YAHOO.buzzWatch.panels["yahoofinance.quotes"].show(false);
    }
    // 2) Chart
    
    // Create a buzzWatch panel
    
      YAHOO.buzzWatch.panels["yahoofinance.chart"] = new BuzzWatchPanel(
        "yahoofinance.chart", 
        10, 
        150, 
        "220px"
      );
      // Overload the load method since we don't use XMLMHTTPRequests at all!
      YAHOO.buzzWatch.panels["yahoofinance.chart"].load = function () {
        if (YAHOO.buzzWatch.config.symbol!="") {
          this.setTimeout(300);
          this.isEmpty = false;
          var img = document.getElementById('yahoofinance.chart.img');
             img.setAttribute("src",
              "../../company/" + YAHOO.buzzWatch.config.symbol + "/yahoo/finance/chart.png" + "?date=" + new Date());
          }
      }
    if (document.getElementById('yahoofinance.chart.img').getAttribute('src').indexOf("chart")>=0) {
      YAHOO.buzzWatch.panels["yahoofinance.chart"].show(false);
    }
       
    // 3) Financial news
  
    // Create a panel
      YAHOO.buzzWatch.panels["yahoofinance.news"] = new BuzzWatchPanel(
        "yahoofinance.news", 
        250, 
        150, 
        "350px",
       function() {
         return YAHOO.buzzWatch.config.symbol == ""? undefined : "../../company/" + YAHOO.buzzWatch.config.symbol + "/yahoo/finance/news.xml";
       }
       );
    if (document.getElementById('yahoofinance.news.channel.title').firstChild.nodeType!=8) {
      // 8 = Node.COMMENT_NODE
      YAHOO.buzzWatch.panels["yahoofinance.news"].show(false);
    }
      
      // 4) del.icio.us 
   
    // Create a panel
    
      YAHOO.buzzWatch.panels["delicious"] = new BuzzWatchPanel(
        "delicious", 
        620, 
        150, 
        "350px",
        function() {
       return YAHOO.buzzWatch.config.tag == ""? undefined : "../../tag/" + YAHOO.buzzWatch.config.tag + "/delicious.xml";
       //return YAHOO.buzzWatch.config.tag == ""? undefined : "http://del.icio.us/rss/tag/" + YAHOO.buzzWatch.config.tag;
       }
       );
    if (document.getElementById('delicious.channel.title').firstChild.nodeType!=8) {
      // 8 = Node.COMMENT_NODE
      YAHOO.buzzWatch.panels["delicious"].show(false);
    }
  
  }
  
  function refreshPanels(){
    for (name in YAHOO.buzzWatch.panels) {
      var panel = YAHOO.buzzWatch.panels[name];
      if (panel.isVisible() || panel.isEmpty)
        panel.show();
    }
  }
  
  function BuzzWatchPanel (name, x, y, width, getUrl) {
    this.name = name;
    this.getUrl = getUrl;
      this.oMenuItemElement = document.getElementById("menubar.view." + name);
      this.panelConfig = {  
          x:x, 
          y:y, 
          width:width,
          fixedcenter: false, 
          constraintoviewport: false, 
          underlay:"none", 
          close:true, 
          visible:true, 
          draggable:true, 
          modal:false 
        } 
      this.panel = new YAHOO.widget.Panel(
        name, 
        this.panelConfig
      );
      this.isEmpty = true;
      YAHOO.util.Event.addListener(this.oMenuItemElement, "click", this.toggle, this, true);
      this.panel.beforeHideEvent.subscribe(this.beforeHide, this);
      this.panel.beforeShowEvent.subscribe(this.beforeShow, this);
      
    this.callback = {
        success: this.handleSuccess,
        failure: this.handleFailure,
        scope: this
    };
    
      
  }
  BuzzWatchPanel.prototype.beforeHide = function(type, args, me) {
      YAHOO.util.Dom.removeClass(me.oMenuItemElement, "checked");
      me.clearTimeout();
  }
  BuzzWatchPanel.prototype.beforeShow = function(type, args, me) {
      YAHOO.util.Dom.addClass(me.oMenuItemElement, "checked");
      me.setTimeout();
  }
  BuzzWatchPanel.prototype.show = function(reload)  {
    if (reload==undefined || reload==true) {
     this.load();
    } else {
      this.setTimeout(300);
    }
    this.panel.render();
    this.panel.show();
  }
  BuzzWatchPanel.prototype.hide = function()  {
    this.panel.hide();
  }
  BuzzWatchPanel.prototype.isVisible = function()  {
    return YAHOO.util.Dom.hasClass(this.oMenuItemElement, "checked");
  }
  BuzzWatchPanel.prototype.toggle = function()  {
      if (this.isVisible()) {       
          this.hide();
      } else {
          this.show();
      }
  }
  BuzzWatchPanel.prototype.clearTimeout = function() {
    if (this.timeout!=undefined) {
      clearTimeout(this.timeout);
      this.timeout = undefined;
    }
  }
  BuzzWatchPanel.prototype.setTimeout = function(duration) {
    this.clearTimeout();
    duration = Number(duration);
    if (duration)
      this.period = duration;
    if (this.period == undefined)
      this.period = 60;
    this.timeout = setTimeout('YAHOO.buzzWatch.panels["' + this.name+ '"].load()' , this.period * 1000);
    //alert ("seting timeout for panel "+this.name+" to "+ this.period);
  }
  
  BuzzWatchPanel.prototype.handleSuccess = function(o) {
      //alert("refreshing "+this.name);
      if(o.responseText !== undefined){
        this.isEmpty = false;
        this.setTimeout(getMaxAge(o));
        var processor = YAHOO.buzzWatch.controller.getXSLTProcessor();
        //alert (processor);
        var result = processor.transformToDocument(o.responseXML);
        YAHOO.buzzWatch.controller.returnXSLTProcessor(processor);
        var o = document.getElementById(this.name);
        var n = document.importNode(result.documentElement, true);
        o.parentNode.replaceChild(n, o);
        this.panelConfig = this.panel.cfg.getConfig();
        this.panel.init(this.name, this.panelConfig);
        this.panel.render();
      }
    }
  BuzzWatchPanel.prototype.handleFailure = function(o) {
      alert("failure");
      this.setTimeout(30);
  }
  BuzzWatchPanel.prototype.load = function () {
    //alert("loading "+this.name);
    if (this.getUrl != undefined && this.getUrl() != undefined) {
      YAHOO.util.Connect.asyncRequest('GET', this.getUrl(), this.callback);
    }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.