examples/phonegap1/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
function createPromptDialog (title, message, buttons, defaultText, callback) {

    var isPhone = cordova.platformId === 'windows' && WinJS.Utilities.isPhone;
    var isWindows = !!cordova.platformId.match(/windows/);

    createCSSElem('notification.css');

    var dlgWrap = document.createElement('div');
    dlgWrap.className = 'dlgWrap';

    var dlg = document.createElement('div');
    dlg.className = 'dlgContainer';

    if (isWindows) {
        dlg.className += ' dlgContainer-windows';
    } else if (isPhone) {
        dlg.className += ' dlgContainer-phone';
    }

    // dialog layout template
    dlg.innerHTML = _cleanHtml("<span id='lbl-title'></span><br/>" + // title
        "<span id='lbl-message'></span><br/>" + // message
        "<input id='prompt-input'/><br/>"); // input fields

    dlg.querySelector('#lbl-title').appendChild(document.createTextNode(title));
    dlg.querySelector('#lbl-message').appendChild(document.createTextNode(message));
    dlg.querySelector('#prompt-input').setAttribute('placeholder', defaultText);
    dlg.querySelector('#prompt-input').setAttribute('value', defaultText);

    function makeButtonCallback (idx) {
        return function () {
            var value = dlg.querySelector('#prompt-input').value || defaultText;
            dlgWrap.parentNode.removeChild(dlgWrap);

            if (callback) {
                callback({ input1: value, buttonIndex: idx }); // eslint-disable-line standard/no-callback-literal
            }
        };
    }

    function addButton (idx, label) {
        var button = document.createElement('button');
        button.className = 'dlgButton';
        button.tabIndex = idx;
        button.onclick = makeButtonCallback(idx + 1);
        if (idx === 0) {
            button.className += ' dlgButtonFirst';
        }
        button.appendChild(document.createTextNode(label));
        dlg.appendChild(button);
    }

    // reverse order is used since we align buttons to the right
    for (var idx = buttons.length - 1; idx >= 0; idx--) {
        addButton(idx, buttons[idx]);
    }

    dlgWrap.appendChild(dlg);
    document.body.appendChild(dlgWrap);

    // make sure input field is under focus
    dlg.querySelector('#prompt-input').select();
    // add Enter/Return key handling
    var defaultButton = dlg.querySelector('.dlgButtonFirst');
    dlg.addEventListener('keypress', function (e) {
        if (e.keyCode === 13) { // enter key
            if (defaultButton) {
                defaultButton.click();
            }
        }
    });

    return dlgWrap;
}
function createPromptDialog (title, message, buttons, defaultText, callback) {

    var isPhone = cordova.platformId === 'windows' && WinJS.Utilities.isPhone;
    var isWindows = !!cordova.platformId.match(/windows/);

    createCSSElem('notification.css');

    var dlgWrap = document.createElement('div');
    dlgWrap.className = 'dlgWrap';

    var dlg = document.createElement('div');
    dlg.className = 'dlgContainer';

    if (isWindows) {
        dlg.className += ' dlgContainer-windows';
    } else if (isPhone) {
        dlg.className += ' dlgContainer-phone';
    }

    // dialog layout template
    dlg.innerHTML = _cleanHtml("<span id='lbl-title'></span><br/>" + // title
        "<span id='lbl-message'></span><br/>" + // message
        "<input id='prompt-input'/><br/>"); // input fields

    dlg.querySelector('#lbl-title').appendChild(document.createTextNode(title));
    dlg.querySelector('#lbl-message').appendChild(document.createTextNode(message));
    dlg.querySelector('#prompt-input').setAttribute('placeholder', defaultText);
    dlg.querySelector('#prompt-input').setAttribute('value', defaultText);

    function makeButtonCallback (idx) {
        return function () {
            var value = dlg.querySelector('#prompt-input').value || defaultText;
            dlgWrap.parentNode.removeChild(dlgWrap);

            if (callback) {
                callback({ input1: value, buttonIndex: idx }); // eslint-disable-line standard/no-callback-literal
            }
        };
    }

    function addButton (idx, label) {
        var button = document.createElement('button');
        button.className = 'dlgButton';
        button.tabIndex = idx;
        button.onclick = makeButtonCallback(idx + 1);
        if (idx === 0) {
            button.className += ' dlgButtonFirst';
        }
        button.appendChild(document.createTextNode(label));
        dlg.appendChild(button);
    }

    // reverse order is used since we align buttons to the right
    for (var idx = buttons.length - 1; idx >= 0; idx--) {
        addButton(idx, buttons[idx]);
    }

    dlgWrap.appendChild(dlg);
    document.body.appendChild(dlgWrap);

    // make sure input field is under focus
    dlg.querySelector('#prompt-input').select();
    // add Enter/Return key handling
    var defaultButton = dlg.querySelector('.dlgButtonFirst');
    dlg.addEventListener('keypress', function (e) {
        if (e.keyCode === 13) { // enter key
            if (defaultButton) {
                defaultButton.click();
            }
        }
    });

    return dlgWrap;
}
function createPromptDialog ( title , message , buttons , defaultText , callback ) { var isPhone = cordova . platformId === 'windows' && WinJS . Utilities . isPhone ; var isWindows = ! ! cordova . platformId . match ( / windows / ) ; createCSSElem ( 'notification.css' ) ; var dlgWrap = document . createElement ( 'div' ) ; dlgWrap . className = 'dlgWrap' ; var dlg = document . createElement ( 'div' ) ; dlg . className = 'dlgContainer' ; if ( isWindows ) { dlg . className += ' dlgContainer-windows' ; } else if ( isPhone ) { dlg . className += ' dlgContainer-phone' ; } // dialog layout template dlg . innerHTML = _cleanHtml ( "<span id='lbl-title'></span><br/>" + // title "<span id='lbl-message'></span><br/>" + // message "<input id='prompt-input'/><br/>" ) ; // input fields dlg . querySelector ( '#lbl-title' ) . appendChild ( document . createTextNode ( title ) ) ; dlg . querySelector ( '#lbl-message' ) . appendChild ( document . createTextNode ( message ) ) ; dlg . querySelector ( '#prompt-input' ) . setAttribute ( 'placeholder' , defaultText ) ; dlg . querySelector ( '#prompt-input' ) . setAttribute ( 'value' , defaultText ) ; function makeButtonCallback ( idx ) { return function ( ) { var value = dlg . querySelector ( '#prompt-input' ) . value || defaultText ; dlgWrap . parentNode . removeChild ( dlgWrap ) ; if ( callback ) { callback ( { input1 : value , buttonIndex : idx } ) ; // eslint-disable-line standard/no-callback-literal } } ; } function addButton ( idx , label ) { var button = document . createElement ( 'button' ) ; button . className = 'dlgButton' ; button . tabIndex = idx ; button . onclick = makeButtonCallback ( idx + 1 ) ; if ( idx === 0 ) { button . className += ' dlgButtonFirst' ; } button . appendChild ( document . createTextNode ( label ) ) ; dlg . appendChild ( button ) ; } // reverse order is used since we align buttons to the right for ( var idx = buttons . length - 1 ; idx >= 0 ; idx -- ) { addButton ( idx , buttons [ idx ] ) ; } dlgWrap . appendChild ( dlg ) ; document . body . appendChild ( dlgWrap ) ; // make sure input field is under focus dlg . querySelector ( '#prompt-input' ) . select ( ) ; // add Enter/Return key handling var defaultButton = dlg . querySelector ( '.dlgButtonFirst' ) ; dlg . addEventListener ( 'keypress' , function ( e ) { if ( e . keyCode === 13 ) { // enter key if ( defaultButton ) { defaultButton . click ( ) ; } } } ) ; return dlgWrap ; }
Windows does not provide native UI for promp dialog so we use some simple html-based implementation until it is available
Windows does not provide native UI for promp dialog so we use some simple html - based implementation until it is available