Fórum

Liferay 7 CE GA2: import a Plugin

thumbnail
Alessandro Candini, modificado 7 Anos atrás.

Liferay 7 CE GA2: import a Plugin

Regular Member Postagens: 130 Data de Entrada: 17/10/15 Postagens Recentes
I everyone. I'm trying to use bootstrap-select plugin, without success.
I've installed it with bower and tryed to import it inside portal_normal.ftl:
<script type="text/javascript" src="${components_folder}/bootstrap-select/dist/js/bootstrap-select.min.js"></script>

But in the javascript console, ,the plugin gives me an error when it loads:
Mismatched anonymous define() module: function (a){return b(a)}

And using the following inside main.js:
AUI().ready(  function() {  $('select').selectpicker(); });
I get this error:
$(...).selectpicker is not a function

It seems like jQuery is not loaded when I call selectpicker() method.
What am I missing?
Maybe should I load this module using the Liferay AMD Loader, in order to load it after jQuery?
Thank you.
thumbnail
Alessandro Candini, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

Regular Member Postagens: 130 Data de Entrada: 17/10/15 Postagens Recentes
I've received an answer in this other thread, but the problem here seems to be more complicated: bootstrap-select is a jQuery plugin, not an isolated JavaScript library.

So, how to import a jQuery plugin and connect it to the jQuery already included in Liferay 7?

Because even importing bootstrap-select inside config.js as described in the other thread, it does not find the bundled jQuery as dependency and the
selectpicker()
method is still missing...

Anyone can help?
Victor Soares, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

New Member Mensagem: 1 Data de Entrada: 29/06/16 Postagens Recentes
Did you make any progress on this? I am with the same issue.
thumbnail
Alessandro Candini, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

Regular Member Postagens: 130 Data de Entrada: 17/10/15 Postagens Recentes
Victor Soares:
Did you make any progress on this? I am with the same issue.

Not yet, unfortunately.
I'm still waiting a response from someone better skilled than me... emoticon
thumbnail
Chema Balsas, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

Regular Member Postagens: 127 Data de Entrada: 25/02/13 Postagens Recentes
Hey Alessandro, Victor

Not that the cleanest solution, but if you simply want to keep loading your modules as globals, you might be able to do the following:

<script>
define._amd = define.amd;
define.amd = false;
</script>

<script type="text/javascript" src="${components_folder}/bootstrap-select/dist/js/bootstrap-select.min.js"></script>

<script>
define.amd = define._amd;
</script>


Setting the amd flag to false before loading your umd-wrapped plugins should do the trick and they should keep loading all the same.

Let me know if that works for you!
thumbnail
Chema Balsas, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

Regular Member Postagens: 127 Data de Entrada: 25/02/13 Postagens Recentes
Additionally, if you're hosting the plugin yourself, you could simple replace &&define.amd by false in the plugin umd wrapper part to make sure it will not be loaded as a a global.
thumbnail
Alessandro Candini, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

Regular Member Postagens: 130 Data de Entrada: 17/10/15 Postagens Recentes
Chema Balsas:
Not that the cleanest solution, but if you simply want to keep loading your modules as globals...


Hi Chema.
I don't want to keep loading my modules as global, I want to understand what is the best practice to load a plugin dependent by another in Liferay 7.
Should I load it as an AMD module? If so, how to do it?
Is jQuery dependent plugins an exception because jQuery is already inside the portal?
If a plugin is an anonymous module, should I declare a name for it in order to properly load it in an AMD way?

If you have some documentation to better understand how this things works in Liferay 7 should be amazing...

Thank you.
Sanju Eapen, modificado 7 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

New Member Postagens: 7 Data de Entrada: 07/09/16 Postagens Recentes
Hello, I am facing a similar issue and have added a new thread Using amd compliant external javascript libraries in portlets. Could you please check and help me resolve the issue? Thanks a lot!
Frederic Bonin, modificado 6 Anos atrás.

RE: Liferay 7 CE GA2: import a jQuery Plugin

New Member Postagens: 6 Data de Entrada: 23/06/11 Postagens Recentes
Did you find the clean solution after all ?