Skip to content

Commit

Permalink
Merge pull request #222 from szpak/upstream/reuseMobileSwitchScript
Browse files Browse the repository at this point in the history
Reuse sidebar on narrow screens script
  • Loading branch information
zzossig authored Mar 8, 2020
2 parents 0dc9e52 + 1507f08 commit 14b1c7c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 208 deletions.
68 changes: 1 addition & 67 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,72 +28,6 @@ <h5 class="list__header--title capitalize h5">{{.Title}}</h5>
{{ end }}
</main>

<script>
{{ $sidebarPosition:= $.Param "sidebarPosition" }}
var sidebarPosition = JSON.parse({{ $sidebarPosition | jsonify }});
{{ $enableSidebar:= $.Param "enableSidebar" }}
var enableSidebar = JSON.parse({{ $enableSidebar | jsonify }});

var listMainElem = document.querySelector('.list__main');
var listSideElem = document.querySelector('.list__sidebar');

var gridSmall = 'l';
var gridBig = 'mr';
var gridFull = 'lmr'

if (sidebarPosition === "right") {
gridSmall = 'r';
gridBig = 'lm'
}
enquire.register("screen and (max-width: 769px)", {
match: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
listSideElem.classList.remove(gridSmall);
listSideElem.classList.add('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}
},
unmatch: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridFull);
listMainElem.classList.add(gridBig);
listSideElem.classList.add(gridSmall);
listSideElem.classList.remove('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

var navCollapseBtn = document.querySelector('.navbar__burger');
var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
if (navCollapse) {
navCollapse.setAttribute('data-open', false);
navCollapse.style.maxHeight = 0;
navCollapseBtn.classList.remove('is-active');
}
document.getElementsByClassName('navbar__menu')[0].classList.remove('is-active');
document.getElementsByClassName('mobile-search')[0].classList.add('hide');
},
setup: function () { },
deferSetup: true,
destroy: function () { },
});
</script>
{{ partial "script/sidebar-script" . }}
{{ partial "script/list-script" . }}
{{ end }}
69 changes: 1 addition & 68 deletions layouts/_default/taxonomy.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,73 +27,6 @@ <h5 class="list__header--title capitalize h5">{{ .Title }}</h5>
{{ end }}
</main>

<script>
{{ $sidebarPosition:= $.Param "sidebarPosition" }}
var sidebarPosition = JSON.parse({{ $sidebarPosition | jsonify }});
{{ $enableSidebar:= $.Param "enableSidebar" }}
var enableSidebar = JSON.parse({{ $enableSidebar | jsonify }});

var listMainElem = document.querySelector('.list__main');
var listSideElem = document.querySelector('.list__sidebar');

var gridSmall = 'l';
var gridBig = 'mr';
var gridFull = 'lmr'

if (sidebarPosition === "right") {
gridSmall = 'r';
gridBig = 'lm'
}

enquire.register("screen and (max-width: 769px)", {
match: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
listSideElem.classList.remove(gridSmall);
listSideElem.classList.add('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}
},
unmatch: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridFull);
listMainElem.classList.add(gridBig);
listSideElem.classList.add(gridSmall);
listSideElem.classList.remove('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

var navCollapseBtn = document.querySelector('.navbar__burger');
var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
if (navCollapse) {
navCollapse.setAttribute('data-open', false);
navCollapse.style.maxHeight = 0;
navCollapseBtn.classList.remove('is-active');
}
document.getElementsByClassName('navbar__menu')[0].classList.remove('is-active');
document.getElementsByClassName('mobile-search')[0].classList.add('hide');
},
setup: function () { },
deferSetup: true,
destroy: function () { },
});
</script>
{{ partial "script/sidebar-script" . }}
{{ partial "script/taxo-script" . }}
{{ end }}
74 changes: 1 addition & 73 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,78 +23,6 @@
</aside>
{{ end }}
</main>
<script>
{{ $sidebarPosition:= $.Param "sidebarPosition" }}
var sidebarPosition = JSON.parse({{ $sidebarPosition | jsonify }});
{{ $enableSidebar:= $.Param "enableSidebar" }}
var enableSidebar = JSON.parse({{ $enableSidebar | jsonify }});

var listMainElem = document.querySelector('.list__main');
var listSideElem = document.querySelector('.list__sidebar');

var gridSmall = 'l';
var gridBig = 'mr';
var gridFull = 'lmr'

if (sidebarPosition === "right") {
gridSmall = 'r';
gridBig = 'lm'
}

enquire.register("screen and (max-width: 769px)", {
match: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
listSideElem.classList.remove(gridSmall);
listSideElem.classList.add('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

},
unmatch: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridFull);
listMainElem.classList.add(gridBig);
listSideElem.classList.add(gridSmall);
listSideElem.classList.remove('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

var navCollapseBtn = document.querySelector('.navbar__burger');
var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
if (navCollapse) {
navCollapse.setAttribute('data-open', false);
navCollapse.style.maxHeight = 0;
navCollapseBtn.classList.remove('is-active');
}
if (document.getElementsByClassName('navbar__menu')[0]) {
document.getElementsByClassName('navbar__menu')[0].classList.remove('is-active');
}
if (document.getElementsByClassName('mobile-search')[0]) {
document.getElementsByClassName('mobile-search')[0].classList.add('hide');
}
},
setup: function () { },
deferSetup: true,
destroy: function () { },
});
</script>
{{ partial "script/sidebar-script" . }}
{{ partial "script/home-script" . }}
{{ end }}
73 changes: 73 additions & 0 deletions layouts/partials/script/sidebar-script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script>
{{ $sidebarPosition:= $.Param "sidebarPosition" }}
var sidebarPosition = JSON.parse({{ $sidebarPosition | jsonify }});
{{ $enableSidebar:= $.Param "enableSidebar" }}
var enableSidebar = JSON.parse({{ $enableSidebar | jsonify }});

var listMainElem = document.querySelector('.list__main');
var listSideElem = document.querySelector('.list__sidebar');

var gridSmall = 'l';
var gridBig = 'mr';
var gridFull = 'lmr'

if (sidebarPosition === "right") {
gridSmall = 'r';
gridBig = 'lm'
}

enquire.register("screen and (max-width: 769px)", {
match: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
listSideElem.classList.remove(gridSmall);
listSideElem.classList.add('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

},
unmatch: function () {
if (enableSidebar) {
listMainElem.classList.remove(gridFull);
listMainElem.classList.add(gridBig);
listSideElem.classList.add(gridSmall);
listSideElem.classList.remove('hide');
} else {
if (listMainElem && !listMainElem.classList.contains(gridFull)) {
listMainElem.classList.remove(gridBig);
listMainElem.classList.add(gridFull);
}

if (listSideElem && !listSideElem.classList.contains('hide')) {
listSideElem.classList.add('hide');
}
}

var navCollapseBtn = document.querySelector('.navbar__burger');
var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
if (navCollapse) {
navCollapse.setAttribute('data-open', false);
navCollapse.style.maxHeight = 0;
navCollapseBtn.classList.remove('is-active');
}
if (document.getElementsByClassName('navbar__menu')[0]) {
document.getElementsByClassName('navbar__menu')[0].classList.remove('is-active');
}
if (document.getElementsByClassName('mobile-search')[0]) {
document.getElementsByClassName('mobile-search')[0].classList.add('hide');
}
},
setup: function () { },
deferSetup: true,
destroy: function () { },
});
</script>

0 comments on commit 14b1c7c

Please sign in to comment.