Skip to content

Commit 2ef3752

Browse files
committed
first msgbox
0 parents  commit 2ef3752

File tree

6 files changed

+312
-0
lines changed

6 files changed

+312
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
jQuery MsgBox
2+
=============
3+
4+
What is it?
5+
-----------
6+
7+
Firefox style simplist dialog form.
8+
9+
10+
How to use this?
11+
----------------
12+
13+
It's quiet simple.
14+
15+
```html
16+
<script src="jquery.lastest.js"></script>
17+
<script src="jquery.msgbox.min.js"></script>
18+
```
19+
20+
alert("i'm alert");
21+
-> $.alert("i'm alert");
22+
23+
confirm("Are you sure?");
24+
-> $.confirm("Are you sure?");
25+
26+
prompt("please text me.");
27+
-> $.prompt("please text me.");
28+
29+
Wait! YOU MUST SEE BEFORE USE THIS PLUGIN,
30+
------------------------------------------
31+
this plugin is can't replace as javascript standard function (alert, etc.)
32+
because, this plugin cannot wait user action while showing dialog.
33+
If you want get user's action, put a callback function in next of message param.
34+
when user clicked in a dialog button, such as OK or cancel, msgbox will call your defined function.
35+
36+
OK. so, How to use with callback function?
37+
------------------------------------------
38+
39+
jQuery.MsgBox can add your callback function for provide next action after user clicked.
40+
It's Very simple.
41+
42+
```js
43+
$.alert("click me.",function(){
44+
$.alert('you clicked');
45+
});
46+
```
47+
```js
48+
$.confirm("press OK or Cancel.",function(bool){
49+
$.alert('you clicked'+(bool?'OK':'cancel'));
50+
});
51+
```
52+
```js
53+
$.prompt("what's your name?",function(string){
54+
$.alert('your name is '+string);
55+
});
56+
```
57+
58+
What browser can run with this plugin?
59+
--------------------------------------
60+
first, jQuery 1.4 or later needed.
61+
and, You can run with most popular major browser,
62+
Internet Explorer 8 or above, Firefox 3 or above, Safari 4 or above, Chrome 10 or above, Opera 9 or above.
63+
NOTE : Old school browser, such as IE 7 or lower is have a problem with CSS issue.
64+
that's all. this plugin have NO images or other resources.
65+
66+
Wow! It's simple and cool! can I join with you for make better this plugin?
67+
---------------------------------------------------------------------------
68+
69+
Sure. contributes are welcome! just fork this plugin and get involved to make a better place for you and for me.
70+
71+
72+
License
73+
-------
74+
75+
(The MIT License)
76+
77+
Copyright (c) 2011-2012 ukjin yang <ukjinplant@msn.com>
78+
79+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
80+
81+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

demo.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>MsgBox 데모</title>
6+
</head>
7+
<body>
8+
<button onclick="alert('테스트 경고창입니다.')">일반 경고창</button>
9+
<button onclick="$.alert('테스트 경고창입니다.')">경고창</button>
10+
<button onclick="$.alert('테스트 경고창입니다. 세상에서 가장 긴 그림은 긴 기린 보고 그린 길다란 기린 그림 ',function(){$.alert('참 길죠잉?');})">긴 경고창</button>
11+
<button onclick="$.confirm('테스트 하시겠습니까?',function(b){$.alert((b?'확인':'취소')+' 하셨습니다.');})">질문창</button>
12+
<button onclick="$.prompt('이름을 입력하세요.',function(s){$.alert('이름은 : '+s);})">입력창</button>
13+
<button onclick="$.prompt('이름을 입력하세요. 세상에서 가장 긴 그림은 긴 기린 보고 그린 길다란 기린 그림 ','test',function(s){$.alert('이름은 : '+s);})">긴 입력창</button>
14+
<button onclick="alert(prompt('이름을 입력하세요. 세상에서 가장 긴 그림은 긴 기린 보고 그린 길다란 기린 그림 ','test'))">일반 입력창</button>
15+
<script src="jquery-1.7.2.min.js"></script>
16+
<script src="jquery.msgbox.min.js"></script>
17+
<script>
18+
for(var i=0;i<100;i++){
19+
document.write('<br/>');
20+
}
21+
</script>
22+
</body>
23+
</html>

