forked from goldledoigt/Ext.ux.CarouselPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExt.ux.CarouselPanel.js
176 lines (149 loc) · 4.32 KB
/
Ext.ux.CarouselPanel.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
** Ext.ux.CarouselPanel.js for Ext.ux.CarouselPanel
**
** Made by goldledoigt
** Contact <[email protected]>
**
** Started on Mon Mar 1 10:47:29 2010 goldledoigt
** Last update Fri Mar 5 01:31:30 2010
**
** DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
** Version 2, December 2004
**
** Copyright (C) 2004 Sam Hocevar <[email protected]>
** Everyone is permitted to copy and distribute verbatim or modified
** copies of this license document, and changing it is allowed as long
** as the name is changed.
**
** DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
** TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
**
** 0. You just DO WHAT THE FUCK YOU WANT TO.
*/
Ext.ns("Ext.ux");
Ext.ux.CarouselPanel = Ext.extend(Ext.util.Observable, {
/**
* Size of each item in the carousel view
*/
itemSize:{width:0, height:0}
/**
* List of items to loop on
*/
,items:[]
/**
* Left and right buttons to slide the carousel view
*/
,buttons:[]
/**
* If set to TRUE the view is never blocked.
* It slides back to the first item after the last item when going to right direction
* It slides forward to the last item after the first item when going to left direction
*/
,enableLoop:false
/**
* Init a repeated task to make move the carousel view automatically
* The task is paused when the cursor is over carousel div
* The task is stopped on any button click
*/
,enableSlideShow:false
/**
* Set a time (in ms) to defer the slideshow frist move
*/
,deferSlideShow:5000
/**
* Allow to display right and left buttons
*/
,enableButtons:true
/**
* Number of items to display together on each move
*/
,itemsPerView:1
/**
* The space between each item of the carousel view
*/
,itemSidesMargin:0
/**
* Hides items labels
*/
,hideLabels:false
,constructor:function(config) {
Ext.apply(this, config);
Ext.ux.CarouselPanel.superclass.constructor.apply(this, arguments);
this.on({render:this.onRender});
},
render:function(el) {
var buttonsWidth = (this.enableButtons) ? this.buttons[0].width + this.buttons[1].width : 0;
this.el = Ext.DomHelper.append(el || Ext.getBody(), {
id:"carousel-panel"
,tag:"div"
,style:"width:"+(buttonsWidth + this.itemSize.width * this.itemsPerView + (this.itemSidesMargin * this.itemsPerView * 2))+"px;"
+ "overflow:hidden;"
+ "margin:0 auto;"
});
this.carousel = new Ext.ux.Carousel({
enableLoop:this.enableSlideShow || this.enableLoop
,items:this.items
,hideLabels:this.hideLabels
,itemsPerView:this.itemsPerView
,itemSize:this.itemSize
,itemSidesMargin:this.itemSidesMargin
});
this.carousel.render(this.el);
if (this.enableButtons) {
var tpl = new Ext.Template(
'<div style="width:{width}px;height:'+this.itemSize.height+'px;'
+ 'float:left;'
+ 'background-position:0 50%;'
+ 'cursor:pointer;'
+ 'background-repeat:no-repeat;'
+ 'background-image:url({image});">'
+ '</div>'
);
this.leftButton = tpl.insertFirst(this.el, this.buttons[0]);
this.rightButton = tpl.append(this.el, this.buttons[1]);
this.setButtonsEvents();
}
Ext.DomHelper.append(this.el, {
id:"carousel-clear",
tag:"div",
style:"clear:both;"
});
this.carousel.on({scope:this, move:this.onMove});
this.fireEvent("render", this);
}
,onRender:function() {
if (this.enableSlideShow) {
(function() {
this.loop = Ext.TaskMgr.start({
run:this.carousel.move
,args:["right"]
,scope:this.carousel
,interval:this.enableSlideShow || 10000
});
}).defer(this.deferSlideShow, this);
}
}
,buttonClick:function(e, el, options, direction) {
if (false !== this.fireEvent("beforemove", this, direction)) {
if (this.loop) {
Ext.TaskMgr.stop(this.loop);
this.loop = false;
}
this.carousel.move(direction);
}
}
,setButtonsEvents:function(direction) {
if (!direction || direction == "left")
Ext.fly(this.leftButton).on({
click:this.buttonClick.createDelegate(this, ["left"], true)
});
if(!direction || direction == "right") {
Ext.fly(this.rightButton).on({
click:this.buttonClick.createDelegate(this, ["right"], true)
});
}
}
,onMove:function(direction) {
this.fireEvent("move", direction);
}
});