MDL-35289 use new TinyMCE en lang import
[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/**
de6a6512 17 * TinyMCE helper javascript functions.
4c508047 18 *
34a30b5c 19 * @package editor_tinymce
de6a6512 20 * @copyright 2010 Petr Skoda (http://skodak.org)
4c508047
PS
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;
fae91170 31
de6a6512 32 // Load necessary Moodle plugins into editor.
fae91170 33 if (options.moodle_init_plugins) {
34 var extraplugins = options.moodle_init_plugins.split(',');
35 for (var i=0; i<extraplugins.length; i++) {
36 var filedetails = extraplugins[i].split(':');
37 tinyMCE.PluginManager.load(filedetails[0],
38 M.cfg.wwwroot + '/lib/editor/tinymce/plugins/' + filedetails[1]);
39 }
40 }
4c508047
PS
41 tinyMCE.init(options);
42
43 var item = document.getElementById(editorid+'_filemanager');
44 if (item) {
45 item.parentNode.removeChild(item);
46 }
47};
48
49M.editor_tinymce.init_filepicker = function(Y, editorid, options) {
50 M.editor_tinymce.filepicker_options[editorid] = options;
51};
52
53M.editor_tinymce.toggle = function(id) {
54 tinyMCE.execCommand('mceToggleEditor', false, id);
55};
56
57M.editor_tinymce.filepicker_callback = function(args) {
58};
59
60M.editor_tinymce.filepicker = function(target_id, url, type, win) {
e0a5793d 61 YUI().use('core_filepicker', function (Y) {
4c508047 62 var editor_id = tinyMCE.selectedInstance.editorId;
5a254328
DC
63 if (editor_id == 'mce_fullscreen') {
64 editor_id = tinyMCE.selectedInstance.settings.elements;
65 }
875f4e7b
DC
66 var options = null;
67 if (type == 'media') {
de6a6512 68 // When media button clicked.
875f4e7b 69 options = M.editor_tinymce.filepicker_options[editor_id]['media'];
766514a0 70 } else if (type == 'file') {
de6a6512 71 // When link button clicked.
766514a0
DC
72 options = M.editor_tinymce.filepicker_options[editor_id]['link'];
73 } else if (type == 'image') {
de6a6512 74 // When image button clicked.
875f4e7b 75 options = M.editor_tinymce.filepicker_options[editor_id]['image'];
766514a0 76 }
4c508047
PS
77
78 options.formcallback = M.editor_tinymce.filepicker_callback;
79 options.editor_target = win.document.getElementById(target_id);
80
81 M.core_filepicker.show(Y, options);
82 });
83};
84
ab978b38 85M.editor_tinymce.onblur_event = function(ed) {
de6a6512 86 // Attach event only after tinymce is initialized.
ab978b38
RT
87 if (ed.onInit != undefined) {
88 var s = ed.settings;
de6a6512
PS
89 // Save before event is attached, so that if this event is not generated then textarea should
90 // have loaded contents and submitting form should not throw error.
ab978b38
RT
91 ed.save();
92
de6a6512 93 // Attach blur event for tinymce to save contents to textarea.
ab978b38
RT
94 var doc = s.content_editable ? ed.getBody() : (tinymce.isGecko ? ed.getDoc() : ed.getWin());
95 tinymce.dom.Event.add(doc, 'blur', function() {
de6a6512 96 // Save contents to textarea before calling validation script.
ab978b38 97 ed.save();
ab978b38
RT
98 });
99 };
100};