DateMenu.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:4k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ /**
  2.  * @class Ext.menu.DateMenu
  3.  * @extends Ext.menu.Menu
  4.  * <p>A menu containing an {@link Ext.DatePicker} Component.</p>
  5.  * <p>Notes:</p><div class="mdetail-params"><ul>
  6.  * <li>Although not listed here, the <b>constructor</b> for this class
  7.  * accepts all of the configuration options of <b>{@link Ext.DatePicker}</b>.</li>
  8.  * <li>If subclassing DateMenu, any configuration options for the DatePicker must be
  9.  * applied to the <tt><b>initialConfig</b></tt> property of the DateMenu.
  10.  * Applying {@link Ext.DatePicker DatePicker} configuration settings to
  11.  * <b><tt>this</tt></b> will <b>not</b> affect the DatePicker's configuration.</li>
  12.  * </ul></div>
  13.  * @xtype datemenu
  14.  */
  15.  Ext.menu.DateMenu = Ext.extend(Ext.menu.Menu, {
  16.     /** 
  17.      * @cfg {Boolean} enableScrolling
  18.      * @hide 
  19.      */
  20.     enableScrolling : false,
  21.     /**
  22.      * @cfg {Function} handler
  23.      * Optional. A function that will handle the select event of this menu.
  24.      * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  25.      * <li><code>picker</code> : DatePicker<div class="sub-desc">The Ext.DatePicker.</div></li>
  26.      * <li><code>date</code> : Date<div class="sub-desc">The selected date.</div></li>
  27.      * </ul></div>
  28.      */
  29.     /**
  30.      * @cfg {Object} scope
  31.      * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  32.      * function will be called.  Defaults to this DateMenu instance.
  33.      */    
  34.     /** 
  35.      * @cfg {Boolean} hideOnClick
  36.      * False to continue showing the menu after a date is selected, defaults to true.
  37.      */
  38.     hideOnClick : true,
  39.     
  40.     /** 
  41.      * @cfg {String} pickerId
  42.      * An id to assign to the underlying date picker. Defaults to <tt>null</tt>.
  43.      */
  44.     pickerId : null,
  45.     
  46.     /** 
  47.      * @cfg {Number} maxHeight
  48.      * @hide 
  49.      */
  50.     /** 
  51.      * @cfg {Number} scrollIncrement
  52.      * @hide 
  53.      */
  54.     /**
  55.      * The {@link Ext.DatePicker} instance for this DateMenu
  56.      * @property picker
  57.      * @type DatePicker
  58.      */
  59.     cls : 'x-date-menu',
  60.     
  61.     /**
  62.      * @event click
  63.      * @hide
  64.      */
  65.     
  66.     /**
  67.      * @event itemclick
  68.      * @hide
  69.      */
  70.     initComponent : function(){
  71.         this.on('beforeshow', this.onBeforeShow, this);
  72.         if(this.strict = (Ext.isIE7 && Ext.isStrict)){
  73.             this.on('show', this.onShow, this, {single: true, delay: 20});
  74.         }
  75.         Ext.apply(this, {
  76.             plain: true,
  77.             showSeparator: false,
  78.             items: this.picker = new Ext.DatePicker(Ext.applyIf({
  79.                 internalRender: this.strict || !Ext.isIE,
  80.                 ctCls: 'x-menu-date-item',
  81.                 id: this.pickerId
  82.             }, this.initialConfig))
  83.         });
  84.         this.picker.purgeListeners();
  85.         Ext.menu.DateMenu.superclass.initComponent.call(this);
  86.         /**
  87.          * @event select
  88.          * Fires when a date is selected from the {@link #picker Ext.DatePicker}
  89.          * @param {DatePicker} picker The {@link #picker Ext.DatePicker}
  90.          * @param {Date} date The selected date
  91.          */
  92.         this.relayEvents(this.picker, ['select']);
  93.         this.on('show', this.picker.focus, this.picker);
  94.         this.on('select', this.menuHide, this);
  95.         if(this.handler){
  96.             this.on('select', this.handler, this.scope || this);
  97.         }
  98.     },
  99.     menuHide : function() {
  100.         if(this.hideOnClick){
  101.             this.hide(true);
  102.         }
  103.     },
  104.     onBeforeShow : function(){
  105.         if(this.picker){
  106.             this.picker.hideMonthPicker(true);
  107.         }
  108.     },
  109.     onShow : function(){
  110.         var el = this.picker.getEl();
  111.         el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode
  112.     }
  113.  });
  114.  Ext.reg('datemenu', Ext.menu.DateMenu);
  115.