1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
6fd71452
|
Julien Enselme
|
if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
|
6 |
|
|
window.CKEDITOR_BASEPATH = Drupal.settings.ckeditor.editor_path;
|
7 |
|
|
}
|
8 |
85ad3d82
|
Assos Assos
|
(function ($) {
|
9 |
|
|
Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined');
|
10 |
|
|
Drupal.ckeditor_ver = false;
|
11 |
|
|
|
12 |
|
|
Drupal.ckeditorToggle = function(textarea_ids, TextTextarea, TextRTE){
|
13 |
|
|
if (!CKEDITOR.env.isCompatible) {
|
14 |
|
|
return;
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
for (i=0; i<textarea_ids.length; i++){
|
18 |
|
|
if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[textarea_ids[i]]) != 'undefined'){
|
19 |
|
|
Drupal.ckeditorOff(textarea_ids[i]);
|
20 |
6fd71452
|
Julien Enselme
|
$('#switch_' + textarea_ids[i]).text(TextRTE);
|
21 |
85ad3d82
|
Assos Assos
|
}
|
22 |
|
|
else {
|
23 |
|
|
Drupal.ckeditorOn(textarea_ids[i]);
|
24 |
6fd71452
|
Julien Enselme
|
$('#switch_' + textarea_ids[i]).text(TextTextarea);
|
25 |
85ad3d82
|
Assos Assos
|
}
|
26 |
|
|
}
|
27 |
|
|
};
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
Drupal.ckeditorInit = function(textarea_id) {
|
35 |
|
|
var ckeditor_obj = Drupal.settings.ckeditor;
|
36 |
|
|
$("#" + textarea_id).next(".grippie").css("display", "none");
|
37 |
|
|
$("#" + textarea_id).addClass("ckeditor-processed");
|
38 |
|
|
|
39 |
|
|
var textarea_settings = false;
|
40 |
|
|
ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]].toolbar = eval(ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]].toolbar);
|
41 |
|
|
textarea_settings = ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]];
|
42 |
|
|
|
43 |
|
|
var drupalTopToolbar = $('#toolbar, #admin-menu', Drupal.overlayChild ? window.parent.document : document);
|
44 |
|
|
|
45 |
|
|
textarea_settings['on'] =
|
46 |
|
|
{
|
47 |
|
|
configLoaded : function(ev)
|
48 |
|
|
{
|
49 |
|
|
Drupal.ckeditor_ver = CKEDITOR.version.split('.')[0];
|
50 |
|
|
if (Drupal.ckeditor_ver == 3) {
|
51 |
|
|
ev.editor.addCss(ev.editor.config.extraCss);
|
52 |
|
|
}
|
53 |
|
|
else {
|
54 |
|
|
CKEDITOR.addCss(ev.editor.config.extraCss);
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
ev.editor.on('change', function(ev) {
|
58 |
|
|
$(ev.editor.element.$).trigger('change');
|
59 |
|
|
});
|
60 |
|
|
ev.editor.on('blur', function(ev) {
|
61 |
|
|
$(ev.editor.element.$).trigger('blur');
|
62 |
|
|
});
|
63 |
|
|
ev.editor.on('focus', function(ev) {
|
64 |
|
|
$(ev.editor.element.$).trigger('click');
|
65 |
|
|
});
|
66 |
|
|
},
|
67 |
|
|
instanceReady : function(ev)
|
68 |
|
|
{
|
69 |
|
|
var body = $(ev.editor.document.$.body);
|
70 |
|
|
if (typeof(ev.editor.dataProcessor.writer.setRules) != 'undefined') {
|
71 |
|
|
ev.editor.dataProcessor.writer.setRules('p', {
|
72 |
|
|
breakAfterOpen: false
|
73 |
|
|
});
|
74 |
|
|
|
75 |
|
|
if (typeof(ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]].custom_formatting) != 'undefined') {
|
76 |
|
|
var dtd = CKEDITOR.dtd;
|
77 |
|
|
for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
|
78 |
|
|
ev.editor.dataProcessor.writer.setRules( e, ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]].custom_formatting);
|
79 |
|
|
}
|
80 |
|
|
ev.editor.dataProcessor.writer.setRules( 'pre',
|
81 |
|
|
{
|
82 |
|
|
indent: ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]].output_pre_indent
|
83 |
|
|
});
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
if (ev.editor.config.bodyClass)
|
88 |
|
|
body.addClass(ev.editor.config.bodyClass);
|
89 |
|
|
if (ev.editor.config.bodyId)
|
90 |
|
|
body.attr('id', ev.editor.config.bodyId);
|
91 |
|
|
if (typeof(Drupal.smileysAttach) != 'undefined' && typeof(ev.editor.dataProcessor.writer) != 'undefined')
|
92 |
|
|
ev.editor.dataProcessor.writer.indentationChars = ' ';
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
((ev.editor.editable && ev.editor.editable()) || ev.editor.document.getBody()).on( 'keyup', function() {
|
96 |
|
|
$(ev.editor.element.$).trigger('keyup');
|
97 |
|
|
});
|
98 |
|
|
((ev.editor.editable && ev.editor.editable()) || ev.editor.document.getBody()).on( 'keydown', function() {
|
99 |
|
|
$(ev.editor.element.$).trigger('keydown');
|
100 |
|
|
});
|
101 |
|
|
},
|
102 |
|
|
focus : function(ev)
|
103 |
|
|
{
|
104 |
|
|
Drupal.ckeditorInstance = ev.editor;
|
105 |
|
|
Drupal.ckeditorActiveId = ev.editor.name;
|
106 |
|
|
},
|
107 |
|
|
afterCommandExec: function(ev)
|
108 |
|
|
{
|
109 |
|
|
if (ev.data.name != 'maximize') {
|
110 |
|
|
return;
|
111 |
|
|
}
|
112 |
|
|
if (ev.data.command.state == CKEDITOR.TRISTATE_ON) {
|
113 |
|
|
drupalTopToolbar.hide();
|
114 |
|
|
} else {
|
115 |
|
|
drupalTopToolbar.show();
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
};
|
119 |
|
|
|
120 |
|
|
if (typeof Drupal.settings.ckeditor.scayt_language != 'undefined'){
|
121 |
|
|
textarea_settings['scayt_sLang'] = Drupal.settings.ckeditor.scayt_language;
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
if (typeof textarea_settings['js_conf'] != 'undefined'){
|
125 |
|
|
for (var add_conf in textarea_settings['js_conf']){
|
126 |
|
|
textarea_settings[add_conf] = eval(textarea_settings['js_conf'][add_conf]);
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
if (textarea_settings.width == '100%') textarea_settings.width = '';
|
132 |
|
|
|
133 |
|
|
if (CKEDITOR.loadFullCore) {
|
134 |
|
|
CKEDITOR.on('loaded', function() {
|
135 |
|
|
textarea_settings = Drupal.ckeditorLoadPlugins(textarea_settings);
|
136 |
|
|
Drupal.ckeditorInstance = CKEDITOR.replace(textarea_id, textarea_settings);
|
137 |
|
|
});
|
138 |
|
|
CKEDITOR.loadFullCore();
|
139 |
|
|
}
|
140 |
|
|
else {
|
141 |
|
|
textarea_settings = Drupal.ckeditorLoadPlugins(textarea_settings);
|
142 |
|
|
Drupal.ckeditorInstance = CKEDITOR.replace(textarea_id, textarea_settings);
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
Drupal.ckeditorOn = function(textarea_id, run_filter) {
|
147 |
|
|
|
148 |
|
|
run_filter = typeof(run_filter) != 'undefined' ? run_filter : true;
|
149 |
|
|
|
150 |
|
|
if (typeof(textarea_id) == 'undefined' || textarea_id.length == 0 || $("#" + textarea_id).length == 0) {
|
151 |
|
|
return;
|
152 |
|
|
}
|
153 |
|
|
if ((typeof(Drupal.settings.ckeditor.load_timeout) == 'undefined') && (typeof(CKEDITOR.instances[textarea_id]) != 'undefined')) {
|
154 |
|
|
return;
|
155 |
|
|
}
|
156 |
|
|
if (typeof(Drupal.settings.ckeditor.elements[textarea_id]) == 'undefined') {
|
157 |
|
|
return;
|
158 |
|
|
}
|
159 |
|
|
var ckeditor_obj = Drupal.settings.ckeditor;
|
160 |
|
|
|
161 |
|
|
if (!CKEDITOR.env.isCompatible) {
|
162 |
|
|
return;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
if (run_filter && ($("#" + textarea_id).val().length > 0) && typeof(ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]) != 'undefined' && ((ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]['ss'] == 1 && typeof(Drupal.settings.ckeditor.autostart) != 'undefined' && typeof(Drupal.settings.ckeditor.autostart[textarea_id]) != 'undefined') || ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]['ss'] == 2)) {
|
166 |
|
|
$.ajax({
|
167 |
|
|
type: 'POST',
|
168 |
|
|
url: Drupal.settings.ckeditor.xss_url,
|
169 |
|
|
async: false,
|
170 |
|
|
data: {
|
171 |
|
|
text: $('#' + textarea_id).val(),
|
172 |
|
|
input_format: ckeditor_obj.textarea_default_format[textarea_id],
|
173 |
|
|
token: Drupal.settings.ckeditor.ajaxToken
|
174 |
|
|
},
|
175 |
|
|
success: function(text){
|
176 |
|
|
$("#" + textarea_id).val(text);
|
177 |
|
|
Drupal.ckeditorInit(textarea_id);
|
178 |
|
|
}
|
179 |
|
|
})
|
180 |
|
|
}
|
181 |
|
|
else {
|
182 |
|
|
Drupal.ckeditorInit(textarea_id);
|
183 |
|
|
}
|
184 |
|
|
};
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
Drupal.ckeditorOff = function(textarea_id) {
|
192 |
|
|
if (!CKEDITOR.instances || typeof(CKEDITOR.instances[textarea_id]) == 'undefined') {
|
193 |
|
|
return;
|
194 |
|
|
}
|
195 |
|
|
if (!CKEDITOR.env.isCompatible) {
|
196 |
|
|
return;
|
197 |
|
|
}
|
198 |
|
|
if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id)
|
199 |
|
|
delete Drupal.ckeditorInstance;
|
200 |
|
|
|
201 |
|
|
$("#" + textarea_id).val(CKEDITOR.instances[textarea_id].getData());
|
202 |
|
|
CKEDITOR.instances[textarea_id].destroy(true);
|
203 |
|
|
|
204 |
|
|
$("#" + textarea_id).next(".grippie").css("display", "block");
|
205 |
|
|
};
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
Drupal.ckeditorLoadPlugins = function(textarea_settings) {
|
213 |
|
|
if (typeof(textarea_settings.extraPlugins) == 'undefined') {
|
214 |
|
|
textarea_settings.extraPlugins = '';
|
215 |
|
|
}
|
216 |
|
|
if (typeof CKEDITOR.plugins != 'undefined') {
|
217 |
|
|
for (var plugin in textarea_settings['loadPlugins']) {
|
218 |
4b706e38
|
Assos Assos
|
textarea_settings.extraPlugins += (textarea_settings.extraPlugins) ? ',' + textarea_settings['loadPlugins'][plugin]['name'] : textarea_settings['loadPlugins'][plugin]['name'];
|
219 |
|
|
CKEDITOR.plugins.addExternal(textarea_settings['loadPlugins'][plugin]['name'], textarea_settings['loadPlugins'][plugin]['path']);
|
220 |
85ad3d82
|
Assos Assos
|
}
|
221 |
|
|
}
|
222 |
|
|
return textarea_settings;
|
223 |
4b706e38
|
Assos Assos
|
};
|
224 |
85ad3d82
|
Assos Assos
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
Drupal.ckeditorCompareVersion = function (version){
|
229 |
|
|
var ckver = CKEDITOR.version;
|
230 |
|
|
ckver = ckver.match(/(([\d]\.)+[\d]+)/i);
|
231 |
|
|
version = version.match(/((\d+\.)+[\d]+)/i);
|
232 |
|
|
ckver = ckver[0].split('.');
|
233 |
|
|
version = version[0].split('.');
|
234 |
|
|
for (var x in ckver) {
|
235 |
|
|
if (ckver[x]<version[x]) {
|
236 |
|
|
return false;
|
237 |
|
|
}
|
238 |
|
|
else if (ckver[x]>version[x]) {
|
239 |
|
|
return true;
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
return true;
|
243 |
|
|
};
|
244 |
|
|
|
245 |
|
|
Drupal.ckeditorInsertHtml = function(html) {
|
246 |
|
|
if (!Drupal.ckeditorInstance)
|
247 |
|
|
return false;
|
248 |
|
|
|
249 |
|
|
if (Drupal.ckeditorInstance.mode == 'wysiwyg') {
|
250 |
|
|
Drupal.ckeditorInstance.insertHtml(html);
|
251 |
|
|
return true;
|
252 |
|
|
}
|
253 |
|
|
else {
|
254 |
|
|
alert(Drupal.t('Content can only be inserted into CKEditor in the WYSIWYG mode.'));
|
255 |
|
|
return false;
|
256 |
|
|
}
|
257 |
|
|
};
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
if (typeof(Drupal.Ajax) != 'undefined' && typeof(Drupal.Ajax.plugins) != 'undefined') {
|
263 |
|
|
Drupal.Ajax.plugins.CKEditor = function(hook, args) {
|
264 |
|
|
if (hook === 'submit' && typeof(CKEDITOR.instances) != 'undefined') {
|
265 |
|
|
for (var i in CKEDITOR.instances)
|
266 |
|
|
CKEDITOR.instances[i].updateElement();
|
267 |
|
|
}
|
268 |
|
|
return true;
|
269 |
|
|
};
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
Drupal.ckeditorSubmitAjaxForm = function () {
|
274 |
|
|
if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances['edit-body']) != 'undefined') {
|
275 |
|
|
Drupal.ckeditorOff('edit-body');
|
276 |
|
|
}
|
277 |
|
|
};
|
278 |
|
|
|
279 |
6fd71452
|
Julien Enselme
|
function attachCKEditor(context) {
|
280 |
|
|
|
281 |
|
|
if (Drupal.behaviors.textarea && Drupal.behaviors.textarea.attach) {
|
282 |
|
|
Drupal.behaviors.textarea.attach(context);
|
283 |
|
|
}
|
284 |
85ad3d82
|
Assos Assos
|
|
285 |
6fd71452
|
Julien Enselme
|
$(context).find("textarea.ckeditor-mod:not(.ckeditor-processed)").each(function () {
|
286 |
|
|
var ta_id=$(this).attr("id");
|
287 |
|
|
if (CKEDITOR.instances && typeof(CKEDITOR.instances[ta_id]) != 'undefined'){
|
288 |
|
|
Drupal.ckeditorOff(ta_id);
|
289 |
85ad3d82
|
Assos Assos
|
}
|
290 |
|
|
|
291 |
6fd71452
|
Julien Enselme
|
if ((typeof(Drupal.settings.ckeditor.autostart) != 'undefined') && (typeof(Drupal.settings.ckeditor.autostart[ta_id]) != 'undefined')) {
|
292 |
|
|
Drupal.ckeditorOn(ta_id);
|
293 |
|
|
}
|
294 |
85ad3d82
|
Assos Assos
|
|
295 |
6fd71452
|
Julien Enselme
|
if (typeof(Drupal.settings.ckeditor.input_formats[Drupal.settings.ckeditor.elements[ta_id]]) != 'undefined') {
|
296 |
|
|
$('.ckeditor_links').show();
|
297 |
|
|
}
|
298 |
85ad3d82
|
Assos Assos
|
|
299 |
6fd71452
|
Julien Enselme
|
var sel_format = $("#" + ta_id.substr(0, ta_id.lastIndexOf("-")) + "-format--2");
|
300 |
|
|
if (sel_format && sel_format.not('.ckeditor-processed')) {
|
301 |
|
|
sel_format.addClass('ckeditor-processed').change(function() {
|
302 |
|
|
Drupal.settings.ckeditor.elements[ta_id] = $(this).val();
|
303 |
|
|
if (CKEDITOR.instances && typeof(CKEDITOR.instances[ta_id]) != 'undefined') {
|
304 |
|
|
$('#'+ta_id).val(CKEDITOR.instances[ta_id].getData());
|
305 |
|
|
}
|
306 |
|
|
Drupal.ckeditorOff(ta_id);
|
307 |
|
|
if (typeof(Drupal.settings.ckeditor.input_formats[$(this).val()]) != 'undefined'){
|
308 |
|
|
if ($('#'+ta_id).hasClass('ckeditor-processed')) {
|
309 |
|
|
Drupal.ckeditorOn(ta_id, false);
|
310 |
85ad3d82
|
Assos Assos
|
}
|
311 |
|
|
else {
|
312 |
6fd71452
|
Julien Enselme
|
Drupal.ckeditorOn(ta_id);
|
313 |
85ad3d82
|
Assos Assos
|
}
|
314 |
6fd71452
|
Julien Enselme
|
$('#switch_'+ta_id).show();
|
315 |
|
|
}
|
316 |
|
|
else {
|
317 |
|
|
$('#switch_'+ta_id).hide();
|
318 |
|
|
}
|
319 |
|
|
});
|
320 |
|
|
}
|
321 |
|
|
});
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
Drupal.behaviors.ckeditor = {
|
328 |
|
|
attach:
|
329 |
|
|
function (context) {
|
330 |
|
|
|
331 |
|
|
if ((typeof(CKEDITOR) == 'undefined') && Drupal.settings.ckeditor.editor_path.match(/^(http(s)?:)?\/\//i)) {
|
332 |
|
|
if (typeof(Drupal.settings.ckeditor.loadAttempts) == 'undefined') {
|
333 |
|
|
Drupal.settings.ckeditor.loadAttempts = 50;
|
334 |
85ad3d82
|
Assos Assos
|
}
|
335 |
6fd71452
|
Julien Enselme
|
if (Drupal.settings.ckeditor.loadAttempts > 0) {
|
336 |
|
|
Drupal.settings.ckeditor.loadAttempts--;
|
337 |
|
|
window.setTimeout(function() {
|
338 |
|
|
Drupal.behaviors.ckeditor.attach(context);
|
339 |
|
|
}, 300);
|
340 |
|
|
}
|
341 |
|
|
return;
|
342 |
|
|
}
|
343 |
|
|
if ((typeof(CKEDITOR) == 'undefined') || !CKEDITOR.env.isCompatible) {
|
344 |
|
|
return;
|
345 |
|
|
}
|
346 |
|
|
attachCKEditor(context);
|
347 |
85ad3d82
|
Assos Assos
|
},
|
348 |
|
|
detach:
|
349 |
|
|
function(context, settings, trigger){
|
350 |
|
|
$(context).find("textarea.ckeditor-mod.ckeditor-processed").each(function () {
|
351 |
|
|
var ta_id=$(this).attr("id");
|
352 |
|
|
if (CKEDITOR.instances[ta_id])
|
353 |
|
|
$('#'+ta_id).val(CKEDITOR.instances[ta_id].getData());
|
354 |
|
|
if(trigger != 'serialize') {
|
355 |
|
|
Drupal.ckeditorOff(ta_id);
|
356 |
|
|
$(this).removeClass('ckeditor-processed');
|
357 |
|
|
}
|
358 |
|
|
});
|
359 |
|
|
}
|
360 |
|
|
};
|
361 |
6fd71452
|
Julien Enselme
|
|
362 |
|
|
|
363 |
|
|
$(document).bind('CToolsDetachBehaviors', function(event, context) {
|
364 |
|
|
Drupal.behaviors.ckeditor.detach(context, {}, 'unload');
|
365 |
|
|
});
|
366 |
85ad3d82
|
Assos Assos
|
})(jQuery);
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
var ckeditor_imceSendTo = function (file, win){
|
372 |
|
|
var cfunc = win.location.href.split('&');
|
373 |
|
|
|
374 |
|
|
for (var x in cfunc) {
|
375 |
|
|
if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) {
|
376 |
|
|
cfunc = cfunc[x].split('=');
|
377 |
|
|
break;
|
378 |
|
|
}
|
379 |
|
|
}
|
380 |
|
|
CKEDITOR.tools.callFunction(cfunc[1], file.url);
|
381 |
|
|
win.close();
|
382 |
|
|
}
|