API Docs for: 1.0.0
Show:

File: Resources/public/js/alloyeditor/plugins/caret.js

/*
 * Copyright (C) eZ Systems AS. All rights reserved.
 * For full copyright and license information view LICENSE file distributed with this source code.
 */
/* global CKEDITOR */
YUI.add('ez-alloyeditor-plugin-caret', function (Y) {
    "use strict";

    if (CKEDITOR.plugins.get('ezcaret')) {
        return;
    }

    function moveCaretToElement(editor, element) {
        var range = editor.createRange();

        range.moveToPosition(element, CKEDITOR.POSITION_AFTER_START);
        editor.getSelection().selectRanges([range]);
    }

    function findCaretElement(element) {
        var child = element.getChild(0);

        if ( child.type !== CKEDITOR.NODE_TEXT ) {
            return findCaretElement(child);
        }
        return element;
    }

    /**
     * CKEDITOR plugin providing an API to handle the caret in the editor.
     *
     * @class ezcaret
     * @namespace CKEDITOR.plugins
     * @constructor
     */
    CKEDITOR.plugins.add('ezcaret', {
        init: function (editor) {
            editor.eZ = editor.eZ || {};

            /**
             * Moves the caret in the editor to the given element
             *
             * @method eZ.moveCaretToElement
             * @param {CKEDITOR.editor} editor
             * @param {CKEDITOR.dom.element} element
             */
            editor.eZ.moveCaretToElement = moveCaretToElement;

            /**
             * Finds the "caret element" for the given element. For some elements,
             * like ul or table, moving the caret inside them actually means finding
             * the first element that can be filled by the user.
             *
             * @method eZ.findCaretElement
             * @protected
             * @param {CKEDITOR.dom.element} element
             * @return {CKEDITOR.dom.element}
             */
            editor.eZ.findCaretElement = findCaretElement;
        },
    });
});