Skip to content

Instantly share code, notes, and snippets.

View calvinmetcalf's full-sized avatar

Calvin Metcalf calvinmetcalf

View GitHub Profile
class PouchCore
constructor: (@remoteUrl,@onChange)->
if @remoteUrl.slice(0,4)=="http" #did we get a real url?
parts = @remoteUrl.split("/") #split the url bu by the slashes
@_dbName = parts.pop() #assign the last part as the db name
while @_dbName == "" #unless it is an empty string
@_dbName = parts.pop()#repeat until you find one
Pouch @_dbName, (e, db) => #making the local db
unless e #error would imply we are on an old browser
@db = db
add: (doc, cb = ()-> true) ->
unless "_id" of doc
@db.post doc, cb
else if "_id" of doc and doc._id.slice(0,8) != "_design/"
@db.put doc, cb
else if doc.length
@db.bulkDocs doc, cb
get: (id, cb = ()-> true) ->
@db.get id, cb
remove: (id, cb = ()-> true) ->
class PouchCore
constructor: (@remoteUrl,@onChange)->
if @remoteUrl.slice(0,4)=="http" #did we get a real url?
parts = @remoteUrl.split("/") #split the url bu by the slashes
@_dbName = parts.pop() #assign the last part as the db name
while @_dbName == "" #unless it is an empty string
@_dbName = parts.pop()#repeat until you find one
Pouch @_dbName, (e, db) => #making the local db
unless e #error would imply we are on an old browser
@db = db
class PouchCore
constructor: (@remoteUrl,@onChange)->
if @remoteUrl.slice(0,4)=="http" #did we get a real url?
parts = @remoteUrl.split("/") #split the url bu by the slashes
@_dbName = parts.pop() #assign the last part as the db name
while @_dbName == "" #unless it is an empty string
@_dbName = parts.pop()#repeat until you find one
Pouch @_dbName, (e, db) => #making the local db
unless e #error would imply we are on an old browser
@db = db
//instead of structuring them like this
$("#someID").on("click", function(e){
e.preventDefault();
doStuff();
});
//I had to hang it all of the main div
$("#body").on("click", "#someID", function(e){
e.preventDefault();
doStuff();
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pouch Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet"><!-- bootstrap css modified based on http://bootswatch.com/spacelab/-->
</head>
<body>
<div id="body"></div>
templateText = """<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="home" id="home">Pouch Demo</a>
<div class="nav-collapse collapse">
obj={}#this will store the data we get from pouch
converter = new Showdown.converter()
update = ->
window.views = {sideList : []}
if location.hash == ""
hash="home"
location.hash="home"
else if location.hash.slice(0,5) == '#edit'
hash = location.hash.slice(5)
views.edit = true
$ ()->
linkaction = (e)->
if e.target.id != ""# and "login" "logout"
location.hash = e.target.id
e.preventDefault()
update()
true
$("#body").on "click","a",linkaction
$("#body").on "click","#editable",(e)->
e.preventDefault()
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=1024, user-scalable=no">
<style>
html { height: 100% }
body { height: 100%; margin: 0; padding: 0;}
#map{ height: 100% }
</style>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css" />