| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" > |
| <title>Bayeux Stock Ticker</title> |
| <script type="text/javascript" src="../../dojo/dojo.js.uncompressed.js"></script> |
| <script type="text/javascript" src="../../dojox/cometd.js"></script> |
| <script type="text/javascript" src="../../dojox/cometd/_base.js"></script> |
| <script type="text/javascript"> |
| |
| dojo.require("dojox.cometd"); |
| |
| dojo.addOnLoad(function() { |
| dojox.cometd.init("/cometd/cometd"); |
| dojox.cometd.startBatch(); |
| dojox.cometd.subscribe("/stock/GOOG", onMsgEvent); |
| dojox.cometd.subscribe("/stock/YHOO", onMsgEvent); |
| dojox.cometd.subscribe("/stock/SPRG", onMsgEvent); |
| dojox.cometd.endBatch(); |
| }); |
| |
| |
| dojo.addOnUnload(function() { |
| dojox.cometd.startBatch(); |
| dojox.cometd.unsubscribe("/stock/GOOG", this,""); |
| dojox.cometd.unsubscribe("/stock/YHOO", this,""); |
| dojox.cometd.unsubscribe("/stock/SPRG", this,""); |
| dojox.cometd.endBatch(); |
| }); |
| |
| |
| function subscribe(box, symbol) { |
| if (box.checked) { |
| dojox.cometd.subscribe("/stock/"+symbol, onMsgEvent); |
| var rowCurrent = dojo.byId("row."+symbol); |
| rowCurrent.bgColor="white"; |
| } else { |
| dojox.cometd.unsubscribe("/stock/"+symbol, onMsgEvent); |
| var rowCurrent = dojo.byId("row."+symbol); |
| rowCurrent.bgColor="gray"; |
| } |
| } |
| |
| function removeChildrenFromNode(node) |
| { |
| if(node == undefined || node == null) |
| { |
| return; |
| } |
| |
| var len = node.childNodes.length; |
| |
| while (node.hasChildNodes()) |
| { |
| node.removeChild(node.firstChild); |
| } |
| } |
| |
| function onMsgEvent(event) { |
| // Break apart the text string into screen name and message parts. |
| var symbol = event.data.symbol; |
| var price = event.data.price; |
| var pricechange = event.data.change; |
| //alert("symbol: "+symbol+" price: "+price+" change: "+pricechange); |
| |
| var pricenode = dojo.byId("price."+symbol); |
| var changenode = dojo.byId("change."+symbol); |
| removeChildrenFromNode(pricenode); |
| removeChildrenFromNode(changenode); |
| var pricelabel = document.createTextNode(price); |
| pricelabel.value = price; |
| var changelabel = document.createTextNode(pricechange); |
| changelabel.value = pricechange; |
| pricenode.appendChild(pricelabel); |
| changenode.appendChild(changelabel); |
| |
| var table = dojo.byId("stocktable"); |
| var rows = table.getElementsByTagName("tr"); |
| for(i = 0; i < rows.length; i++){ |
| if (rows[i].bgColor != "gray") { |
| rows[i].bgColor = "white"; |
| } |
| } |
| //manipulate rows |
| var rowCurrent = dojo.byId("row."+symbol); |
| if (pricechange<=0) { |
| rowCurrent.bgColor = "red"; |
| } else { |
| rowCurrent.bgColor = "cyan"; |
| } |
| } |
| |
| |
| </script> |
| </head> |
| <body bgcolor="#ffffff"> |
| <h1 align="center">Bayeux Stock Ticker</h1> |
| <h2 align="left"> </h2> |
| <p> |
| <table id="stocktable" cellspacing="0" cellpadding="3" width="100%" align="center" border="0"> |
| <tr id="row.HEADER"> |
| <td>SYMBOL</td> |
| <td>PRICE</td> |
| <td>LAST CHANGE</td> |
| <td>SUBSCRIBE</td></tr> |
| <tr id="row.SPRG"> |
| <td>SPRG</td> |
| <td id="price.SPRG"></td> |
| <td id="change.SPRG"></td> |
| <td id="check.SPRG"><input type="checkbox" id="check.SPRG" checked onClick="subscribe(this,'SPRG')"></td> |
| </tr> |
| <tr id="row.GOOG"> |
| <td>GOOG</td> |
| <td id="price.GOOG"></td> |
| <td id="change.GOOG"></td> |
| <td id="check.GOOG"><input type="checkbox" id="check.GOOG" checked onClick="subscribe(this,'GOOG')"></td> |
| </tr> |
| <tr id="row.YHOO"> |
| <td>YHOO</td> |
| <td id="price.YHOO"></td> |
| <td id="change.YHOO"></td> |
| <td id="check.YHOO"><input type="checkbox" id="check.GOOG" checked onClick="subscribe(this,'YHOO')"></td> |
| </tr> |
| </table> |
| </p> |
| </body> |
| </html> |