This repository has been archived by the owner on Jun 14, 2020. It is now read-only.
/
content.js
104 lines (85 loc) · 2.84 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
PROTOTYPE._update = function(content, element, reposition) {
var self = this,
cache = this.cache;
// Make sure tooltip is rendered and content is defined. If not return
if(!this.rendered || !content) { return FALSE; }
// Use function to parse content
if($.isFunction(content)) {
content = content.call(this.elements.target, cache.event, this) || '';
}
// Handle deferred content
if($.isFunction(content.then)) {
cache.waiting = TRUE;
return content.then(function(c) {
cache.waiting = FALSE;
return self._update(c, element, reposition);
}, NULL, function(e) {
return self._update(e, element, reposition);
});
}
// If content is null... return false
if(content === FALSE || (!content && content !== '')) { return FALSE; }
// Append new content if its a DOM array and show it if hidden
if(content.jquery && content.length > 0) {
element.children().detach().end().append( content.css({ display: 'block' }) );
}
// Content is a regular string, insert the new content
else { element.html(content); }
// Ensure images have loaded...
cache.waiting = TRUE;
return element.imagesLoaded()
.done(function(images) {
cache.waiting = FALSE;
// Reposition if rendered
if(reposition !== FALSE && self.rendered && self.tooltip[0].offsetWidth > 0) {
self.reposition(cache.event, !images.length);
}
})
.promise();
};
PROTOTYPE._updateContent = function(content, reposition) {
this._update(content, this.elements.content, reposition);
};
PROTOTYPE._updateTitle = function(content, reposition) {
if(this._update(content, this.elements.title, reposition) === FALSE) {
this._removeTitle(FALSE);
}
};
PROTOTYPE._createTitle = function()
{
var elements = this.elements,
id = this._id+'-title';
// Destroy previous title element, if present
if(elements.titlebar) { this._removeTitle(); }
// Create title bar and title elements
elements.titlebar = $('<div />', {
'class': NAMESPACE + '-titlebar ' + (this.options.style.widget ? createWidgetClass('header') : '')
})
.append(
elements.title = $('<div />', {
'id': id,
'class': NAMESPACE + '-title',
'aria-atomic': TRUE
})
)
.insertBefore(elements.content)
// Button-specific events
.delegate('.qtip-close', 'mousedown keydown mouseup keyup mouseout', function(event) {
$(this).toggleClass('ui-state-active ui-state-focus', event.type.substr(-4) === 'down');
})
.delegate('.qtip-close', 'mouseover mouseout', function(event){
$(this).toggleClass('ui-state-hover', event.type === 'mouseover');
});
// Create button if enabled
if(this.options.content.button) { this._createButton(); }
};
PROTOTYPE._removeTitle = function(reposition)
{
var elements = this.elements;
if(elements.title) {
elements.titlebar.remove();
elements.titlebar = elements.title = elements.button = NULL;
// Reposition if enabled
if(reposition !== FALSE) { this.reposition(); }
}
};