Skip to content

Instantly share code, notes, and snippets.

View KnightAlex's full-sized avatar

Alex Knight KnightAlex

  • Devon, United Kingdom
View GitHub Profile
@KnightAlex
KnightAlex / livetext
Created March 31, 2014 15:59
Show live text as it's being typed (jQuery)
$(document).ready(function(){
$('#mytext').keyup(function(){
$('#carrytext').html(this.value);
});
});
@KnightAlex
KnightAlex / gist:8870374ff1f2b3e22d37
Created July 8, 2014 10:17
Equal height html elements (jQuery)
// Match heights of elements on homepage for uniform display
matchHeight = function() {
//Timeout added to counteract delays in element sizing from loading
setTimeout(function(){
jQuery('.equal').each(function(){
var maxHeight = '0';
jQuery('.equal').each(function(){
maxHeight = (jQuery(this).height() > maxHeight) ? jQuery(this).height() : maxHeight;
});
jQuery('.equal').height(maxHeight);
@KnightAlex
KnightAlex / gist:9cfe0da49683fe577a27
Last active August 29, 2015 14:04
Woothemes Flexslider - responsive height fix
function fixHeight() {
var maxHeight = 0,
slides = el.find('.slides'),
data = el.data('flexslider');
slides.children()
.height('auto')
.each(function() {
maxHeight = Math.max(maxHeight, $(this).height());
})
.height(maxHeight);
@KnightAlex
KnightAlex / WP comments styling
Last active August 29, 2015 14:05
WordPress - basic comments styling
/* --- comments --- */
.commentlist {
margin-left: 0;
}
#comments {
padding-top: 20px;
}
@KnightAlex
KnightAlex / gist:b12d27b55d54745a777d
Created August 25, 2014 09:46
Reverse a list with jQuery
var list = $('ul');
var listItems = list.children('li');
list.append(listItems.get().reverse());
@KnightAlex
KnightAlex / WordPress menu walker
Created September 11, 2014 10:51
WordPress menu walker - to show menu descriptions but could be adapted to do other stuff.
// menu description walker
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
@KnightAlex
KnightAlex / gist:6ef4ff6754771de2a7dc
Last active August 29, 2015 14:06
Detect device rotation and reload page
// RELOADS WEBPAGE WHEN MOBILE ORIENTATION CHANGES
window.onorientationchange = function() {
var orientation = window.orientation;
switch(orientation) {
case 0: window.location.reload();
break;
case 90: window.location.reload();
break;
case -90: window.location.reload();
break;
@KnightAlex
KnightAlex / gist:513bf64501a3bf16d70b
Created October 9, 2014 08:59
WooCommerce get category Id from cat page
<?php
$category = get_queried_object();
echo $category->term_id;
?>
@KnightAlex
KnightAlex / gist:ebfb68cee0bc005d1892
Created October 22, 2014 17:58
WordPress: Toolset views - check if field is empty
[wpv-if fieldname="wpcf-fieldname" evaluate="empty(fieldname)" condition="false"][/wpv-if]
@KnightAlex
KnightAlex / compare arrays
Created November 4, 2014 08:38
Find one arrays items in another array
function compareArrays(sup, sub) {
sup.sort();
sub.sort();
var i, j;
for (i=0,j=0; i<sup.length && j<sub.length;) {
if (sup[i] < sub[j]) {
++i;
} else if (sup[i] == sub[j]) {
++i; ++j;
} else {