Skip to content

Instantly share code, notes, and snippets.

View pixelhandler's full-sized avatar

Billy Heaton pixelhandler

View GitHub Profile
@pixelhandler
pixelhandler / deferred-promise.html
Created October 9, 2011 01:16
Deferred / Promise Example borrowed from gist.github.com/862567
<!docType html>
<html>
<head>
<title>Deferred / Promise</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery-1.6.4-promises.js">// get script at https://gist.github.com/1273133</script>
</head>
<body>
@pixelhandler
pixelhandler / jquery-1.6.4-promises.js
Created October 9, 2011 01:09
Deferred / Promise extracted from jQuery v1.6.4 for use with older version of jQuery 1.4.2
(function($){
var // Promise methods
promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
// Static reference to slice
sliceDeferred = [].slice;
if (typeof $ !== 'function') {
return false;
} else {
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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',