FriendsOfREDAXO / redactor2

Integriert den Redactor WYSIWYG-Editor in Version 2
Other
54 stars 11 forks source link

Seltsamer Effekt #142

Closed dergel closed 5 years ago

dergel commented 5 years ago

Und zwar kommt es bei eigenen PlugIns vor .. Ich selektiere z.B. einen Absatz (p) und mache daraus ein Heading (z.B. h4) und behalte dann diese Selektion. Dann setze ich von meinem Plugin aus eine class. Aber die Selektion ist eine Andere/Falsche und die Ansicht zerhaut sich komplett.. Hat vielleicht auch damit zu tun, dass es Fehler gibt, wenn ich einfach auf z.B. ein Heading Klicke, ohne eine Selektion zu haben. Seltsam.

Ich löse das im Moment dadurch, dass ich die Selektion nach z.B. einen Heading entferne.

            this.block.format('h3');
            this.selection.remove();
phoebusryan commented 5 years ago

Hm, speziell. Habe selection.remove() so bisher noch nicht benutzt. Was ist denn der Sinn des Plugins? Warum muss die Selektion verworfen werden?

dergel commented 5 years ago

Ich kann nicht 100%ig erkennen warum das passiert (Beim Safari gehts, aber nicht bei Chrome). Mein Plugin sieht eigentlich easy aus .. siehe unten .. aber das Problem ist eigentlich früher, nämlich die Selektion, die wohl falsch ist bei z.B. von p zu h4...

$.Redactor.prototype.plus = function() {
    return {
            langs: {
                de: {
                    "plus": "Color",
                    "plus_insert": "Add Color"
                },
                en: {
                    "plus": "Color",
                    "plus_insert": "Add Color"
                }
            },
        init: function() {
            var button = this.button.add('plus', this.lang.get('plus'));
            this.button.setIcon(button, '<i class="fa fa-adjust"></i>');

            var that = this;
            var dropdown = {};

            dropdown.plus = { title: "no style", func: that.plus.reset };

            var elements = [
                { class: 'style-1', title: 'Orange' },
                { class: 'style-2', title: 'Red' },
                { class: 'style-3', title: 'Rose' },
                { class: 'style-4', title: 'Burgundy' },
                { class: 'style-5', title: 'Maroon' },
                { class: 'style-6', title: 'Weiss' },
                { class: 'style-7', title: 'Grau' },
            ];

            $.each(elements, function(i, s) {
                dropdown['s' + i] = {
                    title: '<div class="'+s.class+'">'+s.title+'</div>',
                    func: function() {
                        that.plus.setClass(s.class);
                    },
                };
            });

            this.button.addDropdown(button, dropdown);

        },
        setClass: function (cssClass) {

            var $table = this.table.getTable();
            if ($table) {
                $table.removeClass().addClass(cssClass);
            } else {
                this.block.addAttr('class', cssClass);
            }

        },
        reset: function() {
            var $table = this.table.getTable();
            if ($table) {
                $table.removeClass();
            } else {
                this.block.removeAttr('class');
            }
        }
    };
};
dergel commented 5 years ago

ist ergänzt bei den headlines.. beim nächsten redactor2 release könnte es zwar wieder zerhauen sein, aber dann haben die das dort sicherlich auch gefixt