Skip to content

Commit

Permalink
Merge pull request #1299 from muffinmad/master
Browse files Browse the repository at this point in the history
Don't show empty tooltips - fixes #1298
  • Loading branch information
Arian Stolwijk committed Feb 16, 2015
2 parents ebbbc90 + 6621acb commit 7d556a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions Docs/Interface/Tips.md
Expand Up @@ -27,6 +27,7 @@ Tips Method: constructor

* showDelay - (*number*: defaults to 100) The delay the show event is fired.
* hideDelay - (*number*: defaults to 100) The delay the hide hide is fired.
* hideEmpty - (*boolean*: defaults to *false*) If set to true, the empty tooltip will not be shown.
* title - (*string|function*: defaults to title) The property of the element to be used for the tip-title. If this option is a function it will execute it on every element with it passed as the first argument. It uses the return value of this function as the tip-title
* text - (*string|function*) Behaves the same as the `title` option but for tip-text. By default it either uses the `rel` or the `href` attribute as tip-text.
* className - (*string*: defaults to *null*) The className your tooltip container will get. Useful for styling.
Expand Down
19 changes: 14 additions & 5 deletions Source/Interface/Tips.js
Expand Up @@ -58,7 +58,8 @@ this.Tips = new Class({
offset: {x: 16, y: 16},
windowPadding: {x:0, y:0},
fixed: false,
waiAria: true
waiAria: true,
hideEmpty: false
},

initialize: function(){
Expand Down Expand Up @@ -86,7 +87,8 @@ this.Tips = new Class({
styles: {
position: 'absolute',
top: 0,
left: 0
left: 0,
display: 'none'
}
}).adopt(
new Element('div', {'class': 'tip-top'}),
Expand Down Expand Up @@ -170,15 +172,22 @@ this.Tips = new Class({
clearTimeout(this.timer);
this.timer = (function(){
this.container.empty();

var showTip = !this.options.hideEmpty;
['title', 'text'].each(function(value){
var content = element.retrieve('tip:' + value);
var div = this['_' + value + 'Element'] = new Element('div', {
'class': 'tip-' + value
}).inject(this.container);
if (content) this.fill(div, content);
if (content){
this.fill(div, content);
showTip = true;
}
}, this);
this.show(element);
if (showTip){
this.show(element);
} else {
this.hide(element);
}
this.position((this.options.fixed) ? {page: element.getPosition()} : event);
}).delay(this.options.showDelay, this);
},
Expand Down

0 comments on commit 7d556a0

Please sign in to comment.