Permalink
Browse files

ForumNG: TinyMCE editor appearing wrong size for available space #2064

  • Loading branch information...
1 parent aa356ed commit 82ae65c644a92a26f0c552ec674dfeccbbf65f61 @sammarshallou sammarshallou committed Nov 8, 2011
Showing with 72 additions and 41 deletions.
  1. +13 −8 editpost.php
  2. +20 −12 editpost_form.php
  3. +35 −20 module.js
  4. +4 −1 styles.css
View
@@ -425,11 +425,13 @@ function finish($postid, $cloneid, $url, $fromform, $ajaxdata='') {
// Save attachments
file_save_draft_area_files($fromform->attachments, $filecontext->id, 'mod_forumng',
'attachment', $postid, $fileoptions);
- $newtext = file_save_draft_area_files($fromform->message['itemid'],
- $filecontext->id, 'mod_forumng', 'message', $postid, $fileoptions,
- $fromform->message['text']);
- if ($newtext !== $fromform->message['text']) {
- mod_forumng_post::update_message_for_files($postid, $newtext);
+ if (!empty($fromform->message['itemid'])) {
+ $newtext = file_save_draft_area_files($fromform->message['itemid'],
+ $filecontext->id, 'mod_forumng', 'message', $postid, $fileoptions,
+ $fromform->message['text']);
+ if ($newtext !== $fromform->message['text']) {
+ mod_forumng_post::update_message_for_files($postid, $newtext);
+ }
}
// If there's a draft, get rid of it
@@ -456,9 +458,12 @@ function finish($postid, $cloneid, $url, $fromform, $ajaxdata='') {
file_save_draft_area_files($fromform->attachments, $filecontext->id, 'mod_forumng',
'attachment', $post->get_id(), $fileoptions);
- $fromform->message['text'] = file_save_draft_area_files($fromform->message['itemid'],
- $filecontext->id, 'mod_forumng', 'message', $postid, $fileoptions,
- $fromform->message['text']);
+ // itemid is not present when using text-only editor
+ if (!empty($fromform->message['itemid'])) {
+ $fromform->message['text'] = file_save_draft_area_files($fromform->message['itemid'],
+ $filecontext->id, 'mod_forumng', 'message', $postid, $fileoptions,
+ $fromform->message['text']);
+ }
$post->edit_finish($fromform->message['text'], $fromform->message['format'],
$gotsubject);
View
@@ -121,15 +121,30 @@ function definition() {
'context'=>$forum->get_context(true));
$mform->addElement('editor', 'message', get_string('message', 'forumng'),
$editorattributes, $editoroptions);
+ $gotmessage = true;
} else {
// AJAX version has a placeholder, to be installed by live JavaScript
- $mform->addElement('text', 'message', get_string('message', 'forumng'),
- $editorattributes);
+ if (can_use_html_editor()) {
+ $mform->addElement('text', 'message', get_string('message', 'forumng'),
+ $editorattributes);
+ $gotmessage = true;
+ } else {
+ $mform->addElement('textarea', 'message[text]', get_string('message', 'forumng'),
+ $editorattributes);
+ $mform->addElement('hidden', 'message[format]', FORMAT_MOODLE);
+ $gotmessage = false;
+ }
}
- $mform->setType('message', PARAM_RAW);
- $mform->addRule('message', get_string('required'),
- 'required', null, 'client');
+ if ($gotmessage) {
+ $mform->setType('message', PARAM_CLEANHTML);
+ $mform->addRule('message', get_string('required'),
+ 'required', null, 'client');
+ } else {
+ $mform->setType('message[text]', PARAM_RAW);
+ $mform->addRule('message[text]', get_string('required'),
+ 'required', null, 'client');
+ }
// If you can create attachments...
if ($forum->can_create_attachments()) {
@@ -286,13 +301,6 @@ function validation($data, $files) {
}
return $errors;
}
- function definition_after_data() {
- parent::definition_after_data();
- $mform =& $this->_form;
- if ($mform->elementExists('format')) {
- $mform->getElement('format')->setValue(FORMAT_MOODLE);
- }
- }
/**
* Obtains HTML for form; needed so that this can be printed for AJAX version.
View
@@ -350,7 +350,7 @@ M.mod_forumng = {
*/
init_form: function(f) {
f.expectingeditor = f.get('tryinghtmleditor').get('value')=='1';
- f.usingeditor = f.expectingeditor && window.tinyMCE ;
+ f.usingeditor = f.expectingeditor && window.tinyMCE;
},
/**
@@ -591,7 +591,7 @@ M.mod_forumng = {
// Pick max indent level
var region = this.Y.DOM.region(document.getElementById('forumng-main'));
var width = region.right - region.left;
- var minwidth = 360;
+ var minwidth = 515; // Min size at which the stupid editor doesn't get cut off
var maxindentpixels = width - minwidth;
var stopIndent;
@@ -697,7 +697,13 @@ M.mod_forumng = {
}
clearInterval(submitenableinterval);
if (form.usingeditor) {
- tinyMCE.execCommand('mceRemoveControl', false, form.get('message[text]').get('id'));
+ var id = form.get('message[text]').get('id');
+ tinyMCE.execCommand('mceRemoveControl', false, id);
+
+ // TinyMCE remembers sizes, doesn't work on this page, so
+ // delete cookie pre-emptively
+ var cookieName = 'TinyMCE_' + id + '_size';
+ document.cookie = cookieName + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
form.setStyle('display', 'none');
@@ -845,6 +851,7 @@ M.mod_forumng = {
form.oldinput = input;
input.remove();
+ var Y = this.Y;
if (form.usingeditor) {
// Set up options
var options = {};
@@ -856,25 +863,32 @@ M.mod_forumng = {
}
options[1].elements = options[1].elements.replace('QQidQQ', fieldId);
- // Call the JS init function
- this.Y.use('editor_tinymce', function(Y) { M.editor_tinymce.init_editor(Y, options[0], options[1]); });
-
// Initialise attachments if provided
if (fileoptions) {
// Update the options template
var allfileoptions = [];
allfileoptions[0] = this.editorfileoptions[0].replace('QQidQQ', fieldId);
allfileoptions[1] = this.deep_clone_change_itemid(this.editorfileoptions[1],
fileoptions.itemid);
-
- this.Y.use('editor_tinymce', function(Y) { M.editor_tinymce.init_filepicker(Y, allfileoptions[0], allfileoptions[1]); });
}
+
+ setTimeout(function() {
+ // Call the JS init function
+ Y.use('editor_tinymce', function(Y) { M.editor_tinymce.init_editor(Y, options[0], options[1]); });
+
+ // Initialise attachments if provided
+ if (fileoptions) {
+ Y.use('editor_tinymce', function(Y) { M.editor_tinymce.init_filepicker(Y, allfileoptions[0], allfileoptions[1]); });
+ }
+ }, 0);
}
form.donetextarea = true;
}
}
- form.get('message[text]').set('value', value);
+ var textbox = form.get('message[text]');
+ textbox.set('value', value);
+ textbox.ancestor('div.fitem').addClass('forumng-editarea');
form.get('subject').set('value', '');
if (form.get('setimportant')) {
form.get('setimportant').set('checked', false);
@@ -889,33 +903,34 @@ M.mod_forumng = {
setTimeout(function() {
var id = form.get('message[text]').get('id');
- // Function to focus the editor
- var focusFunction = function() {
+ var fixFunction = function() {
+ var iframe = form.one('iframe');
+ if(!iframe) {
+ setTimeout(fixFunction, 250);
+ return;
+ }
+
if (navigator.product == 'Gecko') {
form.get('subject').focus();
setTimeout(function() {
tinyMCE.execCommand('mceFocus', false, id);
}, 0);
} else {
- // Make sure the editor actually exists, otherwise wait
- if (M.mod_forumng.Y.one('#' + id + '_parent')) {
- tinyMCE.execCommand('mceFocus', false, id);
- } else {
- setTimeout(focusFunction, 250);
- }
+ tinyMCE.execCommand('mceFocus', false, id);
}
- };
+ }
+ setTimeout(fixFunction, 250);
// There is a Firefox bug with disappearing cursor
if (navigator.product != 'Gecko') {
// In other browsers, the focus command only needs a simple setTimeout
- setTimeout(focusFunction, 0);
+ setTimeout(fixFunction, 0);
} else {
// In Gecko, we need to focus a normal (non-richtext) field first, then
// focus the editor. Need to wait a bit first; repeating the
// set_timeout 20 times recursively seems to do the job...
setTimeout(function() {
- M.mod_forumng.set_timeout_multi(focusFunction, 20);
+ M.mod_forumng.set_timeout_multi(fixFunction, 20);
}, 0);
}
}, 0);
View
@@ -519,11 +519,14 @@ ul.forumng-commands li.forumng-replylink {
*/
#page-mod-forumng-discuss .mform {
- width: 100%;
padding: 0;
display: none;
margin-bottom: 1em;
}
+#page-mod-forumng-discuss .mform textarea {
+ width: 99%;
+}
+
.ie#page-mod-forumng-discuss .mform {
margin-top: 0.5em;
}

0 comments on commit 82ae65c

Please sign in to comment.