aboutsummaryrefslogtreecommitdiff
path: root/mod/ckeditor/views/default/js/ckeditor.php
blob: 9e02496ac7ffad0f9661b50bd92fe20302be7122 (plain)
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
<?php
/**
 * CKEditor JavaScript
 */

$css_url = elgg_get_simplecache_url('css', 'wysiwyg');

?>
elgg.provide('elgg.ckeditor');

/**
 * Toggles the CKEditor
 *
 * @param {Object} event
 * @return void
 */
elgg.ckeditor.toggleEditor = function(event) {
	event.preventDefault();
	
	var target = $(this).attr('href').substr(1);

	if (!CKEDITOR.instances[target]) {
		CKEDITOR.replace($('#'+target)[0], elgg.ckeditor.config).on('key', elgg.ckeditor.wordCount);
		$(this).html(elgg.echo('ckeditor:remove'));
	} else {
		CKEDITOR.instances[target].destroy();
		$(this).html(elgg.echo('ckeditor:add'));
	}
}

/**
 * Counts the number of words into an editor
 *
 * @param {Object} event
 * @return void
 */
elgg.ckeditor.wordCount = function(evt) {
	var matches = evt.editor.getData().replace(/<[^<|>]+?>|&nbsp;/gi,' ').match(/\b/g);
	var words = matches ? matches.length / 2 : 0;
	var text = elgg.echo('ckeditor:word_count') + words;
	$('.cke_wordcount', evt.editor.container.$).text(text);
}

/**
 * CKEditor configuration
 *
 * You can find configuration information here:
 * http://docs.ckeditor.com/#!/api/CKEDITOR.config
 */
elgg.ckeditor.config = {
	toolbar : [['Bold', 'Italic', 'Underline', '-', 'Strike', 'NumberedList', 'BulletedList', 'Undo', 'Redo', 'Link', 'Unlink', 'Image', 'Blockquote', 'Paste', 'PasteFromWord', 'Maximize']],
	toolbarCanCollapse : false,
	baseHref : elgg.config.wwwroot,
	extraPlugins : 'autogrow',
	removePlugins : 'contextmenu,showborders,tabletools,resize',
	uiColor : '#EEEEEE',
	contentsCss : '<?php echo $css_url; ?>',
	disableNativeSpellChecker : false,
	removeDialogTabs: 'image:advanced;image:Link;link:advanced;link:target',
	autoGrow_maxHeight : 800,
};

elgg.ckeditor.init = function() {

	elgg.ckeditor.config.language = elgg.get_language();

	$('.ckeditor-toggle-editor').live('click', elgg.ckeditor.toggleEditor);
	$('.elgg-input-longtext').each(function() {
		CKEDITOR.replace(this, elgg.ckeditor.config).on('key', elgg.ckeditor.wordCount);
	});
	CKEDITOR.on('instanceReady', function(evt) {
		$('.cke_bottom', evt.editor.container.$).prepend('<div class="cke_wordcount" />');
		elgg.ckeditor.wordCount(evt);
	});
}

elgg.register_hook_handler('init', 'system', elgg.ckeditor.init);