[AwesomeBB] Script pour éditer un message sans charger la page

Voir le sujet précédent Voir le sujet suivant Aller en bas

Résolu [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Ven 6 Jan 2023 - 18:03

Détails techniques


Version du forum : AwesomeBB
Poste occupé : Fondateur
Navigateur(s) concerné(s) : Mozilla Firefox
Personnes concernées par le problème : Tous les utilisateurs
Lien du forum : https://gemurama.com/

Description du problème

Bonjour,

Toujours soucieux d'améliorer l'expérience utilisateur, j'ai fais quelques recherches ici ou chez votre confrère anglais. J'ai trouvé un script mais qui est très ancien, il permet d'éditer son message sans charger la page.
Et comme il est très vieux, il n'est pas forcément adapté à AwesomeBB.... Puis en lisant le sujet, j'ai vu que le script comportait quelques bugs

Lien du sujet : https://help.forumotion.com/t141665-fast-edit-without-refresh-window

Est-il possible d'adapter et/ou corriger le script pour cette version du forum ?

Merci d'avance pour votre aide Smile
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Dim 8 Jan 2023 - 12:31

Je relance Smile
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.
  • 0

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Toryudo Dim 8 Jan 2023 - 14:56

Bonjour !
Bon, beaucoup de choses ne fonctionnent pas dans ce script :
- pas de gestion de modernBB
- pas de gestion de awesomeBB
- les smileys vont dans le quickreply plutôt que l'edit
- les images hébergées dans servimg vont dans le quickreply plutôt que l'edit
- quand on tente d'éditer 2 posts à la fois, il y a des conflits
- l'édition du premier post d'un sujet avec sondage ne fonctionne pas
- les smileys ne se transforment pas en images quand on bascule le mode édition

Et sûrement d'autres problèmes encore qu'il faudra voir avec le temps.
Du coup, j'ai réécrit beaucoup de choses de façon à corriger tous les points cités ci-dessus.

J'ai testé beaucoup de cas déjà, mais je vous laisse être le beta testeur officiel Razz
Les réponses rapides doivent être activées, le script doit être placé "Sur les sujets" :

Code:
/***
 * Fast edit without refresh window!
 * Version: 1.10292014-jq1.9.1 - ieiunium et dextera
 * Made and Optimizations by JScript - 2013/11/12
 * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var sFE_oldMsg = '',
    sFE_oldID = 0,
    pFE_msgPost = 0,
    oFE_msgID = 0,
    dataObj;

/***
 * Finding the post
 * Function: findPostVersion(post_ID, doc);
 */
function findPostVersion(post_ID, doc) {
    var mess_p = $('#p' + post_ID, doc);
    var mess_post = $('#post-' + post_ID, doc);

    if (mess_p.length) {
        return mess_p;
    } else if (mess_post.length) {
        return mess_post;
    }
}

/***
 * Finding the post content
 * Function: findPostContentVersion(post_ID, doc);
 */
function findPostContentVersion(post_ID, doc) {
    var phpBB2 = pFE_msgPost.find('td .postbody div:eq(0)', doc);
    var phpBB3 = pFE_msgPost.find('div.inner div.content', doc);
    var punbb = pFE_msgPost.next().find('div.entry-content', doc);
    var invision = pFE_msgPost.find('div.post-entry div:eq(0)', doc);
    var modernBB = pFE_msgPost.find('div.content', doc);
    var awesomeBB = pFE_msgPost.find('div.post-content', doc);

    if (phpBB2.length) {
        return phpBB2;
    } else if (phpBB3.length) {
        return phpBB3;
    } else if (punbb.length) {
        return punbb;
    } else if (invision.length) {
        return invision;
    } else if (modernBB.length) {
        return modernBB;
    } else if (awesomeBB.length) {
        return awesomeBB;
    }
}

window.onload = function() {
    var sCSS = '' +
        '<style>' +
        '.input_fastedit_btn {' +
        'background: #E2E9F0;' +
        'border: 1px solid #DAE2EA;' +
        'border-radius: 3px;' +
        'box-shadow: 0 1px 0 0 #EFF3F8 inset, 0 2px 3px rgba(0, 0, 0, 0.2);' +
        'color: #464646 !important;' +
        'margin: 0 4px;' +
        'padding: 4px;' +
        'text-decoration: none !important;' +
        'cursor: pointer;' +
        '}' +
        '.input_fastedit_btn:hover {' +
        'text-decoration: none !important;' +
        '}' +
        '.sceditor-container {' +
        'clear: initial !important' +
        '}' +
        '.row2.desc {' +
        'background-color: #F1F6F9;' +
        'padding: 9px;' +
        'color: #777777;' +
        'font-size: 11px;' +
        '}' +
        '</style>';
    document.head.insertAdjacentHTML('beforeEnd', sCSS);

    $('a[href*="mode=editpost"]').click(function(event) {
        event.preventDefault();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        /* Cancel previous unconfirmed edit */
        if (sFE_oldID) {
            fastEditCancel(sFE_oldID);
        }

        var datahref = $(this).attr('href');
        var post_ID = datahref.split('p=')[1].split('&')[0];

        pFE_msgPost = findPostVersion(post_ID, document);
        oFE_msgID = findPostContentVersion(post_ID, document);
        fastEditMsg(post_ID);
        sFE_oldID = post_ID;
    });
};

/***
 * Fast edit post!
 * Function: fastEditMsg(post_ID);
 */
fastEditMsg = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    /* Change the id of the real text_editor_textarea & hide the quick reply */
    $('#text_editor_textarea').attr('id', 'text_editor_textarea_unload');
    $('#qpost, #pun-qpost, #quick_reply').hide();

    /* Load a news Sceditor in the message we want to edit */
    var sHtml = '<div class="fastEditor main-content topic">' +
        '<div class="post">' +
        '<textarea cols="9" id="text_editor_textarea" name="message" onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" rows="15" style="width: 98%; height: 250px;" tabindex="3" wrap="virtual">' +
        'Chargement du message, veuillez patienter...</textarea>' +
        '<div class="row2 desc">' +
        'Raison : <input type="text" value="" name="post_edit_reason_' + post_ID + '" id="post_edit_reason_' + post_ID + '" class="input_text" maxlength="250" size="35">' +
        '</div>' +
        '<fieldset class="submit" style="font-size: 13px !important; padding: 15px 6px; text-align: center; border: 0 none; background-color: #D1DDEA;">' +
        '<a class="input_fastedit_btn" href="/post?p=' + post_ID + '&mode=editpost">Utiliser l\'éditeur complet</a> - ' +
        '<span class="input_fastedit_btn" onclick="fastEditCancel(' + post_ID + ')">Annuler</span> ' +
        '<span class="input_fastedit_btn" onclick="fastEditSave(' + post_ID + ')">Envoyer</span>' +
        '</fieldset>' +
        '</div>' +
        '</div>';

    sFE_oldMsg = oFE_msgID.html();
    oFE_msgID.html(sHtml);

    try {
        var text_area = $('#text_editor_textarea');
        text_area.sceditor({
            locale: locale,
            width: ($.sceditor.ie <= 9) ? '' : '100%',
            height: "250px",
            plugins: plugin,
            SCE_TopicID: (typeof SCE_TopicID !== "undefined") ? SCE_TopicID : "",
            quick_reply: (typeof quick_reply !== "undefined") ? quick_reply : "",
            toolbar: 'bold,italic,underline,strike|left,center,right,justify|quote,code,faspoiler,fahide|servimg,image,link,youtube|headers,size,color,font,removeformat|emoticon,date,time,source',
            style: cssFile,
            rtl: (isRtl == true),
            emoticonsEnabled: emoticonsEnabled,
            emoticonsCompat: true,
            emoticonsRoot: "",
            emoticons: {
                dropdown: smileys
            },
            emoticonsURL: iframeSrc
        });
        text_area.sceditor("instance").toggleSourceMode();
        text_area.sceditor("instance").focus();
        $('.fastEditor a.sceditor-button-source').addClass("hover");
        $('.fastEditor .sceditor-resize-cover').show();

        /* Get all values from the edit page */
        $.get("/post?p=" + post_ID + "&mode=editpost", function(data) {
            dataObj = {};

            var dataArray = $(data).find('form[name=post]').serializeArray();
            $(dataArray).each(function(i, field) {
                dataObj[field.name] = field.value;
            });

            text_area.val(dataObj['message']);
            text_area.sceditor('instance').val(dataObj['message']);

            /* Get the submit button value */
            dataObj['post'] = $(data).find('input[name="post"]').val();
            if (!dataObj['post']) {
                dataObj['post'] = $(data).find('button[name="post"]').val();
            }

        }).done(function() {
            $('.fastEditor .sceditor-resize-cover').hide();
            $('html,body').animate({
                scrollTop: pFE_msgPost.offset().top
            }, 1200);

        }).fail(function() {
            oFE_msgID.html(sFE_oldMsg);
            sFE_oldID = 0;
            alert('Attention!\n\n An error occurred while requesting the edition of the post, wait 10 seconds and try editing again!');
        });

    } catch (e) {
        if (typeof(console) != 'undefined') {
            console.error(e);
        }
    }
};

