Prompt the user when the app requests SMS messages.

This commit is contained in:
Marcus Cavanaugh 2014-09-19 15:49:57 -07:00
Родитель 27a69516e3
Коммит 665431f21c
4 изменённых файлов: 890 добавлений и 0 удалений

Просмотреть файл

@ -50,6 +50,10 @@
<script type="text/javascript" src="game-ui.js" defer></script>
<script type="text/javascript" src="desktop-ui.js" defer></script>
<script type="text/javascript" src="main.js" defer></script>
<!-- Include shared building blocks -->
<link rel="stylesheet" type="text/css" href="style/confirm.css">
<link rel="stylesheet" type="text/css" href="style/input_areas.css">
</head>
<body>
@ -93,6 +97,19 @@
<button id="right">right</button>
<button id="fire">fire</button>
</div>
<form role="dialog" data-type="confirm" id="sms-listener-prompt" style="display: none">
<section>
<h1>SMS Verification Requested</h1>
<p>This app sent you an SMS. Type the message you received here:</p>
<p><input type="text" placeholder="Type SMS Verification Code Here">
</section>
<menu>
<button class="cancel">Cancel</button>
<button class="recommend">Done</button>
</menu>
</form>
</body>
</html>

Просмотреть файл

@ -17,6 +17,10 @@ document.getElementById("sms_receive").onclick = function() {
document.getElementById("sms_text").value = "SMS text";
document.getElementById("sms_addr").value = "SMS phone number";
receiveSms(text, addr);
}
function receiveSms(text, addr) {
var sms = {
text: text,
addr: addr,
@ -33,6 +37,40 @@ document.getElementById("sms_receive").onclick = function() {
}
}
/**
* This app is listening for SMS messages; for most apps, that means
* they're looking for the content of a message the app's servers just
* sent. Prompt the user to enter that code here, and forward it to
* the app.
*/
function promptForMessageText() {
var el = document.getElementById('sms-listener-prompt').cloneNode(true);
el.style.display = 'block';
var input = el.querySelector('input');
var btnCancel = el.querySelector('button.cancel');
var btnDone = el.querySelector('button.recommend');
btnDone.disabled = true; // Wait for input before enabling.
input.addEventListener('input', function() {
btnDone.disabled = (input.value.length === 0);
});
btnCancel.addEventListener('click', function() {
console.warn('SMS prompt canceled.');
el.parentElement.removeChild(el);
});
btnDone.addEventListener('click', function() {
el.parentElement.removeChild(el);
console.log('SMS prompt filled out:', input.value);
receiveSms(input.value, 'unknown'); // XXX: We don't know who sent it...
});
document.body.appendChild(el);
input.focus();
}
Native["com/sun/midp/io/j2me/sms/Protocol.open0.(Ljava/lang/String;II)I"] = function(ctx, stack) {
var port = stack.pop(), msid = stack.pop(), host = util.fromJavaString(stack.pop()), _this = stack.pop();
@ -42,6 +80,8 @@ Native["com/sun/midp/io/j2me/sms/Protocol.open0.(Ljava/lang/String;II)I"] = func
host: host,
};
promptForMessageText();
stack.push(++MIDP.lastSMSConnection);
}

295
style/confirm.css Normal file
Просмотреть файл

