]> source.dussan.org Git - jquery-ui.git/commitdiff
Core: Move labels into its own module
authorAlexander Schmitz <arschmitz@gmail.com>
Wed, 15 Jul 2015 22:14:26 +0000 (18:14 -0400)
committerAlexander Schmitz <arschmitz@gmail.com>
Sat, 8 Aug 2015 04:29:36 +0000 (00:29 -0400)
Ref #9647

tests/unit/core/core.js
ui/button.js
ui/core.js
ui/labels.js [new file with mode: 0644]
ui/selectmenu.js

index 0d25e22d8b50dae37c26b6bed5e75268db0c9375..1eaa055e5d7936b756cf7eb9d26b85e20145c8e9 100644 (file)
@@ -2,7 +2,8 @@ define( [
        "jquery",
        "lib/common",
        "ui/core",
-       "ui/form"
+       "ui/form",
+       "ui/labels"
 ], function( $, common ) {
 
 module( "core - jQuery extensions" );
index ec6525d2b4a0ea54eaa27c1f15ec55f0cccd58a9..bc391810f205af95e2417f6bdae263f728383734 100644 (file)
@@ -22,9 +22,9 @@
                // AMD. Register as an anonymous module.
                define([
                        "jquery",
-                       "./core",
                        "./data",
                        "./keycode",
+                       "./labels",
                        "./version",
                        "./widget"
                ], factory );
index 6c948d0589d7dcdbb961f8647b11408fc6357f2f..412354151b8ff108f190250581ac0cb9b16495df 100644 (file)
                        "jquery",
                        "./data",
                        "./disable-selection",
-                       "./escape-selector",
                        "./focusable",
                        "./form",
                        "./ie",
                        "./keycode",
+                       "./labels",
                        "./version"
                ], factory );
        } else {
@@ -113,41 +113,6 @@ $.fn.extend( {
                                $( this ).removeAttr( "id" );
                        }
                } );
-       },
-
-       labels: function() {
-               var ancestor, selector, id, labels, ancestors;
-
-               // Check control.labels first
-               if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
-                       return this.pushStack( this[ 0 ].labels );
-               }
-
-               // 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
-               labels = this.eq( 0 ).parents( "label" );
-
-               // Look for the label based on the id
-               id = this.attr( "id" );
-               if ( id ) {
-
-                       // We don't search against the document in case the element
-                       // is disconnected from the DOM
-                       ancestor = this.eq( 0 ).parents().last();
-
-                       // Get a full set of top level ancestors
-                       ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
-
-                       // Create a selector for the label based on the id
-                       selector = "label[for='" + $.ui.escapeSelector( id ) + "']";
-
-                       labels = labels.add( ancestors.find( selector ).addBack( selector ) );
-
-               }
-
-               // Return whatever we have found for labels
-               return this.pushStack( labels );
        }
 } );
 
diff --git a/ui/labels.js b/ui/labels.js
new file mode 100644 (file)
index 0000000..2a78d88
--- /dev/null
@@ -0,0 +1,62 @@
+/*!
+ * jQuery UI Labels @VERSION
+ * http://jqueryui.com
+ *
+ * Copyright jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ */
+
+//>>label: labels
+//>>group: Core
+//>>description: Find all the labels associated with a given input
+//>>docs: http://api.jqueryui.com/labels/
+
+( function( factory ) {
+       if ( typeof define === "function" && define.amd ) {
+
+               // AMD. Register as an anonymous module.
+               define( [ "jquery", "./version", "./escape-selector" ], factory );
+       } else {
+
+               // Browser globals
+               factory( jQuery );
+       }
+} ( function( $ ) {
+
+return $.fn.labels = function() {
+       var ancestor, selector, id, labels, ancestors;
+
+       // Check control.labels first
+       if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
+               return this.pushStack( this[ 0 ].labels );
+       }
+
+       // 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
+       labels = this.eq( 0 ).parents( "label" );
+
+       // Look for the label based on the id
+       id = this.attr( "id" );
+       if ( id ) {
+
+               // We don't search against the document in case the element
+               // is disconnected from the DOM
+               ancestor = this.eq( 0 ).parents().last();
+
+               // Get a full set of top level ancestors
+               ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
+
+               // Create a selector for the label based on the id
+               selector = "label[for='" + $.ui.escapeSelector( id ) + "']";
+
+               labels = labels.add( ancestors.find( selector ).addBack( selector ) );
+
+       }
+
+       // Return whatever we have found for labels
+       return this.pushStack( labels );
+};
+
+} ) );
index dc8df9f1ba506df5de840d7b5a561572f65bda38..04808a87d2115a6b2e62659dd2a55d0ecfc508b7 100644 (file)
                        "./version",
                        "./escape-selector",
                        "./menu",
+                       "./keycode",
+                       "./labels",
                        "./position",
                        "./version",
-                       "./widget" ], factory );
+                       "./widget"
+               ], factory );
        } else {
 
                // Browser globals