Вход Регистрация
Файл: framework/web/js/source/jquery.maskedinput.js
Строк: 274
<?php
/// <reference path="../../../lib/jquery-1.2.6.js" />
/*
    Masked Input plugin for jQuery
    Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
    Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
    Version: 1.2.2 (03/09/2009 22:39:06)
*/
(function($) {
    var 
pasteEventName = ($.browser.msie 'paste' 'input') + ".mask";
    var 
iPhone = (window.orientation != undefined);

    $.
mask = {
        
//Predefined character definitions
        
definitions: {
            
'9'"[0-9]",
            
'a'"[A-Za-z]",
            
'*'"[A-Za-z0-9]"
        
}
    };

    $.fn.
extend({
        
//Helper Function for Caret positioning
        
caret: function(beginend) {
            if (
this.length == 0) return;
            if (
typeof begin == 'number') {
                
end = (typeof end == 'number') ? end begin;
                return 
this.each(function() {
                    if (
this.setSelectionRange) {
                        
this.focus();
                        
this.setSelectionRange(beginend);
                    } else if (
this.createTextRange) {
                        var 
range this.createTextRange();
                        
range.collapse(true);
                        
range.moveEnd('character'end);
                        
range.moveStart('character'begin);
                        
range.select();
                    }
                });
            } else {
                if (
this[0].setSelectionRange) {
                    
begin this[0].selectionStart;
                    
end this[0].selectionEnd;
                } else if (
document.selection && document.selection.createRange) {
                    var 
range document.selection.createRange();
                    
begin range.duplicate().moveStart('character', -100000);
                    
end begin range.text.length;
                }
                return { 
beginbeginendend };
            }
        },
        
unmask: function() { return this.trigger("unmask"); },
        
mask: function(masksettings) {
            if (!
mask && this.length 0) {
                var 
input = $(this[0]);
                var 
tests input.data("tests");
                return $.
map(input.data("buffer"), function(ci) {
                    return 
tests[i] ? null;
                }).
join('');
            }
            
settings = $.extend({
                
placeholder"_",
                
completednull
            
}, settings);

            var 
defs = $.mask.definitions;
            var 
tests = [];
            var 
partialPosition mask.length;
            var 
firstNonMaskPos null;
            var 
len mask.length;

            $.
each(mask.split(""), function(ic) {
                if (
== '?') {
                    
len--;
                    
partialPosition i;
                } else if (
defs[c]) {
                    
tests.push(new RegExp(defs[c]));
                    if(
firstNonMaskPos==null)
                        
firstNonMaskPos =  tests.length 1;
                } else {
                    
tests.push(null);
                }
            });

            return 
this.each(function() {
                var 
input = $(this);
                var 
buffer = $.map(mask.split(""), function(ci) { if (!= '?') return defs[c] ? settings.placeholder });
                var 
ignore false;              //Variable for ignoring control keys
                
var focusText input.val();

                
input.data("buffer"buffer).data("tests"tests);

                function 
seekNext(pos) {
                    while (++
pos <= len && !tests[pos]);
                    return 
pos;
                }

                function 
shiftL(pos) {
                    while (!
tests[pos] && --pos >= 0);
                    for (var 
posleni++) {
                        if (
tests[i]) {
                            
buffer[i] = settings.placeholder;
                            var 
seekNext(i);
                            if (
len && tests[i].test(buffer[j])) {
                                
buffer[i] = buffer[j];
                            } else
                                break;
                        }
                    }
                    
writeBuffer();
                    
input.caret(Math.max(firstNonMaskPospos));
                }

                function 
shiftR(pos) {
                    for (var 
possettings.placeholderleni++) {
                        if (
tests[i]) {
                            var 
seekNext(i);
                            var 
buffer[i];
                            
buffer[i] = c;
                            if (
len && tests[j].test(t))
                                
t;
                            else
                                break;
                        }
                    }
                }

                function 
keydownEvent(e) {
                    var 
pos = $(this).caret();
                    var 
e.keyCode;
                    
ignore = (16 || (16 && 32) || (32 && 41));

                    
//delete selection before proceeding
                    
if ((pos.begin pos.end) != && (!ignore || == || == 46))
                        
clearBuffer(pos.beginpos.end);

                    
//backspace, delete, and escape get special treatment
                    
if (== || == 46 || (iPhone && == 127)) {//backspace/delete
                        
shiftL(pos.begin + (== 46 : -1));
                        return 
false;
                    } else if (
== 27) {//escape
                        
input.val(focusText);
                        
input.caret(0checkVal());
                        return 
false;
                    }
                }

                function 
keypressEvent(e) {
                    if (
ignore) {
                        
ignore false;
                        
//Fixes Mac FF bug on backspace
                        
return (e.keyCode == 8) ? false null;
                    }
                    
|| window.event;
                    var 
e.charCode || e.keyCode || e.which;
                    var 
pos = $(this).caret();

                    if (
e.ctrlKey || e.altKey || e.metaKey) {//Ignore
                        
return true;
                    } else if ((
>= 32 && <= 125) || 186) {//typeable characters
                        
var seekNext(pos.begin 1);
                        if (
len) {
                            var 
String.fromCharCode(k);
                            if (
tests[p].test(c)) {
                                
shiftR(p);
                                
buffer[p] = c;
                                
writeBuffer();
                                var 
next seekNext(p);
                                $(
this).caret(next);
                                if (
settings.completed && next == len)
                                    
settings.completed.call(input);
                            }
                        }
                    }
                    return 
false;
                }

                function 
clearBuffer(startend) {
                    for (var 
startend && leni++) {
                        if (
tests[i])
                            
buffer[i] = settings.placeholder;
                    }
                }

                function 
writeBuffer() { return input.val(buffer.join('')).val(); }

                function 
checkVal(allow) {
                    
//try to place characters where they belong
                    
var test input.val();
                    var 
lastMatch = -1;
                    for (var 
0pos 0leni++) {
                        if (
tests[i]) {
                            
buffer[i] = settings.placeholder;
                            while (
pos++ < test.length) {
                                var 
test.charAt(pos 1);
                                if (
tests[i].test(c)) {
                                    
buffer[i] = c;
                                    
lastMatch i;
                                    break;
                                }
                            }
                            if (
pos test.length)
                                break;
                        } else if (
buffer[i] == test[pos] && i!=partialPosition) {
                            
pos++;
                            
lastMatch i;
                        }
                    }
                    if (!
allow && lastMatch partialPosition) {
                        
input.val("");
                        
clearBuffer(0len);
                    } else if (
allow || lastMatch >= partialPosition) {
                        
writeBuffer();
                        if (!
allowinput.val(input.val().substring(0lastMatch 1));
                    }
                    return (
partialPosition firstNonMaskPos);
                }

                if (!
input.attr("readonly"))
                    
input
                    
.one("unmask", function() {
                        
input
                            
.unbind(".mask")
                            .
removeData("buffer")
                            .
removeData("tests");
                    })
                    .
bind("focus.mask", function() {
                        
focusText input.val();
                        var 
pos checkVal();
                        
writeBuffer();
                        
setTimeout(function() {
                            if (
pos == mask.length)
                                
input.caret(0pos);
                            else
                                
input.caret(pos);
                        }, 
0);
                    })
                    .
bind("blur.mask", function() {
                        
checkVal();
                        if (
input.val() != focusText)
                            
input.change();
                    })
                    .
bind("keydown.mask"keydownEvent)
                    .
bind("keypress.mask"keypressEvent)
                    .
bind(pasteEventName, function() {
                        
setTimeout(function() { input.caret(checkVal(true)); }, 0);
                    });

                
checkVal(); //Perform initial check for existing values
            
});
        }
    });
})(
jQuery);
?>
Онлайн: 0
Реклама