Skip to content

Instantly share code, notes, and snippets.

View julsfelic's full-sized avatar

Julian Feliciano julsfelic

View GitHub Profile
@julsfelic
julsfelic / gist:3884147
Created October 13, 2012 10:56
JavaScript: isHostMethod
function isHostMethod(object, property) {
var t = typeof object[property];
return t=='function' ||
(!!(t=='object' && object[property])) ||
t=='unknown';
}
@julsfelic
julsfelic / gist:3886678
Created October 14, 2012 00:03
JavaScript: eventUtility
var eventUtility = {
addEvent: (function () {
if (typeof addEventListener !== "undefined") {
return function (obj, evt, fn) {
obj.addEventListener(evt, fn, false);
};
} else {
return function (obj, evt, fn) {
obj.attachEvent("on" + evt, fn);
};
@julsfelic
julsfelic / ajaxUtility.js
Created November 6, 2012 13:51
AJAX Utility
var ajaxUtility = {
createXHR: function () {
if (typeof XMLHttpRequest !== "undefined") {
return new XMLHttpRequest();
} else {
var versions = ["MSXML2.XmlHTTP.6.0", "MSXML2.XmlHTTP.3.0"];
for (var i = 0; i < versions.length; i++) {
try {
var xhr = new ActiveXObject(versions[i]);
@julsfelic
julsfelic / index.html
Created December 18, 2012 03:06
A CodePen by JulsFelic. Simple Accordion Faq List - Just a simple accordion faq list. When you hover over the <dt> it reveals the <dd> using the small snippet of jQuery. Also added some text-shadow to give the text a stamped looked and other CSS3 goodies.
<dl>
<dt>Would you like to learn more?</dt>
<dd>Yada Yada Such and Such</dd>
<dt>Would you like to learn more?</dt>
<dd>Yada Yada Such and Such</dd>
<dt>Would you like to learn more?</dt>
<dd>Yada Yada Such and Such</dd>
@julsfelic
julsfelic / protoInherit.js
Created January 26, 2013 11:54
Prototypal Inheritance Pattern (Obj inherit from Obj)
if (typeof Object.create !== 'function') {
Object.create = function(o) {
function F() {};
f.prototype = o;
return new F();
};
}
@julsfelic
julsfelic / getElementsByClassName function
Last active December 15, 2015 15:08
getElementsByClassName function. Provides a fallback for legacy browsers that do not support the native HTML5 DOM method.
function getElementsByClassName(node, className) {
if (node.getElementsByClassName) {
return node.getElementsByClassName(className);
} else {
var results = [];
var elems = node.getElementsByTagName("*");
for (var i = 0, len = elems.length; i < len; i++) {
if (elems[i].className.indexOf(className) != -1) {
results.push(elem[i]);
}
@julsfelic
julsfelic / serializeForm.js
Created April 18, 2013 17:46
Serializing form function
function serialize(form) {
var parts = [],
field = null,
i,
len,
j,
optLen,
option,
optValue;
@julsfelic
julsfelic / xBrowserCORS.js
Created April 20, 2013 15:33
Cross-Browser CORS
function createCORSResquest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
@julsfelic
julsfelic / ScopeSafeConstructor01.js
Created April 20, 2013 17:35
Scope safe constructor example
function Person(name, age, job) {
if (this instanceof Person) {
this.name = name;
this.age = age;
this.job = job;
} else {
return new Person(name, age, job)
}
}
@julsfelic
julsfelic / ScopeSafeConstructor02.js
Created April 20, 2013 17:39
Scope safe constructor pattern w/ prototype chaining
function Polygon(sides) {
if (this instanceof Polygon) {
this.sides = sides;
this.getArea = function() {
return 0;
};
} else {
return new Polygon(sides);
}
}