Software Archive
Read-only legacy content
17061 Discussions

Is there a SideBar event generated when closed or opened?

Troy_B_1
Beginner
681 Views

Hello,

I am using XDK 1995 with JQuery Mobile. I have a button on the header that closes and opens the sidebar. I also set the sidebar to be swipeable. I need to be able to tell whether the sidebar was swiped open or close because my sidebar toggle button changes depending on the state of the sidebar. Does anybody know if the sidebar generates an open or close event?

 

0 Kudos
1 Solution
Chris_P_Intel
Employee
681 Views

This thread is old. A sidebar event was added months ago.

Look into sidebar.js  

View solution in original post

0 Kudos
6 Replies
Hamilton_Tenório_da_
Valued Contributor I
681 Views

You can controle the sidebar with this:

           uib_sb.open_sidebar($sb)
           uib_sb.close_sidebar($sb)
           uib_sb.toggle_sidebar($sb)
            uib_sb.close_all_sidebars()

0 Kudos
Troy_B_1
Beginner
681 Views

Hello Hamilton,

I am already using the commands to control the sidebar. What I need is how to find out if the sidebar was swiped closed or open. Is there an event I can add a listener for?

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
681 Views

Uhn... I never used this. I dont´t know. Sorry.

0 Kudos
Chris_P_Intel
Employee
681 Views

There is no event yet. But that would be easy to add. The uib_sidebar.js file is put into your project and, as you can see, it's very straightforward.  Make the change there to have it fire an event.

I'll add that event as a feature request.

0 Kudos
Andre_G_1
Beginner
681 Views

I've just implemented something like this in my app, which I'm using to inject and remove a page overlay behind the sidebar when it opens.

Chris's comment above got the ball rolling for me, but there was still a great deal of trial-and-error trying to get it working properly. I can't imagine how many people have come across this page while searching for a way to do this, yet this thread has absolutely no useful information.. So in light of that, here's how I achieved this:

Inside the "www/sidebar/js/sidebar.js" file, in the "perform_open_close_sidebar()" function, I extended the "if (open) {}" check from the initial...

if (open) {
    should_toggle = !should_toggle;
}

...to the following...

if (open) {
    should_toggle = !should_toggle;
    $(document).trigger('open_sidebar');
} else {
    $(document).trigger('close_sidebar');
}

This allows me to run custom functions anytime a sidebar is opened or closed, regardless of how it's triggered (by the "toggle", "open" or "close" functions, including activation by button or swipe).

Hope that helps someone. :)

0 Kudos
Chris_P_Intel
Employee
682 Views

This thread is old. A sidebar event was added months ago.

Look into sidebar.js  

0 Kudos
Reply