History | Log In     View a printable version of the current page.  
We are currently focused especially on Moodle 2.0, Moodle 1.9.x bugs and Moodle 1.9.x testing.    Confused? Lost? Please read this introduction to the Tracker.
Issue Details (XML | Word | Printable)

Key: MDL-14795
Type: Sub-task Sub-task
Status: Open Open
Priority: Major Major
Assignee: Mathieu Petit-Clair
Reporter: Mathieu Petit-Clair
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Moodle
MDL-11113

Create and test editor plug-in layer

Created: 12/May/08 05:00 PM   Updated: 29/May/08 03:05 PM
Component/s: HTML Editor
Affects Version/s: 2.0
Fix Version/s: None

File Attachments: 1. Text File patch-14795-editor-layer.txt (36 kb)


Participants: Mathieu Petit-Clair and Mauno Korpelainen
Security Level: None


 Description  « Hide
We need to create the specs for a "plug-in layer" that will sit between Moodle and the code of each editor. The files for this should be separated from the files received in orignal editor distribution (in tinymce case, that means out of the jscripts folder).

Janne Mikkonen starter such a layer two years ago, in the form of the files editorname.class.php. As TinyMCE has changed quite a lot since then, the file needs to be reworked: the configuration variables have changed, the __is_valid_key() function could possibly be removed, etc.

The starting code (as sent in by Mauno K.) and the older code from Janne need to be merged.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Mathieu Petit-Clair - 12/May/08 06:12 PM
Here's a patch that applies to cvs HEAD, heavily based on the code that was in Mauno's 1.9 zipfile, posted in the forum, last week.

 * I added some administration settings, so that the admin can choose the default html editor.
 * I reverted the user selection: we will need to create something a bit more complicated, based on formats.
 * The /0/, /1/, ... folders have been merged back into the editor folder.
 * A new function has been added to moodlelib.php to detect which editors are available on disk.
 * A few more changes/fixes: removed php4 compat, cleaned up based on coding standards, etc.

I am not committing this to the repository, mostly because the change from use_html_editor() to use_admin_editor() needs to be clarified (and if do change, there are a lot more places where this needs to be fixed) (and use_html_editor() deleted, or moved to deprecatedlib.php). Committing this now would make the code in a "clearly uncertain" state.

This has less functionality than what Mauno has in his zipfile, but should make it easier to add it back later.

I'll be out of town for two weeks, will be back on the 28th... to work on that and everything else.

Mauno Korpelainen - 12/May/08 11:27 PM
May I clarify why I used function use_admin_editor(): it was necessary only because I did not get tinymce to render editor properly on admin settings and upgradesettings pages and message editor so I used a different function to load init script through function. The problem comes from different way to init editor: in current version htmlarea and xinha replace textarea created by function print_textarea with editor using use_html_editor and for these editor use_admin_editor was basicly the same as use_html_editor (a little bit different button sets only). TinyMCE has a class selector that it uses to replace elements that have class "form-textarea" with editor and init code is loaded before page itself is loaded - in header tags. FCKEditor is usually using the same method as htmlarea and Xinha but in my tests I have used this kind of a header script in meta.php to do the replacement like tinymce:

<script type="text/javascript">
window.onload = function ()
      {
       var alltextareas = document.getElementsByTagName("textarea");
for (var i=0; i < alltextareas.length; i++) {
if(alltextareas[i].className=='form-textarea') {
       var oFCKeditor = new FCKeditor(alltextareas[i].name) ;
oFCKeditor.Config["CustomConfigurationsPath"] = "<?php echo $CFG->wwwroot ?>/lib/editor/fckeditor/moodleconfig.js";
       oFCKeditor.BasePath = "<?php echo $CFG->wwwroot .'/lib/editor/fckeditor/' ?>" ;

       oFCKeditor.Height = 400 ;
       oFCKeditor.Width = 600 ;

       oFCKeditor.ReplaceTextarea(alltextareas[i].name) ;}
        }
}
</script>

