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 / Backbone.Util.js
Last active May 24, 2016 19:09
Backbone.js & Underscore.js Utlities and Extensions
Backbone.Model.prototype.templateData = function(){
var that = this;
var data = this.toJSON();
// for each attribute, look for models and collections to convert
_.each(this.attributes, function(attr, key){
// is this attribute a Model?
if( attr instanceof Backbone.Model && attr.displayVal )
@kjantzer
kjantzer / Timer.js
Created February 20, 2014 16:37
Timer.js - create a ticking timer like a digital clock. Code is still a little ad-hoc, but it is fully functional.
/*
Timer
@author Kevin Jantzer
@since 2013-11-27
*/
var Timer = function(opts){
@kjantzer
kjantzer / gist:8482542
Created January 17, 2014 22:00
Select / Highlight text in a give element. Nice for quickly copying for pasting later. http://stackoverflow.com/a/1173319/484780
// http://stackoverflow.com/a/1173319/484780
highlightText = function(el){
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(el);
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(el);
window.getSelection().addRange(range);
@kjantzer
kjantzer / flexbox-mixins.less
Last active December 31, 2015 06:29
{LESS} CSS Flexbox Mixins — this is not a complete set of mixins, and I'm not sure if I've got all the correct prefixes. I will update as I learn more.
// http://css-tricks.com/snippets/css/a-guide-to-flexbox/
// container
.display-flex() {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
@kjantzer
kjantzer / backbone.collection.saveToCSV.js
Last active May 14, 2017 10:21
Backbone.Collection.saveToCSV() — adds ability to save all of the collections models as a CSV file. NOTE: only tested on Chrome; may not work on all browsers, but would work well for packaged Chrome apps.
/*
Save To CSV 0.0.2
@author Kevin Jantzer, Blackstone Audio
@since 2015-01-16
intial code from http://stackoverflow.com/a/14966131/484780
TODO
- needs improved (objects as values)
@kjantzer
kjantzer / README.md
Last active April 17, 2018 13:05
Backbone.js & Underscore.js Natural Sorting

Backbone.js & Underscore.js Natural Sorting Algorithm

Backbone is great but I continually found the default sorting method limited due to the following:

Disc 1, Disc 2, … Disc 10 would become Disc 1, Disc 10, Disc 2

With the help of Jim Palmer's naturalSort.js, I was able to integrate natrual sorting into Backbone.Collection.

Backbone collections are automatically sorted and now, by simply adding sortType:"natural", your collections can be sorted naturally.

@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',
/*
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 / 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;
@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($) {