Skip to content

Instantly share code, notes, and snippets.

View kjantzer's full-sized avatar
👨‍💻
Likely writing JavaScript

Kevin Jantzer kjantzer

👨‍💻
Likely writing JavaScript
View GitHub Profile
@kjantzer
kjantzer / gist:4303652
Last active December 9, 2015 17:28
Misc Backbone.js improvements
var _super = function(funcName){ return this.constructor.__super__[funcName].apply(this, _.rest(arguments)); }
Backbone.Model.prototype._super = _super
Backbone.Collection.prototype._super = _super
Backbone.View.prototype._super = _super
Backbone.Model.prototype.getSortString = function(str){
// strip single and double quotes and titles starting with "The " and "A "
return str ? str.replace(/^The |^A |"|“|”|'|‘|’/g, '') : str;
@kjantzer
kjantzer / Mobile Optimization.md
Last active December 10, 2015 15:18
Mobile optimization

Mobile Optimization

Some tags for making sites mobile friendly!

<meta name="apple-mobile-web-app-title" content="Site Title">
<meta http-equiv="cleartype" content="on" />
<meta name="MobileOptimized" content="width" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<meta name="HandheldFriendly" content="true" />
@kjantzer
kjantzer / post-receive.sample
Created January 10, 2013 02:39
GIT post-receive hook for updating live site on code push (and submodules)
#!/bin/sh
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".
# Unset GIT_DIR or the universe will implode
unset GIT_DIR
@kjantzer
kjantzer / Plural.js
Last active May 1, 2019 11:47
JavaScript: Plural - create a plural or singluar sentence based on a number
/*
Plural - create singlular or plural sentence based on number given (all numbers but 1 return plural sentence)
var str = "Do you want to delete this? There {are|is} [num] book{s} attached."
var num = 2 // or 0, 3, 4, ...
"Do you want to delete this? There are 2 books attached."
var num = 1
"Do you want to delete this? There is 1 book attached."
@kjantzer
kjantzer / isMac.js
Last active December 14, 2015 19:19
Underscore extensions for testing Mac vs PC/Windows
isMac: function(){
return navigator.userAgent.indexOf('Mac OS X') != -1
}
isWin: function(){ return !_.isMac(); }
isPC: function(){ return _.isWin(); }
@kjantzer
kjantzer / gutter-scroll-action.js
Created March 26, 2013 16:39
Gutter Scroll Action - "pull-to-refresh" functionality for the web! Built on Backbone.js
GutterView = Backbone.View.extend({
/*
Gutter Scroll action
@author Kevin Jantzer
@since 2013-03-19
call setup in init
this.gutterSetup()
and add event
@kjantzer
kjantzer / sticky-divider.js
Last active December 15, 2015 14:19
Sticky Divider - make dividers stick to the top of the screen/element while scrolling. With multiple dividers, they will push each other out of place just like on iOS
/*
Sticky Divider
@author Kevin Jantzer
@since 2013-03-29
*/
(function($) {
@kjantzer
kjantzer / kjc-reusable-styles.less
Last active December 16, 2015 12:39
General reusable styles — written with less and elements.less
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.clear {
border: none;
float: none;
/*
Convert numbers to words
copyright 25th July 2006, by Stephen Chapman http://javascript.about.com
permission to use this Javascript on your web page is granted
provided that all of the code (including this copyright notice) is
used exactly as shown (you can change the numbering system if you wish)
*/
var numberToWords = function(s){
@kjantzer
kjantzer / CopyTextView.js
Last active December 20, 2015 16:18
Copy Text View; a Backbone.js view. When a user clicks on this view the content inside is automatically selected, ready for the user to press ctrl+c
var CopyTextView = Backbone.View.extend({
className: 'padded clearfix',
attributes: {
'contenteditable':'true'
},
events: {
'keydown': 'stopKey',