-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6249dab
Showing
13 changed files
with
361 additions
and
0 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,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,4 @@ | ||
node_modules | ||
npm-debug.log | ||
.DS_Store | ||
Thumbs.db |
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,4 @@ | ||
node_modules | ||
bower_components | ||
dist | ||
example |
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,23 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"trailing": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"strict": true, | ||
"immed": true, | ||
"expr": true, | ||
"latedef": "nofunc", | ||
"quotmark": "single", | ||
"validthis": true, | ||
"indent": 2, | ||
"node": true, | ||
"browser": 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "bullseye", | ||
"version": "1.0.0", | ||
"description": "Attach elements onto their target", | ||
"main": "dist/bullseye.js", | ||
"homepage": "https://github.com/bevacqua/bullseye", | ||
"authors": [ | ||
"Nicolas Bevacqua <[email protected]>" | ||
], | ||
"license": "MIT" | ||
} |
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,38 @@ | ||
'use strict'; | ||
|
||
var crossvent = require('crossvent'); | ||
var throttle = require('./throttle'); | ||
|
||
function bullseye (el, target, options) { | ||
var o = options || {}; | ||
var destroyed = false; | ||
var throttledPosition = throttle(position, 30); | ||
|
||
position(); | ||
|
||
if (o.tracking !== false) { | ||
crossvent.add(window, 'resize', throttledPosition); | ||
} | ||
|
||
return { | ||
refresh: position, | ||
destroy: destroy | ||
}; | ||
|
||
function position () { | ||
if (destroyed) { | ||
throw new Error('Bullseye can\'t refresh after being destroyed. Create another instance instead.'); | ||
} | ||
var bounds = target.getBoundingClientRect(); | ||
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; | ||
el.style.top = bounds.top + scrollTop + target.offsetHeight + 'px'; | ||
el.style.left = bounds.left + 'px'; | ||
} | ||
|
||
function destroy () { | ||
crossvent.remove(window, 'resize', throttledPosition); | ||
destroyed = true; | ||
} | ||
} | ||
|
||
module.exports = bullseye; |
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,3 @@ | ||
# 1.0.0 IPO | ||
|
||
- Initial Public Release |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2015 Nicolas Bevacqua | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "bullseye", | ||
"version": "1.0.0", | ||
"description": "Attach elements onto their target", | ||
"main": "bullseye.js", | ||
"scripts": { | ||
"scripts": "jshint . && browserify -s bullseye -do dist/bullseye.js bullseye.js && uglifyjs -m -c -o dist/bullseye.min.js dist/bullseye.js", | ||
"build": "npm run scripts", | ||
"deployment": "npm version ${BUMP:-\"patch\"} --no-git-tag-version && git add package.json && git commit -m \"Autogenerated pre-deployment commit\" && bower version ${BUMP:-\"patch\"} && git reset HEAD~2 && git add . && git commit -am \"Release $(cat package.json | jq -r .version)\" && git push --tags && npm publish && git push", | ||
"deploy": "npm run build && npm run deployment" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bevacqua/bullseye.git" | ||
}, | ||
"author": "Nicolas Bevacqua <[email protected]> (http://bevacqua.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/bevacqua/bullseye/issues" | ||
}, | ||
"homepage": "https://github.com/bevacqua/bullseye", | ||
"devDependencies": { | ||
"browserify": "^8.1.0", | ||
"jshint": "^2.5.11", | ||
"uglify-js": "^2.4.16", | ||
"watchify": "^2.2.1" | ||
}, | ||
"dependencies": { | ||
"crossvent": "^1.0.0" | ||
} | ||
} |
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,31 @@ | ||
# bullseye | ||
|
||
> Attach elements onto their target | ||
# Install | ||
|
||
```shell | ||
npm install bullseye --save | ||
``` | ||
|
||
```shell | ||
bower install bullseye --save | ||
``` | ||
|
||
# `bullseye(element, target, options?)` | ||
|
||
Position `element` according to the current position of `target`. If the `tracking` option isn't set to `false`, a listener for window rezize events will make sure `element` stays well-position when the viewport size changes. | ||
|
||
When you call `bullseye(element, target, options?)`, you'll get back a tiny API to interact with the instance. | ||
|
||
### `.refresh()` | ||
|
||
Refreshes position of `element` according to the current position of `target`. | ||
|
||
### `.destroy()` | ||
|
||
Removes the `resize` event listener. Note that further calls to `.refresh` will throw exceptions. | ||
|
||
# License | ||
|
||
MIT |
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,27 @@ | ||
'use strict'; | ||
|
||
function throttle (fn, boundary) { | ||
var last = -Infinity; | ||
var timer; | ||
return function bounced () { | ||
if (timer) { | ||
return; | ||
} | ||
unbound(); | ||
|
||
function unbound () { | ||
clearTimeout(timer); | ||
timer = null; | ||
var next = last + boundary; | ||
var now = Date.now(); | ||
if (now > next) { | ||
last = now; | ||
fn.apply(this, arguments); | ||
} else { | ||
timer = setTimeout(unbound, next - now); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
module.exports = throttle; |