Skip to content

Instantly share code, notes, and snippets.

@jordanneenan
jordanneenan / custom-checkbox.js
Created February 22, 2017 02:31
Custom checkbox with javascript
$(document).ready(function(){
//hide the checkboxes
$('.ginput_container_checkbox li input').hide();
//inject the custom checkbox code
$('.ginput_container_checkbox li input').before('<div class="custom_checkbox"><div class="check_inner"></div></div>');
//control the new checkbox on click
$('.ginput_container_checkbox li').on('click', '.custom_checkbox', function(){
@jordanneenan
jordanneenan / v-align.js
Created March 2, 2016 05:28
Vertically align element to the middle of its parent
//vertically align element to the middle of its parent
function vAlign(){
if(jQuery('.v-align').length){
var jQueryvaChild = jQuery('.v-align');
jQueryvaChild.each(function(){
var vaChildHeight = jQuery(this).height();
var vaParentHeight = jQuery(this).parent().height();
var topOffset = (vaParentHeight - vaChildHeight) / 2;
jQuery(this).css('paddingTop', topOffset).addClass('show');
});
@jordanneenan
jordanneenan / fieldText.js
Created August 27, 2015 23:56
Control default text in a field
//Field text - remove on focus, replace on blur
function fieldText(){
var $fieldText = jQuery('.js-text');
$fieldText.focus(function(){
var fText = jQuery(this).data("fieldtext");
var fVal = jQuery(this).val();
if(fVal === fText){
jQuery(this).val("");
}
})
@jordanneenan
jordanneenan / truncateString.php
Created July 26, 2015 22:17
Truncate a string...nicely.
//truncate a string...nicely
function stringTruncate($string, $stringLength){
if (strlen($string) > $stringLength) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $stringLength));
return $string . '...';
}else{
return $string;
}
@jordanneenan
jordanneenan / svgConvert.js
Created July 23, 2015 11:19
Replace all SVGs images with inline SVGs
//Replace all SVG images with inline SVG
$('img.svg').each(function(){
var $img = $(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
$.get(imgURL, function(data) {
// Get the SVG tag, ignore the rest
var $svg = $(data).find('svg');
@jordanneenan
jordanneenan / resizeTimeout.js
Last active August 29, 2015 14:25
Call function after timeout on page resize
var rtime;
var timeout = false;
var delta = 200;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
@jordanneenan
jordanneenan / disableLink.js
Last active March 2, 2016 05:23
Disable link using the class 'disable-link'.
@jordanneenan
jordanneenan / matchHeight.js
Last active January 20, 2016 04:12
Match height of elements
//match height of elements
function matchHeight($element) {
var heighest = 0;
$element.each(function () {
var elemHeight = $(this).outerHeight();
if (elemHeight > heighest) {
heighest = elemHeight;
}
});
$element.css('height', heighest);
@jordanneenan
jordanneenan / resizeEnd.js
Last active November 2, 2015 01:15
Vertically aligns content with jQuery
var rtime;
var timeout = false;
var delta = 200;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
@mixin vertical-align {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.mixin p {
@include vertical-align;