Skip to content

Instantly share code, notes, and snippets.

@olimortimer
olimortimer / gist:2020935
Created March 12, 2012 09:39
JS: Disable next X working days & weekends
/**
* JS: Disable next X working days & weekends
* This disables selection of the next X working days in the jQuery datepicker
* along with weekends using the built in function
*
* 14/03/2012 - Oli Mortimer (olimortimer.com)
* Originally posted on StackOverflow by Junto (benpowell.co.uk)
*
* Usage: Change the required number of days in AddWeekDays(X)
**/
@olimortimer
olimortimer / cdn-fallback.html
Created March 12, 2012 14:56
CDN Fallbacks
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script>window.jQuery.ui || document.write('<script src="js/jquery-ui-1.8.21.min.js"><\/script>')</script>
<script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script>window.swfobject || document.write('<script src="js/swfobject-2.2"><\/script>')</script>
@olimortimer
olimortimer / gist:2300792
Created April 4, 2012 12:29
JS: Cross-domain jQuery JSON AJAX alternative for IE
// The ajax.php file must also return header('Access-Control-Allow-Origin: *');
if ($.browser.msie && window.XDomainRequest) {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("POST", js_base_url + 'ajax?id='+id);
xdr.onload = function () {
var JSON = $.parseJSON(xdr.responseText);
alert(JSON.response);
@olimortimer
olimortimer / gist:2420148
Created April 19, 2012 10:30
JS: Replace content with show / hide message
$('#filterfeedback form').fadeOut(250, function() {
$('#filterfeedback').append('<div class="successBox alertInner"><p>Filter applied</p></div>').hide().fadeIn(500, function() {
$('#filterfeedback .successBox').delay(1500).fadeOut(250, function() {
$('#filterfeedback form').fadeIn(500);
});
});
});
@olimortimer
olimortimer / gist:2787075
Created May 25, 2012 09:58
JS: jQuery to / from datepickers
$(function() {
// Set each date picker with a min / max date of what was chosen in the other
$("#date_from").datepicker({
dateFormat: "dd/mm/yy",
onClose: function(dateValue, inst) {
$("#date_to").datepicker("option", "minDate", dateValue);
}
});
$("#date_to").datepicker({
dateFormat: "dd/mm/yy",
@olimortimer
olimortimer / is_serialized.php
Created May 29, 2012 10:46
PHP: Serialize Check
<?php
// There's no built in function to check if data is serialized or not
// other than trying to unserialize it, and receiving an error if it isn't...
function is_serialized($data){
if(trim($data) == "") {
return false;
}
if(preg_match("/^(i|s|a|o|d)(.*);/si",$data)) {
@olimortimer
olimortimer / gist:2850505
Created June 1, 2012 08:54
JS: New window rel="external"
$(function() {
// Open rel="external" in a new window
$('a[rel*=external]').click(function(){
window.open(this.href);
return false;
});
});
@olimortimer
olimortimer / drop-shadows.htm
Created June 24, 2012 19:56
CSS: Drop-shadows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS drop-shadows</title>
<style>
body {
padding:20px 0 30px;
font:14px/1.5 Arial, sans-serif;
text-align:center;
@olimortimer
olimortimer / gist:3032672
Created July 2, 2012 10:48
JS: jQuery Replace HREF Query String
// www.website.com/page?id=100
$('#pageLink').attr('href', $('#pageLink').attr('href').replace(/((\?|&)id\=)[0-9]*/, '$1' + '123'));
// www.website.com/page?id=123
@olimortimer
olimortimer / jQueryMobileBlock.js
Created July 2, 2012 23:19 — forked from MorningZ/jQueryMobileBlock.js
JS: Block page whilst showing jQuery loading message
/*
The jQuery Mobile "loading" message allows users to click on UI items around it
Using Mike Alsup's BlockUI, we can stop this
http://jquery.malsup.com/block/#download
Thanks to MorningZ
https://gist.github.com/MorningZ
*/
// Add this right before the closing <body> tag