<commit_before>###
scraperwiki.js
Copyright (c) 2013 ScraperWiki Limited
ScraperWiki tool client library. See
http://x.scraperwiki.com/docs

jQuery is required.
###

# Can use short sw.tool.thing() or long scraperwiki.tool.thing()
scraperwiki = sw = { tool: {} }

scraperwiki.boxName = window.location.pathname.split('/')[1]

# Call container iframe's API
scraperwiki.tool.redirect = (location) ->
  parent.scraperwiki.xdm.redirect(location)

scraperwiki.tool.getURL = (cb) ->
  parent.scraperwiki.xdm.getURL(cb)

scraperwiki.tool.rename = (name) ->
  parent.scraperwiki.xdm.rename(scraperwiki.boxName, name)

scraperwiki.exec = (cmd, success, error) ->
  settings = scraperwiki.readSettings()
  options =
    url: "#{window.location.protocol}//#{window.location.host}/#{scraperwiki.boxName}/exec"
    type: "POST"
    data:
      apikey: settings.source.apikey
      cmd: cmd
  if success?
    options.success = success
  if error?
    options.error = error
  $.ajax options

scraperwiki.sql = (sql, success, error) ->
  settings = scraperwiki.readSettings()
  # Points to the dataset box, when used from either the dataset or a view.
  boxSettings = settings.target ? settings.source
  options =
    url: "#{boxSettings.url}/sql/"
    type: "GET"
    dataType: "json"
    data:
      q: sql
  if success?
    options.success = success
  if error?
    options.error = error
  $.ajax options

scraperwiki.readSettings = ->
  return null if window.location.hash is ''
  hash = window.location.hash.substr(1)
  try
    settings = JSON.parse decodeURIComponent(hash)
  catch e
    return null
  return settings

scraperwiki.alert = (title, message, level=0) ->
  # [title] and [message] should be html strings. The first is displayed in bold.
  # If [level] is a truthful value, the alert is printed in red.
  $a = $('<div>').addClass('alert').prependTo('body')
  $a.addClass('alert-error') if level
  $a.html """<button type="button" class="close" data-dismiss="alert">×</button> <strong>#{title}</strong> #{message}"""<commit_msg>use &times; html entity in alert function<commit_after>###
scraperwiki.js
Copyright (c) 2013 ScraperWiki Limited
ScraperWiki tool client library. See
http://x.scraperwiki.com/docs

jQuery is required.
###

# Can use short sw.tool.thing() or long scraperwiki.tool.thing()
scraperwiki = sw = { tool: {} }

scraperwiki.boxName = window.location.pathname.split('/')[1]

# Call container iframe's API
scraperwiki.tool.redirect = (location) ->
  parent.scraperwiki.xdm.redirect(location)

scraperwiki.tool.getURL = (cb) ->
  parent.scraperwiki.xdm.getURL(cb)

scraperwiki.tool.rename = (name) ->
  parent.scraperwiki.xdm.rename(scraperwiki.boxName, name)

scraperwiki.exec = (cmd, success, error) ->
  settings = scraperwiki.readSettings()
  options =
    url: "#{window.location.protocol}//#{window.location.host}/#{scraperwiki.boxName}/exec"
    type: "POST"
    data:
      apikey: settings.source.apikey
      cmd: cmd
  if success?
    options.success = success
  if error?
    options.error = error
  $.ajax options

scraperwiki.sql = (sql, success, error) ->
  settings = scraperwiki.readSettings()
  # Points to the dataset box, when used from either the dataset or a view.
  boxSettings = settings.target ? settings.source
  options =
    url: "#{boxSettings.url}/sql/"
    type: "GET"
    dataType: "json"
    data:
      q: sql
  if success?
    options.success = success
  if error?
    options.error = error
  $.ajax options

scraperwiki.readSettings = ->
  return null if window.location.hash is ''
  hash = window.location.hash.substr(1)
  try
    settings = JSON.parse decodeURIComponent(hash)
  catch e
    return null
  return settings

scraperwiki.alert = (title, message, level=0) ->
  # [title] and [message] should be html strings. The first is displayed in bold.
  # If [level] is a truthful value, the alert is printed in red.
  $a = $('<div>').addClass('alert').prependTo('body')
  $a.addClass('alert-error') if level
  $a.html """<button type="button" class="close" data-dismiss="alert">&times;</button> <strong>#{title}</strong> #{message}"""
{'fraction_non_alphanumeric': 0.1390518084066471, 'fraction_numerical': 0.003421309872922776, 'mean_word_length': 3.7759626604434073, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '1053915', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1372, 'n_words': 345}