mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
added onShow & onHide events, resolves #95
This commit is contained in:
parent
42f6d4c76d
commit
a71611bde3
20
dist/js/datepicker.js
vendored
20
dist/js/datepicker.js
vendored
@ -75,6 +75,8 @@
|
|||||||
|
|
||||||
// events
|
// events
|
||||||
onSelect: '',
|
onSelect: '',
|
||||||
|
onShow: '',
|
||||||
|
onHide: '',
|
||||||
onChangeMonth: '',
|
onChangeMonth: '',
|
||||||
onChangeYear: '',
|
onChangeYear: '',
|
||||||
onChangeDecade: '',
|
onChangeDecade: '',
|
||||||
@ -785,12 +787,20 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
|
var onShow = this.opts.onShow;
|
||||||
|
|
||||||
this.setPosition(this.opts.position);
|
this.setPosition(this.opts.position);
|
||||||
this.$datepicker.addClass('active');
|
this.$datepicker.addClass('active');
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
|
|
||||||
|
if (onShow) {
|
||||||
|
this._bindVisionEvents(onShow)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function () {
|
hide: function () {
|
||||||
|
var onHide = this.opts.onHide;
|
||||||
|
|
||||||
this.$datepicker
|
this.$datepicker
|
||||||
.removeClass('active')
|
.removeClass('active')
|
||||||
.css({
|
.css({
|
||||||
@ -803,6 +813,10 @@
|
|||||||
this.inFocus = false;
|
this.inFocus = false;
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
this.$el.blur();
|
this.$el.blur();
|
||||||
|
|
||||||
|
if (onHide) {
|
||||||
|
this._bindVisionEvents(onHide)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (date) {
|
down: function (date) {
|
||||||
@ -813,6 +827,12 @@
|
|||||||
this._changeView(date, 'up');
|
this._changeView(date, 'up');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_bindVisionEvents: function (event) {
|
||||||
|
this.$datepicker.off('transitionend.dp');
|
||||||
|
event(this, false);
|
||||||
|
this.$datepicker.one('transitionend.dp', event.bind(this, this, true))
|
||||||
|
},
|
||||||
|
|
||||||
_changeView: function (date, dir) {
|
_changeView: function (date, dir) {
|
||||||
date = date || this.focused || this.date;
|
date = date || this.focused || this.date;
|
||||||
|
|
||||||
|
|||||||
4
dist/js/datepicker.min.js
vendored
4
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -75,6 +75,8 @@
|
|||||||
|
|
||||||
// events
|
// events
|
||||||
onSelect: '',
|
onSelect: '',
|
||||||
|
onShow: '',
|
||||||
|
onHide: '',
|
||||||
onChangeMonth: '',
|
onChangeMonth: '',
|
||||||
onChangeYear: '',
|
onChangeYear: '',
|
||||||
onChangeDecade: '',
|
onChangeDecade: '',
|
||||||
@ -785,12 +787,20 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
|
var onShow = this.opts.onShow;
|
||||||
|
|
||||||
this.setPosition(this.opts.position);
|
this.setPosition(this.opts.position);
|
||||||
this.$datepicker.addClass('active');
|
this.$datepicker.addClass('active');
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
|
|
||||||
|
if (onShow) {
|
||||||
|
this._bindVisionEvents(onShow)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function () {
|
hide: function () {
|
||||||
|
var onHide = this.opts.onHide;
|
||||||
|
|
||||||
this.$datepicker
|
this.$datepicker
|
||||||
.removeClass('active')
|
.removeClass('active')
|
||||||
.css({
|
.css({
|
||||||
@ -803,6 +813,10 @@
|
|||||||
this.inFocus = false;
|
this.inFocus = false;
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
this.$el.blur();
|
this.$el.blur();
|
||||||
|
|
||||||
|
if (onHide) {
|
||||||
|
this._bindVisionEvents(onHide)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (date) {
|
down: function (date) {
|
||||||
@ -813,6 +827,12 @@
|
|||||||
this._changeView(date, 'up');
|
this._changeView(date, 'up');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_bindVisionEvents: function (event) {
|
||||||
|
this.$datepicker.off('transitionend.dp');
|
||||||
|
event(this, false);
|
||||||
|
this.$datepicker.one('transitionend.dp', event.bind(this, this, true))
|
||||||
|
},
|
||||||
|
|
||||||
_changeView: function (date, dir) {
|
_changeView: function (date, dir) {
|
||||||
date = date || this.focused || this.date;
|
date = date || this.focused || this.date;
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
/* Remove transitions to test position options*/
|
/* Remove transitions to test position options*/
|
||||||
.datepicker {
|
.datepicker {
|
||||||
transition: none !important;
|
transition-duration: 0s !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@ -15,6 +15,7 @@ var assert = chai.assert,
|
|||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
if (dp && destroy) {
|
if (dp && destroy) {
|
||||||
dp.destroy();
|
dp.destroy();
|
||||||
|
dp = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy = true;
|
destroy = true;
|
||||||
@ -78,6 +79,39 @@ var assert = chai.assert,
|
|||||||
expect(dates).to.have.length(2)
|
expect(dates).to.have.length(2)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onShow', function () {
|
||||||
|
it('should add callback when datepicker is showing', function () {
|
||||||
|
var test = '';
|
||||||
|
dp = $input.datepicker({
|
||||||
|
onShow: function (dp, completed) {
|
||||||
|
if (!completed) {
|
||||||
|
test = dp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).data('datepicker');
|
||||||
|
|
||||||
|
dp.show();
|
||||||
|
expect(test).to.be.equal(dp);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onHide', function () {
|
||||||
|
it('should add callback when datepicker is hiding (after transition completed)', function () {
|
||||||
|
var test = '';
|
||||||
|
dp = $input.datepicker({
|
||||||
|
onHide: function (dp, completed) {
|
||||||
|
if (!completed) {
|
||||||
|
test = dp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).data('datepicker');
|
||||||
|
|
||||||
|
dp.show();
|
||||||
|
dp.hide();
|
||||||
|
expect(test).to.be.equal(dp);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('onRenderCell', function () {
|
describe('onRenderCell', function () {
|
||||||
it('should add callback when cell is rendered', function () {
|
it('should add callback when cell is rendered', function () {
|
||||||
|
|||||||
@ -5,7 +5,6 @@ var assert = chai.assert,
|
|||||||
describe('Datepicker', function () {
|
describe('Datepicker', function () {
|
||||||
describe('getDaysCount', function () {
|
describe('getDaysCount', function () {
|
||||||
it('should return 31 days in December', function () {
|
it('should return 31 days in December', function () {
|
||||||
console.log(plugin.getDaysCount);
|
|
||||||
assert.equal(plugin.getDaysCount(new Date(2015, 11)), 31)
|
assert.equal(plugin.getDaysCount(new Date(2015, 11)), 31)
|
||||||
});
|
});
|
||||||
it('should return 30 days in September', function () {
|
it('should return 30 days in September', function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user