24 |
├── .gitignore ├── README.md ├── _attachments ├── images │ └── icon.png ├── index.html ├── script │ ├── app.js │ └── md5.js └── style │ ├── iphone.css │ └── main.css ├── evently ├── profile │ ├── loggedOut │ │ └── mustache.html │ └── profileReady │ │ ├── mustache.html │ │ └── selectors │ │ └── form │ │ └── submit.js ├── replies │ └── _init │ │ ├── mustache.html │ │ └── selectors │ │ ├── form │ │ └── submit.js │ │ └── ul │ │ └── _changes │ │ ├── data.js │ │ ├── mustache.html │ │ ├── query.js │ │ └── render.txt ├── tagcloud │ └── _changes │ │ ├── data.js │ │ ├── mustache.html │ │ └── query.json ├── tasks │ ├── mentions │ │ ├── path.txt │ │ └── selectors │ │ │ └── ul │ │ │ └── _changes │ │ │ └── query.js │ ├── recent │ │ ├── mustache.html │ │ ├── path.txt │ │ └── selectors │ │ │ └── ul │ │ │ └── _changes │ │ │ ├── data.js │ │ │ ├── mustache.html │ │ │ ├── query.json │ │ │ ├── render.txt │ │ │ └── selectors │ │ │ ├── a[href=#done] │ │ │ └── click.js │ │ │ └── a[href=#reply] │ │ │ └── click.js │ ├── tags │ │ ├── path.txt │ │ └── selectors │ │ │ └── ul │ │ │ └── _changes │ │ │ └── query.js │ └── users │ │ ├── path.txt │ │ └── selectors │ │ └── ul │ │ └── _changes │ │ └── query.js └── usercloud │ └── _changes │ ├── data.js │ ├── mustache.html │ └── query.json ├── validate_doc_update.js ├── vendor ├── couchapp │ ├── README.md │ ├── _attachments │ │ ├── docs.css │ │ ├── docs.html │ │ ├── docs.js │ │ ├── jquery.couch.app.js │ │ ├── jquery.couch.app.util.js │ │ ├── jquery.evently.js │ │ ├── jquery.mustache.js │ │ ├── jquery.pathbinder.js │ │ └── loader.js │ ├── docs │ │ ├── account.md │ │ ├── couchapp.md │ │ ├── docs.md │ │ ├── evently.md │ │ ├── pathbinder.md │ │ └── profile.md │ ├── evently │ │ ├── README.md │ │ ├── account │ │ │ ├── _init.js │ │ │ ├── adminParty │ │ │ │ └── mustache.html │ │ │ ├── doLogin.js │ │ │ ├── doLogout.js │ │ │ ├── doSignup.js │ │ │ ├── loggedIn │ │ │ │ ├── data.js │ │ │ │ ├── mustache.html │ │ │ │ └── selectors.json │ │ │ ├── loggedOut │ │ │ │ ├── mustache.html │ │ │ │ └── selectors.json │ │ │ ├── loginForm │ │ │ │ ├── after.js │ │ │ │ ├── mustache.html │ │ │ │ └── selectors │ │ │ │ │ ├── a[href=#signup].json │ │ │ │ │ └── form │ │ │ │ │ └── submit.js │ │ │ └── signupForm │ │ │ │ ├── after.js │ │ │ │ ├── mustache.html │ │ │ │ └── selectors │ │ │ │ ├── a[href=#login].json │ │ │ │ └── form │ │ │ │ └── submit.js │ │ ├── docs │ │ │ ├── index │ │ │ │ ├── data.js │ │ │ │ ├── mustache.html │ │ │ │ └── path.txt │ │ │ └── topic │ │ │ │ ├── after.js │ │ │ │ ├── data.js │ │ │ │ ├── edit │ │ │ │ └── _init │ │ │ │ │ ├── fun.js │ │ │ │ │ └── selectors │ │ │ │ │ ├── a.edit │ │ │ │ │ └── click.js │ │ │ │ │ └── a.run │ │ │ │ │ └── click.js │ │ │ │ ├── mustache.html │ │ │ │ └── path.txt │ │ └── profile │ │ │ ├── loggedIn.js │ │ │ ├── loggedOut │ │ │ ├── after.js │ │ │ └── mustache.html │ │ │ ├── noProfile │ │ │ ├── data.js │ │ │ ├── mustache.html │ │ │ └── selectors │ │ │ │ └── form │ │ │ │ └── submit.js │ │ │ └── profileReady │ │ │ ├── after.js │ │ │ ├── data.js │ │ │ └── mustache.html │ ├── lib │ │ ├── atom.js │ │ ├── cache.js │ │ ├── docform.js │ │ ├── list.js │ │ ├── markdown.js │ │ ├── md5.js │ │ ├── path.js │ │ └── redirect.js │ └── metadata.json └── showdown │ ├── _attachments │ └── showdown.js │ └── showdown-licenese.txt └── views ├── mentions └── map.js ├── recent-tasks └── map.js ├── tag-cloud ├── map.js └── reduce.js ├── task-replies └── map.js ├── user-cloud ├── map.js └── reduce.js ├── userProfile └── map.js └── users-tasks └── map.js /.gitignore: -------------------------------------------------------------------------------- 1 | .couchapprc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## A simple group todo app. 2 | 3 | ## Features 4 | 5 | * Realtime group updates across ad-hoc clusters. 6 | * Twitter-style @names and #hashtag browsing. 7 | 8 | [Introductory screencast here.](http://www.youtube.com/watch?v=qJbfRZz6qNY) 9 | 10 | ## Running 11 | 12 | Right now the easiest way to run this is to clone and deploy the checkout with [CouchApp](http://github.com/couchapp/couchapp). 13 | 14 | I'm working on some code to make [sharing CouchApps a breeze](http://github.com/jchris/garden). 15 | 16 | You can get help at the [CouchApp mainling list](http://groups.google.com/group/couchapp). 17 | 18 | ## Contribute 19 | 20 | I could use some help making the replies feature more useful. Maybe a mode where users can toggle hashtags on and off and refresh the view, so you can watch multiple channels, but not all of them. 21 | 22 | Also, it'd be fun to see different skins for this, like back in the day. 23 | 24 | And bugfixes, of course. For development help, I'm on the [#evently](http://search.twitter.com/search?q=evently) hashtag. 25 | -------------------------------------------------------------------------------- /_attachments/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jchris/taskr/164d1ae244d2b29ea75a16acb2fdf69fa143da0f/_attachments/images/icon.png -------------------------------------------------------------------------------- /_attachments/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Please log in to add tasks.
-------------------------------------------------------------------------------- /evently/profile/profileReady/mustache.html: -------------------------------------------------------------------------------- 1 |Leave a reply:
5 | 10 |{{json}}", 23 | data : function() { 24 | var widget = app.ddoc.vendor.couchapp.evently.account; 25 | return { 26 | json : JSON.stringify(widget, null, 2) 27 | } 28 | } 29 | } 30 | }); 31 | }); 32 | 33 | The top level keys are the most important: `loggedIn`, `loggedOut`, `adminParty`, `signupForm`, `loginForm`, `doLogin`, `doSignup`, and `_init`. Each one of these corresponds to an event or state the system can be in. Some of them draw user interface elements, other directly trigger further events. 34 | 35 | ### _init 36 | 37 | The `_init` event is special, in that Evently will automatically trigger it when the widget is created. Here is the code for the account widget's `_init` event handler. 38 | 39 | function() { 40 | var elem = $(this); 41 | $.couch.session({ 42 | success : function(r) { 43 | var userCtx = r.userCtx; 44 | if (userCtx.name) { 45 | elem.trigger("loggedIn", [r]); 46 | } else if (userCtx.roles.indexOf("_admin") != -1) { 47 | elem.trigger("adminParty"); 48 | } else { 49 | elem.trigger("loggedOut"); 50 | }; 51 | } 52 | }); 53 | } 54 | 55 | This code does one query to CouchDB, to retrieve the session information for the current user. For this we use the `$.couch.session()` function which is part of the [jquery.couch.js](/_utils/script/jquery.couch.js) library which is part of the CouchDB distribution. 56 | 57 | The response is handled in one of three ways, depending on the user's session information. Either we trigger the `loggedIn` or `loggedOut` events, or in the special case where we detect that CouchDB's security is not properly configured, we trigger the `adminParty` event to warn the user. 58 | 59 | ### loggedOut 60 | 61 | Because most visitors start logged out, let's now turn our attention to the `loggedOut` event handler to see what will greet a new visitor: 62 | 63 | "loggedOut": { 64 | "mustache": "Signup or Login", 65 | "selectors": { 66 | "a[href=#login]": { 67 | "click": "loginForm" 68 | }, 69 | "a[href=#signup]": { 70 | "click": "signupForm" 71 | } 72 | } 73 | } 74 | 75 | There are two main components to this handler: `mustache` and `selectors`. `mustache` is a template file with two HTML links. `selectors` contains a set of CSS selectors with events bound to them. You can think of each selector as a nested Evently widget. In this case, clicking "Login" will trigger the `loginForm` event, while clicking "Signup" triggers the `signupForm` event. 76 | 77 | ### signupForm 78 | 79 | Let's see what happens during signup. We'll skip showing the whole handler (it should be in the sidebar anyway if you clicked "run" earlier.) 80 | 81 | When the `signupForm` event is triggered, a mustache template draws the form. Then the selectors are run, assigning this function to the form's submit event: 82 | 83 | function(e) { 84 | var name = $('input[name=name]', this).val(), 85 | pass = $('input[name=password]', this).val(); 86 | $(this).trigger('doSignup', [name, pass]); 87 | return false; 88 | } 89 | 90 | This handler is as simple as possible, all it does is use jQuery to pull the user data from the form, and send the name and password to the `doSignup` event. We could just use a function call here, but it's nice to keep our individual events as small as possible, as this makes customizing Evently widgets simpler. 91 | 92 | ### doSignup 93 | 94 | Here is the `doSignup` handler: 95 | 96 | function(e, name, pass) { 97 | var elem = $(this); 98 | $.couch.signup({ 99 | name : name 100 | }, pass, { 101 | success : function() { 102 | elem.trigger("doLogin", [name, pass]); 103 | } 104 | }); 105 | } 106 | 107 | Again, all the complex signup logic (encrypting passwords, etc) is pushed to the [jquery.couch.js](/_utils/script/jquery.couch.js) library (via the `$.couch.signup()` call), so our application code can stay as simple as possible. When signup is complete, we trigger the `doLogin` event, so new users don't have to go through another action. 108 | 109 | ### doLogin 110 | 111 | The code for `doLogin` isn't much different, just take the name and password, and call a jquery.couch.js library function with it. 112 | 113 | function(e, name, pass) { 114 | var elem = $(this); 115 | $.couch.login({ 116 | name : name, 117 | password : pass, 118 | success : function(r) { 119 | elem.trigger("_init") 120 | } 121 | }); 122 | } 123 | 124 | The last thing that `doLogin` does is trigger `_init`, so we come full circle! This time, `_init` will see that the user is logged in, and trigger the `loggedIn` event. You'll probably want to hook your application to this `loggedIn` event, to activate any features which are reserved for registered users. We'll cover linking events in a later section. 125 | 126 | ## Customizing the account widget 127 | 128 | Evently widgets are built out of JSON objects, which makes it easy to replace bits and pieces of them without having to mess with the entire widget. We'll start by customizing what users see when they are logged in. 129 | 130 | $.couch.app(function(app){ 131 | var customizedWidget = $.extend(true, {}, app.ddoc.vendor.couchapp.evently.account, { 132 | loggedIn : { 133 | mustache : 'Hello {{name}} you are logged in! ' + 134 | 'Would you like to logout?' 135 | } 136 | }); 137 | $("#customWelcome").evently(customizedWidget); 138 | }); 139 | 140 | Take a moment to run this example code and login to see how our custom template has replaced just one screen in the widget. The first time I did this I thought it was pretty cool. Hopefully you can think of a lot of powerful stuff you could do with it. The sky is the limit. 141 | 142 | Here's another quick one: 143 | 144 | $.couch.app(function(app){ 145 | var customizedWidget = $.extend(true, {}, app.ddoc.vendor.couchapp.evently.account, { 146 | loggedOut : { 147 | after : "function(){alert('Bye bye');}" 148 | } 149 | }); 150 | $("#afterAlert").evently(customizedWidget); 151 | }); 152 | 153 | For a deeper reference on what the various parts of an Evently widget are named, and how you can use them, see [the Evently docs page](#/topic/evently). 154 | 155 | ## Linking two widgets 156 | 157 | First, lets create a basic widget. This one just has an `_init` handler and a handler called `loggedIn`. There is nothing in this widget definition that will trigger `loggedIn`, unless something else triggers it, there's no way it will run. 158 | 159 | $("#link_target").evently({ 160 | _init : { 161 | mustache : "
Not much to see here
" 162 | }, 163 | loggedIn : { 164 | mustache : "loggedIn was triggered from another widget, {{name}}.
", 165 | data : function(e, r) { 166 | return { name : r.userCtx.name }; 167 | } 168 | } 169 | }); 170 | 171 | Be sure to run the above example code before the next one, otherwise there won't be anything to link to. 172 | 173 | This next block of code demonstrates how to link two widgets together. First we create a normal account widget on the `#link_source` element, then we tell Evently to connect it to the `#link_target` element. Now whenever the `loggedIn` evenr is triggered on the source, it will be triggered on the target. 174 | 175 | $.couch.app(function(app){ 176 | $("#link_source").evently(app.ddoc.vendor.couchapp.evently.account); 177 | // link the source to the target, for the loggedIn event 178 | $.evently.connect($("#link_source"), $("#link_target"), ["loggedIn"]); 179 | }); 180 | 181 | ## Conclusion 182 | 183 | If you are writing a CouchApp that will have users logging and and logging out, you'd do well to use the account widget. It's customizable and linkable. And what's more, it's code that's already written. 184 | 185 | Enjoy! 186 | 187 | -------------------------------------------------------------------------------- /vendor/couchapp/docs/couchapp.md: -------------------------------------------------------------------------------- 1 | # Docs for $.couch.app 2 | 3 | The simplest use of CouchApp in the browser is to get access to information about the database you are running in. 4 | 5 | $.couch.app(function(app) { 6 | $("#dbinfo").evently({ 7 | _init : { 8 | mustache : 'The db name is {{name}}
', 9 | data : app.db 10 | } 11 | }); 12 | }); 13 | 14 | Yay couchapp. 15 | 16 | The `$.couch.app()` function also loads the current design document so that it is available for templates etc. That is how the words you are reading were loaded. This file is included in the CouchApp application library. Let's look at the design doc: 17 | 18 | $.couch.app(function(app) { 19 | $("#ddoc").evently({ 20 | _init : { 21 | mustache : 'Click to show the full doc source:
{{ddoc}}', 22 | data : { 23 | ddoc : JSON.stringify(app.ddoc, null, 2).slice(0,100) + '...' 24 | } 25 | }, 26 | click : { 27 | mustache : '
The full doc source (rerun to hide):
{{ddoc}}', 28 | data : { 29 | ddoc : JSON.stringify(app.ddoc, null, 2) 30 | } 31 | } 32 | }); 33 | }); 34 | 35 | -------------------------------------------------------------------------------- /vendor/couchapp/docs/docs.md: -------------------------------------------------------------------------------- 1 | # Docs for the docs system. 2 | 3 | You are encouraged to use the couchapp docs system to write documentation for your plugins and applications. Extra bonus points because it's fun. 4 | 5 | Docs automatically make divs based on `$("#foo")` pattern matching. That is, we regex the code looking for the first id we see referenced. Remember ids need to be unique on a page. For doc examples you only get one id. 6 | 7 | Example Code: 8 | 9 | $("#hide_foo").hide("slow"); 10 | 11 | That's all it takes. You only get one div in each example for now. Have fun! -------------------------------------------------------------------------------- /vendor/couchapp/docs/evently.md: -------------------------------------------------------------------------------- 1 | # Evently Docs 2 | 3 | Evently is an declarative framework for evented jQuery applications. You write your code as widgets made up of templates and callbacks, while Evently handles the busywork of linking them together. 4 | 5 | Evently has special handlers for CouchDB views and `_changes` feeds, and could be easily extended for other server-side frameworks. 6 | 7 | ## Hello World 8 | 9 | At it's simplest an Evently widget is a set of events connected to a single DOM element. 10 | 11 | JavaScript: 12 | 13 | $("#hello").evently({ 14 | _init : { 15 | mustache : "
Hello world
", 16 | }, 17 | click : { 18 | mustache : "What a crazy world!
", 19 | } 20 | }); 21 | 22 | You can also do some more interesting things: 23 | 24 | $("#heyjane").evently({ 25 | _init : { 26 | mustache : '', 27 | selectors : { 28 | 'a[href=#joan]' : { 29 | click : 'hiJoan' 30 | }, 31 | 'a[href=#jane]' : { 32 | click : 'hiJane' 33 | } 34 | } 35 | }, 36 | hiJoan : { 37 | mustache : 'Hello Joan!
' 38 | }, 39 | hiJane : { 40 | mustache : "Darn, it's Jane...
", 41 | after : function() { 42 | setTimeout(function() { 43 | // automatically trigger the "janeRocks" event after 2 seconds. 44 | $("#heyjane").trigger("janeRocks"); 45 | }, 2000); 46 | } 47 | }, 48 | janeRocks : { 49 | render : "append", 50 | mustache : "Actually Jane is awesome.
" 51 | } 52 | }); 53 | 54 | 55 | The imporant thing about this is that the widget is defined by an JavaScript object. This means we can save it as files on our hard drive and `couchapp` will handle saving it as a JSON object for us. 56 | 57 | [screenshot of the above code in textmate's file drawer] 58 | 59 | When we let CouchApp package our evently apps we get to work on them in individual files, instead of as a great big giant mess of JavaScript. This means HTML is HTML, JSON is JSON, and JavaScript is JavaScript. Yay! 60 | 61 | ## Ajax Hello World 62 | 63 | Let's do a little Ajax. We'll just load the version of the CouchDB instance we happen to be serving our HTML from: 64 | 65 | $("#ajax").evently({ 66 | _init : { 67 | mustache : 'Loading CouchDB server info.
', 68 | after : function() { 69 | var widget = $(this); 70 | $.ajax({ 71 | url : '/', 72 | complete : function(req) { 73 | var resp = $.httpData(req, "json"); 74 | widget.trigger("version", [resp]); 75 | } 76 | }) 77 | } 78 | }, 79 | version : { 80 | mustache : "Running CouchDB version {{version}}
", 81 | data : function(e, resp) { 82 | return resp; 83 | } 84 | } 85 | }); 86 | 87 | Explain `mustache` and `data` 88 | 89 | -- triggering other events 90 | -- selectors 91 | -- create a doc 92 | 93 | ## Evently and CouchApp together 94 | 95 | Evently makes it easy to write decoupled JavaScript code, but as the examples above show, Evently widgets can turn into a lot of JSON to look at all on one screen. Because Evently code is declarative, and each handler and callback stands on its own (instead of being wrapped in a common closure), it can be broken out into individual files. 96 | 97 | CouchApp provides a mechanism for mapping between individual files and JSON structures. In this model a directory structure is mapped to a JSON object. So if you have a directory structure like: 98 | 99 | _init/ 100 | mustache.html 101 | selectors/ 102 | form/ 103 | submit.js 104 | input.name/ 105 | change.js 106 | a.cancel/ 107 | click.txt 108 | cancelled/ 109 | mustache.html 110 | selectors/ 111 | a.continue/ 112 | click.txt 113 | 114 | It will appear within your CouchApp design document as: 115 | 116 | { 117 | _init : { 118 | mustache : "contents of mustache.html", 119 | selectors { 120 | form : { 121 | submit : "function() { ... }" 122 | }, 123 | "input.name" { 124 | change : "function() { ... }" 125 | }, 126 | "a.cancel" { 127 | click : "cancelled" 128 | } 129 | } 130 | }, 131 | cancelled : { 132 | mustache : "contents of mustache.html", 133 | selectors : { 134 | "a.continue" : { 135 | click : "_init" 136 | } 137 | } 138 | } 139 | } 140 | 141 | This makes Evently and CouchApp a natural fit for each other. I swear I didn't plan this when I started writing Evently, it just turned out to be an awesome side effect of trying to stay as close to JSON as possible. 142 | 143 | In the [account widget tutorial](#/topic/account) we see the details of the account widget. What isn't discussed much there, is how the code is edited on your filesystem. 144 | 145 | If you are writing an Evently CouchApp widget you can edit the individual pieces on your filesystem. This has the added advantage of giving you native syntax highlighting for all the code. Instead of editing everything as JSON or JavaScript, the templates can be treated as HTML, the paths as text, etc. 146 | 147 | ## Evently Queries 148 | 149 | Evently understands CouchDB in a couple of very simple ways. If you know CouchDB, you're probably familiar with its Map Reduce views. Evently lets you specify view queries in a declarative way, and even takes care of the Ajax request. All you have to do is write code to handle the returned data. 150 | 151 | -- new rows, etc 152 | 153 | -- run a query 154 | 155 | -- connect to changes 156 | 157 | -- links to example apps 158 | 159 | ## Freeform Asynchronous Actions 160 | 161 | Watch out, you're dangerous! Evently allows you to make any old asyncronous action you want, with the `widget.async` member. The callback is the first argument to the `async` function. Check it out: 162 | 163 | $("#async").evently({ 164 | _init : { 165 | mustache : "How many databases on the local host?
Answer: {{number_of_dbs}}
Other stuff: {{args}}
More: {{allArgs}}
", 166 | async : function(cb) { 167 | var ag = Array.prototype.slice.call(arguments).map(function(a){return a.toSource ? a.toSource() : a}); 168 | $.couch.allDbs({ 169 | success : function(resp) { 170 | cb(resp.length, ag); 171 | } 172 | }) 173 | }, 174 | data : function(count, args) { 175 | return { 176 | number_of_dbs : count, 177 | args : JSON.stringify(args), 178 | allArgs : JSON.stringify(Array.prototype.slice.call(arguments)) 179 | }; 180 | } 181 | }, 182 | click : { 183 | mustache : "What a crazy world!
", 184 | } 185 | }); -------------------------------------------------------------------------------- /vendor/couchapp/docs/pathbinder.md: -------------------------------------------------------------------------------- 1 | # Docs about $.pathbinder 2 | 3 | Pathbinder is a tiny framework for triggering events based on paths in URL hash. For example, you might want to render one panel when the user clicks a link to `#/foo` and another when the URL hash changes to `#/bar`. If you've never used URL hashes for application state in an Ajax app before, prepare to be happy. 4 | 5 | There are two big advantages to having the state in the URL-hash. One is that users can bookmark screens they may have reached by navigating within your app. The other is that the back button will continue to work. 6 | 7 | The page you are on has a URL hash of `#/topic/pathbinder` right now. You can follow links to other "pages" within this application, and Pathbinder takes care of triggering the proper events. 8 | 9 | ## A simple example 10 | 11 | $("#basic_path").html(''); 12 | $("#basic_path").bind("foo", function() { 13 | $(this).html("you went to foo
"); 14 | }); 15 | $("#basic_path").pathbinder("foo", "/foo"); 16 | 17 | This code sets up the `#basic_path` div with some initial content, including a link to `#/foo`. If you click the link to foo, you'll see the URL change. It is the changed URL which Pathbinder sees and uses to trigger any running code. You can experiment by manually entering the `#/foo` URL hash, instead of clicking the link, and you'll see that it also triggers the `foo` event. 18 | 19 | ## Using path parameters 20 | 21 | Pathbinder was inspired by the path handling in [Sammy.js](http://github.com/aq/sammy.js). Like Sammy, you can use it to pull parameters from the URL-hash. This page can be linked [using a path that has "pathbinder" as a parameter](#/topic/pathbinder). Let's explore how you can pull parameters out of a path. 22 | 23 | $("#param_path").html(''); 24 | $("#param_path").bind("foo", function(e, params) { 25 | $(this).html("you went to foo - "+params.id+"
"); 26 | }); 27 | $("#param_path").pathbinder("foo", "/foo/:id"); 28 | 29 | When you click the link to super foo, you'll see the param is passed through the event. You can also edit the URL to see that "super" is not hard coded and can be replaced with other values. 30 | 31 | ## Pathbinder with Evently 32 | 33 | It should be no suprise that Pathbinder and Evently play well together. The gist of it is that Evently looks for a key called `path` and if it finds it, uses Pathbinder to connect that event handler to the path. Let's try it out: 34 | 35 | $("#evently_path").evently({ 36 | _init : { 37 | path : '/index', 38 | mustache : 'the index. more cowbell!
' 39 | }, 40 | cowbell : { 41 | path : '/cowbell', 42 | mustache : 'Now that is a lot of cowbell. back to the index
' 43 | } 44 | }); 45 | 46 | Note that when you use an Evently path, Evently also takes care to visit the path when the corresponding event is triggered. So running the above example code (which automatically triggers the `_init` event) will set the hash to `#/index`. If you were to trigger the `cowbell` event through non-path means, you'd see that it changes the path to `#/cowbell` anyway. 47 | 48 | ### Too many widgets 49 | 50 | One thing worth noting: there is only one URL hash for any given page, so be aware that if you have multiple widgets competing for the real-estate, they could conflict with each other. Pathbinder won't do anything when presented with a path it doesn't care about (go ahead, try out some non-sense ones on this page). 51 | 52 | This means that if you have a few widgets all using the path, the page should still behave in a useful way. However, this breaks down if you intend people to be able to use the URL hash to link to page state. Since there can be only one URL hash, whichever action they took last will be reflected in the bookmarked URL. For this reason it makes sense to limit yourself to one path-based Evently widget per page. 53 | -------------------------------------------------------------------------------- /vendor/couchapp/docs/profile.md: -------------------------------------------------------------------------------- 1 | # docs for the profile evently widget 2 | 3 | This widget makes it easy to give users a profile for your application. -------------------------------------------------------------------------------- /vendor/couchapp/evently/README.md: -------------------------------------------------------------------------------- 1 | ## Starting the Document this code challenge 2 | 3 | I need help on this code. I only have so many hours in the day. Please be liberal about patching and hacking (and sharing code!) so we can all benefit. 4 | 5 | Docs patches are deeply appreciated. For now you can just stick Markdown files in the Docs directory. 6 | 7 | # Evently 8 | 9 | These are some vendor Evently widgets that are running on the CouchApp system. 10 | 11 | ## Account 12 | This is how you signup, login and logout without worry about the code. 13 | Todo, we could have this work against remote APIs like that Facebook stuff or whatever. 14 | 15 | 16 | ## Profile 17 | Use this to load the local users profile for the logged in user. Useful if you're going to be posting new messages. Most applications end up customizing `profile.profileReady` to render the primary data-entry form. This gets you benefits like refreshing on login / logout, etc, automatically. 18 | 19 | 20 | ## Docs 21 | This needs to be moved to it's own app. 22 | I have this vision of a docs app designed for offline editing, that involves each Markdown paragraph being it's own document, with automatic use of Bespin for code samples. Any help on this would be thanked much. 23 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/_init.js: -------------------------------------------------------------------------------- 1 | function() { 2 | var elem = $(this); 3 | $.couch.session({ 4 | success : function(r) { 5 | var userCtx = r.userCtx; 6 | if (userCtx.name) { 7 | elem.trigger("loggedIn", [r]); 8 | } else if (userCtx.roles.indexOf("_admin") != -1) { 9 | elem.trigger("adminParty"); 10 | } else { 11 | elem.trigger("loggedOut"); 12 | }; 13 | } 14 | }); 15 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/adminParty/mustache.html: -------------------------------------------------------------------------------- 1 |Admin party, everyone is admin! Fix this in Futon before proceeding.
-------------------------------------------------------------------------------- /vendor/couchapp/evently/account/doLogin.js: -------------------------------------------------------------------------------- 1 | function(e, name, pass) { 2 | var elem = $(this); 3 | $.couch.login({ 4 | name : name, 5 | password : pass, 6 | success : function(r) { 7 | elem.trigger("_init") 8 | } 9 | }); 10 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/doLogout.js: -------------------------------------------------------------------------------- 1 | function() { 2 | var elem = $(this); 3 | $.couch.logout({ 4 | success : function() { 5 | elem.trigger("_init"); 6 | } 7 | }); 8 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/doSignup.js: -------------------------------------------------------------------------------- 1 | function(e, name, pass) { 2 | var elem = $(this); 3 | $.couch.signup({ 4 | name : name 5 | }, pass, { 6 | success : function() { 7 | elem.trigger("doLogin", [name, pass]); 8 | } 9 | }); 10 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loggedIn/data.js: -------------------------------------------------------------------------------- 1 | function(e, r) { 2 | return { 3 | name : r.userCtx.name, 4 | uri_name : encodeURIComponent(r.userCtx.name), 5 | auth_db : encodeURIComponent(r.info.authentication_db) 6 | }; 7 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loggedIn/mustache.html: -------------------------------------------------------------------------------- 1 | Welcome 2 | {{name}}! 3 | Logout? 4 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loggedIn/selectors.json: -------------------------------------------------------------------------------- 1 | { 2 | "a[href=#logout]" : {"click" : ["doLogout"]} 3 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loggedOut/mustache.html: -------------------------------------------------------------------------------- 1 | Signup or Login -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loggedOut/selectors.json: -------------------------------------------------------------------------------- 1 | { 2 | "a[href=#signup]" : {"click" : ["signupForm"]}, 3 | "a[href=#login]" : {"click" : ["loginForm"]} 4 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loginForm/after.js: -------------------------------------------------------------------------------- 1 | function() { 2 | $("input[name=name]", this).focus(); 3 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loginForm/mustache.html: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loginForm/selectors/a[href=#signup].json: -------------------------------------------------------------------------------- 1 | {"click" : ["signupForm"]} -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/loginForm/selectors/form/submit.js: -------------------------------------------------------------------------------- 1 | function(e) { 2 | var name = $('input[name=name]', this).val(), 3 | pass = $('input[name=password]', this).val(); 4 | $(this).trigger('doLogin', [name, pass]); 5 | return false; 6 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/signupForm/after.js: -------------------------------------------------------------------------------- 1 | function() { 2 | $("input[name=name]", this).focus(); 3 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/signupForm/mustache.html: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/signupForm/selectors/a[href=#login].json: -------------------------------------------------------------------------------- 1 | {"click" : ["loginForm"]} -------------------------------------------------------------------------------- /vendor/couchapp/evently/account/signupForm/selectors/form/submit.js: -------------------------------------------------------------------------------- 1 | function(e) { 2 | var name = $('input[name=name]', this).val(), 3 | pass = $('input[name=password]', this).val(); 4 | $(this).trigger('doSignup', [name, pass]); 5 | return false; 6 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/docs/index/data.js: -------------------------------------------------------------------------------- 1 | function() { 2 | var docs = $$(this).app.ddoc.vendor.couchapp.docs; 3 | var dnames = []; 4 | $.forIn(docs, function(d) { 5 | dnames.push({ 6 | title: d, 7 | href : "#/topic/"+encodeURIComponent(d) 8 | }); 9 | }); 10 | return {docs:dnames}; 11 | }; -------------------------------------------------------------------------------- /vendor/couchapp/evently/docs/index/mustache.html: -------------------------------------------------------------------------------- 1 |Error running #', id, 5 | ' code block:
', 6 | (y.toSource ? y.toSource() : JSON.stringify(y)), 7 | ''].join('')); 8 | } 9 | var id = e.data.args[1]; 10 | var example = $("#code-"+id); 11 | var js = $('textarea',example).val() || $('pre',example).text(); 12 | $('#'+id).unbind(); 13 | try { 14 | eval(js); 15 | } catch (y) { 16 | err(y, id); 17 | } 18 | } catch(x) { 19 | err(x, id); 20 | } 21 | return false; 22 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/docs/topic/mustache.html: -------------------------------------------------------------------------------- 1 |
Please log in to see your profile.
-------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/noProfile/data.js: -------------------------------------------------------------------------------- 1 | function(e, userCtx) { 2 | return userCtx; 3 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/noProfile/mustache.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/noProfile/selectors/form/submit.js: -------------------------------------------------------------------------------- 1 | function() { 2 | var md5 = $$(this).app.require("vendor/couchapp/lib/md5"); 3 | 4 | // TODO this can be cleaned up with docForm? 5 | // it still needs the workflow to edit an existing profile 6 | var name = $("input[name=userCtxName]",this).val(); 7 | var newProfile = { 8 | rand : Math.random().toString(), 9 | nickname : $("input[name=nickname]",this).val(), 10 | email : $("input[name=email]",this).val(), 11 | url : $("input[name=url]",this).val() 12 | }, widget = $(this); 13 | 14 | // setup gravatar_url 15 | if (md5) { 16 | newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon'; 17 | } 18 | 19 | // store the user profile on the user account document 20 | $.couch.userDb(function(db) { 21 | var userDocId = "org.couchdb.user:"+name; 22 | db.openDoc(userDocId, { 23 | success : function(userDoc) { 24 | userDoc["couch.app.profile"] = newProfile; 25 | db.saveDoc(userDoc, { 26 | success : function() { 27 | newProfile.name = userDoc.name; 28 | $$(widget).profile = newProfile; 29 | widget.trigger("profileReady", [newProfile]); 30 | } 31 | }); 32 | } 33 | }); 34 | }); 35 | return false; 36 | } -------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/profileReady/after.js: -------------------------------------------------------------------------------- 1 | function(e, p) { 2 | $$(this).profile = p; 3 | }; -------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/profileReady/data.js: -------------------------------------------------------------------------------- 1 | function(e, p) { 2 | return p 3 | } 4 | -------------------------------------------------------------------------------- /vendor/couchapp/evently/profile/profileReady/mustache.html: -------------------------------------------------------------------------------- 1 |Hello {{nickname}}!
8 | -------------------------------------------------------------------------------- /vendor/couchapp/lib/atom.js: -------------------------------------------------------------------------------- 1 | // atom feed generator 2 | // requries E4X support. 3 | 4 | function f(n) { // Format integers to have at least two digits. 5 | return n < 10 ? '0' + n : n; 6 | } 7 | 8 | function rfc3339(date) { 9 | return date.getUTCFullYear() + '-' + 10 | f(date.getUTCMonth() + 1) + '-' + 11 | f(date.getUTCDate()) + 'T' + 12 | f(date.getUTCHours()) + ':' + 13 | f(date.getUTCMinutes()) + ':' + 14 | f(date.getUTCSeconds()) + 'Z'; 15 | }; 16 | 17 | exports.header = function(data) { 18 | var f =s around 197 | // "paragraphs" that are wrapped in non-block-level tags, such as anchors, 198 | // phrase emphasis, and spans. The list of tags we're looking for is 199 | // hard-coded: 200 | var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del" 201 | var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math" 202 | 203 | // First, look for nested blocks, e.g.: 204 | //
tags around block-level tags.
351 | text = _HashHTMLBlocks(text);
352 | text = _FormParagraphs(text);
353 |
354 | return text;
355 | }
356 |
357 |
358 | var _RunSpanGamut = function(text) {
359 | //
360 | // These are all the transformations that occur *within* block-level
361 | // tags like paragraphs, headers, and list items.
362 | //
363 |
364 | text = _DoCodeSpans(text);
365 | text = _EscapeSpecialCharsWithinTagAttributes(text);
366 | text = _EncodeBackslashEscapes(text);
367 |
368 | // Process anchor and image tags. Images must come first,
369 | // because ![foo][f] looks like an anchor.
370 | text = _DoImages(text);
371 | text = _DoAnchors(text);
372 |
373 | // Make links out of things like ` Just type tags
1029 | //
1030 |
1031 | // Strip leading and trailing lines:
1032 | text = text.replace(/^\n+/g,"");
1033 | text = text.replace(/\n+$/g,"");
1034 |
1035 | var grafs = text.split(/\n{2,}/g);
1036 | var grafsOut = new Array();
1037 |
1038 | //
1039 | // Wrap tags.
1040 | //
1041 | var end = grafs.length;
1042 | for (var i=0; i ");
1052 | str += " ");
317 | str+="
\n");
382 |
383 | return text;
384 | }
385 |
386 | var _EscapeSpecialCharsWithinTagAttributes = function(text) {
387 | //
388 | // Within tags -- meaning between < and > -- encode [\ ` * _] so they
389 | // don't conflict with their use in Markdown for code, italics and strong.
390 | //
391 |
392 | // Build a regex to find HTML tags and comments. See Friedl's
393 | // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
394 | var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|)/gi;
395 |
396 | text = text.replace(regex, function(wholeMatch) {
397 | var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
398 | tag = escapeCharacters(tag,"\\`*_");
399 | return tag;
400 | });
401 |
402 | return text;
403 | }
404 |
405 | var _DoAnchors = function(text) {
406 | //
407 | // Turn Markdown link shortcuts into XHTML tags.
408 | //
409 | //
410 | // First, handle reference-style links: [link text] [id]
411 | //
412 |
413 | /*
414 | text = text.replace(/
415 | ( // wrap whole match in $1
416 | \[
417 | (
418 | (?:
419 | \[[^\]]*\] // allow brackets nested one level
420 | |
421 | [^\[] // or anything else
422 | )*
423 | )
424 | \]
425 |
426 | [ ]? // one optional space
427 | (?:\n[ ]*)? // one optional newline followed by spaces
428 |
429 | \[
430 | (.*?) // id = $3
431 | \]
432 | )()()()() // pad remaining backreferences
433 | /g,_DoAnchors_callback);
434 | */
435 | text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
436 |
437 | //
438 | // Next, inline-style links: [link text](url "optional title")
439 | //
440 |
441 | /*
442 | text = text.replace(/
443 | ( // wrap whole match in $1
444 | \[
445 | (
446 | (?:
447 | \[[^\]]*\] // allow brackets nested one level
448 | |
449 | [^\[\]] // or anything else
450 | )
451 | )
452 | \]
453 | \( // literal paren
454 | [ \t]*
455 | () // no id, so leave $3 empty
456 | (.*?)>? // href = $4
457 | [ \t]*
458 | ( // $5
459 | (['"]) // quote char = $6
460 | (.*?) // Title = $7
461 | \6 // matching quote
462 | [ \t]* // ignore any spaces/tabs between closing quote and )
463 | )? // title is optional
464 | \)
465 | )
466 | /g,writeAnchorTag);
467 | */
468 | text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
469 |
470 | //
471 | // Last, handle reference-style shortcuts: [link text]
472 | // These must come last in case you've also got [link test][1]
473 | // or [link test](/foo)
474 | //
475 |
476 | /*
477 | text = text.replace(/
478 | ( // wrap whole match in $1
479 | \[
480 | ([^\[\]]+) // link text = $2; can't contain '[' or ']'
481 | \]
482 | )()()()()() // pad rest of backreferences
483 | /g, writeAnchorTag);
484 | */
485 | text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
486 |
487 | return text;
488 | }
489 |
490 | var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
491 | if (m7 == undefined) m7 = "";
492 | var whole_match = m1;
493 | var link_text = m2;
494 | var link_id = m3.toLowerCase();
495 | var url = m4;
496 | var title = m7;
497 |
498 | if (url == "") {
499 | if (link_id == "") {
500 | // lower-case and turn embedded newlines into spaces
501 | link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
502 | }
503 | url = "#"+link_id;
504 |
505 | if (g_urls[link_id] != undefined) {
506 | url = g_urls[link_id];
507 | if (g_titles[link_id] != undefined) {
508 | title = g_titles[link_id];
509 | }
510 | }
511 | else {
512 | if (whole_match.search(/\(\s*\)$/m)>-1) {
513 | // Special case for explicit empty url
514 | url = "";
515 | } else {
516 | return whole_match;
517 | }
518 | }
519 | }
520 |
521 | url = escapeCharacters(url,"*_");
522 | var result = "" + link_text + "";
531 |
532 | return result;
533 | }
534 |
535 |
536 | var _DoImages = function(text) {
537 | //
538 | // Turn Markdown image shortcuts into tags.
539 | //
540 |
541 | //
542 | // First, handle reference-style labeled images: ![alt text][id]
543 | //
544 |
545 | /*
546 | text = text.replace(/
547 | ( // wrap whole match in $1
548 | !\[
549 | (.*?) // alt text = $2
550 | \]
551 |
552 | [ ]? // one optional space
553 | (?:\n[ ]*)? // one optional newline followed by spaces
554 |
555 | \[
556 | (.*?) // id = $3
557 | \]
558 | )()()()() // pad rest of backreferences
559 | /g,writeImageTag);
560 | */
561 | text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
562 |
563 | //
564 | // Next, handle inline images: 
565 | // Don't forget: encode * and _
566 |
567 | /*
568 | text = text.replace(/
569 | ( // wrap whole match in $1
570 | !\[
571 | (.*?) // alt text = $2
572 | \]
573 | \s? // One optional whitespace character
574 | \( // literal paren
575 | [ \t]*
576 | () // no id, so leave $3 empty
577 | (\S+?)>? // src url = $4
578 | [ \t]*
579 | ( // $5
580 | (['"]) // quote char = $6
581 | (.*?) // title = $7
582 | \6 // matching quote
583 | [ \t]*
584 | )? // title is optional
585 | \)
586 | )
587 | /g,writeImageTag);
588 | */
589 | text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
590 |
591 | return text;
592 | }
593 |
594 | var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
595 | var whole_match = m1;
596 | var alt_text = m2;
597 | var link_id = m3.toLowerCase();
598 | var url = m4;
599 | var title = m7;
600 |
601 | if (!title) title = "";
602 |
603 | if (url == "") {
604 | if (link_id == "") {
605 | // lower-case and turn embedded newlines into spaces
606 | link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
607 | }
608 | url = "#"+link_id;
609 |
610 | if (g_urls[link_id] != undefined) {
611 | url = g_urls[link_id];
612 | if (g_titles[link_id] != undefined) {
613 | title = g_titles[link_id];
614 | }
615 | }
616 | else {
617 | return whole_match;
618 | }
619 | }
620 |
621 | alt_text = alt_text.replace(/"/g,""");
622 | url = escapeCharacters(url,"*_");
623 | var result = "
";
635 |
636 | return result;
637 | }
638 |
639 |
640 | var _DoHeaders = function(text) {
641 |
642 | // Setext-style headers:
643 | // Header 1
644 | // ========
645 | //
646 | // Header 2
647 | // --------
648 | //
649 | text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
650 | function(wholeMatch,m1){return hashBlock("
" + _RunSpanGamut(m1) + "
");});
651 |
652 | text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
653 | function(matchFound,m1){return hashBlock("" + _RunSpanGamut(m1) + "
");});
654 |
655 | // atx-style headers:
656 | // # Header 1
657 | // ## Header 2
658 | // ## Header 2 with closing hashes ##
659 | // ...
660 | // ###### Header 6
661 | //
662 |
663 | /*
664 | text = text.replace(/
665 | ^(\#{1,6}) // $1 = string of #'s
666 | [ \t]*
667 | (.+?) // $2 = Header text
668 | [ \t]*
669 | \#* // optional closing #'s (not counted)
670 | \n+
671 | /gm, function() {...});
672 | */
673 |
674 | text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
675 | function(wholeMatch,m1,m2) {
676 | var h_level = m1.length;
677 | return hashBlock("` blocks.
835 | //
836 |
837 | /*
838 | text = text.replace(text,
839 | /(?:\n\n|^)
840 | ( // $1 = the code block -- one or more lines, starting with a space/tab
841 | (?:
842 | (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
843 | .*\n+
844 | )+
845 | )
846 | (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
847 | /g,function(){...});
848 | */
849 |
850 | // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
851 | text += "~0";
852 |
853 | text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
854 | function(wholeMatch,m1,m2) {
855 | var codeblock = m1;
856 | var nextChar = m2;
857 |
858 | codeblock = _EncodeCode( _Outdent(codeblock));
859 | codeblock = _Detab(codeblock);
860 | codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
861 | codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
862 |
863 | codeblock = "
";
864 |
865 | return hashBlock(codeblock) + nextChar;
866 | }
867 | );
868 |
869 | // attacklab: strip sentinel
870 | text = text.replace(/~0/,"");
871 |
872 | return text;
873 | }
874 |
875 | var hashBlock = function(text) {
876 | text = text.replace(/(^\n+|\n+$)/g,"");
877 | return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
878 | }
879 |
880 |
881 | var _DoCodeSpans = function(text) {
882 | //
883 | // * Backtick quotes are used for " + codeblock + "\n
spans.
884 | //
885 | // * You can use multiple backticks as the delimiters if you want to
886 | // include literal backticks in the code span. So, this input:
887 | //
888 | // Just type ``foo `bar` baz`` at the prompt.
889 | //
890 | // Will translate to:
891 | //
892 | //
foo `bar` baz
at the prompt.`bar`
...
905 | //
906 |
907 | /*
908 | text = text.replace(/
909 | (^|[^\\]) // Character before opening ` can't be a backslash
910 | (`+) // $2 = Opening run of `
911 | ( // $3 = The code block
912 | [^\r]*?
913 | [^`] // attacklab: work around lack of lookbehind
914 | )
915 | \2 // Matching closer
916 | (?!`)
917 | /gm, function(){...});
918 | */
919 |
920 | text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
921 | function(wholeMatch,m1,m2,m3,m4) {
922 | var c = m3;
923 | c = c.replace(/^([ \t]*)/g,""); // leading whitespace
924 | c = c.replace(/[ \t]*$/g,""); // trailing whitespace
925 | c = _EncodeCode(c);
926 | return m1+""+c+"
";
927 | });
928 |
929 | return text;
930 | }
931 |
932 |
933 | var _EncodeCode = function(text) {
934 | //
935 | // Encode/escape certain characters inside Markdown code runs.
936 | // The point is that in code, these characters are literals,
937 | // and lose their special Markdown meanings.
938 | //
939 | // Encode all ampersands; HTML entities are not
940 | // entities within a Markdown code span.
941 | text = text.replace(/&/g,"&");
942 |
943 | // Do the angle bracket song and dance:
944 | text = text.replace(//g,">");
946 |
947 | // Now, escape characters that are magic in Markdown:
948 | text = escapeCharacters(text,"\*_{}[]\\",false);
949 |
950 | // jj the line above breaks this:
951 | //---
952 |
953 | //* Item
954 |
955 | // 1. Subitem
956 |
957 | // special char: *
958 | //---
959 |
960 | return text;
961 | }
962 |
963 |
964 | var _DoItalicsAndBold = function(text) {
965 |
966 | // must go first:
967 | text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
968 | "$2");
969 |
970 | text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
971 | "$2");
972 |
973 | return text;
974 | }
975 |
976 |
977 | var _DoBlockQuotes = function(text) {
978 |
979 | /*
980 | text = text.replace(/
981 | ( // Wrap whole match in $1
982 | (
983 | ^[ \t]*>[ \t]? // '>' at the start of a line
984 | .+\n // rest of the first line
985 | (.+\n)* // subsequent consecutive lines
986 | \n* // blanks
987 | )+
988 | )
989 | /gm, function(){...});
990 | */
991 |
992 | text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
993 | function(wholeMatch,m1) {
994 | var bq = m1;
995 |
996 | // attacklab: hack around Konqueror 3.5.4 bug:
997 | // "----------bug".replace(/^-/g,"") == "bug"
998 |
999 | bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting
1000 |
1001 | // attacklab: clean up hack
1002 | bq = bq.replace(/~0/g,"");
1003 |
1004 | bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
1005 | bq = _RunBlockGamut(bq); // recurse
1006 |
1007 | bq = bq.replace(/(^|\n)/g,"$1 ");
1008 | // These leading spaces screw with content, so we need to fix that:
1009 | bq = bq.replace(
1010 | /(\s*
[^\r]+?<\/pre>)/gm,
1011 | function(wholeMatch,m1) {
1012 | var pre = m1;
1013 | // attacklab: hack around Konqueror 3.5.4 bug:
1014 | pre = pre.replace(/^ /mg,"~0");
1015 | pre = pre.replace(/~0/g,"");
1016 | return pre;
1017 | });
1018 |
1019 | return hashBlock("
\n" + bq + "\n
");
1020 | });
1021 | return text;
1022 | }
1023 |
1024 |
1025 | var _FormParagraphs = function(text) {
1026 | //
1027 | // Params:
1028 | // $text - string to process with html
");
70 | _19=_19.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
71 | _19=_19.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
72 | _19=_19.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
73 | _19=_1d(_19);
74 | _19=_1e(_19);
75 | _19=_1f(_19);
76 | _19=_7(_19);
77 | _19=_20(_19);
78 | return _19;
79 | };
80 | var _21=function(_22){
81 | _22=_23(_22);
82 | _22=_24(_22);
83 | _22=_25(_22);
84 | _22=_26(_22);
85 | _22=_27(_22);
86 | _22=_28(_22);
87 | _22=_11(_22);
88 | _22=_29(_22);
89 | _22=_22.replace(/ +\n/g,"
\n");
90 | return _22;
91 | };
92 | var _24=function(_2a){
93 | var _2b=/(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|)/gi;
94 | _2a=_2a.replace(_2b,function(_2c){
95 | var tag=_2c.replace(/(.)<\/?code>(?=.)/g,"$1`");
96 | tag=_2e(tag,"\\`*_");
97 | return tag;
98 | });
99 | return _2a;
100 | };
101 | var _27=function(_2f){
102 | _2f=_2f.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,_30);
103 | _2f=_2f.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,_30);
104 | _2f=_2f.replace(/(\[([^\[\]]+)\])()()()()()/g,_30);
105 | return _2f;
106 | };
107 | var _30=function(_31,m1,m2,m3,m4,m5,m6,m7){
108 | if(m7==undefined){
109 | m7="";
110 | }
111 | var _39=m1;
112 | var _3a=m2;
113 | var _3b=m3.toLowerCase();
114 | var url=m4;
115 | var _3d=m7;
116 | if(url==""){
117 | if(_3b==""){
118 | _3b=_3a.toLowerCase().replace(/ ?\n/g," ");
119 | }
120 | url="#"+_3b;
121 | if(_1[_3b]!=undefined){
122 | url=_1[_3b];
123 | if(_2[_3b]!=undefined){
124 | _3d=_2[_3b];
125 | }
126 | }else{
127 | if(_39.search(/\(\s*\)$/m)>-1){
128 | url="";
129 | }else{
130 | return _39;
131 | }
132 | }
133 | }
134 | url=_2e(url,"*_");
135 | var _3e=""+_3a+"";
142 | return _3e;
143 | };
144 | var _26=function(_3f){
145 | _3f=_3f.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,_40);
146 | _3f=_3f.replace(/(!\[(.*?)\]\s?\([ \t]*()(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,_40);
147 | return _3f;
148 | };
149 | var _40=function(_41,m1,m2,m3,m4,m5,m6,m7){
150 | var _49=m1;
151 | var _4a=m2;
152 | var _4b=m3.toLowerCase();
153 | var url=m4;
154 | var _4d=m7;
155 | if(!_4d){
156 | _4d="";
157 | }
158 | if(url==""){
159 | if(_4b==""){
160 | _4b=_4a.toLowerCase().replace(/ ?\n/g," ");
161 | }
162 | url="#"+_4b;
163 | if(_1[_4b]!=undefined){
164 | url=_1[_4b];
165 | if(_2[_4b]!=undefined){
166 | _4d=_2[_4b];
167 | }
168 | }else{
169 | return _49;
170 | }
171 | }
172 | _4a=_4a.replace(/"/g,""");
173 | url=_2e(url,"*_");
174 | var _4e="";
179 | return _4e;
180 | };
181 | var _1a=function(_4f){
182 | _4f=_4f.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,function(_50,m1){
183 | return _1c("
"+_21(m1)+"
");
184 | });
185 | _4f=_4f.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,function(_52,m1){
186 | return _1c(""+_21(m1)+"
");
187 | });
188 | _4f=_4f.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,function(_54,m1,m2){
189 | var _57=m1.length;
190 | return _1c("
";
254 | return _1c(_77)+_78;
255 | });
256 | _73=_73.replace(/~0/,"");
257 | return _73;
258 | };
259 | var _1c=function(_7a){
260 | _7a=_7a.replace(/(^\n+|\n+$)/g,"");
261 | return "\n\n~K"+(_3.push(_7a)-1)+"K\n\n";
262 | };
263 | var _23=function(_7b){
264 | _7b=_7b.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,function(_7c,m1,m2,m3,m4){
265 | var c=m3;
266 | c=c.replace(/^([ \t]*)/g,"");
267 | c=c.replace(/[ \t]*$/g,"");
268 | c=_79(c);
269 | return m1+""+_77+"\n
"+c+"
";
270 | });
271 | return _7b;
272 | };
273 | var _79=function(_82){
274 | _82=_82.replace(/&/g,"&");
275 | _82=_82.replace(//g,">");
277 | _82=_2e(_82,"*_{}[]\\",false);
278 | return _82;
279 | };
280 | var _29=function(_83){
281 | _83=_83.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,"$2");
282 | _83=_83.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,"$2");
283 | return _83;
284 | };
285 | var _1f=function(_84){
286 | _84=_84.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,function(_85,m1){
287 | var bq=m1;
288 | bq=bq.replace(/^[ \t]*>[ \t]?/gm,"~0");
289 | bq=bq.replace(/~0/g,"");
290 | bq=bq.replace(/^[ \t]+$/gm,"");
291 | bq=_9(bq);
292 | bq=bq.replace(/(^|\n)/g,"$1 ");
293 | bq=bq.replace(/(\s*[^\r]+?<\/pre>)/gm,function(_88,m1){
294 | var pre=m1;
295 | pre=pre.replace(/^ /mg,"~0");
296 | pre=pre.replace(/~0/g,"");
297 | return pre;
298 | });
299 | return _1c("
\n"+bq+"\n
");
300 | });
301 | return _84;
302 | };
303 | var _20=function(_8b){
304 | _8b=_8b.replace(/^\n+/g,"");
305 | _8b=_8b.replace(/\n+$/g,"");
306 | var _8c=_8b.split(/\n{2,}/g);
307 | var _8d=new Array();
308 | var end=_8c.length;
309 | for(var i=0;i