Basically, I'm using an existing jQuery plugin that I want to have 2 instances available to use from Jquery.
So for this html:
<div id="div_1"></div>
<div id="div_2"></div>
I would be able to do this:
$('#div_1').myplugin();
$('#div_2').copy_of_myplugin();
Now myplugin is being loaded by a script I pull in from an external source at the top of my html file.
If I console.log($());
I can see a list of all the native jQuery methods as well as the one added by the plugin script.
Basically, after a bit of research I think something like this should work, but I can't work out exactly how to do it.
$.fn.copy_of_my_plugin = function () {
return this.each(function () {
var instance = $(this);
if (instance.data('copy_of_my_plugin')) {
return;
}
var copy_of_my_plugin = new $.extend(true, {}, $.fn.myplugin);
instance.data('copy_of_my_plugin', copy_of_my_plugin);
});
};
I can console.log($());
again and see that copy_of_my_plugin is being added to jquery, but it looks like none of the contents of the myplugin function are actually being copied.
Anyone have any idea what I'm doing wrong?