]> source.dussan.org Git - jquery.git/commitdiff
Move parsing methods to their own files (separates manipulation dependency from core)
authorTimmy Willison <timmywillisn@gmail.com>
Mon, 9 Sep 2013 01:05:07 +0000 (21:05 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 9 Sep 2013 01:05:07 +0000 (21:05 -0400)
src/ajax.js
src/ajax/load.js
src/ajax/parseJSON.js [new file with mode: 0644]
src/ajax/parseXML.js [new file with mode: 0644]
src/core.js
src/core/parseHTML.js [new file with mode: 0644]
src/var/rsingleTag.js [new file with mode: 0644]

index 3fd882a2ff57be651a0daa06aa44272449bf7b16..7310b5e15c9ffc1e50f946b699f602738711640d 100644 (file)
@@ -3,6 +3,8 @@ define([
        "./var/rnotwhite",
        "./ajax/var/nonce",
        "./ajax/var/rquery",
+       "./ajax/parseJSON",
+       "./ajax/parseXML",
        "./deferred"
 ], function( jQuery, rnotwhite, nonce, rquery ) {
 
index 167031697cb51d80ef9acbcd9aea181a4fcd4649..3c345a02780f0491bf2f01377318447f8ed2811d 100644 (file)
@@ -1,5 +1,6 @@
 define([
        "../core",
+       "../core/parseHTML",
        "../ajax",
        "../traversing",
        "../manipulation",
diff --git a/src/ajax/parseJSON.js b/src/ajax/parseJSON.js
new file mode 100644 (file)
index 0000000..9d2ada9
--- /dev/null
@@ -0,0 +1,8 @@
+define([
+       "../core"
+], function( jQuery ) {
+
+       jQuery.parseJSON = JSON.parse;
+
+       return jQuery.parseJSON;
+});
diff --git a/src/ajax/parseXML.js b/src/ajax/parseXML.js
new file mode 100644 (file)
index 0000000..9103c3d
--- /dev/null
@@ -0,0 +1,26 @@
+define([
+       "../core"
+], function( jQuery ) {
+       // Cross-browser xml parsing
+       jQuery.parseXML = function( data ) {
+               var xml, tmp;
+               if ( !data || typeof data !== "string" ) {
+                       return null;
+               }
+
+               // Support: IE9
+               try {
+                       tmp = new DOMParser();
+                       xml = tmp.parseFromString( data , "text/xml" );
+               } catch ( e ) {
+                       xml = undefined;
+               }
+
+               if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
+                       jQuery.error( "Invalid XML: " + data );
+               }
+               return xml;
+       };
+
+       return jQuery.parseXML;
+});
index 175208c2d9245cc85890c9d4dc9b4dbf3c58ef02..ef5df4f65532e7eccbb549be560dccd486f7de20 100644 (file)
@@ -10,9 +10,10 @@ define([
        "./var/toString",
        "./var/hasOwn",
        "./var/trim",
+       "./var/rsingleTag",
        "./var/support"
 ], function( strundefined, arr, slice, concat, push, indexOf,
-       class2type, toString, hasOwn, trim, support ) {
+       class2type, toString, hasOwn, trim, rsingleTag, support ) {
 
 var
        // A central reference to the root jQuery(document)
@@ -40,9 +41,6 @@ var
        // Strict HTML recognition (#11290: must start with <)
        rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
 
-       // Match a standalone tag
-       rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
-
        // Matches dashed string for camelizing
        rmsPrefix = /^-ms-/,
        rdashAlpha = /-([\da-z])/gi,
@@ -84,6 +82,7 @@ jQuery.fn = jQuery.prototype = {
                                        context = context instanceof jQuery ? context[0] : context;
 
                                        // scripts is true for back-compat
+                                       // Intentionally let the error be thrown if parseHTML is not present
                                        jQuery.merge( this, jQuery.parseHTML(
                                                match[1],
                                                context && context.nodeType ? context.ownerDocument || context : document,
@@ -387,60 +386,6 @@ jQuery.extend({
                throw new Error( msg );
        },
 
-       // data: string of html
-       // context (optional): If specified, the fragment will be created in this context, defaults to document
-       // keepScripts (optional): If true, will include scripts passed in the html string
-       // TODO: Circular reference core -> manipulation -> core
-       parseHTML: function( data, context, keepScripts ) {
-               if ( !data || typeof data !== "string" ) {
-                       return null;
-               }
-               if ( typeof context === "boolean" ) {
-                       keepScripts = context;
-                       context = false;
-               }
-               context = context || document;
-
-               var parsed = rsingleTag.exec( data ),
-                       scripts = !keepScripts && [];
-
-               // Single tag
-               if ( parsed ) {
-                       return [ context.createElement( parsed[1] ) ];
-               }
-
-               parsed = jQuery.buildFragment( [ data ], context, scripts );
-
-               if ( scripts && scripts.length ) {
-                       jQuery( scripts ).remove();
-               }
-
-               return jQuery.merge( [], parsed.childNodes );
-       },
-
-       parseJSON: JSON.parse,
-
-       // Cross-browser xml parsing
-       parseXML: function( data ) {
-               var xml, tmp;
-               if ( !data || typeof data !== "string" ) {
-                       return null;
-               }
-
-               // Support: IE9
-               try {
-                       tmp = new DOMParser();
-                       xml = tmp.parseFromString( data , "text/xml" );
-               } catch ( e ) {
-                       xml = undefined;
-               }
-
-               if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
-                       jQuery.error( "Invalid XML: " + data );
-               }
-               return xml;
-       },
-
        noop: function() {},
 
        // Evaluates a script in a global context
diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js
new file mode 100644 (file)
index 0000000..b097bfc
--- /dev/null
@@ -0,0 +1,38 @@
+define([
+       "../core",
+       "../var/rsingleTag",
+       "../manipulation" // buildFragment
+], function( jQuery, rsingleTag ) {
+
+       // data: string of html
+       // context (optional): If specified, the fragment will be created in this context, defaults to document
+       // keepScripts (optional): If true, will include scripts passed in the html string
+       jQuery.parseHTML = function( data, context, keepScripts ) {
+               if ( !data || typeof data !== "string" ) {
+                       return null;
+               }
+               if ( typeof context === "boolean" ) {
+                       keepScripts = context;
+                       context = false;
+               }
+               context = context || document;
+
+               var parsed = rsingleTag.exec( data ),
+                       scripts = !keepScripts && [];
+
+               // Single tag
+               if ( parsed ) {
+                       return [ context.createElement( parsed[1] ) ];
+               }
+
+               parsed = jQuery.buildFragment( [ data ], context, scripts );
+
+               if ( scripts && scripts.length ) {
+                       jQuery( scripts ).remove();
+               }
+
+               return jQuery.merge( [], parsed.childNodes );
+       };
+
+       return jQuery.parseHTML;
+});
diff --git a/src/var/rsingleTag.js b/src/var/rsingleTag.js
new file mode 100644 (file)
index 0000000..7e7090b
--- /dev/null
@@ -0,0 +1,4 @@
+define(function() {
+       // Match a standalone tag
+       return (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
+});