vendor/assets/javascripts/webshims/shims/form-shim-extend2.js in webshims-rails-1.14.3 vs vendor/assets/javascripts/webshims/shims/form-shim-extend2.js in webshims-rails-1.14.4
- old
+ new
@@ -1,11 +1,11 @@
webshims.register('form-shim-extend2', function($, webshims, window, document, undefined, options){
"use strict";
var isNumber = function(string){
return (typeof string == 'number' || (string && string == string * 1));
};
-
+ var support = webshims.support;
//support getSetAttribute
var supportGetSetAttribute = !(('getSetAttribute' in $.support) && !$.support.getSetAttribute);
//submitbubbles for IE6-IE8
var supportSubmitBubbles = !('submitBubbles' in $.support) || $.support.submitBubbles;
var addSubmitBubbles = function(form){
@@ -151,13 +151,13 @@
}
});
}
- if(!Modernizr.formattribute || !Modernizr.fieldsetdisabled || !Modernizr.fieldsetelements){
+ if(!support.fieldsetdisabled || !support.fieldsetelements){
(function(){
- if(!Modernizr.fieldsetdisabled){
+ if(!support.fieldsetdisabled){
var isFieldsetGroup = {
fieldset: 1,
FIELDSET: 1
};
var disableElementsSel = 'input, textarea, select, button';
@@ -248,198 +248,197 @@
;
});
}
- if(!Modernizr.formattribute){
- (function(prop, undefined){
- var isForm = {form: 1, FORM: 1};
- $.prop = function(elem, name, value){
- var ret;
- //TODO: cache + perftest
- if(elem && elem.nodeType == 1 && value === undefined && isForm[elem.nodeName] && elem.id){
- ret = document.getElementsByName(name);
- if(!ret || !ret.length){
- ret = document.getElementById(name);
+ (function(prop, undefined){
+ var isForm = {form: 1, FORM: 1};
+ $.prop = function(elem, name, value){
+ var ret;
+ //TODO: cache + perftest
+ if(elem && elem.nodeType == 1 && value === undefined && isForm[elem.nodeName] && 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;
}
- 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');
}
+ return prop.apply(this, arguments);
};
+ })($.prop, undefined);
- var getAssociatedForm = function () {
- var form = webshims.contentAttr(this, 'form');
- if(form){
- form = document.getElementById(form);
- if(form && !$.nodeName(form, 'form')){
- form = null;
- }
+ var removeAddedElements = function(form){
+ var elements = $.data(form, 'webshimsAddedElements');
+ if(elements){
+ elements.remove();
+ $.removeData(form, 'webshimsAddedElements');
+ }
+ };
+
+ var getAssociatedForm = function () {
+ var form = webshims.contentAttr(this, 'form');
+ if(form){
+ form = document.getElementById(form);
+ if(form && !$.nodeName(form, 'form')){
+ form = null;
}
- return form || this.form;
- };
- webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
- prop: {
- get: getAssociatedForm,
- writeable: false
- }
- });
+ }
+ return form || this.form;
+ };
+ webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
+ prop: {
+ get: getAssociatedForm,
+ writeable: false
+ }
+ });
- webshims.defineNodeNamesProperty(['form'], 'elements', {
- prop: {
- get: function(){
- //TODO: cache + perftest
- var sel, addElements, detachElements, formElements, i, len;
- var id = this.id;
- var elements = [];
- if(id){
- detachElements = $.data(this, 'webshimsAddedElements');
- if(detachElements){
- detachElements.detach();
- }
+ webshims.defineNodeNamesProperty(['form'], 'elements', {
+ prop: {
+ get: function(){
+ //TODO: cache + perftest
+ var sel, addElements, detachElements, formElements, i, len;
+ var id = this.id;
+ var elements = [];
+ if(id){
+ detachElements = $.data(this, 'webshimsAddedElements');
+ if(detachElements){
+ detachElements.detach();
}
+ }
- formElements = this.elements;
+ formElements = this.elements;
- if(this.querySelector('input[form], select[form], textarea[form]')){
- for(i = 0, len = formElements.length; i < len; i++){
- if(getAssociatedForm.call(formElements[i]) == this){
- elements.push(formElements[i]);
- }
+ if(this.querySelector('input[form], select[form], textarea[form]')){
+ for(i = 0, len = formElements.length; i < len; i++){
+ if(getAssociatedForm.call(formElements[i]) == this){
+ elements.push(formElements[i]);
}
- } else {
- elements = $.makeArray(formElements);
}
+ } else {
+ elements = $.makeArray(formElements);
+ }
- if(id){
- sel = 'input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"], button[form="'+ id +'"], fieldset[form="'+ id +'"]';
- addElements = document.querySelectorAll(sel) || [];
- if(addElements.length){
- elements = $(elements).add(addElements).get();
+ if(id){
+ sel = 'input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"], button[form="'+ id +'"], fieldset[form="'+ id +'"]';
+ addElements = document.querySelectorAll(sel) || [];
+ if(addElements.length){
+ elements = $(elements).add(addElements).get();
- }
- if(detachElements){
- detachElements.appendTo(this);
- }
}
- return elements;
- },
- writeable: false
- }
- });
+ if(detachElements){
+ detachElements.appendTo(this);
+ }
+ }
+ return elements;
+ },
+ writeable: false
+ }
+ });
- $(function(){
- var stopPropagation = function(e){
- e.stopPropagation();
- };
- var submitters = {
- image: 1,
- submit: 1
- };
- $(document).on('submit', function(e){
+ $(function(){
+ var stopPropagation = function(e){
+ e.stopPropagation();
+ };
+ var submitters = {
+ image: 1,
+ submit: 1
+ };
+ $(document).on('submit', function(e){
- if(!e.isDefaultPrevented()){
- var form = e.target;
- var id = form.id;
- var elements;
+ if(!e.isDefaultPrevented()){
+ var form = e.target;
+ var id = form.id;
+ var elements;
- if(id){
- removeAddedElements(form);
- elements = document.querySelectorAll('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"]');
- elements = $(elements)
- .filter(function(){
- return !this.disabled && this.name && this.form != form;
- })
- .clone()
- ;
- if(elements.length){
- $.data(form, 'webshimsAddedElements', $('<div class="webshims-visual-hide" />').append(elements).appendTo(form));
- setTimeout(function(){
- removeAddedElements(form);
- }, 9);
- }
- elements = null;
+ if(id){
+ removeAddedElements(form);
+ elements = document.querySelectorAll('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"]');
+ elements = $(elements)
+ .filter(function(){
+ return !this.disabled && this.name && this.form != form;
+ })
+ .clone()
+ ;
+ if(elements.length){
+ $.data(form, 'webshimsAddedElements', $('<div class="webshims-visual-hide" />').append(elements).appendTo(form));
+ setTimeout(function(){
+ removeAddedElements(form);
+ }, 9);
}
+ elements = null;
}
- });
+ }
+ });
- $(document).on('click', function(e){
- if(submitters[e.target.type] && !e.isDefaultPrevented() && webshims.contentAttr(e.target, 'form')){
- var trueForm = $.prop(e.target, 'form');
- var formIn = e.target.form;
- var clone;
- if(trueForm && trueForm != formIn){
- clone = $(e.target)
- .clone()
- .removeAttr('form')
- .addClass('webshims-visual-hide')
- .on('click', stopPropagation)
- .appendTo(trueForm)
- ;
- if(formIn){
- e.preventDefault();
- }
- addSubmitBubbles(trueForm);
- clone.trigger('click');
- setTimeout(function(){
- clone.remove();
- clone = null;
- }, 9);
+ $(document).on('click', function(e){
+ if(submitters[e.target.type] && !e.isDefaultPrevented() && webshims.contentAttr(e.target, 'form')){
+ var trueForm = $.prop(e.target, 'form');
+ var formIn = e.target.form;
+ var clone;
+ if(trueForm && trueForm != formIn){
+ clone = $(e.target)
+ .clone()
+ .removeAttr('form')
+ .addClass('webshims-visual-hide')
+ .on('click', stopPropagation)
+ .appendTo(trueForm)
+ ;
+ if(formIn){
+ e.preventDefault();
}
+ addSubmitBubbles(trueForm);
+ clone.trigger('click');
+ setTimeout(function(){
+ clone.remove();
+ clone = null;
+ }, 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;
+ 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 ) );
})
- .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();
+ .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();
- };
- }
+ 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.fieldsetelements){
+
+ if(!support.fieldsetelements){
webshims.defineNodeNamesProperty(['fieldset'], 'elements', {
prop: {
get: function(){
//add listed elements without keygen, object, output
return this.querySelectorAll('input, select, textarea, button, fieldset') || [];
@@ -710,15 +709,17 @@
}
(function(){
if(options.noPlaceholderPolyfill){return;}
var bustedPlaceholder;
- Modernizr.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
- if(Modernizr.input.placeholder && options.overridePlaceholder){
+ support.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
+ support.placeholder = !!('placeholder' in $('<input />')[0]);
+
+ if(support.placeholder && options.overridePlaceholder){
bustedPlaceholder = true;
}
- if(Modernizr.input.placeholder && Modernizr.textareaPlaceholder && !bustedPlaceholder){
+ if(support.placeholder && support.textareaPlaceholder && !bustedPlaceholder){
(function(){
var ua = navigator.userAgent;
if(ua.indexOf('Mobile') != -1 && ua.indexOf('Safari') != -1){
$(window).on('orientationchange', (function(){
@@ -743,10 +744,10 @@
}
var isOver = (webshims.cfg.forms.placeholderType == 'over');
var isResponsive = (webshims.cfg.forms.responsivePlaceholder);
var polyfillElements = ['textarea'];
- if(!Modernizr.input.placeholder || bustedPlaceholder){
+ if(!support.placeholder || bustedPlaceholder){
polyfillElements.push('input');
}
var setSelection = function(elem){
try {