Ckeditor - configure styles

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
heural
Posts: 63
Joined: 09 Jun 2022, 07:55

Ckeditor - configure styles

Post by heural » 14 Mar 2023, 07:40

Hi Aimeos-Team,

how can I configure the ckeditor´s styles-dropdown?
I have activated the styles-dropdown in my custom overwrite /themes/admin/jqadm/custom.js
but it´s empty. "stylesSet" does not work, see code below.

Is the js-object "Aimeos.ckeditor" the same as "CKEDITOR.config"? (https://ckeditor.com/docs/ckeditor4/lat ... onfig.html)

Code: Select all


class MyUploadAdapter {
    constructor( loader ) {
        // CKEditor 5's FileLoader instance.
        this.loader = loader;

        // URL where to send files.
        this.url = '/typo3conf/ext/my_ext/ckeditor_imageupload.php';

    }

    // Starts the upload process.
    upload() {
        return new Promise( ( resolve, reject ) => {
            this.loader.file.then((file) => {
                this._initRequest();
                this._initListeners(resolve, reject, file);
                this._sendRequest(file);
            });
        } );
    }

    // Aborts the upload process.
    abort() {
        if ( this.xhr ) {
            this.xhr.abort();
        }
    }

    // Example implementation using XMLHttpRequest.
    _initRequest() {
        const xhr = this.xhr = new XMLHttpRequest();

        xhr.open( 'POST', this.url, true );
        xhr.responseType = 'json';
    }

    // Initializes XMLHttpRequest listeners.
    _initListeners( resolve, reject, file ) {
        const xhr = this.xhr;
        const loader = this.loader;
        const genericErrorText = 'Couldn\'t upload file:' + ` ${ file.name }.`;

        xhr.addEventListener( 'error', () => reject( genericErrorText ) );
        xhr.addEventListener( 'abort', () => reject() );
        xhr.addEventListener( 'load', () => {
            const response = xhr.response;

            if ( !response || response.error ) {
                return reject( response && response.error ? response.error.message : genericErrorText );
            }

            // If the upload is successful, resolve the upload promise with an object containing
            // at least the "default" URL, pointing to the image on the server.
            resolve( {
                default: response.url
            } );
        } );

        if ( xhr.upload ) {
            xhr.upload.addEventListener( 'progress', evt => {
                if ( evt.lengthComputable ) {
                    loader.uploadTotal = evt.total;
                    loader.uploaded = evt.loaded;
                }
            } );
        }
    }

    // Prepares the data and sends the request.
    _sendRequest(file) {
        const data = new FormData();

        data.append( 'upload', file) ;

        this.xhr.send( data );
    }
}


function MyCustomUploadAdapterPlugin( editor ) {
    editor.plugins.get( 'FileRepository' ).createUploadAdapter = ( loader ) => {
        return new MyUploadAdapter( loader );
    };
}

Aimeos.ckeditor = {
    toolbar: [
        'heading', '|',
        'link', '|',
        'bold', 'italic', 'underline', '|',
        'undo', 'redo', '|', 'style',
        'alignment', 'outDent', 'indent', '|',
        'specialCharacters', 'removeFormat', '|',
        'bulletedList', 'numberedList', '|',
        'blockQuote', '|',
        'insertTable', 'insertImage', '|',
        'sourceEditing'
    ],
    image: {
        toolbar: [
            'imageStyle:inline', 'imageStyle:wrapText', 'imageStyle:breakText', '|',
            'toggleImageCaption', 'imageTextAlternative'
        ]
    },
    extraPlugins: [MyCustomUploadAdapterPlugin],
    allowedContent: true,
    stylesSet: [
        { name: 'Button', element: 'a',  attributes: { 'class': 'btn-primary' } },
        { name: 'Special', element: 'p', styles: {color: 'blue'} }
    ]
};
Thank you!

heural
Posts: 63
Joined: 09 Jun 2022, 07:55

Re: Ckeditor - configure styles

Post by heural » 14 Mar 2023, 08:30

Ok, i´ve found it.
Instead of "stylesSet":

Code: Select all

style: {
        definitions: [
            {name: 'Button', element: 'a', classes: ['btn-primary']}
        ]
    }

Post Reply