-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.qtip.js
executable file
·2928 lines (2425 loc) · 85.7 KB
/
jquery.qtip.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* qTip2 - Pretty powerful tooltips - v2.2.0
* http://qtip2.com
*
* Copyright (c) 2014 Craig Michael Thompson
* Released under the MIT, GPL licenses
* http://jquery.org/license
*
* Date: Mon Mar 17 2014 08:13 EDT-0400
* Plugins: tips viewport svg
* Styles: None
*/
/*global window: false, jQuery: false, console: false, define: false */
/* Cache window, document, undefined */
(function( window, document, undefined ) {
// Uses AMD or browser globals to create a jQuery plugin.
(function( factory ) {
"use strict";
if(typeof define === 'function' && define.amd) {
define(['jquery'], factory);
}
else if(jQuery && !jQuery.fn.qtip) {
factory(jQuery);
}
}
(function($) {
"use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
;// Munge the primitives - Paul Irish tip
var TRUE = true,
FALSE = false,
NULL = null,
// Common variables
X = 'x', Y = 'y',
WIDTH = 'width',
HEIGHT = 'height',
// Positioning sides
TOP = 'top',
LEFT = 'left',
BOTTOM = 'bottom',
RIGHT = 'right',
CENTER = 'center',
// Position adjustment types
FLIP = 'flip',
FLIPINVERT = 'flipinvert',
SHIFT = 'shift',
// Shortcut vars
QTIP, PROTOTYPE, CORNER, CHECKS,
PLUGINS = {},
NAMESPACE = 'qtip',
ATTR_HAS = 'data-hasqtip',
ATTR_ID = 'data-qtip-id',
WIDGET = ['ui-widget', 'ui-tooltip'],
SELECTOR = '.'+NAMESPACE,
INACTIVE_EVENTS = 'click dblclick mousedown mouseup mousemove mouseleave mouseenter'.split(' '),
CLASS_FIXED = NAMESPACE+'-fixed',
CLASS_DEFAULT = NAMESPACE + '-default',
CLASS_FOCUS = NAMESPACE + '-focus',
CLASS_HOVER = NAMESPACE + '-hover',
CLASS_DISABLED = NAMESPACE+'-disabled',
replaceSuffix = '_replacedByqTip',
oldtitle = 'oldtitle',
trackingBound,
// Browser detection
BROWSER = {
/*
* IE version detection
*
* Adapted from: http://ajaxian.com/archives/attack-of-the-ie-conditional-comment
* Credit to James Padolsey for the original implemntation!
*/
ie: (function(){
var v = 3, div = document.createElement('div');
while ((div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->')) {
if(!div.getElementsByTagName('i')[0]) { break; }
}
return v > 4 ? v : NaN;
}()),
/*
* iOS version detection
*/
iOS: parseFloat(
('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1])
.replace('undefined', '3_2').replace('_', '.').replace('_', '')
) || FALSE
};
;function QTip(target, options, id, attr) {
// Elements and ID
this.id = id;
this.target = target;
this.tooltip = NULL;
this.elements = { target: target };
// Internal constructs
this._id = NAMESPACE + '-' + id;
this.timers = { img: {} };
this.options = options;
this.plugins = {};
// Cache object
this.cache = {
event: {},
target: $(),
disabled: FALSE,
attr: attr,
onTooltip: FALSE,
lastClass: ''
};
// Set the initial flags
this.rendered = this.destroyed = this.disabled = this.waiting =
this.hiddenDuringWait = this.positioning = this.triggering = FALSE;
}
PROTOTYPE = QTip.prototype;
PROTOTYPE._when = function(deferreds) {
return $.when.apply($, deferreds);
};
PROTOTYPE.render = function(show) {
if(this.rendered || this.destroyed) { return this; } // If tooltip has already been rendered, exit
var self = this,
options = this.options,
cache = this.cache,
elements = this.elements,
text = options.content.text,
title = options.content.title,
button = options.content.button,
posOptions = options.position,
namespace = '.'+this._id+' ',
deferreds = [],
tooltip;
// Add ARIA attributes to target
$.attr(this.target[0], 'aria-describedby', this._id);
// Create tooltip element
this.tooltip = elements.tooltip = tooltip = $('<div/>', {
'id': this._id,
'class': [ NAMESPACE, CLASS_DEFAULT, options.style.classes, NAMESPACE + '-pos-' + options.position.my.abbrev() ].join(' '),
'width': options.style.width || '',
'height': options.style.height || '',
'tracking': posOptions.target === 'mouse' && posOptions.adjust.mouse,
/* ARIA specific attributes */
'role': 'alert',
'aria-live': 'polite',
'aria-atomic': FALSE,
'aria-describedby': this._id + '-content',
'aria-hidden': TRUE
})
.toggleClass(CLASS_DISABLED, this.disabled)
.attr(ATTR_ID, this.id)
.data(NAMESPACE, this)
.appendTo(posOptions.container)
.append(
// Create content element
elements.content = $('<div />', {
'class': NAMESPACE + '-content',
'id': this._id + '-content',
'aria-atomic': TRUE
})
);
// Set rendered flag and prevent redundant reposition calls for now
this.rendered = -1;
this.positioning = TRUE;
// Create title...
if(title) {
this._createTitle();
// Update title only if its not a callback (called in toggle if so)
if(!$.isFunction(title)) {
deferreds.push( this._updateTitle(title, FALSE) );
}
}
// Create button
if(button) { this._createButton(); }
// Set proper rendered flag and update content if not a callback function (called in toggle)
if(!$.isFunction(text)) {
deferreds.push( this._updateContent(text, FALSE) );
}
this.rendered = TRUE;
// Setup widget classes
this._setWidget();
// Initialize 'render' plugins
$.each(PLUGINS, function(name) {
var instance;
if(this.initialize === 'render' && (instance = this(self))) {
self.plugins[name] = instance;
}
});
// Unassign initial events and assign proper events
this._unassignEvents();
this._assignEvents();
// When deferreds have completed
this._when(deferreds).then(function() {
// tooltiprender event
self._trigger('render');
// Reset flags
self.positioning = FALSE;
// Show tooltip if not hidden during wait period
if(!self.hiddenDuringWait && (options.show.ready || show)) {
self.toggle(TRUE, cache.event, FALSE);
}
self.hiddenDuringWait = FALSE;
});
// Expose API
QTIP.api[this.id] = this;
return this;
};
PROTOTYPE.destroy = function(immediate) {
// Set flag the signify destroy is taking place to plugins
// and ensure it only gets destroyed once!
if(this.destroyed) { return this.target; }
function process() {
if(this.destroyed) { return; }
this.destroyed = TRUE;
var target = this.target,
title = target.attr(oldtitle);
// Destroy tooltip if rendered
if(this.rendered) {
this.tooltip.stop(1,0).find('*').remove().end().remove();
}
// Destroy all plugins
$.each(this.plugins, function(name) {
this.destroy && this.destroy();
});
// Clear timers and remove bound events
clearTimeout(this.timers.show);
clearTimeout(this.timers.hide);
this._unassignEvents();
// Remove api object and ARIA attributes
target.removeData(NAMESPACE)
.removeAttr(ATTR_ID)
.removeAttr(ATTR_HAS)
.removeAttr('aria-describedby');
// Reset old title attribute if removed
if(this.options.suppress && title) {
target.attr('title', title).removeAttr(oldtitle);
}
// Remove qTip events associated with this API
this._unbind(target);
// Remove ID from used id objects, and delete object references
// for better garbage collection and leak protection
this.options = this.elements = this.cache = this.timers =
this.plugins = this.mouse = NULL;
// Delete epoxsed API object
delete QTIP.api[this.id];
}
// If an immediate destory is needed
if((immediate !== TRUE || this.triggering === 'hide') && this.rendered) {
this.tooltip.one('tooltiphidden', $.proxy(process, this));
!this.triggering && this.hide();
}
// If we're not in the process of hiding... process
else { process.call(this); }
return this.target;
};
;function invalidOpt(a) {
return a === NULL || $.type(a) !== 'object';
}
function invalidContent(c) {
return !( $.isFunction(c) || (c && c.attr) || c.length || ($.type(c) === 'object' && (c.jquery || c.then) ));
}
// Option object sanitizer
function sanitizeOptions(opts) {
var content, text, ajax, once;
if(invalidOpt(opts)) { return FALSE; }
if(invalidOpt(opts.metadata)) {
opts.metadata = { type: opts.metadata };
}
if('content' in opts) {
content = opts.content;
if(invalidOpt(content) || content.jquery || content.done) {
content = opts.content = {
text: (text = invalidContent(content) ? FALSE : content)
};
}
else { text = content.text; }
// DEPRECATED - Old content.ajax plugin functionality
// Converts it into the proper Deferred syntax
if('ajax' in content) {
ajax = content.ajax;
once = ajax && ajax.once !== FALSE;
delete content.ajax;
content.text = function(event, api) {
var loading = text || $(this).attr(api.options.content.attr) || 'Loading...',
deferred = $.ajax(
$.extend({}, ajax, { context: api })
)
.then(ajax.success, NULL, ajax.error)
.then(function(content) {
if(content && once) { api.set('content.text', content); }
return content;
},
function(xhr, status, error) {
if(api.destroyed || xhr.status === 0) { return; }
api.set('content.text', status + ': ' + error);
});
return !once ? (api.set('content.text', loading), deferred) : loading;
};
}
if('title' in content) {
if(!invalidOpt(content.title)) {
content.button = content.title.button;
content.title = content.title.text;
}
if(invalidContent(content.title || FALSE)) {
content.title = FALSE;
}
}
}
if('position' in opts && invalidOpt(opts.position)) {
opts.position = { my: opts.position, at: opts.position };
}
if('show' in opts && invalidOpt(opts.show)) {
opts.show = opts.show.jquery ? { target: opts.show } :
opts.show === TRUE ? { ready: TRUE } : { event: opts.show };
}
if('hide' in opts && invalidOpt(opts.hide)) {
opts.hide = opts.hide.jquery ? { target: opts.hide } : { event: opts.hide };
}
if('style' in opts && invalidOpt(opts.style)) {
opts.style = { classes: opts.style };
}
// Sanitize plugin options
$.each(PLUGINS, function() {
this.sanitize && this.sanitize(opts);
});
return opts;
}
// Setup builtin .set() option checks
CHECKS = PROTOTYPE.checks = {
builtin: {
// Core checks
'^id$': function(obj, o, v, prev) {
var id = v === TRUE ? QTIP.nextid : v,
new_id = NAMESPACE + '-' + id;
if(id !== FALSE && id.length > 0 && !$('#'+new_id).length) {
this._id = new_id;
if(this.rendered) {
this.tooltip[0].id = this._id;
this.elements.content[0].id = this._id + '-content';
this.elements.title[0].id = this._id + '-title';
}
}
else { obj[o] = prev; }
},
'^prerender': function(obj, o, v) {
v && !this.rendered && this.render(this.options.show.ready);
},
// Content checks
'^content.text$': function(obj, o, v) {
this._updateContent(v);
},
'^content.attr$': function(obj, o, v, prev) {
if(this.options.content.text === this.target.attr(prev)) {
this._updateContent( this.target.attr(v) );
}
},
'^content.title$': function(obj, o, v) {
// Remove title if content is null
if(!v) { return this._removeTitle(); }
// If title isn't already created, create it now and update
v && !this.elements.title && this._createTitle();
this._updateTitle(v);
},
'^content.button$': function(obj, o, v) {
this._updateButton(v);
},
'^content.title.(text|button)$': function(obj, o, v) {
this.set('content.'+o, v); // Backwards title.text/button compat
},
// Position checks
'^position.(my|at)$': function(obj, o, v){
'string' === typeof v && (obj[o] = new CORNER(v, o === 'at'));
},
'^position.container$': function(obj, o, v){
this.rendered && this.tooltip.appendTo(v);
},
// Show checks
'^show.ready$': function(obj, o, v) {
v && (!this.rendered && this.render(TRUE) || this.toggle(TRUE));
},
// Style checks
'^style.classes$': function(obj, o, v, p) {
this.rendered && this.tooltip.removeClass(p).addClass(v);
},
'^style.(width|height)': function(obj, o, v) {
this.rendered && this.tooltip.css(o, v);
},
'^style.widget|content.title': function() {
this.rendered && this._setWidget();
},
'^style.def': function(obj, o, v) {
this.rendered && this.tooltip.toggleClass(CLASS_DEFAULT, !!v);
},
// Events check
'^events.(render|show|move|hide|focus|blur)$': function(obj, o, v) {
this.rendered && this.tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v);
},
// Properties which require event reassignment
'^(show|hide|position).(event|target|fixed|inactive|leave|distance|viewport|adjust)': function() {
if(!this.rendered) { return; }
// Set tracking flag
var posOptions = this.options.position;
this.tooltip.attr('tracking', posOptions.target === 'mouse' && posOptions.adjust.mouse);
// Reassign events
this._unassignEvents();
this._assignEvents();
}
}
};
// Dot notation converter
function convertNotation(options, notation) {
var i = 0, obj, option = options,
// Split notation into array
levels = notation.split('.');
// Loop through
while( option = option[ levels[i++] ] ) {
if(i < levels.length) { obj = option; }
}
return [obj || options, levels.pop()];
}
PROTOTYPE.get = function(notation) {
if(this.destroyed) { return this; }
var o = convertNotation(this.options, notation.toLowerCase()),
result = o[0][ o[1] ];
return result.precedance ? result.string() : result;
};
function setCallback(notation, args) {
var category, rule, match;
for(category in this.checks) {
for(rule in this.checks[category]) {
if(match = (new RegExp(rule, 'i')).exec(notation)) {
args.push(match);
if(category === 'builtin' || this.plugins[category]) {
this.checks[category][rule].apply(
this.plugins[category] || this, args
);
}
}
}
}
}
var rmove = /^position\.(my|at|adjust|target|container|viewport)|style|content|show\.ready/i,
rrender = /^prerender|show\.ready/i;
PROTOTYPE.set = function(option, value) {
if(this.destroyed) { return this; }
var rendered = this.rendered,
reposition = FALSE,
options = this.options,
checks = this.checks,
name;
// Convert singular option/value pair into object form
if('string' === typeof option) {
name = option; option = {}; option[name] = value;
}
else { option = $.extend({}, option); }
// Set all of the defined options to their new values
$.each(option, function(notation, value) {
if(rendered && rrender.test(notation)) {
delete option[notation]; return;
}
// Set new obj value
var obj = convertNotation(options, notation.toLowerCase()), previous;
previous = obj[0][ obj[1] ];
obj[0][ obj[1] ] = value && value.nodeType ? $(value) : value;
// Also check if we need to reposition
reposition = rmove.test(notation) || reposition;
// Set the new params for the callback
option[notation] = [obj[0], obj[1], value, previous];
});
// Re-sanitize options
sanitizeOptions(options);
/*
* Execute any valid callbacks for the set options
* Also set positioning flag so we don't get loads of redundant repositioning calls.
*/
this.positioning = TRUE;
$.each(option, $.proxy(setCallback, this));
this.positioning = FALSE;
// Update position if needed
if(this.rendered && this.tooltip[0].offsetWidth > 0 && reposition) {
this.reposition( options.position.target === 'mouse' ? NULL : this.cache.event );
}
return this;
};
;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);
}, NULL, function(e) {
return self._update(e, element);
});
}
// 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.empty().append(
content.css({ display: 'block', visibility: 'visible' })
);
}
// Content is a regular string, insert the new content
else { element.html(content); }
// Wait for content to be loaded, and reposition
return this._waitForContent(element).then(function(images) {
if(images.images && images.images.length && self.rendered && self.tooltip[0].offsetWidth > 0) {
self.reposition(cache.event, !images.length);
}
});
};
PROTOTYPE._waitForContent = function(element) {
var cache = this.cache;
// Set flag
cache.waiting = TRUE;
// If imagesLoaded is included, ensure images have loaded and return promise
return ( $.fn.imagesLoaded ? element.imagesLoaded() : $.Deferred().resolve([]) )
.done(function() { cache.waiting = FALSE; })
.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(); }
}
};
;PROTOTYPE.reposition = function(event, effect) {
if(!this.rendered || this.positioning || this.destroyed) { return this; }
// Set positioning flag
this.positioning = TRUE;
var cache = this.cache,
tooltip = this.tooltip,
posOptions = this.options.position,
target = posOptions.target,
my = posOptions.my,
at = posOptions.at,
viewport = posOptions.viewport,
container = posOptions.container,
adjust = posOptions.adjust,
method = adjust.method.split(' '),
tooltipWidth = tooltip.outerWidth(FALSE),
tooltipHeight = tooltip.outerHeight(FALSE),
targetWidth = 0,
targetHeight = 0,
type = tooltip.css('position'),
position = { left: 0, top: 0 },
visible = tooltip[0].offsetWidth > 0,
isScroll = event && event.type === 'scroll',
win = $(window),
doc = container[0].ownerDocument,
mouse = this.mouse,
pluginCalculations, offset;
// Check if absolute position was passed
if($.isArray(target) && target.length === 2) {
// Force left top and set position
at = { x: LEFT, y: TOP };
position = { left: target[0], top: target[1] };
}
// Check if mouse was the target
else if(target === 'mouse') {
// Force left top to allow flipping
at = { x: LEFT, y: TOP };
// Use the cached mouse coordinates if available, or passed event has no coordinates
if(mouse && mouse.pageX && (adjust.mouse || !event || !event.pageX) ) {
event = mouse;
}
// If the passed event has no coordinates (such as a scroll event)
else if(!event || !event.pageX) {
// Use the mouse origin that caused the show event, if distance hiding is enabled
if((!adjust.mouse || this.options.show.distance) && cache.origin && cache.origin.pageX) {
event = cache.origin;
}
// Use cached event for resize/scroll events
else if(!event || (event && (event.type === 'resize' || event.type === 'scroll'))) {
event = cache.event;
}
}
// Calculate body and container offset and take them into account below
if(type !== 'static') { position = container.offset(); }
if(doc.body.offsetWidth !== (window.innerWidth || doc.documentElement.clientWidth)) {
offset = $(document.body).offset();
}
// Use event coordinates for position
position = {
left: event.pageX - position.left + (offset && offset.left || 0),
top: event.pageY - position.top + (offset && offset.top || 0)
};
// Scroll events are a pain, some browsers
if(adjust.mouse && isScroll && mouse) {
position.left -= (mouse.scrollX || 0) - win.scrollLeft();
position.top -= (mouse.scrollY || 0) - win.scrollTop();
}
}
// Target wasn't mouse or absolute...
else {
// Check if event targetting is being used
if(target === 'event') {
if(event && event.target && event.type !== 'scroll' && event.type !== 'resize') {
cache.target = $(event.target);
}
else if(!event.target) {
cache.target = this.elements.target;
}
}
else if(target !== 'event'){
cache.target = $(target.jquery ? target : this.elements.target);
}
target = cache.target;
// Parse the target into a jQuery object and make sure there's an element present
target = $(target).eq(0);
if(target.length === 0) { return this; }
// Check if window or document is the target
else if(target[0] === document || target[0] === window) {
targetWidth = BROWSER.iOS ? window.innerWidth : target.width();
targetHeight = BROWSER.iOS ? window.innerHeight : target.height();
if(target[0] === window) {
position = {
top: (viewport || target).scrollTop(),
left: (viewport || target).scrollLeft()
};
}
}
// Check if the target is an <AREA> element
else if(PLUGINS.imagemap && target.is('area')) {
pluginCalculations = PLUGINS.imagemap(this, target, at, PLUGINS.viewport ? method : FALSE);
}
// Check if the target is an SVG element
else if(PLUGINS.svg && target && target[0].ownerSVGElement) {
pluginCalculations = PLUGINS.svg(this, target, at, PLUGINS.viewport ? method : FALSE);
}
// Otherwise use regular jQuery methods
else {
targetWidth = target.outerWidth(FALSE);
targetHeight = target.outerHeight(FALSE);
position = target.offset();
}
// Parse returned plugin values into proper variables
if(pluginCalculations) {
targetWidth = pluginCalculations.width;
targetHeight = pluginCalculations.height;
offset = pluginCalculations.offset;
position = pluginCalculations.position;
}
// Adjust position to take into account offset parents
position = this.reposition.offset(target, position, container);
// Adjust for position.fixed tooltips (and also iOS scroll bug in v3.2-4.0 & v4.3-4.3.2)
if((BROWSER.iOS > 3.1 && BROWSER.iOS < 4.1) ||
(BROWSER.iOS >= 4.3 && BROWSER.iOS < 4.33) ||
(!BROWSER.iOS && type === 'fixed')
){
position.left -= win.scrollLeft();
position.top -= win.scrollTop();
}
// Adjust position relative to target
if(!pluginCalculations || (pluginCalculations && pluginCalculations.adjustable !== FALSE)) {
position.left += at.x === RIGHT ? targetWidth : at.x === CENTER ? targetWidth / 2 : 0;
position.top += at.y === BOTTOM ? targetHeight : at.y === CENTER ? targetHeight / 2 : 0;
}
}
// Adjust position relative to tooltip
position.left += adjust.x + (my.x === RIGHT ? -tooltipWidth : my.x === CENTER ? -tooltipWidth / 2 : 0);
position.top += adjust.y + (my.y === BOTTOM ? -tooltipHeight : my.y === CENTER ? -tooltipHeight / 2 : 0);
// Use viewport adjustment plugin if enabled
if(PLUGINS.viewport) {
position.adjusted = PLUGINS.viewport(
this, position, posOptions, targetWidth, targetHeight, tooltipWidth, tooltipHeight
);
// Apply offsets supplied by positioning plugin (if used)
if(offset && position.adjusted.left) { position.left += offset.left; }
if(offset && position.adjusted.top) { position.top += offset.top; }
}
// Viewport adjustment is disabled, set values to zero
else { position.adjusted = { left: 0, top: 0 }; }
// tooltipmove event
if(!this._trigger('move', [position, viewport.elem || viewport], event)) { return this; }
delete position.adjusted;
// If effect is disabled, target it mouse, no animation is defined or positioning gives NaN out, set CSS directly
if(effect === FALSE || !visible || isNaN(position.left) || isNaN(position.top) || target === 'mouse' || !$.isFunction(posOptions.effect)) {
tooltip.css(position);
}
// Use custom function if provided
else if($.isFunction(posOptions.effect)) {
posOptions.effect.call(tooltip, this, $.extend({}, position));
tooltip.queue(function(next) {
// Reset attributes to avoid cross-browser rendering bugs
$(this).css({ opacity: '', height: '' });
if(BROWSER.ie) { this.style.removeAttribute('filter'); }
next();
});
}
// Set positioning flag
this.positioning = FALSE;
return this;
};
// Custom (more correct for qTip!) offset calculator
PROTOTYPE.reposition.offset = function(elem, pos, container) {
if(!container[0]) { return pos; }
var ownerDocument = $(elem[0].ownerDocument),
quirks = !!BROWSER.ie && document.compatMode !== 'CSS1Compat',
parent = container[0],
scrolled, position, parentOffset, overflow;
function scroll(e, i) {
pos.left += i * e.scrollLeft();
pos.top += i * e.scrollTop();
}
// Compensate for non-static containers offset
do {
if((position = $.css(parent, 'position')) !== 'static') {
if(position === 'fixed') {
parentOffset = parent.getBoundingClientRect();
scroll(ownerDocument, -1);
}
else {
parentOffset = $(parent).position();
parentOffset.left += (parseFloat($.css(parent, 'borderLeftWidth')) || 0);
parentOffset.top += (parseFloat($.css(parent, 'borderTopWidth')) || 0);
}
pos.left -= parentOffset.left + (parseFloat($.css(parent, 'marginLeft')) || 0);
pos.top -= parentOffset.top + (parseFloat($.css(parent, 'marginTop')) || 0);
// If this is the first parent element with an overflow of "scroll" or "auto", store it
if(!scrolled && (overflow = $.css(parent, 'overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = $(parent); }
}
}
while((parent = parent.offsetParent));
// Compensate for containers scroll if it also has an offsetParent (or in IE quirks mode)
if(scrolled && (scrolled[0] !== ownerDocument[0] || quirks)) {
scroll(scrolled, 1);
}
return pos;
};
// Corner class
var C = (CORNER = PROTOTYPE.reposition.Corner = function(corner, forceY) {
corner = ('' + corner).replace(/([A-Z])/, ' $1').replace(/middle/gi, CENTER).toLowerCase();
this.x = (corner.match(/left|right/i) || corner.match(/center/) || ['inherit'])[0].toLowerCase();
this.y = (corner.match(/top|bottom|center/i) || ['inherit'])[0].toLowerCase();
this.forceY = !!forceY;
var f = corner.charAt(0);
this.precedance = (f === 't' || f === 'b' ? Y : X);
}).prototype;
C.invert = function(z, center) {
this[z] = this[z] === LEFT ? RIGHT : this[z] === RIGHT ? LEFT : center || this[z];
};
C.string = function() {
var x = this.x, y = this.y;
return x === y ? x : this.precedance === Y || (this.forceY && y !== 'center') ? y+' '+x : x+' '+y;
};
C.abbrev = function() {
var result = this.string().split(' ');
return result[0].charAt(0) + (result[1] && result[1].charAt(0) || '');
};
C.clone = function() {
return new CORNER( this.string(), this.forceY );
};;
PROTOTYPE.toggle = function(state, event) {
var cache = this.cache,
options = this.options,
tooltip = this.tooltip;
// Try to prevent flickering when tooltip overlaps show element
if(event) {
if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) &&
options.show.target.add(event.target).length === options.show.target.length &&
tooltip.has(event.relatedTarget).length) {
return this;
}
// Cache event
cache.event = cloneEvent(event);
}
// If we're currently waiting and we've just hidden... stop it
this.waiting && !state && (this.hiddenDuringWait = TRUE);
// Render the tooltip if showing and it isn't already
if(!this.rendered) { return state ? this.render(1) : this; }
else if(this.destroyed || this.disabled) { return this; }
var type = state ? 'show' : 'hide',
opts = this.options[type],
otherOpts = this.options[ !state ? 'show' : 'hide' ],
posOptions = this.options.position,
contentOptions = this.options.content,
width = this.tooltip.css('width'),
visible = this.tooltip.is(':visible'),
animate = state || opts.target.length === 1,
sameTarget = !event || opts.target.length < 2 || cache.target[0] === event.target,
identicalState, allow, showEvent, delay, after;
// Detect state if valid one isn't provided