Skip to content

Commit

Permalink
ax5toast 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasJang committed Mar 20, 2016
1 parent 5601119 commit fb9c25a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ax5ui-toast",
"version": "0.2.0",
"version": "0.2.1",
"authors": [
"ThomasJ <tom@axisj.com>"
],
Expand Down
98 changes: 46 additions & 52 deletions dist/ax5toast.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

// ax5.ui.toast
(function (root, _SUPER_) {

/**
* @class ax5.ui.toast
* @classdesc
Expand All @@ -13,13 +15,12 @@
* var my_toast = new ax5.ui.toast();
* ```
*/

var U = ax5.util;

//== UI Class
var axClass = function () {
var
self = this,
var axClass = function axClass() {
var self = this,
cfg;

if (_SUPER_) _SUPER_.call(this); // 부모호출
Expand All @@ -40,7 +41,7 @@
containerPosition: "bottom-left"
};
cfg = this.config;

/**
* Preferences of toast UI
* @method ax5.ui.toast.set_config
Expand All @@ -50,19 +51,18 @@
* ```
* ```
*/
//== class body start
//== class body start
this.init = function () {
// after set_config();
self.containerId = ax5.getGuid();
var styles = [];
if(cfg.zIndex){
if (cfg.zIndex) {
styles.push("z-index:" + cfg.zIndex);
}
jQuery(document.body).append('<div class="ax5-ui-toast-container ' + cfg.containerPosition + '" data-toast-container="' +
'' + self.containerId + '" style="' + styles.join(";") + '"></div>');
jQuery(document.body).append('<div class="ax5-ui-toast-container ' + cfg.containerPosition + '" data-toast-container="' + '' + self.containerId + '" style="' + styles.join(";") + '"></div>');
this.toastContainer = jQuery('[data-toast-container="' + self.containerId + '"]');
};

this.push = function (opts, callBack) {
if (!self.containerId) {
this.init();
Expand All @@ -71,7 +71,7 @@
opts = {
title: cfg.title,
msg: opts
}
};
}
opts.toastType = "push";

Expand All @@ -83,7 +83,7 @@
this.open(opts, callBack);
return this;
};

this.confirm = function (opts, callBack) {
if (!self.containerId) {
this.init();
Expand All @@ -92,7 +92,7 @@
opts = {
title: cfg.title,
msg: opts
}
};
}
opts.toastType = "confirm";

Expand All @@ -103,19 +103,19 @@

if (typeof opts.btns === "undefined") {
opts.btns = {
ok: {label: cfg.lang["ok"], theme: opts.theme}
ok: { label: cfg.lang["ok"], theme: opts.theme }
};
}
this.open(opts, callBack);
return this;
};

this.getContent = function (toastId, opts) {
var po = [];
po.push('<div id="' + toastId + '" data-ax5-ui="toast" class="ax5-ui-toast ' + opts.theme + '">');
if (opts.icon) {
po.push('<div class="ax-toast-icon">');
po.push((opts.icon || ""));
po.push(opts.icon || "");
po.push('</div>');
}
po.push('<div class="ax-toast-body">');
Expand All @@ -130,63 +130,59 @@
});
po.push('</div>');
po.push('</div>');
}
else {
} else {
po.push('<a class="ax-toast-close" data-ax-toast-btn="ok">' + (opts.closeIcon || '') + '</a>');
}

po.push('<div style="clear:both;"></div>');
po.push('</div>');
return po.join('');
};

