topical media & game development

talk show tell print

professional-web-01-v1-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 : "yahoo_quotes.php?tag=" + YAHOO.buzzWatch.config.symbol;
                   }
           );
           
           // Overload the success handler since we don't expect RSS
           // which is the default for BuzzWatchPanel
           
          YAHOO.buzzWatch.panels["yahoofinance.quotes"].callback["success"] = function(o) {
                  if(o.responseText !== undefined){
                          this.isEmpty = false;
                          this.setTimeout(getMaxAge(o));
                          var xotree = new XML.ObjTree();
                          var tree = xotree.parseDOM( o.responseXML.documentElement );
                          if (tree.quote.name != undefined) {
                                  setValue('yahoofinance.quotes.title', "Quotes ("+tree.quote.name+")");
                                  setValue('yahoofinance.quotes.last_price', tree.quote.lastTrade.price);
                                  setValue('yahoofinance.quotes.last_time', tree.quote.lastTrade.time + " EST (" + tree.quote.lastTrade.date +")" );
                                  setValue('yahoofinance.quotes.change', tree.quote.change);
                                  setValue('yahoofinance.quotes.open', tree.quote.open);
                                  setValue('yahoofinance.quotes.high', tree.quote.high);
                                  setValue('yahoofinance.quotes.low', tree.quote.low);
                                  setValue('yahoofinance.quotes.volume', tree.quote.volume);
                          }
                  }
          }
  
          // 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", "yahoo_chart.php?tag=" 
                          + YAHOO.buzzWatch.config.symbol + "&date=" + new Date());
          }
      }
       
          // 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 : "yahoo_finance_news.php?tag=" + YAHOO.buzzWatch.config.symbol;
                   }
       );
      
      // 4) del.icio.us 
   
          // Create a panel
          
      YAHOO.buzzWatch.panels["delicious"] = new BuzzWatchPanel(
              "delicious", 
              620, 
              150, 
              "350px",
              function() {
                   return YAHOO.buzzWatch.config.tag == ""? undefined : "delicious.php?tag=" + YAHOO.buzzWatch.config.tag;
                   //return YAHOO.buzzWatch.config.tag == ""? undefined : "http://del.icio.us/rss/tag/" + YAHOO.buzzWatch.config.tag;
                   }
       );
  
  }
  
  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.panel = new YAHOO.widget.Panel(
              name, 
              {  
                      x:x, 
                      y:y, 
                      width:width,
                      fixedcenter: false, 
                      constraintoviewport: false, 
                      underlay:"none", 
                      close:true, 
                      visible:true, 
                      draggable:true, 
                      modal:false 
              } 
      );
      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()  {
          this.load();
      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) {
                  if(o.responseText !== undefined){
                          this.isEmpty = false;
                          this.setTimeout(getMaxAge(o));
                          var xotree = new XML.ObjTree();
                          var tree = xotree.parseDOM( o.responseXML.documentElement );
                          xotree.force_array = ["item"];
                          if (tree.rss) {
                                  var channel = tree.rss.channel;
                                  var items = tree.rss.channel.item;
                          } else if (tree["rdf:RDF"]) {
                                  var channel = tree["rdf:RDF"].channel;
                                  var items = tree["rdf:RDF"].item;
                          } else {
                                  alert ("Can't reckon this RSS format!");
                                  return;
                          }
                          var channelTitle = document.getElementById(this.name + '.channel.title');
                          setValue(channelTitle, channel.title);
                          channelTitle.setAttribute("href", channel.link);
                          setValue(this.name + '.channel.description', channel.description);
                          setValue(this.name + '.channel.copyright', channel.copyright);
                          var itemElement = document.getElementById(this.name + '.item');
                          var itemsElement = itemElement.parentNode;
                          while (itemElement.nextSibling) {
                                  itemsElement.removeChild(itemElement.nextSibling);
                          }
                          var savedItem;
                          var item;
                          var itemTitle;
                          var itemDescription;
                          if (items) for( var i=0; i< items.length; i++ ) {
                                  item = items[i];
                                  itemElement = document.getElementById(this.name + '.item');
                                  if (i > 0) {
                                          savedItem = itemElement.cloneNode(true);
                                  }
                                  itemTitle = document.getElementById(this.name + '.item.title');
                                  setValue(itemTitle, item.title);
                                  itemTitle.setAttribute("href", item.link);
                                  itemDescription = document.getElementById(this.name + '.item.description');
                                  setValue(itemDescription, item.description);
                                  if (i > 0) {
                                          itemElement.removeAttribute("id");
                                          itemTitle.removeAttribute("id");
                                          itemDescription.removeAttribute("id");
                                          itemsElement.insertBefore(savedItem, itemsElement.firstChild);
                                          itemsElement.appendChild(itemElement);
                                  }
                          }
                  }
          }
  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.