<commit_before>module JsHelper
  def set_element_visible(element, status)
    status ? javascript_show_if_exists(element) : javascript_hide_if_exists(element)
  end

  # replacement for app/views/shared/ajax/_spinner_control.js.erb
  # Turn spinner off
  def set_spinner_off
    'miqSparkleOff();'
  end

  # safe variant of j/escape_javascript that calls .to_s to work with non-string values
  def j_str(value)
    j(value.to_s)
  end

  def javascript_focus(element)
    "$('##{j_str(element)}').focus();".html_safe
  end

  def javascript_prepend_span(element, cls)
    "$('##{j_str(element)}').prepend('#{content_tag(:span, nil, :class => cls)}');".html_safe
  end

  def javascript_highlight(element, status)
    "miqHighlight('##{j_str(element)}', #{j_str(status)});".html_safe
  end

  def javascript_disable_field(element)
    "$('##{j_str(element)}').prop('disabled', true);".html_safe
  end

  def javascript_enable_field(element)
    "$('##{j_str(element)}').prop('disabled', false);".html_safe
  end

  def javascript_show(element)
    "$('##{j_str(element)}').show();".html_safe
  end

  def javascript_hide(element)
    "$('##{j_str(element)}').hide();".html_safe
  end

  def javascript_show_if_exists(element)
    "if (miqDomElementExists('#{j_str(element)}')) #{javascript_show(element)}".html_safe
  end

  def javascript_hide_if_exists(element)
    "if (miqDomElementExists('#{j_str(element)}')) #{javascript_hide(element)}".html_safe
  end

  def jquery_pulsate_element(element)
    "$('##{element}').fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();".html_safe
  end

  def partial_replace(from, partial, locals)
    "$(\"##{h(from)}\").replaceWith(\"#{escape_javascript(render(:partial => partial, :locals => locals))}\");".html_safe
  end

  def javascript_checked(element)
    "if ($('##{j_str(element)}').prop('type') == 'checkbox') {$('##{j_str(element)}').prop('checked', true);}"
      .html_safe
  end

  def javascript_unchecked(element)
    "if ($('##{j_str(element)}').prop('type') == 'checkbox') {$('##{j_str(element)}').prop('checked', false);}"
      .html_safe
  end

  def javascript_update_element(element, content)
    "$('##{element}').html('#{escape_javascript(content)}');"
  end

  def js_build_calendar(options = {})
    skip_days = options[:skip_days].nil? ? 'undefined' : options[:skip_days].to_a.to_json

    <<EOD
ManageIQ.calendar.calDateFrom = #{js_format_date(options[:date_from])};
ManageIQ.calendar.calDateTo = #{js_format_date(options[:date_to])};
ManageIQ.calendar.calSkipDays = #{skip_days};
miqBuildCalendar();
EOD
  end

  def javascript_prologue
    'throw "error";'
  end

  def js_format_date(value)
    value.nil? ? 'undefined' : "new Date('#{value.iso8601}')"
  end
end<commit_msg>Brief method explanation<commit_after>module JsHelper
  def set_element_visible(element, status)
    status ? javascript_show_if_exists(element) : javascript_hide_if_exists(element)
  end

  # replacement for app/views/shared/ajax/_spinner_control.js.erb
  # Turn spinner off
  def set_spinner_off
    'miqSparkleOff();'
  end

  # safe variant of j/escape_javascript that calls .to_s to work with non-string values
  def j_str(value)
    j(value.to_s)
  end

  def javascript_focus(element)
    "$('##{j_str(element)}').focus();".html_safe
  end

  def javascript_prepend_span(element, cls)
    "$('##{j_str(element)}').prepend('#{content_tag(:span, nil, :class => cls)}');".html_safe
  end

  def javascript_highlight(element, status)
    "miqHighlight('##{j_str(element)}', #{j_str(status)});".html_safe
  end

  def javascript_disable_field(element)
    "$('##{j_str(element)}').prop('disabled', true);".html_safe
  end

  def javascript_enable_field(element)
    "$('##{j_str(element)}').prop('disabled', false);".html_safe
  end

  def javascript_show(element)
    "$('##{j_str(element)}').show();".html_safe
  end

  def javascript_hide(element)
    "$('##{j_str(element)}').hide();".html_safe
  end

  def javascript_show_if_exists(element)
    "if (miqDomElementExists('#{j_str(element)}')) #{javascript_show(element)}".html_safe
  end

  def javascript_hide_if_exists(element)
    "if (miqDomElementExists('#{j_str(element)}')) #{javascript_hide(element)}".html_safe
  end

  def jquery_pulsate_element(element)
    "$('##{element}').fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();".html_safe
  end

  def partial_replace(from, partial, locals)
    "$(\"##{h(from)}\").replaceWith(\"#{escape_javascript(render(:partial => partial, :locals => locals))}\");".html_safe
  end

  def javascript_checked(element)
    "if ($('##{j_str(element)}').prop('type') == 'checkbox') {$('##{j_str(element)}').prop('checked', true);}"
      .html_safe
  end

  def javascript_unchecked(element)
    "if ($('##{j_str(element)}').prop('type') == 'checkbox') {$('##{j_str(element)}').prop('checked', false);}"
      .html_safe
  end

  def javascript_update_element(element, content)
    "$('##{element}').html('#{escape_javascript(content)}');"
  end

  def js_build_calendar(options = {})
    skip_days = options[:skip_days].nil? ? 'undefined' : options[:skip_days].to_a.to_json

    <<EOD
ManageIQ.calendar.calDateFrom = #{js_format_date(options[:date_from])};
ManageIQ.calendar.calDateTo = #{js_format_date(options[:date_to])};
ManageIQ.calendar.calSkipDays = #{skip_days};
miqBuildCalendar();
EOD
  end

  # JSONP request access prevention
  def javascript_prologue
    'throw "error";'
  end

  def js_format_date(value)
    value.nil? ? 'undefined' : "new Date('#{value.iso8601}')"
  end
end
{'fraction_non_alphanumeric': 0.18689105403011513, 'fraction_numerical': 0.00141718334809566, 'mean_word_length': 5.489655172413793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6780342', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1965, 'n_words': 301}