Convert header_dropdown.js to vanilla JavaScript (no jQuery).
This commit is contained in:
parent
e705c4de61
commit
6c408fb4ea
@ -16,30 +16,73 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function(){
|
'use strict';
|
||||||
|
|
||||||
|
var panel = {};
|
||||||
|
|
||||||
|
(function() {
|
||||||
// The header drop-down header panel defaults to open until you explicitly
|
// The header drop-down header panel defaults to open until you explicitly
|
||||||
// close it. After that, the panel open/closed setting will persist across
|
// close it. After that, the panel open/closed setting will persist across
|
||||||
// page loads.
|
// page loads.
|
||||||
|
var panel_elem = document.getElementById('header_dropdown');
|
||||||
|
var up_arrow_elem = document.querySelector('.header_dropdown_up');
|
||||||
|
var down_arrow_elem = document.querySelector('.header_dropdown_down');
|
||||||
|
|
||||||
// Initialise the panel status when page is loaded.
|
function hide(elem) {
|
||||||
if (localStorage.getItem("panel_closed")) {
|
elem.style.display = 'none';
|
||||||
$("#header_dropdown").hide();
|
|
||||||
$(".header_dropdown_up").hide();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(".header_dropdown_down").hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle and persist the panel status.
|
function show(elem) {
|
||||||
$(".header_dropdown_down, .header_dropdown_up").click(function() {
|
elem.style.display = '';
|
||||||
if (localStorage.getItem("panel_closed")) {
|
}
|
||||||
localStorage.removeItem("panel_closed");
|
|
||||||
|
function isDisplayed(elem) {
|
||||||
|
return elem.style.display === '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle(elem) {
|
||||||
|
if (isDisplayed(elem)) {
|
||||||
|
hide(elem);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
localStorage.setItem("panel_closed", "true");
|
show(elem);
|
||||||
}
|
}
|
||||||
$(".header_dropdown_down").toggle();
|
}
|
||||||
$(".header_dropdown_up").toggle();
|
|
||||||
$("#header_dropdown").slideToggle();
|
function showPanel() {
|
||||||
});
|
localStorage.removeItem('panel_closed');
|
||||||
});
|
show(panel_elem);
|
||||||
|
show(up_arrow_elem);
|
||||||
|
hide(down_arrow_elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hidePanel() {
|
||||||
|
localStorage.setItem('panel_closed', 'true');
|
||||||
|
hide(panel_elem);
|
||||||
|
hide(up_arrow_elem);
|
||||||
|
show(down_arrow_elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function togglePanel() {
|
||||||
|
// Toggle and persist the panel status.
|
||||||
|
if (isDisplayed(panel_elem)) {
|
||||||
|
hidePanel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showPanel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise the panel status when page is loaded.
|
||||||
|
up_arrow_elem.addEventListener('click', togglePanel);
|
||||||
|
down_arrow_elem.addEventListener('click', togglePanel);
|
||||||
|
if (localStorage.getItem('panel_closed')) {
|
||||||
|
hidePanel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export some functionality for use in other modules.
|
||||||
|
panel.show = showPanel;
|
||||||
|
})();
|
||||||
|
@ -42,8 +42,6 @@
|
|||||||
href="{{ request.staticdirect('/images/goblin.ico') }}" />
|
href="{{ request.staticdirect('/images/goblin.ico') }}" />
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
src="{{ request.staticdirect('/js/extlib/jquery.js') }}"></script>
|
src="{{ request.staticdirect('/js/extlib/jquery.js') }}"></script>
|
||||||
<script type="text/javascript"
|
|
||||||
src="{{ request.staticdirect('/js/header_dropdown.js') }}"></script>
|
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
src="{{ request.staticdirect('/js/notifications.js') }}"></script>
|
src="{{ request.staticdirect('/js/notifications.js') }}"></script>
|
||||||
<script>
|
<script>
|
||||||
@ -185,6 +183,8 @@
|
|||||||
{%- include "mediagoblin/bits/base_footer.html" %}
|
{%- include "mediagoblin/bits/base_footer.html" %}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock mediagoblin_body %}
|
{%- endblock mediagoblin_body %}
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="{{ request.staticdirect('/js/header_dropdown.js') }}"></script>
|
||||||
{% include 'mediagoblin/bits/body_end.html' %}
|
{% include 'mediagoblin/bits/body_end.html' %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user