widgets/SecurePass.js
[Pman.Core] / widgets / SecurePass.js
index 20ac8a6..bab5c37 100644 (file)
@@ -71,15 +71,12 @@ Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
 
     // private
     initEvents : function(){
-            if(this.inputType == 'password'){
-                this.el.on('keydown',function(event){
-                    if(event.getKey() == 8){
-                        event.preventDefault();
-                        //this.setValue('');
-                    };
-                },this);
-            }
             Ext.form.SecurePass.superclass.initEvents.call(this);
+        
+            if(this.el.is('input[type=password]') && Roo.isSafari){
+                this.el.on('keydown', this.SafariOnKeyDown, this);
+            }
+
             this.el.on('keyup', this.checkStrength, this, {buffer:50});
        },
 
@@ -295,5 +292,28 @@ Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
     // private
        ClientSideWeakPassword : function(pwd){
                return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
-       }
+       },
+        
+    // private
+    SafariOnKeyDown : function(event){
+        
+        var isSelectAll = false;
+        if(this.el.dom.selectionEnd > 0){
+            isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
+        }
+            event.preventDefault();
+            return;
+        
+        if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
+            event.preventDefault();
+            this.setValue('');
+            return;
+         };
+        if(isSelectAll){ // backspace and delete key
+            event.preventDefault();
+            this.setValue('');
+            (function() { this.setValue(String.fromCharCode(charCode)); }).defer(50);
+            return;
+        };
+    }
 })
\ No newline at end of file