0

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.

2 Answers 2

1

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);
7
  • but is it ok that i do not provide the parameters?
    – Shkipper
    Sep 27, 2012 at 11:09
  • Good call. Updated the answer, now I'm not sure if you should use thisor not in apply
    – eirikb
    Sep 27, 2012 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, 2012 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, 2012 at 11:59
  • i modified the question, is this correct script which i run?
    – Shkipper
    Sep 27, 2012 at 12:02
0

You want to duck punch the function.

Duck punching in javascript.

Duck punching in JQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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