Last active
January 31, 2017 02:23
-
-
Save idettman/819e8239532624ab2bff864ceb8142a9 to your computer and use it in GitHub Desktop.
event sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setTimeout(function () | |
| { | |
| let element = document.createElement('div'); | |
| element.textContent = 'subtree modification test'; | |
| document.body.appendChild(element); | |
| console.log('setTimeout exit'); | |
| }, 1000); | |
| function getOldAndNewHashValues(oldUrl, newUrl) { | |
| let hashValues = { | |
| old: '', | |
| new: '' | |
| }; | |
| /** | |
| * @type {Number} | |
| */ | |
| let hashIndex = oldUrl.lastIndexOf('#'); | |
| if (hashIndex) { | |
| let oldHash = oldUrl.substring(hashIndex + 1); | |
| } | |
| } | |
| this.window.addEventListener('hashchange', event => | |
| { | |
| console.log('hashchange: %O', event); | |
| /** | |
| * @type {String} | |
| */ | |
| let oldUrl = event.oldURL; | |
| /** | |
| * @type {String} | |
| */ | |
| let newUrl = event.newURL; | |
| const hashValues = getOldAndNewHashValues(oldUrl, newUrl); | |
| console.log('hash values: %O', hashValues); | |
| let hashValue = window.location.hash.length > 3 ? '#' + window.location.hash.substring(1) : 'grey'; | |
| console.log('backgroundColor value: ', hashValue); | |
| document.body.style.backgroundColor = hashValue; | |
| }); | |
| document.addEventListener('DOMSubtreeModified', event => { | |
| console.log('domsubtree modified: %O', event); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment