Repository: tapestry-5 Updated Branches: refs/heads/5.4.x 3454e291b -> a86beb205
TAP5-2225: fix and clean up implementation Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a86beb20 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a86beb20 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a86beb20 Branch: refs/heads/5.4.x Commit: a86beb205f689fe163f0c75f64b72360f958eac0 Parents: 3454e29 Author: Jochen Kemnade <jkemn...@apache.org> Authored: Tue Mar 21 09:45:24 2017 +0100 Committer: Jochen Kemnade <jkemn...@apache.org> Committed: Tue Mar 21 10:25:41 2017 +0100 ---------------------------------------------------------------------- .../org/apache/tapestry5/t5-core-dom.coffee | 56 ++++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a86beb20/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee index 1f07d96..97b2a06 100644 --- a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee +++ b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee @@ -874,6 +874,22 @@ define ["underscore", "./utils", "./events", "jquery"], return element + # Returns the value of a given data attribute as an object. + # The "data-" prefix is added automatically. + # element - (object) HTML dom element + # attribute - (string) name of the data attribute without the "data-" prefix. + getDataAttributeAsObject = (element, attribute) -> + +#if jquery + value = $(element).data(attribute) +#elseif prototype + value = JSON.parse($(element).readAttribute('data-' + attribute)) + if value isnt null + value = JSON.parse(value) + else + value = {} +#endif + _.extend exports, wrap: wrapElement @@ -906,65 +922,49 @@ define ["underscore", "./utils", "./events", "jquery"], events = utils.split events #endif onevent elements, events, match, handler - + # Returns the URL of a component event based on its name and an optional element # or null if the event information is not found. When the element isn't passed # or it's null, the event data is taken from the <body> element. # # * eventName - (string) name of the component event - # * element - (object) HTML DOM element to be used as the begining of the event data search. Optional. - getEventUrl = (eventName, element) -> + # * element - (object) HTML DOM element to be used as the beginning of the event data search. Optional. + getEventUrl: (eventName, element) -> if not (eventName?) throw 'dom.getEventUrl: the eventName parameter cannot be null' if not _.isString eventName throw 'dom.getEventUrl: the eventName parameter should be a string' - + eventName = eventName.toLowerCase() - + #if jquery if element instanceof jQuery element = element[0]; -#end - +#endif + if element is null element = document.getElementsByTagName('body')[0] # Look for event data in itself first, then in the preceding siblings # if not found url = null - + while not url? and element.previousElementSibling? data = getDataAttributeAsObject(element, 'component-events') url = data?[eventName]?.url element = element.previousElementSibling if not url? - + # Look at parent elements recursively while not url? and element.parentElement? data = getDataAttributeAsObject(element, 'component-events') url = data?[eventName]?.url element = element.parentElement; - - return url; - - # Returns the value of a given data attribute as an object. - # The "data-" prefix is added automatically. - # element - (object) HTML dom element - # attribute - (string) name of the data attribute without the "data-" prefix. - getDataAttributeAsObject = (element, attribute) -> - -#if jquery - value = $(element).data(attribute) -#elseif prototype - value = JSON.parse($(element).readAttribute('data-' + attribute)) - if value isnt null - value = JSON.parse(value) - else - value = {} -#endif + + return url; # onDocument() is used to add an event handler to the document object; this is used # for global (or default) handlers. @@ -978,7 +978,5 @@ define ["underscore", "./utils", "./events", "jquery"], body: wrapElement document.body scanner: scanner - - getEventUrl : getEventUrl return exports