jquery-1.7.2.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.msgbox.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**************************************************************************************
2+
* jQuery MsgBox 0.2.6
3+
* by composite (ukjinplant@msn.com)
4+
* http://blog.hazard.kr
5+
* This project licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
6+
**************************************************************************************/
7+
;(function($){
8+
var nofix=$.browser.msie&&~~$.browser.version<8,
9+
fixed=nofix?'absolute':'fixed';
10+
$.msgbox=function(msg,options){
11+
//옵션 가공
12+
options=$.extend({},$.msgbox.options,options);
13+
//변수 및 요소 정의
14+
var io={},mb='msgbox-',cok=mb+'-ok',cno=mb+'-no',pw='password',styles=options.css||{},t=!0,f=!1,p=('input' in options),q=!!options.confirm,
15+
$C=$("<div></div>").addClass(mb+'ui').css(styles.ui||{}),//경고창
16+
$M=$("<div>&shy;</div>").addClass(mb+'modal').css(styles.modal||{}),//경고창 배경
17+
$T=$("<pre></pre>").addClass(mb+'msg').css(styles.msg||{}).html(msg).appendTo($C),//경고 내용
18+
$I=p?$("<div><input type='"+(options[pw]?pw:'text')+"'/></div>").addClass(mb+'inbox').css(styles.indiv||{})
19+
.children().addClass(mb+'input').css(styles.input||{}).end().appendTo($C):null,//입력 모드시 입력창
20+
$B=$("<div></div>").addClass(mb+'buttons').css(styles.buttons||{}).appendTo($C),//경고 버튼 나열
21+
$BT=$("<button></button>").addClass(mb+'button').css(styles.button||{}),//버튼 원형
22+
$BS=[
23+
$BT.clone(t).addClass(cok).text(q?options.yes:options.ok).appendTo($B)
24+
,p||q?$BT.clone(t).addClass(cno).text(options.no).appendTo($B):null
25+
];//경고 버튼들
26+
//입력 모드시 조치사항
27+
if(p){
28+
options.confirm=t;//확인 모드 맞음.
29+
if(typeof(options.input)=='string') $I.children().val(options.input);
30+
}
31+
//경고창 비활성화 전
32+
io.before=function(e){
33+
var code=window.event?window.event.keyCode:e.which;
34+
switch(code){
35+
case 13:$C.find('button.'+cok).trigger('click');return f;
36+
case 0:case 27:$C.find('button.'+(p||q?cno:cok)).trigger('click');return f;
37+
}
38+
};
39+
//body에 삽입 후 레이아웃 잡기
40+
var kp='keypress',kt='.'+mb+'ui,.'+mb+'modal',$D=$(document.documentElement?document.documentElement:document.body)
41+
.append($M).append($C).bind(kp,io.before);
42+
//$C.add($M).keypress(io.before);
43+
//경고창 비활성화 후
44+
io.after=function(b,v){
45+
for(var i=0,cn=b.className.split(' ');i<cn.length;i++)
46+
switch(cn[i]){
47+
case cok:
48+
switch(t){
49+
case p:options.submit.call($C[0],v);break;
50+
case q:options.submit.call($C[0],!!t);break;
51+
default:options.submit.call($C[0]);break;
52+
}
53+
break;
54+
case cno:
55+
if(p||!(p&&q)){
56+
options.submit.call($C[0]);
57+
}else{
58+
options.submit.call($C[0],f);
59+
}
60+
break;
61+
}
62+
$D.unbind(kp,io.before);
63+
};
64+
//공통 경고 클릭 시 조치
65+
$C.delegate('button','click',function(e){
66+
$C.add($M).remove();
67+
io.after(this,p?$I.children().val():null);
68+
}).delegate('input','keypress',io.before);
69+
//레이아웃 자동정렬
70+
if(styles.ui)
71+
$C.css({
72+
'margin-left':~~(-$C.outerWidth()*0.5)+'px',
73+
'margin-top':~~(-$C.outerHeight()*0.75)+'px'
74+
});
75+
//경고창 포커스
76+
if(p) $C.find('input:text').select(); else $C.find('button:eq(0)').focus();
77+
return $C;
78+
};
79+
$.extend($.msgbox,{
80+
strings:{
81+
ok:'OK',
82+
yes:'OK',
83+
no:'Cancel'
84+
},
85+
css:{
86+
ui:{
87+
'border':'1px solid black','font':'9pt verdana,gulim,sans-serif',
88+
'background-color':'white',
89+
'position':fixed,'left':'50%','top':'50%','overflow':'hidden'
90+
},modal:{
91+
'position':fixed,'left':'0','top':'0','right':'0','bottom':'0',
92+
'background-color':'black','opacity':'.5'
93+
},msg:{
94+
'padding':'2em 4em','overflow':'hidden','font-family':'verdana,gulim,sans-serif'//,'max-width':(screen.availWidth*0.9)+'px'
95+
},buttons:{
96+
'padding':'1em',
97+
'background-color':'#eee',
98+
'text-align':'right','overflow':'hidden'
99+
},button:{
100+
'width':'72px','margin':'auto .25em'
101+
},indiv:{
102+
'width':'90%','margin':'-2em auto 2em','border':'1px inset #3D7BAD'
103+
},input:{
104+
'width':'100%','display':'block','border':'0'
105+
}
106+
}
107+
});
108+
$.msgbox.options={
109+
submit:function(){},
110+
confirm:false,//input:false,
111+
css:$.msgbox.css,
112+
ok:$.msgbox.strings.ok,
113+
yes:$.msgbox.strings.yes,
114+
no:$.msgbox.strings.no
115+
};
116+
$.alert=function(msg,callback){
117+
return $.msgbox(msg,{
118+
submit:callback
119+
});
120+
};
121+
$.confirm=function(msg,callback){
122+
return $.msgbox(msg,{
123+
confirm:true,
124+
submit:callback
125+
});
126+
};
127+
$.prompt=function(msg,val,callback,pw){
128+
var shift=$.isFunction(val);
129+
return $.msgbox(msg,{
130+
input:shift?true:val,
131+
submit:shift?val:callback,
132+
password:shift?callback:pw
133+
});
134+
};
135+
})(jQuery);

