You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ilya Obshadko <xf...@xfyre.com> on 2016/04/09 14:05:17 UTC
integrating Facebook JS SDK
Facebook recommends the following method to integrate FB SDK using AMD
approach:
https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
However I can't find any obvious way to configure RequireJS paths in
Tapestry.
Is there any way to do it?
--
Ilya Obshadko
Re: integrating Facebook JS SDK
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Thanks for your very useful example, Carlos!
On Sat, 09 Apr 2016 15:48:58 -0300, Carlos Montero Canabal
<ca...@gmail.com> wrote:
> In your controller class (.java) you can write this:
>
>
> javaScriptSupport.addModuleConfigurationCallback(new
> ModuleConfigurationCallback() {
>
> @Override
> public JSONObject configure(final JSONObject configuration) {
> final JSONObject facebookExports = new JSONObject();
> facebookExports.put("exports", "FB");
> configuration.getJSONObject("shim").put("facebook", facebookExports);
>
> final JSONObject paths = new JSONObject();
> paths.put("facebook", "//connect.facebook.net/es_ES/sdk");
> configuration.put("paths", paths);
>
> return configuration;
> }
> });
>
> And in your module file:
>
> define(['facebook'], function(FB){
>
> init = function(appId){
>
> FB.init({
> appId : appId,
> version : 'v2.5',
> xfbml : true
> });
>
> }
>
> return {
> init: init
> }
> });
>
> For example.
>
> I hope help you.
>
> Regards
>
> Carlos Montero
>
>
>> El 9/4/2016, a las 14:11, Pavel Chernyak <ju...@gmail.com> escribió:
>>
>> Greetings, Ilya.
>> Here is my example for Yandex maps module. As you can see I define
>> require.js config in module file.
>>
>> requirejs.config({ paths: { 'ymaps':
>> '//api-maps.yandex.ru/2.1/?lang=ru-RU',
>> 'geolib': 'map/geolib.min' }, "shim": { 'ymaps': { exports: 'ymaps' },
>> 'geolib' : { exports: 'geolib' } } }); define(["jquery", "ymaps",
>> "geolib","./lodash.min","./graham_scan.min"], function ($,
>> ymaps,geolib) {
>> code... });
>>
>> Pavel Chernyak.
>> 9 апр. 2016 г. 15:05 пользователь "Ilya Obshadko" <xf...@xfyre.com>
>> написал:
>>
>>> Facebook recommends the following method to integrate FB SDK using AMD
>>> approach:
>>> https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
>>>
>>> However I can't find any obvious way to configure RequireJS paths in
>>> Tapestry.
>>>
>>> Is there any way to do it?
>>>
>>> --
>>> Ilya Obshadko
>>>
>
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: integrating Facebook JS SDK
Posted by Carlos Montero Canabal <ca...@gmail.com>.
In your controller class (.java) you can write this:
javaScriptSupport.addModuleConfigurationCallback(new ModuleConfigurationCallback() {
@Override
public JSONObject configure(final JSONObject configuration) {
final JSONObject facebookExports = new JSONObject();
facebookExports.put("exports", "FB");
configuration.getJSONObject("shim").put("facebook", facebookExports);
final JSONObject paths = new JSONObject();
paths.put("facebook", "//connect.facebook.net/es_ES/sdk");
configuration.put("paths", paths);
return configuration;
}
});
And in your module file:
define(['facebook'], function(FB){
init = function(appId){
FB.init({
appId : appId,
version : 'v2.5',
xfbml : true
});
}
return {
init: init
}
});
For example.
I hope help you.
Regards
Carlos Montero
> El 9/4/2016, a las 14:11, Pavel Chernyak <ju...@gmail.com> escribió:
>
> Greetings, Ilya.
> Here is my example for Yandex maps module. As you can see I define
> require.js config in module file.
>
> requirejs.config({ paths: { 'ymaps': '//api-maps.yandex.ru/2.1/?lang=ru-RU',
> 'geolib': 'map/geolib.min' }, "shim": { 'ymaps': { exports: 'ymaps' },
> 'geolib' : { exports: 'geolib' } } }); define(["jquery", "ymaps",
> "geolib","./lodash.min","./graham_scan.min"], function ($, ymaps,geolib) {
> code... });
>
> Pavel Chernyak.
> 9 апр. 2016 г. 15:05 пользователь "Ilya Obshadko" <xf...@xfyre.com> написал:
>
>> Facebook recommends the following method to integrate FB SDK using AMD
>> approach:
>> https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
>>
>> However I can't find any obvious way to configure RequireJS paths in
>> Tapestry.
>>
>> Is there any way to do it?
>>
>> --
>> Ilya Obshadko
>>
Re: integrating Facebook JS SDK
Posted by Pavel Chernyak <ju...@gmail.com>.
Greetings, Ilya.
Here is my example for Yandex maps module. As you can see I define
require.js config in module file.
requirejs.config({ paths: { 'ymaps': '//api-maps.yandex.ru/2.1/?lang=ru-RU',
'geolib': 'map/geolib.min' }, "shim": { 'ymaps': { exports: 'ymaps' },
'geolib' : { exports: 'geolib' } } }); define(["jquery", "ymaps",
"geolib","./lodash.min","./graham_scan.min"], function ($, ymaps,geolib) {
code... });
Pavel Chernyak.
9 апр. 2016 г. 15:05 пользователь "Ilya Obshadko" <xf...@xfyre.com> написал:
> Facebook recommends the following method to integrate FB SDK using AMD
> approach:
> https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
>
> However I can't find any obvious way to configure RequireJS paths in
> Tapestry.
>
> Is there any way to do it?
>
> --
> Ilya Obshadko
>
Re: integrating Facebook JS SDK
Posted by Ilya Obshadko <il...@gmail.com>.
Pavel,
So you just manually add requirejs.config call in every module file that
has external AMD dependencies?
This is helpful - thanks a lot!
On Sat, Apr 9, 2016 at 3:47 PM, Pavel Chernyak <fj...@fjfalcon.ru> wrote:
> Greetings, Ilya.
> Here is my example for Yandex maps module. As you can see I define
> require.js config in module file.
>
> requirejs.config({ paths: { 'ymaps': '//api-maps.yandex.ru/2.1/?lang=ru-RU
> ',
> 'geolib': 'map/geolib.min' }, "shim": { 'ymaps': { exports: 'ymaps' },
> 'geolib' : { exports: 'geolib' } } }); define(["jquery", "ymaps",
> "geolib","./lodash.min","./graham_scan.min"], function ($, ymaps,geolib) {
> code... });
>
> Pavel Chernyak
>
--
Ilya Obshadko
Re: integrating Facebook JS SDK
Posted by Pavel Chernyak <fj...@fjfalcon.ru>.
Greetings, Ilya.
Here is my example for Yandex maps module. As you can see I define
require.js config in module file.
requirejs.config({ paths: { 'ymaps': '//api-maps.yandex.ru/2.1/?lang=ru-RU',
'geolib': 'map/geolib.min' }, "shim": { 'ymaps': { exports: 'ymaps' },
'geolib' : { exports: 'geolib' } } }); define(["jquery", "ymaps",
"geolib","./lodash.min","./graham_scan.min"], function ($, ymaps,geolib) {
code... });
Pavel Chernyak
Re: integrating Facebook JS SDK
Posted by Ilya Obshadko <xf...@xfyre.com>.
UPD: the obvious workaround is downloading it locally and contributing to
ModuleManager:
@Contribute(ModuleManager.*class*)
*public* *static* *void* contributeModuleConfigiration (
MappedConfiguration<String, Object> configuration,
@Path("context:js/facebook/sdk.js") Resource facebookSdk ) {
configuration.add ( "facebook", *new* JavaScriptModuleConfiguration
( facebookSdk ).exports ( "FB" ) );
}
However that doesn't look like an elegant solution either. Are there any
other options?
On Sat, Apr 9, 2016 at 3:05 PM, Ilya Obshadko <xf...@xfyre.com> wrote:
> Facebook recommends the following method to integrate FB SDK using AMD
> approach:
> https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
>
> However I can't find any obvious way to configure RequireJS paths in
> Tapestry.
>
> Is there any way to do it?
>
> --
> Ilya Obshadko
>
>
>
>
--
Ilya Obshadko
Re: integrating Facebook JS SDK
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 09 Apr 2016 09:05:17 -0300, Ilya Obshadko <xf...@xfyre.com> wrote:
> Facebook recommends the following method to integrate FB SDK using AMD
> approach:
> https://developers.facebook.com/docs/javascript/howto/requirejs/v2.5
>
> However I can't find any obvious way to configure RequireJS paths in
> Tapestry.
>
> Is there any way to do it?
Yes. See
JavaScriptSupport.addModuleConfigurationCallback(ModuleConfigurationCallback):
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/javascript/JavaScriptSupport.html#addModuleConfigurationCallback(org.apache.tapestry5.services.javascript.ModuleConfigurationCallback)
ModuleConfigurationCallback has a single method, JSONObject
configure(JSONObject configuration), which receives the Require.js
configuration as a JSONObject file so you can modify it to your needs and
return it. There's an example in the Tapestry's test webapps.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org