I have a table which contains a reference to one person on each column. I want to display a popup showing each person's short bio when user clicks each link. The popup should be displayed right next to the where the user clicked.
I found some samples using jquery with qtip, the problem I have is that for each person popup I have to duplicate all the javascript code and I'm thinking there must be a way to reuse it since it's almost the same, the only thing that changes is the content, title and the div id:
This is the jsFiddle.
Here the html code:
<table border="1">
<tr>
<td>
<div id="johndoe" style="background-color: #f0f0f0; width: 50%; margin: 2em">John Doe</div>
</td>
<td>
<div id="janedee" style="background-color: #f0f0f0; width: 50%; margin: 2em">Jane Dee</div>
</td>
</tr>
</table>
And Javascript:
$(document).ready(function () {
$("#johndoe").qtip({
content: {
text: "Here goes John Doe's short bio blah blah",
title: {
text: "Title",
button: true
}
},
position: {
target: 'mouse',
viewport: $(window),
adjust: {
method: 'flip shift',
mouse: false
}
},
style: {
tip: false,
widget: false
},
show: {
event: 'click',
solo: true
},
hide: {
fixed: true,
event: 'unfocus'
}
});
});
$(document).ready(function () {
$("#janedee").qtip({
content: {
text: "Here goes Jane Dee's short bio blah blah",
title: {
text: "Title",
button: true
}
},
position: {
target: 'mouse',
viewport: $(window),
adjust: {
method: 'flip shift',
mouse: false
}
},
style: {
tip: false,
widget: false
},
show: {
event: 'click',
solo: true
},
hide: {
fixed: true,
event: 'unfocus'
}
});
});
I don't have a lot of experience with jquery, so I'm asking the experts, how would you approach this with the least amount of javascript code possible? Like reusing functions, just passing the content, title and div id for each person.
Thanks in advance!