Commit 2c9ea5b6 authored by Joshua Robinson's avatar Joshua Robinson

Clicking any button on the banner will now collapse it.

parent 4f737408
<script type="text/discourse-plugin"version="0.8.18">
<script type="text/discourse-plugin" version="0.8.18">
const { iconNode, convertIconClass } = require("discourse-common/lib/icon-library");
const h = require("virtual-dom").h;
......@@ -76,6 +76,53 @@ api.createWidget("banner-box-widget", {
}
});
function toggleBannerState() {
toggleState = (toggleState === "expanded") ? "collapsed" : "expanded";
$("#banner-content_wrap").slideToggle();
if(cookieExpDate) {
let bannerState;
if($.cookie("banner_collapsed")) {
bannerState = JSON.parse($.cookie('banner_collapsed'));
bannerState.name = settings.cookie_name;
if(bannerState.collapsed == "false") {
bannerState.collapsed = "true";
} else {
bannerState.collapsed = "false";
}
} else {
if(settings.default_collapsed_state == "collapsed") {
bannerState = { name: settings.cookie_name, collapsed: "false" }
} else {
bannerState = { name: settings.cookie_name, collapsed: "true" }
}
}
$.cookie("banner_collapsed", JSON.stringify(bannerState), { expires: cookieExpDate, path: '/' });
}
}
function collapseBanner() {
if (toggleState === "expanded") toggleBannerState();
}
$(document).ready(function(){
$(".button-list").click(function(){
collapseBanner();
});
});
api.createWidget('collapse-button', {
tagName: 'button.btn.btn-primary',
html(arg) {
return arg;
},
click(arg) {
collapseBanner();
}
});
api.decorateWidget('banner-box-widget:after', helper => {
helper.widget.appEvents.on('page:changed', () => {
helper.widget.scheduleRerender();
......@@ -122,28 +169,7 @@ api.createWidget("banner-button-container-widget", {
}
}
else if (button == "toggle") {
toggleState = (toggleState === "expanded") ? "collapsed" : "expanded";
$("#banner-content_wrap").slideToggle();
if(cookieExpDate) {
let bannerState;
if($.cookie("banner_collapsed")) {
bannerState = JSON.parse($.cookie('banner_collapsed'));
bannerState.name = settings.cookie_name;
if(bannerState.collapsed == "false") {
bannerState.collapsed = "true";
} else {
bannerState.collapsed = "false";
}
} else {
if(settings.default_collapsed_state == "collapsed") {
bannerState = { name: settings.cookie_name, collapsed: "false" }
} else {
bannerState = { name: settings.cookie_name, collapsed: "true" }
}
}
$.cookie("banner_collapsed", JSON.stringify(bannerState), { expires: cookieExpDate, path: '/' });
}
toggleBannerState();
}
},
toggleIcon() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment