123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- goog.provide('goog.ui.PopupDatePicker');
- goog.require('goog.events.EventType');
- goog.require('goog.positioning.AnchoredPosition');
- goog.require('goog.positioning.Corner');
- goog.require('goog.positioning.Overflow');
- goog.require('goog.style');
- goog.require('goog.ui.Component');
- goog.require('goog.ui.DatePicker');
- goog.require('goog.ui.Popup');
- goog.require('goog.ui.PopupBase');
- goog.ui.PopupDatePicker = function(opt_datePicker, opt_domHelper) {
- goog.ui.Component.call(this, opt_domHelper);
- this.datePicker_ = opt_datePicker || new goog.ui.DatePicker();
- };
- goog.inherits(goog.ui.PopupDatePicker, goog.ui.Component);
- goog.tagUnsealableClass(goog.ui.PopupDatePicker);
- goog.ui.PopupDatePicker.prototype.datePicker_ = null;
- goog.ui.PopupDatePicker.prototype.popup_ = null;
- goog.ui.PopupDatePicker.prototype.lastTarget_ = null;
- goog.ui.PopupDatePicker.prototype.allowAutoFocus_ = true;
- goog.ui.PopupDatePicker.prototype.createDom = function() {
- goog.ui.PopupDatePicker.superClass_.createDom.call(this);
- this.getElement().className = goog.getCssName('goog-popupdatepicker');
- this.popup_ = new goog.ui.Popup(this.getElement());
- this.popup_.setParentEventTarget(this);
- };
- goog.ui.PopupDatePicker.prototype.isVisible = function() {
- return this.popup_ ? this.popup_.isVisible() : false;
- };
- goog.ui.PopupDatePicker.prototype.enterDocument = function() {
- goog.ui.PopupDatePicker.superClass_.enterDocument.call(this);
-
-
-
- if (!this.datePicker_.isInDocument()) {
- var el = this.getElement();
-
- el.style.visibility = 'hidden';
- goog.style.setElementShown(el, false);
- this.datePicker_.decorate(el);
- }
- this.getHandler()
- .listen(
- this.datePicker_, goog.ui.DatePicker.Events.CHANGE,
- this.onDateChanged_)
- .listen(
- this.datePicker_, goog.ui.DatePicker.Events.SELECT,
- this.onDateSelected_);
- };
- goog.ui.PopupDatePicker.prototype.disposeInternal = function() {
- goog.ui.PopupDatePicker.superClass_.disposeInternal.call(this);
- if (this.popup_) {
- this.popup_.dispose();
- this.popup_ = null;
- }
- this.datePicker_.dispose();
- this.datePicker_ = null;
- this.lastTarget_ = null;
- };
- goog.ui.PopupDatePicker.prototype.canDecorate = function(element) {
- return false;
- };
- goog.ui.PopupDatePicker.prototype.getDatePicker = function() {
- return this.datePicker_;
- };
- goog.ui.PopupDatePicker.prototype.getDate = function() {
- return this.datePicker_.getDate();
- };
- goog.ui.PopupDatePicker.prototype.setDate = function(date) {
- this.datePicker_.setDate(date);
- };
- goog.ui.PopupDatePicker.prototype.getLastTarget = function() {
- return this.lastTarget_;
- };
- goog.ui.PopupDatePicker.prototype.attach = function(element) {
- this.getHandler().listen(
- element, goog.events.EventType.MOUSEDOWN, this.showPopup_);
- };
- goog.ui.PopupDatePicker.prototype.detach = function(element) {
- this.getHandler().unlisten(
- element, goog.events.EventType.MOUSEDOWN, this.showPopup_);
- };
- goog.ui.PopupDatePicker.prototype.setAllowAutoFocus = function(allow) {
- this.allowAutoFocus_ = allow;
- };
- goog.ui.PopupDatePicker.prototype.getAllowAutoFocus = function() {
- return this.allowAutoFocus_;
- };
- goog.ui.PopupDatePicker.prototype.showPopup = function(element, opt_keepDate) {
- this.lastTarget_ = element;
- this.popup_.setPosition(
- new goog.positioning.AnchoredPosition(
- element, goog.positioning.Corner.BOTTOM_START,
- (goog.positioning.Overflow.ADJUST_X_EXCEPT_OFFSCREEN |
- goog.positioning.Overflow.ADJUST_Y_EXCEPT_OFFSCREEN)));
-
-
- this.getHandler()
- .unlisten(
- this.datePicker_, goog.ui.DatePicker.Events.CHANGE,
- this.onDateChanged_)
- .unlisten(
- this.datePicker_, goog.ui.DatePicker.Events.SELECT,
- this.onDateSelected_);
- var keepDate = !!opt_keepDate;
- if (!keepDate) {
- this.datePicker_.setDate(null);
- }
-
-
-
- this.dispatchEvent(goog.ui.PopupBase.EventType.SHOW);
- this.popup_.setVisible(true);
- if (this.allowAutoFocus_) {
- this.getElement().focus();
- }
- this.getHandler()
- .listen(
- this.datePicker_, goog.ui.DatePicker.Events.CHANGE,
- this.onDateChanged_)
- .listen(
- this.datePicker_, goog.ui.DatePicker.Events.SELECT,
- this.onDateSelected_);
- };
- goog.ui.PopupDatePicker.prototype.showPopup_ = function(event) {
- this.showPopup( (event.currentTarget));
- };
- goog.ui.PopupDatePicker.prototype.hidePopup = function() {
- this.popup_.setVisible(false);
- if (this.allowAutoFocus_ && this.lastTarget_) {
- this.lastTarget_.focus();
- }
- };
- goog.ui.PopupDatePicker.prototype.onDateSelected_ = function(event) {
- this.hidePopup();
-
- this.dispatchEvent(event);
- };
- goog.ui.PopupDatePicker.prototype.onDateChanged_ = function(event) {
-
- this.dispatchEvent(event);
- };
|