vendor/assets/javascripts/webshims/shims/combos/24.js in webshims-rails-1.11.3.1 vs vendor/assets/javascripts/webshims/shims/combos/24.js in webshims-rails-1.11.6
- old
+ new
@@ -2,11 +2,10 @@
"use strict";
webshims.inputTypes = webshims.inputTypes || {};
//some helper-functions
var cfg = webshims.cfg.forms;
var bugs = webshims.bugs;
-var isSubmit;
var isNumber = function(string){
return (typeof string == 'number' || (string && string == string * 1));
},
typeModels = webshims.inputTypes,
@@ -77,10 +76,11 @@
badInput: false,
rangeUnderflow: false,
rangeOverflow: false,
stepMismatch: false,
tooLong: false,
+ tooShort: false,
patternMismatch: false,
valueMissing: false,
valid: true
};
@@ -113,10 +113,13 @@
}
ret = ret.filter('[type="radio"]');
}
return ret;
};
+var patternTypes = {url: 1, email: 1, text: 1, search: 1, tel: 1, password: 1};
+var lengthTypes = $.extend({textarea: 1}, patternTypes);
+
var validityRules = {
valueMissing: function(input, val, cache){
if(!input.prop('required')){return false;}
var ret = false;
if(!('type' in cache)){
@@ -129,15 +132,16 @@
} else {
ret = !(val);
}
return ret;
},
- tooLong: function(){
- return false;
- },
patternMismatch: function(input, val, cache) {
if(val === '' || cache.nodeName == 'select'){return false;}
+ if(!('type' in cache)){
+ cache.type = getType(input[0]);
+ }
+ if(!patternTypes[cache.type]){return false;}
var pattern = input.attr('pattern');
if(!pattern){return false;}
try {
pattern = new RegExp('^(?:' + pattern + ')$');
} catch(er){
@@ -148,10 +152,24 @@
return !(pattern.test(val));
}
}
;
+$.each({tooShort: ['minLength', -1], tooLong: ['maxLength', 1]}, function(name, props){
+ validityRules[name] = function(input, val, cache){
+ //defaultValue is not the same as dirty flag, but very similiar
+ if(cache.nodeName == 'select' || input.prop('defaultValue') == val){return false;}
+ if(!('type' in cache)){
+ cache.type = getType(input[0]);
+ }
+ if(!lengthTypes[cache.type]){return false;}
+ var prop = input.prop(props[0]);
+
+ return ( prop > 0 && prop * props[1] < val.length * props[1] );
+ };
+});
+
$.each({typeMismatch: 'mismatch', badInput: 'bad'}, function(name, fn){
validityRules[name] = function (input, val, cache){
if(val === '' || cache.nodeName == 'select'){return false;}
var ret = false;
if(!('type' in cache)){
@@ -198,19 +216,16 @@
teardown: $.noop,
handler: function(e, d){
if( e.type != 'submit' || e.testedValidity || !e.originalEvent || !$.nodeName(e.target, 'form') || $.prop(e.target, 'noValidate') ){return;}
- isSubmit = true;
e.testedValidity = true;
- var notValid = !($(e.target).checkValidity());
+ var notValid = !($(e.target).callProp('reportValidity'));
if(notValid){
e.stopImmediatePropagation();
- isSubmit = false;
return false;
}
- isSubmit = false;
}
};
$.event.special.submit = $.event.special.submit || {setup: function(){return false;}};
var submitSetup = $.event.special.submit.setup;
@@ -273,10 +288,13 @@
//ToDo: add object to this list
webshims.defineNodeNamesProperties(['button', 'fieldset', 'output'], {
checkValidity: {
value: function(){return true;}
},
+ reportValidity: {
+ value: function(){return true;}
+ },
willValidate: {
value: false
},
setCustomValidity: {
value: $.noop
@@ -287,11 +305,11 @@
return $.extend({}, validityPrototype);
}
}
}, 'prop');
-var baseCheckValidity = function(elem){
+var baseCheckValidity = function(elem, type){
var e,
v = $.prop(elem, 'validity')
;
if(v){
$.data(elem, 'cachedValidity', v);
@@ -299,118 +317,134 @@
return true;
}
if( !v.valid ){
e = $.Event('invalid');
var jElm = $(elem).trigger(e);
- if(isSubmit && !baseCheckValidity.unhandledInvalids && !e.isDefaultPrevented()){
+ if(type == 'reportValidity' && !baseCheckValidity.unhandledInvalids && !e.isDefaultPrevented()){
webshims.validityAlert.showFor(jElm);
baseCheckValidity.unhandledInvalids = true;
}
}
$.removeData(elem, 'cachedValidity');
return v.valid;
};
var rsubmittable = /^(?:select|textarea|input)/i;
-webshims.defineNodeNameProperty('form', 'checkValidity', {
- prop: {
- value: function(){
-
- var ret = true,
- elems = $($.prop(this, 'elements')).filter(function(){
- if(!rsubmittable.test(this.nodeName)){return false;}
- var shadowData = webshims.data(this, 'shadowData');
- return !shadowData || !shadowData.nativeElement || shadowData.nativeElement === this;
- })
- ;
-
- baseCheckValidity.unhandledInvalids = false;
- for(var i = 0, len = elems.length; i < len; i++){
- if( !baseCheckValidity(elems[i]) ){
- ret = false;
+
+['checkValidity', 'reportValidity'].forEach(function(name){
+ webshims.defineNodeNameProperty('form', name, {
+ prop: {
+ value: function(){
+
+ var ret = true,
+ elems = $($.prop(this, 'elements')).filter(function(){
+ if(!rsubmittable.test(this.nodeName)){return false;}
+ var shadowData = webshims.data(this, 'shadowData');
+ return !shadowData || !shadowData.nativeElement || shadowData.nativeElement === this;
+ })
+ ;
+
+ baseCheckValidity.unhandledInvalids = false;
+ for(var i = 0, len = elems.length; i < len; i++){
+ if( !baseCheckValidity(elems[i], name) ){
+ ret = false;
+ }
}
+ return ret;
}
- return ret;
}
- }
+ });
});
-webshims.defineNodeNamesProperties(['input', 'textarea', 'select'], {
- checkValidity: {
- value: function(){
- baseCheckValidity.unhandledInvalids = false;
- return baseCheckValidity($(this).getNativeElement()[0]);
- }
- },
- setCustomValidity: {
- value: function(error){
- $.removeData(this, 'cachedValidity');
- webshims.data(this, 'customvalidationMessage', ''+error);
- }
- },
- willValidate: {
- writeable: false,
- get: (function(){
- var types = {
- button: 1,
- reset: 1,
- hidden: 1,
- image: 1
+
+
+
+['input', 'textarea', 'select'].forEach(function(nodeName){
+ var inputValidationAPI = {
+ setCustomValidity: {
+ value: function(error){
+ $.removeData(this, 'cachedValidity');
+ webshims.data(this, 'customvalidationMessage', ''+error);
+ if(bugs.bustedValidity && inputValidationAPI.setCustomValidity.prop._supvalue){
+ inputValidationAPI.setCustomValidity.prop._supvalue.apply(this, arguments);
}
- ;
- return function(){
- var elem = $(this).getNativeElement()[0];
- //elem.name && <- we don't use to make it easier for developers
- return !!(!elem.disabled && !elem.readOnly && !types[elem.type] );
- };
- })()
- },
- validity: {
- writeable: false,
- get: function(){
- var jElm = $(this).getNativeElement();
- var elem = jElm[0];
- var validityState = $.data(elem, 'cachedValidity');
- if(validityState){
- return validityState;
}
- validityState = $.extend({}, validityPrototype);
-
- if( !$.prop(elem, 'willValidate') || elem.type == 'submit' ){
+ },
+ willValidate: {
+ writeable: false,
+ get: (function(){
+ var types = {
+ button: 1,
+ reset: 1,
+ hidden: 1,
+ image: 1
+ }
+ ;
+ return function(){
+ var elem = $(this).getNativeElement()[0];
+ return !!(!elem.readOnly && !types[elem.type] && !$(elem).is(':disabled') );
+ };
+ })()
+ },
+ validity: {
+ writeable: false,
+ get: function(){
+ var jElm = $(this).getNativeElement();
+ var elem = jElm[0];
+ var validityState = $.data(elem, 'cachedValidity');
+ if(validityState){
+ return validityState;
+ }
+ validityState = $.extend({}, validityPrototype);
+
+ if( !$.prop(elem, 'willValidate') || elem.type == 'submit' ){
+ return validityState;
+ }
+ var val = jElm.val(),
+ cache = {nodeName: elem.nodeName.toLowerCase()}
+ ;
+
+ validityState.customError = !!(webshims.data(elem, 'customvalidationMessage'));
+ if( validityState.customError ){
+ validityState.valid = false;
+ }
+
+ $.each(validityRules, function(rule, fn){
+ if (fn(jElm, val, cache)) {
+ validityState[rule] = true;
+ validityState.valid = false;
+ }
+ });
+ $(this).getShadowFocusElement().attr('aria-invalid', validityState.valid ? 'false' : 'true');
+ jElm = null;
+ elem = null;
return validityState;
}
- var val = jElm.val(),
- cache = {nodeName: elem.nodeName.toLowerCase()}
- ;
-
- validityState.customError = !!(webshims.data(elem, 'customvalidationMessage'));
- if( validityState.customError ){
- validityState.valid = false;
+ }
+ };
+
+ ['checkValidity', 'reportValidity'].forEach(function(name){
+ inputValidationAPI[name] = {
+ value: function(){
+ baseCheckValidity.unhandledInvalids = false;
+ return baseCheckValidity($(this).getNativeElement()[0], name);
}
-
- $.each(validityRules, function(rule, fn){
- if (fn(jElm, val, cache)) {
- validityState[rule] = true;
- validityState.valid = false;
- }
- });
- $(this).getShadowFocusElement().attr('aria-invalid', validityState.valid ? 'false' : 'true');
- jElm = null;
- elem = null;
- return validityState;
}
- }
-}, 'prop');
+ });
+
+ webshims.defineNodeNameProperties(nodeName, inputValidationAPI, 'prop');
+});
+
webshims.defineNodeNamesBooleanProperty(['input', 'textarea', 'select'], 'required', {
set: function(value){
$(this).getShadowFocusElement().attr('aria-required', !!(value)+'');
},
initAttr: Modernizr.localstorage //only if we have aria-support
});
webshims.defineNodeNamesBooleanProperty(['input'], 'multiple');
-if(webshims.bugs.bustedValidity){
+if(bugs.bustedValidity){
webshims.defineNodeNameProperty('form', 'novalidate', {
attr: {
set: function(val){
webshims.data(this, 'bustedNoValidate', ''+val);
@@ -449,10 +483,26 @@
return $.attr(this, 'novalidate') != null;
}
}
});
+webshims.defineNodeNamesProperty(['input', 'textarea'], 'minLength', {
+ prop: {
+ set: function(val){
+ val *= 1;
+ if(val < 0){
+ throw('INDEX_SIZE_ERR');
+ }
+ this.setAttribute('minlength', val || 0);
+ },
+ get: function(){
+ var val = this.getAttribute('minlength');
+ return val == null ? -1 : (val * 1) || 0;
+ }
+ }
+})
+
if(Modernizr.inputtypes.date && /webkit/i.test(navigator.userAgent)){
(function(){
var noInputTriggerEvts = {updateInput: 1, input: 1},
fixInputTypes = {
@@ -503,11 +553,11 @@
setTimeout(function(){
if(e && noFocusEvents[e.type]){
focusedin = false;
}
if(input){
- input.unbind('focusout blur', unbind).unbind('input change updateInput', trigger);
+ input.off('focusout blur', unbind).off('input change updateInput', trigger);
trigger();
}
input = null;
}, 1);
@@ -546,11 +596,11 @@
webshims.addReady(function(context, contextElem){
//start constrain-validation
var focusElem;
$('form', context)
.add(contextElem.filter('form'))
- .bind('invalid', $.noop)
+ .on('invalid', $.noop)
;
try {
if(context == document && !('form' in (document.activeElement || {}))) {
focusElem = $('input[autofocus], select[autofocus], textarea[autofocus]', context).eq(0).getShadowFocusElement()[0];
@@ -722,20 +772,20 @@
formSubmitterDescriptors[attrName] = {};
}
formSubmitterDescriptors[attrName].attr = {
set: function(value){
formSubmitterDescriptors[attrName].attr._supset.call(this, value);
- $(this).unbind(eventName).on(eventName, changeSubmitter);
+ $(this).off(eventName).on(eventName, changeSubmitter);
},
get: function(){
return formSubmitterDescriptors[attrName].attr._supget.call(this);
}
};
formSubmitterDescriptors[attrName].initAttr = true;
formSubmitterDescriptors[attrName].removeAttr = {
value: function(){
- $(this).unbind(eventName);
+ $(this).off(eventName);
formSubmitterDescriptors[attrName].removeAttr._supvalue.call(this);
}
};
});
@@ -744,10 +794,13 @@
}); //webshims.ready end
webshims.register('form-shim-extend2', function($, webshims, window, document, undefined, options){
"use strict";
var emptyJ = $([]);
+var isNumber = function(string){
+ return (typeof string == 'number' || (string && string == string * 1));
+};
var getGroupElements = function(elem){
elem = $(elem);
var name;
var form;
var ret = emptyJ;
@@ -826,11 +879,11 @@
}
curLength = nowLen;
};
var remove = function(){
clearTimeout(timer);
- lastElement.unbind('.maxlengthconstraint');
+ lastElement.off('.maxlengthconstraint');
};
return function(element, maxLength){
remove();
if(maxLength > -1){
max = maxLength;
@@ -906,11 +959,11 @@
}
}
});
}
-if(!$.support.getSetAttribute && $('<form novalidate></form>').attr('novalidate') == null){
+if(('getSetAttribute' in $.support) && !$.support.getSetAttribute && $('<form novalidate></form>').attr('novalidate') == null){
webshims.defineNodeNameProperty('form', 'novalidate', {
attr: {
set: function(val){
this.setAttribute('novalidate', ''+val);
},
@@ -921,44 +974,128 @@
}
});
}
-if(Modernizr.formattribute === false || !Modernizr.fieldsetdisabled){
+if(!Modernizr.formattribute || !Modernizr.fieldsetdisabled || !Modernizr.fieldsetelements){
(function(){
-
- (function(prop, undefined){
- $.prop = function(elem, name, value){
- var ret;
- if(elem && elem.nodeType == 1 && value === undefined && $.nodeName(elem, 'form') && elem.id){
- ret = document.getElementsByName(name);
- if(!ret || !ret.length){
- ret = document.getElementById(name);
+ if(!Modernizr.fieldsetdisabled){
+ var isFieldsetGroup = /^(?:fieldset)$/i;
+ $.extend($.expr[":"], {
+ "enabled": function( elem ) {
+ return elem.disabled === false || (isFieldsetGroup.test(elem.nodeName) && elem.getAttribute('disabled') == null && !$(elem).is('fieldset[disabled] *')) ;
+ },
+
+ "disabled": function( elem ) {
+ return elem.disabled === true || (isFieldsetGroup.test(elem.nodeName) && (elem.getAttribute('disabled') != null || $(elem).is('fieldset[disabled] *')));
+ }
+ });
+
+
+ var groupControl = {
+ getElements: function(group){
+ $('input, textarea, select, button', group).each(groupControl.disable);
+ },
+ disable: function(){
+ if(!this.disabled){
+ webshims.data(this, 'groupedisabled', true);
+ this.disabled = true;
}
- if(ret){
- ret = $(ret).filter(function(){
- return $.prop(this, 'form') == elem;
- }).get();
- if(ret.length){
- return ret.length == 1 ? ret[0] : ret;
- }
+ },
+ enable: function(){
+ if(this.disabled && webshims.data(this, 'groupedisabled')){
+ webshims.data(this, 'groupedisabled', false);
+ this.disabled = false;
}
}
- return prop.apply(this, arguments);
};
- })($.prop, undefined);
+
+ $(window).on('unload', function(){
+ $('input, textarea, select, button').each(groupControl.enable);
+ });
+
+ webshims.defineNodeNamesBooleanProperty(['fieldset'], 'disabled', {
+ set: function(value){
+
+ if(value){
+ $('input, textarea, select, button', this).each(groupControl.disable);
+ } else if(!$(this).is('fieldset[disabled] *')){
+ var nested = $('fieldset[disabled]', this);
+ var elements = $('input, textarea, select, button', this);
+ if(nested.length){
+ elements = elements.filter(':not(fieldset[disabled] *');
+ }
+ elements.each(groupControl.enable);
+ }
+ },
+ initAttr: true
+ });
+
+ ['input', 'textarea', 'select', 'button'].forEach(function(nodeName){
+ var desc = webshims.defineNodeNameProperty(nodeName, 'disabled', {
+ prop: {
+ set: function(value){
+ if(value){
+ webshims.data(this, 'groupedisabled', false);
+ desc.prop._supset.call(this, value);
+ } else if($(this).is('fieldset[disabled] *')){
+ webshims.data(this, 'groupedisabled', true);
+ desc.prop._supset.call(this, true);
+ } else {
+ webshims.data(this, 'groupedisabled', false);
+ desc.prop._supset.call(this, value);
+ }
+ },
+ get: function(){
+ var ret = desc.prop._supget.call(this);
+ return ret ? !webshims.data(this, 'groupedisabled') : ret;
+ }
+ },
+ removeAttr: {
+ value: function(){
+ desc.set.call(this, false);
+ }
+ }
+ });
+ });
+
+ webshims.addReady(function(context){
+ $(context).filter('fieldset[disabled], fieldset[disabled] *').each(groupControl.disable);
+ });
+ }
- var removeAddedElements = function(form){
- var elements = $.data(form, 'webshimsAddedElements');
- if(elements){
- elements.remove();
- $.removeData(form, 'webshimsAddedElements');
- }
- };
-
if(!Modernizr.formattribute){
+ (function(prop, undefined){
+ $.prop = function(elem, name, value){
+ var ret;
+ if(elem && elem.nodeType == 1 && value === undefined && $.nodeName(elem, 'form') && elem.id){
+ ret = document.getElementsByName(name);
+ if(!ret || !ret.length){
+ ret = document.getElementById(name);
+ }
+ if(ret){
+ ret = $(ret).filter(function(){
+ return $.prop(this, 'form') == elem;
+ }).get();
+ if(ret.length){
+ return ret.length == 1 ? ret[0] : ret;
+ }
+ }
+ }
+ return prop.apply(this, arguments);
+ };
+ })($.prop, undefined);
+
+ var removeAddedElements = function(form){
+ var elements = $.data(form, 'webshimsAddedElements');
+ if(elements){
+ elements.remove();
+ $.removeData(form, 'webshimsAddedElements');
+ }
+ };
+
webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
prop: {
get: function(){
var form = webshims.contentAttr(this, 'form');
if(form){
@@ -1051,13 +1188,41 @@
}, 9);
}
}
});
});
+
+ if(!$.fn.finish && parseFloat($.fn.jquery, 10) < 1.9){
+ var rCRLF = /\r?\n/g,
+ rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
+ rselectTextarea = /^(?:select|textarea)/i;
+ $.fn.serializeArray = function() {
+ return this.map(function(){
+ var elements = $.prop(this, 'elements');
+ return elements ? $.makeArray( elements ) : this;
+ })
+ .filter(function(){
+ return this.name && !$(this).is(':disabled') &&
+ ( this.checked || rselectTextarea.test( this.nodeName ) ||
+ rinput.test( this.type ) );
+ })
+ .map(function( i, elem ){
+ var val = $( this ).val();
+
+ return val == null ?
+ null :
+ $.isArray( val ) ?
+ $.map( val, function( val, i ){
+ return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+ }) :
+ { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+ }).get();
+ };
+ }
}
- if(!Modernizr.fieldsetdisabled){
+ if(!Modernizr.fieldsetelements){
webshims.defineNodeNamesProperty(['fieldset'], 'elements', {
prop: {
get: function(){
//add listed elements without keygen, object, output
return $('input, select, textarea, button, fieldset', this).get() || [];
@@ -1065,38 +1230,10 @@
writeable: false
}
});
}
- if(!$.fn.finish && parseFloat($.fn.jquery, 10) < 1.9){
- var rCRLF = /\r?\n/g,
- rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
- rselectTextarea = /^(?:select|textarea)/i;
- $.fn.serializeArray = function() {
- return this.map(function(){
- var elements = $.prop(this, 'elements');
- return elements ? $.makeArray( elements ) : this;
- })
- .filter(function(){
- return this.name && !this.disabled &&
- ( this.checked || rselectTextarea.test( this.nodeName ) ||
- rinput.test( this.type ) );
- })
- .map(function( i, elem ){
- var val = $( this ).val();
-
- return val == null ?
- null :
- $.isArray( val ) ?
- $.map( val, function( val, i ){
- return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
- }) :
- { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
- }).get();
- };
- }
-
})();
}
if($('<input />').prop('labels') == null){
webshims.defineNodeNamesProperty('button, input, keygen, meter, output, progress, select, textarea', 'labels', {
@@ -1319,10 +1456,122 @@
;
});
})();
}
+if(!('setSelectionRange' in document.createElement('input'))){
+ (function(){
+ var getSelection = function(elem, getStart){
+ var range, value, normalizedValue, textInputRange, len, endRange;
+ var start = 0;
+ var end = 0;
+ if (document.selection && (range = document.selection.createRange()) && range.parentElement() == elem) {
+ value = $.prop(elem, 'value');
+ len = value.length;
+ normalizedValue = value.replace(/\r\n/g, "\n");
+
+ textInputRange = elem.createTextRange();
+ textInputRange.moveToBookmark(range.getBookmark());
+
+
+ endRange = elem.createTextRange();
+ endRange.collapse(false);
+
+ if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
+ start = end = len;
+ } else {
+ if(getStart){
+ start = -textInputRange.moveStart("character", -len);
+ start += normalizedValue.slice(0, start).split("\n").length - 1;
+ } else {
+ if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
+ end = len;
+ } else {
+ end = -textInputRange.moveEnd("character", -len);
+ end += normalizedValue.slice(0, end).split("\n").length - 1;
+ }
+ }
+
+ }
+ }
+ return {
+ start: start,
+ end: end
+ };
+ };
+
+ ['input', 'textarea'].forEach(function(name){
+ var isTextarea = name == 'textarea';
+ //email?
+ var allowedTypes = {text: 1, search: 1, url: 1, tel: 1, password: 1, email: 1};
+ var error = 'InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. selection not allowed on this type';
+ webshims.defineNodeNameProperties(name, {
+ selectionStart: {
+ get: function(){
+ if(isTextarea || allowedTypes[$.prop(this, 'type')]){
+ return getSelection(this, true).start;
+ }
+ webshims.error(error);
+ },
+ set: function(v){
+ if(this.createTextRange && (isTextarea || allowedTypes[$.prop(this, 'type')])){
+ var range = this.createTextRange();
+ range.collapse(true);
+ range.moveStart('character', v);
+ range.moveEnd('character', $.prop(this, 'selectionEnd'));
+ if($(this).is(':focus')){
+ range.select();
+ }
+ } else {
+ webshims.error(error);
+ }
+ }
+ },
+ selectionEnd: {
+ get: function(){
+ if(isTextarea || allowedTypes[$.prop(this, 'type')]){
+ return getSelection(this).end;
+ }
+ webshims.error(error);
+ },
+ set: function(v){
+ if(this.createTextRange && (isTextarea || allowedTypes[$.prop(this, 'type')])){
+ var range = this.createTextRange();
+ var start;
+ range.collapse(true);
+ start = getSelection(this, true).start;
+ range.moveStart('character', start);
+ range.moveEnd('character', v - start);
+ if($(this).is(':focus')){
+ range.select();
+ }
+ } else {
+ webshims.error(error);
+ }
+ }
+ },
+ setSelectionRange: {
+ value: function(start, end, dir){
+ if(this.createTextRange && (isTextarea || allowedTypes[$.prop(this, 'type')])){
+ var range = this.createTextRange();
+ range.collapse(true);
+ range.moveStart('character', start);
+ range.moveEnd('character', end - start);
+ if($(this).is(':focus')){
+ range.select();
+ }
+ } else {
+ webshims.error(error);
+ }
+ }
+ }
+ }, 'prop');
+ });
+
+ })();
+}
+
(function(){
if(options.noPlaceholderPolyfill){return;}
var bustedPlaceholder;
Modernizr.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
if(Modernizr.input.placeholder && options.overridePlaceholder){
@@ -1355,28 +1604,18 @@
}
var isOver = (webshims.cfg.forms.placeholderType == 'over');
var isResponsive = (webshims.cfg.forms.responsivePlaceholder);
var polyfillElements = ['textarea'];
- var debug = webshims.debug !== false;
if(!Modernizr.input.placeholder || bustedPlaceholder){
polyfillElements.push('input');
}
var setSelection = function(elem){
try {
- if(elem.setSelectionRange){
- elem.setSelectionRange(0, 0);
- return true;
- } else if(elem.createTextRange){
- var range = elem.createTextRange();
- range.collapse(true);
- range.moveEnd('character', 0);
- range.moveStart('character', 0);
- range.select();
- return true;
- }
+ $(elem).setSelectionRange(0,0);
+ return true;
} catch(er){}
};
var hidePlaceholder = function(elem, data, value, _onFocus){
if(value === false){
@@ -1394,22 +1633,22 @@
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
elem.value = $.prop(elem, 'value');
data.box.removeClass('placeholder-visible');
clearTimeout(selectTimer);
- $(elem).unbind('.placeholderremove');
+ $(elem).off('.placeholderremove');
},
'mousedown.placeholderremove drag.placeholderremove select.placeholderremove': function(e){
setSelection(elem);
clearTimeout(selectTimer);
selectTimer = setTimeout(function(){
setSelection(elem);
}, 9);
},
'blur.placeholderremove': function(){
clearTimeout(selectTimer);
- $(elem).unbind('.placeholderremove');
+ $(elem).off('.placeholderremove');
}
})
;
return;
} else if(!_onFocus && !value && elem.value){ //especially on submit
@@ -1420,14 +1659,14 @@
.off('.placeholderremove')
.on({
'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
data.box.removeClass('placeholder-visible');
- $(elem).unbind('.placeholderremove');
+ $(elem).off('.placeholderremove');
},
'blur.placeholderremove': function(){
- $(elem).unbind('.placeholderremove');
+ $(elem).off('.placeholderremove');
}
})
;
return;
}
@@ -1451,11 +1690,11 @@
var isVisible = $(elem).hasClass('placeholder-visible');
if(placeholderTxt === false){
placeholderTxt = $.attr(elem, 'placeholder') || '';
}
- $(elem).unbind('.placeholderremove');
+ $(elem).off('.placeholderremove');
if(value === false){
value = $.prop(elem, 'value');
}
@@ -1524,14 +1763,14 @@
if(elem.type == 'password' || isOver){
data.text = createPlaceholder(elem);
if(isResponsive || $(elem).is('.responsive-width') || (elem.currentStyle || {width: ''}).width.indexOf('%') != -1){
data.box = data.text;
} else {
- data.box = $(elem)
- .wrap('<span class="placeholder-box placeholder-box-'+ (elem.nodeName || '').toLowerCase() +' placeholder-box-'+$.css(elem, 'float')+'" />')
- .parent()
+ data.box = $('<span class="placeholder-box placeholder-box-'+ (elem.nodeName || '').toLowerCase() +' placeholder-box-'+$.css(elem, 'float')+'" />')
+ .insertAfter(elem)
;
+ data.box.append(elem);
}
data.text
.insertAfter(elem)
.on('mousedown.placeholder', function(){
changePlaceholderVisibility(this, false, false, data, 'focus');
@@ -1782,11 +2021,11 @@
extraTest = function(){
clearTimeout(extraTimer);
extraTimer = setTimeout(trigger, 9);
},
unbind = function(){
- input.unbind('focusout', unbind).unbind('keyup keypress keydown paste cut', extraTest).unbind('input change updateInput triggerinput', trigger);
+ input.off('focusout', unbind).off('keyup keypress keydown paste cut', extraTest).off('input change updateInput triggerinput', trigger);
clearInterval(timer);
setTimeout(function(){
trigger();
input = null;
}, 1);
@@ -1814,6 +2053,6 @@
;
})();
})();
-});
\ No newline at end of file
+});