Skip to content

Instantly share code, notes, and snippets.

@viankakrisna
Last active May 26, 2017 18:59
Show Gist options
  • Save viankakrisna/c1850019fc3a09bdbf86 to your computer and use it in GitHub Desktop.
Save viankakrisna/c1850019fc3a09bdbf86 to your computer and use it in GitHub Desktop.
Mobile and Desktop Responsive Layout Handler
var mobileManager = function (mobile, desktop, breakpoint) {
//Defaults to 767, not much desktop running below that right now isn't it?
var _breakpoint = breakpoint || 767;
//Defaults to function, we need to invoke this later
var _desktop = desktop || function () {};
var _mobile = mobile || function () {};
//Counter to see where we are right now
var nowdesktop = 0;
var nowmobile = 0;
//Attach on window load and resize, so the function works even when you resize the window
$(window)
.on('load resize', function () {
if ($(window)
.width() <= _breakpoint) {
if (nowmobile === 0) {
_mobile();
nowmobile++;
nowdesktop = 0;
}
} else {
if (nowdesktop === 0) {
_desktop();
nowdesktop++;
nowmobile = 0;
}
}
});
};
//Init the function, remember to undo all the changes you've done on the break points
mobileManager(function () {
$('.single-event')
.find('#content')
.before($('#sidebar'));
}, function () {
$('.single-event')
.find('#content')
.after($('#sidebar'));
}, 990);
@ivankristianto
Copy link

Ini appaan ya de?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment