Skip to content

Instantly share code, notes, and snippets.

@micho
Created February 3, 2012 23:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micho/1733598 to your computer and use it in GitHub Desktop.
Save micho/1733598 to your computer and use it in GitHub Desktop.
Prevent stupid Mac scroll
/**
* Show a notice when Mac's stupid scroll happens
* http://micho.biz/mac-osx-lion-horizontal-scroll-event/
*/
Global.preventStupidMacScroll = function () {
var self = this,
broken_browser = navigator.userAgent.match(/Macintosh/),
hide = Teambox.models.user.get('settings').hide_scroll_notice;
if (!broken_browser || hide) {
return;
}
$(window)
// Remember the last time you scrolled.
.mousewheel(function (e) {
self.lastScroll = Date.now();
})
// Clear it on click, since that means you're navigating
.click(function (e) {
self.lastScroll = undefined;
})
// If hash changes that means a back/fwd scroll happened
.bind('hashchange', function (e) {
var interval = Date.now() - (self.lastScroll || 0);
if (interval < 1000 && !Teambox.models.user.get('settings').hide_scroll_notice) {
$.facebox(Teambox.modules.ViewCompiler('global.scrolling_message')());
}
});
// Hide notice forever for this user
$('#hide_scroll_notice').live('click', function () {
$.ajax("/api/2/users/" + Teambox.models.user.id + "/update_settings", {
type: "put",
data: {"hide_scroll_notice": true}
});
Teambox.models.user.get('settings').hide_scroll_notice = true;
$.facebox.close();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment