Code Monkey home page Code Monkey logo

Comments (3)

tonydspaniard avatar tonydspaniard commented on July 26, 2024

@alanwillms thank you very much for this tip! Is there a way to do that within the library? Maybe we should write a js module like I did with Editable that will handle this? Is there a way to access the button with a different selector?

from yii2-ckeditor-widget.

nirvana-msu avatar nirvana-msu commented on July 26, 2024

@tonydspaniard, this only works as long as our Upload tab is the third matched element, i.e. you only have a single widget on the page with default image plugin. It breaks if you have multiple widgets loaded or, as in my particular case, when you load the widget several times via ajax (e.g. when the user wants to edit the content). If several widgets are added without reloading the page, eq(2) matches the old Upload tab instead of the new one. It also breaks if you use a different image plugin which has a different number of tabs.

The following modification seems to be generic enough to cover multiple widgets on the same page, different languages (thanks, @mbv) and different image plugins, as long as the id of an Upload tab starts with cke_Upload_. There would also be several forms (including old ones) on the page, so it iterates over them all to add a token if missing:

yii & $(document).off('click', '.cke_dialog_tabs a[id^="cke_Upload_"]').on('click', '.cke_dialog_tabs a[id^="cke_Upload_"]', function () {
    var $forms = $('.cke_dialog_ui_input_file iframe').contents().find('form');
    var csrfName = yii.getCsrfParam();
    $forms.each(function () {
        if (!$(this).find('input[name=' + csrfName + ']').length) {
            var csrfTokenInput = $('<input/>').attr({
                'type': 'hidden',
                'name': csrfName
            }).val(yii.getCsrfToken());
            $(this).append(csrfTokenInput);
        }
    });
});

from yii2-ckeditor-widget.

tonydspaniard avatar tonydspaniard commented on July 26, 2024

@nirvana-msu do you mind providing a PR for that change? I would be more than happy to merge it (but please, make sure tests pass, I have been forced not to merge others due to that issue)

thanks!

from yii2-ckeditor-widget.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.