Skip to content

Instantly share code, notes, and snippets.

View dhigginbotham's full-sized avatar
😸
happycat

David Higginbotham dhigginbotham

😸
happycat
View GitHub Profile
function promise() {
var xhr = $http(optsObj);
return xhr;
}
var xhr = promise()
xhr.sucess(function(err, resp) {});
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.defaults.transformRequest.unshift(function (data, headersGetter) {
var key, result = [];
for (key in data) {
if (data.hasOwnProperty(key)) {
result.push(encodeURIComponent(key) + "=" + encodeURIComponent(data[key]));
}
}
return result.join("&");
});
@dhigginbotham
dhigginbotham / xhrModal.js
Created April 16, 2014 20:55
angular colorbox modal directive
var app = app || {};
/**
* angular xhr modal directive
* @param
*/
app.directive('xhrModal', ['$http','$compile',
function ($http, $compile) {
function compile (elem, cAtts) {
@dhigginbotham
dhigginbotham / idk.js
Created April 2, 2014 14:50
This just doesn't feel right...
var app = app || {};
app.filter('prettyPhone', function () {
return function (input) {
input = input || null;
if (input) {
if ((input[0] == '(') || (!~input.indexOf('-'))) {
return input;
} else {
@dhigginbotham
dhigginbotham / extend.js
Last active August 29, 2015 13:57
bored extend... for kicks
var extend = function (dest) {
var args = Array.prototype.slice.call(arguments, 1),
ln = args.length;
for (var i=0;i<ln;++i) {
for (var o in args[i]) {
dest[o] = args[i][o];
}
};
return dest;
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dhigginbotham
dhigginbotham / hoist.js
Last active August 29, 2015 13:56
simple explanation of the term "variable hoisting"
console.log(meow); // undefined
var meow = 'meow';
console.log(meow); // 'meow'
console.log(bark); //ReferenceError: bark is not defined
@dhigginbotham
dhigginbotham / dom.ready.js
Created February 19, 2014 17:18
alternative dom.ready and dom.load events
(function(root, doc) {
/**
* dom.ready.js is a tiny library
* to help with cross-browser compatible
* `DOMContentLoaded` (dom ready)
* event binding
*
* author: dhigginbotham
* license: MIT
var app = app || angular;
app.factory('photos', ['$rootScope', function ($rootScope) {
var photos = {};
photos.add = function (mixed) {
if (mixed instanceof Array) {
for (var i=0;i<mixed.length;++i) {
photos.data.push(mixed[i]);
}
@dhigginbotham
dhigginbotham / data.events.js
Last active August 29, 2015 13:56
event handling on data-attrs
(function (root) {
/**
* data events add event listeners
* on data-attributes, ie8+
*
* author: dhigginbotham
* license: MIT
*/