webshims.register('form-shim-extend', function($, webshims, window, document, undefined, options){ "use strict"; webshims.inputTypes = webshims.inputTypes || {}; //some helper-functions var cfg = webshims.cfg.forms; var bugs = webshims.bugs; var isNumber = function(string){ return (typeof string == 'number' || (string && string == string * 1)); }, typeModels = webshims.inputTypes, checkTypes = { radio: 1, checkbox: 1 }, getType = function(elem){ return (elem.getAttribute('type') || elem.type || '').toLowerCase(); } ; (function(){ if('querySelector' in document){ try { bugs.findRequired = !($('
').prop('labels') == null){ webshims.defineNodeNamesProperty('button, input, keygen, meter, output, progress, select, textarea', 'labels', { prop: { get: function(){ if(this.type == 'hidden'){return null;} var id = this.id; var labels = $(this) .closest('label') .filter(function(){ var hFor = (this.attributes['for'] || {}); return (!hFor.specified || hFor.value == id); }) ; if(id) { labels = labels.add('label[for="'+ id +'"]'); } return labels.get(); }, writeable: false } }); } if(!('value' in document.createElement('progress'))){ (function(){ var nan = parseInt('NaN', 10); var updateProgress = function(progress){ var position = $.prop(progress, 'position'); $.attr(progress, 'data-position', position); $('> span', progress).css({width: (position < 0 ? 100 : position * 100) +'%'}); }; var desc = { position: { prop: { get: function(){ var max; //jQuery 1.8.x try's to normalize "0" to 0 var val = this.getAttribute('value'); var ret = -1; val = val ? (val * 1) : nan; if(!isNaN(val)){ max = $.prop(this, 'max'); ret = Math.max(Math.min(val / max, 1), 0); if(updateProgress.isInChange){ $.attr(this, 'aria-valuenow', ret * 100); if(updateProgress.isInChange == 'max'){ $.attr(this, 'aria-valuemax', max); } } $(this).removeClass('ws-indeterminate'); } else if(updateProgress.isInChange) { $(this).removeAttr('aria-valuenow').addClass('ws-indeterminate'); } return ret; }, writeable: false } } }; $.each({value: 0, max: 1}, function(name, defValue){ var removeProp = (name == 'value' && !$.fn.finish); desc[name] = { attr: { set: function(value){ var ret = desc[name].attr._supset.call(this, value); updateProgress.isInChange = name; updateProgress(this); updateProgress.isInChange = false; return ret; } }, removeAttr: { value: function(){ this.removeAttribute(name); if(removeProp){ try { delete this.value; } catch(er){} } updateProgress.isInChange = name; updateProgress(this); updateProgress.isInChange = false; } }, prop: { get: function(){ var max; var ret = (desc[name].attr.get.call(this) * 1); if(ret < 0 || isNaN(ret)){ ret = defValue; } else if(name == 'value'){ ret = Math.min(ret, $.prop(this, 'max')); } else if(ret === 0){ ret = defValue; } return ret; }, set: function(value){ value = value * 1; if(isNaN(value)){ webshims.error('Floating-point value is not finite.'); } return desc[name].attr.set.call(this, value); } } }; }); webshims.createElement( 'progress', function(){ var labels = $(this) .attr({role: 'progressbar', 'aria-valuemin': '0'}) .html('') .jProp('labels') .map(function(){ return webshims.getID(this); }) .get() ; if(labels.length){ $.attr(this, 'aria-labelledby', labels.join(' ')); } else { webshims.info("you should use label elements for your prgogress elements"); } if($(this).css('direction') == 'rtl'){ $(this).addClass('ws-is-rtl'); } updateProgress.isInChange = 'max'; updateProgress(this); updateProgress.isInChange = false; }, desc ); })(); } try { document.querySelector(':checked'); } catch(er){ (function(){ $('html').addClass('no-csschecked'); var checkInputs = { radio: 1, checkbox: 1 }; var selectChange = function(){ var options = this.options || []; var i, len, option; for(i = 0, len = options.length; i < len; i++){ option = $(options[i]); option[$.prop(options[i], 'selected') ? 'addClass' : 'removeClass']('prop-checked'); } }; var checkChange = function(){ var fn = $.prop(this, 'checked') ? 'addClass' : 'removeClass'; var className = this.className || ''; var parent; //IE8- has problems to update styles, we help if( (className.indexOf('prop-checked') == -1) == (fn == 'addClass')){ $(this)[fn]('prop-checked'); if((parent = this.parentNode)){ parent.className = parent.className; } } }; webshims.onNodeNamesPropertyModify('select', 'value', selectChange); webshims.onNodeNamesPropertyModify('select', 'selectedIndex', selectChange); webshims.onNodeNamesPropertyModify('option', 'selected', function(){ $(this).closest('select').each(selectChange); }); webshims.onNodeNamesPropertyModify('input', 'checked', function(value, boolVal){ var type = this.type; if(type == 'radio' && boolVal){ getGroupElements(this).each(checkChange); } else if(checkInputs[type]) { $(this).each(checkChange); } }); $(document).on('change', function(e){ if(checkInputs[e.target.type]){ if(e.target.type == 'radio'){ getGroupElements(e.target).each(checkChange); } else { $(e.target)[$.prop(e.target, 'checked') ? 'addClass' : 'removeClass']('prop-checked'); } } else if(e.target.nodeName.toLowerCase() == 'select'){ $(e.target).each(selectChange); } }); webshims.addReady(function(context, contextElem){ $('option, input', context) .add(contextElem.filter('option, input')) .each(function(){ var prop; if(checkInputs[this.type]){ prop = 'checked'; } else if(this.nodeName.toLowerCase() == 'option'){ prop = 'selected'; } if(prop){ $(this)[$.prop(this, prop) ? 'addClass' : 'removeClass']('prop-checked'); } }) ; }); })(); } 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 $('