JQuery Mobile and Scala.js: How to call functions like "navbar()" or "toolbar()"?

In JQuery mobile, to make persistent headers, footers and nabbers work as expected, you have to do something like this:

$(function() {
    $( "[data-role='navbar']" ).navbar();
    $( "[data-role='header'], [data-role='footer']" ).toolbar();
});

What is the equivalent in Scala.js?

Answers


As usual in Scala.js, as a first "draft" you can always use the dynamically typed API:

js.Dynamic.global.$("[data-role='navbar']").navbar()

If you want a statically typed API, you can define it. As far as I know, no one has written facade types for jQuery mobile yet. However, there are facades for jQuery itself, such as 1. You can then "pimp" additional methods provided by a jQuery plugin, such as jQuery mobile, using the monkey patching pattern for Scala.js facades:

import org.querky.jquery._

trait JQueryMobile extends JQuery {
  def navbar(): Unit
}

implicit def JQueryMobileOps(jQ: JQuery): JQueryMobile =
  jQ.asInstanceOf[JQueryMobile]

and then you can do:

$("[data-role='navbar']").navbar()

and it will be statically typechecked.


Need Your Help

VS2015 Crashes when I try to Publish

azure crash visual-studio-2015

So, I am developing a Web Service, and at some point, my Visual Studio 2015 started to crash every time i right click project -> Publish. When I publish a project it gets deployed to Azure.

PHP .dat Processing vs MySQL Query Speed

php mysql apache .htaccess

To monitor spambots and unnecessary crawlers / bots / scrapers, I set up honeypots with rel=nofollow links and hidden links. Now I have nearly 200 IP to block within a week. I do not intend to use .