console
const Mediator = (function() {
let _msg = {};
return {
register(type, action) {
if (_msg[type]) {
_msg[type].push(action);
} else {
_msg[type] = [action];
}
},
send(type) {
if (_msg[type]) {
for (let i = 0, len = _msg[type].length; i < len; i++) {
_msg[type][i] && _msg[type][i]();
}
}
}
}
})();
function showHideNavWidget(modId, tagName, showOrHide) {
const mod = document.getElementById(modId);
const tags = mod.getElementsByTagName(tagName);
const show = (!showOrHide || showOrHide === 'hide') ? 'hidden': 'visible';
for (let i = 0, len = tags.length; i < len; i++) {
tags[i].style.visibility = show;
}
}
(function() {
Mediator.register('hideAllNavNum', () => {
showHideNavWidget('collectionNav', 'b', false);
});
Mediator.register('showAllNavNum', () => {
showHideNavWidget('collectionNav', 'b', true);
});
Mediator.register('hideAllNavUrl', () => {
showHideNavWidget('collectionNav', 'span', false);
});
Mediator.register('showAllNavUrl', () => {
showHideNavWidget('collectionNav', 'span', true);
});
})();
(function() {
Mediator.register('hideAllNavNum', () => {
showHideNavWidget('recommendNav', 'b', false);
});
Mediator.register('showAllNavNum', () => {
showHideNavWidget('recommendNav', 'b', true);
});
})();
(function() {
Mediator.register('hideAllNavUrl', () => {
showHideNavWidget('recentlyNav', 'span', 'hide');
});
Mediator.register('showAllNavUrl', () => {
showHideNavWidget('recentlyNav', 'span', 'show');
});
})();
(function() {
const hideNum = document.getElementById('hideNum');
const hideUrl = document.getElementById('hideUrl');
hideNum.addEventListener('change', function() {
if (this.checked) {
Mediator.send('hideAllNavNum');
} else {
Mediator.send('showAllNavNum');
}
},
false);
hideUrl.addEventListener('change', function() {
if (hideUrl.checked) {
Mediator.send('hideAllNavUrl');
} else {
Mediator.send('showAllNavUrl');
}
},
false);
})();
<article class="flex-box">
<section id="collectionNav">
<header>
<hgroup>
<h1>
用户收藏导航模块
</h1>
<h2>
有消息提醒和导航网址功能
</h2>
</hgroup>
</header>
<section>
<b>
消息1
</b>
<b>
消息2
</b>
<b>
消息3
</b>
</section>
<section>
<span>
导航1
</span>
<span>
导航2
</span>
<span>
导航3
</span>
</section>
</section>
<section id="recommendNav">
<hgroup>
<h1>
推荐用户导航
</h1>
<h2>
推荐用户导航内的导航有消息提醒功能
</h2>
</hgroup>
<section>
<b>
消息4
</b>
<b>
消息5
</b>
<b>
消息6
</b>
</section>
</section>
<section id="recentlyNav">
<hgroup>
<h1>
最近常用导航
</h1>
<h2>
最近常用导航栏内有导航网址功能
</h2>
</hgroup>
<section>
<span>
导航4
</span>
<span>
导航5
</span>
<span>
导航6
</span>
</section>
</section>
</article>
<section class="center">
<p>
<input type="checkbox" id="hideNum">
隐藏消息
</p>
<p>
<input type="checkbox" id="hideUrl">
隐藏导航
</p>
</section>
.flex-box {
display: flex;
justify-content: space-around;
}
h1 {
font-size: 20px;
color: rgba(0, 0, 0, 1);
}
h2 {
font-size: 16px;
color: rgba(0, 0, 0, .4);
}
b {
font-size: 16px;
color: rgba(0, 0, 0, .9);
font-weight: 100;
}
span {
font-size: 16px;
color: rgba(0, 0, 0, .9);
}
.center {
margin: 30px auto;
text-align: center;
}