Skip to content

Keep class of element on formating #1636

Open
@bernhardriegler

Description

@bernhardriegler

IS:
When formatting an element (example: p to h1) all classes on the initial element are lost.
SHOULD:
keep classes on element change

Suggestion:
add a check if config says that classes should be kept and ensure classes are carried over to new element:
https://github.com/alohaeditor/Aloha-Editor/blob/dev/src/lib/aloha/jquery.aloha.js#L246

jQuery.fn.zap = function () {
    if(Aloha.settings && Aloha.settings.plugins && Aloha.settings.plugins.format && Aloha.settings.plugins.format.keepClass) {
        var elem = this.get(0);
        var parent = elem ? elem.parentElement : false;
        if (parent) {
            var classListWithoutRemoveClass = Array.prototype.slice.call(elem.classList).filter(function (className) {
                return className !== "preparedForRemoval"
            });
            classListWithoutRemoveClass.forEach(function (item) {
                parent.classList.add(item);
            });	
        }	
    }
    this.each(function () {
        jQuery(this.childNodes).insertBefore(this);
    }).remove();
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions