EXTJS4扩展实例:一个调用Ext.picker.Color的颜色选择菜单

运行环境:Extjs4.2.1

运行效果:

 

调用代码:

Ext.require(['MyExtend.Form.Field.ColorField']);
	

	Ext.onReady(function()
	{
		
	var combo = Ext.create('MyExtend.Form.Field.ColorField', {
		renderTo: Ext.getBody()
		
	});

源代码:

Ext.define('MyExtend.Form.Field.ColorField', {
  extend: 'Ext.form.field.Trigger',
  alias: 'widget.colorfield',
  triggerTip: '请选择一个颜色',
  onTriggerClick: function() {

    var me = this;
    if (!me.picker) {
      me.picker = Ext.create('Ext.picker.Color', {
        pickerField: this,
        ownerCt: this,
        renderTo: Ext.getBody(),
        floating: true,
        //hidden: true,    
        focusOnShow: true,
        style: {
          backgroundColor: "#fff"
        },
        listeners: {
          scope: this,
          select: function(field, value, opts) {

            me.setValue('#' + value);

            me.inputEl.applyStyles({
              backgroundColor: '#' + value
            });
            me.picker.hide();
          }
        }
      });
      me.picker.alignTo(me.inputEl, 'tl-bl?');

    }
    me.picker.show();
    var attached = me.attached || false;
    me.lastShow = new Date();
    if (!attached) {
      Ext.getDoc().on('mousedown', me.onMouseDown, me, {
        buffer: Ext.isIE9m ? 10 : undefined
      });
      me.attached = true;
    }

  },
  onMouseDown: function(e) {

    var lastShow = this.lastShow,
      doHide = true;

    if (Ext.Date.getElapsed(lastShow) > 50 && !e.getTarget('#' + this.picker.id)) {
      if (Ext.isIE9m && !Ext.getDoc().contains(e.target)) {
        doHide = false;
      }
      if (doHide) {
        this.picker.hide();
        Ext.getDoc().un('mousedown', this.onMouseDown, this);
        this.attached = false;
      }
    }
  }
});

 

转载于:https://www.cnblogs.com/zdkjob/p/3568398.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值