Click here to Skip to main content
15,949,686 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionBest way to trace JavaScript Conflict Pin
ReverseAds10-Jan-21 20:35
ReverseAds10-Jan-21 20:35 
QuestionRe: Best way to trace JavaScript Conflict Pin
Sandeep Mewara10-Jan-21 21:13
mveSandeep Mewara10-Jan-21 21:13 
AnswerRe: Best way to trace JavaScript Conflict Pin
20212a15-Jan-21 8:16
20212a15-Jan-21 8:16 
AnswerRe: Best way to trace JavaScript Conflict Pin
F-ES Sitecore28-Jan-21 21:24
professionalF-ES Sitecore28-Jan-21 21:24 
Questionhow to convert a function in to arrow function Pin
Member 139980429-Jan-21 0:56
Member 139980429-Jan-21 0:56 
AnswerRe: how to convert a function in to arrow function Pin
Afzaal Ahmad Zeeshan9-Jan-21 4:35
professionalAfzaal Ahmad Zeeshan9-Jan-21 4:35 
SuggestionRe: how to convert a function in to arrow function Pin
Richard Deeming11-Jan-21 22:41
mveRichard Deeming11-Jan-21 22:41 
QuestionQuiz Issue Pin
Shobhit Rathour30-Dec-20 3:35
Shobhit Rathour30-Dec-20 3:35 
AnswerRe: Quiz Issue Pin
Afzaal Ahmad Zeeshan9-Jan-21 5:02
professionalAfzaal Ahmad Zeeshan9-Jan-21 5:02 
QuestionReplacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 7:52
professionaljkirkerx21-Dec-20 7:52 
AnswerRe: Replacing the eval() function with something faster, more safe Pin
Graham Breach21-Dec-20 8:27
Graham Breach21-Dec-20 8:27 
GeneralRe: Replacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 9:21
professionaljkirkerx21-Dec-20 9:21 
Questionhigher order functions Pin
atomattacker-png21-Dec-20 1:49
atomattacker-png21-Dec-20 1:49 
AnswerRe: higher order functions Pin
Richard MacCutchan21-Dec-20 2:06
mveRichard MacCutchan21-Dec-20 2:06 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 2:21
atomattacker-png21-Dec-20 2:21 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 3:13
mveRichard MacCutchan21-Dec-20 3:13 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:02
mveRichard MacCutchan21-Dec-20 4:02 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 4:36
atomattacker-png21-Dec-20 4:36 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:44
mveRichard MacCutchan21-Dec-20 4:44 
QuestionAttempting to pre-populate text field and mailto based on ID Pin
Member 1502531419-Dec-20 1:10
Member 1502531419-Dec-20 1:10 
QuestionLooking to run a PHP page in the background using pure Javascript Pin
jkirkerx17-Dec-20 13:50
professionaljkirkerx17-Dec-20 13:50 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P17-Dec-20 22:54
professionalDerekT-P17-Dec-20 22:54 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 6:10
professionaljkirkerx18-Dec-20 6:10 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 7:11
professionalDerekT-P18-Dec-20 7:11 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 7:53
professionaljkirkerx18-Dec-20 7:53 
I'm just trying to run a PHP page, load the spinner, run the page, unload the spinner.

The PHP page will access the SQL server database, read values, crunch the numbers, and write values.

The PHP page also updates HTML in a value container on the presentation layer. Not sure how I'm going to handle that.

The purpose is to let the user know that work is being done; obvious, but the old method was to open a browser window with a progress spinner and close it using this copied from the internet back in 2005.

I get what it does, but it seems over complicated to me.
C#
// JavaScript Document
(function() {
    window.spawn = window.spawn || function(gen) {
        function continuer(verb, arg) {
            let result;
            try {
                result = generator[verb](arg);
            } 
            catch (err) {
                return Promise.reject(err);
            }
            if (result.done) {
                return result.value;
            } else {
                return Promise.resolve(result.value).then(onFulfilled, onRejected);
            }
        }
        let generator = gen();
        let onFulfilled = continuer.bind(continuer, 'next');
        let onRejected = continuer.bind(continuer, 'throw');
        return onFulfilled();
    };

    window.showModalDialog = window.showModalDialog || function(url, arg, opt) {

        url = url || ''; //URL of a dialog
        arg = arg || null; //arguments to a dialog
        opt = opt || 'dialogWidth:300px;dialogHeight:300px'; 

        let caller = showModalDialog.caller.toString();
        let dialog = document.body.appendChild(document.createElement('dialog'));

        dialog.setAttribute('style', opt.replace(/dialog/gi, ''));
        dialog.innerHTML = '<input class="btn-primary" type="button" id="dialog-close" value="Continue" style="position: absolute; top: 2px; right: 4px; font-size: 20px; color: #000; text-decoration: none; outline: none;"><iframe id="dialog-body" src="' + url + '" style="border: 0; width: 100%; height: 100%;"></iframe>';

        document.getElementById('dialog-body').contentWindow.dialogArguments = arg;
        document.getElementById('dialog-close').addEventListener('click', function(e) {
            e.preventDefault();
            dialog.close();
        });

        //if using yield
        if (caller.indexOf('yield') >= 0) {
            return new Promise(function(resolve, reject) {
                dialog.addEventListener('close', function() {
                    var returnValue = document.getElementById('dialog-body').contentWindow.returnValue;
                    document.body.removeChild(dialog);
                    resolve(returnValue);
                });
            });
        }

        //if using eval
        var isNext = false;
        var nextStmts = caller.split('\n').filter(function(stmt) {
            if (isNext || stmt.indexOf('showModalDialog(') >= 0)
                return isNext = true;
            return false;
        });

        dialog.addEventListener('close', function() {
            var returnValue = document.getElementById('dialog-body').contentWindow.returnValue;
            document.body.removeChild(dialog);
            nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\(.*\)/g, JSON.stringify(returnValue));
            eval('{\n' + nextStmts.join('\n'));
        });        

    };
})();
If it ain't broke don't fix it
Discover my world at jkirkerx.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.