Projet

Général

Profil

Paste
Télécharger (2,19 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / plugins / imce / plugin.js @ 6fd71452

1
/*
2
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
3
For licensing, see LICENSE.html or http://ckeditor.com/license
4
*/
5

    
6
/**
7
 * @file Plugin for inserting files from IMCE without image dialog
8
 */
9
( function() {
10
  CKEDITOR.plugins.add( 'imce',
11
  {
12
    init: function( editor )
13
    {
14
      //adding button
15
      editor.ui.addButton( 'IMCE',
16
      {
17
        label: 'IMCE',
18
        command: 'IMCEWindow',
19
        icon: this.path + 'images/icon.png'
20
      });
21

    
22
      //opening imce window
23
      editor.addCommand( 'IMCEWindow', {
24
        exec : function () {
25
          var width = editor.config.filebrowserWindowWidth || '80%',
26
          height = editor.config.filebrowserWindowHeight || '70%';
27

    
28
          editor.popup(Drupal.settings.basePath + 'index.php?q=imce\x26app=ckeditor|sendto@ckeditor_setFile|&CKEditorFuncNum=' + editor._.filebrowserFnIMCE, width, height);
29
        }
30
      });
31

    
32
      //add editor function
33
      editor._.filebrowserFnIMCE = CKEDITOR.tools.addFunction( setFile, editor );
34

    
35
      //function which receive imce response
36
      window.ckeditor_setFile = function (file, win) {
37
        var cfunc = win.location.href.split('&');
38
        for (var x in cfunc) {
39
          if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) {
40
            cfunc = cfunc[x].split('=');
41
            break;
42
          }
43
        }
44
        CKEDITOR.tools.callFunction(cfunc[1], file);
45
        win.close();
46
      };
47

    
48
    }
49
  } );
50
  function setFile(file) {
51
    var sel = this.getSelection(),
52
    text = sel.getSelectedText();
53
    if (file.width != 0 && file.height != 0) {
54
      if (text) {
55
        this.insertHtml('<a href="' + document.location.protocol + '//'+ document.location.host +  file.url + '">' + text + '</a>');
56
      } else {
57
        this.insertHtml('<img src="' + file.url + '" style="width:' + file.width + 'px;height:' + file.height + 'px;" alt="' + file.name + '" />');
58
      }
59
    } else {
60
      if (text) {
61
        this.insertHtml('<a href="' +document.location.protocol + '//'+ document.location.host + file.url + '">' + text + '</a>');
62
      } else {
63
        this.insertHtml('<a href="' + document.location.protocol + '//'+ document.location.host +  file.url + '">' + file.name + '</a>');
64
      }
65
    }
66
  }
67
} )();