Nest views and javascript/jquery

23 views
Skip to first unread message

drfishflan

unread,
Oct 18, 2013, 7:11:04 AM10/18/13
to mach-ii-for...@googlegroups.com
We use nested views in our Machii code base. This works great but I am having issues with jquery.

In my master.cfm I have all sorts of jquery includes and some jquery code .

I then have a sub page which has it's own jquery.....

Both contain a $(document).ready(){}

This the code in the sub page is running twice!!

Also I am wondering how where other people put their Javascript when dealing with nested views? Can't put it in the master page if its specific to the sub page because if the sub page is included in another file it will be missing dependancies.

The sub page needs to work completely independantly of the parent master page.

BUT

by doing this I get the error mentioned above and there is the possibility of confilicts (matching variable names, functions etc)

How do other developers deal with this issues?

thanks!

Brian Klaas

unread,
Oct 18, 2013, 8:25:17 AM10/18/13
to mach-ii-for...@googlegroups.com
One option you may want to consider is creating a variable which contains your jQuery-based JS. You can add to this variable as needed (it's just a string, after all) and insert that on your master view. So you'd have something like:

view1.cfm

<cfset jQueryToInclude &= "some long string of JS">

view2.cfm

<cfset jQueryToInclude &= "some long string of JS">

and then on your masterView.cfm

<cfif Len (jQueryToInclude)>
     <cfoutput>#jQueryToInclude#</cfoutput>
</cfif>

At the end of the day, you're probably best off putting all your JS into an external file, and loading that at the bottom of the page. This way, you have all your JS in one place and you can easily see if you're going to have variable naming conflicts.

brian

Peter J. Farrell

unread,
Oct 18, 2013, 8:10:43 PM10/18/13
to mach-ii-for...@googlegroups.com
Or you can use the view:script custom tags to do the same thing.

Brian Klaas said the following on 10/18/2013 07:25 AM:
--
--
For more options and to unsubscribe, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
 
Git & Wiki: https://github.com/Mach-II/Mach-II-Framework
---
You received this message because you are subscribed to the Google Groups "Mach-II for CFML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mach-ii-for-coldf...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
Peter J. Farrell
OpenBD Steering Committee / Mach-II Lead Developer
http://blog.maestropublishing.com
Identi.ca / Twitter: @maestrofjp

Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/

drfishflan

unread,
Oct 31, 2013, 10:49:57 AM10/31/13
to mach-ii-for...@googlegroups.com
Thanks guys!
To unsubscribe from this group and stop receiving emails from it, send an email to mach-ii-for-coldfusion+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages