<commit_before># CartJS.Data
# Data API for CartJS.
# --------------------

# Reference to the document element.
$document = jQuery(document)

CartJS.Data =

  # Bind the document to listen for data-* API events.
  bind: () ->
    CartJS.Data.bindOrUnbind('on')

  # Unbind listeners for data-* API events.
  unbind: () ->
    CartJS.Data.bindOrUnbind('off')

  # Bind or unbind listeners for Data API events.
  bindOrUnbind: (method) ->
    $document[method]('click', '[data-cart-add]', CartJS.Data.add)
    $document[method]('click', '[data-cart-remove]', CartJS.Data.remove)
    $document[method]('click', '[data-cart-remove-id]', CartJS.Data.removeById)
    $document[method]('change', '[data-cart-toggle]', CartJS.Data.toggle)
    $document[method]('change', '[data-cart-toggle-attribute]', CartJS.Data.toggleAttribute)
    $document[method]('submit', '[data-cart-submit]', CartJS.Data.submit)

  # Handler for [data-cart-add] click events.
  add: (e) ->
    e.preventDefault()
    id = jQuery(e.target).data('cartAdd')
    CartJS.Core.addItem(id)

  # Handler for [data-cart-remove] click events.
  remove: (e) ->
    e.preventDefault()
    line = jQuery(e.target).data('cartRemove')
    CartJS.Core.removeItem(line)

  # Handler for [data-cart-remove-id] click events.
  removeById: (e) ->
    e.preventDefault()
    id = jQuery(e.target).data('cartRemoveId')
    CartJS.Core.removeItemById(id)

  # Handler for [data-cart-toggle] change events.
  toggle: (e) ->
    $input = jQuery(e.target)
    id = $input.attr('data-cart-toggle')
    if $input.is(':checked')
      CartJS.Core.addItem(id)
    else
      CartJS.Core.removeAll(id)

  # Handler for [data-cart-toggle-attribute] change events.
  toggleAttribute: (e) ->
    $input = jQuery(e.target)
    attribute = $input.attr('data-cart-toggle-attribute')
    CartJS.Core.setAttribute(attribute, if $input.is(':checked') then 'Yes' else '')

  # Handle for [data-cart-submit] submit events.
  submit: (e) ->
    e.preventDefault()

    dataArray = jQuery(e.target).serializeArray()

    id = undefined
    quantity = undefined
    properties = {}
    jQuery.each dataArray, (i, item) ->
      if item.name == 'id'
        id = item.value
      else if item.name == 'quantity'
        quantity = item.value
      else
        properties[item.name] = item.value

    CartJS.Core.addItem(id, quantity, CartJS.Utils.unwrapKeys(properties))
<commit_msg>Use .data() methods instead of .attr()<commit_after># CartJS.Data
# Data API for CartJS.
# --------------------

# Reference to the document element.
$document = jQuery(document)

CartJS.Data =

  # Bind the document to listen for data-* API events.
  bind: () ->
    CartJS.Data.bindOrUnbind('on')

  # Unbind listeners for data-* API events.
  unbind: () ->
    CartJS.Data.bindOrUnbind('off')

  # Bind or unbind listeners for Data API events.
  bindOrUnbind: (method) ->
    $document[method]('click', '[data-cart-add]', CartJS.Data.add)
    $document[method]('click', '[data-cart-remove]', CartJS.Data.remove)
    $document[method]('click', '[data-cart-remove-id]', CartJS.Data.removeById)
    $document[method]('change', '[data-cart-toggle]', CartJS.Data.toggle)
    $document[method]('change', '[data-cart-toggle-attribute]', CartJS.Data.toggleAttribute)
    $document[method]('submit', '[data-cart-submit]', CartJS.Data.submit)

  # Handler for [data-cart-add] click events.
  add: (e) ->
    e.preventDefault()
    id = jQuery(e.target).data('cartAdd')
    CartJS.Core.addItem(id)

  # Handler for [data-cart-remove] click events.
  remove: (e) ->
    e.preventDefault()
    line = jQuery(e.target).data('cartRemove')
    CartJS.Core.removeItem(line)

  # Handler for [data-cart-remove-id] click events.
  removeById: (e) ->
    e.preventDefault()
    id = jQuery(e.target).data('cartRemoveId')
    CartJS.Core.removeItemById(id)

  # Handler for [data-cart-toggle] change events.
  toggle: (e) ->
    $input = jQuery(e.target)
    id = $input.data('cartToggle')
    if $input.is(':checked')
      CartJS.Core.addItem(id)
    else
      CartJS.Core.removeAll(id)

  # Handler for [data-cart-toggle-attribute] change events.
  toggleAttribute: (e) ->
    $input = jQuery(e.target)
    attribute = $input.data('cartToggleAttribute')
    CartJS.Core.setAttribute(attribute, if $input.is(':checked') then 'Yes' else '')

  # Handle for [data-cart-submit] submit events.
  submit: (e) ->
    e.preventDefault()

    dataArray = jQuery(e.target).serializeArray()

    id = undefined
    quantity = undefined
    properties = {}
    jQuery.each dataArray, (i, item) ->
      if item.name == 'id'
        id = item.value
      else if item.name == 'quantity'
        quantity = item.value
      else
        properties[item.name] = item.value

    CartJS.Core.addItem(id, quantity, CartJS.Utils.unwrapKeys(properties))

{'fraction_non_alphanumeric': 0.1675642087821044, 'fraction_numerical': 0.0, 'mean_word_length': 3.217467248908297, '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': '2706427', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1582, 'n_words': 331}