PageSourceSearch

https://www.performancephilosophy.org/wordpress/wp-content/themes/square-plus/js/waypoint.js?ver=1.1.0

js performancephilosophy.org collected 2026-10-01 11:41:07 UTC 19,961 bytes, 650 lines download raw bytes

1/*!
2 Waypoints - 4.0.0
3 Copyright © 2011-2015 Caleb Troughton
4 Licensed under the MIT license.
5 https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
6 */
7(function () {
8    'use strict'
9
10    var keyCounter = 0
11    var allWaypoints = {}
12
13    /* http://imakewebthings.com/waypoints/api/waypoint */
14    function Waypoint(options) {
15        if (!options) {
16            throw new Error('No options passed to Waypoint constructor')
17        }
18        if (!options.element) {
19            throw new Error('No element option passed to Waypoint constructor')
20        }
21        if (!options.handler) {
22            throw new Error('No handler option passed to Waypoint constructor')
23        }
24
25        this.key = 'waypoint-' + keyCounter
26        this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options)
27        this.element = this.options.element
28        this.adapter = new Waypoint.Adapter(this.element)
29        this.callback = options.handler
30        this.axis = this.options.horizontal ? 'horizontal' : 'vertical'
31        this.enabled = this.options.enabled
32        this.triggerPoint = null
33        this.group = Waypoint.Group.findOrCreate({
34            name: this.options.group,
35            axis: this.axis
36        })
37        this.context = Waypoint.Context.findOrCreateByElement(this.options.context)
38
39        if (Waypoint.offsetAliases[this.options.offset]) {
40            this.options.offset = Waypoint.offsetAliases[this.options.offset]
41        }
42        this.group.add(this)
43        this.context.add(this)
44        allWaypoints[this.key] = this
45        keyCounter += 1
46    }
47
48    /* Private */
49    Waypoint.prototype.queueTrigger = function (direction) {
50        this.group.queueTrigger(this, direction)
51    }
52
53    /* Private */
54    Waypoint.prototype.trigger = function (args) {
55        if (!this.enabled) {
56            return
57        }
58        if (this.callback) {
59            this.callback.apply(this, args)
60        }
61    }
62
63    /* Public */
64    /* http://imakewebthings.com/waypoints/api/destroy */
65    Waypoint.prototype.destroy = function () {
66        this.context.remove(this)
67        this.group.remove(this)
68        delete allWaypoints[this.key]
69    }
70
71    /* Public */
72    /* http://imakewebthings.com/waypoints/api/disable */
73    Waypoint.prototype.disable = function () {
74        this.enabled = false
75        return this
76    }
77
78    /* Public */
79    /* http://imakewebthings.com/waypoints/api/enable */
80    Waypoint.prototype.enable = function () {
81        this.context.refresh()
82        this.enabled = true
83        return this
84    }
85
86    /* Public */
87    /* http://imakewebthings.com/waypoints/api/next */
88    Waypoint.prototype.next = function () {
89        return this.group.next(this)
90    }
91
92    /* Public */
93    /* http://imakewebthings.com/waypoints/api/previous */
94    Waypoint.prototype.previous = function () {
95        return this.group.previous(this)
96    }
97
98    /* Private */
99    Waypoint.invokeAll = function (method) {
100        var allWaypointsArray = []
101        for (var waypointKey in allWaypoints) {
102            allWaypointsArray.push(allWaypoints[waypointKey])
103        }
104        for (var i = 0, end = allWaypointsArray.length; i < end; i++) {
105            allWaypointsArray[i][method]()
106        }
107    }
108
109    /* Public */
110    /* http://imakewebthings.com/waypoints/api/destroy-all */
111    Waypoint.destroyAll = function () {
112        Waypoint.invokeAll('destroy')
113    }
114
115    /* Public */
116    /* http://imakewebthings.com/waypoints/api/disable-all */
117    Waypoint.disableAll = function () {
118        Waypoint.invokeAll('disable')
119    }
120
121    /* Public */
122    /* http://imakewebthings.com/waypoints/api/enable-all */
123    Waypoint.enableAll = function () {
124        Waypoint.invokeAll('enable')
125    }
126
127    /* Public */
128    /* http://imakewebthings.com/waypoints/api/refresh-all */
129    Waypoint.refreshAll = function () {
130        Waypoint.Context.refreshAll()
131    }
132
133    /* Public */
134    /* http://imakewebthings.com/waypoints/api/viewport-height */
135    Waypoint.viewportHeight = function () {
136        return window.innerHeight || document.documentElement.clientHeight
137    }
138
139    /* Public */
140    /* http://imakewebthings.com/waypoints/api/viewport-width */
141    Waypoint.viewportWidth = function () {
142        return document.documentElement.clientWidth
143    }
144
145    Waypoint.adapters = []
146
147    Waypoint.defaults = {
148        context: window,
149        continuous: true,
150        enabled: true,
151        group: 'default',
152        horizontal: false,
153        offset: 0
154    }
155
156    Waypoint.offsetAliases = {
157        'bottom-in-view': function () {
158            return this.context.innerHeight() - this.adapter.outerHeight()
159        },
160        'right-in-view': function () {
161            return this.context.innerWidth() - this.adapter.outerWidth()
162        }
163    }
164
165    window.Waypoint = Waypoint
166}())
167        ;
168(function () {
169    'use strict'
170
171    function requestAnimationFrameShim(callback) {
172        window.setTimeout(callback, 1000 / 60)
173    }
174
175    var keyCounter = 0
176    var contexts = {}
177    var Waypoint = window.Waypoint
178    var oldWindowLoad = window.onload
179
180    /* http://imakewebthings.com/waypoints/api/context */
181    function Context(element) {
182        this.element = element
183        this.Adapter = Waypoint.Adapter
184        this.adapter = new this.Adapter(element)
185        this.key = 'waypoint-context-' + keyCounter
186        this.didScroll = false
187        this.didResize = false
188        this.oldScroll = {
189            x: this.adapter.scrollLeft(),
190            y: this.adapter.scrollTop()
191        }
192        this.waypoints = {
193            vertical: {},
194            horizontal: {}
195        }
196
197        element.waypointContextKey = this.key
198        contexts[element.waypointContextKey] = this
199        keyCounter += 1
200
201        this.createThrottledScrollHandler()
202        this.createThrottledResizeHandler()
203    }
204
205    /* Private */
206    Context.prototype.add = function (waypoint) {
207        var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical'
208        this.waypoints[axis][waypoint.key] = waypoint
209        this.refresh()
210    }
211
212    /* Private */
213    Context.prototype.checkEmpty = function () {
214        var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal)
215        var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical)
216        if (horizontalEmpty && verticalEmpty) {
217            this.adapter.off('.waypoints')
218            delete contexts[this.key]
219        }
220    }
221
222    /* Private */
223    Context.prototype.createThrottledResizeHandler = function () {
224        var self = this
225
226        function resizeHandler() {
227            self.handleResize()
228            self.didResize = false
229        }
230
231        this.adapter.on('resize.waypoints', function () {
232            if (!self.didResize) {
233                self.didResize = true
234                Waypoint.requestAnimationFrame(resizeHandler)
235            }
236        })
237    }
238
239    /* Private */
240    Context.prototype.createThrottledScrollHandler = function () {
241        var self = this
242        function scrollHandler() {
243            self.handleScroll()
244            self.didScroll = false
245        }
246
247        this.adapter.on('scroll.waypoints', function () {
248            if (!self.didScroll || Waypoint.isTouch) {
249                self.didScroll = true
250                Waypoint.requestAnimationFrame(scrollHandler)
251            }
252        })
253    }
254
255    /* Private */
256    Context.prototype.handleResize = function () {
257        Waypoint.Context.refreshAll()
258    }
259
260    /* Private */
261    Context.prototype.handleScroll = function () {
262        var triggeredGroups = {}
263        var axes = {
264            horizontal: {
265                newScroll: this.adapter.scrollLeft(),
266                oldScroll: this.oldScroll.x,
267                forward: 'right',
268                backward: 'left'
269            },
270            vertical: {
271                newScroll: this.adapter.scrollTop(),
272                oldScroll: this.oldScroll.y,
273                forward: 'down',
274                backward: 'up'
275            }
276        }
277
278        for (var axisKey in axes) {
279            var axis = axes[axisKey]
280            var isForward = axis.newScroll > axis.oldScroll
281            var direction = isForward ? axis.forward : axis.backward
282
283            for (var waypointKey in this.waypoints[axisKey]) {
284                var waypoint = this.waypoints[axisKey][waypointKey]
285                var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint
286                var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint
287                var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint
288                var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint
289                if (crossedForward || crossedBackward) {
290                    waypoint.queueTrigger(direction)
291                    triggeredGroups[waypoint.group.id] = waypoint.group
292                }
293            }
294        }
295
296        for (var groupKey in triggeredGroups) {
297            triggeredGroups[groupKey].flushTriggers()
298        }
299
300        this.oldScroll = {
301            x: axes.horizontal.newScroll,
302            y: axes.vertical.newScroll
303        }
304    }
305
306    /* Private */
307    Context.prototype.innerHeight = function () {
308        /*eslint-disable eqeqeq */
309        if (this.element == this.element.window) {
310            return Waypoint.viewportHeight()
311        }
312        /*eslint-enable eqeqeq */
313        return this.adapter.innerHeight()
314    }
315
316    /* Private */
317    Context.prototype.remove = function (waypoint) {
318        delete this.waypoints[waypoint.axis][waypoint.key]
319        this.checkEmpty()
320    }
321
322    /* Private */
323    Context.prototype.innerWidth = function () {
324        /*eslint-disable eqeqeq */
325        if (this.element == this.element.window) {
326            return Waypoint.viewportWidth()
327        }
328        /*eslint-enable eqeqeq */
329        return this.adapter.innerWidth()
330    }
331
332    /* Public */
333    /* http://imakewebthings.com/waypoints/api/context-destroy */
334    Context.prototype.destroy = function () {
335        var allWaypoints = []
336        for (var axis in this.waypoints) {
337            for (var waypointKey in this.waypoints[axis]) {
338                allWaypoints.push(this.waypoints[axis][waypointKey])
339            }
340        }
341        for (var i = 0, end = allWaypoints.length; i < end; i++) {
342            allWaypoints[i].destroy()
343        }
344    }
345
346    /* Public */
347    /* http://imakewebthings.com/waypoints/api/context-refresh */
348    Context.prototype.refresh = function () {
349        /*eslint-disable eqeqeq */
350        var isWindow = this.element == this.element.window
351        /*eslint-enable eqeqeq */
352        var contextOffset = isWindow ? undefined : this.adapter.offset()
353        var triggeredGroups = {}
354        var axes
355
356        this.handleScroll()
357        axes = {
358            horizontal: {
359                contextOffset: isWindow ? 0 : contextOffset.left,
360                contextScroll: isWindow ? 0 : this.oldScroll.x,
361                contextDimension: this.innerWidth(),
362                oldScroll: this.oldScroll.x,
363                forward: 'right',
364                backward: 'left',
365                offsetProp: 'left'
366            },
367            vertical: {
368                contextOffset: isWindow ? 0 : contextOffset.top,
369                contextScroll: isWindow ? 0 : this.oldScroll.y,
370                contextDimension: this.innerHeight(),
371                oldScroll: this.oldScroll.y,
372                forward: 'down',
373                backward: 'up',
374                offsetProp: 'top'
375            }
376        }
377
378        for (var axisKey in axes) {
379            var axis = axes[axisKey]
380            for (var waypointKey in this.waypoints[axisKey]) {
381                var waypoint = this.waypoints[axisKey][waypointKey]
382                var adjustment = waypoint.options.offset
383                var oldTriggerPoint = waypoint.triggerPoint
384                var elementOffset = 0
385                var freshWaypoint = oldTriggerPoint == null
386                var contextModifier, wasBeforeScroll, nowAfterScroll
387                var triggeredBackward, triggeredForward
388
389                if (waypoint.element !== waypoint.element.window) {
390                    elementOffset = waypoint.adapter.offset()[axis.offsetProp]
391                }
392
393                if (typeof adjustment === 'function') {
394                    adjustment = adjustment.apply(waypoint)
395                } else if (typeof adjustment === 'string') {
396                    adjustment = parseFloat(adjustment)
397                    if (waypoint.options.offset.indexOf('%') > -1) {
398                        adjustment = Math.ceil(axis.contextDimension * adjustment / 100)
399                    }
400                }
401
402                contextModifier = axis.contextScroll - axis.contextOffset
403                waypoint.triggerPoint = elementOffset + contextModifier - adjustment
404                wasBeforeScroll = oldTriggerPoint < axis.oldScroll
405                nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll
406                triggeredBackward = wasBeforeScroll && nowAfterScroll
407                triggeredForward = !wasBeforeScroll && !nowAfterScroll
408
409                if (!freshWaypoint && triggeredBackward) {
410                    waypoint.queueTrigger(axis.backward)
411                    triggeredGroups[waypoint.group.id] = waypoint.group
412                } else if (!freshWaypoint && triggeredForward) {
413                    waypoint.queueTrigger(axis.forward)
414                    triggeredGroups[waypoint.group.id] = waypoint.group
415                } else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) {
416                    waypoint.queueTrigger(axis.forward)
417                    triggeredGroups[waypoint.group.id] = waypoint.group
418                }
419            }
420        }
421
422        Waypoint.requestAnimationFrame(function () {
423            for (var groupKey in triggeredGroups) {
424                triggeredGroups[groupKey].flushTriggers()
425            }
426        })
427
428        return this
429    }
430
431    /* Private */
432    Context.findOrCreateByElement = function (element) {
433        return Context.findByElement(element) || new Context(element)
434    }
435
436    /* Private */
437    Context.refreshAll = function () {
438        for (var contextId in contexts) {
439            contexts[contextId].refresh()
440        }
441    }
442
443    /* Public */
444    /* http://imakewebthings.com/waypoints/api/context-find-by-element */
445    Context.findByElement = function (element) {
446        return contexts[element.waypointContextKey]
447    }
448
449    window.onload = function () {
450        if (oldWindowLoad) {
451            oldWindowLoad()
452        }
453        Context.refreshAll()
454    }
455
456    Waypoint.requestAnimationFrame = function (callback) {
457        var requestFn = window.requestAnimationFrame ||
458                window.mozRequestAnimationFrame ||
459                window.webkitRequestAnimationFrame ||
460                requestAnimationFrameShim
461        requestFn.call(window, callback)
462    }
463    Waypoint.Context = Context
464}())
465        ;
466(function () {
467    'use strict'
468
469    function byTriggerPoint(a, b) {
470        return a.triggerPoint - b.triggerPoint
471    }
472
473    function byReverseTriggerPoint(a, b) {
474        return b.triggerPoint - a.triggerPoint
475    }
476
477    var groups = {
478        vertical: {},
479        horizontal: {}
480    }
481    var Waypoint = window.Waypoint
482
483    /* http://imakewebthings.com/waypoints/api/group */
484    function Group(options) {
485        this.name = options.name
486        this.axis = options.axis
487        this.id = this.name + '-' + this.axis
488        this.waypoints = []
489        this.clearTriggerQueues()
490        groups[this.axis][this.name] = this
491    }
492
493    /* Private */
494    Group.prototype.add = function (waypoint) {
495        this.waypoints.push(waypoint)
496    }
497
498    /* Private */
499    Group.prototype.clearTriggerQueues = function () {
500        this.triggerQueues = {
501            up: [],
502            down: [],
503            left: [],
504            right: []
505        }
506    }
507
508    /* Private */
509    Group.prototype.flushTriggers = function () {
510        for (var direction in this.triggerQueues) {
511            var waypoints = this.triggerQueues[direction]
512            var reverse = direction === 'up' || direction === 'left'
513            waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint)
514            for (var i = 0, end = waypoints.length; i < end; i += 1) {
515                var waypoint = waypoints[i]
516                if (waypoint.options.continuous || i === waypoints.length - 1) {
517                    waypoint.trigger([direction])
518                }
519            }
520        }
521        this.clearTriggerQueues()
522    }
523
524    /* Private */
525    Group.prototype.next = function (waypoint) {
526        this.waypoints.sort(byTriggerPoint)
527        var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
528        var isLast = index === this.waypoints.length - 1
529        return isLast ? null : this.waypoints[index + 1]
530    }
531
532    /* Private */
533    Group.prototype.previous = function (waypoint) {
534        this.waypoints.sort(byTriggerPoint)
535        var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
536        return index ? this.waypoints[index - 1] : null
537    }
538
539    /* Private */
540    Group.prototype.queueTrigger = function (waypoint, direction) {
541        this.triggerQueues[direction].push(waypoint)
542    }
543
544    /* Private */
545    Group.prototype.remove = function (waypoint) {
546        var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
547        if (index > -1) {
548            this.waypoints.splice(index, 1)
549        }
550    }
551
552    /* Public */
553    /* http://imakewebthings.com/waypoints/api/first */
554    Group.prototype.first = function () {
555        return this.waypoints[0]
556    }
557
558    /* Public */
559    /* http://imakewebthings.com/waypoints/api/last */
560    Group.prototype.last = function () {
561        return this.waypoints[this.waypoints.length - 1]
562    }
563
564    /* Private */
565    Group.findOrCreate = function (options) {
566        return groups[options.axis][options.name] || new Group(options)
567    }
568
569    Waypoint.Group = Group
570}())
571        ;
572(function () {
573    'use strict'
574
575    var $ = window.jQuery
576    var Waypoint = window.Waypoint
577
578    function JQueryAdapter(element) {
579        this.$element = $(element)
580    }
581
582    $.each([
583        'innerHeight',
584        'innerWidth',
585        'off',
586        'offset',
587        'on',
588        'outerHeight',
589        'outerWidth',
590        'scrollLeft',
591        'scrollTop'
592    ], function (i, method) {
593        JQueryAdapter.prototype[method] = function () {
594            var args = Array.prototype.slice.call(arguments)
595            return this.$element[method].apply(this.$element, args)
596        }
597    })
598
599    $.each([
600        'extend',
601        'inArray',
602        'isEmptyObject'
603    ], function (i, method) {
604        JQueryAdapter[method] = $[method]
605    })
606
607    Waypoint.adapters.push({
608        name: 'jquery',
609        Adapter: JQueryAdapter
610    })
611    Waypoint.Adapter = JQueryAdapter
612}())
613        ;
614(function () {
615    'use strict'
616
617    var Waypoint = window.Waypoint
618
619    function createExtension(framework) {
620        return function () {
621            var waypoints = []
622            var overrides = arguments[0]
623
624            if (framework.isFunction(arguments[0])) {
625                overrides = framework.extend({}, arguments[1])
626                overrides.handler = arguments[0]
627            }
628
629            this.each(function () {
630                var options = framework.extend({}, overrides, {
631                    element: this
632                })
633                if (typeof options.context === 'string') {
634                    options.context = framework(this).closest(options.context)[0]
635                }
636                waypoints.push(new Waypoint(options))
637            })
638
639            return waypoints
640        }
641    }
642
643    if (window.jQuery) {
644        window.jQuery.fn.waypoint = createExtension(window.jQuery)
645    }
646    if (window.Zepto) {
647        window.Zepto.fn.waypoint = createExtension(window.Zepto)
648    }
649}())
650        ;

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.