Skip to content

Instantly share code, notes, and snippets.

@richgcook
richgcook / styles.css
Last active August 29, 2015 13:56
Progressive enhancement to use SVG images with PNG fallback for IE
.element {
background: url('image.png') no-repeat 0 0;
background: rgba(0,0,0,0) url('image.svg') no-repeat 0 0;
}
@richgcook
richgcook / index.php
Created February 20, 2014 00:02
Simple AJAX example using jQuery .load() and HML5 history
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ajax</title>
<!-- Meta -->
<meta charset="utf-8" />
<meta name="description" content="" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@richgcook
richgcook / index.php
Created February 20, 2014 00:05
CSS Loader/Spinner
<div class="loader"></div>
@richgcook
richgcook / wp-config.php
Created February 20, 2014 00:14
Force upgrades/updates on Wordpress when working locally
define('FS_METHOD','direct');
@richgcook
richgcook / scripts.js
Last active August 29, 2015 13:56
clickToggle replacement (flags)
var _clicked = false;
$('_').on('click', function(e) {
if (!_clicked) { // First click
about_clicked = true;
console.log('true');
} else { // Second click
about_clicked = false;
@richgcook
richgcook / scripts.js
Created February 20, 2014 00:48
history.replaceState (URL); useful when using AJAX
var pushSupport = $('html').hasClass('history') ? true : false; // does html have class .history? (modernizr.js required)
var toLoad = $('.element').attr('href'); // toLoad variable is .element's href attribute
if (pushSupport === true) { // if html does have class .history
history.replaceState(null, null, toLoad); // replace URL with the new href
}
@richgcook
richgcook / scripts.js
Created February 20, 2014 00:51
isMobile JS function
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i) ? true : false;
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPod/i) ? true : false;
@richgcook
richgcook / scripts.js
Created February 24, 2014 09:01
Setting site root/URL for both local and remote development
var siteURL = 'http://www.website.com/';
if ( document.domain == 'localhost' ) siteURL = "http://localhost/website/";
// Example
$('.element').css('background-image', 'url("' + siteURL + 'assets/img/background.png")');
$('.element').next().find('img').attr('src', siteURL + 'assets/img/image.png');
@richgcook
richgcook / scripts.js
Created February 24, 2014 09:03
Preload (specific) images (good for img src changes)
function preloadImages(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
});
}
// Usage
preloadImages([
'img/1.jpg',
'img/2.jpg',
@richgcook
richgcook / functions-xx.php
Created February 24, 2014 11:20
WP functions-xx.php init setup
// Remove specific menus from WP backend
function remove_menus () {
global $menu;
$restricted = array(__('Posts'),__('Comments'),__('Links'),__('Media')); // Can be whatever you want
end ($menu);
while ( prev($menu) ) {
$value = explode( ' ',$menu[key($menu)][0] );
if ( in_array($value[0] != NULL?$value[0]:"" , $restricted) ) {
unset( $menu[key($menu)] );
}