Sign up ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am trying to extend the ctools model functions in my JavaScript file but not getting the exact way.

In ctool model.js contains modalContentClose = function(){close(); return false;}; which I want to override in my JavaScript file to add more functionality.

I have tried to use the following code, but it doesn't work.

function extends modalContentClose() {
  // Some alert here.
}
share|improve this question

1 Answer 1

JavaScript doesn't allow extending a function with another one. If you want to extend modalContentClose() you just redefine it in your JavaScript file that is included after the JavaScript used by ctools.module.

modalContentClose = function() {
  // Add your own code.
  close();
  return false;
};

Your version of modalContentClose() cannot refer the previous modalContentClose(), if you don't save it in a new variable, as with the following code.

originalContentClose = modalContentClose;

modalContentClose = function() {
  // Add your own code.
  originalContentClose();
};
share|improve this answer
    
What do you mean by "if you don't save it in a new variable, as with the following code."? – Aboodred1 Jan 25 '13 at 21:36
    
Once JavaScript executes, modalContentClose = function() { /* code */}; the previous value of modalContentClose is not anymore available. It is like when you use foo = 'bar'; foo = 'another bar';. JavaScript can give you the actual value of foo, but it cannot give you the previous value, if you don't save it in a new variable. – kiamlaluno Jan 26 '13 at 0:03
    
I see, I guess your answer is more generic javascript solution than specific to this function modalContentClose. In ctools module this function "modalContentClose" is an inner function, so I don't think you can override it in any way. Thanks – Aboodred1 Jan 27 '13 at 22:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.