Sha256: 8bfcc31cf560bcac5f0a71e12c88539532ed1e5eda86b6c691af56d9e50a0bc1

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

webshim.register('form-inputmode', function($, webshims, window, document, undefined, options){
	"use strict";
	var ua = navigator.userAgent;
	var removeListener = function(elem){
		elem.removeEventListener('blur', switchBack, true);
	};
	var needsPattern = (/iphone|ipod/i).test(ua);
	var regPattern = /^[\\d\*|\[0\-9\]]*[\+|\{\d*\,\d*\}|*]*$/;
	var stopPatterns = needsPattern || (/ipad|ios/i).test(ua) ?
		{
			'[0-9]*': 1,
			'\\d*': 1
		} :
			false
		;
	var switchBack = function(e){
		removeListener(e.target);
		e.target.type = 'text';
	};
	var removeDocListener = function(){
		document.removeEventListener('focus', addFix, true);
		document.removeEventListener('touchstart', addFix, true);
	};
	var allowSwitchByPattern = function(elem){
		var pattern;
		var switchAllowed = true;

		if(stopPatterns){
			pattern = elem.getAttribute('pattern') || '';
			if(stopPatterns[pattern] || (needsPattern && (!pattern || !regPattern.test(pattern)))){
				switchAllowed = false;
			}
		}

		return switchAllowed;
	};

	var addFix = function(e){
		if(e.target.type == 'text' && e.target.getAttribute('inputmode') == 'numeric' && allowSwitchByPattern(e.target)){
			try{
				removeListener(e.target);
				e.target.addEventListener('blur', switchBack, true);
				e.target.type = 'tel';
			} catch (er){
				removeDocListener();
			}
		}
	};

	document.addEventListener('focus', addFix, true);
	document.addEventListener('touchstart', addFix, true);
});

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
webshims-rails-1.16.0 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.10 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.9 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.8 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.6.4 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.6.3 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.6.2 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.6 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.5 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.4 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.3 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.15.2 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.14.6 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.14.5 vendor/assets/javascripts/webshims/shims/form-inputmode.js
webshims-rails-1.14.4 vendor/assets/javascripts/webshims/shims/form-inputmode.js