<commit_before># Copyright (C) 2012 Orbeon, Inc.
#
# This program is free software; you can redistribute it and/or modify it under the terms of the
# GNU Lesser General Public License as published by the Free Software Foundation; either version
# 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# The full text of the license is available at http://www.gnu.org/copyleft/lesser.html

AjaxServer = ORBEON.xforms.server.AjaxServer
Controls = ORBEON.xforms.Controls

AjaxServer.Event = (args) ->

    supportedArgs = ->
        form:               object ->
                                if   _.isString args.targetId
                                then Controls.getForm document.getElementById args.targetId
                                else null
        targetId:           string -> null
        value:              string -> null
        eventName:          string -> null
        bubbles:            bool -> null
        cancelable:         bool -> null
        ignoreErrors:       bool -> null
        showProgress:       bool -> true
        progressMessage:    string -> null
        additionalAttribs:  object -> null
        properties:         object -> {}

    # Backward compatibility: support arguments passed as a series of parameters
    if arguments.length > 1
        oldParams = ['form', 'targetId', 'value', 'eventName', 'bubbles', 'cancelable',
                     'ignoreErrors', 'showProgress', 'progressMessage', 'additionalAttribs']
        newArgs = {}
        newArgs[name] = arguments[i] for name, i in oldParams
        args = newArgs

    type = (isType) => (alternative) => (name) =>
        @[name] = if isType args[name] then args[name] else alternative()
    object = type _.isObject
    string = type _.isString
    bool = type _.isBoolean
    setDefault name for name, setDefault of supportedArgs()
    return<commit_msg>New `eventCreated` So listeners can add properties as soon as the event is created<commit_after># Copyright (C) 2012 Orbeon, Inc.
#
# This program is free software; you can redistribute it and/or modify it under the terms of the
# GNU Lesser General Public License as published by the Free Software Foundation; either version
# 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# The full text of the license is available at http://www.gnu.org/copyleft/lesser.html

AjaxServer = ORBEON.xforms.server.AjaxServer
Controls = ORBEON.xforms.Controls

AjaxServer.eventCreated = $.Callbacks()

AjaxServer.Event = (args) ->

    supportedArgs = ->
        form:               object ->
                                if   _.isString args.targetId
                                then Controls.getForm document.getElementById args.targetId
                                else null
        targetId:           string -> null
        value:              string -> null
        eventName:          string -> null
        bubbles:            bool -> null
        cancelable:         bool -> null
        ignoreErrors:       bool -> null
        showProgress:       bool -> true
        progressMessage:    string -> null
        additionalAttribs:  object -> null
        properties:         object -> {}

    # Backward compatibility: support arguments passed as a series of parameters
    if arguments.length > 1
        oldParams = ['form', 'targetId', 'value', 'eventName', 'bubbles', 'cancelable',
                     'ignoreErrors', 'showProgress', 'progressMessage', 'additionalAttribs']
        newArgs = {}
        newArgs[name] = arguments[i] for name, i in oldParams
        args = newArgs

    # Set event properties based on `supportedArgs` defined above
    type = (isType) => (alternative) => (name) =>
        @[name] = if isType args[name] then args[name] else alternative()
    object = type _.isObject
    string = type _.isString
    bool = type _.isBoolean
    setDefault name for name, setDefault of supportedArgs()

    # Notify listeners, given them a chance to, say, add properties to the event
    AjaxServer.eventCreated.fire @
    # Make sure we don't return anything, since this is a constructor
    return
{'fraction_non_alphanumeric': 0.07926167209554831, 'fraction_numerical': 0.0030401737242128123, 'mean_word_length': 2.2666666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4632215', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1128, 'n_words': 461}