@ -0,0 +1,295 @@
/* ----------------------------------
* Confirm
* ---------------------------------- */
/* Main dialog setup */
form[role="dialog"][data-type="confirm"] {
background: #2d2d2d;
overflow: hidden;
position: absolute;
z-index: 100;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding-bottom: 7rem;
font-size: 0;
/* Using font-size: 0; we avoid the unwanted visual space (about 3px)
created by white-spaces and break lines in the code betewen inline-block elements */
color: #fff;
text-align: left;
}
form[role="dialog"][data-type="confirm"]:before {
content: "";
display: inline-block;
vertical-align: middle;
width: 0.1rem;
height: 100%;
margin-left: -0.1rem;
}
form[role="dialog"][data-type="confirm"] > section {
font-weight: 300;
font-size: 2.2rem;
color: #FAFAFA;
padding: 0 1.5rem;
-moz-box-sizing: padding-box;
width: 100%;
display: inline-block;
overflow-y: scroll;
max-height: 100%;
vertical-align: middle;
white-space: normal;
}
form[role="dialog"][data-type="confirm"] h1 {
font-weight: normal;
font-size: 1.6rem;
line-height: 1.5em;
color: #fff;
margin: 0;
padding: 1rem 1.5rem 0;
}
/* Menu & buttons setup */
form[role="dialog"][data-type="confirm"] menu {
white-space: nowrap;
margin: 0;
padding: 1.5rem;
background: #4d4d4d;
display: block;
overflow: hidden;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
form[role="dialog"][data-type="confirm"] menu button::-moz-focus-inner {
border: none;
outline: none;
margin-top: -0.2rem; /* To fix line-height bug (697451) */
}
form[role="dialog"][data-type="confirm"] menu button {
font-family: sans-serif;
font-style: italic;
width: 100%;
height: 4rem;
margin: 0 0 1rem;
padding: 0 1.2rem;
-moz-box-sizing: border-box;
display: inline-block;
vertical-align: middle;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
background: #d8d8d8;
border: none;
border-radius: 2rem;
font-weight: normal;
font-size: 1.6rem;
line-height: 4rem;
color: #333;
text-align: center;
text-shadow: none;
text-decoration: none;
outline: none;
}
/* Recommend */
form[role="dialog"][data-type="confirm"] menu button.recommend {
background-color: #00caf2;
color: #fff;
}
/* Danger */
form[role="dialog"][data-type="confirm"] menu button.danger {
background-color: #e51e1e;
color: #fff;
}
/* Pressed */
form[role="dialog"][data-type="confirm"] menu button:active {
background: #00aacc;
color: #fff;
}
/* Disabled */
form[role="dialog"][data-type="confirm"] > menu > button[disabled] {
background-color: #565656;
color: rgba(255,255,255,0.4);
pointer-events: none;
}
form[role="dialog"][data-type="confirm"] > menu > button[disabled].recommend {
background-color: #006579;
}
form[role="dialog"][data-type="confirm"] > menu > button[disabled].danger {
background-color: #730f0f;
}
button[disabled]::-moz-selection {
-moz-user-select: none;
}
form[role="dialog"][data-type="confirm"] menu button:last-child {
margin-left: 1rem;
}
form[role="dialog"][data-type="confirm"] menu button,
form[role="dialog"][data-type="confirm"] menu button:first-child {
margin: 0;
}
form[role="dialog"][data-type="confirm"] menu button {
width: calc((100% - 1rem) / 2);
}
form[role="dialog"][data-type="confirm"] menu button.full {
width: 100%;
}
/* Specific component code */
form[role="dialog"][data-type="confirm"] p {
word-wrap: break-word;
margin: 1rem 0 0;
padding: 1rem 1.5rem;
border-top: 0.1rem solid #686868;
line-height: 3rem;
}
form[role="dialog"][data-type="confirm"] p span {
font-size: 1.5rem;
display: block;
line-height: 1.7rem;
color: rgba(255,255,255,0.6);
}
form[role="dialog"][data-type="confirm"] p img {
float: left;
margin-right: 2rem;
}
form[role="dialog"][data-type="confirm"] p strong {
font-weight: 300;
}
form[role="dialog"][data-type="confirm"] p small {
font-size: 1.4rem;
font-weight: normal;
color: #cbcbcb;
display: block;
}
form[role="dialog"][data-type="confirm"] dl {
border-top: 0.1rem solid #686868;
margin: 1rem 0 0;
overflow: hidden;
padding-top: 1rem;
font-size: 1.6rem;
line-height: 2.2rem;
}
form[role="dialog"][data-type="confirm"] dl > dt {
clear: both;
float: left;
width: 7rem;
padding-left: 1.5rem;
font-weight: 500;
text-align: left;
}
form[role="dialog"][data-type="confirm"] dl > dd {
padding-right: 1.5rem;
font-weight: 300;
text-overflow: ellipsis;
vertical-align: top;
overflow: hidden;
}
form[role="dialog"][data-type="confirm"] figure {
margin: 1.5rem;
display: flex;
align-items: center;
}
form[role="dialog"][data-type="confirm"] figure img {
padding-right: 1.5rem;
flex-shrink: 0;
}
form[role="dialog"][data-type="confirm"] figure figcaption {
font-size: 2.1rem;
font-weight: 300;
}
form[role="dialog"][data-type="confirm"] ul {
margin: 0;
padding: 2rem 1.5rem;
border-top: 0.1rem solid #686868;
list-style: none;
font-size: 1.6rem;
font-weight: normal;
}
form[role="dialog"][data-type="confirm"] ul li {
word-wrap: break-word;
line-height: 2rem;
padding-bottom: 1.5rem;
}
form[role="dialog"][data-type="confirm"] ul li:last-child {
padding-bottom: 0;
}
form[role="dialog"][data-type="confirm"] ul li ul {
border: none;
margin: 0;
padding: 0;
}
/*
* Right to left View
*/
html[dir="rtl"] form[role="dialog"][data-type="confirm"] {
text-align: right;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"]:before {
margin-left: auto;
margin-right: -0.1rem;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"] menu button:last-child {
margin-left: auto;
margin-right: 1rem;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"] p img {
float: right;
margin-left: 2rem;
margin-right: auto;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"] dl > dt {
float: right;
padding-left: inherit;
padding-right: 1.5rem;
text-align: right;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"] dl > dd {
padding-left: 1.5rem;
padding-right: inherit;
}
html[dir="rtl"] form[role="dialog"][data-type="confirm"] figure img {
padding-left: 1.5rem;
padding-right: inherit;
}

538
style/input_areas.css Normal file
Просмотреть файл

@ -0,0 +1,538 @@
/* ----------------------------------
* Input areas
* ---------------------------------- */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea {
font-family: sans-serif;
box-sizing: border-box;
display: block;
width: 100%;
height: 4rem;
line-height: 4rem;
resize: none;
padding: 0 1.5rem;
font-size: 1.6rem;
border: 0.1rem solid #c7c7c7;
border-radius: 0;
box-shadow: none; /* override the box-shadow from the system (performance issue) */
color: #333;
background: #fff;
margin: 0 0 1rem 0;
}
label:active {
background-color: transparent;
}
textarea {
height: 10rem;
max-height: 10rem;
line-height: 2rem;
}
input::-moz-placeholder,
textarea::-moz-placeholder {
color: #a9a9a9;
opacity: 1;
font-style: italic;
font-weight: 400;
}
input[disabled],
textarea[disabled] {
opacity: 0.5;
}
.skin-dark input[type="text"],
.skin-dark input[type="password"],
.skin-dark input[type="email"],
.skin-dark input[type="tel"],
.skin-dark input[type="search"],
.skin-dark input[type="url"],
.skin-dark input[type="number"],
.skin-dark textarea {
color: #fff;
background-color: transparent;
border-color: #454545;
}
form p {
position: relative;
margin: 0;
}
form p input + button[type="reset"],
form p textarea + button[type="reset"] {
position: absolute;
top: 0;
right: -0.3rem;
width: 4rem;
height: 4rem;
padding: 0;
border: none;
font-size: 0;
opacity: 0;
pointer-events: none;
background: url(input_areas/images/clear.png) no-repeat 50% 50% / 2.4rem auto;
}
.skin-dark p input + button[type="reset"],
.skin-dark p textarea + button[type="reset"] {
background-image: url(input_areas/images/clear_dark.png);
}
/* To avoid colission with BB butons */
li input + button[type="reset"]:after,
li textarea + button[type="reset"]:after {
background: none;
}
textarea {
padding: 1.2rem;
}
form p input:focus {
padding-right: 3rem;
}
form p input:focus + button[type="reset"],
form p textarea:focus + button[type="reset"] {
opacity: 1;
pointer-events: all;
}
/* Fieldset */
fieldset {
position: relative;
overflow: hidden;
margin: 1.5rem 0 0 0;
padding: 0;
font-size: 2rem;
line-height: 1em;
background: none;
border: 0;
}
fieldset legend,
input[type="date"],
input[type="time"],
input[type="datetime"],
input[type="datetime-local"] {
border: 0.1rem solid #c7c7c7;
width: 100%;
box-sizing: border-box;
font-family: sans-serif;
font-style: italic;
font-size: 1.6rem;
margin: 0 0 1.5rem;
padding: 0 1.5rem;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
height: 4rem;
color: #333;
border-radius: 0;
background: #fff url(input_areas/images/dialog.svg) no-repeat calc(100% - 1rem) calc(100% - 1rem);
}
fieldset legend {
margin: 0 0 1rem;
padding: 1rem 1.5rem 0;
background-color: rgba(0,0,0,0.05);
}
fieldset[disabled] {
opacity: 0.5;
pointer-events: none;
}
.skin-dark fieldset legend,
.skin-dark input[type="date"],
.skin-dark input[type="time"],
.skin-dark input[type="datetime"],
.skin-dark input[type="datetime-local"] {
color: #fff;
background-color: transparent;
border-color: #454545;
}
fieldset[disabled] legend,
input[type="date"][disabled],
input[type="time"][disabled],
input[type="datetime"][disabled],
input[type="datetime-local"][disabled] {
background-image: url(input_areas/images/dialog_disabled.svg);
background-color: transparent
}
input[type="date"]:focus,
input[type="time"]:focus,
input[type="datetime"]:focus,
input[type="datetime-local"]:focus {
box-shadow: none;
border-bottom-color: #c7c7c7;
}
.skin-dark input[type="date"]:focus,
.skin-dark input[type="time"]:focus,
.skin-dark input[type="datetime"]:focus,
.skin-dark input[type="datetime-local"]:focus {
box-shadow: none;
border-bottom-color: #454545;
}
input[type="date"]:active,
input[type="time"]:active,
input[type="datetime"]:active,
input[type="datetime-local"]:active {
background-color: #b2f2ff;
color: #fff;
}
.skin-dark input[type="date"]:active,
.skin-dark input[type="time"]:active,
.skin-dark input[type="datetime"]:active,
.skin-dark input[type="datetime-local"]:active {
background-color: #00aacc;
background-image: url(input_areas/images/dialog_active.svg);
}
/* fix for required inputs with wrong or empty value e.g. [type=email] */
input:invalid,
textarea:invalid,
.skin-dark input:invalid,
.skin-dark textarea:invalid {
color: #b90000;
}
input:focus,
textarea:focus,
.skin-dark input:focus,
.skin-dark textarea:focus {
box-shadow: inset 0 -0.1rem 0 #00caf2;
border-bottom-color: #00caf2;
}
input:invalid:focus,
textarea:invalid:focus,
.skin-dark input:invalid:focus,
.skin-dark textarea:invalid:focus {
box-shadow: inset 0 -0.1rem 0 #820000;
border-bottom-color: #820000;
}
input[type="range"]:focus,
.skin-dark input[type="range"]:focus {
box-shadow: none;
border-bottom: 0;
}
/* Tidy (search/submit) */
form[role="search"] {
position: relative;
height: 3.7rem;
background: #f4f4f4;
}
form[role="search"].skin-dark {
background: #202020;
}
form[role="search"] p {
padding: 0 1.5rem 0 3rem;
overflow: hidden;
position: relative;
}
form[role="search"] p input,
form[role="search"] p textarea {
height: 3.7rem;
border: none;
background: none;
padding: 0;
margin: 0;
box-shadow: none;
}
form[role="search"] p textarea {
padding: 1rem 0 0 0;
}
form[role="search"] p input::-moz-placeholder {
background: url(input_areas/images/search.svg) right -0.5rem center no-repeat;
background-size: 3rem;
}
form[role="search"].skin-dark p input::-moz-placeholder {
background-image: url(input_areas/images/search_dark.svg);
}
form[role="search"] p input:focus::-moz-placeholder {
background: none;
}
form[role="search"] p input:invalid,
form[role="search"] p textarea:invalid,
form[role="search"] p input:focus,
form[role="search"] p textarea:focus {
border: none;
box-shadow: none;
}
form[role="search"].skin-dark p input,
form[role="search"].skin-dark p textarea {
color: #fff;
background: none;
box-shadow: none;
}
form[role="search"] button[type="submit"] {
float: right;
min-width: 6rem;
height: 3.7rem;
padding: 0 1.5rem;
border: none;
color: #00aac5;
font-weight: normal;
font-size: 1.6rem;
line-height: 3.7rem;
width: auto;
border-radius: 0;
margin: 0;
position: relative;
background-image: none;
background-color: unset;
font-style: italic;
overflow: visible;
}
form[role="search"] button[type="submit"]:after {
content: "";
position: absolute;
left: -0.1rem;
top: 0.7rem;
bottom: 0.7rem;
width: 0.1rem;
background: #c7c7c7;
}
form[role="search"] button[type="submit"].icon {
font-size: 0;
background-repeat: no-repeat;
background-position: center;
background-size: 3rem;
}
form[role="search"] p input + button[type="reset"]{
height: 3.7rem;
right: 0.5rem;
}
form[role="search"].skin-dark button[type="submit"]:after {
background-color: #575757;
}
form[role="search"] button[type="submit"] + p > textarea {
height: 3.7rem;
line-height: 2rem;
}
form[role="search"] button[type="submit"] + p button {
height: 3.7rem;
}
form[role="search"].full button[type="submit"] {
display: none;
}
form[role="search"] button.icon:active,
form[role="search"] button[type="submit"]:active {
background-color: #b2f2ff;
color: #fff;
}
form[role="search"].skin-dark button.icon:active,
form[role="search"].skin-dark button[type="submit"]:active {
background: #00aacc;
}
form[role="search"] button[type="submit"][disabled] {
color: #adadad;
pointer-events: none;
}
form button::-moz-focus-inner {
border: none;
outline: none;
}
/* .bb-editable - e.g email & SMS recipients */
.bb-editable [contenteditable] {
display: inline-block;
box-sizing: border-box;
position: relative;
max-width: calc(100% - 1.4rem);
overflow: hidden;
padding: 0 1.5rem;
margin: 0 0 0.6rem 0;
line-height: 2.8rem;
border-radius: 1.4rem;
text-overflow: ellipsis;
font-size: 1.6rem;
font-style: italic;
white-space: nowrap;
color: #333;
background: #fff;
}
.bb-editable [contenteditable].icon {
padding-right: 3.7rem;
}
.bb-editable [contenteditable="false"].invalid {
background-color: #fedcdc;
padding-left: 3.3rem;
}
.bb-editable [contenteditable="false"].invalid:before {
content: "!";
position: absolute;
top: 0.6rem;
left: 0.8rem;
display: block;
width: 1.7rem;
height: 1.6rem;
padding: 0;
border-radius: 50%;
line-height: 1.6rem;
font-size: 1.2rem;
text-align: center;
text-indent: -0.1rem;
font-style: normal;
font-weight: 600;
color: #fff;
background-color: #b80404;
}
.bb-editable [contenteditable="false"].invalid:hover:before,
.bb-editable [contenteditable="false"].invalid:active:before {
color: #b2f2ff;
background-color: #fff;
}
.bb-editable [contenteditable]:hover,
.bb-editable [contenteditable]:active,
.bb-editable [contenteditable].invalid:hover,
.bb-editable [contenteditable].invalid:active {
color: #fff;
background-color: #b2f2ff;
}
.bb-editable [contenteditable].icon:after {
content: "";
position: absolute;
top: 0.7rem;
right: 0;
width: 3rem;
height: 3rem;
background-position: -0.7rem -3.8rem;
background-repeat: no-repeat;
background-size: 3rem;
}
.bb-editable [contenteditable].icon:hover:after,
.bb-editable [contenteditable].icon:active:after {
background-position: -0.7rem -0.8rem;
}
.bb-editable [contenteditable].invalid.icon:after {
background-position: -0.7rem -6.8rem;
}
.bb-editable [contenteditable].invalid.icon:hover:after,
.bb-editable [contenteditable].invalid.icon:active:after {
background-position: -0.7rem -0.8rem;
}
.bb-editable [contenteditable="true"],
.bb-editable [contenteditable="true"]:hover,
.skin-comms .bb-editable [contenteditable="true"]:hover {
padding: 0 0.2rem;
white-space: normal;
font-size: 1.8rem;
font-style: normal;
color: #000;
background: none repeat scroll 0 0 transparent;
}
.skin-comms .bb-editable [contenteditable]:hover,
.skin-comms .bb-editable [contenteditable]:active {
color: #fff;
background-color: #29bbb5;
}
/******************************************************************************
* Right-to-Left layout
*/
html[dir="rtl"] ::-moz-placeholder {
text-align: right;
}
html[dir="rtl"] fieldset legend {
background: rgba(0,0,0,0.05) url(input_areas/images/dialog_rtl.svg) no-repeat 1rem calc(100% - 1rem);
}
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="time"],
html[dir="rtl"] input[type="datetime"],
html[dir="rtl"] input[type="datetime-local"] {
background: #fff url(input_areas/images/dialog_rtl.svg) no-repeat 1rem calc(100% - 1rem);
}
html[dir="rtl"] fieldset[disabled] legend,
html[dir="rtl"] input[type="date"][disabled],
html[dir="rtl"] input[type="time"][disabled],
html[dir="rtl"] input[type="datetime"][disabled],
html[dir="rtl"] input[type="datetime-local"][disabled] {
background-image: url(input_areas/images/dialog_disabled_rtl.svg);
}
html[dir="rtl"] form p input:focus {
padding: 0 1.5rem 0 3rem;
}
html[dir="rtl"] form p input + button[type="reset"],
html[dir="rtl"] form p textarea + button[type="reset"] {
right: auto;
left: -0.3rem;
}
html[dir="rtl"] form[role="search"] p {
padding: 0 3rem 0 1.5rem;
}
html[dir="rtl"] form[role="search"] p input + button[type="reset"]{
left: 0.5rem;
}
html[dir="rtl"] form[role="search"] p input::-moz-placeholder {
background-position: -0.5rem center;
}
html[dir="rtl"] form[role="search"] button[type="submit"] {
float: left;
}
html[dir="rtl"] form[role="search"] button[type="submit"]:after {
right: 0;
left: auto;
}