2014-01-16 23:28:58 +01:00
|
|
|
function Popup(element, mask) {
|
2014-01-17 17:59:26 +01:00
|
|
|
var autoCloseEnabled = true;
|
|
|
|
var enterEnabled = true;
|
2014-01-16 21:30:57 +01:00
|
|
|
var self = this;
|
|
|
|
|
2014-01-16 23:28:58 +01:00
|
|
|
this.open = function(complete, disableMaskClick) {
|
2014-01-16 21:30:57 +01:00
|
|
|
mask.fadeIn(POPUP_SHOW_DURATION);
|
|
|
|
element.fadeIn(POPUP_SHOW_DURATION, complete);
|
2014-01-16 23:28:58 +01:00
|
|
|
|
|
|
|
keyboardShortcutsEnabled = false;
|
|
|
|
keyboardEscapeEnterEnabled = true;
|
|
|
|
|
|
|
|
document.body.removeEventListener('touchmove', prevent, false);
|
2014-01-17 15:10:39 +01:00
|
|
|
mask.bind("onButtonClick", self.cancel);
|
|
|
|
$(document).bind("onEscapeKey", self.cancel);
|
2014-01-17 17:59:26 +01:00
|
|
|
if (enterEnabled) $(document).bind("onEnterKey", self.commit);
|
2014-01-16 21:30:57 +01:00
|
|
|
}
|
2014-01-16 23:28:58 +01:00
|
|
|
|
2014-01-16 21:30:57 +01:00
|
|
|
this.close = function(complete) {
|
|
|
|
mask.fadeOut(POPUP_SHOW_DURATION);
|
2014-01-16 23:28:58 +01:00
|
|
|
element.fadeOut(POPUP_SHOW_DURATION, complete);
|
|
|
|
|
|
|
|
keyboardShortcutsEnabled = true;
|
|
|
|
keyboardEscapeEnterEnabled = false;
|
2014-01-16 21:30:57 +01:00
|
|
|
|
2014-01-16 23:28:58 +01:00
|
|
|
document.body.addEventListener('touchmove', prevent, false);
|
2014-01-17 15:10:39 +01:00
|
|
|
mask.unbind("onButtonClick", self.cancel);
|
|
|
|
$(document).unbind("onEscapeKey", self.cancel);
|
2014-01-17 17:59:26 +01:00
|
|
|
if (enterEnabled) $(document).unbind("onEnterKey", self.commit);
|
2014-01-16 21:30:57 +01:00
|
|
|
}
|
2014-01-16 23:28:58 +01:00
|
|
|
|
2014-01-17 17:59:26 +01:00
|
|
|
this.setEnterEnabled = function(enabled) { enterEnabled = enabled; }
|
|
|
|
|
|
|
|
this.setAutoCloseEnabled = function(enabled) { autoCloseEnabled = enabled; }
|
|
|
|
|
2014-01-17 15:10:39 +01:00
|
|
|
this.cancel = function() {
|
|
|
|
$(element).trigger('onPopupCancel');
|
2014-01-17 17:59:26 +01:00
|
|
|
if (autoCloseEnabled) self.close();
|
2014-01-17 15:10:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.commit = function() {
|
|
|
|
$(element).trigger('onPopupCommit');
|
2014-01-17 17:59:26 +01:00
|
|
|
if (autoCloseEnabled) self.close();
|
2014-01-17 15:10:39 +01:00
|
|
|
}
|
2014-01-09 17:05:03 +01:00
|
|
|
}
|