ckeditor/samples/js/sample.js
author indvd00m (gotoindvdum[at]gmail[dot]com)
Thu, 15 Dec 2016 18:10:20 +0300
changeset 0 44d330dccc59
permissions -rw-r--r--
Init sample
indvd00m@0
     1
/**
indvd00m@0
     2
 * Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
indvd00m@0
     3
 * For licensing, see LICENSE.md or http://ckeditor.com/license
indvd00m@0
     4
 */
indvd00m@0
     5
indvd00m@0
     6
/* exported initSample */
indvd00m@0
     7
indvd00m@0
     8
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
indvd00m@0
     9
	CKEDITOR.tools.enableHtml5Elements( document );
indvd00m@0
    10
indvd00m@0
    11
// The trick to keep the editor in the sample quite small
indvd00m@0
    12
// unless user specified own height.
indvd00m@0
    13
CKEDITOR.config.height = 150;
indvd00m@0
    14
CKEDITOR.config.width = 'auto';
indvd00m@0
    15
indvd00m@0
    16
var initSample = ( function() {
indvd00m@0
    17
	var wysiwygareaAvailable = isWysiwygareaAvailable(),
indvd00m@0
    18
		isBBCodeBuiltIn = !!CKEDITOR.plugins.get( 'bbcode' );
indvd00m@0
    19
indvd00m@0
    20
	return function() {
indvd00m@0
    21
		var editorElement = CKEDITOR.document.getById( 'editor' );
indvd00m@0
    22
indvd00m@0
    23
		// :(((
indvd00m@0
    24
		if ( isBBCodeBuiltIn ) {
indvd00m@0
    25
			editorElement.setHtml(
indvd00m@0
    26
				'Hello world!\n\n' +
indvd00m@0
    27
				'I\'m an instance of [url=http://ckeditor.com]CKEditor[/url].'
indvd00m@0
    28
			);
indvd00m@0
    29
		}
indvd00m@0
    30
indvd00m@0
    31
		// Depending on the wysiwygare plugin availability initialize classic or inline editor.
indvd00m@0
    32
		if ( wysiwygareaAvailable ) {
indvd00m@0
    33
			CKEDITOR.replace( 'editor' );
indvd00m@0
    34
		} else {
indvd00m@0
    35
			editorElement.setAttribute( 'contenteditable', 'true' );
indvd00m@0
    36
			CKEDITOR.inline( 'editor' );
indvd00m@0
    37
indvd00m@0
    38
			// TODO we can consider displaying some info box that
indvd00m@0
    39
			// without wysiwygarea the classic editor may not work.
indvd00m@0
    40
		}
indvd00m@0
    41
	};
indvd00m@0
    42
indvd00m@0
    43
	function isWysiwygareaAvailable() {
indvd00m@0
    44
		// If in development mode, then the wysiwygarea must be available.
indvd00m@0
    45
		// Split REV into two strings so builder does not replace it :D.
indvd00m@0
    46
		if ( CKEDITOR.revision == ( '%RE' + 'V%' ) ) {
indvd00m@0
    47
			return true;
indvd00m@0
    48
		}
indvd00m@0
    49
indvd00m@0
    50
		return !!CKEDITOR.plugins.get( 'wysiwygarea' );
indvd00m@0
    51
	}
indvd00m@0
    52
} )();
indvd00m@0
    53