Changeset 1073 for trunk


Ignore:
Timestamp:
02/15/13 14:46:51 (12 years ago)
Author:
pharms
Message:
  • corrected event handling for default events under jQuery
  • corrected index of logged GUI elements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js

    r1069 r1073  
    7272    //{ "tag": "bdo", "actions": [  ] }, 
    7373    //{ "tag": "blockquote", "actions": [  ] }, 
    74     { "tag": "body", "actions": [ "onbeforeunload", 
    75                                   "onload", 
    76                                   "onunload", 
    77                                   //"onerror", 
    78                                   "onscroll", 
     74    { "tag": "body", "actions": [ "onclick", 
    7975                                  "onpagehide", 
    8076                                  "onpageshow", 
     77                                  "onscroll", 
    8178                                  "onundo" ] }, 
    8279    { "tag": "button", "actions": [ "onclick", 
     
    206203var autoquestDoLog = false; 
    207204 
    208 /*var matchedTags = ["A", "ABBR", "ACRONYM", "ADDRESS", "AREA", "B", "BIG", "BLOCKQUOTE", "BODY", 
    209                    "BUTTON", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP", "DD", "DEL", 
    210                    "DFN", "DIR", "DIV", "DL", "DT", "EM", "FIELDSET", "FORM", "H1", "H2", "H3", 
    211                    "H4", "H5", "H6", "HR", "I", "IMG", "INPUT", "INS", "KBD", "LABEL", "LEGEND", 
    212                    "LI", "LINK", "MAP", "MENU", "NOFRAMES", "NOSCRIPT", "OBJECT", "OL", 
    213                    "OPTGROUP", "OPTION", "P", "PRE", "Q", "S", "SAMP", "SELECT", "SMALL", "SPAN", 
    214                    "STRIKE", "STRONG", "SUB", "SUP", "TABLE", "TBODY", "TD", "TEXTAREA", "TFOOT", 
    215                    "TH", "THEAD", "TR", "TT", "U", "UL", "VAR"];*/ 
    216 /*var actions = ['onclick', 'ondblclick', 'onkeypress', 'onkeydown', 'onkeyup', 
    217 'onmouseout' , 'onmousemove' ,'onfocus','onscroll'];  // edit*/ 
    218  
    219205/** 
    220206 * stores the structure of the GUI of the current page 
     
    254240            autoquestGUIModel = 
    255241                addEventHandlingAndGetJSONRepresentation(document.documentElement, ""); 
     242             
     243            addDefaultEventHandling(); 
    256244             
    257245            // recall sending data each 100 seconds to ensure, that for browser windows staying 
     
    394382    var tagName = getTagName(node); 
    395383    var action; 
    396     var parameters; 
    397384    var i; 
    398385    var k; 
     
    408395                } 
    409396                else { 
    410                     parameters = { action : action, path : nodePath}; 
    411                     if (jQuery(node).on) { 
    412                         jQuery(node).on(action.substring(2), parameters, handleJQueryEvent); 
    413                     } 
    414                     else { 
    415                         jQuery(node).bind(action.substring(2), parameters, handleJQueryEvent); 
    416                     } 
     397                    registerEventHandler(node, nodePath, action); 
    417398                } 
    418399            } 
     
    423404/** 
    424405 * adapts the event handling attributed provided by the action parameter so that it calls 
    425  * the {@link #handleEvent(node, action, path, even)} function in the case the event occurs. 
     406 * the {@link #handleEvent(node, action, path, event)} function in the case the event occurs. 
    426407 * Either the method creates an appropriate onxxx attribute on the node if there is none, or it 
    427408 * adds a call to the function as first thing called by the onxxx attribute. 
    428409 *  
    429410 * @param node     the node of the DOM structure that shall be equipped with event handling 
    430  * @param nodePath the path to node within the DOM-structure of the HTML-site 
     411 * @param nodePath the path to the node within the DOM-structure of the HTML-site 
    431412 * @param action   the event for which event handling shall be enabled 
    432413 */ 
     
    443424            node.setAttribute(action, value + ' ' + oldValue); 
    444425        } 
     426    } 
     427} 
     428 
     429/** 
     430 * registers an event handler using jQuery for the provided action on the given object so that it 
     431 * calls the {@link #handleJQueryEvent(event)} function in the case the event occurs. 
     432 *  
     433 * @param node     the node of the DOM structure that shall be equipped with event handling 
     434 * @param nodePath the path to the node within the DOM-structure of the HTML-site 
     435 * @param action   the event for which event handling shall be enabled 
     436 */ 
     437function registerEventHandler(node, nodePath, action) { 
     438    var parameters = { action : action, path : nodePath}; 
     439    if (jQuery(node).on) { 
     440        jQuery(node).on(action.substring(2), parameters, handleJQueryEvent); 
     441    } 
     442    else { 
     443        jQuery(node).bind(action.substring(2), parameters, handleJQueryEvent); 
     444    } 
     445} 
     446 
     447/** 
     448 * adds default event handling functionality for receiving load, unload, and other document 
     449 * relevant events. The registration for events is done depending on the availability of jQuery. 
     450 * If jQuery is available and must therefore be used, then the registration is done on the window 
     451 * object. Otherwise, the appropriate attributes of the document's body tag are changed 
     452 */ 
     453function addDefaultEventHandling() { 
     454    var body; 
     455 
     456    if (typeof jQuery === 'undefined') { 
     457        body = document.getElementsByTagName("body").item(0); 
     458        adaptEventHandlingAttribute(body, "/html[0]/body[0]", "onbeforeunload"); 
     459        adaptEventHandlingAttribute(body, "/html[0]/body[0]", "onload"); 
     460        adaptEventHandlingAttribute(body, "/html[0]/body[0]", "onunload"); 
     461        //adaptEventHandlingAttribute(body, "/html[0]/body[0]", "onerror"); 
     462    } 
     463    else { 
     464        registerEventHandler(window, "/html[0]/body[0]", "onbeforeunload"); 
     465        registerEventHandler(window, "/html[0]/body[0]", "onload"); 
     466        registerEventHandler(window, "/html[0]/body[0]", "onunload"); 
     467        //registerEventHandler(body, "/html[0]/body[0]", "onerror"); 
    445468    } 
    446469} 
     
    626649        for (i = 0; i < node.parentNode.childNodes.length; i++) { 
    627650            if (node.parentNode.childNodes[i].tagName === node.tagName) { 
    628                 index++; 
    629651                // if === also returns true if the nodes are not identical but only equal, 
    630652                // this may fail. 
     
    632654                    break; 
    633655                } 
     656                index++; 
    634657            } 
    635658        } 
Note: See TracChangeset for help on using the changeset viewer.