Skip to content

Instantly share code, notes, and snippets.

@tkh44
tkh44 / AddGuest.js
Last active December 21, 2015 23:38
search ion
search: _.debounce(function(e) {
var self = this,
$noResults = this.$('.empty-state'),
$loading = this.$('.loading-state'),
contacts = Mast.data.contacts,
value = $.trim(e.currentTarget.value),
data;
if (value.length < 1) {
self.collection.reset();
@tkh44
tkh44 / ContactsCollection.js
Created August 30, 2013 19:45
Local PhoneGap contacts to Backbone collection
(function() {
// Attach to namespaced window object
window.ioffice = window.ioffice || {};
ioffice.collections = ioffice.collections || {};
ioffice.collections.contacts = Backbone.Collection.extend({
model: Backbone.Model,
getContacts: function(filter, cb) {
@tkh44
tkh44 / ContactsCollection.js
Last active December 22, 2015 10:18
Abuse underscore
self.reset(_.map(_.filter(contacts, function(contact) {
return contact.emails && contact.emails.length;
}), function(contact) {
var name = contact.name,
email;
email = _.findWhere(contact.emails, {'type': 'work'}) || contact.emails[0];
return {
firstName: name.givenName || '',
@tkh44
tkh44 / backbone-phonegapcontacts.js
Created September 9, 2013 17:51
Phonegap contacts as backbone collection store
var PhonegapContactStore = function(){};
_.extend(PhonegapContactStore.prototype,{
create: $.noop,
update: $.noop,
find: function(data, cb) {
// If we are not on device with contacts just return callback
if (typeof ContactFindOptions === "undefined") {
if (cb) cb();
return;
@tkh44
tkh44 / AddGuest.js
Created September 11, 2013 17:53
wtf mate
search: function(e) {
var $input = this.$('input[name="contact"]'),
self = this;
$input.addClass('loading');
_.debounce(function(e) {
var $emptySearch = self.$('.empty-search'),
$noRecentGuests = self.$('no-recent-guests'),
users = self.users,
@tkh44
tkh44 / utils.js
Last active December 25, 2015 05:39
Utility to give a meaningful error from backbone xhr.
digestXHR: function(xhr) {
return xhr.status + ' ' + xhr.statusText + '\nResponse text: ' + (xhr.responseText.length > 0 ? xhr.responseText : 'No response.');
}
var tacoApp = angular.module('tacoApp', ['TacoModel', 'hmTouchevents']);
// Index: http://localhost/views/taco/index.html
tacoApp.controller('IndexCtrl', function ($scope, TacoRestangular) {
// This will be populated with Restangular
$scope.tacos = [];
// The contents of individual model .js files will be concatenated into dist/models.js
(function() {
// Protects views where angular is not loaded from errors
if ( typeof angular == 'undefined' ) {
return;
};
module.exports = function(grunt) {
'use strict';
grunt.loadNpmTasks('grunt-sails-linker');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
dev: {
files: [
@tkh44
tkh44 / AutoComplete.js
Last active December 27, 2015 03:09
Small AutoComplete Library for doing live searches using Backbone collections and JST templates. It uses a basic localStorage cache to try to reduce requests. We use hammer.js for the 'tap' event since we use this is mostly for mobile.
;(function($, window, document, undefined) {
var pluginName = 'AutoComplete',
defaults = {
list: '.auto-complete-list',
cancel: '.auto-complete-cancel',
itemSelector: '.auto-complete-item',
dataId: 'auto-val-set',
valueAttr: 'name',
valueId: 'id',