maciej-gurban / responsive-bootstrap-toolkit

Responsive Bootstrap Toolkit allows for easy breakpoint detection in JavaScript
MIT License
363 stars 89 forks source link

Added event to listen to viewport breakpoints changes #34

Closed boris-burgos closed 8 years ago

boris-burgos commented 8 years ago

The listener allow to execute code only when change from one breakpoint to another. For example:

$(window).resize(
    viewport.onChange(function(event,viewport,current_breakpoint,previous_breakpoint) {
      if(current_breakpoint=="xs"){
        // ...
      }else if(viewport.is(">=sm")){
        //...
      }else{
        //...
      }
    })
);
maciej-gurban commented 8 years ago

Hi Boris,

Thanks for taking the time to write the pull request, I really appreciate it. This functionality has been requested in the past, and is on my roadmap as well.

I was hoping to transform current changed method into something that you proposed, at the same time bootstrap 4 would be released (which also would require changes the visibility classes), but it seems it might take a while, a longer while than I expected.

I think having two methods very similar in naming could be a bit too confusing, so I'm currently quite open to naming suggestions for the new method (perhaps as proposed by another user, breakpointChanged would suffice for now). Upon new major release (with breaking changes), these methods would be renamed to reflect what they are actually doing: changed to debounce and breakpointChanged to changed or onChange.

boris-burgos commented 8 years ago

Hi Maciej.

You are right. At first glance I thought the "change" method was a change listener.

The names you propose are quite better that the "onChange" method until the breaking changes you talk about.

Greetings.

luckydonald commented 6 years ago

Coming back years later, there still is no normal event we can listen too, like the proposed rbt.viewport_breakpoint_changed, right?