Using jQuery with Velocity

View: New views
10 Messages — Rating Filter:   Alert me  

Using jQuery with Velocity

by John Eichelsdorfer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In attempting to integrate the JQuery UI datepicker tool into our site http://jobbank.com/, we are having an issue where the jQuery code is being removed due to both projects using the "$" symbol.

jQuery has this link:  http://docs.jquery.com/Using_jQuery_with_Other_Libraries that describes how to modify the use of jQuery to attempt to get things working, but do you have a preferred solution?   Examples would be great if you have them.

Thank!

John
John Eichelsdorfer
jobbank.com

Re: Using jQuery with Velocity

by Jason Tesser-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes

I would use velocities escape tool to spit our the $ in your JS.

http://dotcms.org/community/documentation/documentation_repository/velocity/velocity-tools-1.2-doc/generic/EscapeTool.html#getD%28%29

so in other words $JQueryStuff you would write the velocity
${esc.d}JQueryStuff

enjoy :-)

Thanks,
Jason Tesser
dotCMS Lead Development Manager
1-305-858-1422


On Wed, Jul 8, 2009 at 2:50 PM, John Eichelsdorfer <jeichels@...>wrote:

>
> In attempting to integrate the JQuery UI datepicker tool into our site
> http://jobbank.com/ http://jobbank.com/ , we are having an issue where the
> jQuery code is being removed due to both projects using the "$" symbol.
>
> jQuery has this link:
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries  that describes
> how
> to modify the use of jQuery to attempt to get things working, but do you
> have a preferred solution?   Examples would be great if you have them.
>
> Thank!
>
> John
>
>
> -----
> John Eichelsdorfer
>
> http://jobbank.com/ jobbank.com
> --
> View this message in context:
> http://www.nabble.com/Using-jQuery-with-Velocity-tp24397241p24397241.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

Re: Using jQuery with Velocity

by ChadDavis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I use jquery with velocity all the time and I never noticed an issue.
For instance, the on ready handler and the selector patterns both work
fine for me.  If velocity doesn't recognize a variable name after the
$, it just print's it straight through, right?  Are you concerned
about a coincidental match . . . seems unlikely since the jqueyr $ is
always followed by a left parens; not even sure if that could be the
start of a valid reference name.

Am I missing something?

On Wed, Jul 8, 2009 at 12:50 PM, John Eichelsdorfer<jeichels@...> wrote:

>
> In attempting to integrate the JQuery UI datepicker tool into our site
> http://jobbank.com/ http://jobbank.com/ , we are having an issue where the
> jQuery code is being removed due to both projects using the "$" symbol.
>
> jQuery has this link:
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries  that describes how
> to modify the use of jQuery to attempt to get things working, but do you
> have a preferred solution?   Examples would be great if you have them.
>
> Thank!
>
> John
>
>
> -----
> John Eichelsdorfer
>
> http://jobbank.com/ jobbank.com
> --
> View this message in context: http://www.nabble.com/Using-jQuery-with-Velocity-tp24397241p24397241.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Using jQuery with Velocity

by Nathan Bubna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If your Velocity template has jQuery javascript (or any other lib that
offers the $ symbol as a shortcut), then i would recommend just not
using the shortcut symbol.  Just use the jQuery variable.  Or if you
really don't want to type six letters, then do:

var J = jQuery;

and use J instead of $. When two syntaxes are close like that, i would
argue that the more maintainable, readable solution is to avoid mixing
them, wherever possible.  But if you really must mix them, then yes,
use the EscapeTool ($esc) or just do:

context.put("D", "$");

and use ${D} instead of ${esc.d}.

But do try to avoid mixing similar syntaxes when an easy alternative
is available.

On Wed, Jul 8, 2009 at 11:50 AM, John Eichelsdorfer<jeichels@...> wrote:

