; (function ($, window, document, undefined) { //'use strict'; var pluginname = 'vivatimeline';//plugin名稱 //timeline建構式 var timeline = function (element, opt) { //私有變數 this.target = element; this.carouselinterval; this.checkimgload; this.imgload = false; //初始化 this._init(opt); this._event(); } //importkml2d預設參數 timeline.options = { carousel: true, carouseltime: 10000 } //timeline私有方法 timeline.prototype = { //初始化 _init: function (_opt) { //合併自訂參數與預設參數 var self = this; self.options = $.extend(true, {}, timeline.options, _opt); self.target .find('.events-body') .each(function(){ var rowcount = $(this).find('.row').length; if(rowcount > 1) { var html = "
    "; for(var i = 0; i < rowcount; i++){ html += "
  1. "; } html += "
"; $(this) .siblings('.events-footer') .html(html) .find('li') .first() .addclass('active'); } }); self.target .find('.events-body') .each(function(){ $(this) .find('.row') .first() .show() .siblings() .hide(); }); self.target .find('img').on('load', function(){ self.target .find('.events-body') .each(function(){ var maxheight = 0; $(this) .find('.row') .each(function(){ if($(this).height() > maxheight){ maxheight = $(this).height(); } }); $(this).find('.row').height(maxheight); }); }); }, //綁定事件 _event: function () { var self = this; self.target .find('.events-header') .click(function(){ $(this) .siblings('.events-body').slidetoggle() .end() .siblings('.events-footer').toggle(); }); self.target .find('.events-footer li') .click(function(){ self._carousel($(this)); }); if(self.options.carousel){ self.carouselinterval = setinterval(function(){ self._carousel(); }, self.options.carouseltime); self.target .find('.events') .hover(function(){ clearinterval(self.carouselinterval); self.carouselinterval = null; }, function(){ if(self.carouselinterval == undefined){ self.carouselinterval = setinterval(function(){ self._carousel(); }, self.options.carouseltime); } }); } }, //自動輪播 _carousel: function(_container) { var self = this; if(_container == undefined){ self.target .find('.events-footer .active') .each(function(){ var nexttarget; if($(this).is(':last-child')){ nexttarget = $(this).siblings().first(); } else{ nexttarget = $(this).next(); } self._carousel(nexttarget); }); } else{ var target = _container.data().target; _container .addclass('active') .siblings() .removeclass('active'); _container .closest('.events-footer') .siblings('.events-body') .find('.row') .eq(target).show() .siblings().hide(); } } } //公開方法 $.fn[pluginname] = function (options, args) { var timeline; this.each(function () { timeline = new timeline($(this), options); }); return this; } })(jquery, window, document);