1

I'm a bit stuck on a problem which I can't solve, I performed investigation on internet and on this site, but I can't find the answer to my question.

So basically I have a javascript file, which I cannot modify, so I have another javascript file which should catch the method when it is called and override it.

Normally I know how it works and I already done the function overriding, but I don't know how to solve this issue.

I have a very big script, but I will show just a small piece of it:

Microsoft.Office.Server.Ajax.NavResizer.prototype = {
    $6: null,
    $7: null,
......
$20:function ($p0) {
    if (this.$1E) {
        $p0.preventDefault();
    } 
},
$21: function ($p0) {
    var $0 = $p0.target;
    this.$1F = ($0 === this.$A);
    if (this.$1F || $0 === this.$B) {
        this.$1E = $0;
        this.$18 = $p0.clientX;
        this.$19 = $p0.clientY;
        Sys.UI.DomEvent.removeHandler(this.$1E, 'mousedown', this.$12);
        var $1 = document.body; Sys.UI.DomEvent.addHandler($1, 'mouseup', this.$13);
        Sys.UI.DomEvent.addHandler($1, 'mousemove', this.$14);
        $1.style.cursor = (this.$1F) ? 'e-resize' : 'n-resize';
        this.$1A = this.get_$42();
        this.$1B = this.get_$43();
        $1.focus();
        Sys.UI.DomEvent.addHandler($1, 'selectstart', this.$15);
        $p0.preventDefault();
    } 
},
$22: function ($p0) {
    this.$34($p0);
    var $0 = document.body;
    Sys.UI.DomEvent.removeHandler($0, 'mouseup', this.$13);
    Sys.UI.DomEvent.removeHandler($0, 'mousemove', this.$14);
    Sys.UI.DomEvent.addHandler($0, 'selectstart', this.$15); 
    $0.style.cursor = 'default';
    Sys.UI.DomEvent.addHandler(this.$1E, 'mousedown', this.$12);
    this.$1E = null;
},
$23: function ($p0) {
    this.$34($p0);
},
$24: function ($p0) {
    this.$26();
},
....

Basically this is the part of the script: so lets say I want to override function: $22: function ($p0) in the script in another javascript file, how do i do that?

I would appreciate any help.

A small update, some good examples were provided but they are not working. The environment where i run this sript is SharePoint, normally when I did override I used this method:

var oldFixRibbonAndWorkspaceDimensions = window.FixRibbonAndWorkspaceDimensions;
window.FixRibbonAndWorkspaceDimensions = function () {
    this.MyFixRibbonAndWorkspaceDimensions();
};

function MyFixRibbonAndWorkspaceDimensions(){...}

And it didn't matter when i load the script as this function was only called when the default function was called not before not after. Just in the same time. But with the example which were provided here, the function is trying to execute on the document.ready()

4 Answers 4

2

You want to permanently override it? Just do this:

Microsoft.Office.Server.Ajax.NavResizer.prototype.$22 = function($p0) {
    // your code.
};

As long as your script is executed after the original is defined, you're good.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah but original script is run i dont know when, as it is by default, how can i let my script run after? :/
2

Old post.. but this works for me:

ExecuteOrDelayUntilScriptLoaded(overrideNavResizer, "NavResizer.js");

function overrideNavResizer(){

    Microsoft.Office.Server.Ajax.NavResizer.prototype.$22 = function($p0) {
    // your code.
};
}

Comments

1

In your new script:

Microsoft.Office.Server.Ajax.NavResizer.prototype.$22 = function () {//your function code}

Comments

1

Assuming you have access to the prototype object (it's in global scope) and your scripts runs after it, that is easy:

var proto = Microsoft.Office.Server.Ajax.NavResizer.prototype,
    oldMethod = proto.$22;
proto.$22 = function newMethod(args, …){
    …
};

4 Comments

yeah looks easy but i get an error Microsoft is undefined ... what does it mean?
Just what I said: The object must be globally available. I don't know enough about your environment (where/when those scripts run, in which scope those code snippets are), but if you don't have access to that object you're lost.
can you tell me how can i load it after the other script? The other script is executed on demand, how about this function ExecuteOrDelayUntilScriptLoaded but dont know how to use it with this
No idea, but it seems you will need to tell us more about your environment

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.