/***
 * Fast cancel post!
 * Function: fastEditCancel(post_ID);
 */
fastEditCancel = function(post_ID) {
    oFE_msgID.html(sFE_oldMsg);
    sFE_oldID = 0;

    /* Change the id of the real text_editor_textarea & show the quick rely */
    $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
    $('#qpost, #pun-qpost, #quick_reply').show();

    /* Remove emoticon & servimg iframe */
    $('.sceditor-dropdown').remove();
};

/***
 * Fast edit post!
 * Function: fastEditSave(post_ID);
 */
fastEditSave = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    var text_area = $('#text_editor_textarea');
    text_area.sceditor("instance").toggleSourceMode();

    dataObj['message'] = text_area.sceditor('instance').val();
    dataObj['edit_reason'] = $('#post_edit_reason_' + post_ID).val();

    oFE_msgID.html('Chargement du message, veuillez patienter...');

    $.post("/post", dataObj).done(function() {
        /* Change the id of the real text_editor_textarea */
        $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
        $('#qpost, #pun-qpost, #quick_reply').show();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        $.get("", function(data) {
            sFE_oldID = 0;
            pFE_msgPost = findPostVersion(post_ID, data);
            oFE_msgID.html(findPostContentVersion(post_ID, data).html());
        });
    }).fail(function() {
        oFE_msgID.html(sFE_oldMsg);
        sFE_oldID = 0;
        alert('Attention!\n\n There was an error saving editing the post, wait 10 seconds and try editing again!');
    });
    $('html,body').animate({
        scrollTop: pFE_msgPost.offset().top
    }, 400);
};
Toryudo

Toryudo
Aidactif
Aidactif

Masculin
Messages : 1372
Inscrit(e) le : 31/03/2020

https://deus-academia.forumactif.com/
Toryudo a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Dim 8 Jan 2023 - 17:08

Bonjour Smile

Tout d'abord, merci d'avoir pris le temps de modifier. Comme je disais c'est un script très très vieux Razz

J'ai créé un forum spécialement pour tester.

Donc à première vue, ça fonctionne très bien ! J'ai testé plein de cas, après il faut voir à la longue Smile

Par contre :

- Sur mobile et tablette, j'ai "Chargement du message, veuillez patienter" sans que rien ne se passe.... Du coup, je ne peux pas écrire....
- Est-il possible de supprimer la case "Raison" car c'est une fonction que je n'utilise pas sur mon forum ?

Merci Smile
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.
  • 0

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Toryudo Dim 8 Jan 2023 - 20:02

Voilà, les deux points devraient être corrigés avec cette nouvelle version :
Code:
/***
 * Fast edit without refresh window!
 * Version: 1.10292014-jq1.9.1 - ieiunium et dextera
 * Made and Optimizations by JScript - 2013/11/12
 * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var sFE_oldMsg = '',
    sFE_oldID = 0,
    pFE_msgPost = 0,
    oFE_msgID = 0,
    dataObj;

/***
 * Finding the post
 * Function: findPostVersion(post_ID, doc);
 */
function findPostVersion(post_ID, doc) {
    var mess_p = $('#p' + post_ID, doc);
    var mess_post = $('#post-' + post_ID, doc);

    if (mess_p.length) {
        return mess_p;
    } else if (mess_post.length) {
        return mess_post;
    }
}

/***
 * Finding the post content
 * Function: findPostContentVersion(post_ID, doc);
 */
