Commit ccfca9d5 by Scott

Fix empty script tag

Clean up some of the JS code
parent 833153ec
...@@ -337,36 +337,39 @@ function qa_output_content($qa_content) ...@@ -337,36 +337,39 @@ function qa_output_content($qa_content)
if (isset($qa_content['script_rel'])) { if (isset($qa_content['script_rel'])) {
$uniquerel = array_unique($qa_content['script_rel']); // remove any duplicates $uniquerel = array_unique($qa_content['script_rel']); // remove any duplicates
foreach ($uniquerel as $script_rel) foreach ($uniquerel as $script_rel) {
$script[] = '<script src="' . qa_html(qa_path_to_root() . $script_rel) . '"></script>'; $script[] = '<script src="' . qa_html(qa_path_to_root() . $script_rel) . '"></script>';
}
} }
if (isset($qa_content['script_src'])) { if (isset($qa_content['script_src'])) {
$uniquesrc = array_unique($qa_content['script_src']); // remove any duplicates $uniquesrc = array_unique($qa_content['script_src']); // remove any duplicates
foreach ($uniquesrc as $script_src) foreach ($uniquesrc as $script_src) {
$script[] = '<script src="' . qa_html($script_src) . '"></script>'; $script[] = '<script src="' . qa_html($script_src) . '"></script>';
}
} }
// JS onloads must come after jQuery is loaded
if (isset($qa_content['focusid'])) { if (isset($qa_content['focusid'])) {
$qa_content['script_onloads'][] = array( $qa_content['script_onloads'][] = array(
'$(' . qa_js('#' . $qa_content['focusid']) . ').focus();', '$(' . qa_js('#' . $qa_content['focusid']) . ').focus();',
); );
} }
// JS onloads must come after jQuery is loaded
$script[] = '<script>';
if (isset($qa_content['script_onloads'])) { if (isset($qa_content['script_onloads'])) {
$script[] = '<script>';
$script[] = '$(window).load(function() {'; $script[] = '$(window).load(function() {';
foreach ($qa_content['script_onloads'] as $scriptonload) { foreach ($qa_content['script_onloads'] as $scriptonload) {
foreach ((array)$scriptonload as $scriptline) foreach ((array)$scriptonload as $scriptline) {
$script[] = "\t" . $scriptline; $script[] = "\t" . $scriptline;
}
} }
$script[] = '});'; $script[] = '});';
$script[] = '</script>';
} }
$script[] = '</script>';
if (!isset($qa_content['script'])) { if (!isset($qa_content['script'])) {
$qa_content['script'] = array(); $qa_content['script'] = array();
......
...@@ -973,23 +973,25 @@ function qa_page_q_add_a_form(&$qa_content, $formid, $captchareason, $question, ...@@ -973,23 +973,25 @@ function qa_page_q_add_a_form(&$qa_content, $formid, $captchareason, $question,
$captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason)); $captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
if (strlen($captchaloadscript)) if (strlen($captchaloadscript))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show = function() { ' . $captchaloadscript . ' };';
} }
if (!$loadnow) { if (!$loadnow) {
if (method_exists($editor, 'load_script')) if (method_exists($editor, 'load_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script('a_content') . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load = function() { ' . $editor->load_script('a_content') . ' };';
$form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element();"'; $form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element();"';
} }
if (!$formrequested) { if (!$formrequested) {
if (method_exists($editor, 'focus_script')) if (method_exists($editor, 'focus_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script('a_content') . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus = function() { ' . $editor->focus_script('a_content') . ' };';
} }
if (count($onloads)) if (count($onloads)) {
$qa_content['script_onloads'][] = $onloads; $qa_content['script_onloads'][] = $onloads;
}
break; break;
} }
...@@ -1118,20 +1120,23 @@ function qa_page_q_add_c_form(&$qa_content, $question, $parent, $formid, $captch ...@@ -1118,20 +1120,23 @@ function qa_page_q_add_c_form(&$qa_content, $question, $parent, $formid, $captch
$captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason)); $captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
if (strlen($captchaloadscript)) if (strlen($captchaloadscript))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show = function() { ' . $captchaloadscript . ' };';
} }
if (!$loadfocusnow) { if (!$loadfocusnow) {
if (method_exists($editor, 'load_script')) if (method_exists($editor, 'load_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script($prefix . 'content') . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load = function() { ' . $editor->load_script($prefix . 'content') . ' };';
if (method_exists($editor, 'focus_script')) if (method_exists($editor, 'focus_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script($prefix . 'content') . ' };'; $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus = function() { ' . $editor->focus_script($prefix . 'content') . ' };';
$form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element()"'; $form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element()"';
} }
if (count($onloads)) if (count($onloads)) {
$qa_content['script_onloads'][] = $onloads; $qa_content['script_onloads'][] = $onloads;
}
break;
} }
$form['id'] = $formid; $form['id'] = $formid;
......
...@@ -411,8 +411,8 @@ class qa_html_theme_base ...@@ -411,8 +411,8 @@ class qa_html_theme_base
{ {
$this->output( $this->output(
'<script>', '<script>',
"var b=document.getElementsByTagName('body')[0];", "var b = document.getElementsByTagName('body')[0];",
"b.className=b.className.replace('qa-body-js-off', 'qa-body-js-on');", "b.className = b.className.replace('qa-body-js-off', 'qa-body-js-on');",
'</script>' '</script>'
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment