Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# HEAD

* **js:** Use window.Mzp in Modal and Notification components (#488)

## 9.0.0

* **assets:** (breaking) Update @mozilla-protocol/assets to 3.0.0 (#479)
Expand Down
31 changes: 13 additions & 18 deletions src/assets/js/protocol/protocol-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ if (typeof Mzp === 'undefined') { // eslint-disable-line block-scoped-var
var Mzp = {};
}

Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var
(function() {
'use strict';

var Modal = {};
var open = false;
var body = w.document.body;
var html = w.document.documentElement;
var body = document.body;
var html = document.documentElement;
var options = {};
var pageContentParent;
var pageContent;
Expand All @@ -29,14 +30,14 @@ Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var
allowScroll: boolean - allow/restrict page scrolling when modal is open.
closeText: string to use for close button a11y.
*/
var _createModal = function(origin, content, opts) {
Modal.createModal = function(origin, content, opts) {
options = opts;

var isSmallViewport = window.innerWidth < 760;

// Make sure modal is closed (if one exists)
if (open) {
_closeModal();
Modal.closeModal();
}

// Create new modal
Expand Down Expand Up @@ -77,13 +78,13 @@ Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var

// close modal on clicking close button or background.
var closeButton = document.querySelector('.mzp-c-modal-button-close');
closeButton.addEventListener('click', _closeModal, false);
closeButton.addEventListener('click', Modal.closeModal, false);
closeButton.setAttribute('title', closeText);

// close modal on clicking the background (but not bubbled event).
document.querySelector('.mzp-c-modal .mzp-c-modal-window').addEventListener('click', function (e) {
if (e.target === this) {
_closeModal();
Modal.closeModal();
}
}, false);

Expand All @@ -108,7 +109,7 @@ Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var

var _onDocumentKeyUp = function(e) {
if (e.keyCode === 27 && open) {
_closeModal();
Modal.closeModal();
}
};

Expand All @@ -120,7 +121,7 @@ Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var
}
};

var _closeModal = function(e) {
Modal.closeModal = function(e) {
if (e) {
e.preventDefault();
}
Expand Down Expand Up @@ -153,12 +154,6 @@ Mzp.Modal = (function(w) { // eslint-disable-line block-scoped-var
options = {};
};

return {
createModal: function(origin, content, opts) {
_createModal(origin, content, opts);
},
closeModal: function() {
_closeModal();
}
};
})(window);
window.Mzp.Modal = Modal;

})();
12 changes: 5 additions & 7 deletions src/assets/js/protocol/protocol-notification-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ if (typeof Mzp === 'undefined') { // eslint-disable-line block-scoped-var
var Mzp = {};
}

Mzp.Notification = (function() { // eslint-disable-line block-scoped-var
(function() {
'use strict';

var Notification = {};
var options = {};

/*
Expand All @@ -24,7 +25,7 @@ Mzp.Notification = (function() { // eslint-disable-line block-scoped-var
onNotificationClose: function to fire after notification has been closed.
*/

var _init = function(origin, opts) {
Notification.init = function(origin, opts) {

if (typeof opts === 'object') {
for (var i in opts) {
Expand Down Expand Up @@ -103,9 +104,6 @@ Mzp.Notification = (function() { // eslint-disable-line block-scoped-var
origin.classList.remove('mzp-c-notification-origin');
};

return {
init: function(origin, opts) {
_init(origin, opts);
}
};
window.Mzp.Notification = Notification;

})(window);