| 1 |
"use strict"; |
| 2 |
|
| 3 |
function NoteTip() { |
| 4 |
this.element = document.createElement("div"); |
| 5 |
$(this.element).addClass("note-tip"); |
| 6 |
$(this.element).html("<span class='note-tip-text'></span> <a class='note-close' href='#'>ⓧ</a>"); |
| 7 |
$("body").append(this.element); |
| 8 |
|
| 9 |
var that = this; |
| 10 |
$(".note-close", this.element).click(function() { |
| 11 |
that.hide(); |
| 12 |
return false; |
| 13 |
}); |
| 14 |
} |
| 15 |
|
| 16 |
NoteTip.prototype.element = null; |
| 17 |
|
| 18 |
NoteTip.prototype.onHide = null; |
| 19 |
|
| 20 |
NoteTip.prototype.hide = function() { |
| 21 |
$(this.element).fadeOut(); |
| 22 |
if (this.onHide) { |
| 23 |
this.onHide(); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
NoteTip.prototype.setText = function(text) { |
| 28 |
$(".note-tip-text", this.element).text(text); |
| 29 |
} |
| 30 |
|
| 31 |
NoteTip.prototype.show = function(anchorElement) { |
| 32 |
var offset = $(anchorElement).offset(); |
| 33 |
var elt = $(this.element); |
| 34 |
elt.css({ |
| 35 |
left: (offset.left + $(anchorElement).width() / 2 - elt.outerWidth(true) / 2) + "px", |
| 36 |
top: (offset.top - elt.outerHeight(true) - 6) + "px" |
| 37 |
}) |
| 38 |
.fadeIn(); |
| 39 |
} |