PageSourceSearch

https://rethinkdiabetesmaine.org/wp-content/plugins/buddypress-mod…/assets/js/ggpopover.js?ver=1.4.8

js rethinkdiabetesmaine.org collected 2026-10-06 00:36:42 UTC 23,157 bytes, 659 lines download raw bytes

vendor: 23,157 bytes, lines 1-659
1+function ($) {
2    'use strict';
3
4    // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
5    // ============================================================
6
7    function transitionEnd() {
8        var el = document.createElement('gg')
9
10        var transEndEventNames = {
11            WebkitTransition: 'webkitTransitionEnd',
12            MozTransition: 'transitionend',
13            OTransition: 'oTransitionEnd otransitionend',
14            transition: 'transitionend'
15        }
16
17        for (var name in transEndEventNames) {
18            if (el.style[name] !== undefined) {
19                return { end: transEndEventNames[name] }
20            }
21        }
22
23        return false // explicit for ie8 (  ._.)
24    }
25
26    // http://blog.alexmaccaw.com/css-transitions
27    $.fn.emulateTransitionEnd = function (duration) {
28        var called = false
29        var $el = this
30        $(this).one('ggTransitionEnd', function () { called = true })
31        var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
32        setTimeout(callback, duration)
33        return this
34    }
35
36    $(function () {
37        $.support.transition = transitionEnd()
38
39        if (!$.support.transition) return
40
41        $.event.special.ggTransitionEnd = {
42            bindType: $.support.transition.end,
43            delegateType: $.support.transition.end,
44            handle: function (e) {
45                if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments)
46            }
47        }
48    })
49
50}(jQuery);
51
52+function ($) {
53    'use strict';
54
55    // GGTOOLTIP PUBLIC CLASS DEFINITION
56    // ===============================
57
58    var ggTooltip = function (element, options) {
59        this.type =
60        this.options =
61        this.enabled =
62        this.timeout =
63        this.hoverState =
64        this.$element = null
65
66        this.init('tooltip', element, options)
67    }
68
69    ggTooltip.VERSION = '2.0'
70
71    ggTooltip.TRANSITION_DURATION = 150
72
73    ggTooltip.DEFAULTS = {
74        animation: true,
75        placement: 'top',
76        selector: false,
77        template: '<div class="ggtooltip" role="tooltip"><div class="arrow-shadow"><div class="arrow"></div></div><div class="tooltip-inner"></div></div>',
78        trigger: 'hover focus',
79        title: '',
80        delay: 0,
81        html: false,
82        container: false,
83        viewport: {
84            selector: 'body',
85            padding: 0
86        },
87        backcolor: '#00ffcc',
88        textcolor: '#000000',
89        bordercolor: '#0066cc'
90    }
91
92    ggTooltip.prototype.init = function (type, element, options) {
93        this.enabled = true
94        this.type = type
95        this.$element = $(element)
96        this.options = this.getOptions(options)
97        this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport)
98
99        var triggers = this.options.trigger.split(' ')
100
101        for (var i = triggers.length; i--;) {
102            var trigger = triggers[i]
103
104            if (trigger == 'click') {
105                this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
106            } else if (trigger != 'manual') {
107                var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
108                var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
109
110                this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
111                this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
112            }
113        }
114
115        this.options.selector ?
116          (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
117          this.fixTitle()
118    }
119
120    ggTooltip.prototype.getDefaults = function () {
121        return ggTooltip.DEFAULTS
122    }
123
124    ggTooltip.prototype.getOptions = function (options) {
125        options = $.extend({}, this.getDefaults(), this.$element.data(), options)
126
127        if (options.delay && typeof options.delay == 'number') {
128            options.delay = {
129                show: options.delay,
130                hide: options.delay
131            }
132        }
133
134        return options
135    }
136
137    ggTooltip.prototype.getDelegateOptions = function () {
138        var options = {}
139        var defaults = this.getDefaults()
140
141        this._options && $.each(this._options, function (key, value) {
142            if (defaults[key] != value) options[key] = value
143        })
144
145        return options
146    }
147
148    ggTooltip.prototype.enter = function (obj) {
149        var self = obj instanceof this.constructor ?
150            obj : $(obj.currentTarget).data('gg.' + this.type)
151
152        if (self && self.$tip && self.$tip.is(':visible')) {
153            self.hoverState = 'in'
154            return
155        }
156
157        if (!self) {
158            self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
159            $(obj.currentTarget).data('gg.' + this.type, self)
160        }
161
162        clearTimeout(self.timeout)
163
164        self.hoverState = 'in'
165
166        if (!self.options.delay || !self.options.delay.show) return self.show()
167
168        self.timeout = setTimeout(function () {
169            if (self.hoverState == 'in') self.show()
170        }, self.options.delay.show)
171    }
172
173    ggTooltip.prototype.leave = function (obj) {
174        var self = obj instanceof this.constructor ?
175            obj : $(obj.currentTarget).data('gg.' + this.type)
176
177        if (!self) {
178            self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
179            $(obj.currentTarget).data('gg.' + this.type, self)
180        }
181
182        clearTimeout(self.timeout)
183
184        self.hoverState = 'out'
185
186        if (!self.options.delay || !self.options.delay.hide) return self.hide()
187
188        self.timeout = setTimeout(function () {
189            if (self.hoverState == 'out') self.hide()
190        }, self.options.delay.hide)
191    }
192
193    ggTooltip.prototype.show = function () {
194        var e = $.Event('show.gg.' + this.type)
195
196        if (this.hasContent() && this.enabled) {
197            this.$element.trigger(e)
198
199            var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
200            if (e.isDefaultPrevented() || !inDom) return
201            var that = this
202
203            var $tip = this.tip()
204
205            var tipId = this.getUID(this.type)
206
207            this.setContent()
208            $tip.attr('id', tipId)
209            this.$element.attr('aria-describedby', tipId)
210
211            if (this.options.animation) $tip.addClass('fade')
212
213            var placement = typeof this.options.placement == 'function' ?
214              this.options.placement.call(this, $tip[0], this.$element[0]) :
215              this.options.placement
216
217            var autoToken = /\s?auto?\s?/i
218            var autoPlace = autoToken.test(placement)
219            if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
220
221            $tip
222              .detach()
223              .css({ top: 0, left: 0, display: 'block' })
224              .addClass(placement)
225              .data('gg.' + this.type, this)
226
227            this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
228
229            var pos = this.getPosition()
230            var actualWidth = $tip[0].offsetWidth
231            var actualHeight = $tip[0].offsetHeight
232
233            if (autoPlace) {
234                var orgPlacement = placement
235                var $container = this.options.container ? $(this.options.container) : this.$element.parent()
236                var containerDim = this.getPosition($container)
237
238                placement = placement == 'bottom' && pos.bottom + actualHeight > containerDim.bottom ? 'top' :
239                            placement == 'top' && pos.top - actualHeight < containerDim.top ? 'bottom' :
240                            placement == 'right' && pos.right + actualWidth > containerDim.width ? 'left' :
241                            placement == 'left' && pos.left - actualWidth < containerDim.left ? 'right' :
242                            placement
243
244                $tip
245                  .removeClass(orgPlacement)
246                  .addClass(placement)
247            }
248
249            var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
250
251            this.applyPlacement(calculatedOffset, placement)
252
253            var complete = function () {
254                var prevHoverState = that.hoverState
255                that.$element.trigger('shown.gg.' + that.type)
256                that.hoverState = null
257
258                if (prevHoverState == 'out') that.leave(that)
259            }
260
261            $.support.transition && this.$tip.hasClass('fade') ?
262              $tip
263                .one('ggTransitionEnd', complete)
264                .emulateTransitionEnd(ggTooltip.TRANSITION_DURATION) :
265              complete()
266        }
267    }
268
269    ggTooltip.prototype.applyPlacement = function (offset, placement) {
270        var $tip = this.tip()
271        var width = $tip[0].offsetWidth
272        var height = $tip[0].offsetHeight
273
274        // manually read margins because getBoundingClientRect includes difference
275        var marginTop = parseInt($tip.css('margin-top'), 10)
276        var marginLeft = parseInt($tip.css('margin-left'), 10)
277
278        // we must check for NaN for ie 8/9
279        if (isNaN(marginTop)) marginTop = 0
280        if (isNaN(marginLeft)) marginLeft = 0
281
282        offset.top = offset.top + marginTop
283        offset.left = offset.left + marginLeft
284
285        // $.fn.offset doesn't round pixel values
286        // so we use setOffset directly with our own function B-0
287        $.offset.setOffset($tip[0], $.extend({
288            using: function (props) {
289                $tip.css({
290                    top: Math.round(props.top),
291                    left: Math.round(props.left)
292                })
293            }
294        }, offset), 0)
295
296        $tip.addClass('in')
297
298        // check to see if placing tip in new offset caused the tip to resize itself
299        var actualWidth = $tip[0].offsetWidth
300        var actualHeight = $tip[0].offsetHeight
301
302        if (placement == 'top' && actualHeight != height) {
303            offset.top = offset.top + height - actualHeight
304        }
305
306        var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
307
308        if (delta.left) offset.left += delta.left
309        else offset.top += delta.top
310
311        var isVertical = /top|bottom/.test(placement)
312        var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
313        var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
314
315        $tip.offset(offset)
316        this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
317        this.setStyles(placement)
318    }
319
320    ggTooltip.prototype.replaceArrow = function (delta, dimension, isHorizontal) {
321        if (delta > 0) {
322            this.arrow()
323              .css(isHorizontal ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
324              .css(isHorizontal ? 'top' : 'left', '')
325
326            this.arrowShadow()
327              .css(isHorizontal ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
328              .css(isHorizontal ? 'top' : 'left', '')
329        }
330    }
331
332    ggTooltip.prototype.setContent = function () {
333        var $tip = this.tip()
334        var title = this.getTitle()
335
336        $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
337        $tip.removeClass('fade in top bottom left right')
338    }
339
340    ggTooltip.prototype.setStyles = function (placement) {
341        var $tip = this.tip()
342
343        $tip.find('.tooltip-inner').css({ 'background': this.options.backcolor, 'color': this.options.textcolor, 'border-color': this.options.bordercolor });
344        $tip.find('.arrow').css('border-' + placement + '-color', this.options.backcolor);
345        $tip.find('.arrow-shadow').css('border-' + placement + '-color', this.options.bordercolor);
346    }
347
348    ggTooltip.prototype.hide = function (callback) {
349        var that = this
350        var $tip = this.tip()
351        var e = $.Event('hide.gg.' + this.type)
352
353        function complete() {
354            if (that.hoverState != 'in') $tip.detach()
355            that.$element
356              .removeAttr('aria-describedby')
357              .trigger('hidden.gg.' + that.type)
358            callback && callback()
359        }
360
361        this.$element.trigger(e)
362
363        if (e.isDefaultPrevented()) return
364
365        $tip.removeClass('in')
366
367        $.support.transition && this.$tip.hasClass('fade') ?
368          $tip
369            .one('ggTransitionEnd', complete)
370            .emulateTransitionEnd(ggTooltip.TRANSITION_DURATION) :
371          complete()
372
373        this.hoverState = null
374
375        return this
376    }
377
378    ggTooltip.prototype.fixTitle = function () {
379        var $e = this.$element
380        if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') {
381            $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
382        }
383    }
384
385    ggTooltip.prototype.hasContent = function () {
386        return this.getTitle()
387    }
388
389    ggTooltip.prototype.getPosition = function ($element) {
390        $element = $element || this.$element
391
392        var el = $element[0]
393        var isBody = el.tagName == 'BODY'
394
395        var elRect = el.getBoundingClientRect()
396        if (elRect.width == null) {
397            // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
398            elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
399        }
400        var elOffset = isBody ? { top: 0, left: 0 } : $element.offset()
401        var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
402        var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
403
404        return $.extend({}, elRect, scroll, outerDims, elOffset)
405    }
406
407    ggTooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
408        return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
409               placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
410               placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
411            /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
412
413    }
414
415    ggTooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
416        var delta = { top: 0, left: 0 }
417        if (!this.$viewport) return delta
418
419        var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
420        var viewportDimensions = this.getPosition(this.$viewport)
421
422        if (/right|left/.test(placement)) {
423            var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
424            var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
425            if (topEdgeOffset < viewportDimensions.top) { // top overflow
426                delta.top = viewportDimensions.top - topEdgeOffset
427            } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
428                delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
429            }
430        } else {
431            var leftEdgeOffset = pos.left - viewportPadding
432            var rightEdgeOffset = pos.left + viewportPadding + actualWidth
433            if (leftEdgeOffset < viewportDimensions.left) { // left overflow
434                delta.left = viewportDimensions.left - leftEdgeOffset
435            } else if (rightEdgeOffset > viewportDimensions.width) { // right overflow
436                delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
437            }
438        }
439
440        return delta
441    }
442
443    ggTooltip.prototype.getTitle = function () {
444        var title
445        var $e = this.$element
446        var o = this.options
447
448        title = $e.attr('data-original-title')
449          || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
450
451        return title
452    }
453
454    ggTooltip.prototype.getUID = function (prefix) {
455        do prefix += ~~(Math.random() * 1000000)
456        while (document.getElementById(prefix))
457        return prefix
458    }
459
460    ggTooltip.prototype.tip = function () {
461        return (this.$tip = this.$tip || $(this.options.template))
462    }
463
464    ggTooltip.prototype.arrow = function () {
465        return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
466    }
467
468    ggTooltip.prototype.arrowShadow = function () {
469        return (this.$arrowShadow = this.$arrowShadow || this.tip().find('.arrow-shadow'))
470    }
471
472    ggTooltip.prototype.enable = function () {
473        this.enabled = true
474    }
475
476    ggTooltip.prototype.disable = function () {
477        this.enabled = false
478    }
479
480    ggTooltip.prototype.toggleEnabled = function () {
481        this.enabled = !this.enabled
482    }
483
484    ggTooltip.prototype.toggle = function (e) {
485        var self = this
486        if (e) {
487            self = $(e.currentTarget).data('gg.' + this.type)
488            if (!self) {
489                self = new this.constructor(e.currentTarget, this.getDelegateOptions())
490                $(e.currentTarget).data('gg.' + this.type, self)
491            }
492        }
493
494        self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
495    }
496
497    ggTooltip.prototype.destroy = function () {
498        var that = this
499        clearTimeout(this.timeout)
500        this.hide(function () {
501            that.$element.off('.' + that.type).removeData('gg.' + that.type)
502        })
503    }
504
505
506    // GGTOOLTIP PLUGIN DEFINITION
507    // =========================
508
509    function Plugin(option) {
510        return this.each(function () {
511            var $this = $(this)
512            var data = $this.data('gg.tooltip')
513            var options = typeof option == 'object' && option
514
515            if (!data && option == 'destroy') return
516            if (!data) $this.data('gg.tooltip', (data = new ggTooltip(this, options)))
517            if (typeof option == 'string') data[option]()
518        })
519    }
520
521    var old = $.fn.ggtooltip
522
523    $.fn.ggtooltip = Plugin
524    $.fn.ggtooltip.Constructor = ggTooltip
525
526
527    // GGTOOLTIP NO CONFLICT
528    // ===================
529
530    $.fn.ggtooltip.noConflict = function () {
531        $.fn.ggtooltip = old
532        return this
533    }
534
535}(jQuery);
536
537+function ($) {
538  'use strict';
539
540  // GGPOPOVER PUBLIC CLASS DEFINITION
541  // ===============================
542
543  var ggPopover = function (element, options) {
544    this.init('popover', element, options)
545  }
546
547  if (!$.fn.ggtooltip) throw new Error('ggPopover requires ggtooltip.js')
548
549  ggPopover.VERSION  = '1.0'
550
551  ggPopover.DEFAULTS = $.extend({}, $.fn.ggtooltip.Constructor.DEFAULTS, {
552      placement: 'right',
553      trigger: 'click',
554      content: '',
555      template: '<div class="ggpopover" role="tooltip"><div class="arrow"><div class="after"></div></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
556      titleBackcolor: '#f7f7f7',
557      titleBordercolor: '#ebebeb',
558      titleTextcolor: '#000000',
559      contentBackcolor: '#ffffff',
560      contentTextcolor: '#000000',
561      bordercolor: '#cccccc',
562      arrowcolor: '#ffffff'
563  })
564
565
566  // NOTE: GGPOPOVER EXTENDS ggtooltip.js
567  // ================================
568
569  ggPopover.prototype = $.extend({}, $.fn.ggtooltip.Constructor.prototype)
570
571  ggPopover.prototype.constructor = ggPopover
572
573  ggPopover.prototype.getDefaults = function () {
574    return ggPopover.DEFAULTS
575  }
576
577  ggPopover.prototype.setContent = function () {
578    var $tip    = this.tip()
579    var title   = this.getTitle()
580    var content = this.getContent()
581
582    $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
583    $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
584      this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
585    ](content)
586
587    $tip.removeClass('fade top bottom left right in')
588
589    // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
590    // this manually by checking the contents.
591    if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
592  }
593
594  ggPopover.prototype.setStyles = function (placement) {
595      var $tip = this.tip()
596      var title = this.getTitle()
597
598      $tip.find('.popover-title').css({ 'background-color': this.options.titleBackcolor, 'color': this.options.titleTextcolor, 'border-bottom-color': this.options.titleBordercolor });
599      $tip.find('.popover-content').css({ 'background-color': this.options.contentBackcolor, 'color': this.options.contentTextcolor });
600      $tip.find('.arrow').css('border-' + placement + '-color', this.options.bordercolor);
601      $tip.find('.arrow > .after').css('border-' + placement + '-color', this.options.arrowcolor);
602      $tip.css({ 'border-color': this.options.bordercolor });
603      
604  }
605
606  ggPopover.prototype.hasContent = function () {
607    return this.getTitle() || this.getContent()
608  }
609
610  ggPopover.prototype.getContent = function () {
611    var $e = this.$element
612    var o  = this.options
613
614    return $e.attr('data-content')
615      || (typeof o.content == 'function' ?
616            o.content.call($e[0]) :
617            o.content)
618  }
619
620  ggPopover.prototype.arrow = function () {
621    return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
622  }
623
624  ggPopover.prototype.tip = function () {
625    if (!this.$tip) this.$tip = $(this.options.template)
626    return this.$tip
627  }
628
629
630  // GGPOPOVER PLUGIN DEFINITION
631  // =========================
632
633  function Plugin(option) {
634    return this.each(function () {
635      var $this   = $(this)
636      var data    = $this.data('gg.popover')
637      var options = typeof option == 'object' && option
638
639      if (!data && option == 'destroy') return
640      if (!data) $this.data('gg.popover', (data = new ggPopover(this, options)))
641      if (typeof option == 'string') data[option]()
642    })
643  }
644
645  var old = $.fn.ggpopover
646
647  $.fn.ggpopover             = Plugin
648  $.fn.ggpopover.Constructor = ggPopover
649
650
651  // GGPOPOVER NO CONFLICT
652  // ===================
653
654  $.fn.ggpopover.noConflict = function () {
655    $.fn.ggpopover = old
656    return this
657  }
658
659}(jQuery);

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.