PageSourceSearch

https://diamondeurogistics.co.uk/sites/all/themes/foundation/ems_f…/js/foundation/foundation.tooltip.js?tmfkj1

js diamondeurogistics.co.uk collected 2026-10-07 19:41:23 UTC 10,704 bytes, 307 lines download raw bytes

vendor: 10,704 bytes, lines 1-307
1;(function ($, window, document, undefined) {
2  'use strict';
3
4  Foundation.libs.tooltip = {
5    name : 'tooltip',
6
7    version : '5.5.1',
8
9    settings : {
10      additional_inheritable_classes : [],
11      tooltip_class : '.tooltip',
12      append_to : 'body',
13      touch_close_text : 'Tap To Close',
14      disable_for_touch : false,
15      hover_delay : 200,
16      show_on : 'all',
17      tip_template : function (selector, content) {
18        return '<span data-selector="' + selector + '" id="' + selector + '" class="'
19          + Foundation.libs.tooltip.settings.tooltip_class.substring(1)
20          + '" role="tooltip">' + content + '<span class="nub"></span></span>';
21      }
22    },
23
24    cache : {},
25
26    init : function (scope, method, options) {
27      Foundation.inherit(this, 'random_str');
28      this.bindings(method, options);
29    },
30
31    should_show : function (target, tip) {
32      var settings = $.extend({}, this.settings, this.data_options(target));
33
34      if (settings.show_on === 'all') {
35        return true;
36      } else if (this.small() && settings.show_on === 'small') {
37        return true;
38      } else if (this.medium() && settings.show_on === 'medium') {
39        return true;
40      } else if (this.large() && settings.show_on === 'large') {
41        return true;
42      }
43      return false;
44    },
45
46    medium : function () {
47      return matchMedia(Foundation.media_queries['medium']).matches;
48    },
49
50    large : function () {
51      return matchMedia(Foundation.media_queries['large']).matches;
52    },
53
54    events : function (instance) {
55      var self = this,
56          S = self.S;
57
58      self.create(this.S(instance));
59
60      $(this.scope)
61        .off('.tooltip')
62        .on('mouseenter.fndtn.tooltip mouseleave.fndtn.tooltip touchstart.fndtn.tooltip MSPointerDown.fndtn.tooltip',
63          '[' + this.attr_name() + ']', function (e) {
64          var $this = S(this),
65              settings = $.extend({}, self.settings, self.data_options($this)),
66              is_touch = false;
67
68          if (Modernizr.touch && /touchstart|MSPointerDown/i.test(e.type) && S(e.target).is('a')) {
69            return false;
70          }
71
72          if (/mouse/i.test(e.type) && self.ie_touch(e)) {
73            return false;
74          }
75
76          if ($this.hasClass('open')) {
77            if (Modernizr.touch && /touchstart|MSPointerDown/i.test(e.type)) {
78              e.preventDefault();
79            }
80            self.hide($this);
81          } else {
82            if (settings.disable_for_touch && Modernizr.touch && /touchstart|MSPointerDown/i.test(e.type)) {
83              return;
84            } else if (!settings.disable_for_touch && Modernizr.touch && /touchstart|MSPointerDown/i.test(e.type)) {
85              e.preventDefault();
86              S(settings.tooltip_class + '.open').hide();
87              is_touch = true;
88            }
89
90            if (/enter|over/i.test(e.type)) {
91              this.timer = setTimeout(function () {
92                var tip = self.showTip($this);
93              }.bind(this), self.settings.hover_delay);
94            } else if (e.type === 'mouseout' || e.type === 'mouseleave') {
95              clearTimeout(this.timer);
96              self.hide($this);
97            } else {
98              self.showTip($this);
99            }
100          }
101        })
102        .on('mouseleave.fndtn.tooltip touchstart.fndtn.tooltip MSPointerDown.fndtn.tooltip', '[' + this.attr_name() + '].open', function (e) {
103          if (/mouse/i.test(e.type) && self.ie_touch(e)) {
104            return false;
105          }
106
107          if ($(this).data('tooltip-open-event-type') == 'touch' && e.type == 'mouseleave') {
108            return;
109          } else if ($(this).data('tooltip-open-event-type') == 'mouse' && /MSPointerDown|touchstart/i.test(e.type)) {
110            self.convert_to_touch($(this));
111          } else {
112            self.hide($(this));
113          }
114        })
115        .on('DOMNodeRemoved DOMAttrModified', '[' + this.attr_name() + ']:not(a)', function (e) {
116          self.hide(S(this));
117        });
118    },
119
120    ie_touch : function (e) {
121      // How do I distinguish between IE11 and Windows Phone 8?????
122      return false;
123    },
124
125    showTip : function ($target) {
126      var $tip = this.getTip($target);
127      if (this.should_show($target, $tip)) {
128        return this.show($target);
129      }
130      return;
131    },
132
133    getTip : function ($target) {
134      var selector = this.selector($target),
135          settings = $.extend({}, this.settings, this.data_options($target)),
136          tip = null;
137
138      if (selector) {
139        tip = this.S('span[data-selector="' + selector + '"]' + settings.tooltip_class);
140      }
141
142      return (typeof tip === 'object') ? tip : false;
143    },
144
145    selector : function ($target) {
146      var id = $target.attr('id'),
147          dataSelector = $target.attr(this.attr_name()) || $target.attr('data-selector');
148
149      if ((id && id.length < 1 || !id) && typeof dataSelector != 'string') {
150        dataSelector = this.random_str(6);
151        $target
152          .attr('data-selector', dataSelector)
153          .attr('aria-describedby', dataSelector);
154      }
155
156      return (id && id.length > 0) ? id : dataSelector;
157    },
158
159    create : function ($target) {
160      var self = this,
161          settings = $.extend({}, this.settings, this.data_options($target)),
162          tip_template = this.settings.tip_template;
163
164      if (typeof settings.tip_template === 'string' && window.hasOwnProperty(settings.tip_template)) {
165        tip_template = window[settings.tip_template];
166      }
167
168      var $tip = $(tip_template(this.selector($target), $('<div></div>').html($target.attr('title')).html())),
169          classes = this.inheritable_classes($target);
170
171      $tip.addClass(classes).appendTo(settings.append_to);
172
173      if (Modernizr.touch) {
174        $tip.append('<span class="tap-to-close">' + settings.touch_close_text + '</span>');
175        $tip.on('touchstart.fndtn.tooltip MSPointerDown.fndtn.tooltip', function (e) {
176          self.hide($target);
177        });
178      }
179
180      $target.removeAttr('title').attr('title', '');
181    },
182
183    reposition : function (target, tip, classes) {
184      var width, nub, nubHeight, nubWidth, column, objPos;
185
186      tip.css('visibility', 'hidden').show();
187
188      width = target.data('width');
189      nub = tip.children('.nub');
190      nubHeight = nub.outerHeight();
191      nubWidth = nub.outerHeight();
192
193      if (this.small()) {
194        tip.css({'width' : '100%'});
195      } else {
196        tip.css({'width' : (width) ? width : 'auto'});
197      }
198
199      objPos = function (obj, top, right, bottom, left, width) {
200        return obj.css({
201          'top' : (top) ? top : 'auto',
202          'bottom' : (bottom) ? bottom : 'auto',
203          'left' : (left) ? left : 'auto',
204          'right' : (right) ? right : 'auto'
205        }).end();
206      };
207
208      objPos(tip, (target.offset().top + target.outerHeight() + 10), 'auto', 'auto', target.offset().left);
209
210      if (this.small()) {
211        objPos(tip, (target.offset().top + target.outerHeight() + 10), 'auto', 'auto', 12.5, $(this.scope).width());
212        tip.addClass('tip-override');
213        objPos(nub, -nubHeight, 'auto', 'auto', target.offset().left);
214      } else {
215        var left = target.offset().left;
216        if (Foundation.rtl) {
217          nub.addClass('rtl');
218          left = target.offset().left + target.outerWidth() - tip.outerWidth();
219        }
220        objPos(tip, (target.offset().top + target.outerHeight() + 10), 'auto', 'auto', left);
221        tip.removeClass('tip-override');
222        if (classes && classes.indexOf('tip-top') > -1) {
223          if (Foundation.rtl) {
224            nub.addClass('rtl');
225          }
226          objPos(tip, (target.offset().top - tip.outerHeight()), 'auto', 'auto', left)
227            .removeClass('tip-override');
228        } else if (classes && classes.indexOf('tip-left') > -1) {
229          objPos(tip, (target.offset().top + (target.outerHeight() / 2) - (tip.outerHeight() / 2)), 'auto', 'auto', (target.offset().left - tip.outerWidth() - nubHeight))
230            .removeClass('tip-override');
231          nub.removeClass('rtl');
232        } else if (classes && classes.indexOf('tip-right') > -1) {
233          objPos(tip, (target.offset().top + (target.outerHeight() / 2) - (tip.outerHeight() / 2)), 'auto', 'auto', (target.offset().left + target.outerWidth() + nubHeight))
234            .removeClass('tip-override');
235          nub.removeClass('rtl');
236        }
237      }
238
239      tip.css('visibility', 'visible').hide();
240    },
241
242    small : function () {
243      return matchMedia(Foundation.media_queries.small).matches &&
244        !matchMedia(Foundation.media_queries.medium).matches;
245    },
246
247    inheritable_classes : function ($target) {
248      var settings = $.extend({}, this.settings, this.data_options($target)),
249          inheritables = ['tip-top', 'tip-left', 'tip-bottom', 'tip-right', 'radius', 'round'].concat(settings.additional_inheritable_classes),
250          classes = $target.attr('class'),
251          filtered = classes ? $.map(classes.split(' '), function (el, i) {
252            if ($.inArray(el, inheritables) !== -1) {
253              return el;
254            }
255          }).join(' ') : '';
256
257      return $.trim(filtered);
258    },
259
260    convert_to_touch : function ($target) {
261      var self = this,
262          $tip = self.getTip($target),
263          settings = $.extend({}, self.settings, self.data_options($target));
264
265      if ($tip.find('.tap-to-close').length === 0) {
266        $tip.append('<span class="tap-to-close">' + settings.touch_close_text + '</span>');
267        $tip.on('click.fndtn.tooltip.tapclose touchstart.fndtn.tooltip.tapclose MSPointerDown.fndtn.tooltip.tapclose', function (e) {
268          self.hide($target);
269        });
270      }
271
272      $target.data('tooltip-open-event-type', 'touch');
273    },
274
275    show : function ($target) {
276      var $tip = this.getTip($target);
277
278      if ($target.data('tooltip-open-event-type') == 'touch') {
279        this.convert_to_touch($target);
280      }
281
282      this.reposition($target, $tip, $target.attr('class'));
283      $target.addClass('open');
284      $tip.fadeIn(150);
285    },
286
287    hide : function ($target) {
288      var $tip = this.getTip($target);
289
290      $tip.fadeOut(150, function () {
291        $tip.find('.tap-to-close').remove();
292        $tip.off('click.fndtn.tooltip.tapclose MSPointerDown.fndtn.tapclose');
293        $target.removeClass('open');
294      });
295    },
296
297    off : function () {
298      var self = this;
299      this.S(this.scope).off('.fndtn.tooltip');
300      this.S(this.settings.tooltip_class).each(function (i) {
301        $('[' + self.attr_name() + ']').eq(i).attr('title', $(this).text());
302      }).remove();
303    },
304
305    reflow : function () {}
306  };
307}(jQuery, window, window.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.