Skip to content

Instantly share code, notes, and snippets.

View tillsanders's full-sized avatar
💪
Working on something better.

Till Sanders tillsanders

💪
Working on something better.
View GitHub Profile
@tillsanders
tillsanders / max-height.js
Created June 11, 2015 12:38
Get max height of a jquery collection
// Found at Stackoverflow: http://stackoverflow.com/questions/6060992/element-with-the-max-height-from-a-set-of-elements
// Credits to http://stackoverflow.com/users/139010/matt-ball
var maxHeight = Math.max.apply(null, $("li").map(function ()
{
return $(this).height();
}).get());
@tillsanders
tillsanders / main.js
Created March 29, 2015 21:57
Update active nav item while scrolling
$(window).scroll(function() {
var current = $('main section').map(function(){
if($(this).offset().top < $(window).scrollTop() + $(window).height() / 2) {
return $(this);
}
});
current = current.last().get(0);
$('nav.main a').removeClass('active');
$('a[href=#' + current.attr('id') + ']').addClass('active');
});
@tillsanders
tillsanders / slideshow-notes.markdown
Last active August 29, 2015 14:13
Very simple slideshow plugin for jquery

Notes

  • div.controls is vital for autoplay functionality
@tillsanders
tillsanders / center-position.jquery.js
Created January 12, 2015 08:22
Center position with jQuery
$.fn.centerPosition = function() {
"use strict";
var $targets = $(this);
if (!$targets.length) {
$targets = $('.centered:visible');
}
$targets.each(function() {
@tillsanders
tillsanders / jquery.adjustat.js
Last active August 29, 2015 14:13
Execute javascript layout adjustments based on breakpoints only once
(function ($) {
$.fn.adjustAt = function(options) {
var elements = $(this);
// Default settings merged with received options
var settings = $.extend({
width: 0,
above: function(element) {},
below: function(element) {},
aboveRepeat: function(element) {},
belowRepeat: function(element) {}
@tillsanders
tillsanders / generate-mobile-first-sass-stylesheets-for-ie.markdown
Last active August 29, 2015 14:11
Generate mobile-first SASS-Stylesheets for IE

Generate mobile-first SASS-Stylesheets for IE

I copied this code from chriseppstein, because it is great :)

Okay, here we go: Put this somewhere in your SASS-files. E.g. _vars.scss oder _helpers.scss, etc.

$media-queries: true !default;
$media-query-free-breakpoint: 1300px;
@mixin respond-to($min-width, $max-width: false) {
@tillsanders
tillsanders / main.js
Created October 14, 2014 15:11
Obfuscating Mailtos in Laravel 4
$(document).ready(function() {
// Hidden Mailtos
$('span.inyourfacespambot').click(function() {
var str = $(this).text();
var re = /^(.+?@).*@(.*)$/gmi;
var m;
while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
@tillsanders
tillsanders / resize-images-sips
Last active August 29, 2015 14:07
Quickly replacing (!) images with proportionally resized versions on OS X Terminal
sips -Z 640 *.jpg
@tillsanders
tillsanders / intro.markdown
Last active June 24, 2021 20:17
Laravel: drag-and-drop repositioning with auto-save of DB entries

Laravel: drag-and-drop repositioning with auto-save of DB entries

Use case: Database entries are represented in a table. By grabbing and moving a row up or down the table, you can change the entries' order/position. The changes are submitted automatically via ajax.

  • Uses jQueryUI (custom download: sortable is needed)
  • newly created elements are added to the top (see route /jobs/create)
@tillsanders
tillsanders / goto-links-with-jquery.js
Last active August 29, 2015 14:04
Automated and animated goto links with jQuery