Skip to content

Instantly share code, notes, and snippets.

View Mottie's full-sized avatar
💭
🥞

Rob Garrison Mottie

💭
🥞
View GitHub Profile
@Mottie
Mottie / dabblet.css
Created June 26, 2012 15:14 — forked from chriscoyier/dabblet.css
Checkbox Hack
/* Checkbox Hack */
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
label {
-webkit-appearance: push-button;
appearance: button;
@Mottie
Mottie / gist:1491097
Created December 17, 2011 19:14
jQuery images loaded function
/*
Check if all images are loaded
- Callback occurs when all images are loaded
- image load errors are ignored (complete will be true)
- Use:
$('.wrap img').imagesLoaded(function(){
alert('all images loaded');
});
*/
@Mottie
Mottie / gist:1329506
Created November 1, 2011 00:32
String.allIndexOf() & Array.allIndexOf()
(function(){
/*
String.allIndexOf(searchstring, ignoreCase)
String [String] - the string to search within for the searchstring
searchstring [String] - the desired string with which to find starting indexes
ignoreCase [Boolean] - set to true to make both the string and searchstring case insensitive
Use:
var s = "The rain in Spain stays mainly in the plain";
s.allIndexOf("ain"); // result [ 5,14,25,40 ]
s.allIndexOf("the"); // result [ 34 ]
@Mottie
Mottie / gist:1301306
Created October 20, 2011 14:35
Add jQuery renameAttr
// http://wowmotty.blogspot.com/2011/10/jquery-rename-attribute-renameattr.html
// *********
jQuery.fn.extend({
renameAttr: function( name, newName, removeData ) {
var val;
return this.each(function() {
val = jQuery.attr( this, name );
jQuery.attr( this, newName, val );
jQuery.removeAttr( this, name );
// remove original data
@Mottie
Mottie / gist:1301303
Created October 20, 2011 14:34
Add Swipe Support
// http://wowmotty.blogspot.com/2011/10/adding-swipe-support.html
// **********
var target = $('#box'),
// allow movement if < 1000 ms (1 sec)
maxTime = 1000,
// swipe movement of 50 pixels triggers the swipe
maxDistance = 50,
@Mottie
Mottie / gist:1079524
Created July 13, 2011 00:55
Adding WordPress Quicktag Buttons to a WP Plugin
<?php
/************************************************
Adding WordPress Quicktag Buttons to a WP Plugin
************************************************/
?>
<style>
/* Simulate the input buttons styles */
#ed_toolbar button {
display: inline-block;
vertical-align: middle;
@Mottie
Mottie / gist:938670
Created April 23, 2011 14:58
Cycle Through Visual Event Bookmarklet Layers
// Code I paste into the Firebug Console after I run the Visual Event
// bookmarklet (http://www.sprymedia.co.uk/article/Visual+Event)
// so I can cycle through the layers - Use arrow keys to cycle
var veColors = [ 'black', 'orange', 'purple', 'green', 'blue', 'yellow', 'red' ],
veColorLength= veColors.length - 1,
veLayerIndex = 0;
function showVeLayer(nxt){
veLayerIndex += (nxt) ? 1 : -1;
@Mottie
Mottie / jQuery Enable-Disable
Last active September 25, 2015 10:18
Enable or disable objects using jQuery
/* Enable or disable DOM objects
* This is a basic script - it won't determine
* if an object can be enabled or disabled
*
* Use: $('button').disable();
* $('button').enable();
*/
(function($){
$.fn.extend( {
enable : function(){
@Mottie
Mottie / gist:642431
Created October 23, 2010 16:52
Return Duplicates from Array
/* Find & return only duplicates from an Array
* also returned is an object with the # of duplicates found
* myArray = ["ccc", "aaa", "bbb", "aaa", "aaa", "aaa", "aaa", "bbb"];
* x = myArray.getDuplicates();
* // x = [ array of duplicates, associative object with # found]
* // x = [ ['aaa','bbb'] , { 'aaa' : 5, 'bbb' : 2 } ]
* alert(x[0]) // x[0] = ['aaa','bbb'] & alerts aaa,bbb
* alert(x[1]['aaa']) // alerts 5;
*/
Array.prototype.getDuplicates = function(sort) {
@Mottie
Mottie / gist:461516
Created July 2, 2010 15:30
Return Unique Array
/* Return a unique array
* myArray = ["ccc","aaa","bbb","aaa"];
* x = myArray.getUnique(); // x = ["ccc","aaa","bbb"]
* y = myArray.getUnique(true); // y = ["aaa","bbb","ccc"]
*/
// Slightly faster version than getUnique2; Modified from
// http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/
Array.prototype.getUnique1 = function(s){
var c, a = [], o = {}, i, j = 0, l = this.length;
for(i=0; i<l; ++i){