Created
April 24, 2015 02:20
-
-
Save arschmitz/bdb1b501f2a18f22b609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| formParent: function() { | |
| var parent; | |
| if ( this[ 0 ].form && typeof this[ 0 ].form !== "string" ) { | |
| return $( this[ 0 ].form ); | |
| } else if ( !this[ 0 ].form ) { | |
| return; | |
| } | |
| // Support: IE8 only ( the rest of the method ) | |
| // IE8 supports the form property, but not the form attribute, worse yet if you supply the | |
| // form attribute it overwrites the form property with the string. Other supported browsers | |
| // like all other IE's and Android 2.3 support the form attribute not at all or partially. | |
| // We don't care in those cases because they still always return an element. We are not | |
| // trying to fix the form attribute here, only deal with the prop supplying a string. | |
| // we don't use document on the first line because we need to support document fragments | |
| parent = ( this[ 0 ].style ? | |
| // element within the document | |
| this[ 0 ].ownerDocument : | |
| // element is window or document | |
| this[ 0 ].document || this[ 0 ] ).getElementByID( element.form ); | |
| if ( parent ) { | |
| return $( parent ); | |
| } | |
| parent = this.closest( "form" ); | |
| if ( parent.length ) { | |
| return parent; | |
| } | |
| return; | |
| }, | |
| _findLabel: function() { | |
| var ancestor, labelSelector, id, | |
| parent; | |
| // Check control.labels first | |
| if ( this.element[ 0 ].labels !== undefined && this.element[ 0 ].labels.length > 0 ) { | |
| this.label = $( this.element[ 0 ].labels[ 0 ] ); | |
| return; | |
| } | |
| // Support: IE <= 11, FF <= 37, Android <=2.3 only | |
| // Above browsers do not support control.labels everything below is to support them | |
| // as well as document fragments control.labels does not work on document fragments anywhere | |
| parent = this.element.closest( "label" ); | |
| // Check if the input has a parent thats a label | |
| if ( parent.length > 0 ) { | |
| this.label = parent; | |
| this.parentLabel = true; | |
| return; | |
| } | |
| // We don't search against the document in case the element | |
| // is disconnected from the DOM | |
| ancestor = this.element.parents().last(); | |
| // Look for the label based on the id | |
| id = this.element.attr( "id" ); | |
| if ( id ) { | |
| labelSelector = "label[for='" + | |
| this.element.attr( "id" ).replace( escapeId, "\\$1" ) + "']"; | |
| this.label = ancestor.find( labelSelector ); | |
| if ( !this.label.length ) { | |
| // The label was not found, make sure ancestors exist. If they do check their | |
| // siblings, if they dont check the elements siblings | |
| ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings(); | |
| // Check if any of the new set of ancestors is the label | |
| this.label = ancestor.filter( labelSelector ); | |
| if ( !this.label.length ) { | |
| // Still not found look inside the ancestors for the label | |
| this.label = ancestor.find( labelSelector ); | |
| } | |
| } | |
| } | |
| if ( !this.label || !this.label.length ) { | |
| $.error( "No label found for checkboxradio widget" ); | |
| } | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment