Reputation: 3699
I want to extend a particular aspect of jQuery UI: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js
Search in the source code for easeInElastic
to see the following snippet:
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c; alert('');
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*9.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
I need to slightly modify the code, but I don't want to duplicate the whole library. How can I include a modified snippet in a separate .js file so that it will overwrite the original?
Edit:
Out of all the suggested methods, this is the only one that worked:
$.extend($.easing,
{
easeInElastic: function (x, t, b, c, d) {
alert('');
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
}
});
Upvotes: 0
Views: 911
Reputation: 95023
Overwrite that particular method with your own.
$.easing.easeInElastic = function(...
As long as your additional .js file with that code is placed after the jqueryui.js, it will overwrite it.
Upvotes: 3
Reputation: 4560
The jQuery documentation has a page on plugins/extensions:
http://docs.jquery.com/Plugins/Authoring
Basically, it's a matter of extending $.fn
.
Upvotes: 1