Note that there are some explanatory texts on larger screens.

plurals
  1. POoverriding a javascript function (Superfish in Drupal)
    primarykey
    data
    text
    <p>Here is the <a href="https://github.com/mehrpadin/Superfish-for-Drupal" rel="nofollow">Superfish library used in Drupal</a>. The superfish.js file at line 102 contains code:</p> <pre><code>$.fn.extend({ hideSuperfishUl : function(){ /* some statements */ }, showSuperfishUl : function(){ /* some statements */ } }); </code></pre> <p>I need to override these two functions. <strong>How to do it?</strong> (I don't mean how to do it in Drupal specifically, but rather how to do it in javascript)</p> <p>P.S. Based on some information, I tried adding this code in my own script:</p> <pre><code>(function ($) { var orig_hideSuperfishUl = $.hideSuperfishUl; $.hideSuperfishUl = function(){ alert('lol'); } })(jQuery); </code></pre> <p>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.</p> <p><strong>[Edit 1]</strong> I changed the custom code to:</p> <pre><code>(function ($) { //var orig_hideSuperfishUl = $.hideSuperfishUl; var hideSuperfishUl = function(){ alert('lol'); } })(jQuery); </code></pre> <p><strong>[Edit 2]</strong> I added 4 breakpoints:</p> <ol> <li>in superfish.js at line 102 with code <code>$.fn.extend({</code></li> <li>in superfish.js at line 106 with code <code>o.retainPath = false;</code></li> <li>in my script at line with <code>var hideSuperfishUl = function(){</code></li> <li>in my script at line with <code>alert('lol');</code></li> </ol> <p>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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload