forked from bombledmonk/advancedsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tooltipster.bundle.js
4217 lines (3497 loc) · 115 KB
/
tooltipster.bundle.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
/**
* tooltipster http://iamceege.github.io/tooltipster/
* A rockin' custom tooltip jQuery plugin
* Developed by Caleb Jacob and Louis Ameline
* MIT license
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define(["jQuery"], function (a0) {
return (factory(a0));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("jQuery"));
} else {
factory(jQuery);
}
}(this, function ($) {
// This file will be UMDified by a build task.
var defaults = {
animation: 'fade',
animationDuration: 350,
content: null,
contentAsHTML: false,
contentCloning: false,
debug: true,
delay: 300,
delayTouch: [300, 500],
functionInit: null,
functionBefore: null,
functionReady: null,
functionAfter: null,
functionFormat: null,
IEmin: 6,
interactive: false,
multiple: false,
// must be 'body' for now, or an element positioned at (0, 0)
// in the document, typically like the very top views of an app.
parent: 'body',
plugins: ['sideTip'],
repositionOnScroll: false,
restoration: 'none',
selfDestruction: true,
theme: [],
timer: 0,
trackerInterval: 500,
trackOrigin: false,
trackTooltip: false,
trigger: 'hover',
triggerClose: {
click: false,
mouseleave: false,
originClick: false,
scroll: false,
tap: false,
touchleave: false
},
triggerOpen: {
click: false,
mouseenter: false,
tap: false,
touchstart: false
},
updateAnimation: 'rotate',
zIndex: 9999999
},
// we'll avoid using window as a global. To run in Node,
// window must be mocked up through $.tooltipster.__setWindow
win = (window !== undefined) ? window : null,
// env will be proxied by the core for plugins to have access its properties
env = {
// detect if this device can trigger touch events. Better have a false
// positive (unused listeners, that's ok) than a false negative.
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
// http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript
hasTouchCapability: !!(
'ontouchstart' in win
|| (win.DocumentTouch && document instanceof DocumentTouch)
|| navigator.maxTouchPoints
),
hasTransitions: transitionSupport(),
IE: false,
// don't set manually, it will be updated by a build task after the manifest
semVer: '4.1.0',
window: win
},
core = function() {
// core variables
// the core emitters
this.__$emitterPrivate = $({});
this.__$emitterPublic = $({});
this.__instancesLatestArr = [];
// collects plugin constructors
this.__plugins = {};
// proxy env variables for plugins who might use them
this._env = env;
};
// core methods
core.prototype = {
/**
* A function to proxy the public methods of an object onto another
*
* @param {object} constructor The constructor to bridge
* @param {object} obj The object that will get new methods (an instance or the core)
* @param {string} pluginName A plugin name for the console log message
* @return {core}
* @private
*/
__bridge: function(constructor, obj, pluginName) {
// if it's not already bridged
if (!obj[pluginName]) {
var fn = function() {};
fn.prototype = constructor;
var pluginInstance = new fn();
// the _init method has to exist in instance constructors but might be missing
// in core constructors
if (pluginInstance.__init) {
pluginInstance.__init(obj);
}
$.each(constructor, function(methodName, fn) {
// don't proxy "private" methods, only "protected" and public ones
if (methodName.indexOf('__') != 0) {
// if the method does not exist yet
if (!obj[methodName]) {
obj[methodName] = function() {
return pluginInstance[methodName].apply(pluginInstance, Array.prototype.slice.apply(arguments));
};
// remember to which plugin this method corresponds (several plugins may
// have methods of the same name, we need to be sure)
obj[methodName].bridged = pluginInstance;
}
else if (defaults.debug) {
console.log('The '+ methodName +' method of the '+ pluginName
+' plugin conflicts with another plugin or native methods');
}
}
});
obj[pluginName] = pluginInstance;
}
return this;
},
/**
* For mockup in Node env if need be, for testing purposes
*
* @return {core}
* @private
*/
__setWindow: function(window) {
env.window = window;
return this;
},
/**
* Returns a ruler, a tool to help measure the size of a tooltip under
* various settings. Meant for plugins
*
* @see Ruler
* @return {object} A Ruler instance
* @protected
*/
_getRuler: function($tooltip) {
return new Ruler($tooltip);
},
/**
* For internal use by plugins, if needed
*
* @return {core}
* @protected
*/
_off: function() {
this.__$emitterPrivate.off.apply(this.__$emitterPrivate, Array.prototype.slice.apply(arguments));
return this;
},
/**
* For internal use by plugins, if needed
*
* @return {core}
* @protected
*/
_on: function() {
this.__$emitterPrivate.on.apply(this.__$emitterPrivate, Array.prototype.slice.apply(arguments));
return this;
},
/**
* For internal use by plugins, if needed
*
* @return {core}
* @protected
*/
_one: function() {
this.__$emitterPrivate.one.apply(this.__$emitterPrivate, Array.prototype.slice.apply(arguments));
return this;
},
/**
* Returns (getter) or adds (setter) a plugin
*
* @param {string|object} plugin Provide a string (in the full form
* "namespace.name") to use as as getter, an object to use as a setter
* @return {object|core}
* @protected
*/
_plugin: function(plugin) {
var self = this;
// getter
if (typeof plugin == 'string') {
var pluginName = plugin,
p = null;
// if the namespace is provided, it's easy to search
if (pluginName.indexOf('.') > 0) {
p = self.__plugins[pluginName];
}
// otherwise, return the first name that matches
else {
$.each(self.__plugins, function(i, plugin) {
if (plugin.name.substring(plugin.name.length - pluginName.length - 1) == '.'+ pluginName) {
p = plugin;
return false;
}
});
}
return p;
}
// setter
else {
// force namespaces
if (plugin.name.indexOf('.') < 0) {
throw new Error('Plugins must be namespaced');
}
self.__plugins[plugin.name] = plugin;
// if the plugin has core features
if (plugin.core) {
// bridge non-private methods onto the core to allow new core methods
self.__bridge(plugin.core, self, plugin.name);
}
return this;
}
},
/**
* Trigger events on the core emitters
*
* @returns {core}
* @protected
*/
_trigger: function() {
var args = Array.prototype.slice.apply(arguments);
if (typeof args[0] == 'string') {
args[0] = { type: args[0] };
}
// note: the order of emitters matters
this.__$emitterPrivate.trigger.apply(this.__$emitterPrivate, args);
this.__$emitterPublic.trigger.apply(this.__$emitterPublic, args);
return this;
},
/**
* Returns instances of all tooltips in the page or an a given element
*
* @param {string|HTML object collection} selector optional Use this
* parameter to restrict the set of objects that will be inspected
* for the retrieval of instances. By default, all instances in the
* page are returned.
* @return {array} An array of instance objects
* @public
*/
instances: function(selector) {
var instances = [],
sel = selector || '.tooltipstered';
$(sel).each(function() {
var $this = $(this),
ns = $this.data('tooltipster-ns');
if (ns) {
$.each(ns, function(i, namespace) {
instances.push($this.data(namespace));
});
}
});
return instances;
},
/**
* Returns the Tooltipster objects generated by the last initializing call
*
* @return {array} An array of instance objects
* @public
*/
instancesLatest: function() {
return this.__instancesLatestArr;
},
/**
* For public use only, not to be used by plugins (use ::_off() instead)
*
* @return {core}
* @public
*/
off: function() {
this.__$emitterPublic.off.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
return this;
},
/**
* For public use only, not to be used by plugins (use ::_on() instead)
*
* @return {core}
* @public
*/
on: function() {
this.__$emitterPublic.on.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
return this;
},
/**
* For public use only, not to be used by plugins (use ::_one() instead)
*
* @return {core}
* @public
*/
one: function() {
this.__$emitterPublic.one.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
return this;
},
/**
* Returns all HTML elements which have one or more tooltips
*
* @param {string} selector optional Use this to restrict the results
* to the descendants of an element
* @return {array} An array of HTML elements
* @public
*/
origins: function(selector) {
var sel = selector ?
selector +' ' :
'';
return $(sel +'.tooltipstered').toArray();
},
/**
* Change default options for all future instances
*
* @param {object} d The options that should be made defaults
* @return {core}
* @public
*/
setDefaults: function(d) {
$.extend(defaults, d);
return this;
},
/**
* For users to trigger their handlers on the public emitter
*
* @returns {core}
* @public
*/
triggerHandler: function() {
this.__$emitterPublic.triggerHandler.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
return this;
}
};
// $.tooltipster will be used to call core methods
$.tooltipster = new core();
// the Tooltipster instance class (mind the capital T)
$.Tooltipster = function(element, options) {
// list of instance variables
// stack of custom callbacks provided as parameters to API methods
this.__callbacks = {
close: [],
open: []
};
// the schedule time of DOM removal
this.__closingTime;
// this will be the user content shown in the tooltip. A capital "C" is used
// because there is also a method called content()
this.__Content;
// for the size tracker
this.__contentBcr;
// to disable the tooltip once the destruction has begun
this.__destroyed = false;
this.__destroying = false;
// we can't emit directly on the instance because if a method with the same
// name as the event exists, it will be called by jQuery. Se we use a plain
// object as emitter. This emitter is for internal use by plugins,
// if needed.
this.__$emitterPrivate = $({});
// this emitter is for the user to listen to events without risking to mess
// with our internal listeners
this.__$emitterPublic = $({});
this.__enabled = true;
// the reference to the gc interval
this.__garbageCollector;
// various position and size data recomputed before each repositioning
this.__Geometry;
// the tooltip position, saved after each repositioning by a plugin
this.__lastPosition;
// a unique namespace per instance
this.__namespace = 'tooltipster-'+ Math.round(Math.random()*1000000);
this.__options;
// will be used to support origins in scrollable areas
this.__$originParents;
this.__pointerIsOverOrigin = false;
// to remove themes if needed
this.__previousThemes = [];
// the state can be either: appearing, stable, disappearing, closed
this.__state = 'closed';
// timeout references
this.__timeouts = {
close: [],
open: null
};
// store touch events to be able to detect emulated mouse events
this.__touchEvents = [];
// the reference to the tracker interval
this.__tracker = null;
// the element to which this tooltip is associated
this._$origin;
// this will be the tooltip element (jQuery wrapped HTML element).
// It's the job of a plugin to create it and append it to the DOM
this._$tooltip;
// launch
this.__init(element, options);
};
$.Tooltipster.prototype = {
/**
* @param origin
* @param options
* @private
*/
__init: function(origin, options) {
var self = this;
self._$origin = $(origin);
self.__options = $.extend(true, {}, defaults, options);
// some options may need to be reformatted
self.__optionsFormat();
// don't run on old IE if asked no to
if ( !env.IE
|| env.IE >= self.__options.IEmin
) {
// note: the content is null (empty) by default and can stay that
// way if the plugin remains initialized but not fed any content. The
// tooltip will just not appear.
// let's save the initial value of the title attribute for later
// restoration if need be.
var initialTitle = null;
// it will already have been saved in case of multiple tooltips
if (self._$origin.data('tooltipster-initialTitle') === undefined) {
initialTitle = self._$origin.attr('title');
// we do not want initialTitle to be "undefined" because
// of how jQuery's .data() method works
if (initialTitle === undefined) initialTitle = null;
self._$origin.data('tooltipster-initialTitle', initialTitle);
}
// If content is provided in the options, it has precedence over the
// title attribute.
// Note: an empty string is considered content, only 'null' represents
// the absence of content.
// Also, an existing title="" attribute will result in an empty string
// content
if (self.__options.content !== null) {
self.__contentSet(self.__options.content);
}
else {
var selector = self._$origin.attr('data-tooltip-content'),
$el;
if (selector){
$el = $(selector);
}
if ($el && $el[0]) {
self.__contentSet($el.first());
}
else {
self.__contentSet(initialTitle);
}
}
self._$origin
// strip the title off of the element to prevent the default tooltips
// from popping up
.removeAttr('title')
// to be able to find all instances on the page later (upon window
// events in particular)
.addClass('tooltipstered');
// set listeners on the origin
self.__prepareOrigin();
// set the garbage collector
self.__prepareGC();
// init plugins
$.each(self.__options.plugins, function(i, pluginName) {
self._plug(pluginName);
});
// to detect swiping
if (env.hasTouchCapability) {
$('body').on('touchmove.'+ self.__namespace +'-triggerOpen', function(event) {
self._touchRecordEvent(event);
});
}
self
// prepare the tooltip when it gets created. This event must
// be fired by a plugin
._on('created', function() {
self.__prepareTooltip();
})
// save position information when it's sent by a plugin
._on('repositioned', function(e) {
self.__lastPosition = e.position;
});
}
else {
self.__options.disabled = true;
}
},
/**
* Insert the content into the appropriate HTML element of the tooltip
*
* @returns {self}
* @private
*/
__contentInsert: function() {
var self = this,
$el = self._$tooltip.find('.tooltipster-content'),
formattedContent = self.__Content,
format = function(content) {
formattedContent = content;
};
self._trigger({
type: 'format',
content: self.__Content,
format: format
});
if (self.__options.functionFormat) {
formattedContent = self.__options.functionFormat.call(
self,
self,
{ origin: self._$origin[0] },
self.__Content
);
}
if (typeof formattedContent === 'string' && !self.__options.contentAsHTML) {
$el.text(formattedContent);
}
else {
$el
.empty()
.append(formattedContent);
}
return self;
},
/**
* Save the content, cloning it beforehand if need be
*
* @param content
* @returns {self}
* @private
*/
__contentSet: function(content) {
// clone if asked. Cloning the object makes sure that each instance has its
// own version of the content (in case a same object were provided for several
// instances)
// reminder: typeof null === object
if (content instanceof $ && this.__options.contentCloning) {
content = content.clone(true);
}
this.__Content = content;
this._trigger({
type: 'updated',
content: content
});
return this;
},
/**
* Error message about a method call made after destruction
*
* @private
*/
__destroyError: function() {
throw new Error('This tooltip has been destroyed and cannot execute your method call.');
},
/**
* Gather all information about dimensions and available space,
* called before every repositioning
*
* @private
* @returns {object}
*/
__geometry: function() {
var self = this,
$target = self._$origin,
originIsArea = self._$origin.is('area');
// if this._$origin is a map area, the target we'll need
// the dimensions of is actually the image using the map,
// not the area itself
if (originIsArea) {
var mapName = self._$origin.parent().attr('name');
$target = $('img[usemap="#'+ mapName +'"]');
}
var bcr = $target[0].getBoundingClientRect(),
$document = $(env.window.document),
$window = $(env.window),
$parent = $target,
// some useful properties of important elements
geo = {
// available space for the tooltip, see down below
available: {
document: null,
window: null
},
document: {
size: {
height: $document.height(),
width: $document.width()
}
},
window: {
scroll: {
// the second ones are for IE compatibility
left: env.window.scrollX || env.window.document.documentElement.scrollLeft,
top: env.window.scrollY || env.window.document.documentElement.scrollTop
},
size: {
height: $window.height(),
width: $window.width()
}
},
origin: {
// the origin has a fixed lineage if itself or one of its
// ancestors has a fixed position
fixedLineage: false,
// relative to the document
offset: {},
size: {
height: bcr.bottom - bcr.top,
width: bcr.right - bcr.left
},
usemapImage: originIsArea ? $target[0] : null,
// relative to the window
windowOffset: {
bottom: bcr.bottom,
left: bcr.left,
right: bcr.right,
top: bcr.top
}
}
},
geoFixed = false;
// if the element is a map area, some properties may need
// to be recalculated
if (originIsArea) {
var shape = self._$origin.attr('shape'),
coords = self._$origin.attr('coords');
if (coords) {
coords = coords.split(',');
$.map(coords, function(val, i) {
coords[i] = parseInt(val);
});
}
// if the image itself is the area, nothing more to do
if (shape != 'default') {
switch(shape) {
case 'circle':
var circleCenterLeft = coords[0],
circleCenterTop = coords[1],
circleRadius = coords[2],
areaTopOffset = circleCenterTop - circleRadius,
areaLeftOffset = circleCenterLeft - circleRadius;
geo.origin.size.height = circleRadius * 2;
geo.origin.size.width = geo.origin.size.height;
geo.origin.windowOffset.left += areaLeftOffset;
geo.origin.windowOffset.top += areaTopOffset;
break;
case 'rect':
var areaLeft = coords[0],
areaTop = coords[1],
areaRight = coords[2],
areaBottom = coords[3];
geo.origin.size.height = areaBottom - areaTop;
geo.origin.size.width = areaRight - areaLeft;
geo.origin.windowOffset.left += areaLeft;
geo.origin.windowOffset.top += areaTop;
break;
case 'poly':
var areaSmallestX = 0,
areaSmallestY = 0,
areaGreatestX = 0,
areaGreatestY = 0,
arrayAlternate = 'even';
for (var i = 0; i < coords.length; i++) {
var areaNumber = coords[i];
if (arrayAlternate == 'even') {
if (areaNumber > areaGreatestX) {
areaGreatestX = areaNumber;
if (i === 0) {
areaSmallestX = areaGreatestX;
}
}
if (areaNumber < areaSmallestX) {
areaSmallestX = areaNumber;
}
arrayAlternate = 'odd';
}
else {
if (areaNumber > areaGreatestY) {
areaGreatestY = areaNumber;
if (i == 1) {
areaSmallestY = areaGreatestY;
}
}
if (areaNumber < areaSmallestY) {
areaSmallestY = areaNumber;
}
arrayAlternate = 'even';
}
}
geo.origin.size.height = areaGreatestY - areaSmallestY;
geo.origin.size.width = areaGreatestX - areaSmallestX;
geo.origin.windowOffset.left += areaSmallestX;
geo.origin.windowOffset.top += areaSmallestY;
break;
}
}
}
// user callback through an event
var edit = function(r) {
geo.origin.size.height = r.height,
geo.origin.windowOffset.left = r.left,
geo.origin.windowOffset.top = r.top,
geo.origin.size.width = r.width
};
self._trigger({
type: 'geometry',
edit: edit,
geometry: {
height: geo.origin.size.height,
left: geo.origin.windowOffset.left,
top: geo.origin.windowOffset.top,
width: geo.origin.size.width
}
});
// calculate the remaining properties with what we got
geo.origin.windowOffset.right = geo.origin.windowOffset.left + geo.origin.size.width;
geo.origin.windowOffset.bottom = geo.origin.windowOffset.top + geo.origin.size.height;
geo.origin.offset.left = geo.origin.windowOffset.left + env.window.scrollX;
geo.origin.offset.top = geo.origin.windowOffset.top + env.window.scrollY;
geo.origin.offset.bottom = geo.origin.offset.top + geo.origin.size.height;
geo.origin.offset.right = geo.origin.offset.left + geo.origin.size.width;
// the space that is available to display the tooltip relatively to the document
geo.available.document = {
bottom: {
height: geo.document.size.height - geo.origin.offset.bottom,
width: geo.document.size.width
},
left: {
height: geo.document.size.height,
width: geo.origin.offset.left
},
right: {
height: geo.document.size.height,
width: geo.document.size.width - geo.origin.offset.right
},
top: {
height: geo.origin.offset.top,
width: geo.document.size.width
}
};
// the space that is available to display the tooltip relatively to the viewport
// (the resulting values may be negative if the origin overflows the viewport)
geo.available.window = {
bottom: {
// the inner max is here to make sure the available height is no bigger
// than the viewport height (when the origin is off screen at the top).
// The outer max just makes sure that the height is not negative (when
// the origin overflows at the bottom).
height: Math.max(geo.window.size.height - Math.max(geo.origin.windowOffset.bottom, 0), 0),
width: geo.window.size.width
},
left: {
height: geo.window.size.height,
width: Math.max(geo.origin.windowOffset.left, 0)
},
right: {
height: geo.window.size.height,
width: Math.max(geo.window.size.width - Math.max(geo.origin.windowOffset.right, 0), 0)
},
top: {
height: Math.max(geo.origin.windowOffset.top, 0),
width: geo.window.size.width
}
};
while ($parent[0].tagName.toLowerCase() != 'html') {
if ($parent.css('position') == 'fixed') {
geo.origin.fixedLineage = true;
break;
}
$parent = $parent.parent();
}
return geo;
},
/**
* Some options may need to be formated before being used
*
* @returns {self}
* @private
*/
__optionsFormat: function() {
if (typeof this.__options.animationDuration == 'number') {
this.__options.animationDuration = [this.__options.animationDuration, this.__options.animationDuration];
}
if (typeof this.__options.delay == 'number') {
this.__options.delay = [this.__options.delay, this.__options.delay];
}
if (typeof this.__options.delayTouch == 'number') {
this.__options.delayTouch = [this.__options.delayTouch, this.__options.delayTouch];
}
if (typeof this.__options.theme == 'string') {
this.__options.theme = [this.__options.theme];
}
// determine the future parent
if (typeof this.__options.parent == 'string') {
this.__options.parent = $(this.__options.parent);
}
if (this.__options.trigger == 'hover') {
this.__options.triggerOpen = {
mouseenter: true,
touchstart: true
};
this.__options.triggerClose = {
mouseleave: true,
originClick: true,
touchleave: true
};
}
else if (this.__options.trigger == 'click') {
this.__options.triggerOpen = {
click: true,
tap: true
};
this.__options.triggerClose = {
click: true,
tap: true
};
}
// for the plugins
this._trigger('options');
return this;
},
/**
* Schedules or cancels the garbage collector task