-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw2.js
executable file
·44 lines (30 loc) · 1.13 KB
/
hw2.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
var Accordion = function(options) { //pas an object literal when declare accordion
this.$el = $(options.sel); //means is a jquery element!!
this.hideContent(); //this represents that instance of accordion
this.bind();
};
Accordion.prototype.replaceLabels = function(newHead) {
this.$el.find('.label').text(newHead);
};
Accordion.prototype.hideContent = function() {
this.$el.find('.content').slideUp().eq(0).slideDown(0).prev().addClass('active');
};
Accordion.prototype.expandAll = function() {
this.$el.find('.content').show();
};
Accordion.prototype.activateAllLabels= function() {
var that = this;
this.$el.on('click', function() {
that.$el.find('.label').addClass('active');
});
};
Accordion.prototype.bind= function() {
var that = this; //saving accordion object so can access other parts of accordion in event listiner
this.$el.on('click', '.label', function() {
//console.log(this, that);
that.$el.find('.content').slideUp(300);
that.$el.find('.label').removeClass('active');
$(this).next().slideDown(300); // wtv we click on
$(this).addClass('active');
});
};