Skip to content

Instantly share code, notes, and snippets.

View roykolak's full-sized avatar

Roy Kolak roykolak

  • Detective.io
  • Chicago, IL USA
View GitHub Profile
@roykolak
roykolak / PseudoClass.js
Created January 28, 2009 22:40
Pseudo class (for IE6)
function PseudoClass(autotarget) {
this.targets = [];
if((autotarget != undefined) && (autotarget == true)) {
this.attach(true);
}
}
PseudoClass.prototype.addTarget = function(target) {
this.targets.push(target);
return target;
}
@roykolak
roykolak / PopupClass.js
Created January 28, 2009 22:49
Popup class
function PopupClass(link, launch_now) {
if(link !== undefined) {
if(typeof link == "string") {
var link = $("#"+link);
}
this.href = link.attr('href');
this.title = link.attr('title');
this.properties = this.setProperties();
if(launch_now !== undefined && launch_now == true) {
return this.launch();
@roykolak
roykolak / simple_inheritance.js
Created January 29, 2009 17:05
Class inheritance helper
function inherit(subclass, superclass) {
var temp = function() {};
temp.prototype = superclass.prototype;
subclass.prototype = new temp();
}
@roykolak
roykolak / cookieJar.js
Created January 29, 2009 19:19
Cookie Manager
CookieJar = {
cookies: {},
// Pass This: { name:'cookie', value:'value', [expires:'365'], [domain:'domain'], [path:'path'], [secure:true] }
addCookie:function(newCookie) {
cookie = [];
// Build the New Cookie Array
$.each(newCookie, function(index, value) {
switch(index) {
case 'name': cookie[0] = value;
@roykolak
roykolak / indexOf.js
Created January 29, 2009 19:29
indexOf for IE6
if($.browser.msie) {
if(!Array.indexOf) {
Array.prototype.indexOf = function(obj){
for(var i=0; i<this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
}
@roykolak
roykolak / prompt_text.js
Created January 29, 2009 19:33
Prompt Text
$(':input.promptText').focus(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val('');
}
});
$(':input.promptText').blur(function resetField() {
if(!$(this).val()) {
$(this).val($(this).attr('title'));
}
});
@roykolak
roykolak / ObserverAttacher.js
Created January 30, 2009 18:13
Safe observer attaching
function AttachOnce() {
this.behavior($('.' + this.target_class));
this.clean();
}
AttachOnce.prototype.clean = function() {
$('.' + this.target_class).removeClass(this.target_class);
}
AttachOnce.prototype.behavior = function() {
// Will be overwritten.
}
/* Clone and Insert Attacher -------------------------------- */
AttachOnceClass.add('CloneAndInsert', 'js_clone_and_insert', function(jquery_selector) {
// TODO: conside refactoring into a class
jquery_selector.click(function() {
var parent = $(this).parent();
var insert = parent.find('.js_insert');
var clone = parent.find('.js_clone').clone(true);
var count = insert.children().length + 2;
// Recursively make attributes unique in cloned html
@roykolak
roykolak / debug.css
Created February 12, 2009 16:44
highlights bad HTML, incomplete tag attributes, and inline javascript
/*
This is a combination of:
http://meyerweb.com/eric/thoughts/2007/09/07/diagnostic-styling/
http://www.nealgrosskopf.com/tech/thread.asp?pid=17
.. with some additional tweaking and additions
*/
/* Empty Attributes */
img[alt=""],
var Micro = (function() {
var proxy = function() {};
var wrap = function(zuper, fn) {
return function() {
var saved = this.zuper;
this.zuper = zuper;
try {
return fn.apply(this, arguments);
} finally {
this.zuper = saved;