function findPostContentVersion(post_ID, doc) {
    var phpBB2 = pFE_msgPost.find('td .postbody div:eq(0)', doc);
    var phpBB3 = pFE_msgPost.find('div.inner div.content', doc);
    var punbb = pFE_msgPost.next().find('div.entry-content', doc);
    var invision = pFE_msgPost.find('div.post-entry div:eq(0)', doc);
    var modernBB = pFE_msgPost.find('div.content', doc);
    var awesomeBB = pFE_msgPost.find('div.post-content', doc);

    if (phpBB2.length) {
        return phpBB2;
    } else if (phpBB3.length) {
        return phpBB3;
    } else if (punbb.length) {
        return punbb;
    } else if (invision.length) {
        return invision;
    } else if (modernBB.length) {
        return modernBB;
    } else if (awesomeBB.length) {
        return awesomeBB;
    }
}

window.onload = function() {
    if ((_userdata["tpl_used"] == "awesomebb") || (_userdata["tpl_mobile"] != "mobi_modern")) {
        var sCSS = '' +
            '<style>' +
            '.input_fastedit_btn {' +
            'background: #E2E9F0;' +
            'border: 1px solid #DAE2EA;' +
            'border-radius: 3px;' +
            'box-shadow: 0 1px 0 0 #EFF3F8 inset, 0 2px 3px rgba(0, 0, 0, 0.2);' +
            'color: #464646 !important;' +
            'margin: 0 4px;' +
            'padding: 4px;' +
            'text-decoration: none !important;' +
            'cursor: pointer;' +
            '}' +
            '.input_fastedit_btn:hover {' +
            'text-decoration: none !important;' +
            '}' +
            '.sceditor-container {' +
            'clear: initial !important' +
            '}' +
            '.row2.desc {' +
            'background-color: #F1F6F9;' +
            'padding: 9px;' +
            'color: #777777;' +
            'font-size: 11px;' +
            '}' +
            '</style>';
        document.head.insertAdjacentHTML('beforeEnd', sCSS);

        $('a[href*="mode=editpost"]').click(function(event) {
            event.preventDefault();

            /* Remove emoticon & servimg iframe */
            $('.sceditor-dropdown').remove();

            /* Cancel previous unconfirmed edit */
            if (sFE_oldID) {
                fastEditCancel(sFE_oldID);
            }

            var datahref = $(this).attr('href');
            var post_ID = datahref.split('p=')[1].split('&')[0];

            pFE_msgPost = findPostVersion(post_ID, document);
            oFE_msgID = findPostContentVersion(post_ID, document);
            fastEditMsg(post_ID);
            sFE_oldID = post_ID;
        });
    }
};

/***
 * Fast edit post!
 * Function: fastEditMsg(post_ID);
 */
fastEditMsg = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    /* Change the id of the real text_editor_textarea & hide the quick reply */
    $('#text_editor_textarea').attr('id', 'text_editor_textarea_unload');
    $('#qpost, #pun-qpost, #quick_reply').hide();

    /* Load a news Sceditor in the message we want to edit */
    var sHtml = '<div class="fastEditor main-content topic">' +
        '<div class="post">' +
        '<textarea cols="9" id="text_editor_textarea" name="message" onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" rows="15" style="width: 98%; height: 250px;" tabindex="3" wrap="virtual">' +
        'Chargement du message, veuillez patienter...</textarea>' +
        '<fieldset class="submit" style="font-size: 13px !important; padding: 15px 6px; text-align: center; border: 0 none; background-color: #D1DDEA;">' +
        '<a class="input_fastedit_btn" href="/post?p=' + post_ID + '&mode=editpost">Utiliser l\'éditeur complet</a> - ' +
        '<span class="input_fastedit_btn" onclick="fastEditCancel(' + post_ID + ')">Annuler</span> ' +
        '<span class="input_fastedit_btn" onclick="fastEditSave(' + post_ID + ')">Envoyer</span>' +
        '</fieldset>' +
        '</div>' +
        '</div>';

    sFE_oldMsg = oFE_msgID.html();
    oFE_msgID.html(sHtml);

    try {
        var text_area = $('#text_editor_textarea');
        text_area.sceditor({
            locale: locale,
            width: ($.sceditor.ie <= 9) ? '' : '100%',
            height: "250px",
            plugins: plugin,
            SCE_TopicID: (typeof SCE_TopicID !== "undefined") ? SCE_TopicID : "",
            quick_reply: (typeof quick_reply !== "undefined") ? quick_reply : "",
            toolbar: 'bold,italic,underline,strike|left,center,right,justify|quote,code,faspoiler,fahide|servimg,image,link,youtube|headers,size,color,font,removeformat|emoticon,date,time,source',
            style: cssFile,
            rtl: (isRtl == true),
            emoticonsEnabled: emoticonsEnabled,
            emoticonsCompat: true,
            emoticonsRoot: "",
            emoticons: {
                dropdown: smileys
            },
            emoticonsURL: iframeSrc
        });
        text_area.sceditor("instance").toggleSourceMode();
        text_area.sceditor("instance").focus();
        $('.fastEditor a.sceditor-button-source').addClass("hover");
        $('.fastEditor .sceditor-resize-cover').show();

        /* Get all values from the edit page */
        $.get("/post?p=" + post_ID + "&mode=editpost", function(data) {
            dataObj = {};

            var dataArray = $(data).find('form[name=post]').serializeArray();
            $(dataArray).each(function(i, field) {
                dataObj[field.name] = field.value;
            });

            text_area.val(dataObj['message']);
            text_area.sceditor('instance').val(dataObj['message']);

            /* Get the submit button value */
            dataObj['post'] = $(data).find('input[name="post"]').val();
            if (!dataObj['post']) {
                dataObj['post'] = $(data).find('button[name="post"]').val();
            }

        }).done(function() {
            $('.fastEditor .sceditor-resize-cover').hide();
            $('html,body').animate({
                scrollTop: pFE_msgPost.offset().top
            }, 1200);

        }).fail(function() {
            oFE_msgID.html(sFE_oldMsg);
            sFE_oldID = 0;
            alert('Attention!\n\n An error occurred while requesting the edition of the post, wait 10 seconds and try editing again!');
        });

    } catch (e) {
        if (typeof(console) != 'undefined') {
            console.error(e);
        }
    }
};

/***
 * Fast cancel post!
 * Function: fastEditCancel(post_ID);
 */
fastEditCancel = function(post_ID) {
    oFE_msgID.html(sFE_oldMsg);
    sFE_oldID = 0;

    /* Change the id of the real text_editor_textarea & show the quick rely */
    $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
    $('#qpost, #pun-qpost, #quick_reply').show();

    /* Remove emoticon & servimg iframe */
    $('.sceditor-dropdown').remove();
};

/***
 * Fast edit post!
 * Function: fastEditSave(post_ID);
 */
