conflict with jquery

801 views
Skip to first unread message

optimum...@laposte.net

unread,
Jan 27, 2011, 4:40:26 PM1/27/11
to django-cms
Hi,
when I'm not logged, everything is working fine, but when I'm logged,
i have javscript error. I think it is because of a conflict between
the jquery I use with my site, and the jquery used by django-cms
toolbar.

here is what I do :

<head>
[...]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js"></script>
[...]
</head>
<body>
<script type="text/javascript" src="/media/admin/js/jquery.min.js"></
script>

<script type="text/javascript">
//<![CDATA[
// When jQuery is sourced, it's going to overwrite whatever might
be in the
// '$' variable, so store a reference of it in a temporary
variable...
var _$ = window.$;
// add stylesheets to head
(function ($) {
$('<link>').appendTo('head').attr({
rel: 'stylesheet', type: 'text/css',
href: '/media/cms/css/toolbar.css'
});
$('<link>').appendTo('head').attr({
rel: 'stylesheet', type: 'text/css',
href: '/media/cms/css/jquery.dialog.css'
});
})(jQuery);
//]]>
</script>
<script type="text/javascript" src="/media/cms/js/lib/
jquery.cookie.js"></script>
<script type="text/javascript" src="/media/cms/js/lib/
jquery.backgroundposition.js"></script>
<script type="text/javascript" src="/media/cms/js/tools.js"></script>
<script type="text/javascript" src="/media/cms/js/lib/
jquery.nyroModal-1.6.2.pack.js"></script>
<script type="text/javascript" src="/media/cms/js/lib/ui.core.js"></
script>
<script type="text/javascript" src="/media/cms/js/lib/ui.dialog.js"></
script>
<script type="text/javascript">
//<![CDATA[
// dynamic variables for the toolbar js file
var placeholder_data = {};
var page_is_defined = true;
var translations = {
move_slot: "Move to %(name)s",
question: "Are you sure you want to delete this plugin?"
};
var urls = {
cms_page_move_plugin: "/admin/cms/page/move-plugin/",
cms_page_changelist: "/admin/cms/page/",
cms_page_change_template: "/admin/cms/page/1/
change_template/",
cms_page_add_plugin: "/admin/cms/page/add-plugin/",
cms_page_remove_plugin: "/admin/cms/page/remove-plugin/",
cms_page_move_plugin: "/admin/cms/page/move-plugin/"
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
(function($) {
$(document).ready(function() {

var submitActor;
var forceSubmit = false;
var seen = false;

// change submit states, open dialog
$('#cms_toolbar_requestapproval').click(function(event){
return showDialog(event);
});

function showDialog(event, actor) {
if (forceSubmit) return true; // escape sequence

if (!seen) {
// show previously posted message if there were an
error
//$('#id_df_moderator_message').val($
('#id_moderator_message').val());
}
seen = true
event.preventDefault();
submitActor = actor;
$('#dialog').dialog('open');
return false;
}

function dialogSave(){
// assign values from dialog form to real form
$('#id_moderator_message').val($
('#id_df_moderator_message').val());
$('#id_moderator_state').val(
$('#id_df_moderator_state').is(':checked') ? $
('#id_df_moderator_state').val() : 0
);
$('#dialog').dialog('close');
forceSubmit = true;

// we need to post an updated to server-side to send
the email!
$(submitActor || '#page_form
input[name=_save]').click();
return false;
}

$('#dialog').dialog({
bgiframe: true,
autoOpen: false,
height: 200,
width: 400,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog('close');
},
Save: function() {
dialogSave();
}
},
open: function(){
var val = $('#id_moderator_state').val();
$('#id_df_moderator_state').attr('checked', val >=
1 ? 'checked': '');
$('#id_df_moderator_message')
.focus()
.keydown(function(event) { if (event.keyCode
== 13) dialogSave()});

// add default button class to last rendered
button (Save)
$(this.uiDialogButtonPane).find('div.ui-dialog-
buttonpane button:last').addClass('default');
},
close: function(){
forceSubmit = false;
}
});
});
})(jQuery);
//]]>

</script>
<script type="text/javascript" src="/media/cms/js/toolbar.js"></
script>
<script type="text/javascript" charset="utf-8">
//<![CDATA[
// Now that jQuery is done loading, put the '$' variable back to
what it was...
var $ = _$;
//]]>
</script>



</body>

Is there a way to desactivate it ?

thanks

benzkji

unread,
Jan 27, 2011, 4:50:09 PM1/27/11
to djang...@googlegroups.com
I solved this using the same jquery version as the cms.

But I agree, this might not always be possible - so you could put your own jquery into compatibility mode, should work then? Don't know if there are better ways.

-> a "jquery best practice" section for the django-cms manual would be very nice.

regards
benzkji

Miroslav Georgiev

unread,
Jan 28, 2011, 1:50:24 AM1/28/11
to djang...@googlegroups.com
I solved this by removing toolbar middware from settings.py.
regards
miro


--
You received this message because you are subscribed to the Google Groups "django-cms" group.
To post to this group, send email to djang...@googlegroups.com.
To unsubscribe from this group, send email to django-cms+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-cms?hl=en.



