Permalink
Browse files

remove jquery

  • Loading branch information...
1 parent 86f0c59 commit 143e52be03492e2a76f84cde8a0c8d7fc82be392 leemachin committed Nov 24, 2012
Showing with 47 additions and 10 deletions.
  1. +21 −7 say-cheese.js
  2. +26 −3 test/say-cheese-test.js
View
@@ -40,23 +40,37 @@ var SayCheese = (function($) {
return this;
};
- // todo: remove jquery dependency
SayCheese.prototype.on = function on(evt, handler) {
- return $(this).on(evt, handler);
+ if (this.events.hasOwnProperty(evt) === false) {
+ this.events[evt] = [];
+ }
+
+ this.events[evt].push(handler)
};
SayCheese.prototype.off = function off(evt, handler) {
- return $(this).off(evt, handler);
+ this.events = this.events[evt].filter(function(h) {
+ if (h !== handler) {
+ return h;
+ }
+ });
};
SayCheese.prototype.trigger = function trigger(evt, data) {
- // bubbling up the DOM makes things go a bit crazy. This assumes
- // preventDefault
- return $(this).triggerHandler(evt, data);
+ if (this.events.hasOwnProperty(evt) === false) {
+ return false;
+ }
+
+ this.events[evt].forEach(function(handler) {
+ handler.call(this, data);
+ }.bind(this));
};
SayCheese.prototype.setOptions = function setOptions(options) {
- this.options = $.extend(this.options, options);
+ // just use naïve, shallow cloning
+ for (var opt in options) {
+ this.options[opt] = options[opt];
+ }
}
SayCheese.prototype.getStreamUrl = function getStreamUrl() {
View
@@ -1,5 +1,28 @@
+function equals(obj1, obj2) {
+ for (var prop in obj1) {
+ if (obj1[prop] !== obj2[prop] || obj2.hasOwnProperty(prop) === false) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+test("options are set correctly", function() {
+ var options = { snapshots: false, audio: false },
+ sayCheese = new SayCheese('#camera-test', options);
+
+ ok(equals(sayCheese.options, options), "options correctly set");
+
+ options.audio = true
+ sayCheese.setOptions(options);
+
+ ok(equals(sayCheese.options, options), "options correctly updated");
+});
+
asyncTest("triggers 'start' event when access permitted (click Allow)", function() {
var sayCheese = new SayCheese('#camera-test');
+
sayCheese.on('start', function() {
ok(true, "start event triggered");
start();
@@ -16,7 +39,7 @@ asyncTest("triggers 'snapshot' event when taking a snapshot", function() {
this.takeSnapshot();
});
- sayCheese.on('snapshot', function(evt, snapshot) {
+ sayCheese.on('snapshot', function(snapshot) {
ok(snapshot.tagName === 'CANVAS', "snapshot event triggered");
start();
this.stop();
@@ -62,7 +85,7 @@ asyncTest("triggers 'error' event when not supported", function() {
// simulate the lack of functionality
navigator.getUserMedia = false;
- sayCheese.on('error', function(evt, err) {
+ sayCheese.on('error', function(err) {
navigator.getUserMedia = origGetUserMedia;
ok(err === "NOT_SUPPORTED", "not supported event triggered");
start();
@@ -74,7 +97,7 @@ asyncTest("triggers 'error' event when not supported", function() {
asyncTest("triggers 'error' event when access denied (click Deny)", function() {
var sayCheese = new SayCheese('#camera-test');
- sayCheese.on('error', function(evt, err) {
+ sayCheese.on('error', function(err) {
ok(true, "access denied event triggered");
start();
});

0 comments on commit 143e52b

Please sign in to comment.