this.open = function (opts, callBack) {
var
toastBox;

var toastBox;

opts.id = 'ax5-toast-' + self.containerId + '-' + this.queue.length;
box = {
width: opts.width
};

if (U.left(cfg.containerPosition, '-') == 'bottom') {
this.toastContainer.append(this.getContent(opts.id, opts));
}
else {
} else {
this.toastContainer.prepend(this.getContent(opts.id, opts));
}

toastBox = jQuery('#' + opts.id);
toastBox.css({width: box.width});
toastBox.css({ width: box.width });
opts.toastBox = toastBox;
this.queue.push(opts);

if (opts && opts.onStateChanged) {
var that = {
self: this,
state: "open",
toastId: opts.id
};
opts.onStateChanged.call(that, that);
}

if (opts.toastType === "push") {
// 자동 제거 타이머 시작
setTimeout((function () {
setTimeout(function () {
this.close(opts, toastBox, callBack);
}).bind(this), cfg.displayTime);
}.bind(this), cfg.displayTime);

toastBox.find("[data-ax-toast-btn]").on(cfg.clickEventName, (function (e) {
toastBox.find("[data-ax-toast-btn]").on(cfg.clickEventName, function (e) {
this.btnOnClick(e || window.event, opts, toastBox, callBack);
}).bind(this));
}
else if (opts.toastType === "confirm") {
toastBox.find("[data-ax-toast-btn]").on(cfg.clickEventName, (function (e) {
}.bind(this));
} else if (opts.toastType === "confirm") {
toastBox.find("[data-ax-toast-btn]").on(cfg.clickEventName, function (e) {
this.btnOnClick(e || window.event, opts, toastBox, callBack);
}).bind(this));
}.bind(this));
}

};

this.btnOnClick = function (e, opts, toastBox, callBack, target, k) {

target = U.findParentNode(e.target, function (target) {
Expand All @@ -199,19 +195,17 @@
k = target.getAttribute("data-ax-toast-btn");

var that = {
key: k, value: (opts.btns) ? opts.btns[k] : k,
key: k, value: opts.btns ? opts.btns[k] : k,
toastId: opts.id,
btn_target: target
};

if (opts.btns && opts.btns[k].onClick) {
opts.btns[k].onClick.call(that, k);
}
else if (opts.toastType === "push") {
} else if (opts.toastType === "push") {
if (callBack) callBack.call(that, k);
this.close(opts, toastBox);
}
else if (opts.toastType === "confirm") {
} else if (opts.toastType === "confirm") {
if (callBack) callBack.call(that, k);
this.close(opts, toastBox);
}
Expand All @@ -223,7 +217,7 @@
if (this.queue.length > 0) this.close();
}
};

/**
* close the toast
* @method ax5.ui.toast.close
Expand All @@ -239,7 +233,7 @@
toastBox = opts.toastBox;
}

toastBox.addClass((opts.toastType == "push") ? "removed" : "destroy");
toastBox.addClass(opts.toastType == "push" ? "removed" : "destroy");
this.queue = U.filter(this.queue, function () {
return opts.id != this.id;
});
Expand All @@ -253,6 +247,7 @@

if (opts && opts.onStateChanged) {
that = {
self: this,
state: "close",
toastId: opts.id
};
Expand All @@ -263,17 +258,16 @@
};

// 클래스 생성자
this.main = (function () {
if(arguments && U.isObject(arguments[0])) {
this.main = function () {
if (arguments && U.isObject(arguments[0])) {
this.setConfig(arguments[0]);
}
}).apply(this, arguments);
}.apply(this, arguments);
};
//== UI Class

root.toast = (function(){
root.toast = function () {
if (U.isFunction(_SUPER_)) axClass.prototype = new _SUPER_(); // 상속
return axClass;
})(); // ax5.ui에 연결

}(); // ax5.ui에 연결
})(ax5.ui, ax5.ui.root);
2 changes: 1 addition & 1 deletion dist/ax5toast.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ax5ui-toast",
"version": "0.2.0",
"version": "0.2.1",
"description": "A toast plugin that works with Bootstrap & jQuery",
"license": "MIT",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/ax5toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@

if (opts && opts.onStateChanged) {
var that = {
self: this,
state: "open",
toastId: opts.id
};
Expand Down Expand Up @@ -253,6 +254,7 @@

if (opts && opts.onStateChanged) {
that = {
self: this,
state: "close",
toastId: opts.id
};
Expand Down

0 comments on commit fb9c25a

Please sign in to comment.