<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ray Acayan &#187; JavaScript</title>
	<atom:link href="http://www.RayAcayan.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.RayAcayan.com</link>
	<description>A Geek of All Trades</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Image Overlay Project</title>
		<link>http://www.RayAcayan.com/projects/the-image-overlay-project/</link>
		<comments>http://www.RayAcayan.com/projects/the-image-overlay-project/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 18:15:51 +0000</pubDate>
		<dc:creator>Ray Acayan</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Consulting]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rayacayan.com/blog/?p=212</guid>
		<description><![CDATA[I. Overview This is a simple project for displaying an image overlay whenever the user moves the mouse over an element on the web page. This effect is demonstrated on my website in the menu items above, the scrolling stock ticker, and the icons to the right of my photo. This feature is useful for [...]]]></description>
			<content:encoded><![CDATA[<p></br></p>
<h2 style="color:darkblue">I. Overview</h2>
<p>This is a simple project for displaying an image overlay whenever the user moves the mouse over an element on the web page.  This effect is demonstrated on my website in the menu items above, the scrolling stock ticker, and the icons to the right of my photo.</p>
<p>This feature is useful for displaying value-added information quickly on the same web page without requiring the user to click the mouse, find the information on a different page, then click back to the original page.  It is also helpful for mobile devices with limited screen space, where small icons representing web sites can be enlarged as the user moves the mouse over them.<br />
<br /></br></p>
<h2 style="color:darkblue">II. Source Code</h2>
<p>I do my best to explain the concepts and techniques behind my projects, but I cannot provide the complete source code.  If you like my work and can use my expertise in your projects, I am available for <span id="consulting_page" onmouseover="consulting_mouseOver()" onmousemove="consulting_mouseMove()" onmouseout="consulting_mouseOut()"><a href="http://www.rayacayan.com/blog/consulting/"><strong>consulting</strong></a></span> at a very competitive rate.<br />
<br /></br></p>
<h2 style="color:darkblue">III. Components</h2>
<p><strong>1.  Mouse Position Component</strong></p>
<p>This component captures the mouse cursor&#8217;s current position, which is later used to determine the screen position for displaying the image overlay.  It uses &lt;div&lt; elements for the X and Y position of the mouse, then updates those variables as follows:</p>
<div class="code">
  if (window.Event) { document.captureEvents(Event.MOUSEMOVE); }<br />
  document.onmousemove = getCursorXY;
</div>
<p>The getCursorXY() function uses the value of document.body.scrollLeft and document.bodyscrollTop to determine the mouse cursor&#8217;s X and Y position on the web page.</p>
<p><strong>2. Event Assignment Component</strong></p>
<p>This component is a set of JavaScript functions for assigning events to trigger elements such as icons or text, which are assumed to be in basic form, such as an &lt;img&gt; or &lt;a&gt;.  It finds a trigger element and encapsulates it in a &lt;div&gt; or &lt;span&gt; tag containing mouseover, mousemove, and mouseout events pointing to the corresponding JavaScript functions.  For example:</p>
<div class="code">
var node = document.getElementById(&#8220;navigation&#8221;).getElementsByTagName(&#8220;a&#8221;)[i];<br />
if( node.innerHTML == &#8220;Resume&#8221; )<br />
&nbsp;&nbsp;  node.innerHTML = &#8216;&lt;span id=&#8221;resume_page&#8221; &#8216; + &#8230;<br />
&nbsp;&nbsp;  + onmouseover=&#8221;resume_mouseOver()&#8221;>&#8217;<br />
&nbsp;&nbsp;  + node.innerHTML + &#8216;&lt;/span&gt;&#8217;;
</div>
<p><strong>3. Image Display Component</strong></p>
<p>This component is a set of JavaScript functions which respond to the mouse events and display the image overlay.  The onmouseover() event calls a function which dynamically creates an &lt;img&gt; element from a file as follows:</p>
<div class="code">
var imgbox=document.getElementById(&#8220;resume_page&#8221;);<br />
imgbox.style.visibility=&#8221;visible&#8221;;<br />
var img = document.createElement(&#8220;img&#8221;);<br />
img.src=&#8221;RayResume.png&#8221;;<br />
imgbox.appendChild(img);
</div>
<p>The mousemove() function moves the chart based on the mouse cursor&#8217;s current position. The onmouseout() function hides the chart by setting the imgbox visibility to &#8220;hidden&#8221;<br />
<br /></br></p>
<h2 style="color:darkblue">IV. Future Enhancements</h2>
<p><strong>1. Dynamic Image Caching</strong></p>
<p>I do not currently implement caching on this website.  Consequently, there is an intermittent delay when retrieving images as you move the mouse over certain items such as the scrolling stock ticker.  A cache can be developed to automatically create image snapshots of this information and display the cached image instead.</p>
<p><strong>2.  Other Types of Overlay</strong></p>
<p>The overlay effect can enhanced to display dynamic content types such as dynamic stock charts, video surveillance cameras, and real-time GPS maps, rather than just static images.  The possibilities are endless.</p>
<p></br><br /></br></p>
]]></content:encoded>
			<wfw:commentRss>http://www.RayAcayan.com/projects/the-image-overlay-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Scrolling Stock Ticker Project</title>
		<link>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/</link>
		<comments>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 21:00:17 +0000</pubDate>
		<dc:creator>Ray Acayan</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Consulting]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stocks]]></category>

		<guid isPermaLink="false">http://www.rayacayan.com/blog/?p=58</guid>
		<description><![CDATA[I. Overview The scrolling stock ticker above is a simple example of a lightweight component for retrieving real-time data and displaying it dynamically in a web browser. Many stock tickers today are based on heavy Java applets, which tend to slow down my computer considerably. Other tickers based on JavaScript and Ajax do not have [...]]]></description>
			<content:encoded><![CDATA[<p></br></p>
<h2 style="color:darkblue">I. Overview</h2>
<p>The scrolling stock ticker above is a simple example of a lightweight component for retrieving real-time data and displaying it dynamically in a web browser. Many stock tickers today are based on heavy Java applets, which tend to slow down my computer considerably. Other tickers based on JavaScript and Ajax do not have a scrolling feature. The basic marquee scrollers do not retrieve real-time data. So, I decided to develop my own simple scrolling stock ticker which combines all of these functions.<br />
<br /></br></p>
<h2 style="color:darkblue">II. Consulting</h2>
<p>I do my best to explain the concepts and techniques behind my projects.  If you like my work and can use my expertise in your projects, I am available for <span id="consulting_page" onmouseover="consulting_mouseOver()" onmousemove="consulting_mouseMove()" onmouseout="consulting_mouseOut()"><a href="http://www.rayacayan.com/blog/consulting/"><strong>consulting</strong></a></span> at a competitive rate.<br />
<br /></br></p>
<h2 style="color:darkblue">III. Components</h2>
<p><strong>1. Stock Data Retrieval Component</strong></p>
<p>This component is a group of PHP functions for querying a web data source, retrieving the resulting data, and storing the result in a DOM document object. These functions are located in a standalone PHP file.</p>
<p>First, the stock quotes are retrieved using the @fopen() file pointer to the following url:</p>
<div class="code">&#8220;http://finance.yahoo.com/d/quotes.csv?s=$stock&amp;f=sn1l1c1p2&amp;e=.csv&#8221;
</div>
<p>The Yahoo Finance site will return a comma-delimited CSV file based on the query parameters. More info on Yahoo&#8217;s data protocol can be found <a href="http://www.gummy-stuff.org/Yahoo-data.htm">here</a>. Other web services return data in RSS, JSON, or XML formats, which will require different query and parsing methods.</p>
<p>Next, the CSV-formatted results are parsed by the @fgetcsv() function, which stores the comma-delimited values into an array.  The array values are then placed into &lt;span&gt; elements and returned in the following format:</p>
<div class="code">&lt;span class=&#8221;stock_up&#8221;&gt;GOLD 5,000.00 +4,000.00, +400.0%&lt;/span&gt;</div>
<p><strong>2. CSS Display Component</strong></p>
<p>Not exactly a &#8220;component&#8221;, this is simply a CSS file which contains formatting for the &lt;span&gt; data above. For example:</p>
<div class="code">
.stock_up<br />
{<br />
&nbsp;&nbsp;  color: green;<br />
&nbsp;&nbsp;  cursor: hand;<br />
&nbsp;&nbsp;  cursor: pointer;<br />
&nbsp;&nbsp;  padding-bottom: 2px;<br />
&nbsp;&nbsp;  padding-left: 1em;<br />
&nbsp;&nbsp;  padding-right: 1em;<br />
&nbsp;&nbsp;  margin: 0px;<br />
}
</div>
<p><strong>3. Ajax Stock Update Component</strong></p>
<p>This component is a group of JavaScript functions for dynamically updating the stock quotes using Ajax.  Ajax is a group of web techniques for updating a web page without the user having to press the Refresh button.</p>
<p>The function uses the http_request.onreadystatechange property to call the Stock Data Retrieval Component (i.e. the standalone PHP file) to retrieve a new set of &lt;span&gt; elements containing the newly-updated stock quotes.  The document object is then updated dynamically by replacing the &lt;span&gt; contents of the &lt;div id=&#8221;RayStockTickerID&#8221;&gt; node as follows:</p>
<div class="code">document.getElementById(&#8216;RayStockTickerID&#8217;).innerHTML = http_request.responseText;</div>
<p><strong>4. Scrolling Marquee Component</strong></p>
<p>This component is a group of JavaScript functions which retrieve the stock quotes from the DOM document object, display the css-formatted stock quotes in a line of text, then scroll the text from right to left one pixel at a time with the setTimeout() function.</p>
<p>As each stock quote falls off the left of the screen, its &lt;span&gt; node is removed and appended to the end of the chain to create a continuous loop.  At the end of each loop, the stock quotes are updated dynamically by the Ajax Stock Update Component.</p>
<p><strong>5. Chart Display Component</strong></p>
<p>When you move the mouse to a particular stock in the ticker, this component will display an overlay of the corresponding daily stock chart.  This is accomplished using onmouseover() event handlers within each stock&#8217;s &lt;span&gt; tag.  The onmouseover() event calls a function which dynamically creates an &lt;img&gt; element and retrieves the chart from Yahoo Finance as follows:</p>
<div class="code">
  var imgbox=document.getElementById(&#8220;stockchart&#8221;);<br />
  imgbox.style.visibility=&#8217;visible&#8217;;<br />
  var img = document.createElement(&#8220;img&#8221;);<br />
  img.src=&#8217;http://ichart.finance.yahoo.com/t?s=&#8217; + stock;<br />
  imgbox.appendChild(img);
</div>
<p>The mousemove() function moves the chart based on the mouse cursor&#8217;s current position.  The onmouseout() function hides the chart by setting the imgbox visibility to &#8216;hidden&#8217;.</p>
<p><strong>6. Main Component</strong></p>
<p>The main component is a a section of PHP code in the main website which creates all the components above and initiates the program.<br />
<br /></br></p>
<h2 style="color:darkblue">IV. Future Enhancements</h2>
<p><strong>A. Different Input Formats</strong></p>
<p>As mentioned above, the input data streams may be formatted in RSS, JSON, XML, etc.  Functions can be developed for parsing and querying these other data protocols.</p>
<p><strong>B. Caching</strong></p>
<p>This simple project does not implement caching since it does not use previous stock data.  A cache can be developed to store data into an external database or text file before displaying it on the screen.</p>
<p><strong>C. Data Processing</strong></p>
<p>The incoming data can be processed and enriched before displaying to the web page.  For example, the stock ticker could display only those stocks which have crossed their 50-day moving average, or those that have exceeded their daily VaR limits within a portfolio.</p>
<p><strong>D. Different Output Formats</strong></p>
<p>Instead of a simple scrolling ticker display, this app can be modified to create an output data stream in other formats like RSS, JSON, XML, database, e-mail, etc, or other platforms such as Facebook, Twitter, and mobile devices.</p>
<p></br><br /></br></p>
]]></content:encoded>
			<wfw:commentRss>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

