Skip to content

Instantly share code, notes, and snippets.

@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);
<meta name="viewport" content="width=1280, initial-scale=1">
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(){
(function($,window, undefined){
var pluginName = "stickyScroll",
defaults = {
"class":"scrolled-off"
}
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
(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();
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{
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");
Vagrant::Config.run do |config|
config.vm.box = "base"
config.vm.network(:hostonly, "33.33.33.10")
config.vm.network(:bridged)
config.vm.forward_port(80, 4567)
en
@johnkpaul
johnkpaul / gist:2361303
Created April 11, 2012 18:44
gruntjs Mocha task
/*
* grunt
* https://github.com/cowboy/grunt
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Copyright (c) 2012 John K. Paul @johnkpaul
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
@johnkpaul
johnkpaul / jsfiddle.changedefault.user.js
Created April 13, 2012 17:14
Change the default Javascript library on jsFiddle to jQuery
// ==UserScript==
// @match http://jsfiddle.net/*
// ==/UserScript==
// @author: John K. Paul @johnkpaul
// @license: http://www.opensource.org/licenses/MIT
// http://johnkpaul.tumblr.com/post/21030300518/changing-jsfiddles-default-library-to-jquery
(function(){
var script = document.createElement('script');