Skip to content

Instantly share code, notes, and snippets.

View aaronranard's full-sized avatar

Aaron Ranard aaronranard

View GitHub Profile
@aaronranard
aaronranard / _icons-material-design.scss
Created June 16, 2015 16:03
SCSS: Materialize icons gulp build fix
$font-mdi : 'Material-Design-Icons';
$mdi-prefix : 'mdi-';
@font-face {
font-family: "#{$font-mdi}";
src:url("#{$icons-font-path}#{$font-mdi}.eot?#iefix") format("embedded-opentype"),
url("#{$icons-font-path}#{$font-mdi}.woff2") format("woff2"),
url("#{$icons-font-path}#{$font-mdi}.woff") format("woff"),
url("#{$icons-font-path}#{$font-mdi}.ttf") format("truetype"),
url("#{$icons-font-path}#{$font-mdi}.svg##{$font-mdi}") format("svg");
@aaronranard
aaronranard / file-upload.js
Last active August 29, 2015 14:12
Angular: File Uploader
$scope.onFileSelect = function($files) {
// https://github.com/danialfarid/angular-file-upload
var file = $files[0];
$scope.upload = $upload.upload({
url: apiEndpoint + '/api/file/upload',
// method: 'POST' or 'PUT',
// headers: {'header-key': 'header-value'},
// withCredentials: true,
//data: {myObj: $scope.myModelObj},
file: file, // or list of files: $files for html5 only
@aaronranard
aaronranard / input-max-length.js
Last active April 24, 2019 13:03
Angular: directive to limit an input field to a max number of characters
app.directive('inputMaxlength', function() {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
var maxlength = Number(attrs.inputMaxlength);
function fromUser(text) {
if (text.length > maxlength) {
var transformedInput = text.substring(0, maxlength);
ngModelCtrl.$setViewValue(transformedInput);
ngModelCtrl.$render();
@aaronranard
aaronranard / cookies.js
Last active August 29, 2015 14:00
Javascript: Cookie Management
/**
* determine whether this is the first visit to the animation page
* @param {string} c_name cookie name
* @return {string} cookie value
*/
function getCookie(c_name){
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start === -1){
c_start = c_value.indexOf(c_name + "=");
@aaronranard
aaronranard / acf-gallery-lightbox.php
Created April 8, 2014 17:03
WordPress: ACF - Lightbox Gallery
@aaronranard
aaronranard / acf-gallery.php
Created April 8, 2014 17:00
WordPress: ACF - Output Gallery
@aaronranard
aaronranard / custom-taxonomies.php
Last active August 29, 2015 13:58
WordPress - get custom taxonomies for post
$categories = get_the_terms( get_the_id() , 'service' );
$separator = '<br />';
$output = '';
if($categories){
foreach($categories as $category) {
//$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
$output .= $category->name . $separator;
}
echo trim($output, $separator);
}
@aaronranard
aaronranard / is_child.php
Created November 26, 2013 18:35
WordPress: is a child page
/**
* Child page conditional
* @ Accept's page ID, page slug or page title as parameters
*/
function is_child( $parent = '' ) {
global $post;
$parent_obj = get_page( $post->post_parent, ARRAY_A );
$parent = (string) $parent;
$parent_array = (array) $parent;
@aaronranard
aaronranard / search_functions.php
Created September 20, 2013 21:04
WordPress - Blank Search to go to search.php
//For blank searches to use search.php
add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}
@aaronranard
aaronranard / repeater.php
Last active December 22, 2015 18:39
WordPress: Repeater Field Loop
<?php if(have_rows('repeater_field_name')): ?>
<ul>
<?php while( have_rows('repeater_field_name')): the_row(); ?>
<li><?php echo get_sub_field('image'); ?></li>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>