diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-16 00:53:10 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-16 00:53:10 -0700 |
commit | b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff (patch) | |
tree | 95a8519b719a37dfb791bb6771c940a11e9f7e9e /app/src/main/assets/js/menu.js | |
parent | f84a05f8aeb73ce63f77b7cc779845c31427b2b2 (diff) | |
download | frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.gz frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.bz2 frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.zip |
Add listener logic
Diffstat (limited to 'app/src/main/assets/js/menu.js')
-rw-r--r-- | app/src/main/assets/js/menu.js | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/app/src/main/assets/js/menu.js b/app/src/main/assets/js/menu.js index 2c517ed2..4a39a93b 100644 --- a/app/src/main/assets/js/menu.js +++ b/app/src/main/assets/js/menu.js @@ -1,35 +1,38 @@ -var viewport = document.getElementById('viewport'); -var root = document.getElementById('root'); -var y = new MutationObserver(function(mutations) { - viewport.removeAttribute('style'); - root.removeAttribute('style'); -}); -y.observe(viewport, { - attributes: true -}); -y.observe(root, { - attributes: true -}); -var x = new MutationObserver(function(mutations) { - var menuChildren = document.getElementsByClassName('mSideMenu'); - if (menuChildren.length > 0) { - x.disconnect(); - console.log('Found side menu'); - var menu = menuChildren[0]; - while (root.firstChild) - root.removeChild(root.firstChild); - while (menu.childNodes.length) - root.appendChild(menu.childNodes[0]); - Frost.emit(0); - setTimeout(function() { - y.disconnect(); - console.log('Unhook styler'); - Frost.handleHtml(document.documentElement.outerHTML); - }, 500); - } -}); -x.observe(document.getElementById('mJewelNav'), { - childList: true, - subtree: true -}); -document.getElementById('bookmarks_jewel').getElementsByTagName('a')[0].click(); +if (document.querySelector('#mJewelNav') !== null) { + console.log('Fetching menu'); + var viewport = document.querySelector('#viewport'); + var root = document.querySelector('#root'); + var y = new MutationObserver(function(mutations) { + viewport.removeAttribute('style'); + root.removeAttribute('style'); + }); + y.observe(viewport, { + attributes: true + }); + y.observe(root, { + attributes: true + }); + var x = new MutationObserver(function(mutations) { + var menu = document.querySelector('.mSideMenu'); + if (menu !== null) { + x.disconnect(); + console.log('Found side menu'); + while (root.firstChild) + root.removeChild(root.firstChild); + while (menu.childNodes.length) + root.appendChild(menu.childNodes[0]); + Frost.emit(0); + setTimeout(function() { + y.disconnect(); + console.log('Unhook styler'); + Frost.handleHtml(document.documentElement.outerHTML); + }, 500); + } + }); + x.observe(document.querySelector('#mJewelNav'), { + childList: true, + subtree: true + }); + document.querySelector('#bookmarks_jewel').querySelector('a').click(); +} +//otherwise we've already found the side nav and this is unnecessary |