123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*!
- Waypoints Inview Shortcut - 4.0.1
- Copyright © 2011-2016 Caleb Troughton
- Licensed under the MIT license.
- https://github.com/imakewebthings/waypoints/blob/master/licenses.txt
- */
- (function() {
- 'use strict'
- function noop() {}
- var Waypoint = window.Waypoint
- /* http://imakewebthings.com/waypoints/shortcuts/inview */
- function Inview(options) {
- this.options = Waypoint.Adapter.extend({}, Inview.defaults, options)
- this.axis = this.options.horizontal ? 'horizontal' : 'vertical'
- this.waypoints = []
- this.element = this.options.element
- this.createWaypoints()
- }
- /* Private */
- Inview.prototype.createWaypoints = function() {
- var configs = {
- vertical: [{
- down: 'enter',
- up: 'exited',
- offset: '100%'
- }, {
- down: 'entered',
- up: 'exit',
- offset: 'bottom-in-view'
- }, {
- down: 'exit',
- up: 'entered',
- offset: 0
- }, {
- down: 'exited',
- up: 'enter',
- offset: function() {
- return -this.adapter.outerHeight()
- }
- }],
- horizontal: [{
- right: 'enter',
- left: 'exited',
- offset: '100%'
- }, {
- right: 'entered',
- left: 'exit',
- offset: 'right-in-view'
- }, {
- right: 'exit',
- left: 'entered',
- offset: 0
- }, {
- right: 'exited',
- left: 'enter',
- offset: function() {
- return -this.adapter.outerWidth()
- }
- }]
- }
- for (var i = 0, end = configs[this.axis].length; i < end; i++) {
- var config = configs[this.axis][i]
- this.createWaypoint(config)
- }
- }
- /* Private */
- Inview.prototype.createWaypoint = function(config) {
- var self = this
- this.waypoints.push(new Waypoint({
- context: this.options.context,
- element: this.options.element,
- enabled: this.options.enabled,
- handler: (function(config) {
- return function(direction) {
- self.options[config[direction]].call(self, direction)
- }
- }(config)),
- offset: config.offset,
- horizontal: this.options.horizontal
- }))
- }
- /* Public */
- Inview.prototype.destroy = function() {
- for (var i = 0, end = this.waypoints.length; i < end; i++) {
- this.waypoints[i].destroy()
- }
- this.waypoints = []
- }
- Inview.prototype.disable = function() {
- for (var i = 0, end = this.waypoints.length; i < end; i++) {
- this.waypoints[i].disable()
- }
- }
- Inview.prototype.enable = function() {
- for (var i = 0, end = this.waypoints.length; i < end; i++) {
- this.waypoints[i].enable()
- }
- }
- Inview.defaults = {
- context: window,
- enabled: true,
- enter: noop,
- entered: noop,
- exit: noop,
- exited: noop
- }
- Waypoint.Inview = Inview
- }())
- ;
|