<commit_before>#
#  Adapter for [jQuery framework](http://jquery.com/).
#  For methods {@see Adapter}
#
class JQueryAdapter extends Adapter
  bind: (element, selector, event, fn) ->
    if selector == null
      jQuery(element).on(event, fn)
    else
      jQuery(element).on(event, selector, fn)

  form_to_json: (selector) ->
    o = {}
    a = jQuery(selector).serializeArray()

    for obj in a
      do(obj) =>
        name = obj["name"]
        value = obj["value"]
        if o[name]
          if !o[name].push
            o[name] = [o[name]]
          else
            o[name].push(value || '')
        else
          o[name] = value || ''
    JSON.stringify(o)

  fire: (element, event, params...) ->
    jQuery(element).trigger(event, params)

  get_property: (event, properties) ->
    for p in properties then jQuery(event.target).attr(p)

  swap: (element, content) ->
    tag = @get_attr(element, 'tagName')
    if tag == "INPUT" || tag == "TEXTAREA"
      jQuery(element).val(content)
    else
      jQuery(element).text(content) #FIXME use text ?

  get_attr: (element, attr) ->
    if attr.indexOf('data') == 0
      attr = attr.substring(5, attr.length)
      jQuery(element).data(attr)
    else
      jQuery(element).prop(attr)

  set_attr: (element, attr, value) ->
    jQuery(element).attr(attr, value)

  append: (element, content) ->
    tag = @get_attr(element, 'tagName')
    if tag == "INPUT" || tag == "TEXTAREA"
      old_val = jQuery(element).val()
      jQuery(element).val("#{old_val}#{content}")
    else
      jQuery(element).append(content)


  prepend: (element, content) ->
    tag = @get_attr(element, 'tagName')<commit_msg>fix when work with attr and data<commit_after>#
#  Adapter for [jQuery framework](http://jquery.com/).
#  For methods {@see Adapter}
#
class JQueryAdapter extends Adapter
  bind: (element, selector, event, fn) ->
    if selector == null
      jQuery(element).on(event, fn)
    else
      jQuery(element).on(event, selector, fn)

  form_to_json: (selector) ->
    o = {}
    a = jQuery(selector).serializeArray()

    for obj in a
      do(obj) =>
        name = obj["name"]
        value = obj["value"]
        if o[name]
          if !o[name].push
            o[name] = [o[name]]
          else
            o[name].push(value || '')
        else
          o[name] = value || ''
    JSON.stringify(o)

  fire: (element, event, params...) ->
    jQuery(element).trigger(event, params)

  get_property: (event, properties) ->
    for p in properties then jQuery(event.target).attr(p)

  swap: (element, content) ->
    tag = @get_attr(element, 'tagName')
    if tag == "INPUT" || tag == "TEXTAREA"
      jQuery(element).val(content)
    else
      jQuery(element).text(content) #FIXME use text ?

  get_attr: (element, attr) ->
    if attr.indexOf('data') == 0
      attr = attr.substring(5, attr.length)
      jQuery(element).data(attr)
    else
      jQuery(element).prop(attr)

  set_attr: (element, attr, value) ->
    if attr.indexOf('data-') == -1
      jQuery(element).attr(attr, value)
    else
      jQuery(element).data(attr.replace("data-", ""), value)

  append: (element, content) ->
    tag = @get_attr(element, 'tagName')
    if tag == "INPUT" || tag == "TEXTAREA"
      old_val = jQuery(element).val()
      jQuery(element).val("#{old_val}#{content}")
    else
      jQuery(element).append(content)


  prepend: (element, content) ->
    tag = @get_attr(element, 'tagName')
{'fraction_non_alphanumeric': 0.16241299303944315, 'fraction_numerical': 0.0014501160092807424, 'mean_word_length': 2.657476139978791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1847544', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1107, 'n_words': 261}