Skip to content

Instantly share code, notes, and snippets.

@ksdSnippets
ksdSnippets / gist:6181716
Created August 8, 2013 05:26
JS: show CSS animation once element is visible on page
function isElementInViewport(elem) {
var $elem = $(elem);
// Get the scroll position of the page.
var scrollElem = ((navigator.userAgent.toLowerCase().indexOf('webkit') != -1) ? 'body' : 'html');
var viewportTop = $(scrollElem).scrollTop();
var viewportBottom = viewportTop + $(window).height();
// Get the position of the element on the page.
var elemTop = Math.round( $elem.offset().top );
@ksdSnippets
ksdSnippets / gist:5940833
Created July 6, 2013 18:46
jQuery: $.ajax boilerplate
var newAjax = $.ajax({
url: 'url.php',
type: "POST",
cache: false,
data: {test: "hello"},
dataType: 'json',
timeout: 2000
});
@ksdSnippets
ksdSnippets / gist:5930522
Created July 4, 2013 22:10
WP: enqueue styles
* Register with hook 'wp_enqueue_scripts', which can be used for front end CSS and JavaScript
*/
add_action( 'wp_enqueue_scripts', 'prefix_add_my_stylesheet' );
/**
* Enqueue plugin style-file
*/
function prefix_add_my_stylesheet() {
// Respects SSL, Style.css is relative to the current file
wp_register_style( 'prefix-style', plugins_url('style.css', __FILE__) );
@ksdSnippets
ksdSnippets / gist:5811592
Created June 19, 2013 03:58
WP: sidebar widget boilerplate
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
@ksdSnippets
ksdSnippets / gist:5789352
Created June 15, 2013 19:49
WP: Plugin Header Info
<?php
/*
Plugin Name: KS Plugin
Plugin URI: http://kevinsalter.me
Description: A brief description of the Plugin.
Version: 1.0
Author: Name Of The Plugin Author
Author URI: http://kevinsalter.me
*/
@ksdSnippets
ksdSnippets / gist:5458239
Created April 25, 2013 08:06
WP: Login Page Function File Lines
/************* CUSTOM login PAGE *****************/
function ksd_login_css() {
wp_enqueue_style( 'ksd_login_css', get_template_directory_uri() . ' /css/login.css', false );
}
// changing the logo link from wordpress.org to your site
function ksd_login_url() { return home_url(); }
// changing the alt text on the logo to show your site name
/************* CUSTOM login PAGE *****************/
function ksd_login_css() {
wp_enqueue_style( 'ksd_login_css', get_template_directory_uri() . ' /css/login.css', false );
}
// changing the logo link from wordpress.org to your site
function ksd_login_url() { return home_url(); }
// changing the alt text on the logo to show your site name
@ksdSnippets
ksdSnippets / gist:5130172
Created March 10, 2013 19:59
JS: Handsome Curtain Effect
;(function ( $, window, document, undefined ) {
var methods, settings;
var state = 1;
settings = {
animationSpeed: 500,
animationEasing: 'linear',
curtainClass: 'curtain',
curtainLeftClass: 'left',
@ksdSnippets
ksdSnippets / gist:5094215
Created March 5, 2013 20:57
JS: push TBS tab ids to URL
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop();
window.location.hash = this.hash;
$('html,body').scrollTop(scrollmem);
});
@ksdSnippets
ksdSnippets / gist:5073605
Created March 2, 2013 22:44
JS: make console.log safe
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());