]> source.dussan.org Git - jquery.git/commitdiff
Clean up regexen; use common regex for numbers. Close gh-862.
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 23 Jul 2012 02:23:32 +0000 (22:23 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 23 Jul 2012 02:23:32 +0000 (22:23 -0400)
src/ajax.js
src/attributes.js
src/core.js
src/css.js
src/deprecated.js
src/effects.js
src/event.js
src/manipulation.js

index 053bd696bb01baef0cbd192fe96eab6b16a4af10..304a41d4819243a3154127399bab649e7223c72d 100644 (file)
@@ -12,7 +12,7 @@ var // Document location
        rquery = /\?/,
        rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
        rts = /([?&])_=[^&]*/,
-       rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
+       rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,
 
        // Keep a copy of the old load method
        _load = jQuery.fn.load,
index c3890c459b1c3215643488162a30053ac992691c..e10ddced76d93df00e6b15abe1f16c90a5380e75 100644 (file)
@@ -1,9 +1,9 @@
 var nodeHook, boolHook, fixSpecified,
-       rclass = /[\n\t\r]/g,
+       rclass = /[\t\r\n]/g,
        rreturn = /\r/g,
        rtype = /^(?:button|input)$/i,
        rfocusable = /^(?:button|input|object|select|textarea)$/i,
-       rclickable = /^a(?:rea)?$/i,
+       rclickable = /^a(?:rea|)$/i,
        rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
        getSetAttribute = jQuery.support.getSetAttribute;
 
index 01a3019e758d2edc126be3e2186b9b5fa30fcb1d..89e25978cd31eaf34eb83826e49e1f82649b765a 100644 (file)
@@ -30,6 +30,9 @@ var
                return new jQuery.fn.init( selector, context, rootjQuery );
        },
 
+       // Used for matching numbers
+       core_pnum = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,
+
        // Used for detecting and trimming whitespace
        core_rnotwhite = /\S/,
        core_rspace = /\s+/,
@@ -42,13 +45,13 @@ var
        rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
 
        // Match a standalone tag
-       rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
+       rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
 
        // JSON RegExp
        rvalidchars = /^[\],:{}\s]*$/,
        rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
        rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
-       rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
+       rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,
 
        // Matches dashed string for camelizing
        rmsPrefix = /^-ms-/,
index 41b978542e4fac7e4831dc736a590b56b9b51c9c..0b20b7c4c4849affcac71b0bf8fdaf924e588087 100644 (file)
@@ -1,25 +1,24 @@
 var curCSS, iframe, iframeDoc,
        ralpha = /alpha\([^)]*\)/i,
        ropacity = /opacity=([^)]*)/,
-       rnumsplit = /^([\-+]?(?:\d*\.)?\d+)(.*)$/i,
-       rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
-       rrelNum = /^([\-+])=([\-+.\de]+)/,
+       rposition = /^(top|right|bottom|left)$/,
        rmargin = /^margin/,
+       rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ),
+       rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ),
+       rrelNum = new RegExp( "^([-+])=(" + core_pnum + ")", "i" ),
        elemdisplay = {},
-       cssShow = { position: "absolute", visibility: "hidden", display: "block" },
-
-       // order is important!
-       cssExpand = [ "Top", "Right", "Bottom", "Left" ],
-       cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
-       rposition = /^(top|right|bottom|left)$/,
-
-       eventsToggle = jQuery.fn.toggle,
 
+       cssShow = { position: "absolute", visibility: "hidden", display: "block" },
        cssNormalTransform = {
                letterSpacing: 0,
                fontWeight: 400,
                lineHeight: 1
-       };
+       },
+
+       cssExpand = [ "Top", "Right", "Bottom", "Left" ],
+       cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
+
+       eventsToggle = jQuery.fn.toggle;
 
 // return a css property mapped to a potentially vendor prefixed property
 function vendorPropName( style, name ) {
index d165a872431bd0eb3f934497ddbcbf6146ee01be..331755ff383085e9f884021ecef9ebd4a14c05bb 100644 (file)
@@ -11,9 +11,9 @@ jQuery.uaMatch = function( ua ) {
 
        var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
                /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
-               /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
+               /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
                /(msie) ([\w.]+)/.exec( ua ) ||
-               ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
+               ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
                [];
 
        return {
index 8ab41cbd346f368710297f0619d637dfe99dfbd9..dbca88650587d360cb86c34b912a30580cacf537 100644 (file)
@@ -1,6 +1,6 @@
 var fxNow, timerId,
        rfxtypes = /^(?:toggle|show|hide)$/,
-       rfxnum = /^(?:([\-+])=)?([\d+.\-]+)([a-z%]*)$/i,
+       rfxnum = new RegExp( "^(?:([-+])=|)(" + core_pnum + ")([a-z%]*)$", "i" ),
        rrun = /queueHooks$/,
        animationPrefilters = [ defaultPrefilter ],
        tweeners = {
index c3f164e6d81fc9ff160f99d2a660494989370fc8..4703306ca15fe5faf42a45c0bf5462488fc4f59b 100644 (file)
@@ -1,6 +1,6 @@
 var rformElems = /^(?:textarea|input|select)$/i,
-       rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/,
-       rhoverHack = /(?:^|\s)hover(\.\S+)?\b/,
+       rtypenamespace = /^([^\.]*|)(?:\.(.+)|)$/,
+       rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
        rkeyEvent = /^key/,
        rmouseEvent = /^(?:mouse|contextmenu)|click/,
        rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
@@ -157,7 +157,7 @@ jQuery.event = {
                        type = ( selector? special.delegateType : special.bindType ) || type;
                        eventType = events[ type ] || [];
                        origCount = eventType.length;
-                       namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
+                       namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
 
                        // Remove matching events
                        for ( j = 0; j < eventType.length; j++ ) {
@@ -254,7 +254,7 @@ jQuery.event = {
                event.isTrigger = true;
                event.exclusive = exclusive;
                event.namespace = namespaces.join( "." );
-               event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
+               event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
                ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
 
                // Handle a global trigger
index b248f51b8136f3e6457f7194dd67312c38c56198..d118529d489c6e380abda6172fd7ec78e0d364a6 100644 (file)
@@ -14,7 +14,7 @@ function createSafeFragment( document ) {
 
 var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
                "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
-       rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
+       rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
        rleadingWhitespace = /^\s+/,
        rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
        rtagName = /<([\w:]+)/,