Вход Регистрация
Файл: module-assets/admin/js/lib/bootstrap-inputmask.js
Строк: 378
<?php
/* ===========================================================
 * bootstrap-inputmask.js j2
 * http://twitter.github.com/bootstrap/javascript.html#tooltips
 * Based on Masked Input plugin by Josh Bush (digitalbush.com)
 * ===========================================================
 * Copyright 2012 Jasny BV, Netherlands.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */

!function ($) {

  
"use strict"// jshint ;_;

  
var isIphone = (window.orientation !== undefined),
      
isAndroid navigator.userAgent.toLowerCase().indexOf("android") > -1

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


 
/* INPUTMASK PUBLIC CLASS DEFINITION
  * ================================= */

  
var Inputmask = function (elementoptions) {
    if (
isAndroid) return // No support because caret positioning doesn't work on Android
    
    
this.$element = $(element)
    
this.mask String(options.mask)
    
this.options = $.extend({}, $.fn.inputmask.defaultsoptions)
    
    
this.init()
    
this.listen()
        
    
this.checkVal() //Perform initial check for existing values
  
}

  
Inputmask.prototype = {
    
    
init: function() {
      var 
defs = $.mask.definitions
      
var len this.mask.length

      this
.tests = [] 
      
this.partialPosition this.mask.length
      this
.firstNonMaskPos null

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

      
this.buffer = $.map(this.mask.split(""), $.proxy(function(ci) {
        if (
!= '?') return defs[c] ? this.options.placeholder c
      
}, this))
      
      
this.focusText this.$element.val()

      
this.$element.data($.mask.dataName, $.proxy(function() {
        return $.
map(this.buffer, function(ci) {
          return 
this.tests[i] && != this.options.placeholder null
        
}).join('')
      }, 
this))
    },
    
    
listen: function() {
      if (
this.$element.attr("readonly")) return

      var 
pasteEventName = ($.browser.msie 'paste' 'input') + ".mask"

      
this.$element
        
.on("unmask", $.proxy(this.unmaskthis))
        
        .
on("focus.mask", $.proxy(this.focusEventthis))
        .
on("blur.mask", $.proxy(this.blurEventthis))
        
        .
on("keydown.mask", $.proxy(this.keydownEventthis))
        .
on("keypress.mask", $.proxy(this.keypressEventthis))

        .
on(pasteEventName, $.proxy(this.pasteEventthis))
    },

    
//Helper Function for Caret positioning
    
caret: function(beginend) {
      if (
this.$element.length === 0) return
      if (
typeof begin == 'number') {
        
end = (typeof end == 'number') ? end begin
        
return this.$element.each(function() {
          if (
this.setSelectionRange) {
            
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.$element[0].setSelectionRange) {
          
begin this.$element[0].selectionStart
          end 
this.$element[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 {
          
beginbegin
          
endend
        
}
      }
    },
    
    
seekNext: function(pos) {
      var 
len this.mask.length
      
while (++pos <= len && !this.tests[pos]);
      
      return 
pos
    
},
    
    
seekPrev: function(pos) {
      while (--
pos >= && !this.tests[pos]);
      
      return 
pos
    
},

    
shiftL: function(begin,end) {
      var 
len this.mask.length
      
      
if(begin<0) return
      
      for (var 
begin,this.seekNext(end); leni++) {
        if (
this.tests[i]) {
          if (
len && this.tests[i].test(this.buffer[j])) {
            
this.buffer[i] = this.buffer[j]
            
this.buffer[j] = this.options.placeholder
          
} else
            break
          
this.seekNext(j)
        }
      }
      
this.writeBuffer()
      
this.caret(Math.max(this.firstNonMaskPosbegin))
    },

    
shiftR: function(pos) {
      var 
len this.mask.length
      
      
for (var posthis.options.placeholderleni++) {
        if (
this.tests[i]) {
          var 
this.seekNext(i)
          var 
this.buffer[i]
          
this.buffer[i] = c
          
if (len && this.tests[j].test(t))
            
t
          
else
            break
        }
      }
    },

    
unmask: function() {
      
this.$element
        
.unbind(".mask")
        .
removeData("inputmask")
    },
    
    
focusEvent: function() {
      
this.focusText this.$element.val()
      var 
len this.mask.length 
      
var pos this.checkVal()
      
this.writeBuffer()

      var 
that this
      
var moveCaret = function() {
        if (
pos == len)
          
that.caret(0pos)
        else
          
that.caret(pos)
      }

      if ($.
browser.msie)
        
moveCaret()
      else
        
setTimeout(moveCaret0)
    },
    
    
blurEvent: function() {
      
this.checkVal()
      if (
this.$element.val() != this.focusText)
        
this.$element.trigger('change')
    },
        
    
keydownEvent: function(e) {
      var 
k=e.which

      
//backspace, delete, and escape get special treatment
      
if (== || == 46 || (isIphone && == 127)) {
        var 
pos this.caret(),
        
begin pos.begin,
        
end pos.end
                        
        
if (end-begin === 0) {
          
begin k!=46 this.seekPrev(begin) : (end=this.seekNext(begin-1))
          
end k==46 this.seekNext(end) : end
        
}
        
this.clearBuffer(beginend)
        
this.shiftL(begin,end-1)

        return 
false
      
} else if (== 27) {//escape
        
this.$element.val(this.focusText)
        
this.caret(0this.checkVal())
        return 
false
      
}
    },

    
keypressEvent: function(e) {
      var 
len this.mask.length
      
      
var e.which,
      
pos this.caret()

      if (
e.ctrlKey || e.altKey || e.metaKey || k<32)  {//Ignore
        
return true
      
} else if (k) {
        if (
pos.end pos.begin !== 0) {
          
this.clearBuffer(pos.beginpos.end)
          
this.shiftL(pos.beginpos.end-1)
        }

        var 
this.seekNext(pos.begin 1)
        if (
len) {
          var 
String.fromCharCode(k)
          if (
this.tests[p].test(c)) {
            
this.shiftR(p)
            
this.buffer[p] = c
            this
.writeBuffer()
            var 
next this.seekNext(p)
            
this.caret(next)
          }
        }
        return 
false
      
}
    },

    
pasteEvent: function() {
      var 
that this
      
      setTimeout
(function() {
        
that.caret(that.checkVal(true))
      }, 
0)
    },
    
    
clearBuffer: function(startend) {
      var 
len this.mask.length
      
      
for (var startend && leni++) {
        if (
this.tests[i])
          
this.buffer[i] = this.options.placeholder
      
}
    },

    
writeBuffer: function() {
      return 
this.$element.val(this.buffer.join('')).val()
    },

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

  
 
/* INPUTMASK PLUGIN DEFINITION
  * =========================== */

  
$.fn.inputmask = function (options) {
    return 
this.each(function () {
      var 
$this = $(this)
      , 
data $this.data('inputmask')
      if (!
data$this.data('inputmask', (data = new Inputmask(thisoptions)))
    })
  }

  $.
fn.inputmask.defaults = {
    
placeholder"_"
  
}

  $.
fn.inputmask.Constructor Inputmask


 
/* INPUTMASK DATA-API
  * ================== */

  
$(function () {
    $(
'body').on('focus.inputmask.data-api''[data-mask]', function (e) {
      var 
$this = $(this)
      if (
$this.data('inputmask')) return
      
e.preventDefault()
      
$this.inputmask($this.data())
    })
  })

}(
window.jQuery);
?>
Онлайн: 1
Реклама