')
+ .attr('id', this.containerId)
+ .html(html)
-jasmine.Fixtures.prototype.createContainer_ = function(html) {
- var container
- if(html instanceof jQuery) {
- container = jQuery('
')
- container.html(html)
- } else {
- container = '
' + html + '
'
+ $(document.body).append(container)
+ return container
}
- jQuery('body').append(container)
-}
-jasmine.Fixtures.prototype.addToContainer_ = function(html){
- var container = jQuery('body').find('#'+this.containerId).append(html)
- if(!container.length){
- this.createContainer_(html)
+ jasmine.Fixtures.prototype.addToContainer_ = function (html){
+ var container = $(document.body).find('#'+this.containerId).append(html)
+ if(!container.length){
+ this.createContainer_(html)
+ }
}
-}
-jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
- if (typeof this.fixturesCache_[url] === 'undefined') {
- this.loadFixtureIntoCache_(url)
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) {
+ if (typeof this.fixturesCache_[url] === 'undefined') {
+ this.loadFixtureIntoCache_(url)
+ }
+ return this.fixturesCache_[url]
}
- return this.fixturesCache_[url]
-}
-jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
- var url = this.makeFixtureUrl_(relativeUrl)
- var request = new XMLHttpRequest()
- request.open("GET", url + "?" + new Date().getTime(), false)
- request.send(null)
- this.fixturesCache_[relativeUrl] = request.responseText
-}
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
+ var self = this
+ , url = this.makeFixtureUrl_(relativeUrl)
+ , request = $.ajax({
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
+ cache: false,
+ url: url,
+ success: function (data, status, $xhr) {
+ self.fixturesCache_[relativeUrl] = $xhr.responseText
+ },
+ error: function (jqXHR, status, errorThrown) {
+ throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
+ }
+ })
+ }
-jasmine.Fixtures.prototype.makeFixtureUrl_ = function(relativeUrl){
- return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
-}
+ jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
+ return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
+ }
-jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
- return this[methodName].apply(this, passedArguments)
-}
+ jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
+ return this[methodName].apply(this, passedArguments)
+ }
-jasmine.JQuery = function() {}
+ jasmine.StyleFixtures = function () {
+ this.fixturesCache_ = {}
+ this.fixturesNodes_ = []
+ this.fixturesPath = 'spec/javascripts/fixtures'
+ }
-jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
- return jQuery('
').append(html).html()
-}
+ jasmine.StyleFixtures.prototype.set = function (css) {
+ this.cleanUp()
+ this.createStyle_(css)
+ }
-jasmine.JQuery.elementToString = function(element) {
- var domEl = $(element).get(0)
- if (domEl == undefined || domEl.cloneNode)
- return jQuery('
').append($(element).clone()).html()
- else
- return element.toString()
-}
+ jasmine.StyleFixtures.prototype.appendSet = function (css) {
+ this.createStyle_(css)
+ }
+
+ jasmine.StyleFixtures.prototype.preload = function () {
+ this.read_.apply(this, arguments)
+ }
+
+ jasmine.StyleFixtures.prototype.load = function () {
+ this.cleanUp()
+ this.createStyle_(this.read_.apply(this, arguments))
+ }
+
+ jasmine.StyleFixtures.prototype.appendLoad = function () {
+ this.createStyle_(this.read_.apply(this, arguments))
+ }
+
+ jasmine.StyleFixtures.prototype.cleanUp = function () {
+ while(this.fixturesNodes_.length) {
+ this.fixturesNodes_.pop().remove()
+ }
+ }
-jasmine.JQuery.matchersClass = {};
+ jasmine.StyleFixtures.prototype.createStyle_ = function (html) {
+ var styleText = $('
').html(html).text()
+ , style = $('')
+
+ this.fixturesNodes_.push(style)
+ $('head').append(style)
+ }
+
+ jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
+ jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
+ jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
+ jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
+ jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
+ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
+
+ jasmine.getJSONFixtures = function () {
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
+ }
+
+ jasmine.JSONFixtures = function () {
+ this.fixturesCache_ = {}
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
+ }
+
+ jasmine.JSONFixtures.prototype.load = function () {
+ this.read.apply(this, arguments)
+ return this.fixturesCache_
+ }
+
+ jasmine.JSONFixtures.prototype.read = function () {
+ var fixtureUrls = arguments
+
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
+ this.getFixtureData_(fixtureUrls[urlIndex])
+ }
+
+ return this.fixturesCache_
+ }
+
+ jasmine.JSONFixtures.prototype.clearCache = function () {
+ this.fixturesCache_ = {}
+ }
+
+ jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
+ if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
+ return this.fixturesCache_[url]
+ }
+
+ jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
+ var self = this
+ , url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
+
+ $.ajax({
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
+ cache: false,
+ dataType: 'json',
+ url: url,
+ success: function (data) {
+ self.fixturesCache_[relativeUrl] = data
+ },
+ error: function (jqXHR, status, errorThrown) {
+ throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
+ }
+ })
+ }
+
+ jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
+ return this[methodName].apply(this, passedArguments)
+ }
+
+ jasmine.jQuery = function () {}
+
+ jasmine.jQuery.browserTagCaseIndependentHtml = function (html) {
+ return $('
').append(html).html()
+ }
+
+ jasmine.jQuery.elementToString = function (element) {
+ return $(element).map(function () { return this.outerHTML; }).toArray().join(', ')
+ }
+
+ jasmine.jQuery.matchersClass = {}
-!function(namespace) {
var data = {
- spiedEvents: {},
- handlers: []
+ spiedEvents: {}
+ , handlers: []
}
- namespace.events = {
- spyOn: function(selector, eventName) {
- var handler = function(e) {
- data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = e
+ jasmine.jQuery.events = {
+ spyOn: function (selector, eventName) {
+ var handler = function (e) {
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments)
}
- jQuery(selector).bind(eventName, handler)
+
+ $(selector).on(eventName, handler)
data.handlers.push(handler)
+
return {
selector: selector,
eventName: eventName,
handler: handler,
- reset: function(){
- delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)];
+ reset: function (){
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
}
}
},
- wasTriggered: function(selector, eventName) {
+ args: function (selector, eventName) {
+ var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
+
+ if (!actualArgs) {
+ throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
+ }
+
+ return actualArgs
+ },
+
+ wasTriggered: function (selector, eventName) {
return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
},
- wasPrevented: function(selector, eventName) {
- return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].isDefaultPrevented()
+ wasTriggeredWith: function (selector, eventName, expectedArgs, env) {
+ var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1)
+ if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') {
+ actualArgs = actualArgs[0]
+ }
+ return env.equals_(expectedArgs, actualArgs)
+ },
+
+ wasPrevented: function (selector, eventName) {
+ var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
+ , e = args ? args[0] : undefined
+
+ return e && e.isDefaultPrevented()
+ },
+
+ wasStopped: function (selector, eventName) {
+ var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
+ , e = args ? args[0] : undefined
+ return e && e.isPropagationStopped()
},
- cleanUp: function() {
+ cleanUp: function () {
data.spiedEvents = {}
data.handlers = []
}
}
-}(jasmine.JQuery)
-!function(){
var jQueryMatchers = {
- toHaveClass: function(className) {
+ toHaveClass: function (className) {
return this.actual.hasClass(className)
},
- toHaveCss: function(css){
+ toHaveCss: function (css){
for (var prop in css){
- if (this.actual.css(prop) !== css[prop]) return false
+ var value = css[prop]
+ // see issue #147 on gh
+ ;if (value === 'auto' && this.actual.get(0).style[prop] === 'auto') continue
+ if (this.actual.css(prop) !== value) return false
}
return true
},
- toBeVisible: function() {
+ toBeVisible: function () {
return this.actual.is(':visible')
},
- toBeHidden: function() {
+ toBeHidden: function () {
return this.actual.is(':hidden')
},
- toBeSelected: function() {
+ toBeSelected: function () {
return this.actual.is(':selected')
},
- toBeChecked: function() {
+ toBeChecked: function () {
return this.actual.is(':checked')
},
- toBeEmpty: function() {
+ toBeEmpty: function () {
return this.actual.is(':empty')
},
- toExist: function() {
- return $(document).find(this.actual).length
+ toBeInDOM: function () {
+ return $.contains(document.documentElement, this.actual[0])
+ },
+
+ toExist: function () {
+ return this.actual.length
},
- toHaveAttr: function(attributeName, expectedAttributeValue) {
+ toHaveLength: function (length) {
+ return this.actual.length === length
+ },
+
+ toHaveAttr: function (attributeName, expectedAttributeValue) {
return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
},
- toHaveProp: function(propertyName, expectedPropertyValue) {
+ toHaveProp: function (propertyName, expectedPropertyValue) {
return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
},
- toHaveId: function(id) {
+ toHaveId: function (id) {
return this.actual.attr('id') == id
},
- toHaveHtml: function(html) {
- return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
+ toHaveHtml: function (html) {
+ return this.actual.html() == jasmine.jQuery.browserTagCaseIndependentHtml(html)
},
- toContainHtml: function(html){
+ toContainHtml: function (html){
var actualHtml = this.actual.html()
- var expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
+ , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html)
+
return (actualHtml.indexOf(expectedHtml) >= 0)
},
- toHaveText: function(text) {
+ toHaveText: function (text) {
var trimmedText = $.trim(this.actual.text())
- if (text && jQuery.isFunction(text.test)) {
+
+ if (text && $.isFunction(text.test)) {
return text.test(trimmedText)
} else {
return trimmedText == text
}
},
- toHaveValue: function(value) {
- return this.actual.val() == value
+ toContainText: function (text) {
+ var trimmedText = $.trim(this.actual.text())
+
+ if (text && $.isFunction(text.test)) {
+ return text.test(trimmedText)
+ } else {
+ return trimmedText.indexOf(text) != -1
+ }
+ },
+
+ toHaveValue: function (value) {
+ return this.actual.val() === value
},
- toHaveData: function(key, expectedValue) {
+ toHaveData: function (key, expectedValue) {
return hasProperty(this.actual.data(key), expectedValue)
},
- toBe: function(selector) {
+ toBe: function (selector) {
return this.actual.is(selector)
},
- toContain: function(selector) {
+ toContain: function (selector) {
return this.actual.find(selector).length
},
- toBeDisabled: function(selector){
- return this.actual.is(':disabled')
+ toBeMatchedBy: function (selector) {
+ return this.actual.filter(selector).length
},
- toBeFocused: function(selector) {
- return this.actual.is(':focus')
+ toBeDisabled: function (selector){
+ return this.actual.is(':disabled')
},
- toHandle: function(event) {
+ toBeFocused: function (selector) {
+ return this.actual[0] === this.actual[0].ownerDocument.activeElement
+ },
- var events = this.actual.data('events')
+ toHandle: function (event) {
+ var events = $._data(this.actual.get(0), "events")
if(!events || !event || typeof event !== "string") {
return false
}
var namespaces = event.split(".")
- var eventType = namespaces.shift()
- var sortedNamespaces = namespaces.slice(0).sort()
- var namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
+ , eventType = namespaces.shift()
+ , sortedNamespaces = namespaces.slice(0).sort()
+ , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
if(events[eventType] && namespaces.length) {
for(var i = 0; i < events[eventType].length; i++) {
var namespace = events[eventType][i].namespace
+
if(namespaceRegExp.test(namespace)) {
return true
}
@@ -303,33 +465,38 @@ jasmine.JQuery.matchersClass = {};
}
},
- // tests the existence of a specific event binding + handler
- toHandleWith: function(eventName, eventHandler) {
- var stack = this.actual.data("events")[eventName]
+ toHandleWith: function (eventName, eventHandler) {
+ var normalizedEventName = eventName.split('.')[0]
+ , stack = $._data(this.actual.get(0), "events")[normalizedEventName]
+
for (var i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) return true
}
+
return false
}
}
- var hasProperty = function(actualValue, expectedValue) {
+ var hasProperty = function (actualValue, expectedValue) {
if (expectedValue === undefined) return actualValue !== undefined
- return actualValue == expectedValue
+
+ return actualValue === expectedValue
}
- var bindMatcher = function(methodName) {
+ var bindMatcher = function (methodName) {
var builtInMatcher = jasmine.Matchers.prototype[methodName]
- jasmine.JQuery.matchersClass[methodName] = function() {
+ jasmine.jQuery.matchersClass[methodName] = function () {
if (this.actual
- && (this.actual instanceof jQuery
+ && (this.actual instanceof $
|| jasmine.isDomNode(this.actual))) {
this.actual = $(this.actual)
var result = jQueryMatchers[methodName].apply(this, arguments)
- var element;
- if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
- this.actual = jasmine.JQuery.elementToString(this.actual)
+ , element
+
+ if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
+ this.actual = jasmine.jQuery.elementToString(this.actual)
+
return result
}
@@ -344,61 +511,195 @@ jasmine.JQuery.matchersClass = {};
for(var methodName in jQueryMatchers) {
bindMatcher(methodName)
}
-}()
-
-beforeEach(function() {
- this.addMatchers(jasmine.JQuery.matchersClass)
- this.addMatchers({
- toHaveBeenTriggeredOn: function(selector) {
- this.message = function() {
- return [
- "Expected event " + this.actual + " to have been triggered on " + selector,
- "Expected event " + this.actual + " not to have been triggered on " + selector
- ]
+
+ beforeEach(function () {
+ this.addMatchers(jasmine.jQuery.matchersClass)
+ this.addMatchers({
+ toHaveBeenTriggeredOn: function (selector) {
+ this.message = function () {
+ return [
+ "Expected event " + this.actual + " to have been triggered on " + selector,
+ "Expected event " + this.actual + " not to have been triggered on " + selector
+ ]
+ }
+ return jasmine.jQuery.events.wasTriggered(selector, this.actual)
}
- return jasmine.JQuery.events.wasTriggered(selector, this.actual)
- }
- })
- this.addMatchers({
- toHaveBeenTriggered: function(){
- var eventName = this.actual.eventName,
- selector = this.actual.selector;
- this.message = function() {
- return [
- "Expected event " + eventName + " to have been triggered on " + selector,
- "Expected event " + eventName + " not to have been triggered on " + selector
- ]
+ })
+
+ this.addMatchers({
+ toHaveBeenTriggered: function (){
+ var eventName = this.actual.eventName
+ , selector = this.actual.selector
+
+ this.message = function () {
+ return [
+ "Expected event " + eventName + " to have been triggered on " + selector,
+ "Expected event " + eventName + " not to have been triggered on " + selector
+ ]
+ }
+
+ return jasmine.jQuery.events.wasTriggered(selector, eventName)
}
- return jasmine.JQuery.events.wasTriggered(selector, eventName)
- }
- })
- this.addMatchers({
- toHaveBeenPreventedOn: function(selector) {
- this.message = function() {
- return [
- "Expected event " + this.actual + " to have been prevented on " + selector,
- "Expected event " + this.actual + " not to have been prevented on " + selector
- ]
+ })
+
+ this.addMatchers({
+ toHaveBeenTriggeredOnAndWith: function () {
+ var selector = arguments[0]
+ , expectedArgs = arguments[1]
+ , wasTriggered = jasmine.jQuery.events.wasTriggered(selector, this.actual)
+
+ this.message = function () {
+ if (wasTriggered) {
+ var actualArgs = jasmine.jQuery.events.args(selector, this.actual, expectedArgs)[1]
+ return [
+ "Expected event " + this.actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs),
+ "Expected event " + this.actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
+ ]
+ } else {
+ return [
+ "Expected event " + this.actual + " to have been triggered on " + selector,
+ "Expected event " + this.actual + " not to have been triggered on " + selector
+ ]
+ }
+ }
+
+ return wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, this.actual, expectedArgs, this.env)
}
- return jasmine.JQuery.events.wasPrevented(selector, this.actual)
- }
- })
- this.addMatchers({
- toHaveBeenPrevented: function() {
- var eventName = this.actual.eventName,
- selector = this.actual.selector;
- this.message = function() {
- return [
- "Expected event " + eventName + " to have been prevented on " + selector,
- "Expected event " + eventName + " not to have been prevented on " + selector
- ]
+ })
+
+ this.addMatchers({
+ toHaveBeenPreventedOn: function (selector) {
+ this.message = function () {
+ return [
+ "Expected event " + this.actual + " to have been prevented on " + selector,
+ "Expected event " + this.actual + " not to have been prevented on " + selector
+ ]
+ }
+
+ return jasmine.jQuery.events.wasPrevented(selector, this.actual)
}
- return jasmine.JQuery.events.wasPrevented(selector, eventName)
- }
+ })
+
+ this.addMatchers({
+ toHaveBeenPrevented: function () {
+ var eventName = this.actual.eventName
+ , selector = this.actual.selector
+ this.message = function () {
+ return [
+ "Expected event " + eventName + " to have been prevented on " + selector,
+ "Expected event " + eventName + " not to have been prevented on " + selector
+ ]
+ }
+
+ return jasmine.jQuery.events.wasPrevented(selector, eventName)
+ }
+ })
+
+ this.addMatchers({
+ toHaveBeenStoppedOn: function (selector) {
+ this.message = function () {
+ return [
+ "Expected event " + this.actual + " to have been stopped on " + selector,
+ "Expected event " + this.actual + " not to have been stopped on " + selector
+ ]
+ }
+
+ return jasmine.jQuery.events.wasStopped(selector, this.actual)
+ }
+ })
+
+ this.addMatchers({
+ toHaveBeenStopped: function () {
+ var eventName = this.actual.eventName
+ , selector = this.actual.selector
+ this.message = function () {
+ return [
+ "Expected event " + eventName + " to have been stopped on " + selector,
+ "Expected event " + eventName + " not to have been stopped on " + selector
+ ]
+ }
+ return jasmine.jQuery.events.wasStopped(selector, eventName)
+ }
+ })
+
+ jasmine.getEnv().addEqualityTester(function (a, b) {
+ if(a instanceof $ && b instanceof $) {
+ if(a.size() != b.size()) {
+ return jasmine.undefined
+ }
+ else if(a.is(b)) {
+ return true
+ }
+ }
+
+ return jasmine.undefined
+ })
+ })
+
+ afterEach(function () {
+ jasmine.getFixtures().cleanUp()
+ jasmine.getStyleFixtures().cleanUp()
+ jasmine.jQuery.events.cleanUp()
})
-})
-afterEach(function() {
- jasmine.getFixtures().cleanUp()
- jasmine.JQuery.events.cleanUp()
-})
+ window.readFixtures = function () {
+ return jasmine.getFixtures().proxyCallTo_('read', arguments)
+ }
+
+ window.preloadFixtures = function () {
+ jasmine.getFixtures().proxyCallTo_('preload', arguments)
+ }
+
+ window.loadFixtures = function () {
+ jasmine.getFixtures().proxyCallTo_('load', arguments)
+ }
+
+ window.appendLoadFixtures = function () {
+ jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
+ }
+
+ window.setFixtures = function (html) {
+ return jasmine.getFixtures().proxyCallTo_('set', arguments)
+ }
+
+ window.appendSetFixtures = function () {
+ jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
+ }
+
+ window.sandbox = function (attributes) {
+ return jasmine.getFixtures().sandbox(attributes)
+ }
+
+ window.spyOnEvent = function (selector, eventName) {
+ return jasmine.jQuery.events.spyOn(selector, eventName)
+ }
+
+ window.preloadStyleFixtures = function () {
+ jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
+ }
+
+ window.loadStyleFixtures = function () {
+ jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
+ }
+
+ window.appendLoadStyleFixtures = function () {
+ jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
+ }
+
+ window.setStyleFixtures = function (html) {
+ jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
+ }
+
+ window.appendSetStyleFixtures = function (html) {
+ jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
+ }
+
+ window.loadJSONFixtures = function () {
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
+ }
+
+ window.getJSONFixture = function (url) {
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
+ }
+}(window.jasmine, window.jQuery);
+
diff --git a/test/lib/jasmine.css b/test/lib/jasmine.css
index 826e5753..8c008dc7 100644
--- a/test/lib/jasmine.css
+++ b/test/lib/jasmine.css
@@ -19,6 +19,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
+#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
#HTMLReporter .runningAlert { background-color: #666666; }
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
diff --git a/test/lib/jasmine.js b/test/lib/jasmine.js
index 03bf89a0..6b3459b9 100644
--- a/test/lib/jasmine.js
+++ b/test/lib/jasmine.js
@@ -1,4 +1,4 @@
-var isCommonJS = typeof window == "undefined";
+var isCommonJS = typeof window == "undefined" && typeof exports == "object";
/**
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
@@ -34,11 +34,23 @@ jasmine.VERBOSE = false;
*/
jasmine.DEFAULT_UPDATE_INTERVAL = 250;
+/**
+ * Maximum levels of nesting that will be included when an object is pretty-printed
+ */
+jasmine.MAX_PRETTY_PRINT_DEPTH = 40;
+
/**
* Default timeout interval in milliseconds for waitsFor() blocks.
*/
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
+/**
+ * By default exceptions thrown in the context of a test are caught by jasmine so that it can run the remaining tests in the suite.
+ * Set to false to let the exception bubble up in the browser.
+ *
+ */
+jasmine.CATCH_EXCEPTIONS = true;
+
jasmine.getGlobal = function() {
function getGlobal() {
return this;
@@ -463,7 +475,7 @@ jasmine.log = function() {
* @see jasmine.createSpy
* @param obj
* @param methodName
- * @returns a Jasmine spy that can be chained with all spy methods
+ * @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
*/
var spyOn = function(obj, methodName) {
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
@@ -508,6 +520,7 @@ if (isCommonJS) exports.xit = xit;
* jasmine.Matchers functions.
*
* @param {Object} actual Actual value to test against and expected value
+ * @return {jasmine.Matchers}
*/
var expect = function(actual) {
return jasmine.getEnv().currentSpec.expect(actual);
@@ -867,6 +880,25 @@ jasmine.Env.prototype.xit = function(desc, func) {
};
};
+jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
+ if (a.source != b.source)
+ mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
+
+ if (a.ignoreCase != b.ignoreCase)
+ mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
+
+ if (a.global != b.global)
+ mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
+
+ if (a.multiline != b.multiline)
+ mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
+
+ if (a.sticky != b.sticky)
+ mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
+
+ return (mismatchValues.length === 0);
+};
+
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
return true;
@@ -953,6 +985,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return (a == b);
}
+ if (a instanceof RegExp && b instanceof RegExp) {
+ return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
+ }
+
if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
@@ -1019,11 +1055,16 @@ jasmine.Block = function(env, func, spec) {
this.spec = spec;
};
-jasmine.Block.prototype.execute = function(onComplete) {
- try {
+jasmine.Block.prototype.execute = function(onComplete) {
+ if (!jasmine.CATCH_EXCEPTIONS) {
this.func.apply(this.spec);
- } catch (e) {
- this.spec.fail(e);
+ }
+ else {
+ try {
+ this.func.apply(this.spec);
+ } catch (e) {
+ this.spec.fail(e);
+ }
}
onComplete();
};
@@ -1281,6 +1322,17 @@ jasmine.Matchers.prototype.toBeNull = function() {
return (this.actual === null);
};
+/**
+ * Matcher that compares the actual to NaN.
+ */
+jasmine.Matchers.prototype.toBeNaN = function() {
+ this.message = function() {
+ return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
+ };
+
+ return (this.actual !== this.actual);
+};
+
/**
* Matcher that boolean not-nots the actual.
*/
@@ -1358,18 +1410,14 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
+ var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was.";
+ var positiveMessage = "";
if (this.actual.callCount === 0) {
- // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
- return [
- "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
- "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
- ];
+ positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
- return [
- "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
- "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
- ];
+ positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
}
+ return [positiveMessage, invertedMessage];
};
return this.env.contains_(this.actual.argsForCall, expectedArgs);
@@ -1427,22 +1475,19 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
* up to a given level of decimal precision (default 2).
*
* @param {Number} expected
- * @param {Number} precision
+ * @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
precision = precision || 2;
}
- var multiplier = Math.pow(10, precision);
- var actual = Math.round(this.actual * multiplier);
- expected = Math.round(expected * multiplier);
- return expected == actual;
+ return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
};
/**
* Matcher that checks that the expected exception was thrown by the actual.
*
- * @param {String} expected
+ * @param {String} [expected]
*/
jasmine.Matchers.prototype.toThrow = function(expected) {
var result = false;
@@ -1840,10 +1885,6 @@ jasmine.PrettyPrinter = function() {
* @param value
*/
jasmine.PrettyPrinter.prototype.format = function(value) {
- if (this.ppNestLevel_ > 40) {
- throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
- }
-
this.ppNestLevel_++;
try {
if (value === jasmine.undefined) {
@@ -1886,6 +1927,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
+ if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
obj.__lookupGetter__(property) !== null) : false);
@@ -1913,6 +1955,11 @@ jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
};
jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
+ if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
+ this.append("Array");
+ return;
+ }
+
this.append('[ ');
for (var i = 0; i < array.length; i++) {
if (i > 0) {
@@ -1924,6 +1971,11 @@ jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
};
jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
+ if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
+ this.append("Object");
+ return;
+ }
+
var self = this;
this.append('{ ');
var first = true;
@@ -1952,6 +2004,10 @@ jasmine.StringPrettyPrinter.prototype.append = function(value) {
};
jasmine.Queue = function(env) {
this.env = env;
+
+ // parallel to blocks. each true value in this array means the block will
+ // get executed even if we abort
+ this.ensured = [];
this.blocks = [];
this.running = false;
this.index = 0;
@@ -1959,15 +2015,30 @@ jasmine.Queue = function(env) {
this.abort = false;
};
-jasmine.Queue.prototype.addBefore = function(block) {
+jasmine.Queue.prototype.addBefore = function(block, ensure) {
+ if (ensure === jasmine.undefined) {
+ ensure = false;
+ }
+
this.blocks.unshift(block);
+ this.ensured.unshift(ensure);
};
-jasmine.Queue.prototype.add = function(block) {
+jasmine.Queue.prototype.add = function(block, ensure) {
+ if (ensure === jasmine.undefined) {
+ ensure = false;
+ }
+
this.blocks.push(block);
+ this.ensured.push(ensure);
};
-jasmine.Queue.prototype.insertNext = function(block) {
+jasmine.Queue.prototype.insertNext = function(block, ensure) {
+ if (ensure === jasmine.undefined) {
+ ensure = false;
+ }
+
+ this.ensured.splice((this.index + this.offset + 1), 0, ensure);
this.blocks.splice((this.index + this.offset + 1), 0, block);
this.offset++;
};
@@ -1991,7 +2062,7 @@ jasmine.Queue.prototype.next_ = function() {
while (goAgain) {
goAgain = false;
- if (self.index < self.blocks.length && !this.abort) {
+ if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) {
var calledSynchronously = true;
var completedSynchronously = false;
@@ -2282,7 +2353,7 @@ jasmine.Spec.prototype.finish = function(onComplete) {
jasmine.Spec.prototype.after = function(doAfter) {
if (this.queue.isRunning()) {
- this.queue.add(new jasmine.Block(this.env, doAfter, this));
+ this.queue.add(new jasmine.Block(this.env, doAfter, this), true);
} else {
this.afterCallbacks.unshift(doAfter);
}
@@ -2320,15 +2391,15 @@ jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
}
for (i = 0; i < this.afterCallbacks.length; i++) {
- this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
+ this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true);
}
for (suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.after_.length; i++) {
- this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
+ this.queue.add(new jasmine.Block(this.env, suite.after_[i], this), true);
}
}
for (i = 0; i < runner.after_.length; i++) {
- this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
+ this.queue.add(new jasmine.Block(this.env, runner.after_[i], this), true);
}
};
@@ -2523,7 +2594,7 @@ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
jasmine.version_= {
"major": 1,
- "minor": 2,
- "build": 0,
- "revision": 1337005947
+ "minor": 3,
+ "build": 1,
+ "revision": 1354556913
};
diff --git a/test/settings.js b/test/settings.js
new file mode 100644
index 00000000..0cdda718
--- /dev/null
+++ b/test/settings.js
@@ -0,0 +1,9 @@
+/* global jasmine, Waypoint */
+
+'use strict'
+
+jasmine.getFixtures().fixturesPath = 'test/fixtures'
+jasmine.getEnv().defaultTimeoutInterval = 1000
+Waypoint.requestAnimationFrame = function(callback) {
+ callback()
+}
diff --git a/test/sticky-spec.js b/test/sticky-spec.js
new file mode 100644
index 00000000..b6128a0b
--- /dev/null
+++ b/test/sticky-spec.js
@@ -0,0 +1,117 @@
+'use strict'
+/* global
+ * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs,
+ * waitsFor, loadFixtures, Waypoint, jasmine
+ */
+
+describe('Waypoint Sticky Shortcut', function() {
+ var $ = window.jQuery
+ var $scroller = $(window)
+ var $sticky, waypoint, handlerSpy
+
+ beforeEach(function() {
+ loadFixtures('sticky.html')
+ $sticky = $('.sticky')
+ })
+
+ describe('with default options', function() {
+ beforeEach(function() {
+ handlerSpy = jasmine.createSpy('on handler')
+ waypoint = new Waypoint.Sticky({
+ element: $sticky[0],
+ handler: handlerSpy
+ })
+ })
+
+ afterEach(function() {
+ if (waypoint) {
+ waypoint.destroy()
+ }
+ $scroller.scrollTop(0)
+ })
+
+ describe('on init', function() {
+ afterEach(function() {
+ waypoint.destroy()
+ })
+
+ it('returns an instance of the Waypoint.Sticky class', function() {
+ expect(waypoint instanceof Waypoint.Sticky).toBeTruthy()
+ })
+
+ it('wraps the sticky element on init', function() {
+ expect($sticky.parent()).toHaveClass('sticky-wrapper')
+ })
+
+ describe('when sticky element is scrolled to', function() {
+ beforeEach(function() {
+ runs(function() {
+ $scroller.scrollTop($sticky.offset().top)
+ })
+ waitsFor(function() {
+ return $sticky.hasClass('stuck')
+ }, 'stuck class to apply')
+ })
+
+ it('adds/removes stuck class', function() {
+ runs(function() {
+ $scroller.scrollTop($scroller.scrollTop() - 1)
+ })
+ waitsFor(function() {
+ return !$sticky.hasClass('stuck')
+ })
+ })
+
+ it('gives the wrapper the same height as the sticky element', function() {
+ expect($sticky.parent().height()).toEqual($sticky.outerHeight())
+ })
+
+ it('executes handler option after stuck class applied', function() {
+ expect(handlerSpy).toHaveBeenCalled()
+ })
+ })
+ })
+
+ describe('#destroy', function() {
+ beforeEach(function() {
+ runs(function() {
+ $scroller.scrollTop($sticky.offset().top)
+ })
+ waitsFor(function() {
+ return handlerSpy.callCount
+ })
+ runs(function() {
+ waypoint.destroy()
+ })
+ })
+
+ it('unwraps the sticky element', function() {
+ expect($sticky.parent()).not.toHaveClass('sticky-wrapper')
+ })
+
+ it('removes the stuck class', function() {
+ expect($sticky).not.toHaveClass('stuck')
+ })
+ })
+ })
+
+ describe('with wrapper false', function() {
+ beforeEach(function() {
+ waypoint = new Waypoint.Sticky({
+ element: $sticky[0],
+ handler: handlerSpy,
+ wrapper: false
+ })
+ })
+
+ it('does not wrap the sticky element', function() {
+ expect($sticky.parent()).not.toHaveClass('sticky-wrapper')
+ })
+
+ it('does not unwrap on destroy', function() {
+ var parent = waypoint.wrapper
+ waypoint.destroy()
+ expect(parent).toBe(waypoint.wrapper)
+ })
+ })
+})
diff --git a/test/sticky.coffee b/test/sticky.coffee
deleted file mode 100644
index 7ef18cda..00000000
--- a/test/sticky.coffee
+++ /dev/null
@@ -1,62 +0,0 @@
-$.waypoints.settings.scrollThrottle = 10
-$.waypoints.settings.resizeThrottle = 20
-standardWait = 50
-
-describe 'Waypoints Sticky Elements Shortcut', ->
- $sticky = $return = handlerSpy = null
- $win = $ window
-
- beforeEach ->
- loadFixtures 'sticky.html'
- $sticky = $ '.sticky'
- handlerSpy = jasmine.createSpy 'on handler'
- $return = $sticky.waypoint 'sticky',
- handler: handlerSpy
-
- it 'returns the same jQuery object for chaining', ->
- expect($return.get()).toEqual $sticky.get()
-
- it 'wraps the sticky element', ->
- expect($sticky.parent()).toHaveClass 'sticky-wrapper'
-
- it 'gives the wrapper the same height as the sticky element', ->
- expect($sticky.parent().height()).toEqual $sticky.outerHeight()
-
- it 'adds stuck class when you reach the element', ->
- runs ->
- $win.scrollTop $sticky.offset().top
- waits standardWait
-
- runs ->
- expect($sticky).toHaveClass 'stuck'
- $win.scrollTop $win.scrollTop()-1
- waits standardWait
-
- runs ->
- expect($sticky).not.toHaveClass 'stuck'
-
- it 'executes handler option after stuck class applied', ->
- runs ->
- $win.scrollTop $sticky.offset().top
- waits standardWait
-
- runs ->
- expect(handlerSpy).toHaveBeenCalled()
-
- describe '#waypoint("unsticky")', ->
- beforeEach ->
- $return = $sticky.waypoint 'unsticky'
-
- it 'returns the same jQuery object for chaining', ->
- expect($return.get()).toEqual $sticky.get()
-
- it 'unwraps the sticky element', ->
- expect($sticky.parent()).not.toHaveClass 'sticky-wrapper'
-
- it 'should not have stuck class', ->
- expect($sticky).not.toHaveClass 'stuck'
-
- afterEach ->
- $.waypoints 'destroy'
- $win.scrollTop 0
-
diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js
new file mode 100644
index 00000000..8ffa6580
--- /dev/null
+++ b/test/waypoint-spec.js
@@ -0,0 +1,557 @@
+'use strict'
+/* global
+ * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs,
+ * waitsFor, loadFixtures, Waypoint
+ */
+
+window.jQuery.each(Waypoint.adapters, function(i, adapter) {
+ describe(adapter.name + ' adapter: ', function() {
+ describe('Waypoint', function() {
+ var $ = window.jQuery
+ var standard = 50
+ var hit, $scroller, waypoint, $target, returnValue
+
+ function setHitTrue() {
+ hit = true
+ }
+
+ function hitToBeTrue() {
+ return hit
+ }
+
+ beforeEach(function() {
+ Waypoint.Adapter = adapter.Adapter
+ loadFixtures('standard.html')
+ $scroller = $(window)
+ hit = false
+ waypoint = null
+ })
+
+ afterEach(function() {
+ Waypoint.destroyAll()
+ $scroller.scrollTop(0).scrollLeft(0)
+ })
+
+ describe('new Waypoint()', function() {
+ it('errors out', function() {
+ expect(function() {
+ waypoint = new Waypoint()
+ }).toThrow()
+ })
+ })
+
+ describe('new Waypoint(options)', function() {
+ it('returns an instance of the Waypoint class', function() {
+ waypoint = new Waypoint({
+ element: document.getElementById('same1'),
+ handler: function() {}
+ })
+ expect(waypoint instanceof Waypoint).toBeTruthy()
+ })
+
+ it('requires the element option', function() {
+ expect(function() {
+ waypoint = new Waypoint({
+ handler: function() {}
+ })
+ }).toThrow()
+ })
+
+ it('requires the handler option', function() {
+ expect(function() {
+ waypoint = new Waypoint({
+ element: document.getElementById('same1')
+ })
+ }).toThrow()
+ })
+
+ it('triggers down on new already-reached waypoints', function() {
+ runs(function() {
+ $target = $('#same2')
+ $scroller.scrollTop($target.offset().top + 1)
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: function(direction) {
+ hit = direction === 'down'
+ }
+ })
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+ })
+
+ describe('handler option', function() {
+ var currentDirection
+
+ beforeEach(function() {
+ $target = $('#same1')
+ currentDirection = null
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: function(direction) {
+ currentDirection = direction
+ }
+ })
+ })
+
+ it('triggers with direction parameter', function() {
+ runs(function() {
+ $scroller.scrollTop($target.offset().top)
+ })
+ waitsFor(function() {
+ return currentDirection === 'down'
+ }, 'down to trigger')
+ runs(function() {
+ $scroller.scrollTop($target.offset().top - 1)
+ })
+ waitsFor(function() {
+ return currentDirection === 'up'
+ }, 'up to trigger')
+ })
+ })
+
+ describe('offset option', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ })
+
+ it('takes a px offset', function(){
+ runs(function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ offset: 50
+ })
+ $scroller.scrollTop($target.offset().top - 51)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop($target.offset().top - 50)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('takes a % offset', function() {
+ var trigger = $target.offset().top - Waypoint.viewportHeight() * 0.37
+ runs(function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ offset: '37%'
+ })
+ $scroller.scrollTop(trigger - 1)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(trigger)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('takes a function offset', function() {
+ runs(function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ offset: function() {
+ return -$(this.element).height()
+ }
+ })
+ $scroller.scrollTop($target.offset().top + $target.height() - 1)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop($target.offset().top + $target.height())
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('takes a bottom-in-view function alias', function() {
+ var top = $target.offset().top
+ var height = $target.outerHeight()
+ var windowHeight = Waypoint.viewportHeight()
+ var inview = top + height - windowHeight
+ runs(function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ offset: 'bottom-in-view'
+ })
+ $scroller.scrollTop(inview - 1)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(inview)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+ })
+
+ describe('context option', function() {
+ beforeEach(function() {
+ $scroller = $('#bottom')
+ $target = $('#inner3')
+ })
+
+ it('works with px offset', function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ context: $scroller[0],
+ offset: 10
+ })
+ runs(function() {
+ $scroller.scrollTop(189)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(190)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('works with % offset', function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ context: $scroller[0],
+ offset: '100%'
+ })
+ runs(function() {
+ $scroller.scrollTop(149)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(150)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('works with function offset', function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ context: $scroller[0],
+ offset: function() {
+ return $(this.element).height() / 2
+ }
+ })
+ runs(function() {
+ $scroller.scrollTop(149)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(150)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+
+ it('works with bottom-in-view offset alias', function() {
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue,
+ context: $scroller[0],
+ offset: 'bottom-in-view'
+ })
+ runs(function() {
+ $scroller.scrollTop(249)
+ expect(hit).toBeFalsy()
+ $scroller.scrollTop(250)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+ })
+
+ describe('horizontal option', function() {
+ var currentDirection
+
+ beforeEach(function() {
+ currentDirection = null
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ horizontal: true,
+ handler: function(direction) {
+ currentDirection = direction
+ }
+ })
+ })
+
+ it('triggers right/left directions', function() {
+ runs(function() {
+ $scroller.scrollLeft($target.offset().left)
+ })
+ waitsFor(function() {
+ return currentDirection === 'right'
+ }, 'right direction to trigger')
+ runs(function() {
+ $scroller.scrollLeft($target.offset().left - 1)
+ })
+ waitsFor(function() {
+ return currentDirection === 'left'
+ })
+ })
+ })
+
+ describe('continuous option', function() {
+ var $later, laterWaypoint, hitCount, hitWaypoint
+
+ function incrementHitCount() {
+ hitCount += 1
+ hitWaypoint = this
+ }
+
+ beforeEach(function() {
+ $target = $('#same1')
+ $later = $('#near1')
+ hitCount = 0
+ waypoint = new Waypoint({
+ element: $target[0],
+ continuous: false,
+ handler: incrementHitCount
+ })
+ laterWaypoint = new Waypoint({
+ element: $later[0],
+ continuous: false,
+ handler: incrementHitCount
+ })
+ })
+
+ it('does not trigger the earlier waypoint', function() {
+ runs(function() {
+ $scroller.scrollTop($later.offset().top)
+ })
+ waitsFor(function() {
+ return hitCount
+ }, 'later callback to trigger')
+ runs(function() {
+ expect(hitCount).toEqual(1)
+ expect(hitWaypoint).toEqual(laterWaypoint)
+ })
+ })
+
+ it('prevents earlier trigger on refresh', function() {
+ runs(function() {
+ $target.css('top', '-1px')
+ $later.css('top', '-2px')
+ Waypoint.refreshAll()
+ })
+ waitsFor(function() {
+ return hitCount
+ }, 'later callback to trigger')
+ runs(function() {
+ expect(hitCount).toEqual(1)
+ expect(hitWaypoint).toEqual(waypoint)
+ })
+ })
+ })
+
+ describe('with window as the waypoint element', function() {
+ beforeEach(function() {
+ $target = $(window)
+ waypoint = new Waypoint({
+ element: $target[0],
+ offset: -$target.height(),
+ handler: setHitTrue
+ })
+ })
+
+ it('triggers waypoint', function() {
+ runs(function() {
+ $target.scrollTop($target.height() + 1)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+ })
+
+ describe('#disable()', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue
+ })
+ returnValue = waypoint.disable()
+ })
+
+ it('returns the same waypoint object for chaining', function() {
+ expect(returnValue).toEqual(waypoint)
+ })
+
+ it('disables callback triggers', function() {
+ runs(function() {
+ $scroller.scrollTop($target.offset().top)
+ })
+ waits(standard)
+ runs(function() {
+ expect(hit).toBeFalsy()
+ })
+ })
+ })
+
+ describe('#enable()', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue
+ })
+ waypoint.disable()
+ returnValue = waypoint.enable()
+ })
+
+ it('returns the same waypoint instance for chaining', function() {
+ expect(returnValue).toEqual(waypoint)
+ })
+
+ it('enables callback triggers', function() {
+ runs(function() {
+ $scroller.scrollTop($target.offset().top)
+ })
+ waitsFor(hitToBeTrue, 'callback to trigger')
+ })
+ })
+
+ describe('#destroy()', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue
+ })
+ returnValue = waypoint.destroy()
+ })
+
+ it('returns undefined', function() {
+ expect(returnValue).toBeUndefined()
+ })
+
+ it('no longer triggers callbacks', function() {
+ runs(function() {
+ $scroller.scrollTop($target.offset().top)
+ })
+ waits(standard)
+ runs(function() {
+ expect(hit).toBeFalsy()
+ })
+ })
+ })
+
+ describe('#previous', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue
+ })
+ })
+
+ it('calls previous on the waypoint group', function() {
+ spyOn(waypoint.group, 'previous')
+ waypoint.previous()
+ expect(waypoint.group.previous).toHaveBeenCalledWith(waypoint)
+ })
+
+ it('returns the group call results', function() {
+ expect(waypoint.previous()).toBeNull()
+ })
+ })
+
+ describe('#next', function() {
+ beforeEach(function() {
+ $target = $('#same1')
+ waypoint = new Waypoint({
+ element: $target[0],
+ handler: setHitTrue
+ })
+ })
+
+ it('calls next on the waypoint group', function() {
+ spyOn(waypoint.group, 'next')
+ waypoint.next()
+ expect(waypoint.group.next).toHaveBeenCalledWith(waypoint)
+ })
+
+ it('returns the group call results', function() {
+ expect(waypoint.next()).toBeNull()
+ })
+ })
+
+ describe('Waypoint.viewportHeight()', function() {
+ it('returns window innerHeight if it exists', function() {
+ var height = Waypoint.viewportHeight()
+ if (window.innerHeight) {
+ expect(height).toEqual(window.innerHeight)
+ }
+ else {
+ expect(height).toEqual(document.documentElement.clientHeight)
+ }
+ })
+ })
+
+ describe('Waypoint.viewportWidth()', function() {
+ it('returns client width', function() {
+ var clientWidth = document.documentElement.clientWidth
+ expect(Waypoint.viewportWidth()).toEqual(clientWidth)
+ })
+ })
+
+ describe('Waypoint.refreshAll()', function() {
+ it('is an alias for Waypoint.Context.refreshAll', function() {
+ spyOn(Waypoint.Context, 'refreshAll')
+ Waypoint.refreshAll()
+ expect(Waypoint.Context.refreshAll).toHaveBeenCalled()
+ })
+ })
+
+ describe('Waypoint.destroyAll()', function() {
+ it('calls destroy on all waypoints', function() {
+ var secondWaypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ waypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ spyOn(secondWaypoint, 'destroy').andCallThrough()
+ spyOn(waypoint, 'destroy').andCallThrough()
+ Waypoint.destroyAll()
+ expect(secondWaypoint.destroy).toHaveBeenCalled()
+ expect(waypoint.destroy).toHaveBeenCalled()
+ })
+ })
+
+ describe('Waypoint.disableAll()', function() {
+ it('calls disable on all waypoints', function() {
+ var secondWaypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ waypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ spyOn(secondWaypoint, 'disable').andCallThrough()
+ spyOn(waypoint, 'disable').andCallThrough()
+ Waypoint.disableAll()
+ expect(secondWaypoint.disable).toHaveBeenCalled()
+ expect(waypoint.disable).toHaveBeenCalled()
+ })
+ })
+
+ describe('Waypoint.enableAll()', function() {
+ var secondWaypoint
+
+ beforeEach(function() {
+ secondWaypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ waypoint = new Waypoint({
+ element: $('#same1')[0],
+ handler: function() {}
+ })
+ Waypoint.disableAll()
+ spyOn(Waypoint.Context, 'refreshAll').andCallThrough()
+ Waypoint.enableAll()
+ })
+
+ it('sets enabled on all waypoints', function() {
+ expect(secondWaypoint.enabled).toBeTruthy()
+ expect(waypoint.enabled).toBeTruthy()
+ })
+
+ it('refreshes all contexts', function() {
+ expect(Waypoint.Context.refreshAll).toHaveBeenCalled()
+ })
+ })
+ })
+ })
+})
diff --git a/test/waypoints.coffee b/test/waypoints.coffee
deleted file mode 100644
index 9055899b..00000000
--- a/test/waypoints.coffee
+++ /dev/null
@@ -1,725 +0,0 @@
-$.waypoints.settings.scrollThrottle = 10
-$.waypoints.settings.resizeThrottle = 20
-standardWait = 50
-
-# Go tests, go
-
-describe 'jQuery Waypoints', ->
- hit = $se = $e = $return = null
-
- beforeEach ->
- loadFixtures 'standard.html'
- $se = $ window
- hit = false
-
- describe '#waypoint()', ->
- it 'errors out', ->
- fn = -> $('#same1').waypoint()
- expect(fn).toThrow $.Error
-
- describe '#waypoint(callback)', ->
- currentDirection = null
-
- beforeEach ->
- currentDirection = null
- $e = $('#same1').waypoint (direction) ->
- currentDirection = direction
- hit = true
-
- it 'creates a waypoint', ->
- expect($.waypoints().vertical.length).toEqual 1
-
- it 'triggers the callback', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'uses the default offset', ->
- runs ->
- $se.scrollTop($e.offset().top - 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'passes correct directions', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(currentDirection).toEqual 'down'
- $se.scrollTop($e.offset().top - 1)
- waits standardWait
-
- runs ->
- expect(currentDirection).toEqual 'up'
-
-
-
- describe '#waypoint(options)', ->
- beforeEach ->
- $e = $ '#same1'
-
- it 'creates a waypoint', ->
- $e.waypoint
- offset: 1
- triggerOnce: true
- expect($.waypoints().vertical.length).toEqual 1
-
- it 'respects a px offset', ->
- runs ->
- $e.waypoint
- offset: 50
- handler: -> hit = true
- $se.scrollTop($e.offset().top - 51)
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop($e.offset().top - 50)
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects a % offset', ->
- pos = null
-
- runs ->
- $e.waypoint
- offset: '37%'
- handler: -> hit = true
- pos = $e.offset().top - $.waypoints('viewportHeight') * .37 - 1
- $se.scrollTop pos
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop pos + 1
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects a function offset', ->
- runs ->
- $e.waypoint
- offset: ->
- $(this).height() * -1
- handler: -> hit = true
- $se.scrollTop($e.offset().top + $e.height() - 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop($e.offset().top + $e.height())
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects the bottom-in-view function alias', ->
- inview = $e.offset().top \
- - $.waypoints('viewportHeight') \
- + $e.outerHeight()
-
- runs ->
- $e.waypoint
- offset: 'bottom-in-view'
- handler: -> hit = true
- $se.scrollTop(inview - 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop inview
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'destroys the waypoint if triggerOnce is true', ->
- runs ->
- $e.waypoint
- triggerOnce: true
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect($.waypoints().length).toBeFalsy()
-
- it 'triggers if continuous is true and waypoint is not last', ->
- $f = $ '#near1'
- $g = $ '#near2'
- hitcount = 0
-
- runs ->
- $e.add($f).add($g).waypoint ->
- hitcount++
- $se.scrollTop $g.offset().top
- waits standardWait
-
- runs ->
- expect(hitcount).toEqual 3
-
- it 'does not trigger if continuous false, waypoint not last', ->
- $f = $ '#near1'
- $g = $ '#near2'
- hitcount = 0
-
- runs ->
- callback = ->
- hitcount++
- options =
- continuous: false
- $e.add($g).waypoint callback
- $f.waypoint callback, options
- $se.scrollTop $g.offset().top
- waits standardWait
-
- runs ->
- expect(hitcount).toEqual 2
-
- it 'triggers if continuous is false, waypoint is last', ->
- $f = $ '#near1'
- $g = $ '#near2'
- hitcount = 0
-
- runs ->
- callback = ->
- hitcount++
- options =
- continuous: false
- $e.add($f).waypoint callback
- $g.waypoint callback, options
- $se.scrollTop $g.offset().top
- waits standardWait
-
- runs ->
- expect(hitcount).toEqual 3
-
- it 'uses the handler option if provided', ->
- hitcount = 0
-
- runs ->
- $e.waypoint
- handler: (dir) ->
- hitcount++
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hitcount).toEqual 1
-
- describe '#waypoint(callback, options)', ->
- beforeEach ->
- callback = ->
- hit = true
- options =
- offset: -1
- $e = $('#same1').waypoint callback, options
-
- it 'creates a waypoint', ->
- expect($.waypoints().vertical.length).toEqual 1
-
- it 'respects options', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $se.scrollTop($e.offset().top + 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'fires the callback', ->
- runs ->
- $se.scrollTop($e.offset().top + 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- describe '#waypoint("disable")', ->
- beforeEach ->
- $e = $('#same1').waypoint ->
- hit = true
- $return = $e.waypoint 'disable'
-
- it 'disables callback triggers', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
-
- it 'returns the same jQuery object for chaining', ->
- expect($return.get()).toEqual $e.get()
-
- describe '.waypoint("enable")', ->
- beforeEach ->
- $e = $('#same1').waypoint ->
- hit = true
- $e.waypoint 'disable'
- $return = $e.waypoint 'enable'
-
- it 'enables callback triggers', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'returns the same jQuery object for chaining', ->
- expect($return.get()).toEqual $e.get()
-
-
- describe '#waypoint("destroy")', ->
- beforeEach ->
- $e = $('#same1').waypoint ->
- hit = true
- $return = $e.waypoint 'destroy'
-
- it 'removes waypoint from list of waypoints', ->
- expect($.waypoints().length).toBeFalsy()
-
- it 'no longer triggers callback', ->
- runs ->
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
-
- it 'does not preserve callbacks if .waypoint recalled', ->
- runs ->
- $e.waypoint({})
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
-
- it 'returns the same jQuery object for chaining', ->
- expect($return.get()).toEqual $e.get()
-
- it 'unregisters waypoint even if underlying nodes are removed', ->
- $e = $('#same2').waypoint ->
- hit = true
- $e.remove()
- $e.waypoint 'destroy'
- expect($.waypoints().vertical.length).toEqual(0);
-
- describe '#waypoint("prev")', ->
- it 'returns jQuery object containing previous waypoint', ->
- $e = $ '#same1'
- $f = $ '#near1'
- $e.add($f).waypoint({})
- expect($f.waypoint('prev')[0]).toEqual $e[0]
-
- it 'can be used in a non-window context', ->
- $e = $ '#inner1'
- $f = $ '#inner2'
- $e.add($f).waypoint
- context: '#bottom'
- expect($f.waypoint('prev', 'vertical', '#bottom')[0]).toEqual $e[0]
-
- describe '#waypoint("next")', ->
- it 'returns jQuery object containing next waypoint', ->
- $e = $ '#same1'
- $f = $ '#near1'
- $e.add($f).waypoint({})
- expect($e.waypoint('next')[0]).toEqual $f[0]
-
- describe 'jQuery#waypoints()', ->
- it 'starts as an empty array for each axis', ->
- expect($.waypoints().vertical.length).toBeFalsy()
- expect($.waypoints().horizontal.length).toBeFalsy()
- expect($.isPlainObject $.waypoints()).toBeTruthy()
- expect($.isArray $.waypoints().horizontal).toBeTruthy()
- expect($.isArray $.waypoints().vertical).toBeTruthy()
-
- it 'returns waypoint elements', ->
- $e = $('#same1').waypoint({})
- expect($.waypoints().vertical[0]).toEqual $e[0]
-
- it 'does not blow up with multiple waypoint', ->
- $e = $('.sameposition, #top').waypoint({})
- $e = $e.add $('#near1').waypoint({})
- expect($.waypoints().vertical.length).toEqual 4
- expect($.waypoints().vertical[0]).toEqual $('#top')[0]
-
- it 'returns horizontal elements', ->
- $e = $('#same1').waypoint
- horizontal: true
- expect($.waypoints().horizontal[0]).toEqual $e[0]
-
- describe 'Directional filters', ->
- $f = null
-
- beforeEach ->
- $e = $ '#same1'
- $f = $ '#near1'
-
- describe 'above', ->
- it 'returns waypoints only above the current scroll position', ->
- runs ->
- $e.add($f).waypoint({})
- $se.scrollTop 1500
- waits standardWait
-
- runs ->
- expect($.waypoints('above')).toEqual [$e[0]]
-
- describe 'below', ->
- it 'returns waypoints only below the current scroll position', ->
- runs ->
- $e.add($f).waypoint({})
- $se.scrollTop 1500
- waits standardWait
-
- runs ->
- expect($.waypoints('below')).toEqual [$f[0]]
-
- describe 'left', ->
- it 'returns waypoints only left of the current scroll position', ->
- runs ->
- $e.add($f).waypoint
- horizontal: true
- $se.scrollLeft 1500
- waits standardWait
-
- runs ->
- expect($.waypoints('left')).toEqual [$e[0]]
-
- describe 'right', ->
- it 'returns waypoints only right of the current scroll position', ->
- runs ->
- $e.add($f).waypoint
- horizontal: true
- $se.scrollLeft 1500
- waits standardWait
-
- runs ->
- expect($.waypoints('right')).toEqual [$f[0]]
-
-
- describe 'jQuery#waypoints("refresh")', ->
- currentDirection = null
-
- beforeEach ->
- currentDirection = null
- $e = $('#same1').waypoint (direction) ->
- currentDirection = direction
-
- it 'triggers callback if refresh crosses scroll', ->
- runs ->
- $se.scrollTop($e.offset().top - 1)
- waits standardWait
-
- runs ->
- $e.css('top', ($e.offset().top - 50) + 'px')
- $.waypoints 'refresh'
- expect(currentDirection).toEqual 'down'
- expect(currentDirection).not.toEqual 'up'
- $e.css('top', $e.offset().top + 50 + 'px')
- $.waypoints 'refresh'
- expect(currentDirection).not.toEqual 'down'
- expect(currentDirection).toEqual 'up'
-
-
- it 'does not trigger callback if onlyOnScroll true', ->
- $f = null
-
- runs ->
- $f = $('#same2').waypoint
- onlyOnScroll: true
- handler: -> hit = true
- $se.scrollTop($f.offset().top - 1)
- waits standardWait
-
- runs ->
- $f.css('top', ($f.offset().top - 50) + 'px')
- $.waypoints 'refresh'
- expect(hit).toBeFalsy()
- $f.css('top', $f.offset().top + 50 + 'px')
- $.waypoints 'refresh'
- expect(hit).toBeFalsy()
-
- it 'updates the offset', ->
- runs ->
- $se.scrollTop($e.offset().top - 51)
- $e.css('top', ($e.offset().top - 50) + 'px')
- $.waypoints 'refresh'
- waits standardWait
-
- runs ->
- expect(currentDirection).toBeFalsy()
- $se.scrollTop $e.offset().top
- waits standardWait
-
- runs ->
- expect(currentDirection).toBeTruthy()
-
- describe 'jQuery#waypoints("viewportHeight")', ->
- it 'returns window innerheight if it exists', ->
- if window.innerHeight
- expect($.waypoints 'viewportHeight').toEqual window.innerHeight
- else
- expect($.waypoints 'viewportHeight').toEqual $(window).height()
-
- describe 'jQuery#waypoints("disable")', ->
- it 'disables all waypoints', ->
- count = 0
-
- runs ->
- $e = $('.sameposition').waypoint -> count++
- $.waypoints 'disable'
- $se.scrollTop($e.offset().top + 50)
- waits standardWait
-
- runs ->
- expect(count).toEqual 0
-
- describe 'jQuery#waypoints("enable")', ->
- it 'enables all waypoints', ->
- count = 0
-
- runs ->
- $e = $('.sameposition').waypoint -> count++
- $.waypoints 'disable'
- $.waypoints 'enable'
- $se.scrollTop($e.offset().top + 50)
- waits standardWait
-
- runs ->
- expect(count).toEqual 2
-
- describe 'jQuery#waypoints("destroy")', ->
- it 'destroys all waypoints', ->
- $e = $('.sameposition').waypoint({})
- $.waypoints 'destroy'
- expect($.waypoints().vertical.length).toEqual 0
-
- describe 'jQuery#waypoints("extendFn", methodName, function)', ->
- it 'adds method to the waypoint namespace', ->
- currentArg = null
- $.waypoints 'extendFn', 'myMethod', (arg) ->
- currentArg = arg
- $('#same1').waypoint 'myMethod', 'test'
- expect(currentArg).toEqual 'test'
-
- describe 'jQuery#waypoints.settings', ->
- count = curID = null
-
- beforeEach ->
- count = 0
- $('.sameposition, #near1, #near2').waypoint ->
- count++
- curID = $(this).attr 'id'
-
- it 'throttles the scroll check', ->
- runs ->
- $se.scrollTop $('#same1').offset().top
- expect(count).toEqual 0
- waits standardWait
-
- runs ->
- expect(count).toEqual 2
-
- it 'throttles the resize event and calls refresh', ->
- runs ->
- $('#same1').css 'top', "-1000px"
- $(window).resize()
- expect(count).toEqual 0
- waits standardWait
-
- runs ->
- expect(count).toEqual 1
-
- describe 'non-window scroll context', ->
- $inner = null
-
- beforeEach ->
- $inner = $ '#bottom'
-
- it 'triggers the waypoint within its context', ->
- $e = $('#inner3').waypoint
- context: '#bottom'
- handler: -> hit = true
-
- runs ->
- $inner.scrollTop 199
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $inner.scrollTop 200
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects % offsets within contexts', ->
- $e = $('#inner3').waypoint
- context: '#bottom'
- offset: '100%'
- handler: -> hit = true
-
- runs ->
- $inner.scrollTop 149
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $inner.scrollTop 150
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects function offsets within context', ->
- $e = $('#inner3').waypoint
- context: '#bottom'
- offset: ->
- $(this).height() / 2
- handler: -> hit = true
-
- runs ->
- $inner.scrollTop 149
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $inner.scrollTop 150
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- it 'respects bottom-in-view alias', ->
- $e = $('#inner3').waypoint
- context: '#bottom'
- offset: 'bottom-in-view'
- handler: -> hit = true
-
- runs ->
- $inner.scrollTop 249
- waits standardWait
-
- runs ->
- expect(hit).toBeFalsy()
- $inner.scrollTop 250
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- afterEach ->
- $inner.scrollTop 0
-
- describe 'Waypoints added after load, Issue #28, 62, 63', ->
- it 'triggers down on new but already reached waypoints', ->
- runs ->
- $e = $ '#same2'
- $se.scrollTop($e.offset().top + 1)
- waits standardWait
-
- runs ->
- $e.waypoint (direction) ->
- hit = direction is 'down'
-
- waitsFor (-> hit), '#same2 to trigger', 1000
-
- describe 'Multiple waypoints on the same element', ->
- hit2 = false
-
- beforeEach ->
- hit2 = false
- $e = $('#same1').waypoint
- handler: ->
- hit = true
- $e.waypoint
- handler: ->
- hit2 = true
- offset: -50
-
- it 'triggers all handlers', ->
- runs ->
- $se.scrollTop($e.offset().top + 50)
- waits standardWait
-
- runs ->
- expect(hit and hit2).toBeTruthy()
-
- it 'uses only one element in $.waypoints() array', ->
- expect($.waypoints().vertical.length).toEqual 1
-
- it 'disables all waypoints on the element when #disabled called', ->
- runs ->
- $e.waypoint 'disable'
- $se.scrollTop($e.offset().top + 50)
- waits standardWait
-
- runs ->
- expect(hit or hit2).toBeFalsy()
-
- describe 'Horizontal waypoints', ->
- currentDirection = null
-
- beforeEach ->
- currentDirection = null
- $e = $('#same1').waypoint
- horizontal: true
- handler: (direction) ->
- currentDirection = direction
-
- it 'triggers right/left direction', ->
- runs ->
- $se.scrollLeft $e.offset().left
- waits standardWait
-
- runs ->
- expect(currentDirection).toEqual 'right'
- $se.scrollLeft($e.offset().left - 1)
- waits standardWait
-
- runs ->
- expect(currentDirection).toEqual 'left'
-
- describe 'Waypoints attached to window object, pull request 86', ->
- $win = $ window;
-
- beforeEach ->
- $e = $win.waypoint
- offset:
- -$win.height()
- handler: -> hit = true
-
- it 'triggers waypoint reached', ->
- runs ->
- $win.scrollTop($win.height() + 1)
- waits standardWait
-
- runs ->
- expect(hit).toBeTruthy()
-
- afterEach ->
- $.waypoints 'destroy'
- $se.scrollTop(0).scrollLeft 0
- hit = false
- waits standardWait
diff --git a/testem.json b/testem.json
new file mode 100644
index 00000000..21f89a03
--- /dev/null
+++ b/testem.json
@@ -0,0 +1,24 @@
+{
+ "framework": "jasmine",
+ "launch_in_dev": [
+ "PhantomJS"
+ ],
+ "launch_in_ci": [
+ "PhantomJS"
+ ],
+ "src_files": [
+ "bower_components/jquery/dist/jquery.js",
+ "bower_components/jasmine-jquery/lib/jasmine-jquery.js",
+ "bower_components/zepto/zepto.js",
+
+ "src/waypoint.js",
+ "src/context.js",
+ "src/group.js",
+ "src/debug.js",
+ "src/adapters/*.js",
+ "src/shortcuts/*.js",
+
+ "test/settings.js",
+ "test/*-spec.js"
+ ]
+}
diff --git a/waypoints.coffee b/waypoints.coffee
deleted file mode 100644
index 5e89aff0..00000000
--- a/waypoints.coffee
+++ /dev/null
@@ -1,692 +0,0 @@
-###
-jQuery Waypoints - v2.0.4
-Copyright (c) 2011-2014 Caleb Troughton
-Dual licensed under the MIT license and GPL license.
-https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
-###
-((root, factory) ->
- if typeof define is 'function' and define.amd
- define 'waypoints', ['jquery'], ($) ->
- factory $, root
- else
- factory root.jQuery, root
-) this, ($, window) ->
- $w = $ window
-
- # Touch support feature test
- isTouch = 'ontouchstart' in window
-
- # Internal plugin-wide variables:
-
- # - allWaypoints: A hash containing two hashes, one for vertical waypoints
- # and one for horizontal waypoints. In each hash they value is a Waypoint
- # instance and the key is that waypoint's unique ID.
-
- # - contextCounter: A counter that is incremented with each instantiation
- # of the Context class, used in its unique ID.
-
- # - contexts: A hash of all contexts. The value of each entry is a Context
- # instance and the key is that context's unique ID.
-
- # - contextKey: The DOM element for each context keeps a reference to the
- # context's unique ID in the jQuery .data() object. This is the key for
- # that data entry.
-
- # - resizeEvent: The namespaced resize event used by contexts.
-
- # - scrollEvent: The namespaced scroll event used by contexts.
-
- # - waypointCounter: A counter that is incremented with each instantiation
- # of the Waypoint class, used in its unique ID.
-
- # - waypointKey: The DOM element for each waypoint keeps a reference to an
- # array of the unique IDs of all waypoints attached to that element. This
- # array is kept in the jQuery .data() object, and this is the key for
- # that entry.
-
- # - wp: A variable shortcut for the waypoint method name on the $.fn object.
- # Using this variable just helps with minification.
-
- # - wps: A variable shortcut for the waypoints method name on the $ object.
- # Using this variable just helps with minification.
-
- allWaypoints =
- horizontal: {}
- vertical: {}
- contextCounter = 1
- contexts = {}
- contextKey = 'waypoints-context-id'
- resizeEvent = 'resize.waypoints'
- scrollEvent = 'scroll.waypoints'
- waypointCounter = 1
- waypointKey = 'waypoints-waypoint-ids'
- wp = 'waypoint'
- wps = 'waypoints'
-
- # Context: Represents a single scrolling element in which waypoints live.
- # For most users there will only be one Context, the window, but users can
- # use other scrollable elements as a context using the "context" option
- # when creating waypoints.
-
- # Properties:
-
- # - $element: jQuery object containing the context element.
-
- # - element: The raw HTMLNode of the context element.
-
- # - didResize: A flag used in throttling the resize event.
-
- # - didScroll: A flag used in throttling the scroll event.
-
- # - id: A unique identifier for the context.
-
- # - oldScroll: A hash containing...
- # - x: The context's last known horizontal scroll value.
- # - y: The context's last known vertical scroll value.
-
- # - waypoints: A hash containing two hashes with all waypoints in the context.
- # Entries are in the same style as the allWaypoints hashes:
- # (key = waypoint.id, value = waypoint)
- # - horizontal: A hash of all horizontal waypoints.
- # - vertical: A hash of all vertical waypoints.
-
- class Context
- constructor: ($element) ->
- @$element = $element
- @element = $element[0]
- @didResize = no
- @didScroll = no
- @id = 'context' + contextCounter++
- @oldScroll =
- x: $element.scrollLeft()
- y: $element.scrollTop()
- @waypoints =
- horizontal: {}
- vertical: {}
-
- # We need to keep a reference to this Context instance on the DOM node
- # so we can look it up later based on the node.
- @element[contextKey] = @id
-
- # To do that look up, we need to have this instance in the global hash.
- contexts[@id] = this
-
- # Run scroll checks on scroll, but throttle it for performance reasons.
- $element.bind scrollEvent, =>
- unless @didScroll or isTouch
- @didScroll = yes
- scrollHandler = =>
- @doScroll()
- @didScroll = no
- window.setTimeout scrollHandler, $[wps].settings.scrollThrottle
-
- # Run a refresh on resize, but throttle it for performance reasons.
- $element.bind resizeEvent, =>
- unless @didResize
- @didResize = yes
- resizeHandler = =>
- $[wps] 'refresh'
- @didResize = no
- window.setTimeout resizeHandler, $[wps].settings.resizeThrottle
-
- # doScroll()
-
- # Looks at the new scroll values for the context, compares them to the old
- # scroll values, and checks to see if any waypoints should be triggered
- # by that change.
- doScroll: ->
-
- # We use some hashes with common values for each axis so that we can
- # just iterate over it rather than write the whole thing twice for
- # each axis.
- axes =
- horizontal:
- newScroll: @$element.scrollLeft()
- oldScroll: @oldScroll.x
- forward: 'right'
- backward: 'left'
- vertical:
- newScroll: @$element.scrollTop()
- oldScroll: @oldScroll.y
- forward: 'down'
- backward: 'up'
-
- # This is a small "hack" for iOS, needed because scrolls in mobile
- # Safari that start or end with the URL bar showing will cause window
- # height changes without firing a resize event.
- if isTouch and (!axes.vertical.oldScroll or !axes.vertical.newScroll)
- $[wps] 'refresh'
-
- # For each axis, check to see if any waypoints have been crossed.
- # Also determine the direction it's being crossed and sort/reverse all
- # crossed waypoints accordingly. And, of course, trigger the waypoints.
- $.each axes, (aKey, axis) =>
- triggered = []
- isForward = axis.newScroll > axis.oldScroll
- direction = if isForward then axis.forward else axis.backward
- $.each @waypoints[aKey], (wKey, waypoint) ->
- if axis.oldScroll < waypoint.offset <= axis.newScroll
- triggered.push waypoint
- else if axis.newScroll < waypoint.offset <= axis.oldScroll
- triggered.push waypoint
- triggered.sort (a, b) -> a.offset - b.offset
- triggered.reverse() unless isForward
- $.each triggered, (i, waypoint) ->
- if waypoint.options.continuous or i is triggered.length - 1
- waypoint.trigger [direction]
-
- # Now that we're done with the check, the new scroll values become
- # the old scroll values for the next check.
- @oldScroll =
- x: axes.horizontal.newScroll
- y: axes.vertical.newScroll
-
- # refresh()
- # Runs through all of the waypoints in the context and recalculates
- # their offsets (the scroll value at which the waypoint is triggered.)
- # If a change in offset also happens to cross the context's current
- # scroll value, the waypoint will be triggered in the appropriate direction
- # unless prevented by the "onlyOnScroll" waypoint option.
- refresh: () ->
- isWin = $.isWindow @element
- cOffset = @$element.offset()
-
- # Make sure we have the most up-to-date scroll values for our context.
- @doScroll()
-
- # Each axis recalculation needs to know some things:
-
- # - contextOffset: The distance between the edge of the document and
- # the context element.
-
- # - contextScroll: The scroll value of the context. However, if the
- # context is the window this needs to be 0 because this value only
- # comes into play when used in adjustment calculations for non-window
- # context waypoints.
-
- # - contextDimension: Width or height of the context.
-
- # - oldScroll: The scroll value of the context. Unlike "contextScroll",
- # this is the same no matter the type of context, and is used when
- # determining whether a newly added waypoint should immediately fire
- # on its first offset calculation.
-
- # - forward: Direction string passed to forward waypoint triggers.
-
- # - backward: Direction string passed to backward waypoint triggers.
-
- # - offsetProp: Key of the .offset() object for this axis.
- axes =
- horizontal:
- contextOffset: if isWin then 0 else cOffset.left
- contextScroll: if isWin then 0 else @oldScroll.x
- contextDimension: @$element.width()
- oldScroll: @oldScroll.x
- forward: 'right'
- backward: 'left'
- offsetProp: 'left'
- vertical:
- contextOffset: if isWin then 0 else cOffset.top
- contextScroll: if isWin then 0 else @oldScroll.y
- contextDimension: if isWin then $[wps]('viewportHeight') else \
- @$element.height()
- oldScroll: @oldScroll.y
- forward: 'down'
- backward: 'up'
- offsetProp: 'top'
-
- # For each axis, run through the waypoints. Store the old offset.
- # Recalculate the new offset. Check the difference against the context's
- # current scroll value and trigger any crossed waypoints accordingly.
- $.each axes, (aKey, axis) =>
- $.each @waypoints[aKey], (i, waypoint) ->
- adjustment = waypoint.options.offset
- oldOffset = waypoint.offset
- elementOffset = if $.isWindow waypoint.element then 0 else \
- waypoint.$element.offset()[axis.offsetProp]
-
- # The "offset" waypoint option (which we call "adjustment" here) can
- # be a number, percentage string, keyword string (bottom-in-view),
- # or a function. So we deal with all of these types here.
- if $.isFunction adjustment
- adjustment = adjustment.apply waypoint.element
- else if typeof adjustment is 'string'
- adjustment = parseFloat adjustment
- if waypoint.options.offset.indexOf('%') > -1
- adjustment = Math.ceil(axis.contextDimension * adjustment / 100)
-
- # We've finally calculated all the crazy little adjustments that
- # can come from using non-window contexts and the "offset" option.
- # Store the damn thing.
- waypoint.offset = elementOffset \
- - axis.contextOffset \
- + axis.contextScroll \
- - adjustment
-
- # "onlyOnScroll" tells us to not even consider triggering waypoints
- # during refresh, so we can eject early.
- return if (waypoint.options.onlyOnScroll and oldOffset?) or \
- !waypoint.enabled
-
- # Case where the refresh causes a backward trigger.
- if oldOffset isnt null and \
- oldOffset < axis.oldScroll <= waypoint.offset
- waypoint.trigger [axis.backward]
-
- # Now the forward case.
- else if oldOffset isnt null and \
- oldOffset > axis.oldScroll >= waypoint.offset
- waypoint.trigger [axis.forward]
-
- # "oldOffset" values of null mean this is the first calculation of
- # the waypoint's offset. It's a special time in a waypoint's life.
- else if oldOffset is null and axis.oldScroll >= waypoint.offset
- waypoint.trigger [axis.forward]
-
- # checkEmpty()
-
- # Looks at the waypoints hashes. If they are empty, the context removes
- # itself from the global contexts hash.
- checkEmpty: ->
- if $.isEmptyObject(@waypoints.horizontal) and \
- $.isEmptyObject(@waypoints.vertical)
- @$element.unbind [resizeEvent, scrollEvent].join(' ')
- delete contexts[@id]
-
- # Waypoint: Represents a single callback function tied to an element. An
- # element can have multiple waypoints with multiple offsets.
-
- # Properties:
-
- # - $element: jQuery object containing the waypoint element.
-
- # - element: The raw HTMLNode of the waypoint element.
-
- # - axis: 'horizontal' || 'vertical' - The axis on which this waypoint lives.
-
- # - callback: The function that is fired when the waypoint is triggered.
-
- # - context: A reference to the context this waypoint belongs to.
-
- # - enabled: Boolean indicating whether this waypoint is enabled or not.
- # Disabled waypoints are still returned in functions that aggregate
- # waypoints, but do not fire their callbacks.
-
- # - id: A unique identifier for the waypoint.
-
- # - offset: The scroll offset at which the waypoint should trigger.
-
- # - options: A hash containing the various waypoint options.
- # See $.fn.waypoint.defaults for more information on those options.
- class Waypoint
- constructor: ($element, context, options) ->
- options = $.extend {}, $.fn[wp].defaults, options
- if options.offset is 'bottom-in-view'
- options.offset = ->
- contextHeight = $[wps] 'viewportHeight'
- unless $.isWindow context.element
- contextHeight = context.$element.height()
- contextHeight - $(this).outerHeight()
-
- @$element = $element
- @element = $element[0]
- @axis = if options.horizontal then 'horizontal' else 'vertical'
- @callback = options.handler
- @context = context
- @enabled = options.enabled
- @id = 'waypoints' + waypointCounter++
- @offset = null
- @options = options
-
- # Add our new waypoint to its context.
- context.waypoints[@axis][@id] = this
-
- # Add it to the global hash.
- allWaypoints[@axis][@id] = this
-
- # Add the waypoint's id to the element's waypoint id list.
- idList = @element[waypointKey] ? []
- idList.push @id
- @element[waypointKey] = idList
-
- # trigger(array)
-
- # Calls the waypoint's callback function, passing to it the arguments
- # supplied in the "args" array.
- trigger: (args) ->
- return unless @enabled
- if @callback?
- @callback.apply @element, args
- if @options.triggerOnce
- @destroy()
-
- # disable()
-
- # Temporarily disables a waypoint from firing its callback.
- disable: ->
- @enabled = false
-
- # enable()
-
- # Breathe life back into the waypoint.
- enable: ->
- @context.refresh()
- @enabled = true
-
- # destroy()
-
- # Kills the waypoint for good.
- destroy: ->
- delete allWaypoints[@axis][@id]
- delete @context.waypoints[@axis][@id]
- @context.checkEmpty()
-
- # Waypoint.getWaypointsByElement(HTMLNode)
-
- # Returns an array of all Waypoint instances attached to the "element"
- # HTMLNode. Returns an empty array if there are no attached waypoints.
- @getWaypointsByElement: (element) ->
- ids = element[waypointKey]
- return [] unless ids
- all = $.extend {}, allWaypoints.horizontal, allWaypoints.vertical
- $.map ids, (id) ->
- all[id]
-
- # These methods are available on the $.fn object by using the method
- # name as the first argument to .waypoint. Ex: $('div').waypoint('destroy')
- methods =
-
- # init(function, object)
-
- # Creates a new waypoint (and if needed, a new context) using the supplied
- # callback function and options.
-
- # The "f" function and the "options" object are both optional, but at least
- # one must be supplied. So acceptable signatures are:
-
- # - .waypoint(f)
- # - .waypoint(options)
- # - .waypoint(f, options)
-
- # This "init" method should never need to be called explicity by the user.
- # It is the default method that is delegated to when .waypoint is called
- # with one of the above signatures.
-
- # Ex: $('div').waypoint(function(direction) {
- # // Do things
- # }, { offset: '100%' });
- init: (f, options) ->
- options ?= {}
- options.handler ?= f
-
- @each ->
- $this = $ this
- contextElement = options.context ? $.fn[wp].defaults.context
- unless $.isWindow contextElement
- contextElement = $this.closest contextElement
- contextElement = $ contextElement
- context = contexts[contextElement[0][contextKey]]
- context = new Context contextElement unless context
- new Waypoint $this, context, options
- $[wps] 'refresh'
- this
-
- # Disable, enable, and destroy all just delegate to the instance methods
- # of the waypoints attached to the subject elements.
- disable: -> methods._invoke.call this, 'disable'
- enable: -> methods._invoke.call this, 'enable'
- destroy: -> methods._invoke.call this, 'destroy'
-
- # .waypoint('prev', string, string|HTMLNode|jQuery)
-
- # Returns a jQuery object containing previous waypoint elements. This
- # creates a new entry in the jQuery object stack just like jQuery's prev
- # function. "axis" indicates the axis on which to traverse
- # ('horizontal' | 'vertical') and "selector" indicates which context
- # element to use. The defaults are 'vertical' and window respectively.
- prev: (axis, selector) ->
- methods._traverse.call this, axis, selector, (stack, index, waypoints) ->
- stack.push waypoints[index-1] if index > 0
-
- # .waypoint('next', string, string|HTMLNode|jQuery)
-
- # Returns a jQuery object containing next waypoint elements. This
- # creates a new entry in the jQuery object stack just like jQuery's next
- # function. "axis" indicates the axis on which to traverse
- # ('horizontal' | 'vertical') and "selector" indicates which context
- # element to use. The defaults are 'vertical' and window respectively.
- next: (axis, selector) ->
- methods._traverse.call this, axis, selector, (stack, index, waypoints) ->
- stack.push waypoints[index+1] if index < waypoints.length-1
-
- # Internal: Aggregates waypoints on a given axis of a context, and applies
- # a "push" callback for each element in the subject jQuery object. This
- # callback builds the element array to push to the jQuery stack.
- _traverse: (axis = 'vertical', selector = window, push) ->
- waypoints = jQMethods.aggregate selector
- stack = []
- @each ->
- index = $.inArray this, waypoints[axis]
- push stack, index, waypoints[axis]
- @pushStack stack
-
- # Internal: Finds all waypoints on a given set of "$elements" and invokes
- # "method" on each instance.
- _invoke: (method) ->
- this.each ->
- waypoints = Waypoint.getWaypointsByElement this
- $.each waypoints, (i, waypoint) ->
- waypoint[method]()
- true
- this
-
- # $.fn.waypoint. Let's just hook this guy up to our methods hash and
- # add some trivial error reporting for bogus calls.
- $.fn[wp] = (method, args...) ->
- if methods[method]
- methods[method].apply this, args
- else if $.isFunction(method)
- methods.init.apply this, arguments
- else if $.isPlainObject(method)
- methods.init.apply this, [null, method]
- else if !method
- $.error "jQuery Waypoints needs a callback function or handler option."
- else
- $.error "The #{method} method does not exist in jQuery Waypoints."
-
- # The default options object for a waypoint.
-
- # - context: string|HTMLNode|jQuery - The scrollable element that the
- # waypoint acts within. The waypoint will look for the closest ancestor
- # element that matches this selector or node.
-
- # - continuous: Multiple waypoints may be triggered by a single scroll check.
- # If you would like a waypoint to only trigger if it is the last waypoint
- # in a scroll check, set this to false.
-
- # - enabled: Should this waypoint start enabled (true) or disabled (false)?
-
- # - handler: This option is not defined by default, but can be used as an
- # alternate way to pass the waypoint callback function, rather than as
- # the first argument to .waypoint.
-
- # Ex: $('div').waypoint({
- # handler: function(direction) { ... }
- # });
-
- # - horizontal: Set this to true if the waypoint is, well, horizontal.
-
- # - offset: number|string|function - Determines how far from the top (or left
- # if the waypoint is horizontal) of the context's viewport to trigger the
- # waypoint. The default of 0 means that the waypoint is triggered when the
- # top of the waypoint element hits the top of the window/context-element.
- # An offset of 50 would mean the waypoint triggers when the top of the
- # element is 50 pixels from the top of the window.
-
- # A % string is translated into a percentage of the width/height of
- # the context.
-
- # If a function is passed, that function should return a number. The "this"
- # keyword within this function will be set to the raw HTMLNode of the
- # waypoint element.
-
- # - triggerOnce: If true, the waypoint will destroy itself after
- # first trigger.
- $.fn[wp].defaults =
- context: window
- continuous: true
- enabled: true
- horizontal: false
- offset: 0
- triggerOnce: false
-
- # These methods are available on the $ object by using the method name as
- # the first argument to .waypoint. Ex: $.waypoints('refresh')
- jQMethods =
-
- # $.waypoints('refresh')
-
- # Forces a refresh on all contexts, recalculating all waypoint offsets.
- # This is done automatically on waypoint addition and during resize events,
- # but if a user does something to change the DOM, CSS, or in some way
- # change the layout of a page and its elements, they might need to call
- # this method manually.
- refresh: ->
- $.each contexts, (i, context) -> context.refresh()
-
- # $.waypoints('viewportHeight')
-
- # A utility method that returns the window height, but takes into account
- # inconsistencies that come with just using jQuery's .height() on iOS.
- viewportHeight: ->
- window.innerHeight ? $w.height()
-
- # $.waypoints(['aggregate'], [contextSelector])
-
- # Returns an object containing two HTMLNode arrays, one for each axis:
-
- # {
- # horizontal: [ HTMLNode... ]
- # vertical: [ HTMLNode... ]
- # }
-
- # This is the default method used when calling $.waypoints(). If
- # "contextSelector" is not supplied, it returns all waypoints. If
- # "contextSelector" is supplied it only returns waypoints for that context.
-
- # The array of waypoint elements is returned sorted by calculated offset,
- # the order in which they would be triggered on the page.
- aggregate: (contextSelector) ->
- collection = allWaypoints
- if contextSelector
- collection = contexts[$(contextSelector)[0][contextKey]]?.waypoints
- return [] unless collection
- waypoints =
- horizontal: []
- vertical: []
- $.each waypoints, (axis, arr) ->
- $.each collection[axis], (key, waypoint) ->
- arr.push waypoint
- arr.sort (a, b) -> a.offset - b.offset
- waypoints[axis] = $.map arr, (waypoint) -> waypoint.element
- waypoints[axis] = $.unique waypoints[axis]
- waypoints
-
- # $.waypoints('above', [string|HTMLNode|jQuery])
-
- # Returns all vertical waypoints that lie above the current scroll position
- # of the context specified by "contextSelector". If no "contextSelector"
- # is supplied, it defaults to the window.
- above: (contextSelector = window) ->
- jQMethods._filter contextSelector, 'vertical', (context, waypoint) ->
- waypoint.offset <= context.oldScroll.y
-
- # $.waypoints('below', [string|HTMLNode|jQuery])
-
- # Returns all vertical waypoints that lie below the current scroll position
- # of the context specified by "contextSelector". If no "contextSelector"
- # is supplied, it defaults to the window.
- below: (contextSelector = window) ->
- jQMethods._filter contextSelector, 'vertical', (context, waypoint) ->
- waypoint.offset > context.oldScroll.y
-
- # $.waypoints('left', [string|HTMLNode|jQuery])
-
- # Returns all horizontal waypoints left of the current scroll position
- # of the context specified by "contextSelector". If no "contextSelector"
- # is supplied, it defaults to the window.
- left: (contextSelector = window) ->
- jQMethods._filter contextSelector, 'horizontal', (context, waypoint) ->
- waypoint.offset <= context.oldScroll.x
-
- # $.waypoints('right', [string|HTMLNode|jQuery])
-
- # Returns all horizontal waypoints right of the current scroll position
- # of the context specified by "contextSelector". If no "contextSelector"
- # is supplied, it defaults to the window.
- right: (contextSelector = window) ->
- jQMethods._filter contextSelector, 'horizontal', (context, waypoint) ->
- waypoint.offset > context.oldScroll.x
-
- # $.waypoints('enable/disable/destroy')
-
- # These methods delegate to the enable/disable/destroy instance methods
- # for all waypoints.
- enable: -> jQMethods._invoke 'enable'
- disable: -> jQMethods._invoke 'disable'
- destroy: -> jQMethods._invoke 'destroy'
-
- # $.waypoints('extendFn', string, function)
-
- # Extends the $.fn.waypoint method object with a new method, "f". This
- # just lets other modules piggyback on the .waypoint namespace.
- extendFn: (methodName, f) ->
- methods[methodName] = f
-
- # Internal: Invokes "method" on all waypoints.
- _invoke: (method) ->
- waypoints = $.extend {}, allWaypoints.vertical, allWaypoints.horizontal
- $.each waypoints, (key, waypoint) ->
- waypoint[method]()
- true
-
- # Internal: Returns an array of all HTMLNodes for each waypoint that passes
- # the "test" function. Only waypoints within the "selector" context on the
- # "axis" axis are tested. As with .aggregate, the array is sorted by
- # calculated offset (trigger order).
- _filter: (selector, axis, test) ->
- context = contexts[$(selector)[0][contextKey]]
- return [] unless context
- waypoints = []
- $.each context.waypoints[axis], (i, waypoint) ->
- waypoints.push waypoint if test context, waypoint
- waypoints.sort (a, b) -> a.offset - b.offset
- $.map waypoints, (waypoint) -> waypoint.element
-
- # Hook up jQMethods to the $.waypoints namespace.
- $[wps] = (method, args...) ->
- if jQMethods[method]
- jQMethods[method].apply null, args
- else
- jQMethods.aggregate.call null, method
-
- # Plugin-wide settings:
-
- # - resizeThrottle: For performance reasons, the refresh performed during
- # resizes is throttled. This value is the rate-limit in milliseconds
- # between resize refreshes. For more information on throttling, check out
- # Ben Alman’s throttle / debounce plugin.
- # http://benalman.com/projects/jquery-throttle-debounce-plugin/
-
- # - scrollThrottle: For performance reasons, checking for any crossed
- # waypoints during a scroll event is throttled. This value is the
- # rate-limit in milliseconds between scroll checks. For more information
- # on throttling, check out Ben Alman’s throttle / debounce plugin.
- # http://benalman.com/projects/jquery-throttle-debounce-plugin/
-
- $[wps].settings =
- resizeThrottle: 100
- scrollThrottle: 30
-
- # Ensure a refresh on page load. Newly loaded images often shift layout.
- $w.load -> $[wps] 'refresh'
diff --git a/waypoints.js b/waypoints.js
deleted file mode 100644
index 2987f871..00000000
--- a/waypoints.js
+++ /dev/null
@@ -1,520 +0,0 @@
-// Generated by CoffeeScript 1.6.2
-/*
-jQuery Waypoints - v2.0.4
-Copyright (c) 2011-2014 Caleb Troughton
-Dual licensed under the MIT license and GPL license.
-https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
-*/
-
-
-(function() {
- var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
- __slice = [].slice;
-
- (function(root, factory) {
- if (typeof define === 'function' && define.amd) {
- return define('waypoints', ['jquery'], function($) {
- return factory($, root);
- });
- } else {
- return factory(root.jQuery, root);
- }
- })(this, function($, window) {
- var $w, Context, Waypoint, allWaypoints, contextCounter, contextKey, contexts, isTouch, jQMethods, methods, resizeEvent, scrollEvent, waypointCounter, waypointKey, wp, wps;
-
- $w = $(window);
- isTouch = __indexOf.call(window, 'ontouchstart') >= 0;
- allWaypoints = {
- horizontal: {},
- vertical: {}
- };
- contextCounter = 1;
- contexts = {};
- contextKey = 'waypoints-context-id';
- resizeEvent = 'resize.waypoints';
- scrollEvent = 'scroll.waypoints';
- waypointCounter = 1;
- waypointKey = 'waypoints-waypoint-ids';
- wp = 'waypoint';
- wps = 'waypoints';
- Context = (function() {
- function Context($element) {
- var _this = this;
-
- this.$element = $element;
- this.element = $element[0];
- this.didResize = false;
- this.didScroll = false;
- this.id = 'context' + contextCounter++;
- this.oldScroll = {
- x: $element.scrollLeft(),
- y: $element.scrollTop()
- };
- this.waypoints = {
- horizontal: {},
- vertical: {}
- };
- this.element[contextKey] = this.id;
- contexts[this.id] = this;
- $element.bind(scrollEvent, function() {
- var scrollHandler;
-
- if (!(_this.didScroll || isTouch)) {
- _this.didScroll = true;
- scrollHandler = function() {
- _this.doScroll();
- return _this.didScroll = false;
- };
- return window.setTimeout(scrollHandler, $[wps].settings.scrollThrottle);
- }
- });
- $element.bind(resizeEvent, function() {
- var resizeHandler;
-
- if (!_this.didResize) {
- _this.didResize = true;
- resizeHandler = function() {
- $[wps]('refresh');
- return _this.didResize = false;
- };
- return window.setTimeout(resizeHandler, $[wps].settings.resizeThrottle);
- }
- });
- }
-
- Context.prototype.doScroll = function() {
- var axes,
- _this = this;
-
- axes = {
- horizontal: {
- newScroll: this.$element.scrollLeft(),
- oldScroll: this.oldScroll.x,
- forward: 'right',
- backward: 'left'
- },
- vertical: {
- newScroll: this.$element.scrollTop(),
- oldScroll: this.oldScroll.y,
- forward: 'down',
- backward: 'up'
- }
- };
- if (isTouch && (!axes.vertical.oldScroll || !axes.vertical.newScroll)) {
- $[wps]('refresh');
- }
- $.each(axes, function(aKey, axis) {
- var direction, isForward, triggered;
-
- triggered = [];
- isForward = axis.newScroll > axis.oldScroll;
- direction = isForward ? axis.forward : axis.backward;
- $.each(_this.waypoints[aKey], function(wKey, waypoint) {
- var _ref, _ref1;
-
- if ((axis.oldScroll < (_ref = waypoint.offset) && _ref <= axis.newScroll)) {
- return triggered.push(waypoint);
- } else if ((axis.newScroll < (_ref1 = waypoint.offset) && _ref1 <= axis.oldScroll)) {
- return triggered.push(waypoint);
- }
- });
- triggered.sort(function(a, b) {
- return a.offset - b.offset;
- });
- if (!isForward) {
- triggered.reverse();
- }
- return $.each(triggered, function(i, waypoint) {
- if (waypoint.options.continuous || i === triggered.length - 1) {
- return waypoint.trigger([direction]);
- }
- });
- });
- return this.oldScroll = {
- x: axes.horizontal.newScroll,
- y: axes.vertical.newScroll
- };
- };
-
- Context.prototype.refresh = function() {
- var axes, cOffset, isWin,
- _this = this;
-
- isWin = $.isWindow(this.element);
- cOffset = this.$element.offset();
- this.doScroll();
- axes = {
- horizontal: {
- contextOffset: isWin ? 0 : cOffset.left,
- contextScroll: isWin ? 0 : this.oldScroll.x,
- contextDimension: this.$element.width(),
- oldScroll: this.oldScroll.x,
- forward: 'right',
- backward: 'left',
- offsetProp: 'left'
- },
- vertical: {
- contextOffset: isWin ? 0 : cOffset.top,
- contextScroll: isWin ? 0 : this.oldScroll.y,
- contextDimension: isWin ? $[wps]('viewportHeight') : this.$element.height(),
- oldScroll: this.oldScroll.y,
- forward: 'down',
- backward: 'up',
- offsetProp: 'top'
- }
- };
- return $.each(axes, function(aKey, axis) {
- return $.each(_this.waypoints[aKey], function(i, waypoint) {
- var adjustment, elementOffset, oldOffset, _ref, _ref1;
-
- adjustment = waypoint.options.offset;
- oldOffset = waypoint.offset;
- elementOffset = $.isWindow(waypoint.element) ? 0 : waypoint.$element.offset()[axis.offsetProp];
- if ($.isFunction(adjustment)) {
- adjustment = adjustment.apply(waypoint.element);
- } else if (typeof adjustment === 'string') {
- adjustment = parseFloat(adjustment);
- if (waypoint.options.offset.indexOf('%') > -1) {
- adjustment = Math.ceil(axis.contextDimension * adjustment / 100);
- }
- }
- waypoint.offset = elementOffset - axis.contextOffset + axis.contextScroll - adjustment;
- if ((waypoint.options.onlyOnScroll && (oldOffset != null)) || !waypoint.enabled) {
- return;
- }
- if (oldOffset !== null && (oldOffset < (_ref = axis.oldScroll) && _ref <= waypoint.offset)) {
- return waypoint.trigger([axis.backward]);
- } else if (oldOffset !== null && (oldOffset > (_ref1 = axis.oldScroll) && _ref1 >= waypoint.offset)) {
- return waypoint.trigger([axis.forward]);
- } else if (oldOffset === null && axis.oldScroll >= waypoint.offset) {
- return waypoint.trigger([axis.forward]);
- }
- });
- });
- };
-
- Context.prototype.checkEmpty = function() {
- if ($.isEmptyObject(this.waypoints.horizontal) && $.isEmptyObject(this.waypoints.vertical)) {
- this.$element.unbind([resizeEvent, scrollEvent].join(' '));
- return delete contexts[this.id];
- }
- };
-
- return Context;
-
- })();
- Waypoint = (function() {
- function Waypoint($element, context, options) {
- var idList, _ref;
-
- options = $.extend({}, $.fn[wp].defaults, options);
- if (options.offset === 'bottom-in-view') {
- options.offset = function() {
- var contextHeight;
-
- contextHeight = $[wps]('viewportHeight');
- if (!$.isWindow(context.element)) {
- contextHeight = context.$element.height();
- }
- return contextHeight - $(this).outerHeight();
- };
- }
- this.$element = $element;
- this.element = $element[0];
- this.axis = options.horizontal ? 'horizontal' : 'vertical';
- this.callback = options.handler;
- this.context = context;
- this.enabled = options.enabled;
- this.id = 'waypoints' + waypointCounter++;
- this.offset = null;
- this.options = options;
- context.waypoints[this.axis][this.id] = this;
- allWaypoints[this.axis][this.id] = this;
- idList = (_ref = this.element[waypointKey]) != null ? _ref : [];
- idList.push(this.id);
- this.element[waypointKey] = idList;
- }
-
- Waypoint.prototype.trigger = function(args) {
- if (!this.enabled) {
- return;
- }
- if (this.callback != null) {
- this.callback.apply(this.element, args);
- }
- if (this.options.triggerOnce) {
- return this.destroy();
- }
- };
-
- Waypoint.prototype.disable = function() {
- return this.enabled = false;
- };
-
- Waypoint.prototype.enable = function() {
- this.context.refresh();
- return this.enabled = true;
- };
-
- Waypoint.prototype.destroy = function() {
- delete allWaypoints[this.axis][this.id];
- delete this.context.waypoints[this.axis][this.id];
- return this.context.checkEmpty();
- };
-
- Waypoint.getWaypointsByElement = function(element) {
- var all, ids;
-
- ids = element[waypointKey];
- if (!ids) {
- return [];
- }
- all = $.extend({}, allWaypoints.horizontal, allWaypoints.vertical);
- return $.map(ids, function(id) {
- return all[id];
- });
- };
-
- return Waypoint;
-
- })();
- methods = {
- init: function(f, options) {
- var _ref;
-
- if (options == null) {
- options = {};
- }
- if ((_ref = options.handler) == null) {
- options.handler = f;
- }
- this.each(function() {
- var $this, context, contextElement, _ref1;
-
- $this = $(this);
- contextElement = (_ref1 = options.context) != null ? _ref1 : $.fn[wp].defaults.context;
- if (!$.isWindow(contextElement)) {
- contextElement = $this.closest(contextElement);
- }
- contextElement = $(contextElement);
- context = contexts[contextElement[0][contextKey]];
- if (!context) {
- context = new Context(contextElement);
- }
- return new Waypoint($this, context, options);
- });
- $[wps]('refresh');
- return this;
- },
- disable: function() {
- return methods._invoke.call(this, 'disable');
- },
- enable: function() {
- return methods._invoke.call(this, 'enable');
- },
- destroy: function() {
- return methods._invoke.call(this, 'destroy');
- },
- prev: function(axis, selector) {
- return methods._traverse.call(this, axis, selector, function(stack, index, waypoints) {
- if (index > 0) {
- return stack.push(waypoints[index - 1]);
- }
- });
- },
- next: function(axis, selector) {
- return methods._traverse.call(this, axis, selector, function(stack, index, waypoints) {
- if (index < waypoints.length - 1) {
- return stack.push(waypoints[index + 1]);
- }
- });
- },
- _traverse: function(axis, selector, push) {
- var stack, waypoints;
-
- if (axis == null) {
- axis = 'vertical';
- }
- if (selector == null) {
- selector = window;
- }
- waypoints = jQMethods.aggregate(selector);
- stack = [];
- this.each(function() {
- var index;
-
- index = $.inArray(this, waypoints[axis]);
- return push(stack, index, waypoints[axis]);
- });
- return this.pushStack(stack);
- },
- _invoke: function(method) {
- this.each(function() {
- var waypoints;
-
- waypoints = Waypoint.getWaypointsByElement(this);
- return $.each(waypoints, function(i, waypoint) {
- waypoint[method]();
- return true;
- });
- });
- return this;
- }
- };
- $.fn[wp] = function() {
- var args, method;
-
- method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
- if (methods[method]) {
- return methods[method].apply(this, args);
- } else if ($.isFunction(method)) {
- return methods.init.apply(this, arguments);
- } else if ($.isPlainObject(method)) {
- return methods.init.apply(this, [null, method]);
- } else if (!method) {
- return $.error("jQuery Waypoints needs a callback function or handler option.");
- } else {
- return $.error("The " + method + " method does not exist in jQuery Waypoints.");
- }
- };
- $.fn[wp].defaults = {
- context: window,
- continuous: true,
- enabled: true,
- horizontal: false,
- offset: 0,
- triggerOnce: false
- };
- jQMethods = {
- refresh: function() {
- return $.each(contexts, function(i, context) {
- return context.refresh();
- });
- },
- viewportHeight: function() {
- var _ref;
-
- return (_ref = window.innerHeight) != null ? _ref : $w.height();
- },
- aggregate: function(contextSelector) {
- var collection, waypoints, _ref;
-
- collection = allWaypoints;
- if (contextSelector) {
- collection = (_ref = contexts[$(contextSelector)[0][contextKey]]) != null ? _ref.waypoints : void 0;
- }
- if (!collection) {
- return [];
- }
- waypoints = {
- horizontal: [],
- vertical: []
- };
- $.each(waypoints, function(axis, arr) {
- $.each(collection[axis], function(key, waypoint) {
- return arr.push(waypoint);
- });
- arr.sort(function(a, b) {
- return a.offset - b.offset;
- });
- waypoints[axis] = $.map(arr, function(waypoint) {
- return waypoint.element;
- });
- return waypoints[axis] = $.unique(waypoints[axis]);
- });
- return waypoints;
- },
- above: function(contextSelector) {
- if (contextSelector == null) {
- contextSelector = window;
- }
- return jQMethods._filter(contextSelector, 'vertical', function(context, waypoint) {
- return waypoint.offset <= context.oldScroll.y;
- });
- },
- below: function(contextSelector) {
- if (contextSelector == null) {
- contextSelector = window;
- }
- return jQMethods._filter(contextSelector, 'vertical', function(context, waypoint) {
- return waypoint.offset > context.oldScroll.y;
- });
- },
- left: function(contextSelector) {
- if (contextSelector == null) {
- contextSelector = window;
- }
- return jQMethods._filter(contextSelector, 'horizontal', function(context, waypoint) {
- return waypoint.offset <= context.oldScroll.x;
- });
- },
- right: function(contextSelector) {
- if (contextSelector == null) {
- contextSelector = window;
- }
- return jQMethods._filter(contextSelector, 'horizontal', function(context, waypoint) {
- return waypoint.offset > context.oldScroll.x;
- });
- },
- enable: function() {
- return jQMethods._invoke('enable');
- },
- disable: function() {
- return jQMethods._invoke('disable');
- },
- destroy: function() {
- return jQMethods._invoke('destroy');
- },
- extendFn: function(methodName, f) {
- return methods[methodName] = f;
- },
- _invoke: function(method) {
- var waypoints;
-
- waypoints = $.extend({}, allWaypoints.vertical, allWaypoints.horizontal);
- return $.each(waypoints, function(key, waypoint) {
- waypoint[method]();
- return true;
- });
- },
- _filter: function(selector, axis, test) {
- var context, waypoints;
-
- context = contexts[$(selector)[0][contextKey]];
- if (!context) {
- return [];
- }
- waypoints = [];
- $.each(context.waypoints[axis], function(i, waypoint) {
- if (test(context, waypoint)) {
- return waypoints.push(waypoint);
- }
- });
- waypoints.sort(function(a, b) {
- return a.offset - b.offset;
- });
- return $.map(waypoints, function(waypoint) {
- return waypoint.element;
- });
- }
- };
- $[wps] = function() {
- var args, method;
-
- method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
- if (jQMethods[method]) {
- return jQMethods[method].apply(null, args);
- } else {
- return jQMethods.aggregate.call(null, method);
- }
- };
- $[wps].settings = {
- resizeThrottle: 100,
- scrollThrottle: 30
- };
- return $w.load(function() {
- return $[wps]('refresh');
- });
- });
-
-}).call(this);
diff --git a/waypoints.min.js b/waypoints.min.js
deleted file mode 100644
index 8281ad7f..00000000
--- a/waypoints.min.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Generated by CoffeeScript 1.6.2
-/*
-jQuery Waypoints - v2.0.4
-Copyright (c) 2011-2014 Caleb Troughton
-Dual licensed under the MIT license and GPL license.
-https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
-*/
-(function(){var t=[].indexOf||function(t){for(var e=0,n=this.length;e
=0;s={horizontal:{},vertical:{}};f=1;c={};u="waypoints-context-id";p="resize.waypoints";y="scroll.waypoints";v=1;w="waypoints-waypoint-ids";g="waypoint";m="waypoints";o=function(){function t(t){var e=this;this.$element=t;this.element=t[0];this.didResize=false;this.didScroll=false;this.id="context"+f++;this.oldScroll={x:t.scrollLeft(),y:t.scrollTop()};this.waypoints={horizontal:{},vertical:{}};this.element[u]=this.id;c[this.id]=this;t.bind(y,function(){var t;if(!(e.didScroll||a)){e.didScroll=true;t=function(){e.doScroll();return e.didScroll=false};return r.setTimeout(t,n[m].settings.scrollThrottle)}});t.bind(p,function(){var t;if(!e.didResize){e.didResize=true;t=function(){n[m]("refresh");return e.didResize=false};return r.setTimeout(t,n[m].settings.resizeThrottle)}})}t.prototype.doScroll=function(){var t,e=this;t={horizontal:{newScroll:this.$element.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.$element.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};if(a&&(!t.vertical.oldScroll||!t.vertical.newScroll)){n[m]("refresh")}n.each(t,function(t,r){var i,o,l;l=[];o=r.newScroll>r.oldScroll;i=o?r.forward:r.backward;n.each(e.waypoints[t],function(t,e){var n,i;if(r.oldScroll<(n=e.offset)&&n<=r.newScroll){return l.push(e)}else if(r.newScroll<(i=e.offset)&&i<=r.oldScroll){return l.push(e)}});l.sort(function(t,e){return t.offset-e.offset});if(!o){l.reverse()}return n.each(l,function(t,e){if(e.options.continuous||t===l.length-1){return e.trigger([i])}})});return this.oldScroll={x:t.horizontal.newScroll,y:t.vertical.newScroll}};t.prototype.refresh=function(){var t,e,r,i=this;r=n.isWindow(this.element);e=this.$element.offset();this.doScroll();t={horizontal:{contextOffset:r?0:e.left,contextScroll:r?0:this.oldScroll.x,contextDimension:this.$element.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:r?0:e.top,contextScroll:r?0:this.oldScroll.y,contextDimension:r?n[m]("viewportHeight"):this.$element.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};return n.each(t,function(t,e){return n.each(i.waypoints[t],function(t,r){var i,o,l,s,f;i=r.options.offset;l=r.offset;o=n.isWindow(r.element)?0:r.$element.offset()[e.offsetProp];if(n.isFunction(i)){i=i.apply(r.element)}else if(typeof i==="string"){i=parseFloat(i);if(r.options.offset.indexOf("%")>-1){i=Math.ceil(e.contextDimension*i/100)}}r.offset=o-e.contextOffset+e.contextScroll-i;if(r.options.onlyOnScroll&&l!=null||!r.enabled){return}if(l!==null&&l<(s=e.oldScroll)&&s<=r.offset){return r.trigger([e.backward])}else if(l!==null&&l>(f=e.oldScroll)&&f>=r.offset){return r.trigger([e.forward])}else if(l===null&&e.oldScroll>=r.offset){return r.trigger([e.forward])}})})};t.prototype.checkEmpty=function(){if(n.isEmptyObject(this.waypoints.horizontal)&&n.isEmptyObject(this.waypoints.vertical)){this.$element.unbind([p,y].join(" "));return delete c[this.id]}};return t}();l=function(){function t(t,e,r){var i,o;r=n.extend({},n.fn[g].defaults,r);if(r.offset==="bottom-in-view"){r.offset=function(){var t;t=n[m]("viewportHeight");if(!n.isWindow(e.element)){t=e.$element.height()}return t-n(this).outerHeight()}}this.$element=t;this.element=t[0];this.axis=r.horizontal?"horizontal":"vertical";this.callback=r.handler;this.context=e;this.enabled=r.enabled;this.id="waypoints"+v++;this.offset=null;this.options=r;e.waypoints[this.axis][this.id]=this;s[this.axis][this.id]=this;i=(o=this.element[w])!=null?o:[];i.push(this.id);this.element[w]=i}t.prototype.trigger=function(t){if(!this.enabled){return}if(this.callback!=null){this.callback.apply(this.element,t)}if(this.options.triggerOnce){return this.destroy()}};t.prototype.disable=function(){return this.enabled=false};t.prototype.enable=function(){this.context.refresh();return this.enabled=true};t.prototype.destroy=function(){delete s[this.axis][this.id];delete this.context.waypoints[this.axis][this.id];return this.context.checkEmpty()};t.getWaypointsByElement=function(t){var e,r;r=t[w];if(!r){return[]}e=n.extend({},s.horizontal,s.vertical);return n.map(r,function(t){return e[t]})};return t}();d={init:function(t,e){var r;if(e==null){e={}}if((r=e.handler)==null){e.handler=t}this.each(function(){var t,r,i,s;t=n(this);i=(s=e.context)!=null?s:n.fn[g].defaults.context;if(!n.isWindow(i)){i=t.closest(i)}i=n(i);r=c[i[0][u]];if(!r){r=new o(i)}return new l(t,r,e)});n[m]("refresh");return this},disable:function(){return d._invoke.call(this,"disable")},enable:function(){return d._invoke.call(this,"enable")},destroy:function(){return d._invoke.call(this,"destroy")},prev:function(t,e){return d._traverse.call(this,t,e,function(t,e,n){if(e>0){return t.push(n[e-1])}})},next:function(t,e){return d._traverse.call(this,t,e,function(t,e,n){if(e<=t.oldScroll.y})},below:function(t){if(t==null){t=r}return h._filter(t,"vertical",function(t,e){return e.offset>t.oldScroll.y})},left:function(t){if(t==null){t=r}return h._filter(t,"horizontal",function(t,e){return e.offset<=t.oldScroll.x})},right:function(t){if(t==null){t=r}return h._filter(t,"horizontal",function(t,e){return e.offset>t.oldScroll.x})},enable:function(){return h._invoke("enable")},disable:function(){return h._invoke("disable")},destroy:function(){return h._invoke("destroy")},extendFn:function(t,e){return d[t]=e},_invoke:function(t){var e;e=n.extend({},s.vertical,s.horizontal);return n.each(e,function(e,n){n[t]();return true})},_filter:function(t,e,r){var i,o;i=c[n(t)[0][u]];if(!i){return[]}o=[];n.each(i.waypoints[e],function(t,e){if(r(i,e)){return o.push(e)}});o.sort(function(t,e){return t.offset-e.offset});return n.map(o,function(t){return t.element})}};n[m]=function(){var t,n;n=arguments[0],t=2<=arguments.length?e.call(arguments,1):[];if(h[n]){return h[n].apply(null,t)}else{return h.aggregate.call(null,n)}};n[m].settings={resizeThrottle:100,scrollThrottle:30};return i.load(function(){return n[m]("refresh")})})}).call(this);
\ No newline at end of file