sjivan / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 0 forks source link

fix - Events specialKey Field #535

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Fix for keyboard events to carecteres special form for browser chrome / ... 
webkit.

    /**
     * note 1: IE fires ONLY the keydown event on specialkey autorepeat
     * note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
     * (research done by Jan Wolter at http://unixpapa.com/js/key.html)
     * @private
     */    
    var isUseKeyDown = Ext.isWebKit ? parseInt(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1], 10) >= 525 : !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);

Ext.EventManager.getKeyEvent : function(){
   return isUseKeyDown ? 'keydown' : 'keypress';
}

Ext.form.Field.prototype.initEvents = function(){
   this.el.on(Ext.EventManager.getKeyEvent(), this.fireKey, this);
   this.el.on("focus", this.onFocus,  this);
   this.el.on("blur", this.onBlur,  this);

   this.originalValue = this.getValue();
}

Original issue reported on code.google.com by marlon...@gmail.com on 7 Dec 2011 at 7:18

GoogleCodeExporter commented 8 years ago
Ext.EventManager.useKeyDown = isUseKeyDown;

// Fix for events keyboard in chrome/iron - webkit

Ext.KeyNav.prototype.getKeyEvent = function(){
   return (this.forceKeyDown || Ext.EventManager.useKeyDown) ? 'keydown' : 'keypress';
};

Ext.KeyNav.prototype.enable = function(){
   if(this.disabled){
      this.el.on(this.getKeyEvent(), this.relay,  this);
      this.disabled = false;
   }
};

Ext.KeyNav.prototype.disable = function(){
   if (!this.disabled) {
       this.el.un(this.getKeyEvent(), this.relay,  this);
       this.disabled = true;
   }
};

Original comment by marlon...@gmail.com on 8 Dec 2011 at 12:11

GoogleCodeExporter commented 8 years ago
// Fix for events keyboard in chrome/iron - webkit

Ext.grid.CellSelectionModel.prototype.initEvents = function(){      
   this.grid.on("cellmousedown", this.handleMouseDown, this);
   this.grid.getGridEl().on(Ext.EventManager.getKeyEvent(), this.handleKeyDown, this);
   var view = this.grid.view;
   view.on("refresh", this.onViewChange, this);
   view.on("rowupdated", this.onRowUpdated, this);
   view.on("beforerowremoved", this.clearSelections, this);
   view.on("beforerowsinserted", this.clearSelections, this);
   if(this.grid.isEditor){
       this.grid.on("beforeedit", this.beforeEdit,  this);
   }
}

Original comment by marlon...@gmail.com on 8 Dec 2011 at 1:07

GoogleCodeExporter commented 8 years ago
// Fix for events keyboard in chrome/iron - webkit

Ext.form.HtmlEditor.prototype.initEditor=function(){
   var dbody = this.getEditorBody();
   var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
   ss['background-attachment'] = 'fixed'; // w3c
   dbody.bgProperties = 'fixed'; // ie
   Ext.DomHelper.applyStyles(dbody, ss);
   Ext.EventManager.on(this.doc, {
            'mousedown': this.onEditorEvent,
            'dblclick': this.onEditorEvent,
            'click': this.onEditorEvent,
            'keyup': this.onEditorEvent,
            buffer:100,
            scope: this
   });
   if(Ext.isGecko){
       Ext.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
   }
   if(Ext.isIE || Ext.isWebKit || Ext.isOpera){
       Ext.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
   }
   this.initialized = true;

   this.fireEvent('initialize', this);
   this.pushValue();
};

Ext.form.HtmlEditor.prototype.fixKeys=function(){
    if(Ext.isIE){
        return function(e){
            var k = e.getKey(), r;
            if(k == e.TAB){
                e.stopEvent();
                r = this.doc.selection.createRange();
                if(r){
                    r.collapse(true);
                    r.pasteHTML('    ');
                    this.deferFocus();
                }
            }else if(k == e.ENTER){
                r = this.doc.selection.createRange();
                if(r){
                    var target = r.parentElement();
                    if(!target || target.tagName.toLowerCase() != 'li'){
                        e.stopEvent();
                        r.pasteHTML('<br />');
                        r.collapse(false);
                        r.select();
                    }
                }
            }
        };
    }else if(Ext.isOpera){
        return function(e){
            var k = e.getKey();
            if(k == e.TAB){
                e.stopEvent();
                this.win.focus();
                this.execCmd('InsertHTML','    ');
                this.deferFocus();
            }
        };
    }else if(Ext.isWebKit){
        return function(e){
            var k = e.getKey();
            if(k == e.TAB){
                e.stopEvent();
                this.execCmd('InsertText','\t');
                this.deferFocus();
            } else if (k == e.ENTER) {
                e.stopEvent();
                me.execCmd('InsertHtml','<br/><br/>');
                me.deferFocus();
            }
         };
    }
}();

Original comment by marlon...@gmail.com on 8 Dec 2011 at 1:13