escapeSelector.js (773B)
1 define( [ 2 "../core" 3 ], function( jQuery ) { 4 5 "use strict"; 6 7 // CSS string/identifier serialization 8 // https://drafts.csswg.org/cssom/#common-serializing-idioms 9 var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g; 10 11 function fcssescape( ch, asCodePoint ) { 12 if ( asCodePoint ) { 13 14 // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER 15 if ( ch === "\0" ) { 16 return "\uFFFD"; 17 } 18 19 // Control characters and (dependent upon position) numbers get escaped as code points 20 return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " "; 21 } 22 23 // Other potentially-special ASCII characters get backslash-escaped 24 return "\\" + ch; 25 } 26 27 jQuery.escapeSelector = function( sel ) { 28 return ( sel + "" ).replace( rcssescape, fcssescape ); 29 }; 30 31 } );