--
Miroslav Georgiev
Tech Lead
+359888836456
www.magicbg.com

optimum...@laposte.net

unread,
Jan 28, 2011, 6:14:10 PM1/28/11
to django-cms
Hi,
thanks for answers.
For removing toolbar, I cant, it is a usefull tool.
for changing my jquery, i try, but it still doesnt work.

any other idea ? ;-)

On 28 jan, 07:50, Miroslav Georgiev <miro.georg...@gmail.com> wrote:
> I solved this by removing toolbar middware from settings.py.
> regards
> miro
>
>
>
>
>
> On Thu, Jan 27, 2011 at 11:50 PM, benzkji <benz...@gmail.com> wrote:
> > I solved this using the same jquery version as the cms.
>
> > But I agree, this might not always be possible - so you could put your own
> > jquery into compatibility mode, should work then? Don't know if there are
> > better ways.
>
> > -> a "jquery best practice" section for the django-cms manual would be very
> > nice.
>
> > regards
> > benzkji
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "django-cms" group.
> > To post to this group, send email to djang...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-cms+...@googlegroups.com<django-cms%2Bunsubscribe@googlegrou­ps.com>
> > .

Piotr Kilczuk

unread,
Jan 29, 2011, 4:47:03 PM1/29/11
to djang...@googlegroups.com



Hi,
thanks for answers.
For removing toolbar, I cant, it is a usefull tool.
for changing my jquery, i try, but it still doesnt work.

any other idea ? ;-)

Hi,

You can have as many versions of jquery 'installed' as long as each one of them is in separate namespace. Log into the admin and take a look at /media/admin/js/jquery.init.js. It's how django separates jQuery from global namespace.

However, I'd personally stay compatible with djangocms's jQuery version.

Regards,
Piotr

optimum...@laposte.net

unread,
Feb 19, 2011, 6:17:09 PM2/19/11
to django-cms
Hi,
I still have the same problem. I try different things but nothing was
working. Especially, i don't understand why even such a code below is
not working, with the same jquery.

[...]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>accueil UFC / Que Choisir Lille Métropole à votre écoute !</
title>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link rel="icon" type="image/png" href="/medias/images/favicon.png" />
<link rel="shortcut icon" type="image/x-icon" href="/medias/images/
favicon.ico" />
<link href="/medias/css/global_stylesheet.css" rel="stylesheet"
type="text/css" />
<!--[if IE 7]>
<link href="/medias/css/if-ie7.css" rel="stylesheet" type="text/css" /
>
<![endif]-->
<!--[if IE 8]>
<link href="/medias/css/if-ie8.css" rel="stylesheet" type="text/css" /
>
<![endif]-->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" src="/medias/js/dropDown.js"></script>
<script type="text/javascript" src="/medias/js/jquery.scrollTo.js"></
script>
<script type="text/javascript" src="/medias/js/
jquery.localscroll.js"></script>
<script type="text/javascript" src="/medias/js/globals.js"></script>
<script type="text/javascript" src="/medias/js/easySlider1.7.js"></
script>



</head>

<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="/medias/cms/js/csrf.js"></script>
<script type="text/javascript">
[...]

I have this error : "$("#slider").easySlider is not a function"
here is pge working : http://ufc-que-choisir-lille.org/ when I'm not
logged, but not working when logged

Do I do something bad ?

thanks

On 29 jan, 22:47, Piotr Kilczuk <kilc...@gmail.com> wrote:
> 2011/1/29 optimum.dulo...@laposte.net <optimum.dulo...@laposte.net>

Simon Spencer

unread,
Feb 19, 2011, 6:26:00 PM2/19/11
to djang...@googlegroups.com
For all of your jquery make sure you add this line of code: var $j =
jQuery.noConflict(); where $j can be anything you want. Then when
calling jquery make sure you replace $ with whatever you have chosen.

Here is an example:
<script>
var $j = jQuery.noConflict();

// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});

// Use Prototype with $(...), etc.
$('someid').hide();
</script>

What is happening is that the Javascript that is generated from being
logged in is overriding your jquery. Read more about it here:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries

> --
> You received this message because you are subscribed to the Google Groups "django-cms" group.
> To post to this group, send email to djang...@googlegroups.com.

> To unsubscribe from this group, send email to django-cms+...@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/django-cms?hl=en.
>
>

--
Simon Spencer
Webmaster for UO Eclub
SCS Web Consulting
simon...@gmail.com
(971) 533 5157

Javier Nievas

unread,
Feb 21, 2011, 6:13:38 AM2/21/11
to djang...@googlegroups.com
I have just moved all my .js includes to the bottom, and everything works again.

Steven Githens

unread,
Jul 4, 2011, 11:46:31 AM7/4/11
to djang...@googlegroups.com
I'm running into the same issue right now working on a plugin.  My question is, in addition to creating a namespaced jquery, how do you then load a newer version of jQuery UI into that jquery namespace, so that it doesn't conflict with the ones that the django-cms toolbar loads right after the body tag.

Cheers,
Steve
Reply all
Reply to author
Forward
0 new messages