jquery Timesheet Plugin B1njtimeline

Source: Internet
Author: User
Tags date datetime diff return window

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));


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.