3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
17 Ext.ux.Carousel = Ext.extend(Ext.util.Observable, {
19 transitionDuration: 1,
20 transitionType: 'carousel',
21 transitionEasing: 'easeOut',
25 showPlayButton: false,
26 pauseOnNavigate: false,
29 navigationOnHover: false,
30 hideNavigation: false,
34 constructor: function(elId, config) {
35 config = config || {};
36 Ext.apply(this, config);
38 Ext.ux.Carousel.superclass.constructor.call(this, config);
52 this.el = Ext.get(elId);
53 this.slides = this.els = [];
55 if(this.autoPlay || this.showPlayButton) {
59 if(this.autoPlay && typeof config.showPlayButton === 'undefined') {
60 this.showPlayButton = true;
66 if(this.carouselSize > 0) {
71 initMarkup: function() {
72 var dh = Ext.DomHelper;
74 this.carouselSize = 0;
75 var items = this.el.select(this.itemSelector);
76 this.els.container = dh.append(this.el, {cls: 'ux-carousel-container'}, true);
77 this.els.slidesWrap = dh.append(this.els.container, {cls: 'ux-carousel-slides-wrap'}, true);
79 this.els.navigation = dh.append(this.els.container, {cls: 'ux-carousel-nav'}, true).hide();
80 this.els.caption = dh.append(this.els.navigation, {tag: 'h2', cls: 'ux-carousel-caption'}, true);
81 this.els.navNext = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-next'}, true);
82 if(this.showPlayButton) {
83 this.els.navPlay = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-play'}, true)
85 this.els.navPrev = dh.append(this.els.navigation, {tag: 'a', href: '#', cls: 'ux-carousel-nav-prev'}, true);
87 // set the dimensions of the container
88 this.slideWidth = this.width || this.el.getWidth(true);
89 this.slideHeight = this.height || this.el.getHeight(true);
90 this.els.container.setStyle({
91 width: this.slideWidth + 'px',
92 height: this.slideHeight + 'px'
95 this.els.caption.setWidth((this.slideWidth - (this.els.navNext.getWidth()*2) - (this.showPlayButton ? this.els.navPlay.getWidth() : 0) - 20) + 'px')
97 items.appendTo(this.els.slidesWrap).each(function(item) {
98 item = item.wrap({cls: 'ux-carousel-slide'});
99 this.slides.push(item);
100 item.setWidth(this.slideWidth + 'px').setHeight(this.slideHeight + 'px');
102 this.carouselSize = this.slides.length;
103 if(this.navigationOnHover) {
104 this.els.navigation.setStyle('top', (-1*this.els.navigation.getHeight()) + 'px');
109 initEvents: function() {
110 this.els.navPrev.on('click', function(ev) {
112 var target = ev.getTarget();
114 if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
118 this.els.navNext.on('click', function(ev) {
120 var target = ev.getTarget();
122 if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
126 if(this.showPlayButton) {
127 this.els.navPlay.on('click', function(ev){
129 ev.getTarget().blur();
139 if(this.freezeOnHover) {
140 this.els.container.on('mouseenter', function(){
142 this.fireEvent('freeze', this.slides[this.activeSlide]);
143 Ext.TaskMgr.stop(this.playTask);
146 this.els.container.on('mouseleave', function(){
148 this.fireEvent('unfreeze', this.slides[this.activeSlide]);
149 Ext.TaskMgr.start(this.playTask);
151 }, this, {buffer: (this.interval/2)*1000});
154 if(this.navigationOnHover) {
155 this.els.container.on('mouseenter', function(){
156 if(!this.navigationShown) {
157 this.navigationShown = true;
158 this.els.navigation.stopFx(false).shift({
159 y: this.els.container.getY(),
160 duration: this.transitionDuration
165 this.els.container.on('mouseleave', function(){
166 if(this.navigationShown) {
167 this.navigationShown = false;
168 this.els.navigation.stopFx(false).shift({
169 y: this.els.navigation.getHeight() - this.els.container.getY(),
170 duration: this.transitionDuration
176 if(this.interval && this.autoPlay) {
182 if (this.fireEvent('beforeprev') === false) {
185 if(this.pauseOnNavigate) {
188 this.setSlide(this.activeSlide - 1);
190 this.fireEvent('prev', this.activeSlide);
195 if(this.fireEvent('beforenext') === false) {
198 if(this.pauseOnNavigate) {
201 this.setSlide(this.activeSlide + 1);
203 this.fireEvent('next', this.activeSlide);
209 this.playTask = this.playTask || {
212 this.setSlide(this.activeSlide+1);
214 interval: this.interval*1000,
218 this.playTaskBuffer = this.playTaskBuffer || new Ext.util.DelayedTask(function() {
219 Ext.TaskMgr.start(this.playTask);
222 this.playTaskBuffer.delay(this.interval*1000);
224 if(this.showPlayButton) {
225 this.els.navPlay.addClass('ux-carousel-playing');
227 this.fireEvent('play');
234 Ext.TaskMgr.stop(this.playTask);
235 this.playTaskBuffer.cancel();
236 this.playing = false;
237 if(this.showPlayButton) {
238 this.els.navPlay.removeClass('ux-carousel-playing');
240 this.fireEvent('pause');
246 this.els.slidesWrap.update('');
248 this.carouselSize = 0;
253 add: function(el, refresh) {
254 var item = Ext.fly(el).appendTo(this.els.slidesWrap).wrap({cls: 'ux-carousel-slide'});
255 item.setWidth(this.slideWidth + 'px').setHeight(this.slideHeight + 'px');
256 this.slides.push(item);
263 refresh: function() {
264 this.carouselSize = this.slides.length;
265 this.els.slidesWrap.setWidth((this.slideWidth * this.carouselSize) + 'px');
266 if(this.carouselSize > 0) {
267 if(!this.hideNavigation) this.els.navigation.show();
268 this.activeSlide = 0;
269 this.setSlide(0, true);
274 setSlide: function(index, initial) {
275 if(!this.wrap && !this.slides[index]) {
280 index = this.carouselSize-1;
282 else if(index > this.carouselSize-1) {
286 if(!this.slides[index]) {
290 this.els.caption.update(this.slides[index].child(':first-child', true).title || '');
291 var offset = index * this.slideWidth;
293 switch (this.transitionType) {
295 this.slides[index].setOpacity(0);
296 this.slides[this.activeSlide].stopFx(false).fadeOut({
297 duration: this.transitionDuration / 2,
298 callback: function(){
299 this.els.slidesWrap.setStyle('left', (-1 * offset) + 'px');
300 this.slides[this.activeSlide].setOpacity(1);
301 this.slides[index].fadeIn({
302 duration: this.transitionDuration / 2
310 var xNew = (-1 * offset) + this.els.container.getX();
311 this.els.slidesWrap.stopFx(false);
312 this.els.slidesWrap.shift({
313 duration: this.transitionDuration,
315 easing: this.transitionEasing
321 this.els.slidesWrap.setStyle('left', '0');
324 this.activeSlide = index;
326 this.fireEvent('change', this.slides[index], index);
329 updateNav: function() {
330 this.els.navPrev.removeClass('ux-carousel-nav-disabled');
331 this.els.navNext.removeClass('ux-carousel-nav-disabled');
333 if(this.activeSlide === 0) {
334 this.els.navPrev.addClass('ux-carousel-nav-disabled');
336 if(this.activeSlide === this.carouselSize-1) {
337 this.els.navNext.addClass('ux-carousel-nav-disabled');