views:

30

answers:

1

Hi,

The basic question is: How do I perform a basic override of a plugin method without editing the original plugin file?

Is it possible to create an override for a specific instance:

Example: An rtf plugin uses:

$('selector').wysiwyg('setContent',newContent);

In order to display the rtf text as readonly I would like for the same method to be applied to a div instead of the body of the IFRAME

I would like to overwrite the original 'setContent' with my own code, just for this one element.

Thanks

+3  A: 
(function($){

var _oldcss = $.fn.css;

$.fn.css = function(prop,value){

    if (value.toLowerCase() === 'somecolor') {
       return _oldcss.call(this,prop,'#EA7E5D');
    } else {
       return _oldcss.apply(this,arguments);
    }
};
})(jQuery);

You can easily overwrite (I like to call it semi-hooking) functions in that manner. In this example, you overwrite the .css() jQuery function and return a custom value of your value equals 'somecolor', otherwise, the original function is called with passed arguments.

Kind Regards

--Andy

jAndy