Skip to content

Instantly share code, notes, and snippets.

Avatar

Cory LaViska claviska

View GitHub Profile
@claviska
claviska / LICENSE.md
Last active Feb 7, 2022
A Reactive Controller for detecting "click presses."
View LICENSE.md

Copyright (c) 2020 A Beautiful Site, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

@claviska
claviska / form-submit-controller.ts
Last active Feb 15, 2022
A Reactive Controller for Custom Element Form Controls
View form-submit-controller.ts
//
// This is a Reactive Controller (https://lit.dev/docs/composition/controllers/) that allows custom elements to submit
// with standard <form> elements.
//
// The formdata event didn't land in Safari until 15.1, which is still somewhat recent. You can use this lightweight
// polyfill to make it work: https://gist.github.com/WickyNilliams/eb6a44075356ee504dd9491c5a3ab0be
//
// If your custom element shares the same API as HTMLInputElement for name/value/disabled/reportValidity, this is all
// you need to do:
//
@claviska
claviska / vertically-centered-bootstrap-modals.js
Last active May 15, 2020
Vertically Centered Bootstrap Modals
View vertically-centered-bootstrap-modals.js
/**
* Vertically center Bootstrap 3 modals so they aren't always stuck at the top
*/
$(function() {
function reposition() {
var modal = $(this),
dialog = modal.find('.modal-dialog');
@claviska
claviska / jquery.offscreen.js
Created Oct 30, 2013
jQuery offscreen plugin
View jquery.offscreen.js
/*
* jQuery offscreen plugin
*
* Filters that detect when an element is partially or completely outside
* of the viewport.
*
* Usage:
*
* $('#element').is(':off-bottom')
*
@claviska
claviska / pretty-buttons.less
Last active Feb 24, 2022
A Less mixin' for pretty buttons with Bootstrap 3
View pretty-buttons.less
.pretty-buttons(@color, @background, @text-shadow: none) {
color: @color;
#gradient > .vertical(lighten(@background, 5%), darken(@background, 5%), 0%, 100%);
border-color: darken(@background, 10%);
border-bottom-color: darken(@background, 20%);
text-shadow: @text-shadow;
.box-shadow(inset 0 1px 0 rgba(255, 255, 255, .1));
&:hover,
@claviska
claviska / parseTime.js
Last active Feb 10, 2017
Parse time strings input by humans
View parseTime.js
function parseTime(time, format, step) {
var hour, minute, stepMinute,
defaultFormat = 'g:ia',
pm = time.match(/p/i) !== null,
num = time.replace(/[^0-9]/g, '');
// Parse for hour and minute
switch(num.length) {
case 4:
@claviska
claviska / rest.class.php
Created Aug 30, 2012
Barebones PHP-based REST client
View rest.class.php
<?php
/*
Usage:
$rest = new REST($config);
$result = $rest->get('http://example.com/method, array(
'name' => 'value',
...
));