Alex Karasev
Alex Karasev

Reputation: 1128

Google Picker using Scala.js

I'd like to use Google Picker in my Scala.js app. I need to convert this example somehow.

There are two main questions:

The first, how can I load and use https://apis.google.com/js/api.js in my Scala.js code to use gapi object?

gapi.load('auth', {'callback': onAuthApiLoad});
gapi.load('picker', {'callback': onPickerApiLoad});

The second, after a picker will be loaded, how can I access to the google.picker object to create the picker?

var picker = new google.picker.PickerBuilder()

Upvotes: 0

Views: 82

Answers (1)

sjrd
sjrd

Reputation: 22105

As for any other JavaScript API, you can basically access it with a dynamically typed API using js.Dynamic or with a (possibly hand-written) typed facade.

In this case, I'd recommend the dynamic API for the first part:

import scala.scalajs.js
import js.Dynamic.{global => g, literal => lit}

g.gapi.load("auth", lit(callback = onAuthApiLoad))
g.gapi.load("picker", lit(callback = onPickerApiLoad))

and a static API for the second part:

@js.native
@JSName("google.picker.PickerBuilder")
class PickerBuilder() extends js.Object {
  // here you can declare methods and fields of PickerBuilder
}

val picker = new PickerBuilder()

Upvotes: 1

Related Questions