fastEditSave = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    var text_area = $('#text_editor_textarea');
    text_area.sceditor("instance").toggleSourceMode();

    dataObj['message'] = text_area.sceditor('instance').val();

    oFE_msgID.html('Chargement du message, veuillez patienter...');

    $.post("/post", dataObj).done(function() {
        /* Change the id of the real text_editor_textarea */
        $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
        $('#qpost, #pun-qpost, #quick_reply').show();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        $.get("", function(data) {
            sFE_oldID = 0;
            pFE_msgPost = findPostVersion(post_ID, data);
            oFE_msgID.html(findPostContentVersion(post_ID, data).html());
        });
    }).fail(function() {
        oFE_msgID.html(sFE_oldMsg);
        sFE_oldID = 0;
        alert('Attention!\n\n There was an error saving editing the post, wait 10 seconds and try editing again!');
    });
    $('html,body').animate({
        scrollTop: pFE_msgPost.offset().top
    }, 400);
};
Toryudo

Toryudo
Aidactif
Aidactif

Masculin
Messages : 1372
Inscrit(e) le : 31/03/2020

https://deus-academia.forumactif.com/
Toryudo a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Dim 8 Jan 2023 - 20:29

Re,

Le champs "Raison" a bien été supprimé Smile

Mais malheureusement, j'ai toujours "Chargement du message, veuillez patienter" sur mobile et tablette.... :/
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Toryudo Lun 9 Jan 2023 - 13:29

Pour l'instant, je ne trouve pas de problème sur mon forum.
Est-ce que je peux avoir le lien du forum test ? Est-ce que les Templates sont modifiés là-bas ?
Au cas où, je m'inscrirai peut-être dessus pour faire d'autres tests ou voir en direct ce qui ne marche pas, ce sera peut-être plus simple comme ça !
Toryudo

Toryudo
Aidactif
Aidactif

Masculin
Messages : 1372
Inscrit(e) le : 31/03/2020

https://deus-academia.forumactif.com/
Toryudo a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Lun 9 Jan 2023 - 14:11

Toryudo a écrit:Pour l'instant, je ne trouve pas de problème sur mon forum.
Est-ce que je peux avoir le lien du forum test ? Est-ce que les Templates sont modifiés là-bas ?
Au cas où, je m'inscrirai peut-être dessus pour faire d'autres tests ou voir en direct ce qui ne marche pas, ce sera peut-être plus simple comme ça !

Pas de souci :

C'est un forum complètement vierge (il y a juste le script dessus) : https://gemutest.forumactif.com

Testé sur IOS et Firefox sur mobile et tablette

Photo du problème :

[AwesomeBB] Script pour éditer un message sans charger la page Image012

Vous pouvez vous inscrire Smile
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.
  • 0

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Toryudo Lun 9 Jan 2023 - 16:25

