diff options
author | Ryan Van Etten <ryanve@gmail.com> | 2014-02-02 14:03:45 -0500 |
---|---|---|
committer | Ryan Van Etten <ryanve@gmail.com> | 2014-02-02 14:03:45 -0500 |
commit | 5e54034a4d6f8e5a5862b51bcd878d5830c402db (patch) | |
tree | 64b8c7edf62703ab8e65c961603a85f2964143de | |
parent | c10da267eb3e6cc57c72e8032f8061f6671981fc (diff) | |
download | verge-5e54034a4d6f8e5a5862b51bcd878d5830c402db.zip verge-5e54034a4d6f8e5a5862b51bcd878d5830c402db.tar.gz verge-5e54034a4d6f8e5a5862b51bcd878d5830c402db.tar.bz2 |
Use 2-space indents
-rw-r--r-- | GruntFile.js | 100 | ||||
-rw-r--r-- | package.json | 38 | ||||
-rw-r--r-- | src/ender.js | 6 | ||||
-rw-r--r-- | src/verge.js | 318 | ||||
-rw-r--r-- | test/index.html | 230 | ||||
-rw-r--r-- | test/index.js | 118 |
6 files changed, 405 insertions, 405 deletions
diff --git a/GruntFile.js b/GruntFile.js index c7a22b3..b17beab 100644 --- a/GruntFile.js +++ b/GruntFile.js @@ -1,53 +1,53 @@ module.exports = function(grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - jshint: { - // gruntjs.com/configuring-tasks#globbing-patterns - // **/** matches in current and sub dirs - all: ['./'], // current dir and sub dirs - sub: ['*/'], // sub dirs - dir: ['*.js'], // current dir - src: ['src/'], - test: ['test/'], - grunt: ['GruntFile.js'], - build: ['<%= pkg.name %>.js'], - options: { - ignores: ['**/**/node_modules/', '**/**/vendor/', '**/**.min.js'], - debug:true, expr:true, sub:true, boss:true, supernew:true, node:true, - undef:true, unused:true, devel:true, evil:true, laxcomma:true, eqnull:true, - browser:true, globals:{ender:true}, jquery:true, maxerr:10 - } - }, - concat: { - options: { - banner: [ - '/*!', - ' * <%= pkg.name %> <%= pkg.version %>+<%= grunt.template.today("UTC:yyyymmddHHMM") %>', - ' * <%= pkg.homepage %>', - ' * MIT License 2013 <%= pkg.author %>', - ' */\n\n' - ].join('\n') - }, - build: { - files: { - '<%= pkg.name %>.js': ['src/<%= pkg.name %>.js'] - } - } - }, - uglify: { - options: { - report: 'gzip', - preserveComments: 'some' - }, - build: { - files: { - '<%= pkg.name %>.min.js': ['<%= pkg.name %>.js'] - } - } + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + jshint: { + // gruntjs.com/configuring-tasks#globbing-patterns + // **/** matches in current and sub dirs + all: ['./'], // current dir and sub dirs + sub: ['*/'], // sub dirs + dir: ['*.js'], // current dir + src: ['src/'], + test: ['test/'], + grunt: ['GruntFile.js'], + build: ['<%= pkg.name %>.js'], + options: { + ignores: ['**/**/node_modules/', '**/**/vendor/', '**/**.min.js'], + debug:true, expr:true, sub:true, boss:true, supernew:true, node:true, + undef:true, unused:true, devel:true, evil:true, laxcomma:true, eqnull:true, + browser:true, globals:{ender:true}, jquery:true, maxerr:10 + } + }, + concat: { + options: { + banner: [ + '/*!', + ' * <%= pkg.name %> <%= pkg.version %>+<%= grunt.template.today("UTC:yyyymmddHHMM") %>', + ' * <%= pkg.homepage %>', + ' * MIT License 2013 <%= pkg.author %>', + ' */\n\n' + ].join('\n') + }, + build: { + files: { + '<%= pkg.name %>.js': ['src/<%= pkg.name %>.js'] } - }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.registerTask('default', ['jshint:grunt', 'jshint:sub', 'concat', 'jshint:build', 'uglify']); + } + }, + uglify: { + options: { + report: 'gzip', + preserveComments: 'some' + }, + build: { + files: { + '<%= pkg.name %>.min.js': ['<%= pkg.name %>.js'] + } + } + } + }); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.registerTask('default', ['jshint:grunt', 'jshint:sub', 'concat', 'jshint:build', 'uglify']); };
\ No newline at end of file diff --git a/package.json b/package.json index 843dba9..b6bcad7 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { - "name": "verge", - "description": "viewport utilities module", - "version": "1.8.3", - "homepage": "https://github.com/ryanve/verge", - "license": "MIT", - "author": "Ryan Van Etten", - "keywords": ["viewport", "dimensions", "responsive", "media queries", "ender"], - "main": "./verge.js", - "ender": "./src/ender.js", - "repository": { - "type": "git", - "url": "https://github.com/ryanve/verge.git" - }, - "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-uglify": "~0.2.4", - "grunt-contrib-concat": "~0.3.0", - "grunt-contrib-jshint": "~0.6.4" - } + "name": "verge", + "description": "viewport utilities module", + "version": "1.8.3", + "homepage": "https://github.com/ryanve/verge", + "license": "MIT", + "author": "Ryan Van Etten", + "keywords": ["viewport", "dimensions", "responsive", "media queries", "ender"], + "main": "./verge.js", + "ender": "./src/ender.js", + "repository": { + "type": "git", + "url": "https://github.com/ryanve/verge.git" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-uglify": "~0.2.4", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-jshint": "~0.6.4" + } }
\ No newline at end of file diff --git a/src/ender.js b/src/ender.js index ff65151..eca9fb1 100644 --- a/src/ender.js +++ b/src/ender.js @@ -1,4 +1,4 @@ -/* bridge (integration) for ender.jit.su */ -(function ($, name) { - $ && $.ender(require(name)); +/* integrate with ender.jit.su */ +(function($, name) { + $ && $.ender(require(name)); }(this.ender, 'verge'));
\ No newline at end of file diff --git a/src/verge.js b/src/verge.js index 0cf0684..1e2711f 100644 --- a/src/verge.js +++ b/src/verge.js @@ -1,174 +1,174 @@ (function(root, name, make) { - if (typeof module != 'undefined' && module['exports']) module['exports'] = make(); - else root[name] = make(); + if (typeof module != 'undefined' && module['exports']) module['exports'] = make(); + else root[name] = make(); }(this, 'verge', function() { - var xports = {} - , win = typeof window != 'undefined' && window - , doc = typeof document != 'undefined' && document - , docElem = doc && doc.documentElement - , matchMedia = win['matchMedia'] || win['msMatchMedia'] - , mq = matchMedia ? function(q) { - return !!matchMedia.call(win, q).matches; - } : function() { - return false; - } - // http://ryanve.com/lab/dimensions - // http://github.com/ryanve/verge/issues/7 - , viewportW = docElem['clientWidth'] < win['innerWidth'] ? function() { - return win['innerWidth']; - } : function() { - return docElem['clientWidth']; - } - , viewportH = docElem['clientHeight'] < win['innerHeight'] ? function() { - return win['innerHeight']; - } : function() { - return docElem['clientHeight']; - }; - - /** - * Test if a media query is active. Like Modernizr.mq - * @since 1.6.0 - * @return {boolean} - */ - xports['mq'] = mq; + var xports = {} + , win = typeof window != 'undefined' && window + , doc = typeof document != 'undefined' && document + , docElem = doc && doc.documentElement + , matchMedia = win['matchMedia'] || win['msMatchMedia'] + , mq = matchMedia ? function(q) { + return !!matchMedia.call(win, q).matches; + } : function() { + return false; + } + // http://ryanve.com/lab/dimensions + // http://github.com/ryanve/verge/issues/7 + , viewportW = docElem['clientWidth'] < win['innerWidth'] ? function() { + return win['innerWidth']; + } : function() { + return docElem['clientWidth']; + } + , viewportH = docElem['clientHeight'] < win['innerHeight'] ? function() { + return win['innerHeight']; + } : function() { + return docElem['clientHeight']; + }; + + /** + * Test if a media query is active. Like Modernizr.mq + * @since 1.6.0 + * @return {boolean} + */ + xports['mq'] = mq; - /** - * Normalized matchMedia - * @since 1.6.0 - * @return {MediaQueryList|Object} - */ - xports['matchMedia'] = matchMedia ? function() { - // matchMedia must be binded to window - return matchMedia.apply(win, arguments); - } : function() { - // Gracefully degrade to plain object - return {}; - }; + /** + * Normalized matchMedia + * @since 1.6.0 + * @return {MediaQueryList|Object} + */ + xports['matchMedia'] = matchMedia ? function() { + // matchMedia must be binded to window + return matchMedia.apply(win, arguments); + } : function() { + // Gracefully degrade to plain object + return {}; + }; - /** - * Get the layout viewport width. - * @since 1.0.0 - * @return {number} - */ - xports['viewportW'] = viewportW; + /** + * Get the layout viewport width. + * @since 1.0.0 + * @return {number} + */ + xports['viewportW'] = viewportW; - /** - * Get the layout viewport height. - * @since 1.0.0 - * @return {number} - */ - xports['viewportH'] = viewportH; - - /** - * alternate syntax for getting viewport dims - * @since 1.8.0 - * @return {Object} - */ - function viewport() { - return {'width':viewportW(), 'height':viewportH()}; - } - xports['viewport'] = viewport; - - /** - * Cross-browser window.scrollX - * @since 1.0.0 - * @return {number} - */ - xports['scrollX'] = function() { - return win.pageXOffset || docElem.scrollLeft; - }; + /** + * Get the layout viewport height. + * @since 1.0.0 + * @return {number} + */ + xports['viewportH'] = viewportH; + + /** + * alternate syntax for getting viewport dims + * @since 1.8.0 + * @return {Object} + */ + function viewport() { + return {'width':viewportW(), 'height':viewportH()}; + } + xports['viewport'] = viewport; + + /** + * Cross-browser window.scrollX + * @since 1.0.0 + * @return {number} + */ + xports['scrollX'] = function() { + return win.pageXOffset || docElem.scrollLeft; + }; - /** - * Cross-browser window.scrollY - * @since 1.0.0 - * @return {number} - */ - xports['scrollY'] = function() { - return win.pageYOffset || docElem.scrollTop; - }; + /** + * Cross-browser window.scrollY + * @since 1.0.0 + * @return {number} + */ + xports['scrollY'] = function() { + return win.pageYOffset || docElem.scrollTop; + }; - /** - * @param {{top:number, right:number, bottom:number, left:number}} coords - * @param {number=} cushion adjustment - * @return {Object} - */ - function calibrate(coords, cushion) { - var o = {}; - cushion = +cushion || 0; - o['width'] = (o['right'] = coords['right'] + cushion) - (o['left'] = coords['left'] - cushion); - o['height'] = (o['bottom'] = coords['bottom'] + cushion) - (o['top'] = coords['top'] - cushion); - return o; - } + /** + * @param {{top:number, right:number, bottom:number, left:number}} coords + * @param {number=} cushion adjustment + * @return {Object} + */ + function calibrate(coords, cushion) { + var o = {}; + cushion = +cushion || 0; + o['width'] = (o['right'] = coords['right'] + cushion) - (o['left'] = coords['left'] - cushion); + o['height'] = (o['bottom'] = coords['bottom'] + cushion) - (o['top'] = coords['top'] - cushion); + return o; + } - /** - * Cross-browser element.getBoundingClientRect plus optional cushion. - * Coords are relative to the top-left corner of the viewport. - * @since 1.0.0 - * @param {Element|Object} el element or stack (uses first item) - * @param {number=} cushion +/- pixel adjustment amount - * @return {Object|boolean} - */ - function rectangle(el, cushion) { - el = el && !el.nodeType ? el[0] : el; - if (!el || 1 !== el.nodeType) return false; - return calibrate(el.getBoundingClientRect(), cushion); - } - xports['rectangle'] = rectangle; + /** + * Cross-browser element.getBoundingClientRect plus optional cushion. + * Coords are relative to the top-left corner of the viewport. + * @since 1.0.0 + * @param {Element|Object} el element or stack (uses first item) + * @param {number=} cushion +/- pixel adjustment amount + * @return {Object|boolean} + */ + function rectangle(el, cushion) { + el = el && !el.nodeType ? el[0] : el; + if (!el || 1 !== el.nodeType) return false; + return calibrate(el.getBoundingClientRect(), cushion); + } + xports['rectangle'] = rectangle; - /** - * Get the viewport aspect ratio (or the aspect ratio of an object or element) - * @since 1.7.0 - * @param {(Element|Object)=} o optional object with width/height props or methods - * @return {number} - * @link http://w3.org/TR/css3-mediaqueries/#orientation - */ - function aspect(o) { - o = null == o ? viewport() : 1 === o.nodeType ? rectangle(o) : o; - var h = o['height'], w = o['width']; - h = typeof h == 'function' ? h.call(o) : h; - w = typeof w == 'function' ? w.call(o) : w; - return w/h; - } - xports['aspect'] = aspect; + /** + * Get the viewport aspect ratio (or the aspect ratio of an object or element) + * @since 1.7.0 + * @param {(Element|Object)=} o optional object with width/height props or methods + * @return {number} + * @link http://w3.org/TR/css3-mediaqueries/#orientation + */ + function aspect(o) { + o = null == o ? viewport() : 1 === o.nodeType ? rectangle(o) : o; + var h = o['height'], w = o['width']; + h = typeof h == 'function' ? h.call(o) : h; + w = typeof w == 'function' ? w.call(o) : w; + return w/h; + } + xports['aspect'] = aspect; - /** - * Test if an element is in the same x-axis section as the viewport. - * @since 1.0.0 - * @param {Element|Object} el - * @param {number=} cushion - * @return {boolean} - */ - xports['inX'] = function(el, cushion) { - var r = rectangle(el, cushion); - return !!r && r.right >= 0 && r.left <= viewportW(); - }; + /** + * Test if an element is in the same x-axis section as the viewport. + * @since 1.0.0 + * @param {Element|Object} el + * @param {number=} cushion + * @return {boolean} + */ + xports['inX'] = function(el, cushion) { + var r = rectangle(el, cushion); + return !!r && r.right >= 0 && r.left <= viewportW(); + }; - /** - * Test if an element is in the same y-axis section as the viewport. - * @since 1.0.0 - * @param {Element|Object} el - * @param {number=} cushion - * @return {boolean} - */ - xports['inY'] = function(el, cushion) { - var r = rectangle(el, cushion); - return !!r && r.bottom >= 0 && r.top <= viewportH(); - }; + /** + * Test if an element is in the same y-axis section as the viewport. + * @since 1.0.0 + * @param {Element|Object} el + * @param {number=} cushion + * @return {boolean} + */ + xports['inY'] = function(el, cushion) { + var r = rectangle(el, cushion); + return !!r && r.bottom >= 0 && r.top <= viewportH(); + }; - /** - * Test if an element is in the viewport. - * @since 1.0.0 - * @param {Element|Object} el - * @param {number=} cushion - * @return {boolean} - */ - xports['inViewport'] = function(el, cushion) { - // Equiv to `inX(el, cushion) && inY(el, cushion)` but just manually do both - // to avoid calling rectangle() twice. It gzips just as small like this. - var r = rectangle(el, cushion); - return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= viewportH() && r.left <= viewportW(); - }; + /** + * Test if an element is in the viewport. + * @since 1.0.0 + * @param {Element|Object} el + * @param {number=} cushion + * @return {boolean} + */ + xports['inViewport'] = function(el, cushion) { + // Equiv to `inX(el, cushion) && inY(el, cushion)` but just manually do both + // to avoid calling rectangle() twice. It gzips just as small like this. + var r = rectangle(el, cushion); + return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= viewportH() && r.left <= viewportW(); + }; - return xports; + return xports; }));
\ No newline at end of file diff --git a/test/index.html b/test/index.html index 208c895..209db3f 100644 --- a/test/index.html +++ b/test/index.html @@ -1,124 +1,124 @@ <!DOCTYPE html> <html lang="en-US"> <head> - <meta charset="utf-8"> - <title>verge // test suite</title> - <meta name=viewport content="width=device-width,initial-scale=1.0"> - <meta name=description content="JavaScript module test page"> - <style> - html { font-family:sans-serif; background:#fdf6e3; color:#586e75; font-size:1em } - body { margin:1em auto; max-width:100%; width:94%; } - a:link, a:visited { color:#268bd2 } - code .number { color:#b58900 } - pre, td, th { padding:1em;text-align:left; border:1px dotted #93a1a1 } - th { font-weight:bold; } - td { color:#2aa198 } - td:first-child { font-weight:normal;color:#586e75 } - td:last-child { color:#dc322f; } - pre { padding:1em; background:#073642; color:#93a1a1 } - </style> - <script src="./vendor/ender.min.js"></script> - <script src="../src/verge.js"></script> - <script src="./index.js"></script> + <meta charset="utf-8"> + <title>verge // test suite</title> + <meta name=viewport content="width=device-width,initial-scale=1.0"> + <meta name=description content="JavaScript module test page"> + <style> + html { font-family:sans-serif; background:#fdf6e3; color:#586e75; font-size:1em } + body { margin:1em auto; max-width:100%; width:94%; } + a:link, a:visited { color:#268bd2 } + code .number { color:#b58900 } + pre, td, th { padding:1em;text-align:left; border:1px dotted #93a1a1 } + th { font-weight:bold; } + td { color:#2aa198 } + td:first-child { font-weight:normal;color:#586e75 } + td:last-child { color:#dc322f; } + pre { padding:1em; background:#073642; color:#93a1a1 } + </style> + <script src="./vendor/ender.min.js"></script> + <script src="../src/verge.js"></script> + <script src="./index.js"></script> </head> <body> - <div> - <h1><a href="http://github.com/ryanve/verge">verge</a> Test Suite</h1> - </div> + <div> + <h1><a href="http://github.com/ryanve/verge">verge</a> Test Suite</h1> + </div> - <pre id="ua"></pre> + <pre id="ua"></pre> - <div id="a"><pre><code>div#a</code></pre></div> - - <table id=tests> - <tr> - <th scope="col"><a href=#tests accesskey=s>test<br>code</a></th> - <th scope="col"><a href=#tests>expected<br>type</a></th> - <th scope="col"><a href=#tests>live<br>output</a></th> - </tr> - <tr> - <td><code>$<wbr>.inViewport(a, <span class=number>-100</span>)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-a-neg"></code></td> - </tr> - <tr> - <td><code>$<wbr>.inViewport(a)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-a"></code></td> - </tr> - <tr> - <td><code>$<wbr>.inViewport(a, <span class=number>100</span>)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-a-pos"></code></td> - </tr> - <tr> - <td><code>$<wbr>.viewportW()</code></td> - <td><code>number</code></td> - <td><code id="viewport-w"></code></td> - </tr> - <tr> - <td><code>$<wbr>.viewportH()</code></td> - <td><code>number</code></td> - <td><code id="viewport-h"></code></td> - </tr> - <tr> - <td><code>$<wbr>.scrollX()</code></td> - <td><code>number</code></td> - <td><code id="scroll-x"></code></td> - </tr> - <tr> - <td><code>$<wbr>.scrollY()</code></td> - <td><code>number</code></td> - <td><code id="scroll-y"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.top</code></td> - <td><code>number</code></td> - <td><code id="rectangle-top"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.bottom</code></td> - <td><code>number</code></td> - <td><code id="rectangle-bottom"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.left</code></td> - <td><code>number</code></td> - <td><code id="rectangle-left"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.right</code></td> - <td><code>number</code></td> - <td><code id="rectangle-right"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.width</code></td> - <td><code>number</code></td> - <td><code id="rectangle-width"></code></td> - </tr> - <tr> - <td><code>$<wbr>.rectangle(a)<wbr>.height</code></td> - <td><code>number</code></td> - <td><code id="rectangle-height"></code></td> - </tr> - <tr> - <td><code>$<wbr>.inViewport(b, <span class=number>100</span>)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-b-pos"></code></td> - </tr> - <tr> - <td><code>$<wbr>.inViewport(b)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-b"></code></td> - </tr> - <tr> - <td><code>$<wbr>.inViewport(b, <span class=number>-100</span>)</code></td> - <td><code>boolean</code></td> - <td><code id="in-viewport-b-neg"></code></td> - </tr> - </table> - - <div id="b"><pre><code>div#b</code></pre></div> - <div id="c"><pre><code>div#c</code></pre></div> + <div id="a"><pre><code>div#a</code></pre></div> + + <table id=tests> + <tr> + <th scope="col"><a href=#tests accesskey=s>test<br>code</a></th> + <th scope="col"><a href=#tests>expected<br>type</a></th> + <th scope="col"><a href=#tests>live<br>output</a></th> + </tr> + <tr> + <td><code>$<wbr>.inViewport(a, <span class=number>-100</span>)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-a-neg"></code></td> + </tr> + <tr> + <td><code>$<wbr>.inViewport(a)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-a"></code></td> + </tr> + <tr> + <td><code>$<wbr>.inViewport(a, <span class=number>100</span>)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-a-pos"></code></td> + </tr> + <tr> + <td><code>$<wbr>.viewportW()</code></td> + <td><code>number</code></td> + <td><code id="viewport-w"></code></td> + </tr> + <tr> + <td><code>$<wbr>.viewportH()</code></td> + <td><code>number</code></td> + <td><code id="viewport-h"></code></td> + </tr> + <tr> + <td><code>$<wbr>.scrollX()</code></td> + <td><code>number</code></td> + <td><code id="scroll-x"></code></td> + </tr> + <tr> + <td><code>$<wbr>.scrollY()</code></td> + <td><code>number</code></td> + <td><code id="scroll-y"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.top</code></td> + <td><code>number</code></td> + <td><code id="rectangle-top"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.bottom</code></td> + <td><code>number</code></td> + <td><code id="rectangle-bottom"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.left</code></td> + <td><code>number</code></td> + <td><code id="rectangle-left"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.right</code></td> + <td><code>number</code></td> + <td><code id="rectangle-right"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.width</code></td> + <td><code>number</code></td> + <td><code id="rectangle-width"></code></td> + </tr> + <tr> + <td><code>$<wbr>.rectangle(a)<wbr>.height</code></td> + <td><code>number</code></td> + <td><code id="rectangle-height"></code></td> + </tr> + <tr> + <td><code>$<wbr>.inViewport(b, <span class=number>100</span>)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-b-pos"></code></td> + </tr> + <tr> + <td><code>$<wbr>.inViewport(b)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-b"></code></td> + </tr> + <tr> + <td><code>$<wbr>.inViewport(b, <span class=number>-100</span>)</code></td> + <td><code>boolean</code></td> + <td><code id="in-viewport-b-neg"></code></td> + </tr> + </table> + + <div id="b"><pre><code>div#b</code></pre></div> + <div id="c"><pre><code>div#c</code></pre></div> </body> </html>
\ No newline at end of file diff --git a/test/index.js b/test/index.js index aa3011a..260aac5 100644 --- a/test/index.js +++ b/test/index.js @@ -1,65 +1,65 @@ (function(root, window, document) { - var a, b, c - , $ = root.$ - , verge = root.verge - , _ = require('blood').assign(require('curious')) - , aok = require('aok') - , log = aok.log - , id = aok.id - , readyTests = {} - , resizeTests = {} - , scrollTests = {} - , dynamicTests = {} - , dims = ['top', 'bottom', 'left', 'right', 'width', 'height'] - , slice = dims.slice - , push = dims.push; - - _.assign($, verge); - log(verge); - - function bind(fn, scope) { - var partial = slice.call(arguments, 2); - return function() { - var args = partial.slice(0); - push.apply(args, arguments); - return fn.apply(scope, args); - }; - } + var a, b, c + , $ = root.$ + , verge = root.verge + , _ = require('blood').assign(require('curious')) + , aok = require('aok') + , log = aok.log + , id = aok.id + , readyTests = {} + , resizeTests = {} + , scrollTests = {} + , dynamicTests = {} + , dims = ['top', 'bottom', 'left', 'right', 'width', 'height'] + , slice = dims.slice + , push = dims.push; - function html(el, markup) { - el && (el.innerHTML = aok.explain(aok.result(markup)) || ''); - } + _.assign($, verge); + log(verge); + + function bind(fn, scope) { + var partial = slice.call(arguments, 2); + return function() { + var args = partial.slice(0); + push.apply(args, arguments); + return fn.apply(scope, args); + }; + } + + function html(el, markup) { + el && (el.innerHTML = aok.explain(aok.result(markup)) || ''); + } - function update(tests) { - for (var n in tests) html(id(n), tests[n]); - return tests; - } + function update(tests) { + for (var n in tests) html(id(n), tests[n]); + return tests; + } - readyTests['ua'] = navigator.userAgent || ''; - resizeTests['viewport-w'] = $.viewportW; - resizeTests['viewport-h'] = $.viewportH; - scrollTests['scroll-x'] = $.scrollX; - scrollTests['scroll-y'] = $.scrollY; + readyTests['ua'] = navigator.userAgent || ''; + resizeTests['viewport-w'] = $.viewportW; + resizeTests['viewport-h'] = $.viewportH; + scrollTests['scroll-x'] = $.scrollX; + scrollTests['scroll-y'] = $.scrollY; - $(document).ready(function() { - if (!_.every([a = id('a'), b = id('b'), c = id('c')], _.isElement)) - throw Error('Required DOM elements did not exist.'); - log($.rectangle(a)); - _.some(dims, function(key) { - var bound = this; - dynamicTests['rectangle-' + key] = function() { - return bound.call()[key]; - }; - }, bind($.rectangle, $, a)); - dynamicTests['in-viewport-a'] = bind($.inViewport, $, a); - dynamicTests['in-viewport-a-pos'] = bind($.inViewport, $, a, 100); - dynamicTests['in-viewport-a-neg'] = bind($.inViewport, $, a, -100); - dynamicTests['in-viewport-b'] = bind($.inViewport, $, b); - dynamicTests['in-viewport-b-pos'] = bind($.inViewport, $, b, 100); - dynamicTests['in-viewport-b-neg'] = bind($.inViewport, $, b, -100); - _.assign(resizeTests, dynamicTests); - _.assign(scrollTests, dynamicTests); - _.every([readyTests, resizeTests, scrollTests], update); - $(window).on('resize', bind(update, null, resizeTests)).on('scroll', bind(update, null, scrollTests)); - }); + $(document).ready(function() { + if (!_.every([a = id('a'), b = id('b'), c = id('c')], _.isElement)) + throw Error('Required DOM elements did not exist.'); + log($.rectangle(a)); + _.some(dims, function(key) { + var bound = this; + dynamicTests['rectangle-' + key] = function() { + return bound.call()[key]; + }; + }, bind($.rectangle, $, a)); + dynamicTests['in-viewport-a'] = bind($.inViewport, $, a); + dynamicTests['in-viewport-a-pos'] = bind($.inViewport, $, a, 100); + dynamicTests['in-viewport-a-neg'] = bind($.inViewport, $, a, -100); + dynamicTests['in-viewport-b'] = bind($.inViewport, $, b); + dynamicTests['in-viewport-b-pos'] = bind($.inViewport, $, b, 100); + dynamicTests['in-viewport-b-neg'] = bind($.inViewport, $, b, -100); + _.assign(resizeTests, dynamicTests); + _.assign(scrollTests, dynamicTests); + _.every([readyTests, resizeTests, scrollTests], update); + $(window).on('resize', bind(update, null, resizeTests)).on('scroll', bind(update, null, scrollTests)); + }); }(this, window, document));
\ No newline at end of file |