Overriding jQuery plugin default and instance methods

Main question: How to perform a basic redefinition of the plugin method without editing the plugin source file?

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

Example: The rtf plugin uses:

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

To display rtf text as readonly, I would like the same method to be applied to the div instead of the IFRAME body

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

thanks

+4
source share
1 answer
 (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 rewrite (I like to call it semi-grabbing) functions in this way. In this example, you overwrite the .css() jQuery function and return the custom value of your value is "somecolor", otherwise the original function is called with arguments.

+5
source

Source: https://habr.com/ru/post/1307022/


All Articles