Skip to content

Instantly share code, notes, and snippets.

@pjschreifels
pjschreifels / Truncate Breadcrumb
Last active December 11, 2015 16:28
#breadcrumb #coffeescript #truncate #ellipsis #bootstrap Truncate the last node in a breadcrumb and add an ellipsis. I use this with Twitter Bootstrap. Requires: ellipsis.js
# Fix the Breadcrumb display
$(document).ready ->
$("ul.breadcrumb").children("li:not(:last)").append "<span class='divider'>&nbsp;/&nbsp;</span>"
$("ul.breadcrumb").children("li:last").addClass "active"
# Add ellipsis to last item if it's too long
lessWidth = 0
liWidth = $("ul.breadcrumb").children("li:last").width()
$("ul.breadcrumb").children("li:not(:last)").each ->
lessWidth += $(this).outerWidth()
@pjschreifels
pjschreifels / google.analytics.js.coffee
Created February 4, 2013 06:11 — forked from rezwyi/google.analytics.js.coffee
#analytics #coffeescript Google Analytics code in coffeescript for rails projects.
# See http://stackoverflow.com/questions/4214731/coffeescript-global-variables
root = exports ? this
root._gaq = [['_setAccount', 'UA-xxxxxxxx-y'], ['_trackPageview']]
insertGAScript = ->
ga = document.createElement 'script'
ga.type = 'text/javascript'
ga.async = true
proto = document.location.protocol
@pjschreifels
pjschreifels / js-orm.js
Last active December 14, 2015 13:38
#javascript #ORM manipulates a browser's Local Storage with create, update, increment, decrement and delete. Also provides functions for getting data with get, get all, find value, and find. The script treats the Local Storage like a database (as much as possible), so when manipulating the data, the function requires: table - a string that refer…
function createStore(table, row){ // Inserts a single row of data into a table
var rows = JSON.parse(localStorage.getItem(table));
if (rows == null) {
rows = {};
var id = 1;
} else {
var id = $.map(Object.keys(rows), function(val, i){return parseInt(val);}).reduce(function(a,b){return Math.max(a,b);})+1;
}
row.id = id;
@pjschreifels
pjschreifels / buttons.coffee
Created February 2, 2013 21:01 — forked from mathias/buttons.coffee
#social-buttons #coffeescript Facebook and Twitter social media buttons using coffeescript for rails projects.
((d, s, id) ->
js = undefined
fjs = d.getElementsByTagName(s)[0]
return if d.getElementById(id)
js = d.createElement(s)
js.id = id
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"
fjs.parentNode.insertBefore js, fjs
) document, "script", "facebook-jssdk"
<template>
<button type="button" class="btn btn-secondary" click.trigger="show()">Show</button>
</template>
@pjschreifels
pjschreifels / aurelia.json
Created August 23, 2016 22:29
Bootstrapv4-alpha.3 — Tether and RequireJS
"dependencies": [
...
"jquery",
{
"name": "tether",
"path": "../node_modules/tether/dist",
"main": "js/tether",
"resources": [
"css/tether.css"
import {customAttribute, autoinject} from 'aurelia-framework';
import { PaymentPlan } from './payment-plan';
import $ from 'jquery';
import 'bootstrap-slider';
@customAttribute('installment-slider')
@autoinject
export class InstallmentSlider {
mySlider: any;
@pjschreifels
pjschreifels / app.html
Last active October 23, 2016 17:36 — forked from jdanyow/app.html
Aurelia Validation Demo with Radio Button
<template>
<require from="./registration-form"></require>
<registration-form></registration-form>
</template>
@pjschreifels
pjschreifels / app.html
Last active October 24, 2016 19:13
Aurelia update form values from custom component.
<template>
<require from='./records'></require>
<require from='./record-form'></require>
<div class="container-fluid">
<div class="row mt-1">
<div class="col-xs-12">
<p class="lead text-muted">${heading}</p>
</div>
</div>
@pjschreifels
pjschreifels / app.html
Last active October 25, 2016 05:36
Aurelia form validation of properties from an injected view-model.
<template>
<require from="./registration-form"></require>
<registration-form></registration-form>
</template>