From 854a9d6d1c1ff0446c2a084e138a730e206ef4d1 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 4 Jun 2013 16:19:47 +0100 Subject: [PATCH] Toggle a style on the page container when a modal is displayed --- core/modules/startup.js | 7 ++++--- core/modules/utils/dom/modal.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/core/modules/startup.js b/core/modules/startup.js index 43560511e..455aeead3 100644 --- a/core/modules/startup.js +++ b/core/modules/startup.js @@ -116,9 +116,10 @@ exports.startup = function() { parser = $tw.wiki.parseTiddler(templateTitle), renderTree = new $tw.WikiRenderTree(parser,{wiki: $tw.wiki, context: {tiddlerTitle: templateTitle}, document: document}); renderTree.execute(); - var container = document.createElement("div"); - document.body.insertBefore(container,document.body.firstChild); - renderTree.renderInDom(container); + $tw.pageContainer = document.createElement("div"); + $tw.utils.addClass($tw.pageContainer,"tw-page-container"); + document.body.insertBefore($tw.pageContainer,document.body.firstChild); + renderTree.renderInDom($tw.pageContainer); $tw.wiki.addEventListener("change",function(changes) { renderTree.refreshInDom(changes); }); diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js index ddc2ecee8..e157007f0 100644 --- a/core/modules/utils/dom/modal.js +++ b/core/modules/utils/dom/modal.js @@ -14,6 +14,7 @@ Modal message mechanism var Modal = function(wiki) { this.wiki = wiki; + this.modalCount = 0; }; /* @@ -25,6 +26,10 @@ Options include: */ Modal.prototype.display = function(title,options) { options = options || {}; + var self = this; + // Up the modal count and adjust the body class + this.modalCount++; + this.adjustPageClass(); // Create the wrapper divs var wrapper = document.createElement("div"), modalBackdrop = document.createElement("div"), @@ -43,6 +48,7 @@ Modal.prototype.display = function(title,options) { return; } // Add classes + $tw.utils.addClass(wrapper,"modal-wrapper"); $tw.utils.addClass(modalBackdrop,"modal-backdrop"); $tw.utils.addClass(modalWrapper,"modal"); $tw.utils.addClass(modalHeader,"modal-header"); @@ -110,6 +116,9 @@ Modal.prototype.display = function(title,options) { }); // Add the close event handler wrapper.addEventListener("tw-close-tiddler",function(event) { + // Decrease the modal count and adjust the body class + self.modalCount--; + self.adjustPageClass(); // Force layout and animate the modal message away $tw.utils.forceLayout(modalBackdrop); $tw.utils.forceLayout(modalWrapper); @@ -159,6 +168,12 @@ Modal.prototype.display = function(title,options) { ]); }; +Modal.prototype.adjustPageClass = function() { + if($tw.pageContainer) { + $tw.utils.toggleClass($tw.pageContainer,"tw-modal-displayed",this.modalCount > 0); + } +}; + exports.Modal = Modal; })();