Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bevacqua committed Mar 3, 2015
0 parents commit 6249dab
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
npm-debug.log
.DS_Store
Thumbs.db
4 changes: 4 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
bower_components
dist
example
23 changes: 23 additions & 0 deletions .jshintrc
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
}
11 changes: 11 additions & 0 deletions bower.json
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"
}
38 changes: 38 additions & 0 deletions bullseye.js
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;
3 changes: 3 additions & 0 deletions changelog.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0 IPO

- Initial Public Release
155 changes: 155 additions & 0 deletions dist/bullseye.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/bullseye.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions license
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.
31 changes: 31 additions & 0 deletions package.json
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"
}
}
31 changes: 31 additions & 0 deletions readme.markdown
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
27 changes: 27 additions & 0 deletions throttle.js
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;

0 comments on commit 6249dab

Please sign in to comment.