datepicker.ext.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module.exports = {
  2. name: 'datepicker',
  3. methods: {
  4. // @extend
  5. _init: function() {
  6. this._buildDatepicker();
  7. },
  8. _buildDatepicker: function() {
  9. var $datepicker = this.$form.find('input.datepicker');
  10. // Always show datepicker below the input
  11. if (jQuery.ui) {
  12. $.datepicker._checkOffset = function(a,b,c){ return b };
  13. }
  14. if (jQuery.ui && $datepicker.length) {
  15. $datepicker.each(function() {
  16. $(this).datepicker({
  17. beforeShow: function(input) {
  18. $(input).addClass('open');
  19. },
  20. onChangeMonthYear: function() {
  21. // Hack to fix IE9 not resizing
  22. var $this = $(this)
  23. , width = $this.outerWidth(); // cache first!
  24. setTimeout(function() {
  25. $this.datepicker('widget').css('width', width);
  26. }, 1);
  27. },
  28. onClose: function() {
  29. $(this).removeClass('open');
  30. }
  31. });
  32. });
  33. // Adjust width
  34. $datepicker.on('focus keyup', function() {
  35. var t = $(this), w = t.outerWidth();
  36. t.datepicker('widget').css('width', w);
  37. });
  38. }
  39. }
  40. }
  41. };