gino-news  2.1.0
Modulo News per gino CMS
news.js
Go to the documentation of this file.
1 
24 var NewSlider = new Class({
25 
26  Implements: [Options],
27  options: {
28  auto_start: false,
29  auto_interval: 5000
30  },
31  initialize: function(wrapper, ctrl_begin, options) {
32  this.setOptions(options);
33  this.wrapper = $(wrapper);
34  this.current = 0;
35  this.slides = this.wrapper.getChildren();
36  this.slides[this.current].addClass('active');
37  this.ctrls = $$('div[id^=' + ctrl_begin + ']');
38  this.ctrls[this.current].addClass('on');
39  if(this.options.auto_start) {
40  this.timeout = setTimeout(this.autoSet.bind(this), this.options.auto_interval);
41  }
42  // if true does nothing when clicking a controller
43  this.idle = false;
44  },
45  set: function(index) {
46 
47  if(this.options.auto_start) {
48  clearTimeout(this.timeout);
49  }
50 
51  if(!this.idle) {
52 
53  // content fade
54  var myfx = new Fx.Tween(this.slides[this.current], {'property': 'opacity'});
55  current_zindex = this.slides[this.current].getStyle('z-index');
56  this.slides[this.current].setStyle('z-index', current_zindex.toInt() + 1);
57  this.slides[index].setStyle('z-index', current_zindex);
58 
59  myfx.start(1,0).chain(function() {
60  if(this.slides.length > 1) {
61  this.slides[this.current].setStyle('z-index', current_zindex.toInt() - 1);
62  }
63  myfx.set(1);
64  this.slides[this.current].removeClass('active');
65  this.slides[index].addClass('active');
66  this.current = index;
67  this.idle = false;
68  }.bind(this));
69 
70  // controllers animation
71  var current = this.current;
72  var next = current;
73  var i = 0;
74  // chain, loop over every intermediate state
75  while(i < Math.abs(index - next)) {
76  var prev = next;
77  next = index > current ? next + 1 : next - 1;
78  var self = this;
79  // closure to pass prev and next by value
80  (function(c, n) {
81  setTimeout(function() { self.setCtrl(n, c) }, 100 * (Math.abs(n-current) - 1));
82  })(prev, next)
83  }
84  }
85 
86  if(this.options.auto_start) {
87  this.timeout = setTimeout(this.autoSet.bind(this), this.options.auto_interval);
88  }
89 
90  },
91  setCtrl: function(next, current) {
92 
93  // current transition, fwd or rwd
94  this.ctrls[current].removeClass('on');
95  this.ctrls[current].addClass(next > current ? 'fwd' : 'rwd');
96 
97  // next transition
98  this.ctrls[next].addClass('on');
99 
100  // prepare all controllers for the next transition
101  for(var i = next + 1; i < this.ctrls.length; i++) {
102  this.ctrls[i].removeClass('fwd');
103  this.ctrls[i].addClass('rwd');
104  }
105  for(var i = next - 1; i >= 0; i--) {
106  this.ctrls[i].removeClass('rwd');
107  this.ctrls[i].addClass('fwd');
108  }
109 
110  // avoid click actions till the chain as finished
111  if(next == this.current) {
112  this.idle = false;
113  }
114  else {
115  this.idle = true;
116  }
117 
118  },
119  autoSet: function() {
120  if(this.current >= this.slides.length - 1) {
121  var index = 0;
122  }
123  else {
124  var index = this.current + 1;
125  }
126  this.set(index);
127  }
128 
129 });
var NewSlider
Costruttore della classe Slider utilizzata dalla vista showcase.
Definition: news.js:24