From 803dec3d329ce5d19ad4f0804f366a09829daeb9 Mon Sep 17 00:00:00 2001 From: ThomasJ Date: Tue, 26 Jan 2016 20:06:27 +0900 Subject: [PATCH] change class structure --- API.md | 16 +++++++++++++++- README.md | 3 +-- bower.json | 2 +- dist/ax5toast.js | 45 +++++++++++++++++++++++--------------------- dist/ax5toast.min.js | 2 +- package.json | 2 +- src/ax5toast.js | 45 +++++++++++++++++++++++--------------------- 7 files changed, 67 insertions(+), 48 deletions(-) diff --git a/API.md b/API.md index 6a1ab64..0696cd8 100644 --- a/API.md +++ b/API.md @@ -20,7 +20,21 @@ myToast.set_config({ lang: "Object" }); ``` - +**Easy Way - without setConfig** +```js +var myToast = new ax5.ui.toast({ + msg: "String", + theme: "String", + width: "Number", + icon: "String", + closeIcon: "String", + onStateChanged: "Function", + displayTime: "Number", + animateTime: "Number", + containerPosition: "String", + lang: "Object" +}); +``` ### msg diff --git a/README.md b/README.md index ba3c7fd..1fe0d21 100755 --- a/README.md +++ b/README.md @@ -44,8 +44,7 @@ exactly the path. ### Basic Usages ```js -var myToast = new ax5.ui.toast(); -myToast.setConfig({ +var myToast = new ax5.ui.toast({ icon: '', containerPosition: "bottom-right", closeIcon: '' diff --git a/bower.json b/bower.json index abf5a22..5303c19 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5toast", - "version": "0.1.0", + "version": "0.2.0", "authors": [ "ThomasJ " ], diff --git a/dist/ax5toast.js b/dist/ax5toast.js index 6d56849..5f8368b 100755 --- a/dist/ax5toast.js +++ b/dist/ax5toast.js @@ -21,28 +21,24 @@ var self = this, cfg; - - // 클래스 생성자 - this.main = (function () { - if (_SUPER_) _SUPER_.call(this); // 부모호출 - this.config = { - clickEventName: "click", //(('ontouchstart' in document.documentElement) ? "touchstart" : "click"), - theme: 'default', - width: 300, - icon: '', - closeIcon: '', - msg: '', - lang: { - "ok": "ok", "cancel": "cancel" - }, - displayTime: 3000, - animateTime: 250, - containerPosition: "bottom-left" - }; - }).apply(this, arguments); - + + if (_SUPER_) _SUPER_.call(this); // 부모호출 this.toastContainer = null; this.queue = []; + this.config = { + clickEventName: "click", //(('ontouchstart' in document.documentElement) ? "touchstart" : "click"), + theme: 'default', + width: 300, + icon: '', + closeIcon: '', + msg: '', + lang: { + "ok": "ok", "cancel": "cancel" + }, + displayTime: 3000, + animateTime: 250, + containerPosition: "bottom-left" + }; cfg = this.config; /** @@ -265,7 +261,14 @@ } }, cfg.animateTime); return this; - } + }; + + // 클래스 생성자 + this.main = (function () { + if(arguments && U.isObject(arguments[0])) { + this.setConfig(arguments[0]); + } + }).apply(this, arguments); }; //== UI Class diff --git a/dist/ax5toast.min.js b/dist/ax5toast.min.js index 6889e2d..65b535c 100755 --- a/dist/ax5toast.min.js +++ b/dist/ax5toast.min.js @@ -1 +1 @@ -!function(t,i){var n=ax5.util,e=function(){var t,e=this;this.main=function(){i&&i.call(this),this.config={clickEventName:"click",theme:"default",width:300,icon:"",closeIcon:"",msg:"",lang:{ok:"ok",cancel:"cancel"},displayTime:3e3,animateTime:250,containerPosition:"bottom-left"}}.apply(this,arguments),this.toastContainer=null,this.queue=[],t=this.config,this.init=function(){e.containerId=ax5.getGuid();var i=[];t.zIndex&&i.push("z-index:"+t.zIndex),jQuery(document.body).append('
'),this.toastContainer=jQuery('[data-toast-container="'+e.containerId+'"]')},this.push=function(i,o){return e.containerId||this.init(),n.isString(i)&&(i={title:t.title,msg:i}),i.toastType="push",e.dialogConfig={},jQuery.extend(!0,e.dialogConfig,t),jQuery.extend(!0,e.dialogConfig,i),i=e.dialogConfig,this.open(i,o),this},this.confirm=function(i,o){return e.containerId||this.init(),n.isString(i)&&(i={title:t.title,msg:i}),i.toastType="confirm",e.dialogConfig={},jQuery.extend(!0,e.dialogConfig,t),jQuery.extend(!0,e.dialogConfig,i),i=e.dialogConfig,"undefined"==typeof i.btns&&(i.btns={ok:{label:t.lang.ok,theme:i.theme}}),this.open(i,o),this},this.getContent=function(t,i){var e=[];return e.push('
'),i.icon&&(e.push('
'),e.push(i.icon||""),e.push("
")),e.push('
'),e.push((i.msg||"").replace(/\n/g,"
")),e.push("
"),i.btns?(e.push('
'),e.push('
'),n.each(i.btns,function(t,i){e.push('")}),e.push("
"),e.push("
")):e.push(''+(i.closeIcon||"")+""),e.push('
'),e.push("
"),e.join("")},this.open=function(i,o){var a;if(i.id="ax5-toast-"+e.containerId+"-"+this.queue.length,box={width:i.width},"bottom"==n.left(t.containerPosition,"-")?this.toastContainer.append(this.getContent(i.id,i)):this.toastContainer.prepend(this.getContent(i.id,i)),a=jQuery("#"+i.id),a.css({width:box.width}),i.toastBox=a,this.queue.push(i),i&&i.onStateChanged){var s={state:"open",toastId:i.id};i.onStateChanged.call(s,s)}"push"===i.toastType?(setTimeout(function(){this.close(i,a,o)}.bind(this),t.displayTime),a.find("[data-ax-toast-btn]").on(t.clickEventName,function(t){this.btnOnClick(t||window.event,i,a,o)}.bind(this))):"confirm"===i.toastType&&a.find("[data-ax-toast-btn]").on(t.clickEventName,function(t){this.btnOnClick(t||window.event,i,a,o)}.bind(this))},this.btnOnClick=function(t,i,e,o,a,s){if(a=n.findParentNode(t.target,function(t){return t.getAttribute("data-ax-toast-btn")?!0:void 0})){s=a.getAttribute("data-ax-toast-btn");var d={key:s,value:i.btns?i.btns[s]:s,toastId:i.id,btn_target:a};i.btns&&i.btns[s].onClick?i.btns[s].onClick.call(d,s):"push"===i.toastType?(o&&o.call(d,s),this.close(i,e)):"confirm"===i.toastType&&(o&&o.call(d,s),this.close(i,e))}},this.onKeyup=function(t,i,n,e,o){t.keyCode==ax5.info.eventKeys.ESC&&this.queue.length>0&&this.close()},this.close=function(i,e,o){return"undefined"==typeof e&&(i=n.last(this.queue),e=i.toastBox),e.addClass("push"==i.toastType?"removed":"destroy"),this.queue=n.filter(this.queue,function(){return i.id!=this.id}),setTimeout(function(){var t={toastId:i.id};e.remove(),o&&o.call(t),i&&i.onStateChanged&&(t={state:"close",toastId:i.id},i.onStateChanged.call(t,t))},t.animateTime),this}};n.isFunction(i)&&(e.prototype=new i),t.toast=e}(ax5.ui,ax5.ui.root); \ No newline at end of file +!function(t,i){var n=ax5.util,e=function(){var t,e=this;i&&i.call(this),this.toastContainer=null,this.queue=[],this.config={clickEventName:"click",theme:"default",width:300,icon:"",closeIcon:"",msg:"",lang:{ok:"ok",cancel:"cancel"},displayTime:3e3,animateTime:250,containerPosition:"bottom-left"},t=this.config,this.init=function(){e.containerId=ax5.getGuid();var i=[];t.zIndex&&i.push("z-index:"+t.zIndex),jQuery(document.body).append('
'),this.toastContainer=jQuery('[data-toast-container="'+e.containerId+'"]')},this.push=function(i,o){return e.containerId||this.init(),n.isString(i)&&(i={title:t.title,msg:i}),i.toastType="push",e.dialogConfig={},jQuery.extend(!0,e.dialogConfig,t),jQuery.extend(!0,e.dialogConfig,i),i=e.dialogConfig,this.open(i,o),this},this.confirm=function(i,o){return e.containerId||this.init(),n.isString(i)&&(i={title:t.title,msg:i}),i.toastType="confirm",e.dialogConfig={},jQuery.extend(!0,e.dialogConfig,t),jQuery.extend(!0,e.dialogConfig,i),i=e.dialogConfig,"undefined"==typeof i.btns&&(i.btns={ok:{label:t.lang.ok,theme:i.theme}}),this.open(i,o),this},this.getContent=function(t,i){var e=[];return e.push('
'),i.icon&&(e.push('
'),e.push(i.icon||""),e.push("
")),e.push('
'),e.push((i.msg||"").replace(/\n/g,"
")),e.push("
"),i.btns?(e.push('
'),e.push('
'),n.each(i.btns,function(t,i){e.push('")}),e.push("
"),e.push("
")):e.push(''+(i.closeIcon||"")+""),e.push('
'),e.push("
"),e.join("")},this.open=function(i,o){var s;if(i.id="ax5-toast-"+e.containerId+"-"+this.queue.length,box={width:i.width},"bottom"==n.left(t.containerPosition,"-")?this.toastContainer.append(this.getContent(i.id,i)):this.toastContainer.prepend(this.getContent(i.id,i)),s=jQuery("#"+i.id),s.css({width:box.width}),i.toastBox=s,this.queue.push(i),i&&i.onStateChanged){var a={state:"open",toastId:i.id};i.onStateChanged.call(a,a)}"push"===i.toastType?(setTimeout(function(){this.close(i,s,o)}.bind(this),t.displayTime),s.find("[data-ax-toast-btn]").on(t.clickEventName,function(t){this.btnOnClick(t||window.event,i,s,o)}.bind(this))):"confirm"===i.toastType&&s.find("[data-ax-toast-btn]").on(t.clickEventName,function(t){this.btnOnClick(t||window.event,i,s,o)}.bind(this))},this.btnOnClick=function(t,i,e,o,s,a){if(s=n.findParentNode(t.target,function(t){return t.getAttribute("data-ax-toast-btn")?!0:void 0})){a=s.getAttribute("data-ax-toast-btn");var d={key:a,value:i.btns?i.btns[a]:a,toastId:i.id,btn_target:s};i.btns&&i.btns[a].onClick?i.btns[a].onClick.call(d,a):"push"===i.toastType?(o&&o.call(d,a),this.close(i,e)):"confirm"===i.toastType&&(o&&o.call(d,a),this.close(i,e))}},this.onKeyup=function(t,i,n,e,o){t.keyCode==ax5.info.eventKeys.ESC&&this.queue.length>0&&this.close()},this.close=function(i,e,o){return"undefined"==typeof e&&(i=n.last(this.queue),e=i.toastBox),e.addClass("push"==i.toastType?"removed":"destroy"),this.queue=n.filter(this.queue,function(){return i.id!=this.id}),setTimeout(function(){var t={toastId:i.id};e.remove(),o&&o.call(t),i&&i.onStateChanged&&(t={state:"close",toastId:i.id},i.onStateChanged.call(t,t))},t.animateTime),this},this.main=function(){arguments&&n.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};n.isFunction(i)&&(e.prototype=new i),t.toast=e}(ax5.ui,ax5.ui.root); \ No newline at end of file diff --git a/package.json b/package.json index accd8ce..b96712a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5toast", - "version": "0.1.0", + "version": "0.2.0", "description": "A toast plugin that works with Bootstrap & jQuery", "license": "MIT", "repository": { diff --git a/src/ax5toast.js b/src/ax5toast.js index 6d56849..5f8368b 100755 --- a/src/ax5toast.js +++ b/src/ax5toast.js @@ -21,28 +21,24 @@ var self = this, cfg; - - // 클래스 생성자 - this.main = (function () { - if (_SUPER_) _SUPER_.call(this); // 부모호출 - this.config = { - clickEventName: "click", //(('ontouchstart' in document.documentElement) ? "touchstart" : "click"), - theme: 'default', - width: 300, - icon: '', - closeIcon: '', - msg: '', - lang: { - "ok": "ok", "cancel": "cancel" - }, - displayTime: 3000, - animateTime: 250, - containerPosition: "bottom-left" - }; - }).apply(this, arguments); - + + if (_SUPER_) _SUPER_.call(this); // 부모호출 this.toastContainer = null; this.queue = []; + this.config = { + clickEventName: "click", //(('ontouchstart' in document.documentElement) ? "touchstart" : "click"), + theme: 'default', + width: 300, + icon: '', + closeIcon: '', + msg: '', + lang: { + "ok": "ok", "cancel": "cancel" + }, + displayTime: 3000, + animateTime: 250, + containerPosition: "bottom-left" + }; cfg = this.config; /** @@ -265,7 +261,14 @@ } }, cfg.animateTime); return this; - } + }; + + // 클래스 생성자 + this.main = (function () { + if(arguments && U.isObject(arguments[0])) { + this.setConfig(arguments[0]); + } + }).apply(this, arguments); }; //== UI Class