Attached is V1 beta of the abstraction library (TestLib), and a page that uses
it.
So far the library provides:
1. Abstraction API for adding event listeners to objects x-browser
(tested on FF2/IE7/Saf3/O9.2 all on Windows platform).
/* TestLib -- Simple Testing Library
Abstracts common browser inconsistencies where the purpose of the test case does not depent on testing the given functionality
*/
// [global scope]
function TestLibrary() { }
// [TestLib scope] addEvent( [in] Object /* HTMLElement / HTMLDocument / Window */,
// [in] String /* event name */,
// [in] FunctionPointer /* JS function pointer variable */,
// [in] Bool /* useCapture (optional)*/ )
TestLibrary.prototype.addEvent = function (ob, name, func, capture)
{
if (!ob || (typeof ob != 'object'))
throw new Error("Call to TestLib.addEvent([ob], name, func, capture): Please provide the object (element, document, window) to which the event should be attached.", "Call to TestLib.addEvent: Please provide the object (element, document, window) to which the event should be attached.");
if (!name || (typeof name != 'string'))
throw new Error("Call to TestLib.addEvent(ob, [name], func, capture): Please provide the name of the event to attach (sans the 'on' prefix). For example: 'click' not 'onclick'.", "Call to TestLib.addEvent(ob, [name], func, capture): Please provide the name of the event to attach (sans the 'on' prefix). For example: 'click' not 'onclick'.");
if (!func || (typeof func != 'function'))
throw new Error("Call to TestLib.addEvent(ob, name, [func], capture): Please provide the function pointer to be called when the event is raised. For example: function () { ... }", "Call to TestLib.addEvent(ob, name, [func], capture): Please provide the function pointer to be called when the event is raised. For example: function () { ... }");
// Param 4 is optional. if specified it will be used--however, some browsers (IE) do not support the capture phase.
if (capture == undefined)
capture = false;
if (document.addEventListener)
return ob.addEventListener(name, func, capture);
else // IE special case
return ob.attachEvent("on" + name, func);
}
var TestLib = new TestLibrary();Title: DOM Events API Test Suite - doubleclick-001
| Row 1, Cell 1 | Row 1, Cell 2 |
| Row 2, Cell 1 | Row 2, Cell 2 |
| Row 3, Cell 1 | Row 3, Cell 2 |
| Row 4, Cell 1 | Row 4, Cell 2 |
| Row 5, Cell 1 | This Value should change as you double click on this table. |