Created
August 13, 2014 15:05
-
-
Save cirocosta/f41bcbea972002bf90de to your computer and use it in GitHub Desktop.
Tracking.js with umd
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
<!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> |
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
/** | |
* 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'); |
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
// 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); |
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
(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; | |
})); |
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
(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