>
> In attempting to integrate the JQuery UI datepicker tool into our site
> http://jobbank.com/ http://jobbank.com/ , we are having an issue where the
> jQuery code is being removed due to both projects using the "$" symbol.
>
> jQuery has this link:
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries  that describes how
> to modify the use of jQuery to attempt to get things working, but do you
> have a preferred solution?   Examples would be great if you have them.
>
> Thank!
>
> John
>
>
> -----
> John Eichelsdorfer
>
> http://jobbank.com/ jobbank.com
> --
> View this message in context: http://www.nabble.com/Using-jQuery-with-Velocity-tp24397241p24397241.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Using jQuery with Velocity

by bluejoe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, John. I use velocity with jQuery, and find they work well. I think all you should pay attention to is esaping character '$'.
Ususally, I define a tool in tools.xml:

 <data type="string" key="dollar">$</data>
 <data type="string" key="D">$</data>

and use $D when I want to write jQuery codes such as: $('#QueryForm')

-bluejoe

----- Original Message -----
From: "John Eichelsdorfer" <jeichels@...>
To: <user@...>
Sent: Thursday, July 09, 2009 2:50 AM
Subject: Using jQuery with Velocity


>
> In attempting to integrate the JQuery UI datepicker tool into our site
> http://jobbank.com/ http://jobbank.com/ , we are having an issue where the
> jQuery code is being removed due to both projects using the "$" symbol.
>
> jQuery has this link:  
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries  that describes how
> to modify the use of jQuery to attempt to get things working, but do you
> have a preferred solution?   Examples would be great if you have them.
>
> Thank!
>
> John
>
>
> -----
> John Eichelsdorfer
>
> http://jobbank.com/ jobbank.com
> --
> View this message in context: http://www.nabble.com/Using-jQuery-with-Velocity-tp24397241p24397241.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>

Re: Using jQuery with Velocity

by John Eichelsdorfer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wanted to thank you for the responses.  Wanted to make the thing work before responding.  Ended up using the recommended ${esc.d}.

Without it, the following code was trying to have "datepicker" turned into a velocity variable.   Not sure if it should have, but...


        $.datepicker.setDefaults({
            dateFormat: 'mm/dd/yy',
            showOn: 'focus',
            changeMonth: true,
            changeYear: true
        });



John Eichelsdorfer
jobbank.com

Re: Using jQuery with Velocity

by ChadDavis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Without it, the following code was trying to have "datepicker" turned into a
> velocity variable.   Not sure if it should have, but...
>        $.datepicker.setDefaults({
>            dateFormat: 'mm/dd/yy',
>            showOn: 'focus',
>            changeMonth: true,
>            changeYear: true
>        });

I'd like to understand why this is interpreted as a Velocity reference
though.  "." is not a legal reference name character.  Is this a bug?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Using jQuery with Velocity

by Byron Foster-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 13, 2009, at 5:57 , ChadDavis wrote:

>> Without it, the following code was trying to have "datepicker"  
>> turned into a
>> velocity variable.   Not sure if it should have, but...
>>        $.datepicker.setDefaults({
>>            dateFormat: 'mm/dd/yy',
>>            showOn: 'focus',
>>            changeMonth: true,
>>            changeYear: true
>>        });
>
> I'd like to understand why this is interpreted as a Velocity reference
> though.  "." is not a legal reference name character.  Is this a bug?

Yes, this is a bug.  In my test the following:

$.x

renders as:

.x

So it simply eats the dollar sign, which isn't correct.  But the  
following:

$..x
$("foo")

renders correctly as:

$..x
$("foo")



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Using jQuery with Velocity

by ChadDavis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Yes, this is a bug.  In my test the following:
>
> $.x
>
> renders as:
>
> .x
>

Looks like the bug is in the parsing of a reference before the dot
syntax, it allows an empty reference.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Using jQuery with Velocity

by Byron Foster-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 13, 2009, at 7:22 , ChadDavis wrote:

>> Yes, this is a bug.  In my test the following:
>>
>> $.x
>>
>> renders as:
>>
>> .x
>>
>
> Looks like the bug is in the parsing of a reference before the dot
> syntax, it allows an empty reference.

I created a bug for it here:

https://issues.apache.org/jira/browse/VELOCITY-729



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...