Skip to content

Instantly share code, notes, and snippets.

@soemarko
Created November 27, 2011 06:15

Revisions

  1. soemarko created this gist Nov 27, 2011.
    35 changes: 35 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    var btn = Ti.UI.createButton({
    title: 'Prompt!',
    height: 40,
    width: 100,
    top: 20
    });

    var lbl = Ti.UI.createLabel({
    text: 'Label',
    textAlign: 'center'
    });

    var wv = Ti.UI.createWebView({
    url: 'prompt.html',
    visible: false
    });

    var win = Ti.UI.createWindow({
    backgroundColor: '#cecece',
    title: 'Window'
    });

    win.add(btn);
    win.add(lbl);
    win.add(wv);

    btn.addEventListener('click', function(e) {
    wv.evalJS('doPrompt()');
    });

    Ti.App.addEventListener('app:prompt', function(e) {
    lbl.text = 'prompt> ' + e.data;
    });

    win.open();
    14 changes: 14 additions & 0 deletions prompt.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <html>
    <head>
    <title>Prompt!</title>
    <script>
    function doPrompt() {
    var x = prompt('Question for prompt:');
    if(x && x != '') { /* ignoring 'Cancel' or empty string */
    Ti.App.fireEvent('app:prompt', {data: x});
    }
    }
    </script>
    </head>
    <body></body>
    </html>