jquery.msgbox.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
jQuery MsgBox 0.2.6 Beta
2+
3+
MIT License
4+
5+
Basic Usage :
6+
7+
$.alert(message,callback) : normal alert
8+
message : alert message
9+
callback : a function that call after user clicked ok button.
10+
function(){
11+
//'this' keyword scopes alert container.
12+
}
13+
14+
$.confirm(message,callback) : normal confirm
15+
message : confirm message
16+
callback : a function that call after user click ok or cancel button
17+
function(bool){
18+
//bool is a boolean value that true if user click ok, false if user click cancel.
19+
//'this' keyword scopes alert container.
20+
}
21+
22+
$.prompt(message,value,callback,ispassword) : normal prompt alert
23+
message : prompt message
24+
value : a string value that default prompt value.
25+
callback : a function that call after user click ok or cacel button
26+
function(value){
27+
//value will provide user prompt value to your callback function.
28+
//when user clicked ok, value arg will provide user defined value.
29+
//but when user clicked cacel, value arg will provide 'undefined' value. NOT NULL. UNDEFINED.
30+
//when user input no word in prompt value and clicked ok, value arg will provide empty string.
31+
//'this' keyword scopes alert container.
32+
}
33+
34+
Advenced Usage :
35+
36+
$.msgbox(message,options) : A prototype of jQuery msgbox function.
37+
message : A message of msgbox.
38+
options : A options.
39+
submit : callback function. default is null.
40+
confirm : the msgbox will user confirm box, true. otherwise, false. default is false.
41+
input : the msgbox will prompt, give true or value string. otherwise you shouldn't define this option.
42+
css : a jQuery style css json value. default is firefox style defined css.
43+
ui : msgbox container style
44+
modal : modal background style
45+
msg : message area style
46+
buttons : common button style
47+
indiv : text input container style
48+
input : test input style
49+
ok : a string defined alert ok button. default is 'OK'.
50+
yes : a string defined confirm or prompt ok button. default is 'OK'.
51+
no : a string defined confirm or prompt cancel button. default is 'Cancel'.
52+
53+
Tested Browser :
54+
Internet Explorer 8 or above, Firefox 3 or above, Chrome 9 or above, Safari 3 or above.
55+
NOT Supported Browser : Internet Explorer 7 or lower due to CSS issue. but you can define alternative css to prevent not support browser issue.
56+
jQuery 1.4 or above. (delegate method used.)
57+
58+
Known Issues :
59+
60+
jQuery MsgBox is NOT awaiting user confirmation while script running. you should give callback function to provide next process.

0 commit comments

Comments
 (0)