Skip to content

Instantly share code, notes, and snippets.

View Craga89's full-sized avatar

Craig Michael Thompson Craga89

View GitHub Profile
@Craga89
Craga89 / gist:586997
Created September 19, 2010 18:31
Implementation of jGrowl using qTip2 Library
$(document).ready(function()
{
$('button').click(function() {
// Check if it should be persistent (can set to a normal bool if you like!)
createGrowl( $(this).hasClass('persistent') );
});
// Make it a window property see we can call it outside via createGrowls() at any point
window.createGrowl = function(persistent) {
// Use the last visible jGrowl qtip as our positioning target
@Craga89
Craga89 / jQueryOffsetMobileSafariFix.js
Created November 3, 2010 22:35
Fixes the jQuery.offset() function for use with Mobile Safari browsers such as iPad, iPhone and iPod Touch
if( parseFloat(((/CPU.+OS ([0-9_]{3}).*AppleWebkit.*Mobile/i.exec(val)) || [0,'4_2'])[1].replace('_','.')) < 4.1) {
$.fn.Oldoffset = $.fn.offset;
$.fn.offset = function() {
var result = $(this).Oldoffset();
result.top -= window.scrollY;
result.left -= window.scrollX;
return result;
}
}
@Craga89
Craga89 / ios-fixedpos-fix.js
Created November 3, 2010 22:38
Fixes the jQuery.fn.offset() function in iOS to correct for fixed positioning issues (v3.1-4.0, v4.3-4.3.3)
(function() {
var iOS = parseFloat(
('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1])
.replace('undefined', '3_2').replace('_', '.').replace('_', '')
) || FALSE;
if((iOS > 3.1 && iOS < 4.1) || (iOS >= 4.3 && iOS < 4.33)){
$.fn._oldOffset = $.fn.offset;
$.fn.offset = function() {
var result = $.fn._oldOffset.call(this);
@Craga89
Craga89 / gist:2466525
Created April 22, 2012 20:02
Efficient JavaScript Delta-encoding merge method
var Entity = function(params) {
this.merge(Entity.defaults);
this.merge(params);
};
Entity.defaults = {
position: [0, 0],
velocity: [0, 0],
acceleration: [1, 1]
};
@Craga89
Craga89 / ios-version.js
Created May 29, 2012 16:39
JavaScript iOS version detection
/*
* Outputs a float representing the iOS version if user is using an iOS browser i.e. iPhone, iPad
* Possible values include:
* 3 - v3.0
* 4.0 - v4.0
* 4.14 - v4.1.4
* false - Not iOS
*/
var iOS = parseFloat(
@Craga89
Craga89 / varcommasequals.js
Last active October 8, 2015 16:48
var, commas and equals
function pollute() {
var foo = bar = 'uhoh'; // bar pollutes upper scope!
}
pollute(); // Execute the pollution!
@Craga89
Craga89 / varcommasequals-fix.js
Last active October 8, 2015 16:48
var, commas and equals - the fix
function pollute() {
var foo = 'uhoh',
bar = foo; // bar is in local scope, no pollution!
}
pollute(); // Execute the pollution..?
@Craga89
Craga89 / jquery-ui-droppable-iframe-fix.js
Last active September 4, 2019 07:14
jQuery UI Draggable - Droppables in an iFrame
// Create new object to cache iframe offsets
$.ui.ddmanager.frameOffsets = {};
// Override the native `prepareOffsets` method. This is almost
// identical to the un-edited method, except for the last part!
$.ui.ddmanager.prepareOffsets = function (t, event) {
var i, j,
m = $.ui.ddmanager.droppables[t.options.scope] || [],
type = event ? event.type : null, // workaround for #2317
list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack(),
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Flip bug with Overflow</title>
<link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/qtip2/2.1.1/jquery.qtip.css">
<link rel="stylesheet" type="text/css" href="qtip-bug.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/qtip2/2.1.1/jquery.qtip.js"></script>
@Craga89
Craga89 / bootstrap3-disabled-dropdown-links.css
Last active August 29, 2015 14:02
Bootstrap 3 - Disabled dropdown links