Click here to Skip to main content
15,173,031 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 5:36
Memberatomattacker-png21-Dec-20 5:36 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 5:44
mveRichard MacCutchan21-Dec-20 5:44 
QuestionAttempting to pre-populate text field and mailto based on ID Pin
Member 1502531419-Dec-20 2:10
MemberMember 1502531419-Dec-20 2:10 
QuestionLooking to run a PHP page in the background using pure Javascript Pin
jkirkerx17-Dec-20 14:50
professionaljkirkerx17-Dec-20 14:50 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P17-Dec-20 23:54
professionalDerekT-P17-Dec-20 23:54 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 7:10
professionaljkirkerx18-Dec-20 7:10 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 8:11
professionalDerekT-P18-Dec-20 8:11 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 8:53
professionaljkirkerx18-Dec-20 8: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 9:26
professionalDerekT-P18-Dec-20 9:26 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 9:47
professionaljkirkerx18-Dec-20 9:47 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 13:27
professionaljkirkerx18-Dec-20 13:27 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 14:31
professionaljkirkerx18-Dec-20 14:31 
AnswerGot it Pin
jkirkerx18-Dec-20 14:47
professionaljkirkerx18-Dec-20 14:47 
QuestionFinding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 20:43
Membersimpledeveloper18-Dec-20 20:43 
QuestionRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 0:39
mveRichard MacCutchan18-Dec-20 0:39 
AnswerRe: Finding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 16:40
Membersimpledeveloper18-Dec-20 16:40 
GeneralRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 23:40
mveRichard MacCutchan18-Dec-20 23:40 
Questiondatepicker on button click not working Pin
Dhyanga17-Dec-20 4:45
MemberDhyanga17-Dec-20 4:45 
QuestionTernary operator Pin
atomattacker-png12-Dec-20 6:06
Memberatomattacker-png12-Dec-20 6:06 
AnswerRe: Ternary operator Pin
Sandeep Mewara12-Dec-20 6:42
mveSandeep Mewara12-Dec-20 6:42 
GeneralRe: Ternary operator Pin
atomattacker-png12-Dec-20 7:01
Memberatomattacker-png12-Dec-20 7:01 
QuestionReference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 9:42
MemberMember 1492460710-Dec-20 9:42 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 9:58
MemberBabyYoda10-Dec-20 9:58 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 10:45
MemberMember 1492460710-Dec-20 10:45 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 11:06
MemberBabyYoda10-Dec-20 11: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.