You have an error in your code: });(jQuery);
You should call the anonymous function, not just define it, and use jQuery as the argument for calling it, therefore inside the anonymous function $
is jQuery
, because you now have a different scope.
If you do (function($){/*your stuff*/});(jquery)
you define an anonymous function, but do not execute it. Anything inside the function is not executed, and as an anonymous function does not have a name, you have no way to execute it.
Remove the first semicolon in the line:
(function($) {
// do your stuff
})(jQuery);
EDIT:
A little explanation on what this works:
It is an anonymous function (if you don't know, how anonymous functions in Javascript work, see this question), and you call the function with jQuery
. If you use jQuery.noConflict()
in your code, as you should do to avoid binding $
to jquery, then you will only be able to use calls like jQuery('#myId')
for jquery functions, instead of $('#myId')
as $
is still bound to the Prototype library (I explicitely call it that way to destinguish it from the prototype
chain for objects).
Now consider your anonymous function:
You have (function($){ /* Some stuff with $ as a variable */ })
. Inside the function, you have a new scope, therefore $
is only the variable that you pass to the function, not the $
outside of it (still bound to the Prototype library).
Now you pass something to the anonymous function and therefore execute it: (function($){ /* Some stuff with $ as a variable */ })(jQuery)
. Now $
inside the function is ..... jQuery
, not the same as $
outside of it.
EDIT 2:
As you have updated your question, I will explain the steps to make both libraries work.
You need to include the reference for Prototype before jQuery, and then call jQuery.noConflict()
. After that call, $()
defaults to the functions in the Prototype library. To call functions in the jQuery library, you will have to use jQuery()
(see the jQuery API reference). You pass a reference to the jQuery
object to your anonymous function, so inside the anonymous function $
refers to the jQuery object, you cannot use the functionality of the Prototype library.
Now about your problem with the callback function: The problem may lie inside the contextMenu
function, as this function may not correctly make use of the no conflict initialization, but that is just a wild guess. Could you please give your implementation of the contextMenu
function?