Skip to content

Instantly share code, notes, and snippets.

@FND
Created September 16, 2010 12:48
Show Gist options
  • Save FND/582364 to your computer and use it in GitHub Desktop.
Save FND/582364 to your computer and use it in GitHub Desktop.
[
"deploy.sh",
"plugins",
"fixtures"
]
{
"env": {
"default": {
"db": "http://fnd.couchone.com"
}
}
}
fixtures/adaptor.json
fixtures/ServerSideSavingPlugin.json
fixtures/jquery-json.json
TiddlyCouch
TiddlyWiki CouchDB application

Generated by CouchApp

CouchApps are web applications which can be served directly from CouchDB. This gives them the nice property of replicating just like any other data stored in CouchDB. They are also simple to write as they can use the built-in jQuery libraries and plugins that ship with CouchDB.

More info about CouchApps here.

Deploying this app

Assuming you just cloned this app from git, and you have changed into the app directory in your terminal, you want to push it to your CouchDB with the CouchApp command line tool, like this:

couchapp push . http://name:password@hostname:5984/mydatabase

If you don't have a password on your CouchDB (admin party) you can do it like this (but it's a bad, idea, set a password):

couchapp push . http://hostname:5984/mydatabase

If you get sick of typing the URL, you should setup a .couchapprc file in the root of your directory. Remember not to check this into version control as it will have passwords in it.

The .couchapprc file should have contents like this:

{
  "env" : {
    "public" : {
      "db" : "http://name:pass@mycouch.couchone.com/mydatabase"
    },
    "default" : {
      "db" : "http://name:pass@localhost:5984/mydatabase"
    }
  }
}

Now that you have the .couchapprc file set up, you can push your app to the CouchDB as simply as:

couchapp push

This pushes to the default as specified. To push to the public you'd run:

couchapp push public

Of course you can continue to add more deployment targets as you see fit, and give them whatever names you like.

CouchApp - more than just a filesystem mapper

This is where documentation will go for the client and server JavaScript parts of CouchApp.

Starting the Document this code challenge

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.

Docs patches are deeply appreciated. For now you can just stick Markdown files in the Docs directory.

Evently

These are some vendor Evently widgets that are running on the CouchApp system.

Account

This is how you signup, login and logout without worry about the code. Todo, we could have this work against remote APIs like that Facebook stuff or whatever.

Profile

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.

Docs

This needs to be moved to it's own app. 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.

_design/tiddlycouch
function() {
var elem = $(this);
$$(this).userCtx = null;
$.couch.session({
success : function(r) {
var userCtx = r.userCtx;
if (userCtx.name) {
elem.trigger("loggedIn", [r]);
} else if (userCtx.roles.indexOf("_admin") != -1) {
elem.trigger("adminParty");
} else {
elem.trigger("loggedOut");
};
}
});
}
{"click" : ["loginForm"]}
{"click" : ["signupForm"]}
/***
|''Name''|CouchDBAdaptor|
|''Description''|adaptor for interacting with CouchDB|
|''Author:''|FND|
|''Version''|0.1.0|
|''Status''|@@experimental@@|
|''Source''|[TBD]|
|''CodeRepository''|[TBD]|
|''License''|[[BSD|http://www.opensource.org/licenses/bsd-license.php]]|
|''CoreVersion''|2.5|
|''Keywords''|serverSide CouchDB|
!Code
***/
//{{{
(function($) {
var adaptor = config.adaptors.couchdb = function() {};
adaptor.prototype = new AdaptorBase();
adaptor.serverType = "couchdb";
adaptor.serverLabel = "CouchDB";
adaptor.mimeType = "application/json";
adaptor.prototype.putTiddler = function(tiddler, context, userParams, callback) {
var fields = tiddler.fields;
context = this.setContext(context, userParams, callback);
context.title = tiddler.title;
context.tiddler = tiddler;
context.host = context.host || this.fullHostName(fields["server.host"]);
context.workspace = context.workspace || fields["server.workspace"];
var payload = {
type: fields["server.content-type"] || null,
title: tiddler.title,
modified: tiddler.modified,
modifier: tiddler.modifier,
text: tiddler.text,
tags: tiddler.tags,
fields: $.extend({}, fields)
};
if(tiddler.created) {
payload.created = tiddler.created;
}
if(tiddler.creator) {
payload.creator = tiddler.creator;
}
delete payload.fields.changecount;
$.each(payload.fields, function(key, value) {
if(key.indexOf("server.") == 0) {
delete payload.fields[key];
}
});
var options = {
url: context.host + "/" + encodeURIComponent(context.workspace),
type: null,
contentType: adaptor.mimeType,
data: $.toJSON(payload),
success: function(data, status, xhr) {
context.responseData = data;
adaptor.putTiddlerCallback(xhr.status, context,
xhr.responseText, options.url, xhr);
},
error: function(xhr, error, exc) {
adaptor.putTiddlerCallback(xhr.status, context,
xhr.responseText, options.url, xhr);
}
};
var id = fields["server.id"];
if(id) {
options.url += "/" + id;
options.type = "PUT";
payload._id = fields["server.id"];
payload._rev = fields["server.page.revision"];
options.data = $.toJSON(payload);
} else {
options.type = "POST";
}
return $.ajax(options);
};
adaptor.putTiddlerCallback = function(status, context, responseText, uri, xhr) {
context.status = [201, 202].contains(xhr.status);
context.statusText = xhr.statusText;
context.httpStatus = xhr.status;
if(context.responseData) {
var fields = context.tiddler.fields;
fields["server.id"] = context.responseData.id;
fields["server.page.revision"] = context.responseData.rev;
}
if(context.callback) {
context.callback(context, context.userParams);
}
};
})(jQuery);
//}}}
function(e, r) {
$$(this).userCtx = r.userCtx;
$$(this).info = r.info;
};
function() {
$("input[name=name]", this).focus();
}
function() {
$("input[name=name]", this).focus();
}
function() {
$$(this).profile = null;
};
function(e, p) {
$$(this).profile = p;
};
{
"rev": null,
"title": "Alpha",
"text": "hello world",
"tags": ["tmp"]
}
// atom feed generator
// requries E4X support.
function f(n) { // Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
function rfc3339(date) {
return date.getUTCFullYear() + '-' +
f(date.getUTCMonth() + 1) + '-' +
f(date.getUTCDate()) + 'T' +
f(date.getUTCHours()) + ':' +
f(date.getUTCMinutes()) + ':' +
f(date.getUTCSeconds()) + 'Z';
};
exports.header = function(data) {
var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
f.title = data.title;
f.id = data.feed_id;
f.link.@href = data.feed_link;
f.link.@rel = "self";
f.generator = "CouchApp on CouchDB";
f.updated = rfc3339(data.updated);
return f.toXMLString().replace(/\<\/feed\>/,'');
};
exports.entry = function(data) {
var entry = <entry/>;
entry.id = data.entry_id;
entry.title = data.title;
entry.content = data.content;
entry.content.@type = (data.content_type || 'html');
entry.updated = rfc3339(data.updated);
entry.author = <author><name>{data.author}</name></author>;
entry.link.@href = data.alternate;
entry.link.@rel = "alternate";
return entry;
}
{
"rev": null,
"title": "Bar",
"text": "dolor sit amet",
"tags": ["tmp", "sample"]
}
{
"rev": null,
"title": "Baz",
"text": "sed do eiusmod tempor",
"tags": ["tmp", "sample"]
}
{
"rev": null,
"title": "Bravo",
"text": "...",
"tags": ["tmp"]
}
exports.get = function(db, docid, setFun, getFun) {
db.openDoc(docid, {
success : function(doc) {
getFun(doc.cache);
},
error : function() {
setFun(function(cache) {
db.saveDoc({
_id : docid,
cache : cache
});
getFun(cache);
});
}
});
};
exports.clear = function(db, docid) {
db.openDoc(docid, {
success : function(doc) {
db.removeDoc(doc);
},
error : function() {}
});
};
{
"name": "Name of your CouchApp",
"description": "CouchApp"
}
function(data) {
// $.log(data)
var p;
return {
items : data.rows.map(function(r) {
p = (r.value && r.value.profile) || {};
p.message = r.value && r.value.message;
return p;
})
}
};
function(e, r) {
return {
name : r.userCtx.name,
uri_name : encodeURIComponent(r.userCtx.name),
auth_db : encodeURIComponent(r.info.authentication_db)
};
}
function(e, userCtx) {
return userCtx;
}
function(e, p) {
return p
}
#!/usr/bin/env sh
set -e
url="$*"
./js2tiddler "http://svn.tiddlywiki.org/Trunk/association/plugins/ServerSideSavingPlugin.js" \
> fixtures/ServerSideSavingPlugin.json
./js2tiddler "http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js" \
> fixtures/jquery-json.json
./js2tiddler plugins/adaptor.js > fixtures/adaptor.json
couchapp pushdocs fixtures $url
couchapp push $url
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
// turn the form into deep json
// field names like 'author-email' get turned into json like
// {"author":{"email":"quentin@example.com"}}
// acts on doc by reference, so you can safely pass non-form fields through
function formToDeepJSON(form, fields, doc) {
form = $(form);
fields.forEach(function(field) {
var val = form.find("[name="+field+"]").val();
if (!val) {return;}
var parts = field.split('-');
var frontObj = doc, frontName = parts.shift();
while (parts.length > 0) {
frontObj[frontName] = frontObj[frontName] || {};
frontObj = frontObj[frontName];
frontName = parts.shift();
}
frontObj[frontName] = val;
});
}
function onSubmit(form, db, doc, opts) {
formToDeepJSON(form, opts.fields, doc);
if (opts.beforeSave) {opts.beforeSave(doc);}
db.saveDoc(localFormDoc, {
success : function(resp) {
if (opts.success) {opts.success(resp, doc);}
}
});
};
function applyFields(form, doc) {
};
exports.applyFields = applyFields;
// docForm applies CouchDB behavior to HTML forms.
// todo make this a couch.app plugin
function docForm(formSelector, opts) {
var localFormDoc = {};
opts = opts || {};
opts.fields = opts.fields || [];
// Apply the behavior
$(formSelector).submit(function(e) {
return false;
});
// populate form from an existing doc
function docToForm(doc) {
var form = $(formSelector);
// fills in forms
opts.fields.forEach(function(field) {
var parts = field.split('-');
var run = true, frontObj = doc, frontName = parts.shift();
while (frontObj && parts.length > 0) {
frontObj = frontObj[frontName];
frontName = parts.shift();
}
if (frontObj && frontObj[frontName]) {
form.find("[name="+field+"]").val(frontObj[frontName]);
}
});
}
if (opts.id) {
db.openDoc(opts.id, {
success: function(doc) {
if (opts.onLoad) {opts.onLoad(doc);}
localFormDoc = doc;
docToForm(doc);
}});
} else if (opts.template) {
if (opts.onLoad) {opts.onLoad(opts.template);}
localFormDoc = opts.template;
docToForm(localFormDoc);
}
var instance = {
deleteDoc : function(opts) {
opts = opts || {};
if (confirm("Really delete this document?")) {
db.removeDoc(localFormDoc, opts);
}
},
localDoc : function() {
formToDeepJSON(formSelector, opts.fields, localFormDoc);
return localFormDoc;
}
};
return instance;
}
function(e, name, pass) {
var elem = $(this);
$.couch.login({
name : name,
password : pass,
success : function(r) {
elem.trigger("_init")
}
});
}
function() {
var elem = $(this);
$.couch.logout({
success : function() {
elem.trigger("_init");
}
});
}
function(e, name, pass) {
var elem = $(this);
$.couch.signup({
name : name
}, pass, {
success : function() {
elem.trigger("doLogin", [name, pass]);
}
});
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script id="versionArea" type="text/javascript">
//<![CDATA[
var version = {title: "TiddlyWiki", major: 2, minor: 6, revision: 1, date: new Date("Aug 18, 2010"), extensions: {}};
//]]>
</script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="copyright" content="
TiddlyWiki created by Jeremy Ruston, (jeremy [at] osmosoft [dot] com)
Copyright (c) UnaMesa Association 2004-2009
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
Neither the name of the UnaMesa Association nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
" />
<!--PRE-HEAD-START-->
<!--{{{-->
<link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml' />
<!--}}}-->
<!--PRE-HEAD-END-->
<title>
</title>
<style id="styleArea" type="text/css">
#saveTest {display:none;}
#messageArea {display:none;}
#copyright {display:none;}
#storeArea {display:none;}
#storeArea div {padding:0.5em; margin:1em 0em 0em 0em; border-color:#fff #666 #444 #ddd; border-style:solid; border-width:2px; overflow:auto;}
#shadowArea {display:none;}
#javascriptWarning {width:100%; text-align:center; font-weight:bold; background-color:#dd1100; color:#fff; padding:1em 0em;}
</style>
<!--POST-HEAD-START-->
<!--POST-HEAD-END-->
</head>
<body onload="main();" onunload="if(window.unload) unload();">
<!--PRE-BODY-START-->
<!--PRE-BODY-END-->
<div id="copyright">
Welcome to TiddlyWiki created by Jeremy Ruston, Copyright &copy; 2007 UnaMesa Association
</div>
<noscript>
<div id="javascriptWarning">
This page requires JavaScript to function properly.<br /><br />If you are using Microsoft Internet Explorer you may need to click on the yellow bar above and select 'Allow Blocked Content'. You must then click 'Yes' on the following security warning.
</div>
</noscript>
<div id="saveTest"></div>
<div id="backstageCloak"></div>
<div id="backstageButton"></div>
<div id="backstageArea"><div id="backstageToolbar"></div></div>
<div id="backstage">
<div id="backstagePanel"></div>
</div>
<div id="contentWrapper"></div>
<div id="contentStash"></div>
<div id="shadowArea">
<div title="MarkupPreHead">
<pre>&lt;!--{{{--&gt;
&lt;link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml' /&gt;
&lt;!--}}}--&gt;
</pre>
</div>
<div title="ColorPalette">
<pre>Background: #fff
Foreground: #000
PrimaryPale: #8cf
PrimaryLight: #18f
PrimaryMid: #04b
PrimaryDark: #014
SecondaryPale: #ffc
SecondaryLight: #fe8
SecondaryMid: #db4
SecondaryDark: #841
TertiaryPale: #eee
TertiaryLight: #ccc
TertiaryMid: #999
TertiaryDark: #666
Error: #f88
</pre>
</div>
<div title="StyleSheetColors">
<pre>/*{{{*/
body {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
a {color:[[ColorPalette::PrimaryMid]];}
a:hover {background-color:[[ColorPalette::PrimaryMid]]; color:[[ColorPalette::Background]];}
a img {border:0;}
h1,h2,h3,h4,h5,h6 {color:[[ColorPalette::SecondaryDark]]; background:transparent;}
h1 {border-bottom:2px solid [[ColorPalette::TertiaryLight]];}
h2,h3 {border-bottom:1px solid [[ColorPalette::TertiaryLight]];}
.button {color:[[ColorPalette::PrimaryDark]]; border:1px solid [[ColorPalette::Background]];}
.button:hover {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::SecondaryLight]]; border-color:[[ColorPalette::SecondaryMid]];}
.button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::SecondaryDark]];}
.header {background:[[ColorPalette::PrimaryMid]];}
.headerShadow {color:[[ColorPalette::Foreground]];}
.headerShadow a {font-weight:normal; color:[[ColorPalette::Foreground]];}
.headerForeground {color:[[ColorPalette::Background]];}
.headerForeground a {font-weight:normal; color:[[ColorPalette::PrimaryPale]];}
.tabSelected{color:[[ColorPalette::PrimaryDark]];
background:[[ColorPalette::TertiaryPale]];
border-left:1px solid [[ColorPalette::TertiaryLight]];
border-top:1px solid [[ColorPalette::TertiaryLight]];
border-right:1px solid [[ColorPalette::TertiaryLight]];
}
.tabUnselected {color:[[ColorPalette::Background]]; background:[[ColorPalette::TertiaryMid]];}
.tabContents {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::TertiaryPale]]; border:1px solid [[ColorPalette::TertiaryLight]];}
.tabContents .button {border:0;}
#sidebar {}
#sidebarOptions input {border:1px solid [[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel {background:[[ColorPalette::PrimaryPale]];}
#sidebarOptions .sliderPanel a {border:none;color:[[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel a:hover {color:[[ColorPalette::Background]]; background:[[ColorPalette::PrimaryMid]];}
#sidebarOptions .sliderPanel a:active {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::Background]];}
.wizard {background:[[ColorPalette::PrimaryPale]]; border:1px solid [[ColorPalette::PrimaryMid]];}
.wizard h1 {color:[[ColorPalette::PrimaryDark]]; border:none;}
.wizard h2 {color:[[ColorPalette::Foreground]]; border:none;}
.wizardStep {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];
border:1px solid [[ColorPalette::PrimaryMid]];}
.wizardStep.wizardStepDone {background:[[ColorPalette::TertiaryLight]];}
.wizardFooter {background:[[ColorPalette::PrimaryPale]];}
.wizardFooter .status {background:[[ColorPalette::PrimaryDark]]; color:[[ColorPalette::Background]];}
.wizard .button {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryLight]]; border: 1px solid;
border-color:[[ColorPalette::SecondaryPale]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryPale]];}
.wizard .button:hover {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Background]];}
.wizard .button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::Foreground]]; border: 1px solid;
border-color:[[ColorPalette::PrimaryDark]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryDark]];}
.wizard .notChanged {background:transparent;}
.wizard .changedLocally {background:#80ff80;}
.wizard .changedServer {background:#8080ff;}
.wizard .changedBoth {background:#ff8080;}
.wizard .notFound {background:#ffff80;}
.wizard .putToServer {background:#ff80ff;}
.wizard .gotFromServer {background:#80ffff;}
#messageArea {border:1px solid [[ColorPalette::SecondaryMid]]; background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]];}
#messageArea .button {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::SecondaryPale]]; border:none;}
.popupTiddler {background:[[ColorPalette::TertiaryPale]]; border:2px solid [[ColorPalette::TertiaryMid]];}
.popup {background:[[ColorPalette::TertiaryPale]]; color:[[ColorPalette::TertiaryDark]]; border-left:1px solid [[ColorPalette::TertiaryMid]]; border-top:1px solid [[ColorPalette::TertiaryMid]]; border-right:2px solid [[ColorPalette::TertiaryDark]]; border-bottom:2px solid [[ColorPalette::TertiaryDark]];}
.popup hr {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::PrimaryDark]]; border-bottom:1px;}
.popup li.disabled {color:[[ColorPalette::TertiaryMid]];}
.popup li a, .popup li a:visited {color:[[ColorPalette::Foreground]]; border: none;}
.popup li a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border: none;}
.popup li a:active {background:[[ColorPalette::SecondaryPale]]; color:[[ColorPalette::Foreground]]; border: none;}
.popupHighlight {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
.listBreak div {border-bottom:1px solid [[ColorPalette::TertiaryDark]];}
.tiddler .defaultCommand {font-weight:bold;}
.shadow .title {color:[[ColorPalette::TertiaryDark]];}
.title {color:[[ColorPalette::SecondaryDark]];}
.subtitle {color:[[ColorPalette::TertiaryDark]];}
.toolbar {color:[[ColorPalette::PrimaryMid]];}
.toolbar a {color:[[ColorPalette::TertiaryLight]];}
.selected .toolbar a {color:[[ColorPalette::TertiaryMid]];}
.selected .toolbar a:hover {color:[[ColorPalette::Foreground]];}
.tagging, .tagged {border:1px solid [[ColorPalette::TertiaryPale]]; background-color:[[ColorPalette::TertiaryPale]];}
.selected .tagging, .selected .tagged {background-color:[[ColorPalette::TertiaryLight]]; border:1px solid [[ColorPalette::TertiaryMid]];}
.tagging .listTitle, .tagged .listTitle {color:[[ColorPalette::PrimaryDark]];}
.tagging .button, .tagged .button {border:none;}
.footer {color:[[ColorPalette::TertiaryLight]];}
.selected .footer {color:[[ColorPalette::TertiaryMid]];}
.sparkline {background:[[ColorPalette::PrimaryPale]]; border:0;}
.sparktick {background:[[ColorPalette::PrimaryDark]];}
.error, .errorButton {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Error]];}
.warning {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryPale]];}
.lowlight {background:[[ColorPalette::TertiaryLight]];}
.zoomer {background:none; color:[[ColorPalette::TertiaryMid]]; border:3px solid [[ColorPalette::TertiaryMid]];}
.imageLink, #displayArea .imageLink {background:transparent;}
.annotation {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border:2px solid [[ColorPalette::SecondaryMid]];}
.viewer .listTitle {list-style-type:none; margin-left:-2em;}
.viewer .button {border:1px solid [[ColorPalette::SecondaryMid]];}
.viewer blockquote {border-left:3px solid [[ColorPalette::TertiaryDark]];}
.viewer table, table.twtable {border:2px solid [[ColorPalette::TertiaryDark]];}
.viewer th, .viewer thead td, .twtable th, .twtable thead td {background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::Background]];}
.viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid [[ColorPalette::TertiaryDark]];}
.viewer pre {border:1px solid [[ColorPalette::SecondaryLight]]; background:[[ColorPalette::SecondaryPale]];}
.viewer code {color:[[ColorPalette::SecondaryDark]];}
.viewer hr {border:0; border-top:dashed 1px [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::TertiaryDark]];}
.highlight, .marked {background:[[ColorPalette::SecondaryLight]];}
.editor input {border:1px solid [[ColorPalette::PrimaryMid]];}
.editor textarea {border:1px solid [[ColorPalette::PrimaryMid]]; width:100%;}
.editorFooter {color:[[ColorPalette::TertiaryMid]];}
.readOnly {background:[[ColorPalette::TertiaryPale]];}
#backstageArea {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::TertiaryMid]];}
#backstageArea a {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
#backstageArea a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; }
#backstageArea a.backstageSelTab {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
#backstageButton a {background:none; color:[[ColorPalette::Background]]; border:none;}
#backstageButton a:hover {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
#backstagePanel {background:[[ColorPalette::Background]]; border-color: [[ColorPalette::Background]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]];}
.backstagePanelFooter .button {border:none; color:[[ColorPalette::Background]];}
.backstagePanelFooter .button:hover {color:[[ColorPalette::Foreground]];}
#backstageCloak {background:[[ColorPalette::Foreground]]; opacity:0.6; filter:'alpha(opacity=60)';}
/*}}}*/</pre>
</div>
<div title="StyleSheetLayout">
<pre>/*{{{*/
* html .tiddler {height:1%;}
body {font-size:.75em; font-family:arial,helvetica; margin:0; padding:0;}
h1,h2,h3,h4,h5,h6 {font-weight:bold; text-decoration:none;}
h1,h2,h3 {padding-bottom:1px; margin-top:1.2em;margin-bottom:0.3em;}
h4,h5,h6 {margin-top:1em;}
h1 {font-size:1.35em;}
h2 {font-size:1.25em;}
h3 {font-size:1.1em;}
h4 {font-size:1em;}
h5 {font-size:.9em;}
hr {height:1px;}
a {text-decoration:none;}
dt {font-weight:bold;}
ol {list-style-type:decimal;}
ol ol {list-style-type:lower-alpha;}
ol ol ol {list-style-type:lower-roman;}
ol ol ol ol {list-style-type:decimal;}
ol ol ol ol ol {list-style-type:lower-alpha;}
ol ol ol ol ol ol {list-style-type:lower-roman;}
ol ol ol ol ol ol ol {list-style-type:decimal;}
.txtOptionInput {width:11em;}
#contentWrapper .chkOptionInput {border:0;}
.externalLink {text-decoration:underline;}
.indent {margin-left:3em;}
.outdent {margin-left:3em; text-indent:-3em;}
code.escaped {white-space:nowrap;}
.tiddlyLinkExisting {font-weight:bold;}
.tiddlyLinkNonExisting {font-style:italic;}
/* the 'a' is required for IE, otherwise it renders the whole tiddler in bold */
a.tiddlyLinkNonExisting.shadow {font-weight:bold;}
#mainMenu .tiddlyLinkExisting,
#mainMenu .tiddlyLinkNonExisting,
#sidebarTabs .tiddlyLinkNonExisting {font-weight:normal; font-style:normal;}
#sidebarTabs .tiddlyLinkExisting {font-weight:bold; font-style:normal;}
.header {position:relative;}
.header a:hover {background:transparent;}
.headerShadow {position:relative; padding:4.5em 0 1em 1em; left:-1px; top:-1px;}
.headerForeground {position:absolute; padding:4.5em 0 1em 1em; left:0px; top:0px;}
.siteTitle {font-size:3em;}
.siteSubtitle {font-size:1.2em;}
#mainMenu {position:absolute; left:0; width:10em; text-align:right; line-height:1.6em; padding:1.5em 0.5em 0.5em 0.5em; font-size:1.1em;}
#sidebar {position:absolute; right:3px; width:16em; font-size:.9em;}
#sidebarOptions {padding-top:0.3em;}
#sidebarOptions a {margin:0 0.2em; padding:0.2em 0.3em; display:block;}
#sidebarOptions input {margin:0.4em 0.5em;}
#sidebarOptions .sliderPanel {margin-left:1em; padding:0.5em; font-size:.85em;}
#sidebarOptions .sliderPanel a {font-weight:bold; display:inline; padding:0;}
#sidebarOptions .sliderPanel input {margin:0 0 0.3em 0;}
#sidebarTabs .tabContents {width:15em; overflow:hidden;}
.wizard {padding:0.1em 1em 0 2em;}
.wizard h1 {font-size:2em; font-weight:bold; background:none; padding:0; margin:0.4em 0 0.2em;}
.wizard h2 {font-size:1.2em; font-weight:bold; background:none; padding:0; margin:0.4em 0 0.2em;}
.wizardStep {padding:1em 1em 1em 1em;}
.wizard .button {margin:0.5em 0 0; font-size:1.2em;}
.wizardFooter {padding:0.8em 0.4em 0.8em 0;}
.wizardFooter .status {padding:0 0.4em; margin-left:1em;}
.wizard .button {padding:0.1em 0.2em;}
#messageArea {position:fixed; top:2em; right:0; margin:0.5em; padding:0.5em; z-index:2000; _position:absolute;}
.messageToolbar {display:block; text-align:right; padding:0.2em;}
#messageArea a {text-decoration:underline;}
.tiddlerPopupButton {padding:0.2em;}
.popupTiddler {position: absolute; z-index:300; padding:1em; margin:0;}
.popup {position:absolute; z-index:300; font-size:.9em; padding:0; list-style:none; margin:0;}
.popup .popupMessage {padding:0.4em;}
.popup hr {display:block; height:1px; width:auto; padding:0; margin:0.2em 0;}
.popup li.disabled {padding:0.4em;}
.popup li a {display:block; padding:0.4em; font-weight:normal; cursor:pointer;}
.listBreak {font-size:1px; line-height:1px;}
.listBreak div {margin:2px 0;}
.tabset {padding:1em 0 0 0.5em;}
.tab {margin:0 0 0 0.25em; padding:2px;}
.tabContents {padding:0.5em;}
.tabContents ul, .tabContents ol {margin:0; padding:0;}
.txtMainTab .tabContents li {list-style:none;}
.tabContents li.listLink { margin-left:.75em;}
#contentWrapper {display:block;}
#splashScreen {display:none;}
#displayArea {margin:1em 17em 0 14em;}
.toolbar {text-align:right; font-size:.9em;}
.tiddler {padding:1em 1em 0;}
.missing .viewer,.missing .title {font-style:italic;}
.title {font-size:1.6em; font-weight:bold;}
.missing .subtitle {display:none;}
.subtitle {font-size:1.1em;}
.tiddler .button {padding:0.2em 0.4em;}
.tagging {margin:0.5em 0.5em 0.5em 0; float:left; display:none;}
.isTag .tagging {display:block;}
.tagged {margin:0.5em; float:right;}
.tagging, .tagged {font-size:0.9em; padding:0.25em;}
.tagging ul, .tagged ul {list-style:none; margin:0.25em; padding:0;}
.tagClear {clear:both;}
.footer {font-size:.9em;}
.footer li {display:inline;}
.annotation {padding:0.5em; margin:0.5em;}
* html .viewer pre {width:99%; padding:0 0 1em 0;}
.viewer {line-height:1.4em; padding-top:0.5em;}
.viewer .button {margin:0 0.25em; padding:0 0.25em;}
.viewer blockquote {line-height:1.5em; padding-left:0.8em;margin-left:2.5em;}
.viewer ul, .viewer ol {margin-left:0.5em; padding-left:1.5em;}
.viewer table, table.twtable {border-collapse:collapse; margin:0.8em 1.0em;}
.viewer th, .viewer td, .viewer tr,.viewer caption,.twtable th, .twtable td, .twtable tr,.twtable caption {padding:3px;}
table.listView {font-size:0.85em; margin:0.8em 1.0em;}
table.listView th, table.listView td, table.listView tr {padding:0px 3px 0px 3px;}
.viewer pre {padding:0.5em; margin-left:0.5em; font-size:1.2em; line-height:1.4em; overflow:auto;}
.viewer code {font-size:1.2em; line-height:1.4em;}
.editor {font-size:1.1em;}
.editor input, .editor textarea {display:block; width:100%; font:inherit;}
.editorFooter {padding:0.25em 0; font-size:.9em;}
.editorFooter .button {padding-top:0px; padding-bottom:0px;}
.fieldsetFix {border:0; padding:0; margin:1px 0px;}
.sparkline {line-height:1em;}
.sparktick {outline:0;}
.zoomer {font-size:1.1em; position:absolute; overflow:hidden;}
.zoomer div {padding:1em;}
* html #backstage {width:99%;}
* html #backstageArea {width:99%;}
#backstageArea {display:none; position:relative; overflow: hidden; z-index:150; padding:0.3em 0.5em;}
#backstageToolbar {position:relative;}
#backstageArea a {font-weight:bold; margin-left:0.5em; padding:0.3em 0.5em;}
#backstageButton {display:none; position:absolute; z-index:175; top:0; right:0;}
#backstageButton a {padding:0.1em 0.4em; margin:0.1em;}
#backstage {position:relative; width:100%; z-index:50;}
#backstagePanel {display:none; z-index:100; position:absolute; width:90%; margin-left:3em; padding:1em;}
.backstagePanelFooter {padding-top:0.2em; float:right;}
.backstagePanelFooter a {padding:0.2em 0.4em;}
#backstageCloak {display:none; z-index:20; position:absolute; width:100%; height:100px;}
.whenBackstage {display:none;}
.backstageVisible .whenBackstage {display:block;}
/*}}}*/
</pre>
</div>
<div title="StyleSheetLocale">
<pre>/***
StyleSheet for use when a translation requires any css style changes.
This StyleSheet can be used directly by languages such as Chinese, Japanese and Korean which need larger font sizes.
***/
/*{{{*/
body {font-size:0.8em;}
#sidebarOptions {font-size:1.05em;}
#sidebarOptions a {font-style:normal;}
#sidebarOptions .sliderPanel {font-size:0.95em;}
.subtitle {font-size:0.8em;}
.viewer table.listView {font-size:0.95em;}
/*}}}*/</pre>
</div>
<div title="StyleSheetPrint">
<pre>/*{{{*/
@media print {
#mainMenu, #sidebar, #messageArea, .toolbar, #backstageButton, #backstageArea {display: none !important;}
#displayArea {margin: 1em 1em 0em;}
noscript {display:none;} /* Fixes a feature in Firefox 1.5.0.2 where print preview displays the noscript content */
}
/*}}}*/</pre>
</div>
<div title="PageTemplate">
<pre>&lt;!--{{{--&gt;
&lt;div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'&gt;
&lt;div class='headerShadow'&gt;
&lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
&lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div class='headerForeground'&gt;
&lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
&lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id='mainMenu' refresh='content' tiddler='MainMenu'&gt;&lt;/div&gt;
&lt;div id='sidebar'&gt;
&lt;div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'&gt;&lt;/div&gt;
&lt;div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id='displayArea'&gt;
&lt;div id='messageArea'&gt;&lt;/div&gt;
&lt;div id='tiddlerDisplay'&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!--}}}--&gt;</pre>
</div>
<div title="ViewTemplate">
<pre>&lt;!--{{{--&gt;
&lt;div class='toolbar' macro='toolbar [[ToolbarCommands::ViewToolbar]]'&gt;&lt;/div&gt;
&lt;div class='title' macro='view title'&gt;&lt;/div&gt;
&lt;div class='subtitle'&gt;&lt;span macro='view modifier link'&gt;&lt;/span&gt;, &lt;span macro='view modified date'&gt;&lt;/span&gt; (&lt;span macro='message views.wikified.createdPrompt'&gt;&lt;/span&gt; &lt;span macro='view created date'&gt;&lt;/span&gt;)&lt;/div&gt;
&lt;div class='tagging' macro='tagging'&gt;&lt;/div&gt;
&lt;div class='tagged' macro='tags'&gt;&lt;/div&gt;
&lt;div class='viewer' macro='view text wikified'&gt;&lt;/div&gt;
&lt;div class='tagClear'&gt;&lt;/div&gt;
&lt;!--}}}--&gt;</pre>
</div>
<div title="EditTemplate">
<pre>&lt;!--{{{--&gt;
&lt;div class='toolbar' macro='toolbar [[ToolbarCommands::EditToolbar]]'&gt;&lt;/div&gt;
&lt;div class='title' macro='view title'&gt;&lt;/div&gt;
&lt;div class='editor' macro='edit title'&gt;&lt;/div&gt;
&lt;div macro='annotations'&gt;&lt;/div&gt;
&lt;div class='editor' macro='edit text'&gt;&lt;/div&gt;
&lt;div class='editor' macro='edit tags'&gt;&lt;/div&gt;&lt;div class='editorFooter'&gt;&lt;span macro='message views.editor.tagPrompt'&gt;&lt;/span&gt;&lt;span macro='tagChooser excludeLists'&gt;&lt;/span&gt;&lt;/div&gt;
&lt;!--}}}--&gt;</pre>
</div>
<div title="GettingStarted">
<pre>To get started with this blank [[TiddlyWiki]], you'll need to modify the following tiddlers:
* [[SiteTitle]] &amp; [[SiteSubtitle]]: The title and subtitle of the site, as shown above (after saving, they will also appear in the browser title bar)
* [[MainMenu]]: The menu (usually on the left)
* [[DefaultTiddlers]]: Contains the names of the tiddlers that you want to appear when the TiddlyWiki is opened
You'll also need to enter your username for signing your edits: &lt;&lt;option txtUserName&gt;&gt;</pre>
</div>
<div title="OptionsPanel">
<pre>These [[InterfaceOptions]] for customising [[TiddlyWiki]] are saved in your browser
Your username for signing your edits. Write it as a [[WikiWord]] (eg [[JoeBloggs]])
&lt;&lt;option txtUserName&gt;&gt;
&lt;&lt;option chkSaveBackups&gt;&gt; [[SaveBackups]]
&lt;&lt;option chkAutoSave&gt;&gt; [[AutoSave]]
&lt;&lt;option chkRegExpSearch&gt;&gt; [[RegExpSearch]]
&lt;&lt;option chkCaseSensitiveSearch&gt;&gt; [[CaseSensitiveSearch]]
&lt;&lt;option chkAnimate&gt;&gt; [[EnableAnimations]]
----
Also see [[AdvancedOptions]]</pre>
</div>
<div title="ImportTiddlers">
<pre>&lt;&lt;importTiddlers&gt;&gt;</pre>
</div>
</div>
<!--POST-SHADOWAREA-->
<div id="storeArea">
</div>
<!--POST-STOREAREA-->
<!--POST-BODY-START-->
<!--POST-BODY-END-->
<script id="jsArea" type="text/javascript">
//<![CDATA[
//
// Please note:
//
// * This code is designed to be readable but for compactness it only includes brief comments. You can see fuller comments
// in the project Subversion repository at http://svn.tiddlywiki.org/Trunk/core/
//
// * You should never need to modify this source code directly. TiddlyWiki is carefully designed to allow deep customisation
// without changing the core code. Please consult the development group at http://groups.google.com/group/TiddlyWikiDev
//
//--
//-- Configuration repository
//--
// Miscellaneous options
var config = {
numRssItems: 20, // Number of items in the RSS feed
animDuration: 400, // Duration of UI animations in milliseconds
cascadeFast: 20, // Speed for cascade animations (higher == slower)
cascadeSlow: 60, // Speed for EasterEgg cascade animations
cascadeDepth: 5, // Depth of cascade animation
locale: "en" // W3C language tag
};
// Hashmap of alternative parsers for the wikifier
config.parsers = {};
// Adaptors
config.adaptors = {};
config.defaultAdaptor = null;
// Backstage tasks
config.tasks = {};
// Annotations
config.annotations = {};
// Custom fields to be automatically added to new tiddlers
config.defaultCustomFields = {};
// Messages
config.messages = {
messageClose: {},
dates: {},
tiddlerPopup: {}
};
// Options that can be set in the options panel and/or cookies
config.options = {
chkRegExpSearch: false,
chkCaseSensitiveSearch: false,
chkIncrementalSearch: true,
chkAnimate: true,
chkSaveBackups: true,
chkAutoSave: false,
chkGenerateAnRssFeed: false,
chkSaveEmptyTemplate: false,
chkOpenInNewWindow: true,
chkToggleLinks: false,
chkHttpReadOnly: true,
chkForceMinorUpdate: false,
chkConfirmDelete: true,
chkInsertTabs: false,
chkUsePreForStorage: true, // Whether to use <pre> format for storage
chkDisplayInstrumentation: false,
txtBackupFolder: "",
txtEditorFocus: "text",
txtMainTab: "tabTimeline",
txtMoreTab: "moreTabAll",
txtMaxEditRows: "30",
txtFileSystemCharSet: "UTF-8",
txtTheme: ""
};
config.optionsDesc = {};
// Default tiddler templates
var DEFAULT_VIEW_TEMPLATE = 1;
var DEFAULT_EDIT_TEMPLATE = 2;
config.tiddlerTemplates = {
1: "ViewTemplate",
2: "EditTemplate"
};
// More messages (rather a legacy layout that should not really be like this)
config.views = {
wikified: {
tag: {}
},
editor: {
tagChooser: {}
}
};
// Backstage tasks
config.backstageTasks = ["save","sync","importTask","tweak","upgrade","plugins"];
// Extensions
config.extensions = {};
// Macros; each has a 'handler' member that is inserted later
config.macros = {
today: {},
version: {},
search: {sizeTextbox: 15},
tiddler: {},
tag: {},
tags: {},
tagging: {},
timeline: {},
allTags: {},
list: {
all: {},
missing: {},
orphans: {},
shadowed: {},
touched: {},
filter: {}
},
closeAll: {},
permaview: {},
saveChanges: {},
slider: {},
option: {},
options: {},
newTiddler: {},
newJournal: {},
tabs: {},
gradient: {},
message: {},
view: {defaultView: "text"},
edit: {},
tagChooser: {},
toolbar: {},
plugins: {},
refreshDisplay: {},
importTiddlers: {},
upgrade: {
source: "http://www.tiddlywiki.com/upgrade/",
backupExtension: "pre.core.upgrade"
},
sync: {},
annotations: {}
};
// Commands supported by the toolbar macro
config.commands = {
closeTiddler: {},
closeOthers: {},
editTiddler: {},
saveTiddler: {hideReadOnly: true},
cancelTiddler: {},
deleteTiddler: {hideReadOnly: true},
permalink: {},
references: {type: "popup"},
jump: {type: "popup"},
syncing: {type: "popup"},
fields: {type: "popup"}
};
// Browser detection... In a very few places, there's nothing else for it but to know what browser we're using.
config.userAgent = navigator.userAgent.toLowerCase();
config.browser = {
isIE: config.userAgent.indexOf("msie") != -1 && config.userAgent.indexOf("opera") == -1,
isGecko: navigator.product == "Gecko" && config.userAgent.indexOf("WebKit") == -1,
ieVersion: /MSIE (\d.\d)/i.exec(config.userAgent), // config.browser.ieVersion[1], if it exists, will be the IE version string, eg "6.0"
isSafari: config.userAgent.indexOf("applewebkit") != -1,
isBadSafari: !((new RegExp("[\u0150\u0170]","g")).test("\u0150")),
firefoxDate: /gecko\/(\d{8})/i.exec(config.userAgent), // config.browser.firefoxDate[1], if it exists, will be Firefox release date as "YYYYMMDD"
isOpera: config.userAgent.indexOf("opera") != -1,
isLinux: config.userAgent.indexOf("linux") != -1,
isUnix: config.userAgent.indexOf("x11") != -1,
isMac: config.userAgent.indexOf("mac") != -1,
isWindows: config.userAgent.indexOf("win") != -1
};
// Basic regular expressions
config.textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]",
anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]"
};
if(config.browser.isBadSafari) {
config.textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de]",
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff]",
anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff]",
anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff]"
};
}
config.textPrimitives.sliceSeparator = "::";
config.textPrimitives.sectionSeparator = "##";
config.textPrimitives.urlPattern = "(?:file|http|https|mailto|ftp|irc|news|data):[^\\s'\"]+(?:/|\\b)";
config.textPrimitives.unWikiLink = "~";
config.textPrimitives.wikiLink = "(?:(?:" + config.textPrimitives.upperLetter + "+" +
config.textPrimitives.lowerLetter + "+" +
config.textPrimitives.upperLetter +
config.textPrimitives.anyLetter + "*)|(?:" +
config.textPrimitives.upperLetter + "{2,}" +
config.textPrimitives.lowerLetter + "+))";
config.textPrimitives.cssLookahead = "(?:(" + config.textPrimitives.anyLetter + "+)\\(([^\\)\\|\\n]+)(?:\\):))|(?:(" + config.textPrimitives.anyLetter + "+):([^;\\|\\n]+);)";
config.textPrimitives.cssLookaheadRegExp = new RegExp(config.textPrimitives.cssLookahead,"mg");
config.textPrimitives.brackettedLink = "\\[\\[([^\\]]+)\\]\\]";
config.textPrimitives.titledBrackettedLink = "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+)\\]\\]";
config.textPrimitives.tiddlerForcedLinkRegExp = new RegExp("(?:" + config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
config.textPrimitives.tiddlerAnyLinkRegExp = new RegExp("("+ config.textPrimitives.wikiLink + ")|(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
config.glyphs = {
browsers: [
function() {return config.browser.isIE;},
function() {return true;}
],
currBrowser: null,
codes: {
downTriangle: ["\u25BC","\u25BE"],
downArrow: ["\u2193","\u2193"],
bentArrowLeft: ["\u2190","\u21A9"],
bentArrowRight: ["\u2192","\u21AA"]
}
};
//--
//-- Shadow tiddlers
//--
config.shadowTiddlers = {
StyleSheet: "",
MarkupPreHead: "",
MarkupPostHead: "",
MarkupPreBody: "",
MarkupPostBody: "",
TabTimeline: '<<timeline>>',
TabAll: '<<list all>>',
TabTags: '<<allTags excludeLists>>',
TabMoreMissing: '<<list missing>>',
TabMoreOrphans: '<<list orphans>>',
TabMoreShadowed: '<<list shadowed>>',
AdvancedOptions: '<<options>>',
PluginManager: '<<plugins>>',
ToolbarCommands: '|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|',
WindowTitle: '<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>'
};
//--
//-- Translateable strings
//--
// Strings in "double quotes" should be translated; strings in 'single quotes' should be left alone
merge(config.options,{
txtUserName: "YourName"});
merge(config.tasks,{
save: {text: "save", tooltip: "Save your changes to this TiddlyWiki", action: saveChanges},
sync: {text: "sync", tooltip: "Synchronise changes with other TiddlyWiki files and servers", content: '<<sync>>'},
importTask: {text: "import", tooltip: "Import tiddlers and plugins from other TiddlyWiki files and servers", content: '<<importTiddlers>>'},
tweak: {text: "tweak", tooltip: "Tweak the appearance and behaviour of TiddlyWiki", content: '<<options>>'},
upgrade: {text: "upgrade", tooltip: "Upgrade TiddlyWiki core code", content: '<<upgrade>>'},
plugins: {text: "plugins", tooltip: "Manage installed plugins", content: '<<plugins>>'}
});
// Options that can be set in the options panel and/or cookies
merge(config.optionsDesc,{
txtUserName: "Username for signing your edits",
chkRegExpSearch: "Enable regular expressions for searches",
chkCaseSensitiveSearch: "Case-sensitive searching",
chkIncrementalSearch: "Incremental key-by-key searching",
chkAnimate: "Enable animations",
chkSaveBackups: "Keep backup file when saving changes",
chkAutoSave: "Automatically save changes",
chkGenerateAnRssFeed: "Generate an RSS feed when saving changes",
chkSaveEmptyTemplate: "Generate an empty template when saving changes",
chkOpenInNewWindow: "Open external links in a new window",
chkToggleLinks: "Clicking on links to open tiddlers causes them to close",
chkHttpReadOnly: "Hide editing features when viewed over HTTP",
chkForceMinorUpdate: "Don't update modifier username and date when editing tiddlers",
chkConfirmDelete: "Require confirmation before deleting tiddlers",
chkInsertTabs: "Use the tab key to insert tab characters instead of moving between fields",
txtBackupFolder: "Name of folder to use for backups",
txtMaxEditRows: "Maximum number of rows in edit boxes",
txtTheme: "Name of the theme to use",
txtFileSystemCharSet: "Default character set for saving changes (Firefox/Mozilla only)"});
merge(config.messages,{
customConfigError: "Problems were encountered loading plugins. See PluginManager for details",
pluginError: "Error: %0",
pluginDisabled: "Not executed because disabled via 'systemConfigDisable' tag",
pluginForced: "Executed because forced via 'systemConfigForce' tag",
pluginVersionError: "Not executed because this plugin needs a newer version of TiddlyWiki",
nothingSelected: "Nothing is selected. You must select one or more items first",
savedSnapshotError: "It appears that this TiddlyWiki has been incorrectly saved. Please see http://www.tiddlywiki.com/#Download for details",
subtitleUnknown: "(unknown)",
undefinedTiddlerToolTip: "The tiddler '%0' doesn't yet exist",
shadowedTiddlerToolTip: "The tiddler '%0' doesn't yet exist, but has a pre-defined shadow value",
tiddlerLinkTooltip: "%0 - %1, %2",
externalLinkTooltip: "External link to %0",
noTags: "There are no tagged tiddlers",
notFileUrlError: "You need to save this TiddlyWiki to a file before you can save changes",
cantSaveError: "It's not possible to save changes. Possible reasons include:\n- your browser doesn't support saving (Firefox, Internet Explorer, Safari and Opera all work if properly configured)\n- the pathname to your TiddlyWiki file contains illegal characters\n- the TiddlyWiki HTML file has been moved or renamed",
invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
backupSaved: "Backup saved",
backupFailed: "Failed to save backup file",
rssSaved: "RSS feed saved",
rssFailed: "Failed to save RSS feed file",
emptySaved: "Empty template saved",
emptyFailed: "Failed to save empty template file",
mainSaved: "Main TiddlyWiki file saved",
mainFailed: "Failed to save main TiddlyWiki file. Your changes have not been saved",
macroError: "Error in macro <<\%0>>",
macroErrorDetails: "Error while executing macro <<\%0>>:\n%1",
missingMacro: "No such macro",
overwriteWarning: "A tiddler named '%0' already exists. Choose OK to overwrite it",
unsavedChangesWarning: "WARNING! There are unsaved changes in TiddlyWiki\n\nChoose OK to save\nChoose CANCEL to discard",
confirmExit: "--------------------------------\n\nThere are unsaved changes in TiddlyWiki. If you continue you will lose those changes\n\n--------------------------------",
saveInstructions: "SaveChanges",
unsupportedTWFormat: "Unsupported TiddlyWiki format '%0'",
tiddlerSaveError: "Error when saving tiddler '%0'",
tiddlerLoadError: "Error when loading tiddler '%0'",
wrongSaveFormat: "Cannot save with storage format '%0'. Using standard format for save.",
invalidFieldName: "Invalid field name %0",
fieldCannotBeChanged: "Field '%0' cannot be changed",
loadingMissingTiddler: "Attempting to retrieve the tiddler '%0' from the '%1' server at:\n\n'%2' in the workspace '%3'",
upgradeDone: "The upgrade to version %0 is now complete\n\nClick 'OK' to reload the newly upgraded TiddlyWiki",
invalidCookie: "Invalid cookie '%0'"});
merge(config.messages.messageClose,{
text: "close",
tooltip: "close this message area"});
config.messages.backstage = {
open: {text: "backstage", tooltip: "Open the backstage area to perform authoring and editing tasks"},
close: {text: "close", tooltip: "Close the backstage area"},
prompt: "backstage: ",
decal: {
edit: {text: "edit", tooltip: "Edit the tiddler '%0'"}
}
};
config.messages.listView = {
tiddlerTooltip: "Click for the full text of this tiddler",
previewUnavailable: "(preview not available)"
};
config.messages.dates.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"];
config.messages.dates.days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
config.messages.dates.shortMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
config.messages.dates.shortDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
// suffixes for dates, eg "1st","2nd","3rd"..."30th","31st"
config.messages.dates.daySuffixes = ["st","nd","rd","th","th","th","th","th","th","th",
"th","th","th","th","th","th","th","th","th","th",
"st","nd","rd","th","th","th","th","th","th","th",
"st"];
config.messages.dates.am = "am";
config.messages.dates.pm = "pm";
merge(config.messages.tiddlerPopup,{
});
merge(config.views.wikified.tag,{
labelNoTags: "no tags",
labelTags: "tags: ",
openTag: "Open tag '%0'",
tooltip: "Show tiddlers tagged with '%0'",
openAllText: "Open all",
openAllTooltip: "Open all of these tiddlers",
popupNone: "No other tiddlers tagged with '%0'"});
merge(config.views.wikified,{
defaultText: "The tiddler '%0' doesn't yet exist. Double-click to create it",
defaultModifier: "(missing)",
shadowModifier: "(built-in shadow tiddler)",
dateFormat: "DD MMM YYYY",
createdPrompt: "created"});
merge(config.views.editor,{
tagPrompt: "Type tags separated with spaces, [[use double square brackets]] if necessary, or add existing",
defaultText: "Type the text for '%0'"});
merge(config.views.editor.tagChooser,{
text: "tags",
tooltip: "Choose existing tags to add to this tiddler",
popupNone: "There are no tags defined",
tagTooltip: "Add the tag '%0'"});
merge(config.messages,{
sizeTemplates:
[
{unit: 1024*1024*1024, template: "%0\u00a0GB"},
{unit: 1024*1024, template: "%0\u00a0MB"},
{unit: 1024, template: "%0\u00a0KB"},
{unit: 1, template: "%0\u00a0B"}
]});
merge(config.macros.search,{
label: "search",
prompt: "Search this TiddlyWiki",
accessKey: "F",
successMsg: "%0 tiddlers found matching %1",
failureMsg: "No tiddlers found matching %0"});
merge(config.macros.tagging,{
label: "tagging: ",
labelNotTag: "not tagging",
tooltip: "List of tiddlers tagged with '%0'"});
merge(config.macros.timeline,{
dateFormat: "DD MMM YYYY"});
merge(config.macros.allTags,{
tooltip: "Show tiddlers tagged with '%0'",
noTags: "There are no tagged tiddlers"});
config.macros.list.all.prompt = "All tiddlers in alphabetical order";
config.macros.list.missing.prompt = "Tiddlers that have links to them but are not defined";
config.macros.list.orphans.prompt = "Tiddlers that are not linked to from any other tiddlers";
config.macros.list.shadowed.prompt = "Tiddlers shadowed with default contents";
config.macros.list.touched.prompt = "Tiddlers that have been modified locally";
merge(config.macros.closeAll,{
label: "close all",
prompt: "Close all displayed tiddlers (except any that are being edited)"});
merge(config.macros.permaview,{
label: "permaview",
prompt: "Link to an URL that retrieves all the currently displayed tiddlers"});
merge(config.macros.saveChanges,{
label: "save changes",
prompt: "Save all tiddlers to create a new TiddlyWiki",
accessKey: "S"});
merge(config.macros.newTiddler,{
label: "new tiddler",
prompt: "Create a new tiddler",
title: "New Tiddler",
accessKey: "N"});
merge(config.macros.newJournal,{
label: "new journal",
prompt: "Create a new tiddler from the current date and time",
accessKey: "J"});
merge(config.macros.options,{
wizardTitle: "Tweak advanced options",
step1Title: "These options are saved in cookies in your browser",
step1Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='false' name='chkUnknown'>Show unknown options</input>",
unknownDescription: "//(unknown)//",
listViewTemplate: {
columns: [
{name: 'Option', field: 'option', title: "Option", type: 'String'},
{name: 'Description', field: 'description', title: "Description", type: 'WikiText'},
{name: 'Name', field: 'name', title: "Name", type: 'String'}
],
rowClasses: [
{className: 'lowlight', field: 'lowlight'}
]}
});
merge(config.macros.plugins,{
wizardTitle: "Manage plugins",
step1Title: "Currently loaded plugins",
step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
skippedText: "(This plugin has not been executed because it was added since startup)",
noPluginText: "There are no plugins installed",
confirmDeleteText: "Are you sure you want to delete these plugins:\n\n%0",
removeLabel: "remove systemConfig tag",
removePrompt: "Remove systemConfig tag",
deleteLabel: "delete",
deletePrompt: "Delete these tiddlers forever",
listViewTemplate: {
columns: [
{name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
{name: 'Description', field: 'Description', title: "Description", type: 'String'},
{name: 'Version', field: 'Version', title: "Version", type: 'String'},
{name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
{name: 'Forced', field: 'forced', title: "Forced", tag: 'systemConfigForce', type: 'TagCheckbox'},
{name: 'Disabled', field: 'disabled', title: "Disabled", tag: 'systemConfigDisable', type: 'TagCheckbox'},
{name: 'Executed', field: 'executed', title: "Loaded", type: 'Boolean', trueText: "Yes", falseText: "No"},
{name: 'Startup Time', field: 'startupTime', title: "Startup Time", type: 'String'},
{name: 'Error', field: 'error', title: "Status", type: 'Boolean', trueText: "Error", falseText: "OK"},
{name: 'Log', field: 'log', title: "Log", type: 'StringList'}
],
rowClasses: [
{className: 'error', field: 'error'},
{className: 'warning', field: 'warning'}
]}
});
merge(config.macros.toolbar,{
moreLabel: "more",
morePrompt: "Show additional commands",
lessLabel: "less",
lessPrompt: "Hide additional commands",
separator: "|"
});
merge(config.macros.refreshDisplay,{
label: "refresh",
prompt: "Redraw the entire TiddlyWiki display"
});
merge(config.macros.importTiddlers,{
readOnlyWarning: "You cannot import into a read-only TiddlyWiki file. Try opening it from a file:// URL",
wizardTitle: "Import tiddlers from another file or server",
step1Title: "Step 1: Locate the server or TiddlyWiki file",
step1Html: "Specify the type of the server: <select name='selTypes'><option value=''>Choose...</option></select><br>Enter the URL or pathname here: <input type='text' size=50 name='txtPath'><br>...or browse for a file: <input type='file' size=50 name='txtBrowse'><br><hr>...or select a pre-defined feed: <select name='selFeeds'><option value=''>Choose...</option></select>",
openLabel: "open",
openPrompt: "Open the connection to this file or server",
statusOpenHost: "Opening the host",
statusGetWorkspaceList: "Getting the list of available workspaces",
step2Title: "Step 2: Choose the workspace",
step2Html: "Enter a workspace name: <input type='text' size=50 name='txtWorkspace'><br>...or select a workspace: <select name='selWorkspace'><option value=''>Choose...</option></select>",
cancelLabel: "cancel",
cancelPrompt: "Cancel this import",
statusOpenWorkspace: "Opening the workspace",
statusGetTiddlerList: "Getting the list of available tiddlers",
errorGettingTiddlerList: "Error getting list of tiddlers, click Cancel to try again",
step3Title: "Step 3: Choose the tiddlers to import",
step3Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='true' name='chkSync'>Keep these tiddlers linked to this server so that you can synchronise subsequent changes</input><br><input type='checkbox' name='chkSave'>Save the details of this server in a 'systemServer' tiddler called:</input> <input type='text' size=25 name='txtSaveTiddler'>",
importLabel: "import",
importPrompt: "Import these tiddlers",
confirmOverwriteText: "Are you sure you want to overwrite these tiddlers:\n\n%0",
step4Title: "Step 4: Importing %0 tiddler(s)",
step4Html: "<input type='hidden' name='markReport'></input>", // DO NOT TRANSLATE
doneLabel: "done",
donePrompt: "Close this wizard",
statusDoingImport: "Importing tiddlers",
statusDoneImport: "All tiddlers imported",
systemServerNamePattern: "%2 on %1",
systemServerNamePatternNoWorkspace: "%1",
confirmOverwriteSaveTiddler: "The tiddler '%0' already exists. Click 'OK' to overwrite it with the details of this server, or 'Cancel' to leave it unchanged",
serverSaveTemplate: "|''Type:''|%0|\n|''URL:''|%1|\n|''Workspace:''|%2|\n\nThis tiddler was automatically created to record the details of this server",
serverSaveModifier: "(System)",
listViewTemplate: {
columns: [
{name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
{name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
{name: 'Tags', field: 'tags', title: "Tags", type: 'Tags'}
],
rowClasses: [
]}
});
merge(config.macros.upgrade,{
wizardTitle: "Upgrade TiddlyWiki core code",
step1Title: "Update or repair this TiddlyWiki to the latest release",
step1Html: "You are about to upgrade to the latest release of the TiddlyWiki core code (from <a href='%0' class='externalLink' target='_blank'>%1</a>). Your content will be preserved across the upgrade.<br><br>Note that core upgrades have been known to interfere with older plugins. If you run into problems with the upgraded file, see <a href='http://www.tiddlywiki.org/wiki/CoreUpgrades' class='externalLink' target='_blank'>http://www.tiddlywiki.org/wiki/CoreUpgrades</a>",
errorCantUpgrade: "Unable to upgrade this TiddlyWiki. You can only perform upgrades on TiddlyWiki files stored locally",
errorNotSaved: "You must save changes before you can perform an upgrade",
step2Title: "Confirm the upgrade details",
step2Html_downgrade: "You are about to downgrade to TiddlyWiki version %0 from %1.<br><br>Downgrading to an earlier version of the core code is not recommended",
step2Html_restore: "This TiddlyWiki appears to be already using the latest version of the core code (%0).<br><br>You can continue to upgrade anyway to ensure that the core code hasn't been corrupted or damaged",
step2Html_upgrade: "You are about to upgrade to TiddlyWiki version %0 from %1",
upgradeLabel: "upgrade",
upgradePrompt: "Prepare for the upgrade process",
statusPreparingBackup: "Preparing backup",
statusSavingBackup: "Saving backup file",
errorSavingBackup: "There was a problem saving the backup file",
statusLoadingCore: "Loading core code",
errorLoadingCore: "Error loading the core code",
errorCoreFormat: "Error with the new core code",
statusSavingCore: "Saving the new core code",
statusReloadingCore: "Reloading the new core code",
startLabel: "start",
startPrompt: "Start the upgrade process",
cancelLabel: "cancel",
cancelPrompt: "Cancel the upgrade process",
step3Title: "Upgrade cancelled",
step3Html: "You have cancelled the upgrade process"
});
merge(config.macros.sync,{
listViewTemplate: {
columns: [
{name: 'Selected', field: 'selected', rowName: 'title', type: 'Selector'},
{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
{name: 'Server Type', field: 'serverType', title: "Server type", type: 'String'},
{name: 'Server Host', field: 'serverHost', title: "Server host", type: 'String'},
{name: 'Server Workspace', field: 'serverWorkspace', title: "Server workspace", type: 'String'},
{name: 'Status', field: 'status', title: "Synchronisation status", type: 'String'},
{name: 'Server URL', field: 'serverUrl', title: "Server URL", text: "View", type: 'Link'}
],
rowClasses: [
],
buttons: [
{caption: "Sync these tiddlers", name: 'sync'}
]},
wizardTitle: "Synchronize with external servers and files",
step1Title: "Choose the tiddlers you want to synchronize",
step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
syncLabel: "sync",
syncPrompt: "Sync these tiddlers",
hasChanged: "Changed while unplugged",
hasNotChanged: "Unchanged while unplugged",
syncStatusList: {
none: {text: "...", display:null, className:'notChanged'},
changedServer: {text: "Changed on server", display:null, className:'changedServer'},
changedLocally: {text: "Changed while unplugged", display:null, className:'changedLocally'},
changedBoth: {text: "Changed while unplugged and on server", display:null, className:'changedBoth'},
notFound: {text: "Not found on server", display:null, className:'notFound'},
putToServer: {text: "Saved update on server", display:null, className:'putToServer'},
gotFromServer: {text: "Retrieved update from server", display:null, className:'gotFromServer'}
}
});
merge(config.macros.annotations,{
});
merge(config.commands.closeTiddler,{
text: "close",
tooltip: "Close this tiddler"});
merge(config.commands.closeOthers,{
text: "close others",
tooltip: "Close all other tiddlers"});
merge(config.commands.editTiddler,{
text: "edit",
tooltip: "Edit this tiddler",
readOnlyText: "view",
readOnlyTooltip: "View the source of this tiddler"});
merge(config.commands.saveTiddler,{
text: "done",
tooltip: "Save changes to this tiddler"});
merge(config.commands.cancelTiddler,{
text: "cancel",
tooltip: "Undo changes to this tiddler",
warning: "Are you sure you want to abandon your changes to '%0'?",
readOnlyText: "done",
readOnlyTooltip: "View this tiddler normally"});
merge(config.commands.deleteTiddler,{
text: "delete",
tooltip: "Delete this tiddler",
warning: "Are you sure you want to delete '%0'?"});
merge(config.commands.permalink,{
text: "permalink",
tooltip: "Permalink for this tiddler"});
merge(config.commands.references,{
text: "references",
tooltip: "Show tiddlers that link to this one",
popupNone: "No references"});
merge(config.commands.jump,{
text: "jump",
tooltip: "Jump to another open tiddler"});
merge(config.commands.syncing,{
text: "syncing",
tooltip: "Control synchronisation of this tiddler with a server or external file",
currentlySyncing: "<div>Currently syncing via <span class='popupHighlight'>'%0'</span> to:</"+"div><div>host: <span class='popupHighlight'>%1</span></"+"div><div>workspace: <span class='popupHighlight'>%2</span></"+"div>", // Note escaping of closing <div> tag
notCurrentlySyncing: "Not currently syncing",
captionUnSync: "Stop synchronising this tiddler",
chooseServer: "Synchronise this tiddler with another server:",
currServerMarker: "\u25cf ",
notCurrServerMarker: " "});
merge(config.commands.fields,{
text: "fields",
tooltip: "Show the extended fields of this tiddler",
emptyText: "There are no extended fields for this tiddler",
listViewTemplate: {
columns: [
{name: 'Field', field: 'field', title: "Field", type: 'String'},
{name: 'Value', field: 'value', title: "Value", type: 'String'}
],
rowClasses: [
],
buttons: [
]}});
merge(config.shadowTiddlers,{
DefaultTiddlers: "[[GettingStarted]]",
MainMenu: "[[GettingStarted]]",
SiteTitle: "My TiddlyWiki",
SiteSubtitle: "a reusable non-linear personal web notebook",
SiteUrl: "",
SideBarOptions: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>',
SideBarTabs: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>',
TabMore: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'
});
merge(config.annotations,{
AdvancedOptions: "This shadow tiddler provides access to several advanced options",
ColorPalette: "These values in this shadow tiddler determine the colour scheme of the ~TiddlyWiki user interface",
DefaultTiddlers: "The tiddlers listed in this shadow tiddler will be automatically displayed when ~TiddlyWiki starts up",
EditTemplate: "The HTML template in this shadow tiddler determines how tiddlers look while they are being edited",
GettingStarted: "This shadow tiddler provides basic usage instructions",
ImportTiddlers: "This shadow tiddler provides access to importing tiddlers",
MainMenu: "This shadow tiddler is used as the contents of the main menu in the left-hand column of the screen",
MarkupPreHead: "This tiddler is inserted at the top of the <head> section of the TiddlyWiki HTML file",
MarkupPostHead: "This tiddler is inserted at the bottom of the <head> section of the TiddlyWiki HTML file",
MarkupPreBody: "This tiddler is inserted at the top of the <body> section of the TiddlyWiki HTML file",
MarkupPostBody: "This tiddler is inserted at the end of the <body> section of the TiddlyWiki HTML file immediately after the script block",
OptionsPanel: "This shadow tiddler is used as the contents of the options panel slider in the right-hand sidebar",
PageTemplate: "The HTML template in this shadow tiddler determines the overall ~TiddlyWiki layout",
PluginManager: "This shadow tiddler provides access to the plugin manager",
SideBarOptions: "This shadow tiddler is used as the contents of the option panel in the right-hand sidebar",
SideBarTabs: "This shadow tiddler is used as the contents of the tabs panel in the right-hand sidebar",
SiteSubtitle: "This shadow tiddler is used as the second part of the page title",
SiteTitle: "This shadow tiddler is used as the first part of the page title",
SiteUrl: "This shadow tiddler should be set to the full target URL for publication",
StyleSheetColors: "This shadow tiddler contains CSS definitions related to the color of page elements. ''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
StyleSheet: "This tiddler can contain custom CSS definitions",
StyleSheetLayout: "This shadow tiddler contains CSS definitions related to the layout of page elements. ''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
StyleSheetLocale: "This shadow tiddler contains CSS definitions related to the translation locale",
StyleSheetPrint: "This shadow tiddler contains CSS definitions for printing",
TabAll: "This shadow tiddler contains the contents of the 'All' tab in the right-hand sidebar",
TabMore: "This shadow tiddler contains the contents of the 'More' tab in the right-hand sidebar",
TabMoreMissing: "This shadow tiddler contains the contents of the 'Missing' tab in the right-hand sidebar",
TabMoreOrphans: "This shadow tiddler contains the contents of the 'Orphans' tab in the right-hand sidebar",
TabMoreShadowed: "This shadow tiddler contains the contents of the 'Shadowed' tab in the right-hand sidebar",
TabTags: "This shadow tiddler contains the contents of the 'Tags' tab in the right-hand sidebar",
TabTimeline: "This shadow tiddler contains the contents of the 'Timeline' tab in the right-hand sidebar",
ToolbarCommands: "This shadow tiddler determines which commands are shown in tiddler toolbars",
ViewTemplate: "The HTML template in this shadow tiddler determines how tiddlers look"
});
//--
//-- Main
//--
var params = null; // Command line parameters
var store = null; // TiddlyWiki storage
var story = null; // Main story
var formatter = null; // Default formatters for the wikifier
var anim = typeof Animator == "function" ? new Animator() : null; // Animation engine
var readOnly = false; // Whether we're in readonly mode
var highlightHack = null; // Embarrassing hack department...
var hadConfirmExit = false; // Don't warn more than once
var safeMode = false; // Disable all plugins and cookies
var showBackstage; // Whether to include the backstage area
var installedPlugins = []; // Information filled in when plugins are executed
var startingUp = false; // Whether we're in the process of starting up
var pluginInfo,tiddler; // Used to pass information to plugins in loadPlugins()
// Whether to use the JavaSaver applet
var useJavaSaver = (config.browser.isSafari || config.browser.isOpera) && (document.location.toString().substr(0,4) != "http");
// Starting up
function main()
{
var t10,t9,t8,t7,t6,t5,t4,t3,t2,t1,t0 = new Date();
startingUp = true;
var doc = jQuery(document);
jQuery.noConflict();
window.onbeforeunload = function(e) {if(window.confirmExit) return confirmExit();};
params = getParameters();
if(params)
params = params.parseParams("open",null,false);
store = new TiddlyWiki();
invokeParamifier(params,"oninit");
story = new Story("tiddlerDisplay","tiddler");
addEvent(document,"click",Popup.onDocumentClick);
saveTest();
loadOptionsCookie();
for(var s=0; s<config.notifyTiddlers.length; s++)
store.addNotification(config.notifyTiddlers[s].name,config.notifyTiddlers[s].notify);
t1 = new Date();
loadShadowTiddlers();
doc.trigger("loadShadows");
t2 = new Date();
store.loadFromDiv("storeArea","store",true);
doc.trigger("loadTiddlers");
t3 = new Date();
invokeParamifier(params,"onload");
t4 = new Date();
readOnly = (window.location.protocol == "file:") ? false : config.options.chkHttpReadOnly;
var pluginProblem = loadPlugins();
doc.trigger("loadPlugins");
t5 = new Date();
formatter = new Formatter(config.formatters);
invokeParamifier(params,"onconfig");
story.switchTheme(config.options.txtTheme);
showBackstage = showBackstage !== undefined ? showBackstage : !readOnly;
t6 = new Date();
for(var m in config.macros) {
if(config.macros[m].init)
config.macros[m].init();
}
t7 = new Date();
store.notifyAll();
t8 = new Date();
restart();
refreshDisplay();
t9 = new Date();
if(pluginProblem) {
story.displayTiddler(null,"PluginManager");
displayMessage(config.messages.customConfigError);
}
if(showBackstage)
backstage.init();
t10 = new Date();
if(config.options.chkDisplayInstrumentation) {
displayMessage("LoadShadows " + (t2-t1) + " ms");
displayMessage("LoadFromDiv " + (t3-t2) + " ms");
displayMessage("LoadPlugins " + (t5-t4) + " ms");
displayMessage("Macro init " + (t7-t6) + " ms");
displayMessage("Notify " + (t8-t7) + " ms");
displayMessage("Restart " + (t9-t8) + " ms");
displayMessage("Total: " + (t10-t0) + " ms");
}
startingUp = false;
doc.trigger("startup");
}
// Called on unload. All functions called conditionally since they themselves may have been unloaded.
function unload()
{
if(window.checkUnsavedChanges)
checkUnsavedChanges();
if(window.scrubNodes)
scrubNodes(document.body);
}
// Restarting
function restart()
{
invokeParamifier(params,"onstart");
if(story.isEmpty()) {
story.displayDefaultTiddlers();
}
window.scrollTo(0,0);
}
function saveTest()
{
var s = document.getElementById("saveTest");
if(s.hasChildNodes())
alert(config.messages.savedSnapshotError);
s.appendChild(document.createTextNode("savetest"));
}
function loadShadowTiddlers()
{
var shadows = new TiddlyWiki();
shadows.loadFromDiv("shadowArea","shadows",true);
shadows.forEachTiddler(function(title,tiddler){config.shadowTiddlers[title] = tiddler.text;});
delete shadows;
}
function loadPlugins()
{
if(safeMode)
return false;
var tiddlers = store.getTaggedTiddlers("systemConfig");
var toLoad = [];
var nLoaded = 0;
var map = {};
var nPlugins = tiddlers.length;
installedPlugins = [];
for(var i=0; i<nPlugins; i++) {
var p = getPluginInfo(tiddlers[i]);
installedPlugins[i] = p;
var n = p.Name || p.title;
if(n)
map[n] = p;
n = p.Source;
if(n)
map[n] = p;
}
var visit = function(p) {
if(!p || p.done)
return;
p.done = 1;
var reqs = p.Requires;
if(reqs) {
reqs = reqs.readBracketedList();
for(var i=0; i<reqs.length; i++)
visit(map[reqs[i]]);
}
toLoad.push(p);
};
for(i=0; i<nPlugins; i++)
visit(installedPlugins[i]);
for(i=0; i<toLoad.length; i++) {
p = toLoad[i];
pluginInfo = p;
tiddler = p.tiddler;
if(isPluginExecutable(p)) {
if(isPluginEnabled(p)) {
p.executed = true;
var startTime = new Date();
try {
if(tiddler.text)
window.eval(tiddler.text);
nLoaded++;
} catch(ex) {
p.log.push(config.messages.pluginError.format([exceptionText(ex)]));
p.error = true;
if(!console.tiddlywiki) {
console.log("error evaluating " + tiddler.title, ex);
}
}
pluginInfo.startupTime = String((new Date()) - startTime) + "ms";
} else {
nPlugins--;
}
} else {
p.warning = true;
}
}
return nLoaded != nPlugins;
}
function getPluginInfo(tiddler)
{
var p = store.getTiddlerSlices(tiddler.title,["Name","Description","Version","Requires","CoreVersion","Date","Source","Author","License","Browsers"]);
p.tiddler = tiddler;
p.title = tiddler.title;
p.log = [];
return p;
}
// Check that a particular plugin is valid for execution
function isPluginExecutable(plugin)
{
if(plugin.tiddler.isTagged("systemConfigForce")) {
plugin.log.push(config.messages.pluginForced);
return true;
}
if(plugin["CoreVersion"]) {
var coreVersion = plugin["CoreVersion"].split(".");
var w = parseInt(coreVersion[0],10) - version.major;
if(w == 0 && coreVersion[1])
w = parseInt(coreVersion[1],10) - version.minor;
if(w == 0 && coreVersion[2])
w = parseInt(coreVersion[2],10) - version.revision;
if(w > 0) {
plugin.log.push(config.messages.pluginVersionError);
return false;
}
}
return true;
}
function isPluginEnabled(plugin)
{
if(plugin.tiddler.isTagged("systemConfigDisable")) {
plugin.log.push(config.messages.pluginDisabled);
return false;
}
return true;
}
function invokeMacro(place,macro,params,wikifier,tiddler)
{
try {
var m = config.macros[macro];
if(m && m.handler) {
var tiddlerElem = story.findContainingTiddler(place);
window.tiddler = tiddlerElem ? store.getTiddler(tiddlerElem.getAttribute("tiddler")) : null;
window.place = place;
m.handler(place,macro,m.noPreParse?null:params.readMacroParams(),wikifier,params,tiddler);
} else {
createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,config.messages.missingMacro]));
}
} catch(ex) {
createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,ex.toString()]));
}
}
//--
//-- Paramifiers
//--
function getParameters()
{
var p = null;
if(window.location.hash) {
p = decodeURIComponent(window.location.hash.substr(1));
if(config.browser.firefoxDate != null && config.browser.firefoxDate[1] < "20051111")
p = convertUTF8ToUnicode(p);
}
return p;
}
function invokeParamifier(params,handler)
{
if(!params || params.length == undefined || params.length <= 1)
return;
for(var i=1; i<params.length; i++) {
var p = config.paramifiers[params[i].name];
if(p && p[handler] instanceof Function)
p[handler](params[i].value);
else {
var h = config.optionHandlers[params[i].name.substr(0,3)];
if(h && h.set instanceof Function)
h.set(params[i].name,params[i].value);
}
}
}
config.paramifiers = {};
config.paramifiers.start = {
oninit: function(v) {
safeMode = v.toLowerCase() == "safe";
}
};
config.paramifiers.open = {
onstart: function(v) {
if(!readOnly || store.tiddlerExists(v) || store.isShadowTiddler(v))
story.displayTiddler("bottom",v,null,false,null);
}
};
config.paramifiers.story = {
onstart: function(v) {
var list = store.getTiddlerText(v,"").parseParams("open",null,false);
invokeParamifier(list,"onstart");
}
};
config.paramifiers.search = {
onstart: function(v) {
story.search(v,false,false);
}
};
config.paramifiers.searchRegExp = {
onstart: function(v) {
story.prototype.search(v,false,true);
}
};
config.paramifiers.tag = {
onstart: function(v) {
story.displayTiddlers(null,store.filterTiddlers("[tag["+v+"]]"),null,false,null);
}
};
config.paramifiers.newTiddler = {
onstart: function(v) {
if(!readOnly) {
story.displayTiddler(null,v,DEFAULT_EDIT_TEMPLATE);
story.focusTiddler(v,"text");
}
}
};
config.paramifiers.newJournal = {
onstart: function(v) {
if(!readOnly) {
var now = new Date();
var title = now.formatString(v.trim());
story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE);
story.focusTiddler(title,"text");
}
}
};
config.paramifiers.readOnly = {
onconfig: function(v) {
var p = v.toLowerCase();
readOnly = p == "yes" ? true : (p == "no" ? false : readOnly);
}
};
config.paramifiers.theme = {
onconfig: function(v) {
story.switchTheme(v);
}
};
config.paramifiers.upgrade = {
onstart: function(v) {
upgradeFrom(v);
}
};
config.paramifiers.recent= {
onstart: function(v) {
var titles=[];
var tiddlers=store.getTiddlers("modified","excludeLists").reverse();
for(var i=0; i<v && i<tiddlers.length; i++)
titles.push(tiddlers[i].title);
story.displayTiddlers(null,titles);
}
};
config.paramifiers.filter = {
onstart: function(v) {
story.displayTiddlers(null,store.filterTiddlers(v),null,false);
}
};
//--
//-- Formatter helpers
//--
function Formatter(formatters)
{
this.formatters = [];
var pattern = [];
for(var n=0; n<formatters.length; n++) {
pattern.push("(" + formatters[n].match + ")");
this.formatters.push(formatters[n]);
}
this.formatterRegExp = new RegExp(pattern.join("|"),"mg");
}
config.formatterHelpers = {
createElementAndWikify: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
},
inlineCssHelper: function(w)
{
var styles = [];
config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var s,v;
if(lookaheadMatch[1]) {
s = lookaheadMatch[1].unDash();
v = lookaheadMatch[2];
} else {
s = lookaheadMatch[3].unDash();
v = lookaheadMatch[4];
}
if(s=="bgcolor")
s = "backgroundColor";
styles.push({style: s, value: v});
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
}
return styles;
},
applyCssHelper: function(e,styles)
{
for(var t=0; t< styles.length; t++) {
try {
e.style[styles[t].style] = styles[t].value;
} catch (ex) {
}
}
},
enclosedTextHelper: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
if(config.browser.isIE)
text = text.replace(/\n/g,"\r");
createTiddlyElement(w.output,this.element,null,null,text);
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
},
isExternalLink: function(link)
{
if(store.tiddlerExists(link) || store.isShadowTiddler(link)) {
return false;
}
var urlRegExp = new RegExp(config.textPrimitives.urlPattern,"mg");
if(urlRegExp.exec(link)) {
return true;
}
if(link.indexOf(".")!=-1 || link.indexOf("\\")!=-1 || link.indexOf("/")!=-1 || link.indexOf("#")!=-1) {
return true;
}
return false;
}
};
//--
//-- Standard formatters
//--
config.formatters = [
{
name: "table",
match: "^\\|(?:[^\\n]*)\\|(?:[fhck]?)$",
lookaheadRegExp: /^\|([^\n]*)\|([fhck]?)$/mg,
rowTermRegExp: /(\|(?:[fhck]?)$\n?)/mg,
cellRegExp: /(?:\|([^\n\|]*)\|)|(\|[fhck]?$\n?)/mg,
cellTermRegExp: /((?:\x20*)\|)/mg,
rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
handler: function(w)
{
var table = createTiddlyElement(w.output,"table",null,"twtable");
var prevColumns = [];
var currRowType = null;
var rowContainer;
var rowCount = 0;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
var nextRowType = lookaheadMatch[2];
if(nextRowType == "k") {
table.className = lookaheadMatch[1];
w.nextMatch += lookaheadMatch[0].length+1;
} else {
if(nextRowType != currRowType) {
rowContainer = createTiddlyElement(table,this.rowTypes[nextRowType]);
currRowType = nextRowType;
}
if(currRowType == "c") {
// Caption
w.nextMatch++;
if(rowContainer != table.firstChild)
table.insertBefore(rowContainer,table.firstChild);
rowContainer.setAttribute("align",rowCount == 0?"top":"bottom");
w.subWikifyTerm(rowContainer,this.rowTermRegExp);
} else {
var theRow = createTiddlyElement(rowContainer,"tr",null,(rowCount&1)?"oddRow":"evenRow");
theRow.onmouseover = function() {addClass(this,"hoverRow");};
theRow.onmouseout = function() {removeClass(this,"hoverRow");};
this.rowHandler(w,theRow,prevColumns);
rowCount++;
}
}
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
},
rowHandler: function(w,e,prevColumns)
{
var col = 0;
var colSpanCount = 1;
var prevCell = null;
this.cellRegExp.lastIndex = w.nextMatch;
var cellMatch = this.cellRegExp.exec(w.source);
while(cellMatch && cellMatch.index == w.nextMatch) {
if(cellMatch[1] == "~") {
// Rowspan
var last = prevColumns[col];
if(last) {
last.rowSpanCount++;
last.element.setAttribute("rowspan",last.rowSpanCount);
last.element.setAttribute("rowSpan",last.rowSpanCount); // Needed for IE
last.element.valign = "center";
if(colSpanCount > 1) {
last.element.setAttribute("colspan",colSpanCount);
last.element.setAttribute("colSpan",colSpanCount); // Needed for IE
colSpanCount = 1;
}
}
w.nextMatch = this.cellRegExp.lastIndex-1;
} else if(cellMatch[1] == ">") {
// Colspan
colSpanCount++;
w.nextMatch = this.cellRegExp.lastIndex-1;
} else if(cellMatch[2]) {
// End of row
if(prevCell && colSpanCount > 1) {
prevCell.setAttribute("colspan",colSpanCount);
prevCell.setAttribute("colSpan",colSpanCount); // Needed for IE
}
w.nextMatch = this.cellRegExp.lastIndex;
break;
} else {
// Cell
w.nextMatch++;
var styles = config.formatterHelpers.inlineCssHelper(w);
var spaceLeft = false;
var chr = w.source.substr(w.nextMatch,1);
while(chr == " ") {
spaceLeft = true;
w.nextMatch++;
chr = w.source.substr(w.nextMatch,1);
}
var cell;
if(chr == "!") {
cell = createTiddlyElement(e,"th");
w.nextMatch++;
} else {
cell = createTiddlyElement(e,"td");
}
prevCell = cell;
prevColumns[col] = {rowSpanCount:1,element:cell};
if(colSpanCount > 1) {
cell.setAttribute("colspan",colSpanCount);
cell.setAttribute("colSpan",colSpanCount); // Needed for IE
colSpanCount = 1;
}
config.formatterHelpers.applyCssHelper(cell,styles);
w.subWikifyTerm(cell,this.cellTermRegExp);
if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
cell.align = spaceLeft ? "center" : "left";
else if(spaceLeft)
cell.align = "right";
w.nextMatch--;
}
col++;
this.cellRegExp.lastIndex = w.nextMatch;
cellMatch = this.cellRegExp.exec(w.source);
}
}
},
{
name: "heading",
match: "^!{1,6}",
termRegExp: /(\n)/mg,
handler: function(w)
{
w.subWikifyTerm(createTiddlyElement(w.output,"h" + w.matchLength),this.termRegExp);
}
},
{
name: "list",
match: "^(?:[\\*#;:]+)",
lookaheadRegExp: /^(?:(?:(\*)|(#)|(;)|(:))+)/mg,
termRegExp: /(\n)/mg,
handler: function(w)
{
var stack = [w.output];
var currLevel = 0, currType = null;
var listLevel, listType, itemType, baseType;
w.nextMatch = w.matchStart;
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
if(lookaheadMatch[1]) {
listType = "ul";
itemType = "li";
} else if(lookaheadMatch[2]) {
listType = "ol";
itemType = "li";
} else if(lookaheadMatch[3]) {
listType = "dl";
itemType = "dt";
} else if(lookaheadMatch[4]) {
listType = "dl";
itemType = "dd";
}
if(!baseType)
baseType = listType;
listLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
var t;
if(listLevel > currLevel) {
for(t=currLevel; t<listLevel; t++) {
var target = (currLevel == 0) ? stack[stack.length-1] : stack[stack.length-1].lastChild;
stack.push(createTiddlyElement(target,listType));
}
} else if(listType!=baseType && listLevel==1) {
w.nextMatch -= lookaheadMatch[0].length;
return;
} else if(listLevel < currLevel) {
for(t=currLevel; t>listLevel; t--)
stack.pop();
} else if(listLevel == currLevel && listType != currType) {
stack.pop();
stack.push(createTiddlyElement(stack[stack.length-1].lastChild,listType));
}
currLevel = listLevel;
currType = listType;
var e = createTiddlyElement(stack[stack.length-1],itemType);
w.subWikifyTerm(e,this.termRegExp);
this.lookaheadRegExp.lastIndex = w.nextMatch;
lookaheadMatch = this.lookaheadRegExp.exec(w.source);
}
}
},
{
name: "quoteByBlock",
match: "^<<<\\n",
termRegExp: /(^<<<(\n|$))/mg,
element: "blockquote",
handler: config.formatterHelpers.createElementAndWikify
},
{
name: "quoteByLine",
match: "^>+",
lookaheadRegExp: /^>+/mg,
termRegExp: /(\n)/mg,
element: "blockquote",
handler: function(w)
{
var stack = [w.output];
var currLevel = 0;
var newLevel = w.matchLength;
var t;
do {
if(newLevel > currLevel) {
for(t=currLevel; t<newLevel; t++)
stack.push(createTiddlyElement(stack[stack.length-1],this.element));
} else if(newLevel < currLevel) {
for(t=currLevel; t>newLevel; t--)
stack.pop();
}
currLevel = newLevel;
w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
createTiddlyElement(stack[stack.length-1],"br");
this.lookaheadRegExp.lastIndex = w.nextMatch;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
var matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
if(matched) {
newLevel = lookaheadMatch[0].length;
w.nextMatch += lookaheadMatch[0].length;
}
} while(matched);
}
},
{
name: "rule",
match: "^----+$\\n?|<hr ?/?>\\n?",
handler: function(w)
{
createTiddlyElement(w.output,"hr");
}
},
{
name: "monospacedByLine",
match: "^(?:/\\*\\{\\{\\{\\*/|\\{\\{\\{|//\\{\\{\\{|<!--\\{\\{\\{-->)\\n",
element: "pre",
handler: function(w)
{
switch(w.matchText) {
case "/*{{{*/\n": // CSS
this.lookaheadRegExp = /\/\*\{\{\{\*\/\n*((?:^[^\n]*\n)+?)(\n*^\f*\/\*\}\}\}\*\/$\n?)/mg;
break;
case "{{{\n": // monospaced block
this.lookaheadRegExp = /^\{\{\{\n((?:^[^\n]*\n)+?)(^\f*\}\}\}$\n?)/mg;
break;
case "//{{{\n": // plugin
this.lookaheadRegExp = /^\/\/\{\{\{\n\n*((?:^[^\n]*\n)+?)(\n*^\f*\/\/\}\}\}$\n?)/mg;
break;
case "<!--{{{-->\n": //template
this.lookaheadRegExp = /<!--\{\{\{-->\n*((?:^[^\n]*\n)+?)(\n*^\f*<!--\}\}\}-->$\n?)/mg;
break;
default:
break;
}
config.formatterHelpers.enclosedTextHelper.call(this,w);
}
},
{
name: "wikifyComment",
match: "^(?:/\\*\\*\\*|<!---)\\n",
handler: function(w)
{
var termRegExp = (w.matchText == "/***\n") ? (/(^\*\*\*\/\n)/mg) : (/(^--->\n)/mg);
w.subWikifyTerm(w.output,termRegExp);
}
},
{
name: "macro",
match: "<<",
lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
w.nextMatch = this.lookaheadRegExp.lastIndex;
invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
}
}
},
{
name: "prettyLink",
match: "\\[\\[",
lookaheadRegExp: /\[\[(.*?)(?:\|(~)?(.*?))?\]\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e;
var text = lookaheadMatch[1];
if(lookaheadMatch[3]) {
// Pretty bracketted link
var link = lookaheadMatch[3];
e = (!lookaheadMatch[2] && config.formatterHelpers.isExternalLink(link)) ?
createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
} else {
// Simple bracketted link
e = createTiddlyLink(w.output,text,false,null,w.isStatic,w.tiddler);
}
createTiddlyText(e,text);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "wikiLink",
match: config.textPrimitives.unWikiLink+"?"+config.textPrimitives.wikiLink,
handler: function(w)
{
if(w.matchText.substr(0,1) == config.textPrimitives.unWikiLink) {
w.outputText(w.output,w.matchStart+1,w.nextMatch);
return;
}
if(w.matchStart > 0) {
var preRegExp = new RegExp(config.textPrimitives.anyLetterStrict,"mg");
preRegExp.lastIndex = w.matchStart-1;
var preMatch = preRegExp.exec(w.source);
if(preMatch.index == w.matchStart-1) {
w.outputText(w.output,w.matchStart,w.nextMatch);
return;
}
}
if(w.autoLinkWikiWords || store.isShadowTiddler(w.matchText)) {
var link = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic,w.tiddler);
w.outputText(link,w.matchStart,w.nextMatch);
} else {
w.outputText(w.output,w.matchStart,w.nextMatch);
}
}
},
{
name: "urlLink",
match: config.textPrimitives.urlPattern,
handler: function(w)
{
w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
}
},
{
name: "image",
match: "\\[[<>]?[Ii][Mm][Gg]\\[",
lookaheadRegExp: /\[([<]?)(>?)[Ii][Mm][Gg]\[(?:([^\|\]]+)\|)?([^\[\]\|]+)\](?:\[([^\]]*)\])?\]/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = w.output;
if(lookaheadMatch[5]) {
var link = lookaheadMatch[5];
e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
addClass(e,"imageLink");
}
var img = createTiddlyElement(e,"img");
if(lookaheadMatch[1])
img.align = "left";
else if(lookaheadMatch[2])
img.align = "right";
if(lookaheadMatch[3]) {
img.title = lookaheadMatch[3];
img.setAttribute("alt",lookaheadMatch[3]);
}
img.src = lookaheadMatch[4];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "html",
match: "<[Hh][Tt][Mm][Ll]>",
lookaheadRegExp: /<[Hh][Tt][Mm][Ll]>((?:.|\n)*?)<\/[Hh][Tt][Mm][Ll]>/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"span").innerHTML = lookaheadMatch[1];
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "commentByBlock",
match: "/%",
lookaheadRegExp: /\/%((?:.|\n)*?)%\//mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart)
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
},
{
name: "characterFormat",
match: "''|//|__|\\^\\^|~~|--(?!\\s|$)|\\{\\{\\{",
handler: function(w)
{
switch(w.matchText) {
case "''":
w.subWikifyTerm(w.output.appendChild(document.createElement("strong")),/('')/mg);
break;
case "//":
w.subWikifyTerm(createTiddlyElement(w.output,"em"),/(\/\/)/mg);
break;
case "__":
w.subWikifyTerm(createTiddlyElement(w.output,"u"),/(__)/mg);
break;
case "^^":
w.subWikifyTerm(createTiddlyElement(w.output,"sup"),/(\^\^)/mg);
break;
case "~~":
w.subWikifyTerm(createTiddlyElement(w.output,"sub"),/(~~)/mg);
break;
case "--":
w.subWikifyTerm(createTiddlyElement(w.output,"strike"),/(--)/mg);
break;
case "{{{":
var lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"code",null,null,lookaheadMatch[1]);
w.nextMatch = lookaheadRegExp.lastIndex;
}
break;
}
}
},
{
name: "customFormat",
match: "@@|\\{\\{",
handler: function(w)
{
switch(w.matchText) {
case "@@":
var e = createTiddlyElement(w.output,"span");
var styles = config.formatterHelpers.inlineCssHelper(w);
if(styles.length == 0)
e.className = "marked";
else
config.formatterHelpers.applyCssHelper(e,styles);
w.subWikifyTerm(e,/(@@)/mg);
break;
case "{{":
var lookaheadRegExp = /\{\{[\s]*([\w]+[\s\w]*)[\s]*\{(\n?)/mg;
lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch) {
w.nextMatch = lookaheadRegExp.lastIndex;
e = createTiddlyElement(w.output,lookaheadMatch[2] == "\n" ? "div" : "span",null,lookaheadMatch[1]);
w.subWikifyTerm(e,/(\}\}\})/mg);
}
break;
}
}
},
{
name: "mdash",
match: "--",
handler: function(w)
{
createTiddlyElement(w.output,"span").innerHTML = "&mdash;";
}
},
{
name: "lineBreak",
match: "\\n|<br ?/?>",
handler: function(w)
{
createTiddlyElement(w.output,"br");
}
},
{
name: "rawText",
match: "\"{3}|<nowiki>",
lookaheadRegExp: /(?:\"{3}|<nowiki>)((?:.|\n)*?)(?:\"{3}|<\/nowiki>)/mg,
handler: function(w)
{
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
createTiddlyElement(w.output,"span",null,null,lookaheadMatch[1]);
w.nextMatch = this.lookaheadRegExp.lastIndex;
}
}
},
{
name: "htmlEntitiesEncoding",
match: "(?:(?:&#?[a-zA-Z0-9]{2,8};|.)(?:&#?(?:x0*(?:3[0-6][0-9a-fA-F]|1D[c-fC-F][0-9a-fA-F]|20[d-fD-F][0-9a-fA-F]|FE2[0-9a-fA-F])|0*(?:76[89]|7[7-9][0-9]|8[0-7][0-9]|761[6-9]|76[2-7][0-9]|84[0-3][0-9]|844[0-7]|6505[6-9]|6506[0-9]|6507[0-1]));)+|&#?[a-zA-Z0-9]{2,8};)",
handler: function(w)
{
createTiddlyElement(w.output,"span").innerHTML = w.matchText;
}
}
];
//--
//-- Wikifier
//--
function getParser(tiddler,format)
{
if(tiddler) {
if(!format)
format = tiddler.fields["wikiformat"];
var i;
if(format) {
for(i in config.parsers) {
if(format == config.parsers[i].format)
return config.parsers[i];
}
} else {
for(i in config.parsers) {
if(tiddler.isTagged(config.parsers[i].formatTag))
return config.parsers[i];
}
}
}
return formatter;
}
function wikify(source,output,highlightRegExp,tiddler)
{
if(source) {
var wikifier = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
var t0 = new Date();
wikifier.subWikify(output);
if(tiddler && config.options.chkDisplayInstrumentation)
displayMessage("wikify:" +tiddler.title+ " in " + (new Date()-t0) + " ms");
}
}
function wikifyStatic(source,highlightRegExp,tiddler,format)
{
var e = createTiddlyElement(document.body,"pre");
e.style.display = "none";
var html = "";
if(source && source != "") {
if(!tiddler)
tiddler = new Tiddler("temp");
var wikifier = new Wikifier(source,getParser(tiddler,format),highlightRegExp,tiddler);
wikifier.isStatic = true;
wikifier.subWikify(e);
html = e.innerHTML;
removeNode(e);
}
return html;
}
function wikifyPlain(title,theStore,limit)
{
if(!theStore)
theStore = store;
if(theStore.tiddlerExists(title) || theStore.isShadowTiddler(title)) {
return wikifyPlainText(theStore.getTiddlerText(title),limit,tiddler);
} else {
return "";
}
}
function wikifyPlainText(text,limit,tiddler)
{
if(limit > 0)
text = text.substr(0,limit);
var wikifier = new Wikifier(text,formatter,null,tiddler);
return wikifier.wikifyPlain();
}
function highlightify(source,output,highlightRegExp,tiddler)
{
if(source) {
var wikifier = new Wikifier(source,formatter,highlightRegExp,tiddler);
wikifier.outputText(output,0,source.length);
}
}
function Wikifier(source,formatter,highlightRegExp,tiddler)
{
this.source = source;
this.output = null;
this.formatter = formatter;
this.nextMatch = 0;
this.autoLinkWikiWords = tiddler && tiddler.autoLinkWikiWords() == false ? false : true;
this.highlightRegExp = highlightRegExp;
this.highlightMatch = null;
this.isStatic = false;
if(highlightRegExp) {
highlightRegExp.lastIndex = 0;
this.highlightMatch = highlightRegExp.exec(source);
}
this.tiddler = tiddler;
}
Wikifier.prototype.wikifyPlain = function()
{
var e = createTiddlyElement(document.body,"div");
e.style.display = "none";
this.subWikify(e);
var text = getPlainText(e);
removeNode(e);
return text;
};
Wikifier.prototype.subWikify = function(output,terminator)
{
try {
if(terminator)
this.subWikifyTerm(output,new RegExp("(" + terminator + ")","mg"));
else
this.subWikifyUnterm(output);
} catch(ex) {
showException(ex);
}
};
Wikifier.prototype.subWikifyUnterm = function(output)
{
var oldOutput = this.output;
this.output = output;
this.formatter.formatterRegExp.lastIndex = this.nextMatch;
var formatterMatch = this.formatter.formatterRegExp.exec(this.source);
while(formatterMatch) {
// Output any text before the match
if(formatterMatch.index > this.nextMatch)
this.outputText(this.output,this.nextMatch,formatterMatch.index);
// Set the match parameters for the handler
this.matchStart = formatterMatch.index;
this.matchLength = formatterMatch[0].length;
this.matchText = formatterMatch[0];
this.nextMatch = this.formatter.formatterRegExp.lastIndex;
for(var t=1; t<formatterMatch.length; t++) {
if(formatterMatch[t]) {
this.formatter.formatters[t-1].handler(this);
this.formatter.formatterRegExp.lastIndex = this.nextMatch;
break;
}
}
formatterMatch = this.formatter.formatterRegExp.exec(this.source);
}
if(this.nextMatch < this.source.length) {
this.outputText(this.output,this.nextMatch,this.source.length);
this.nextMatch = this.source.length;
}
this.output = oldOutput;
};
Wikifier.prototype.subWikifyTerm = function(output,terminatorRegExp)
{
var oldOutput = this.output;
this.output = output;
terminatorRegExp.lastIndex = this.nextMatch;
var terminatorMatch = terminatorRegExp.exec(this.source);
this.formatter.formatterRegExp.lastIndex = this.nextMatch;
var formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
while(terminatorMatch || formatterMatch) {
if(terminatorMatch && (!formatterMatch || terminatorMatch.index <= formatterMatch.index)) {
if(terminatorMatch.index > this.nextMatch)
this.outputText(this.output,this.nextMatch,terminatorMatch.index);
this.matchText = terminatorMatch[1];
this.matchLength = terminatorMatch[1].length;
this.matchStart = terminatorMatch.index;
this.nextMatch = this.matchStart + this.matchLength;
this.output = oldOutput;
return;
}
if(formatterMatch.index > this.nextMatch)
this.outputText(this.output,this.nextMatch,formatterMatch.index);
this.matchStart = formatterMatch.index;
this.matchLength = formatterMatch[0].length;
this.matchText = formatterMatch[0];
this.nextMatch = this.formatter.formatterRegExp.lastIndex;
for(var t=1; t<formatterMatch.length; t++) {
if(formatterMatch[t]) {
this.formatter.formatters[t-1].handler(this);
this.formatter.formatterRegExp.lastIndex = this.nextMatch;
break;
}
}
terminatorRegExp.lastIndex = this.nextMatch;
terminatorMatch = terminatorRegExp.exec(this.source);
formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
}
if(this.nextMatch < this.source.length) {
this.outputText(this.output,this.nextMatch,this.source.length);
this.nextMatch = this.source.length;
}
this.output = oldOutput;
};
Wikifier.prototype.outputText = function(place,startPos,endPos)
{
while(this.highlightMatch && (this.highlightRegExp.lastIndex > startPos) && (this.highlightMatch.index < endPos) && (startPos < endPos)) {
if(this.highlightMatch.index > startPos) {
createTiddlyText(place,this.source.substring(startPos,this.highlightMatch.index));
startPos = this.highlightMatch.index;
}
var highlightEnd = Math.min(this.highlightRegExp.lastIndex,endPos);
var theHighlight = createTiddlyElement(place,"span",null,"highlight",this.source.substring(startPos,highlightEnd));
startPos = highlightEnd;
if(startPos >= this.highlightRegExp.lastIndex)
this.highlightMatch = this.highlightRegExp.exec(this.source);
}
if(startPos < endPos) {
createTiddlyText(place,this.source.substring(startPos,endPos));
}
};
//--
//-- Macro definitions
//--
config.macros.today.handler = function(place,macroName,params)
{
var now = new Date();
var text = params[0] ? now.formatString(params[0].trim()) : now.toLocaleString();
jQuery("<span/>").text(text).appendTo(place);
};
config.macros.version.handler = function(place)
{
jQuery("<span/>").text(formatVersion()).appendTo(place);
};
config.macros.list.handler = function(place,macroName,params)
{
var type = params[0] || "all";
var list = document.createElement("ul");
place.appendChild(list);
if(this[type].prompt)
createTiddlyElement(list,"li",null,"listTitle",this[type].prompt);
var results;
if(this[type].handler)
results = this[type].handler(params);
for(var t = 0; t < results.length; t++) {
var li = document.createElement("li");
list.appendChild(li);
createTiddlyLink(li,typeof results[t] == "string" ? results[t] : results[t].title,true);
}
};
config.macros.list.all.handler = function(params)
{
return store.reverseLookup("tags","excludeLists",false,"title");
};
config.macros.list.missing.handler = function(params)
{
return store.getMissingLinks();
};
config.macros.list.orphans.handler = function(params)
{
return store.getOrphans();
};
config.macros.list.shadowed.handler = function(params)
{
return store.getShadowed();
};
config.macros.list.touched.handler = function(params)
{
return store.getTouched();
};
config.macros.list.filter.handler = function(params)
{
var filter = params[1];
var results = [];
if(filter) {
var tiddlers = store.filterTiddlers(filter);
for(var t=0; t<tiddlers.length; t++)
results.push(tiddlers[t].title);
}
return results;
};
config.macros.allTags.handler = function(place,macroName,params)
{
var tags = store.getTags(params[0]);
var ul = createTiddlyElement(place,"ul");
if(tags.length == 0)
createTiddlyElement(ul,"li",null,"listTitle",this.noTags);
for(var t=0; t<tags.length; t++) {
var title = tags[t][0];
var info = getTiddlyLinkInfo(title);
var li = createTiddlyElement(ul,"li");
var btn = createTiddlyButton(li,title + " (" + tags[t][1] + ")",this.tooltip.format([title]),onClickTag,info.classes);
btn.setAttribute("tag",title);
btn.setAttribute("refresh","link");
btn.setAttribute("tiddlyLink",title);
if(params[1]) {
btn.setAttribute("sortby",params[1]);
}
}
};
config.macros.timeline.handler = function(place,macroName,params)
{
var field = params[0] || "modified";
var tiddlers = store.reverseLookup("tags","excludeLists",false,field);
var lastDay = "";
var last = params[1] ? tiddlers.length-Math.min(tiddlers.length,parseInt(params[1])) : 0;
var dateFormat = params[2] || this.dateFormat;
for(var t=tiddlers.length-1; t>=last; t--) {
var tiddler = tiddlers[t];
var theDay = tiddler[field].convertToLocalYYYYMMDDHHMM().substr(0,8);
if(theDay != lastDay) {
var ul = document.createElement("ul");
addClass(ul,"timeline");
place.appendChild(ul);
createTiddlyElement(ul,"li",null,"listTitle",tiddler[field].formatString(dateFormat));
lastDay = theDay;
}
createTiddlyElement(ul,"li",null,"listLink").appendChild(createTiddlyLink(place,tiddler.title,true));
}
};
config.macros.tiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
params = paramString.parseParams("name",null,true,false,true);
var names = params[0]["name"];
var tiddlerName = names[0];
var className = names[1] || null;
var args = params[0]["with"];
var wrapper = createTiddlyElement(place,"span",null,className,null,{
refresh: "content", tiddler: tiddlerName
});
if(args!==undefined)
wrapper.setAttribute("args","[["+args.join("]] [[")+"]]");
this.transclude(wrapper,tiddlerName,args);
};
config.macros.tiddler.transclude = function(wrapper,tiddlerName,args)
{
var text = store.getTiddlerText(tiddlerName);
if(!text)
return;
var stack = config.macros.tiddler.tiddlerStack;
if(stack.indexOf(tiddlerName) !== -1)
return;
stack.push(tiddlerName);
try {
if(typeof args == "string")
args = args.readBracketedList();
var n = args ? Math.min(args.length,9) : 0;
for(var i=0; i<n; i++) {
var placeholderRE = new RegExp("\\$" + (i + 1),"mg");
text = text.replace(placeholderRE,args[i]);
}
config.macros.tiddler.renderText(wrapper,text,tiddlerName,params);
} finally {
stack.pop();
}
};
config.macros.tiddler.renderText = function(place,text,tiddlerName,params)
{
wikify(text,place,null,store.getTiddler(tiddlerName));
};
config.macros.tiddler.tiddlerStack = [];
config.macros.tag.handler = function(place,macroName,params)
{
createTagButton(place,params[0],null,params[1],params[2]);
if(params[3]) {
btn.setAttribute('sortby',params[3]);
}
};
config.macros.tags.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
params = paramString.parseParams("anon",null,true,false,false);
var ul = createTiddlyElement(place,"ul");
var title = getParam(params,"anon","");
if(title && store.tiddlerExists(title))
tiddler = store.getTiddler(title);
var sep = getParam(params,"sep"," ");
var lingo = config.views.wikified.tag;
var label = null;
for(var t=0; t<tiddler.tags.length; t++) {
var tag = store.getTiddler(tiddler.tags[t]);
if(!tag || !tag.tags.contains("excludeLists")) {
if(!label)
label = createTiddlyElement(ul,"li",null,"listTitle",lingo.labelTags.format([tiddler.title]));
createTagButton(createTiddlyElement(ul,"li"),tiddler.tags[t],tiddler.title);
if(t<tiddler.tags.length-1)
createTiddlyText(ul,sep);
}
}
if(!label)
createTiddlyElement(ul,"li",null,"listTitle",lingo.labelNoTags.format([tiddler.title]));
};
config.macros.tagging.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
params = paramString.parseParams("anon",null,true,false,false);
var ul = createTiddlyElement(place,"ul");
var title = getParam(params,"anon","");
if(title == "" && tiddler instanceof Tiddler)
title = tiddler.title;
var sep = getParam(params,"sep"," ");
ul.setAttribute("title",this.tooltip.format([title]));
var tagged = store.getTaggedTiddlers(title);
var prompt = tagged.length == 0 ? this.labelNotTag : this.label;
createTiddlyElement(ul,"li",null,"listTitle",prompt.format([title,tagged.length]));
for(var t=0; t<tagged.length; t++) {
createTiddlyLink(createTiddlyElement(ul,"li"),tagged[t].title,true);
if(t<tagged.length-1)
createTiddlyText(ul,sep);
}
};
config.macros.closeAll.handler = function(place)
{
createTiddlyButton(place,this.label,this.prompt,this.onClick);
};
config.macros.closeAll.onClick = function(e)
{
story.closeAllTiddlers();
return false;
};
config.macros.permaview.handler = function(place)
{
createTiddlyButton(place,this.label,this.prompt,this.onClick);
};
config.macros.permaview.onClick = function(e)
{
story.permaView();
return false;
};
config.macros.saveChanges.handler = function(place,macroName,params)
{
if(!readOnly)
createTiddlyButton(place,params[0] || this.label,params[1] || this.prompt,this.onClick,null,null,this.accessKey);
};
config.macros.saveChanges.onClick = function(e)
{
saveChanges();
return false;
};
config.macros.slider.onClickSlider = function(ev)
{
var e = ev || window.event;
var n = this.nextSibling;
var cookie = n.getAttribute("cookie");
var isOpen = n.style.display != "none";
if(config.options.chkAnimate && anim && typeof Slider == "function")
anim.startAnimating(new Slider(n,!isOpen,null,"none"));
else
n.style.display = isOpen ? "none" : "block";
config.options[cookie] = !isOpen;
saveOptionCookie(cookie);
return false;
};
config.macros.slider.createSlider = function(place,cookie,title,tooltip)
{
var c = cookie || "";
var btn = createTiddlyButton(place,title,tooltip,this.onClickSlider);
var panel = createTiddlyElement(null,"div",null,"sliderPanel");
panel.setAttribute("cookie",c);
panel.style.display = config.options[c] ? "block" : "none";
place.appendChild(panel);
return panel;
};
config.macros.slider.handler = function(place,macroName,params)
{
var panel = this.createSlider(place,params[0],params[2],params[3]);
var text = store.getTiddlerText(params[1]);
panel.setAttribute("refresh","content");
panel.setAttribute("tiddler",params[1]);
if(text)
wikify(text,panel,null,store.getTiddler(params[1]));
};
// <<gradient [[tiddler name]] vert|horiz rgb rgb rgb rgb... >>
config.macros.gradient.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
var panel = wikifier ? createTiddlyElement(place,"div",null,"gradient") : place;
panel.style.position = "relative";
panel.style.overflow = "hidden";
panel.style.zIndex = "0";
if(wikifier) {
var styles = config.formatterHelpers.inlineCssHelper(wikifier);
config.formatterHelpers.applyCssHelper(panel,styles);
}
params = paramString.parseParams("color");
var locolors = [], hicolors = [];
for(var t=2; t<params.length; t++) {
var c = params[t].value;
if(params[t].name == "snap") {
hicolors[hicolors.length-1] = c;
} else {
locolors.push(c);
hicolors.push(c);
}
}
drawGradient(panel,params[1].value != "vert",locolors,hicolors);
if(wikifier)
wikifier.subWikify(panel,">>");
if(document.all) {
panel.style.height = "100%";
panel.style.width = "100%";
}
};
config.macros.message.handler = function(place,macroName,params)
{
if(params[0]) {
var names = params[0].split(".");
var lookupMessage = function(root,nameIndex) {
if(names[nameIndex] in root) {
if(nameIndex < names.length-1)
return (lookupMessage(root[names[nameIndex]],nameIndex+1));
else
return root[names[nameIndex]];
} else
return null;
};
var m = lookupMessage(config,0);
if(m == null)
m = lookupMessage(window,0);
createTiddlyText(place,m.toString().format(params.splice(1)));
}
};
config.macros.view.views = {
text: function(value,place,params,wikifier,paramString,tiddler) {
highlightify(value,place,highlightHack,tiddler);
},
link: function(value,place,params,wikifier,paramString,tiddler) {
createTiddlyLink(place,value,true);
},
wikified: function(value,place,params,wikifier,paramString,tiddler) {
if(params[2])
value=params[2].unescapeLineBreaks().format([value]);
wikify(value,place,highlightHack,tiddler);
},
date: function(value,place,params,wikifier,paramString,tiddler) {
value = Date.convertFromYYYYMMDDHHMM(value);
createTiddlyText(place,value.formatString(params[2] ? params[2] : config.views.wikified.dateFormat));
}
};
config.macros.view.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if((tiddler instanceof Tiddler) && params[0]) {
var value = store.getValue(tiddler,params[0]);
if(value) {
var type = params[1] || config.macros.view.defaultView;
var handler = config.macros.view.views[type];
if(handler)
handler(value,place,params,wikifier,paramString,tiddler);
}
}
};
config.macros.edit.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
var field = params[0];
var rows = params[1] || 0;
var defVal = params[2] || '';
if((tiddler instanceof Tiddler) && field) {
story.setDirty(tiddler.title,true);
var e,v;
if(field != "text" && !rows) {
e = createTiddlyElement(null,"input",null,null,null,{
type: "text", edit: field, size: "40", autocomplete: "off"
});
e.value = store.getValue(tiddler,field) || defVal;
place.appendChild(e);
} else {
var wrapper1 = createTiddlyElement(null,"fieldset",null,"fieldsetFix");
var wrapper2 = createTiddlyElement(wrapper1,"div");
e = createTiddlyElement(wrapper2,"textarea");
e.value = v = store.getValue(tiddler,field) || defVal;
rows = rows || 10;
var lines = v.match(/\n/mg);
var maxLines = Math.max(parseInt(config.options.txtMaxEditRows),5);
if(lines != null && lines.length > rows)
rows = lines.length + 5;
rows = Math.min(rows,maxLines);
e.setAttribute("rows",rows);
e.setAttribute("edit",field);
place.appendChild(wrapper1);
}
if(tiddler.isReadOnly()) {
e.setAttribute("readOnly","readOnly");
addClass(e,"readOnly");
}
return e;
}
};
config.macros.tagChooser.onClick = function(ev)
{
var e = ev || window.event;
var lingo = config.views.editor.tagChooser;
var popup = Popup.create(this);
var tags = store.getTags(this.getAttribute("tags"));
if(tags.length == 0)
jQuery("<li/>").text(lingo.popupNone).appendTo(popup);
for(var t=0; t<tags.length; t++) {
var tag = createTiddlyButton(createTiddlyElement(popup,"li"),tags[t][0],lingo.tagTooltip.format([tags[t][0]]),config.macros.tagChooser.onTagClick);
tag.setAttribute("tag",tags[t][0]);
tag.setAttribute("tiddler",this.getAttribute("tiddler"));
}
Popup.show();
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
return false;
};
config.macros.tagChooser.onTagClick = function(ev)
{
var e = ev || window.event;
if(e.metaKey || e.ctrlKey) stopEvent(e); //# keep popup open on CTRL-click
var tag = this.getAttribute("tag");
var title = this.getAttribute("tiddler");
if(!readOnly)
story.setTiddlerTag(title,tag,0);
return false;
};
config.macros.tagChooser.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if(tiddler instanceof Tiddler) {
var lingo = config.views.editor.tagChooser;
var btn = createTiddlyButton(place,lingo.text,lingo.tooltip,this.onClick);
btn.setAttribute("tiddler",tiddler.title);
btn.setAttribute("tags",params[0]);
}
};
config.macros.refreshDisplay.handler = function(place)
{
createTiddlyButton(place,this.label,this.prompt,this.onClick);
};
config.macros.refreshDisplay.onClick = function(e)
{
refreshAll();
return false;
};
config.macros.annotations.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
var title = tiddler ? tiddler.title : null;
var a = title ? config.annotations[title] : null;
if(!tiddler || !title || !a)
return;
var text = a.format([title]);
wikify(text,createTiddlyElement(place,"div",null,"annotation"),null,tiddler);
};
//--
//-- NewTiddler and NewJournal macros
//--
config.macros.newTiddler.createNewTiddlerButton = function(place,title,params,label,prompt,accessKey,newFocus,isJournal)
{
var tags = [];
for(var t=1; t<params.length; t++) {
if((params[t].name == "anon" && t != 1) || (params[t].name == "tag"))
tags.push(params[t].value);
}
label = getParam(params,"label",label);
prompt = getParam(params,"prompt",prompt);
accessKey = getParam(params,"accessKey",accessKey);
newFocus = getParam(params,"focus",newFocus);
var customFields = getParam(params,"fields","");
if(!customFields && !store.isShadowTiddler(title))
customFields = String.encodeHashMap(config.defaultCustomFields);
var btn = createTiddlyButton(place,label,prompt,this.onClickNewTiddler,null,null,accessKey);
btn.setAttribute("newTitle",title);
btn.setAttribute("isJournal",isJournal ? "true" : "false");
if(tags.length > 0)
btn.setAttribute("params",tags.join("|"));
btn.setAttribute("newFocus",newFocus);
btn.setAttribute("newTemplate",getParam(params,"template",DEFAULT_EDIT_TEMPLATE));
if(customFields !== "")
btn.setAttribute("customFields",customFields);
var text = getParam(params,"text");
if(text !== undefined)
btn.setAttribute("newText",text);
return btn;
};
config.macros.newTiddler.onClickNewTiddler = function()
{
var title = this.getAttribute("newTitle");
if(this.getAttribute("isJournal") == "true") {
title = new Date().formatString(title.trim());
}
var params = this.getAttribute("params");
var tags = params ? params.split("|") : [];
var focus = this.getAttribute("newFocus");
var template = this.getAttribute("newTemplate");
var customFields = this.getAttribute("customFields");
if(!customFields && !store.isShadowTiddler(title))
customFields = String.encodeHashMap(config.defaultCustomFields);
story.displayTiddler(null,title,template,false,null,null);
var tiddlerElem = story.getTiddler(title);
if(customFields)
story.addCustomFields(tiddlerElem,customFields);
var text = this.getAttribute("newText");
if(typeof text == "string" && story.getTiddlerField(title,"text"))
story.getTiddlerField(title,"text").value = text.format([title]);
for(var t=0;t<tags.length;t++)
story.setTiddlerTag(title,tags[t],+1);
story.focusTiddler(title,focus);
return false;
};
config.macros.newTiddler.handler = function(place,macroName,params,wikifier,paramString)
{
if(!readOnly) {
params = paramString.parseParams("anon",null,true,false,false);
var title = params[1] && params[1].name == "anon" ? params[1].value : this.title;
title = getParam(params,"title",title);
this.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"title",false);
}
};
config.macros.newJournal.handler = function(place,macroName,params,wikifier,paramString)
{
if(!readOnly) {
params = paramString.parseParams("anon",null,true,false,false);
var title = params[1] && params[1].name == "anon" ? params[1].value : config.macros.timeline.dateFormat;
title = getParam(params,"title",title);
config.macros.newTiddler.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"text",true);
}
};
//--
//-- Search macro
//--
config.macros.search.handler = function(place,macroName,params)
{
var searchTimeout = null;
var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick,"searchButton");
var txt = createTiddlyElement(null,"input",null,"txtOptionInput searchField");
if(params[0])
txt.value = params[0];
if(config.browser.isSafari) {
txt.setAttribute("type","search");
txt.setAttribute("results","5");
} else {
txt.setAttribute("type","text");
}
place.appendChild(txt);
txt.onkeyup = this.onKeyPress;
txt.onfocus = this.onFocus;
txt.setAttribute("size",this.sizeTextbox);
txt.setAttribute("accessKey",params[1] || this.accessKey);
txt.setAttribute("autocomplete","off");
txt.setAttribute("lastSearchText","");
};
// Global because there's only ever one outstanding incremental search timer
config.macros.search.timeout = null;
config.macros.search.doSearch = function(txt)
{
if(txt.value.length > 0) {
story.search(txt.value,config.options.chkCaseSensitiveSearch,config.options.chkRegExpSearch);
txt.setAttribute("lastSearchText",txt.value);
}
};
config.macros.search.onClick = function(e)
{
config.macros.search.doSearch(this.nextSibling);
return false;
};
config.macros.search.onKeyPress = function(ev)
{
var me = config.macros.search;
var e = ev || window.event;
switch(e.keyCode) {
case 13: // Ctrl-Enter
case 10: // Ctrl-Enter on IE PC
me.doSearch(this);
break;
case 27: // Escape
this.value = "";
clearMessage();
break;
}
if(config.options.chkIncrementalSearch) {
if(this.value.length > 2) {
if(this.value != this.getAttribute("lastSearchText")) {
if(me.timeout)
clearTimeout(me.timeout);
var txt = this;
me.timeout = setTimeout(function() {me.doSearch(txt);},500);
}
} else {
if(me.timeout)
clearTimeout(me.timeout);
}
}
};
config.macros.search.onFocus = function(e)
{
this.select();
};
//--
//-- Tabs macro
//--
config.macros.tabs.handler = function(place,macroName,params)
{
var cookie = params[0];
var numTabs = (params.length-1)/3;
var wrapper = createTiddlyElement(null,"div",null,"tabsetWrapper " + cookie);
var tabset = createTiddlyElement(wrapper,"div",null,"tabset");
tabset.setAttribute("cookie",cookie);
var validTab = false;
for(var t=0; t<numTabs; t++) {
var label = params[t*3+1];
var prompt = params[t*3+2];
var content = params[t*3+3];
var tab = createTiddlyButton(tabset,label,prompt,this.onClickTab,"tab tabUnselected");
createTiddlyElement(tab,"span",null,null," ",{style:"font-size:0pt;line-height:0px"});
tab.setAttribute("tab",label);
tab.setAttribute("content",content);
tab.title = prompt;
if(config.options[cookie] == label)
validTab = true;
}
if(!validTab)
config.options[cookie] = params[1];
place.appendChild(wrapper);
this.switchTab(tabset,config.options[cookie]);
};
config.macros.tabs.onClickTab = function(e)
{
config.macros.tabs.switchTab(this.parentNode,this.getAttribute("tab"));
return false;
};
config.macros.tabs.switchTab = function(tabset,tab)
{
var cookie = tabset.getAttribute("cookie");
var theTab = null;
var nodes = tabset.childNodes;
for(var t=0; t<nodes.length; t++) {
if(nodes[t].getAttribute && nodes[t].getAttribute("tab") == tab) {
theTab = nodes[t];
theTab.className = "tab tabSelected";
} else {
nodes[t].className = "tab tabUnselected";
}
}
if(theTab) {
if(tabset.nextSibling && tabset.nextSibling.className == "tabContents")
removeNode(tabset.nextSibling);
var tabContent = createTiddlyElement(null,"div",null,"tabContents");
tabset.parentNode.insertBefore(tabContent,tabset.nextSibling);
var contentTitle = theTab.getAttribute("content");
wikify(store.getTiddlerText(contentTitle),tabContent,null,store.getTiddler(contentTitle));
if(cookie) {
config.options[cookie] = tab;
saveOptionCookie(cookie);
}
}
};
//--
//-- Tiddler toolbar
//--
// Create a toolbar command button
config.macros.toolbar.createCommand = function(place,commandName,tiddler,className)
{
if(typeof commandName != "string") {
var c = null;
for(var t in config.commands) {
if(config.commands[t] == commandName)
c = t;
}
commandName = c;
}
if((tiddler instanceof Tiddler) && (typeof commandName == "string")) {
var command = config.commands[commandName];
if(command.isEnabled ? command.isEnabled(tiddler) : this.isCommandEnabled(command,tiddler)) {
var text = command.getText ? command.getText(tiddler) : this.getCommandText(command,tiddler);
var tooltip = command.getTooltip ? command.getTooltip(tiddler) : this.getCommandTooltip(command,tiddler);
var cmd;
switch(command.type) {
case "popup":
cmd = this.onClickPopup;
break;
case "command":
default:
cmd = this.onClickCommand;
break;
}
var btn = createTiddlyButton(null,text,tooltip,cmd);
btn.setAttribute("commandName",commandName);
btn.setAttribute("tiddler",tiddler.title);
addClass(btn,"command_" + commandName);
if(className)
addClass(btn,className);
place.appendChild(btn);
}
}
};
config.macros.toolbar.isCommandEnabled = function(command,tiddler)
{
var title = tiddler.title;
var ro = tiddler.isReadOnly();
var shadow = store.isShadowTiddler(title) && !store.tiddlerExists(title);
return (!ro || (ro && !command.hideReadOnly)) && !(shadow && command.hideShadow);
};
config.macros.toolbar.getCommandText = function(command,tiddler)
{
return tiddler.isReadOnly() && command.readOnlyText || command.text;
};
config.macros.toolbar.getCommandTooltip = function(command,tiddler)
{
return tiddler.isReadOnly() && command.readOnlyTooltip || command.tooltip;
};
config.macros.toolbar.onClickCommand = function(ev)
{
var e = ev || window.event;
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
var command = config.commands[this.getAttribute("commandName")];
return command.handler(e,this,this.getAttribute("tiddler"));
};
config.macros.toolbar.onClickPopup = function(ev)
{
var e = ev || window.event;
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
var popup = Popup.create(this);
var command = config.commands[this.getAttribute("commandName")];
var title = this.getAttribute("tiddler");
var tiddler = store.fetchTiddler(title);
popup.setAttribute("tiddler",title);
command.handlePopup(popup,title);
Popup.show();
return false;
};
// Invoke the first command encountered from a given place that is tagged with a specified class
config.macros.toolbar.invokeCommand = function(place,className,event)
{
var children = place.getElementsByTagName("a");
for(var t=0; t<children.length; t++) {
var c = children[t];
if(hasClass(c,className) && c.getAttribute && c.getAttribute("commandName")) {
if(c.onclick instanceof Function)
c.onclick.call(c,event);
break;
}
}
};
config.macros.toolbar.onClickMore = function(ev)
{
var e = this.nextSibling;
e.style.display = "inline";
this.style.display = "none";
return false;
};
config.macros.toolbar.onClickLess = function(ev)
{
var e = this.parentNode;
var m = e.previousSibling;
e.style.display = "none";
m.style.display = "inline";
return false;
};
config.macros.toolbar.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
for(var t=0; t<params.length; t++) {
var c = params[t];
switch(c) {
case "!":
createTiddlyText(place,this.separator);
break;
case "*":
createTiddlyElement(place,"br");
break;
case "<":
var btn = createTiddlyButton(place,this.lessLabel,this.lessPrompt,config.macros.toolbar.onClickLess);
addClass(btn,"lessCommand");
break;
case ">":
var btn = createTiddlyButton(place,this.moreLabel,this.morePrompt,config.macros.toolbar.onClickMore);
addClass(btn,"moreCommand");
var e = createTiddlyElement(place,"span",null,"moreCommand");
e.style.display = "none";
place = e;
break;
default:
var className = "";
switch(c.substr(0,1)) {
case "+":
className = "defaultCommand";
c = c.substr(1);
break;
case "-":
className = "cancelCommand";
c = c.substr(1);
break;
}
if(c in config.commands) {
this.createCommand(place,c,tiddler,className);
} else {
this.customCommand(place,c,wikifier,tiddler);
}
break;
}
}
};
// Overrideable function to extend toolbar handler
config.macros.toolbar.customCommand = function(place,command,wikifier,tiddler)
{
}
//--
//-- Menu and toolbar commands
//--
config.commands.closeTiddler.handler = function(event,src,title)
{
if(story.isDirty(title) && !readOnly) {
if(!confirm(config.commands.cancelTiddler.warning.format([title])))
return false;
}
story.setDirty(title,false);
story.closeTiddler(title,true);
return false;
};
config.commands.closeOthers.handler = function(event,src,title)
{
story.closeAllTiddlers(title);
return false;
};
config.commands.editTiddler.handler = function(event,src,title)
{
clearMessage();
var tiddlerElem = story.getTiddler(title);
var fields = tiddlerElem.getAttribute("tiddlyFields");
story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE,false,null,fields);
story.focusTiddler(title,config.options.txtEditorFocus||"text");
return false;
};
config.commands.saveTiddler.handler = function(event,src,title)
{
var newTitle = story.saveTiddler(title,event.shiftKey);
if(newTitle)
story.displayTiddler(null,newTitle);
return false;
};
config.commands.cancelTiddler.handler = function(event,src,title)
{
if(story.hasChanges(title) && !readOnly) {
if(!confirm(this.warning.format([title])))
return false;
}
story.setDirty(title,false);
story.displayTiddler(null,title);
return false;
};
config.commands.deleteTiddler.handler = function(event,src,title)
{
var deleteIt = true;
if(config.options.chkConfirmDelete)
deleteIt = confirm(this.warning.format([title]));
if(deleteIt) {
store.removeTiddler(title);
story.closeTiddler(title,true);
autoSaveChanges();
}
return false;
};
config.commands.permalink.handler = function(event,src,title)
{
var t = encodeURIComponent(String.encodeTiddlyLink(title));
if(window.location.hash != t)
window.location.hash = t;
return false;
};
config.commands.references.handlePopup = function(popup,title)
{
var references = store.getReferringTiddlers(title);
var c = false;
for(var r=0; r<references.length; r++) {
if(references[r].title != title && !references[r].isTagged("excludeLists")) {
createTiddlyLink(createTiddlyElement(popup,"li"),references[r].title,true);
c = true;
}
}
if(!c)
createTiddlyElement(popup,"li",null,"disabled",this.popupNone);
};
config.commands.jump.handlePopup = function(popup,title)
{
story.forEachTiddler(function(title,element) {
createTiddlyLink(createTiddlyElement(popup,"li"),title,true,null,false,null,true);
});
};
config.commands.syncing.handlePopup = function(popup,title)
{
var me = config.commands.syncing;
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return;
var serverType = tiddler.getServerType();
var serverHost = tiddler.fields["server.host"];
var serverWorkspace = tiddler.fields["server.workspace"];
if(!serverWorkspace)
serverWorkspace = "";
if(serverType) {
var e = createTiddlyElement(popup,"li",null,"popupMessage");
e.innerHTML = me.currentlySyncing.format([serverType,serverHost,serverWorkspace]);
} else {
createTiddlyElement(popup,"li",null,"popupMessage",me.notCurrentlySyncing);
}
if(serverType) {
createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
var btn = createTiddlyButton(createTiddlyElement(popup,"li"),this.captionUnSync,null,me.onChooseServer);
btn.setAttribute("tiddler",title);
btn.setAttribute("server.type","");
}
createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
createTiddlyElement(popup,"li",null,"popupMessage",me.chooseServer);
var feeds = store.getTaggedTiddlers("systemServer","title");
for(var t=0; t<feeds.length; t++) {
var f = feeds[t];
var feedServerType = store.getTiddlerSlice(f.title,"Type");
if(!feedServerType)
feedServerType = "file";
var feedServerHost = store.getTiddlerSlice(f.title,"URL");
if(!feedServerHost)
feedServerHost = "";
var feedServerWorkspace = store.getTiddlerSlice(f.title,"Workspace");
if(!feedServerWorkspace)
feedServerWorkspace = "";
var caption = f.title;
if(serverType == feedServerType && serverHost == feedServerHost && serverWorkspace == feedServerWorkspace) {
caption = me.currServerMarker + caption;
} else {
caption = me.notCurrServerMarker + caption;
}
btn = createTiddlyButton(createTiddlyElement(popup,"li"),caption,null,me.onChooseServer);
btn.setAttribute("tiddler",title);
btn.setAttribute("server.type",feedServerType);
btn.setAttribute("server.host",feedServerHost);
btn.setAttribute("server.workspace",feedServerWorkspace);
}
};
config.commands.syncing.onChooseServer = function(e)
{
var tiddler = this.getAttribute("tiddler");
var serverType = this.getAttribute("server.type");
if(serverType) {
store.addTiddlerFields(tiddler,{
"server.type": serverType,
"server.host": this.getAttribute("server.host"),
"server.workspace": this.getAttribute("server.workspace")
});
} else {
store.setValue(tiddler,"server",null);
}
return false;
};
config.commands.fields.handlePopup = function(popup,title)
{
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return;
var items = [];
store.forEachField(tiddler,function(tiddler,fieldName,value){items.push({field:fieldName,value:value});},true);
items.sort(function(a,b) {return a.field < b.field ? -1 : (a.field == b.field ? 0 : +1);});
if(items.length > 0)
ListView.create(popup,items,this.listViewTemplate);
else
createTiddlyElement(popup,"div",null,null,this.emptyText);
};
//--
//-- Tiddler() object
//--
function Tiddler(title)
{
this.title = title;
this.text = "";
this.creator = null;
this.modifier = null;
this.created = new Date();
this.modified = this.created;
this.links = [];
this.linksUpdated = false;
this.tags = [];
this.fields = {};
return this;
}
Tiddler.prototype.getLinks = function()
{
if(this.linksUpdated==false)
this.changed();
return this.links;
};
// Returns the fields that are inherited in string field:"value" field2:"value2" format
Tiddler.prototype.getInheritedFields = function()
{
var f = {};
for(var i in this.fields) {
if(i=="server.host" || i=="server.workspace" || i=="wikiformat"|| i=="server.type") {
f[i] = this.fields[i];
}
}
return String.encodeHashMap(f);
};
// Increment the changeCount of a tiddler
Tiddler.prototype.incChangeCount = function()
{
var c = this.fields['changecount'];
c = c ? parseInt(c,10) : 0;
this.fields['changecount'] = String(c+1);
};
// Clear the changeCount of a tiddler
Tiddler.prototype.clearChangeCount = function()
{
if(this.fields['changecount']) {
delete this.fields['changecount'];
}
};
Tiddler.prototype.doNotSave = function()
{
return this.fields['doNotSave'];
};
// Returns true if the tiddler has been updated since the tiddler was created or downloaded
Tiddler.prototype.isTouched = function()
{
var changeCount = this.fields['changecount'];
if(changeCount === undefined)
changeCount = 0;
return changeCount > 0;
};
// Change the text and other attributes of a tiddler
Tiddler.prototype.set = function(title,text,modifier,modified,tags,created,fields,creator)
{
this.assign(title,text,modifier,modified,tags,created,fields,creator);
this.changed();
return this;
};
// Change the text and other attributes of a tiddler without triggered a tiddler.changed() call
Tiddler.prototype.assign = function(title,text,modifier,modified,tags,created,fields,creator)
{
if(title != undefined)
this.title = title;
if(text != undefined)
this.text = text;
if(modifier != undefined)
this.modifier = modifier;
if(modified != undefined)
this.modified = modified;
if(creator != undefined)
this.creator = creator;
if(created != undefined)
this.created = created;
if(fields != undefined)
this.fields = fields;
if(tags != undefined)
this.tags = (typeof tags == "string") ? tags.readBracketedList() : tags;
else if(this.tags == undefined)
this.tags = [];
return this;
};
// Get the tags for a tiddler as a string (space delimited, using [[brackets]] for tags containing spaces)
Tiddler.prototype.getTags = function()
{
return String.encodeTiddlyLinkList(this.tags);
};
// Test if a tiddler carries a tag
Tiddler.prototype.isTagged = function(tag)
{
return this.tags.indexOf(tag) != -1;
};
// Static method to convert "\n" to newlines, "\s" to "\"
Tiddler.unescapeLineBreaks = function(text)
{
return text ? text.unescapeLineBreaks() : "";
};
// Convert newlines to "\n", "\" to "\s"
Tiddler.prototype.escapeLineBreaks = function()
{
return this.text.escapeLineBreaks();
};
// Updates the secondary information (like links[] array) after a change to a tiddler
Tiddler.prototype.changed = function()
{
this.links = [];
var text = this.text;
// remove 'quoted' text before scanning tiddler source
text = text.replace(/\/%((?:.|\n)*?)%\//g,"").
replace(/\{{3}((?:.|\n)*?)\}{3}/g,"").
replace(/"""((?:.|\n)*?)"""/g,"").
replace(/\<nowiki\>((?:.|\n)*?)\<\/nowiki\>/g,"").
replace(/\<html\>((?:.|\n)*?)\<\/html\>/g,"").
replace(/\<script((?:.|\n)*?)\<\/script\>/g,"");
var t = this.autoLinkWikiWords() ? 0 : 1;
var tiddlerLinkRegExp = t==0 ? config.textPrimitives.tiddlerAnyLinkRegExp : config.textPrimitives.tiddlerForcedLinkRegExp;
tiddlerLinkRegExp.lastIndex = 0;
var formatMatch = tiddlerLinkRegExp.exec(text);
while(formatMatch) {
var lastIndex = tiddlerLinkRegExp.lastIndex;
if(t==0 && formatMatch[1] && formatMatch[1] != this.title) {
// wikiWordLink
if(formatMatch.index > 0) {
var preRegExp = new RegExp(config.textPrimitives.unWikiLink+"|"+config.textPrimitives.anyLetter,"mg");
preRegExp.lastIndex = formatMatch.index-1;
var preMatch = preRegExp.exec(text);
if(preMatch.index != formatMatch.index-1)
this.links.pushUnique(formatMatch[1]);
} else {
this.links.pushUnique(formatMatch[1]);
}
}
else if(formatMatch[2-t] && !config.formatterHelpers.isExternalLink(formatMatch[3-t])) // titledBrackettedLink
this.links.pushUnique(formatMatch[3-t]);
else if(formatMatch[4-t] && formatMatch[4-t] != this.title) // brackettedLink
this.links.pushUnique(formatMatch[4-t]);
tiddlerLinkRegExp.lastIndex = lastIndex;
formatMatch = tiddlerLinkRegExp.exec(text);
}
this.linksUpdated = true;
};
Tiddler.prototype.getSubtitle = function()
{
var modifier = this.modifier;
if(!modifier)
modifier = config.messages.subtitleUnknown;
var modified = this.modified;
if(modified)
modified = modified.toLocaleString();
else
modified = config.messages.subtitleUnknown;
return config.messages.tiddlerLinkTooltip.format([this.title,modifier,modified]);
};
Tiddler.prototype.isReadOnly = function()
{
return readOnly;
};
Tiddler.prototype.autoLinkWikiWords = function()
{
return !(this.isTagged("systemConfig") || this.isTagged("excludeMissing"));
};
Tiddler.prototype.getServerType = function()
{
var serverType = null;
if(this.fields['server.type'])
serverType = this.fields['server.type'];
if(!serverType)
serverType = this.fields['wikiformat'];
if(serverType && !config.adaptors[serverType])
serverType = null;
return serverType;
};
Tiddler.prototype.getAdaptor = function()
{
var serverType = this.getServerType();
return serverType ? new config.adaptors[serverType]() : null;
};
//--
//-- TiddlyWiki() object contains Tiddler()s
//--
function TiddlyWiki()
{
var tiddlers = {}; // Hashmap by name of tiddlers
this.tiddlersUpdated = false;
this.namedNotifications = []; // Array of {name:,notify:} of notification functions
this.notificationLevel = 0;
this.slices = {}; // map tiddlerName->(map sliceName->sliceValue). Lazy.
this.clear = function() {
tiddlers = {};
this.setDirty(false);
};
this.fetchTiddler = function(title) {
var t = tiddlers[title];
return t instanceof Tiddler ? t : null;
};
this.deleteTiddler = function(title) {
delete this.slices[title];
delete tiddlers[title];
};
this.addTiddler = function(tiddler) {
delete this.slices[tiddler.title];
tiddlers[tiddler.title] = tiddler;
};
this.forEachTiddler = function(callback) {
for(var t in tiddlers) {
var tiddler = tiddlers[t];
if(tiddler instanceof Tiddler)
callback.call(this,t,tiddler);
}
};
}
TiddlyWiki.prototype.setDirty = function(dirty)
{
this.dirty = dirty;
};
TiddlyWiki.prototype.isDirty = function()
{
return this.dirty;
};
TiddlyWiki.prototype.tiddlerExists = function(title)
{
var t = this.fetchTiddler(title);
return t != undefined;
};
TiddlyWiki.prototype.isShadowTiddler = function(title)
{
return config.shadowTiddlers[title] === undefined ? false : true;
};
TiddlyWiki.prototype.createTiddler = function(title)
{
var tiddler = this.fetchTiddler(title);
if(!tiddler) {
tiddler = new Tiddler(title);
this.addTiddler(tiddler);
this.setDirty(true);
}
return tiddler;
};
TiddlyWiki.prototype.getTiddler = function(title)
{
var t = this.fetchTiddler(title);
if(t != undefined)
return t;
else
return null;
};
TiddlyWiki.prototype.getShadowTiddlerText = function(title)
{
if(typeof config.shadowTiddlers[title] == "string")
return config.shadowTiddlers[title];
else
return "";
};
// Retrieve tiddler contents
TiddlyWiki.prototype.getTiddlerText = function(title,defaultText)
{
if(!title)
return defaultText;
var pos = title.indexOf(config.textPrimitives.sectionSeparator);
var section = null;
if(pos != -1) {
section = title.substr(pos + config.textPrimitives.sectionSeparator.length);
title = title.substr(0,pos);
}
pos = title.indexOf(config.textPrimitives.sliceSeparator);
if(pos != -1) {
var slice = this.getTiddlerSlice(title.substr(0,pos),title.substr(pos + config.textPrimitives.sliceSeparator.length));
if(slice)
return slice;
}
var tiddler = this.fetchTiddler(title);
if(tiddler) {
if(!section)
return tiddler.text;
var re = new RegExp("(^!{1,6}[ \t]*" + section.escapeRegExp() + "[ \t]*\n)","mg");
re.lastIndex = 0;
var match = re.exec(tiddler.text);
if(match) {
var t = tiddler.text.substr(match.index+match[1].length);
var re2 = /^!/mg;
re2.lastIndex = 0;
match = re2.exec(t); //# search for the next heading
if(match)
t = t.substr(0,match.index-1);//# don't include final \n
return t;
}
return defaultText;
}
if(this.isShadowTiddler(title))
return this.getShadowTiddlerText(title);
if(defaultText != undefined)
return defaultText;
return null;
};
TiddlyWiki.prototype.getRecursiveTiddlerText = function(title,defaultText,depth)
{
var bracketRegExp = new RegExp("(?:\\[\\[([^\\]]+)\\]\\])","mg");
var text = this.getTiddlerText(title,null);
if(text == null)
return defaultText;
var textOut = [];
var lastPos = 0;
do {
var match = bracketRegExp.exec(text);
if(match) {
textOut.push(text.substr(lastPos,match.index-lastPos));
if(match[1]) {
if(depth <= 0)
textOut.push(match[1]);
else
textOut.push(this.getRecursiveTiddlerText(match[1],"",depth-1));
}
lastPos = match.index + match[0].length;
} else {
textOut.push(text.substr(lastPos));
}
} while(match);
return textOut.join("");
};
TiddlyWiki.prototype.slicesRE = /(?:^([\'\/]{0,2})~?([\.\w]+)\:\1[\t\x20]*([^\n]+)[\t\x20]*$)|(?:^\|([\'\/]{0,2})~?([\.\w]+)\:?\4\|[\t\x20]*([^\n]+)[\t\x20]*\|$)/gm;
// @internal
TiddlyWiki.prototype.calcAllSlices = function(title)
{
var slices = {};
var text = this.getTiddlerText(title,"");
this.slicesRE.lastIndex = 0;
var m = this.slicesRE.exec(text);
while(m) {
if(m[2])
slices[m[2]] = m[3];
else
slices[m[5]] = m[6];
m = this.slicesRE.exec(text);
}
return slices;
};
// Returns the slice of text of the given name
TiddlyWiki.prototype.getTiddlerSlice = function(title,sliceName)
{
var slices = this.slices[title];
if(!slices) {
slices = this.calcAllSlices(title);
this.slices[title] = slices;
}
return slices[sliceName];
};
// Build an hashmap of the specified named slices of a tiddler
TiddlyWiki.prototype.getTiddlerSlices = function(title,sliceNames)
{
var r = {};
for(var t=0; t<sliceNames.length; t++) {
var slice = this.getTiddlerSlice(title,sliceNames[t]);
if(slice)
r[sliceNames[t]] = slice;
}
return r;
};
TiddlyWiki.prototype.suspendNotifications = function()
{
this.notificationLevel--;
};
TiddlyWiki.prototype.resumeNotifications = function()
{
this.notificationLevel++;
};
// Invoke the notification handlers for a particular tiddler
TiddlyWiki.prototype.notify = function(title,doBlanket)
{
if(!this.notificationLevel) {
for(var t=0; t<this.namedNotifications.length; t++) {
var n = this.namedNotifications[t];
if((n.name == null && doBlanket) || (n.name == title))
n.notify(title);
}
}
};
// Invoke the notification handlers for all tiddlers
TiddlyWiki.prototype.notifyAll = function()
{
if(!this.notificationLevel) {
for(var t=0; t<this.namedNotifications.length; t++) {
var n = this.namedNotifications[t];
if(n.name)
n.notify(n.name);
}
}
};
// Add a notification handler to a tiddler
TiddlyWiki.prototype.addNotification = function(title,fn)
{
for(var i=0; i<this.namedNotifications.length; i++) {
if((this.namedNotifications[i].name == title) && (this.namedNotifications[i].notify == fn))
return this;
}
this.namedNotifications.push({name: title, notify: fn});
return this;
};
TiddlyWiki.prototype.removeTiddler = function(title)
{
var tiddler = this.fetchTiddler(title);
if(tiddler) {
this.deleteTiddler(title);
this.notify(title,true);
this.setDirty(true);
}
};
// Reset the sync status of a freshly synced tiddler
TiddlyWiki.prototype.resetTiddler = function(title)
{
var tiddler = this.fetchTiddler(title);
if(tiddler) {
tiddler.clearChangeCount();
this.notify(title,true);
this.setDirty(true);
}
};
TiddlyWiki.prototype.setTiddlerTag = function(title,status,tag)
{
var tiddler = this.fetchTiddler(title);
if(tiddler) {
var t = tiddler.tags.indexOf(tag);
if(t != -1)
tiddler.tags.splice(t,1);
if(status)
tiddler.tags.push(tag);
tiddler.changed();
tiddler.incChangeCount();
this.notify(title,true);
this.setDirty(true);
}
};
TiddlyWiki.prototype.addTiddlerFields = function(title,fields)
{
var tiddler = this.fetchTiddler(title);
if(!tiddler)
return;
merge(tiddler.fields,fields);
tiddler.changed();
tiddler.incChangeCount();
this.notify(title,true);
this.setDirty(true);
};
// Store tiddler in TiddlyWiki instance
TiddlyWiki.prototype.saveTiddler = function(title,newTitle,newBody,modifier,modified,tags,fields,clearChangeCount,created,creator)
{
var tiddler = this.fetchTiddler(title);
if(tiddler) {
created = created || tiddler.created; // Preserve created date
creator = creator || tiddler.creator;
this.deleteTiddler(title);
} else {
created = created || modified;
tiddler = new Tiddler();
}
fields = merge({},fields);
tiddler.set(newTitle,newBody,modifier,modified,tags,created,fields,creator);
this.addTiddler(tiddler);
if(clearChangeCount)
tiddler.clearChangeCount();
else
tiddler.incChangeCount();
if(title != newTitle)
this.notify(title,true);
this.notify(newTitle,true);
this.setDirty(true);
return tiddler;
};
TiddlyWiki.prototype.incChangeCount = function(title)
{
var tiddler = this.fetchTiddler(title);
if(tiddler)
tiddler.incChangeCount();
};
TiddlyWiki.prototype.getLoader = function()
{
if(!this.loader)
this.loader = new TW21Loader();
return this.loader;
};
TiddlyWiki.prototype.getSaver = function()
{
if(!this.saver)
this.saver = new TW21Saver();
return this.saver;
};
// Return all tiddlers formatted as an HTML string
TiddlyWiki.prototype.allTiddlersAsHtml = function()
{
return this.getSaver().externalize(store);
};
// Load contents of a TiddlyWiki from an HTML DIV
TiddlyWiki.prototype.loadFromDiv = function(src,idPrefix,noUpdate)
{
this.idPrefix = idPrefix;
var storeElem = (typeof src == "string") ? document.getElementById(src) : src;
if(!storeElem)
return;
var tiddlers = this.getLoader().loadTiddlers(this,storeElem.childNodes);
this.setDirty(false);
if(!noUpdate) {
for(var i = 0;i<tiddlers.length; i++)
tiddlers[i].changed();
}
jQuery(document).trigger("loadTiddlers");
};
// Load contents of a TiddlyWiki from a string
// Returns null if there's an error
TiddlyWiki.prototype.importTiddlyWiki = function(text)
{
var posDiv = locateStoreArea(text);
if(!posDiv)
return null;
var content = "<" + "html><" + "body>" + text.substring(posDiv[0],posDiv[1] + endSaveArea.length) + "<" + "/body><" + "/html>";
// Create the iframe
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);
var doc = iframe.document;
if(iframe.contentDocument)
doc = iframe.contentDocument; // For NS6
else if(iframe.contentWindow)
doc = iframe.contentWindow.document; // For IE5.5 and IE6
// Put the content in the iframe
doc.open();
doc.writeln(content);
doc.close();
// Load the content into a TiddlyWiki() object
var storeArea = doc.getElementById("storeArea");
this.loadFromDiv(storeArea,"store");
// Get rid of the iframe
iframe.parentNode.removeChild(iframe);
return this;
};
TiddlyWiki.prototype.updateTiddlers = function()
{
this.tiddlersUpdated = true;
this.forEachTiddler(function(title,tiddler) {
tiddler.changed();
});
};
// Return an array of tiddlers matching a search regular expression
TiddlyWiki.prototype.search = function(searchRegExp,sortField,excludeTag,match)
{
var candidates = this.reverseLookup("tags",excludeTag,!!match);
var results = [];
for(var t=0; t<candidates.length; t++) {
if((candidates[t].title.search(searchRegExp) != -1) || (candidates[t].text.search(searchRegExp) != -1))
results.push(candidates[t]);
}
if(!sortField)
sortField = "title";
results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
return results;
};
// Returns a list of all tags in use
// excludeTag - if present, excludes tags that are themselves tagged with excludeTag
// Returns an array of arrays where [tag][0] is the name of the tag and [tag][1] is the number of occurances
TiddlyWiki.prototype.getTags = function(excludeTag)
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
for(var g=0; g<tiddler.tags.length; g++) {
var tag = tiddler.tags[g];
var n = true;
for(var c=0; c<results.length; c++) {
if(results[c][0] == tag) {
n = false;
results[c][1]++;
}
}
if(n && excludeTag) {
var t = this.fetchTiddler(tag);
if(t && t.isTagged(excludeTag))
n = false;
}
if(n)
results.push([tag,1]);
}
});
results.sort(function(a,b) {return a[0].toLowerCase() < b[0].toLowerCase() ? -1 : (a[0].toLowerCase() == b[0].toLowerCase() ? 0 : +1);});
return results;
};
// Return an array of the tiddlers that are tagged with a given tag
TiddlyWiki.prototype.getTaggedTiddlers = function(tag,sortField)
{
return this.reverseLookup("tags",tag,true,sortField);
};
// Return an array of the tiddlers that link to a given tiddler
TiddlyWiki.prototype.getReferringTiddlers = function(title,unusedParameter,sortField)
{
if(!this.tiddlersUpdated)
this.updateTiddlers();
return this.reverseLookup("links",title,true,sortField);
};
// Return an array of the tiddlers that do or do not have a specified entry in the specified storage array (ie, "links" or "tags")
// lookupMatch == true to match tiddlers, false to exclude tiddlers
TiddlyWiki.prototype.reverseLookup = function(lookupField,lookupValue,lookupMatch,sortField)
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
var f = !lookupMatch;
for(var lookup=0; lookup<tiddler[lookupField].length; lookup++) {
if(tiddler[lookupField][lookup] == lookupValue)
f = lookupMatch;
}
if(f)
results.push(tiddler);
});
if(!sortField)
sortField = "title";
results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
return results;
};
// Return the tiddlers as a sorted array
TiddlyWiki.prototype.getTiddlers = function(field,excludeTag)
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(excludeTag == undefined || !tiddler.isTagged(excludeTag))
results.push(tiddler);
});
if(field)
results.sort(function(a,b) {return a[field] < b[field] ? -1 : (a[field] == b[field] ? 0 : +1);});
return results;
};
// Return array of names of tiddlers that are referred to but not defined
TiddlyWiki.prototype.getMissingLinks = function(sortField)
{
if(!this.tiddlersUpdated)
this.updateTiddlers();
var results = [];
this.forEachTiddler(function (title,tiddler) {
if(tiddler.isTagged("excludeMissing") || tiddler.isTagged("systemConfig"))
return;
for(var n=0; n<tiddler.links.length;n++) {
var link = tiddler.links[n];
if(this.fetchTiddler(link) == null && !this.isShadowTiddler(link))
results.pushUnique(link);
}
});
results.sort();
return results;
};
// Return an array of names of tiddlers that are defined but not referred to
TiddlyWiki.prototype.getOrphans = function()
{
var results = [];
this.forEachTiddler(function (title,tiddler) {
if(this.getReferringTiddlers(title).length == 0 && !tiddler.isTagged("excludeLists"))
results.push(title);
});
results.sort();
return results;
};
// Return an array of names of all the shadow tiddlers
TiddlyWiki.prototype.getShadowed = function()
{
var results = [];
for(var t in config.shadowTiddlers) {
if(this.isShadowTiddler(t))
results.push(t);
}
results.sort();
return results;
};
// Return an array of tiddlers that have been touched since they were downloaded or created
TiddlyWiki.prototype.getTouched = function()
{
var results = [];
this.forEachTiddler(function(title,tiddler) {
if(tiddler.isTouched())
results.push(tiddler);
});
results.sort();
return results;
};
// Resolves a Tiddler reference or tiddler title into a Tiddler object, or null if it doesn't exist
TiddlyWiki.prototype.resolveTiddler = function(tiddler)
{
var t = (typeof tiddler == "string") ? this.getTiddler(tiddler) : tiddler;
return t instanceof Tiddler ? t : null;
};
// Filter a list of tiddlers
TiddlyWiki.prototype.filterTiddlers = function(filter)
{
var results = [];
if(filter) {
var tiddler;
var re = /([^\s\[\]]+)|(?:\[([ \w]+)\[([^\]]+)\]\])|(?:\[\[([^\]]+)\]\])/mg;
var match = re.exec(filter);
while(match) {
if(match[1] || match[4]) {
var title = match[1] || match[4];
tiddler = this.fetchTiddler(title);
if(tiddler) {
results.pushUnique(tiddler);
} else if(this.isShadowTiddler(title)) {
tiddler = new Tiddler();
tiddler.set(title,this.getTiddlerText(title));
results.pushUnique(tiddler);
} else {
results.pushUnique(new Tiddler(title));
}
} else if(match[2]) {
switch(match[2]) {
case "tag":
var matched = this.getTaggedTiddlers(match[3]);
for(var m = 0; m < matched.length; m++)
results.pushUnique(matched[m]);
break;
case "sort":
results = this.sortTiddlers(results,match[3]);
break;
}
}
match = re.exec(filter);
}
}
return results;
};
// Sort a list of tiddlers
TiddlyWiki.prototype.sortTiddlers = function(tiddlers,field)
{
var asc = +1;
switch(field.substr(0,1)) {
case "-":
asc = -1;
// Note: this fall-through is intentional
/*jsl:fallthru*/
case "+":
field = field.substr(1);
break;
}
if(TiddlyWiki.standardFieldAccess[field])
tiddlers.sort(function(a,b) {return a[field] < b[field] ? -asc : (a[field] == b[field] ? 0 : asc);});
else
tiddlers.sort(function(a,b) {return a.fields[field] < b.fields[field] ? -asc : (a.fields[field] == b.fields[field] ? 0 : +asc);});
return tiddlers;
};
// Returns true if path is a valid field name (path),
// i.e. a sequence of identifiers, separated by "."
TiddlyWiki.isValidFieldName = function(name)
{
var match = /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*/.exec(name);
return match && (match[0] == name);
};
// Throws an exception when name is not a valid field name.
TiddlyWiki.checkFieldName = function(name)
{
if(!TiddlyWiki.isValidFieldName(name))
throw config.messages.invalidFieldName.format([name]);
};
function StringFieldAccess(n,readOnly)
{
this.set = readOnly ?
function(t,v) {if(v != t[n]) throw config.messages.fieldCannotBeChanged.format([n]);} :
function(t,v) {if(v != t[n]) {t[n] = v; return true;}};
this.get = function(t) {return t[n];};
}
function DateFieldAccess(n)
{
this.set = function(t,v) {
var d = v instanceof Date ? v : Date.convertFromYYYYMMDDHHMM(v);
if(d != t[n]) {
t[n] = d; return true;
}
};
this.get = function(t) {return t[n].convertToYYYYMMDDHHMM();};
}
function LinksFieldAccess(n)
{
this.set = function(t,v) {
var s = (typeof v == "string") ? v.readBracketedList() : v;
if(s.toString() != t[n].toString()) {
t[n] = s; return true;
}
};
this.get = function(t) {return String.encodeTiddlyLinkList(t[n]);};
}
TiddlyWiki.standardFieldAccess = {
// The set functions return true when setting the data has changed the value.
"title": new StringFieldAccess("title",true),
// Handle the "tiddler" field name as the title
"tiddler": new StringFieldAccess("title",true),
"text": new StringFieldAccess("text"),
"modifier": new StringFieldAccess("modifier"),
"modified": new DateFieldAccess("modified"),
"creator": new StringFieldAccess("creator"),
"created": new DateFieldAccess("created"),
"tags": new LinksFieldAccess("tags")
};
TiddlyWiki.isStandardField = function(name)
{
return TiddlyWiki.standardFieldAccess[name] != undefined;
};
// Sets the value of the given field of the tiddler to the value.
// Setting an ExtendedField's value to null or undefined removes the field.
// Setting a namespace to undefined removes all fields of that namespace.
// The fieldName is case-insensitive.
// All values will be converted to a string value.
TiddlyWiki.prototype.setValue = function(tiddler,fieldName,value)
{
TiddlyWiki.checkFieldName(fieldName);
var t = this.resolveTiddler(tiddler);
if(!t)
return;
fieldName = fieldName.toLowerCase();
var isRemove = (value === undefined) || (value === null);
var accessor = TiddlyWiki.standardFieldAccess[fieldName];
if(accessor) {
if(isRemove)
// don't remove StandardFields
return;
var h = TiddlyWiki.standardFieldAccess[fieldName];
if(!h.set(t,value))
return;
} else {
var oldValue = t.fields[fieldName];
if(isRemove) {
if(oldValue !== undefined) {
// deletes a single field
delete t.fields[fieldName];
} else {
// no concrete value is defined for the fieldName
// so we guess this is a namespace path.
// delete all fields in a namespace
var re = new RegExp("^"+fieldName+"\\.");
var dirty = false;
for(var n in t.fields) {
if(n.match(re)) {
delete t.fields[n];
dirty = true;
}
}
if(!dirty)
return;
}
} else {
// the "normal" set case. value is defined (not null/undefined)
// For convenience provide a nicer conversion Date->String
value = value instanceof Date ? value.convertToYYYYMMDDHHMMSSMMM() : String(value);
if(oldValue == value)
return;
t.fields[fieldName] = value;
}
}
// When we are here the tiddler/store really was changed.
this.notify(t.title,true);
if(!fieldName.match(/^temp\./))
this.setDirty(true);
};
// Returns the value of the given field of the tiddler.
// The fieldName is case-insensitive.
// Will only return String values (or undefined).
TiddlyWiki.prototype.getValue = function(tiddler,fieldName)
{
var t = this.resolveTiddler(tiddler);
if(!t)
return undefined;
fieldName = fieldName.toLowerCase();
var accessor = TiddlyWiki.standardFieldAccess[fieldName];
if(accessor) {
return accessor.get(t);
}
return t.fields[fieldName];
};
// Calls the callback function for every field in the tiddler.
// When callback function returns a non-false value the iteration stops
// and that value is returned.
// The order of the fields is not defined.
// @param callback a function(tiddler,fieldName,value).
TiddlyWiki.prototype.forEachField = function(tiddler,callback,onlyExtendedFields)
{
var t = this.resolveTiddler(tiddler);
if(!t)
return undefined;
var n,result;
for(n in t.fields) {
result = callback(t,n,t.fields[n]);
if(result)
return result;
}
if(onlyExtendedFields)
return undefined;
for(n in TiddlyWiki.standardFieldAccess) {
if(n == "tiddler")
// even though the "title" field can also be referenced through the name "tiddler"
// we only visit this field once.
continue;
result = callback(t,n,TiddlyWiki.standardFieldAccess[n].get(t));
if(result)
return result;
}
return undefined;
};
//--
//-- Story functions
//--
function Story(containerId,idPrefix)
{
this.container = containerId;
this.idPrefix = idPrefix;
this.highlightRegExp = null;
this.tiddlerId = function(title) {
var id = this.idPrefix + title;
return id==this.container ? this.idPrefix + "_" + title : id;
};
this.containerId = function() {
return this.container;
};
}
Story.prototype.getTiddler = function(title)
{
return document.getElementById(this.tiddlerId(title));
};
Story.prototype.getContainer = function()
{
return document.getElementById(this.containerId());
};
Story.prototype.forEachTiddler = function(fn)
{
var place = this.getContainer();
if(!place)
return;
var e = place.firstChild;
while(e) {
var n = e.nextSibling;
var title = e.getAttribute("tiddler");
fn.call(this,title,e);
e = n;
}
};
Story.prototype.displayDefaultTiddlers = function()
{
this.displayTiddlers(null,store.filterTiddlers(store.getTiddlerText("DefaultTiddlers")));
};
Story.prototype.displayTiddlers = function(srcElement,titles,template,animate,unused,customFields,toggle)
{
for(var t = titles.length-1;t>=0;t--)
this.displayTiddler(srcElement,titles[t],template,animate,unused,customFields);
};
Story.prototype.displayTiddler = function(srcElement,tiddler,template,animate,unused,customFields,toggle,animationSrc)
{
var title = (tiddler instanceof Tiddler) ? tiddler.title : tiddler;
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem) {
if(toggle) {
if(tiddlerElem.getAttribute("dirty") != "true")
this.closeTiddler(title,true);
} else {
this.refreshTiddler(title,template,false,customFields);
}
} else {
var place = this.getContainer();
var before = this.positionTiddler(srcElement);
tiddlerElem = this.createTiddler(place,before,title,template,customFields);
}
if(animationSrc && typeof animationSrc !== "string") {
srcElement = animationSrc;
}
if(srcElement && typeof srcElement !== "string") {
if(config.options.chkAnimate && (animate == undefined || animate == true) && anim && typeof Zoomer == "function" && typeof Scroller == "function")
anim.startAnimating(new Zoomer(title,srcElement,tiddlerElem),new Scroller(tiddlerElem));
else
window.scrollTo(0,ensureVisible(tiddlerElem));
}
return tiddlerElem;
};
Story.prototype.positionTiddler = function(srcElement)
{
var place = this.getContainer();
var before = null;
if(typeof srcElement == "string") {
switch(srcElement) {
case "top":
before = place.firstChild;
break;
case "bottom":
before = null;
break;
}
} else {
var after = this.findContainingTiddler(srcElement);
if(after == null) {
before = place.firstChild;
} else if(after.nextSibling) {
before = after.nextSibling;
if(before.nodeType != 1)
before = null;
}
}
return before;
};
Story.prototype.createTiddler = function(place,before,title,template,customFields)
{
var tiddlerElem = createTiddlyElement(null,"div",this.tiddlerId(title),"tiddler");
tiddlerElem.setAttribute("refresh","tiddler");
if(customFields)
tiddlerElem.setAttribute("tiddlyFields",customFields);
place.insertBefore(tiddlerElem,before);
var defaultText = null;
if(!store.tiddlerExists(title) && !store.isShadowTiddler(title))
defaultText = this.loadMissingTiddler(title,customFields,tiddlerElem);
this.refreshTiddler(title,template,false,customFields,defaultText);
return tiddlerElem;
};
Story.prototype.loadMissingTiddler = function(title,fields,tiddlerElem)
{
var getTiddlerCallback = function(context)
{
if(context.status) {
var t = context.tiddler;
if(!t.created)
t.created = new Date();
if(!t.modified)
t.modified = t.created;
store.saveTiddler(t.title,t.title,t.text,t.modifier,t.modified,t.tags,t.fields,true,t.created,t.creator);
autoSaveChanges();
} else {
story.refreshTiddler(context.title,null,true);
}
context.adaptor.close();
delete context.adaptor;
};
var tiddler = new Tiddler(title);
tiddler.fields = typeof fields == "string" ? fields.decodeHashMap() : fields||{};
var context = {serverType:tiddler.getServerType()};
if(!context.serverType)
return;
context.host = tiddler.fields['server.host'];
context.workspace = tiddler.fields['server.workspace'];
var adaptor = new config.adaptors[context.serverType];
adaptor.getTiddler(title,context,null,getTiddlerCallback);
return config.messages.loadingMissingTiddler.format([title,context.serverType,context.host,context.workspace]);
};
Story.prototype.chooseTemplateForTiddler = function(title,template)
{
if(!template)
template = DEFAULT_VIEW_TEMPLATE;
if(template == DEFAULT_VIEW_TEMPLATE || template == DEFAULT_EDIT_TEMPLATE)
template = config.tiddlerTemplates[template];
return template;
};
Story.prototype.getTemplateForTiddler = function(title,template,tiddler)
{
return store.getRecursiveTiddlerText(template,null,10);
};
Story.prototype.refreshTiddler = function(title,template,force,customFields,defaultText)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem) {
if(tiddlerElem.getAttribute("dirty") == "true" && !force)
return tiddlerElem;
template = this.chooseTemplateForTiddler(title,template);
var currTemplate = tiddlerElem.getAttribute("template");
if((template != currTemplate) || force) {
var tiddler = store.getTiddler(title);
if(!tiddler) {
tiddler = new Tiddler();
if(store.isShadowTiddler(title)) {
var tags = [];
tiddler.set(title,store.getTiddlerText(title),config.views.wikified.shadowModifier,version.date,tags,version.date);
} else {
var text = template=="EditTemplate" ?
config.views.editor.defaultText.format([title]) :
config.views.wikified.defaultText.format([title]);
text = defaultText || text;
var fields = customFields ? customFields.decodeHashMap() : null;
tiddler.set(title,text,config.views.wikified.defaultModifier,version.date,[],version.date,fields);
}
}
tiddlerElem.setAttribute("tags",tiddler.tags.join(" "));
tiddlerElem.setAttribute("tiddler",title);
tiddlerElem.setAttribute("template",template);
tiddlerElem.onmouseover = this.onTiddlerMouseOver;
tiddlerElem.onmouseout = this.onTiddlerMouseOut;
tiddlerElem.ondblclick = this.onTiddlerDblClick;
tiddlerElem[window.event?"onkeydown":"onkeypress"] = this.onTiddlerKeyPress;
tiddlerElem.innerHTML = this.getTemplateForTiddler(title,template,tiddler);
applyHtmlMacros(tiddlerElem,tiddler);
if(store.getTaggedTiddlers(title).length > 0)
addClass(tiddlerElem,"isTag");
else
removeClass(tiddlerElem,"isTag");
if(store.tiddlerExists(title)) {
removeClass(tiddlerElem,"shadow");
removeClass(tiddlerElem,"missing");
} else {
addClass(tiddlerElem, store.isShadowTiddler(title) ? "shadow" : "missing");
}
if(customFields)
this.addCustomFields(tiddlerElem,customFields);
forceReflow();
}
}
return tiddlerElem;
};
Story.prototype.addCustomFields = function(place,customFields)
{
var fields = customFields.decodeHashMap();
var w = createTiddlyElement(place,"div",null,"customFields");
w.style.display = "none";
for(var t in fields) {
var e = document.createElement("input");
e.setAttribute("type","text");
e.setAttribute("value",fields[t]);
w.appendChild(e);
e.setAttribute("edit",t);
}
};
Story.prototype.refreshAllTiddlers = function(force)
{
var e = this.getContainer().firstChild;
while(e) {
var template = e.getAttribute("template");
if(template && e.getAttribute("dirty") != "true") {
this.refreshTiddler(e.getAttribute("tiddler"),force ? null : template,true);
}
e = e.nextSibling;
}
};
Story.prototype.onTiddlerMouseOver = function(e)
{
addClass(this, "selected");
};
Story.prototype.onTiddlerMouseOut = function(e)
{
removeClass(this,"selected");
};
Story.prototype.onTiddlerDblClick = function(ev)
{
var e = ev || window.event;
var target = resolveTarget(e);
if(target && target.nodeName.toLowerCase() != "input" && target.nodeName.toLowerCase() != "textarea") {
if(document.selection && document.selection.empty)
document.selection.empty();
config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
return true;
}
return false;
};
Story.prototype.onTiddlerKeyPress = function(ev)
{
var e = ev || window.event;
clearMessage();
var consume = false;
var title = this.getAttribute("tiddler");
var target = resolveTarget(e);
switch(e.keyCode) {
case 9: // Tab
if(config.options.chkInsertTabs && target.tagName.toLowerCase() == "textarea") {
replaceSelection(target,String.fromCharCode(9));
consume = true;
}
if(config.isOpera) {
target.onblur = function() {
this.focus();
this.onblur = null;
};
}
break;
case 13: // Ctrl-Enter
case 10: // Ctrl-Enter on IE PC
case 77: // Ctrl-Enter is "M" on some platforms
if(e.ctrlKey) {
blurElement(this);
config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
consume = true;
}
break;
case 27: // Escape
blurElement(this);
config.macros.toolbar.invokeCommand(this,"cancelCommand",e);
consume = true;
break;
}
e.cancelBubble = consume;
if(consume) {
if(e.stopPropagation) e.stopPropagation(); // Stop Propagation
e.returnValue = true; // Cancel The Event in IE
if(e.preventDefault ) e.preventDefault(); // Cancel The Event in Moz
}
return !consume;
};
Story.prototype.getTiddlerField = function(title,field)
{
var tiddlerElem = this.getTiddler(title);
var e = null;
if(tiddlerElem ) {
var children = tiddlerElem.getElementsByTagName("*");
for(var t=0; t<children.length; t++) {
var c = children[t];
if(c.tagName.toLowerCase() == "input" || c.tagName.toLowerCase() == "textarea") {
if(!e)
e = c;
if(c.getAttribute("edit") == field)
e = c;
}
}
}
return e;
};
Story.prototype.focusTiddler = function(title,field)
{
var e = this.getTiddlerField(title,field);
if(e) {
e.focus();
e.select();
}
};
Story.prototype.blurTiddler = function(title)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem && tiddlerElem.focus && tiddlerElem.blur) {
tiddlerElem.focus();
tiddlerElem.blur();
}
};
Story.prototype.setTiddlerField = function(title,tag,mode,field)
{
var c = this.getTiddlerField(title,field);
var tags = c.value.readBracketedList();
tags.setItem(tag,mode);
c.value = String.encodeTiddlyLinkList(tags);
};
Story.prototype.setTiddlerTag = function(title,tag,mode)
{
this.setTiddlerField(title,tag,mode,"tags");
};
Story.prototype.closeTiddler = function(title,animate,unused)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem) {
clearMessage();
this.scrubTiddler(tiddlerElem);
if(config.options.chkAnimate && animate && anim && typeof Slider == "function")
anim.startAnimating(new Slider(tiddlerElem,false,null,"all"));
else {
removeNode(tiddlerElem);
forceReflow();
}
}
};
Story.prototype.scrubTiddler = function(tiddlerElem)
{
tiddlerElem.id = null;
};
Story.prototype.setDirty = function(title,dirty)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem)
tiddlerElem.setAttribute("dirty",dirty ? "true" : "false");
};
Story.prototype.isDirty = function(title)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem)
return tiddlerElem.getAttribute("dirty") == "true";
return null;
};
Story.prototype.areAnyDirty = function()
{
var r = false;
this.forEachTiddler(function(title,element) {
if(this.isDirty(title))
r = true;
});
return r;
};
Story.prototype.closeAllTiddlers = function(exclude)
{
clearMessage();
this.forEachTiddler(function(title,element) {
if((title != exclude) && element.getAttribute("dirty") != "true")
this.closeTiddler(title);
});
window.scrollTo(0,ensureVisible(this.container));
};
Story.prototype.isEmpty = function()
{
var place = this.getContainer();
return place && place.firstChild == null;
};
Story.prototype.search = function(text,useCaseSensitive,useRegExp)
{
this.closeAllTiddlers();
highlightHack = new RegExp(useRegExp ? text : text.escapeRegExp(),useCaseSensitive ? "mg" : "img");
var matches = store.search(highlightHack,"title","excludeSearch");
this.displayTiddlers(null,matches);
highlightHack = null;
var q = useRegExp ? "/" : "'";
if(matches.length > 0)
displayMessage(config.macros.search.successMsg.format([matches.length.toString(),q + text + q]));
else
displayMessage(config.macros.search.failureMsg.format([q + text + q]));
};
Story.prototype.findContainingTiddler = function(e)
{
while(e && !hasClass(e,"tiddler")) {
e = hasClass(e,"popup") && Popup.stack[0] ? Popup.stack[0].root : e.parentNode;
}
return e;
};
Story.prototype.gatherSaveFields = function(e,fields)
{
if(e && e.getAttribute) {
var f = e.getAttribute("edit");
if(f)
fields[f] = e.value.replace(/\r/mg,"");
if(e.hasChildNodes()) {
var c = e.childNodes;
for(var t=0; t<c.length; t++)
this.gatherSaveFields(c[t],fields);
}
}
};
Story.prototype.hasChanges = function(title)
{
var e = this.getTiddler(title);
if(e) {
var fields = {};
this.gatherSaveFields(e,fields);
if(store.fetchTiddler(title)) {
for(var n in fields) {
if(store.getValue(title,n) != fields[n]) //# tiddler changed
return true;
}
} else {
if(store.isShadowTiddler(title) && store.getShadowTiddlerText(title) == fields.text) { //# not checking for title or tags
return false;
} else { //# changed shadow or new tiddler
return true;
}
}
}
return false;
};
Story.prototype.saveTiddler = function(title,minorUpdate)
{
var tiddlerElem = this.getTiddler(title);
if(tiddlerElem) {
var fields = {};
this.gatherSaveFields(tiddlerElem,fields);
var newTitle = fields.title || title;
if(!store.tiddlerExists(newTitle)) {
newTitle = newTitle.trim();
var creator = config.options.txtUserName;
}
if(store.tiddlerExists(newTitle) && newTitle != title) {
if(!confirm(config.messages.overwriteWarning.format([newTitle.toString()])))
return null;
}
if(newTitle != title)
this.closeTiddler(newTitle,false);
tiddlerElem.id = this.tiddlerId(newTitle);
tiddlerElem.setAttribute("tiddler",newTitle);
tiddlerElem.setAttribute("template",DEFAULT_VIEW_TEMPLATE);
tiddlerElem.setAttribute("dirty","false");
if(config.options.chkForceMinorUpdate)
minorUpdate = !minorUpdate;
if(!store.tiddlerExists(newTitle))
minorUpdate = false;
var newDate = new Date();
if(store.tiddlerExists(title)) {
var t = store.fetchTiddler(title);
var extendedFields = t.fields;
creator = t.creator;
} else {
extendedFields = merge({},config.defaultCustomFields);
}
for(var n in fields) {
if(!TiddlyWiki.isStandardField(n))
extendedFields[n] = fields[n];
}
var tiddler = store.saveTiddler(title,newTitle,fields.text,minorUpdate ? undefined : config.options.txtUserName,minorUpdate ? undefined : newDate,fields.tags,extendedFields,null,null,creator);
autoSaveChanges(null,[tiddler]);
return newTitle;
}
return null;
};
Story.prototype.permaView = function()
{
var links = [];
this.forEachTiddler(function(title,element) {
links.push(String.encodeTiddlyLink(title));
});
var t = encodeURIComponent(links.join(" "));
if(t == "")
t = "#";
if(window.location.hash != t)
window.location.hash = t;
};
Story.prototype.switchTheme = function(theme)
{
if(safeMode)
return;
var isAvailable = function(title) {
var s = title ? title.indexOf(config.textPrimitives.sectionSeparator) : -1;
if(s!=-1)
title = title.substr(0,s);
return store.tiddlerExists(title) || store.isShadowTiddler(title);
};
var getSlice = function(theme,slice) {
var r;
if(readOnly)
r = store.getTiddlerSlice(theme,slice+"ReadOnly") || store.getTiddlerSlice(theme,"Web"+slice);
r = r || store.getTiddlerSlice(theme,slice);
if(r && r.indexOf(config.textPrimitives.sectionSeparator)==0)
r = theme + r;
return isAvailable(r) ? r : slice;
};
var replaceNotification = function(i,name,theme,slice) {
var newName = getSlice(theme,slice);
if(name!=newName && store.namedNotifications[i].name==name) {
store.namedNotifications[i].name = newName;
return newName;
}
return name;
};
var pt = config.refresherData.pageTemplate;
var vi = DEFAULT_VIEW_TEMPLATE;
var vt = config.tiddlerTemplates[vi];
var ei = DEFAULT_EDIT_TEMPLATE;
var et = config.tiddlerTemplates[ei];
for(var i=0; i<config.notifyTiddlers.length; i++) {
var name = config.notifyTiddlers[i].name;
switch(name) {
case "PageTemplate":
config.refresherData.pageTemplate = replaceNotification(i,config.refresherData.pageTemplate,theme,name);
break;
case "StyleSheet":
removeStyleSheet(config.refresherData.styleSheet);
config.refresherData.styleSheet = replaceNotification(i,config.refresherData.styleSheet,theme,name);
break;
case "ColorPalette":
config.refresherData.colorPalette = replaceNotification(i,config.refresherData.colorPalette,theme,name);
break;
default:
break;
}
}
config.tiddlerTemplates[vi] = getSlice(theme,"ViewTemplate");
config.tiddlerTemplates[ei] = getSlice(theme,"EditTemplate");
if(!startingUp) {
if(config.refresherData.pageTemplate!=pt || config.tiddlerTemplates[vi]!=vt || config.tiddlerTemplates[ei]!=et) {
refreshAll();
this.refreshAllTiddlers(true);
} else {
setStylesheet(store.getRecursiveTiddlerText(config.refresherData.styleSheet,"",10),config.refreshers.styleSheet);
}
config.options.txtTheme = theme;
saveOptionCookie("txtTheme");
}
};
//--
//-- Backstage
//--
var backstage = {
area: null,
toolbar: null,
button: null,
showButton: null,
hideButton: null,
cloak: null,
panel: null,
panelBody: null,
panelFooter: null,
currTabName: null,
currTabElem: null,
content: null,
init: function() {
var cmb = config.messages.backstage;
this.area = document.getElementById("backstageArea");
this.toolbar = jQuery("#backstageToolbar").empty()[0];
this.button = jQuery("#backstageButton").empty()[0];
this.button.style.display = "block";
var t = cmb.open.text + " " + glyph("bentArrowLeft");
this.showButton = createTiddlyButton(this.button,t,cmb.open.tooltip,
function(e) {backstage.show(); return false;},null,"backstageShow");
t = glyph("bentArrowRight") + " " + cmb.close.text;
this.hideButton = createTiddlyButton(this.button,t,cmb.close.tooltip,
function(e) {backstage.hide(); return false;},null,"backstageHide");
this.cloak = document.getElementById("backstageCloak");
this.panel = document.getElementById("backstagePanel");
this.panelFooter = createTiddlyElement(this.panel,"div",null,"backstagePanelFooter");
this.panelBody = createTiddlyElement(this.panel,"div",null,"backstagePanelBody");
this.cloak.onmousedown = function(e) {backstage.switchTab(null);};
createTiddlyText(this.toolbar,cmb.prompt);
for(t=0; t<config.backstageTasks.length; t++) {
var taskName = config.backstageTasks[t];
var task = config.tasks[taskName];
var handler = task.action ? this.onClickCommand : this.onClickTab;
var text = task.text + (task.action ? "" : glyph("downTriangle"));
var btn = createTiddlyButton(this.toolbar,text,task.tooltip,handler,"backstageTab");
addClass(btn,task.action ? "backstageAction" : "backstageTask");
btn.setAttribute("task", taskName);
}
this.content = document.getElementById("contentWrapper");
if(config.options.chkBackstage)
this.show();
else
this.hide();
},
isVisible: function() {
return this.area ? this.area.style.display == "block" : false;
},
show: function() {
this.area.style.display = "block";
if(anim && config.options.chkAnimate) {
backstage.toolbar.style.left = findWindowWidth() + "px";
var p = [{style: "left", start: findWindowWidth(), end: 0, template: "%0px"}];
anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p));
} else {
backstage.area.style.left = "0px";
}
jQuery(this.showButton).hide();
jQuery(this.hideButton).show();
config.options.chkBackstage = true;
saveOptionCookie("chkBackstage");
addClass(this.content,"backstageVisible");
},
hide: function() {
if(this.currTabElem) {
this.switchTab(null);
} else {
backstage.toolbar.style.left = "0px";
if(anim && config.options.chkAnimate) {
var p = [{style: "left", start: 0, end: findWindowWidth(), template: "%0px"}];
var c = function(element,properties) {backstage.area.style.display = "none";};
anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p,c));
} else {
this.area.style.display = "none";
}
this.showButton.style.display = "block";
this.hideButton.style.display = "none";
config.options.chkBackstage = false;
saveOptionCookie("chkBackstage");
removeClass(this.content, "backstageVisible");
}
},
onClickCommand: function(e) {
var task = config.tasks[this.getAttribute("task")];
if(task.action) {
backstage.switchTab(null);
task.action();
}
return false;
},
onClickTab: function(e) {
backstage.switchTab(this.getAttribute("task"));
return false;
},
// Switch to a given tab, or none if null is passed
switchTab: function(tabName) {
var tabElem = null;
var e = this.toolbar.firstChild;
while(e)
{
if(e.getAttribute && e.getAttribute("task") == tabName)
tabElem = e;
e = e.nextSibling;
}
if(tabName == backstage.currTabName) {
backstage.hidePanel();
return;
}
if(backstage.currTabElem) {
removeClass(this.currTabElem, "backstageSelTab");
}
if(tabElem && tabName) {
backstage.preparePanel();
addClass(tabElem,"backstageSelTab");
var task = config.tasks[tabName];
wikify(task.content,backstage.panelBody,null,null);
backstage.showPanel();
} else if(backstage.currTabElem) {
backstage.hidePanel();
}
backstage.currTabName = tabName;
backstage.currTabElem = tabElem;
},
isPanelVisible: function() {
return backstage.panel ? backstage.panel.style.display == "block" : false;
},
preparePanel: function() {
backstage.cloak.style.height = findWindowHeight() + "px";
backstage.cloak.style.display = "block";
removeChildren(backstage.panelBody);
return backstage.panelBody;
},
showPanel: function() {
backstage.panel.style.display = "block";
if(anim && config.options.chkAnimate) {
backstage.panel.style.top = (-backstage.panel.offsetHeight) + "px";
var p = [{style: "top", start: -backstage.panel.offsetHeight, end: 0, template: "%0px"}];
anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p),new Scroller(backstage.panel,false));
} else {
backstage.panel.style.top = "0px";
}
return backstage.panelBody;
},
hidePanel: function() {
if(backstage.currTabElem)
removeClass(backstage.currTabElem, "backstageSelTab");
backstage.currTabElem = null;
backstage.currTabName = null;
if(anim && config.options.chkAnimate) {
var p = [
{style: "top", start: 0, end: -(backstage.panel.offsetHeight), template: "%0px"},
{style: "display", atEnd: "none"}
];
var c = function(element,properties) {backstage.cloak.style.display = "none";};
anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p,c));
} else {
jQuery([backstage.panel,backstage.cloak]).hide();
}
}
};
config.macros.backstage = {};
config.macros.backstage.handler = function(place,macroName,params)
{
var backstageTask = config.tasks[params[0]];
if(backstageTask)
createTiddlyButton(place,backstageTask.text,backstageTask.tooltip,function(e) {backstage.switchTab(params[0]); return false;});
};
//--
//-- ImportTiddlers macro
//--
config.macros.importTiddlers.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if(readOnly) {
createTiddlyElement(place,"div",null,"marked",this.readOnlyWarning);
return;
}
var w = new Wizard();
w.createWizard(place,this.wizardTitle);
this.restart(w);
};
config.macros.importTiddlers.onCancel = function(e)
{
var wizard = new Wizard(this);
var place = wizard.clear();
config.macros.importTiddlers.restart(wizard);
return false;
};
config.macros.importTiddlers.onClose = function(e)
{
backstage.hidePanel();
return false;
};
config.macros.importTiddlers.restart = function(wizard)
{
var me = config.macros.importTiddlers;
wizard.addStep(this.step1Title,this.step1Html);
var s = wizard.getElement("selTypes");
for(var t in config.adaptors) {
var e = createTiddlyElement(s,"option",null,null,config.adaptors[t].serverLabel ? config.adaptors[t].serverLabel : t);
e.value = t;
}
if(config.defaultAdaptor)
s.value = config.defaultAdaptor;
s = wizard.getElement("selFeeds");
var feeds = this.getFeeds();
for(t in feeds) {
e = createTiddlyElement(s,"option",null,null,t);
e.value = t;
}
wizard.setValue("feeds",feeds);
s.onchange = me.onFeedChange;
var fileInput = wizard.getElement("txtBrowse");
fileInput.onchange = me.onBrowseChange;
fileInput.onkeyup = me.onBrowseChange;
wizard.setButtons([{caption: this.openLabel, tooltip: this.openPrompt, onClick: me.onOpen}]);
wizard.formElem.action = "javascript:;";
wizard.formElem.onsubmit = function() {
if(!this.txtPath || this.txtPath.value.length) //# check for manually entered path in first step
this.lastChild.firstChild.onclick();
};
};
config.macros.importTiddlers.getFeeds = function()
{
var feeds = {};
var tagged = store.getTaggedTiddlers("systemServer","title");
for(var t=0; t<tagged.length; t++) {
var title = tagged[t].title;
var serverType = store.getTiddlerSlice(title,"Type");
if(!serverType)
serverType = "file";
feeds[title] = {title: title,
url: store.getTiddlerSlice(title,"URL"),
workspace: store.getTiddlerSlice(title,"Workspace"),
workspaceList: store.getTiddlerSlice(title,"WorkspaceList"),
tiddlerFilter: store.getTiddlerSlice(title,"TiddlerFilter"),
serverType: serverType,
description: store.getTiddlerSlice(title,"Description")};
}
return feeds;
};
config.macros.importTiddlers.onFeedChange = function(e)
{
var wizard = new Wizard(this);
var selTypes = wizard.getElement("selTypes");
var fileInput = wizard.getElement("txtPath");
var feeds = wizard.getValue("feeds");
var f = feeds[this.value];
if(f) {
selTypes.value = f.serverType;
fileInput.value = f.url;
wizard.setValue("feedName",f.serverType);
wizard.setValue("feedHost",f.url);
wizard.setValue("feedWorkspace",f.workspace);
wizard.setValue("feedWorkspaceList",f.workspaceList);
wizard.setValue("feedTiddlerFilter",f.tiddlerFilter);
}
return false;
};
config.macros.importTiddlers.onBrowseChange = function(e)
{
var wizard = new Wizard(this);
if(this.files && this.files[0]) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
} catch (ex) {
showException(ex);
}
}
var fileInput = wizard.getElement("txtPath");
fileInput.value = config.macros.importTiddlers.getURLFromLocalPath(this.value);
var serverType = wizard.getElement("selTypes");
serverType.value = "file";
return true;
};
config.macros.importTiddlers.getURLFromLocalPath = function(v)
{
if(!v || !v.length)
return v;
v = v.replace(/\\/g,"/"); // use "/" for cross-platform consistency
var u;
var t = v.split(":");
var p = t[1] || t[0]; // remove drive letter (if any)
if(t[1] && (t[0] == "http" || t[0] == "https" || t[0] == "file")) {
u = v;
} else if(p.substr(0,1)=="/") {
u = document.location.protocol + "//" + document.location.hostname + (t[1] ? "/" : "") + v;
} else {
var c = document.location.href.replace(/\\/g,"/");
var pos = c.lastIndexOf("/");
if(pos!=-1)
c = c.substr(0,pos); // remove filename
u = c + "/" + p;
}
return u;
};
config.macros.importTiddlers.onOpen = function(e)
{
var me = config.macros.importTiddlers;
var wizard = new Wizard(this);
var fileInput = wizard.getElement("txtPath");
var url = fileInput.value;
var serverType = wizard.getElement("selTypes").value || config.defaultAdaptor;
var adaptor = new config.adaptors[serverType]();
wizard.setValue("adaptor",adaptor);
wizard.setValue("serverType",serverType);
wizard.setValue("host",url);
var ret = adaptor.openHost(url,null,wizard,me.onOpenHost);
if(ret !== true)
displayMessage(ret);
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.statusOpenHost);
return false;
};
config.macros.importTiddlers.onOpenHost = function(context,wizard)
{
var me = config.macros.importTiddlers;
var adaptor = wizard.getValue("adaptor");
if(context.status !== true)
displayMessage("Error in importTiddlers.onOpenHost: " + context.statusText);
var ret = adaptor.getWorkspaceList(context,wizard,me.onGetWorkspaceList);
if(ret !== true)
displayMessage(ret);
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.statusGetWorkspaceList);
};
config.macros.importTiddlers.onGetWorkspaceList = function(context,wizard)
{
var me = config.macros.importTiddlers;
if(context.status !== true)
displayMessage("Error in importTiddlers.onGetWorkspaceList: " + context.statusText);
wizard.setValue("context",context);
var workspace = wizard.getValue("feedWorkspace");
if(!workspace && context.workspaces.length==1)
workspace = context.workspaces[0].title;
if(workspace) {
var ret = context.adaptor.openWorkspace(workspace,context,wizard,me.onOpenWorkspace);
if(ret !== true)
displayMessage(ret);
wizard.setValue("workspace",workspace);
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.statusOpenWorkspace);
return;
}
wizard.addStep(me.step2Title,me.step2Html);
var s = wizard.getElement("selWorkspace");
s.onchange = me.onWorkspaceChange;
for(var t=0; t<context.workspaces.length; t++) {
var e = createTiddlyElement(s,"option",null,null,context.workspaces[t].title);
e.value = context.workspaces[t].title;
}
var workspaceList = wizard.getValue("feedWorkspaceList");
if(workspaceList) {
var list = workspaceList.parseParams("workspace",null,false,true);
for(var n=1; n<list.length; n++) {
if(context.workspaces.findByField("title",list[n].value) == null) {
e = createTiddlyElement(s,"option",null,null,list[n].value);
e.value = list[n].value;
}
}
}
if(workspace) {
t = wizard.getElement("txtWorkspace");
t.value = workspace;
}
wizard.setButtons([{caption: me.openLabel, tooltip: me.openPrompt, onClick: me.onChooseWorkspace}]);
};
config.macros.importTiddlers.onWorkspaceChange = function(e)
{
var wizard = new Wizard(this);
var t = wizard.getElement("txtWorkspace");
t.value = this.value;
this.selectedIndex = 0;
return false;
};
config.macros.importTiddlers.onChooseWorkspace = function(e)
{
var me = config.macros.importTiddlers;
var wizard = new Wizard(this);
var adaptor = wizard.getValue("adaptor");
var workspace = wizard.getElement("txtWorkspace").value;
wizard.setValue("workspace",workspace);
var context = wizard.getValue("context");
var ret = adaptor.openWorkspace(workspace,context,wizard,me.onOpenWorkspace);
if(ret !== true)
displayMessage(ret);
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.statusOpenWorkspace);
return false;
};
config.macros.importTiddlers.onOpenWorkspace = function(context,wizard)
{
var me = config.macros.importTiddlers;
if(context.status !== true)
displayMessage("Error in importTiddlers.onOpenWorkspace: " + context.statusText);
var adaptor = wizard.getValue("adaptor");
var ret = adaptor.getTiddlerList(context,wizard,me.onGetTiddlerList,wizard.getValue("feedTiddlerFilter"));
if(ret !== true)
displayMessage(ret);
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.statusGetTiddlerList);
};
config.macros.importTiddlers.onGetTiddlerList = function(context,wizard)
{
var me = config.macros.importTiddlers;
if(context.status !== true) {
wizard.setButtons([{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}],me.errorGettingTiddlerList);
return;
}
// Extract data for the listview
var listedTiddlers = [];
if(context.tiddlers) {
for(var n=0; n<context.tiddlers.length; n++) {
var tiddler = context.tiddlers[n];
listedTiddlers.push({
title: tiddler.title,
modified: tiddler.modified,
modifier: tiddler.modifier,
text: tiddler.text ? wikifyPlainText(tiddler.text,100) : "",
tags: tiddler.tags,
size: tiddler.text ? tiddler.text.length : 0,
tiddler: tiddler
});
}
}
listedTiddlers.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
// Display the listview
wizard.addStep(me.step3Title,me.step3Html);
var markList = wizard.getElement("markList");
var listWrapper = document.createElement("div");
markList.parentNode.insertBefore(listWrapper,markList);
var listView = ListView.create(listWrapper,listedTiddlers,me.listViewTemplate);
wizard.setValue("listView",listView);
wizard.setValue("context",context);
var txtSaveTiddler = wizard.getElement("txtSaveTiddler");
txtSaveTiddler.value = me.generateSystemServerName(wizard);
wizard.setButtons([
{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel},
{caption: me.importLabel, tooltip: me.importPrompt, onClick: me.doImport}
]);
};
config.macros.importTiddlers.generateSystemServerName = function(wizard)
{
var serverType = wizard.getValue("serverType");
var host = wizard.getValue("host");
var workspace = wizard.getValue("workspace");
var pattern = config.macros.importTiddlers[workspace ? "systemServerNamePattern" : "systemServerNamePatternNoWorkspace"];
return pattern.format([serverType,host,workspace]);
};
config.macros.importTiddlers.saveServerTiddler = function(wizard)
{
var me = config.macros.importTiddlers;
var txtSaveTiddler = wizard.getElement("txtSaveTiddler").value;
if(store.tiddlerExists(txtSaveTiddler)) {
if(!confirm(me.confirmOverwriteSaveTiddler.format([txtSaveTiddler])))
return;
store.suspendNotifications();
store.removeTiddler(txtSaveTiddler);
store.resumeNotifications();
}
var serverType = wizard.getValue("serverType");
var host = wizard.getValue("host");
var workspace = wizard.getValue("workspace");
var text = me.serverSaveTemplate.format([serverType,host,workspace]);
store.saveTiddler(txtSaveTiddler,txtSaveTiddler,text,me.serverSaveModifier,new Date(),["systemServer"]);
};
config.macros.importTiddlers.doImport = function(e)
{
var me = config.macros.importTiddlers;
var wizard = new Wizard(this);
if(wizard.getElement("chkSave").checked)
me.saveServerTiddler(wizard);
var chkSync = wizard.getElement("chkSync").checked;
wizard.setValue("sync",chkSync);
var listView = wizard.getValue("listView");
var rowNames = ListView.getSelectedRows(listView);
var adaptor = wizard.getValue("adaptor");
var overwrite = [];
var t;
for(t=0; t<rowNames.length; t++) {
if(store.tiddlerExists(rowNames[t]))
overwrite.push(rowNames[t]);
}
if(overwrite.length > 0) {
if(!confirm(me.confirmOverwriteText.format([overwrite.join(", ")])))
return false;
}
wizard.addStep(me.step4Title.format([rowNames.length]),me.step4Html);
for(t=0; t<rowNames.length; t++) {
var link = document.createElement("div");
createTiddlyLink(link,rowNames[t],true);
var place = wizard.getElement("markReport");
place.parentNode.insertBefore(link,place);
}
wizard.setValue("remainingImports",rowNames.length);
wizard.setButtons([
{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}
],me.statusDoingImport);
var wizardContext = wizard.getValue("context");
var tiddlers = wizardContext ? wizardContext.tiddlers : [];
for(t=0; t<rowNames.length; t++) {
var context = {
allowSynchronous:true,
tiddler:tiddlers[tiddlers.findByField("title",rowNames[t])]
};
adaptor.getTiddler(rowNames[t],context,wizard,me.onGetTiddler);
}
return false;
};
config.macros.importTiddlers.onGetTiddler = function(context,wizard)
{
var me = config.macros.importTiddlers;
if(!context.status)
displayMessage("Error in importTiddlers.onGetTiddler: " + context.statusText);
var tiddler = context.tiddler;
store.suspendNotifications();
store.saveTiddler(tiddler.title, tiddler.title, tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags, tiddler.fields, true, tiddler.created);
if(!wizard.getValue("sync")) {
store.setValue(tiddler.title,'server',null);
}
store.resumeNotifications();
if(!context.isSynchronous)
store.notify(tiddler.title,true);
var remainingImports = wizard.getValue("remainingImports")-1;
wizard.setValue("remainingImports",remainingImports);
if(remainingImports == 0) {
if(context.isSynchronous) {
store.notifyAll();
refreshDisplay();
}
wizard.setButtons([
{caption: me.doneLabel, tooltip: me.donePrompt, onClick: me.onClose}
],me.statusDoneImport);
autoSaveChanges();
}
};
//--
//-- Upgrade macro
//--
config.macros.upgrade.handler = function(place)
{
var w = new Wizard();
w.createWizard(place,this.wizardTitle);
w.addStep(this.step1Title,this.step1Html.format([this.source,this.source]));
w.setButtons([{caption: this.upgradeLabel, tooltip: this.upgradePrompt, onClick: this.onClickUpgrade}]);
};
config.macros.upgrade.onClickUpgrade = function(e)
{
var me = config.macros.upgrade;
var w = new Wizard(this);
if(window.location.protocol != "file:") {
alert(me.errorCantUpgrade);
return false;
}
if(story.areAnyDirty() || store.isDirty()) {
alert(me.errorNotSaved);
return false;
}
var localPath = getLocalPath(document.location.toString());
var backupPath = getBackupPath(localPath,me.backupExtension);
w.setValue("backupPath",backupPath);
w.setButtons([],me.statusPreparingBackup);
var original = loadOriginal(localPath);
w.setButtons([],me.statusSavingBackup);
var backup = copyFile(backupPath,localPath);
if(!backup)
backup = saveFile(backupPath,original);
if(!backup) {
w.setButtons([],me.errorSavingBackup);
alert(me.errorSavingBackup);
return false;
}
w.setButtons([],me.statusLoadingCore);
var load = loadRemoteFile(me.source,me.onLoadCore,w);
if(typeof load == "string") {
w.setButtons([],me.errorLoadingCore);
alert(me.errorLoadingCore);
return false;
}
return false;
};
config.macros.upgrade.onLoadCore = function(status,params,responseText,url,xhr)
{
var me = config.macros.upgrade;
var w = params;
var errMsg;
if(!status)
errMsg = me.errorLoadingCore;
var newVer = me.extractVersion(responseText);
if(!newVer)
errMsg = me.errorCoreFormat;
if(errMsg) {
w.setButtons([],errMsg);
alert(errMsg);
return;
}
var onStartUpgrade = function(e) {
w.setButtons([],me.statusSavingCore);
var localPath = getLocalPath(document.location.toString());
saveFile(localPath,responseText);
w.setButtons([],me.statusReloadingCore);
var backupPath = w.getValue("backupPath");
var newLoc = document.location.toString() + "?time=" + new Date().convertToYYYYMMDDHHMM() + "#upgrade:[[" + encodeURI(backupPath) + "]]";
window.setTimeout(function () {window.location = newLoc;},10);
};
var step2 = [me.step2Html_downgrade,me.step2Html_restore,me.step2Html_upgrade][compareVersions(version,newVer) + 1];
w.addStep(me.step2Title,step2.format([formatVersion(newVer),formatVersion(version)]));
w.setButtons([{caption: me.startLabel, tooltip: me.startPrompt, onClick: onStartUpgrade},{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}]);
};
config.macros.upgrade.onCancel = function(e)
{
var me = config.macros.upgrade;
var w = new Wizard(this);
w.addStep(me.step3Title,me.step3Html);
w.setButtons([]);
return false;
};
config.macros.upgrade.extractVersion = function(upgradeFile)
{
var re = /^var version = \{title: "([^"]+)", major: (\d+), minor: (\d+), revision: (\d+)(, beta: (\d+)){0,1}, date: new Date\("([^"]+)"\)/mg;
var m = re.exec(upgradeFile);
return m ? {title: m[1], major: m[2], minor: m[3], revision: m[4], beta: m[6], date: new Date(m[7])} : null;
};
function upgradeFrom(path)
{
var importStore = new TiddlyWiki();
var tw = loadFile(path);
if(window.netscape !== undefined)
tw = convertUTF8ToUnicode(tw);
importStore.importTiddlyWiki(tw);
importStore.forEachTiddler(function(title,tiddler) {
if(!store.getTiddler(title)) {
store.addTiddler(tiddler);
}
});
refreshDisplay();
saveChanges(); //# To create appropriate Markup* sections
alert(config.messages.upgradeDone.format([formatVersion()]));
window.location = window.location.toString().substr(0,window.location.toString().lastIndexOf("?"));
}
//--
//-- Sync macro
//--
// Synchronisation handlers
config.syncers = {};
// Sync state.
var currSync = null;
// sync macro
config.macros.sync.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
if(!wikifier.isStatic)
this.startSync(place);
};
config.macros.sync.cancelSync = function()
{
currSync = null;
};
config.macros.sync.startSync = function(place)
{
if(currSync)
config.macros.sync.cancelSync();
currSync = {};
currSync.syncList = this.getSyncableTiddlers();
currSync.syncTasks = this.createSyncTasks(currSync.syncList);
this.preProcessSyncableTiddlers(currSync.syncList);
var wizard = new Wizard();
currSync.wizard = wizard;
wizard.createWizard(place,this.wizardTitle);
wizard.addStep(this.step1Title,this.step1Html);
var markList = wizard.getElement("markList");
var listWrapper = document.createElement("div");
markList.parentNode.insertBefore(listWrapper,markList);
currSync.listView = ListView.create(listWrapper,currSync.syncList,this.listViewTemplate);
this.processSyncableTiddlers(currSync.syncList);
wizard.setButtons([{caption: this.syncLabel, tooltip: this.syncPrompt, onClick: this.doSync}]);
};
config.macros.sync.getSyncableTiddlers = function()
{
var list = [];
store.forEachTiddler(function(title,tiddler) {
var syncItem = {};
syncItem.serverType = tiddler.getServerType();
syncItem.serverHost = tiddler.fields['server.host'];
if(syncItem.serverType && syncItem.serverHost) {
syncItem.adaptor = new config.adaptors[syncItem.serverType];
syncItem.serverHost = syncItem.adaptor.fullHostName(syncItem.serverHost);
syncItem.serverWorkspace = tiddler.fields['server.workspace'];
syncItem.tiddler = tiddler;
syncItem.title = tiddler.title;
syncItem.isTouched = tiddler.isTouched();
syncItem.selected = syncItem.isTouched;
syncItem.syncStatus = config.macros.sync.syncStatusList[syncItem.isTouched ? "changedLocally" : "none"];
syncItem.status = syncItem.syncStatus.text;
list.push(syncItem);
}
});
list.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
return list;
};
config.macros.sync.preProcessSyncableTiddlers = function(syncList)
{
for(var i=0; i<syncList.length; i++) {
var si = syncList[i];
si.serverUrl = si.adaptor.generateTiddlerInfo(si.tiddler).uri;
}
};
config.macros.sync.processSyncableTiddlers = function(syncList)
{
for(var i=0; i<syncList.length; i++) {
var si = syncList[i];
if(si.syncStatus.display)
si.rowElement.style.display = si.syncStatus.display;
if(si.syncStatus.className)
si.rowElement.className = si.syncStatus.className;
}
};
config.macros.sync.createSyncTasks = function(syncList)
{
var syncTasks = [];
for(var i=0; i<syncList.length; i++) {
var si = syncList[i];
var r = null;
for(var j=0; j<syncTasks.length; j++) {
var cst = syncTasks[j];
if(si.serverType == cst.serverType && si.serverHost == cst.serverHost && si.serverWorkspace == cst.serverWorkspace)
r = cst;
}
if(r) {
si.syncTask = r;
r.syncItems.push(si);
} else {
si.syncTask = this.createSyncTask(si);
syncTasks.push(si.syncTask);
}
}
return syncTasks;
};
config.macros.sync.createSyncTask = function(syncItem)
{
var st = {};
st.serverType = syncItem.serverType;
st.serverHost = syncItem.serverHost;
st.serverWorkspace = syncItem.serverWorkspace;
st.syncItems = [syncItem];
var openWorkspaceCallback = function(context,syncItems) {
if(context.status) {
context.adaptor.getTiddlerList(context,syncItems,getTiddlerListCallback);
return true;
}
displayMessage(context.statusText);
return false;
};
var getTiddlerListCallback = function(context,sycnItems) {
var me = config.macros.sync;
if(!context.status) {
displayMessage(context.statusText);
return false;
}
syncItems = context.userParams;
var tiddlers = context.tiddlers;
for(var i=0; i<syncItems.length; i++) {
var si = syncItems[i];
var f = tiddlers.findByField("title",si.title);
if(f !== null) {
if(tiddlers[f].fields['server.page.revision'] > si.tiddler.fields['server.page.revision']) {
si.syncStatus = me.syncStatusList[si.isTouched ? 'changedBoth' : 'changedServer'];
}
} else {
si.syncStatus = me.syncStatusList.notFound;
}
me.updateSyncStatus(si);
}
return true;
};
var context = {host:st.serverHost,workspace:st.serverWorkspace};
syncItem.adaptor.openHost(st.serverHost);
syncItem.adaptor.openWorkspace(st.serverWorkspace,context,st.syncItems,openWorkspaceCallback);
return st;
};
config.macros.sync.updateSyncStatus = function(syncItem)
{
var e = syncItem.colElements["status"];
removeChildren(e);
createTiddlyText(e,syncItem.syncStatus.text);
if(syncItem.syncStatus.display)
syncItem.rowElement.style.display = syncItem.syncStatus.display;
if(syncItem.syncStatus.className)
syncItem.rowElement.className = syncItem.syncStatus.className;
};
config.macros.sync.doSync = function(e)
{
var me = config.macros.sync;
var getTiddlerCallback = function(context,syncItem) {
if(syncItem) {
var tiddler = context.tiddler;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields,true,tiddler.created);
syncItem.syncStatus = me.syncStatusList.gotFromServer;
me.updateSyncStatus(syncItem);
}
};
var putTiddlerCallback = function(context,syncItem) {
if(syncItem) {
store.resetTiddler(context.title);
syncItem.syncStatus = me.syncStatusList.putToServer;
me.updateSyncStatus(syncItem);
}
};
var rowNames = ListView.getSelectedRows(currSync.listView);
var sl = me.syncStatusList;
for(var i=0; i<currSync.syncList.length; i++) {
var si = currSync.syncList[i];
if(rowNames.indexOf(si.title) != -1) {
var errorMsg = "Error in doSync: ";
try {
var r = true;
switch(si.syncStatus) {
case sl.changedServer:
r = si.adaptor.getTiddler(si.title,null,si,getTiddlerCallback);
break;
case sl.notFound:
case sl.changedLocally:
case sl.changedBoth:
r = si.adaptor.putTiddler(si.tiddler,null,si,putTiddlerCallback);
break;
default:
break;
}
if(!r)
displayMessage(errorMsg + r);
} catch(ex) {
if(ex.name == "TypeError")
displayMessage("sync operation unsupported: " + ex.message);
else
displayMessage(errorMsg + ex.message);
}
}
}
return false;
};
//--
//-- Manager UI for groups of tiddlers
//--
config.macros.plugins.handler = function(place,macroName,params,wikifier,paramString)
{
var wizard = new Wizard();
wizard.createWizard(place,this.wizardTitle);
wizard.addStep(this.step1Title,this.step1Html);
var markList = wizard.getElement("markList");
var listWrapper = document.createElement("div");
markList.parentNode.insertBefore(listWrapper,markList);
listWrapper.setAttribute("refresh","macro");
listWrapper.setAttribute("macroName","plugins");
listWrapper.setAttribute("params",paramString);
this.refresh(listWrapper,paramString);
};
config.macros.plugins.refresh = function(listWrapper,params)
{
var me = config.macros.plugins;
var wizard = new Wizard(listWrapper);
var selectedRows = [];
ListView.forEachSelector(listWrapper,function(e,rowName) {
if(e.checked)
selectedRows.push(e.getAttribute("rowName"));
});
removeChildren(listWrapper);
params = params.parseParams("anon");
var plugins = installedPlugins.slice(0);
var t,tiddler,p;
var configTiddlers = store.getTaggedTiddlers("systemConfig");
for(t=0; t<configTiddlers.length; t++) {
tiddler = configTiddlers[t];
if(plugins.findByField("title",tiddler.title) == null) {
p = getPluginInfo(tiddler);
p.executed = false;
p.log.splice(0,0,this.skippedText);
plugins.push(p);
}
}
for(t=0; t<plugins.length; t++) {
p = plugins[t];
p.size = p.tiddler.text ? p.tiddler.text.length : 0;
p.forced = p.tiddler.isTagged("systemConfigForce");
p.disabled = p.tiddler.isTagged("systemConfigDisable");
p.Selected = selectedRows.indexOf(plugins[t].title) != -1;
}
if(plugins.length == 0) {
createTiddlyElement(listWrapper,"em",null,null,this.noPluginText);
wizard.setButtons([]);
} else {
var listView = ListView.create(listWrapper,plugins,this.listViewTemplate,this.onSelectCommand);
wizard.setValue("listView",listView);
wizard.setButtons([
{caption: me.removeLabel, tooltip: me.removePrompt, onClick: me.doRemoveTag},
{caption: me.deleteLabel, tooltip: me.deletePrompt, onClick: me.doDelete}
]);
}
};
config.macros.plugins.doRemoveTag = function(e)
{
var wizard = new Wizard(this);
var listView = wizard.getValue("listView");
var rowNames = ListView.getSelectedRows(listView);
if(rowNames.length == 0) {
alert(config.messages.nothingSelected);
} else {
for(var t=0; t<rowNames.length; t++)
store.setTiddlerTag(rowNames[t],false,"systemConfig");
}
};
config.macros.plugins.doDelete = function(e)
{
var wizard = new Wizard(this);
var listView = wizard.getValue("listView");
var rowNames = ListView.getSelectedRows(listView);
if(rowNames.length == 0) {
alert(config.messages.nothingSelected);
} else {
if(confirm(config.macros.plugins.confirmDeleteText.format([rowNames.join(", ")]))) {
for(var t=0; t<rowNames.length; t++) {
store.removeTiddler(rowNames[t]);
story.closeTiddler(rowNames[t],true);
}
}
}
};
//--
//-- Message area
//--
function getMessageDiv()
{
var msgArea = document.getElementById("messageArea");
if(!msgArea)
return null;
if(!msgArea.hasChildNodes())
createTiddlyButton(createTiddlyElement(msgArea,"div",null,"messageToolbar"),
config.messages.messageClose.text,
config.messages.messageClose.tooltip,
clearMessage);
msgArea.style.display = "block";
return createTiddlyElement(msgArea,"div");
}
function displayMessage(text,linkText)
{
var e = getMessageDiv();
if(!e) {
alert(text);
return;
}
if(linkText) {
var link = createTiddlyElement(e,"a",null,null,text);
link.href = linkText;
link.target = "_blank";
} else {
e.appendChild(document.createTextNode(text));
}
}
function clearMessage()
{
var msgArea = document.getElementById("messageArea");
if(msgArea) {
removeChildren(msgArea);
msgArea.style.display = "none";
}
return false;
}
//--
//-- Refresh mechanism
//--
config.notifyTiddlers = [
{name: "StyleSheetLayout", notify: refreshStyles},
{name: "StyleSheetColors", notify: refreshStyles},
{name: "StyleSheet", notify: refreshStyles},
{name: "StyleSheetPrint", notify: refreshStyles},
{name: "PageTemplate", notify: refreshPageTemplate},
{name: "SiteTitle", notify: refreshPageTitle},
{name: "SiteSubtitle", notify: refreshPageTitle},
{name: "WindowTitle", notify: refreshPageTitle},
{name: "ColorPalette", notify: refreshColorPalette},
{name: null, notify: refreshDisplay}
];
config.refreshers = {
link: function(e,changeList)
{
var title = e.getAttribute("tiddlyLink");
refreshTiddlyLink(e,title);
return true;
},
tiddler: function(e,changeList)
{
var title = e.getAttribute("tiddler");
var template = e.getAttribute("template");
if(changeList && changeList.indexOf(title) != -1 && !story.isDirty(title))
story.refreshTiddler(title,template,true);
else
refreshElements(e,changeList);
return true;
},
content: function(e,changeList)
{
var title = e.getAttribute("tiddler");
var force = e.getAttribute("force");
var args = e.getAttribute("args");
if(force != null || changeList == null || changeList.indexOf(title) != -1) {
removeChildren(e);
config.macros.tiddler.transclude(e,title,args);
return true;
} else
return false;
},
macro: function(e,changeList)
{
var macro = e.getAttribute("macroName");
var params = e.getAttribute("params");
if(macro)
macro = config.macros[macro];
if(macro && macro.refresh)
macro.refresh(e,params);
return true;
}
};
config.refresherData = {
styleSheet: "StyleSheet",
defaultStyleSheet: "StyleSheet",
pageTemplate: "PageTemplate",
defaultPageTemplate: "PageTemplate",
colorPalette: "ColorPalette",
defaultColorPalette: "ColorPalette"
};
function refreshElements(root,changeList)
{
var nodes = root.childNodes;
for(var c=0; c<nodes.length; c++) {
var e = nodes[c], type = null;
if(e.getAttribute && (e.tagName ? e.tagName != "IFRAME" : true))
type = e.getAttribute("refresh");
var refresher = config.refreshers[type];
var refreshed = false;
if(refresher != undefined)
refreshed = refresher(e,changeList);
if(e.hasChildNodes() && !refreshed)
refreshElements(e,changeList);
}
}
function applyHtmlMacros(root,tiddler)
{
var e = root.firstChild;
while(e) {
var nextChild = e.nextSibling;
if(e.getAttribute) {
var macro = e.getAttribute("macro");
if(macro) {
e.removeAttribute("macro");
var params = "";
var p = macro.indexOf(" ");
if(p != -1) {
params = macro.substr(p+1);
macro = macro.substr(0,p);
}
invokeMacro(e,macro,params,null,tiddler);
}
}
if(e.hasChildNodes())
applyHtmlMacros(e,tiddler);
e = nextChild;
}
}
function refreshPageTemplate(title)
{
var stash = jQuery("<div/>").appendTo("body").hide()[0];
var display = story.getContainer();
var nodes,t;
if(display) {
nodes = display.childNodes;
for(t=nodes.length-1; t>=0; t--)
stash.appendChild(nodes[t]);
}
var wrapper = document.getElementById("contentWrapper");
var isAvailable = function(title) {
var s = title ? title.indexOf(config.textPrimitives.sectionSeparator) : -1;
if(s!=-1)
title = title.substr(0,s);
return store.tiddlerExists(title) || store.isShadowTiddler(title);
};
if(!title || !isAvailable(title))
title = config.refresherData.pageTemplate;
if(!isAvailable(title))
title = config.refresherData.defaultPageTemplate; //# this one is always avaialable
wrapper.innerHTML = store.getRecursiveTiddlerText(title,null,10);
applyHtmlMacros(wrapper);
refreshElements(wrapper);
display = story.getContainer();
removeChildren(display);
if(!display)
display = createTiddlyElement(wrapper,"div",story.containerId());
nodes = stash.childNodes;
for(t=nodes.length-1; t>=0; t--)
display.appendChild(nodes[t]);
removeNode(stash);
}
function refreshDisplay(hint)
{
if(typeof hint == "string")
hint = [hint];
var e = document.getElementById("contentWrapper");
refreshElements(e,hint);
if(backstage.isPanelVisible()) {
e = document.getElementById("backstage");
refreshElements(e,hint);
}
}
function refreshPageTitle()
{
document.title = getPageTitle();
}
function getPageTitle()
{
return wikifyPlain("WindowTitle");
}
function refreshStyles(title,doc)
{
setStylesheet(title == null ? "" : store.getRecursiveTiddlerText(title,"",10),title,doc || document);
}
function refreshColorPalette(title)
{
if(!startingUp)
refreshAll();
}
function refreshAll()
{
refreshPageTemplate();
refreshDisplay();
refreshStyles("StyleSheetLayout");
refreshStyles("StyleSheetColors");
refreshStyles(config.refresherData.styleSheet);
refreshStyles("StyleSheetPrint");
}
//--
//-- Options stuff
//--
config.optionHandlers = {
'txt': {
get: function(name) {return encodeCookie(config.options[name].toString());},
set: function(name,value) {config.options[name] = decodeCookie(value);}
},
'chk': {
get: function(name) {return config.options[name] ? "true" : "false";},
set: function(name,value) {config.options[name] = value == "true";}
}
};
function loadOptionsCookie()
{
if(safeMode)
return;
var cookies = document.cookie.split(";");
for(var c=0; c<cookies.length; c++) {
var p = cookies[c].indexOf("=");
if(p != -1) {
var name = cookies[c].substr(0,p).trim();
var value = cookies[c].substr(p+1).trim();
var optType = name.substr(0,3);
var handlers = config.optionHandlers;
if(handlers[optType] && handlers[optType].set)
handlers[optType].set(name,value);
}
}
}
function saveOptionCookie(name)
{
if(safeMode)
return;
if(name.match(/[()\s]/g, "_")) {
alert(config.messages.invalidCookie.format([name]));
return;
}
var c = name + "=";
var optType = name.substr(0,3);
var handlers = config.optionHandlers;
if(handlers[optType] && handlers[optType].get)
c += handlers[optType].get(name);
c += "; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/";
document.cookie = c;
}
function removeCookie(name)
{
document.cookie = name + "=; expires=Thu, 01-Jan-1970 00:00:01 UTC; path=/;";
}
function encodeCookie(s)
{
return escape(convertUnicodeToHtmlEntities(s));
}
function decodeCookie(s)
{
s = unescape(s);
var re = /&#[0-9]{1,5};/g;
return s.replace(re,function($0) {return String.fromCharCode(eval($0.replace(/[&#;]/g,"")));});
}
config.macros.option.genericCreate = function(place,type,opt,className,desc)
{
var typeInfo = config.macros.option.types[type];
var c = document.createElement(typeInfo.elementType);
if(typeInfo.typeValue)
c.setAttribute("type",typeInfo.typeValue);
c[typeInfo.eventName] = typeInfo.onChange;
c.setAttribute("option",opt);
c.className = className || typeInfo.className;
if(config.optionsDesc[opt])
c.setAttribute("title",config.optionsDesc[opt]);
place.appendChild(c);
if(desc != "no")
createTiddlyText(place,config.optionsDesc[opt] || opt);
c[typeInfo.valueField] = config.options[opt];
return c;
};
config.macros.option.genericOnChange = function(e)
{
var opt = this.getAttribute("option");
if(opt) {
var optType = opt.substr(0,3);
var handler = config.macros.option.types[optType];
if(handler.elementType && handler.valueField)
config.macros.option.propagateOption(opt,handler.valueField,this[handler.valueField],handler.elementType,this);
}
return true;
};
config.macros.option.types = {
'txt': {
elementType: "input",
valueField: "value",
eventName: "onchange",
className: "txtOptionInput",
create: config.macros.option.genericCreate,
onChange: config.macros.option.genericOnChange
},
'chk': {
elementType: "input",
valueField: "checked",
eventName: "onclick",
className: "chkOptionInput",
typeValue: "checkbox",
create: config.macros.option.genericCreate,
onChange: config.macros.option.genericOnChange
}
};
config.macros.option.propagateOption = function(opt,valueField,value,elementType,elem)
{
config.options[opt] = value;
saveOptionCookie(opt);
var nodes = document.getElementsByTagName(elementType);
for(var t=0; t<nodes.length; t++) {
var optNode = nodes[t].getAttribute("option");
if(opt == optNode && nodes[t]!=elem)
nodes[t][valueField] = value;
}
};
config.macros.option.handler = function(place,macroName,params,wikifier,paramString)
{
params = paramString.parseParams("anon",null,true,false,false);
var opt = (params[1] && params[1].name == "anon") ? params[1].value : getParam(params,"name",null);
var className = (params[2] && params[2].name == "anon") ? params[2].value : getParam(params,"class",null);
var desc = getParam(params,"desc","no");
var type = opt.substr(0,3);
var h = config.macros.option.types[type];
if(h && h.create)
h.create(place,type,opt,className,desc);
};
config.macros.options.handler = function(place,macroName,params,wikifier,paramString)
{
params = paramString.parseParams("anon",null,true,false,false);
var showUnknown = getParam(params,"showUnknown","no");
var wizard = new Wizard();
wizard.createWizard(place,this.wizardTitle);
wizard.addStep(this.step1Title,this.step1Html);
var markList = wizard.getElement("markList");
var chkUnknown = wizard.getElement("chkUnknown");
chkUnknown.checked = showUnknown == "yes";
chkUnknown.onchange = this.onChangeUnknown;
var listWrapper = document.createElement("div");
markList.parentNode.insertBefore(listWrapper,markList);
wizard.setValue("listWrapper",listWrapper);
this.refreshOptions(listWrapper,showUnknown == "yes");
};
config.macros.options.refreshOptions = function(listWrapper,showUnknown)
{
var opts = [];
for(var n in config.options) {
var opt = {};
opt.option = "";
opt.name = n;
opt.lowlight = !config.optionsDesc[n];
opt.description = opt.lowlight ? this.unknownDescription : config.optionsDesc[n];
if(!opt.lowlight || showUnknown)
opts.push(opt);
}
opts.sort(function(a,b) {return a.name.substr(3) < b.name.substr(3) ? -1 : (a.name.substr(3) == b.name.substr(3) ? 0 : +1);});
var listview = ListView.create(listWrapper,opts,this.listViewTemplate);
for(n=0; n<opts.length; n++) {
var type = opts[n].name.substr(0,3);
var h = config.macros.option.types[type];
if(h && h.create) {
h.create(opts[n].colElements['option'],type,opts[n].name,null,"no");
}
}
};
config.macros.options.onChangeUnknown = function(e)
{
var wizard = new Wizard(this);
var listWrapper = wizard.getValue("listWrapper");
removeChildren(listWrapper);
config.macros.options.refreshOptions(listWrapper,this.checked);
return false;
};
//--
//-- Saving
//--
var saveUsingSafari = false;
var startSaveArea = '<div id="' + 'storeArea">'; // Split up into two so that indexOf() of this source doesn't find it
var endSaveArea = '</d' + 'iv>';
// If there are unsaved changes, force the user to confirm before exitting
function confirmExit()
{
hadConfirmExit = true;
if((store && store.isDirty && store.isDirty()) || (story && story.areAnyDirty && story.areAnyDirty()))
return config.messages.confirmExit;
}
// Give the user a chance to save changes before exitting
function checkUnsavedChanges()
{
if(store && store.isDirty && store.isDirty() && window.hadConfirmExit === false) {
if(confirm(config.messages.unsavedChangesWarning))
saveChanges();
}
}
function updateLanguageAttribute(s)
{
if(config.locale) {
var mRE = /(<html(?:.*?)?)(?: xml:lang\="([a-z]+)")?(?: lang\="([a-z]+)")?>/;
var m = mRE.exec(s);
if(m) {
var t = m[1];
if(m[2])
t += ' xml:lang="' + config.locale + '"';
if(m[3])
t += ' lang="' + config.locale + '"';
t += ">";
s = s.substr(0,m.index) + t + s.substr(m.index+m[0].length);
}
}
return s;
}
function updateMarkupBlock(s,blockName,tiddlerName)
{
return s.replaceChunk(
"<!--%0-START-->".format([blockName]),
"<!--%0-END-->".format([blockName]),
"\n" + convertUnicodeToFileFormat(store.getRecursiveTiddlerText(tiddlerName,"")) + "\n");
}
function updateOriginal(original,posDiv,localPath)
{
if(!posDiv)
posDiv = locateStoreArea(original);
if(!posDiv) {
alert(config.messages.invalidFileError.format([localPath]));
return null;
}
var revised = original.substr(0,posDiv[0] + startSaveArea.length) + "\n" +
convertUnicodeToFileFormat(store.allTiddlersAsHtml()) + "\n" +
original.substr(posDiv[1]);
var newSiteTitle = convertUnicodeToFileFormat(getPageTitle()).htmlEncode();
revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");
revised = updateLanguageAttribute(revised);
revised = updateMarkupBlock(revised,"PRE-HEAD","MarkupPreHead");
revised = updateMarkupBlock(revised,"POST-HEAD","MarkupPostHead");
revised = updateMarkupBlock(revised,"PRE-BODY","MarkupPreBody");
revised = updateMarkupBlock(revised,"POST-SCRIPT","MarkupPostBody");
return revised;
}
function locateStoreArea(original)
{
// Locate the storeArea div's
var posOpeningDiv = original.indexOf(startSaveArea);
var limitClosingDiv = original.indexOf("<"+"!--POST-STOREAREA--"+">");
if(limitClosingDiv == -1)
limitClosingDiv = original.indexOf("<"+"!--POST-BODY-START--"+">");
var posClosingDiv = original.lastIndexOf(endSaveArea,limitClosingDiv == -1 ? original.length : limitClosingDiv);
return (posOpeningDiv != -1 && posClosingDiv != -1) ? [posOpeningDiv,posClosingDiv] : null;
}
function autoSaveChanges(onlyIfDirty,tiddlers)
{
if(config.options.chkAutoSave)
saveChanges(onlyIfDirty,tiddlers);
}
function loadOriginal(localPath)
{
return loadFile(localPath);
}
// Save this tiddlywiki with the pending changes
function saveChanges(onlyIfDirty,tiddlers)
{
if(onlyIfDirty && !store.isDirty())
return;
clearMessage();
var t0 = new Date();
var msg = config.messages;
var originalPath = document.location.toString();
if(originalPath.substr(0,5) != "file:") {
alert(msg.notFileUrlError);
if(store.tiddlerExists(msg.saveInstructions))
story.displayTiddler(null,msg.saveInstructions);
return;
}
var localPath = getLocalPath(originalPath);
var original = loadOriginal(localPath);
if(original == null) {
alert(msg.cantSaveError);
if(store.tiddlerExists(msg.saveInstructions))
story.displayTiddler(null,msg.saveInstructions);
return;
}
var posDiv = locateStoreArea(original);
if(!posDiv) {
alert(msg.invalidFileError.format([localPath]));
return;
}
saveMain(localPath,original,posDiv);
if(config.options.chkSaveBackups)
saveBackup(localPath,original);
if(config.options.chkSaveEmptyTemplate)
saveEmpty(localPath,original,posDiv);
if(config.options.chkGenerateAnRssFeed && saveRss instanceof Function)
saveRss(localPath);
if(config.options.chkDisplayInstrumentation)
displayMessage("saveChanges " + (new Date()-t0) + " ms");
}
function saveMain(localPath,original,posDiv)
{
var save;
try {
var revised = updateOriginal(original,posDiv,localPath);
save = saveFile(localPath,revised);
} catch (ex) {
showException(ex);
}
if(save) {
displayMessage(config.messages.mainSaved,"file://" + localPath);
store.setDirty(false);
} else {
alert(config.messages.mainFailed);
}
}
function saveBackup(localPath,original)
{
var backupPath = getBackupPath(localPath);
var backup = copyFile(backupPath,localPath);
if(!backup)
backup = saveFile(backupPath,original);
if(backup)
displayMessage(config.messages.backupSaved,"file://" + backupPath);
else
alert(config.messages.backupFailed);
}
function saveEmpty(localPath,original,posDiv)
{
var emptyPath,p;
if((p = localPath.lastIndexOf("/")) != -1)
emptyPath = localPath.substr(0,p) + "/";
else if((p = localPath.lastIndexOf("\\")) != -1)
emptyPath = localPath.substr(0,p) + "\\";
else
emptyPath = localPath + ".";
emptyPath += "empty.html";
var empty = original.substr(0,posDiv[0] + startSaveArea.length) + original.substr(posDiv[1]);
var emptySave = saveFile(emptyPath,empty);
if(emptySave)
displayMessage(config.messages.emptySaved,"file://" + emptyPath);
else
alert(config.messages.emptyFailed);
}
function getLocalPath(origPath)
{
var originalPath = convertUriToUTF8(origPath,config.options.txtFileSystemCharSet);
// Remove any location or query part of the URL
var argPos = originalPath.indexOf("?");
if(argPos != -1)
originalPath = originalPath.substr(0,argPos);
var hashPos = originalPath.indexOf("#");
if(hashPos != -1)
originalPath = originalPath.substr(0,hashPos);
// Convert file://localhost/ to file:///
if(originalPath.indexOf("file://localhost/") == 0)
originalPath = "file://" + originalPath.substr(16);
// Convert to a native file format
var localPath;
if(originalPath.charAt(9) == ":") // pc local file
localPath = unescape(originalPath.substr(8)).replace(new RegExp("/","g"),"\\");
else if(originalPath.indexOf("file://///") == 0) // FireFox pc network file
localPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/","g"),"\\");
else if(originalPath.indexOf("file:///") == 0) // mac/unix local file
localPath = unescape(originalPath.substr(7));
else if(originalPath.indexOf("file:/") == 0) // mac/unix local file
localPath = unescape(originalPath.substr(5));
else // pc network file
localPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/","g"),"\\");
return localPath;
}
function getBackupPath(localPath,title,extension)
{
var slash = "\\";
var dirPathPos = localPath.lastIndexOf("\\");
if(dirPathPos == -1) {
dirPathPos = localPath.lastIndexOf("/");
slash = "/";
}
var backupFolder = config.options.txtBackupFolder;
if(!backupFolder || backupFolder == "")
backupFolder = ".";
var backupPath = localPath.substr(0,dirPathPos) + slash + backupFolder + localPath.substr(dirPathPos);
backupPath = backupPath.substr(0,backupPath.lastIndexOf(".")) + ".";
if(title)
backupPath += title.replace(/[\\\/\*\?\":<> ]/g,"_") + ".";
backupPath += (new Date()).convertToYYYYMMDDHHMMSSMMM() + "." + (extension || "html");
return backupPath;
}
//--
//-- RSS Saving
//--
function saveRss(localPath)
{
var rssPath = localPath.substr(0,localPath.lastIndexOf(".")) + ".xml";
if(saveFile(rssPath,convertUnicodeToFileFormat(generateRss())))
displayMessage(config.messages.rssSaved,"file://" + rssPath);
else
alert(config.messages.rssFailed);
}
tiddlerToRssItem = function(tiddler,uri)
{
var s = "<title" + ">" + tiddler.title.htmlEncode() + "</title" + ">\n";
s += "<description>" + wikifyStatic(tiddler.text,null,tiddler).htmlEncode() + "</description>\n";
for(var i=0; i<tiddler.tags.length; i++)
s += "<category>" + tiddler.tags[i] + "</category>\n";
s += "<link>" + uri + "#" + encodeURIComponent(String.encodeTiddlyLink(tiddler.title)) + "</link>\n";
s +="<pubDate>" + tiddler.modified.toGMTString() + "</pubDate>\n";
return s;
};
function generateRss()
{
var s = [];
var d = new Date();
var u = store.getTiddlerText("SiteUrl");
// Assemble the header
s.push("<" + "?xml version=\"1.0\"?" + ">");
s.push("<rss version=\"2.0\">");
s.push("<channel>");
s.push("<title" + ">" + wikifyPlain("SiteTitle").htmlEncode() + "</title" + ">");
if(u)
s.push("<link>" + u.htmlEncode() + "</link>");
s.push("<description>" + wikifyPlain("SiteSubtitle").htmlEncode() + "</description>");
s.push("<language>" + config.locale + "</language>");
s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
s.push("<generator>TiddlyWiki " + formatVersion() + "</generator>");
// The body
var tiddlers = store.getTiddlers("modified","excludeLists");
var n = config.numRssItems > tiddlers.length ? 0 : tiddlers.length-config.numRssItems;
for(var i=tiddlers.length-1; i>=n; i--) {
s.push("<item>\n" + tiddlerToRssItem(tiddlers[i],u) + "\n</item>");
}
// And footer
s.push("</channel>");
s.push("</rss>");
// Save it all
return s.join("\n");
}
//--
//-- Filesystem code
//--
function convertUTF8ToUnicode(u)
{
return config.browser.isOpera || !window.netscape ? manualConvertUTF8ToUnicode(u) : mozConvertUTF8ToUnicode(u);
}
function manualConvertUTF8ToUnicode(utf)
{
var uni = utf;
var src = 0;
var dst = 0;
var b1, b2, b3;
var c;
while(src < utf.length) {
b1 = utf.charCodeAt(src++);
if(b1 < 0x80) {
dst++;
} else if(b1 < 0xE0) {
b2 = utf.charCodeAt(src++);
c = String.fromCharCode(((b1 & 0x1F) << 6) | (b2 & 0x3F));
uni = uni.substring(0,dst++).concat(c,utf.substr(src));
} else {
b2 = utf.charCodeAt(src++);
b3 = utf.charCodeAt(src++);
c = String.fromCharCode(((b1 & 0xF) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
uni = uni.substring(0,dst++).concat(c,utf.substr(src));
}
}
return uni;
}
function mozConvertUTF8ToUnicode(u)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
} catch(ex) {
return manualConvertUTF8ToUnicode(u);
} // fallback
var s = converter.ConvertToUnicode(u);
var fin = converter.Finish();
return fin.length > 0 ? s+fin : s;
}
function convertUnicodeToFileFormat(s)
{
return config.browser.isOpera || !window.netscape ? (config.browser.isIE ? convertUnicodeToHtmlEntities(s) : s) : mozConvertUnicodeToUTF8(s);
}
function convertUnicodeToHtmlEntities(s)
{
var re = /[^\u0000-\u007F]/g;
return s.replace(re,function($0) {return "&#" + $0.charCodeAt(0).toString() + ";";});
}
function convertUnicodeToUTF8(s)
{
// return convertUnicodeToFileFormat to allow plugin migration
return convertUnicodeToFileFormat(s);
}
function manualConvertUnicodeToUTF8(s)
{
return unescape(encodeURIComponent(s));
}
function mozConvertUnicodeToUTF8(s)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
} catch(ex) {
return manualConvertUnicodeToUTF8(s);
} // fallback
var u = converter.ConvertFromUnicode(s);
var fin = converter.Finish();
return fin.length > 0 ? u + fin : u;
}
function convertUriToUTF8(uri,charSet)
{
if(window.netscape == undefined || charSet == undefined || charSet == "")
return uri;
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var converter = Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
} catch(ex) {
return uri;
}
return converter.convertURISpecToUTF8(uri,charSet);
}
function copyFile(dest,source)
{
return config.browser.isIE ? ieCopyFile(dest,source) : false;
}
function saveFile(fileUrl,content)
{
var r = mozillaSaveFile(fileUrl,content);
if(!r)
r = ieSaveFile(fileUrl,content);
if(!r)
r = javaSaveFile(fileUrl,content);
return r;
}
function loadFile(fileUrl)
{
var r = mozillaLoadFile(fileUrl);
if((r == null) || (r == false))
r = ieLoadFile(fileUrl);
if((r == null) || (r == false))
r = javaLoadFile(fileUrl);
return r;
}
function ieCreatePath(path)
{
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
} catch(ex) {
return null;
}
var pos = path.lastIndexOf("\\");
if(pos==-1)
pos = path.lastIndexOf("/");
if(pos!=-1)
path = path.substring(0,pos+1);
var scan = [path];
var parent = fso.GetParentFolderName(path);
while(parent && !fso.FolderExists(parent)) {
scan.push(parent);
parent = fso.GetParentFolderName(parent);
}
for(i=scan.length-1;i>=0;i--) {
if(!fso.FolderExists(scan[i])) {
fso.CreateFolder(scan[i]);
}
}
return true;
}
// Returns null if it can't do it, false if there's an error, true if it saved OK
function ieSaveFile(filePath,content)
{
ieCreatePath(filePath);
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
} catch(ex) {
return null;
}
var file = fso.OpenTextFile(filePath,2,-1,0);
file.Write(content);
file.Close();
return true;
}
// Returns null if it can't do it, false if there's an error, or a string of the content if successful
function ieLoadFile(filePath)
{
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(filePath,1);
var content = file.ReadAll();
file.Close();
} catch(ex) {
return null;
}
return content;
}
function ieCopyFile(dest,source)
{
ieCreatePath(dest);
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetFile(source).Copy(dest);
} catch(ex) {
return false;
}
return true;
}
// Returns null if it can't do it, false if there's an error, true if it saved OK
function mozillaSaveFile(filePath,content)
{
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0664);
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
out.init(file,0x20|0x02,00004,null);
out.write(content,content.length);
out.flush();
out.close();
return true;
} catch(ex) {
return false;
}
}
return null;
}
// Returns null if it can't do it, false if there's an error, or a string of the content if successful
function mozillaLoadFile(filePath)
{
if(window.Components) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
return null;
var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
inputStream.init(file,0x01,00004,null);
var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
sInputStream.init(inputStream);
var contents = sInputStream.read(sInputStream.available());
sInputStream.close();
inputStream.close();
return contents;
} catch(ex) {
return false;
}
}
return null;
}
function javaUrlToFilename(url)
{
var f = "//localhost";
if(url.indexOf(f) == 0)
return url.substring(f.length);
var i = url.indexOf(":");
return i > 0 ? url.substring(i-1) : url;
}
function javaSaveFile(filePath,content)
{
try {
if(document.applets["TiddlySaver"])
return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
} catch(ex) {
}
try {
var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
s.print(content);
s.close();
} catch(ex) {
return null;
}
return true;
}
function javaLoadFile(filePath)
{
try {
if(document.applets["TiddlySaver"])
return String(document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8"));
} catch(ex) {
}
var content = [];
try {
var r = new java.io.BufferedReader(new java.io.FileReader(javaUrlToFilename(filePath)));
var line;
while((line = r.readLine()) != null)
content.push(new String(line));
r.close();
} catch(ex) {
return null;
}
return content.join("\n");
}
//--
//-- Server adaptor base class
//--
function AdaptorBase()
{
this.host = null;
this.store = null;
return this;
}
AdaptorBase.prototype.close = function()
{
return true;
};
AdaptorBase.prototype.fullHostName = function(host)
{
if(!host)
return '';
host = host.trim();
if(!host.match(/:\/\//))
host = 'http://' + host;
if(host.substr(host.length-1) == '/')
host = host.substr(0,host.length-1);
return host;
};
AdaptorBase.minHostName = function(host)
{
return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
};
AdaptorBase.prototype.setContext = function(context,userParams,callback)
{
if(!context) context = {};
context.userParams = userParams;
if(callback) context.callback = callback;
context.adaptor = this;
if(!context.host)
context.host = this.host;
context.host = this.fullHostName(context.host);
if(!context.workspace)
context.workspace = this.workspace;
return context;
};
// Open the specified host
AdaptorBase.prototype.openHost = function(host,context,userParams,callback)
{
this.host = host;
context = this.setContext(context,userParams,callback);
context.status = true;
if(callback)
window.setTimeout(function() {context.callback(context,userParams);},10);
return true;
};
// Open the specified workspace
AdaptorBase.prototype.openWorkspace = function(workspace,context,userParams,callback)
{
this.workspace = workspace;
context = this.setContext(context,userParams,callback);
context.status = true;
if(callback)
window.setTimeout(function() {callback(context,userParams);},10);
return true;
};
//--
//-- Server adaptor for talking to static TiddlyWiki files
//--
function FileAdaptor()
{
}
FileAdaptor.prototype = new AdaptorBase();
FileAdaptor.serverType = 'file';
FileAdaptor.serverLabel = 'TiddlyWiki';
FileAdaptor.loadTiddlyWikiCallback = function(status,context,responseText,url,xhr)
{
context.status = status;
if(!status) {
context.statusText = "Error reading file";
} else {
context.adaptor.store = new TiddlyWiki();
if(!context.adaptor.store.importTiddlyWiki(responseText)) {
context.statusText = config.messages.invalidFileError.format([url]);
context.status = false;
}
}
context.complete(context,context.userParams);
};
// Get the list of workspaces on a given server
FileAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.workspaces = [{title:"(default)"}];
context.status = true;
if(callback)
window.setTimeout(function() {callback(context,userParams);},10);
return true;
};
// Gets the list of tiddlers within a given workspace
FileAdaptor.prototype.getTiddlerList = function(context,userParams,callback,filter)
{
context = this.setContext(context,userParams,callback);
if(!context.filter)
context.filter = filter;
context.complete = FileAdaptor.getTiddlerListComplete;
if(this.store) {
var ret = context.complete(context,context.userParams);
} else {
ret = loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context);
if(typeof ret != "string")
ret = true;
}
return ret;
};
FileAdaptor.getTiddlerListComplete = function(context,userParams)
{
if(context.status) {
if(context.filter) {
context.tiddlers = context.adaptor.store.filterTiddlers(context.filter);
} else {
context.tiddlers = [];
context.adaptor.store.forEachTiddler(function(title,tiddler) {context.tiddlers.push(tiddler);});
}
for(var i=0; i<context.tiddlers.length; i++) {
context.tiddlers[i].fields['server.type'] = FileAdaptor.serverType;
context.tiddlers[i].fields['server.host'] = AdaptorBase.minHostName(context.host);
context.tiddlers[i].fields['server.page.revision'] = context.tiddlers[i].modified.convertToYYYYMMDDHHMM();
}
context.status = true;
}
if(context.callback) {
window.setTimeout(function() {context.callback(context,userParams);},10);
}
return true;
};
FileAdaptor.prototype.generateTiddlerInfo = function(tiddler)
{
var info = {};
info.uri = tiddler.fields['server.host'] + "#" + tiddler.title;
return info;
};
// Retrieve a tiddler from a given workspace on a given server
FileAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
{
context = this.setContext(context,userParams,callback);
context.title = title;
context.complete = FileAdaptor.getTiddlerComplete;
return context.adaptor.store ?
context.complete(context,context.userParams) :
loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context);
};
FileAdaptor.getTiddlerComplete = function(context,userParams)
{
var t = context.adaptor.store.fetchTiddler(context.title);
if(t) {
t.fields['server.type'] = FileAdaptor.serverType;
t.fields['server.host'] = AdaptorBase.minHostName(context.host);
t.fields['server.page.revision'] = t.modified.convertToYYYYMMDDHHMM();
context.tiddler = t;
context.status = true;
} else { //# tiddler does not exist in document
context.status = false;
}
if(context.allowSynchronous) {
context.isSynchronous = true;
context.callback(context,userParams);
} else {
window.setTimeout(function() {context.callback(context,userParams);},10);
}
return true;
};
FileAdaptor.prototype.close = function()
{
delete this.store;
this.store = null;
};
config.adaptors[FileAdaptor.serverType] = FileAdaptor;
config.defaultAdaptor = FileAdaptor.serverType;
//--
//-- HTTP request code
//--
function ajaxReq(args)
{
if(window.Components && window.netscape && window.netscape.security && document.location.protocol.indexOf("http") == -1)
window.netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
return jQuery.ajax(args);
}
//--
//-- TiddlyWiki-specific utility functions
//--
// Returns TiddlyWiki version string
function formatVersion(v)
{
v = v || version;
return v.major + "." + v.minor + "." + v.revision +
(v.alpha ? " (alpha " + v.alpha + ")" : "") +
(v.beta ? " (beta " + v.beta + ")" : "");
}
function compareVersions(v1,v2)
{
var a = ["major","minor","revision"];
for(var i = 0; i<a.length; i++) {
var x1 = v1[a[i]] || 0;
var x2 = v2[a[i]] || 0;
if(x1<x2)
return 1;
if(x1>x2)
return -1;
}
x1 = v1.beta || 9999;
x2 = v2.beta || 9999;
if(x1<x2)
return 1;
return x1 > x2 ? -1 : 0;
}
function createTiddlyButton(parent,text,tooltip,action,className,id,accessKey,attribs)
{
var btn = document.createElement("a");
if(action) {
btn.onclick = action;
btn.setAttribute("href","javascript:;");
}
if(tooltip)
btn.setAttribute("title",tooltip);
if(text)
btn.appendChild(document.createTextNode(text));
btn.className = className || "button";
if(id)
btn.id = id;
if(attribs) {
for(var i in attribs) {
btn.setAttribute(i,attribs[i]);
}
}
if(parent)
parent.appendChild(btn);
if(accessKey)
btn.setAttribute("accessKey",accessKey);
return btn;
}
function createTiddlyLink(place,title,includeText,className,isStatic,linkedFromTiddler,noToggle)
{
var text = includeText ? title : null;
var i = getTiddlyLinkInfo(title,className);
var btn = isStatic ? createExternalLink(place,store.getTiddlerText("SiteUrl",null) + "#" + title) : createTiddlyButton(place,text,i.subTitle,onClickTiddlerLink,i.classes);
if(isStatic)
btn.className += ' ' + className;
btn.setAttribute("refresh","link");
btn.setAttribute("tiddlyLink",title);
if(noToggle)
btn.setAttribute("noToggle","true");
if(linkedFromTiddler) {
var fields = linkedFromTiddler.getInheritedFields();
if(fields)
btn.setAttribute("tiddlyFields",fields);
}
return btn;
}
function refreshTiddlyLink(e,title)
{
var i = getTiddlyLinkInfo(title,e.className);
e.className = i.classes;
e.title = i.subTitle;
}
function getTiddlyLinkInfo(title,currClasses)
{
var classes = currClasses ? currClasses.split(" ") : [];
classes.pushUnique("tiddlyLink");
var tiddler = store.fetchTiddler(title);
var subTitle;
if(tiddler) {
subTitle = tiddler.getSubtitle();
classes.pushUnique("tiddlyLinkExisting");
classes.remove("tiddlyLinkNonExisting");
classes.remove("shadow");
} else {
classes.remove("tiddlyLinkExisting");
classes.pushUnique("tiddlyLinkNonExisting");
if(store.isShadowTiddler(title)) {
subTitle = config.messages.shadowedTiddlerToolTip.format([title]);
classes.pushUnique("shadow");
} else {
subTitle = config.messages.undefinedTiddlerToolTip.format([title]);
classes.remove("shadow");
}
}
if(typeof config.annotations[title]=="string")
subTitle = config.annotations[title];
return {classes: classes.join(" "),subTitle: subTitle};
}
function createExternalLink(place,url,label)
{
var link = document.createElement("a");
link.className = "externalLink";
link.href = url;
link.title = config.messages.externalLinkTooltip.format([url]);
if(config.options.chkOpenInNewWindow)
link.target = "_blank";
place.appendChild(link);
if(label)
createTiddlyText(link, label);
return link;
}
// Event handler for clicking on a tiddly link
function onClickTiddlerLink(ev)
{
var e = ev || window.event;
var target = resolveTarget(e);
var link = target;
var title = null;
var fields = null;
var noToggle = null;
do {
title = link.getAttribute("tiddlyLink");
fields = link.getAttribute("tiddlyFields");
noToggle = link.getAttribute("noToggle");
link = link.parentNode;
} while(title == null && link != null);
if(!store.isShadowTiddler(title)) {
var f = fields ? fields.decodeHashMap() : {};
fields = String.encodeHashMap(merge(f,config.defaultCustomFields,true));
}
if(title) {
var toggling = e.metaKey || e.ctrlKey;
if(config.options.chkToggleLinks)
toggling = !toggling;
if(noToggle)
toggling = false;
if(store.getTiddler(title))
fields = null;
story.displayTiddler(target,title,null,true,null,fields,toggling);
}
clearMessage();
return false;
}
// Create a button for a tag with a popup listing all the tiddlers that it tags
function createTagButton(place,tag,excludeTiddler,title,tooltip)
{
var btn = createTiddlyButton(place,title||tag,(tooltip||config.views.wikified.tag.tooltip).format([tag]),onClickTag);
btn.setAttribute("tag",tag);
if(excludeTiddler)
btn.setAttribute("tiddler",excludeTiddler);
return btn;
}
// Event handler for clicking on a tiddler tag
function onClickTag(ev)
{
var e = ev || window.event;
var popup = Popup.create(this);
addClass(popup,"taggedTiddlerList");
var tag = this.getAttribute("tag");
var title = this.getAttribute("tiddler");
if(popup && tag) {
var tagged = tag.indexOf("[")==-1 ? store.getTaggedTiddlers(tag) : store.filterTiddlers(tag);
var sortby = this.getAttribute("sortby");
if(sortby&&sortby.length) {
store.sortTiddlers(tagged,sortby);
}
var titles = [];
var li,r;
for(r=0;r<tagged.length;r++) {
if(tagged[r].title != title)
titles.push(tagged[r].title);
}
var lingo = config.views.wikified.tag;
if(titles.length > 0) {
var openAll = createTiddlyButton(createTiddlyElement(popup,"li"),lingo.openAllText.format([tag]),lingo.openAllTooltip,onClickTagOpenAll);
openAll.setAttribute("tag",tag);
openAll.setAttribute("sortby",sortby);
createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
for(r=0; r<titles.length; r++) {
createTiddlyLink(createTiddlyElement(popup,"li"),titles[r],true);
}
} else {
createTiddlyElement(popup,"li",null,"disabled",lingo.popupNone.format([tag]));
}
createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
var h = createTiddlyLink(createTiddlyElement(popup,"li"),tag,false);
createTiddlyText(h,lingo.openTag.format([tag]));
}
Popup.show();
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
return false;
}
// Event handler for 'open all' on a tiddler popup
function onClickTagOpenAll(ev)
{
var tiddlers = store.getTaggedTiddlers(this.getAttribute("tag"));
var sortby = this.getAttribute("sortby");
if(sortby&&sortby.length) {
store.sortTiddlers(tiddlers,sortby);
}
story.displayTiddlers(this,tiddlers);
return false;
}
function onClickError(ev)
{
var e = ev || window.event;
var popup = Popup.create(this);
var lines = this.getAttribute("errorText").split("\n");
for(var t=0; t<lines.length; t++)
createTiddlyElement(popup,"li",null,null,lines[t]);
Popup.show();
e.cancelBubble = true;
if(e.stopPropagation) e.stopPropagation();
return false;
}
function createTiddlyDropDown(place,onchange,options,defaultValue)
{
var sel = createTiddlyElement(place,"select");
sel.onchange = onchange;
for(var t=0; t<options.length; t++) {
var e = createTiddlyElement(sel,"option",null,null,options[t].caption);
e.value = options[t].name;
if(options[t].name == defaultValue)
e.selected = true;
}
return sel;
}
function createTiddlyPopup(place,caption,tooltip,tiddler)
{
if(tiddler.text) {
createTiddlyLink(place,caption,true);
var btn = createTiddlyButton(place,glyph("downArrow"),tooltip,onClickTiddlyPopup,"tiddlerPopupButton");
btn.tiddler = tiddler;
} else {
createTiddlyText(place,caption);
}
}
function onClickTiddlyPopup(ev)
{
var e = ev || window.event;
var tiddler = this.tiddler;
if(tiddler.text) {
var popup = Popup.create(this,"div","popupTiddler");
wikify(tiddler.text,popup,null,tiddler);
Popup.show();
}
if(e) e.cancelBubble = true;
if(e && e.stopPropagation) e.stopPropagation();
return false;
}
function createTiddlyError(place,title,text)
{
var btn = createTiddlyButton(place,title,null,onClickError,"errorButton");
if(text) btn.setAttribute("errorText",text);
}
function merge(dst,src,preserveExisting)
{
for(var i in src) {
if(!preserveExisting || dst[i] === undefined)
dst[i] = src[i];
}
return dst;
}
// Returns a string containing the description of an exception, optionally prepended by a message
function exceptionText(e,message)
{
var s = e.description || e.toString();
return message ? "%0:\n%1".format([message,s]) : s;
}
// Displays an alert of an exception description with optional message
function showException(e,message)
{
alert(exceptionText(e,message));
}
function alertAndThrow(m)
{
alert(m);
throw(m);
}
function glyph(name)
{
var g = config.glyphs;
var b = g.currBrowser;
if(b == null) {
b = 0;
while(!g.browsers[b]() && b < g.browsers.length-1)
b++;
g.currBrowser = b;
}
if(!g.codes[name])
return "";
return g.codes[name][b];
}
if(!window.console) {
console = {tiddlywiki:true,log:function(message) {displayMessage(message);}};
}
//-
//- Animation engine
//-
function Animator()
{
this.running = 0; // Incremented at start of each animation, decremented afterwards. If zero, the interval timer is disabled
this.timerID = 0; // ID of the timer used for animating
this.animations = []; // List of animations in progress
return this;
}
// Start animation engine
Animator.prototype.startAnimating = function() //# Variable number of arguments
{
for(var t=0; t<arguments.length; t++)
this.animations.push(arguments[t]);
if(this.running == 0) {
var me = this;
this.timerID = window.setInterval(function() {me.doAnimate(me);},10);
}
this.running += arguments.length;
};
// Perform an animation engine tick, calling each of the known animation modules
Animator.prototype.doAnimate = function(me)
{
var a = 0;
while(a < me.animations.length) {
var animation = me.animations[a];
if(animation.tick()) {
a++;
} else {
me.animations.splice(a,1);
if(--me.running == 0)
window.clearInterval(me.timerID);
}
}
};
Animator.slowInSlowOut = function(progress)
{
return(1-((Math.cos(progress * Math.PI)+1)/2));
};
//--
//-- Morpher animation
//--
// Animate a set of properties of an element
function Morpher(element,duration,properties,callback)
{
this.element = element;
this.duration = duration;
this.properties = properties;
this.startTime = new Date();
this.endTime = Number(this.startTime) + duration;
this.callback = callback;
this.tick();
return this;
}
Morpher.prototype.assignStyle = function(element,style,value)
{
switch(style) {
case "-tw-vertScroll":
window.scrollTo(findScrollX(),value);
break;
case "-tw-horizScroll":
window.scrollTo(value,findScrollY());
break;
default:
element.style[style] = value;
break;
}
};
Morpher.prototype.stop = function()
{
for(var t=0; t<this.properties.length; t++) {
var p = this.properties[t];
if(p.atEnd !== undefined) {
this.assignStyle(this.element,p.style,p.atEnd);
}
}
if(this.callback)
this.callback(this.element,this.properties);
};
Morpher.prototype.tick = function()
{
var currTime = Number(new Date());
var progress = Animator.slowInSlowOut(Math.min(1,(currTime-this.startTime)/this.duration));
for(var t=0; t<this.properties.length; t++) {
var p = this.properties[t];
if(p.start !== undefined && p.end !== undefined) {
var template = p.template || "%0";
switch(p.format) {
case undefined:
case "style":
var v = p.start + (p.end-p.start) * progress;
this.assignStyle(this.element,p.style,template.format([v]));
break;
case "color":
break;
}
}
}
if(currTime >= this.endTime) {
this.stop();
return false;
}
return true;
};
//--
//-- Zoomer animation
//--
function Zoomer(text,startElement,targetElement,unused)
{
var e = createTiddlyElement(document.body,"div",null,"zoomer");
createTiddlyElement(e,"div",null,null,text);
var winWidth = findWindowWidth();
var winHeight = findWindowHeight();
var p = [
{style: 'left', start: findPosX(startElement), end: findPosX(targetElement), template: '%0px'},
{style: 'top', start: findPosY(startElement), end: findPosY(targetElement), template: '%0px'},
{style: 'width', start: Math.min(startElement.scrollWidth,winWidth), end: Math.min(targetElement.scrollWidth,winWidth), template: '%0px', atEnd: 'auto'},
{style: 'height', start: Math.min(startElement.scrollHeight,winHeight), end: Math.min(targetElement.scrollHeight,winHeight), template: '%0px', atEnd: 'auto'},
{style: 'fontSize', start: 8, end: 24, template: '%0pt'}
];
var c = function(element,properties) {removeNode(element);};
return new Morpher(e,config.animDuration,p,c);
}
//--
//-- Scroller animation
//--
function Scroller(targetElement)
{
var p = [{style: '-tw-vertScroll', start: findScrollY(), end: ensureVisible(targetElement)}];
return new Morpher(targetElement,config.animDuration,p);
}
//--
//-- Slider animation
//--
// deleteMode - "none", "all" [delete target element and it's children], [only] "children" [but not the target element]
function Slider(element,opening,unused,deleteMode)
{
element.style.overflow = 'hidden';
if(opening)
element.style.height = '0px'; // Resolves a Firefox flashing bug
element.style.display = 'block';
var left = findPosX(element);
var width = element.scrollWidth;
var height = element.scrollHeight;
var winWidth = findWindowWidth();
var p = [];
var c = null;
if(opening) {
p.push({style: 'height', start: 0, end: height, template: '%0px', atEnd: 'auto'});
p.push({style: 'opacity', start: 0, end: 1, template: '%0'});
p.push({style: 'filter', start: 0, end: 100, template: 'alpha(opacity:%0)'});
} else {
p.push({style: 'height', start: height, end: 0, template: '%0px'});
p.push({style: 'display', atEnd: 'none'});
p.push({style: 'opacity', start: 1, end: 0, template: '%0'});
p.push({style: 'filter', start: 100, end: 0, template: 'alpha(opacity:%0)'});
switch(deleteMode) {
case "all":
c = function(element,properties) {removeNode(element);};
break;
case "children":
c = function(element,properties) {removeChildren(element);};
break;
}
}
return new Morpher(element,config.animDuration,p,c);
}
//--
//-- Popup menu
//--
var Popup = {
stack: [] // Array of objects with members root: and popup:
};
Popup.create = function(root,elem,className)
{
var stackPosition = this.find(root,"popup");
Popup.remove(stackPosition+1);
var popup = createTiddlyElement(document.body,elem || "ol","popup",className || "popup");
popup.stackPosition = stackPosition;
Popup.stack.push({root: root, popup: popup});
return popup;
};
Popup.onDocumentClick = function(ev)
{
var e = ev || window.event;
if(e.eventPhase == undefined)
Popup.remove();
else if(e.eventPhase == Event.BUBBLING_PHASE || e.eventPhase == Event.AT_TARGET)
Popup.remove();
return true;
};
Popup.show = function(valign,halign,offset)
{
var curr = Popup.stack[Popup.stack.length-1];
this.place(curr.root,curr.popup,valign,halign,offset);
addClass(curr.root,"highlight");
if(config.options.chkAnimate && anim && typeof Scroller == "function")
anim.startAnimating(new Scroller(curr.popup));
else
window.scrollTo(0,ensureVisible(curr.popup));
};
Popup.place = function(root,popup,valign,halign,offset)
{
if(!offset)
var offset = {x:0,y:0};
if(popup.stackPosition >= 0 && !valign && !halign) {
offset.x = offset.x + root.offsetWidth;
} else {
offset.x = (halign == "right") ? offset.x + root.offsetWidth : offset.x;
offset.y = (valign == "top") ? offset.y : offset.y + root.offsetHeight;
}
var rootLeft = findPosX(root);
var rootTop = findPosY(root);
var popupLeft = rootLeft + offset.x;
var popupTop = rootTop + offset.y;
var winWidth = findWindowWidth();
if(popup.offsetWidth > winWidth*0.75)
popup.style.width = winWidth*0.75 + "px";
var popupWidth = popup.offsetWidth;
var scrollWidth = winWidth - document.body.offsetWidth;
if(popupLeft + popupWidth > winWidth - scrollWidth - 1) {
if(halign == "right")
popupLeft = popupLeft - root.offsetWidth - popupWidth;
else
popupLeft = winWidth - popupWidth - scrollWidth - 1;
}
popup.style.left = popupLeft + "px";
popup.style.top = popupTop + "px";
popup.style.display = "block";
};
Popup.find = function(e)
{
var pos = -1;
for (var t=this.stack.length-1; t>=0; t--) {
if(isDescendant(e,this.stack[t].popup))
pos = t;
}
return pos;
};
Popup.remove = function(pos)
{
if(!pos) var pos = 0;
if(Popup.stack.length > pos) {
Popup.removeFrom(pos);
}
};
Popup.removeFrom = function(from)
{
for(var t=Popup.stack.length-1; t>=from; t--) {
var p = Popup.stack[t];
removeClass(p.root,"highlight");
removeNode(p.popup);
}
Popup.stack = Popup.stack.slice(0,from);
};
//--
//-- Wizard support
//--
function Wizard(elem)
{
if(elem) {
this.formElem = findRelated(elem,"wizard","className");
this.bodyElem = findRelated(this.formElem.firstChild,"wizardBody","className","nextSibling");
this.footElem = findRelated(this.formElem.firstChild,"wizardFooter","className","nextSibling");
} else {
this.formElem = null;
this.bodyElem = null;
this.footElem = null;
}
}
Wizard.prototype.setValue = function(name,value)
{
if(this.formElem)
this.formElem[name] = value;
};
Wizard.prototype.getValue = function(name)
{
return this.formElem ? this.formElem[name] : null;
};
Wizard.prototype.createWizard = function(place,title)
{
this.formElem = createTiddlyElement(place,"form",null,"wizard");
createTiddlyElement(this.formElem,"h1",null,null,title);
this.bodyElem = createTiddlyElement(this.formElem,"div",null,"wizardBody");
this.footElem = createTiddlyElement(this.formElem,"div",null,"wizardFooter");
};
Wizard.prototype.clear = function()
{
removeChildren(this.bodyElem);
};
Wizard.prototype.setButtons = function(buttonInfo,status)
{
removeChildren(this.footElem);
for(var t=0; t<buttonInfo.length; t++) {
createTiddlyButton(this.footElem,buttonInfo[t].caption,buttonInfo[t].tooltip,buttonInfo[t].onClick);
insertSpacer(this.footElem);
}
if(typeof status == "string") {
createTiddlyElement(this.footElem,"span",null,"status",status);
}
};
Wizard.prototype.addStep = function(stepTitle,html)
{
removeChildren(this.bodyElem);
var w = createTiddlyElement(this.bodyElem,"div");
createTiddlyElement(w,"h2",null,null,stepTitle);
var step = createTiddlyElement(w,"div",null,"wizardStep");
step.innerHTML = html;
applyHtmlMacros(step,tiddler);
};
Wizard.prototype.getElement = function(name)
{
return this.formElem.elements[name];
};
//--
//-- ListView gadget
//--
var ListView = {};
// Create a listview
ListView.create = function(place,listObject,listTemplate,callback,className)
{
var table = createTiddlyElement(place,"table",null,className || "listView twtable");
var thead = createTiddlyElement(table,"thead");
var r = createTiddlyElement(thead,"tr");
for(var t=0; t<listTemplate.columns.length; t++) {
var columnTemplate = listTemplate.columns[t];
var c = createTiddlyElement(r,"th");
var colType = ListView.columnTypes[columnTemplate.type];
if(colType && colType.createHeader) {
colType.createHeader(c,columnTemplate,t);
if(columnTemplate.className)
addClass(c,columnTemplate.className);
}
}
var tbody = createTiddlyElement(table,"tbody");
for(var rc=0; rc<listObject.length; rc++) {
var rowObject = listObject[rc];
r = createTiddlyElement(tbody,"tr");
for(c=0; c<listTemplate.rowClasses.length; c++) {
if(rowObject[listTemplate.rowClasses[c].field])
addClass(r,listTemplate.rowClasses[c].className);
}
rowObject.rowElement = r;
rowObject.colElements = {};
for(var cc=0; cc<listTemplate.columns.length; cc++) {
c = createTiddlyElement(r,"td");
columnTemplate = listTemplate.columns[cc];
var field = columnTemplate.field;
colType = ListView.columnTypes[columnTemplate.type];
if(colType && colType.createItem) {
colType.createItem(c,rowObject,field,columnTemplate,cc,rc);
if(columnTemplate.className)
addClass(c,columnTemplate.className);
}
rowObject.colElements[field] = c;
}
}
if(callback && listTemplate.actions)
createTiddlyDropDown(place,ListView.getCommandHandler(callback),listTemplate.actions);
if(callback && listTemplate.buttons) {
for(t=0; t<listTemplate.buttons.length; t++) {
var a = listTemplate.buttons[t];
if(a && a.name != "")
createTiddlyButton(place,a.caption,null,ListView.getCommandHandler(callback,a.name,a.allowEmptySelection));
}
}
return table;
};
ListView.getCommandHandler = function(callback,name,allowEmptySelection)
{
return function(e) {
var view = findRelated(this,"TABLE",null,"previousSibling");
var tiddlers = [];
ListView.forEachSelector(view,function(e,rowName) {
if(e.checked)
tiddlers.push(rowName);
});
if(tiddlers.length == 0 && !allowEmptySelection) {
alert(config.messages.nothingSelected);
} else {
if(this.nodeName.toLowerCase() == "select") {
callback(view,this.value,tiddlers);
this.selectedIndex = 0;
} else {
callback(view,name,tiddlers);
}
}
};
};
// Invoke a callback for each selector checkbox in the listview
ListView.forEachSelector = function(view,callback)
{
var checkboxes = view.getElementsByTagName("input");
var hadOne = false;
for(var t=0; t<checkboxes.length; t++) {
var cb = checkboxes[t];
if(cb.getAttribute("type") == "checkbox") {
var rn = cb.getAttribute("rowName");
if(rn) {
callback(cb,rn);
hadOne = true;
}
}
}
return hadOne;
};
ListView.getSelectedRows = function(view)
{
var rowNames = [];
ListView.forEachSelector(view,function(e,rowName) {
if(e.checked)
rowNames.push(rowName);
});
return rowNames;
};
ListView.columnTypes = {};
ListView.columnTypes.String = {
createHeader: function(place,columnTemplate,col)
{
createTiddlyText(place,columnTemplate.title);
},
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined)
createTiddlyText(place,v);
}
};
ListView.columnTypes.WikiText = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined)
wikify(v,place,null,null);
}
};
ListView.columnTypes.Tiddler = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined && v.title)
createTiddlyPopup(place,v.title,config.messages.listView.tiddlerTooltip,v);
}
};
ListView.columnTypes.Size = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var msg = config.messages.sizeTemplates;
var v = listObject[field];
if(v != undefined) {
var t = 0;
while(t<msg.length-1 && v<msg[t].unit)
t++;
createTiddlyText(place,msg[t].template.format([Math.round(v/msg[t].unit)]));
}
}
};
ListView.columnTypes.Link = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
var c = columnTemplate.text;
if(v != undefined)
createExternalLink(place,v,c || v);
}
};
ListView.columnTypes.Date = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined)
createTiddlyText(place,v.formatString(columnTemplate.dateFormat));
}
};
ListView.columnTypes.StringList = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined) {
for(var t=0; t<v.length; t++) {
createTiddlyText(place,v[t]);
createTiddlyElement(place,"br");
}
}
}
};
ListView.columnTypes.Selector = {
createHeader: function(place,columnTemplate,col)
{
createTiddlyCheckbox(place,null,false,this.onHeaderChange);
},
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var e = createTiddlyCheckbox(place,null,listObject[field],null);
e.setAttribute("rowName",listObject[columnTemplate.rowName]);
},
onHeaderChange: function(e)
{
var state = this.checked;
var view = findRelated(this,"TABLE");
if(!view)
return;
ListView.forEachSelector(view,function(e,rowName) {
e.checked = state;
});
}
};
ListView.columnTypes.Tags = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var tags = listObject[field];
createTiddlyText(place,String.encodeTiddlyLinkList(tags));
}
};
ListView.columnTypes.Boolean = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
if(listObject[field] == true)
createTiddlyText(place,columnTemplate.trueText);
if(listObject[field] == false)
createTiddlyText(place,columnTemplate.falseText);
}
};
ListView.columnTypes.TagCheckbox = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var e = createTiddlyCheckbox(place,null,listObject[field],this.onChange);
e.setAttribute("tiddler",listObject.title);
e.setAttribute("tag",columnTemplate.tag);
},
onChange : function(e)
{
var tag = this.getAttribute("tag");
var tiddler = this.getAttribute("tiddler");
store.setTiddlerTag(tiddler,this.checked,tag);
}
};
ListView.columnTypes.TiddlerLink = {
createHeader: ListView.columnTypes.String.createHeader,
createItem: function(place,listObject,field,columnTemplate,col,row)
{
var v = listObject[field];
if(v != undefined) {
var link = createTiddlyLink(place,listObject[columnTemplate.tiddlerLink],false,null);
createTiddlyText(link,listObject[field]);
}
}
};
//--
//-- Augmented methods for the JavaScript Number(), Array(), String() and Date() objects
//--
// Clamp a number to a range
Number.prototype.clamp = function(min,max)
{
var c = this;
if(c < min)
c = min;
if(c > max)
c = max;
return Number(c);
};
// Add indexOf function if browser does not support it
if(!Array.indexOf) {
Array.prototype.indexOf = function(item,from)
{
if(!from)
from = 0;
for(var i=from; i<this.length; i++) {
if(this[i] === item)
return i;
}
return -1;
};}
// Find an entry in a given field of the members of an array
Array.prototype.findByField = function(field,value)
{
for(var t=0; t<this.length; t++) {
if(this[t][field] === value)
return t;
}
return null;
};
// Return whether an entry exists in an array
Array.prototype.contains = function(item)
{
return this.indexOf(item) != -1;
};
// Adds, removes or toggles a particular value within an array
// value - value to add
// mode - +1 to add value, -1 to remove value, 0 to toggle it
Array.prototype.setItem = function(value,mode)
{
var p = this.indexOf(value);
if(mode == 0)
mode = (p == -1) ? +1 : -1;
if(mode == +1) {
if(p == -1)
this.push(value);
} else if(mode == -1) {
if(p != -1)
this.splice(p,1);
}
};
// Return whether one of a list of values exists in an array
Array.prototype.containsAny = function(items)
{
for(var i=0; i<items.length; i++) {
if(this.indexOf(items[i]) != -1)
return true;
}
return false;
};
// Return whether all of a list of values exists in an array
Array.prototype.containsAll = function(items)
{
for(var i = 0; i<items.length; i++) {
if(this.indexOf(items[i]) == -1)
return false;
}
return true;
};
// Push a new value into an array only if it is not already present in the array. If the optional unique parameter is false, it reverts to a normal push
Array.prototype.pushUnique = function(item,unique)
{
if(unique === false) {
this.push(item);
} else {
if(this.indexOf(item) == -1)
this.push(item);
}
};
Array.prototype.remove = function(item)
{
var p = this.indexOf(item);
if(p != -1)
this.splice(p,1);
};
if(!Array.prototype.map) {
Array.prototype.map = function(fn,thisObj)
{
var scope = thisObj || window;
var a = [];
for(var i=0, j=this.length; i < j; ++i) {
a.push(fn.call(scope,this[i],i,this));
}
return a;
};}
// Get characters from the right end of a string
String.prototype.right = function(n)
{
return n < this.length ? this.slice(this.length-n) : this;
};
// Trim whitespace from both ends of a string
String.prototype.trim = function()
{
return this.replace(/^\s*|\s*$/g,"");
};
// Convert a string from a CSS style property name to a JavaScript style name ("background-color" -> "backgroundColor")
String.prototype.unDash = function()
{
var s = this.split("-");
if(s.length > 1) {
for(var t=1; t<s.length; t++)
s[t] = s[t].substr(0,1).toUpperCase() + s[t].substr(1);
}
return s.join("");
};
// Substitute substrings from an array into a format string that includes '%1'-type specifiers
String.prototype.format = function(s)
{
var substrings = s && s.constructor == Array ? s : arguments;
var subRegExp = /(?:%(\d+))/mg;
var currPos = 0;
var r = [];
do {
var match = subRegExp.exec(this);
if(match && match[1]) {
if(match.index > currPos)
r.push(this.substring(currPos,match.index));
r.push(substrings[parseInt(match[1])]);
currPos = subRegExp.lastIndex;
}
} while(match);
if(currPos < this.length)
r.push(this.substring(currPos,this.length));
return r.join("");
};
// Escape any special RegExp characters with that character preceded by a backslash
String.prototype.escapeRegExp = function()
{
var s = "\\^$*+?()=!|,{}[].";
var c = this;
for(var t=0; t<s.length; t++)
c = c.replace(new RegExp("\\" + s.substr(t,1),"g"),"\\" + s.substr(t,1));
return c;
};
// Convert "\" to "\s", newlines to "\n" (and remove carriage returns)
String.prototype.escapeLineBreaks = function()
{
return this.replace(/\\/mg,"\\s").replace(/\n/mg,"\\n").replace(/\r/mg,"");
};
// Convert "\n" to newlines, "\b" to " ", "\s" to "\" (and remove carriage returns)
String.prototype.unescapeLineBreaks = function()
{
return this.replace(/\\n/mg,"\n").replace(/\\b/mg," ").replace(/\\s/mg,"\\").replace(/\r/mg,"");
};
// Convert & to "&amp;", < to "&lt;", > to "&gt;" and " to "&quot;"
String.prototype.htmlEncode = function()
{
return this.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
};
// Convert "&amp;" to &, "&lt;" to <, "&gt;" to > and "&quot;" to "
String.prototype.htmlDecode = function()
{
return this.replace(/&lt;/mg,"<").replace(/&gt;/mg,">").replace(/&quot;/mg,"\"").replace(/&amp;/mg,"&");
};
// Parse a space-separated string of name:value parameters
// The result is an array of objects:
// result[0] = object with a member for each parameter name, value of that member being an array of values
// result[1..n] = one object for each parameter, with 'name' and 'value' members
String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults)
{
var parseToken = function(match,p) {
var n;
if(match[p]) // Double quoted
n = match[p];
else if(match[p+1]) // Single quoted
n = match[p+1];
else if(match[p+2]) // Double-square-bracket quoted
n = match[p+2];
else if(match[p+3]) // Double-brace quoted
try {
n = match[p+3];
if(allowEval)
n = window.eval(n);
} catch(ex) {
throw "Unable to evaluate {{" + match[p+3] + "}}: " + exceptionText(ex);
}
else if(match[p+4]) // Unquoted
n = match[p+4];
else if(match[p+5]) // empty quote
n = "";
return n;
};
var r = [{}];
var dblQuote = "(?:\"((?:(?:\\\\\")|[^\"])+)\")";
var sngQuote = "(?:'((?:(?:\\\\\')|[^'])+)')";
var dblSquare = "(?:\\[\\[((?:\\s|\\S)*?)\\]\\])";
var dblBrace = "(?:\\{\\{((?:\\s|\\S)*?)\\}\\})";
var unQuoted = noNames ? "([^\"'\\s]\\S*)" : "([^\"':\\s][^\\s:]*)";
var emptyQuote = "((?:\"\")|(?:''))";
var skipSpace = "(?:\\s*)";
var token = "(?:" + dblQuote + "|" + sngQuote + "|" + dblSquare + "|" + dblBrace + "|" + unQuoted + "|" + emptyQuote + ")";
var re = noNames ? new RegExp(token,"mg") : new RegExp(skipSpace + token + skipSpace + "(?:(\\:)" + skipSpace + token + ")?","mg");
var params = [];
do {
var match = re.exec(this);
if(match) {
var n = parseToken(match,1);
if(noNames) {
r.push({name:"",value:n});
} else {
var v = parseToken(match,8);
if(v == null && defaultName) {
v = n;
n = defaultName;
} else if(v == null && defaultValue) {
v = defaultValue;
}
r.push({name:n,value:v});
if(cascadeDefaults) {
defaultName = n;
defaultValue = v;
}
}
}
} while(match);
// Summarise parameters into first element
for(var t=1; t<r.length; t++) {
if(r[0][r[t].name])
r[0][r[t].name].push(r[t].value);
else
r[0][r[t].name] = [r[t].value];
}
return r;
};
// Process a string list of macro parameters into an array. Parameters can be quoted with "", '',
// [[]], {{ }} or left unquoted (and therefore space-separated). Double-braces {{}} results in
// an *evaluated* parameter: e.g. {{config.options.txtUserName}} results in the current user's name.
String.prototype.readMacroParams = function()
{
var p = this.parseParams("list",null,true,true);
var n = [];
for(var t=1; t<p.length; t++)
n.push(p[t].value);
return n;
};
// Process a string list of unique tiddler names into an array. Tiddler names that have spaces in them must be [[bracketed]]
String.prototype.readBracketedList = function(unique)
{
var p = this.parseParams("list",null,false,true);
var n = [];
for(var t=1; t<p.length; t++) {
if(p[t].value)
n.pushUnique(p[t].value,unique);
}
return n;
};
// Returns array with start and end index of chunk between given start and end marker, or undefined.
String.prototype.getChunkRange = function(start,end)
{
var s = this.indexOf(start);
if(s != -1) {
s += start.length;
var e = this.indexOf(end,s);
if(e != -1)
return [s,e];
}
};
// Replace a chunk of a string given start and end markers
String.prototype.replaceChunk = function(start,end,sub)
{
var r = this.getChunkRange(start,end);
return r ? this.substring(0,r[0]) + sub + this.substring(r[1]) : this;
};
// Returns a chunk of a string between start and end markers, or undefined
String.prototype.getChunk = function(start,end)
{
var r = this.getChunkRange(start,end);
if(r)
return this.substring(r[0],r[1]);
};
// Static method to bracket a string with double square brackets if it contains a space
String.encodeTiddlyLink = function(title)
{
return title.indexOf(" ") == -1 ? title : "[[" + title + "]]";
};
// Static method to encodeTiddlyLink for every item in an array and join them with spaces
String.encodeTiddlyLinkList = function(list)
{
if(list) {
var results = [];
for(var t=0; t<list.length; t++)
results.push(String.encodeTiddlyLink(list[t]));
return results.join(" ");
} else {
return "";
}
};
// Convert a string as a sequence of name:"value" pairs into a hashmap
String.prototype.decodeHashMap = function()
{
var fields = this.parseParams("anon","",false);
var r = {};
for(var t=1; t<fields.length; t++)
r[fields[t].name] = fields[t].value;
return r;
};
// Static method to encode a hashmap into a name:"value"... string
String.encodeHashMap = function(hashmap)
{
var r = [];
for(var t in hashmap)
r.push(t + ':"' + hashmap[t] + '"');
return r.join(" ");
};
// Static method to left-pad a string with 0s to a certain width
String.zeroPad = function(n,d)
{
var s = n.toString();
if(s.length < d)
s = "000000000000000000000000000".substr(0,d-s.length) + s;
return s;
};
String.prototype.startsWith = function(prefix)
{
return !prefix || this.substring(0,prefix.length) == prefix;
};
// Returns the first value of the given named parameter.
function getParam(params,name,defaultValue)
{
if(!params)
return defaultValue;
var p = params[0][name];
return p ? p[0] : defaultValue;
}
// Returns the first value of the given boolean named parameter.
function getFlag(params,name,defaultValue)
{
return !!getParam(params,name,defaultValue);
}
// Substitute date components into a string
Date.prototype.formatString = function(template)
{
var t = template.replace(/0hh12/g,String.zeroPad(this.getHours12(),2));
t = t.replace(/hh12/g,this.getHours12());
t = t.replace(/0hh/g,String.zeroPad(this.getHours(),2));
t = t.replace(/hh/g,this.getHours());
t = t.replace(/mmm/g,config.messages.dates.shortMonths[this.getMonth()]);
t = t.replace(/0mm/g,String.zeroPad(this.getMinutes(),2));
t = t.replace(/mm/g,this.getMinutes());
t = t.replace(/0ss/g,String.zeroPad(this.getSeconds(),2));
t = t.replace(/ss/g,this.getSeconds());
t = t.replace(/[ap]m/g,this.getAmPm().toLowerCase());
t = t.replace(/[AP]M/g,this.getAmPm().toUpperCase());
t = t.replace(/wYYYY/g,this.getYearForWeekNo());
t = t.replace(/wYY/g,String.zeroPad(this.getYearForWeekNo()-2000,2));
t = t.replace(/YYYY/g,this.getFullYear());
t = t.replace(/YY/g,String.zeroPad(this.getFullYear()-2000,2));
t = t.replace(/MMM/g,config.messages.dates.months[this.getMonth()]);
t = t.replace(/0MM/g,String.zeroPad(this.getMonth()+1,2));
t = t.replace(/MM/g,this.getMonth()+1);
t = t.replace(/0WW/g,String.zeroPad(this.getWeek(),2));
t = t.replace(/WW/g,this.getWeek());
t = t.replace(/DDD/g,config.messages.dates.days[this.getDay()]);
t = t.replace(/ddd/g,config.messages.dates.shortDays[this.getDay()]);
t = t.replace(/0DD/g,String.zeroPad(this.getDate(),2));
t = t.replace(/DDth/g,this.getDate()+this.daySuffix());
t = t.replace(/DD/g,this.getDate());
var tz = this.getTimezoneOffset();
var atz = Math.abs(tz);
t = t.replace(/TZD/g,(tz < 0 ? '+' : '-') + String.zeroPad(Math.floor(atz / 60),2) + ':' + String.zeroPad(atz % 60,2));
t = t.replace(/\\/g,"");
return t;
};
Date.prototype.getWeek = function()
{
var dt = new Date(this.getTime());
var d = dt.getDay();
if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo
var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
return Math.floor(n/7)+1;
};
Date.prototype.getYearForWeekNo = function()
{
var dt = new Date(this.getTime());
var d = dt.getDay();
if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
return dt.getFullYear();
};
Date.prototype.getHours12 = function()
{
var h = this.getHours();
return h > 12 ? h-12 : ( h > 0 ? h : 12 );
};
Date.prototype.getAmPm = function()
{
return this.getHours() >= 12 ? config.messages.dates.pm : config.messages.dates.am;
};
Date.prototype.daySuffix = function()
{
return config.messages.dates.daySuffixes[this.getDate()-1];
};
// Convert a date to local YYYYMMDDHHMM string format
Date.prototype.convertToLocalYYYYMMDDHHMM = function()
{
return this.getFullYear() + String.zeroPad(this.getMonth()+1,2) + String.zeroPad(this.getDate(),2) + String.zeroPad(this.getHours(),2) + String.zeroPad(this.getMinutes(),2);
};
// Convert a date to UTC YYYYMMDDHHMM string format
Date.prototype.convertToYYYYMMDDHHMM = function()
{
return this.getUTCFullYear() + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2);
};
// Convert a date to UTC YYYYMMDD.HHMMSSMMM string format
Date.prototype.convertToYYYYMMDDHHMMSSMMM = function()
{
return this.getUTCFullYear() + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + "." + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2) + String.zeroPad(this.getUTCSeconds(),2) + String.zeroPad(this.getUTCMilliseconds(),3) +"0";
};
// Static method to create a date from a UTC YYYYMMDDHHMM format string
Date.convertFromYYYYMMDDHHMM = function(d)
{
d = d?d.replace(/[^0-9]/g, ""):"";
return Date.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,12));
};
// Static method to create a date from a UTC YYYYMMDDHHMMSS format string
Date.convertFromYYYYMMDDHHMMSS = function(d)
{
d = d?d.replace(/[^0-9]/g, ""):"";
return Date.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,14));
};
// Static method to create a date from a UTC YYYYMMDDHHMMSSMMM format string
Date.convertFromYYYYMMDDHHMMSSMMM = function(d)
{
d = d ? d.replace(/[^0-9]/g, "") : "";
return new Date(Date.UTC(parseInt(d.substr(0,4),10),
parseInt(d.substr(4,2),10)-1,
parseInt(d.substr(6,2),10),
parseInt(d.substr(8,2)||"00",10),
parseInt(d.substr(10,2)||"00",10),
parseInt(d.substr(12,2)||"00",10),
parseInt(d.substr(14,3)||"000",10)));
};
//--
//-- RGB colour object
//--
// Construct an RGB colour object from a '#rrggbb', '#rgb' or 'rgb(n,n,n)' string or from separate r,g,b values
function RGB(r,g,b)
{
this.r = 0;
this.g = 0;
this.b = 0;
if(typeof r == "string") {
if(r.substr(0,1) == "#") {
if(r.length == 7) {
this.r = parseInt(r.substr(1,2),16)/255;
this.g = parseInt(r.substr(3,2),16)/255;
this.b = parseInt(r.substr(5,2),16)/255;
} else {
this.r = parseInt(r.substr(1,1),16)/15;
this.g = parseInt(r.substr(2,1),16)/15;
this.b = parseInt(r.substr(3,1),16)/15;
}
} else {
var rgbPattern = /rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/;
var c = r.match(rgbPattern);
if(c) {
this.r = parseInt(c[1],10)/255;
this.g = parseInt(c[2],10)/255;
this.b = parseInt(c[3],10)/255;
}
}
} else {
this.r = r;
this.g = g;
this.b = b;
}
return this;
}
// Mixes this colour with another in a specified proportion
// c = other colour to mix
// f = 0..1 where 0 is this colour and 1 is the new colour
// Returns an RGB object
RGB.prototype.mix = function(c,f)
{
return new RGB(this.r + (c.r-this.r) * f,this.g + (c.g-this.g) * f,this.b + (c.b-this.b) * f);
};
// Return an rgb colour as a #rrggbb format hex string
RGB.prototype.toString = function()
{
return "#" + ("0" + Math.floor(this.r.clamp(0,1) * 255).toString(16)).right(2) +
("0" + Math.floor(this.g.clamp(0,1) * 255).toString(16)).right(2) +
("0" + Math.floor(this.b.clamp(0,1) * 255).toString(16)).right(2);
};
//--
//-- DOM utilities - many derived from www.quirksmode.org
//--
// Resolve the target object of an event
function resolveTarget(e)
{
var obj;
if(e.target)
obj = e.target;
else if(e.srcElement)
obj = e.srcElement;
if(obj.nodeType == 3) // defeat Safari bug
obj = obj.parentNode;
return obj;
}
function drawGradient(place,horiz,locolors,hicolors)
{
if(!hicolors)
hicolors = locolors;
for(var t=0; t<= 100; t+=2) {
var bar = document.createElement("div");
place.appendChild(bar);
bar.style.position = "absolute";
bar.style.left = horiz ? t + "%" : 0;
bar.style.top = horiz ? 0 : t + "%";
bar.style.width = horiz ? (101-t) + "%" : "100%";
bar.style.height = horiz ? "100%" : (101-t) + "%";
bar.style.zIndex = -1;
var p = t/100*(locolors.length-1);
var hc = hicolors[Math.floor(p)];
if(typeof hc == "string")
hc = new RGB(hc);
var lc = locolors[Math.ceil(p)];
if(typeof lc == "string")
lc = new RGB(lc);
bar.style.backgroundColor = hc.mix(lc,p-Math.floor(p)).toString();
}
}
function createTiddlyText(parent,text)
{
return parent.appendChild(document.createTextNode(text));
}
function createTiddlyCheckbox(parent,caption,checked,onChange)
{
var cb = document.createElement("input");
cb.setAttribute("type","checkbox");
cb.onclick = onChange;
parent.appendChild(cb);
cb.checked = checked;
cb.className = "chkOptionInput";
if(caption)
wikify(caption,parent);
return cb;
}
function createTiddlyElement(parent,element,id,className,text,attribs)
{
var e = document.createElement(element);
if(className != null)
e.className = className;
if(id != null)
e.setAttribute("id",id);
if(text != null)
e.appendChild(document.createTextNode(text));
if(attribs) {
for(var n in attribs) {
e.setAttribute(n,attribs[n]);
}
}
if(parent != null)
parent.appendChild(e);
return e;
}
function addEvent(obj,type,fn)
{
if(obj.attachEvent) {
obj["e"+type+fn] = fn;
obj[type+fn] = function(){obj["e"+type+fn](window.event);};
obj.attachEvent("on"+type,obj[type+fn]);
} else {
obj.addEventListener(type,fn,false);
}
}
function removeEvent(obj,type,fn)
{
if(obj.detachEvent) {
obj.detachEvent("on"+type,obj[type+fn]);
obj[type+fn] = null;
} else {
obj.removeEventListener(type,fn,false);
}
}
// Find the closest relative with a given property value (property defaults to tagName, relative defaults to parentNode)
function findRelated(e,value,name,relative)
{
name = name || "tagName";
relative = relative || "parentNode";
if(name == "className") {
while(e && !hasClass(e,value)) {
e = e[relative];
}
} else {
while(e && e[name] != value) {
e = e[relative];
}
}
return e;
}
// Get the scroll position for window.scrollTo necessary to scroll a given element into view
function ensureVisible(e)
{
var posTop = findPosY(e);
var posBot = posTop + e.offsetHeight;
var winTop = findScrollY();
var winHeight = findWindowHeight();
var winBot = winTop + winHeight;
if(posTop < winTop) {
return posTop;
} else if(posBot > winBot) {
if(e.offsetHeight < winHeight)
return posTop - (winHeight - e.offsetHeight);
else
return posTop;
} else {
return winTop;
}
}
// Get the current width of the display window
function findWindowWidth()
{
return window.innerWidth || document.documentElement.clientWidth;
}
// Get the current height of the display window
function findWindowHeight()
{
return window.innerHeight || document.documentElement.clientHeight;
}
// Get the current horizontal page scroll position
function findScrollX()
{
return window.scrollX || document.documentElement.scrollLeft;
}
// Get the current vertical page scroll position
function findScrollY()
{
return window.scrollY || document.documentElement.scrollTop;
}
function findPosX(obj)
{
var curleft = 0;
while(obj.offsetParent) {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
return curleft;
}
function findPosY(obj)
{
var curtop = 0;
while(obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
return curtop;
}
// Blur a particular element
function blurElement(e)
{
if(e && e.focus && e.blur) {
e.focus();
e.blur();
}
}
// Create a non-breaking space
function insertSpacer(place)
{
var e = document.createTextNode(String.fromCharCode(160));
if(place)
place.appendChild(e);
return e;
}
// Force the browser to do a document reflow when needed to workaround browser bugs
function forceReflow()
{
if(config.browser.isGecko) {
setStylesheet("body {top:0px;margin-top:0px;}","forceReflow");
setTimeout(function() {setStylesheet("","forceReflow");},1);
}
}
// Replace the current selection of a textarea or text input and scroll it into view
function replaceSelection(e,text)
{
if(e.setSelectionRange) {
var oldpos = e.selectionStart;
var isRange = e.selectionEnd > e.selectionStart;
e.value = e.value.substr(0,e.selectionStart) + text + e.value.substr(e.selectionEnd);
e.setSelectionRange(isRange ? oldpos : oldpos + text.length,oldpos + text.length);
var linecount = e.value.split("\n").length;
var thisline = e.value.substr(0,e.selectionStart).split("\n").length-1;
e.scrollTop = Math.floor((thisline - e.rows / 2) * e.scrollHeight / linecount);
} else if(document.selection) {
var range = document.selection.createRange();
if(range.parentElement() == e) {
var isCollapsed = range.text == "";
range.text = text;
if(!isCollapsed) {
range.moveStart("character", -text.length);
range.select();
}
}
}
}
// Returns the text of the given (text) node, possibly merging subsequent text nodes
function getNodeText(e)
{
var t = "";
while(e && e.nodeName == "#text") {
t += e.nodeValue;
e = e.nextSibling;
}
return t;
}
// Returns true if the element e has a given ancestor element
function isDescendant(e,ancestor)
{
while(e) {
if(e === ancestor)
return true;
e = e.parentNode;
}
return false;
}
// deprecate the following...
// Prevent an event from bubbling
function stopEvent(e)
{
var ev = e || window.event;
ev.cancelBubble = true;
if(ev.stopPropagation) ev.stopPropagation();
return false;
}
// Remove any event handlers or non-primitve custom attributes
function scrubNode(e)
{
if(!config.browser.isIE)
return;
var att = e.attributes;
if(att) {
for(var t=0; t<att.length; t++) {
var n = att[t].name;
if(n !== "style" && (typeof e[n] === "function" || (typeof e[n] === "object" && e[n] != null))) {
try {
e[n] = null;
} catch(ex) {
}
}
}
}
var c = e.firstChild;
while(c) {
scrubNode(c);
c = c.nextSibling;
}
}
function addClass(e,className)
{
jQuery(e).addClass(className);
}
function removeClass(e,className)
{
jQuery(e).removeClass(className);
}
function hasClass(e,className)
{
return jQuery(e).hasClass(className);
}
// Remove all children of a node
function removeChildren(e)
{
jQuery(e).empty();
}
// Return the content of an element as plain text with no formatting
function getPlainText(e)
{
return jQuery(e).text();
}
// Remove a node and all it's children
function removeNode(e)
{
jQuery(e).remove();
}
//--
//-- LoaderBase and SaverBase
//--
function LoaderBase() {}
LoaderBase.prototype.loadTiddler = function(store,node,tiddlers)
{
var title = this.getTitle(store,node);
if(safeMode && store.isShadowTiddler(title))
return;
if(title) {
var tiddler = store.createTiddler(title);
this.internalizeTiddler(store,tiddler,title,node);
tiddlers.push(tiddler);
}
};
LoaderBase.prototype.loadTiddlers = function(store,nodes)
{
var tiddlers = [];
for(var t = 0; t < nodes.length; t++) {
try {
this.loadTiddler(store,nodes[t],tiddlers);
} catch(ex) {
showException(ex,config.messages.tiddlerLoadError.format([this.getTitle(store,nodes[t])]));
}
}
return tiddlers;
};
function SaverBase() {}
SaverBase.prototype.externalize = function(store)
{
var results = [];
var tiddlers = store.getTiddlers("title");
for(var t = 0; t < tiddlers.length; t++) {
if(!tiddlers[t].doNotSave())
results.push(this.externalizeTiddler(store, tiddlers[t]));
}
return results.join("\n");
};
//--
//-- TW21Loader (inherits from LoaderBase)
//--
function TW21Loader() {}
TW21Loader.prototype = new LoaderBase();
TW21Loader.prototype.getTitle = function(store,node)
{
var title = null;
if(node.getAttribute) {
title = node.getAttribute("title");
if(!title)
title = node.getAttribute("tiddler");
}
if(!title && node.id) {
var lenPrefix = store.idPrefix.length;
if(node.id.substr(0,lenPrefix) == store.idPrefix)
title = node.id.substr(lenPrefix);
}
return title;
};
TW21Loader.prototype.internalizeTiddler = function(store,tiddler,title,node)
{
var e = node.firstChild;
var text = null;
if(node.getAttribute("tiddler")) {
text = getNodeText(e).unescapeLineBreaks();
} else {
while(e.nodeName!="PRE" && e.nodeName!="pre") {
e = e.nextSibling;
}
text = e.innerHTML.replace(/\r/mg,"").htmlDecode();
}
var creator = node.getAttribute("creator");
var modifier = node.getAttribute("modifier");
var c = node.getAttribute("created");
var m = node.getAttribute("modified");
var created = c ? Date.convertFromYYYYMMDDHHMMSS(c) : version.date;
var modified = m ? Date.convertFromYYYYMMDDHHMMSS(m) : created;
var tags = node.getAttribute("tags");
var fields = {};
var attrs = node.attributes;
for(var i = attrs.length-1; i >= 0; i--) {
var name = attrs[i].name;
if(attrs[i].specified && !TiddlyWiki.isStandardField(name)) {
fields[name] = attrs[i].value.unescapeLineBreaks();
}
}
tiddler.assign(title,text,modifier,modified,tags,created,fields,creator);
return tiddler;
};
//--
//-- TW21Saver (inherits from SaverBase)
//--
function TW21Saver() {}
TW21Saver.prototype = new SaverBase();
TW21Saver.prototype.externalizeTiddler = function(store,tiddler)
{
try {
var extendedAttributes = "";
var usePre = config.options.chkUsePreForStorage;
store.forEachField(tiddler,
function(tiddler,fieldName,value) {
// don't store stuff from the temp namespace
if(typeof value != "string")
value = "";
if(!fieldName.match(/^temp\./))
extendedAttributes += ' %0="%1"'.format([fieldName,value.escapeLineBreaks().htmlEncode()]);
},true);
var created = tiddler.created;
var modified = tiddler.modified;
var attributes = tiddler.creator ? ' creator="' + tiddler.creator.htmlEncode() + '"' : "";
attributes += tiddler.modifier ? ' modifier="' + tiddler.modifier.htmlEncode() + '"' : "";
attributes += (usePre && created == version.date) ? "" :' created="' + created.convertToYYYYMMDDHHMM() + '"';
attributes += (usePre && modified == created) ? "" : ' modified="' + modified.convertToYYYYMMDDHHMM() +'"';
var tags = tiddler.getTags();
if(!usePre || tags)
attributes += ' tags="' + tags.htmlEncode() + '"';
return ('<div %0="%1"%2%3>%4</'+'div>').format([
usePre ? "title" : "tiddler",
tiddler.title.htmlEncode(),
attributes,
extendedAttributes,
usePre ? "\n<pre>" + tiddler.text.htmlEncode() + "</pre>\n" : tiddler.text.escapeLineBreaks().htmlEncode()
]);
} catch (ex) {
throw exceptionText(ex,config.messages.tiddlerSaveError.format([tiddler.title]));
}
};
//]]>
</script>
<script id="jsdeprecatedArea" type="text/javascript">
//<![CDATA[
//--
//-- Deprecated Crypto functions and associated conversion routines.
//-- Use the jQuery.encoding functions directly instead.
//--
// Crypto 'namespace'
function Crypto() {}
// Convert a string to an array of big-endian 32-bit words
Crypto.strToBe32s = function(str)
{
return jQuery.encoding.strToBe32s(str);
};
// Convert an array of big-endian 32-bit words to a string
Crypto.be32sToStr = function(be)
{
return jQuery.encoding.be32sToStr(be);
};
// Convert an array of big-endian 32-bit words to a hex string
Crypto.be32sToHex = function(be)
{
return jQuery.encoding.be32sToHex(be);
};
// Return, in hex, the SHA-1 hash of a string
Crypto.hexSha1Str = function(str)
{
return jQuery.encoding.digests.hexSha1Str(str);
};
// Return the SHA-1 hash of a string
Crypto.sha1Str = function(str)
{
return jQuery.encoding.digests.sha1Str(str);
};
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
Crypto.sha1 = function(x,blen)
{
return jQuery.encoding.digests.sha1(x,blen);
};
//--
//-- Deprecated DOM utilities
//--
// @Deprecated: Use jQuery.stylesheet instead
function setStylesheet(s,id,doc)
{
jQuery.twStylesheet(s,{ id: id, doc: doc });
}
// @Deprecated: Use jQuery.stylesheet.remove instead
function removeStyleSheet(id)
{
jQuery.twStylesheet.remove({ id: id });
}
//--
//-- Deprecated HTTP request code
//-- Use the jQuery ajax functions directly instead
//--
function loadRemoteFile(url,callback,params)
{
return httpReq("GET",url,callback,params);
}
function doHttp(type,url,data,contentType,username,password,callback,params,headers,allowCache)
{
return httpReq(type,url,callback,params,headers,data,contentType,username,password,allowCache);
}
function httpReq(type,url,callback,params,headers,data,contentType,username,password,allowCache)
{
var options = {
type:type,
url:url,
processData:false,
data:data,
cache:!!allowCache,
beforeSend: function(xhr) {
for(var i in headers)
xhr.setRequestHeader(i,headers[i]);
xhr.setRequestHeader("X-Requested-With", "TiddlyWiki " + formatVersion());
}
};
if(callback) {
options.complete = function(xhr,textStatus) {
if(jQuery.httpSuccess(xhr))
callback(true,params,xhr.responseText,url,xhr);
else
callback(false,params,null,url,xhr);
};
}
if(contentType)
options.contentType = contentType;
if(username)
options.username = username;
if(password)
options.password = password;
if(window.Components && window.netscape && window.netscape.security && document.location.protocol.indexOf("http") == -1)
window.netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
return jQuery.ajax(options);
}
//--
//-- Deprecated String functions
//--
// @Deprecated: no direct replacement, since not used in core code
String.prototype.toJSONString = function()
{
// Convert a string to it's JSON representation by encoding control characters, double quotes and backslash. See json.org
var m = {
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'"' : '\\"',
'\\': '\\\\'
};
var replaceFn = function(a,b) {
var c = m[b];
if(c)
return c;
c = b.charCodeAt();
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
};
if(/["\\\x00-\x1f]/.test(this))
return '"' + this.replace(/([\x00-\x1f\\"])/g,replaceFn) + '"';
return '"' + this + '"';
};
//--
//-- Deprecated Tiddler code
//--
// @Deprecated: Use tiddlerToRssItem(tiddler,uri) instead
Tiddler.prototype.toRssItem = function(uri)
{
return tiddlerToRssItem(this,uri);
};
// @Deprecated: Use "<item>\n" + tiddlerToRssItem(tiddler,uri) + "\n</item>" instead
Tiddler.prototype.saveToRss = function(uri)
{
return "<item>\n" + tiddlerToRssItem(this,uri) + "\n</item>";
};
// @Deprecated: Use jQuery.encoding.digests.hexSha1Str instead
Tiddler.prototype.generateFingerprint = function()
{
return "0x" + Crypto.hexSha1Str(this.text);
};
//]]>
</script>
<script id="jslibArea" type="text/javascript">
//<![CDATA[
/*!
* jQuery JavaScript Library v1.4.2
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
* http://sizzlejs.com/
* Copyright 2010, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Sat Feb 13 22:33:48 2010 -0500
*/
(function(A,w){function ma(){if(!c.isReady){try{s.documentElement.doScroll("left")}catch(a){setTimeout(ma,1);return}c.ready()}}function Qa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function X(a,b,d,f,e,j){var i=a.length;if(typeof b==="object"){for(var o in b)X(a,o,b[o],f,e,d);return a}if(d!==w){f=!j&&f&&c.isFunction(d);for(o=0;o<i;o++)e(a[o],b,f?d.call(a[o],o,e(a[o],b)):d,j);return a}return i?
e(a[0],b):w}function J(){return(new Date).getTime()}function Y(){return false}function Z(){return true}function na(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function oa(a){var b,d=[],f=[],e=arguments,j,i,o,k,n,r;i=c.data(this,"events");if(!(a.liveFired===this||!i||!i.live||a.button&&a.type==="click")){a.liveFired=this;var u=i.live.slice(0);for(k=0;k<u.length;k++){i=u[k];i.origType.replace(O,"")===a.type?f.push(i.selector):u.splice(k--,1)}j=c(a.target).closest(f,a.currentTarget);n=0;for(r=
j.length;n<r;n++)for(k=0;k<u.length;k++){i=u[k];if(j[n].selector===i.selector){o=j[n].elem;f=null;if(i.preType==="mouseenter"||i.preType==="mouseleave")f=c(a.relatedTarget).closest(i.selector)[0];if(!f||f!==o)d.push({elem:o,handleObj:i})}}n=0;for(r=d.length;n<r;n++){j=d[n];a.currentTarget=j.elem;a.data=j.handleObj.data;a.handleObj=j.handleObj;if(j.handleObj.origHandler.apply(j.elem,e)===false){b=false;break}}return b}}function pa(a,b){return"live."+(a&&a!=="*"?a+".":"")+b.replace(/\./g,"`").replace(/ /g,
"&")}function qa(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function ra(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var f=c.data(a[d++]),e=c.data(this,f);if(f=f&&f.events){delete e.handle;e.events={};for(var j in f)for(var i in f[j])c.event.add(this,j,f[j][i],f[j][i].data)}}})}function sa(a,b,d){var f,e,j;b=b&&b[0]?b[0].ownerDocument||b[0]:s;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===s&&!ta.test(a[0])&&(c.support.checkClone||!ua.test(a[0]))){e=
true;if(j=c.fragments[a[0]])if(j!==1)f=j}if(!f){f=b.createDocumentFragment();c.clean(a,b,f,d)}if(e)c.fragments[a[0]]=j?f:1;return{fragment:f,cacheable:e}}function K(a,b){var d={};c.each(va.concat.apply([],va.slice(0,b)),function(){d[this]=a});return d}function wa(a){return"scrollTo"in a&&a.document?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var c=function(a,b){return new c.fn.init(a,b)},Ra=A.jQuery,Sa=A.$,s=A.document,T,Ta=/^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,Ua=/^.[^:#\[\.,]*$/,Va=/\S/,
Wa=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,Xa=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,P=navigator.userAgent,xa=false,Q=[],L,$=Object.prototype.toString,aa=Object.prototype.hasOwnProperty,ba=Array.prototype.push,R=Array.prototype.slice,ya=Array.prototype.indexOf;c.fn=c.prototype={init:function(a,b){var d,f;if(!a)return this;if(a.nodeType){this.context=this[0]=a;this.length=1;return this}if(a==="body"&&!b){this.context=s;this[0]=s.body;this.selector="body";this.length=1;return this}if(typeof a==="string")if((d=Ta.exec(a))&&
(d[1]||!b))if(d[1]){f=b?b.ownerDocument||b:s;if(a=Xa.exec(a))if(c.isPlainObject(b)){a=[s.createElement(a[1])];c.fn.attr.call(a,b,true)}else a=[f.createElement(a[1])];else{a=sa([d[1]],[f]);a=(a.cacheable?a.fragment.cloneNode(true):a.fragment).childNodes}return c.merge(this,a)}else{if(b=s.getElementById(d[2])){if(b.id!==d[2])return T.find(a);this.length=1;this[0]=b}this.context=s;this.selector=a;return this}else if(!b&&/^\w+$/.test(a)){this.selector=a;this.context=s;a=s.getElementsByTagName(a);return c.merge(this,
a)}else return!b||b.jquery?(b||T).find(a):c(b).find(a);else if(c.isFunction(a))return T.ready(a);if(a.selector!==w){this.selector=a.selector;this.context=a.context}return c.makeArray(a,this)},selector:"",jquery:"1.4.2",length:0,size:function(){return this.length},toArray:function(){return R.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this.slice(a)[0]:this[a]},pushStack:function(a,b,d){var f=c();c.isArray(a)?ba.apply(f,a):c.merge(f,a);f.prevObject=this;f.context=this.context;if(b===
"find")f.selector=this.selector+(this.selector?" ":"")+d;else if(b)f.selector=this.selector+"."+b+"("+d+")";return f},each:function(a,b){return c.each(this,a,b)},ready:function(a){c.bindReady();if(c.isReady)a.call(s,c);else Q&&Q.push(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(R.apply(this,arguments),"slice",R.call(arguments).join(","))},map:function(a){return this.pushStack(c.map(this,
function(b,d){return a.call(b,d,b)}))},end:function(){return this.prevObject||c(null)},push:ba,sort:[].sort,splice:[].splice};c.fn.init.prototype=c.fn;c.extend=c.fn.extend=function(){var a=arguments[0]||{},b=1,d=arguments.length,f=false,e,j,i,o;if(typeof a==="boolean"){f=a;a=arguments[1]||{};b=2}if(typeof a!=="object"&&!c.isFunction(a))a={};if(d===b){a=this;--b}for(;b<d;b++)if((e=arguments[b])!=null)for(j in e){i=a[j];o=e[j];if(a!==o)if(f&&o&&(c.isPlainObject(o)||c.isArray(o))){i=i&&(c.isPlainObject(i)||
c.isArray(i))?i:c.isArray(o)?[]:{};a[j]=c.extend(f,i,o)}else if(o!==w)a[j]=o}return a};c.extend({noConflict:function(a){A.$=Sa;if(a)A.jQuery=Ra;return c},isReady:false,ready:function(){if(!c.isReady){if(!s.body)return setTimeout(c.ready,13);c.isReady=true;if(Q){for(var a,b=0;a=Q[b++];)a.call(s,c);Q=null}c.fn.triggerHandler&&c(s).triggerHandler("ready")}},bindReady:function(){if(!xa){xa=true;if(s.readyState==="complete")return c.ready();if(s.addEventListener){s.addEventListener("DOMContentLoaded",
L,false);A.addEventListener("load",c.ready,false)}else if(s.attachEvent){s.attachEvent("onreadystatechange",L);A.attachEvent("onload",c.ready);var a=false;try{a=A.frameElement==null}catch(b){}s.documentElement.doScroll&&a&&ma()}}},isFunction:function(a){return $.call(a)==="[object Function]"},isArray:function(a){return $.call(a)==="[object Array]"},isPlainObject:function(a){if(!a||$.call(a)!=="[object Object]"||a.nodeType||a.setInterval)return false;if(a.constructor&&!aa.call(a,"constructor")&&!aa.call(a.constructor.prototype,
"isPrototypeOf"))return false;var b;for(b in a);return b===w||aa.call(a,b)},isEmptyObject:function(a){for(var b in a)return false;return true},error:function(a){throw a;},parseJSON:function(a){if(typeof a!=="string"||!a)return null;a=c.trim(a);if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return A.JSON&&A.JSON.parse?A.JSON.parse(a):(new Function("return "+
a))();else c.error("Invalid JSON: "+a)},noop:function(){},globalEval:function(a){if(a&&Va.test(a)){var b=s.getElementsByTagName("head")[0]||s.documentElement,d=s.createElement("script");d.type="text/javascript";if(c.support.scriptEval)d.appendChild(s.createTextNode(a));else d.text=a;b.insertBefore(d,b.firstChild);b.removeChild(d)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,b,d){var f,e=0,j=a.length,i=j===w||c.isFunction(a);if(d)if(i)for(f in a){if(b.apply(a[f],
d)===false)break}else for(;e<j;){if(b.apply(a[e++],d)===false)break}else if(i)for(f in a){if(b.call(a[f],f,a[f])===false)break}else for(d=a[0];e<j&&b.call(d,e,d)!==false;d=a[++e]);return a},trim:function(a){return(a||"").replace(Wa,"")},makeArray:function(a,b){b=b||[];if(a!=null)a.length==null||typeof a==="string"||c.isFunction(a)||typeof a!=="function"&&a.setInterval?ba.call(b,a):c.merge(b,a);return b},inArray:function(a,b){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;d++)if(b[d]===
a)return d;return-1},merge:function(a,b){var d=a.length,f=0;if(typeof b.length==="number")for(var e=b.length;f<e;f++)a[d++]=b[f];else for(;b[f]!==w;)a[d++]=b[f++];a.length=d;return a},grep:function(a,b,d){for(var f=[],e=0,j=a.length;e<j;e++)!d!==!b(a[e],e)&&f.push(a[e]);return f},map:function(a,b,d){for(var f=[],e,j=0,i=a.length;j<i;j++){e=b(a[j],j,d);if(e!=null)f[f.length]=e}return f.concat.apply([],f)},guid:1,proxy:function(a,b,d){if(arguments.length===2)if(typeof b==="string"){d=a;a=d[b];b=w}else if(b&&
!c.isFunction(b)){d=b;b=w}if(!b&&a)b=function(){return a.apply(d||this,arguments)};if(a)b.guid=a.guid=a.guid||b.guid||c.guid++;return b},uaMatch:function(a){a=a.toLowerCase();a=/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||!/compatible/.test(a)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(a)||[];return{browser:a[1]||"",version:a[2]||"0"}},browser:{}});P=c.uaMatch(P);if(P.browser){c.browser[P.browser]=true;c.browser.version=P.version}if(c.browser.webkit)c.browser.safari=
true;if(ya)c.inArray=function(a,b){return ya.call(b,a)};T=c(s);if(s.addEventListener)L=function(){s.removeEventListener("DOMContentLoaded",L,false);c.ready()};else if(s.attachEvent)L=function(){if(s.readyState==="complete"){s.detachEvent("onreadystatechange",L);c.ready()}};(function(){c.support={};var a=s.documentElement,b=s.createElement("script"),d=s.createElement("div"),f="script"+J();d.style.display="none";d.innerHTML=" <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
var e=d.getElementsByTagName("*"),j=d.getElementsByTagName("a")[0];if(!(!e||!e.length||!j)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(j.getAttribute("style")),hrefNormalized:j.getAttribute("href")==="/a",opacity:/^0.55$/.test(j.style.opacity),cssFloat:!!j.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:s.createElement("select").appendChild(s.createElement("option")).selected,
parentNode:d.removeChild(d.appendChild(s.createElement("div"))).parentNode===null,deleteExpando:true,checkClone:false,scriptEval:false,noCloneEvent:true,boxModel:null};b.type="text/javascript";try{b.appendChild(s.createTextNode("window."+f+"=1;"))}catch(i){}a.insertBefore(b,a.firstChild);if(A[f]){c.support.scriptEval=true;delete A[f]}try{delete b.test}catch(o){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function k(){c.support.noCloneEvent=
false;d.detachEvent("onclick",k)});d.cloneNode(true).fireEvent("onclick")}d=s.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=s.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var k=s.createElement("div");k.style.width=k.style.paddingLeft="1px";s.body.appendChild(k);c.boxModel=c.support.boxModel=k.offsetWidth===2;s.body.removeChild(k).style.display="none"});a=function(k){var n=
s.createElement("div");k="on"+k;var r=k in n;if(!r){n.setAttribute(k,"return;");r=typeof n[k]==="function"}return r};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=e=j=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var G="jQuery"+J(),Ya=0,za={};c.extend({cache:{},expando:G,noData:{embed:true,object:true,
applet:true},data:function(a,b,d){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var f=a[G],e=c.cache;if(!f&&typeof b==="string"&&d===w)return null;f||(f=++Ya);if(typeof b==="object"){a[G]=f;e[f]=c.extend(true,{},b)}else if(!e[f]){a[G]=f;e[f]={}}a=e[f];if(d!==w)a[b]=d;return typeof b==="string"?a[b]:a}},removeData:function(a,b){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var d=a[G],f=c.cache,e=f[d];if(b){if(e){delete e[b];c.isEmptyObject(e)&&c.removeData(a)}}else{if(c.support.deleteExpando)delete a[c.expando];
else a.removeAttribute&&a.removeAttribute(c.expando);delete f[d]}}}});c.fn.extend({data:function(a,b){if(typeof a==="undefined"&&this.length)return c.data(this[0]);else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===w){var f=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(f===w&&this.length)f=c.data(this[0],a);return f===w&&d[1]?this.data(d[0]):f}else return this.trigger("setData"+d[1]+"!",[d[0],b]).each(function(){c.data(this,
a,b)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var f=c.data(a,b);if(!d)return f||[];if(!f||c.isArray(d))f=c.data(a,b,c.makeArray(d));else f.push(d);return f}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),f=d.shift();if(f==="inprogress")f=d.shift();if(f){b==="fx"&&d.unshift("inprogress");f.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===
w)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var Aa=/[\n\t]/g,ca=/\s+/,Za=/\r/g,$a=/href|src|style/,ab=/(button|input)/i,bb=/(button|input|object|select|textarea)/i,
cb=/^(a|area)$/i,Ba=/radio|checkbox/;c.fn.extend({attr:function(a,b){return X(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(n){var r=c(this);r.addClass(a.call(this,n,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1)if(e.className){for(var j=" "+e.className+" ",
i=e.className,o=0,k=b.length;o<k;o++)if(j.indexOf(" "+b[o]+" ")<0)i+=" "+b[o];e.className=c.trim(i)}else e.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(k){var n=c(this);n.removeClass(a.call(this,k,n.attr("class")))});if(a&&typeof a==="string"||a===w)for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1&&e.className)if(a){for(var j=(" "+e.className+" ").replace(Aa," "),i=0,o=b.length;i<o;i++)j=j.replace(" "+b[i]+" ",
" ");e.className=c.trim(j)}else e.className=""}return this},toggleClass:function(a,b){var d=typeof a,f=typeof b==="boolean";if(c.isFunction(a))return this.each(function(e){var j=c(this);j.toggleClass(a.call(this,e,j.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var e,j=0,i=c(this),o=b,k=a.split(ca);e=k[j++];){o=f?o:!i.hasClass(e);i[o?"addClass":"removeClass"](e)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,"__className__",this.className);this.className=
this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(Aa," ").indexOf(a)>-1)return true;return false},val:function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var j=b?d:0;for(d=b?d+1:e.length;j<d;j++){var i=
e[j];if(i.selected){a=c(i).val();if(b)return a;f.push(a)}}return f}if(Ba.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Za,"")}return w}var o=c.isFunction(a);return this.each(function(k){var n=c(this),r=a;if(this.nodeType===1){if(o)r=a.call(this,k,n.val());if(typeof r==="number")r+="";if(c.isArray(r)&&Ba.test(this.type))this.checked=c.inArray(n.val(),r)>=0;else if(c.nodeName(this,"select")){var u=c.makeArray(r);c("option",this).each(function(){this.selected=
c.inArray(c(this).val(),u)>=0});if(!u.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,f){if(!a||a.nodeType===3||a.nodeType===8)return w;if(f&&b in c.attrFn)return c(a)[b](d);f=a.nodeType!==1||!c.isXMLDoc(a);var e=d!==w;b=f&&c.props[b]||b;if(a.nodeType===1){var j=$a.test(b);if(b in a&&f&&!j){if(e){b==="type"&&ab.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");
a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:bb.test(a.nodeName)||cb.test(a.nodeName)&&a.href?0:w;return a[b]}if(!c.support.style&&f&&b==="style"){if(e)a.style.cssText=""+d;return a.style.cssText}e&&a.setAttribute(b,""+d);a=!c.support.hrefNormalized&&f&&j?a.getAttribute(b,2):a.getAttribute(b);return a===null?w:a}return c.style(a,b,d)}});var O=/\.(.*)$/,db=function(a){return a.replace(/[^\w\s\.\|`]/g,
function(b){return"\\"+b})};c.event={add:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){if(a.setInterval&&a!==A&&!a.frameElement)a=A;var e,j;if(d.handler){e=d;d=e.handler}if(!d.guid)d.guid=c.guid++;if(j=c.data(a)){var i=j.events=j.events||{},o=j.handle;if(!o)j.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,arguments):w};o.elem=a;b=b.split(" ");for(var k,n=0,r;k=b[n++];){j=e?c.extend({},e):{handler:d,data:f};if(k.indexOf(".")>-1){r=k.split(".");
k=r.shift();j.namespace=r.slice(0).sort().join(".")}else{r=[];j.namespace=""}j.type=k;j.guid=d.guid;var u=i[k],z=c.event.special[k]||{};if(!u){u=i[k]=[];if(!z.setup||z.setup.call(a,f,r,o)===false)if(a.addEventListener)a.addEventListener(k,o,false);else a.attachEvent&&a.attachEvent("on"+k,o)}if(z.add){z.add.call(a,j);if(!j.handler.guid)j.handler.guid=d.guid}u.push(j);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){var e,j=0,i,o,k,n,r,u,z=c.data(a),
C=z&&z.events;if(z&&C){if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(e in C)c.event.remove(a,e+b)}else{for(b=b.split(" ");e=b[j++];){n=e;i=e.indexOf(".")<0;o=[];if(!i){o=e.split(".");e=o.shift();k=new RegExp("(^|\\.)"+c.map(o.slice(0).sort(),db).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(r=C[e])if(d){n=c.event.special[e]||{};for(B=f||0;B<r.length;B++){u=r[B];if(d.guid===u.guid){if(i||k.test(u.namespace)){f==null&&r.splice(B--,1);n.remove&&n.remove.call(a,u)}if(f!=
null)break}}if(r.length===0||f!=null&&r.length===1){if(!n.teardown||n.teardown.call(a,o)===false)Ca(a,e,z.handle);delete C[e]}}else for(var B=0;B<r.length;B++){u=r[B];if(i||k.test(u.namespace)){c.event.remove(a,n,u.handler,B);r.splice(B--,1)}}}if(c.isEmptyObject(C)){if(b=z.handle)b.elem=null;delete z.events;delete z.handle;c.isEmptyObject(z)&&c.removeData(a)}}}}},trigger:function(a,b,d,f){var e=a.type||a;if(!f){a=typeof a==="object"?a[G]?a:c.extend(c.Event(e),a):c.Event(e);if(e.indexOf("!")>=0){a.type=
e=e.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[e]&&c.each(c.cache,function(){this.events&&this.events[e]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===8)return w;a.result=w;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(f=c.data(d,"handle"))&&f.apply(d,b);f=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+e]&&d["on"+e].apply(d,b)===false)a.result=false}catch(j){}if(!a.isPropagationStopped()&&
f)c.event.trigger(a,b,f,true);else if(!a.isDefaultPrevented()){f=a.target;var i,o=c.nodeName(f,"a")&&e==="click",k=c.event.special[e]||{};if((!k._default||k._default.call(d,a)===false)&&!o&&!(f&&f.nodeName&&c.noData[f.nodeName.toLowerCase()])){try{if(f[e]){if(i=f["on"+e])f["on"+e]=null;c.event.triggered=true;f[e]()}}catch(n){}if(i)f["on"+e]=i;c.event.triggered=false}}},handle:function(a){var b,d,f,e;a=arguments[0]=c.event.fix(a||A.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;
if(!b){d=a.type.split(".");a.type=d.shift();f=new RegExp("(^|\\.)"+d.slice(0).sort().join("\\.(?:.*\\.)?")+"(\\.|$)")}e=c.data(this,"events");d=e[a.type];if(e&&d){d=d.slice(0);e=0;for(var j=d.length;e<j;e++){var i=d[e];if(b||f.test(i.namespace)){a.handler=i.handler;a.data=i.data;a.handleObj=i;i=i.handler.apply(this,arguments);if(i!==w){a.result=i;if(i===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
fix:function(a){if(a[G])return a;var b=a;a=c.Event(b);for(var d=this.props.length,f;d;){f=this.props[--d];a[f]=b[f]}if(!a.target)a.target=a.srcElement||s;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=s.documentElement;d=s.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(!a.which&&(a.charCode||a.charCode===0?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==w)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,a.origType,c.extend({},a,{handler:oa}))},remove:function(a){var b=true,d=a.origType.replace(O,"");c.each(c.data(this,
"events").live||[],function(){if(d===this.origType.replace(O,""))return b=false});b&&c.event.remove(this,a.origType,oa)}},beforeunload:{setup:function(a,b,d){if(this.setInterval)this.onbeforeunload=d;return false},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};var Ca=s.removeEventListener?function(a,b,d){a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=
a;this.type=a.type}else this.type=a;this.timeStamp=J();this[G]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=Z;var a=this.originalEvent;if(a){a.preventDefault&&a.preventDefault();a.returnValue=false}},stopPropagation:function(){this.isPropagationStopped=Z;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=Z;this.stopPropagation()},isDefaultPrevented:Y,isPropagationStopped:Y,
isImmediatePropagationStopped:Y};var Da=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},Ea=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?Ea:Da,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?Ea:Da)}}});if(!c.support.submitBubbles)c.event.special.submit=
{setup:function(){if(this.nodeName.toLowerCase()!=="form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length)return na("submit",this,arguments)});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13)return na("submit",this,arguments)})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};
if(!c.support.changeBubbles){var da=/textarea|input|select/i,ea,Fa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(f){return f.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},fa=function(a,b){var d=a.target,f,e;if(!(!da.test(d.nodeName)||d.readOnly)){f=c.data(d,"_change_data");e=Fa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",
e);if(!(f===w||e===f))if(f!=null||e){a.type="change";return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:fa,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return fa.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return fa.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,
"_change_data",Fa(a))}},setup:function(){if(this.type==="file")return false;for(var a in ea)c.event.add(this,a+".specialChange",ea[a]);return da.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return da.test(this.nodeName)}};ea=c.event.special.change.filters}s.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(f){f=c.event.fix(f);f.type=b;return c.event.handle.call(this,f)}c.event.special[b]={setup:function(){this.addEventListener(a,
d,true)},teardown:function(){this.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,f,e){if(typeof d==="object"){for(var j in d)this[b](j,f,d[j],e);return this}if(c.isFunction(f)){e=f;f=w}var i=b==="one"?c.proxy(e,function(k){c(this).unbind(k,i);return e.apply(this,arguments)}):e;if(d==="unload"&&b!=="one")this.one(d,f,e);else{j=0;for(var o=this.length;j<o;j++)c.event.add(this[j],d,i,f)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&
!a.preventDefault)for(var d in a)this.unbind(d,a[d]);else{d=0;for(var f=this.length;d<f;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,f){return this.live(b,d,f,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){a=c.Event(a);a.preventDefault();a.stopPropagation();c.event.trigger(a,b,this[0]);return a.result}},
toggle:function(a){for(var b=arguments,d=1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(f){var e=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,e+1);f.preventDefault();return b[e].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var Ga={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,f,e,j){var i,o=0,k,n,r=j||this.selector,
u=j?this:c(this.context);if(c.isFunction(f)){e=f;f=w}for(d=(d||"").split(" ");(i=d[o++])!=null;){j=O.exec(i);k="";if(j){k=j[0];i=i.replace(O,"")}if(i==="hover")d.push("mouseenter"+k,"mouseleave"+k);else{n=i;if(i==="focus"||i==="blur"){d.push(Ga[i]+k);i+=k}else i=(Ga[i]||i)+k;b==="live"?u.each(function(){c.event.add(this,pa(i,r),{data:f,selector:r,handler:e,origType:i,origHandler:e,preType:n})}):u.unbind(pa(i,r),e)}}return this}});c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),
function(a,b){c.fn[b]=function(d){return d?this.bind(b,d):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});A.attachEvent&&!A.addEventListener&&A.attachEvent("onunload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});(function(){function a(g){for(var h="",l,m=0;g[m];m++){l=g[m];if(l.nodeType===3||l.nodeType===4)h+=l.nodeValue;else if(l.nodeType!==8)h+=a(l.childNodes)}return h}function b(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];
if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1&&!p){t.sizcache=l;t.sizset=q}if(t.nodeName.toLowerCase()===h){y=t;break}t=t[g]}m[q]=y}}}function d(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1){if(!p){t.sizcache=l;t.sizset=q}if(typeof h!=="string"){if(t===h){y=true;break}}else if(k.filter(h,[t]).length>0){y=t;break}}t=t[g]}m[q]=y}}}var f=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
e=0,j=Object.prototype.toString,i=false,o=true;[0,0].sort(function(){o=false;return 0});var k=function(g,h,l,m){l=l||[];var q=h=h||s;if(h.nodeType!==1&&h.nodeType!==9)return[];if(!g||typeof g!=="string")return l;for(var p=[],v,t,y,S,H=true,M=x(h),I=g;(f.exec(""),v=f.exec(I))!==null;){I=v[3];p.push(v[1]);if(v[2]){S=v[3];break}}if(p.length>1&&r.exec(g))if(p.length===2&&n.relative[p[0]])t=ga(p[0]+p[1],h);else for(t=n.relative[p[0]]?[h]:k(p.shift(),h);p.length;){g=p.shift();if(n.relative[g])g+=p.shift();
t=ga(g,t)}else{if(!m&&p.length>1&&h.nodeType===9&&!M&&n.match.ID.test(p[0])&&!n.match.ID.test(p[p.length-1])){v=k.find(p.shift(),h,M);h=v.expr?k.filter(v.expr,v.set)[0]:v.set[0]}if(h){v=m?{expr:p.pop(),set:z(m)}:k.find(p.pop(),p.length===1&&(p[0]==="~"||p[0]==="+")&&h.parentNode?h.parentNode:h,M);t=v.expr?k.filter(v.expr,v.set):v.set;if(p.length>0)y=z(t);else H=false;for(;p.length;){var D=p.pop();v=D;if(n.relative[D])v=p.pop();else D="";if(v==null)v=h;n.relative[D](y,v,M)}}else y=[]}y||(y=t);y||k.error(D||
g);if(j.call(y)==="[object Array]")if(H)if(h&&h.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&E(h,y[g])))l.push(t[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&l.push(t[g]);else l.push.apply(l,y);else z(y,l);if(S){k(S,q,l,m);k.uniqueSort(l)}return l};k.uniqueSort=function(g){if(B){i=o;g.sort(B);if(i)for(var h=1;h<g.length;h++)g[h]===g[h-1]&&g.splice(h--,1)}return g};k.matches=function(g,h){return k(g,null,null,h)};k.find=function(g,h,l){var m,q;if(!g)return[];
for(var p=0,v=n.order.length;p<v;p++){var t=n.order[p];if(q=n.leftMatch[t].exec(g)){var y=q[1];q.splice(1,1);if(y.substr(y.length-1)!=="\\"){q[1]=(q[1]||"").replace(/\\/g,"");m=n.find[t](q,h,l);if(m!=null){g=g.replace(n.match[t],"");break}}}}m||(m=h.getElementsByTagName("*"));return{set:m,expr:g}};k.filter=function(g,h,l,m){for(var q=g,p=[],v=h,t,y,S=h&&h[0]&&x(h[0]);g&&h.length;){for(var H in n.filter)if((t=n.leftMatch[H].exec(g))!=null&&t[2]){var M=n.filter[H],I,D;D=t[1];y=false;t.splice(1,1);if(D.substr(D.length-
1)!=="\\"){if(v===p)p=[];if(n.preFilter[H])if(t=n.preFilter[H](t,v,l,p,m,S)){if(t===true)continue}else y=I=true;if(t)for(var U=0;(D=v[U])!=null;U++)if(D){I=M(D,t,U,v);var Ha=m^!!I;if(l&&I!=null)if(Ha)y=true;else v[U]=false;else if(Ha){p.push(D);y=true}}if(I!==w){l||(v=p);g=g.replace(n.match[H],"");if(!y)return[];break}}}if(g===q)if(y==null)k.error(g);else break;q=g}return v};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var n=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
CLASS:/\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},
relative:{"+":function(g,h){var l=typeof h==="string",m=l&&!/\W/.test(h);l=l&&!m;if(m)h=h.toLowerCase();m=0;for(var q=g.length,p;m<q;m++)if(p=g[m]){for(;(p=p.previousSibling)&&p.nodeType!==1;);g[m]=l||p&&p.nodeName.toLowerCase()===h?p||false:p===h}l&&k.filter(h,g,true)},">":function(g,h){var l=typeof h==="string";if(l&&!/\W/.test(h)){h=h.toLowerCase();for(var m=0,q=g.length;m<q;m++){var p=g[m];if(p){l=p.parentNode;g[m]=l.nodeName.toLowerCase()===h?l:false}}}else{m=0;for(q=g.length;m<q;m++)if(p=g[m])g[m]=
l?p.parentNode:p.parentNode===h;l&&k.filter(h,g,true)}},"":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("parentNode",h,m,g,p,l)},"~":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("previousSibling",h,m,g,p,l)}},find:{ID:function(g,h,l){if(typeof h.getElementById!=="undefined"&&!l)return(g=h.getElementById(g[1]))?[g]:[]},NAME:function(g,h){if(typeof h.getElementsByName!=="undefined"){var l=[];
h=h.getElementsByName(g[1]);for(var m=0,q=h.length;m<q;m++)h[m].getAttribute("name")===g[1]&&l.push(h[m]);return l.length===0?null:l}},TAG:function(g,h){return h.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,h,l,m,q,p){g=" "+g[1].replace(/\\/g,"")+" ";if(p)return g;p=0;for(var v;(v=h[p])!=null;p++)if(v)if(q^(v.className&&(" "+v.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))l||m.push(v);else if(l)h[p]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},
CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,l,m,q,p){h=g[1].replace(/\\/g,"");if(!p&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,l,m,q){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,h);else{g=k.filter(g[3],h,l,true^q);l||m.push.apply(m,
g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,l){return!!k(l[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},
text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},
setFilters:{first:function(g,h){return h===0},last:function(g,h,l,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,l){return h<l[3]-0},gt:function(g,h,l){return h>l[3]-0},nth:function(g,h,l){return l[3]-0===h},eq:function(g,h,l){return l[3]-0===h}},filter:{PSEUDO:function(g,h,l,m){var q=h[1],p=n.filters[q];if(p)return p(g,l,h,m);else if(q==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(q==="not"){h=
h[3];l=0;for(m=h.length;l<m;l++)if(h[l]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+q)},CHILD:function(g,h){var l=h[1],m=g;switch(l){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(l==="first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":l=h[2];var q=h[3];if(l===1&&q===0)return true;h=h[0];var p=g.parentNode;if(p&&(p.sizcache!==h||!g.nodeIndex)){var v=0;for(m=p.firstChild;m;m=
m.nextSibling)if(m.nodeType===1)m.nodeIndex=++v;p.sizcache=h}g=g.nodeIndex-q;return l===0?g===0:g%l===0&&g/l>=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m===
"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g,
h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l<m;l++)h.push(g[l]);else for(l=0;g[l];l++)h.push(g[l]);return h}}var B;if(s.documentElement.compareDocumentPosition)B=function(g,h){if(!g.compareDocumentPosition||
!h.compareDocumentPosition){if(g==h)i=true;return g.compareDocumentPosition?-1:1}g=g.compareDocumentPosition(h)&4?-1:g===h?0:1;if(g===0)i=true;return g};else if("sourceIndex"in s.documentElement)B=function(g,h){if(!g.sourceIndex||!h.sourceIndex){if(g==h)i=true;return g.sourceIndex?-1:1}g=g.sourceIndex-h.sourceIndex;if(g===0)i=true;return g};else if(s.createRange)B=function(g,h){if(!g.ownerDocument||!h.ownerDocument){if(g==h)i=true;return g.ownerDocument?-1:1}var l=g.ownerDocument.createRange(),m=
h.ownerDocument.createRange();l.setStart(g,0);l.setEnd(g,0);m.setStart(h,0);m.setEnd(h,0);g=l.compareBoundaryPoints(Range.START_TO_END,m);if(g===0)i=true;return g};(function(){var g=s.createElement("div"),h="script"+(new Date).getTime();g.innerHTML="<a name='"+h+"'/>";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&&
q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML="<a href='#'></a>";
if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="<p class='TEST'></p>";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}();
(function(){var g=s.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}:
function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q<p;q++)k(g,h[q],l);return k.filter(m,l)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=a;c.isXMLDoc=x;c.contains=E})();var eb=/Until$/,fb=/^(?:parents|prevUntil|prevAll)/,
gb=/,/;R=Array.prototype.slice;var Ia=function(a,b,d){if(c.isFunction(b))return c.grep(a,function(e,j){return!!b.call(e,j,e)===d});else if(b.nodeType)return c.grep(a,function(e){return e===b===d});else if(typeof b==="string"){var f=c.grep(a,function(e){return e.nodeType===1});if(Ua.test(b))return c.filter(b,f,!d);else b=c.filter(b,f)}return c.grep(a,function(e){return c.inArray(e,b)>=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f<e;f++){d=b.length;
c.find(a,this[f],b);if(f>0)for(var j=d;j<b.length;j++)for(var i=0;i<d;i++)if(b[i]===b[j]){b.splice(j--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,f=b.length;d<f;d++)if(c.contains(this,b[d]))return true})},not:function(a){return this.pushStack(Ia(this,a,false),"not",a)},filter:function(a){return this.pushStack(Ia(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j=
{},i;if(f&&a.length){e=0;for(var o=a.length;e<o;e++){i=a[e];j[i]||(j[i]=c.expr.match.POS.test(i)?c(i,b||this.context):i)}for(;f&&f.ownerDocument&&f!==b;){for(i in j){e=j[i];if(e.jquery?e.index(f)>-1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a===
"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",
d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?
a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType===
1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/<tbody/i,jb=/<|&#?\w+;/,ta=/<script|<object|<embed|<option|<style/i,ua=/checked\s*(?:[^=]|=\s*.checked.)/i,Ma=function(a,b,d){return hb.test(d)?
a:b+"></"+d+">"},F={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja,
""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(f){this.empty().append(a)}}else c.isFunction(a)?this.each(function(e){var j=c(this),i=j.html();j.empty().append(function(){return a.call(this,e,i)})}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&
this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=c(this),f=d.html();d.replaceWith(a.call(this,b,f))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){function f(u){return c.nodeName(u,"table")?u.getElementsByTagName("tbody")[0]||
u.appendChild(u.ownerDocument.createElement("tbody")):u}var e,j,i=a[0],o=[],k;if(!c.support.checkClone&&arguments.length===3&&typeof i==="string"&&ua.test(i))return this.each(function(){c(this).domManip(a,b,d,true)});if(c.isFunction(i))return this.each(function(u){var z=c(this);a[0]=i.call(this,u,b?z.html():w);z.domManip(a,b,d)});if(this[0]){e=i&&i.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:sa(a,this,o);k=e.fragment;if(j=k.childNodes.length===
1?(k=k.firstChild):k.firstChild){b=b&&c.nodeName(j,"tr");for(var n=0,r=this.length;n<r;n++)d.call(b?f(this[n],j):this[n],n>0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]);
return this}else{e=0;for(var j=d.length;e<j;e++){var i=(e>0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["",
""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]==="<table>"&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e=
c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]?
c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja=
function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter=
Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a,
"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f=
a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=
a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/<script(.|\s)*?\/script>/gi,ub=/select|textarea/i,vb=/color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,N=/=\?(&|$)/,ka=/\?/,wb=/(\?|&)_=.*?(&|$)/,xb=/^(\w+:)?\/\/([^\/?#]+)/,yb=/%20/g,zb=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!==
"string")return zb.call(this,a);else if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var e=a.slice(f,a.length);a=a.slice(0,f)}f="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b==="object"){b=c.param(b,c.ajaxSettings.traditional);f="POST"}var j=this;c.ajax({url:a,type:f,dataType:"html",data:b,complete:function(i,o){if(o==="success"||o==="notmodified")j.html(e?c("<div />").append(i.responseText.replace(tb,"")).find(e):i.responseText);d&&j.each(d,[i.responseText,o,i])}});return this},
serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||ub.test(this.nodeName)||vb.test(this.type))}).map(function(a,b){a=c(this).val();return a==null?null:c.isArray(a)?c.map(a,function(d){return{name:b.name,value:d}}):{name:b.name,value:a}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),
function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:f})},getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:f})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,
global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:A.XMLHttpRequest&&(A.location.protocol!=="file:"||!A.ActiveXObject)?function(){return new A.XMLHttpRequest}:function(){try{return new A.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},etag:{},ajax:function(a){function b(){e.success&&
e.success.call(k,o,i,x);e.global&&f("ajaxSuccess",[x,e])}function d(){e.complete&&e.complete.call(k,x,i);e.global&&f("ajaxComplete",[x,e]);e.global&&!--c.active&&c.event.trigger("ajaxStop")}function f(q,p){(e.context?c(e.context):c.event).trigger(q,p)}var e=c.extend(true,{},c.ajaxSettings,a),j,i,o,k=a&&a.context||e,n=e.type.toUpperCase();if(e.data&&e.processData&&typeof e.data!=="string")e.data=c.param(e.data,e.traditional);if(e.dataType==="jsonp"){if(n==="GET")N.test(e.url)||(e.url+=(ka.test(e.url)?
"&":"?")+(e.jsonp||"callback")+"=?");else if(!e.data||!N.test(e.data))e.data=(e.data?e.data+"&":"")+(e.jsonp||"callback")+"=?";e.dataType="json"}if(e.dataType==="json"&&(e.data&&N.test(e.data)||N.test(e.url))){j=e.jsonpCallback||"jsonp"+sb++;if(e.data)e.data=(e.data+"").replace(N,"="+j+"$1");e.url=e.url.replace(N,"="+j+"$1");e.dataType="script";A[j]=A[j]||function(q){o=q;b();d();A[j]=w;try{delete A[j]}catch(p){}z&&z.removeChild(C)}}if(e.dataType==="script"&&e.cache===null)e.cache=false;if(e.cache===
false&&n==="GET"){var r=J(),u=e.url.replace(wb,"$1_="+r+"$2");e.url=u+(u===e.url?(ka.test(e.url)?"&":"?")+"_="+r:"")}if(e.data&&n==="GET")e.url+=(ka.test(e.url)?"&":"?")+e.data;e.global&&!c.active++&&c.event.trigger("ajaxStart");r=(r=xb.exec(e.url))&&(r[1]&&r[1]!==location.protocol||r[2]!==location.host);if(e.dataType==="script"&&n==="GET"&&r){var z=s.getElementsByTagName("head")[0]||s.documentElement,C=s.createElement("script");C.src=e.url;if(e.scriptCharset)C.charset=e.scriptCharset;if(!j){var B=
false;C.onload=C.onreadystatechange=function(){if(!B&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){B=true;b();d();C.onload=C.onreadystatechange=null;z&&C.parentNode&&z.removeChild(C)}}}z.insertBefore(C,z.firstChild);return w}var E=false,x=e.xhr();if(x){e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);try{if(e.data||a&&a.contentType)x.setRequestHeader("Content-Type",e.contentType);if(e.ifModified){c.lastModified[e.url]&&x.setRequestHeader("If-Modified-Since",
c.lastModified[e.url]);c.etag[e.url]&&x.setRequestHeader("If-None-Match",c.etag[e.url])}r||x.setRequestHeader("X-Requested-With","XMLHttpRequest");x.setRequestHeader("Accept",e.dataType&&e.accepts[e.dataType]?e.accepts[e.dataType]+", */*":e.accepts._default)}catch(ga){}if(e.beforeSend&&e.beforeSend.call(k,x,e)===false){e.global&&!--c.active&&c.event.trigger("ajaxStop");x.abort();return false}e.global&&f("ajaxSend",[x,e]);var g=x.onreadystatechange=function(q){if(!x||x.readyState===0||q==="abort"){E||
d();E=true;if(x)x.onreadystatechange=c.noop}else if(!E&&x&&(x.readyState===4||q==="timeout")){E=true;x.onreadystatechange=c.noop;i=q==="timeout"?"timeout":!c.httpSuccess(x)?"error":e.ifModified&&c.httpNotModified(x,e.url)?"notmodified":"success";var p;if(i==="success")try{o=c.httpData(x,e.dataType,e)}catch(v){i="parsererror";p=v}if(i==="success"||i==="notmodified")j||b();else c.handleError(e,x,i,p);d();q==="timeout"&&x.abort();if(e.async)x=null}};try{var h=x.abort;x.abort=function(){x&&h.call(x);
g("abort")}}catch(l){}e.async&&e.timeout>0&&setTimeout(function(){x&&!E&&g("timeout")},e.timeout);try{x.send(n==="POST"||n==="PUT"||n==="DELETE"?e.data:null)}catch(m){c.handleError(e,x,null,m);d()}e.async||g();return x}},handleError:function(a,b,d,f){if(a.error)a.error.call(a.context||a,b,d,f);if(a.global)(a.context?c(a.context):c.event).trigger("ajaxError",[b,a,f])},active:0,httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===
1223||a.status===0}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),f=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(f)c.etag[b]=f;return a.status===304||a.status===0},httpData:function(a,b,d){var f=a.getResponseHeader("content-type")||"",e=b==="xml"||!b&&f.indexOf("xml")>=0;a=e?a.responseXML:a.responseText;e&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b===
"json"||!b&&f.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&f.indexOf("javascript")>=0)c.globalEval(a);return a},param:function(a,b){function d(i,o){if(c.isArray(o))c.each(o,function(k,n){b||/\[\]$/.test(i)?f(i,n):d(i+"["+(typeof n==="object"||c.isArray(n)?k:"")+"]",n)});else!b&&o!=null&&typeof o==="object"?c.each(o,function(k,n){d(i+"["+k+"]",n)}):f(i,o)}function f(i,o){o=c.isFunction(o)?o():o;e[e.length]=encodeURIComponent(i)+"="+encodeURIComponent(o)}var e=[];if(b===w)b=c.ajaxSettings.traditional;
if(c.isArray(a)||a.jquery)c.each(a,function(){f(this.name,this.value)});else for(var j in a)d(j,a[j]);return e.join("&").replace(yb,"+")}});var la={},Ab=/toggle|show|hide/,Bb=/^([+-]=)?([\d+-.]+)(.*)$/,W,va=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b){if(a||a===0)return this.animate(K("show",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");
this[a].style.display=d||"";if(c.css(this[a],"display")==="none"){d=this[a].nodeName;var f;if(la[d])f=la[d];else{var e=c("<"+d+" />").appendTo("body");f=e.css("display");if(f==="none")f="block";e.remove();la[d]=f}c.data(this[a],"olddisplay",f)}}a=0;for(b=this.length;a<b;a++)this[a].style.display=c.data(this[a],"olddisplay")||"";return this}},hide:function(a,b){if(a||a===0)return this.animate(K("hide",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");!d&&d!=="none"&&c.data(this[a],
"olddisplay",c.css(this[a],"display"))}a=0;for(b=this.length;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b){var d=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||d?this.each(function(){var f=d?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(K("toggle",3),a,b);return this},fadeTo:function(a,b,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d)},
animate:function(a,b,d,f){var e=c.speed(b,d,f);if(c.isEmptyObject(a))return this.each(e.complete);return this[e.queue===false?"each":"queue"](function(){var j=c.extend({},e),i,o=this.nodeType===1&&c(this).is(":hidden"),k=this;for(i in a){var n=i.replace(ia,ja);if(i!==n){a[n]=a[i];delete a[i];i=n}if(a[i]==="hide"&&o||a[i]==="show"&&!o)return j.complete.call(this);if((i==="height"||i==="width")&&this.style){j.display=c.css(this,"display");j.overflow=this.style.overflow}if(c.isArray(a[i])){(j.specialEasing=
j.specialEasing||{})[i]=a[i][1];a[i]=a[i][0]}}if(j.overflow!=null)this.style.overflow="hidden";j.curAnim=c.extend({},a);c.each(a,function(r,u){var z=new c.fx(k,j,r);if(Ab.test(u))z[u==="toggle"?o?"show":"hide":u](a);else{var C=Bb.exec(u),B=z.cur(true)||0;if(C){u=parseFloat(C[2]);var E=C[3]||"px";if(E!=="px"){k.style[r]=(u||1)+E;B=(u||1)/z.cur(true)*B;k.style[r]=B+E}if(C[1])u=(C[1]==="-="?-1:1)*u+B;z.custom(B,u,E)}else z.custom(B,u,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);
this.each(function(){for(var f=d.length-1;f>=0;f--)if(d[f].elem===this){b&&d[f](true);d.splice(f,1)}});b||this.dequeue();return this}});c.each({slideDown:K("show",1),slideUp:K("hide",1),slideToggle:K("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(a,b){c.fn[a]=function(d,f){return this.animate(b,d,f)}});c.extend({speed:function(a,b,d){var f=a&&typeof a==="object"?a:{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};f.duration=c.fx.off?0:typeof f.duration===
"number"?f.duration:c.fx.speeds[f.duration]||c.fx.speeds._default;f.old=f.complete;f.complete=function(){f.queue!==false&&c(this).dequeue();c.isFunction(f.old)&&f.old.call(this)};return f},easing:{linear:function(a,b,d,f){return d+f*a},swing:function(a,b,d,f){return(-Math.cos(a*Math.PI)/2+0.5)*f+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||
c.fx.step._default)(this);if((this.prop==="height"||this.prop==="width")&&this.elem.style)this.elem.style.display="block"},cur:function(a){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];return(a=parseFloat(c.css(this.elem,this.prop,a)))&&a>-10000?a:parseFloat(c.curCSS(this.elem,this.prop))||0},custom:function(a,b,d){function f(j){return e.step(j)}this.startTime=J();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;
this.pos=this.state=0;var e=this;f.elem=this.elem;if(f()&&c.timers.push(f)&&!W)W=setInterval(c.fx.tick,13)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(a){var b=J(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=
this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var f in this.options.curAnim)if(this.options.curAnim[f]!==true)d=false;if(d){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;a=c.data(this.elem,"olddisplay");this.elem.style.display=a?a:this.options.display;if(c.css(this.elem,"display")==="none")this.elem.style.display="block"}this.options.hide&&c(this.elem).hide();if(this.options.hide||this.options.show)for(var e in this.options.curAnim)c.style(this.elem,
e,this.options.orig[e]);this.options.complete.call(this.elem)}return false}else{e=b-this.startTime;this.state=e/this.options.duration;a=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||a](this.state,e,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||
c.fx.stop()},stop:function(){clearInterval(W);W=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===b.elem}).length};c.fn.offset="getBoundingClientRect"in s.documentElement?
function(a){var b=this[0];if(a)return this.each(function(e){c.offset.setOffset(this,a,e)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);var d=b.getBoundingClientRect(),f=b.ownerDocument;b=f.body;f=f.documentElement;return{top:d.top+(self.pageYOffset||c.support.boxModel&&f.scrollTop||b.scrollTop)-(f.clientTop||b.clientTop||0),left:d.left+(self.pageXOffset||c.support.boxModel&&f.scrollLeft||b.scrollLeft)-(f.clientLeft||b.clientLeft||0)}}:function(a){var b=
this[0];if(a)return this.each(function(r){c.offset.setOffset(this,a,r)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d=b.offsetParent,f=b,e=b.ownerDocument,j,i=e.documentElement,o=e.body;f=(e=e.defaultView)?e.getComputedStyle(b,null):b.currentStyle;for(var k=b.offsetTop,n=b.offsetLeft;(b=b.parentNode)&&b!==o&&b!==i;){if(c.offset.supportsFixedPosition&&f.position==="fixed")break;j=e?e.getComputedStyle(b,null):b.currentStyle;
k-=b.scrollTop;n-=b.scrollLeft;if(b===d){k+=b.offsetTop;n+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(b.nodeName))){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=d;d=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&j.overflow!=="visible"){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=j}if(f.position==="relative"||f.position==="static"){k+=o.offsetTop;n+=o.offsetLeft}if(c.offset.supportsFixedPosition&&
f.position==="fixed"){k+=Math.max(i.scrollTop,o.scrollTop);n+=Math.max(i.scrollLeft,o.scrollLeft)}return{top:k,left:n}};c.offset={initialize:function(){var a=s.body,b=s.createElement("div"),d,f,e,j=parseFloat(c.curCSS(a,"marginTop",true))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
a.insertBefore(b,a.firstChild);d=b.firstChild;f=d.firstChild;e=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=f.offsetTop!==5;this.doesAddBorderForTableAndCells=e.offsetTop===5;f.style.position="fixed";f.style.top="20px";this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15;f.style.position=f.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==j;a.removeChild(b);
c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.curCSS(a,"marginTop",true))||0;d+=parseFloat(c.curCSS(a,"marginLeft",true))||0}return{top:b,left:d}},setOffset:function(a,b,d){if(/static/.test(c.curCSS(a,"position")))a.style.position="relative";var f=c(a),e=f.offset(),j=parseInt(c.curCSS(a,"top",true),10)||0,i=parseInt(c.curCSS(a,"left",true),10)||0;if(c.isFunction(b))b=b.call(a,
d,e);d={top:b.top-e.top+j,left:b.left-e.left+i};"using"in b?b.using.call(a,d):f.css(d)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),f=/^body|html$/i.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.curCSS(a,"marginTop",true))||0;d.left-=parseFloat(c.curCSS(a,"marginLeft",true))||0;f.top+=parseFloat(c.curCSS(b[0],"borderTopWidth",true))||0;f.left+=parseFloat(c.curCSS(b[0],"borderLeftWidth",true))||0;return{top:d.top-
f.top,left:d.left-f.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||s.body;a&&!/^body|html$/i.test(a.nodeName)&&c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(f){var e=this[0],j;if(!e)return null;if(f!==w)return this.each(function(){if(j=wa(this))j.scrollTo(!a?f:c(j).scrollLeft(),a?f:c(j).scrollTop());else this[d]=f});else return(j=wa(e))?"pageXOffset"in j?j[a?"pageYOffset":
"pageXOffset"]:c.support.boxModel&&j.document.documentElement[d]||j.document.body[d]:e[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();c.fn["inner"+b]=function(){return this[0]?c.css(this[0],d,false,"padding"):null};c.fn["outer"+b]=function(f){return this[0]?c.css(this[0],d,false,f?"margin":"border"):null};c.fn[d]=function(f){var e=this[0];if(!e)return f==null?null:this;if(c.isFunction(f))return this.each(function(j){var i=c(this);i[d](f.call(this,j,i[d]()))});return"scrollTo"in
e&&e.document?e.document.compatMode==="CSS1Compat"&&e.document.documentElement["client"+b]||e.document.body["client"+b]:e.nodeType===9?Math.max(e.documentElement["client"+b],e.body["scroll"+b],e.documentElement["scroll"+b],e.body["offset"+b],e.documentElement["offset"+b]):f===w?c.css(e,d):this.css(d,typeof f==="string"?f:f+"px")}});A.jQuery=A.$=c})(window);
//]]>
</script>
<script id="jqueryArea" type="text/javascript">
//<![CDATA[
/*
jQuery.encoding.digests.sha1.js
SHA-1 digest and associated utility functions
Copyright (c) UnaMesa Association 2009
Dual licensed under the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
*/
(function($) {
if(!$.encoding)
$.encoding = {};
$.extend($.encoding,{
strToBe32s: function(str) {
// Convert a string to an array of big-endian 32-bit words
var be=[];
var len=Math.floor(str.length/4);
var i, j;
for(i=0, j=0; i<len; i++, j+=4) {
be[i]=((str.charCodeAt(j)&0xff) << 24)|((str.charCodeAt(j+1)&0xff) << 16)|((str.charCodeAt(j+2)&0xff) << 8)|(str.charCodeAt(j+3)&0xff);
}
while(j<str.length) {
be[j>>2] |= (str.charCodeAt(j)&0xff)<<(24-(j*8)%32);
j++;
}
return be;
},
be32sToStr: function(be) {
// Convert an array of big-endian 32-bit words to a string
var str='';
for(var i=0;i<be.length*32;i+=8) {
str += String.fromCharCode((be[i>>5]>>>(24-i%32)) & 0xff);
}
return str;
},
be32sToHex: function(be) {
// Convert an array of big-endian 32-bit words to a hex string
var hex='0123456789ABCDEF';
var str='';
for(var i=0;i<be.length*4;i++) {
str += hex.charAt((be[i>>2]>>((3-i%4)*8+4))&0xF) + hex.charAt((be[i>>2]>>((3-i%4)*8))&0xF);
}
return str;
}
});
})(jQuery);
(function($) {
if(!$.encoding.digests)
$.encoding.digests = {};
$.extend($.encoding.digests,{
hexSha1Str: function(str) {
// Return, in hex, the SHA-1 hash of a string
return $.encoding.be32sToHex($.encoding.digests.sha1Str(str));
},
sha1Str: function(str) {
// Return the SHA-1 hash of a string
return sha1($.encoding.strToBe32s(str),str.length);
},
sha1: function(x,blen) {
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
return sha1($.encoding.strToBe32s(str),str.length);
}
});
// Private functions.
function sha1(x,blen) {
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
function add32(a,b) {
// Add 32-bit integers, wrapping at 32 bits
// Uses 16-bit operations internally to work around bugs in some JavaScript interpreters.
var lsw=(a&0xFFFF)+(b&0xFFFF);
var msw=(a>>16)+(b>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function AA(a,b,c,d,e) {
// Cryptographic round helper function. Add five 32-bit integers, wrapping at 32 bits, second parameter is rotated left 5 bits before the addition
// Uses 16-bit operations internally to work around bugs in some JavaScript interpreters.
b=(b>>>27)|(b<<5);
var lsw=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
var msw=(a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
}
function RR(w,j) {
// Cryptographic round helper function.
var n=w[j-3]^w[j-8]^w[j-14]^w[j-16];
return (n>>>31)|(n<<1);
}
var len=blen*8;
x[len>>5] |= 0x80 << (24-len%32);
x[((len+64>>9)<<4)+15]=len;
var w=new Array(80);
var k1=0x5A827999;
var k2=0x6ED9EBA1;
var k3=0x8F1BBCDC;
var k4=0xCA62C1D6;
var h0=0x67452301;
var h1=0xEFCDAB89;
var h2=0x98BADCFE;
var h3=0x10325476;
var h4=0xC3D2E1F0;
for(var i=0;i<x.length;i+=16) {
var j=0;
var t;
var a=h0;
var b=h1;
var c=h2;
var d=h3;
var e=h4;
while(j<16) {
w[j]=x[i+j];
t=AA(e,a,d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<20) {
w[j]=RR(w,j);
t=AA(e,a,d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<40) {
w[j]=RR(w,j);
t=AA(e,a,b^c^d,w[j],k2);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<60) {
w[j]=RR(w,j);
t=AA(e,a,(b&c)|(d&(b|c)),w[j],k3);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
while(j<80) {
w[j]=RR(w,j);
t=AA(e,a,b^c^d,w[j],k4);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
}
h0=add32(h0,a);
h1=add32(h1,b);
h2=add32(h2,c);
h3=add32(h3,d);
h4=add32(h4,e);
}
return [h0,h1,h2,h3,h4];
}
})(jQuery);
/*
jQuery.twStylesheet.js
jQuery plugin to dynamically insert CSS rules into a document
Usage:
jQuery.twStylesheet applies style definitions
jQuery.twStylesheet.remove neutralizes style definitions
Copyright (c) UnaMesa Association 2009
Triple licensed under the BSD, MIT and GPL licenses:
http://www.opensource.org/licenses/bsd-license.php
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
*/
(function($) {
var defaultId = "customStyleSheet"; // XXX: rename to dynamicStyleSheet?
// Add or replace a style sheet
// css argument is a string of CSS rule sets
// options.id is an optional name identifying the style sheet
// options.doc is an optional document reference
// N.B.: Uses DOM methods instead of jQuery to ensure cross-browser comaptibility.
$.twStylesheet = function(css, options) {
options = options || {};
var id = options.id || defaultId;
var doc = options.doc || document;
var el = doc.getElementById(id);
if(doc.createStyleSheet) { // IE-specific handling
if(el) {
el.cssText = css;
} else {
doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd",
'&nbsp;<style id="' + id + '" type="text/css">' + css + '</style>'); // fails without &nbsp;
}
} else { // modern browsers
if(el) {
el.replaceChild(doc.createTextNode(css), el.firstChild);
} else {
el = doc.createElement("style");
el.type = "text/css";
el.id = id;
el.appendChild(doc.createTextNode(css));
doc.getElementsByTagName("head")[0].appendChild(el);
}
}
};
// Remove existing style sheet
// options.id is an optional name identifying the style sheet
// options.doc is an optional document reference
$.twStylesheet.remove = function(options) {
options = options || {};
var id = options.id || defaultId;
var doc = options.doc || document;
var el = doc.getElementById(id);
if(el) {
el.parentNode.removeChild(el);
}
};
})(jQuery);
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
if(useJavaSaver)
document.write("<applet style='position:absolute;left:-1px' name='TiddlySaver' code='TiddlySaver.class' archive='TiddlySaver.jar' width='1' height='1'></applet>");
//]]>
</script>
<!--POST-SCRIPT-START-->
<!--POST-SCRIPT-END-->
</body>
</html>
{
"rev": null,
"title": "Foo",
"text": "lorem ipsum",
"tags": ["tmp", "sample"]
}
<!DOCTYPE html>
<html>
<head>
<title>My New CouchApp</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<div id="account"></div>
<h1>Generated CouchApp</h1>
<div id="profile"></div>
<div id="items"></div>
<div id="sidebar">
<p>Edit welcome message.</p>
<p>Ideas: You could easily turn this into a photo sharing app, or a grocery list, or a chat room.</p>
</div>
</body>
<script src="vendor/couchapp/loader.js"></script>
<script type="text/javascript" charset="utf-8">
$.couch.app(function(app) {
$("#account").evently("account", app);
$("#profile").evently("profile", app);
$.evently.connect("#account","#profile", ["loggedIn","loggedOut"]);
$("#items").evently("items", app);
});
</script>
</html>
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
// Usage: The passed in function is called when the page is ready.
// CouchApp passes in the app object, which takes care of linking to
// the proper database, and provides access to the CouchApp helpers.
// $.couch.app(function(app) {
// app.db.view(...)
// ...
// });
(function($) {
function Design(db, name) {
this.doc_id = "_design/"+name;
this.view = function(view, opts) {
db.view(name+'/'+view, opts);
};
this.list = function(list, view, opts) {
db.list(name+'/'+list, view, opts);
};
}
$.couch.app = $.couch.app || function(appFun, opts) {
opts = opts || {};
$(function() {
var urlPrefix = opts.urlPrefix || "";
$.couch.urlPrefix = urlPrefix;
var index = urlPrefix.split('/').length;
var fragments = unescape(document.location.href).split('/');
var dbname = opts.db || fragments[index + 2];
var dname = opts.design || fragments[index + 4];
var db = $.couch.db(dbname);
var design = new Design(db, dname);
// docForm applies CouchDB behavior to HTML forms.
// todo make this a couch.app plugin
function docForm(formSelector, opts) {
var localFormDoc = {};
opts = opts || {};
opts.fields = opts.fields || [];
// turn the form into deep json
// field names like 'author-email' get turned into json like
// {"author":{"email":"quentin@example.com"}}
function formToDeepJSON(form, fields, doc) {
form = $(form);
fields.forEach(function(field) {
var element = form.find("[name="+field+"]");
if (element.attr('type') === 'checkbox') {
var val = element.attr('checked');
} else {
var val = element.val();
if (!val) return;
}
var parts = field.split('-');
var frontObj = doc, frontName = parts.shift();
while (parts.length > 0) {
frontObj[frontName] = frontObj[frontName] || {};
frontObj = frontObj[frontName];
frontName = parts.shift();
}
frontObj[frontName] = val;
});
}
// Apply the behavior
$(formSelector).submit(function(e) {
e.preventDefault();
if (opts.validate && opts.validate() == false) { return false;}
// formToDeepJSON acts on localFormDoc by reference
formToDeepJSON(this, opts.fields, localFormDoc);
if (opts.beforeSave) {opts.beforeSave(localFormDoc);}
db.saveDoc(localFormDoc, {
success : function(resp) {
if (opts.success) {opts.success(resp, localFormDoc);}
}
});
return false;
});
// populate form from an existing doc
function docToForm(doc) {
var form = $(formSelector);
// fills in forms
opts.fields.forEach(function(field) {
var parts = field.split('-');
var run = true, frontObj = doc, frontName = parts.shift();
while (frontObj && parts.length > 0) {
frontObj = frontObj[frontName];
frontName = parts.shift();
}
if (frontObj && frontObj[frontName]) {
var element = form.find("[name="+field+"]");
if (element.attr('type') === 'checkbox') {
element.attr('checked', frontObj[frontName]);
} else {
element.val(frontObj[frontName]);
}
}
});
}
if (opts.id) {
db.openDoc(opts.id, {
attachPrevRev : opts.attachPrevRev,
error: function() {
if (opts.error) {opts.error.apply(opts, arguments);}
},
success: function(doc) {
if (opts.load || opts.onLoad) {(opts.load || opts.onLoad)(doc);}
localFormDoc = doc;
docToForm(doc);
}});
} else if (opts.template) {
if (opts.load || opts.onLoad) {(opts.load || opts.onLoad)(opts.template);}
localFormDoc = opts.template;
docToForm(localFormDoc);
}
var instance = {
deleteDoc : function(opts) {
opts = opts || {};
if (confirm("Really delete this document?")) {
db.removeDoc(localFormDoc, opts);
}
},
localDoc : function() {
formToDeepJSON(formSelector, opts.fields, localFormDoc);
return localFormDoc;
}
};
return instance;
}
function resolveModule(names, parent, current) {
if (names.length === 0) {
if (typeof current != "string") {
throw ["error","invalid_require_path",
'Must require a JavaScript string, not: '+(typeof current)];
}
return [current, parent];
}
// we need to traverse the path
var n = names.shift();
if (n == '..') {
if (!(parent && parent.parent)) {
throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)];
}
return resolveModule(names, parent.parent.parent, parent.parent);
} else if (n == '.') {
if (!parent) {
throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)];
}
return resolveModule(names, parent.parent, parent);
}
if (!current[n]) {
throw ["error", "invalid_require_path", 'Object has no property "'+n+'". '+JSON.stringify(current)];
}
var p = current;
current = current[n];
current.parent = p;
return resolveModule(names, p, current);
}
var p = document.location.pathname.split('/');
p.shift();
var qs = document.location.search.replace(/^\?/,'').split('&');
var q = {};
qs.forEach(function(param) {
var ps = param.split('=');
var k = decodeURIComponent(ps[0]);
var v = decodeURIComponent(ps[1]);
if (["startkey", "endkey", "key"].indexOf(k) != -1) {
q[k] = JSON.parse(v);
} else {
q[k] = v;
}
});
var mockReq = {
path : p,
query : q
};
var appExports = $.extend({
db : db,
design : design,
view : design.view,
list : design.list,
docForm : docForm,
req : mockReq
}, $.couch.app.app);
function handleDDoc(ddoc) {
var moduleCache = [];
function getCachedModule(name, parent) {
var key, i, len = moduleCache.length;
for (i=0;i<len;++i) {
key = moduleCache[i].key;
if (key[0] === name && key[1] === parent) {
return moduleCache[i].module;
}
}
return null;
}
function setCachedModule(name, parent, module) {
moduleCache.push({ key: [name, parent], module: module });
}
if (ddoc) {
var require = function(name, parent) {
var cachedModule = getCachedModule(name, parent);
if (cachedModule !== null) {
return cachedModule;
}
var exports = {};
var resolved = resolveModule(name.split('/'), parent, ddoc);
var source = resolved[0];
parent = resolved[1];
var s = "var func = function (exports, require) { " + source + " };";
try {
eval(s);
func.apply(ddoc, [exports, function(name) {return require(name, parent, source)}]);
} catch(e) {
throw ["error","compilation_error","Module require('"+name+"') raised error "+e.toSource()];
}
setCachedModule(name, parent, exports);
return exports;
}
appExports.ddoc = ddoc;
appExports.require = require;
}
// todo make app-exports the this in the execution context?
appFun.apply(appExports, [appExports]);
}
if ($.couch.app.ddocs[design.doc_id]) {
handleDDoc($.couch.app.ddocs[design.doc_id])
} else {
// only open 1 connection for this ddoc
if ($.couch.app.ddoc_handlers[design.doc_id]) {
// we are already fetching, just wait
$.couch.app.ddoc_handlers[design.doc_id].push(handleDDoc);
} else {
$.couch.app.ddoc_handlers[design.doc_id] = [handleDDoc];
db.openDoc(design.doc_id, {
success : function(doc) {
$.couch.app.ddocs[design.doc_id] = doc;
$.couch.app.ddoc_handlers[design.doc_id].forEach(function(h) {
h(doc);
});
$.couch.app.ddoc_handlers[design.doc_id] = null;
},
error : function() {
$.couch.app.ddoc_handlers[design.doc_id].forEach(function(h) {
h();
});
$.couch.app.ddoc_handlers[design.doc_id] = null;
}
});
}
}
});
};
$.couch.app.ddocs = {};
$.couch.app.ddoc_handlers = {};
// legacy support. $.CouchApp is deprecated, please use $.couch.app
$.CouchApp = $.couch.app;
})(jQuery);
// JavaScript 1.6 compatibility functions that are missing from IE7/IE8
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
$.log = function(m) {
if (window && window.console && window.console.log) {
window.console.log(arguments.length == 1 ? m : arguments);
}
};
// http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery/1186309#1186309
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
// todo remove this crap
function escapeHTML(st) {
return(
st && st.replace(/&/g,'&amp;').
replace(/>/g,'&gt;').
replace(/</g,'&lt;').
replace(/"/g,'&quot;')
);
};
function safeHTML(st, len) {
return st ? escapeHTML(st.substring(0,len)) : '';
}
// todo this should take a replacement template
$.linkify = function(body) {
return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
return '<a target="_blank" href="'+a+'">'+a+'</a>';
}).replace(/\@([\w\-]+)/g,function(user,name) {
return '<a href="#/mentions/'+encodeURIComponent(name.toLowerCase())+'">'+user+'</a>';
}).replace(/\#([\w\-\.]+)/g,function(word,tag) {
return '<a href="#/tags/'+encodeURIComponent(tag.toLowerCase())+'">'+word+'</a>';
});
};
$.fn.prettyDate = function() {
$(this).each(function() {
$(this).text($.prettyDate($(this).text()));
});
};
$.prettyDate = function(time){
var date = new Date(time.replace(/-/g,"/").replace("T", " ").replace("Z", " +0000").replace(/(\d*\:\d*:\d*)\.\d*/g,"$1")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff)) return time;
return day_diff < 1 && (
diff < 60 && "just now" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
day_diff == 1 && "yesterday" ||
day_diff < 21 && day_diff + " days ago" ||
day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
Math.ceil( day_diff / 365 ) + " years ago";
};
$.argsToArray = function(args) {
if (!args.callee) return args;
var array = [];
for (var i=0; i < args.length; i++) {
array.push(args[i]);
};
return array;
}
// $$ inspired by @wycats: http://yehudakatz.com/2009/04/20/evented-programming-with-jquery/
function $$(node) {
var data = $(node).data("$$");
if (data) {
return data;
} else {
data = {};
$(node).data("$$", data);
return data;
}
};
(function($) {
// utility functions used in the implementation
function forIn(obj, fun) {
var name;
for (name in obj) {
if (obj.hasOwnProperty(name)) {
fun(name, obj[name]);
}
}
};
$.forIn = forIn;
function funViaString(fun) {
if (fun && fun.match && fun.match(/^function/)) {
eval("var f = "+fun);
if (typeof f == "function") {
return function() {
try {
return f.apply(this, arguments);
} catch(e) {
// IF YOU SEE AN ERROR HERE IT HAPPENED WHEN WE TRIED TO RUN YOUR FUNCTION
$.log({"message": "Error in evently function.", "error": e, "src" : fun});
throw(e);
}
};
}
}
return fun;
};
function runIfFun(me, fun, args) {
// if the field is a function, call it, bound to the widget
var f = funViaString(fun);
if (typeof f == "function") {
return f.apply(me, args);
} else {
return fun;
}
}
$.evently = {
connect : function(source, target, events) {
events.forEach(function(ev) {
$(source).bind(ev, function() {
var args = $.makeArray(arguments);
// remove the original event to keep from stacking args extra deep
// it would be nice if jquery had a way to pass the original
// event to the trigger method.
args.shift();
$(target).trigger(ev, args);
return false;
});
});
},
paths : [],
changesDBs : {},
changesOpts : {}
};
function extractFrom(name, evs) {
return evs[name];
};
function extractEvents(name, ddoc) {
// extract events from ddoc.evently and ddoc.vendor.*.evently
var events = [true, {}];
$.forIn(ddoc.vendor, function(k, v) {
if (v.evently && v.evently[name]) {
events.push(v.evently[name]);
}
});
if (ddoc.evently[name]) {events.push(ddoc.evently[name]);}
return $.extend.apply(null, events);
}
$.fn.evently = function(events, app, args) {
var elem = $(this);
// store the app on the element for later use
if (app) {
$$(elem).app = app;
}
if (typeof events == "string") {
events = extractEvents(events, app.ddoc);
}
$$(elem).evently = events;
// setup the handlers onto elem
forIn(events, function(name, h) {
eventlyHandler(elem, name, h, args);
});
if (events._init) {
// $.log("ev _init", elem);
elem.trigger("_init", args);
}
if (app && events._changes) {
$("body").bind("evently-changes-"+app.db.name, function() {
// we want to unbind this function when the element is deleted.
// maybe jquery 1.4.2 has this covered?
// $.log('changes', elem);
elem.trigger("_changes");
});
followChanges(app);
elem.trigger("_changes");
}
};
// eventlyHandler applies the user's handler (h) to the
// elem, bound to trigger based on name.
function eventlyHandler(elem, name, h, args) {
if (h.path) {
elem.pathbinder(name, h.path);
}
var f = funViaString(h);
if (typeof f == "function") {
elem.bind(name, {args:args}, f);
} else if (typeof f == "string") {
elem.bind(name, {args:args}, function() {
$(this).trigger(f, arguments);
return false;
});
} else if ($.isArray(h)) {
// handle arrays recursively
for (var i=0; i < h.length; i++) {
eventlyHandler(elem, name, h[i], args);
}
} else {
// an object is using the evently / mustache template system
if (h.fun) {
elem.bind(name, {args:args}, funViaString(h.fun));
}
// templates, selectors, etc are intepreted
// when our named event is triggered.
elem.bind(name, {args:args}, function() {
renderElement($(this), h, arguments);
return false;
});
}
};
$.fn.replace = function(elem) {
// $.log("Replace", this)
$(this).empty().append(elem);
};
// todo: ability to call this
// to render and "prepend/append/etc" a new element to the host element (me)
// as well as call this in a way that replaces the host elements content
// this would be easy if there is a simple way to get at the element we just appended
// (as html) so that we can attache the selectors
function renderElement(me, h, args, qrun, arun) {
// if there's a query object we run the query,
// and then call the data function with the response.
if (h.before && (!qrun || !arun)) {
funViaString(h.before).apply(me, args);
}
if (h.async && !arun) {
runAsync(me, h, args)
} else if (h.query && !qrun) {
// $.log("query before renderElement", arguments)
runQuery(me, h, args)
} else {
// $.log("renderElement")
// $.log(me, h, args, qrun)
// otherwise we just render the template with the current args
var selectors = runIfFun(me, h.selectors, args);
var act = (h.render || "replace").replace(/\s/g,"");
var app = $$(me).app;
if (h.mustache) {
// $.log("rendering", h.mustache)
var newElem = mustachioed(me, h, args);
me[act](newElem);
}
if (selectors) {
if (act == "replace") {
var s = me;
} else {
var s = newElem;
}
forIn(selectors, function(selector, handlers) {
// $.log("selector", selector);
// $.log("selected", $(selector, s));
$(selector, s).evently(handlers, app, args);
// $.log("applied", selector);
});
}
if (h.after) {
runIfFun(me, h.after, args);
// funViaString(h.after).apply(me, args);
}
}
};
// todo this should return the new element
function mustachioed(me, h, args) {
return $($.mustache(
runIfFun(me, h.mustache, args),
runIfFun(me, h.data, args),
runIfFun(me, h.partials, args)));
};
function runAsync(me, h, args) {
// the callback is the first argument
funViaString(h.async).apply(me, [function() {
renderElement(me, h,
$.argsToArray(arguments).concat($.argsToArray(args)), false, true);
}].concat($.argsToArray(args)));
};
function runQuery(me, h, args) {
// $.log("runQuery: args", args)
var app = $$(me).app;
var qu = runIfFun(me, h.query, args);
var qType = qu.type;
var viewName = qu.view;
var userSuccess = qu.success;
// $.log("qType", qType)
var q = {};
forIn(qu, function(k, v) {
q[k] = v;
});
if (qType == "newRows") {
q.success = function(resp) {
// $.log("runQuery newRows success", resp.rows.length, me, resp)
resp.rows.reverse().forEach(function(row) {
renderElement(me, h, [row].concat($.argsToArray(args)), true)
});
if (userSuccess) userSuccess(resp);
};
newRows(me, app, viewName, q);
} else {
q.success = function(resp) {
// $.log("runQuery success", resp)
renderElement(me, h, [resp].concat($.argsToArray(args)), true);
userSuccess && userSuccess(resp);
};
// $.log(app)
app.view(viewName, q);
}
}
// this is for the items handler
// var lastViewId, highKey, inFlight;
// this needs to key per elem
function newRows(elem, app, view, opts) {
// $.log("newRows", arguments);
// on success we'll set the top key
var thisViewId, successCallback = opts.success, full = false;
function successFun(resp) {
// $.log("newRows success", resp)
$$(elem).inFlight = false;
var JSONhighKey = JSON.stringify($$(elem).highKey);
resp.rows = resp.rows.filter(function(r) {
return JSON.stringify(r.key) != JSONhighKey;
});
if (resp.rows.length > 0) {
if (opts.descending) {
$$(elem).highKey = resp.rows[0].key;
} else {
$$(elem).highKey = resp.rows[resp.rows.length -1].key;
}
};
if (successCallback) {successCallback(resp, full)};
};
opts.success = successFun;
if (opts.descending) {
thisViewId = view + (opts.startkey ? JSON.stringify(opts.startkey) : "");
} else {
thisViewId = view + (opts.endkey ? JSON.stringify(opts.endkey) : "");
}
// $.log(["thisViewId",thisViewId])
// for query we'll set keys
if (thisViewId == $$(elem).lastViewId) {
// we only want the rows newer than changesKey
var hk = $$(elem).highKey;
if (hk !== undefined) {
if (opts.descending) {
opts.endkey = hk;
// opts.inclusive_end = false;
} else {
opts.startkey = hk;
}
}
// $.log("add view rows", opts)
if (!$$(elem).inFlight) {
$$(elem).inFlight = true;
app.view(view, opts);
}
} else {
// full refresh
// $.log("new view stuff")
full = true;
$$(elem).lastViewId = thisViewId;
$$(elem).highKey = undefined;
$$(elem).inFlight = true;
app.view(view, opts);
}
};
// only start one changes listener per db
function followChanges(app) {
var dbName = app.db.name, changeEvent = function(resp) {
$("body").trigger("evently-changes-"+dbName, [resp]);
};
if (!$.evently.changesDBs[dbName]) {
if (app.db.changes) {
// new api in jquery.couch.js 1.0
app.db.changes(null, $.evently.changesOpts).onChange(changeEvent);
} else {
// in case you are still on CouchDB 0.11 ;) deprecated.
connectToChanges(app, changeEvent);
}
$.evently.changesDBs[dbName] = true;
}
}
$.evently.followChanges = followChanges;
// deprecated. use db.changes() from jquery.couch.js
// this does not have an api for closing changes request.
function connectToChanges(app, fun, update_seq) {
function changesReq(seq) {
var url = app.db.uri+"_changes?heartbeat=10000&feed=longpoll&since="+seq;
if ($.evently.changesOpts.include_docs) {
url = url + "&include_docs=true";
}
$.ajax({
url: url,
contentType: "application/json",
dataType: "json",
complete: function(req) {
var resp = $.httpData(req, "json");
fun(resp);
connectToChanges(app, fun, resp.last_seq);
}
});
};
if (update_seq) {
changesReq(update_seq);
} else {
app.db.info({success: function(db_info) {
changesReq(db_info.update_seq);
}});
}
};
})(jQuery);
/*
Shameless port of a shameless port
@defunkt => @janl => @aq
See http://github.com/defunkt/mustache for more info.
*/
;(function($) {
/*
mustache.js — Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
var Renderer = function() {};
Renderer.prototype = {
otag: "{{",
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
this.send(template);
return;
}
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
}
this.render_tags(html, context, partials, in_recursion);
},
/*
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
}
},
/*
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
// no pragmas
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
that.pragmas[pragma][opts[0]] = opts[1];
}
return "";
// ignore unknown pragmas silently
});
},
/*
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
var dels = delimiters.split(" ");
this.otag = this.escape_regex(dels[0]);
this.ctag = this.escape_regex(dels[1]);
},
escape_regex: function(text) {
// thank you Simon Willison
if(!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
var value;
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unkown variables
return "";
},
// Utility methods
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '\"';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context;
return ctx;
}
},
is_object: function(a) {
return a && typeof a == "object";
},
is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},
/*
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
}
}
};
return({
name: "mustache.js",
version: "0.3.1-dev",
/*
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}
},
escape : function(text) {
return new Renderer().escape(text);
}
});
}();
$.mustache = function(template, view, partials) {
return Mustache.to_html(template, view, partials);
};
$.mustache.escape = function(text) {
return Mustache.escape(text);
};
})(jQuery);
(function($) {
// functions for handling the path
// thanks sammy.js
var PATH_REPLACER = "([^\/]+)",
PATH_NAME_MATCHER = /:([\w\d]+)/g,
QUERY_STRING_MATCHER = /\?([^#]*)$/,
SPLAT_MATCHER = /(\*)/,
SPLAT_REPLACER = "(.+)",
_currentPath,
_lastPath,
_pathInterval;
function hashChanged() {
_currentPath = getPath();
// if path is actually changed from what we thought it was, then react
if (_lastPath != _currentPath) {
_lastPath = _currentPath;
return triggerOnPath(_currentPath);
}
}
$.pathbinder = {
changeFuns : [],
paths : [],
begin : function(defaultPath) {
// this should trigger the defaultPath if there's not a path in the URL
// otherwise it should trigger the URL's path
$(function() {
var loadPath = getPath();
if (loadPath) {
triggerOnPath(loadPath);
} else {
goPath(defaultPath);
triggerOnPath(defaultPath);
}
})
},
go : function(path) {
goPath(path);
triggerOnPath(path);
},
currentPath : function() {
return getPath();
},
onChange : function (fun) {
$.pathbinder.changeFuns.push(fun);
}
};
function pollPath(every) {
function hashCheck() {
_currentPath = getPath();
// path changed if _currentPath != _lastPath
if (_lastPath != _currentPath) {
setTimeout(function() {
$(window).trigger('hashchange');
}, 1);
}
};
hashCheck();
_pathInterval = setInterval(hashCheck, every);
$(window).bind('unload', function() {
clearInterval(_pathInterval);
});
}
function triggerOnPath(path) {
path = path.replace(/^#/,'');
$.pathbinder.changeFuns.forEach(function(fun) {fun(path)});
var pathSpec, path_params, params = {}, param_name, param;
for (var i=0; i < $.pathbinder.paths.length; i++) {
pathSpec = $.pathbinder.paths[i];
// $.log("pathSpec", pathSpec);
if ((path_params = pathSpec.matcher.exec(path)) !== null) {
// $.log("path_params", path_params);
path_params.shift();
for (var j=0; j < path_params.length; j++) {
param_name = pathSpec.param_names[j];
param = decodeURIComponent(path_params[j]);
if (param_name) {
params[param_name] = param;
} else {
if (!params.splat) params.splat = [];
params.splat.push(param);
}
};
pathSpec.callback(params);
// return true; // removed this to allow for multi match
}
};
};
// bind the event
$(function() {
if ('onhashchange' in window) {
// we have a native event
} else {
pollPath(10);
}
// setTimeout(hashChanged,50);
$(window).bind('hashchange', hashChanged);
});
function registerPath(pathSpec) {
$.pathbinder.paths.push(pathSpec);
};
function setPath(pathSpec, params) {
var newPath = $.mustache(pathSpec.template, params);
goPath(newPath);
};
function goPath(newPath) {
// $.log("goPath", newPath)
window.location = '#'+newPath;
_lastPath = getPath();
};
function getPath() {
var matches = window.location.toString().match(/^[^#]*(#.+)$/);
return matches ? matches[1] : '';
};
function makePathSpec(path, callback) {
var param_names = [];
var template = "";
PATH_NAME_MATCHER.lastIndex = 0;
while ((path_match = PATH_NAME_MATCHER.exec(path)) !== null) {
param_names.push(path_match[1]);
}
return {
param_names : param_names,
matcher : new RegExp("^" + path.replace(
PATH_NAME_MATCHER, PATH_REPLACER).replace(
SPLAT_MATCHER, SPLAT_REPLACER) + "/?$"),
template : path.replace(PATH_NAME_MATCHER, function(a, b) {
return '{{'+b+'}}';
}).replace(SPLAT_MATCHER, '{{splat}}'),
callback : callback
};
};
$.fn.pathbinder = function(name, paths, options) {
options = options || {};
var self = $(this), pathList = paths.split(/\n/);
$.each(pathList, function() {
var path = this;
if (path) {
// $.log("bind path", path);
var pathSpec = makePathSpec(path, function(params) {
// $.log("path cb", name, path, self)
// $.log("trigger path: "+path+" params: ", params);
self.trigger(name, [params]);
});
// set the path when the event triggered through other means
if (options.bindPath) {
self.bind(name, function(ev, params) {
params = params || {};
// $.log("set path", name, pathSpec)
setPath(pathSpec, params);
});
}
// trigger when the path matches
registerPath(pathSpec);
}
});
};
})(jQuery);
#!/usr/bin/env python
"""
converts a JavaScipt file to a plugin tiddler (JSON format)
"""
import sys
import json
from urllib2 import urlopen
def main(args):
args = [unicode(arg, "utf-8") for arg in args]
uri = args[1]
try:
f = open(uri)
source = f.read()
f.close()
except IOError:
source = urlopen(uri).read()
filename = uri.rsplit("/", 1)[1]
tiddler = {
"title": filename.rsplit(".", 1)[0],
"tags": ["systemConfig"],
"text": source
}
print json.dumps(tiddler)
return True
if __name__ == "__main__":
status = not main(sys.argv)
sys.exit(status)
javascript
// this code makes http://example.com into a link,
// and also handles @name and #hashtag
// todo add [[wiki_links]]
var mustache = require("vendor/couchapp/lib/mustache");
exports.encode = function(body, person_prefix, tag_prefix) {
body = mustache.escape(body);
person_prefix = person_prefix || "http://twitter.com/";
tag_prefix = tag_prefix || "http://delicious.com/tag/";
return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
return '<a target="_blank" href="'+a+'">'+a+'</a>';
}).replace(/\@([\w\-]+)/g,function(user,name) {
return '<a href="'+person_prefix+encodeURIComponent(name.toLowerCase())+'">'+user+'</a>';
}).replace(/\#([\w\-\.]+)/g,function(word,tag) {
return '<a href="'+tag_prefix+encodeURIComponent(tag.toLowerCase())+'">'+word+'</a>';
});
};
// Helpers for writing server-side _list functions in CouchDB
exports.withRows = function(fun) {
var f = function() {
var row = getRow();
return row && fun(row);
};
f.iterator = true;
return f;
}
exports.send = function(chunk) {
send(chunk + "\n")
}
function couchapp_load(scripts) {
for (var i=0; i < scripts.length; i++) {
document.write('<script src="'+scripts[i]+'"><\/script>')
};
};
couchapp_load([
"/_utils/script/sha1.js",
"/_utils/script/json2.js",
"/_utils/script/jquery.js",
"/_utils/script/jquery.couch.js",
"vendor/couchapp/jquery.couch.app.js",
"vendor/couchapp/jquery.couch.app.util.js",
"vendor/couchapp/jquery.mustache.js",
"vendor/couchapp/jquery.evently.js"
]);
function(e, r) {
var userCtx = r.userCtx;
var widget = $(this);
// load the profile from the user doc
var db = $.couch.db(r.info.authentication_db);
var userDocId = "org.couchdb.user:"+userCtx.name;
db.openDoc(userDocId, {
success : function(userDoc) {
var profile = userDoc["couch.app.profile"];
if (profile) {
// we copy the name to the profile so it can be used later
// without publishing the entire userdoc (roles, pass, etc)
profile.name = userDoc.name;
$$(widget).profile = profile;
widget.trigger("profileReady", [profile]);
} else {
widget.trigger("noProfile", [userCtx]);
}
}
});
}
/* add styles here */
body {
font:1em Helvetica, sans-serif;
padding:4px;
}
h1 {
margin-top:0;
}
#account {
float:right;
}
#profile {
border:4px solid #edd;
background:#fee;
padding:8px;
margin-bottom:8px;
}
#items {
border:4px solid #dde;
background:#eef;
padding:8px;
width:60%;
float:left;
}
#sidebar {
border:4px solid #dfd;
padding:8px;
float:right;
width:30%;
}
#items li {
border:4px solid #f5f5ff;
background:#fff;
padding:8px;
margin:4px 0;
}
form {
padding:4px;
margin:6px;
background-color:#ddd;
}
div.avatar {
padding:2px;
padding-bottom:0;
margin-right:4px;
float:left;
font-size:0.78em;
width : 60px;
height : 60px;
text-align: center;
}
div.avatar .name {
padding-top:2px;
}
div.avatar img {
margin:0 auto;
padding:0;
width : 40px;
height : 40px;
}
#items ul {
list-style: none;
}
function(doc) {
if(doc.title && doc.text) {
emit(doc.title, doc);
}
}
//
// showdown.js -- A javascript port of Markdown.
//
// Copyright (c) 2007 John Fraser.
//
// Original Markdown Copyright (c) 2004-2005 John Gruber
// <http://daringfireball.net/projects/markdown/>
//
// Redistributable under a BSD-style open source license.
// See license.txt for more information.
//
// The full source distribution is at:
//
// A A L
// T C A
// T K B
//
// <http://www.attacklab.net/>
//
//
// Wherever possible, Showdown is a straight, line-by-line port
// of the Perl version of Markdown.
//
// This is not a normal parser design; it's basically just a
// series of string substitutions. It's hard to read and
// maintain this way, but keeping Showdown close to the original
// design makes it easier to port new features.
//
// More importantly, Showdown behaves like markdown.pl in most
// edge cases. So web applications can do client-side preview
// in Javascript, and then build identical HTML on the server.
//
// This port needs the new RegExp functionality of ECMA 262,
// 3rd Edition (i.e. Javascript 1.5). Most modern web browsers
// should do fine. Even with the new regular expression features,
// We do a lot of work to emulate Perl's regex functionality.
// The tricky changes in this file mostly have the "attacklab:"
// label. Major or self-explanatory changes don't.
//
// Smart diff tools like Araxis Merge will be able to match up
// this file with markdown.pl in a useful way. A little tweaking
// helps: in a copy of markdown.pl, replace "#" with "//" and
// replace "$text" with "text". Be sure to ignore whitespace
// and line endings.
//
//
// Showdown usage:
//
// var text = "Markdown *rocks*.";
//
// var markdown = require("markdown");
// var html = markdown.encode(text);
//
// print(html);
//
// Note: move the sample code to the bottom of this
// file before uncommenting it.
//
//
// Globals:
//
// Global hashes, used by various utility routines
var g_urls;
var g_titles;
var g_html_blocks;
// Used to track when we're inside an ordered or unordered list
// (see _ProcessListItems() for details):
var g_list_level = 0;
exports.makeHtml = function(text) {
//
// Main function. The order in which other subs are called here is
// essential. Link and image substitutions need to happen before
// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
// and <img> tags get encoded.
//
// Clear the global hashes. If we don't clear these, you get conflicts
// from other articles when generating a page which contains more than
// one article (e.g. an index page that shows the N most recent
// articles):
g_urls = new Array();
g_titles = new Array();
g_html_blocks = new Array();
// attacklab: Replace ~ with ~T
// This lets us use tilde as an escape char to avoid md5 hashes
// The choice of character is arbitray; anything that isn't
// magic in Markdown will work.
text = text.replace(/~/g,"~T");
// attacklab: Replace $ with ~D
// RegExp interprets $ as a special character
// when it's in a replacement string
text = text.replace(/\$/g,"~D");
// Standardize line endings
text = text.replace(/\r\n/g,"\n"); // DOS to Unix
text = text.replace(/\r/g,"\n"); // Mac to Unix
// Make sure text begins and ends with a couple of newlines:
text = "\n\n" + text + "\n\n";
// Convert all tabs to spaces.
text = _Detab(text);
// Strip any lines consisting only of spaces and tabs.
// This makes subsequent regexen easier to write, because we can
// match consecutive blank lines with /\n+/ instead of something
// contorted like /[ \t]*\n+/ .
text = text.replace(/^[ \t]+$/mg,"");
// Turn block-level HTML blocks into hash entries
text = _HashHTMLBlocks(text);
// Strip link definitions, store in hashes.
text = _StripLinkDefinitions(text);
text = _RunBlockGamut(text);
text = _UnescapeSpecialChars(text);
// attacklab: Restore dollar signs
text = text.replace(/~D/g,"$$");
// attacklab: Restore tildes
text = text.replace(/~T/g,"~");
return text;
}
var _StripLinkDefinitions = function(text) {
//
// Strips link definitions from text, stores the URLs and titles in
// hash references.
//
// Link defs are in the form: ^[id]: url "optional title"
/*
var text = text.replace(/
^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
[ \t]*
\n? // maybe *one* newline
[ \t]*
<?(\S+?)>? // url = $2
[ \t]*
\n? // maybe one newline
[ \t]*
(?:
(\n*) // any lines skipped = $3 attacklab: lookbehind removed
["(]
(.+?) // title = $4
[")]
[ \t]*
)? // title is optional
(?:\n+|$)
/gm,
function(){...});
*/
var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|\Z)/gm,
function (wholeMatch,m1,m2,m3,m4) {
m1 = m1.toLowerCase();
g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive
if (m3) {
// Oops, found blank lines, so it's not a title.
// Put back the parenthetical statement we stole.
return m3+m4;
} else if (m4) {
g_titles[m1] = m4.replace(/"/g,"&quot;");
}
// Completely remove the definition from the text
return "";
}
);
return text;
}
var _HashHTMLBlocks = function(text) {
// attacklab: Double up blank lines to reduce lookaround
text = text.replace(/\n/g,"\n\n");
// Hashify HTML blocks:
// We only want to do this for block-level HTML tags, such as headers,
// lists, and tables. That's because we still want to wrap <p>s around
// "paragraphs" that are wrapped in non-block-level tags, such as anchors,
// phrase emphasis, and spans. The list of tags we're looking for is
// hard-coded:
var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"
var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"
// First, look for nested blocks, e.g.:
// <div>
// <div>
// tags for inner block must be indented.
// </div>
// </div>
//
// The outermost tags must start at the left margin for this to match, and
// the inner nested divs must be indented.
// We need to do this before the next, more liberal match, because the next
// match will start at the first `<div>` and stop at the first `</div>`.
// attacklab: This regex can be expensive when it fails.
/*
var text = text.replace(/
( // save in $1
^ // start of line (with /m)
<($block_tags_a) // start tag = $2
\b // word break
// attacklab: hack around khtml/pcre bug...
[^\r]*?\n // any number of lines, minimally matching
</\2> // the matching end tag
[ \t]* // trailing spaces/tabs
(?=\n+) // followed by a newline
) // attacklab: there are sentinel newlines at end of document
/gm,function(){...}};
*/
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,hashElement);
//
// Now match more liberally, simply from `\n<tag>` to `</tag>\n`
//
/*
var text = text.replace(/
( // save in $1
^ // start of line (with /m)
<($block_tags_b) // start tag = $2
\b // word break
// attacklab: hack around khtml/pcre bug...
[^\r]*? // any number of lines, minimally matching
.*</\2> // the matching end tag
[ \t]* // trailing spaces/tabs
(?=\n+) // followed by a newline
) // attacklab: there are sentinel newlines at end of document
/gm,function(){...}};
*/
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);
// Special case just for <hr />. It was easier to make a special case than
// to make the other regex more complicated.
/*
text = text.replace(/
( // save in $1
\n\n // Starting after a blank line
[ ]{0,3}
(<(hr) // start tag = $2
\b // word break
([^<>])*? //
\/?>) // the matching end tag
[ \t]*
(?=\n{2,}) // followed by a blank line
)
/g,hashElement);
*/
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);
// Special case for standalone HTML comments:
/*
text = text.replace(/
( // save in $1
\n\n // Starting after a blank line
[ ]{0,3} // attacklab: g_tab_width - 1
<!
(--[^\r]*?--\s*)+
>
[ \t]*
(?=\n{2,}) // followed by a blank line
)
/g,hashElement);
*/
text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
/*
text = text.replace(/
(?:
\n\n // Starting after a blank line
)
( // save in $1
[ ]{0,3} // attacklab: g_tab_width - 1
(?:
<([?%]) // $2
[^\r]*?
\2>
)
[ \t]*
(?=\n{2,}) // followed by a blank line
)
/g,hashElement);
*/
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);
// attacklab: Undo double lines (see comment at top of this function)
text = text.replace(/\n\n/g,"\n");
return text;
}
var hashElement = function(wholeMatch,m1) {
var blockText = m1;
// Undo double lines
blockText = blockText.replace(/\n\n/g,"\n");
blockText = blockText.replace(/^\n/,"");
// strip trailing blank lines
blockText = blockText.replace(/\n+$/g,"");
// Replace the element text with a marker ("~KxK" where x is its key)
blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
return blockText;
};
var _RunBlockGamut = function(text) {
//
// These are all the transformations that form block-level
// tags like paragraphs, headers, and list items.
//
text = _DoHeaders(text);
// Do Horizontal Rules:
var key = hashBlock("<hr />");
text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
text = _DoLists(text);
text = _DoCodeBlocks(text);
text = _DoBlockQuotes(text);
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
// was to escape raw HTML in the original Markdown source. This time,
// we're escaping the markup we've just created, so that we don't wrap
// <p> tags around block-level tags.
text = _HashHTMLBlocks(text);
text = _FormParagraphs(text);
return text;
}
var _RunSpanGamut = function(text) {
//
// These are all the transformations that occur *within* block-level
// tags like paragraphs, headers, and list items.
//
text = _DoCodeSpans(text);
text = _EscapeSpecialCharsWithinTagAttributes(text);
text = _EncodeBackslashEscapes(text);
// Process anchor and image tags. Images must come first,
// because ![foo][f] looks like an anchor.
text = _DoImages(text);
text = _DoAnchors(text);
// Make links out of things like `<http://example.com/>`
// Must come after _DoAnchors(), because you can use < and >
// delimiters in inline links like [this](<url>).
text = _DoAutoLinks(text);
text = _EncodeAmpsAndAngles(text);
text = _DoItalicsAndBold(text);
// Do hard breaks:
text = text.replace(/ +\n/g," <br />\n");
return text;
}
var _EscapeSpecialCharsWithinTagAttributes = function(text) {
//
// Within tags -- meaning between < and > -- encode [\ ` * _] so they
// don't conflict with their use in Markdown for code, italics and strong.
//
// Build a regex to find HTML tags and comments. See Friedl's
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
text = text.replace(regex, function(wholeMatch) {
var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
tag = escapeCharacters(tag,"\\`*_");
return tag;
});
return text;
}
var _DoAnchors = function(text) {
//
// Turn Markdown link shortcuts into XHTML <a> tags.
//
//
// First, handle reference-style links: [link text] [id]
//
/*
text = text.replace(/
( // wrap whole match in $1
\[
(
(?:
\[[^\]]*\] // allow brackets nested one level
|
[^\[] // or anything else
)*
)
\]
[ ]? // one optional space
(?:\n[ ]*)? // one optional newline followed by spaces
\[
(.*?) // id = $3
\]
)()()()() // pad remaining backreferences
/g,_DoAnchors_callback);
*/
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
//
// Next, inline-style links: [link text](url "optional title")
//
/*
text = text.replace(/
( // wrap whole match in $1
\[
(
(?:
\[[^\]]*\] // allow brackets nested one level
|
[^\[\]] // or anything else
)
)
\]
\( // literal paren
[ \t]*
() // no id, so leave $3 empty
<?(.*?)>? // href = $4
[ \t]*
( // $5
(['"]) // quote char = $6
(.*?) // Title = $7
\6 // matching quote
[ \t]* // ignore any spaces/tabs between closing quote and )
)? // title is optional
\)
)
/g,writeAnchorTag);
*/
text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
//
// Last, handle reference-style shortcuts: [link text]
// These must come last in case you've also got [link test][1]
// or [link test](/foo)
//
/*
text = text.replace(/
( // wrap whole match in $1
\[
([^\[\]]+) // link text = $2; can't contain '[' or ']'
\]
)()()()()() // pad rest of backreferences
/g, writeAnchorTag);
*/
text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
return text;
}
var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
if (m7 == undefined) m7 = "";
var whole_match = m1;
var link_text = m2;
var link_id = m3.toLowerCase();
var url = m4;
var title = m7;
if (url == "") {
if (link_id == "") {
// lower-case and turn embedded newlines into spaces
link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
}
url = "#"+link_id;
if (g_urls[link_id] != undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
title = g_titles[link_id];
}
}
else {
if (whole_match.search(/\(\s*\)$/m)>-1) {
// Special case for explicit empty url
url = "";
} else {
return whole_match;
}
}
}
url = escapeCharacters(url,"*_");
var result = "<a href=\"" + url + "\"";
if (title != "") {
title = title.replace(/"/g,"&quot;");
title = escapeCharacters(title,"*_");
result += " title=\"" + title + "\"";
}
result += ">" + link_text + "</a>";
return result;
}
var _DoImages = function(text) {
//
// Turn Markdown image shortcuts into <img> tags.
//
//
// First, handle reference-style labeled images: ![alt text][id]
//
/*
text = text.replace(/
( // wrap whole match in $1
!\[
(.*?) // alt text = $2
\]
[ ]? // one optional space
(?:\n[ ]*)? // one optional newline followed by spaces
\[
(.*?) // id = $3
\]
)()()()() // pad rest of backreferences
/g,writeImageTag);
*/
text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
//
// Next, handle inline images: ![alt text](url "optional title")
// Don't forget: encode * and _
/*
text = text.replace(/
( // wrap whole match in $1
!\[
(.*?) // alt text = $2
\]
\s? // One optional whitespace character
\( // literal paren
[ \t]*
() // no id, so leave $3 empty
<?(\S+?)>? // src url = $4
[ \t]*
( // $5
(['"]) // quote char = $6
(.*?) // title = $7
\6 // matching quote
[ \t]*
)? // title is optional
\)
)
/g,writeImageTag);
*/
text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
return text;
}
var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
var whole_match = m1;
var alt_text = m2;
var link_id = m3.toLowerCase();
var url = m4;
var title = m7;
if (!title) title = "";
if (url == "") {
if (link_id == "") {
// lower-case and turn embedded newlines into spaces
link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
}
url = "#"+link_id;
if (g_urls[link_id] != undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
title = g_titles[link_id];
}
}
else {
return whole_match;
}
}
alt_text = alt_text.replace(/"/g,"&quot;");
url = escapeCharacters(url,"*_");
var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
// attacklab: Markdown.pl adds empty title attributes to images.
// Replicate this bug.
//if (title != "") {
title = title.replace(/"/g,"&quot;");
title = escapeCharacters(title,"*_");
result += " title=\"" + title + "\"";
//}
result += " />";
return result;
}
var _DoHeaders = function(text) {
// Setext-style headers:
// Header 1
// ========
//
// Header 2
// --------
//
text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
function(wholeMatch,m1){return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>");});
text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
function(matchFound,m1){return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>");});
// atx-style headers:
// # Header 1
// ## Header 2
// ## Header 2 with closing hashes ##
// ...
// ###### Header 6
//
/*
text = text.replace(/
^(\#{1,6}) // $1 = string of #'s
[ \t]*
(.+?) // $2 = Header text
[ \t]*
\#* // optional closing #'s (not counted)
\n+
/gm, function() {...});
*/
text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
function(wholeMatch,m1,m2) {
var h_level = m1.length;
return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">");
});
return text;
}
// This declaration keeps Dojo compressor from outputting garbage:
var _ProcessListItems;
var _DoLists = function(text) {
//
// Form HTML ordered (numbered) and unordered (bulleted) lists.
//
// attacklab: add sentinel to hack around khtml/safari bug:
// http://bugs.webkit.org/show_bug.cgi?id=11231
text += "~0";
// Re-usable pattern to match any entirel ul or ol list:
/*
var whole_list = /
( // $1 = whole list
( // $2
[ ]{0,3} // attacklab: g_tab_width - 1
([*+-]|\d+[.]) // $3 = first list item marker
[ \t]+
)
[^\r]+?
( // $4
~0 // sentinel for workaround; should be $
|
\n{2,}
(?=\S)
(?! // Negative lookahead for another list item marker
[ \t]*
(?:[*+-]|\d+[.])[ \t]+
)
)
)/g
*/
var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
if (g_list_level) {
text = text.replace(whole_list,function(wholeMatch,m1,m2) {
var list = m1;
var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";
// Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary:
list = list.replace(/\n{2,}/g,"\n\n\n");;
var result = _ProcessListItems(list);
// Trim any trailing whitespace, to put the closing `</$list_type>`
// up on the preceding line, to get it past the current stupid
// HTML block parser. This is a hack to work around the terrible
// hack that is the HTML block parser.
result = result.replace(/\s+$/,"");
result = "<"+list_type+">" + result + "</"+list_type+">\n";
return result;
});
} else {
whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {
var runup = m1;
var list = m2;
var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
// Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary:
var list = list.replace(/\n{2,}/g,"\n\n\n");;
var result = _ProcessListItems(list);
result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
return result;
});
}
// attacklab: strip sentinel
text = text.replace(/~0/,"");
return text;
}
_ProcessListItems = function(list_str) {
//
// Process the contents of a single ordered or unordered list, splitting it
// into individual list items.
//
// The $g_list_level global keeps track of when we're inside a list.
// Each time we enter a list, we increment it; when we leave a list,
// we decrement. If it's zero, we're not in a list anymore.
//
// We do this because when we're not inside a list, we want to treat
// something like this:
//
// I recommend upgrading to version
// 8. Oops, now this line is treated
// as a sub-list.
//
// As a single paragraph, despite the fact that the second line starts
// with a digit-period-space sequence.
//
// Whereas when we're inside a list (or sub-list), that line will be
// treated as the start of a sub-list. What a kludge, huh? This is
// an aspect of Markdown's syntax that's hard to parse perfectly
// without resorting to mind-reading. Perhaps the solution is to
// change the syntax rules such that sub-lists must start with a
// starting cardinal number; e.g. "1." or "a.".
g_list_level++;
// trim trailing blank lines:
list_str = list_str.replace(/\n{2,}$/,"\n");
// attacklab: add sentinel to emulate \z
list_str += "~0";
/*
list_str = list_str.replace(/
(\n)? // leading line = $1
(^[ \t]*) // leading whitespace = $2
([*+-]|\d+[.]) [ \t]+ // list marker = $3
([^\r]+? // list item text = $4
(\n{1,2}))
(?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))
/gm, function(){...});
*/
list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
function(wholeMatch,m1,m2,m3,m4){
var item = m4;
var leading_line = m1;
var leading_space = m2;
if (leading_line || (item.search(/\n{2,}/)>-1)) {
item = _RunBlockGamut(_Outdent(item));
}
else {
// Recursion for sub-lists:
item = _DoLists(_Outdent(item));
item = item.replace(/\n$/,""); // chomp(item)
item = _RunSpanGamut(item);
}
return "<li>" + item + "</li>\n";
}
);
// attacklab: strip sentinel
list_str = list_str.replace(/~0/g,"");
g_list_level--;
return list_str;
}
var _DoCodeBlocks = function(text) {
//
// Process Markdown `<pre><code>` blocks.
//
/*
text = text.replace(text,
/(?:\n\n|^)
( // $1 = the code block -- one or more lines, starting with a space/tab
(?:
(?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
.*\n+
)+
)
(\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
/g,function(){...});
*/
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += "~0";
text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
function(wholeMatch,m1,m2) {
var codeblock = m1;
var nextChar = m2;
codeblock = _EncodeCode( _Outdent(codeblock));
codeblock = _Detab(codeblock);
codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
codeblock = "<pre><code>" + codeblock + "\n</code></pre>";
return hashBlock(codeblock) + nextChar;
}
);
// attacklab: strip sentinel
text = text.replace(/~0/,"");
return text;
}
var hashBlock = function(text) {
text = text.replace(/(^\n+|\n+$)/g,"");
return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
}
var _DoCodeSpans = function(text) {
//
// * Backtick quotes are used for <code></code> spans.
//
// * You can use multiple backticks as the delimiters if you want to
// include literal backticks in the code span. So, this input:
//
// Just type ``foo `bar` baz`` at the prompt.
//
// Will translate to:
//
// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
//
// There's no arbitrary limit to the number of backticks you
// can use as delimters. If you need three consecutive backticks
// in your code, use four for delimiters, etc.
//
// * You can use spaces to get literal backticks at the edges:
//
// ... type `` `bar` `` ...
//
// Turns to:
//
// ... type <code>`bar`</code> ...
//
/*
text = text.replace(/
(^|[^\\]) // Character before opening ` can't be a backslash
(`+) // $2 = Opening run of `
( // $3 = The code block
[^\r]*?
[^`] // attacklab: work around lack of lookbehind
)
\2 // Matching closer
(?!`)
/gm, function(){...});
*/
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
function(wholeMatch,m1,m2,m3,m4) {
var c = m3;
c = c.replace(/^([ \t]*)/g,""); // leading whitespace
c = c.replace(/[ \t]*$/g,""); // trailing whitespace
c = _EncodeCode(c);
return m1+"<code>"+c+"</code>";
});
return text;
}
var _EncodeCode = function(text) {
//
// Encode/escape certain characters inside Markdown code runs.
// The point is that in code, these characters are literals,
// and lose their special Markdown meanings.
//
// Encode all ampersands; HTML entities are not
// entities within a Markdown code span.
text = text.replace(/&/g,"&amp;");
// Do the angle bracket song and dance:
text = text.replace(/</g,"&lt;");
text = text.replace(/>/g,"&gt;");
// Now, escape characters that are magic in Markdown:
text = escapeCharacters(text,"\*_{}[]\\",false);
// jj the line above breaks this:
//---
//* Item
// 1. Subitem
// special char: *
//---
return text;
}
var _DoItalicsAndBold = function(text) {
// <strong> must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
"<strong>$2</strong>");
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
"<em>$2</em>");
return text;
}
var _DoBlockQuotes = function(text) {
/*
text = text.replace(/
( // Wrap whole match in $1
(
^[ \t]*>[ \t]? // '>' at the start of a line
.+\n // rest of the first line
(.+\n)* // subsequent consecutive lines
\n* // blanks
)+
)
/gm, function(){...});
*/
text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
function(wholeMatch,m1) {
var bq = m1;
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting
// attacklab: clean up hack
bq = bq.replace(/~0/g,"");
bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
bq = _RunBlockGamut(bq); // recurse
bq = bq.replace(/(^|\n)/g,"$1 ");
// These leading spaces screw with <pre> content, so we need to fix that:
bq = bq.replace(
/(\s*<pre>[^\r]+?<\/pre>)/gm,
function(wholeMatch,m1) {
var pre = m1;
// attacklab: hack around Konqueror 3.5.4 bug:
pre = pre.replace(/^ /mg,"~0");
pre = pre.replace(/~0/g,"");
return pre;
});
return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
});
return text;
}
var _FormParagraphs = function(text) {
//
// Params:
// $text - string to process with html <p> tags
//
// Strip leading and trailing lines:
text = text.replace(/^\n+/g,"");
text = text.replace(/\n+$/g,"");
var grafs = text.split(/\n{2,}/g);
var grafsOut = new Array();
//
// Wrap <p> tags.
//
var end = grafs.length;
for (var i=0; i<end; i++) {
var str = grafs[i];
// if this is an HTML marker, copy it
if (str.search(/~K(\d+)K/g) >= 0) {
grafsOut.push(str);
}
else if (str.search(/\S/) >= 0) {
str = _RunSpanGamut(str);
str = str.replace(/^([ \t]*)/g,"<p>");
str += "</p>"
grafsOut.push(str);
}
}
//
// Unhashify HTML blocks
//
end = grafsOut.length;
for (var i=0; i<end; i++) {
// if this is a marker for an html block...
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
var blockText = g_html_blocks[RegExp.$1];
blockText = blockText.replace(/\$/g,"$$$$"); // Escape any dollar signs
grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
}
}
return grafsOut.join("\n\n");
}
var _EncodeAmpsAndAngles = function(text) {
// Smart processing for ampersands and angle brackets that need to be encoded.
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&amp;");
// Encode naked <'s
text = text.replace(/<(?![a-z\/?\$!])/gi,"&lt;");
return text;
}
var _EncodeBackslashEscapes = function(text) {
//
// Parameter: String.
// Returns: The string, with after processing the following backslash
// escape sequences.
//
// attacklab: The polite way to do this is with the new
// escapeCharacters() function:
//
// text = escapeCharacters(text,"\\",true);
// text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
//
// ...but we're sidestepping its use of the (slow) RegExp constructor
// as an optimization for Firefox. This function gets called a LOT.
text = text.replace(/\\(\\)/g,escapeCharacters_callback);
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);
return text;
}
var _DoAutoLinks = function(text) {
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
// Email addresses: <address@domain.foo>
/*
text = text.replace(/
<
(?:mailto:)?
(
[-.\w]+
\@
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
)
>
/gi, _DoAutoLinks_callback());
*/
text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,
function(wholeMatch,m1) {
return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );
}
);
return text;
}
var _EncodeEmailAddress = function(addr) {
//
// Input: an email address, e.g. "foo@example.com"
//
// Output: the email address as a mailto link, with each character
// of the address encoded as either a decimal or hex entity, in
// the hopes of foiling most address harvesting spam bots. E.g.:
//
// <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
// x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
// &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
//
// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
// mailing list: <http://tinyurl.com/yu7ue>
//
// attacklab: why can't javascript speak hex?
function char2hex(ch) {
var hexDigits = '0123456789ABCDEF';
var dec = ch.charCodeAt(0);
return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15));
}
var encode = [
function(ch){return "&#"+ch.charCodeAt(0)+";";},
function(ch){return "&#x"+char2hex(ch)+";";},
function(ch){return ch;}
];
addr = "mailto:" + addr;
addr = addr.replace(/./g, function(ch) {
if (ch == "@") {
// this *must* be encoded. I insist.
ch = encode[Math.floor(Math.random()*2)](ch);
} else if (ch !=":") {
// leave ':' alone (to spot mailto: later)
var r = Math.random();
// roughly 10% raw, 45% hex, 45% dec
ch = (
r > .9 ? encode[2](ch) :
r > .45 ? encode[1](ch) :
encode[0](ch)
);
}
return ch;
});
addr = "<a href=\"" + addr + "\">" + addr + "</a>";
addr = addr.replace(/">.+:/g,"\">"); // strip the mailto: from the visible part
return addr;
}
var _UnescapeSpecialChars = function(text) {
//
// Swap back in all the special characters we've hidden.
//
text = text.replace(/~E(\d+)E/g,
function(wholeMatch,m1) {
var charCodeToReplace = parseInt(m1);
return String.fromCharCode(charCodeToReplace);
}
);
return text;
}
var _Outdent = function(text) {
//
// Remove one level of line-leading tabs or spaces
//
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
text = text.replace(/^(\t|[ ]{1,4})/gm,"~0"); // attacklab: g_tab_width
// attacklab: clean up hack
text = text.replace(/~0/g,"")
return text;
}
var _Detab = function(text) {
// attacklab: Detab's completely rewritten for speed.
// In perl we could fix it by anchoring the regexp with \G.
// In javascript we're less fortunate.
// expand first n-1 tabs
text = text.replace(/\t(?=\t)/g," "); // attacklab: g_tab_width
// replace the nth with two sentinels
text = text.replace(/\t/g,"~A~B");
// use the sentinel to anchor our regex so it doesn't explode
text = text.replace(/~B(.+?)~A/g,
function(wholeMatch,m1,m2) {
var leadingText = m1;
var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width
// there *must* be a better way to do this:
for (var i=0; i<numSpaces; i++) leadingText+=" ";
return leadingText;
}
);
// clean up sentinels
text = text.replace(/~A/g," "); // attacklab: g_tab_width
text = text.replace(/~B/g,"");
return text;
}
//
// attacklab: Utility functions
//
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
// First we have to escape the escape characters so that
// we can build a character class out of them
var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
if (afterBackslash) {
regexString = "\\\\" + regexString;
}
var regex = new RegExp(regexString,"g");
text = text.replace(regex,escapeCharacters_callback);
return text;
}
var escapeCharacters_callback = function(wholeMatch,m1) {
var charCodeToEscape = m1.charCodeAt(0);
return "~E"+charCodeToEscape+"E";
}
exports.encode = exports.markdown = function (src) {
return exports.makeHtml(src);
};
exports.main = function (system) {
var command = system.args.shift();
if (!system.args.length) {
system.stdout.write(exports.markdown(system.stdin.read())).flush();
} else {
var arg;
while (arg = system.args.shift()) {
var out = system.fs.basename(arg, '.md') + '.html';
print(out);
system.fs.write(out, exports.markdown(system.fs.read(arg)));
}
}
};
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test()
{
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length
keep
*/
function core_md5(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for(var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return Array(a, b, c, d);
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data)
{
var bkey = str2binl(key);
if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
var ipad = Array(16), opad = Array(16);
for(var i = 0; i < 16; i++)
{
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
return core_md5(opad.concat(hash), 512 + 128);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}
/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
keep
*/
function str2binl(str)
{
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
return bin;
}
/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin)
{
var str = "";
var mask = (1 << chrsz) - 1;
for(var i = 0; i < bin.length * 32; i += chrsz)
str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
return str;
}
/*
* Convert an array of little-endian words to a hex string.
keep
*/
function binl2hex(binarray)
{
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++)
{
str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
}
return str;
}
/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray)
{
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for(var i = 0; i < binarray.length * 4; i += 3)
{
var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
| ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
for(var j = 0; j < 4; j++)
{
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
}
}
return str;
}
exports.hex = hex_md5;
{
"name": "couchapp",
"description": "official couchapp vendor",
"fetch_uri": "git://github.com/couchapp/couchapp.git"
}
<p>Customize this format here: <tt>ddoc.evently.items._changes.mustache</tt></p>
<h3>Recent Messages</h3>
<ul>
{{#items}}
<li>
<div class="avatar">
{{#gravatar_url}}<img src="{{gravatar_url}}" alt="{{name}}"/>{{/gravatar_url}}
<div class="name">
{{nickname}}
</div>
</div>
<p>{{message}}</p>
<div style="clear:left;"></div>
</li>
{{/items}}
</ul>
<p><em>Protip:</em> If you setup continuous replication between this database and a remote one, this list will reflect remote changes in near real-time.</p>
<p>This would be a good place to add pagination.</p>
<p>Most applications will customize this template (<tt>ddoc.evently.profile.profileReady.mustache</tt>) for user input.</p>
<div class="avatar">
{{#gravatar_url}}<img src="{{gravatar_url}}"/>{{/gravatar_url}}
<div class="name">
{{name}}
</div>
</div>
<form>
<label>New message from {{nickname}}: <input type="text" name="message" size=60 value=""></label>
</form>
<div style="clear:left;"></div>
<p><strong>Admin party, everyone is admin!</strong> Fix this in <a href="/_utils/index.html">Futon</a> before proceeding.</p>
<span>Welcome
<a target="_new" href="/_utils/document.html?{{auth_db}}/org.couchdb.user%3A{{uri_name}}">{{name}}</a>!
<a href="#logout">Logout?</a>
</span>
<a href="#signup">Signup</a> or <a href="#login">Login</a>
<form>
<label for="name">Name</label> <input type="text" name="name" value="">
<label for="password">Password</label> <input type="password" name="password" value="">
<input type="submit" value="Login">
<a href="#signup">or Signup</a>
</form>
<form>
<label for="name">Name</label> <input type="text" name="name" value="">
<label for="password">Password</label> <input type="password" name="password" value="">
<input type="submit" value="Signup">
<a href="#login">or Login</a>
</form>
<p>Please log in to see your profile.</p>
<form>
<p>Hello {{name}}, Please setup your user profile.</p>
<label for="nickname">Nickname
<input type="text" name="nickname" value=""></label>
<label for="email">Email (<em>for <a href="http://gravatar.com">Gravatar</a></em>)
<input type="text" name="email" value=""></label>
<label for="url">URL
<input type="text" name="url" value=""></label>
<input type="submit" value="Go &rarr;">
<input type="hidden" name="userCtxName" value="{{name}}" id="userCtxName">
</form>
<div class="avatar">
{{#gravatar_url}}<img src="{{gravatar_url}}"/>{{/gravatar_url}}
<div class="name">
{{nickname}}
</div>
</div>
<p>Hello {{nickname}}!</p>
<div style="clear:left;"></div>
/*
* CommonJS-compatible mustache.js module
*
* See http://github.com/janl/mustache.js for more info.
*/
/*
mustache.js — Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
var Renderer = function() {};
Renderer.prototype = {
otag: "{{",
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
this.send(template);
return;
}
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
}
this.render_tags(html, context, partials, in_recursion);
},
/*
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
}
},
/*
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
// no pragmas
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
that.pragmas[pragma][opts[0]] = opts[1];
}
return "";
// ignore unknown pragmas silently
});
},
/*
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
var dels = delimiters.split(" ");
this.otag = this.escape_regex(dels[0]);
this.ctag = this.escape_regex(dels[1]);
},
escape_regex: function(text) {
// thank you Simon Willison
if(!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
var value;
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unkown variables
return "";
},
// Utility methods
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '\"';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context;
return ctx;
}
},
is_object: function(a) {
return a && typeof a == "object";
},
is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},
/*
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
}
}
};
return({
name: "mustache.js",
version: "0.3.1-dev",
/*
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}
},
escape : function(text) {
return new Renderer().escape(text);
}
});
}();
exports.name = Mustache.name;
exports.version = Mustache.version;
exports.to_html = Mustache.to_html;
exports.escape = Mustache.escape;
// from couch.js
function encodeOptions(options) {
var buf = [];
if (typeof(options) == "object" && options !== null) {
for (var name in options) {
if (!options.hasOwnProperty(name)) {continue;}
var value = options[name];
if (name == "key" || name == "startkey" || name == "endkey") {
value = JSON.stringify(value);
}
buf.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));
}
}
if (!buf.length) {
return "";
}
return "?" + buf.join("&");
}
function concatArgs(array, args) {
for (var i=0; i < args.length; i++) {
array.push(args[i]);
};
return array;
};
function makePath(array) {
var options, path;
if (typeof array[array.length - 1] != "string") {
// it's a params hash
options = array.pop();
}
path = array.map(function(item) {return encodeURIComponent(item)}).join('/');
if (options) {
return path + encodeOptions(options);
} else {
return path;
}
};
exports.init = function(req) {
return {
asset : function() {
var p = req.path, parts = ['', p[0], p[1] , p[2]];
return makePath(concatArgs(parts, arguments));
},
show : function() {
var p = req.path, parts = ['', p[0], p[1] , p[2], '_show'];
return makePath(concatArgs(parts, arguments));
},
list : function() {
var p = req.path, parts = ['', p[0], p[1] , p[2], '_list'];
return makePath(concatArgs(parts, arguments));
},
update : function() {
var p = req.path, parts = ['', p[0], p[1] , p[2], '_update'];
return makePath(concatArgs(parts, arguments));
},
limit : function(limit) {
var query = req.query;
var l = query.limit;
query.limit = limit;
var view = req.path[req.path.length - 1];
var list = req.path[req.path.length - 2];
var link = this.list(list, view, query);
query.limit = l;
return link;
},
older : function(key) {
if (!typeof key == "undefined") return null;
var query = req.query;
query.startkey = key;
query.skip=1;
var view = req.path[req.path.length - 1];
var list = req.path[req.path.length - 2];
return this.list(list, view, query);
},
absolute : function(path) {
return 'http://' + req.headers.Host + path;
}
}
};
{
"view" : "recent-items",
"descending" : "true",
"limit" : 50
}
exports.permanent = function(redirect) {
return {
code : 301,
headers : {
"Location" : redirect
}
};
};
{
"a[href=#logout]" : {"click" : ["doLogout"]}
}
{
"a[href=#signup]" : {"click" : ["signupForm"]},
"a[href=#login]" : {"click" : ["loginForm"]}
}
function() {
var form = $(this);
var fdoc = form.serializeObject();
fdoc.created_at = new Date();
fdoc.profile = $$("#profile").profile;
$$(this).app.db.saveDoc(fdoc, {
success : function() {
form[0].reset();
}
});
return false;
};
function(e) {
var name = $('input[name=name]', this).val(),
pass = $('input[name=password]', this).val();
$(this).trigger('doLogin', [name, pass]);
return false;
}
function(e) {
var name = $('input[name=name]', this).val(),
pass = $('input[name=password]', this).val();
$(this).trigger('doSignup', [name, pass]);
return false;
}
function() {
var md5 = $$(this).app.require("vendor/couchapp/lib/md5");
// TODO this can be cleaned up with docForm?
// it still needs the workflow to edit an existing profile
var name = $("input[name=userCtxName]",this).val();
var newProfile = {
rand : Math.random().toString(),
nickname : $("input[name=nickname]",this).val(),
email : $("input[name=email]",this).val(),
url : $("input[name=url]",this).val()
}, widget = $(this);
// setup gravatar_url
if (md5) {
newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon';
}
// store the user profile on the user account document
$.couch.userDb(function(db) {
var userDocId = "org.couchdb.user:"+name;
db.openDoc(userDocId, {
success : function(userDoc) {
userDoc["couch.app.profile"] = newProfile;
db.saveDoc(userDoc, {
success : function() {
newProfile.name = userDoc.name;
$$(widget).profile = newProfile;
widget.trigger("profileReady", [newProfile]);
}
});
}
});
});
return false;
}
<div title="{{title}}" created="{{created}}" server.type="couchdb" server.page.revision="{{_rev}}" server.host="{{host}}" server.id="{{_id}}" tags="{{tags}}" server.workspace="{{db}}">
<pre>{{{text}}}</pre>
</div>
function(head, req) {
var Mustache = require("vendor/couchapp/lib/mustache");
var db = req.info.db_name;
var host = req.headers.Host;
var ddoc = this;
var templates = ddoc.templates;
var tiddler = "{{#tiddlers}}" + templates.tiddlywiki.tiddler + "{{/tiddlers}}";
provides("html", function() {
//start(headers); // TODO
var tiddlers = []; // TODO: inject config for defaultCustomFields
var row;
while(row = getRow()) {
row.value.tags = "[[" + row.value.tags.join("]] [[") + "]]"; // XXX: hacky
row.value.text = row.value.text.replace(/</g, "&lt;").replace(/>/g, "&gt;"); // XXX: hacky
tiddlers.push(row.value);
}
tiddlers = Mustache.to_html(tiddler, { tiddlers: tiddlers, db: db, host: host });
return templates.tiddlywiki.empty.replace('<div id="storeArea">',
'<div id="storeArea">\n' + tiddlers);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment