function _content_lock_add_unload_js in Content locking (anti-concurrent editing) 7
Same name and namespace in other branches
- 6.2 content_lock.module \_content_lock_add_unload_js()
- 6 content_lock.module \_content_lock_add_unload_js()
- 7.2 content_lock.module \_content_lock_add_unload_js()
1 string reference to '_content_lock_add_unload_js'
- content_lock_form_alter in ./content_lock.module
- Implementation of hook_form_alter().
File
- ./content_lock.module, line 333
- Allows users to lock documents for modification.
Code
function _content_lock_add_unload_js(&$form, $form_state) {
$m = drupal_get_path('module', 'content_lock');
drupal_add_js("{$m}/js/jquery.url.packed.js", array(
'group' => JS_LIBRARY,
));
drupal_add_js("{$m}/js/onUserExit.js", array(
'group' => JS_LIBRARY,
));
drupal_add_js("{$m}/js/content_lock_init.js");
$nid = empty($form['nid']['#value']) ? NULL : $form['nid']['#value'];
$internal_urls = array();
$internal_form_selectors = array();
if (!empty($form['#node_revision']->nid)) {
$nid = $form['#node_revision']->nid;
$internal_urls[] = $form['actions']['cancel']['#href'];
$internal_form_selectors[] = '.confirmation';
}
$internal_urls[] = 'node/' . $nid . '/edit';
$internal_form_selectors[] = 'form.node-form';
$lock = content_lock_fetch_lock($nid);
$token = content_lock_get_release_token($nid);
$settings = array(
'nid' => $nid,
'ajax_key' => $lock->ajax_key,
'token' => $token,
'unload_js_message_enable' => variable_get('content_lock_unload_js_message_enable', TRUE),
'internal_urls' => implode('|', $internal_urls),
'internal_forms' => implode(', ', $internal_form_selectors),
);
if ($settings['unload_js_message_enable']) {
$settings['unload_js_message'] = variable_get('content_lock_unload_js_message', 'If you proceed, ALL of your changes will be lost.');
}
$called =& drupal_static(__FUNCTION__ . '__called');
if (!empty($called)) {
$called++;
return $form;
}
$called = 1;
drupal_add_js(array(
'content_lock' => $settings,
), 'setting');
return $form;
}