J'ai compris, le Sceditor n'est pas chargé dans le quickreply version mobile (barre d'outils) :

[AwesomeBB] Script pour éditer un message sans charger la page Image116

Alors qu'il est bien chargé dans le quickreply version PC :

[AwesomeBB] Script pour éditer un message sans charger la page Image117

Comme ce n'est pas un bug et que la chose est voulue (je me le suis fait confirmer), j'ai fait en sorte d'ajouter un test pour vérifier le chargement de Sceditor sur la page. S'il n'est pas chargé, on ne peut pas faire le fastedit sur la page.
Du coup, on ne peut pas avoir le fastedit sur AwesomeBB quand on est en version mobile, ça ne marchera que sur version PC. Mais au moins, le bouton éditer ne provoquera plus de problème !

Code:
/***
 * Fast edit without refresh window!
 * Version: 1.10292014-jq1.9.1 - ieiunium et dextera
 * Made and Optimizations by JScript - 2013/11/12
 * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var sFE_oldMsg = '',
    sFE_oldID = 0,
    pFE_msgPost = 0,
    oFE_msgID = 0,
    dataObj;

/***
 * Finding the post
 * Function: findPostVersion(post_ID, doc);
 */
function findPostVersion(post_ID, doc) {
    var mess_p = $('#p' + post_ID, doc);
    var mess_post = $('#post-' + post_ID, doc);

    if (mess_p.length) {
        return mess_p;
    } else if (mess_post.length) {
        return mess_post;
    }
}

/***
 * Finding the post content
 * Function: findPostContentVersion(post_ID, doc);
 */
function findPostContentVersion(post_ID, doc) {
    var phpBB2 = pFE_msgPost.find('td .postbody div:eq(0)', doc);
    var phpBB3 = pFE_msgPost.find('div.inner div.content', doc);
    var punbb = pFE_msgPost.next().find('div.entry-content', doc);
    var invision = pFE_msgPost.find('div.post-entry div:eq(0)', doc);
    var modernBB = pFE_msgPost.find('div.content', doc);
    var awesomeBB = pFE_msgPost.find('div.post-content', doc);

    if (phpBB2.length) {
        return phpBB2;
    } else if (phpBB3.length) {
        return phpBB3;
    } else if (punbb.length) {
        return punbb;
    } else if (invision.length) {
        return invision;
    } else if (modernBB.length) {
        return modernBB;
    } else if (awesomeBB.length) {
        return awesomeBB;
    }
}

window.onload = function() {
    if (($.sceditor) && ((_userdata["tpl_used"] == "awesomebb") || (_userdata["tpl_mobile"] != "mobi_modern"))) {
        var sCSS = '' +
            '<style>' +
            '.input_fastedit_btn {' +
            'background: #E2E9F0;' +
            'border: 1px solid #DAE2EA;' +
            'border-radius: 3px;' +
            'box-shadow: 0 1px 0 0 #EFF3F8 inset, 0 2px 3px rgba(0, 0, 0, 0.2);' +
            'color: #464646 !important;' +
            'margin: 0 4px;' +
            'padding: 4px;' +
            'text-decoration: none !important;' +
            'cursor: pointer;' +
            '}' +
            '.input_fastedit_btn:hover {' +
            'text-decoration: none !important;' +
            '}' +
            '.sceditor-container {' +
            'clear: initial !important' +
            '}' +
            '.row2.desc {' +
            'background-color: #F1F6F9;' +
            'padding: 9px;' +
            'color: #777777;' +
            'font-size: 11px;' +
            '}' +
            '</style>';
        document.head.insertAdjacentHTML('beforeEnd', sCSS);

        $('a[href*="mode=editpost"]').click(function(event) {
            event.preventDefault();

            /* Remove emoticon & servimg iframe */
            $('.sceditor-dropdown').remove();

            /* Cancel previous unconfirmed edit */
            if (sFE_oldID) {
                fastEditCancel(sFE_oldID);
            }

            var datahref = $(this).attr('href');
            var post_ID = datahref.split('p=')[1].split('&')[0];

            pFE_msgPost = findPostVersion(post_ID, document);
            oFE_msgID = findPostContentVersion(post_ID, document);
            fastEditMsg(post_ID);
            sFE_oldID = post_ID;
        });
    }
};

/***
 * Fast edit post!
 * Function: fastEditMsg(post_ID);
 */
fastEditMsg = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    /* Change the id of the real text_editor_textarea & hide the quick reply */
    $('#text_editor_textarea').attr('id', 'text_editor_textarea_unload');
    $('#qpost, #pun-qpost, #quick_reply').hide();

    /* Load a news Sceditor in the message we want to edit */
    var sHtml = '<div class="fastEditor main-content topic">' +
        '<div class="post">' +
        '<textarea cols="9" id="text_editor_textarea" name="message" onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" rows="15" style="width: 98%; height: 250px;" tabindex="3" wrap="virtual">' +
        'Chargement du message, veuillez patienter...</textarea>' +
        '<fieldset class="submit" style="font-size: 13px !important; padding: 15px 6px; text-align: center; border: 0 none; background-color: #D1DDEA;">' +
        '<a class="input_fastedit_btn" href="/post?p=' + post_ID + '&mode=editpost">Utiliser l\'éditeur complet</a> - ' +
        '<span class="input_fastedit_btn" onclick="fastEditCancel(' + post_ID + ')">Annuler</span> ' +
        '<span class="input_fastedit_btn" onclick="fastEditSave(' + post_ID + ')">Envoyer</span>' +
        '</fieldset>' +
        '</div>' +
        '</div>';

    sFE_oldMsg = oFE_msgID.html();
    oFE_msgID.html(sHtml);

    try {
        var text_area = $('#text_editor_textarea');
        text_area.sceditor({
            locale: locale,
            width: ($.sceditor.ie <= 9) ? '' : '100%',
            height: "250px",
            plugins: plugin,
            SCE_TopicID: (typeof SCE_TopicID !== "undefined") ? SCE_TopicID : "",
            quick_reply: (typeof quick_reply !== "undefined") ? quick_reply : "",
            toolbar: 'bold,italic,underline,strike|left,center,right,justify|quote,code,faspoiler,fahide|servimg,image,link,youtube|headers,size,color,font,removeformat|emoticon,date,time,source',
            style: cssFile,
            rtl: (isRtl == true),
            emoticonsEnabled: emoticonsEnabled,
            emoticonsCompat: true,
            emoticonsRoot: "",
            emoticons: {
                dropdown: smileys
            },
            emoticonsURL: iframeSrc
        });
        text_area.sceditor("instance").toggleSourceMode();
        text_area.sceditor("instance").focus();
        $('.fastEditor a.sceditor-button-source').addClass("hover");
        $('.fastEditor .sceditor-resize-cover').show();

        /* Get all values from the edit page */
        $.get("/post?p=" + post_ID + "&mode=editpost", function(data) {
            dataObj = {};

            var dataArray = $(data).find('form[name=post]').serializeArray();
            $(dataArray).each(function(i, field) {
                dataObj[field.name] = field.value;
            });

            text_area.val(dataObj['message']);
            text_area.sceditor('instance').val(dataObj['message']);

            /* Get the submit button value */
            dataObj['post'] = $(data).find('input[name="post"]').val();
            if (!dataObj['post']) {
                dataObj['post'] = $(data).find('button[name="post"]').val();
            }

        }).done(function() {
            $('.fastEditor .sceditor-resize-cover').hide();
            $('html,body').animate({
                scrollTop: pFE_msgPost.offset().top
            }, 1200);

        }).fail(function() {
            oFE_msgID.html(sFE_oldMsg);
            sFE_oldID = 0;
            alert('Attention!\n\n An error occurred while requesting the edition of the post, wait 10 seconds and try editing again!');
        });

    } catch (e) {
        if (typeof(console) != 'undefined') {
            console.error(e);
        }
    }
};

/***
 * Fast cancel post!
 * Function: fastEditCancel(post_ID);
 */
fastEditCancel = function(post_ID) {
    oFE_msgID.html(sFE_oldMsg);
    sFE_oldID = 0;

    /* Change the id of the real text_editor_textarea & show the quick rely */
    $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
    $('#qpost, #pun-qpost, #quick_reply').show();

    /* Remove emoticon & servimg iframe */
    $('.sceditor-dropdown').remove();
};

/***
 * Fast edit post!
 * Function: fastEditSave(post_ID);
 */
fastEditSave = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    var text_area = $('#text_editor_textarea');
    text_area.sceditor("instance").toggleSourceMode();

    dataObj['message'] = text_area.sceditor('instance').val();

    oFE_msgID.html('Chargement du message, veuillez patienter...');

    $.post("/post", dataObj).done(function() {
        /* Change the id of the real text_editor_textarea */
        $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
        $('#qpost, #pun-qpost, #quick_reply').show();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        $.get("", function(data) {
            sFE_oldID = 0;
            pFE_msgPost = findPostVersion(post_ID, data);
            oFE_msgID.html(findPostContentVersion(post_ID, data).html());
        });
    }).fail(function() {
        oFE_msgID.html(sFE_oldMsg);
        sFE_oldID = 0;
        alert('Attention!\n\n There was an error saving editing the post, wait 10 seconds and try editing again!');
    });
    $('html,body').animate({
        scrollTop: pFE_msgPost.offset().top
    }, 400);
};
Toryudo

Toryudo
Aidactif
Aidactif

Masculin
Messages : 1372
Inscrit(e) le : 31/03/2020

https://deus-academia.forumactif.com/
Toryudo a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Lun 9 Jan 2023 - 16:37

C'est vrai que AwesomeBB n'aime pas trop les scripts en format mobile/tablette.

Merci beaucoup, je ne vais pas clôturer tout de suite, le temps de bien tester (quelques jours)
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Lun 9 Jan 2023 - 18:33

J'ai mis le script sur mon (vrai) forum Smile

J'ai modifié un peu (la partie CSS). Je le mets, ça m'évitera si besoin de modifier à chaque fois Smile

