MDL-33041 (2) Tidy up tinymce lib.php before starting real changes
[moodle.git] / lib / editor / tinymce / module.js
CommitLineData
4c508047
PS
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
17 * TinyMCE helper javascript functions
18 *
34a30b5c 19 * @package editor_tinymce
4c508047
PS
20 * @copyright 2010 Petr Skoda (skodak) info@skoda.org
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24M.editor_tinymce = M.editor_tinymce || {};
25
26M.editor_tinymce.editor_options = M.editor_tinymce.options || {};
27M.editor_tinymce.filepicker_options = M.editor_tinymce.filepicker_options || {};
28
29M.editor_tinymce.init_editor = function(Y, editorid, options) {
30 M.editor_tinymce.editor_options[editorid] = options;
31 tinyMCE.init(options);
32
33 var item = document.getElementById(editorid+'_filemanager');
34 if (item) {
35 item.parentNode.removeChild(item);
36 }
37};
38
39M.editor_tinymce.init_filepicker = function(Y, editorid, options) {
40 M.editor_tinymce.filepicker_options[editorid] = options;
41};
42
43M.editor_tinymce.toggle = function(id) {
44 tinyMCE.execCommand('mceToggleEditor', false, id);
45};
46
47M.editor_tinymce.filepicker_callback = function(args) {
48};
49
50M.editor_tinymce.filepicker = function(target_id, url, type, win) {
51 YUI(M.yui.loader).use('core_filepicker', function (Y) {
52 var editor_id = tinyMCE.selectedInstance.editorId;
5a254328
DC
53 if (editor_id == 'mce_fullscreen') {
54 editor_id = tinyMCE.selectedInstance.settings.elements;
55 }
875f4e7b
DC
56 var options = null;
57 if (type == 'media') {
766514a0 58 // when mediaw button clicked
875f4e7b 59 options = M.editor_tinymce.filepicker_options[editor_id]['media'];
766514a0
DC
60 } else if (type == 'file') {
61 // when link button clicked
62 options = M.editor_tinymce.filepicker_options[editor_id]['link'];
63 } else if (type == 'image') {
64 // when image button clicked
875f4e7b 65 options = M.editor_tinymce.filepicker_options[editor_id]['image'];
766514a0 66 }
4c508047
PS
67
68 options.formcallback = M.editor_tinymce.filepicker_callback;
69 options.editor_target = win.document.getElementById(target_id);
70
71 M.core_filepicker.show(Y, options);
72 });
73};
74
ab978b38
RT
75M.editor_tinymce.onblur_event = function(ed) {
76 //Attach event only after tinymce is intialized.
77 if (ed.onInit != undefined) {
78 var s = ed.settings;
79 //Save before event is attached, so that if this event is not generated then textarea should
80 //have loaded contents and submitting form should not throw error.
81 ed.save();
82
a82e9ada 83 //Attach blur event for tinymce to save contents to textarea
ab978b38
RT
84 var doc = s.content_editable ? ed.getBody() : (tinymce.isGecko ? ed.getDoc() : ed.getWin());
85 tinymce.dom.Event.add(doc, 'blur', function() {
86 //save contents to textarea before calling validation script.
87 ed.save();
ab978b38
RT
88 });
89 };
90};