daattali / shinycssloaders

⌛ Add loading animations to a Shiny output while it's recalculating
https://daattali.com/shiny/shinycssloaders-demo/
Other
399 stars 45 forks source link

Escape special IDs #27

Closed merlinoa closed 5 years ago

merlinoa commented 5 years ago

Escaping the input ids for jQuery selector. Resolves issue #16.

Shiny's bookmarking feature creates an input with an id of ".bookmark". This input id was throwing the following javascript error when used as a jQuery selector

Uncaught Error: Syntax error, unrecognized expression: #._bookmark_
    at Function.fa.error (jquery.min.js:2)
    at fa.tokenize (jquery.min.js:2)
    at fa.select (jquery.min.js:2)
    at Function.fa [as find] (jquery.min.js:2)
    at n.fn.init.find (jquery.min.js:2)
    at new n.fn.init (jquery.min.js:2)
    at n (jquery.min.js:2)
    at show_spinner (spinner.js:5)
    at update_spinner (spinner.js:23)
    at HTMLDocument.<anonymous> (spinner.js:34)

The error was resolved by @andrewsali commit ab4cff1542bed6f996c0783a2911eeae7f80530e which escapes jQuery selector special characters. Specifically the "." for the case of the bookmarking issue mentioned above.

Additional detail on the regex used to escape the jQuery selector can be found here: https://stackoverflow.com/questions/2786538/need-to-escape-a-special-character-in-a-jquery-selector-string

andrewsali commented 5 years ago

Thanks!

keqiang commented 5 years ago

I think this PR introduces an issue. I will try to make a minimal reproducible example later.

Uncaught TypeError: Cannot read property 'replace' of undefined at escapeSelector (eval at (jquery.min.js:2), :5:14) at hide_spinner (eval at (jquery.min.js:2), :17:24) at update_spinner (eval at (jquery.min.js:2), :31:5) at HTMLDocument.eval (eval at (jquery.min.js:2), :52:3) at HTMLDocument.dispatch (jquery.min.js:3) at HTMLDocument.r.handle (jquery.min.js:3) at Object.trigger (jquery.min.js:3) at HTMLDocument. (jquery.min.js:3) at Function.each (jquery.min.js:2) at n.fn.init.each (jquery.min.js:2)