UNPKG

persiandate-picker

Version:
271 lines (226 loc) 8.82 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: yearpicker.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: yearpicker.js</h1> <section> <article> <pre class="prettyprint source"><code>'use strict'; /** * @desc Instantiate in {@link ClassDatepicker} * @class ClassYearPicker * @instance * @type {{cssClass: {selectedYear: string, yearItem: string}, events: {select: select}, _updateNavigator: _updateNavigator, hide: hide, show: show, next: next, prev: prev, selectYear: selectYear, updateView: updateView, _render: _render, init: init}} */ var ClassYearPicker = { /** * cssClass */ cssClass: { selectedYear: "selected", yearItem: "year-item", disbaleItem: "year-item-disable" }, /** * events */ events: { select: function () { } }, /** * * @private */ _updateNavigator: function () { var self = this; var year = self.datepicker.state.view.year; self.datepicker.updateNavigator(self.titleFormatter(year)); return this; }, /** * @public * @returns {Class_YearPicker} */ hide: function () { this.container.hide(); return this; }, /** * @public * @returns {Class_YearPicker} */ show: function () { this.container.show(); this.updateView(); return this; }, /** * @public * @returns {Class_YearPicker} */ next: function () { var self = this; self.datepicker.state.view.year += 12; self._render().updateView(); return this; }, /** * @public * @returns {Class_YearPicker} */ prev: function () { var self = this; self.datepicker.state.view.year -= 12; self._render().updateView(); return this; }, /** * @public */ selectYear: function () { this.updateView(); }, /** * @public * @returns {Class_YearPicker} */ updateView: function () { var self = this; self._render(); self.container.children("." + self.cssClass.yearItem).each(function () { $(this).removeClass(self.cssClass.selectedYear); if ($(this).data().year === self.datepicker.state.selected.year) { $(this).addClass(self.cssClass.selectedYear); } }); self._updateNavigator(); return this; }, /** * * @param y * @returns {boolean} * @private */ _checkYearAccess: function (y) { if (this.datepicker.state._filetredDate) { var startYear = this.datepicker.state.filterDate.start.year; var endYear = this.datepicker.state.filterDate.end.year; if (startYear &lt;= y &amp; y &lt;= endYear) { return true; } else { return false; } }else { return this.datepicker.checkYear(y); } }, /** * * @returns {ClassMonthPicker} * @private */ _attachEvents: function () { var self = this; if (this.scrollEnabled) { $(this.container).mousewheel(function (event) { if (event.deltaY > 0) { self.next(); } else { self.prev(); } }); $(this.container).bind('mousewheel DOMMouseScroll', function (e) { var scrollTo = null; if (e.type == 'mousewheel') { scrollTo = (e.originalEvent.wheelDelta * -1); } else if (e.type == 'DOMMouseScroll') { scrollTo = 40 * e.originalEvent.detail; } if (scrollTo) { e.preventDefault(); $(this).scrollTop(scrollTo + $(this).scrollTop()); } }); } return this; }, /** * * @returns {Class_YearPicker} * @private */ _render: function () { var self = this; var yearItem , year = self.datepicker.state.view.year , remaining = parseInt(year / 12) * 12; self.container.children("." + self.cssClass.yearItem).remove(); var i; for (i in range(12)) { yearItem = $("&lt;div/>") .addClass(self.cssClass.yearItem) .data({year: (remaining + parseInt(i))}) .text(self.datepicker._formatDigit(remaining + parseInt(i))) .appendTo(self.container); if (year === remaining + parseInt(i)) { yearItem.addClass(self.cssClass.selectedYear); } if (self._checkYearAccess(remaining + parseInt(i))) { yearItem.click(function () { var y = $(this).data().year; self.datepicker.selectYear(parseInt(y)); self.onSelect(y); return false; }); } else { yearItem.addClass(self.cssClass.disbaleItem); yearItem.click(function () { return false; }); } } return this; }, /** * @private */ init: function () { this._render(); this._attachEvents(); return this; } }; var YearPicker = function (options, container) { return inherit(this, [ClassSprite, ClassYearPicker, options, { container: container }]); }; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ClassBase.html">ClassBase</a></li><li><a href="ClassDatepicker.html">ClassDatepicker</a></li><li><a href="ClassDatepicker.ClassCompat.html">ClassCompat</a></li><li><a href="ClassDatepicker.ClassConfig.html">ClassConfig</a></li><li><a href="ClassDatepicker.ViewsDatePicker.html">ViewsDatePicker</a></li><li><a href="ClassDatepickerState.html">ClassDatepickerState</a></li><li><a href="ClassDayPicker.html">ClassDayPicker</a></li><li><a href="ClassDayPicker.ClassMonthGrid.html">ClassMonthGrid</a></li><li><a href="ClassMonthGrid.ViewsMonthGrid.html">ViewsMonthGrid</a></li><li><a href="ClassMonthPicker.html">ClassMonthPicker</a></li><li><a href="ClassNavigator.html">ClassNavigator</a></li><li><a href="ClassSprite.html">ClassSprite</a></li><li><a href="ClassTimePicker.html">ClassTimePicker</a></li><li><a href="ClassToolbox.html">ClassToolbox</a></li><li><a href="ClassYearPicker.html">ClassYearPicker</a></li><li><a href="TEMPLATE.html">TEMPLATE</a></li></ul><h3>Events</h3><ul><li><a href="ClassDatepicker.ClassConfig.html#.event:onHide">onHide</a></li><li><a href="ClassDatepicker.ClassConfig.html#.event:onSelect">onSelect</a></li><li><a href="ClassDatepicker.ClassConfig.html#.event:onShow">onShow</a></li><li><a href="ClassDatepicker.ClassConfig.html#.navigator#.event:onNext">onNext</a></li><li><a href="ClassDatepicker.ClassConfig.html#.navigator#.event:onPrev">onPrev</a></li><li><a href="ClassDatepicker.ClassConfig.html#.navigator#.event:onSwitch">onSwitch</a></li><li><a href="ClassDatepicker.html#.event:selectDate">selectDate</a></li><li><a href="ClassDatepicker.html#.event:selectDateTime">selectDateTime</a></li><li><a href="ClassDatepicker.html#.event:selectTime">selectTime</a></li></ul><h3>Global</h3><ul><li><a href="global.html#ClassDateRange">ClassDateRange</a></li><li><a href="global.html#delay">delay</a></li><li><a href="global.html#inherit">inherit</a></li><li><a href="global.html#log">log</a></li><li><a href="global.html#range">range</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sun Aug 07 2016 12:06:04 GMT+0430 (Iran Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>