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