ffffng/app/bower_components/jquery/src/attributes/prop.js

144 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-05-13 13:25:33 +02:00
define( [
2014-05-12 20:08:19 +02:00
"../core",
"../core/access",
2017-05-13 13:25:33 +02:00
"./support",
"../selector"
2014-05-12 20:08:19 +02:00
], function( jQuery, access, support ) {
2017-05-13 13:25:33 +02:00
"use strict";
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
var rfocusable = /^(?:input|select|textarea|button)$/i,
rclickable = /^(?:a|area)$/i;
jQuery.fn.extend( {
2014-05-12 20:08:19 +02:00
prop: function( name, value ) {
return access( this, jQuery.prop, name, value, arguments.length > 1 );
},
removeProp: function( name ) {
2017-05-13 13:25:33 +02:00
return this.each( function() {
2014-05-12 20:08:19 +02:00
delete this[ jQuery.propFix[ name ] || name ];
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
jQuery.extend( {
2014-05-12 20:08:19 +02:00
prop: function( elem, name, value ) {
2017-05-13 13:25:33 +02:00
var ret, hooks,
2014-05-12 20:08:19 +02:00
nType = elem.nodeType;
2016-05-16 13:33:49 +02:00
// Don't get/set properties on text, comment and attribute nodes
2017-05-13 13:25:33 +02:00
if ( nType === 3 || nType === 8 || nType === 2 ) {
2014-05-12 20:08:19 +02:00
return;
}
2017-05-13 13:25:33 +02:00
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
2014-05-12 20:08:19 +02:00
// Fix name and attach hooks
name = jQuery.propFix[ name ] || name;
hooks = jQuery.propHooks[ name ];
}
if ( value !== undefined ) {
2017-05-13 13:25:33 +02:00
if ( hooks && "set" in hooks &&
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
return ret;
}
return ( elem[ name ] = value );
}
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
return ret;
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
return elem[ name ];
2014-05-12 20:08:19 +02:00
},
propHooks: {
tabIndex: {
get: function( elem ) {
2017-05-13 13:25:33 +02:00
// Support: IE <=9 - 11 only
// elem.tabIndex doesn't always return the
// correct value when it hasn't been explicitly set
// https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
// Use proper attribute retrieval(#12072)
var tabindex = jQuery.find.attr( elem, "tabindex" );
if ( tabindex ) {
return parseInt( tabindex, 10 );
}
if (
rfocusable.test( elem.nodeName ) ||
rclickable.test( elem.nodeName ) &&
elem.href
) {
return 0;
}
return -1;
2014-05-12 20:08:19 +02:00
}
}
2017-05-13 13:25:33 +02:00
},
propFix: {
"for": "htmlFor",
"class": "className"
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Support: IE <=11 only
// Accessing the selectedIndex property
// forces the browser to respect setting selected
// on the option
// The getter ensures a default option is selected
// when in an optgroup
// eslint rule "no-unused-expressions" is disabled for this code
// since it considers such accessions noop
2014-05-12 20:08:19 +02:00
if ( !support.optSelected ) {
jQuery.propHooks.selected = {
get: function( elem ) {
2017-05-13 13:25:33 +02:00
/* eslint no-unused-expressions: "off" */
2014-05-12 20:08:19 +02:00
var parent = elem.parentNode;
if ( parent && parent.parentNode ) {
parent.parentNode.selectedIndex;
}
return null;
2017-05-13 13:25:33 +02:00
},
set: function( elem ) {
/* eslint no-unused-expressions: "off" */
var parent = elem.parentNode;
if ( parent ) {
parent.selectedIndex;
if ( parent.parentNode ) {
parent.parentNode.selectedIndex;
}
}
2014-05-12 20:08:19 +02:00
}
};
}
2017-05-13 13:25:33 +02:00
jQuery.each( [
2014-05-12 20:08:19 +02:00
"tabIndex",
"readOnly",
"maxLength",
"cellSpacing",
"cellPadding",
"rowSpan",
"colSpan",
"useMap",
"frameBorder",
"contentEditable"
], function() {
jQuery.propFix[ this.toLowerCase() ] = this;
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
} );