Author: ranger
Date: Sun May 7 20:14:05 2006
New Revision: 2
URL:
<http://svn.finkproject.org/websvn/listing.php?sc=1&rev=2&repname=user%3a+ranger>
Log:
initial commit of phenomenon javascript
Added:
trunk/phenomenon/js/
trunk/phenomenon/js/fvlogger/
trunk/phenomenon/js/fvlogger/debug.png (with props)
trunk/phenomenon/js/fvlogger/error.png (with props)
trunk/phenomenon/js/fvlogger/fatal.png (with props)
trunk/phenomenon/js/fvlogger/index.html (with props)
trunk/phenomenon/js/fvlogger/info.png (with props)
trunk/phenomenon/js/fvlogger/logger.css
trunk/phenomenon/js/fvlogger/logger.js
trunk/phenomenon/js/fvlogger/magnet.png (with props)
trunk/phenomenon/js/fvlogger/readme.txt
trunk/phenomenon/js/fvlogger/warn.png (with props)
trunk/phenomenon/js/phenomenon.js
Added: trunk/phenomenon/js/fvlogger/debug.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/debug.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/debug.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/fvlogger/error.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/error.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/error.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/fvlogger/fatal.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/fatal.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/fatal.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/fvlogger/index.html
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/index.html&rev=2&repname=user%3a+ranger>
==============================================================================
--- trunk/phenomenon/js/fvlogger/index.html (added)
+++ trunk/phenomenon/js/fvlogger/index.html Sun May 7 20:14:05 2006
@@ -1,0 +1,194 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+
+<title>fvlogger</title>
+
+<script type="text/javascript" src="logger.js"></script>
+
+<!-- styles for this page -->
+<style type="text/css">
+ * { font: 9pt lucida grande, verdana, arial, helvetica, sans-serif;
text-align: justify; line-height: 1.5em; }
+ em { font-weight: inherit; font-style: italic; }
+ code, pre { font-family: monaco, courier, monospace; color: #00c; }
+ pre { color: #444; border: 1px solid #00c; background-color: #efefef;
border: 1px solid #ddd; padding: 8px; }
+ h1 { font-size: 12pt; font-weight: bold; padding: 0; margin: 0 0 2px 0;
}
+ h2 { font-size: 10pt; font-weight: bold; padding: 0; margin: 0;}
+ fieldset { border: 0; padding: 0; margin: 0; }
+ body { margin: 32px; }
+ #bottle { margin: 0; padding: 0; float: left; width: 450px; margin-top:
16px; }
+ p { margin-bottom: 8px; padding: 0; margin-top: 0; }
+ #fvlogger { margin: 0; width: 450px; padding: 0; margin-bottom: 4px; }
+
+ /* the following css rule should be applied to all elements whose class
is "labrat" */
+ .labrat { font-weight: bold; color: red; }
+</style>
+
+<!-- import the supporting logger files -->
+<link rel="stylesheet" type="text/css" href="logger.css" />
+
+<link rel="icon" type="image/png" href="magnet.png" />
+
+</head>
+
+<body>
+
+<h1>fvlogger Example Page</h1>
+<div id="fvlogger">
+ <dl>
+ <dt>fvlogger</dt>
+ <dd class="all"><a href="#fvlogger" onclick="showAll();"
title="show all" id="abcdef">all</a></dd>
+ <dd class="debug"><a href="#fvlogger" onclick="showDebug();"
title="show debug" id="showDebug">debug</a></dd>
+ <dd class="info"><a href="#fvlogger" title="show info"
id="showInfo">info</a></dd>
+ <dd class="warn"><a href="#fvlogger" onclick="showWarn();"
title="show warnings" id="showWarn">warn</a></dd>
+ <dd class="error"><a href="#fvlogger" onclick="showError();"
title="show errors" id="showError">error</a></dd>
+ <dd class="fatal"><a href="#fvlogger" onclick="showFatal();"
title="show fatals" id="showFatal">fatal</a></dd>
+ <dd><a href="#fvlogger" onclick="eraseLog(true);"
title="erase">erase</a></dd>
+ </dl>
+</div>
+
+
+<div id="bottle">
+
+ <p>
+ This page illustrates how the use of logging can aid JavaScript
development, <em>especially</em> in creating scripts that behave identically
across multiple browsers. As a real–world example, let’s look at
how <acronym title="Internet Explorer">IE</acronym> assigns attributes to
dynamically–created document elements—something that caused a
hiccup in the development of fvlogger.
+ </p>
+
+ <h2>The Theory</h2>
+ <p>
+ Included in the styles of this page is the follwing rule:
+ </p>
+ <pre>.labrat { font-weight: bold; color: red; }</pre>
+
+ <p>
+ Thus, any elements in the document whose class is
“labrat”—whether they be a part of the <code>document</code>
when the page is loaded into the browser or appended at some point
thereafter—should appear in bold–faced red type, including the
following two examples.
+ </p>
+
+ <p class="labrat">This is the first example.</p>
+ <p class="labrat">This is the second example.</p>
+
+ <p>
+ Easy–peasy, right? Almost, but not quite.
+ </p>
+
+ <h2>The Problem</h2>
+ <p>
+ The examples shown above are included in the document (ie: they
were created when authoring the rest of this page), so it should come as no
surprise that they appear as they should (ie: <span class="labrat">like
this</span>) in every browser that supports <acronym title="Cascading Style
Sheets">CSS</acronym>. However, with the cross–browser support of the
DOM, dynamically creating elements and appending them to the
<code>document</code> has become commonplace (and even <em>required</em> by
many websites and applications). Let’s take a quick look to make sure
that this method also works.
+ </p>
+
+ <p>
+ The code to accomplish our task <em>should</em> look something
like the following:
+ </p>
+
+ <pre>var p = document.createElement("p");
+p.appendChild(
+ document.createTextNode("This is the third example")
+);
+p.setAttribute("class", "labrat");
+document.appendChild(p);
+</pre>
+
+<p>
+ The above snippet of code works in all modern browser
families—WebKit, Gecko, and Opera—<em>except</em> for <acronym
title="Internet Explorer">IE</acronym>. So in Internet Explrer, the following
paragraph will have the same font as all regular paragraphs, even though it has
the “labrat” class applied:
+</p>
+
+ <script type="text/javascript" class="js" id="js1">
+var bottle = document.getElementById("bottle");
+var p = document.createElement("p");
+p.setAttribute("class", "labrat");
+p.appendChild(
+ document.createTextNode("This paragraph is created dynamically and appears
with the proper bold-faced red type in virtually all modern browsers except for
Internet Explorer. The paragraph element is created and the text is appended,
but the styles are not properly applied. Why?"));
+
+bottle.appendChild(p);
+ </script>
+
+ <p>
+ After a little investigating, the cause is <acronym
title="Internet Explorer">IE</acronym>’s implementation of the
<code>setAttribute</code> and <code>createElement</code> methods. Take a look
at the following code, which is used to create the following paragraph…
+ </p>
+
+ <script type="text/javascript" class="js" id="js2">
+
+ // create and append the paragraph to the document
+ var p2 = document.createElement("p");
+ p2.appendChild(
+ document.createTextNode(
+ "This is another dynamically created paragraph.")
+ );
+ p2.setAttribute("class", "labrat");
+ var bottle = document.getElementById("bottle");
+ bottle.appendChild(p2);
+
+ // use fvlogger to log all attributes to the document
+ var i = 0; var attrs = p.attributes;
+ for (i = 0; i < attrs.length; i++) {
+ debug("attribute #" + i + ": " +
+ attrs[i].name + "=" + attrs[i].value);
+ }
+
+ // display a summary of attrs length
+ if (i == 0) { error("new element has no attributes"); }
+ else { info("p has " + i + " attribute(s)"); }
+
+ // the code is mirrored below for display purposes
+ </script>
+
+ <pre id="listing2">// create and append the paragraph to the document
+var p2 = document.createElement("p");
+p2.appendChild(
+ document.createTextNode(
+ "This is another dynamically created paragraph.")
+);
+p2.setAttribute("class", "labrat");
+var bottle = document.getElementById("bottle");
+bottle.appendChild(p2);
+
+// use fvlogger to log all attributes to the document
+var i = 0; var attrs = p2.attributes;
+for (i = 0; i < attrs.length; i++) {
+ debug("attribute #" + i + ": " +
+ attrs[i].name + "=" + attrs[i].value);
+}
+
+// display a summary of attrs length
+if (i == 0) { error("new element has no attributes"); }
+else { info("p has " + i + " attribute(s)"); }</pre>
+
+ <p>… and the output that it <a href="#fvlogger" title="Logging
output">produces</a>, shown at the top of the page. In Opera, Mozilla, and
WebKit–based browsers, there are only two logging statements: one debug
statement that shows the class of the element that we created, and the other
indicating the number of attributes belonging to the element. Because we are
only assigning one attribute to the element (its class), the output is exactly
what we would expect it to be: the paragraph has 1 attribute named, not
surprisingly, “labrat”.
+ </p>
+
+ <p>
+ However, Internet Explorer is unique in the way that it creates
elements; instead of having zero attributes (as one would expect) immediately
after creation, new elements inherit all attributes that are defined in
Internet Explorer’s default <acronym title="Document Type
Definition">DTD</acronym>. Thus, instead of our new element having only
<em>one</em> attribute after setting its <code>class</code>, it actually has 84!
+ </p>
+
+ <p>
+ But what’s <em>equally</em> as odd is that when
attempting to set the <code>class</code> of a new element through its
<code>setAttribute()</code> method, <acronym title="Internet
Explorer">IE</acronym> will actually create <em>another</em> attribute node
instead of replacing the value of the existing <code>class</code> attribute.
Thus, we end up with two <code>class</code> attributes instead of one
(attributes #3 and #83 in the log statements shown at the <a href="#fvlogger"
title="Log Statements">top</a> of the page when viewed with <acronym
title="Internet Explorer">IE</acronym>).
+ </p>
+
+ <h2>The Solution</h2>
+ <p>
+ Luckily, there is, a relatively simple fix <acronym
title="Internet Explorer">IE</acronym>’s problem: instead of simply
setting the value of an attribute based on its name, we can loop through all
existing attributes until we find the one that we’re looking for and set
its value based on its numeric index in the node’s
<code>attributes[]</code> array. The following snippet of JavaScript will get
the job done:
+ </p>
+
+ <pre>
+// if the node’s class already exists, then replace its value
+if (p.getAttributeNode("class")) {
+ for (var i = 0; i < p.attributes.length; i++) {
+ if (p.attributes[i].name.toUpperCase() == 'CLASS') {
+ p.attributes[i].value = className;
+ }
+ }
+// otherwise create a new attribute
+} else {
+ p.setAttribute("class", LOG_CLASSES[level]);
+}
+ </pre>
+
+ <p>
+ This example illustrates how logging can aid in developing
JavaScripts that work in <em>all</em> browsers.
+ </p>
+
+</div>
+
+</body>
+</html>
Propchange: trunk/phenomenon/js/fvlogger/index.html
------------------------------------------------------------------------------
svn:executable = *
Added: trunk/phenomenon/js/fvlogger/info.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/info.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/info.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/fvlogger/logger.css
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/logger.css&rev=2&repname=user%3a+ranger>
==============================================================================
--- trunk/phenomenon/js/fvlogger/logger.css (added)
+++ trunk/phenomenon/js/fvlogger/logger.css Sun May 7 20:14:05 2006
@@ -1,0 +1,86 @@
+/*
+ fvlogger styles
+ (c) 2005 davidfmiller
+ http://www.fivevoltlogic.com/code/fvlogger/
+
+ note: this stylesheet is designed to work with the stock configuration of
+ the fvlogger.js file; changes made there may or may not lead to
+ changing this file as well.
+
+ history:
+ v0.1 February 3, 2005
+ - basics in place
+*/
+
+#fvlogger {
+ border: 1px solid #ddd;
+ padding: 8px;
+ background-color: #fafafa;
+}
+
+#fvlogger * {
+ background-repeat: no-repeat;
+ font-size: 9pt;
+ text-transform: lowercase;
+}
+
+#fvlogger h6 {
+ font-weight: bold;
+}
+
+#fvlogger p, #fvlogger h6, #fvlogger ul {
+ margin: 0;
+ padding: 0;
+ text-align: left;
+}
+
+#fvlogger dl {
+ padding-bottom: 4px;
+ border-bottom: 1px solid #eee;
+ margin-bottom: 4px;
+}
+
+#fvlogger dl dt:after {
+ content: " :";
+}
+
+#fvlogger dl dt, #fvlogger dl dd {
+ padding: 0;
+ margin: 0 4px 0 0;
+ display: inline;
+}
+
+#fvlogger dl dt {
+ font-weight: bold;
+ background-image: url(magnet.png);
+ min-height: 18px;
+ padding-left: 20px;
+ float: left;
+}
+
+#fvlogger dl dd {
+
+}
+
+#fvlogger a { font-weight: bold;}
+#fvlogger p {
+ padding-left: 20px;
+ background-position: top left;
+ line-height: 1.4em;
+}
+
+#fvlogger dd.debug a { color: #0CCD14; }
+#fvlogger dd.info a { color: #0082C6; }
+#fvlogger dd.warn a { color: #E9C000; }
+#fvlogger dd.error a { color: #EE0000; }
+#fvlogger dd.fatal a { color: #444; }
+
+#fvlogger p.debug, #fvlogger p.info, #fvlogger p.warn, #fvlogger p.error {
+
+}
+
+#fvlogger p.debug { background-image: url(debug.png); color: #0CCD14;
font-weight: bold; }
+#fvlogger p.info { background-image: url(info.png); color: #0066B3;
font-weight: bold; }
+#fvlogger p.warn { background-image: url(warn.png); color: #E9C000;
font-weight: bold; }
+#fvlogger p.error { background-image: url(error.png); color: #EE0000;
font-weight: bold; }
+#fvlogger p.fatal { background-image: url(fatal.png); color: #656565;
font-weight: bold; }
Added: trunk/phenomenon/js/fvlogger/logger.js
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/logger.js&rev=2&repname=user%3a+ranger>
==============================================================================
--- trunk/phenomenon/js/fvlogger/logger.js (added)
+++ trunk/phenomenon/js/fvlogger/logger.js Sun May 7 20:14:05 2006
@@ -1,0 +1,180 @@
+/*
+ fvlogger v1.0
+ (c) 2005 davidfmiller
+ http://www.fivevoltlogic.com/code/fvlogger/
+ see readme.txt for documentation
+*/
+
+// version number
+var FVLOGGER_VERSION = '1.0';
+
+// turn logging on or off;
+var FVL_LOG_ON = true;
+
+// all logging statements that whose level is greater than or equal to
FVL_DEFAULT_LOG_LEVEL will be processed;
+// all others will be ignored
+var FVL_DEFAULT_LOG_LEVEL = FVL_DEBUG;
+
+// the id of the node that will have the logging statements appended to it
+var FVL_LOG_ID = 'fvlogger';
+
+// the element that should be wrapped around the log messages
+var FVL_LOG_ELEMENT = 'p';
+
+/* the code that follows is */
+
+// constants for logging levels
+var FVL_DEBUG = 0;
+var FVL_INFO = 1;
+var FVL_WARN = 2;
+var FVL_ERROR = 3;
+var FVL_FATAL = 4;
+
+// the css classes that will be applied to the logging elements
+var FVL_LOG_CLASSES = new Array("debug","info","warn","error","fatal");
+
+/* */
+
+// retrieves the element whose id is equal to FVL_LOG_ID
+function getLogger(id) {
+ if (arguments.length == 0) { id = FVL_LOG_ID; }
+ return document.getElementById(id);
+}
+
+function showDebug() { FVL_showMessages(FVL_DEBUG); }
+function showInfo() { FVL_showMessages(FVL_INFO); }
+function showWarn() { FVL_showMessages(FVL_WARN); }
+function showError() { FVL_showMessages(FVL_ERROR); }
+function showFatal() { FVL_showMessages(FVL_FATAL); }
+function showAll() { FVL_showMessages(); }
+
+// removes all logging information from the logging element
+function eraseLog(ask) {
+ var debug = getLogger();
+ if (! debug) { return false; }
+
+ if (ask && ! confirm("Are you sure you wish to erase the log?")) {
+ return false;
+ }
+
+ var ps = debug.getElementsByTagName(FVL_LOG_ELEMENT);
+ var length = ps.length;
+ for (var i = 0; i < length; i++) { debug.removeChild(ps[length - i -
1]); }
+ return true;
+}
+
+function debug(message) { FVL_log("" + message, FVL_DEBUG); }
+function warn(message) { FVL_log("" + message, FVL_WARN); }
+function info(message) { FVL_log("" + message, FVL_INFO); }
+function error(message) { FVL_log("" + message, FVL_ERROR);}
+//function fatal(message) { FVL_log("" + message, FVL_FATAL);}
+
+function windowError(message, url, line) {
+ FVL_log('Error on line ' + line + ' of document ' + url + ': ' +
message, FVL_FATAL);
+ return true; //
+}
+
+// only override the window's error handler if we logging is turned on
+if (FVL_LOG_ON) {
+ window.onerror = windowError;
+}
+
+//
+function FVL_showMessages(level, hideOthers) {
+
+// alert('showing ' + level);
+
+ var showAll = false;
+ // if no level has been specified, use the default
+ if (arguments.length == 0) { level = FVL_DEFAULT_LOG_LEVEL; showAll =
true; }
+ if (arguments.length < 2) { hideOthers = true; }
+
+ // retrieve the element and current statements
+ var debug = getLogger();
+ if (! debug) { return false; }
+ var ps = debug.getElementsByTagName("p");
+ if (ps.length == 0) { return true; }
+
+ // get the number of nodes in the list
+ var l = ps.length;
+
+ // get the class name for the specified level
+ var lookup = FVL_LOG_CLASSES[level];
+
+ // loop through all logging statements/<p> elements...
+ for (var i = l - 1; i >= 0; i--) {
+
+ // hide all elements by default, if specified
+ if (hideOthers) { hide(ps[i]); }
+
+ // get the class name for this <p>
+ var c = getNodeClass(ps[i]);
+// alert(c);
+// alert("Node #" + i + "'s class is:" + c);
+ if (c && c.indexOf(lookup) > -1 || showAll) { show(ps[i]); }
+ }
+}
+
+// appends a statement to the logging element if the threshold level is
exceeded
+function FVL_log(message, level) {
+
+ // check to make sure logging is turned on
+ if (! FVL_LOG_ON) { return false; }
+
+ // retrieve the infrastructure
+ if (arguments.length == 1) { level = FVL_INFO;}
+ if (level < FVL_DEFAULT_LOG_LEVEL) { return false; }
+ var div = getLogger();
+ if (! div) { return false; }
+
+ // append the statement
+ var p = document.createElement(FVL_LOG_ELEMENT);
+
+ // this is a hack work around a bug in ie
+ if (p.getAttributeNode("class")) {
+ for (var i = 0; i < p.attributes.length; i++) {
+ if (p.attributes[i].name.toUpperCase() == 'CLASS') {
+ p.attributes[i].value = FVL_LOG_CLASSES[level];
+ }
+ }
+ } else {
+ p.setAttribute("class", FVL_LOG_CLASSES[level]);
+ }
+ var text = document.createTextNode(message);
+ p.appendChild(text);
+ div.appendChild(p);
+ return true;
+}
+
+function exampleLogs() {
+ // describe the four types of logging messages
+ debug('Scatter debug messages throughout your code to provide a
high-level overview of what your code is doing, such as which function is
currently in scope and the values of loop counters.');
+ info('Information messages are the meat and potatoes of logging
messages; sprinkle them around to reveal more detailed information about your
script\'s execution, such as the values of variables and function/method return
values.');
+ warn('Warning messages are used to indicate potentially hazardous
situations, such as missing function arguments...');
+ error('While error messages are used to indicate that something bad is
about to happen; note that these kinds of errors are considered to be run-time
errors, which are a different type of beast from the parse errors mentioned
below.');
+
+// generate an error to demonstrate the fatal error in ie and mozilla browsers
+ a
+}
+
+// show a node
+function show(target) {
+ target.style.display = "";
+ return true;
+}
+
+// hide a node
+function hide(target) {
+ target.style.display = "none";
+ return true;
+}
+
+// returns the class attribute of a node
+function getNodeClass(obj) {
+ var result = false;
+
+ if (obj.getAttributeNode("class")) {
+ result = obj.attributes.getNamedItem("class").value;
+ }
+ return result;
+}
Added: trunk/phenomenon/js/fvlogger/magnet.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/magnet.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/magnet.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/fvlogger/readme.txt
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/readme.txt&rev=2&repname=user%3a+ranger>
==============================================================================
--- trunk/phenomenon/js/fvlogger/readme.txt (added)
+++ trunk/phenomenon/js/fvlogger/readme.txt Sun May 7 20:14:05 2006
@@ -1,0 +1,5 @@
+fvlogger
+(c) 2005 davidfmiller
+http://www.fivevoltlogic.com/code/log4js
+
+http://www.mojavelinux.com/blog/archives/2005/01/javascript_logging_via_meta/
Added: trunk/phenomenon/js/fvlogger/warn.png
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/fvlogger/warn.png&rev=2&repname=user%3a+ranger>
==============================================================================
Binary file - no diff available.
Propchange: trunk/phenomenon/js/fvlogger/warn.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/phenomenon/js/phenomenon.js
URL:
<http://svn.finkproject.org/websvn/filedetails.php?path=/trunk/phenomenon/js/phenomenon.js&rev=2&repname=user%3a+ranger>
==============================================================================
--- trunk/phenomenon/js/phenomenon.js (added)
+++ trunk/phenomenon/js/phenomenon.js Sun May 7 20:14:05 2006
@@ -1,0 +1,184 @@
+function RRStats(idname)
+{
+ info("RRStats() instantiated");
+ if (!idname)
+ idname = "phenomenon";
+
+ this.injectImg = function()
+ {
+ debug("injectImg called")
+ if (document.getElementById && document.getElementById(idname))
+ {
+ document.getElementById(idname).innerHTML =
this.getImg();
+ }
+ else
+ {
+ error("couldn't find the stats element!");
+ }
+ }
+
+ this.getImg = function()
+ {
+ debug("getImg() called");
+ var retArray = this.getData();
+ var retval = "<img src=\"testimg.gif?" + serialize(retArray) +
"\" width=\"1\" height=\"1\" alt=\"\" />";
+ info(retval);
+ return retval;
+ }
+
+ this.getData = function()
+ {
+ debug("getData() called");
+ var data = new Array();
+
+ var items = new Array(new PageInfo(), new BrowserInfo(), new
MetaInfo());
+
+ for (var itemkey in items)
+ {
+ var item = items[itemkey];
+ var itemAsArray = item.asArray();
+ var classname = getObjectClass(item);
+
+ debug("class name = " + classname);
+
+ for (var key in itemAsArray)
+ {
+ if (itemAsArray[key])
+ data[classname + "." + key] =
itemAsArray[key];
+ }
+
+ }
+
+ return data;
+ }
+}
+
+function serialize(array)
+{
+ var ret = new Array();
+ for (var key in array)
+ {
+ ret.push(escape(key) + "=" + escape(array[key]));
+ }
+
+ return ret.join("&");
+}
+
+function MetaInfo()
+{
+ var _meta;
+
+ this.init = function()
+ {
+ var returnval = new Array();
+ metas = document.getElementsByTagName("meta");
+ for (var i = 0; i < metas.length; i++)
+ {
+ var m = metas[i];
+ if (m && !m.httpEquiv)
+ {
+ if (m.name && m.content)
+ {
+ returnval[m.name] = m.content;
+ }
+ }
+ }
+ this._meta = returnval;
+ }
+
+ this.asArray = function()
+ {
+ return this._meta;
+ }
+
+ this.init();
+}
+
+function PageInfo()
+{
+ var _referrer;
+ var _href;
+ var _page;
+ var _keywords;
+
+ this.setReferrer = function(ref) { this._referrer = ref; }
+ this.getReferrer = function() { return this._referrer; }
+ this.setHref = function(href) { this._href = href; }
+ this.getHref = function() { return this._href; }
+ this.setPage = function(page) { this._page = page; }
+ this.getPage = function() { return this._page; }
+ this.setKeywords = function(keywords) { this._keywords = keywords; }
+ this.getKeywords = function() { return this._keywords; }
+
+ this.asArray = function()
+ {
+ var returnval = new Array();
+
+ returnval["referrer"] = this.getReferrer();
+ returnval["href"] = this.getHref();
+ returnval["page"] = this.getPage();
+ returnval["keywords"] = this.getKeywords();
+
+ return returnval;
+ }
+
+ this._referrer = document.referrer;
+ this._href = document.location.href;
+}
+
+function BrowserInfo()
+{
+ var _width = 0;
+ var _height = 0;
+
+ this.setWidth = function(width) { this._width = width; }
+ this.getWidth = function() { return this._width; }
+ this.setHeight = function(height) { this._height = height; }
+ this.getHeight = function() { return this._height; }
+
+ this.asArray = function()
+ {
+ var returnval = new Array();
+
+ returnval["height"] = this.getHeight();
+ returnval["width"] = this.getWidth();
+
+ return returnval;
+ }
+
+ if( typeof( window.innerWidth ) == 'number' )
+ {
+ debug("non-IE");
+ this.setWidth(window.innerWidth);
+ this.setHeight(window.innerHeight);
+ }
+ else if( document.documentElement && (
document.documentElement.clientWidth || document.documentElement.clientHeight )
)
+ {
+ debug("IE 6+ in standards-compliant mode");
+ this.setWidth(document.documentElement.clientWidth);
+ this.setHeight(document.documentElement.clientHeight);
+ }
+ else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) )
+ {
+ debug("IE 4 compatible");
+ this.setWidth(document.body.clientWidth);
+ this.setHeight(document.body.clientHeight);
+ }
+
+}
+
+/* Returns the class of the argument or undefined if it's not a valid
JavaScript
+ object.
+*/
+function getObjectClass(obj)
+{
+ if (obj && obj.constructor && obj.constructor.toString)
+ {
+ var arr = obj.constructor.toString().match(/function\s*(\w+)/);
+ return arr && arr.length == 2 ? arr[1] : undefined;
+ }
+ else
+ {
+ return undefined;
+ }
+}
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits