JSFiddle - React, Tailwind, and code Playground
HTML
<div class="post">
<div class="content">
This is for testing purposes google is magic and the dragon is testing.
Present us with different words so we can change em up. Greatest ever! <a href="#">Different</a> <a href="#">google</a> <a href="#">Dragon</a>
<code>google$(function(){
var dictionary = "Doodle Dee Doo";
var google ="Welcome to life";
var different = "Dude wheres my car";
});</code>
</div>
</div>
CSS
#tipper_box {
width: auto;
min-width: 100px;
height: auto;
min-height: 25px;
background: rgba(0, 0, 0, 0.78);
display: none;
position: absolute;
border: 1px solid rgb(71, 71, 71);
border-radius: 4px;
color: rgb(255, 255, 255);
box-shadow: 2px 2px 3px rgb(163, 163, 163);
}
.tipper_content > img {
margin: 0 auto;
max-width: 200px;
max-height: 200px;
}
.tipper_title {
color: rgb(255, 255, 255);
text-align: Center;
}
JavaScript
(function(w,d,undefined){
var i=0,
j=0,
tregex=[],wregex=[],iregex=[],treg,wreg,ireg,
w,
_text={},_image={},_links={},
selector;
var start = {
init:function(type,opts){
return new start.Dictionary(type,opts);
},
Dictionary:function(type,opts){
if(type && typeof type == 'string'){
selector = d.querySelectorAll(type);
}else if(typeof type == 'object') opts=type;
if(opts){
if(opts.text){
for(w in opts.text){
_text[w]=opts.text[w];
tregex.push(w);
}
treg = RegExp('\\b([^<(.*?)>(.)<\/(.*?)>])(' + tregex.join('|') + ')\\b(?=\\W)', 'gim');
console.log(treg.source);
}
if(opts.image){
for(w in opts.image) {
_image[w]=opts.image[w];
iregex.push(w);
}
ireg = RegExp('\\b([^<(.*?)>(.*?)])(' + iregex.join('|') + ')\\b(?=\\W)', 'gim');
}
if(opts.links){
for(w in opts.links) {
_links[w]=(/http(s)?:\/\//).test(opts.links[w]) ? opts.links[w] : "http://"+opts.links[w];
wregex.push(w);
}
wreg = RegExp('\\b([^<(.*?)>(.?+)<\/(.*?)>])(' + wregex.join('|') + ')\\b(?=\\W)', 'gim');
}
}
for(;i<selector.length;i++){
var post = selector[i];
post.innerHTML = post.innerHTML.replace(treg, function(m) {
console.log(_text);
return '<span class="tipper" data-title="' + _text[m.replace(/^\s+|\s+$/g,'')] + '">' + m + '</span>';
}).replace(wreg, function(m) {
return '<a class="tech_link" href="' + _links[m.replace(/^\s+|\s+$/g,'')] + '">' + m + '</a>';
}).replace(ireg, function(m) {
return '<span class="tips_image" data-image-src="'+_image[m.replace(/^\s+|\s+$/g,'')]+'">'+m+'</span>';
});
}
start.tipit('.tipper','.tips_image');
return {
mouseover:function(x){
var kk = d.querySelectorAll('.tipper');
...