Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 8a1216a

Browse files
committed
added prompt() equivalent mscPrompt()
1 parent 4390e44 commit 8a1216a

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#### joe made this: http://goel.io/joe
2+
3+
#####=== OSX ===#####
4+
.DS_Store
5+
.AppleDouble
6+
.LSOverride
7+
8+
# Icon must end with two \r
9+
Icon
10+
11+
# Thumbnails
12+
._*
13+
14+
# Files that might appear on external disk
15+
.Spotlight-V100
16+
.Trashes
17+
18+
# Directories potentially created on remote AFP share
19+
.AppleDB
20+
.AppleDesktop
21+
Network Trash Folder
22+
Temporary Items
23+
.apdisk
24+

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "medium-style-confirm",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"homepage": "http://bitwiser.i/medium-style-confirm/",
55
"authors": [
66
"Brijesh Bittu <brijeshb42@gmail.com>"

css/msc-style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@
9595
margin-bottom: 1em;
9696
color: #666;
9797
}
98+
.msc-body p {
99+
margin: 0 0 10px 0;
100+
}
101+
102+
.msc-input {
103+
box-sizing: border-box;
104+
width: 100%;
105+
height: 38px;
106+
font-size: 14px;
107+
text-align: center;
108+
letter-spacing: 0.02em;
109+
font-weight: 400;
110+
font-style: normal;
111+
font-family: "Lucida Grande","Lucida Sans Unicode","Lucida Sans",Geneva,Verdana,sans-serif;
112+
border: none;
113+
border-bottom: 1px solid rgba(0,0,0,0.15);
114+
padding: 0 15px;
115+
}
116+
117+
.msc-input:focus {
118+
outline: none;
119+
border-color: #0F985A;
120+
}
121+
98122

99123
.msc-action button {
100124
border: 1px solid #ccc;

js/msc-script.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
return ele;
1111
}
1212
var KEY_ESC = 27;
13+
var KEY_ENTER = 13;
1314

14-
var MscConfirm = function(title, sub, onOk, onCancel) {
15+
function buildUI(title, sub, onOk, onCancel, type) {
1516
var prev = document.getElementsByClassName('msc-confirm');
1617
if(prev.length > 0){
1718
document.body.removeChild(prev[0]);
@@ -30,6 +31,12 @@
3031
for(var key in title) {
3132
options[key] = title[key];
3233
}
34+
if(typeof options.onOk !== 'function') {
35+
options.onOk = null;
36+
}
37+
if(typeof options.onCancel !== 'function') {
38+
options.onCancel = null;
39+
}
3340
} else {
3441
options.title = (typeof title === 'string') ? title : options.title;
3542
options.subtitle = (typeof sub === 'string') ? sub : options.subtitle;
@@ -51,10 +58,13 @@
5158

5259
var content = ce('div', 'msc-content'),
5360
cTitle = ce('h3', 'msc-title', options.title),
54-
body = ce('div', 'msc-body', options.subtitle),
61+
body = ce('div', 'msc-body'),
5562
action = ce('div', 'msc-action'),
5663
okBtn = ce('button', 'msc-ok', options.okText),
57-
cancelbtn = ce('button', 'msc-cancel', options.cancelText);
64+
cancelbtn = ce('button', 'msc-cancel', options.cancelText),
65+
input = ce('input', 'msc-input');
66+
67+
body.appendChild(ce('p','', options.subtitle));
5868

5969
action.appendChild(okBtn);
6070
action.appendChild(cancelbtn);
@@ -71,7 +81,18 @@
7181
document.body.appendChild(dialog);
7282
dialog.style.display = 'block';
7383
content.classList.add('msc-confirm--animate');
74-
cancelbtn.focus();
84+
if(type === "prompt") {
85+
input.setAttribute("type", "text");
86+
input.addEventListener("keyup", function(e) {
87+
if(e.keyCode === KEY_ENTER) {
88+
ok();
89+
}
90+
});
91+
body.appendChild(input);
92+
input.focus();
93+
}else {
94+
cancelbtn.focus();
95+
}
7596

7697
document.addEventListener('keyup', _hide);
7798

@@ -86,7 +107,11 @@
86107
function ok() {
87108
destroy();
88109
if(options.onOk !== null) {
89-
options.onOk();
110+
if(type === "prompt") {
111+
options.onOk(input.value);
112+
}else {
113+
options.onOk();
114+
}
90115
}
91116
}
92117

@@ -103,7 +128,11 @@
103128
}
104129
}
105130
};
106-
107131
//window.msc = MscConfirm;
108-
window.mscConfirm = MscConfirm;
132+
window.mscConfirm = function(title, sub, onOk, onCancel) {
133+
buildUI(title, sub, onOk, onCancel, "confirm");
134+
};
135+
window.mscPrompt = function(title, sub, onOk, onCancel) {
136+
buildUI(title, sub, onOk, onCancel, "prompt");
137+
};
109138
})();

0 commit comments

Comments
 (0)