[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/editor/tinymce/plugins/managefiles/tinymce/ -> editor_plugin.js (source)

   1  /**
   2   * TinyMCE plugin ManageFiles - provides UI to edit files embedded in the text editor.
   3   *
   4   * @author  Marina Glancy
   5   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
   6   */
   7  
   8  (function() {
   9      tinymce.create('tinymce.plugins.MoodleManageFiles', {
  10          /**
  11           * Initializes the plugin, this will be executed after the plugin has been created.
  12           * This call is done before the editor instance has finished it's initialization so use the onInit event
  13           * of the editor instance to intercept that event.
  14           *
  15           * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
  16           * @param {string} url Absolute URL to where the plugin is located.
  17           */
  18          init : function(ed, url) {
  19              ed.addCommand('mceForceRepaint', function() {
  20                  var root = ed.dom.getRoot();
  21                  items = root.getElementsByTagName("img");
  22                  for (var i = 0; i < items.length; i++) {
  23                      src = items[i].getAttribute('src').replace(/\?\d+$/, '');
  24                      items[i].setAttribute('src', src+'?'+(new Date().getTime()))
  25                  }
  26                  ed.execCommand('mceRepaint');
  27                  ed.focus();
  28              });
  29  
  30              ed.addCommand('mceMaximizeWindow', function(w) {
  31                  // This function duplicates the TinyMCE windowManager code when 'maximize' button is pressed.
  32                  var vp = ed.dom.getViewPort(),
  33                      id = w.id;
  34                  // Reduce viewport size to avoid scrollbars
  35                  vp.w -= 2;
  36                  vp.h -= 2;
  37  
  38                  w.oldPos = w.element.getXY();
  39                  w.oldSize = w.element.getSize();
  40  
  41                  w.element.moveTo(vp.x, vp.y);
  42                  w.element.resizeTo(vp.w, vp.h);
  43                  ed.dom.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
  44                  ed.dom.addClass(id + '_wrapper', 'mceMaximized');
  45              });
  46  
  47              ed.addCommand('mceManageFiles', function() {
  48                  var managefiles = ed.getParam('managefiles', {}), key, cnt = 0,
  49                      fileurl = ed.getParam("moodle_plugin_base") + 'managefiles/manage.php?';
  50                  for (key in managefiles) {
  51                      fileurl += (cnt++ ? '&' : '') + encodeURIComponent(key) + "=" + encodeURIComponent(managefiles[key]) + "&";
  52                  }
  53                  var onClose = function() {
  54                     ed.windowManager.onClose.remove(onClose);
  55                     ed.execCommand('mceForceRepaint');
  56                  };
  57                  ed.windowManager.onClose.add(onClose);
  58                  var vp = ed.dom.getViewPort(),
  59                          width = 900 + parseInt(ed.getLang('advimage.delta_width', 0)),
  60                          height = 600 + parseInt(ed.getLang('advimage.delta_height', 0)),
  61                          maximizedmode = (width >= vp.w - 2 || height >= vp.h - 2);
  62                  if (maximizedmode) {
  63                      width = vp.w;
  64                      height = vp.h;
  65                  }
  66                  w = ed.windowManager.open({
  67                      file : fileurl ,
  68                      width : width,
  69                      height : height,
  70                      inline : 1
  71                  }, {
  72                      plugin_url : url // Plugin absolute URL
  73                  });
  74                  if (maximizedmode) {
  75                      ed.execCommand('mceMaximizeWindow', w);
  76                  }
  77              });
  78  
  79              ed.addCommand('mceManageFilesUsedFiles', function() {
  80                  var managefiles = ed.getParam('managefiles', {}),
  81                      text = ed.dom.getRoot().innerHTML,
  82                      base = ed.getParam('document_base_url') + '/draftfile.php/' + managefiles['usercontext'] + '/user/draft/' + managefiles['itemid'] + '/',
  83                      patt = new RegExp(base.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
  84                      arr = [], match, filename;
  85                  while ((match = patt.exec(text)) !== null) {
  86                      filename = decodeURI(match[1]);
  87                      if (arr.indexOf(filename) === -1) {
  88                          arr[arr.length] = filename;
  89                      }
  90                  }
  91                  return arr;
  92              });
  93  
  94              var managefiles = ed.getParam('managefiles', {});
  95              // Get draft area id from filepicker options.
  96              if (!managefiles.itemid && M.editor_tinymce.filepicker_options
  97                      && M.editor_tinymce.filepicker_options[ed.id]
  98                      && M.editor_tinymce.filepicker_options[ed.id].image
  99                      && M.editor_tinymce.filepicker_options[ed.id].image.itemid) {
 100                  managefiles.itemid = M.editor_tinymce.filepicker_options[ed.id].image.itemid;
 101                  ed.settings['managefiles'].itemid = managefiles.itemid;
 102              }
 103  
 104              // Register buttons
 105              if (managefiles.itemid) {
 106                  ed.addButton('managefiles', {
 107                      title : 'managefiles.desc',
 108                      cmd : 'mceManageFiles',
 109                      image : url + '/img/managefiles.png'
 110                  });
 111              }
 112          },
 113          createControl : function(n, cm) {
 114              return null;
 115          },
 116  
 117          /**
 118           * Returns information about the plugin as a name/value array.
 119           * The current keys are longname, author, authorurl, infourl and version.
 120           *
 121           * @return {Object} Name/value array containing information about the plugin.
 122           */
 123          getInfo : function() {
 124              return {
 125                  longname : 'Moodle Manage embedded files plugin',
 126                  author : 'Marina Glancy',
 127                  infourl : 'http://moodle.org',
 128                  version : "1.0"
 129              };
 130          }
 131      });
 132  
 133      // Register plugin.
 134      tinymce.PluginManager.add('managefiles', tinymce.plugins.MoodleManageFiles);
 135  })();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1