|
1 /* |
|
2 |
|
3 Content Timeline 3.0 |
|
4 |
|
5 Date organised content slider. |
|
6 |
|
7 Copyright (c) 2012 Br0 (shindiristudio.com) |
|
8 |
|
9 Project site: http://codecanyon.net/ |
|
10 Project demo: http://shindiristudio.com/timeline |
|
11 |
|
12 */ |
|
13 |
|
14 (function($){ |
|
15 |
|
16 // EVENTS.timeline |
|
17 |
|
18 // init.timeline : triggered when timeline is initialised |
|
19 // scrollStart.timeline : triggered when item move animation starts |
|
20 // scrollEnd.timeline : triggered when item move animation ends |
|
21 // itemOpen.timeline : triggered on click to open item |
|
22 // itemClose.timeline : triggered on click to close item |
|
23 |
|
24 // --------------------------------------------------------- |
|
25 |
|
26 // On KeyPress (left) : trigger $.timeline('left') |
|
27 // On KeyPress (right) : trigger $.timeline('right') |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 |
|
31 // $.timeline(METHODS) |
|
32 |
|
33 // $.timeline('init') : initialises timeline |
|
34 // $.timeline('destroy') : clears timeline data |
|
35 // $.timeline('left') : moves one left by one element |
|
36 // $.timeline('right') : moves right by one element |
|
37 // $.timeline('open', id) : opens element with 'data-id' = id |
|
38 // $.timeline('close', id): closes element with 'data-id' = id |
|
39 // $.timeline('goTo', id) : goes to element width 'data-id' = id |
|
40 |
|
41 |
|
42 var t_methods = { |
|
43 init : function( options ) { |
|
44 |
|
45 // Default settings |
|
46 var settings = $.extend( { |
|
47 'itemClass' : '.item', // class used for timeline items |
|
48 'itemOpenClass' : '.item_open', // class used for item details |
|
49 'openTriggerClass' : '.item', // class of read more element (default uses whole item to trigger open event) |
|
50 'closeText' : 'Close', // text of close button in open item |
|
51 'itemMargin' : 10, // spacing between items |
|
52 'scrollSpeed' : 500, // animation speed |
|
53 'startItem' : 'last', // timeline start item id, 'last' or 'first' can be used insted |
|
54 'easing' : 'easeOutSine', // jquery.easing function for animations, |
|
55 'categories' : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], // categories shown above timeline (months are default) |
|
56 'nuberOfSegments' : [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], // number of elements per category (number of days) |
|
57 'yearsOn' : true, // show years (can be any number you use in data-id (elementNumber/category/yearOrSomeOtherNumber)) |
|
58 'swipeOn' : true, // turn on swipe moving function |
|
59 'hideTimeline' : false, |
|
60 'hideControles' : false |
|
61 }, options); // Setings |
|
62 |
|
63 |
|
64 // main queries |
|
65 var $this = this, |
|
66 $body = $('body'), |
|
67 $items = $this.find(settings.itemClass), |
|
68 $itemsOpen = $this.find(settings.itemOpenClass), |
|
69 itemWidth = $items.first().width(), |
|
70 itemOpenWidth = $itemsOpen.first().width(); |
|
71 |
|
72 // Trigger init event |
|
73 $this.trigger('init.Timeline'); |
|
74 |
|
75 |
|
76 // If no index found |
|
77 var startIndex = $items.length-1; |
|
78 |
|
79 // Find index of start element |
|
80 if(settings.startItem == 'first') |
|
81 { |
|
82 startIndex = 0; |
|
83 } |
|
84 else if (settings.startItem == 'last') |
|
85 { |
|
86 startIndex = $items.length-1; |
|
87 } |
|
88 else { |
|
89 $items.each(function(index){ |
|
90 if(settings.startItem == $(this).attr('data-id')) |
|
91 { |
|
92 startIndex = index; |
|
93 return true; |
|
94 } |
|
95 }); |
|
96 } |
|
97 $items.each(function(index){ |
|
98 $(this).attr('data-count', index); |
|
99 $(this).next(settings.itemOpenClass).attr('data-count', index); |
|
100 if(!$(this).hasClass(settings.openTriggerClass)) { |
|
101 $(this).find(settings.openTriggerClass).attr('data-count', index); |
|
102 } |
|
103 }); |
|
104 |
|
105 // Create wrapper elements, and needed properties |
|
106 $this.append('<div style="clear:both"></div>'); |
|
107 $this.css({width: '100%', 'overflow' : 'hidden', marginLeft : 'auto', marginRight : 'auto','text-align': 'center', height:0}); |
|
108 $this.wrapInner('<div class="timeline_items" />'); |
|
109 $this.find('.timeline_items').css('text-align','left'); |
|
110 if(!settings.hideControles) { |
|
111 $this.append('<div class="t_controles"><div class="t_left"></div><div class="t_right"></div></div>'); |
|
112 } |
|
113 |
|
114 // ZoomOut placement fix |
|
115 $this.wrapInner('<div class="timeline_items_holder" />'); |
|
116 $this.find('.timeline_items_holder').css({width: '300px', marginLeft : 'auto', marginRight : 'auto'}); |
|
117 |
|
118 |
|
119 $items.css({paddingLeft:0 , paddingRight:0, marginLeft: settings.itemMargin/2, marginRight: settings.itemMargin/2, float: 'left', position:'relative'}); |
|
120 |
|
121 $itemsOpen.each(function(){ |
|
122 $(this).prepend('<div class="t_close" data-count="'+$(this).attr('data-count')+'" data-id="'+$(this).attr('data-id')+'">'+settings.closeText+'</div>'); |
|
123 $(this).wrapInner('<div class="'+settings.itemOpenClass.substr(1)+'_cwrapper" />').find('div:first').css({position: 'relative'}); |
|
124 $(this).css({width: 0, padding:0 , margin: 0, float: 'left', display : 'none', position : 'relative', overflow : 'hidden'}); |
|
125 }); |
|
126 |
|
127 |
|
128 // Get new queries |
|
129 var $iholder = $this.find('.timeline_items:first'), |
|
130 $line = $this.find('.t_line_wrapper:first'), |
|
131 margin = 300/2 - (itemWidth + settings.itemMargin)*(1/2 + startIndex) , |
|
132 width = (itemWidth + settings.itemMargin)*$items.length + (itemOpenWidth + settings.itemMargin) + 660 , |
|
133 data = $this.data('timeline'); |
|
134 |
|
135 // Set margin so start element would place in midle of the screen |
|
136 $iholder.css({width: width, marginLeft: margin}); |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 // If the plugin hasn't been initialized yet |
|
142 if (!data){ |
|
143 $this.data('timeline', { |
|
144 currentIndex : startIndex, |
|
145 itemCount : $items.length, |
|
146 margin : margin, |
|
147 itemWidth : itemWidth, |
|
148 itemOpenWidth : itemOpenWidth, |
|
149 lineMargin : 0, |
|
150 lineViewCount : 0, |
|
151 options : settings, |
|
152 items : $items, |
|
153 iholder : $iholder, |
|
154 open : false, |
|
155 noAnimation : false, |
|
156 marginResponse: false, |
|
157 mousedown : false, |
|
158 mousestartpos : 0 |
|
159 }); |
|
160 } |
|
161 if(!settings.hideTimeline) { |
|
162 $this.timeline('createElements'); |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 // Bind keyLeft and KeyRight functions |
|
168 $(document).keydown(function(e){ |
|
169 if (e.keyCode == 37) { |
|
170 $this.timeline('left'); |
|
171 return false; |
|
172 } |
|
173 if (e.keyCode == 39) { |
|
174 $this.timeline('right'); |
|
175 return false; |
|
176 } |
|
177 }); |
|
178 |
|
179 // Respond to window resizing |
|
180 $(window).resize(function() { |
|
181 //var id = $this.find('.active:first').attr('href').substr(1); |
|
182 var data = $this.data('timeline'), |
|
183 id = $items.eq(data.currentIndex).attr('data-id'); |
|
184 |
|
185 itemWidth = $items.first().width(), |
|
186 itemOpenWidth = $itemsOpen.first().find('div:first').width(); |
|
187 |
|
188 data.margin += data.itemCount*(data.itemWidth-itemWidth); |
|
189 data.itemWidth = itemWidth; |
|
190 |
|
191 if(data.open) data.margin += (data.itemOpenWidth-itemOpenWidth)/2; |
|
192 data.itemOpenWidth = itemOpenWidth; |
|
193 |
|
194 |
|
195 if($('body').width() < 767 && data.open && !data.marginResponse) { |
|
196 data.margin -= (itemWidth+settings.itemMargin)/2; |
|
197 data.marginResponse = true; |
|
198 } |
|
199 else if($('body').width() >= 767 && data.marginResponse && data.open) { |
|
200 data.margin += (itemWidth+settings.itemMargin)/2; |
|
201 data.marginResponse = false; |
|
202 } |
|
203 |
|
204 data.noAnimation = true; |
|
205 $this.timeline('goTo', id); |
|
206 }); |
|
207 |
|
208 // Bind left on click |
|
209 $this.find('.t_left').click(function(){ |
|
210 $this.timeline('left'); |
|
211 }); |
|
212 |
|
213 // Bind right on click |
|
214 $this.find('.t_right').click(function(){ |
|
215 $this.timeline('right'); |
|
216 }); |
|
217 |
|
218 // SWIPE bind |
|
219 |
|
220 if(settings.swipeOn) { |
|
221 $items.find('*').each(function(){ |
|
222 $(this).css({'-webkit-touch-callout': 'none', |
|
223 '-webkit-user-select': 'none', |
|
224 '-khtml-user-select': 'none', |
|
225 '-moz-user-select': 'none', |
|
226 '-ms-user-select': 'none', |
|
227 'user-select': 'none'}); |
|
228 }); |
|
229 |
|
230 $this.find(settings.itemClass).mousedown(function(e){ |
|
231 $this.timeline('mouseDown', e.pageX); |
|
232 }); |
|
233 $(document).mouseup(function(e){ |
|
234 var data = $this.data('timeline'); |
|
235 if(data.mousedown) { |
|
236 $this.timeline('mouseUp', e.pageX); |
|
237 } |
|
238 }); |
|
239 } |
|
240 |
|
241 |
|
242 |
|
243 // Bind open on click |
|
244 $this.find(settings.openTriggerClass).click(function(){ |
|
245 $this.timeline('goTo',$(this).attr('data-id'), $(this).attr('data-count'), true); |
|
246 }); |
|
247 |
|
248 // Bind close on click |
|
249 $this.find('.t_close').click(function(){ |
|
250 $this.timeline('close',$(this).attr('data-id'),$(this).attr('data-count')); |
|
251 }); |
|
252 |
|
253 // Show when loaded |
|
254 $this.css({height: 'auto'}).show(); |
|
255 |
|
256 // Reposition nodes due to their width |
|
257 $this.find('.t_line_node').each(function(){ |
|
258 if($(this).width() < 10) $(this).width(12); |
|
259 $(this).css({marginLeft: -$(this).width()/2}); |
|
260 }); |
|
261 return $this; |
|
262 }, |
|
263 |
|
264 // Clear data |
|
265 destroy : function( ) { |
|
266 $(document).unbind('mouseup'); |
|
267 $(window).unbind('resize'); |
|
268 var $this = this, |
|
269 data = $this.data('timeline'); |
|
270 $this.removeData('timeline'); |
|
271 |
|
272 }, |
|
273 |
|
274 mouseDown : function(xpos) { |
|
275 var $this = this, |
|
276 data = $this.data('timeline'), |
|
277 xmargin = 0; |
|
278 data.mousedown = true; |
|
279 data.mousestartpos = xpos; |
|
280 |
|
281 $('body').css('cursor','move'); |
|
282 $(document).mousemove(function(e){ |
|
283 xmargin = data.margin - xpos + e.pageX; |
|
284 data.iholder.css('marginLeft', xmargin + 'px'); |
|
285 }); |
|
286 }, |
|
287 |
|
288 mouseUp : function(xpos) { |
|
289 |
|
290 var $this = this, |
|
291 data = $this.data('timeline'), |
|
292 itemWidth = data.itemWidth + data.options.itemMargin, |
|
293 itemC = data.currentIndex, |
|
294 mod = 0, |
|
295 xmargin = xpos - data.mousestartpos; |
|
296 data.mousedown = false; |
|
297 |
|
298 $(document).unbind('mousemove'); |
|
299 $('body').css('cursor','auto'); |
|
300 |
|
301 itemC -= parseInt(xmargin/itemWidth); |
|
302 mod = xmargin%itemWidth; |
|
303 if (xmargin < 0 && mod < -itemWidth/2) { |
|
304 itemC++; |
|
305 } |
|
306 if (xmargin > 0 && mod > itemWidth/2) { |
|
307 itemC--; |
|
308 } |
|
309 |
|
310 if(itemC < 0) { |
|
311 itemC = 0; |
|
312 } |
|
313 if(itemC >= data.itemCount) { |
|
314 itemC = data.itemCount-1; |
|
315 } |
|
316 |
|
317 $this.timeline('goTo', data.items.eq(itemC).attr('data-id'), data.items.eq(itemC).attr('data-count')); |
|
318 |
|
319 |
|
320 }, |
|
321 |
|
322 open : function (id, data_count) { |
|
323 var $this = this, |
|
324 data = $this.data('timeline'), |
|
325 $items = $this.find(data.options.itemOpenClass), |
|
326 speed = data.options.scrollSpeed, |
|
327 width = data.itemOpenWidth, |
|
328 easing = data.options.easin, |
|
329 itemMargin = data.options.itemMargin; |
|
330 |
|
331 |
|
332 $items.each(function(){ |
|
333 if ($(this).attr('data-id') == id) { |
|
334 if (!data_count || data_count == $(this).attr('data-count')) { |
|
335 |
|
336 // Trigger itemOpen event |
|
337 $this.trigger('itemOpen.Timeline'); |
|
338 |
|
339 // Open content and move margin |
|
340 $(this).stop(true).show().animate({width: width, marginLeft: itemMargin/2, marginRight: itemMargin/2,}, speed, easing); |
|
341 if($('body').width() < 767) { |
|
342 data.margin -= (data.itemWidth+data.options.itemMargin)/2; |
|
343 data.marginResponse = true; |
|
344 } |
|
345 else { |
|
346 data.marginResponse = false; |
|
347 } |
|
348 data.margin -= (width + data.options.itemMargin + data.itemWidth)/2 - data.itemWidth/2; |
|
349 data.iholder.stop(true).animate({marginLeft : data.margin}, speed, easing); |
|
350 data.open = id; |
|
351 } |
|
352 } |
|
353 |
|
354 }); |
|
355 return $this; |
|
356 }, |
|
357 |
|
358 close : function (id, idOpen, dataCountOpen) { |
|
359 var $this = this, |
|
360 data = $this.data('timeline'), |
|
361 $items = $this.find(data.options.itemOpenClass), |
|
362 speed = data.options.scrollSpeed, |
|
363 width = data.itemOpenWidth, |
|
364 easing = data.options.easing; |
|
365 |
|
366 |
|
367 $items.each(function(){ |
|
368 if ($(this).attr('data-id') == id && $(this).is(":visible")) { |
|
369 // Trigger itemOpen event |
|
370 $this.trigger('itemClose.Timeline'); |
|
371 |
|
372 // Close content and move margin |
|
373 $(this).stop(true).animate({width: 0, margin:0}, speed, easing, function(){$(this).hide()}); |
|
374 if (data.marginResponse) { |
|
375 data.margin += (data.itemWidth+data.options.itemMargin)/2; |
|
376 } |
|
377 data.margin += (width + data.options.itemMargin)/2; |
|
378 data.iholder.stop(true).animate({marginLeft : data.margin}, speed, easing); |
|
379 data.open = false; |
|
380 } |
|
381 }); |
|
382 if(idOpen) { |
|
383 $this.timeline('open', idOpen, dataCountOpen); |
|
384 } |
|
385 return $this; |
|
386 }, |
|
387 |
|
388 |
|
389 // Move one step left |
|
390 right : function() { |
|
391 var $this = this, |
|
392 data = $this.data('timeline'), |
|
393 speed = data.options.scrollSpeed, |
|
394 easing = data.options.easing; |
|
395 if (data.currentIndex < data.itemCount-1) |
|
396 { |
|
397 var dataId = data.items.eq(data.currentIndex+1).attr('data-id'); |
|
398 var dataCount = data.items.eq(data.currentIndex+1).attr('data-count'); |
|
399 $this.timeline('goTo', dataId, dataCount); |
|
400 } |
|
401 else |
|
402 { |
|
403 data.iholder.stop(true).animate({marginLeft : data.margin-50}, speed/2, easing).animate({marginLeft : data.margin}, speed/2, easing); |
|
404 } |
|
405 return $this |
|
406 }, |
|
407 |
|
408 // Move one step right |
|
409 left : function( ) { |
|
410 var $this = this, |
|
411 data = $this.data('timeline'), |
|
412 speed = data.options.scrollSpeed, |
|
413 easing = data.options.easing; |
|
414 if (data.currentIndex > 0) |
|
415 { |
|
416 var dataId = data.items.eq(data.currentIndex-1).attr('data-id'); |
|
417 var dataCount = data.items.eq(data.currentIndex-1).attr('data-count'); |
|
418 $this.timeline('goTo', dataId, dataCount); |
|
419 } |
|
420 else |
|
421 { |
|
422 data.iholder.stop(true).animate({marginLeft : data.margin+50}, speed/2, easing).animate({marginLeft : data.margin}, speed/2, easing); |
|
423 } |
|
424 return $this; |
|
425 }, |
|
426 |
|
427 // Go to item |
|
428 goTo : function (id, data_count, openElement) { |
|
429 var $this = this, |
|
430 data = $this.data('timeline'), |
|
431 speed = data.options.scrollSpeed, |
|
432 easing = data.options.easing, |
|
433 $items = data.items, |
|
434 timelineWidth = $this.find('.timeline_line').width(), |
|
435 count = -1, |
|
436 found = false; |
|
437 |
|
438 // Find item index |
|
439 $items.each(function(index){ |
|
440 if(id == $(this).attr('data-id')) |
|
441 { |
|
442 if (!data_count || data_count == $(this).attr('data-count')) |
|
443 { |
|
444 found = true; |
|
445 count = index; |
|
446 return false; |
|
447 } |
|
448 } |
|
449 }); |
|
450 |
|
451 // Move if fount |
|
452 if(found) |
|
453 { |
|
454 // Move lineView to current element |
|
455 var $nodes = $this.find('.t_line_node'); |
|
456 $nodes.removeClass('active'); |
|
457 var $goToNode = $nodes.parent().parent().find('[href="#'+id+'"]').addClass('active'); |
|
458 data.lineMargin = -parseInt($goToNode.parent().parent().attr('data-id'),10)*100; |
|
459 |
|
460 // check if responsive width |
|
461 if($this.find('.t_line_view:first').width() > $this.find('.timeline_line').width()) { |
|
462 data.lineMargin *=2; |
|
463 if ($goToNode.parent().hasClass('right')) data.lineMargin -= 100; |
|
464 } |
|
465 |
|
466 if(data.noAnimation){ |
|
467 data.noAnimation = false; |
|
468 $this.find('.t_line_wrapper').stop(true).css({marginLeft : data.lineMargin+'%'}); |
|
469 } |
|
470 else { |
|
471 $this.find('.t_line_wrapper').stop(true).animate({marginLeft : data.lineMargin+'%'}, speed, easing ); |
|
472 } |
|
473 |
|
474 |
|
475 if(data.open) { |
|
476 $this.timeline('close', data.open, id, data_count); |
|
477 } |
|
478 else if (openElement) { |
|
479 $this.timeline('open', id, data_count); |
|
480 } |
|
481 |
|
482 // Trigger ScrollStart event |
|
483 $this.trigger('scrollStart.Timeline'); |
|
484 |
|
485 // Scroll |
|
486 |
|
487 data.margin += (data.itemWidth + data.options.itemMargin)*(data.currentIndex - count); |
|
488 data.currentIndex = count; |
|
489 |
|
490 var multiply = (parseInt(data.iholder.css('margin-left')) - data.margin)/data.itemWidth; |
|
491 data.iholder.stop(true).animate({marginLeft : data.margin}, speed+(speed/5)*(Math.abs(multiply)-1), easing, function(){ |
|
492 // Trigger ScrollStop event |
|
493 $this.trigger('scrollStop.Timeline'); |
|
494 }); |
|
495 } |
|
496 return $this; |
|
497 }, |
|
498 |
|
499 // move line to the left |
|
500 lineLeft : function() { |
|
501 var $this = this, |
|
502 data = $this.data('timeline'), |
|
503 speed = data.options.scrollSpeed, |
|
504 easing = data.options.easing; |
|
505 if (data.lineMargin != 0 && data.options.categories) { |
|
506 data.lineMargin += 100; |
|
507 $this.find('.t_line_wrapper').stop(true).animate({marginLeft : data.lineMargin+'%'}, speed, easing); |
|
508 } |
|
509 |
|
510 }, |
|
511 |
|
512 // move line to the right |
|
513 lineRight : function() { |
|
514 var $this = this, |
|
515 data = $this.data('timeline'), |
|
516 speed = data.options.scrollSpeed, |
|
517 easing = data.options.easing; |
|
518 if ($this.find('.t_line_view:first').width() > $this.find('.timeline_line').width()) |
|
519 var viewCount = data.lineViewCount*2; |
|
520 else |
|
521 var viewCount = data.lineViewCount; |
|
522 |
|
523 if (data.lineMargin != -(viewCount-1)*100 && data.options.categories) { |
|
524 data.lineMargin -= 100; |
|
525 $this.find('.t_line_wrapper').stop(true).animate({marginLeft : data.lineMargin+'%'}, speed, easing); |
|
526 } |
|
527 |
|
528 }, |
|
529 |
|
530 // Create timeline elements and css dependent properties |
|
531 createElements : function() { |
|
532 var $this = this, |
|
533 data = $this.data('timeline'), |
|
534 $items = data.items; |
|
535 |
|
536 var html = '\n' + |
|
537 ' <div class="timeline_line" style="text-align: left; position:relative; margin-left:auto; margin-right:auto;">\n' + |
|
538 ' </div>\n'; |
|
539 $this.prepend(html); |
|
540 var timelineWidth = $this.find('.timeline_line').width(), |
|
541 cnt = 0, |
|
542 nodes = new Array(), |
|
543 months = [''].concat(data.options.categories); |
|
544 monthsDays = [0].concat(data.options.nuberOfSegments), |
|
545 minM = months.length, |
|
546 minY = 99999, |
|
547 maxM = 0, |
|
548 maxY = 0; |
|
549 if(!data.options.yearsOn) maxY = 99999; |
|
550 |
|
551 // find timeline date range and make node elements |
|
552 $items.each(function(){ |
|
553 var dataId = $(this).attr('data-id'), |
|
554 nodeName = $(this).attr('data-name'), |
|
555 dataDesc = $(this).attr('data-description'), |
|
556 dataArray = dataId.split('/'), |
|
557 d = parseInt(dataArray[0],10), |
|
558 m = (months.indexOf(dataArray[1]) != -1) ? months.indexOf(dataArray[1]) : parseInt(dataArray[1],10), |
|
559 y = parseInt(dataArray[2],10); |
|
560 |
|
561 |
|
562 maxY = Math.max(maxY, y); |
|
563 maxM = Math.max(maxM, m); |
|
564 minY = Math.min(minY, y); |
|
565 minM = Math.min(minM, m); |
|
566 |
|
567 |
|
568 // Store node element |
|
569 nodes[dataId] = '<a href="#'+dataId+'" class="t_line_node'+(cnt == data.currentIndex ? ' active' : '')+'" style="left: '+(100/(data.options.categories ? monthsDays[m] : monthsDays[1]))*d+'%; position:absolute; text-align:center;">'+((typeof nodeName != 'undefined') ? nodeName : d); |
|
570 |
|
571 if(typeof dataDesc != 'undefined') nodes[dataId]+= '<span class="t_node_desc'+( m%2==0 ? ' pos_right': '')+'" style="white-space:nowrap; position:absolute; z-index: 1;">'+dataDesc+'</span>'; |
|
572 |
|
573 nodes[dataId]+='</a>\n'; |
|
574 cnt++; |
|
575 }); |
|
576 |
|
577 // Make wrapper elements |
|
578 html = '\n' + |
|
579 ' <div id="t_line_left" style="position: absolute;"></div><div id="t_line_right" style="position: absolute;"></div>\n' + |
|
580 ' <div class="t_line_holder" style="position:relative; overflow: hidden; width:100%;">\n' + |
|
581 ' <div class="t_line_wrapper" style="white-space:nowrap;">\n'; |
|
582 |
|
583 cnt=0; |
|
584 // Prepare for loop, every view has 2 months, we show both if first has nodes in it |
|
585 if(maxM > 0) { |
|
586 if (minM%2 == 0) minM--; |
|
587 |
|
588 // Set max to be on first next view (the one that is going to stop the loop) |
|
589 if (maxM%2 == 0) { |
|
590 if (maxM == 12) { |
|
591 maxM = 1; maxY++; |
|
592 } |
|
593 else maxM++; |
|
594 } |
|
595 else { |
|
596 maxM +=2; |
|
597 if (maxM == 13) { |
|
598 maxM = 1; maxY++; |
|
599 } |
|
600 } |
|
601 |
|
602 |
|
603 if (!data.options.categories) { |
|
604 html += |
|
605 '<div class="t_line_view" data-id="'+cnt+'" style="position:relative; display:inline-block; width:100%;">\n'+ |
|
606 ' <div class="t_line_m" style="width:100%; border:0; position:absolute; top:0;">\n'; |
|
607 for (var x in nodes) { |
|
608 html += nodes[x]; |
|
609 } |
|
610 html += '</div>\n'+ |
|
611 '</div>'; |
|
612 } |
|
613 else { |
|
614 |
|
615 // Generate months and place nodes |
|
616 while ((minY != maxY && !isNaN(minY) && !isNaN(maxY)) || minM != maxM) { |
|
617 |
|
618 html += |
|
619 '<div class="t_line_view" data-id="'+cnt+'" style="position:relative; display:inline-block;">\n'+ |
|
620 (data.options.yearsOn ? ' <h3 class="t_line_year" style="text-align:center; width:100%">'+minY+'</h3>\n' : '' )+ |
|
621 ' <div class="t_line_m" style="position:absolute; top:0;">\n'+ |
|
622 ' <h4 class="t_line_month" style="position:abolute; width:100% top:0; text-align:center;">'+months[minM]+(data.options.yearsOn ? '<span class="t_line_month_year"> '+(data.options.yearsOn ? minY: '' )+'</span>' : '' )+'</h4>\n'; |
|
623 |
|
624 // Fill with nodes |
|
625 for (x in nodes) { |
|
626 var dataArray = x.split('/'); |
|
627 m = (months.indexOf(dataArray[1]) != -1) ? months.indexOf(dataArray[1]) : parseInt(dataArray[1],10); |
|
628 if(!data.options.yearsOn) y = minY; |
|
629 else y = parseInt(dataArray[2],10); |
|
630 if (m == minM && (y == minY || !data.options.yearsOn)){ |
|
631 html+= nodes[x]; |
|
632 nodes.splice(x,1); |
|
633 } |
|
634 } |
|
635 minM++; |
|
636 html += |
|
637 ' </div>\n'+ |
|
638 ' <div class="t_line_m right" style="position:absolute; top:0;">\n'+ |
|
639 ' <h4 class="t_line_month" style="position:abolute; width:100% top:0; text-align:center;">'+(typeof months[minM] !== 'undefined' ? months[minM] : '')+(data.options.yearsOn ? '<span class="t_line_month_year"> '+(data.options.yearsOn ? minY: '' )+'</span>' : '' )+'</h4>\n'; |
|
640 |
|
641 // Fill with nodes |
|
642 for (x in nodes) { |
|
643 dataArray = x.split('/'); |
|
644 m = (months.indexOf(dataArray[1]) != -1) ? months.indexOf(dataArray[1]) : parseInt(dataArray[1],10); |
|
645 if(!data.options.yearsOn) y = minY; |
|
646 else y = parseInt(dataArray[2],10); |
|
647 |
|
648 if (m == minM && (y == minY || !data.options.yearsOn)){ |
|
649 html+= nodes[x]; |
|
650 nodes.splice(x,1); |
|
651 } |
|
652 } |
|
653 html += |
|
654 ' </div>\n'+ |
|
655 ' <div style="clear:both"></div>\n'+ |
|
656 ' </div>'; |
|
657 |
|
658 if (minM == months.length-1) { minM = 1; minY++;} |
|
659 else { minM++; } |
|
660 |
|
661 cnt++; |
|
662 |
|
663 if(minM == maxM && !data.options.yearsOn) break; |
|
664 |
|
665 } |
|
666 |
|
667 } |
|
668 } |
|
669 |
|
670 |
|
671 html += '\n' + |
|
672 ' <div style="clear:both"></div>\n'+ |
|
673 ' </div>\n'+ |
|
674 ' </div>\n'; |
|
675 |
|
676 // Set number of View elements |
|
677 data.lineViewCount = cnt; |
|
678 // Add generated html and set width & margin for dinamic timeline |
|
679 $this.find('.timeline_line').html(html); |
|
680 $this.find('.t_line_node').each(function(){ |
|
681 var $thisNode = $(this); |
|
682 $(this).find('span').hide(); |
|
683 $(this).hover(function(){ |
|
684 $items.each(function(){ |
|
685 if($(this).attr('data-id') == $thisNode.attr('href').substr(1)) { |
|
686 $(this).addClass('item_node_hover'); |
|
687 } |
|
688 }); |
|
689 $(this).find('span').show(); |
|
690 }, function(){ |
|
691 $(this).find('span').hide(); |
|
692 $('.item_node_hover').removeClass('item_node_hover'); |
|
693 }); |
|
694 |
|
695 //Position lineView to selected item |
|
696 if($(this).hasClass('active')) { |
|
697 data.lineMargin = -parseInt($(this).parent().parent('.t_line_view').attr('data-id'),10)*100; |
|
698 $this.find('.t_line_wrapper').css('margin-left', data.lineMargin+'%'); |
|
699 } |
|
700 // Bind goTo function to click event |
|
701 $(this).click(function(e){ |
|
702 e.preventDefault(); |
|
703 $this.find('.t_line_node').removeClass('active'); |
|
704 $(this).addClass('active'); |
|
705 $this.timeline('goTo', $(this).attr('href').substr(1)); |
|
706 }); |
|
707 }); |
|
708 |
|
709 $this.find('#t_line_left').click(function(){ |
|
710 $this.timeline('lineLeft'); |
|
711 }); |
|
712 |
|
713 $this.find('#t_line_right').click(function(){ |
|
714 $this.timeline('lineRight'); |
|
715 }); |
|
716 |
|
717 } |
|
718 }; |
|
719 |
|
720 // Initiate methods |
|
721 $.fn.timeline = function( method ) { |
|
722 |
|
723 if ( t_methods[method] ) { |
|
724 return t_methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); |
|
725 } else if ( typeof method === 'object' || ! method ) { |
|
726 return t_methods.init.apply( this, arguments ); |
|
727 } else { |
|
728 $.error( 'Method ' + method + ' does not exist on jQuery.timeline' ); |
|
729 } |
|
730 |
|
731 }; |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 })(jQuery); |
|
738 |
|
739 if (!Array.prototype.indexOf) { |
|
740 Array.prototype.indexOf = function(obj, start) { |
|
741 for (var i = (start || 0), j = this.length; i < j; i++) { |
|
742 if (this[i] === obj) { return i; } |
|
743 } |
|
744 return -1; |
|
745 } |
|
746 |
|
747 } |