From d2ac632ce40164668e1f0040806865688018ffb8 Mon Sep 17 00:00:00 2001 From: composite Date: Mon, 16 Jul 2012 17:55:01 +0900 Subject: [PATCH 01/27] new in 0.3.6 : keyboard event added. such as tab, arrow keys. --- demo.html | 2 +- jquery.msgbox.js | 70 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/demo.html b/demo.html index 7e842f8..51b685b 100644 --- a/demo.html +++ b/demo.html @@ -13,7 +13,7 @@ - + - -``` - -alert("i'm alert"); --> $.alert("i'm alert"); - -confirm("Are you sure?"); --> $.confirm("Are you sure?"); - -prompt("please text me."); --> $.prompt("please text me."); - -Wait! YOU MUST SEE BEFORE USE THIS PLUGIN, ------------------------------------------- -this plugin is can't replace as javascript standard function (alert, etc.) -because, this plugin cannot wait user action while showing dialog. -If you want get user's action, put a callback function in next of message param. -when user clicked in a dialog button, such as OK or cancel, msgbox will call your defined function. - -OK. so, How to use with callback function? ------------------------------------------- - -jQuery.MsgBox can add your callback function for provide next action after user clicked. -It's Very simple. - -```js -$.alert("click me.",function(){ - $.alert('you clicked'); -}); -``` -```js -$.confirm("press OK or Cancel.",function(bool){ - $.alert('you clicked'+(bool?'OK':'cancel')); -}); -``` -```js -$.prompt("what's your name?",function(string){ - $.alert('your name is '+string); -}); -``` - -I want view live example. -------------------------- - -OK. [here an example](http://jsfiddle.net/preFy/ "live example"). - -What browser can run with this plugin? --------------------------------------- -first, jQuery 1.4 or later needed. -and, You can run with most popular major browser, -Internet Explorer 8 or above, Firefox 3 or above, Safari 4 or above, Chrome 10 or above, Opera 9 or above. -NOTE : Old school browser, such as IE 7 or lower is have a problem with CSS issue. -that's all. this plugin have NO images or other resources. - -Wow! It's simple and cool! can I join with you for make better this plugin? ---------------------------------------------------------------------------- - -Sure. contributes are welcome! just fork this plugin and get involved to make a better place for you and for me. - - -License -------- - -(The MIT License) - -Copyright (c) 2011-2012 Ukjin 'composite' Yang - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - +jQuery MsgBox +============= + +0.3.7 BETA + +What is it? +----------- + +Firefox style simplist dialog form. + + +How to use this? +---------------- + +It's quiet simple. + +```html + + +``` + +alert("i'm alert"); +-> $.alert("i'm alert"); + +confirm("Are you sure?"); +-> $.confirm("Are you sure?"); + +prompt("please text me."); +-> $.prompt("please text me."); + +Wait! YOU MUST SEE BEFORE USE THIS PLUGIN, +------------------------------------------ +this plugin is can't replace as javascript standard function (alert, etc.) +because, this plugin cannot wait user action while showing dialog. +If you want get user's action, put a callback function in next of message param. +when user clicked in a dialog button, such as OK or cancel, msgbox will call your defined function. + +OK. so, How to use with callback function? +------------------------------------------ + +jQuery.MsgBox can add your callback function for provide next action after user clicked. +It's Very simple. + +```js +$.alert("click me.",function(){ + $.alert('you clicked'); +}); +``` +```js +$.confirm("press OK or Cancel.",function(bool){ + $.alert('you clicked'+(bool?'OK':'cancel')); +}); +``` +```js +$.prompt("what's your name?",function(string){ + $.alert('your name is '+string); +}); +``` + +I want view live example. +------------------------- + +OK. [here's an example](http://jsfiddle.net/preFy/ "live example"). + +What browser can run with this plugin? +-------------------------------------- +first, jQuery 1.4 or later needed. +and, You can run with most popular major browser, +Internet Explorer 8 or above, Firefox 3 or above, Safari 4 or above, Chrome 10 or above, Opera 9 or above. +NOTE : Old school browser, such as IE 7 or lower is have a problem with CSS issue. +that's all. this plugin have NO images or other resources. + +Wow! It's simple and cool! can I join with you for make better this plugin? +--------------------------------------------------------------------------- + +Sure. contributes are welcome! just fork this plugin and get involved to make a better place for you and for me. + + +License +------- + +(The MIT License) + +Copyright (c) 2011-2012 Ukjin 'composite' Yang + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + 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. \ No newline at end of file diff --git a/jquery.msgbox.js b/jquery.msgbox.js index 0b6b78f..61f7c5c 100644 --- a/jquery.msgbox.js +++ b/jquery.msgbox.js @@ -1,217 +1,226 @@ -/************************************************************************************** - * jQuery MsgBox 0.3.6 - * by composite (ukjinplant@msn.com) - * http://blog.hazard.kr - * This project licensed under a MIT License. - **************************************************************************************/; -(function ($) { - var nofix = $.browser.msie && ~~$.browser.version < 8, - fixed = nofix ? 'absolute' : 'fixed'; - $.msgbox = function (msg, options) { - //옵션 가공 - options = $.extend({}, $.msgbox.options, options); - //변수 및 요소 정의 - 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, - iae = function(e) { //포커스된 요소가 메시지박스 아니면 메시지박스로 강제 포커스 이동 - setTimeout(function(){ - var act=$(document.activeElement),ms=['.'+mb+'input','.'+mb+'button']; - if(act.length&&(act.is(ms[0])||act.is(ms[1]))){console.log('good.');} - else $C.find(ms+'').eq(0).focus(); - },0); - }, - $C = $("
").addClass(mb + 'ui').css(styles.ui || {}), - //경고창 - $M = $("
­
").addClass(mb + 'modal').css(styles.modal || {}), - //경고창 배경 - $T = $("
").addClass(mb + 'msg').css(styles.msg || {}).html(msg).appendTo($C),
-            //경고 내용
-            $I = p ?
-				$("
").addClass(mb + 'inbox').css(styles.indiv || {}).children() - .addClass(mb + 'input').css(styles.input || {}).bind('keydown',function(e){//탭의 역순 시 마지막 버튼 포커스 - if((window.event ? window.event.keyCode : e.which)==9&&e.shiftKey){ - e.preventDefault(); - $C.find('.'+mb+'button').filter(':last').focus(); - } - }).bind('blur',iae).end().appendTo($C) - : null, - //입력 모드시 입력창 - $B = $("
").addClass(mb + 'buttons').css(styles.buttons || {}).appendTo($C), - //경고 버튼 나열 - $BT = $("").addClass(mb + 'button').css(styles.button || {}).bind('keydown',function(e){ - if(this!=document.activeElement) return; - e.stopPropagation(); - var code = window.event ? window.event.keyCode : e.which,that=$(this),target,shift=e.shiftKey; - switch (code) { - case 9://탭키 누르면 다음 버튼 및 입력창 포커스 - case 39://오른쪽키 누르면 다음 버튼으로만 포커스 - e.preventDefault(); - if(target=that[code==9&&shift?'prev':'next']('button'),target.length) target.focus(); - else if(code==9){ - if(target=$C.find('.'+mb+'input'),target.length) target.select(); - else if(target=that[shift?'next':'prev']('button'),target.length) target.focus(); - } - break; - case 37://왼쪽키는 이전 버튼으로만 포커스 - e.preventDefault(); - if(target=that.prev('button'),target.length) target.focus(); - break; - case 27://ESC는 무조건 취소처리 - e.preventDefault(); - $C.find('button.' + (p || q ? cno : cok)).trigger('click'); - break; - } - }).bind('blur',iae), - //버튼 원형 - $BS = [ - $BT.clone(t).addClass(cok).text(q ? options.yes : options.ok).appendTo($B), p || q ? $BT.clone(t).addClass(cno).text(options.no).appendTo($B) : null]; //경고 버튼들 - $C.add($M).bind('keydown',function(){}); - //입력 모드시 조치사항 - if (p) { - options.confirm = t; //확인 모드 맞음. - if (typeof (options.input) == 'string') $I.children().val(options.input); - } - //경고창 비활성화 전 - io.before = function (e) { - var code = window.event ? window.event.keyCode : e.which; - switch (code) { - case 27: - $C.find('button.' + (p || q ? cno : cok)).trigger('click'); - return f; - } - }; - //body에 삽입 후 레이아웃 잡기 - var kp = 'keypress', - kt = '.' + mb + 'ui,.' + mb + 'modal', - $D = $(document.documentElement ? document.documentElement : document.body).append($M).append($C).bind(kp, io.before); - //경고창 비활성화 후 - io.after = function (b, v) { - for (var i = 0, cn = b.className.split(' '); i < cn.length; i++) - switch (cn[i]) { - case cok: - switch (t) { - case p: - options.submit.call($C[0], v); - break; - case q: - options.submit.call($C[0], !! t); - break; - default: - options.submit.call($C[0]); - break; - } - break; - case cno: - if (p || !(p && q)) { - options.submit.call($C[0]); - } else { - options.submit.call($C[0], f); - } - break; - } - $D.unbind(kp, io.before); - }; - //공통 경고 클릭 시 조치 - $C.delegate('button', 'click', function (e) { - $C.add($M).remove(); - io.after(this, p ? $I.children().val() : null); - }).delegate('input', 'keypress', io.before); - //레이아웃 자동정렬 - if (styles.ui) $C.css({ - 'margin-left': ~~ (-$C.outerWidth() * 0.5) + 'px', - 'margin-top': ~~ (-$C.outerHeight() * 0.32) + 'px' - }); - //경고창 포커스 - if (p) $C.find('input:text').select(); - else $C.find('button:eq(0)').focus(); - return $C; - }; - $.extend($.msgbox, { - strings: { - ok: 'OK', - yes: 'OK', - no: 'Cancel' - }, - css: { - ui: { - 'border': '1px solid black', - 'font': '9pt verdana,gulim,sans-serif', - 'background-color': 'white', - 'position': fixed, - 'left': '50%', - 'top': '32%', - 'overflow': 'hidden' - }, - modal: { - 'position': fixed, - 'left': '0', - 'top': '0', - 'right': '0', - 'bottom': '0', - 'background-color': 'black', - 'opacity': '.4' - }, - msg: { - 'padding': '2em 4em', - 'overflow': 'hidden', - 'font-family': 'verdana,gulim,sans-serif' //,'max-width':(screen.availWidth*0.9)+'px' - }, - buttons: { - 'padding': '1em', - 'background-color': '#eee', - 'text-align': 'right', - 'overflow': 'hidden' - }, - button: { - 'width': '72px', - 'margin': 'auto .25em' - }, - indiv: { - 'width': '90%', - 'margin': '-2em auto 2em', - 'border': '1px inset #3D7BAD' - }, - input: { - 'width': '99%', - 'display': 'block', - 'border': '0' - } - } - }); - $.msgbox.options = { - submit: function () {}, - confirm: false, - //input:false, - css: $.msgbox.css, - ok: $.msgbox.strings.ok, - yes: $.msgbox.strings.yes, - no: $.msgbox.strings.no - }; - $.alert = function (msg, callback) { - return $.msgbox(msg, { - submit: callback - }); - }; - $.confirm = function (msg, callback) { - return $.msgbox(msg, { - confirm: true, - submit: callback - }); - }; - $.prompt = function (msg, val, callback, pw) { - var shift = $.isFunction(val); - return $.msgbox(msg, { - input: shift ? true : val, - submit: shift ? val : callback, - password: shift ? callback : pw - }); - }; +/************************************************************************************** + * jQuery MsgBox 0.3.7 + * by composite (ukjinplant@msn.com) + * http://blog.hazard.kr + * This project licensed under a MIT License. + **************************************************************************************/; +(function ($) { + var nofix = $.browser.msie && ~~$.browser.version < 8, + fixed = nofix ? 'absolute' : 'fixed'; + $.msgbox = function (msg, options) { + //옵션 가공 + options = $.extend({}, $.msgbox.options, options); + //변수 및 요소 정의 + 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, + iae = function(e) { //포커스된 요소가 메시지박스 아니면 메시지박스로 강제 포커스 이동 + setTimeout(function(){ + var act=$(document.activeElement),ms=['.'+mb+'input','.'+mb+'button']; + if(act.length&&(act.is(ms[0])||act.is(ms[1]))){console.log('good.');} + else $C.find(ms+'').eq(0).focus(); + },0); + }, + $C = $("
").addClass(mb + 'ui').css(styles.ui || {}), + //경고창 + $M = $("
­
").addClass(mb + 'modal').css(styles.modal || {}), + //경고창 배경 + $T = $("
").addClass(mb + 'msg').css(styles.msg || {}).html(msg).appendTo($C),
+            //경고 내용
+            $I = p ?
+				$("
").addClass(mb + 'inbox').css(styles.indiv || {}).children() + .addClass(mb + 'input').css(styles.input || {}).bind('keydown',function(e){//탭의 역순 시 마지막 버튼 포커스 + if((window.event ? window.event.keyCode : e.which)==9&&e.shiftKey){ + e.preventDefault(); + $C.find('.'+mb+'button').filter(':last').focus(); + } + }).bind('blur',iae).end().appendTo($C) + : null, + //입력 모드시 입력창 + $B = $("
").addClass(mb + 'buttons').css(styles.buttons || {}).appendTo($C), + //경고 버튼 나열 + $BT = $("").addClass(mb + 'button').css(styles.button || {}).bind('keydown',function(e){ + if(this!=document.activeElement) return; + e.stopPropagation(); + var code = window.event ? window.event.keyCode : e.which,that=$(this),target,shift=e.shiftKey; + switch (code) { + case 9://탭키 누르면 다음 버튼 및 입력창 포커스 + case 39://오른쪽키 누르면 다음 버튼으로만 포커스 + e.preventDefault(); + if(target=that[code==9&&shift?'prev':'next']('button'),target.length) target.focus(); + else if(code==9){ + if(target=$C.find('.'+mb+'input'),target.length) target.select(); + else if(target=that[shift?'next':'prev']('button'),target.length) target.focus(); + } + break; + case 37://왼쪽키는 이전 버튼으로만 포커스 + e.preventDefault(); + if(target=that.prev('button'),target.length) target.focus(); + break; + case 27://ESC는 무조건 취소처리 + e.preventDefault(); + $C.find('button.' + (p || q ? cno : cok)).trigger('click'); + break; + } + }).bind('blur',iae), + //버튼 원형 + $BS = [ + $BT.clone(t).addClass(cok).text(q ? options.yes : options.ok).appendTo($B), p || q ? $BT.clone(t).addClass(cno).text(options.no).appendTo($B) : null]; //경고 버튼들 + $C.add($M).bind('keydown',function(){}); + //입력 모드시 조치사항 + if (p) { + options.confirm = t; //확인 모드 맞음. + if (typeof (options.input) == 'string') $I.children().val(options.input); + } + //경고창 비활성화 전 + io.before = function (e) { + e.stopPropagation(); + var code = window.event ? window.event.keyCode : e.which; + //전역 메시지박스에도 before가 붙으므로 격리. + if(e.target.type=='text'&&!code){ + $C.find('button.' + (p || q ? cno : cok)).trigger('click'); + return f; + } + switch (code) { + case 13: + $C.find('button.' + cok).trigger('click'); + return f; + case 27: + $C.find('button.' + (p || q ? cno : cok)).trigger('click'); + return f; + } + }; + //body에 삽입 후 레이아웃 잡기 + var kp = 'keypress', + kt = '.' + mb + 'ui,.' + mb + 'modal', + $D = $(document.documentElement ? document.documentElement : document.body).append($M).append($C).bind(kp, io.before); + //경고창 비활성화 후 + io.after = function (b, v) { + for (var i = 0, cn = b.className.split(' '); i < cn.length; i++) + switch (cn[i]) { + case cok: + switch (t) { + case p: + options.submit.call($C[0], v); + break; + case q: + options.submit.call($C[0], !! t); + break; + default: + options.submit.call($C[0]); + break; + } + break; + case cno: + if (p || !(p && q)) { + options.submit.call($C[0]); + } else { + options.submit.call($C[0], f); + } + break; + } + $D.unbind(kp, io.before); + }; + //공통 경고 클릭 시 조치 + $C.delegate('button', 'click', function (e) { + $C.add($M).remove(); + io.after(this, p ? $I.children().val() : null); + }); + //레이아웃 자동정렬 + if (styles.ui) $C.css({ + 'margin-left': ~~ (-$C.outerWidth() * 0.5) + 'px', + 'margin-top': ~~ (-$C.outerHeight() * 0.32) + 'px' + }); + //경고창 포커스 + if (p) $C.find('input:text').select(); + else $C.find('button:eq(0)').focus(); + return $C; + }; + $.extend($.msgbox, { + strings: { + ok: 'OK', + yes: 'OK', + no: 'Cancel' + }, + css: { + ui: { + 'border': '1px solid black', + 'font': '9pt verdana,gulim,sans-serif', + 'background-color': 'white', + 'position': fixed, + 'left': '50%', + 'top': '32%', + 'overflow': 'hidden' + }, + modal: { + 'position': fixed, + 'left': '0', + 'top': '0', + 'right': '0', + 'bottom': '0', + 'background-color': 'black', + 'opacity': '.4' + }, + msg: { + 'padding': '2em 4em', + 'overflow': 'hidden', + 'font-family': 'verdana,gulim,sans-serif' //,'max-width':(screen.availWidth*0.9)+'px' + }, + buttons: { + 'padding': '1em', + 'background-color': '#eee', + 'text-align': 'right', + 'overflow': 'hidden' + }, + button: { + 'width': '72px', + 'margin': 'auto .25em' + }, + indiv: { + 'width': '90%', + 'margin': '-2em auto 2em', + 'border': '1px inset #3D7BAD' + }, + input: { + 'width': '99%', + 'display': 'block', + 'border': '0' + } + } + }); + $.msgbox.options = { + submit: function () {}, + confirm: false, + //input:false, + css: $.msgbox.css, + ok: $.msgbox.strings.ok, + yes: $.msgbox.strings.yes, + no: $.msgbox.strings.no + }; + $.alert = function (msg, callback) { + return $.msgbox(msg, { + submit: callback + }); + }; + $.confirm = function (msg, callback) { + return $.msgbox(msg, { + confirm: true, + submit: callback + }); + }; + $.prompt = function (msg, val, callback, pw) { + var shift = $.isFunction(val); + return $.msgbox(msg, { + input: shift ? true : val, + submit: shift ? val : callback, + password: shift ? callback : pw + }); + }; })(jQuery); \ No newline at end of file diff --git a/jquery.msgbox.min.js b/jquery.msgbox.min.js index 54869fa..accbb31 100644 --- a/jquery.msgbox.min.js +++ b/jquery.msgbox.min.js @@ -1,7 +1,7 @@ -/*************************************************************** - * jQuery MsgBox 0.2.6 - * by composite (ukjinplant@msn.com) - * http://blog.hazard.kr - * Licensed under MIT License. - ***************************************************************/ - (function(b){var c=b.browser.msie&&~~b.browser.version<8,a=c?"absolute":"fixed";b.msgbox=function(h,g){g=b.extend({},b.msgbox.options,g);var j={},d="msgbox-",i=d+"-ok",B=d+"-no",o="password",k=g.css||{},m=!0,y=!1,u=("input" in g),r=!!g.confirm,z=b("
").addClass(d+"ui").css(k.ui||{}),v=b("
­
").addClass(d+"modal").css(k.modal||{}),l=b("
").addClass(d+"msg").css(k.msg||{}).html(h).appendTo(z),w=u?b("
").addClass(d+"inbox").css(k.indiv||{}).children().addClass(d+"input").css(k.input||{}).end().appendTo(z):null,A=b("
").addClass(d+"buttons").css(k.buttons||{}).appendTo(z),n=b("").addClass(d+"button").css(k.button||{}),s=[n.clone(m).addClass(i).text(r?g.yes:g.ok).appendTo(A),u||r?n.clone(m).addClass(B).text(g.no).appendTo(A):null];if(u){g.confirm=m;if(typeof(g.input)=="string"){w.children().val(g.input)}}j.before=function(p){var f=window.event?window.event.keyCode:p.which;switch(f){case 13:z.find("button."+i).trigger("click");return y;case 0:case 27:z.find("button."+(u||r?B:i)).trigger("click");return y}};var e="keypress",C="."+d+"ui,."+d+"modal",x=b(document.documentElement?document.documentElement:document.body).append(v).append(z).bind(e,j.before);j.after=function(f,p){for(var q=0,t=f.className.split(" ");q