Skip to content

Commit

Permalink
refs #40870. Add user preferenc e feature to sidePanel
Browse files Browse the repository at this point in the history
  • Loading branch information
poliphilochu committed Jul 5, 2024
1 parent 01adea9 commit 36d4af6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/sidePanel/sidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
_nspOpened,
_nspFullscreen,
_nspContainerClass,
_nspUserPreference,
_nspAPI = window.location.origin + "/api/",
_container,
_content = "." + NSP_CONTENT,
Expand Down Expand Up @@ -246,19 +247,36 @@
_cssVariablesUpdate("--nsp-width", _nspWidth);
}

if (_nspOpened) {
let nspOpenedDefault = _nspOpened;
if (_nspUserPreference) {
if (typeof window.setCookie !== 'undefined') {
nspOpenedDefault = getCookie('nsp_user_preference_open_status');
}
}

if (nspOpenedDefault && nspOpenedDefault != 'false') {
_nspMain.open();
}
},
},
open: function() {
$(_container).addClass(OPEN_CLASS);
$(_container).removeClass(CLOSE_CLASS);
$("body").addClass("nsp-" + OPEN_CLASS);
if (_nspUserPreference) {
if (typeof window.setCookie !== 'undefined') {
setCookie('nsp_user_preference_open_status', true, 86400*30, window.location.pathname);
}
}
},
close: function() {
$(_container).removeClass(OPEN_CLASS);
$(_container).addClass(CLOSE_CLASS);
$("body").removeClass("nsp-" + OPEN_CLASS);
if (_nspUserPreference) {
if (typeof window.setCookie !== 'undefined') {
setCookie('nsp_user_preference_open_status', false, 86400*30, window.location.pathname);
}
}
},
fullscreen: function() {
_nspMain.open();
Expand Down Expand Up @@ -453,6 +471,7 @@
_nspWidth = _nspOptions.width;
_nspOpened = _nspOptions.opened;
_nspFullscreen = _nspOptions.fullscreen;
_nspUserPreference = _nspOptions.userPreference;

if (_debugMode) {
$("html").addClass("is-debug");
Expand Down
1 change: 1 addition & 0 deletions templates/CRM/common/sidePanel.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
neticrmSidePanelOpts.width = "{/literal}{$width}{literal}";
neticrmSidePanelOpts.opened = "{/literal}{$opened}{literal}";
neticrmSidePanelOpts.fullscreen = "{/literal}{$fullscreen}{literal}";
neticrmSidePanelOpts.userPreference = "{/literal}{$userPreference}{literal}";
neticrmSidePanelOpts.debugMode = "{/literal}{$config->debug}{literal}";
window.neticrmSidePanelInstance = $(".nsp-container").neticrmSidePanel(".nsp-container", neticrmSidePanelOpts);
});
Expand Down

0 comments on commit 36d4af6

Please sign in to comment.