-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe3842c
commit 6ca1568
Showing
5 changed files
with
317 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ax5ui-dialog", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"authors": [ | ||
"ThomasJ <[email protected]>" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/** | ||
* @class ax5.ui.dialog | ||
* @classdesc | ||
* @version 0.6.4 | ||
* @version 0.6.5 | ||
* @author [email protected] | ||
* @example | ||
* ``` | ||
|
@@ -60,6 +60,150 @@ | |
} | ||
}; | ||
return ax5.mustache.render(getContentTmpl(), data); | ||
}, | ||
open = function open(opts, callBack) { | ||
var pos = {}, | ||
box; | ||
|
||
opts.id = opts.id || cfg.id; | ||
|
||
box = { | ||
width: opts.width | ||
}; | ||
jQuery(document.body).append(getContent.call(this, opts.id, opts)); | ||
|
||
this.activeDialog = jQuery('#' + opts.id); | ||
this.activeDialog.css({ width: box.width }); | ||
|
||
// dialog 높이 구하기 - 너비가 정해지면 높이가 변경 될 것. | ||
opts.height = box.height = this.activeDialog.height(); | ||
|
||
//- position 정렬 | ||
if (typeof opts.position === "undefined" || opts.position === "center") { | ||
pos.top = jQuery(window).height() / 2 - box.height / 2; | ||
pos.left = jQuery(window).width() / 2 - box.width / 2; | ||
} else { | ||
pos.left = opts.position.left || 0; | ||
pos.top = opts.position.top || 0; | ||
} | ||
this.activeDialog.css(pos); | ||
|
||
// bind button event | ||
if (opts.dialogType === "prompt") { | ||
this.activeDialog.find("[data-dialog-prompt]").get(0).focus(); | ||
} else { | ||
this.activeDialog.find("[data-dialog-btn]").get(0).focus(); | ||
} | ||
|
||
this.activeDialog.find("[data-dialog-btn]").on(cfg.clickEventName, function (e) { | ||
btnOnClick.call(this, e || window.event, opts, callBack); | ||
}.bind(this)); | ||
|
||
// bind key event | ||
jQuery(window).bind("keydown.ax5dialog", function (e) { | ||
onKeyup.call(this, e || window.event, opts, callBack); | ||
}.bind(this)); | ||
|
||
jQuery(window).bind("resize.ax5dialog", function (e) { | ||
align.call(this, e || window.event); | ||
}.bind(this)); | ||
|
||
onStateChanged.call(this, opts, { | ||
self: this, | ||
state: "open" | ||
}); | ||
}, | ||
align = function align(e) { | ||
if (!this.activeDialog) return this; | ||
var opts = self.dialogConfig, | ||
box = { | ||
width: opts.width, | ||
height: opts.height | ||
}; | ||
//- position 정렬 | ||
if (typeof opts.position === "undefined" || opts.position === "center") { | ||
box.top = window.innerHeight / 2 - box.height / 2; | ||
box.left = window.innerWidth / 2 - box.width / 2; | ||
} else { | ||
box.left = opts.position.left || 0; | ||
box.top = opts.position.top || 0; | ||
} | ||
this.activeDialog.css(box); | ||
return this; | ||
}, | ||
btnOnClick = function btnOnClick(e, opts, callBack, target, k) { | ||
if (e.srcElement) e.target = e.srcElement; | ||
|
||
target = U.findParentNode(e.target, function (target) { | ||
if (target.getAttribute("data-dialog-btn")) { | ||
return true; | ||
} | ||
}); | ||
|
||
if (target) { | ||
k = target.getAttribute("data-dialog-btn"); | ||
|
||
var that = { | ||
self: this, | ||
key: k, value: opts.btns[k], | ||
dialogId: opts.id, | ||
btnTarget: target | ||
}; | ||
if (opts.dialogType === "prompt") { | ||
var emptyKey = null; | ||
for (var oi in opts.input) { | ||
that[oi] = this.activeDialog.find('[data-dialog-prompt=' + oi + ']').val(); | ||
if (that[oi] == "" || that[oi] == null) { | ||
emptyKey = oi; | ||
break; | ||
} | ||
} | ||
} | ||
if (opts.btns[k].onClick) { | ||
opts.btns[k].onClick.call(that, k); | ||
} else if (opts.dialogType === "alert") { | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} else if (opts.dialogType === "confirm") { | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} else if (opts.dialogType === "prompt") { | ||
if (k === 'ok') { | ||
if (emptyKey) { | ||
this.activeDialog.find('[data-dialog-prompt="' + emptyKey + '"]').get(0).focus(); | ||
return false; | ||
} | ||
} | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} | ||
} | ||
}, | ||
onKeyup = function onKeyup(e, opts, callBack, target, k) { | ||
if (e.keyCode == ax5.info.eventKeys.ESC) { | ||
this.close(); | ||
} | ||
if (opts.dialogType === "prompt") { | ||
if (e.keyCode == ax5.info.eventKeys.RETURN) { | ||
var that = { | ||
self: this, | ||
key: k, value: opts.btns[k], | ||
dialogId: opts.id, | ||
btnTarget: target | ||
}; | ||
var emptyKey = null; | ||
for (var oi in opts.input) { | ||
that[oi] = this.activeDialog.find('[data-dialog-prompt=' + oi + ']').val(); | ||
if (that[oi] == "" || that[oi] == null) { | ||
emptyKey = oi; | ||
break; | ||
} | ||
} | ||
if (emptyKey) return false; | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
|
@@ -106,8 +250,7 @@ | |
} | ||
|
||
self.dialogConfig = {}; | ||
jQuery.extend(true, self.dialogConfig, cfg); | ||
jQuery.extend(true, self.dialogConfig, opts); | ||
jQuery.extend(true, self.dialogConfig, cfg, opts); | ||
opts = self.dialogConfig; | ||
|
||
opts.dialogType = "alert"; | ||
|
@@ -116,7 +259,7 @@ | |
ok: { label: cfg.lang["ok"], theme: opts.theme } | ||
}; | ||
} | ||
this.open(opts, callBack); | ||
open.call(this, opts, callBack); | ||
return this; | ||
}; | ||
|
||
|
@@ -148,8 +291,7 @@ | |
} | ||
|
||
self.dialogConfig = {}; | ||
jQuery.extend(true, self.dialogConfig, cfg); | ||
jQuery.extend(true, self.dialogConfig, opts); | ||
jQuery.extend(true, self.dialogConfig, cfg, opts); | ||
opts = self.dialogConfig; | ||
|
||
opts.dialogType = "confirm"; | ||
|
@@ -160,7 +302,7 @@ | |
cancel: { label: cfg.lang["cancel"] } | ||
}; | ||
} | ||
this.open(opts, callBack); | ||
open.call(this, opts, callBack); | ||
return this; | ||
}; | ||
|
||
|
@@ -192,8 +334,7 @@ | |
} | ||
|
||
self.dialogConfig = {}; | ||
jQuery.extend(true, self.dialogConfig, cfg); | ||
jQuery.extend(true, self.dialogConfig, opts); | ||
jQuery.extend(true, self.dialogConfig, cfg, opts); | ||
opts = self.dialogConfig; | ||
|
||
opts.dialogType = "prompt"; | ||
|
@@ -210,168 +351,10 @@ | |
cancel: { label: cfg.lang["cancel"] } | ||
}; | ||
} | ||
this.open(opts, callBack); | ||
open.call(this, opts, callBack); | ||
return this; | ||
}; | ||
|
||
this.open = function (opts, callBack) { | ||
var pos = {}, | ||
that, | ||
box; | ||
|
||
opts.id = opts.id || cfg.id; | ||
|
||
box = { | ||
width: opts.width | ||
}; | ||
jQuery(document.body).append(getContent.call(this, opts.id, opts)); | ||
|
||
this.activeDialog = jQuery('#' + opts.id); | ||
this.activeDialog.css({ width: box.width }); | ||
|
||
// dialog 높이 구하기 - 너비가 정해지면 높이가 변경 될 것. | ||
opts.height = box.height = this.activeDialog.height(); | ||
|
||
//- position 정렬 | ||
if (typeof opts.position === "undefined" || opts.position === "center") { | ||
var w = window.innerWidth; | ||
var h = window.innerHeight; | ||
|
||
pos.top = h / 2 - box.height / 2; | ||
pos.left = w / 2 - box.width / 2; | ||
} else { | ||
pos.left = opts.position.left || 0; | ||
pos.top = opts.position.top || 0; | ||
} | ||
this.activeDialog.css(pos); | ||
|
||
// bind button event | ||
if (opts.dialogType === "prompt") { | ||
this.activeDialog.find("[data-dialog-prompt]").get(0).focus(); | ||
} else { | ||
this.activeDialog.find("[data-dialog-btn]").get(0).focus(); | ||
} | ||
|
||
this.activeDialog.find("[data-dialog-btn]").on(cfg.clickEventName, function (e) { | ||
this.btnOnClick(e || window.event, opts, callBack); | ||
}.bind(this)); | ||
|
||
// bind key event | ||
jQuery(window).bind("keydown.ax5dialog", function (e) { | ||
this.onKeyup(e || window.event, opts, callBack); | ||
}.bind(this)); | ||
|
||
jQuery(window).bind("resize.ax5dialog", function (e) { | ||
this.align(e || window.event); | ||
}.bind(this)); | ||
|
||
that = { | ||
self: this, | ||
state: "open" | ||
}; | ||
if (opts && opts.onStateChanged) { | ||
opts.onStateChanged.call(that, that); | ||
} else if (this.onStateChanged) { | ||
this.onStateChanged.call(that, that); | ||
} | ||
return this; | ||
}; | ||
|
||
this.align = function (e) { | ||
if (!this.activeDialog) return this; | ||
var opts = self.dialogConfig, | ||
box = { | ||
width: opts.width, | ||
height: opts.height | ||
}; | ||
//- position 정렬 | ||
if (typeof opts.position === "undefined" || opts.position === "center") { | ||
box.top = window.innerHeight / 2 - box.height / 2; | ||
box.left = window.innerWidth / 2 - box.width / 2; | ||
} else { | ||
box.left = opts.position.left || 0; | ||
box.top = opts.position.top || 0; | ||
} | ||
this.activeDialog.css(box); | ||
return this; | ||
}; | ||
|
||
this.btnOnClick = function (e, opts, callBack, target, k) { | ||
if (e.srcElement) e.target = e.srcElement; | ||
|
||
target = U.findParentNode(e.target, function (target) { | ||
if (target.getAttribute("data-dialog-btn")) { | ||
return true; | ||
} | ||
}); | ||
|
||
if (target) { | ||
k = target.getAttribute("data-dialog-btn"); | ||
|
||
var that = { | ||
self: this, | ||
key: k, value: opts.btns[k], | ||
dialogId: opts.id, | ||
btnTarget: target | ||
}; | ||
if (opts.dialogType === "prompt") { | ||
var emptyKey = null; | ||
for (var oi in opts.input) { | ||
that[oi] = this.activeDialog.find('[data-dialog-prompt=' + oi + ']').val(); | ||
if (that[oi] == "" || that[oi] == null) { | ||
emptyKey = oi; | ||
break; | ||
} | ||
} | ||
} | ||
if (opts.btns[k].onClick) { | ||
opts.btns[k].onClick.call(that, k); | ||
} else if (opts.dialogType === "alert") { | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} else if (opts.dialogType === "confirm") { | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} else if (opts.dialogType === "prompt") { | ||
if (k === 'ok') { | ||
if (emptyKey) { | ||
this.activeDialog.find('[data-dialog-prompt="' + emptyKey + '"]').get(0).focus(); | ||
return false; | ||
} | ||
} | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} | ||
} | ||
}; | ||
|
||
this.onKeyup = function (e, opts, callBack, target, k) { | ||
if (e.keyCode == ax5.info.eventKeys.ESC) { | ||
this.close(); | ||
} | ||
if (opts.dialogType === "prompt") { | ||
if (e.keyCode == ax5.info.eventKeys.RETURN) { | ||
var that = { | ||
self: this, | ||
key: k, value: opts.btns[k], | ||
dialogId: opts.id, | ||
btnTarget: target | ||
}; | ||
var emptyKey = null; | ||
for (var oi in opts.input) { | ||
that[oi] = this.activeDialog.find('[data-dialog-prompt=' + oi + ']').val(); | ||
if (that[oi] == "" || that[oi] == null) { | ||
emptyKey = oi; | ||
break; | ||
} | ||
} | ||
if (emptyKey) return false; | ||
if (callBack) callBack.call(that, k); | ||
this.close(); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* close the dialog | ||
* @method ax5.ui.dialog.close | ||
|
Oops, something went wrong.