mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fixNsv
This commit is contained in:
+48
-12
@@ -58,6 +58,16 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
return this.trigger("unmask");
|
||||
},
|
||||
mask: function(mask, settings) {
|
||||
var triggerEvent = function (el, eventName, options) {
|
||||
var event;
|
||||
if (window.CustomEvent) {
|
||||
event = new CustomEvent(eventName, options);
|
||||
} else {
|
||||
event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent(eventName, true, true, options);
|
||||
}
|
||||
el.dispatchEvent(event);
|
||||
};
|
||||
var input,
|
||||
defs,
|
||||
tests,
|
||||
@@ -193,6 +203,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
}
|
||||
|
||||
function androidInputEvent(e) {
|
||||
console.log('androidInputEvent');
|
||||
var curVal = input.val();
|
||||
var pos = input.caret();
|
||||
if (oldVal && oldVal.length && oldVal.length > curVal.length ) {
|
||||
@@ -228,6 +239,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
|
||||
|
||||
function blurEvent(e) {
|
||||
console.log('blurEvent');
|
||||
clearInterval(actualCaretID);
|
||||
checkVal();
|
||||
|
||||
@@ -235,7 +247,10 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
input.change();
|
||||
}
|
||||
|
||||
var inputCancel = false;
|
||||
|
||||
function keydownEvent(e) {
|
||||
console.log('keydownEvent');
|
||||
if (input.prop("readonly")){
|
||||
return;
|
||||
}
|
||||
@@ -259,6 +274,8 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
shiftL(begin, end - 1);
|
||||
|
||||
e.preventDefault();
|
||||
inputCancel = true;
|
||||
triggerEvent(input[0], 'input', { 'bubbles': true });
|
||||
} else if( k === 13 ) { // enter
|
||||
blurEvent.call(this, e);
|
||||
} else if (k === 27) { // escape
|
||||
@@ -269,6 +286,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
}
|
||||
|
||||
function keypressEvent(e) {
|
||||
console.log('keypressEvent');
|
||||
if (input.prop("readonly")){
|
||||
return;
|
||||
}
|
||||
@@ -313,6 +331,8 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
inputCancel = true;
|
||||
triggerEvent(input[0], 'input', { 'bubbles': true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,7 +432,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
|
||||
function getRaw()
|
||||
{
|
||||
console.log('mask input.data($.mask.dataName)');
|
||||
checkVal();
|
||||
return $.map(buffer, function(c, i) {
|
||||
return tests[i]&&c!=getPlaceholder(i) ? c : null;
|
||||
}).join('');
|
||||
@@ -430,6 +450,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
});
|
||||
|
||||
function focusEvent () {
|
||||
console.log('focusEvent');
|
||||
if (input.prop("readonly")){
|
||||
return;
|
||||
}
|
||||
@@ -442,20 +463,32 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
pos = checkVal();
|
||||
|
||||
caretTimeoutId = setTimeout(function(){
|
||||
console.log('caretTimeoutId')
|
||||
if(input.get(0) !== document.activeElement){
|
||||
return;
|
||||
}
|
||||
writeBuffer();
|
||||
if (pos == mask.replace("?","").length) {
|
||||
input.caret(0, pos);
|
||||
//input.caret(0, pos);
|
||||
input.caret(pos);
|
||||
} else {
|
||||
input.caret(pos);
|
||||
}
|
||||
|
||||
}, 10);
|
||||
|
||||
}
|
||||
|
||||
function unmask() {
|
||||
// console.log('mask one unmask');
|
||||
input
|
||||
.off(".mask")
|
||||
.removeData($.mask.dataName);
|
||||
if(isInput) {
|
||||
input.removeData('maskCall');
|
||||
}
|
||||
delete input[0]['mask'];
|
||||
}
|
||||
|
||||
function actualCaret(){
|
||||
var pos = checkVal(true),
|
||||
c = input.caret();
|
||||
@@ -467,15 +500,7 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
}
|
||||
}
|
||||
input
|
||||
.one("unmask", function() {
|
||||
// console.log('mask one unmask');
|
||||
input
|
||||
.off(".mask")
|
||||
.removeData($.mask.dataName);
|
||||
if(isInput) {
|
||||
input.removeData('maskCall');
|
||||
}
|
||||
});
|
||||
.one("unmask", unmask);
|
||||
isInput && input
|
||||
.on("focus.mask", focusEvent)
|
||||
.on("blur.mask", blurEvent)
|
||||
@@ -483,6 +508,11 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
.on("keypress.mask", keypressEvent);
|
||||
input
|
||||
.on("input.mask paste.mask", function() {
|
||||
if(inputCancel) {
|
||||
inputCancel = false;
|
||||
return;
|
||||
}
|
||||
console.log('input.mask paste.mask');
|
||||
if (input.prop("readonly")){
|
||||
return;
|
||||
}
|
||||
@@ -510,6 +540,12 @@ kit.PluginManager.register('mask', function(module, exports, require){
|
||||
isInput && input.on('input.mask', androidInputEvent);
|
||||
}
|
||||
checkVal(); //Perform initial check for existing values
|
||||
|
||||
this.mask = {
|
||||
unmask: unmask,
|
||||
getRaw: getRaw,
|
||||
isValid: isValid,
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user