Here is the Superfish library used in Drupal. The superfish.js file at line 102 contains code:
$.fn.extend({
hideSuperfishUl : function(){
/* some statements */
},
showSuperfishUl : function(){
/* some statements */
}
});
I need to override these two functions. How to do it? (I don't mean how to do it in Drupal specifically, but rather how to do it in javascript)
P.S. Based on some information, I tried adding this code in my own script:
(function ($) {
var orig_hideSuperfishUl = $.hideSuperfishUl;
$.hideSuperfishUl = function(){
alert('lol');
}
})(jQuery);
Firebug shows that the statement starting with "var" runs once the page is refreshed, but the statement with "alert" does not run. Instead, the original hideSuperfishUl function runs.
[Edit 1] I changed the custom code to:
(function ($) {
//var orig_hideSuperfishUl = $.hideSuperfishUl;
var hideSuperfishUl = function(){
alert('lol');
}
})(jQuery);
[Edit 2] I added 4 breakpoints:
- in superfish.js at line 102 with code
$.fn.extend({ - in superfish.js at line 106 with code
o.retainPath = false; - in my script at line with
var hideSuperfishUl = function(){ - in my script at line with
alert('lol');
After refreshing the page, code at breakpoint 1 runs first, then at breakpoint 3. After moving the mouse on and off menu, code at breakpoint 2 runs. Breakpoint 4 is not reached.
The call stack at breakpoint 1 is only two anonymous functions (the first is the outermost function with jQuery argument, the second is the breakpoint). Very similar call stack at breakpoint 3.
$.fn.hideSuperfishUl = function(){(...)}instead of$.hideSuperfishUl = function(){(...)}orvar hideSuperfishUl = function(){(...)}.That way it works.