Custom Fields
Re-Envisioned
Support General WYSIWYG clone stops working when clones are deleted

This topic contains 3 replies, has 2 voices, and was last updated by  Anh Tran 2 years, 10 months ago.

  • Creator
    Topic
  • #3427

    AdamKettani
    Participant

    When you clone a wysiwyg and then delete a preceding wysiwig. Everything falls appart.

    Anyone experiencing the same problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #3428

    AdamKettani
    Participant

    Actually, the bug happens only when you delete the first wysiwig

    #3430

    AdamKettani
    Participant

    So I found where the problem come from and found a solution:

    In wysiwyg.js in the GetOriginalId function on line 54.

    The function wants to get the original ID to get tinyMCEPreInit.mceInit

    The problem is if you delete the first wysiwig, you only get IDs that looks like “myId_1″. So when it wants to compare its value with tinyMCEPreInit.mceInit.hasOwnProperty (which looks for”myId” without The “_1” on line 61. Tt returns false.

    Here’s an easy solution:

    Replace this (line 58 to 66) :

    $clones.each( function ()
    {
            var currentId = $( this ).find( '.rwmb-wysiwyg' ).attr( 'id' );
            if ( tinyMCEPreInit.mceInit.hasOwnProperty( currentId ) )
            {
                    id = currentId;
                    return false; // Immediately stop the .each() loop
            }
    } );

    With :

    var substracted_charaters = [0,2,3];
    for (let count of substracted_charaters ){
        currentId = currentId.substring(0, currentId.length - count);
        if ( tinyMCEPreInit.mceInit.hasOwnProperty( currentId ) ) {
                return currentId; // Immediately stop the .each() loop
        }
    }

    Tested it and it works.

    Instead of looping through each input to find the original ID, we take the first ID we find and get rid of 2 or 3 characters until we find the original ID. Will not work if someone creates more than 100 wysiwyg and deletes them all.

    Thank you for the awesome plugin !

    Adam Kettani

    #3491

    Anh Tran
    Keymaster

    Thanks a lot for your fix, Adam! I’ve just made an improvement to make it works in all cases.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.