Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My question is regarding a default SharePoint imglib script. The script is located in following folder: 14\TEMPLATE\LAYOUTS\1033\imglib.js

The script has a function called: GenerateFooterContent(f, g).

Basically i want to override this method, and do some other stuff instead of the current. Anyone has any idea how can i achieve that?

I've copied the whole function to my custom javascript file and i added it to the masterpage. But how can i say now that instead of default function my custom function should be used by the script?

On this Link there is similar problem, but no solution is provided.

So can anyone give me a hint how to solve the problem?

UPDATE:

function to modify: function GenerateNFooterContent(f, g) because it takes parameteres i have to call the above calling function

function ViewFooterScript() In this function i'll call the NEWGenerateNFooterContent

So here is the script which should override it, is it correct:

window.ViewFooterScript = function () {

    this.ViewFooterScript();
};

Althought it doesnt work.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Make sure you use the global object (window) when you override it, like this:

var oldGenerateFooterContent = window.GenerateFooterContent;
window.GenerateFooterContent = function() {
  console.log('Hello, world!');
  // if you want you can call the old function here
  oldGenerateFooterContent();
};

Update:
If you want to provide the same arguments you can do that by calling apply.
like this:

oldGenerateFooterContent.apply(this, arguments);
// or
oldGenerateFooterContent.apply(null, arguments);
share|improve this answer
    
but is it ok that i do not provide the parameters? –  Shkipper Sep 27 '12 at 11:09
    
Good call. Updated the answer, now I'm not sure if you should use thisor not in apply –  eirikb Sep 27 '12 at 11:14
    
It is complicated: you see i want to modify in one script something, not add, but modify. But this function is called with paramteres which i do not have. So i decided to override the above calling function to call this function but modified version ... but hmm still not working –  Shkipper Sep 27 '12 at 11:58
    
By copying the whole function as you did, and replacing window.GenerateFooterContent you should be good to go, simply run console.log(arguments) directly after if you wonder what arguments it is given –  eirikb Sep 27 '12 at 11:59
    
i modified the question, is this correct script which i run? –  Shkipper Sep 27 '12 at 12:02
show 2 more comments

You want to duck punch the function.

Duck punching in javascript.

Duck punching in JQuery

share|improve this answer
add comment

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.