-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
237 lines (208 loc) · 8.36 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
(function() {
var globalSchemaIdentifier;
var windowTitle = 'WebSpellChecker';
var wscSizes = {
minWidth: 514,
minHeight: 534
};
var languages = {
'da': 'da_DK',
'de': 'de_DE',
'el': 'el_GR',
'en': 'en_US',
'es': 'es_ES',
'fi': 'fi_FI',
'fr': 'fr_FR',
'it': 'it_IT',
'nb': 'nb_NO',
'nl': 'nl_NL',
'pt': 'pt_PT',
'sv': 'sv_SE'
};
// allow to load wsc lang pack
if(!tinymce.settings.language) {
tinymce.settings.language = 'en';
}
if(!tinymce.settings.language_load) {
tinymce.settings.language_load = true;
}
// Load plugin specific language pack
tinymce.PluginManager.requireLangPack('wsc');
// Create WSC plugin
tinymce.create('tinymce.plugins.wsc', {
init : function(editor, url) {
var that = this;
// basic settings
var settings = {};
settings.wscCorePath = window.WSCCorePath;
settings.customerId = editor.getParam('wsc_customerId', '');
settings.customerIdParam = (settings.customerId) ? '&customerid=' + settings.customerId : '';
settings.lang = editor.getParam('wsc_lang', that._getCurrentTinyMCEIntLang(editor));
settings.ctrl = editor.id;
settings.cmd = editor.getParam('wsc_cmd', '');
settings.intLang = editor.getParam('wsc_intLang', that._getCurrentTinyMCEIntLang(editor));
settings.userDictionaryName = editor.getParam('wsc_userDictionaryName', '');
settings.customDictionaryName = editor.getParam('wsc_customDictionaryName', '');
// prevent from executing two different lf on the same page
if(!globalSchemaIdentifier) {
globalSchemaIdentifier = editor.getParam('wsc_schemaIdentifier', 18);
}
settings.schemaIdentifier = globalSchemaIdentifier;
settings.width = editor.getParam('wsc_width', wscSizes.minWidth);
settings.height = editor.getParam('wsc_height', wscSizes.minHeight);
settings.top = editor.getParam('wsc_top', 0);
settings.left = editor.getParam('wsc_left', 0);
settings.title = editor.getParam('wsc_popup_title', windowTitle);
settings.autoClose = editor.getParam('wsc_autoClose', '');
settings.domainName = editor.getParam('wsc_domainName', '');
settings.schemaURI = editor.getParam('wsc_schemaURI', '');
settings.onCancel = editor.getParam('wsc_popup_cancel', function(){});
settings.onFinish = editor.getParam('wsc_popup_finish', function(){});
settings.onClose = editor.getParam('wsc_popup_close', function(){});
settings.wscCoreURL = settings.wscCorePath + 'wsc&schema=' + settings.schemaIdentifier + settings.customerIdParam ;
for(var key in settings) {
if(settings[key] === '') {
delete settings[key];
}
}
// Register commands
editor.addCommand('mceWSC', function() {
that._initializeWSC(editor, settings, url);
});
editor.addCommand('wscRunInsideModal', function(ui, value) {
that._runInsideModalWindow(editor, settings, value);
});
editor.addCommand('wscResizeWSCWindow', function(ui, value) {
that._resizeWSCWindow(editor, settings, value);
});
// Register spell check button
var wscBtnIcoPath = editor.baseURI.source + '/plugins/wsc/img/btn_wsc_tinymce.gif';
editor.addButton('wsc', {
title : 'WebSpellChecker',
cmd: 'mceWSC',
image: wscBtnIcoPath
});
},
// Init WSC service
_initializeWSC: function(editor, settings, url) {
var that = this;
// load script via tinymce api
var scriptLoader = new tinymce.dom.ScriptLoader();
scriptLoader.loadScripts([ settings.wscCoreURL ], function() {
that._openWindow(editor, settings, url);
});
},
// Open WSC window
_openWindow: function(editor, settings, url) {
var el = document.getElementById(editor.id);
var _onFinish = settings.onFinish;
var _onCancel = settings.onCancel;
// if there is active modal window - close it
if(editor.wscDialogWindow) {
editor.wscDialogWindow.close();
}
// prevent callbacks rewriting
if(!settings._callbacksChanged) {
settings._callbacksChanged = true;
settings.onFinish = function(mCtrl) {
// Set changed content back to editor
editor.setContent(mCtrl.value);
// since tinymce doesn't save snapeshot after setting content through its method 'setContent'
editor.save();
if(editor.wscDialogWindow) {
editor.wscDialogWindow.close();
}
if(typeof _onFinish === 'function') {
_onFinish(mCtrl);
}
};
settings.onCancel = function() {
if(editor.wscDialogWindow) {
editor.wscDialogWindow.close();
}
if(typeof _onCancel === 'function') {
_onCancel();
}
};
}
// Set editors content to hidden control
el.value = editor.getContent();
// for 118 schema we need to use tinymce dialogs manager
if(settings.schemaIdentifier == 118 && el.value !== '') {
if(window.DragHandler) {
window.DragHandler.attach = function() {};
window.DragHandler.updateWindowSize = function() {};
window.DragHandler.resetElement = function() {};
window.DragHandler.initView = function() {};
}
editor.wscDialogWindow = editor.windowManager.open({
title: settings.title,
width: settings.width,
height: settings.height,
resizable: true,
maximizable: false,
body: [],
buttons: [],
onpostrender: function() {
setTimeout(function() {
editor.execCommand('wscRunInsideModal', false, editor.wscDialogWindow);
editor.execCommand('wscResizeWSCWindow', false, editor.wscDialogWindow);
}, 0);
}
});
} else {
window.WSC.doSpell(settings);
}
},
_runInsideModalWindow: function(editor, settings, value) {
window.WSC.doSpell(settings);
// find elements
editor.plugins.wsc._wscInfo = {};
editor.plugins.wsc._wscInfo.modalWindowWrapper = document.getElementById('webspellchecker-modal-window-wrapper');
editor.plugins.wsc._wscInfo.modalWindowHeader = document.getElementById('webspellchecker-modal-header');
editor.plugins.wsc._wscInfo.modalWindow = document.getElementById('webspellchecker-modal-window');
editor.plugins.wsc._wscInfo.modalWindowIframe = editor.plugins.wsc._wscInfo.modalWindow.children[0] || editor.plugins.wsc._wscInfo.modalWindow;
editor.plugins.wsc._wscInfo.contentArea = document.getElementById(value._id + '-body');
// set wsc modal window inside of tinymce dialog
editor.plugins.wsc._wscInfo.contentArea.appendChild(editor.plugins.wsc._wscInfo.modalWindowWrapper);
// remove waste elements
var wscModalBg = document.getElementById('webspellchecker-modal-bg');
var wscResize = document.getElementById('webspellchecker-wsc_resize');
var wscCloseBtn = document.getElementById('webspellchecker-closeButton');
if(wscModalBg) {
tinyMCE.DOM.remove(wscModalBg);
}
if(wscResize) {
tinyMCE.DOM.remove(wscResize);
}
if(wscCloseBtn) {
tinyMCE.DOM.remove(wscCloseBtn);
}
},
_resizeWSCWindow: function(editor, settings, value) {
var newWidth = (parseInt(tinymce.DOM.getStyle(editor.plugins.wsc._wscInfo.contentArea, 'width', true), 10) || 0) - 2; // minus border width
var newHeight = (parseInt(tinymce.DOM.getStyle(editor.plugins.wsc._wscInfo.contentArea, 'height', true), 10) || 0) - 2; // minus border width
var wscHeaderHeight = editor.plugins.wsc._wscInfo.modalWindowHeader.clientHeight + (parseInt(tinymce.DOM.getStyle(editor.plugins.wsc._wscInfo.modalWindow, 'marginTop', true), 10) || 0);
// resize wsc window wrapper
editor.plugins.wsc._wscInfo.modalWindowWrapper.style.width = newWidth + 'px';
editor.plugins.wsc._wscInfo.modalWindowWrapper.style.height = newHeight + 'px';
// resize wsc window
editor.plugins.wsc._wscInfo.modalWindow.style.marginLeft = '0';
editor.plugins.wsc._wscInfo.modalWindow.style.width = '100%';
editor.plugins.wsc._wscInfo.modalWindow.style.height = (newHeight - wscHeaderHeight) + 'px';
// resize wsc iframe
editor.plugins.wsc._wscInfo.modalWindowIframe.style.width = '100%';
editor.plugins.wsc._wscInfo.modalWindowIframe.style.height = '100%';
},
_getCurrentTinyMCEIntLang: function(editor) {
var currIntLang = editor.settings.language;
currIntLang = languages[currIntLang];
if(!currIntLang) {
currIntLang = 'en_US';
}
return currIntLang;
}
});
// Register plugin with a short name
tinymce.PluginManager.add('wsc', tinymce.plugins.wsc);
}());