Skip to content

Instantly share code, notes, and snippets.

@trentsnippets
trentsnippets / push
Created June 15, 2014 02:54
Html5 Push state Starter
jQuery('#element').on('click', function(event) {
// if pushState is supported!
if (Modernizr.history) {
event.preventDefault();
var url_to_load = 'our-work';
history.pushState(url_to_load, '', url_to_load);
@trentsnippets
trentsnippets / 0_reuse_code.js
Created February 16, 2014 23:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@trentsnippets
trentsnippets / jqueryOn
Created February 12, 2014 03:13
Jquery Attach Event Handler With .on
/*-------------------------------------------------------------------
| This will attach an eventHandler to an object even if it is added
| to the DOM after doc.ready / .load via ajax etc...
|--------------------------------------------------------------------
*/
jQuery( "body" ).on( "event", "element", function() {
});
@trentsnippets
trentsnippets / CustomLoginLogo.php
Created September 6, 2013 03:40
Add a custom logo to the login screen for wordpress.
/**
* Custom admin login header link
*/
function custom_login_url() {
return home_url( '/' );
}
add_filter( 'login_headerurl', 'custom_login_url' );
/**
* Custom admin login header link alt text
@trentsnippets
trentsnippets / Wordpress-Echo-Current-Template.php
Created September 4, 2013 22:57
Wordpress - Show the current template name you are working on..
<?php
/* Display current template you are using
* Add to functions.php
*/
add_action('wp_head', 'display_template');
function display_template() {
global $template;
$filename = basename($template);
@trentsnippets
trentsnippets / script.js
Created August 21, 2013 01:07
Make Bootstrap drop down menu work on hover instead of click.
//Enable bootstrap drop down menu on hover
$(document).ready(function() {
$('.nav li.dropdown').hover(function() {
$('.nav li.dropdown').removeClass('open');
$(this).addClass('open');
}, function() {
$(this).removeClass('open');
@trentsnippets
trentsnippets / Navigation.ss
Created August 20, 2013 22:41
Add's Bootstrap navigation menu to a silverstripe template. Also includes another menu for mobile devices which can be removed if not making responsive site. The mobile menu is in two columns for this gist simply put it into one if that is what you require.
<!-- Nav -->
<div id="navbar" class="navbar navbar_absolute">
<div class="container">
<a class="brand" href="{$BaseHref}"><img src="{$ThemeDir}/img/logo.gif" alt="Logo" /></a>
<% if $Menu(1) %>
<ul class="nav">
<% loop $MenuSet('Main Menu').MenuItems %>
@trentsnippets
trentsnippets / CompassCreateCustomProject
Created August 2, 2013 03:02
Compass Create Custom Projects
compass create . --bare --sass-dir "assets/stylesheets/sass" --css-dir "assets/stylesheets/css" --javascripts-dir "assets/js" --images-dir "assets/img"
@trentsnippets
trentsnippets / FormValues.js
Last active December 19, 2015 12:28
This jQuery code will make form values show / hide on click so you can use them as titles.
$(document).ready(function(){
$('form input:text, form textarea').each(function(){
$.data(this, 'default', this.value);
}).focus(function(){
if ($.data(this, 'default') == this.value) {
this.value = '';
}
}).blur(function(){
if (this.value === '') {
this.value = $.data(this, 'default');
@trentsnippets
trentsnippets / silverstripeUploadField.php
Last active December 19, 2015 06:48
Add an upload field to silverstripe
//Add a single upload field to upload one image.
static $has_one = array(
'BackgroundImage' => 'Image'
);
$fields->addFieldToTab('Root.Main', new UploadField('BackgroundImage', 'Background Image'), 'Content');