Skip to content

Commit

Permalink
fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
dolymood committed Mar 2, 2018
1 parent 661d0b3 commit c0b0f7b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/core/datetime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ var config = {
value: 'month',
rows: function (dateTime) {
var rows = []
var now = dateTime.now
var nowYear = now.getFullYear()
var minYear = dateTime.options.min.getFullYear()
var minMonth = dateTime.options.min.getMonth()
var maxYear = dateTime.options.max.getFullYear()
var maxMonth = dateTime.options.max.getMonth()
if (nowYear > minYear) {
minMonth = 0
}
if (maxYear > nowYear) {
maxMonth = 11
}
var start = minMonth
while (start <= maxMonth) {
rows.push([start++])
Expand Down
1 change: 0 additions & 1 deletion src/panel/days.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ utils.extend(DaysPanel.prototype, {
}
this._renderHead()
this.main.innerHTML = buildCalendar(this.picker.prevDateTime, this.picker.config, 'prev') + buildCalendar(this.picker.dateTime, this.picker.config, 'curr') + buildCalendar(this.picker.nextDateTime, this.picker.config, 'next')
this.afterRender()
},
_renderHead: function () {
this.picker.head.innerHTML = (
Expand Down
8 changes: 5 additions & 3 deletions src/panel/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ function ScrollerPanel (picker) {

utils.extend(ScrollerPanel.prototype, {
render: function () {
this.rows = this.picker.dateTime.getRows()
if (!this.main) {
this._init()
}
this._renderHead()
this.main.innerHTML = CONFIG[this.type](this.picker.dateTime, this.rows)
this._afterRender()
},
_renderHead: function () {
var isYears = this.type === 'C'
Expand All @@ -35,15 +35,17 @@ utils.extend(ScrollerPanel.prototype, {
'</div>'
)
},
_afterRender: function () {
afterRender: function () {
var activeEle = this.main.querySelector('.picker-active')
if (!activeEle) {
return
}
this.itemHeight = activeEle.offsetHeight
this.activeEle = activeEle
var t = activeEle.offsetTop - (this.contentHeight - this.itemHeight) / 2
this._slideTo(-t, 0)
},
_init: function () {
this.rows = this.picker.dateTime.getRows()
this._initMain()
this._initMidd()
},
Expand Down
12 changes: 8 additions & 4 deletions src/panel/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function TimePanel (picker) {

utils.extend(TimePanel.prototype, {
render: function () {
this.rows = this.picker.dateTime.getRows()
if (!this.main) {
this._init()
}
Expand All @@ -33,15 +34,15 @@ utils.extend(TimePanel.prototype, {
'</div>'
)
this.main.innerHTML = CONFIG[this.type](this.picker.dateTime, this.rows)
this.afterRender()
},
afterRender: function () {
this.headHourEle = this.picker.head.querySelector('.picker-hour')
this.headMinuteEle = this.picker.head.querySelector('.picker-minute')
this.headActiveEle = this.picker.head.querySelector('.picker-head-active')
this.activeEle = this.main.querySelector('.picker-active')
this.pickerLineEle = this.main.querySelector('.time-picker-line')
},
_init: function () {
this.rows = this.picker.dateTime.getRows()
this._initMain()
},
_initMain: function () {
Expand All @@ -58,8 +59,11 @@ utils.extend(TimePanel.prototype, {
this.mainStyle.display = 'none'
},
selfChange: function () {
var h = utils.formatDate(this.picker.dateTime.now, 'HH')
var m = utils.formatDate(this.picker.dateTime.now, 'mm')
this.headHourEle.innerHTML = h
this.headMinuteEle.innerHTML = m
var v = this.picker.dateTime.getLevelValue()
this.headActiveEle.innerHTML = utils.pad(v, 2)
var newActiveEle = this.main.querySelector('.picker-cell[data-val="' + v + '"]')
this.activeEle && this.activeEle.classList.remove('picker-active')
newActiveEle.classList.add('picker-active')
Expand Down Expand Up @@ -93,7 +97,7 @@ utils.extend(TimePanel.prototype, {
},
destroy: function () {
this.picker.content.removeChild(this.main)
utils.set2Null(['picker', 'main', 'mainStyle', 'headActiveEle', 'activeEle', 'pickerLineEle', '__move', '__end'], this)
utils.set2Null(['picker', 'main', 'mainStyle', 'headHourEle', 'headMinuteEle', 'headActiveEle', 'activeEle', 'pickerLineEle', '__move', '__end'], this)
}
})

Expand Down
3 changes: 1 addition & 2 deletions src/picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ utils.extend(pickerPro, {
this.options.default = now
this.setDateTime()
},
afterRender: utils.noop,
_setDateTime: utils.noop,
init: utils.noop,
_init: function () {
Expand Down Expand Up @@ -316,7 +315,7 @@ utils.extend(pickerPro, {
}
}, events)

var es = ['selfChange', 'render', '__start', '__move', '__end']
var es = ['selfChange', 'render', 'afterRender', '__start', '__move', '__end']
es.forEach(function (name) {
pickerPro[name] = function () {
this.panel && this.panel[name] && this.panel[name].apply(this.panel, arguments)
Expand Down

0 comments on commit c0b0f7b

Please sign in to comment.