forked from faiwer/imap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
executable file
·106 lines (91 loc) · 2.38 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"use strict";
(function()
{
var plugin_name = 'imap';
var lang_list = [ 'ru', 'en' ];
if( CKEDITOR.plugins.get( plugin_name ) )
{
return false;
}
var dialog_name = plugin_name;
var command = plugin_name;
var button = command.charAt( 0 ).toUpperCase() + command.substr( 1 );
var result_class = 'site_' + plugin_name + '_anchor';
var img_class = 'cke_' + plugin_name;
var obj_kind = plugin_name;
var tag_name = 'em';
var priority = 1;
var create_fake_element = function( editor, real_el )
{
return editor.createFakeParserElement( real_el, img_class, obj_kind, true );
};
CKEDITOR.plugins.add( plugin_name,
{
requires: [ 'dialog', 'fakeobjects' ],
icons: 'imap',
hidpi: false,
lang: lang_list,
onLoad: function()
{
var css = 'img.' + img_class +
'{' +
' -moz-box-sizing: border-box;' +
' -webkit-box-sizing: border-box;' +
' box-sizing: border-box;' +
' display: block;' +
' background: url(' + this.path + 'images/placeholder.png) ' +
'no-repeat center center white;' +
' border: 1px solid #a9a9a9;' +
' min-width: 100px;' +
' min-height: 50px;' +
' margin: 5px 0 10px 0;' +
'}';
CKEDITOR.addCss( css );
},
init: function( editor )
{
var req = 'em' /* tag */ + '[!data-plugin,!width,!height]' /* attrs */ +
'(' + result_class + ')' /* classes */ +
'{width,height}' /* styles */;
editor.addCommand( command, new CKEDITOR.dialogCommand( command,
{
allowedContent: req
} ) );
editor.ui.addButton( button,
{
label: editor.lang[ plugin_name ].button_label,
command: command
} );
var dialog_path = this.path + 'dialogs/' + plugin_name + '.js';
CKEDITOR.dialog.add( dialog_name, dialog_path );
editor.on( 'doubleclick', function( e )
{
var element = e.data.element;
if( element.is('img') &&
element.data('cke-real-element-type') === obj_kind )
{
e.data.dialog = dialog_name;
}
} );
},
afterInit: function( editor )
{
var dataProcessor = editor.dataProcessor,
dataFilter = dataProcessor && dataProcessor.dataFilter;
if( ! dataFilter )
{
return;
}
var elements = {};
elements[ tag_name ] = function( el )
{
if( el.classes && el.classes.indexOf( result_class ) !== -1 )
{
return create_fake_element( editor, el );
}
return null;
};
dataFilter.addRules( { elements: elements }, priority );
}
} );
} )();