Skip to content

Instantly share code, notes, and snippets.

View pixelhandler's full-sized avatar
🍊
Working remotely

Bill Heaton pixelhandler

🍊
Working remotely
View GitHub Profile
@pixelhandler
pixelhandler / index.html
Created October 11, 2010 23:57
Event Pooling example using jQuery
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Event Pooling, or perhaps Pub/Sub</title>
<script type="text/javascript" charset="utf-8" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
</head>
<body>
<strong>Who is this?</strong>
<form action="#" method="get" accept-charset="utf-8" id="whoisit">
@pixelhandler
pixelhandler / index.html
Created November 6, 2010 19:38
searchText() jQuery plugin to add helper text in search input. This jQuery plugin script added text to an input field in a search form. The defaults are set to the IDs used in a WordPress search form. The behavior can be set to force clearing of text ever
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML for .searchText() jQuery Plugin, custom helper text input value</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<h1>.searchText() jQuery Plugin, adding search helper text / behavior</h1>
<ol>
<li>
@pixelhandler
pixelhandler / matchHeight.js
Created July 14, 2011 04:05
jQuery plugin to ‘matchHeight’ of multiple columns with floating elements
(function($) {
/**
* .matchHeight()
* - match heights of multiple columns that use css layout with floating elements
*/
$.fn.matchHeight = function(options) {
// set the containing element and set elements used as columns
var defaults = {
container : '.main',
columns : 'div',
@pixelhandler
pixelhandler / boilerplate_jQuery_plugin.js
Created July 14, 2011 04:08
Boilerplate code for jQuery plugin with debug and logging methods
//jQuery.noConflict();
(function($) { // $ is jQuery
// plugin for yada yada
$.fn.yadayada = function(options) {
var defaults = {
foo : 'bar'
};
// Extend our default options with those provided.
var opts = $.extend({}, defaults, options);
// Do something to each item
@pixelhandler
pixelhandler / hijack_form_submit.js
Created July 14, 2011 04:10
Hijack form’s submit onclick, validate, and use enter key to post form
// using jQuery library and validation plugin in this code
// for checking keycodes
function getKeyCode(event) {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
return keycode;
}
// is there an anchor as Submit button?
var $submit = $('a[id$="_submit"]');
// is there any behavior already on submit, like -> onclick="__doPostBack(...)"
@pixelhandler
pixelhandler / images_loaded.js
Created July 14, 2011 04:12
Images loaded or not? Check with JavaScript
// Check if images load properly
// returns false if image not loaded
function imgOK(img) {
if (!img.complete) {
return false;
}
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
return false;
}
return true;
@pixelhandler
pixelhandler / import_url_ruby.rb
Created July 14, 2011 04:14
Import a URL with Ruby
def importHTML
require 'open-uri'
@source = open("http://domain.com/some.html").read
end
# uses a reference parameter when getting remote XML
def importXML
require 'open-uri'
@aclass = AClass.find(params[:id]) # expecting a param named ref
@content = open("http://domain.com" + @aclass.ref + "&type=xml").read
@pixelhandler
pixelhandler / grid.sass
Created July 14, 2011 04:16
Use ruby gem, Sass to generate a CSS grid layout
// Grid
// ===========================
// e.g. 960px, 12 columns (px) : | 10+ | 60 + 20 (x11) | 60 + 10 |
// Setup your grid ...
// total page width
!gTotal = 960px
// number of columns
!grid = 16
// gutter between columns
@pixelhandler
pixelhandler / browserName.js
Created July 14, 2011 04:20
PXHLRbrowserName - add browser info to class
/* Pixelhandler namespace. */
if (!window.PXHLR) { var PXHLR = {}; }
/**
* PXHLRbrowserName - add browser info to class
* @return sting like ...
* webkit, opera, msie, mozilla
* written in into the class attribute of obj
*/
(function($) {
@pixelhandler
pixelhandler / getParam.js
Created July 14, 2011 04:25
getParam fn and preventXSS fn
/**
* method to test string for XSS
* @name PXHLR.preventXSS
* @type Function
* @member PXHLR
* @returns String that doesn't allow XSS Cross Site Scripting attack
*/
PXHLR.preventXSS = function (str) {
var paramStr = str;