diff --git a/comment/comment.js b/comment/comment.js index 3441b9d2ec1..897840f6247 100644 --- a/comment/comment.js +++ b/comment/comment.js @@ -197,6 +197,7 @@ M.core_comment = { } }); }, + delete: function(id) { var scope = this; var params = {'commentid': id}; diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 30f249d82f2..3bf4f8bb5de 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -147,6 +147,7 @@ class page_requirements_manager { $this->M_yui_loader->insertBefore = 'firstthemesheet'; $this->M_yui_loader->modules = array(); $this->add_yui2_modules(); // adds loading info for YUI2 + $this->js_module($this->find_module('core_filepicker')); // YUI3 init code $libs = array('cssreset', 'cssbase', 'cssfonts', 'cssgrids', 'node', 'loader'); // full CSS reset + basic libs @@ -335,9 +336,7 @@ class page_requirements_manager { if (strpos($name, 'core_') === 0) { // must be some core stuff if ($name === 'core_filepicker') { - $module = array('name'=>$name, 'fullpath'=>'/repository/filepicker.js', 'requires' => array('base', 'node', 'json', 'async-queue', 'io')); - } else if($name === 'core_filemanager') { - $module = array('name'=>$name, 'fullpath'=>'/lib/form/filemanager.js', 'requires' => array('base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview')); + $module = array('name'=>$name, 'fullpath'=>'/repository/filepicker.js', 'requires' => array('base', 'node', 'json', 'async-queue', 'io', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview')); } else if($name === 'core_comment') { $module = array('name'=>$name, 'fullpath'=>'/comment/comment.js', 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation')); } else if($name === 'core_role') { @@ -496,14 +495,16 @@ class page_requirements_manager { * The first argument is always the YUI3 Y instance with all required dependencies * already loaded. * @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM) + * @param array $module JS module specification array * @return void */ - public function js_init_call($function, array $extraarguments = null, $ondomready = false) { + public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) { $jscode = js_writer::function_call_with_Y($function, $extraarguments); - $module = null; - // detect module automatically - if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) { - $module = $this->find_module($matches[1]); + if (!$module) { + // detect module automatically + if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) { + $module = $this->find_module($matches[1]); + } } $this->js_init_code($jscode, $ondomready, $module); diff --git a/lib/editor/textarea/lib.php b/lib/editor/textarea/lib.php index 1258d5fc887..9e582a1e5df 100644 --- a/lib/editor/textarea/lib.php +++ b/lib/editor/textarea/lib.php @@ -45,7 +45,7 @@ class textarea_texteditor extends texteditor { return true; } - public function use_editor($elementid, array $options=null) { + public function use_editor($elementid, array $options=null, $fpoptions=null) { return; } } diff --git a/lib/editor/tinymce/extra/tinymce_utils.js b/lib/editor/tinymce/extra/tinymce_utils.js deleted file mode 100644 index 920ed9484e5..00000000000 --- a/lib/editor/tinymce/extra/tinymce_utils.js +++ /dev/null @@ -1,69 +0,0 @@ -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - -/** - * TinyMCE helper javascript functions - * - * @package moodlecore - * @subpackage editor - * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -function mce_init_editor(elementid, params) { - tinyMCE.init(params); -} - -function mce_toggleEditor(id) { - tinyMCE.execCommand('mceToggleEditor',false,id); -} - -function mce_saveOnSubmit(id) { - var prevOnSubmit = document.getElementById(id).form.onsubmit; - document.getElementById(id).form.onsubmit = function() { - tinyMCE.triggerSave(); - var ret = true; - if (prevOnSubmit != undefined) { - if (prevOnSubmit()) { - ret = true; - prevOnSubmit = null; - } else { - ret = false; - } - } - return ret; - }; -} - -var editor_filepickers = {}; -var editor_options = {}; -function editor_filepicker_callback(args) { -} -function editor_init_filepicker(editorid, options) { - editor_options[editorid] = options; -} -function mce_moodlefilemanager(target_id, url, type, win) { - YUI(M.yui.loader).use('core_filepicker', function (Y) { - var editor_id = tinyMCE.selectedInstance.editorId; - var options = editor_options[editor_id]; - var client_id = options.client_id; - options.formcallback = editor_filepicker_callback; - options.editor_target = win.document.getElementById(target_id); - if (!editor_filepickers[client_id]) { - editor_filepickers[client_id] = new M.core_filepicker(options); - } - editor_filepickers[client_id].show(); - }); -} diff --git a/lib/editor/tinymce/lib.php b/lib/editor/tinymce/lib.php index 0345e0297d8..908f781db5f 100644 --- a/lib/editor/tinymce/lib.php +++ b/lib/editor/tinymce/lib.php @@ -52,15 +52,15 @@ class tinymce_texteditor extends texteditor { } 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) { + public function use_editor($elementid, array $options=null, $fpoptions=null) { global $PAGE; - $PAGE->requires->js_function_call('mce_init_editor', array($elementid, $this->get_init_params($elementid, $options))); + $PAGE->requires->js('/lib/editor/tinymce/tiny_mce_src.js'); + $PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true); + if ($fpoptions) { + $PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true); + } } protected function get_init_params($elementid, array $options=null) { @@ -131,7 +131,7 @@ class tinymce_texteditor extends texteditor { if (empty($options['legacy'])) { if (isset($options['maxfiles']) and $options['maxfiles'] != 0) { - $params['file_browser_callback'] = "mce_moodlefilemanager"; + $params['file_browser_callback'] = "M.editor_tinymce.filepicker"; } } diff --git a/lib/editor/tinymce/module.js b/lib/editor/tinymce/module.js new file mode 100644 index 00000000000..f5556a58ddd --- /dev/null +++ b/lib/editor/tinymce/module.js @@ -0,0 +1,62 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * TinyMCE helper javascript functions + * + * @package moodlecore + * @subpackage editor + * @copyright 2010 Petr Skoda (skodak) info@skoda.org + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +M.editor_tinymce = M.editor_tinymce || {}; + +M.editor_tinymce.editor_options = M.editor_tinymce.options || {}; +M.editor_tinymce.filepicker_options = M.editor_tinymce.filepicker_options || {}; + +M.editor_tinymce.init_editor = function(Y, editorid, options) { + M.editor_tinymce.editor_options[editorid] = options; + tinyMCE.init(options); + + var item = document.getElementById(editorid+'_filemanager'); + if (item) { + item.parentNode.removeChild(item); + } +}; + +M.editor_tinymce.init_filepicker = function(Y, editorid, options) { + M.editor_tinymce.filepicker_options[editorid] = options; +}; + +M.editor_tinymce.toggle = function(id) { + tinyMCE.execCommand('mceToggleEditor', false, id); +}; + +M.editor_tinymce.filepicker_callback = function(args) { +}; + +M.editor_tinymce.filepicker = function(target_id, url, type, win) { + YUI(M.yui.loader).use('core_filepicker', function (Y) { + var editor_id = tinyMCE.selectedInstance.editorId; + var options = M.editor_tinymce.filepicker_options[editor_id]; + + options.formcallback = M.editor_tinymce.filepicker_callback; + options.editor_target = win.document.getElementById(target_id); + + M.core_filepicker.show(Y, options); + }); +}; + diff --git a/lib/editorlib.php b/lib/editorlib.php index 0696bf26e61..59e81904c7e 100644 --- a/lib/editorlib.php +++ b/lib/editorlib.php @@ -32,7 +32,7 @@ * @global object * @global object * @param int $format text format or null of none - * @return object texteditor object + * @return texteditor object */ function get_preferred_texteditor($format=null) { global $CFG, $USER; @@ -171,9 +171,10 @@ abstract class texteditor { * Add required JS needed for editor * @param string $elementid id of text area to be converted to editor * @param array $options + * @param obejct $fpoptions file picker options * @return void */ - public abstract function use_editor($elementid, array $options=null); + public abstract function use_editor($elementid, array $options=null, $fpoptions = null); /** * Setup all JS and CSS needed for editor. diff --git a/lib/form/editor.php b/lib/form/editor.php index 54142cff175..bba2c0a5b1d 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -119,6 +119,8 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { return $this->getFrozenHtml(); } + $ctx = $this->_options['context']; + $id = $this->_attributes['id']; $elname = $this->_attributes['name']; @@ -146,9 +148,34 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { $formats[$fid] = $strformats[$fid]; } + // get filepicker info + $fpoptions = null; + if ($maxfiles != 0 ) { + if (empty($draftitemid)) { + // no existing area info provided - let's use fresh new draft area + require_once("$CFG->libdir/filelib.php"); + $this->setValue(array('itemid'=>file_get_unused_draft_itemid())); + $draftitemid = $this->_values['itemid']; + } + + $args = new stdclass; + // need these three to filter repositories list + $args->accepted_types = array('image', 'video', 'media'); + $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL); + $args->context = $ctx; + $args->env = 'filepicker'; + + $fpoptions = initialise_filepicker($args); + + $fpoptions->client_id = uniqid(); + $fpoptions->maxbytes = $this->_options['maxbytes']; + $fpoptions->maxfiles = 1; + $fpoptions->env = 'editor'; + $fpoptions->itemid = $draftitemid; + } + /// print text area - TODO: add on-the-fly switching, size configuration, etc. - $editor->use_editor($id, $this->_options); - $ctx = $this->_options['context']; + $editor->use_editor($id, $this->_options, $fpoptions); $str .= '