Skip to content

Instantly share code, notes, and snippets.

View samdelagarza's full-sized avatar

Sam De La Garza samdelagarza

View GitHub Profile
@samdelagarza
samdelagarza / 1.js
Created May 4, 2012 17:49 — forked from mxriverlynn/1.js
ajax command wrapper
var signForm = $.ajax({
type: "POST",
url: "/some/form",
dataType: "JSON",
data: myData
});
signForm.done(function(response){
// handle success here
});
@samdelagarza
samdelagarza / example-user.js
Created May 4, 2012 13:34 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
Backbone.View.extend({
template: 'my-view-template',
render: function () {
var deferred = new $.Deferred(),
promise = deferred.promise(),
that = this;
require('/templates/' + this.template + '.html', function (tmpl) {
deferred.resolve(that.$el.html(tmpl));
define([
// notice the text! prefix
// this tells require.js to
// use the text plugin to
// retrieve the template
'text!./myTemplate.htm'
], function(myTemplate){
// use your template here
});
geocoder.geocode( { 'address': unitOfWork}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = {};
result.address = unitOfWork.replace(/\+/g,' ');
result.location = results[0].geometry.location.b + ',' + results[0].geometry.location.c;
displayMarkerStack.push(results[0].geometry.location);
finishedStack.push(result);
$("body").trigger('addressComplete');
search.View = Backbone.View.extend({
events: {
"keydown input": "search"
},
search: function(event) {
this.trigger('search',"myq");
}
});
search.View = Backbone.View.extend({
events: {
"keydown input": "search"
},
search: function(event) {
var o = {};
_.extend(o,Backbone.Events);
o.trigger('route:search');
// Modeling
{
"Operator": "",
"ColumnName": "",
"Value": "",
"RelationshipToPreviousSibling": "",
"Attributes": {
"ModelId": "3e267d46-343b-4f76-9774-3537d425f3e5"
},
(function (models) {
models.Contract = Backbone.Model.extend({
Value: "",
Text: ""
});
}(widgets.models = widgets.models || {}));
// events simply proxy through.
_onModelEvent : function(ev, model) {
if (ev === 'change:id') {
delete this._byId[model.previous('id')];
this._byId[model.id] = model;
}
this.trigger.apply(this, arguments);
}
});