-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ryanve/next
0.4.0 release
- Loading branch information
Showing
12 changed files
with
141 additions
and
168 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,57 @@ | ||
{ | ||
"name": "res", | ||
"description": "Device resolution detection module", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/ryanve/res", | ||
"license": "MIT", | ||
"author": "Ryan Van Etten", | ||
"keywords": ["device", "resolution", "detection", "ender"], | ||
"keywords": [ | ||
"device", | ||
"screen", | ||
"browser", | ||
"resolution", | ||
"detection", | ||
"responsive", | ||
"retina", | ||
"device-pixel-ratio", | ||
"ender", | ||
"mobile", | ||
"detect", | ||
"dpr" | ||
], | ||
"main": "res.js", | ||
"scripts": { | ||
"pretest": "jshint res.js && jshint test.js", | ||
"test": "node test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ryanve/res.git" | ||
}, | ||
"dependencies": {}, | ||
"optionalDependencies": { | ||
"actual": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"actual": "^0.2.0", | ||
"aok": "^1.9.0", | ||
"universal": "^0.1.0", | ||
"grunt-contrib-uglify": "^0.6.0", | ||
"grunt-contrib-concat": "^0.4.0", | ||
"grunt-contrib-jshint": "^0.10.0" | ||
"jshint": "^2.9.3", | ||
"sos": "0.0.1" | ||
}, | ||
"jshintConfig": { | ||
"asi": true, | ||
"boss": true, | ||
"browser": true, | ||
"debug": false, | ||
"devel": false, | ||
"eqnull": true, | ||
"evil": false, | ||
"expr": true, | ||
"globals": {}, | ||
"jquery": false, | ||
"lastsemic": true, | ||
"latedef": "nofunc", | ||
"laxcomma": true, | ||
"maxcomplexity": 10, | ||
"maxerr": 10, | ||
"maxerr": 4, | ||
"maxlen": 115, | ||
"maxparams": 4, | ||
"node": true, | ||
"sub": true, | ||
"supernew": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true, | ||
"worker": false | ||
"unused": true | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,26 @@ | ||
/*! | ||
* res 0.3.0+201410120233 | ||
* https://github.com/ryanve/res | ||
* MIT License, 2014 Ryan Van Etten | ||
*/ | ||
!function(root, name, make) { | ||
if (typeof module != 'undefined' && module.exports) module.exports = make(require) | ||
else root[name] = make(function(id) { return root[id] }) | ||
}(this, 'res', function(require) { | ||
/** | ||
* @param {string} unit CSS resolution unit like "dppx", "dpi", or "dpcm" | ||
* @return {number} as measured by matchMedia by github.com/ryanve/actual | ||
*/ | ||
function res(unit) { | ||
return require('actual')('resolution', unit.valueOf(), one[unit]) | ||
if (typeof module != 'undefined' && module.exports) module.exports = make() | ||
else root[name] = make() | ||
}(this, 'res', function() { | ||
|
||
var one = {dpi: 96, dpcm: 96 / 2.54} | ||
|
||
function ie() { | ||
return Math.sqrt(screen.deviceXDPI * screen.deviceYDPI) / one.dpi | ||
} | ||
|
||
/** | ||
* @return {number} dppx resolution a.k.a. devicePixelRatio | ||
*/ | ||
function ratio() { | ||
if (typeof window == 'undefined') return 0 | ||
|
||
function dppx() { | ||
// devicePixelRatio: Webkit (Chrome/Android/Safari), Opera (Presto 2.8+), FF 18+ | ||
// logicalXDPI/logicalYDPI: IE6+ (Assuming 1 could suffice here) | ||
return +window.devicePixelRatio || Math.sqrt(screen.deviceXDPI*screen.deviceYDPI)/one.dpi || 0 | ||
return typeof window == 'undefined' ? 0 : +window.devicePixelRatio || ie() || 0 | ||
} | ||
|
||
function dpcm() { | ||
return dppx() * one.dpcm | ||
} | ||
|
||
/** | ||
* @param {string} unit CSS resolution property name from `one` | ||
*/ | ||
function expose(unit) { | ||
var conversion = one[unit]; | ||
res[unit] = 1 == conversion ? ratio : function() { | ||
// convert resolution to `units` units | ||
return ratio()*conversion | ||
} | ||
function dpi() { | ||
return dppx() * one.dpi | ||
} | ||
|
||
var one = {'dppx':1, 'dpi':96, 'dpcm':96/2.54} | ||
expose('dppx') | ||
expose('dpcm') | ||
expose('dpi') | ||
return res | ||
}); | ||
return {'dppx': dppx, 'dpi': dpi, 'dpcm': dpcm} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<title>Tests</title> | ||
<style> | ||
html { font: 1em/1.6 monospace; background: PapayaWhip; color: MediumVioletRed } | ||
body { width: 94%; margin: auto } | ||
</style> | ||
|
||
<h1>Tests</h1> | ||
Open the console | ||
|
||
<script src="res.js"></script> | ||
<script src="node_modules/actual/actual.js"></script> | ||
<script src="node_modules/sos/sos.js"></script> | ||
<script src="node_modules/aok/aok.js"></script> | ||
<script src="test.js"></script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
!function(root, name) { | ||
var common = typeof module != 'undefined' && !!module.exports | ||
var actual = common ? require('actual') : root.actual | ||
var sos = common ? require('sos') : root.sos | ||
var aok = common ? require('aok') : root.aok | ||
var res = common ? require('./') : root[name] | ||
var precision = 1/10 | ||
|
||
function isNatural(n) { | ||
return typeof n == 'number' && n >= 0 && n === n | ||
} | ||
|
||
function isClose(a, b) { | ||
var diff = a - b | ||
if (diff !== diff) throw new Error('cannot compare') | ||
return precision >= Math.abs(diff) | ||
} | ||
|
||
aok.pass(['dpi', 'dpcm', 'dppx'], function(unit) { | ||
sos('group', unit) | ||
var rNum = res[unit]() | ||
var aNum = actual('resolution', unit) | ||
aok(unit + ' return', isNatural(rNum)) | ||
if (rNum && aNum) aok(unit + ' accuracy', isClose(rNum, aNum)) | ||
sos.info(unit, rNum, 'res') | ||
sos.info(unit, aNum, 'actual') | ||
sos('groupEnd') | ||
}) | ||
|
||
sos('group', 'unit conversion') | ||
aok('dppx to dpi', isClose(96*res.dppx(), res.dpi())) | ||
aok('dpcm to dpi', isClose(2.54*res.dpcm(), res.dpi())) | ||
sos('groupEnd') | ||
|
||
sos.info('All tests passed :)') | ||
}(this, 'res'); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.