Commit de3d7304 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Move javascript to hide/expand forum post subjects into pieforms



Change-Id: I027945b8eb3b0c541837d2306610b4ceacedcdde
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 0924df8b
......@@ -121,26 +121,6 @@ else { // edit post
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime);
// Javascript to hide the subject box if it has nothing in it, with a link you
// click to expand it.
$clicksetsubject = json_encode(get_string('clicksetsubject', 'interaction.forum'));
$inlinejs = <<<EOF
addLoadEvent(function() {
var subjectInput = $('editpost_subject');
if (subjectInput.value == '') {
hideElement(subjectInput);
var expandLink = A({'href': ''}, {$clicksetsubject});
connect(expandLink, 'onclick', function(e) {
showElement(subjectInput);
subjectInput.focus();
e.stop();
removeElement(expandLink);
});
insertSiblingNodesBefore(subjectInput, expandLink);
}
});
EOF;
$editform = pieform(array(
'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
......@@ -152,7 +132,9 @@ $editform = pieform(array(
'defaultvalue' => isset($post) ? $post->subject : null,
'rules' => array(
'maxlength' => 255
)
),
'hidewhenempty' => true,
'expandtext' => get_string('clicksetsubject', 'interaction.forum'),
),
'body' => array(
'type' => 'wysiwyg',
......
......@@ -32,9 +32,18 @@
* @return string The HTML for the element
*/
function pieform_element_text(Pieform $form, $element) {/*{{{*/
return '<input type="text"'
. $form->element_attributes($element)
. ' value="' . Pieform::hsc($form->get_value($element)) . '">';
}/*}}}*/
$value = Pieform::hsc($form->get_value($element));
$html = '';
// If hidewhenempty is set, the text box is hidden by a link which expands it.
if (!empty($element['hidewhenempty']) && $value == '') {
$inputid = hsc($form->get_name() . '_' . $element['name']);
$linktext = $element['expandtext'] ? hsc($element['expandtext']) : get_string('edit');
$html .= '<a href="" '
. "onclick=\"addElementClass('${inputid}_expand', 'hidden'); removeElementClass('{$inputid}', 'hidden'); return false;\""
. "id=\"${inputid}_expand\">" . $linktext . '</a>';
$element['class'] .= ' hidden';
}
?>
return $html . '<input type="text"' . $form->element_attributes($element) . ' value="' . $value . '">';
}/*}}}*/
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