Code:
/***
 * Fast edit without refresh window!
 * Version: 1.10292014-jq1.9.1 - ieiunium et dextera
 * Made and Optimizations by JScript - 2013/11/12
 * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var sFE_oldMsg = '',
    sFE_oldID = 0,
    pFE_msgPost = 0,
    oFE_msgID = 0,
    dataObj;

/***
 * Finding the post
 * Function: findPostVersion(post_ID, doc);
 */
function findPostVersion(post_ID, doc) {
    var mess_p = $('#p' + post_ID, doc);
    var mess_post = $('#post-' + post_ID, doc);

    if (mess_p.length) {
        return mess_p;
    } else if (mess_post.length) {
        return mess_post;
    }
}

/***
 * Finding the post content
 * Function: findPostContentVersion(post_ID, doc);
 */
function findPostContentVersion(post_ID, doc) {
    var phpBB2 = pFE_msgPost.find('td .postbody div:eq(0)', doc);
    var phpBB3 = pFE_msgPost.find('div.inner div.content', doc);
    var punbb = pFE_msgPost.next().find('div.entry-content', doc);
    var invision = pFE_msgPost.find('div.post-entry div:eq(0)', doc);
    var modernBB = pFE_msgPost.find('div.content', doc);
    var awesomeBB = pFE_msgPost.find('div.post-content', doc);

    if (phpBB2.length) {
        return phpBB2;
    } else if (phpBB3.length) {
        return phpBB3;
    } else if (punbb.length) {
        return punbb;
    } else if (invision.length) {
        return invision;
    } else if (modernBB.length) {
        return modernBB;
    } else if (awesomeBB.length) {
        return awesomeBB;
    }
}

window.onload = function() {
    if (($.sceditor) && ((_userdata["tpl_used"] == "awesomebb") || (_userdata["tpl_mobile"] != "mobi_modern"))) {
        var sCSS = '' +
            '<style>' +
            '.input_fastedit_btn {' +
            'border-radius: 3px;' +
            'color: #E84F1F !important;' +
            'font-weight: bold;' +
            'margin: 0 4px;' +
            'padding: 4px;' +
            'text-decoration: none !important;' +
            'cursor: pointer;' +
            '}' +
            '.input_fastedit_btn:hover {' +
            'background: #E84F1F;' +
            'color: #FFFFFF !important;' +
            'text-decoration: none !important;' +
            '}' +
            '.sceditor-container {' +
            'clear: initial !important' +
            '}' +
            '.row2.desc {' +
            'background-color: #F1F6F9;' +
            'padding: 9px;' +
            'color: #777777;' +
            'font-size: 11px;' +
            '}' +
            '</style>';
        document.head.insertAdjacentHTML('beforeEnd', sCSS);

        $('a[href*="mode=editpost"]').click(function(event) {
            event.preventDefault();

            /* Remove emoticon & servimg iframe */
            $('.sceditor-dropdown').remove();

            /* Cancel previous unconfirmed edit */
            if (sFE_oldID) {
                fastEditCancel(sFE_oldID);
            }

            var datahref = $(this).attr('href');
            var post_ID = datahref.split('p=')[1].split('&')[0];

            pFE_msgPost = findPostVersion(post_ID, document);
            oFE_msgID = findPostContentVersion(post_ID, document);
            fastEditMsg(post_ID);
            sFE_oldID = post_ID;
        });
    }
};

/***
 * Fast edit post!
 * Function: fastEditMsg(post_ID);
 */
fastEditMsg = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    /* Change the id of the real text_editor_textarea & hide the quick reply */
    $('#text_editor_textarea').attr('id', 'text_editor_textarea_unload');
    $('#qpost, #pun-qpost, #quick_reply').hide();

    /* Load a news Sceditor in the message we want to edit */
    var sHtml = '<div class="fastEditor main-content topic">' +
        '<div class="post">' +
        '<textarea cols="9" id="text_editor_textarea" name="message" onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" rows="15" style="width: 98%; height: 250px;" tabindex="3" wrap="virtual">' +
        'Chargement du message, veuillez patienter...</textarea>' +
        '<fieldset class="submit" style="font-size: 13px !important; padding: 15px 6px; text-align: center; border: 0 none;">' +
        '<a class="input_fastedit_btn" href="/post?p=' + post_ID + '&mode=editpost">Editeur complet</a> - ' +
        '<span class="input_fastedit_btn" onclick="fastEditCancel(' + post_ID + ')">Annuler</span> ' +
        '<span class="input_fastedit_btn" onclick="fastEditSave(' + post_ID + ')">Envoyer</span>' +
        '</fieldset>' +
        '</div>' +
        '</div>';

    sFE_oldMsg = oFE_msgID.html();
    oFE_msgID.html(sHtml);

    try {
        var text_area = $('#text_editor_textarea');
        text_area.sceditor({
            locale: locale,
            width: ($.sceditor.ie <= 9) ? '' : '100%',
            height: "250px",
            plugins: plugin,
            SCE_TopicID: (typeof SCE_TopicID !== "undefined") ? SCE_TopicID : "",
            quick_reply: (typeof quick_reply !== "undefined") ? quick_reply : "",
            toolbar: 'bold,italic,underline,strike|bulletlist,orderedlist,horizontalrule|left,center,right|quote,code,faspoiler,fahide|servimg,image,link,embed|headers,size,color,font,removeformat|mention,emoticon,source',
            style: cssFile,
            rtl: (isRtl == true),
            emoticonsEnabled: emoticonsEnabled,
            emoticonsCompat: true,
            emoticonsRoot: "",
            emoticons: {
                dropdown: smileys
            },
            emoticonsURL: iframeSrc
        });
        text_area.sceditor("instance").toggleSourceMode();
        text_area.sceditor("instance").focus();
        $('.fastEditor a.sceditor-button-source').addClass("hover");
        $('.fastEditor .sceditor-resize-cover').show();

        /* Get all values from the edit page */
        $.get("/post?p=" + post_ID + "&mode=editpost", function(data) {
            dataObj = {};

            var dataArray = $(data).find('form[name=post]').serializeArray();
            $(dataArray).each(function(i, field) {
                dataObj[field.name] = field.value;
            });

            text_area.val(dataObj['message']);
            text_area.sceditor('instance').val(dataObj['message']);

            /* Get the submit button value */
            dataObj['post'] = $(data).find('input[name="post"]').val();
            if (!dataObj['post']) {
                dataObj['post'] = $(data).find('button[name="post"]').val();
            }

        }).done(function() {
            $('.fastEditor .sceditor-resize-cover').hide();
            $('html,body').animate({
                scrollTop: pFE_msgPost.offset().top
            }, 1200);

        }).fail(function() {
            oFE_msgID.html(sFE_oldMsg);
            sFE_oldID = 0;
            alert('Attention!\n\n An error occurred while requesting the edition of the post, wait 10 seconds and try editing again!');
        });

    } catch (e) {
        if (typeof(console) != 'undefined') {
            console.error(e);
        }
    }
};

