Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
changed subscribe to on and unsubscribe to off
Browse files Browse the repository at this point in the history
  • Loading branch information
stutrek committed Jan 24, 2013
1 parent cc4898b commit 9f32c1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions js/lectric.js 100644 → 100755
Expand Up @@ -122,10 +122,10 @@
$.each(this.opts.hooks, function(name, fn) {
if ($.isArray(fn)) {
$.each(fn, function(fn2) {
self.subscribe(name, fn2);
self.on(name, fn2);
});
} else {
self.subscribe(name, fn);
self.on(name, fn);
}
});

Expand Down Expand Up @@ -167,7 +167,7 @@
// fn - The Function callback to execute when the hook is triggered.
//
// Returns the Function callback that was bound to the hook.
BaseSlider.prototype.subscribe = function(name, fn) {
BaseSlider.prototype.on = function(name, fn) {
var self = this;
var callback = function(e) {
if (e.target == self.element[0]) {
Expand All @@ -179,7 +179,7 @@
return callback;
};
BaseSlider.prototype.bind = function(name, fn) {
this.subscribe(name, fn);
this.on(name, fn);
};

// Unsubscribe a callback function from a hook or unsubscribe all callbacks from a hook.
Expand All @@ -188,15 +188,15 @@
// fn - The Function handler to unbind from the element.
//
// Returns nothing.
BaseSlider.prototype.unsubscribe = function(name, fn) {
BaseSlider.prototype.off = function(name, fn) {
if (typeof fn !== undefined && $.isFunction(fn)) {
this.element.unbind(name + '.lectric', fn);
} else {
this.element.unbind(name + '.lectric');
}
};
BaseSlider.prototype.unbind = function(name, fn) {
this.unsubscribe(name, fn);
this.off(name, fn);
};

// Retrieve the current page of the slider.
Expand Down
10 changes: 5 additions & 5 deletions tests/lectric.js 100644 → 100755
Expand Up @@ -22,7 +22,7 @@ $(function() {
test("movement", function() {
expect(3);

slider.subscribe('animationEnd', function() {
slider.on('animationEnd', function() {
start();
});
equals(slider.page(), 0, "start on item 0");
Expand All @@ -39,28 +39,28 @@ $(function() {
test("subscribing to hooks", function() {
expect(1);

var handler = slider.subscribe('hello', function(s, e) {
var handler = slider.on('hello', function(s, e) {
equals(e.type, 'hello');
start();
});
slider.element.trigger('hello.lectric');
stop();
slider.unsubscribe('hello', handler);
slider.off('hello', handler);
});

test("unsubscribing from hooks", function() {
expect(1);

var counter = 0;
var handler = slider.subscribe('hello', function(s, e) {
var handler = slider.on('hello', function(s, e) {
counter++;
start();
});

slider.element.trigger('hello.lectric');
stop();

slider.unsubscribe('hello', handler);
slider.off('hello', handler);
slider.element.trigger('hello.lectric');
equals(counter, 1);
});
Expand Down

0 comments on commit 9f32c1c

Please sign in to comment.