You are here

function _hide_submit_get_javascript_settings in Hide submit button 7

Same name and namespace in other branches
  1. 6 hide_submit.module \_hide_submit_get_javascript_settings()

Get javascript code for injection

1 call to _hide_submit_get_javascript_settings()
hide_submit_init in ./hide_submit.module
Implements hook_init().

File

./hide_submit.module, line 349
Hide the submit button after clicked to prevent/reduce duplicate postings.

Code

function _hide_submit_get_javascript_settings() {

  // Set base path for local image, none for external
  $image = _hide_submit_get_image();
  if ($image !== FALSE) {
    $image = url($image) == $image ? $image : base_path() . $image;
    $image = check_url($image);
  }

  // Assemble jQuery selector
  $selector = 'input:submit:not(.' . HIDE_SUBMIT_EXCLUDE_CLASS . ')';
  $selector .= implode("", explode("\r\n", filter_xss_admin(variable_get('hide_submit_attribute_filter', ''))));

  // Prevent known conflicts by using jquery attributes
  if (variable_get('hide_submit_fix_known_conflicts', TRUE)) {

    // Draft module
    if (module_exists('draft')) {
      $selector .= check_plain('[value!=' . t('Save As Draft') . ']');
      if (_hide_submit_debug_on()) {
        drupal_set_message("hide submit: Possible conflict detected and handled - draft module");
      }
    }
  }
  $mode = variable_get('hide_submit_script_mode', HIDE_SUBMIT_MODE_HIDE) == HIDE_SUBMIT_MODE_HIDE ? "hide" : "disable";
  $settings = array(
    'hide_submit' => array(
      'selector' => $selector,
      'mode' => $mode,
      'keypress' => variable_get('hide_submit_keypress', HIDE_SUBMIT_BUTTON_AND_KEY),
      'dbg' => _hide_submit_debug_on(),
    ),
  );

  // Add Message and image only when needed
  if ($mode == 'hide') {
    $settings['hide_submit']['message'] = filter_xss_admin(_hide_submit_clean_for_javascript(_hide_submit_get_message()));
    $settings['hide_submit']['image'] = $image;
  }
  return $settings;
}