Commit ccfca9d5 by Scott

Fix empty script tag

Clean up some of the JS code
parent 833153ec
......@@ -337,15 +337,19 @@ function qa_output_content($qa_content)
if (isset($qa_content['script_rel'])) {
$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>';
}
}
if (isset($qa_content['script_src'])) {
$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>';
}
}
// JS onloads must come after jQuery is loaded
if (isset($qa_content['focusid'])) {
$qa_content['script_onloads'][] = array(
......@@ -353,20 +357,19 @@ function qa_output_content($qa_content)
);
}
// JS onloads must come after jQuery is loaded
$script[] = '<script>';
if (isset($qa_content['script_onloads'])) {
$script[] = '<script>';
$script[] = '$(window).load(function() {';
foreach ($qa_content['script_onloads'] as $scriptonload) {
foreach ((array)$scriptonload as $scriptline)
foreach ((array)$scriptonload as $scriptline) {
$script[] = "\t" . $scriptline;
}
}
$script[] = '});';
}
$script[] = '</script>';
}
if (!isset($qa_content['script'])) {
$qa_content['script'] = array();
......
......@@ -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));
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 (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();"';
}
if (!$formrequested) {
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;
}
break;
}
......@@ -1118,22 +1120,25 @@ 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));
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 (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'))
$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()"';
}
if (count($onloads))
if (count($onloads)) {
$qa_content['script_onloads'][] = $onloads;
}
break;
}
$form['id'] = $formid;
$form['collapse'] = !$loadfocusnow;
$form['style'] = 'tall';
......
......@@ -411,8 +411,8 @@ class qa_html_theme_base
{
$this->output(
'<script>',
"var b=document.getElementsByTagName('body')[0];",
"b.className=b.className.replace('qa-body-js-off', 'qa-body-js-on');",
"var b = document.getElementsByTagName('body')[0];",
"b.className = b.className.replace('qa-body-js-off', 'qa-body-js-on');",
'</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