User:Chicocvenancio/HelpDeskTBLinks.js

Today we are going to delve into the fascinating world of User:Chicocvenancio/HelpDeskTBLinks.js. This topic has been the object of study and interest for many years, and its importance is undeniable in different areas of daily life. User:Chicocvenancio/HelpDeskTBLinks.js has impacted history, science, culture, technology and society in general. Through this article, we will explore different aspects of User:Chicocvenancio/HelpDeskTBLinks.js, from its origin and evolution to its influence on the world today. We will discover fascinating facts, curiosities and relevant information that will allow us to better understand the importance of User:Chicocvenancio/HelpDeskTBLinks.js in our daily lives.
if ((mw.config.get('wgPageName') === "Wikipedia:Help_desk") || (mw.config.get('wgPageName') === "Wikipedia:Media_copyright_questions") || (mw.config.get('wgPageName') === "Wikipedia:New_contributors'_help_page/questions") || (mw.config.get('wgPageName') === "Wikipedia:Editor_assistance/Requests") && mw.config.get('wgAction') === 'view') {
    mw.loader.using(, function () {
    $(mw.TBLinks()); });
};
( function ( mw, $ ) {
    var TBLinks;
    TBLinks = function () {
        "use strict";
        if ($("#mw-content-text").length > 0) {
            var $nodeList = $('a'), pdne = ' (page does not exist)', i, $link, $newLink;
            if ($nodeList !== null) {
                for (i = 0; i < $nodeList.length; i += 1) {
                    $link = $($nodeList);
                    $newLink = $('<a href="#' + $link.title.replace(pdne, "") + '" style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="TBsubmit' + i + '">TB</a>');
                    $($link).after($newLink);
                }
            }
            $('a').tipsy({html: true}).before("|").after("|").click(function (e) {
                TBLinks.submit($(this).attr('href').substr(1), this.id);
            });
        };
    };
    TBLinks.submit = function  (page, id) {
        'use strict';
        TBLinks.edit = function (section) {
            var sectionTitle = "{{Talkback|" + mw.config.get('wgPageName').replace(/_/g, ' ') + "|", data;
            if (section === "") {
                sectionTitle += "ts=~~" + "~~}}";
            } else {
                sectionTitle += section + "|ts=~~" + "~~}}";
            }
            data = {
                format : 'json',
                action : 'edit',
                minor : false,
                title : page,
                text : sectionTitle,
                section : 'new',
                summary : "Talkback: you've got messages!",
                token : mw.user.tokens.get('csrfToken')
            };
            $.ajax({
                url : mw.util.wikiScript('api'),
                type : 'POST',
                dataType : 'json',
                data : data,
                success : function (data) {
                    if (data && data.edit && data.edit.result && data.edit.result === 'Success') {
                        TBLinks.useDialog('Success', 'Success in sending your talkback (<a href="' +
                            mw.util.getUrl( page ) + '">Open</a>) (<a href="' +
                            mw.util.getUrl( page ) + '?diff=0">diff</a>)', 'nprompt-dialog');
                    } else {
                        TBLinks.useDialog('Error!!', 'There was an error requesting the edit. Code: ' + data.error.code + '": ' + data.error.info, 'nprompt-dialog');
                    }
                },
                error : function () {
                    TBLinks.useDialog('Error!!', 'There was an error in using AJAX to edit the page.', 'nprompt-dialog');
                }
            });
        }
        TBLinks.nicePrompt("Please enter the title of the question you're replying to (or just leave it blank):", "Section:", TBLinks.edit);
    };
    TBLinks.nicePrompt = function (title, label, callback) {
        'use strict';
        $('<div id="nprompt-dialog" class="ui-widget">' + (label ? '<label for="nprompt-input">' + label + '</label>' : '') + '<input type="text" id="nprompt-input"> </input></div>').dialog({
            title: title,
            open: function () {
                $(".ui-dialog-titlebar-close").hide();
                $('#nprompt-input').autocomplete({source: $('.toctext').map(function() { return $(this).text(); }).get()})
            },
            close: function () {
            $('#nprompt-dialog').dialog('destroy')
            $('#nprompt-dialog').remove()
            },
            buttons: {
                "OK": function () {
                    callback($('#nprompt-input').val());
                },
                Cancel: function() {
                    TBLinks.useDialog('Oh!', 'You have canceled!', 'nprompt-dialog');
                }
            }         
        });
    };
    TBLinks.useDialog = function (title, message, id) {
        'use strict';
        $('#' + id).empty();
        $('#' + id).dialog("option", "title", title);
        $('#' + id).append($('<div>' + message + '</div>'));
        $('#' + id).dialog("option", "buttons", { "Close": function() {
            $(this).dialog("close");
        } } );
    };
    mw.TBLinks = TBLinks;
}( mediaWiki, jQuery ) );