/***
 * Fast cancel post!
 * Function: fastEditCancel(post_ID);
 */
fastEditCancel = function(post_ID) {
    oFE_msgID.html(sFE_oldMsg);
    sFE_oldID = 0;

    /* Change the id of the real text_editor_textarea & show the quick rely */
    $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
    $('#qpost, #pun-qpost, #quick_reply').show();

    /* Remove emoticon & servimg iframe */
    $('.sceditor-dropdown').remove();
};

/***
 * Fast edit post!
 * Function: fastEditSave(post_ID);
 */
fastEditSave = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    var text_area = $('#text_editor_textarea');
    text_area.sceditor("instance").toggleSourceMode();

    dataObj['message'] = text_area.sceditor('instance').val();

    oFE_msgID.html('Chargement du message, veuillez patienter...');

    $.post("/post", dataObj).done(function() {
        /* Change the id of the real text_editor_textarea */
        $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
        $('#qpost, #pun-qpost, #quick_reply').show();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        $.get("", function(data) {
            sFE_oldID = 0;
            pFE_msgPost = findPostVersion(post_ID, data);
            oFE_msgID.html(findPostContentVersion(post_ID, data).html());
        });
    }).fail(function() {
        oFE_msgID.html(sFE_oldMsg);
        sFE_oldID = 0;
        alert('Attention!\n\n There was an error saving editing the post, wait 10 seconds and try editing again!');
    });
    $('html,body').animate({
        scrollTop: pFE_msgPost.offset().top
    }, 400);
};

Mon forum utilise un mode nuit.

Pour avoir l'écriture en blanc en mode nuit au lieu du noir de base, j'utilise un petit script :

Code:
$(function(){  $(function(){    $(".darkmode .sceditor-container iframe").contents().find("head").append("<style>body,html,code:before,p,table{color:#fff!important;} blockquote,code{color:black;}</style>");  });});

Et ce script ne semble pas être pris en compte pour l'édition rapide.... Y-a-t-il quelque chose à modifier ?

Merci par avance
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.
  • 0

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Toryudo Lun 9 Jan 2023 - 19:18

Peut-être de cette façon, mais si ça ne marche pas, je veux bien que vous ajoutiez le mode sombre à votre forum test pour plus de tests Razz

En fait, le script de base est exécuté une fois et il ajoute un CSS dans l'iframe de composition de message. Or le fastedit crée un nouvel iframe à chaque fois, et votre script n'est pas réexécuté (parce qu'on ne lui demande pas spécialement de se réexécuter). Du coup, j'ai ajouté une ligne pour faire la même chose après l'apparition du fastedit, on va voir si ça donne le bon résultat chez vous :

Code:
/***
 * Fast edit without refresh window!
 * Version: 1.10292014-jq1.9.1 - ieiunium et dextera
 * Made and Optimizations by JScript - 2013/11/12
 * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
 * This work is free. You can redistribute it and/or modify it
 * under the terms of the WTFPL, Version 2
 */
var sFE_oldMsg = '',
    sFE_oldID = 0,
    pFE_msgPost = 0,
    oFE_msgID = 0,
    dataObj;

/***
 * Finding the post
 * Function: findPostVersion(post_ID, doc);
 */
function findPostVersion(post_ID, doc) {
    var mess_p = $('#p' + post_ID, doc);
    var mess_post = $('#post-' + post_ID, doc);

    if (mess_p.length) {
        return mess_p;
    } else if (mess_post.length) {
        return mess_post;
    }
}

/***
 * Finding the post content
 * Function: findPostContentVersion(post_ID, doc);
 */
function findPostContentVersion(post_ID, doc) {
    var phpBB2 = pFE_msgPost.find('td .postbody div:eq(0)', doc);
    var phpBB3 = pFE_msgPost.find('div.inner div.content', doc);
    var punbb = pFE_msgPost.next().find('div.entry-content', doc);
    var invision = pFE_msgPost.find('div.post-entry div:eq(0)', doc);
    var modernBB = pFE_msgPost.find('div.content', doc);
    var awesomeBB = pFE_msgPost.find('div.post-content', doc);

    if (phpBB2.length) {
        return phpBB2;
    } else if (phpBB3.length) {
        return phpBB3;
    } else if (punbb.length) {
        return punbb;
    } else if (invision.length) {
        return invision;
    } else if (modernBB.length) {
        return modernBB;
    } else if (awesomeBB.length) {
        return awesomeBB;
    }
}

window.onload = function() {
    if (($.sceditor) && ((_userdata["tpl_used"] == "awesomebb") || (_userdata["tpl_mobile"] != "mobi_modern"))) {
        var sCSS = '' +
            '<style>' +
            '.input_fastedit_btn {' +
            'border-radius: 3px;' +
            'color: #E84F1F !important;' +
            'font-weight: bold;' +
            'margin: 0 4px;' +
            'padding: 4px;' +
            'text-decoration: none !important;' +
            'cursor: pointer;' +
            '}' +
            '.input_fastedit_btn:hover {' +
            'background: #E84F1F;' +
            'color: #FFFFFF !important;' +
            'text-decoration: none !important;' +
            '}' +
            '.sceditor-container {' +
            'clear: initial !important' +
            '}' +
            '.row2.desc {' +
            'background-color: #F1F6F9;' +
            'padding: 9px;' +
            'color: #777777;' +
            'font-size: 11px;' +
            '}' +
            '</style>';
        document.head.insertAdjacentHTML('beforeEnd', sCSS);

        $('a[href*="mode=editpost"]').click(function(event) {
            event.preventDefault();

            /* Remove emoticon & servimg iframe */
            $('.sceditor-dropdown').remove();

            /* Cancel previous unconfirmed edit */
            if (sFE_oldID) {
                fastEditCancel(sFE_oldID);
            }

            var datahref = $(this).attr('href');
            var post_ID = datahref.split('p=')[1].split('&')[0];

            pFE_msgPost = findPostVersion(post_ID, document);
            oFE_msgID = findPostContentVersion(post_ID, document);
            fastEditMsg(post_ID);
            sFE_oldID = post_ID;
        });
    }
};

/***
 * Fast edit post!
 * Function: fastEditMsg(post_ID);
 */
fastEditMsg = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    /* Change the id of the real text_editor_textarea & hide the quick reply */
    $('#text_editor_textarea').attr('id', 'text_editor_textarea_unload');
    $('#qpost, #pun-qpost, #quick_reply').hide();

    /* Load a news Sceditor in the message we want to edit */
    var sHtml = '<div class="fastEditor main-content topic">' +
        '<div class="post">' +
        '<textarea cols="9" id="text_editor_textarea" name="message" onclick="storeCaret(this)" onkeyup="storeCaret(this)" onselect="storeCaret(this)" rows="15" style="width: 98%; height: 250px;" tabindex="3" wrap="virtual">' +
        'Chargement du message, veuillez patienter...</textarea>' +
        '<fieldset class="submit" style="font-size: 13px !important; padding: 15px 6px; text-align: center; border: 0 none;">' +
        '<a class="input_fastedit_btn" href="/post?p=' + post_ID + '&mode=editpost">Editeur complet</a> - ' +
        '<span class="input_fastedit_btn" onclick="fastEditCancel(' + post_ID + ')">Annuler</span> ' +
        '<span class="input_fastedit_btn" onclick="fastEditSave(' + post_ID + ')">Envoyer</span>' +
        '</fieldset>' +
        '</div>' +
        '</div>';

    sFE_oldMsg = oFE_msgID.html();
    oFE_msgID.html(sHtml);

    try {
        var text_area = $('#text_editor_textarea');
        text_area.sceditor({
            locale: locale,
            width: ($.sceditor.ie <= 9) ? '' : '100%',
            height: "250px",
            plugins: plugin,
            SCE_TopicID: (typeof SCE_TopicID !== "undefined") ? SCE_TopicID : "",
            quick_reply: (typeof quick_reply !== "undefined") ? quick_reply : "",
            toolbar: 'bold,italic,underline,strike|bulletlist,orderedlist,horizontalrule|left,center,right|quote,code,faspoiler,fahide|servimg,image,link,embed|headers,size,color,font,removeformat|mention,emoticon,source',
            style: cssFile,
            rtl: (isRtl == true),
            emoticonsEnabled: emoticonsEnabled,
            emoticonsCompat: true,
            emoticonsRoot: "",
            emoticons: {
                dropdown: smileys
            },
            emoticonsURL: iframeSrc
        });
        text_area.sceditor("instance").toggleSourceMode();
        text_area.sceditor("instance").focus();
        $(".darkmode .sceditor-container iframe").contents().find("head").append("<style>body,html,code:before,p,table{color:#fff!important;} blockquote,code{color:black;}</style>");
        $('.fastEditor a.sceditor-button-source').addClass("hover");
        $('.fastEditor .sceditor-resize-cover').show();

        /* Get all values from the edit page */
        $.get("/post?p=" + post_ID + "&mode=editpost", function(data) {
            dataObj = {};

            var dataArray = $(data).find('form[name=post]').serializeArray();
            $(dataArray).each(function(i, field) {
                dataObj[field.name] = field.value;
            });

            text_area.val(dataObj['message']);
            text_area.sceditor('instance').val(dataObj['message']);

            /* Get the submit button value */
            dataObj['post'] = $(data).find('input[name="post"]').val();
            if (!dataObj['post']) {
                dataObj['post'] = $(data).find('button[name="post"]').val();
            }

        }).done(function() {
            $('.fastEditor .sceditor-resize-cover').hide();
            $('html,body').animate({
                scrollTop: pFE_msgPost.offset().top
            }, 1200);

        }).fail(function() {
            oFE_msgID.html(sFE_oldMsg);
            sFE_oldID = 0;
            alert('Attention!\n\n An error occurred while requesting the edition of the post, wait 10 seconds and try editing again!');
        });

    } catch (e) {
        if (typeof(console) != 'undefined') {
            console.error(e);
        }
    }
};

