Created
February 3, 2012 23:17
-
-
Save micho/1733598 to your computer and use it in GitHub Desktop.
Prevent stupid Mac scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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