This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am I doing Unobtrusive JavaScript correctly?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I use buttons to navigate in my application and jQuery as our JavaScript library.

And here is demo.js

So in my $(function() { // JS Code }); of the main layout template, how to call or refer to the code in demo.js?
Sorry, I'm really new to Unobtrusive JavaScript concept.

One a side note, how not to hard code the application context in JavaScript files?
Thanks for help and time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Todd wrote:
So in my $(function() { // JS Code }); of the main layout template, how to call or refer to the code in demo.js?

All script included in the page is loaded into the same scope, so just reference anything that's loaded.

One a side note, how not to hard code the application context in JavaScript files?

In the parent JSP:
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my main.gsp template page, what should go under:


You mentioned to use the following line in the parent JSP:

How to point to this value from a separate JavaScript file (demo.js in my case)?
Sorry if my questions sound -well not smart-.
Appreciate your time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Todd wrote:In my main.gsp template page, what should go under:


Whatever you want. The code in this block forms a jQuery ready handler and will be executed after the DOM has been built, but before the load event is triggered.

You mentioned to use the following line in the parent JSP:

How to point to this value from a separate JavaScript file (demo.js in my case)?

contextPath

You are making this much more complicated that it is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic