1
|
|
2
|
|
3
|
(function($) {
|
4
|
"use strict";
|
5
|
CKEDITOR.plugins.add('token_insert_ckeditor', {
|
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
|
};
|
13
|
|
14
|
|
15
|
CKEDITOR.dialog.add('token_insert_ckeditor_dialog', function() {
|
16
|
return {
|
17
|
title: Drupal.t('Insert token'),
|
18
|
minWidth: 250,
|
19
|
minHeight: 50,
|
20
|
contents: [
|
21
|
{
|
22
|
id: 'info',
|
23
|
label: Drupal.t('Insert a token'),
|
24
|
title: Drupal.t('Insert a token'),
|
25
|
elements: [
|
26
|
dialogcontent
|
27
|
]
|
28
|
}
|
29
|
],
|
30
|
buttons: [CKEDITOR.dialog.cancelButton],
|
31
|
onShow: function () {
|
32
|
var editor = this.getParentEditor();
|
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
|
});
|
52
|
}
|
53
|
};
|
54
|
});
|
55
|
|
56
|
|
57
|
editor.addCommand('TokenInsert', new CKEDITOR.dialogCommand('token_insert_ckeditor_dialog'));
|
58
|
|
59
|
editor.ui.addButton('TokenInsert', {
|
60
|
label: Drupal.t('Insert a token'),
|
61
|
command: 'TokenInsert',
|
62
|
icon: this.path + 'images/insert.png'
|
63
|
});
|
64
|
}
|
65
|
});
|
66
|
})(jQuery);
|
67
|
|