//$Id$ // // < Navigators: /* * Reset view. * Resets current to point at the root. * @return {node} current node. */ ADom.prototype.reset = function() { this.root_ = this.document_.documentElement; return this.current_ = this.root_; }; /* * next: Move to next sibling. * @return {node} current node. */ ADom.prototype.next = function() { return this.current_ = this.current_.nextSibling; }; /* * previous: Move to previous sibling. * @return {node} current node. */ ADom.prototype.previous = function() { return this.current_ = this.current_.previousSibling; }; /* * up: Move to parent. * @return {node} current node. */ ADom.prototype.up = function() { return this.current_ = this.parentNode; }; /* * down: Move to first child * @return {node} current node. */ ADom.prototype.down = function() { return this.current_ = this.current_.firstChild; }; /* * first: Move to first sibling * @return {node} current node. */ ADom.prototype.first = function() { return this.current_ = this.current_.parentNode.firstChild; }; /* * last: Move to last sibling. * @return {node} current node. */ ADom.prototype.last = function() { return this.current_ = this.current_.parentNode.lastChild; }; /* * Move to document body * @return {node} current node. */ ADom.prototype.body = function() { return this.current_ = this.document_.body; }; /* * Move to element identified by id * @return {node} current node. */ ADom.prototype.selectId = function(elementId) { return this.current_ = this.document_.getElementById(elementId); }; // > // \n'; }; /* * Return HTML for current node. * Produces a if optional boolean flag gen_base is true. *@Return {string}; HTML */ ADom.prototype.html = function(gen_base) { var html = ''; if (gen_base) { html += this.base(); } html += '<' + this.current_.tagName; if (this.current_.value !== undefined) { html += ' value' + '='; html += '\"' + this.current_.value + '\"\n'; } var map = this.current_.attributes; if (map instanceof NamedNodeMap) { for (var i = 0; i < map.length; i++) { html += ' ' + map[i].name + '='; html += '\"' + map[i].value + '\"\n'; } } if (this.current_.childNodes.length === 0) { return html += '/>\n'; } else { html += '>\n' + this.current_.innerHTML; html += '\n'; return html; } }; /* * summarize: Summarize current node. * @Return {string}; */ ADom.prototype.summarize = function() { var summary = this.current_.tagName + ' '; summary += 'has ' + this.current_.childNodes.length + 'children '; summary += ' with ' + this.current_.innerHTML.length + ' bytes of content.'; return summary; }; /* * title: return document title * @Return {string} */ ADom.prototype.title = function() { return this.document_.title; }; /* * url: Return base URL of document. * @return {String} url */ ADom.prototype.url = function() { return this.document_.baseURI; }; /* * Return document being viewed. */ ADom.prototype.document = function() { return this.document_; }; /* * Return root of document being viewed. */ ADom.prototype.root = function() { return this.root_; }; /* * Return the current node being viewed. */ ADom.prototype.current = function() { return this.current_; }; // > // // // // // < Eventing: /* * target: Return a suitable target for sending keypresses * We need to know where the focus is, * for now, we depend on Fire Vox doing the work for us. * Uses Fire Vox global CLC_SR_CurrentAtomicObject * that gets set by Fire Vox whenever a focus event occurs. * If that variable is 0 i.e. unset, * we return document.body * @Return: Node */ ADom.prototype.target = function() { if (!CLC_SR_CurrentAtomicObject){ CLC_SR_CurrentAtomicObject = CLC_GetFirstAtomicObject(CLC_Window().document.body); } return CLC_SR_CurrentAtomicObject || this.document_.body; }; /** * Dispatches a left click event on the element that is the targetNode. * @param {Node} targetNode The target node of this operation. * @return {Null} */ ADom.prototype.click = function(targetNode){ var evt = document.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); targetNode.dispatchEvent(evt); }; /* * send a key */ ADom.prototype.keyPress = function(targetNode, theKey, holdCtrl, holdAlt, holdShift){ var keyCode = 0; var charCode = 0; if (theKey == 'ENTER'){ keyCode = 13; } else if (theKey == 'TAB'){ keyCode = 9; } else if (theKey.length == 1){ charCode = theKey.charCodeAt(0); keyCode = charCode; } var evt = document.createEvent('KeyboardEvent'); evt.initKeyEvent('keypress', true, true, this.document_.defaultView, holdCtrl, holdAlt, holdShift, false, keyCode, charCode); targetNode.dispatchEvent(evt); }; /* * send a key down */ ADom.prototype.keyDown = function(targetNode, theKey, holdCtrl, holdAlt, holdShift){ var keyCode = 0; var charCode = 0; if (theKey == 'ENTER'){ keyCode = 13; } else if (theKey == 'TAB'){ keyCode = 9; } else if (theKey.length == 1){ charCode = theKey.charCodeAt(0); } var evt = document.createEvent('KeyboardEvent'); evt.initKeyEvent('keydown', true, true, null, holdCtrl, holdAlt, holdShift, false, keyCode, charCode); targetNode.dispatchEvent(evt); }; /* * send a key up */ ADom.prototype.keyUp = function(targetNode, theKey, holdCtrl, holdAlt, holdShift){ var keyCode = 0; var charCode = 0; if (theKey == 'ENTER'){ keyCode = 13; } else if (theKey == 'TAB'){ keyCode = 9; } else if (theKey.length == 1){ charCode = theKey.charCodeAt(0); } var evt = document.createEvent('KeyboardEvent'); evt.initKeyEvent('keyup', true, true, null, holdCtrl, holdAlt, holdShift, false, keyCode, charCode); targetNode.dispatchEvent(evt); }; // > // < A11y Reflection: // > // // //