Skip to content

Commit 037d8b8

Browse files
committed
Add option to flash new waiting notices in modalish stacks.
1 parent 7111aef commit 037d8b8

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

src/PNotifyCoreComponent.html

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,28 +845,47 @@
845845
return _moveClass = value;
846846
}
847847

848-
export function _setMasking (value, immediate) {
848+
export async function _setMasking (value, immediate, callback) {
849849
if (_maskingTimer) {
850850
clearTimeout(_maskingTimer);
851851
}
852+
if (_masking === value) {
853+
return;
854+
}
852855
if (value) {
853-
insertIntoDOM();
854856
_masking = value;
855-
if (immediate) {
856-
_maskingIn = true;
857-
} else {
858-
window.requestAnimationFrame(() => {
859-
if (_masking) {
857+
_maskingIn = !!immediate;
858+
insertIntoDOM();
859+
await tick();
860+
window.requestAnimationFrame(() => {
861+
if (_masking) {
862+
if (immediate && callback) {
863+
callback();
864+
} else {
860865
_maskingIn = true;
866+
const finished = () => {
867+
refs.elem && refs.elem.removeEventListener('transitionend', finished);
868+
if (_maskingTimer) {
869+
clearTimeout(_maskingTimer);
870+
}
871+
if (_maskingIn && callback) {
872+
callback();
873+
}
874+
};
875+
refs.elem && refs.elem.addEventListener('transitionend', finished);
876+
_maskingTimer = setTimeout(finished, 650);
861877
}
862-
});
863-
}
878+
}
879+
});
864880
} else if (immediate) {
865881
_masking = false;
866882
_maskingIn = false;
867883
if (remove && ['open', 'opening', 'closing'].indexOf(_state) === -1) {
868884
removeFromDOM();
869885
}
886+
if (callback) {
887+
callback();
888+
}
870889
} else {
871890
const finished = () => {
872891
refs.elem && refs.elem.removeEventListener('transitionend', finished);
@@ -878,6 +897,9 @@
878897
if (remove && ['open', 'opening', 'closing'].indexOf(_state) === -1) {
879898
removeFromDOM();
880899
}
900+
if (callback) {
901+
callback();
902+
}
881903
}
882904
};
883905

src/Stack.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Stack {
1313
maxStrategy: 'wait',
1414
maxClosureCausesWait: true,
1515
modal: 'ish',
16+
modalishFlash: true,
1617
overlayClose: true,
1718
overlayClosesPinned: false,
1819
context: (window && document.body) || null
@@ -161,7 +162,7 @@ export default class Stack {
161162
}
162163

163164
// Position the notice.
164-
_positionNotice (notice) {
165+
_positionNotice (notice, masking = notice === this._masking) {
165166
// Get the notice's stack.
166167
const elem = notice.refs.elem;
167168
if (!elem) {
@@ -172,7 +173,7 @@ export default class Stack {
172173
if (
173174
!elem.classList.contains('ui-pnotify-in') &&
174175
!elem.classList.contains('ui-pnotify-initial-hidden') &&
175-
notice !== this._masking
176+
!masking
176177
) {
177178
return;
178179
}
@@ -190,7 +191,7 @@ export default class Stack {
190191
// Read from the DOM to cause refresh.
191192
elem.getBoundingClientRect();
192193

193-
if (this._animation && notice !== this._masking && !this._collapsingModalState) {
194+
if (this._animation && !masking && !this._collapsingModalState) {
194195
// Add animate class.
195196
notice._setMoveClass('ui-pnotify-move');
196197
} else {
@@ -265,7 +266,7 @@ export default class Stack {
265266

266267
// Don't move masking notices along dir2. They should always be beside the
267268
// leader along dir1.
268-
if (notice !== this._masking) {
269+
if (!masking) {
269270
// Check that it's not beyond the viewport edge.
270271
const endY = _nextpos1 + elem.offsetHeight + this.spacing1;
271272
const endX = _nextpos1 + elem.offsetWidth + this.spacing1;
@@ -361,7 +362,7 @@ export default class Stack {
361362
}
362363

363364
// If we're not positioning the masking notice, update the stack properties.
364-
if (notice !== this._masking) {
365+
if (!masking) {
365366
this.firstpos1 = firstpos1;
366367
this.firstpos2 = firstpos2;
367368
this._nextpos1 = _nextpos1;
@@ -402,9 +403,22 @@ export default class Stack {
402403
this.context.addEventListener('pnotify:position', this._listener);
403404
}
404405

405-
// If the notice is already open, handle it immediately.
406406
if (['open', 'opening', 'closing'].indexOf(notice.getState()) !== -1) {
407+
// If the notice is already open, handle it immediately.
407408
this._handleNoticeOpened(notice);
409+
} else if (this.modal === 'ish' && this.modalishFlash && this._shouldNoticeWait()) {
410+
// If it's not open, and it's going to be a waiting notice, flash it.
411+
const off = notice.on('pnotify:mount', () => {
412+
off();
413+
notice._setMasking(this.dir1, false, () => {
414+
notice._setMasking(false);
415+
});
416+
this._resetPositionData();
417+
this._positionNotice(this._leader);
418+
window.requestAnimationFrame(() => {
419+
this._positionNotice(notice, true);
420+
});
421+
});
408422
}
409423
}
410424

0 commit comments

Comments
 (0)