]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19500 improved editor embedding
authorskodak <skodak>
Sun, 14 Jun 2009 21:35:07 +0000 (21:35 +0000)
committerskodak <skodak>
Sun, 14 Jun 2009 21:35:07 +0000 (21:35 +0000)
lib/adminlib.php
lib/editor/textarea/lib.php
lib/editor/tinymce/lib.php
lib/editorlib.php
lib/form/editor.php
lib/javascript.php
lib/weblib.php

index 5c21b668c11a8bae0bc548f1d5dc6c261b120804..ebec3dfeebdef3d967a8cf4294a10308e35cb0a1 100644 (file)
@@ -1634,6 +1634,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext {
 
         $editor = get_preferred_texteditor(FORMAT_HTML);
         $editorclass = $editor->get_legacy_textarea_class();
+        $editor->use_editor($this->get_id());
 
         return format_admin_setting($this, $this->visiblename,
                 '<div class="form-textarea"><textarea class="'.$editorclass.'" rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
index 82552ff1023d80edc967fa7164c04d2efc3bf1b9..d6400e92ef70b903cb689ce93e7bf57cafb697ed 100644 (file)
@@ -53,8 +53,8 @@ class textarea_texteditor extends texteditor {
         return 'form-textarea-legacy';
     }
 
-    public function header_js() {
-        return '';
+    public function use_editor($elementid=null) {
+        return;
     }    
 }
 
index fbeec676cc448727dafa8d243be7ad8285206c5c..3e2ef835b91c84802b20fd33b80630a5d73aceda 100644 (file)
@@ -59,14 +59,14 @@ class tinymce_texteditor extends texteditor {
         return 'form-tinymce-legacy';
     }
 
-    public function header_js() {
-        global $CFG;
-
+    public function use_editor($elementid=null) {
+        global $CFG, $PAGE;
         $usehttps = (int)($CFG->httpswwwroot !== $CFG->wwwroot); //hmm, is there a better test?
-        
-        $js = '<script type="text/javascript" src="'.$CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce_src.js"></script>'."\n".
-              '<script type="text/javascript" src="'.$CFG->httpswwwroot.'/lib/editor/tinymce/extra/tinymce.js.php?elanguage='.current_language().'&amp;etheme='.current_theme().'&amp;eusehttps='.$usehttps.'"></script>'."\n";
-        return $js;
+
+        //TODO: requirements manager does not support parameters :-(
+
+        $PAGE->requires->js($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce_src.js', true);
+        $PAGE->requires->js($CFG->httpswwwroot.'/lib/editor/tinymce/extra/tinymce.js.php?elanguage='.current_language().'&amp;etheme='.current_theme().'&amp;eusehttps='.$usehttps, true);
     }
     
 }
\ No newline at end of file
index b86ddc0996741823dba296ff85354aa3a4a4120e..f68292d7372d543b59964ed6808bc873a307f8f5 100644 (file)
@@ -156,10 +156,10 @@ abstract class texteditor {
     public abstract function get_legacy_textarea_class();
 
     /**
-     * Returns js script statements needed in html head.
-     * @return string
+     * Add required JS needed for editor
+     * @return void
      */
-    public abstract function header_js();
+    public abstract function use_editor($elementid=null);
 }
 
 
index 6f2e35c59afbf79cbd8862440f3a8469f2a4cf6a..26718e816963dce24ed276bf5d4ecfe9d9a812a7 100644 (file)
@@ -137,6 +137,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
 
     /// print text area - TODO: add on-the-fly switching, size configuration, etc.
         $editorclass = $editor->get_editor_element_class();
+        $editor->use_editor($id);
 
         $str .= '<div><textarea class="'.$editorclass.'" id="'.$id.'" name="'.$elname.'[text]" rows="15" cols="80">';
         $str .= s($text);
index b106cd50b720b853d7b9ef12453df1310ba81793..7816e183c29baf3fb9dd451b660c795e36849124 100644 (file)
@@ -62,16 +62,3 @@ if (!empty($focus)) {
 ?>
 //]]>
 </script>
-<?php
-    // editors integrations
-    //TODO: optimize loading of editors
-    if (empty($CFG->texteditors)) {
-        $CFG->texteditors = 'tinymce,textarea';
-    }
-    $activeeditors = explode(',', $CFG->texteditors);
-    foreach ($activeeditors as $editor) {
-        if ($editor = get_texteditor($editor)) {
-            echo $editor->header_js();
-        }
-    }
-?>
\ No newline at end of file
index 26feb67dda1db57a9377e999909c9414986033ec..24f9cd4bfe1b4c054b7027f3db79b7be91feedf0 100644 (file)
@@ -4965,6 +4965,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
     if ($usehtmleditor) {
         $editor = get_preferred_texteditor(FORMAT_HTML);
         $editorclass = $editor->get_legacy_textarea_class();
+        $editor->use_editor($id);
     } else {
         $editorclass = '';
     }