Skip to content

Instantly share code, notes, and snippets.

@jayllellis
jayllellis / password-prompt.html
Last active August 29, 2015 14:28
Simple prompt user for password before allowing access to page.
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Password Prompt</title>
<script type="text/javascript">
function checkpassword(){
var VIPpassword;
VIPpassword = prompt("Please enter the password", "");
if (VIPpassword != 'testpassword') {
@jayllellis
jayllellis / active-slide.js
Last active February 8, 2020 13:04
Add a class to current slide in bxSlider
$('.top-slider').bxSlider({
onSliderLoad: function(currentIndex) {
$('.top-slider').children().eq(currentIndex).addClass('active-slide');
},
onSlideAfter: function($slideElement){
$('.top-slider').children().removeClass('active-slide');
$slideElement.addClass('active-slide');
}
});
@jayllellis
jayllellis / done-resizing.js
Created July 16, 2015 18:01
Detects when the user is done reszing
var resizeTimer;
$(window).on('resize', function(e) {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Run code here, resizing has "stopped"
}, 250);
@jayllellis
jayllellis / scroll-stop.js
Created July 3, 2015 14:10
When the user stops scrolling, do something
(function($) {
"use strict";
$(document).ready (function(){
$(window).scroll(function(){
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {// when the user stops scrolling
// do something
}, 500));
});
});// end document ready
@jayllellis
jayllellis / content-changed.js
Created April 6, 2015 04:28
Detect when an element in the DOM's content changes.
$(document).ready(function(){
$('.some-element').bind('DOMSubtreeModified', function() {
// Do something
});
});
@jayllellis
jayllellis / custom-excerpt-length.php
Created April 2, 2015 15:00
WordPress Custom Excerpt Length
/*************************************************************************************
* Custom excerpt length
*************************************************************************************/
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
@jayllellis
jayllellis / nav-scroll-active.js
Created March 4, 2015 02:49
Change nav items to active as you scroll
$(window).scroll(function() {
$('section').each(function(){
var currentSection = $(this);
var currentId = $(this).attr('id');
if(currentSection.isOnScreen()){
$('.sidenav a').removeClass('active');
$('a[href="#'+currentId+'"]').addClass('active');
}
});
@jayllellis
jayllellis / top-is-visible.js
Created January 21, 2015 14:12
Top of element becomes visible within viewport
/**
* @desc checks if current element is on screen or within viewport (as soon as it becomes visible)
* @param none
* @return int - the coordinates of the window vs. the element
*/
jQuery.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
@jayllellis
jayllellis / equal-heights.js
Last active January 16, 2017 21:45
Simple jQuery equal height columns
/**
* @desc create equal height columns
* @param object - the elements to apply equal heights to
* @return none
*/
jQuery.fn.equalHeights = function(){
var colSelector = this.selector;// Get the selector of the object
var newHeight;
var colHeights = [];
$(colSelector).css('height', '');// Clear heights first
@jayllellis
jayllellis / setcookie.php
Last active August 29, 2015 14:06
PHP setcookie
<?php
if( isset($_COOKIE['cw_section']) ){// cookie is set
$redirect_section = $_COOKIE['cw_section'];
if($redirect_section == 'doctor'){
header('Location: http://www.example.com/doctor/');
}
else{
header('Location: http://www.example.com/patient/');
}
}