(function(w, d) {
function createPopup(el, options) {
// Create popup from DOM elements, a string, or read from a template
var popup = d.createElement('div');
//*** I haven't been able to get className to work, so I commented it out
// popup.className = options.className;
//***popup.innerText = 'Foobar!';
popup.insertAdjacentHTML("afterBegin",'Foobar!');
// Possibly insert popup into DOM, depending on how you've implemented it
//***el.parentNode.insertAfter(popup, el);
el.appendChild(popup);
//**** added to hide div by default
popup.style.display = 'none';
//*** added to connect this.popup (from MyPlugin function) to the reference of the created div
return popup;
}
var defaultOptions = {
//*** I haven't got className to work, so I just took out the related functions
className: 'popup'
};
var MyPlugin = function(el, options) {
this.element = el;
this.options = options || defaultOptions;
this.popup = createPopup(el, this.options);
var self = this;
// Ignoring IE for now
el.addEventListener('mouseover', function() {
//alert("clicked");
self.popup.style.display = 'block';
// Possibly want to set position of popup, depending on how you've implemented it
});
el.addEventListener('mouseout', function() {
self.popup.style.display = 'none';
});
};
MyPlugin.prototype = {
// Other methods you want an instance of MyPlugin to have, for example:
setText: function(text) {
//***I didn't get the innerText to work, so I changed it with synonymous code
//***this.popup.innerText = text;
this.popup.insertAdjacentHTML("beforeEnd",text);
}
};
// Static methods
MyPlugin.setDefaults = function(options) {
defaultOptions = options;
};
w.MyPlugin = MyPlugin;
})(window,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.