Skip to content

Instantly share code, notes, and snippets.

View adamsilver's full-sized avatar

Adam Silver adamsilver

View GitHub Profile
@adamsilver
adamsilver / gist:2171308
Created March 23, 2012 14:43
Opting out generic bullet styles
li {
margin-bottom: 10px;
margin-left: 30px;
padding: 5px;
list-style: square;
font-size: 1.2em;
}
@adamsilver
adamsilver / gist:1564687
Created January 5, 2012 10:46
Quick plan for a potential new router style so that client side apps are more server-side like
/****************************************************************************************
* Router stuff
****************************************************************************************/
var Router = function() {
};
Router.prototype.triggerRoute = function(verb, path, actionFunction, params, id) {
switch(verb) {
@adamsilver
adamsilver / gist:1266908
Created October 6, 2011 09:07
Spec testing AJAX with Jasmine
describe("AjaxThingy", function () {
var successResponse = {
basket: {
itemCount: 2
}
}
describe("Requesting something", function () {
it("Makes an AJAX request", function () {
@adamsilver
adamsilver / gist:1266827
Created October 6, 2011 08:18
JavaScript namespacing example
//Jungle.js
var Jungle = {};
//Jungle.Global.js
Jungle.Global = {};
//Jungle.Global.AutoComplete.js
Jungle.Global.AutoComplete = {};
//Jungle.Global.AnotherGlobalComponent .js
@adamsilver
adamsilver / gist:1037427
Created June 21, 2011 07:54
Body class and id
<body id="pgPaymentInformation" class="checkout">
@adamsilver
adamsilver / gist:1022617
Created June 13, 2011 11:19
User Edit Controller
var App = App || {};
App.Controllers = App.Controllers || {};
App.Controllers.UserEdit = function() {
this.model = new App.Models.Users();
this.view = new App.Views.UserEdit();
App.Routes.addRoute("/users/:user_uuid/edit/", $.proxy(this.handleUserEditRoute, this));
// This is a little jQuery plugin that provides custom events
$.subscribe("UserEditFormSubmitted", $.proxy(this.handleFormSubmitted, this));
}
App.Controllers.UserList.prototype.handleUserEditRoute = function(params) {
@adamsilver
adamsilver / gist:1009887
Created June 6, 2011 07:40
User Edit Template
<script id="tmplUserEdit" type="text/x-jquery-tmpl">
<div id="userEdit">
<form>
<input type="hidden" name="uuid" value="${uuid}" />
<div class="field">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="${email}" />
</div>
<div class="field">
<label for="first_name">First name</label>
@adamsilver
adamsilver / gist:1009871
Created June 6, 2011 07:22
viewModel for single user record
{ "data": { "uuid": "123456", "first_name": "Adam", "last_name": "Silver" } } }
@adamsilver
adamsilver / gist:1009859
Created June 6, 2011 07:16
User Edit View
var App = App || {};
App.Views = App.Views || {};
App.Views.UserEdit = function() {
this.container = "#someContainer"; // a container where users edit will render into
}
App.Views.UserEdit.prototype.render = function(viewModel) {
var container = $(this.container);
// inject jQuery template into container
container.html($.tmpl($("#userEditTemplate").html(), viewModel));
container.find("form").bind("submit", $.proxy(this.handleFormSubmit, this));
//previous code
App.Models.User.prototype.getRecord = function(options) {
$.ajax({
type: "GET",
url: this.url + "/" options.uuid + ".json",
success: options.success
});
}