Skip to content

Commit

Permalink
Merge pull request #36 from exlame/ajax_buffer
Browse files Browse the repository at this point in the history
Ajax buffer
  • Loading branch information
Bojan Petkovski committed Nov 10, 2015
2 parents ddc475f + 1cfd00b commit 12ddd17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ To use css3 animation effects please include [Animate.css](http://daneden.github
| tooltipHover | false | Abillity to interact with the tooltip content |
| content | null | The content of the tooltip, can be text, html or whatever you want |
| ajaxContentUrl | null | Url for Ajax content |
| ajaxContentBuffer | 0 | Buffer timer for Ajax content |
| contentElementId | null | Normally used for picking template scripts |
| useTitle | false | To use the default title attribute as content (true, false) |
| templateEngineFunc | null | A function that compiles and renders the content |
Expand Down
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
jQuery('.ajax').tipso({
background: 'tomato',
useTitle: false,
ajaxContentUrl : 'ajax.html'
ajaxContentUrl : 'ajax.html',
ajaxContentBuffer : 5000
});
// Destroy Tipso
jQuery('.destroy-tipso').on('click', function(e){
Expand Down Expand Up @@ -293,6 +294,7 @@ <h3>Defaults</h3>
tooltipHover : false,
content : null,
ajaxContentUrl : null,
ajaxContentBuffer : 0,
contentElementId : null,
useTitle : false,
templateEngineFunc: null,
Expand Down Expand Up @@ -739,7 +741,8 @@ <h4>Ajax content</h4>
jQuery('.ajax').tipso({
background: 'tomato',
useTitle: false,
ajaxContentUrl : 'ajax.html'
ajaxContentUrl : 'ajax.html',
ajaxContentBuffer : 5000
});
</code>
</pre>
Expand Down
32 changes: 27 additions & 5 deletions src/tipso.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
tooltipHover : false,
content : null,
ajaxContentUrl : null,
ajaxContentBuffer : 0,
contentElementId : null, //Normally used for picking template scripts
useTitle : false, //Use the title tag as tooptip or not
templateEngineFunc: null, //A function that compiles and renders the content
Expand Down Expand Up @@ -148,6 +149,10 @@
obj.hide();
});
}
if(obj.settings.ajaxContentUrl)
{
obj.ajaxContent = null;
}
},
tooltip: function() {
if (!this.tipso_bubble) {
Expand Down Expand Up @@ -305,11 +310,28 @@
title = this._title;
if (obj.settings.ajaxContentUrl)
{
content = $.ajax({
type: "GET",
url: obj.settings.ajaxContentUrl,
async: false
}).responseText;
if(obj._ajaxContent)
{
content = obj._ajaxContent;
}
else
{
obj._ajaxContent = content = $.ajax({
type: "GET",
url: obj.settings.ajaxContentUrl,
async: false
}).responseText;
if(obj.settings.ajaxContentBuffer > 0)
{
setTimeout(function(){
obj._ajaxContent = null;
}, obj.settings.ajaxContentBuffer);
}
else
{
obj._ajaxContent = null;
}
}
}
else if (obj.settings.contentElementId)
{
Expand Down

0 comments on commit 12ddd17

Please sign in to comment.