0

I have a jQuery UI element and I want to write something like that

$('myAccordion').accordion("refresh")

However, this does not compile since I only have a facade for jQuery - not jQuery UI.

How can I proceed here?

Klaus Schulz
  • 527
  • 1
  • 5
  • 20

1 Answers1

1

Basically, you write a mini-facade for the function you need. This looks intimidating, but the key is that you only need to write what you actually use, so it's pretty simple.

Mind, this is off-the-cuff and not tested, but a simplistic version would be something like this:

@js.native
trait JQueryAccordionFacade extends js.Object {
  def accordion(cmd:String):JQuery = js.native
}
...
implicit def jq2Accordion(jq:JQuery):JQueryAccordionFacade = jq.asInstanceOf[JQueryAccordionFacade]

You'll need some imports and stuff, and obviously this could be written in a more strongly-typed fashion, but that's most of it: just a description of the function you want to call, and the implicit conversion from an ordinary JQuery facade to the Accordion one. Facade-writing's pretty easy, once you get the hang of it.

Here are a couple of examples of some fully-worked jQuery UI facades, and here are the full details on how to write jQuery facades (far more than you need here, but in case you want to push this further).

Justin du Coeur
  • 2,699
  • 1
  • 14
  • 19
  • Thank you, I'll dig into your information. I solved the problem for now with a dirty workaround.... I added `dom.document.body.appendChild(script("function refreshAccordion() {$(\"#usingAccordion\").accordion(\"refresh\");}").render)` and `val clickButton = button(onclick := "refreshAccordion();").render` and then I could refresh my accordion with `clickButton.click()`. – Klaus Schulz Feb 18 '16 at 13:29