/***
 * Fast cancel post!
 * Function: fastEditCancel(post_ID);
 */
fastEditCancel = function(post_ID) {
    oFE_msgID.html(sFE_oldMsg);
    sFE_oldID = 0;

    /* Change the id of the real text_editor_textarea & show the quick rely */
    $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
    $('#qpost, #pun-qpost, #quick_reply').show();

    /* Remove emoticon & servimg iframe */
    $('.sceditor-dropdown').remove();
};

/***
 * Fast edit post!
 * Function: fastEditSave(post_ID);
 */
fastEditSave = function(post_ID) {
    if (isNaN(post_ID) || (oFE_msgID.length == 0)) {
        return false
    }

    var text_area = $('#text_editor_textarea');
    text_area.sceditor("instance").toggleSourceMode();

    dataObj['message'] = text_area.sceditor('instance').val();

    oFE_msgID.html('Chargement du message, veuillez patienter...');

    $.post("/post", dataObj).done(function() {
        /* Change the id of the real text_editor_textarea */
        $('#text_editor_textarea_unload').attr('id', 'text_editor_textarea');
        $('#qpost, #pun-qpost, #quick_reply').show();

        /* Remove emoticon & servimg iframe */
        $('.sceditor-dropdown').remove();

        $.get("", function(data) {
            sFE_oldID = 0;
            pFE_msgPost = findPostVersion(post_ID, data);
            oFE_msgID.html(findPostContentVersion(post_ID, data).html());
        });
    }).fail(function() {
        oFE_msgID.html(sFE_oldMsg);
        sFE_oldID = 0;
        alert('Attention!\n\n There was an error saving editing the post, wait 10 seconds and try editing again!');
    });
    $('html,body').animate({
        scrollTop: pFE_msgPost.offset().top
    }, 400);
};
Toryudo

Toryudo
Aidactif
Aidactif

Masculin
Messages : 1372
Inscrit(e) le : 31/03/2020

https://deus-academia.forumactif.com/
Toryudo a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Lun 9 Jan 2023 - 20:25

La solution fonctionne, bravo Smile !

Je vais pouvoir continuer d'utiliser et de tester le script. Merci
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.

Résolu Re: [AwesomeBB] Script pour éditer un message sans charger la page

Message par Invité Mer 11 Jan 2023 - 19:32

Je clôture le sujet, depuis deux jours, nous avons bien posté et pas de problème à signaler.

Au pire, j'ouvrirai un autre sujet.

Encore merci et bravo à Toryudo Smile
Anonymous

Invité
Invité


Invité a été remercié(e) par l'auteur de ce sujet.

Voir le sujet précédent Voir le sujet suivant Revenir en haut

- Sujets similaires

Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum