From a2cc12da6b8948113ab053fd60a2ba9167f45ccb Mon Sep 17 00:00:00 2001 From: Brandon Moore Date: Mon, 29 Jul 2024 16:42:03 -0700 Subject: [PATCH] side panel add side panel functionality just like modal functionality --- itulFramework.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/itulFramework.js b/itulFramework.js index 3d48371..05de85f 100644 --- a/itulFramework.js +++ b/itulFramework.js @@ -1027,6 +1027,118 @@ function init_fill_height(trigger = true){ //--------------------------------------- END AJAX FILE UPLOAD PROGRESS -------------------------// + //--------------------------------------- BEGIN AJAX SIDEBAR LISTENING AND FUNCTIONS -------------------------// + + $(document).off('click.itul.sidePanel.close').on('click.itul.sidePanel.close', '[data-itul-dismiss="sidepanel"]', function(e){ + e.preventDefault(); + e.stopPropagation(); + + var target = $(this).closest('.itul-sidepanel'); + $(target).trigger('itul.sidepanel.hiding'); + $(target).removeClass('panel-open'); + var that = this; + setTimeout(function(){ + $(target).trigger('itul.sidepanel.hidden'); + var sidePanelWrap = $(target).closest('.itul-sidepanel'); + try{ + $(sidePanelWrap).data('sidepanel_overlay').remove(); + } + catch{ + + } + $(sidePanelWrap).remove(); + //$(target).closest('.itul-sidepanel').remove(); + }, 500); + }); + + //LISTEN FOR AJAX SIDEPANEL REQUEST + var sidePanelTrigger; + $(document).off('click.itul.sidePanel.trigger').on('click.itul.sidePanel.trigger', 'a.show-side-panel', function(e){ + + //PREVENT OTHER EVENTS + e.preventDefault(); + e.stopPropagation(); + spinner(); + + //APPEND THE STYLES + if(!$('style#itul-sidepanel-styles').length) $('head').append(''); + + //MEMORIZE THE TRIGGERING ELEMENT + sidePanelTrigger = $(this); + var tmpSidePanelTrigger = $(this); + + //REMOVE EXISTING SIDEPANEL + $('.itul-sidepanel').remove(); + $('.itul-sidepanel-overlay').remove(); + + //DEFINE VARIABLES + var url = $(this).attr('href'); + var data = $(this).data(); + var type = typeof($(this).attr('method')) !== 'undefined' ? $(this).attr('method') : 'get'; + var ele = $(this); + var callbackName = typeof($(this).attr('callback')) ? $(this).attr('callback') : null; + var title = typeof($(this).attr('title')) !== 'undefined' ? $(this).attr('title') : ''; + var size = typeof($(this).attr('data-itul-sidepanel-size')) !== 'undefined' ? $(this).attr('data-itul-sidepanel-size') : 'md'; + + //EXECUTE AJAX + $.ajax({ + url : url, + data : data, + type : type, + success : function(data){ + + data = typeof(data) == 'object' ? $(data.html) : $(data); + + var sidePanelWrap = $('
'); + $(sidePanelWrap).data('sidepanel_trigger', $(tmpSidePanelTrigger)); + if(size.length) $(sidePanelWrap).addClass('itul-sidepanel-'+size); + $('body').append($(sidePanelWrap)); + var header = $( + '
'+ + '
'+ + '

'+title+'

'+ + '
'+ + '
'+ + '
' + ); + + var dismissBtn = $('X'); + + $(header).find('.side-panel-close-btn-wrap').append($(dismissBtn)); + $(sidePanelWrap).append($(header)); + var bodyWrap = $('
'); + $(bodyWrap).append($(data)); + $(sidePanelWrap).append($(bodyWrap)); + var sidePanelOverlay = $('
').click(function(){ + var forceCloseBtn = $(''); + $(this).next('.itul-sidepanel').append($(forceCloseBtn)); + $(forceCloseBtn).trigger('click.itul.sidePanel.close'); + }); + $(sidePanelWrap).before($(sidePanelOverlay)); + $(sidePanelWrap).data('sidepanel_overlay', $(sidePanelOverlay)); + $(sidePanelWrap).trigger('itul.sidepanel.showing'); + + //POPULATE THE SIDE PANEL HTML + setTimeout(function(){ + $(sidePanelWrap).addClass('panel-open'); + setTimeout(function(){ + $(sidePanelWrap).trigger('itul.sidepanel.shown'); + }, 500); + }, 1); + + //HANDLE NAMESPACED CALLBACK FUNCTION + if(callbackName !== null){ + if(typeof(window[callbackName]) == 'function'){ + window[callbackName](data, ele) + } + } + } + }).done(function(){ + spinner('hide'); + }); + }); + + //--------------------------------------- END AJAX SIDEBAR LISTENING AND FUNCTIONS -------------------------//