MDL-19580 cleanup of require css and js filepicker code

This commit is contained in:
skodak 2009-06-24 22:34:29 +00:00
parent b14e77c966
commit ff5fe31160
14 changed files with 169 additions and 121 deletions

View file

@ -1578,6 +1578,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext {
$this->rows = $rows;
$this->cols = $cols;
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
editors_head_setup();
}
/**
* Returns an XHTML string for the editor
@ -2985,6 +2986,7 @@ class admin_setting_special_frontpagedesc extends admin_setting {
*/
public function __construct() {
parent::__construct('summary', get_string('frontpagedescription'), get_string('frontpagedescriptionhelp'), NULL);
editors_head_setup();
}
/**

View file

@ -658,7 +658,9 @@ class required_yui_lib extends linked_requirement {
$this->jss[] = $manager->js($jsurl, true);
}
foreach ($cssurls as $cssurl) {
//$manager->css($cssurl, true);
// this might be a bit problematic because it requires yui to be
// requested before print_header() - this was not required in 1.9.x
$manager->css($cssurl, true);
}
}

View file

@ -51,11 +51,15 @@ class tinymce_texteditor extends texteditor {
return true;
}
public function use_editor($elementid, array $options=null) {
public function head_setup() {
global $CFG, $PAGE;
require_once("$CFG->dirroot/repository/lib.php");
$PAGE->requires->js('/lib/editor/tinymce/tiny_mce_src.js');
$PAGE->requires->js('/lib/editor/tinymce/extra/tinymce_utils.js');
}
public function use_editor($elementid, array $options=null) {
global $PAGE;
$PAGE->requires->js_function_call('mce_init_editor', array($elementid, $this->get_init_params($elementid, $options)));
}

View file

@ -111,6 +111,30 @@ function get_available_editors() {
return $editors;
}
/**
* Setup all JS and CSS needed for editors.
* @return void
*/
function editors_head_setup() {
global $CFG;
if (empty($CFG->texteditors)) {
$CFG->texteditors = 'tinymce,textarea';
}
$active = explode(',', $CFG->texteditors);
foreach ($active as $editorname) {
if (!$editor = get_texteditor($editorname)) {
continue;
}
if (!$editor->supported_by_browser()) {
// bad luck, this editor is not compatible
continue;
}
$editor->head_setup();
}
}
/**
* Base abstract text editor class.
*
@ -150,6 +174,13 @@ abstract class texteditor {
* @return void
*/
public abstract function use_editor($elementid, array $options=null);
/**
* Setup all JS and CSS needed for editor.
* @return void
*/
public function head_setup() {
}
}

View file

@ -15,6 +15,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
$options = (array)$options;
foreach ($options as $name=>$value) {
@ -29,6 +30,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$this->_options['context'] = get_context_instance(CONTEXT_SYSTEM);
}
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
repository_head_setup();
editors_head_setup();
}
function setName($name) {
@ -171,9 +175,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
require_once($CFG->dirroot.'/repository/lib.php');
$client_id = uniqid();
$ret = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
$repojs = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
$str .= $ret['css'].$ret['js'];
$str .= $repojs;
$str .= <<<EOD
<script type="text/javascript">
id2clientid['$id'] = '$client_id';

View file

@ -9,6 +9,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
$options = (array)$options;
foreach ($options as $name=>$value) {
@ -20,6 +21,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
repository_head_setup();
}
function setName($name) {
@ -162,15 +165,14 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
}
$client_id = uniqid();
$repo_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
$repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
$html = $this->_get_draftfiles($draftitemid, $client_id);
$accessiblefp = get_string('accessiblefilepicker', 'repository');
$str = $this->_getTabs();
$str .= $html;
$str .= $repo_info['css'];
$str .= $repo_info['js'];
$str .= $repojs;
$str .= <<<EOD
<input value="$draftitemid" name="{$this->_attributes['name']}" type="hidden" />
<a href="###" id="btnadd-{$client_id}" style="display:none" class="btnaddfile" onclick="return callpicker('$id', '$client_id', '$draftitemid')">$straddfile</a>

View file

@ -18,6 +18,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
$options = (array)$options;
foreach ($options as $name=>$value) {
@ -29,6 +30,8 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
repository_head_setup();
}
function setHelpButton($helpbuttonargs, $function='helpbutton') {
@ -84,14 +87,14 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
}
$client_id = uniqid();
$repository_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
$repojs = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
$str = $this->_getTabs();
$str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />';
$str .= $repository_info['css'].$repository_info['js'];
$str .= $repojs;
$str .= <<<EOD
<a href="#nonjsfp" class="btnaddfile" onclick="return callpicker('$client_id', '$id', '$draftvalue')">$straddfile</a>

View file

@ -36,6 +36,8 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
$this->_type='textarea';
}
$this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
editors_head_setup();
}
/**
* set html for help button

View file

@ -45,8 +45,6 @@ setTimeout('fix_column_widths()', 20);
</script>
<script type="text/javascript">
//<![CDATA[
var id2clientid = {};
var id2itemid = {};
<?php
if (!empty($focus)) {
if(($pos = strpos($focus, '.')) !== false) {

View file

@ -4991,6 +4991,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
}
if ($usehtmleditor) {
editors_head_setup();
$editor = get_preferred_texteditor(FORMAT_HTML);
$editor->use_editor($id, array('legacy'=>true));
} else {