Path

ez projects / ezjscore / forum / general / question about ezscript_req...


Question about ezscript_require

You need to be logged in to post messages in the forums. New users may register here.

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Thursday 03 September 2009 11:32:26 am

Hi. I'm starting with ezjscore because i'm using ezstarrating.

Previously, i was usign jquery for another custom extensions we need for this project.
so, in one of my design.ini.append.php, i had something like



[JavaScriptSettings]


JavaScriptList[]=jquery-1.3.2.min.js


JavaScriptList[]=jquery-ui-1.7.2.custom.min.js




Having it like that, if i try to use ezstarrating i get a javascript error if i try to vote something.

Error is like 'jQuery.ez is not a function'.

If a comment out jquery in my javascript settings, this is like



[JavaScriptSettings]


#JavaScriptList[]=jquery-1.3.2.min.js


JavaScriptList[]=jquery-ui-1.7.2.custom.min.js




i can vote perfectly again, but then i cannot use jquery in my other custom extension...

so, which could be the best way to solve this?

should i add



{ezscript_require(array( concat( 'ezjsc::jquery'), concat( 'ezjsc::jqueryio' ) ) )}




to all templates of my other extensions, or maybe just move this line to my pagelayout?

Thank you.

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Thursday 03 September 2009 1:47:29 pm

I guess you only have this issue in admin?

One solution could be to remove (override and remove) this code block in 'design/admin/templates/pagelayout.tpl':



{section name=JavaScript loop=ezini( 'JavaScriptSettings', 'JavaScriptList', 'design.ini' ) }


<script language="JavaScript" type="text/javascript" src={concat( 'javascript/',$:item )|ezdesign}></script>


{/section}




And change (override and change) 'extension/ezjscore/design/admin/templates/page_head.tpl':



{* Load JavaScript dependencys *}


{ezscript_load()}




To



{* Load JavaScript dependencys + JavaScriptList *}


{ezscript_load( ezini( 'JavaScriptSettings', 'JavaScriptList', 'design.ini' ) )}




And change:
JavaScriptList[]=jquery-1.3.2.min.js

to
JavaScriptList[]=ezjsc::jquery


The other way is to start to use this everywhere you need jquery code:
{ezscript_require('ezjsc::jquery')}


BTW: where did you get the 'concat' from? Thats not needed when your not actually concating strings.

--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Thursday 03 September 2009 2:05:49 pm

Sorry about the concat. it was my fault.
just rests of the test i did related to
http://projects.ez.no/ezstarratin...eral/jquery_code_for_voting#msg19068

there we talked about choosing yui3 or jquery.

Your solution seems to work. Thank you again.

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Thursday 03 September 2009 2:10:27 pm

Ok, nop :)

Which of the solutions?

--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Thursday 03 September 2009 2:21:08 pm

First one. Seems to be more elegant than having to add that piece of code if we need more extensions in the future
Best Regards.

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Thursday 03 September 2009 3:34:47 pm

Ok, thanks for testing :)
Will try to get the need changes to 4.2 pagelayout templates so this doesn't happen there.

BTW: bundled jquery-1.3.2.min now.

--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Friday 04 September 2009 10:43:22 am

Hi again.

Following with my question, now i have another issue. After testing your solution my design.ini.append.php looks like



[JavaScriptSettings]


..


JavaScriptList[]=ezjsc::jquery


..




But now i'm trying to work with another extension. i need a jquery plugin for it. it's called treeview, and there's a script called jquery.treeview.min.js needed to work (Btw, it converts a nested list in a nice treeview). I only need this script for this specific part of my project, so i tried to load it from this template and not for entire the admin zone.

So, in my template i have



{ezscript_require( array('jquery.treeview.min.js', 'jquery.cookie.js') )}



(jquery.cookie is used for remember the last state of the tree).

Now, i'm getting javascript error. I think is because these scripts are added to the packed file before jquery. error looks like



jQuery is not defined




I set DeveloptmentMode to enable to see what happens and this is what i get in my <head>



<script language="javascript" type="text/javascript" src="/extension/filtros/design/standard/javascript/jquery.treeview.min.js" charset="utf-8"></script>


<script language="javascript" type="text/javascript" src="/extension/filtros/design/standard/javascript/jquery.cookie.js" charset="utf-8"></script>


<script language="javascript" type="text/javascript" src="/extension/ezjscore/design/standard/javascript/jquery-1.3.2.min.js" charset="utf-8"></script>


---




I don't know if we can find a way to force jquery to be added first to the packed files or something...

Best Regards.
Carlos.

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Friday 04 September 2009 1:02:14 pm

What if you do it like:



{ezscript_require( array('ezjsc::jquery', 'jquery.treeview.min.js', 'jquery.cookie.js') )}




If you instead want them on all pages, do something like:



[JavaScriptSettings]


JavaScriptList[]=ezjsc::jquery


JavaScriptList[]=jquery.treeview.min.js


JavaScriptList[]=jquery.cookie.js


--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Friday 04 September 2009 1:17:07 pm

Yeah. Both forms work, but:
- The first one requires me to add jquery in every templates where i need jquery
- The second one will load jquery.treeview and jquery.cookie.js in every 'page', even i don't need them...

Would be too hard change the way that files are added to the packed one? I mean, it seems that actually, ezscript_require calls in templates are readed before JavaScriptSettings in ini files...
If this could be changed to "read ini files first and then add all what templates need", all will be ok for me.

But i'm afraid this is not an easy one...

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Friday 04 September 2009 2:21:39 pm

I can do that, but I got the impression that you had to add the code* you mentioned anywhere you used it anyway.


*



{ezscript_require( array('jquery.treeview.min.js', 'jquery.cookie.js') )}


--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Friday 04 September 2009 2:32:27 pm

Sorry. Would you mean i will have to add this line of code everywhere or only everywhere where i need those scripts?
i mean this line




{ezscript_require( array('jquery.treeview.min.js', 'jquery.cookie.js') )}




If only where i need that's what i need...

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Friday 04 September 2009 2:53:36 pm

Forget it, to many lost in translation threads today, I'll just fix it.

UPDATE: Fixed in svn, please test.

--
ar

Up

Carlos Revillo

Member since:
31 January 2007

Posts: 53

Friday 04 September 2009 4:47:23 pm

It works like a charm!

Thanks a lot.
Carlos.

Twitter: @crevillo
Skype ID: crevillo1976
http://www.tantacom.com
eZ Diff Squad member

Up

André R

Member since:
20 August 2005

Posts: 171

Tuesday 08 September 2009 8:12:13 pm

Hi!

Small update: Fix for the issue you had earlier in admin design where "JavaScriptList" files would override scripts from "ezscript_require" is now fixed in eZ Publish 4.2:
http://issues.ez.no/IssueView.php?Id=15440&

Additionally it's now possible to use ezcss_require() for both admin and webin design out of the box (So we for instance don't have to load css with javascript in ezstarrating) ;-)

--
ar

Up

You need to be logged in to post messages in the forums. New users may register here.