Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for loading in HEAD #98

Closed
wants to merge 1 commit into from

2 participants

@Andy77L

The generation of the 'compat' object requires the document BODY to
exist and this is not available if Overscroll is loaded into the HEAD.
The setup of compat has been moved into the entry-point function.

Andy Larter Fix for loading in HEAD
The generation of the 'compat' object requires the document BODY to
exist and this is not available if Overscroll is loaded into the HEAD.
The setup of compat has been moved into the entry-point function.
64728f0
@azoff azoff added this to the 1.7.4 milestone
@azoff azoff closed this pull request from a commit
Jonathan Azoff 1.7.4 Release
- Adds source map to compiled output
- Removes legacy `demo.html`
- Drops IE<9 support
- Updates License and Copyright
- Changes compat to be lazy-loaded and memoized. Closes #98. Fixes #91
- Fixes formatting in test files
- Adds `thumbColor` option, to allow user-defined thumb colors. Closes #102
- Adds, and removes, a DOM body if required for testing. Closes #93
ee50e80
@azoff azoff closed this in ee50e80
@azoff azoff referenced this pull request from a commit
Jonathan Azoff 1.7.4 Release
- Adds source map to compiled output
- Removes legacy `demo.html`
- Drops IE<9 support
- Updates License and Copyright
- Changes compat to be lazy-loaded and memoized. Closes #98. Fixes #91
- Fixes formatting in test files
- Adds `thumbColor` option, to allow user-defined thumb colors. Closes #102
- Adds, and removes, a DOM body if required for testing. Closes #93
1913bfb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 15, 2013
  1. Fix for loading in HEAD

    Andy Larter authored
    The generation of the 'compat' object requires the document BODY to
    exist and this is not available if Overscroll is loaded into the HEAD.
    The setup of compat has been moved into the entry-point function.
This page is out of date. Refresh to see the latest.
Showing with 75 additions and 68 deletions.
  1. +75 −68 jquery.overscroll.js
View
143 jquery.overscroll.js
@@ -24,75 +24,8 @@
// The key used to bind-instance specific data to an object
var datakey = 'overscroll';
- // create <body> node if there's not one present (e.g., for test runners)
- if (dom.body === null) {
- dom.documentElement.appendChild(
- dom.createElement('body')
- );
- }
-
// runs feature detection for overscroll
- var compat = {
- animate: (function(){
- var fn = global.requestAnimationFrame ||
- global.webkitRequestAnimationFrame ||
- global.mozRequestAnimationFrame ||
- global.oRequestAnimationFrame ||
- global.msRequestAnimationFrame ||
- function(callback) { wait(callback, 1000/60); };
- return function(callback) {
- fn.call(global, callback);
- };
- })(),
- overflowScrolling: (function(){
- var style = '';
- var div = dom.createElement('div');
- var prefixes = ['webkit', 'moz', 'o', 'ms'];
- dom.body.appendChild(div);
- $.each(prefixes, function(i, prefix){
- div.style[prefix + 'OverflowScrolling'] = 'touch';
- });
- div.style.overflowScrolling = 'touch';
- var computedStyle = global.getComputedStyle(div);
- if (!!computedStyle.overflowScrolling) {
- style = 'overflow-scrolling';
- } else {
- $.each(prefixes, function(i, prefix){
- if (!!computedStyle[prefix + 'OverflowScrolling']) {
- style = '-' + prefix + '-overflow-scrolling';
- }
- return !style;
- });
- }
- div.parentNode.removeChild(div);
- return style;
- })(),
- cursor: (function() {
- var div = dom.createElement('div');
- var prefixes = ['webkit', 'moz'];
- var gmail = 'https://mail.google.com/mail/images/2/';
- var style = {
- grab: 'url('+gmail+'openhand.cur), move',
- grabbing: 'url('+gmail+'closedhand.cur), move'
- };
- dom.body.appendChild(div);
- $.each(prefixes, function(i, prefix){
- var found, cursor = '-' + prefix + '-grab';
- div.style.cursor = cursor;
- var computedStyle = global.getComputedStyle(div);
- found = computedStyle.cursor === cursor;
- if (found) {
- style = {
- grab: '-' + prefix + '-grab',
- grabbing: '-' + prefix + '-grabbing'
- };
- }
- return !found;
- });
- div.parentNode.removeChild(div);
- return style;
- })()
- };
+ var compat = null;
// These are all the events that could possibly
// be used by the plug-in
@@ -741,6 +674,80 @@
// You can find it's exposure point at the end
// of this closure
function overscroll(options) {
+ if (!compat) {
+
+ // create <body> node if there's not one present (e.g., for test runners)
+ if (dom.body === null) {
+ dom.documentElement.appendChild(
+ dom.createElement('body')
+ );
+ }
+
+ // runs feature detection for overscroll
+ compat = {
+ animate: (function(){
+ var fn = global.requestAnimationFrame ||
+ global.webkitRequestAnimationFrame ||
+ global.mozRequestAnimationFrame ||
+ global.oRequestAnimationFrame ||
+ global.msRequestAnimationFrame ||
+ function(callback) { wait(callback, 1000/60); };
+ return function(callback) {
+ fn.call(global, callback);
+ };
+ })(),
+ overflowScrolling: (function(){
+ var style = '';
+ var div = dom.createElement('div');
+ var prefixes = ['webkit', 'moz', 'o', 'ms'];
+ dom.body.appendChild(div);
+ $.each(prefixes, function(i, prefix){
+ div.style[prefix + 'OverflowScrolling'] = 'touch';
+ });
+ div.style.overflowScrolling = 'touch';
+ var computedStyle = global.getComputedStyle(div);
+ if (!!computedStyle.overflowScrolling) {
+ style = 'overflow-scrolling';
+ } else {
+ $.each(prefixes, function(i, prefix){
+ if (!!computedStyle[prefix + 'OverflowScrolling']) {
+ style = '-' + prefix + '-overflow-scrolling';
+ }
+ return !style;
+ });
+ }
+ div.parentNode.removeChild(div);
+ return style;
+ })(),
+ cursor: (function() {
+ var div = dom.createElement('div');
+ var prefixes = ['webkit', 'moz'];
+ var gmail = 'https://mail.google.com/mail/images/2/';
+ var style = {
+ grab: 'url('+gmail+'openhand.cur), move',
+ grabbing: 'url('+gmail+'closedhand.cur), move'
+ };
+ dom.body.appendChild(div);
+ $.each(prefixes, function(i, prefix){
+ var found, cursor = '-' + prefix + '-grab';
+ div.style.cursor = cursor;
+ var computedStyle = global.getComputedStyle(div);
+ found = computedStyle.cursor === cursor;
+ if (found) {
+ style = {
+ grab: '-' + prefix + '-grab',
+ grabbing: '-' + prefix + '-grabbing'
+ };
+ }
+ return !found;
+ });
+ div.parentNode.removeChild(div);
+ return style;
+ })()
+ };
+ }
+
+
return this.removeOverscroll().each(function() {
setup(this, options);
});
Something went wrong with that request. Please try again.