persiandate-picker
Version:
Jalali Calendar Date picker
274 lines (229 loc) • 9.22 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: monthpicker.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: monthpicker.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>'use strict';
/**
* @desc Instantiate in {@link ClassDatepicker}
* @class ClassMonthPicker
* @type {{cssClass: {selectedMonth: string, monthItem: string}, monthRange: (ClassDateRange.monthRange|*), _updateNavigator: _updateNavigator, hide: hide, show: show, selectMonth: selectMonth, defineSelectedMonth: defineSelectedMonth, next: next, prev: prev, updateView: updateView, _render: _render, init: init}}
*/
var ClassMonthPicker = {
/**
* @desc cssClass
*/
cssClass: {
selectedMonth: "selected",
monthItem: "month-item",
disbaleItem: "month-item-disable"
},
/**
* @desc monthRange
*/
monthRange: ClassDateRange.monthRange,
/**
* @desc _updateNavigator
* @private
*/
_updateNavigator: function () {
var self = this;
self.datepicker.updateNavigator(this.titleFormatter(self.datepicker.state.view.unixDate));
return this;
},
/**
* @desc hide
* @returns {Class_MonthPicker}
*/
hide: function () {
this.container.hide();
return this;
},
/**
* @desc show
* @returns {Class_MonthPicker}
*/
show: function () {
this.container.show();
this._updateNavigator();
this._render();
return this;
},
/**
* @desc selectMonth
*/
selectMonth: function () {
this.defineSelectedMonth();
this._updateNavigator();
},
/**
* @desc defineSelectedMonth
* @returns {Class_MonthPicker}
*/
defineSelectedMonth: function () {
var self = this;
self.container.children('.' + self.cssClass.monthItem).removeClass(self.cssClass.selectedMonth);
if (self.datepicker.state.view.year === self.datepicker.state.selected.year) {
self.container.children(".month" + self.datepicker.state.selected.month).addClass(self.cssClass.selectedMonth);
}
return this;
},
/**
* @desc next
* @returns {Class_MonthPicker}
*/
next: function () {
var self = this;
self.datepicker.state.setView('year', self.datepicker.state.view.year + 1);
self.updateView();
self._render();
return this;
},
/**
* @desc prev
* @returns {Class_MonthPicker}
*/
prev: function () {
var self = this;
self.datepicker.state.setView('year', self.datepicker.state.view.year - 1);
self.updateView();
self._render();
return this;
},
/**
* @desc updateView
* @returns {Class_MonthPicker}
*/
updateView: function () {
this.defineSelectedMonth();
this._updateNavigator();
return this;
},
/**
* @desc _checkMonthAccess
* @param month
* @returns {boolean}
* @private
*/
_checkMonthAccess: function (month) {
if (this.datepicker.state._filetredDate) {
var y = this.datepicker.state.view.year;
var monthUnix = new pDate([y, month]).unix() * 1000;
if (monthUnix >= this.datepicker.state.filterDate.start.unixDate &&
monthUnix <= this.datepicker.state.filterDate.end.unixDate
) {
return true;
} else {
return false;
}
}
else {
return this.datepicker.checkMonth(month);
}
},
/**
* @desc _attachEvents
* @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;
},
/**
* @desc _render
* @returns {Class_MonthPicker}
* @private
*/
_render: function () {
var self = this, m;
self.container.empty();
for (m in this.monthRange) {
var monthItem = $("<div/>").data({
monthIndex: m
}).addClass("month" + m)
.addClass(self.cssClass.monthItem)
.text(self.monthRange[m].name.fa)
.appendTo(self.container);
if (self._checkMonthAccess(m)) {
monthItem.click(function () {
self.onSelect($(this).data().monthIndex);
self.datepicker.selectMonth(parseInt($(this).data().monthIndex));
return false;
});
} else {
monthItem.addClass(self.cssClass.disbaleItem);
monthItem.click(function () {
return false;
});
}
}
;
this.defineSelectedMonth();
return this;
},
/**
* @desc init
* @returns {ClassMonthPicker}
*/
init: function () {
this._render();
this._attachEvents();
return this;
}
};
var MonthPicker = function (options, container) {
return inherit(this, [ClassSprite, ClassMonthPicker, 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>