Skip to content

Instantly share code, notes, and snippets.

View wallin's full-sized avatar

Sebastian Wallin wallin

View GitHub Profile
@wallin
wallin / script.js
Created April 12, 2011 21:11 — forked from jacobk/script.js
$(function() {
$('div.content').live('showoff:show', function(evt) {
var bg_img = $('img[alt=background]', evt.target);
var old_bg = '';
if (bg_img.size() > 0) {
var src = bg_img.attr('src');
bg_img.hide();
// Set new background on body
old_bg = $('body').css('background-image');
$('body')
/////// Homework 1 ///////
var logCar = function (car) {
car = car || {};
car.make = car.make || 'anonymous car';
car.color = car.color || 'uncolored';
var a = /^[aeiouy]/.test(this.color) ? 'an' : 'a';
console.log('I\'m ' + a + ' ' + car.color + ' ' + car.make);
};
var Person = function (name) {
this.name = name;
}
Person.prototype.getName = function () {
return this.name;
}
// 1. Write a class to support the following code:
<!-- 1. -->
<script type="text/javascript" charset="utf-8">
function log(string){
document.getElementById('log').innerHTML += (string + '<br/>');
}
document.getElementById('the_div').addEventListener(
'click', function(){ log('the_div!') }, true);
document.getElementById('the_list').addEventListener(
@wallin
wallin / multiple_touchdrag.html
Created September 17, 2011 14:24
Multiple drag n' drop for touch
<html>
<head>
<meta charset=utf-8 />
<title>Drag n' drop touch demo - sewa.se</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
.draggable {
position: absolute;
left: 30px;
@wallin
wallin / .gitconfig
Last active December 12, 2015 09:49
Useful git aliases
[color]
diff = auto
status = auto
branch = auto
[alias]
b = branch
ba = branch -a
ci = commit
co = checkout
d = diff
@wallin
wallin / ie-cors-fix.coffee
Created June 28, 2013 13:56
Drop-in jQuery-plugin for allowing cross domain ajax-calls in IE
$.ajaxTransport((options, originalOptions, jqXHR) ->
if window.XDomainRequest
xdr = null
return {
send: (headers, completeCallback) ->
# Match protocol since XDR doesn't allow differences
if 'http:' is document.location.protocol
options.url = options.url.replace('https:', 'http:')
xdr = new XDomainRequest()
@wallin
wallin / angular-configure-http.coffee
Created July 22, 2013 06:28
Configure HTTP headers in Angular JS
angular.module('myApp').config([
'$httpProvider'
($httpProvider) ->
# For all request types
$httpProvider.defaults.headers.common['Content-Type'] = 'application/json'
# For GET only
$httpProvider.defaults.headers.get['My-Header']='value'.
])
@wallin
wallin / http_text_response.coffee
Created October 9, 2013 08:43
Getting raw text response from Angular JS $http
# If you have an API that returns JSON but want the reponse as raw text you
# can override Angulars built in JSON response parser by using an identity
# function as response transformer function
$http.get("/myapi",
{ transformResponse: (d, h) -> return d } # return raw response
)
.success((data, status, headers) ->
# data is now pure text
alert("Response is text: #{angular.isString(data)}")
@wallin
wallin / angular-inputFocus.coffee
Created October 11, 2013 13:11
Angular JS directive that adds $focus attribute to form elements
angular.module('ui.inputFocus', []).directive "input", [->
restrict: "E"
require: '?^ngModel'
link: (scope, elm, attrs, ctrl) ->
return unless ctrl
ctrl.$focus = no
elm.focus ->
scope.$apply(-> ctrl.$focus = yes)
elm.blur ->
scope.$apply(-> ctrl.$focus = no)