Projet

Général

Profil

Révision 5721e759

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/token_insert/token_insert_ckeditor/plugins/token_insert_ckeditor/plugin.js
1
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */
2
/*global Drupal:true, jQuery: true, CKEDITOR:true*/
1 3
(function($) {
4
  "use strict";
2 5
  CKEDITOR.plugins.add('token_insert_ckeditor', {
3
    init: function(editor, pluginPath) {
4
      var tokens = [];
5

  
6
      // Ajax call to get the tokens.
7
      $.getJSON(Drupal.settings.basePath + 'token_insert_ckeditor/insert', function(data) {
8
        tokens = data;
9
      });
6
    init: function(editor) {
7
      var id = 'token-insert-' + editor.id + '-dialog-container';
8
      var dialogcontent = {
9
        id: 'token_insert_ckeditor',
10
        type: 'html',
11
        html: '<div id="' + id + '"></div>'
12
      };
10 13

  
11 14
      // Register a dialog box with CKEditor.
12
      CKEDITOR.dialog.add('token_insert_ckeditor_dialog', function(editor) {
15
      CKEDITOR.dialog.add('token_insert_ckeditor_dialog', function() {
13 16
        return {
14 17
          title: Drupal.t('Insert token'),
15 18
          minWidth: 250,
......
20 23
              label: Drupal.t('Insert a token'),
21 24
              title: Drupal.t('Insert a token'),
22 25
              elements: [
23
                {
24
                  id: 'token_insert_ckeditor',
25
                  type: 'select',
26
                  items: tokens,
27
                  label: Drupal.t('Select a variable to insert:')
28
                }
26
                dialogcontent
29 27
              ]
30 28
            }
31 29
          ],
32
          onOk: function() {
30
          buttons: [CKEDITOR.dialog.cancelButton],
31
          onShow: function () {
33 32
            var editor = this.getParentEditor();
34
            var content = this.getValueOf('info', 'token_insert_ckeditor');
35
            if (content.length > 0) {
36
              editor.insertText('[' + content + ']');
37
            }
33
            var id = 'token-insert-' + editor.id + '-dialog-container';
34
            var $content = $(this.getElement('info', 'token_insert_ckeditor').$);
35
            var ajax_settings = {
36
              url: Drupal.settings.basePath + 'token_insert_ckeditor/insert/' + id,
37
              event: 'dialog.token-insert-ckeditor',
38
              method: 'html'
39
            };
40
            new Drupal.ajax(id, $content[0], ajax_settings);
41
            $content.trigger(ajax_settings.event);
42
            $content.bind('token-insert-table-loaded', function () {
43
              $(this).find('.token-insert-table .token-key').once('token-insert-table', function() {
44
                var $token_link = $(this);
45
                var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $token_link.html() + '</a>').click(function() {
46
                  var $self = $(this);
47
                  editor.insertText($self.text());
48
                });
49
                $token_link.html(newThis);
50
              });
51
            });
38 52
          }
39 53
        };
40 54
      });
41 55

  
42 56
      // Register a command with CKeditor to launch the dialog box.
43 57
      editor.addCommand('TokenInsert', new CKEDITOR.dialogCommand('token_insert_ckeditor_dialog'));
44

  
45 58
      // Add a button to the CKeditor that executes a CKeditor command.
46 59
      editor.ui.addButton('TokenInsert', {
47 60
        label: Drupal.t('Insert a token'),
......
51 64
    }
52 65
  });
53 66
})(jQuery);
67

  

Formats disponibles : Unified diff