JQuery Timesheet Plug-in B1njtimeline
;(function ($, window, undefined) {var pluginname = ' B1njtimeline ', document = Window.document, D
Efaults = {height:400, margetop:40};
Pugin constructor function Plugin (element, options) {this.element = element;
this. $element = null;
This.options = $.extend ({}, defaults, options);
This._datedebut = false;
This._datefin = false;
This._duree = false;
This._name = Pluginname;
This.init ();
} Plugin.prototype.init = function () {var self = this;
$ (this.element). addclass (' events '). Wrap (' <div class= ' b1njtimeline "/> ');
this. $element = $ (this.element). parent ();
this. $element. css (' height ', this.options.height); Recherche date la plus ancienne et la plus r cente this._datedebut = new Moment (this. $element. Find (' Li:first ti
Me '). attr (' datetime '), ' yyyy-mm-dd '); This._datefin = new moment (this. $element. Find (' Li:last time '). attr (' datetime '), ' yyyy-mm-dd ');
This._duree = This._datefin.diff (this._datedebut);
Placement de l ' Mao venement this. $element. Find (' Li '). each (function () {$li = $ (this);
$li. Wrapinner (' <div class= "event"/> ");
var date = new Moment ($li. Find ("Time"). attr (' datetime '), ' yyyy-mm-dd ') $li. CSS (' top ', self._gettop (date));
$li. On (' click ', Function (e) {self.open (this);
});
});
Mise en place des dates gradu Mao es var date = this._datedebut.year ();
var num_years = This._datefin.diff (this._datedebut, ' years ');
var tranche = 1;
if (Num_years >) {tranche = 100;
else if (Num_years >) {tranche = 50;
else if (Num_years > MB) {tranche = 25;
else if (Num_years >) {tranche = 10; } elsE if (Num_years >) {tranche = 5;
else if (Num_years >) {tranche = 2;
Date = date + 1;
while (date% tranche!= 0) {date = date + 1;
var html_dates = ' <ol class= ' timeline_dates ' > '; for (var i = date; I <= this._datefin.year (), i = i + tranche) {var top = Self._gettop (New Moment (I.tostri
Ng (), ' YYYY '));
Html_dates + + ' <li style= ' top: ' + top + ' px ' ><div> ' + i + ' </div></li> ';
} html_dates + = ' <ol> ';
this. $element. Find (' ol '). After (html_dates);
}; Plugin.prototype._gettop = function (date) {var top = Date.diff (this._datedebut) * This.options.height/this._du
Ree
top = Math.Abs (parseint (top));
top = top + This.options.margeTop;
return top;
};
Plugin.prototype.open = function (desc) {var $evenement 2 = $ (DESC). Find ('. event '); if ($evenement 2.hasClass (' open ')) {$evenement 2.removeClass (' open ');
} else {this. $element. Find ('. Event '). Removeclass (' open ');
$evenement 2.addClass (' open ');
}
}; Adding Plugin to the Jquery.fn object $.fn[pluginname] = function (options) {return This.each (function () {if (!$.data, ' plugin_ ' + pluginname)) {$.data (this, ' plugin_ ' + pluginname, new plugin
(This, options));
}
});
}; } (jQuery, window));