Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit bd905ef

Browse files
committed
Merge branch 'unify-modals' into some-tweaks
2 parents 4636bfb + f6a417a commit bd905ef

File tree

3 files changed

+75
-14
lines changed

3 files changed

+75
-14
lines changed

js/start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,13 @@ launchOnboarding = function(guidCreating) {
541541
onboardingModal = new OnboardingModal({
542542
model: user,
543543
userProfile: userProfile,
544-
guidCreationPromise: guidCreating
544+
guidCreationPromise: guidCreating,
545+
dismissOnOverlayClick: false,
546+
dismissOnEscPress: false,
547+
showCloseButton: false
545548
});
546549
onboardingModal.render().open();
550+
startUpLoadingModal.close();
547551

548552
onboardingModal.on('onboarding-complete', function(guid) {
549553
app.serverConnectModal.succeedConnection(app.serverConfigs.getActive());

js/views/baseModal.js

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
var __ = require('underscore'),
44
domUtils = require('../utils/dom'),
55
loadTemplate = require('../utils/loadTemplate'),
6-
baseVw = require('./baseVw');
6+
baseVw = require('./baseVw'),
7+
baseModal;
78

8-
module.exports = baseVw.extend({
9+
baseModal = baseVw.extend({
910
constructor: function (options) {
1011
var events = {},
1112
args = Array.prototype.slice.call(arguments),
@@ -36,18 +37,27 @@ module.exports = baseVw.extend({
3637
events['click .js-modal-close'] = '__closeClick';
3738
this.events = __.extend({}, events, this.events || {});
3839

39-
if (typeof this.constructor.__modalsOpen === 'undefined') {
40-
this.constructor.__modalsOpen = 0;
41-
}
40+
if (typeof baseModal.__openModals === 'undefined') {
41+
baseModal.__openModals = [];
42+
}
43+
44+
this.$html = baseModal.$html = baseModal.$html || $('html');
45+
this.$container = baseModal.$container = baseModal.$container || $('#contentFrame');
4246

43-
this.$html = this.constructor.$html = this.constructor.$html || $('html');
44-
this.$container = this.constructor.$container = this.constructor.$container || $('#contentFrame');
47+
if (!baseModal.__docKeyPressHandlerBound) {
48+
$(document).on('keyup', baseModal.__onDocKeypress);
49+
baseModal.__docKeyPressHandlerBound = true;
50+
}
4551

4652
baseVw.prototype.constructor.apply(this, args);
4753
},
4854

4955
__onDocKeypress: function(e) {
50-
if (this.__options.dismissOnEscPress && e.keyCode === 27) {
56+
var openModals = baseModal.__openModals,
57+
topModal = this.__getTopModal();
58+
59+
if (this.__options.dismissOnEscPress && e.keyCode === 27 &&
60+
topModal && topModal === this) {
5161
this.close();
5262
}
5363
},
@@ -62,6 +72,27 @@ module.exports = baseVw.extend({
6272
this.close();
6373
},
6474

75+
__getTopModal: function() {
76+
var openModals = baseModal.__openModals.slice();
77+
78+
openModals = openModals.map((modal, i) => {
79+
return { modal: modal, index: i };
80+
});
81+
82+
openModals = openModals.sort((a, b) => {
83+
var aZindex = parseInt(window.getComputedStyle(a.modal.el).zIndex) || 0,
84+
bZindex = parseInt(window.getComputedStyle(b.modal.el).zIndex) || 0;
85+
86+
if (aZindex === bZindex) {
87+
return (a.index < b.index) ? -1 : (a.index > b.index) ? 1 : 0;
88+
} else {
89+
return (aZindex < bZindex) ? -1 : (aZindex > bZindex) ? 1 : 0;
90+
}
91+
});
92+
93+
return openModals[openModals.length - 1] && openModals[openModals.length - 1].modal;
94+
},
95+
6596
isOpen: function() {
6697
return this._open;
6798
},
@@ -70,8 +101,8 @@ module.exports = baseVw.extend({
70101
if (!domUtils.isInPage(this.el)) {
71102
this.$html.addClass('modalOpen');
72103
this.$container.append(this.el);
73-
this.constructor.__modalsOpen += 1;
74-
$(document).on('keyup', this.__onDocKeypress);
104+
baseModal.__openModals.push(this);
105+
baseModal.__topModal = this.__getTopModal();
75106
this._open = true;
76107
this.trigger('open');
77108
window.obEventBus.trigger('modal-open', { modal: this });
@@ -81,10 +112,13 @@ module.exports = baseVw.extend({
81112
},
82113

83114
close: function() {
115+
var modalIndex;
116+
84117
if (domUtils.isInPage(this.el)) {
85-
this.constructor.__modalsOpen -= 1;
86-
!this.constructor.__modalsOpen && this.$html.removeClass('modalOpen');
87-
$(document).off('keyup', this.__onDocKeypress);
118+
modalIndex = baseModal.__openModals.indexOf(this);
119+
modalIndex >= 0 && baseModal.__openModals.splice(modalIndex, 1);
120+
!baseModal.__openModals.length && this.$html.removeClass('modalOpen');
121+
baseModal.__topModal = this.__getTopModal();
88122
this.$container[0].removeChild(this.el);
89123
this._open = false;
90124
this.trigger('close');
@@ -131,3 +165,14 @@ module.exports = baseVw.extend({
131165
return this;
132166
}
133167
});
168+
169+
baseModal.__onDocKeypress = function(e) {
170+
var topModal;
171+
172+
if (e.keyCode === 27 && (topModal = baseModal.__topModal) &&
173+
topModal.__options.dismissOnEscPress) {
174+
topModal.close();
175+
}
176+
};
177+
178+
module.exports = baseModal;

js/views/loadingModal.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ module.exports = baseModal.extend({
1111
'click .js-indexReload': 'onClickIndexReload'
1212
},
1313

14+
constructor: function(options) {
15+
var events = {};
16+
17+
options = __.extend({
18+
dismissOnOverlayClick: false,
19+
dismissOnEscPress: false,
20+
showCloseButton: false
21+
}, options || {});
22+
23+
baseModal.prototype.constructor.apply(this, [options].concat(Array.prototype.slice.call(arguments, 1)));
24+
},
25+
1426
initialize: function(options) {
1527
this.options = __.extend({
1628
showLoadIndexButton: true

0 commit comments

Comments
 (0)