PageSourceSearch

https://www.jhrl.com/sites/all/themes/custom/vrweb_foundation/js/v…/foundation/foundation.tooltips.js?tlse4v

js jhrl.com collected 2026-10-06 13:18:49 UTC 7,181 bytes, 208 lines download raw bytes

1/*jslint unparam: true, browser: true, indent: 2 */
2
3;(function ($, window, document, undefined) {
4  'use strict';
5
6  Foundation.libs.tooltips = {
7    name : 'tooltips',
8
9    version : '4.2.2',
10
11    settings : {
12      selector : '.has-tip',
13      additionalInheritableClasses : [],
14      tooltipClass : '.tooltip',
15      appendTo: 'body',
16      'disable-for-touch': false,
17      tipTemplate : function (selector, content) {
18        return '<span data-selector="' + selector + '" class="' 
19          + Foundation.libs.tooltips.settings.tooltipClass.substring(1) 
20          + '">' + content + '<span class="nub"></span></span>';
21      }
22    },
23
24    cache : {},
25
26    init : function (scope, method, options) {
27      Foundation.inherit(this, 'data_options');
28      var self = this;
29
30      if (typeof method === 'object') {
31        $.extend(true, this.settings, method);
32      } else if (typeof options !== 'undefined') {
33        $.extend(true, this.settings, options);
34      }
35
36      if (typeof method !== 'string') {
37        if (Modernizr.touch) {
38          $(this.scope)
39            .on('click.fndtn.tooltip touchstart.fndtn.tooltip touchend.fndtn.tooltip', 
40              '[data-tooltip]', function (e) {
41              var settings = $.extend({}, self.settings, self.data_options($(this)));
42              if (!settings['disable-for-touch']) {
43                e.preventDefault();
44                $(settings.tooltipClass).hide();
45                self.showOrCreateTip($(this));
46              }
47            })
48            .on('click.fndtn.tooltip touchstart.fndtn.tooltip touchend.fndtn.tooltip', 
49              this.settings.tooltipClass, function (e) {
50              e.preventDefault();
51              $(this).fadeOut(150);
52            });
53        } else {
54          $(this.scope)
55            .on('mouseenter.fndtn.tooltip mouseleave.fndtn.tooltip', 
56              '[data-tooltip]', function (e) {
57              var $this = $(this);
58
59              if (/enter|over/i.test(e.type)) {
60                self.showOrCreateTip($this);
61              } else if (e.type === 'mouseout' || e.type === 'mouseleave') {
62                self.hide($this);
63              }
64            });
65        }
66
67        // $(this.scope).data('fndtn-tooltips', true);
68      } else {
69        return this[method].call(this, options);
70      }
71
72    },
73
74    showOrCreateTip : function ($target) {
75      var $tip = this.getTip($target);
76
77      if ($tip && $tip.length > 0) {
78        return this.show($target);
79      }
80
81      return this.create($target);
82    },
83
84    getTip : function ($target) {
85      var selector = this.selector($target),
86          tip = null;
87
88      if (selector) {
89        tip = $('span[data-selector="' + selector + '"]' + this.settings.tooltipClass);
90      }
91
92      return (typeof tip === 'object') ? tip : false;
93    },
94
95    selector : function ($target) {
96      var id = $target.attr('id'),
97          dataSelector = $target.attr('data-tooltip') || $target.attr('data-selector');
98
99      if ((id && id.length < 1 || !id) && typeof dataSelector != 'string') {
100        dataSelector = 'tooltip' + Math.random().toString(36).substring(7);
101        $target.attr('data-selector', dataSelector);
102      }
103
104      return (id && id.length > 0) ? id : dataSelector;
105    },
106
107    create : function ($target) {
108      var $tip = $(this.settings.tipTemplate(this.selector($target), $('<div></div>').html($target.attr('title')).html())),
109          classes = this.inheritable_classes($target);
110
111      $tip.addClass(classes).appendTo(this.settings.appendTo);
112      if (Modernizr.touch) {
113        $tip.append('<span class="tap-to-close">tap to close </span>');
114      }
115      $target.removeAttr('title').attr('title','');
116      this.show($target);
117    },
118
119    reposition : function (target, tip, classes) {
120      var width, nub, nubHeight, nubWidth, column, objPos;
121
122      tip.css('visibility', 'hidden').show();
123
124      width = target.data('width');
125      nub = tip.children('.nub');
126      nubHeight = this.outerHeight(nub);
127      nubWidth = this.outerHeight(nub);
128
129      objPos = function (obj, top, right, bottom, left, width) {
130        return obj.css({
131          'top' : (top) ? top : 'auto',
132          'bottom' : (bottom) ? bottom : 'auto',
133          'left' : (left) ? left : 'auto',
134          'right' : (right) ? right : 'auto',
135          'width' : (width) ? width : 'auto'
136        }).end();
137      };
138
139      objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', target.offset().left, width);
140
141      if ($(window).width() < 767) {
142        objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', 12.5, $(this.scope).width());
143        tip.addClass('tip-override');
144        objPos(nub, -nubHeight, 'auto', 'auto', target.offset().left);
145      } else {
146        var left = target.offset().left;
147        if (Foundation.rtl) {
148          left = target.offset().left + target.offset().width - this.outerWidth(tip);
149        }
150        objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', left, width);
151        tip.removeClass('tip-override');
152        if (classes && classes.indexOf('tip-top') > -1) {
153          objPos(tip, (target.offset().top - this.outerHeight(tip)), 'auto', 'auto', left, width)
154            .removeClass('tip-override');
155        } else if (classes && classes.indexOf('tip-left') > -1) {
156          objPos(tip, (target.offset().top + (this.outerHeight(target) / 2) - nubHeight*2.5), 'auto', 'auto', (target.offset().left - this.outerWidth(tip) - nubHeight), width)
157            .removeClass('tip-override');
158        } else if (classes && classes.indexOf('tip-right') > -1) {
159          objPos(tip, (target.offset().top + (this.outerHeight(target) / 2) - nubHeight*2.5), 'auto', 'auto', (target.offset().left + this.outerWidth(target) + nubHeight), width)
160            .removeClass('tip-override');
161        }
162      }
163
164      tip.css('visibility', 'visible').hide();
165    },
166
167    inheritable_classes : function (target) {
168      var inheritables = ['tip-top', 'tip-left', 'tip-bottom', 'tip-right', 'noradius'].concat(this.settings.additionalInheritableClasses),
169          classes = target.attr('class'),
170          filtered = classes ? $.map(classes.split(' '), function (el, i) {
171            if ($.inArray(el, inheritables) !== -1) {
172              return el;
173            }
174          }).join(' ') : '';
175
176      return $.trim(filtered);
177    },
178
179    show : function ($target) {
180      var $tip = this.getTip($target);
181
182      this.reposition($target, $tip, $target.attr('class'));
183      $tip.fadeIn(150);
184    },
185
186    hide : function ($target) {
187      var $tip = this.getTip($target);
188
189      $tip.fadeOut(150);
190    },
191
192    // deprecate reload
193    reload : function () {
194      var $self = $(this);
195
196      return ($self.data('fndtn-tooltips')) ? $self.foundationTooltips('destroy').foundationTooltips('init') : $self.foundationTooltips('init');
197    },
198
199    off : function () {
200      $(this.scope).off('.fndtn.tooltip');
201      $(this.settings.tooltipClass).each(function (i) {
202        $('[data-tooltip]').get(i).attr('title', $(this).text());
203      }).remove();
204    },
205
206    reflow : function () {}
207  };
208}(Foundation.zj, this, this.document));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.