and moodleconfig.js has all the settings for fckeditor. If we have only a couple of different ways to use editor we can have also a couple of different config files (for administration and messages).

It might still be good to keep both function print_textarea and use_html_editor (even if it was empty) or have different functions for editor header tags/scripts and editor body tags/scripts. Or those "special cases" (like message editor and front page description page could use header tags and editor the same way as other pages)

Mauno Korpelainen - 12/May/08 11:44 PM
Anyway a common plug-in layer is a great thing. We might have some settings stable in lib files and some settings might be configurable through themes and css or some custom config files. FCKEditor is using a 3-level configuration 1) default configuration file (fckconfig.js) 2) custom configuration file(s) (moodleconfig.js) and 3) custom tags like oFCKeditor.Height = 400 ; that can be given for example in theme header.html or meta.php

Settings 2) overide settings 1) and settings 3) override settings 2) (if there are some custom settings)

Mauno Korpelainen - 13/May/08 12:23 AM
And if you decide that tinymce is the default editor it would be natural to force other editors (htmlarea and xinha) to use the same logic to render editor like tinymce with build-in-class-selector and fckeditor with window.onload-class-selector. Then functions use_html_editor and probably also use_admin_editor could be moved to deprecatedlib.php. One big question is how to set editor configuration for special needs - with common plug-in-layer and functions like print_editor_config($editorhidebuttons='', ...) or some other method like theme tags. The difference is that if we use common plug-in-layer we can have stable settings for activities like messages and settings are given by the activity. If we use theme settings we can change the layout of editors so that message window does not have to look the same in different themes. Both are good choices and have several benefits...

If possible these settings could be given before printing textarea with class="form-textarea" and not after printing the textarea (now htmlarea gets the settings in function use_html_editor after function print_textarea and tinymce can't use function use_html_editor to give new settings because it has already replaced textarea with editor according to class="form-textarea".

Mauno Korpelainen - 13/May/08 12:27 AM
...or Tinymce needs to reload the editor with new settings.

Mathieu Petit-Clair - 28/May/08 04:54 PM
Thanks for the explanations Mauno, I will start working on this patch again, make it work against head again and possibly commit it soon.

Mauno Korpelainen - 29/May/08 03:05 PM
I added a link to new test package to http://moodle.org/mod/forum/discuss.php?d=96160 and tested some optional ways to render editors. We may use also editor functions like Xinha.replace() directly. If you download the package and check the files I tried for example the following "tricks" to get the problematic pages loaded with use_admin_editor() - textarea id, textarea name and textarea class are used differently in different editors:

For Xinha:

function tsetup() {
       var alltextareas = document.getElementsByTagName("textarea");
for (var i=0; i < alltextareas.length; i++) {
if(alltextareas[i].className=='form-textarea') {
       Xinha.replace(alltextareas[i].id) ;}
        }
}

For FCKEditor no extra functions needed:

window.onload = function ()
      {
       var alltextareas = document.getElementsByTagName("textarea");
for (var i=0; i < alltextareas.length; i++) {
if(alltextareas[i].className=='form-textarea') {
       var oFCKeditor = new FCKeditor(alltextareas[i].name) ;
       oFCKeditor.ReplaceTextarea(alltextareas[i].name) ;}
        }
}

For tinymce (only IE has problems):

<!--[if IE]>
<script type="text/javascript">
function tsetup() {
tinyMCE.init({
... all tinymce init code for those admin pages here - tinymce uses class-selector

editor_selector : "form-textarea",
...
    }
}
</script>
<![endif]-->
<!--[if !IE]>-->
<script type="text/javascript">
function tsetup() {}
</script>
<!--<![endif]-->

If all pages had a same kind of header, same way to get settings and same way to render editor life would be much easier. Could it be possible to get Front page description field and messages to use same logic to render editor as other pages and activities? Then no tricks were needed afterwards.