[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/editor/tinymce/ -> module.js (source)

   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   *
  19   * @package    editor_tinymce
  20   * @copyright  2010 Petr Skoda (http://skodak.org)
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  M.editor_tinymce = M.editor_tinymce || {};
  25  
  26  M.editor_tinymce.editor_options = M.editor_tinymce.options || {};
  27  M.editor_tinymce.filepicker_options = M.editor_tinymce.filepicker_options || {};
  28  M.editor_tinymce.initialised = false;
  29  
  30  M.editor_tinymce.init_editor = function(Y, editorid, options) {
  31  
  32      if (!M.editor_tinymce.initialised) {
  33          // Load all language strings for all plugins - we do not use standard TinyMCE lang pack loading!
  34          tinymce.ScriptLoader.add(M.cfg.wwwroot + '/lib/editor/tinymce/all_strings.php?elanguage=' + options.language + '&rev=' + options.langrev);
  35  
  36          // Monkey patch for MDL-35284 - this hack ignores empty toolbars.
  37          tinymce.ui.Toolbar.prototype.oldRenderHTML = tinymce.ui.Toolbar.prototype.renderHTML;
  38          tinymce.ui.Toolbar.prototype.renderHTML = function() {
  39              if (this.controls.length == 0) {
  40                  return;
  41              }
  42              return tinymce.ui.Toolbar.prototype.oldRenderHTML.call(this);
  43          };
  44  
  45          M.editor_tinymce.initialised = true;
  46          M.util.js_pending('editors');
  47          options.oninit = "M.editor_tinymce.init_callback";
  48      }
  49  
  50      M.editor_tinymce.editor_options[editorid] = options;
  51  
  52      // Load necessary Moodle plugins into editor.
  53      if (options.moodle_init_plugins) {
  54          var extraplugins = options.moodle_init_plugins.split(',');
  55          for (var i=0; i<extraplugins.length; i++) {
  56              var filedetails = extraplugins[i].split(':');
  57              tinyMCE.PluginManager.load(filedetails[0],
  58                  M.cfg.wwwroot + '/lib/editor/tinymce/plugins/' + filedetails[1]);
  59          }
  60      }
  61  
  62      // We have to override the editor setup to work around a bug in iOS browsers - MDL-36803.
  63      if (Y.UA.ios) {
  64          // Retain any setup which is already defined.
  65          options.originalSetupFunction = options.setup || function(){};
  66          options.setup = function(editor) {
  67              options.originalSetupFunction();
  68              editor.onPostRender.add(function(ed) {
  69                  // Whenever there is a keydown event, ensure that the contentWindow still have focus.
  70                  ed.contentDocument.addEventListener('keydown', function() {
  71                      ed.contentWindow.focus();
  72                  });
  73  
  74                  // Whenever a touch event is registered against the content document,
  75                  // reapply focus. This works around an issue with the location caret not
  76                  // being focusable without use of the Loupe.
  77                  ed.contentDocument.addEventListener('touchend', function() {
  78                      ed.contentWindow.focus();
  79                  });
  80              });
  81          };
  82      }
  83      tinyMCE.init(options);
  84  
  85      var item = document.getElementById(editorid+'_filemanager');
  86      if (item) {
  87          item.parentNode.removeChild(item);
  88      }
  89  };
  90  
  91  M.editor_tinymce.init_callback = function() {
  92      M.util.js_complete('editors');
  93  }
  94  
  95  M.editor_tinymce.init_filepicker = function(Y, editorid, options) {
  96      M.editor_tinymce.filepicker_options[editorid] = options;
  97  };
  98  
  99  M.editor_tinymce.toggle = function(id) {
 100      tinyMCE.execCommand('mceToggleEditor', false, id);
 101  };
 102  
 103  M.editor_tinymce.filepicker_callback = function(args) {
 104  };
 105  
 106  M.editor_tinymce.filepicker = function(target_id, url, type, win) {
 107      YUI().use('core_filepicker', function (Y) {
 108          var editor_id = tinyMCE.selectedInstance.editorId;
 109          if (editor_id == 'mce_fullscreen') {
 110              editor_id = tinyMCE.selectedInstance.settings.elements;
 111          }
 112          var options = null;
 113          if (type == 'media') {
 114              // When media button clicked.
 115              options = M.editor_tinymce.filepicker_options[editor_id]['media'];
 116          } else if (type == 'file') {
 117              // When link button clicked.
 118              options = M.editor_tinymce.filepicker_options[editor_id]['link'];
 119          } else if (type == 'image') {
 120              // When image button clicked.
 121              options = M.editor_tinymce.filepicker_options[editor_id]['image'];
 122          }
 123  
 124          options.formcallback = M.editor_tinymce.filepicker_callback;
 125          options.editor_target = win.document.getElementById(target_id);
 126  
 127          M.core_filepicker.show(Y, options);
 128      });
 129  };
 130  
 131  M.editor_tinymce.onblur_event = function(ed) {
 132      // Attach event only after tinymce is initialized.
 133      if (ed.onInit != undefined) {
 134          var s = ed.settings;
 135          // Save before event is attached, so that if this event is not generated then textarea should
 136          // have loaded contents and submitting form should not throw error.
 137          ed.save();
 138  
 139          // Attach blur event for tinymce to save contents to textarea.
 140          var doc = s.content_editable ? ed.getBody() : (tinymce.isGecko ? ed.getDoc() : ed.getWin());
 141          tinymce.dom.Event.add(doc, 'blur', function() {
 142              // Save contents to textarea before calling validation script.
 143              ed.save();
 144          });
 145      };
 146  };


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1