This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
/
lectric.js
91 lines (73 loc) · 2.25 KB
/
lectric.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
$(function() {
var slider = new Lectric();
slider.init('#slider', {next: '.next', previous: '.previous'});
test("setup", function() {
expect(1);
ok(window.Lectric, 'global Lectric object is created');
});
test("structure", function() {
expect(6);
equals(slider.itemWidth(), 530, "report the width of each individual item");
equals(slider.itemCount(), 4, "report the number of pages");
equals(slider.element.parent().css('position'), 'relative', "relative positioning set to container");
equals(slider.element.css('position'), 'relative', "relative positioning set to items container");
equals(slider.element.css('left'), '0px', "assigns an initial value to left");
ok(slider.element.parent().hasClass('lectric-slider'), "has the lectric-slider class assigned to the container");
});
test("movement", function() {
expect(3);
slider.subscribe('animationEnd', function() {
start();
});
equals(slider.page(), 0, "start on item 0");
slider.to(1);
stop();
equals(slider.page(), 1, "move to item 1");
slider.toItem($('#slider .item').eq(3));
stop();
equals(slider.page(), 3, "move to item 3");
});
test("subscribing to hooks", function() {
expect(1);
var handler = slider.subscribe('hello', function(s, e) {
equals(e.type, 'hello');
start();
});
slider.element.trigger('hello.lectric');
stop();
slider.unsubscribe('hello', handler);
});
test("unsubscribing from hooks", function() {
expect(1);
var counter = 0;
var handler = slider.subscribe('hello', function(s, e) {
counter++;
start();
});
slider.element.trigger('hello.lectric');
stop();
slider.unsubscribe('hello', handler);
slider.element.trigger('hello.lectric');
equals(counter, 1);
});
test("next button", function() {
expect(1);
var click = function(e) {
equals(e.type, 'click');
start();
};
$('.next').bind('click', click);
$('.next').trigger('click');
stop();
});
test("previous button", function() {
expect(1);
var click = function(e) {
equals(e.type, 'click');
start();
};
$('.previous').bind('click', click);
$('.previous').trigger('click');
stop();
});
});