Skip to content

Instantly share code, notes, and snippets.

module("sticky scroll integration tests",{
"setup":function(){
this.$el = $("<div class='test-scroll'></div>");
this.$el.appendTo(document.body);
},
"expandDocumentBody":function($el){
$(document.body).css("height","10000px");
},
"shrinkDocumentBody":function($el){
$(document.body).css("height","auto");
Plugin.prototype.init = function(){
var self = this,
offset = $(this.element).offset(); //need to inject test data here
$(window).scroll(function(event){
//event.target is usually the object that jQuery was called on
//I could have used this or $(window), but neither is testable
if(elementIsOutsideViewport(event.target, offset)){
self.elementScrolledOff();
}
else{
(function($,window, undefined){
module("sticky scroll unit tests",{
"setup":function(){
this.$el.get(0).getBoundingClientRect = function(){
return {left:100,top:100};
}
},
"setupSpies":function($el){
var plugin = this.getStickyScrollPlugin($el);
plugin.elementScrolledOff = sinon.spy();
(function($,window, undefined){
var pluginName = "stickyScroll",
defaults = {
"class":"scrolled-off"
}
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
module("sticky scroll unit tests",{
"setup":function(){
this.$el = $("<div></div>");
},
"getStickyScrollPlugin":function($el){
return $.data($el.get(0), "plugin_stickyScroll");
}
});
test("sticky scroll default class is scrolled-off", function(){
<meta name="viewport" content="width=1280, initial-scale=1">
@johnkpaul
johnkpaul / gist:1935555
Created February 28, 2012 22:02 — forked from anonymous/gist:1935517
a guest on Feb 28th, 2012 - pastebin.com/1YXe6Nvd
//for (var i = 0; i < mapPoints.length; i++){
// for (var j = i + 1; j < mapPoints.length; j++){
// var p1 = mapPoints[i];
// var p2 = mapPoints[j];
// if (getDistance(p1, p2) < 0.1){ // If distance between points is greater than .1 km
// var midpoint = getMidpoint(p1, p2);
//
// mapPoints.push(midpoint);
// mapPoints.splice(i, 1);
// mapPoints.splice(j, 1);
@johnkpaul
johnkpaul / getComputedStylePropertyValue.js
Created February 10, 2012 16:42
Shim for getComputedStyle in old IEs
(function(window, undefined){
window.getComputedStylePropertyValue = function(el,cssProperty){
if(!window.getComputedStyle){
if(document.defaultView && document.defaultView.getComputedStyle){
return document.defaultView.getComputedStyle.getPropertyValue(cssProperty);
}
else{
var camelCasedCssProperty = getCamelCasedCssProperty(cssProperty);
if(el.currentStyle){
return el.currentStyle(camelCasedCssProperty);
@johnkpaul
johnkpaul / getComputedStyleCssText.js
Created February 6, 2012 20:58
Approximate cssText on a CSSStyleDeclaration object in Firefox
function getComputedStyleCssText(element){
var cssObject = window.getComputedStyle(element),
prop,
cssText,
cssAccumulator = [];
if(cssObject.cssText != ""){
return cssObject.cssText;
}
.original-background{
background:url(http://img850.imageshack.us/img850/2400/rowofstars.gif) repeat;
}
.diagonal-background:before{
content:"";
background:url(http://img850.imageshack.us/img850/2400/rowofstars.gif) repeat;
width:200%;
height:200%;
position:absolute;