Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Created August 13, 2014 15:05
Show Gist options
  • Save cirocosta/f41bcbea972002bf90de to your computer and use it in GitHub Desktop.
Save cirocosta/f41bcbea972002bf90de to your computer and use it in GitHub Desktop.
Tracking.js with umd
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Teste</title>
</head>
<body>
<h1>ashuhas</h1>
<script src="tracking.js"></script>
<script src="ObjectTracker.js"></script>
<script>
var tracker = new tracking.ObjectTracker(['face', 'eye', 'mouth']);
tracking.track('#img', tracker);
</script>
</body>
</html>
/**
* Node Only (NPM's 'main')
*
* We export ObjectTracker (instead of
* 'tracking') because the 'tracking' object
* is being mutated. As we want to expose its
* full functionality we must expose when the
* mutation finishes.
*/
module.exports = require('./ObjectTracker');
// it'd be require('tracking.js') -- exposed by
// npm's main field
var tracking = require('./index');
var tracker = new tracking.ObjectTracker(['face', 'eye', 'mouth']);
tracking.track('#img', tracker);
(function (root, factory) {
if (typeof exports === 'object')
module.exports = factory(require('./tracking'));
else
root.tracking = factory(root.tracking);
}(this, function (tracking) {
function ObjectTracker (list) {
this.list = list;
}
ObjectTracker.prototype.show = function() {
var scope = this;
setTimeout(function () {
console.log("tracking: %s", scope.list.join());
}, 1000);
};
tracking.ObjectTracker = ObjectTracker;
return tracking;
}));
(function (root, factory) {
if (typeof exports === 'object')
module.exports = factory({}, {});
else
root.tracking = factory(window, navigator);
}(this, function (window, navigator) {
var tracking = {};
tracking.track = function (selector, tracker) {
console.log("Using seelector %s with tracker", selector);
tracker.show();
};
return tracking;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment