Prototype and JQuery and chat plugin

3 messages Options
Embed this post
Permalink
Kieron

Prototype and JQuery and chat plugin

Reply Threaded More More options
Print post
Permalink
Hi,

I don't know if this is of any help to anyone but... if you followed Ch. 13 and the chat plugin section recently you may have noticed that the latest version of the chat plugin now uses jQuery and not Prototype.

For anyone who might be interested the includes for the js libraries naturally have to be changed for the chat plugin, upload and comments sections to work properly; so in default.ctp instead of the line from the book:

  if(isset($javascript)):
    echo ($this->params['controller'] == 'posts' && $this->params['action'] == 'add' ? $javascript->link(array('jquery.js','jquery.form.js')) : $javascript->link('prototype.js'));
  endif;

you can put the following call to a jquery no conflict function:

  if(isset($javascript)):
    echo $javascript->link('prototype.js');
    echo $javascript->link(array('jquery.js','jquery.form.js'));
    // call jquery no conflict func - from now on all '$' calls refer to prototype and jquery must be referenced directly with 'jQuery' replacing '$'
    echo "<script> jQuery.noConflict(); </script>";
  endif;

only as my comments above point out, you now have to amend the references to jQuery in the file upload section as follows in you posts add.ctp:

e($form->button('UploadText',array('onClick'=>'jQuery(\'#postAddForm\').ajaxSubmit({target: \'#postTextUpload\',url:\''.$html->url('/posts/text').'\'});return false;')));

I hope this is of use to someone.
Cheers.
davidgolding

Re: Prototype and JQuery and chat plugin

Reply Threaded More More options
Print post
Permalink
Thanks for the info Kieron.

A lot of code is moving over to jQuery. I've heard from Mark Grabanski that jQuery is probably going to replace Prototype in the Cake core, but I've yet to see that come to pass or to get listed on Cake's trac or anything.
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]
Musa

Re: Prototype and JQuery and chat plugin

Reply Threaded More More options
Print post
Permalink
In reply to this post by Kieron
i try to use prototype with jquery in cakephp project. I've used the following code on layout

        echo $javascript->link('prototype');
        echo $javascript->link(array('jquery.js','jquery.form.js')) ;
        echo "<script> jQuery.noConflict(); </script>";

and used the following code on view

<?=$form->create('News',array('name'=>'newsEdit','id'=>'newsEdit','type'=>'file'));?>

.....................
.....................

<?=$form->button('Upload',array('onClick'=>'jQuery(\'#newsEdit\').ajaxSubmit({target: \'#newsPageC\',url: \''.$html->url('/news/editNews/').'\'}); return false;'));?>

but error happens. i couldn't identify the problem. would you help me.