Click here to Skip to main content
15,884,237 members
Home / Discussions / JavaScript
   

JavaScript

 
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

GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 8:26
professionalDerekT-P18-Dec-20 8:26 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 8:47
professionaljkirkerx18-Dec-20 8:47 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 12:27
professionaljkirkerx18-Dec-20 12:27 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 13:31
professionaljkirkerx18-Dec-20 13:31 
AnswerGot it Pin
jkirkerx18-Dec-20 13:47
professionaljkirkerx18-Dec-20 13:47 
QuestionFinding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 19:43
simpledeveloper18-Dec-20 19:43 
QuestionRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan17-Dec-20 23:39
mveRichard MacCutchan17-Dec-20 23:39 
AnswerRe: Finding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 15:40
simpledeveloper18-Dec-20 15:40 
GeneralRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 22:40
mveRichard MacCutchan18-Dec-20 22:40 
Questiondatepicker on button click not working Pin
Dhyanga17-Dec-20 3:45
Dhyanga17-Dec-20 3:45 
QuestionTernary operator Pin
atomattacker-png12-Dec-20 5:06
atomattacker-png12-Dec-20 5:06 
AnswerRe: Ternary operator Pin
Sandeep Mewara12-Dec-20 5:42
mveSandeep Mewara12-Dec-20 5:42 
GeneralRe: Ternary operator Pin
atomattacker-png12-Dec-20 6:01
atomattacker-png12-Dec-20 6:01 
QuestionReference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 8:42
Member 1492460710-Dec-20 8:42 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 8:58
BabyYoda10-Dec-20 8:58 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 9:45
Member 1492460710-Dec-20 9:45 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 10:06
BabyYoda10-Dec-20 10:06 

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.