Welcome to TiddlyWiki created by Jeremy Ruston, Copyright © 2007 UnaMesa Association
//{{{
// Updates the secondary information (like links[] array) after a change to a tiddler
Tiddler.prototype.annotatedLinks = function()
{
links = [];
var t = this.autoLinkWikiWords() ? 0 : 1;
var tiddlerLinkRegExp = t==0 ? config.textPrimitives.tiddlerAnyLinkRegExp : config.textPrimitives.tiddlerForcedLinkRegExp;
tiddlerLinkRegExp.lastIndex = 0;
var formatMatch = tiddlerLinkRegExp.exec(this.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(this.text);
if(preMatch.index != formatMatch.index-1)
links.pushUnique({link:formatMatch[1], info:{type:"direct", text:""}});
} else {
links.pushUnique({link:formatMatch[1], info:{type:"direct", text:""}});
}
}
else if(formatMatch[2-t] && !config.formatterHelpers.isExternalLink(formatMatch[3-t])) // titledBrackettedLink
links.pushUnique({link:formatMatch[3-t], info:{type:"titled", text:formatMatch[2-t]}});
else if(formatMatch[4-t] && formatMatch[4-t] != this.title) // brackettedLink
links.pushUnique({link:formatMatch[4-t], info:{type:"bracket", text:""}});
tiddlerLinkRegExp.lastIndex = lastIndex;
formatMatch = tiddlerLinkRegExp.exec(this.text);
}
return links;
};
//}}}
/***
|''Name:''|FieldsEditorPlugin|
|''Description:''|//create//, //edit//, //view// and //delete// commands in toolbar <<toolbar fields>>.|
|''Version:''|1.0.2|
|''Date:''|Dec 21,2007|
|''Source:''|http://visualtw.ouvaton.org/VisualTW.html|
|''Author:''|Pascal Collin|
|''License:''|[[BSD open source license|License]]|
|''~CoreVersion:''|2.2.0|
|''Browser:''|Firefox 2.0; InternetExplorer 6.0, others|
!Demo:
On [[homepage|http://visualtw.ouvaton.org/VisualTW.html]], see [[FieldEditor example]]
!Installation:
*import this tiddler from [[homepage|http://visualtw.ouvaton.org/VisualTW.html]] (tagged as systemConfig)
*save and reload
*optionnaly : add the following css text in your StyleSheet : {{{#popup tr.fieldTableRow td {padding:1px 3px 1px 3px;}}}}
!Code
***/
//{{{
config.commands.fields.handlePopup = function(popup,title) {
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return;
var fields = {};
store.forEachField(tiddler,function(tiddler,fieldName,value) {fields[fieldName] = value;},true);
var items = [];
for(var t in fields) {
var editCommand = "<<untiddledCall editFieldDialog "+escape(title)+" "+escape(t)+">>";
var deleteCommand = "<<untiddledCall deleteField "+escape(title)+" "+escape(t)+">>";
var renameCommand = "<<untiddledCall renameField "+escape(title)+" "+escape(t)+">>";
items.push({field: t,value: fields[t], actions: editCommand+renameCommand+deleteCommand});
}
items.sort(function(a,b) {return a.field < b.field ? -1 : (a.field == b.field ? 0 : +1);});
var createNewCommand = "<<untiddledCall createField "+escape(title)+">>";
items.push({field : "", value : "", actions:createNewCommand });
if(items.length > 0)
ListView.create(popup,items,this.listViewTemplate);
else
createTiddlyElement(popup,"div",null,null,this.emptyText);
}
config.commands.fields.listViewTemplate = {
columns: [
{name: 'Field', field: 'field', title: "Field", type: 'String'},
{name: 'Actions', field: 'actions', title: "Actions", type: 'WikiText'},
{name: 'Value', field: 'value', title: "Value", type: 'WikiText'}
],
rowClasses: [
{className: 'fieldTableRow', field: 'actions'}
],
buttons: [ //can't use button for selected then delete, because click on checkbox will hide the popup
]
}
config.macros.untiddledCall = { // when called from listview, tiddler is unset, so we need to pass tiddler as parameter
handler : function(place,macroName,params,wikifier,paramString) {
var macroName = params.shift();
if (macroName) var macro = config.macros[macroName];
var title = params.shift();
if (title) var tiddler = store.getTiddler(unescape(title));
if (macro) macro.handler(place,macroName,params,wikifier,paramString,tiddler);
}
}
config.macros.deleteField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"delete", "delete "+fieldName,this.onClickDeleteField);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickDeleteField : function() {
var title=this.getAttribute("title");
var fieldName=this.getAttribute("fieldName");
var tiddler = store.getTiddler(title);
if (tiddler && fieldName && confirm("delete field " + fieldName+" from " + title +" tiddler ?")) {
delete tiddler.fields[fieldName];
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
return false;
}
}
config.macros.createField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly) {
var btn = createTiddlyButton(place,"create new", "create a new field",this.onClickCreateField);
btn.setAttribute("title",tiddler.title);
}
},
onClickCreateField : function() {
var title=this.getAttribute("title");
var tiddler = store.getTiddler(title);
if (tiddler) {
var fieldName = prompt("Field name","");
if (store.getValue(tiddler,fieldName)) {
window.alert("This field already exists.");
}
else if (fieldName) {
var v = prompt("Field value","");
tiddler.fields[fieldName]=v;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.macros.editFieldDialog = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"edit", "edit this field",this.onClickEditFieldDialog);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickEditFieldDialog : function() {
var title=this.getAttribute("title");
var tiddler = store.getTiddler(title);
var fieldName=this.getAttribute("fieldName");
if (tiddler && fieldName) {
var value = tiddler.fields[fieldName];
value = value ? value : "";
var lines = value.match(/\n/mg);
lines = lines ? true : false;
if (!lines || confirm("This field contains more than one line. Only the first line will be kept if you edit it here. Proceed ?")) {
var v = prompt("Field value",value);
tiddler.fields[fieldName]=v;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.macros.renameField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"rename", "rename "+fieldName,this.onClickRenameField);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickRenameField : function() {
var title=this.getAttribute("title");
var fieldName=this.getAttribute("fieldName");
var tiddler = store.getTiddler(title);
if (tiddler && fieldName) {
var newName = prompt("Rename " + fieldName + " as ?", fieldName);
if (newName) {
tiddler.fields[newName]=tiddler.fields[fieldName];
delete tiddler.fields[fieldName];
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.shadowTiddlers.StyleSheetFieldsEditor = "/*{{{*/\n";
config.shadowTiddlers.StyleSheetFieldsEditor += ".fieldTableRow td {padding : 1px 3px}\n";
config.shadowTiddlers.StyleSheetFieldsEditor += ".fieldTableRow .button {border:0; padding : 0 0.2em}\n";
config.shadowTiddlers.StyleSheetFieldsEditor +="/*}}}*/";
store.addNotification("StyleSheetFieldsEditor", refreshStyles);
//}}}
/***
|''Name:''|FieldsEditorPlugin|
|''Description:''|//create//, //edit//, //view// and //delete// commands in toolbar <<toolbar fields>>.|
|''Version:''|1.0.2|
|''Date:''|Dec 21,2007|
|''Source:''|http://visualtw.ouvaton.org/VisualTW.html|
|''Author:''|Pascal Collin|
|''License:''|[[BSD open source license|License]]|
|''~CoreVersion:''|2.2.0|
|''Browser:''|Firefox 2.0; InternetExplorer 6.0, others|
!Demo:
On [[homepage|http://visualtw.ouvaton.org/VisualTW.html]], see [[FieldEditor example]]
!Installation:
*import this tiddler from [[homepage|http://visualtw.ouvaton.org/VisualTW.html]] (tagged as systemConfig)
*save and reload
*optionnaly : add the following css text in your StyleSheet : {{{#popup tr.fieldTableRow td {padding:1px 3px 1px 3px;}}}}
!Code
***/
//{{{
config.commands.fields.handlePopup = function(popup,title) {
var tiddler = store.fetchTiddler(title);
if(!tiddler)
return;
var fields = {};
store.forEachField(tiddler,function(tiddler,fieldName,value) {fields[fieldName] = value;},true);
var items = [];
for(var t in fields) {
var editCommand = "<<untiddledCall editFieldDialog "+escape(title)+" "+escape(t)+">>";
var deleteCommand = "<<untiddledCall deleteField "+escape(title)+" "+escape(t)+">>";
var renameCommand = "<<untiddledCall renameField "+escape(title)+" "+escape(t)+">>";
items.push({field: t,value: fields[t], actions: editCommand+renameCommand+deleteCommand});
}
items.sort(function(a,b) {return a.field < b.field ? -1 : (a.field == b.field ? 0 : +1);});
var createNewCommand = "<<untiddledCall createField "+escape(title)+">>";
items.push({field : "", value : "", actions:createNewCommand });
if(items.length > 0)
ListView.create(popup,items,this.listViewTemplate);
else
createTiddlyElement(popup,"div",null,null,this.emptyText);
}
config.commands.fields.listViewTemplate = {
columns: [
{name: 'Field', field: 'field', title: "Field", type: 'String'},
{name: 'Actions', field: 'actions', title: "Actions", type: 'WikiText'},
{name: 'Value', field: 'value', title: "Value", type: 'WikiText'}
],
rowClasses: [
{className: 'fieldTableRow', field: 'actions'}
],
buttons: [ //can't use button for selected then delete, because click on checkbox will hide the popup
]
}
config.macros.untiddledCall = { // when called from listview, tiddler is unset, so we need to pass tiddler as parameter
handler : function(place,macroName,params,wikifier,paramString) {
var macroName = params.shift();
if (macroName) var macro = config.macros[macroName];
var title = params.shift();
if (title) var tiddler = store.getTiddler(unescape(title));
if (macro) macro.handler(place,macroName,params,wikifier,paramString,tiddler);
}
}
config.macros.deleteField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"delete", "delete "+fieldName,this.onClickDeleteField);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickDeleteField : function() {
var title=this.getAttribute("title");
var fieldName=this.getAttribute("fieldName");
var tiddler = store.getTiddler(title);
if (tiddler && fieldName && confirm("delete field " + fieldName+" from " + title +" tiddler ?")) {
delete tiddler.fields[fieldName];
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
return false;
}
}
config.macros.createField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly) {
var btn = createTiddlyButton(place,"create new", "create a new field",this.onClickCreateField);
btn.setAttribute("title",tiddler.title);
}
},
onClickCreateField : function() {
var title=this.getAttribute("title");
var tiddler = store.getTiddler(title);
if (tiddler) {
var fieldName = prompt("Field name","");
if (store.getValue(tiddler,fieldName)) {
window.alert("This field already exists.");
}
else if (fieldName) {
var v = prompt("Field value","");
tiddler.fields[fieldName]=v;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.macros.editFieldDialog = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"edit", "edit this field",this.onClickEditFieldDialog);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickEditFieldDialog : function() {
var title=this.getAttribute("title");
var tiddler = store.getTiddler(title);
var fieldName=this.getAttribute("fieldName");
if (tiddler && fieldName) {
var value = tiddler.fields[fieldName];
value = value ? value : "";
var lines = value.match(/\n/mg);
lines = lines ? true : false;
if (!lines || confirm("This field contains more than one line. Only the first line will be kept if you edit it here. Proceed ?")) {
var v = prompt("Field value",value);
tiddler.fields[fieldName]=v;
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.macros.renameField = {
handler : function(place,macroName,params,wikifier,paramString,tiddler) {
if(!readOnly && params[0]) {
fieldName = unescape(params[0]);
var btn = createTiddlyButton(place,"rename", "rename "+fieldName,this.onClickRenameField);
btn.setAttribute("title",tiddler.title);
btn.setAttribute("fieldName", fieldName);
}
},
onClickRenameField : function() {
var title=this.getAttribute("title");
var fieldName=this.getAttribute("fieldName");
var tiddler = store.getTiddler(title);
if (tiddler && fieldName) {
var newName = prompt("Rename " + fieldName + " as ?", fieldName);
if (newName) {
tiddler.fields[newName]=tiddler.fields[fieldName];
delete tiddler.fields[fieldName];
store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields);
story.refreshTiddler(title,"ViewTemplate",true);
}
}
return false;
}
}
config.shadowTiddlers.StyleSheetFieldsEditor = "/*{{{*/\n";
config.shadowTiddlers.StyleSheetFieldsEditor += ".fieldTableRow td {padding : 1px 3px}\n";
config.shadowTiddlers.StyleSheetFieldsEditor += ".fieldTableRow .button {border:0; padding : 0 0.2em}\n";
config.shadowTiddlers.StyleSheetFieldsEditor +="/*}}}*/";
store.addNotification("StyleSheetFieldsEditor", refreshStyles);
//}}}
direct.strokeStyle:green
direct.fillStyle:green
back.strokeStyle:blue
back.fillStyle:blue
titled.fillStyle:grey
titled.strokeStyle:grey
titled.lineWidth:3.0
direct.display:yes
bracket.display:yes
titled.display:yes
plot.display:yes
!Warning
This wiki is provided by [[IDEIA|http://www.ideia.fr]].
It's a work in progress provided as is... no garanty !
Feel free to play with it, modify it. Please, if you improve the TiddlerGraphPlugin, send the code to mailto:ybabel@ideia.fr
!Short Manual
* To draw a graph, you must create tiddlers (which will be graph nodes) tagged with "draw" (tag can be changed in the macro call)
* There are 3 ways to create links
** by tagging a tiddler with another tiddler
** by linking to another tiddler inside the tiddler. Note that titled bracketed links will create an anotated link.
** using the "graphviz" like syntax inside a tiddler
!Example
<<graph 500 200 fields nogroups tags:draw anim:100 >>
<<graph 500 200 plot:PlotTest>>
/***
|''Name:''|LoadRemoteFileThroughProxy (previous LoadRemoteFileHijack)|
|''Description:''|When the TiddlyWiki file is located on the web (view over http) the content of [[SiteProxy]] tiddler is added in front of the file url. If [[SiteProxy]] does not exist "/proxy/" is added. |
|''Version:''|1.1.0|
|''Date:''|mar 17, 2007|
|''Source:''|http://tiddlywiki.bidix.info/#LoadRemoteFileHijack|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0|
***/
//{{{
version.extensions.LoadRemoteFileThroughProxy = {
major: 1, minor: 1, revision: 0,
date: new Date("mar 17, 2007"),
source: "http://tiddlywiki.bidix.info/#LoadRemoteFileThroughProxy"};
if (!window.bidix) window.bidix = {}; // bidix namespace
if (!bidix.core) bidix.core = {};
bidix.core.loadRemoteFile = loadRemoteFile;
loadRemoteFile = function(url,callback,params)
{
if ((document.location.toString().substr(0,4) == "http") && (url.substr(0,4) == "http")){
url = store.getTiddlerText("SiteProxy", "/proxy/") + url;
}
return bidix.core.loadRemoteFile(url,callback,params);
}
//}}}
/***
|''Name:''|PasswordOptionPlugin|
|''Description:''|Extends TiddlyWiki options with non encrypted password option.|
|''Version:''|1.0.2|
|''Date:''|Apr 19, 2007|
|''Source:''|http://tiddlywiki.bidix.info/#PasswordOptionPlugin|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0 (Beta 5)|
***/
//{{{
version.extensions.PasswordOptionPlugin = {
major: 1, minor: 0, revision: 2,
date: new Date("Apr 19, 2007"),
source: 'http://tiddlywiki.bidix.info/#PasswordOptionPlugin',
author: 'BidiX (BidiX (at) bidix (dot) info',
license: '[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D]]',
coreVersion: '2.2.0 (Beta 5)'
};
config.macros.option.passwordCheckboxLabel = "Save this password on this computer";
config.macros.option.passwordInputType = "password"; // password | text
setStylesheet(".pasOptionInput {width: 11em;}\n","passwordInputTypeStyle");
merge(config.macros.option.types, {
'pas': {
elementType: "input",
valueField: "value",
eventName: "onkeyup",
className: "pasOptionInput",
typeValue: config.macros.option.passwordInputType,
create: function(place,type,opt,className,desc) {
// password field
config.macros.option.genericCreate(place,'pas',opt,className,desc);
// checkbox linked with this password "save this password on this computer"
config.macros.option.genericCreate(place,'chk','chk'+opt,className,desc);
// text savePasswordCheckboxLabel
place.appendChild(document.createTextNode(config.macros.option.passwordCheckboxLabel));
},
onChange: config.macros.option.genericOnChange
}
});
merge(config.optionHandlers['chk'], {
get: function(name) {
// is there an option linked with this chk ?
var opt = name.substr(3);
if (config.options[opt])
saveOptionCookie(opt);
return config.options[name] ? "true" : "false";
}
});
merge(config.optionHandlers, {
'pas': {
get: function(name) {
if (config.options["chk"+name]) {
return encodeCookie(config.options[name].toString());
} else {
return "";
}
},
set: function(name,value) {config.options[name] = decodeCookie(value);}
}
});
// need to reload options to load passwordOptions
loadOptionsCookie();
/*
if (!config.options['pasPassword'])
config.options['pasPassword'] = '';
merge(config.optionsDesc,{
pasPassword: "Test password"
});
*/
//}}}
|company|my small one|
* ''company'' :< [[georges]] [[susan]] [[burt]]
* ''georges'' -> [[likes|susan]] susan very much, and is [[employee|burt]]
* ''susan'' -> [[secretary|burt]]
* ''michel'' -> [[married to|susan]]
//{{{
/* Prototype JavaScript framework
* (c) 2005 Sam Stephenson <sam@conio.net>
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/
//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
Object.extend = function(destination, source) {
for (property in source) destination[property] = source[property];
return destination;
}
Function.prototype.bind = function(object) {
var __method = this;
return function() {
return __method.apply(object, arguments);
}
}
Function.prototype.bindAsEventListener = function(object) {
var __method = this;
return function(event) {
__method.call(object, event || window.event);
}
}
function $() {
if (arguments.length == 1) return get$(arguments[0]);
var elements = [];
$c(arguments).each(function(el){
elements.push(get$(el));
});
return elements;
function get$(el){
if (typeof el == 'string') el = document.getElementById(el);
return el;
}
}
if (!window.Element) var Element = new Object();
Object.extend(Element, {
remove: function(element) {
element = $(element);
element.parentNode.removeChild(element);
},
hasClassName: function(element, className) {
element = $(element);
if (!element) return;
var hasClass = false;
element.className.split(' ').each(function(cn){
if (cn == className) hasClass = true;
});
return hasClass;
},
addClassName: function(element, className) {
element = $(element);
Element.removeClassName(element, className);
element.className += ' ' + className;
},
removeClassName: function(element, className) {
element = $(element);
if (!element) return;
var newClassName = '';
element.className.split(' ').each(function(cn, i){
if (cn != className){
if (i > 0) newClassName += ' ';
newClassName += cn;
}
});
element.className = newClassName;
},
cleanWhitespace: function(element) {
element = $(element);
$c(element.childNodes).each(function(node){
if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
});
},
find: function(element, what) {
element = $(element)[what];
while (element.nodeType != 1) element = element[what];
return element;
}
});
var Position = {
cumulativeOffset: function(element) {
var valueT = 0, valueL = 0;
do {
valueT += element.offsetTop || 0;
valueL += element.offsetLeft || 0;
element = element.offsetParent;
} while (element);
return [valueL, valueT];
}
};
document.getElementsByClassName = function(className) {
var children = document.getElementsByTagName('*') || document.all;
var elements = [];
$c(children).each(function(child){
if (Element.hasClassName(child, className)) elements.push(child);
});
return elements;
}
//useful array functions
Array.prototype.iterate = function(func){
for(var i=0;i<this.length;i++) func(this[i], i);
}
if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;
function $c(array){
var nArray = [];
for (var i=0;i<array.length;i++) nArray.push(array[i]);
return nArray;
}
//}}}
/***
***/
//{{{
config.commands.refresh = {
text: 'refresh',
tooltip: 'Refresh this tiddler',
handler: function(e,src,title) {
clearMessage();
story.refreshTiddler(title,false,true); // force=true
return false;
}
};
//}}}
TiddlerGraphPlugin made public
//{{{
/* GraphMacro for TiddlyWiki, ported by IDEIA (www.ideia.fr) from
* Graph JavaScript framework, version 0.1.0
* (c) 2006 Aslak Hellesoy <aslak.hellesoy@gmail.com>
* (c) 2006 Dave Hoover <dave.hoover@gmail.com>
*
* Ported from Graph::Layouter::Spring in
* http://search.cpan.org/~pasky/Graph-Layderer-0.02/
* The algorithm is based on a spring-style layouter of a Java-based social
* network tracker PieSpy written by Paul Mutton E<lt>paul@jibble.orgE<gt>.
*
* Graph is freely distributable under the terms of an MIT-style license.
* For details, see the Graph web site: http://dev.buildpatternd.com/trac
*
/*--------------------------------------------------------------------------*/
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none'){
document.getElementById(divid).style.display = '';
}else{
document.getElementById(divid).style.display = 'none';
}
}
function roundedRect(ctx, x,y,width,height,radius){
ctx.beginPath();
ctx.moveTo(x,y+radius);
ctx.lineTo(x,y+height-radius);
ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
ctx.lineTo(x+width-radius,y+height);
ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
ctx.lineTo(x+width,y+radius);
ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
ctx.lineTo(x+radius,y);
ctx.quadraticCurveTo(x,y,x,y+radius);
ctx.closePath();
ctx.fill();
}
var Graph = Class.create();
Graph.prototype = {
initialize: function(element) {
this.nodeSet = {};
this.nodes = [];
this.edges = [];
this.root = element;
this.useSlice = true;
this.useGroup = true;
},
getValue: function(title, name) {
return this.useSlice ? store.getTiddlerSlice(title,name) : store.getValue(title,name);
},
addNode: function(value, sub) {
var valueID = value+"_graph";
if(typeof value == 'string') {
if (document.getElementById(valueID) != null)
{ var key = valueID; element = document.getElementById(valueID) }
else {
// Create a new div
var key = valueID;
var element = document.createElement('div');
var t = createTiddlyLink(element,value,true);
var title = this.getValue(value,"graph.title");
if (title) t.title = title;
element.id = valueID;
element.className = "draggable";
var handle = document.createElement('span');
handle.innerHTML = "°";
handle.title = "Drag handle";
element.appendChild(handle);
var subtext = sub?sub:this.getValue(value,"graph.subTitle");
if (subtext) {
var subtitle = document.createElement('div');
subtitle.className = "graphSubTitle";
subtitle.innerHTML = subtext;
element.appendChild(subtitle);
}
this.root.appendChild(element);
}
} else {
// Assuming it's a DOM node *with* and id.
var key = value.id;
var element = value;
}
var node = this.nodeSet[key];
if(node == undefined) {
node = new Graph.Node(element);
node.tiddler = store.getTiddler(value);
this.nodeSet[key] = node;
this.nodes.push(node);
}
return node;
},
// Uniqueness must be ensured by caller
addEdge: function(source, target, info) {
var s = this.addNode(source);
var t = this.addNode(target);
var divID = s.value.id+"_"+t.value.id;
var e = document.createElement('span');
e.id = 'inner'+divID;
var display = store.getTiddlerSlice("GraphConfig",info.type+'.display');
e.style.display = display?display:'none';
e.innerHTML = info.text ? info.text:"";
if (info.text) {
var tmp = document.createElement('div');
tmp.id = divID;
tmp.style.position = 'absolute';
tmp.innerHTML = '<a href="javascript:;" title="'+info.text+'" onmousedown="toggleDiv(\'inner'+divID+'\');">+</a>';
this.root.appendChild(tmp);
tmp.appendChild(e);
var edge = {source: s, target: t, element:tmp, information:info};
} else {
this.root.appendChild(e);
var edge = {source: s, target: t, element:e, information:info};
}
this.edges.push(edge);
if (info.type == "tag" && this.useGroup) {
t.group.push(s);
}
},
// change graph structure over time depending on graph slices
animate: function(time) {
for (var i = this.nodes.length-1; i>=0; i--) {
var node = this.nodes[i];
if (node.tiddler) {
endLife = this.getValue(node.tiddler.title, "graph.endLife");
if (endLife && time == endLife) {
for (var j = this.edges.length-1; j>=0; j--) {
if ( (this.edges[j].source == node) || (this.edges[j].target == node) ) {
this.root.removeChild(this.edges[j].element);
this.edges.splice(j,1); }
}
this.root.removeChild(node.value);
this.nodes.splice(i,1);
}
}
}
for (var i = this.edges.length-1; i>=0; i--) {
var edge = this.edges[i];
if (edge.information.text != "")
var t = store.getTiddler(edge.information.text);
if (t) {
var endLife = this.getValue(edge.information.text, "graph.endLife");
if (endLife && time == endLife) { this.root.removeChild(this.edges[i].element); this.edges.splice(i,1); }
}
}
}
};
Graph.Node = Class.create();
Graph.Node.prototype = {
initialize: function(value) {
this.value = value;
this.tiddler = null;
this.group = [];
}
};
Graph.Renderer = {};
Graph.Renderer.Basic = Class.create();
Graph.Renderer.Basic.prototype = {
initialize: function(element, graph) {
this.element = element;
this.graph = graph;
this.ctx = element.getContext("2d");
this.arrowAngle = Math.PI/10;
},
getValue: function(title, name) {
return this.graph.useSlice ? store.getTiddlerSlice(title,name) : store.getValue(title,name);
},
translate: function(point) {
return [
(point[0] - this.graph.layoutMinX) * this.factorX,
(point[1] - this.graph.layoutMinY) * this.factorY
];
},
rotate: function(point, length, angle) {
var dx = length * Math.cos(angle);
var dy = length * Math.sin(angle);
return [point[0]+dx, point[1]+dy];
},
clear : function () {
this.ctx.fillStyle = "rgb(255,255,255)";
this.ctx.fillRect(0,0,this.element.width, this.element.height);
this.factorX = (this.element.width-50) / (this.graph.layoutMaxX - this.graph.layoutMinX);
this.factorY = (this.element.height-25) / (this.graph.layoutMaxY - this.graph.layoutMinY);
},
draw: function() {
this.ctx.save();
this.clear();
for (var i = 0; i < this.graph.nodes.length; i++) {
this.moveNode(this.graph.nodes[i]);
}
for (var i = 0; i < this.graph.nodes.length; i++) {
this.drawNode(this.graph.nodes[i]);
}
for (var i = 0; i < this.graph.edges.length; i++) {
this.drawEdge(this.graph.edges[i]);
}
this.ctx.restore();
},
unionRect: function(rect1, rect2) {
var result = {left:0, right:0, bottom:0, top:0};
result.left = rect1.left < rect2.left ? rect1.left : rect2.left;
result.right = rect1.right > rect2.right ? rect1.right : rect2.right;
result.bottom = rect1.bottom > rect2.bottom ? rect1.bottom : rect2.bottom;
result.top = rect1.top < rect2.top ? rect1.top : rect2.top;
return result;
},
moveNode: function(node) {
var point = this.translate([node.layoutPosX, node.layoutPosY]);
node.value.style.position = 'absolute';
node.value.style.top = point[1] + 'px';
node.value.style.left = point[0] + 'px';
var rect = node.value.getBoundingClientRect();
node.drawingRect = {left:point[0], right:point[0] + rect.right-rect.left, top:point[1], bottom:point[1]+ rect.bottom-rect.top};
},
drawNode: function(node) {
var point = this.translate([node.layoutPosX, node.layoutPosY]);
var rect = node.value.getBoundingClientRect();
var drawingRect = node.drawingRect;
if (node.group.length > 0 && this.graph.useGroup) {
for (var i = 0; i < node.group.length; i++) {
var gnode = node.group[i];
drawingRect = this.unionRect(drawingRect, gnode.drawingRect);
}
rect = drawingRect; this.drawingRect=drawingRect;
point = [rect.left, rect.top];
}
if (node.tiddler) {
var fill = this.getValue(node.tiddler.title, "graph.fillStyle");
var stroke = this.getValue(node.tiddler.title, "graph.strokeStyle");
var rounded = this.getValue(node.tiddler.title, "graph.rounded");
var margin = this.getValue(node.tiddler.title, "graph.margin");
}
this.ctx.strokeStyle = stroke?stroke:'black';
this.ctx.fillStyle = fill?fill:node.group.length!=0?"rgb(50,250,100)":"rgb(100,200,200)";
margin = margin ? margin : 0;
if (rounded) {
var rx=parseInt(point[0]-margin);
var ry=parseInt(point[1]-margin);
var rw=parseInt(rect.right-rect.left+margin*2);
var rh=parseInt(rect.bottom-rect.top+margin*2);
roundedRect(this.ctx, rx, ry, rw, rh, parseInt(rounded));
}
else
this.ctx.fillRect (point[0], point[1], rect.right-rect.left, rect.bottom-rect.top);
},
getMiddle: function(point) {
var pos = this.translate([point.layoutPosX, point.layoutPosY]);
var rect = point.value.getBoundingClientRect();
var X = (rect.right-rect.left) / 2;
var Y = (rect.bottom-rect.top) / 2;
pos[0] += X; pos[1] += Y;
return pos;
},
getIntersection: function(source, target, element) {
var pos = this.translate([element.layoutPosX, element.layoutPosY]);
var sourceP = new Point2D(source[0], source[1]);
var targetP = new Point2D(target[0], target[1]);
var rect = element.value.getBoundingClientRect();
var rect1 = new Point2D(pos[0], pos[1]);
var rect2 = new Point2D(pos[0]+rect.right-rect.left, pos[1]+rect.bottom-rect.top);
var intersect = Intersection.intersectLineRectangle(sourceP, targetP, rect2, rect1);
// we MUST have one intersection point in every case because we aim at the center of the rectangle !
//if (intersect.points.length != 1) displayMessage(sourceP+" + "+targetP+" * "+rect1+" * "+ rect2+" : "+intersect+"\n");
if (intersect.points.length != 1) return null;
return intersect;
},
drawEdge: function(edge) {
if (edge.information.type == "tag" && this.graph.useGroup) return;
source = this.getMiddle(edge.source);
target = this.getMiddle(edge.target);
if (edge.information.text != "")
var t = store.getTiddler(edge.information.text);
var tan = (target[1] - source[1]) / (target[0] - source[0]);
var theta = Math.atan(tan);
if(source[0] <= target[0]) {theta = Math.PI+theta}
// draw the edge
if (t) {
var fill = this.getValue(edge.information.text, "graph.fillStyle");
var stroke = this.getValue(edge.information.text, "graph.strokeStyle");
var width = this.getValue(edge.information.text, "graph.lineWidth");
}
var stroke = stroke?stroke:this.getValue("GraphConfig",edge.information.type+'.strokeStyle');
var fill = fill?fill:this.getValue("GraphConfig",edge.information.type+'.fillStyle');
var width = width?width:this.getValue("GraphConfig",edge.information.type+'.lineWidth');
this.ctx.strokeStyle = stroke? stroke : 'red';
this.ctx.fillStyle = fill ? fill : 'red';
this.ctx.lineWidth = width ? parseFloat(width) : 1.0;
this.ctx.beginPath();
var intersectT = this.getIntersection(source, target, edge.target);
var intersectS = this.getIntersection(source, target, edge.source);
if (intersectT == null || intersectS == null) return;
this.ctx.moveTo(intersectS.points[0].x, intersectS.points[0].y);
this.ctx.lineTo(intersectT.points[0].x, intersectT.points[0].y);
this.ctx.stroke();
this.drawArrowHead(20, this.arrowAngle, theta, source[0], source[1], intersectT.points[0].x, intersectT.points[0].y);
if (t) {
var position = this.getValue(edge.information.text, "graph.position");
var text = this.getValue(edge.information.text, "graph.text");
position = position ? parseFloat(position) : 0.5;
edge.element.innerHTML = text?text:edge.information.text;
} else {
var position = 0.5;
}
edge.element.style.left = (source[0]*(1-position)+target[0]*position) + 'px';
edge.element.style.top = (source[1]*(1-position)+target[1]*position) + 'px';
},
drawArrowHead: function(length, alpha, theta, startx, starty, endx, endy) {
var top = this.rotate([endx, endy], length, theta + alpha);
var bottom = this.rotate([endx, endy], length, theta - alpha);
this.ctx.beginPath();
this.ctx.moveTo(endx, endy);
this.ctx.lineTo(top[0], top[1]);
this.ctx.lineTo(bottom[0], bottom[1]);
this.ctx.fill();
}
};
Graph.Layout = {};
Graph.Layout.Spring = Class.create();
Graph.Layout.Spring.prototype = {
initialize: function(graph) {
this.graph = graph;
this.iterations = 500;
this.maxRepulsiveForceDistance = 10;
this.k = 1;
this.c = 0.01;
this.maxVertexMovement = 0.5;
this.useSlice = true;
},
getValue: function(title, name) {
return this.graph.useSlice ? store.getTiddlerSlice(title,name) : store.getValue(title,name);
},
prepare: function() {
this.layoutPrepare();
this.layoutIteration();
this.layoutCalcBounds();
},
step: function () {
this.layoutIteration();
this.layoutCalcBounds();
},
reverse: function(factorX, factorY) {
for (var i = 0; i < this.graph.nodes.length; i++) {
var s = this.graph.nodes[i].value.style;
var y = s.top.substring(0, s.top.length-2);
var x = s.left.substring(0, s.left.length-2);
this.graph.nodes[i].layoutPosX = x/factorX + this.graph.layoutMinX;
this.graph.nodes[i].layoutPosY = y/factorY + this.graph.layoutMinY;
}
},
layout: function() {
this.layoutPrepare();
for (var i = 0; i < this.iterations; i++) {
this.layoutIteration();
}
this.layoutCalcBounds();
},
layoutPrepare: function() {
for (var i = 0; i < this.graph.nodes.length; i++) {
var node = this.graph.nodes[i];
this.layoutPrepareNode(node, i);
}
},
layoutPrepareNode: function(node, i) {
node.layoutPosX = node.tiddler?node.tiddler.tags.length:i;
node.layoutPosY = node.tiddler?node.tiddler.title.length:node.value.id.length;
node.layoutForceX = 0;
node.layoutForceY = 0;
},
layoutPrepareLastNode: function() {
var node = this.graph.nodes[this.graph.nodes.length-1];
this.layoutPrepareNode(node, this.graph.nodes.length-1);
},
layoutCalcBounds: function() {
var minx = Infinity, maxx = -Infinity, miny = Infinity, maxy = -Infinity;
for (var i = 0; i < this.graph.nodes.length; i++) {
var x = this.graph.nodes[i].layoutPosX;
var y = this.graph.nodes[i].layoutPosY;
if(x > maxx) maxx = x;
if(x < minx) minx = x;
if(y > maxy) maxy = y;
if(y < miny) miny = y;
}
this.graph.layoutMinX = minx;
this.graph.layoutMaxX = maxx;
this.graph.layoutMinY = miny;
this.graph.layoutMaxY = maxy;
},
layoutIteration: function() {
// Forces on nodes due to node-node repulsions
for (var i = 0; i < this.graph.nodes.length; i++) {
var node1 = this.graph.nodes[i];
for (var j = i + 1; j < this.graph.nodes.length; j++) {
var node2 = this.graph.nodes[j];
this.layoutRepulsive(node1, node2);
}
}
// Forces on nodes due to edge attractions
for (var i = 0; i < this.graph.edges.length; i++) {
var edge = this.graph.edges[i];
this.layoutAttractive(edge);
}
// Move by the given force
for (var i = 0; i < this.graph.nodes.length; i++) {
var node = this.graph.nodes[i];
if (node.tiddler) {
var X = this.getValue(node.tiddler.title, "graph.X");
var Y = this.getValue(node.tiddler.title, "graph.Y");
}
var xmove = this.c * node.layoutForceX;
var ymove = this.c * node.layoutForceY;
var max = this.maxVertexMovement;
if(xmove > max) xmove = max;
if(xmove < -max) xmove = -max;
if(ymove > max) ymove = max;
if(ymove < -max) ymove = -max;
node.layoutPosX += xmove;
node.layoutPosY += ymove;
node.layoutPosX = X?X:node.layoutPosX;
node.layoutPosY = Y?Y:node.layoutPosY;
node.layoutForceX = 0;
node.layoutForceY = 0;
}
},
getRepulse: function(node) {
if (node.tiddler)
var repulse = this.getValue(node.tiddler.title, "graph.repulse");
repulse = repulse?repulse:1;
return repulse;
},
layoutRepulsive: function(node1, node2) {
var dx = node2.layoutPosX - node1.layoutPosX;
var dy = node2.layoutPosY - node1.layoutPosY;
var d2 = dx * dx + dy * dy;
if(d2 < 0.01) {
dx = 0.1 * Math.random() + 0.1;
dy = 0.1 * Math.random() + 0.1;
var d2 = dx * dx + dy * dy;
}
var d = Math.sqrt(d2);
if(d < this.maxRepulsiveForceDistance) {
var repulsiveForce = this.getRepulse(node1) * this.getRepulse(node2) * this.k * this.k / d;
node2.layoutForceX += repulsiveForce * dx / d;
node2.layoutForceY += repulsiveForce * dy / d;
node1.layoutForceX -= repulsiveForce * dx / d;
node1.layoutForceY -= repulsiveForce * dy / d;
}
},
layoutAttractive: function(edge) {
var node1 = edge.source;
var node2 = edge.target;
var dx = node2.layoutPosX - node1.layoutPosX;
var dy = node2.layoutPosY - node1.layoutPosY;
var d2 = dx * dx + dy * dy;
if(d2 < 0.01) {
dx = 0.1 * Math.random() + 0.1;
dy = 0.1 * Math.random() + 0.1;
var d2 = dx * dx + dy * dy;
}
var d = Math.sqrt(d2);
if(d > this.maxRepulsiveForceDistance) {
d = this.maxRepulsiveForceDistance;
d2 = d * d;
}
var attractiveForce = (d2 - this.k * this.k) / this.k;
if(edge.weight == undefined || edge.weight < 1) edge.weight = 1;
attractiveForce *= Math.log(edge.weight) * 0.5 + 1;
attractiveForce *= 1+node1.group.length;
node2.layoutForceX -= attractiveForce * dx / d;
node2.layoutForceY -= attractiveForce * dy / d;
node1.layoutForceX += attractiveForce * dx / d;
node1.layoutForceY += attractiveForce * dy / d;
}
};
//}}}
/***
|''Name''|GraphPlugin|
|''Description''|Display dot graphs|
|''Version''|0.12.1|
|''Status''|beta|
|''License''|[[BSD open source license]] from [[IDEIA|http://www.ideia.fr]]|
|''~CoreVersion''|2.4.0|
|''Keywords''|visualization, graph, diagram, forcedirected, animated|
!Usage
Draw a graph
{{{
<<graph dimX dimY nolinks backlinks strict tags:tags anim:timing filter:tags start:tiddlers plot:tiddler>>
}}}
Options
* ''nolinks'' : do not follow forward links and tags
* ''nogroups'' : do not treat "tag" links as group links
* ''backlinks'' : follow reverse links
* ''strict'' : exclude all node not tagged with "tags" (otherwise direct links are included)
* ''notags'' : ignore tag links
* ''fields'' : read from fields instead of slices
* ''anim'':animate graph for some time
* ''tags'' : choose tiddlers with specified tags
* ''filter'' : exclude those tiddler with specified tags
* ''start'' : check also from these tiddler (+ thier direct links)
* ''plot'' : use the text of this tiddler to draw a graph from the text and not the tiddlers node, annot, link, type in an array. '->' for direct link, '<-' for backlinks and ':>' or ':<' for tag/group link.
Change node properties with slices
* ''color'' : graph.fillStyle, graph.strokeStyle,
* ''position'' : graph.X, graph.Y, graph.repulse
* ''display'': graph.title, graph.subTitle, graph.ignore
* ''life'' : graph.endLife, graph.startLife
In GraphConfig, you can configure style for links by combining
* ''link type'': direct, titled, bracket, back, tag
* ''display'' : fillStyle, strokeStyle, lineWidth, margin, rounded
!!History
|15.01.09| 0.1.0|Initial release, draw graph with anotated nodes from tiddler|
|16.01.09| 0.2.0|Add animation (the 3 parameter is the number of steps calculated)|
|19.01.09| 0.3.0|Added ability to move nodes, graph dynamically updated|
|22.01.09| 0.4.0|Support of multiple tags and filter also|
|22.01.09| 0.5.0|Can set color for node and links, depending of it's type|
|23.01.09| 0.6.0|Annotated links can be overiden by a tiddler|
|23.01.09| 0.6.1|Fix a bug : now start can have multiple tiddlers|
|23.01.09| 0.7.0|Now a new slice graph.subtitle|
|28.01.09| 0.8.0|Add preliminary time support in graph : graph.endLife|
|02.02.09| 0.8.1|Add "strict" filter for some graph displaying unwanted nodes|
|03.02.09| 0.8.2|Add graph.ignore to filter some individual links in graph|
|04.02.09| 0.8.3|Initial position of node is not 0 any more, so that no more random graphs|
|04.02.09| 0.9.0|Option to read from slices or from fields|
|05.02.09| 0.9.1|Add : graph.startLife|
|05.02.09| 0.9.2|Add : graph.repulse : so that nodes can be more isolated (useful for anotated links|
|13.02.09| 0.9.3|Links can be individually colored in their tiddler if it exist, rather than in GraphConfig|
|20.02.09| 0.10.0|Add : rounded rectangle + collapsible text for links|
|13.04.09| 0.11.0|Add direct graph plotting from table syntax|
|13.04.09| 0.12.0|Add group node support (eq tag link = group link)|
|13.04.09| 0.12.0|Add 'dot' syntax to direct graph (it means that it can read plain text to draw graphs|
!Known BUGS
* In some cases when every node in the graph have exactly the same tags, it can create a NaN anomaly. To bypass it, just change some tags.
* the new functionnalité collapsible links is not yet compatible with "full links" ... full links are links described in a tiddler
!Code
***/
//{{{
if(!version.extensions.GraphPlugin) {
version.extensions.GraphPlugin = {installed:true};
config.macros.graph = {};
config.macros.graph.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
var box = createTiddlyElement(place,"div",null,"graphBox",'');
box.title = "Graph";
box.id = "graphBox";
box.style.position = "relative";
var canvas = document.createElement("canvas");
canvas.width = params[0];
canvas.height = params[1];
box.appendChild(canvas);
var ctx = canvas.getContext("2d");
var timer = document.createElement("div");
box.appendChild(timer);
var parameters = paramString.parseParams("noname",null,true);
var includeTags = parameters[0]["tags"]?parameters[0]["tags"][0].split(","):[];
var startTiddlers = parameters[0]["start"]?parameters[0]["start"][0].split(","):[];
var plotTiddlers = parameters[0]["plot"]?parameters[0]["plot"][0].split(","):[];
var excludeTags = parameters[0]["filter"]?parameters[0]["filter"][0].split(","):[];
var anim = parameters[0]["anim"]?parseInt(parameters[0]["anim"][0]):0;
var results = [];
if (parameters[0]["start"]) {
for (var k=0; k<startTiddlers.length; k++)
results.push( store.getTiddler(startTiddlers[k]) );
} else store.forEachTiddler(function(title,tiddler) {
if (tiddler.tags.containsAny(includeTags)
&& !tiddler.tags.containsAny(excludeTags))
results.push(tiddler);
});
var g = new Graph(box);
g.useSlice = parameters[0]["noname"].indexOf("fields") == -1;
g.useGroup = parameters[0]["noname"].indexOf("nogroups") == -1;
var strict = parameters[0]["noname"].indexOf("strict") != -1;
var waitingList = [];
var time=0;
if (parameters[0]["plot"]) {
for (var k=0; k<plotTiddlers.length; k++)
plotTiddler( store.getTiddler(plotTiddlers[k]) );
}
for (var i=0; i<results.length; i++)
{
if (!g.getValue(results[i].title, "graph.startLife"))
g.addNode(results[i].title);
else
waitingList.push(results[i]);
}
relink();
function plotGetTableLine(line) {
params = line.split('|');
node = params[1];
if (!node) return;
annot = params[2];
link = params[3];
linktype = params[4]?params[4]:"plot";
if (link)
g.addEdge(node, link,{type:linktype, text:annot?annot:""})
else
g.addNode(node, annot);
}
function plotGetWikiLinks(node, line, mode) {
// mode = 0 : direct link, mode = 1 : backlink, mode = 2, group link
node = node.replace(/ /g,'').replace(/^\*/g, '').replace(/\'/g, '').replace(/\[/g,'').replace(/\]/g,'');
var tiddlerLinkRegExp = config.textPrimitives.tiddlerForcedLinkRegExp;
t=1;
function addInternalLink(link, annot) {
switch (mode) {
case '->' : g.addEdge(node, link,{type:"plot", text:annot}); break;
case '<-' : g.addEdge(link, node,{type:"plot", text:annot}); break;
case ':>' : g.addEdge(node, link,{type:"tag", text:annot}); break;
case ':<' : g.addEdge(link, node,{type:"tag", text:annot}); break;
}
}
//tiddlerLinkRegExp.lastIndex = 0;
var formatMatch = tiddlerLinkRegExp.exec(line);
while(formatMatch) {
//var lastIndex = tiddlerLinkRegExp.lastIndex;
if(formatMatch[2-t] && !config.formatterHelpers.isExternalLink(formatMatch[3-t])) // titledBrackettedLink
addInternalLink(formatMatch[3-t], formatMatch[2-t], node, mode)
else if(formatMatch[4-t] && formatMatch[4-t] != this.title) // brackettedLink
addInternalLink(formatMatch[4-t], "", node, mode);
//tiddlerLinkRegExp.lastIndex = lastIndex;
formatMatch = tiddlerLinkRegExp.exec(line);
}
}
function plotTiddler(tiddler) {
var lines = new Array();
lines = tiddler.text.split("\n");
for (var i=0; i < lines.length; i++) {
var line = lines[i];
if (line == "") continue;
if (line[0] == "|") plotGetTableLine(line);
var n = line.indexOf("->");
if (n != -1) plotGetWikiLinks(line.slice(0, n), line.slice(n+2), '->');
n = line.indexOf("<-");
if (n != -1) plotGetWikiLinks(line.slice(0, n), line.slice(n+2), '<-');
n = line.indexOf(":>");
if (n != -1) plotGetWikiLinks(line.slice(0, n), line.slice(n+2), ':>');
n = line.indexOf(":<");
if (n != -1) plotGetWikiLinks(line.slice(0, n), line.slice(n+2), ':<');
}
}
function relink() {
for (var i=0; i<results.length; i++)
{
if (!g.getValue(results[i].title, "graph.startLife"))
addLinks(results[i]);
}
}
function tiddlerIndexOf(a, t) {
for (var i=0; i<a.length; i++)
if (a[i].title == t) return i;
return -1;
}
function addLivingEdge(ta, tb, info) {
if (!g.getValue(tb, "graph.startLife") )
g.addEdge(ta, tb, info);
else if (time >= g.getValue(tb, "graph.startLife" ))
g.addEdge(ta, tb, info);
}
function addLinks(ta) {
var ignoreList = g.getValue(ta.title, "graph.ignore");
ignoreList = ignoreList ? ignoreList.readBracketedList():[];
if (parameters[0]["noname"].indexOf("notags") == -1) {
for (var j=0; j<results.length; j++) {
var tb = results[j];
if (ignoreList.contains(tb.title)) continue;
if ( ta.tags.contains(tb.title) )
addLivingEdge(ta.title, tb.title, {type:"tag", text:""});
}
}
if (parameters[0]["noname"].indexOf("backlinks") != -1) {
var references = store.getReferringTiddlers(ta.title);
for(var r=0; r<references.length; r++) {
if(references[r].title != ta.title
&& !references[r].tags.contains("excludeLists")
&& (tiddlerIndexOf(results, references[r].title) != -1 || !strict)
&& (!ignoreList.contains(references[r].title)) )
addLivingEdge(ta.title, references[r].title, {type:"back", text:""});
}
}
if (parameters[0]["noname"].indexOf("nolinks") == -1) {
var links = ta.annotatedLinks();
for (var r=0; r<links.length; r++) {
if ( (tiddlerIndexOf(results, links[r].link) != -1 || !strict)
&& !ignoreList.contains(links[r].link))
addLivingEdge(ta.title, links[r].link, links[r].info);
}
}
}
var layouter = new Graph.Layout.Spring(g);
layouter.prepare();
var renderer = new Graph.Renderer.Basic(canvas, g);
var interval = 0;
if (anim != 0)
interval = setInterval(animate, 250);
else
{
layouter.layout();
renderer.draw();
}
function animate()
{
timer.innerHTML = "time :"+time;
if (isdrag) {
elementToMove.style.left = newElementX + 'px';
elementToMove.style.top = newElementY + 'px';
layouter.reverse(renderer.factorX, renderer.factorY);
}
for (var i=waitingList.length-1; i>=0; i--) {
var current = waitingList[i];
if (time >= g.getValue(current.title, "graph.startLife")) {
g.addNode(current.title);
relink();
layouter.layoutPrepareLastNode();
waitingList.splice(i,1);
}
}
g.animate(time);
layouter.step();
renderer.draw();
time++;
if (time==anim || time > 500) clearInterval(interval);
}
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false; // this flag indicates that the mouse movement is actually a drag.
var mouseStartX, mouseStartY; // mouse position when drag starts
var elementStartX, elementStartY; // element position when drag starts
var newElementX, newElementY;
var elementToMove;
var bounds = new Array(4);
function movemouse(e)
{
if (isdrag)
{
var currentMouseX = nn6 ? e.clientX : event.clientX;
var currentMouseY = nn6 ? e.clientY : event.clientY;
newElementX = elementStartX + currentMouseX - mouseStartX;
newElementY = elementStartY + currentMouseY - mouseStartY;
/*/ check bounds
// note: the "-1" and "+1" is to avoid borders overlap
if(newElementX < bounds[0])
newElementX = bounds[0] + 1;
if(newElementX + elementToMove.offsetWidth > bounds[2])
newElementX = bounds[2] - elementToMove.offsetWidth - 1;
if(newElementY < bounds[1])
newElementY = bounds[1] + 1;
if(newElementY + elementToMove.offsetHeight > bounds[3])
newElementY = bounds[3] - elementToMove.offsetHeight - 1;*/
// move element
elementToMove.style.left = newElementX + 'px';
elementToMove.style.top = newElementY + 'px';
elementToMove.style.right = null;
elementToMove.style.bottom = null;
layouter.reverse(renderer.factorX, renderer.factorY);
return false;
}
}
function startDrag(e)
{
var eventSource = nn6 ? e.target : event.srcElement;
if(eventSource.tagName == 'HTML')
return;
while (eventSource != document.body && !hasClass(eventSource, "draggable"))
{
eventSource = nn6 ? eventSource.parentNode : eventSource.parentElement;
}
// if a draggable element was found, calculate its actual position
if (hasClass(eventSource, "draggable"))
{
time = 0;
isdrag = true;
elementToMove = eventSource;
// set absolute positioning on the element
//elementToMove.style.position = "absolute";
// calculate start point
elementStartX = elementToMove.offsetLeft;
elementStartY = elementToMove.offsetTop;
// calculate mouse start point
mouseStartX = nn6 ? e.clientX : event.clientX;
mouseStartY = nn6 ? e.clientY : event.clientY;
/*/ calculate bounds as left, top, width, height of the parent element
if(getStyle(elementToMove.parentNode, "position") == 'absolute')
{
bounds[0] = 0;
bounds[1] = 0;
}
else
{
bounds[0] = calculateOffsetLeft(elementToMove.parentNode);
bounds[1] = calculateOffsetTop(elementToMove.parentNode);
}
bounds[2] = bounds[0] + elementToMove.parentNode.offsetWidth;
bounds[3] = bounds[1] + elementToMove.parentNode.offsetHeight;*/
document.onmousemove = movemouse;
interval = setInterval(animate, 50);
return false;
}
}
function stopDrag(e)
{
isdrag=false;
elementToMove = null;
document.onmousemove = null;
clearInterval(interval);
animate(); // one last time to refresh correctly last mouse pos
}
document.onmousedown = startDrag;
document.onmouseup = stopDrag;
function hasClass(element, className)
{
if(!element || !element.className)
return false;
var classes = element.className.split(' ');
var i;
for(i = 0; i < classes.length; i++)
if(classes[i] == className)
return true;
return false;
}
function getStyle(node, styleProp)
{
// if not an element
if( node.nodeType != 1)
return;
var value;
if (node.currentStyle)
{
// ie case
styleProp = replaceDashWithCamelNotation(styleProp);
value = node.currentStyle[styleProp];
}
else if (window.getComputedStyle)
{
// mozilla case
value = document.defaultView.getComputedStyle(node, null).getPropertyValue(styleProp);
}
return value;
}
function replaceDashWithCamelNotation(value)
{
var pos = value.indexOf('-');
while(pos > 0 && value.length > pos + 1)
{
value = value.substring(0, pos) + value.substring(pos + 1, pos + 2).toUpperCase() + value.substring(pos + 2);
pos = value.indexOf('-');
}
return value;
}
/*
* This function calculates the absolute 'top' value for a html node
*/
function calculateOffsetTop(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
curtop = obj.offsetTop
while (obj = obj.offsetParent)
curtop += obj.offsetTop
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
/*
* This function calculates the absolute 'left' value for a html node
*/
function calculateOffsetLeft(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
curleft = obj.offsetLeft
while (obj = obj.offsetParent)
{
curleft += obj.offsetLeft;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
}
}
//}}}
|~ViewToolbar|refresh closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|
|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|
/***
Description: Contains the stuff you need to use Tiddlyspot
Note, you also need UploadPlugin, PasswordOptionPlugin and LoadRemoteFileThroughProxy
from http://tiddlywiki.bidix.info for a complete working Tiddlyspot site.
***/
//{{{
// edit this if you are migrating sites or retrofitting an existing TW
config.tiddlyspotSiteId = 'ideia';
// make it so you can by default see edit controls via http
config.options.chkHttpReadOnly = false;
window.readOnly = false; // make sure of it (for tw 2.2)
window.showBackstage = true; // show backstage too
// disable autosave in d3
if (window.location.protocol != "file:")
config.options.chkGTDLazyAutoSave = false;
// tweak shadow tiddlers to add upload button, password entry box etc
with (config.shadowTiddlers) {
SiteUrl = 'http://'+config.tiddlyspotSiteId+'.tiddlyspot.com';
SideBarOptions = SideBarOptions.replace(/(<<saveChanges>>)/,"$1<<tiddler TspotSidebar>>");
OptionsPanel = OptionsPanel.replace(/^/,"<<tiddler TspotOptions>>");
DefaultTiddlers = DefaultTiddlers.replace(/^/,"[[WelcomeToTiddlyspot]] ");
MainMenu = MainMenu.replace(/^/,"[[WelcomeToTiddlyspot]] ");
}
// create some shadow tiddler content
merge(config.shadowTiddlers,{
'WelcomeToTiddlyspot':[
"This document is a ~TiddlyWiki from tiddlyspot.com. A ~TiddlyWiki is an electronic notebook that is great for managing todo lists, personal information, and all sorts of things.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //What now?// @@ Before you can save any changes, you need to enter your password in the form below. Then configure privacy and other site settings at your [[control panel|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/controlpanel]] (your control panel username is //" + config.tiddlyspotSiteId + "//).",
"<<tiddler TspotControls>>",
"See also GettingStarted.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Working online// @@ You can edit this ~TiddlyWiki right now, and save your changes using the \"save to web\" button in the column on the right.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Working offline// @@ A fully functioning copy of this ~TiddlyWiki can be saved onto your hard drive or USB stick. You can make changes and save them locally without being connected to the Internet. When you're ready to sync up again, just click \"upload\" and your ~TiddlyWiki will be saved back to tiddlyspot.com.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Help!// @@ Find out more about ~TiddlyWiki at [[TiddlyWiki.com|http://tiddlywiki.com]]. Also visit [[TiddlyWiki.org|http://tiddlywiki.org]] for documentation on learning and using ~TiddlyWiki. New users are especially welcome on the [[TiddlyWiki mailing list|http://groups.google.com/group/TiddlyWiki]], which is an excellent place to ask questions and get help. If you have a tiddlyspot related problem email [[tiddlyspot support|mailto:support@tiddlyspot.com]].",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Enjoy :)// @@ We hope you like using your tiddlyspot.com site. Please email [[feedback@tiddlyspot.com|mailto:feedback@tiddlyspot.com]] with any comments or suggestions."
].join("\n"),
'TspotControls':[
"| tiddlyspot password:|<<option pasUploadPassword>>|",
"| site management:|<<upload http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/store.cgi index.html . . " + config.tiddlyspotSiteId + ">>//(requires tiddlyspot password)//<br>[[control panel|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/controlpanel]], [[download (go offline)|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/download]]|",
"| links:|[[tiddlyspot.com|http://tiddlyspot.com/]], [[FAQs|http://faq.tiddlyspot.com/]], [[blog|http://tiddlyspot.blogspot.com/]], email [[support|mailto:support@tiddlyspot.com]] & [[feedback|mailto:feedback@tiddlyspot.com]], [[donate|http://tiddlyspot.com/?page=donate]]|"
].join("\n"),
'TspotSidebar':[
"<<upload http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/store.cgi index.html . . " + config.tiddlyspotSiteId + ">><html><a href='http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/download' class='button'>download</a></html>"
].join("\n"),
'TspotOptions':[
"tiddlyspot password:",
"<<option pasUploadPassword>>",
""
].join("\n")
});
//}}}
| !date | !user | !location | !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |
| 05/02/2009 11:00:09 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . |
| 05/02/2009 11:19:56 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . |
| 16/04/2009 14:51:05 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.php|http://ideia.tiddlyspot.com/store.php]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | |
| 16/04/2009 14:53:14 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | |
| 16/04/2009 14:58:04 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . |
| 16/04/2009 14:59:44 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . | ok |
| 16/04/2009 15:00:27 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . |
| 16/04/2009 15:02:31 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . | ok |
| 16/04/2009 15:20:29 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . | ok |
| 16/04/2009 15:21:53 | YourName | [[/|http://ideia.tiddlyspot.com/]] | [[store.cgi|http://ideia.tiddlyspot.com/store.cgi]] | . | [[index.html | http://ideia.tiddlyspot.com/index.html]] | . |
/***
|''Name:''|UploadPlugin|
|''Description:''|Save to web a TiddlyWiki|
|''Version:''|4.1.3|
|''Date:''|Feb 24, 2008|
|''Source:''|http://tiddlywiki.bidix.info/#UploadPlugin|
|''Documentation:''|http://tiddlywiki.bidix.info/#UploadPluginDoc|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0|
|''Requires:''|PasswordOptionPlugin|
***/
//{{{
version.extensions.UploadPlugin = {
major: 4, minor: 1, revision: 3,
date: new Date("Feb 24, 2008"),
source: 'http://tiddlywiki.bidix.info/#UploadPlugin',
author: 'BidiX (BidiX (at) bidix (dot) info',
coreVersion: '2.2.0'
};
//
// Environment
//
if (!window.bidix) window.bidix = {}; // bidix namespace
bidix.debugMode = false; // true to activate both in Plugin and UploadService
//
// Upload Macro
//
config.macros.upload = {
// default values
defaultBackupDir: '', //no backup
defaultStoreScript: "store.php",
defaultToFilename: "index.html",
defaultUploadDir: ".",
authenticateUser: true // UploadService Authenticate User
};
config.macros.upload.label = {
promptOption: "Save and Upload this TiddlyWiki with UploadOptions",
promptParamMacro: "Save and Upload this TiddlyWiki in %0",
saveLabel: "save to web",
saveToDisk: "save to disk",
uploadLabel: "upload"
};
config.macros.upload.messages = {
noStoreUrl: "No store URL in parmeters or options",
usernameOrPasswordMissing: "Username or password missing"
};
config.macros.upload.handler = function(place,macroName,params) {
if (readOnly)
return;
var label;
if (document.location.toString().substr(0,4) == "http")
label = this.label.saveLabel;
else
label = this.label.uploadLabel;
var prompt;
if (params[0]) {
prompt = this.label.promptParamMacro.toString().format([this.destFile(params[0],
(params[1] ? params[1]:bidix.basename(window.location.toString())), params[3])]);
} else {
prompt = this.label.promptOption;
}
createTiddlyButton(place, label, prompt, function() {config.macros.upload.action(params);}, null, null, this.accessKey);
};
config.macros.upload.action = function(params)
{
// for missing macro parameter set value from options
if (!params) params = {};
var storeUrl = params[0] ? params[0] : config.options.txtUploadStoreUrl;
var toFilename = params[1] ? params[1] : config.options.txtUploadFilename;
var backupDir = params[2] ? params[2] : config.options.txtUploadBackupDir;
var uploadDir = params[3] ? params[3] : config.options.txtUploadDir;
var username = params[4] ? params[4] : config.options.txtUploadUserName;
var password = config.options.pasUploadPassword; // for security reason no password as macro parameter
// for still missing parameter set default value
if ((!storeUrl) && (document.location.toString().substr(0,4) == "http"))
storeUrl = bidix.dirname(document.location.toString())+'/'+config.macros.upload.defaultStoreScript;
if (storeUrl.substr(0,4) != "http")
storeUrl = bidix.dirname(document.location.toString()) +'/'+ storeUrl;
if (!toFilename)
toFilename = bidix.basename(window.location.toString());
if (!toFilename)
toFilename = config.macros.upload.defaultToFilename;
if (!uploadDir)
uploadDir = config.macros.upload.defaultUploadDir;
if (!backupDir)
backupDir = config.macros.upload.defaultBackupDir;
// report error if still missing
if (!storeUrl) {
alert(config.macros.upload.messages.noStoreUrl);
clearMessage();
return false;
}
if (config.macros.upload.authenticateUser && (!username || !password)) {
alert(config.macros.upload.messages.usernameOrPasswordMissing);
clearMessage();
return false;
}
bidix.upload.uploadChanges(false,null,storeUrl, toFilename, uploadDir, backupDir, username, password);
return false;
};
config.macros.upload.destFile = function(storeUrl, toFilename, uploadDir)
{
if (!storeUrl)
return null;
var dest = bidix.dirname(storeUrl);
if (uploadDir && uploadDir != '.')
dest = dest + '/' + uploadDir;
dest = dest + '/' + toFilename;
return dest;
};
//
// uploadOptions Macro
//
config.macros.uploadOptions = {
handler: function(place,macroName,params) {
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);
wizard.setValue("listWrapper",listWrapper);
this.refreshOptions(listWrapper,false);
var uploadCaption;
if (document.location.toString().substr(0,4) == "http")
uploadCaption = config.macros.upload.label.saveLabel;
else
uploadCaption = config.macros.upload.label.uploadLabel;
wizard.setButtons([
{caption: uploadCaption, tooltip: config.macros.upload.label.promptOption,
onClick: config.macros.upload.action},
{caption: this.cancelButton, tooltip: this.cancelButtonPrompt, onClick: this.onCancel}
]);
},
options: [
"txtUploadUserName",
"pasUploadPassword",
"txtUploadStoreUrl",
"txtUploadDir",
"txtUploadFilename",
"txtUploadBackupDir",
"chkUploadLog",
"txtUploadLogMaxLine"
],
refreshOptions: function(listWrapper) {
var opts = [];
for(i=0; i<this.options.length; i++) {
var opt = {};
opts.push();
opt.option = "";
n = this.options[i];
opt.name = n;
opt.lowlight = !config.optionsDesc[n];
opt.description = opt.lowlight ? this.unknownDescription : config.optionsDesc[n];
opts.push(opt);
}
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,opts[n].name,"no");
}
}
},
onCancel: function(e)
{
backstage.switchTab(null);
return false;
},
wizardTitle: "Upload with options",
step1Title: "These options are saved in cookies in your browser",
step1Html: "<input type='hidden' name='markList'></input><br>",
cancelButton: "Cancel",
cancelButtonPrompt: "Cancel prompt",
listViewTemplate: {
columns: [
{name: 'Description', field: 'description', title: "Description", type: 'WikiText'},
{name: 'Option', field: 'option', title: "Option", type: 'String'},
{name: 'Name', field: 'name', title: "Name", type: 'String'}
],
rowClasses: [
{className: 'lowlight', field: 'lowlight'}
]}
};
//
// upload functions
//
if (!bidix.upload) bidix.upload = {};
if (!bidix.upload.messages) bidix.upload.messages = {
//from saving
invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
backupSaved: "Backup saved",
backupFailed: "Failed to upload backup file",
rssSaved: "RSS feed uploaded",
rssFailed: "Failed to upload RSS feed file",
emptySaved: "Empty template uploaded",
emptyFailed: "Failed to upload empty template file",
mainSaved: "Main TiddlyWiki file uploaded",
mainFailed: "Failed to upload main TiddlyWiki file. Your changes have not been saved",
//specific upload
loadOriginalHttpPostError: "Can't get original file",
aboutToSaveOnHttpPost: 'About to upload on %0 ...',
storePhpNotFound: "The store script '%0' was not found."
};
bidix.upload.uploadChanges = function(onlyIfDirty,tiddlers,storeUrl,toFilename,uploadDir,backupDir,username,password)
{
var callback = function(status,uploadParams,original,url,xhr) {
if (!status) {
displayMessage(bidix.upload.messages.loadOriginalHttpPostError);
return;
}
if (bidix.debugMode)
alert(original.substr(0,500)+"\n...");
// Locate the storeArea div's
var posDiv = locateStoreArea(original);
if((posDiv[0] == -1) || (posDiv[1] == -1)) {
alert(config.messages.invalidFileError.format([localPath]));
return;
}
bidix.upload.uploadRss(uploadParams,original,posDiv);
};
if(onlyIfDirty && !store.isDirty())
return;
clearMessage();
// save on localdisk ?
if (document.location.toString().substr(0,4) == "file") {
var path = document.location.toString();
var localPath = getLocalPath(path);
saveChanges();
}
// get original
var uploadParams = new Array(storeUrl,toFilename,uploadDir,backupDir,username,password);
var originalPath = document.location.toString();
// If url is a directory : add index.html
if (originalPath.charAt(originalPath.length-1) == "/")
originalPath = originalPath + "index.html";
var dest = config.macros.upload.destFile(storeUrl,toFilename,uploadDir);
var log = new bidix.UploadLog();
log.startUpload(storeUrl, dest, uploadDir, backupDir);
displayMessage(bidix.upload.messages.aboutToSaveOnHttpPost.format([dest]));
if (bidix.debugMode)
alert("about to execute Http - GET on "+originalPath);
var r = doHttp("GET",originalPath,null,null,username,password,callback,uploadParams,null);
if (typeof r == "string")
displayMessage(r);
return r;
};
bidix.upload.uploadRss = function(uploadParams,original,posDiv)
{
var callback = function(status,params,responseText,url,xhr) {
if(status) {
var destfile = responseText.substring(responseText.indexOf("destfile:")+9,responseText.indexOf("\n", responseText.indexOf("destfile:")));
displayMessage(bidix.upload.messages.rssSaved,bidix.dirname(url)+'/'+destfile);
bidix.upload.uploadMain(params[0],params[1],params[2]);
} else {
displayMessage(bidix.upload.messages.rssFailed);
}
};
// do uploadRss
if(config.options.chkGenerateAnRssFeed) {
var rssPath = uploadParams[1].substr(0,uploadParams[1].lastIndexOf(".")) + ".xml";
var rssUploadParams = new Array(uploadParams[0],rssPath,uploadParams[2],'',uploadParams[4],uploadParams[5]);
var rssString = generateRss();
// no UnicodeToUTF8 conversion needed when location is "file" !!!
if (document.location.toString().substr(0,4) != "file")
rssString = convertUnicodeToUTF8(rssString);
bidix.upload.httpUpload(rssUploadParams,rssString,callback,Array(uploadParams,original,posDiv));
} else {
bidix.upload.uploadMain(uploadParams,original,posDiv);
}
};
bidix.upload.uploadMain = function(uploadParams,original,posDiv)
{
var callback = function(status,params,responseText,url,xhr) {
var log = new bidix.UploadLog();
if(status) {
// if backupDir specified
if ((params[3]) && (responseText.indexOf("backupfile:") > -1)) {
var backupfile = responseText.substring(responseText.indexOf("backupfile:")+11,responseText.indexOf("\n", responseText.indexOf("backupfile:")));
displayMessage(bidix.upload.messages.backupSaved,bidix.dirname(url)+'/'+backupfile);
}
var destfile = responseText.substring(responseText.indexOf("destfile:")+9,responseText.indexOf("\n", responseText.indexOf("destfile:")));
displayMessage(bidix.upload.messages.mainSaved,bidix.dirname(url)+'/'+destfile);
store.setDirty(false);
log.endUpload("ok");
} else {
alert(bidix.upload.messages.mainFailed);
displayMessage(bidix.upload.messages.mainFailed);
log.endUpload("failed");
}
};
// do uploadMain
var revised = bidix.upload.updateOriginal(original,posDiv);
bidix.upload.httpUpload(uploadParams,revised,callback,uploadParams);
};
bidix.upload.httpUpload = function(uploadParams,data,callback,params)
{
var localCallback = function(status,params,responseText,url,xhr) {
url = (url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1));
if (xhr.status == 404)
alert(bidix.upload.messages.storePhpNotFound.format([url]));
if ((bidix.debugMode) || (responseText.indexOf("Debug mode") >= 0 )) {
alert(responseText);
if (responseText.indexOf("Debug mode") >= 0 )
responseText = responseText.substring(responseText.indexOf("\n\n")+2);
} else if (responseText.charAt(0) != '0')
alert(responseText);
if (responseText.charAt(0) != '0')
status = null;
callback(status,params,responseText,url,xhr);
};
// do httpUpload
var boundary = "---------------------------"+"AaB03x";
var uploadFormName = "UploadPlugin";
// compose headers data
var sheader = "";
sheader += "--" + boundary + "\r\nContent-disposition: form-data; name=\"";
sheader += uploadFormName +"\"\r\n\r\n";
sheader += "backupDir="+uploadParams[3] +
";user=" + uploadParams[4] +
";password=" + uploadParams[5] +
";uploaddir=" + uploadParams[2];
if (bidix.debugMode)
sheader += ";debug=1";
sheader += ";;\r\n";
sheader += "\r\n" + "--" + boundary + "\r\n";
sheader += "Content-disposition: form-data; name=\"userfile\"; filename=\""+uploadParams[1]+"\"\r\n";
sheader += "Content-Type: text/html;charset=UTF-8" + "\r\n";
sheader += "Content-Length: " + data.length + "\r\n\r\n";
// compose trailer data
var strailer = new String();
strailer = "\r\n--" + boundary + "--\r\n";
data = sheader + data + strailer;
if (bidix.debugMode) alert("about to execute Http - POST on "+uploadParams[0]+"\n with \n"+data.substr(0,500)+ " ... ");
var r = doHttp("POST",uploadParams[0],data,"multipart/form-data; ;charset=UTF-8; boundary="+boundary,uploadParams[4],uploadParams[5],localCallback,params,null);
if (typeof r == "string")
displayMessage(r);
return r;
};
// same as Saving's updateOriginal but without convertUnicodeToUTF8 calls
bidix.upload.updateOriginal = function(original, posDiv)
{
if (!posDiv)
posDiv = locateStoreArea(original);
if((posDiv[0] == -1) || (posDiv[1] == -1)) {
alert(config.messages.invalidFileError.format([localPath]));
return;
}
var revised = original.substr(0,posDiv[0] + startSaveArea.length) + "\n" +
store.allTiddlersAsHtml() + "\n" +
original.substr(posDiv[1]);
var newSiteTitle = getPageTitle().htmlEncode();
revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");
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;
};
//
// UploadLog
//
// config.options.chkUploadLog :
// false : no logging
// true : logging
// config.options.txtUploadLogMaxLine :
// -1 : no limit
// 0 : no Log lines but UploadLog is still in place
// n : the last n lines are only kept
// NaN : no limit (-1)
bidix.UploadLog = function() {
if (!config.options.chkUploadLog)
return; // this.tiddler = null
this.tiddler = store.getTiddler("UploadLog");
if (!this.tiddler) {
this.tiddler = new Tiddler();
this.tiddler.title = "UploadLog";
this.tiddler.text = "| !date | !user | !location | !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |";
this.tiddler.created = new Date();
this.tiddler.modifier = config.options.txtUserName;
this.tiddler.modified = new Date();
store.addTiddler(this.tiddler);
}
return this;
};
bidix.UploadLog.prototype.addText = function(text) {
if (!this.tiddler)
return;
// retrieve maxLine when we need it
var maxLine = parseInt(config.options.txtUploadLogMaxLine,10);
if (isNaN(maxLine))
maxLine = -1;
// add text
if (maxLine != 0)
this.tiddler.text = this.tiddler.text + text;
// Trunck to maxLine
if (maxLine >= 0) {
var textArray = this.tiddler.text.split('\n');
if (textArray.length > maxLine + 1)
textArray.splice(1,textArray.length-1-maxLine);
this.tiddler.text = textArray.join('\n');
}
// update tiddler fields
this.tiddler.modifier = config.options.txtUserName;
this.tiddler.modified = new Date();
store.addTiddler(this.tiddler);
// refresh and notifiy for immediate update
story.refreshTiddler(this.tiddler.title);
store.notify(this.tiddler.title, true);
};
bidix.UploadLog.prototype.startUpload = function(storeUrl, toFilename, uploadDir, backupDir) {
if (!this.tiddler)
return;
var now = new Date();
var text = "\n| ";
var filename = bidix.basename(document.location.toString());
if (!filename) filename = '/';
text += now.formatString("0DD/0MM/YYYY 0hh:0mm:0ss") +" | ";
text += config.options.txtUserName + " | ";
text += "[["+filename+"|"+location + "]] |";
text += " [[" + bidix.basename(storeUrl) + "|" + storeUrl + "]] | ";
text += uploadDir + " | ";
text += "[[" + bidix.basename(toFilename) + " | " +toFilename + "]] | ";
text += backupDir + " |";
this.addText(text);
};
bidix.UploadLog.prototype.endUpload = function(status) {
if (!this.tiddler)
return;
this.addText(" "+status+" |");
};
//
// Utilities
//
bidix.checkPlugin = function(plugin, major, minor, revision) {
var ext = version.extensions[plugin];
if (!
(ext &&
((ext.major > major) ||
((ext.major == major) && (ext.minor > minor)) ||
((ext.major == major) && (ext.minor == minor) && (ext.revision >= revision))))) {
// write error in PluginManager
if (pluginInfo)
pluginInfo.log.push("Requires " + plugin + " " + major + "." + minor + "." + revision);
eval(plugin); // generate an error : "Error: ReferenceError: xxxx is not defined"
}
};
bidix.dirname = function(filePath) {
if (!filePath)
return;
var lastpos;
if ((lastpos = filePath.lastIndexOf("/")) != -1) {
return filePath.substring(0, lastpos);
} else {
return filePath.substring(0, filePath.lastIndexOf("\\"));
}
};
bidix.basename = function(filePath) {
if (!filePath)
return;
var lastpos;
if ((lastpos = filePath.lastIndexOf("#")) != -1)
filePath = filePath.substring(0, lastpos);
if ((lastpos = filePath.lastIndexOf("/")) != -1) {
return filePath.substring(lastpos + 1);
} else
return filePath.substring(filePath.lastIndexOf("\\")+1);
};
bidix.initOption = function(name,value) {
if (!config.options[name])
config.options[name] = value;
};
//
// Initializations
//
// require PasswordOptionPlugin 1.0.1 or better
bidix.checkPlugin("PasswordOptionPlugin", 1, 0, 1);
// styleSheet
setStylesheet('.txtUploadStoreUrl, .txtUploadBackupDir, .txtUploadDir {width: 22em;}',"uploadPluginStyles");
//optionsDesc
merge(config.optionsDesc,{
txtUploadStoreUrl: "Url of the UploadService script (default: store.php)",
txtUploadFilename: "Filename of the uploaded file (default: in index.html)",
txtUploadDir: "Relative Directory where to store the file (default: . (downloadService directory))",
txtUploadBackupDir: "Relative Directory where to backup the file. If empty no backup. (default: ''(empty))",
txtUploadUserName: "Upload Username",
pasUploadPassword: "Upload Password",
chkUploadLog: "do Logging in UploadLog (default: true)",
txtUploadLogMaxLine: "Maximum of lines in UploadLog (default: 10)"
});
// Options Initializations
bidix.initOption('txtUploadStoreUrl','');
bidix.initOption('txtUploadFilename','');
bidix.initOption('txtUploadDir','');
bidix.initOption('txtUploadBackupDir','');
bidix.initOption('txtUploadUserName','');
bidix.initOption('pasUploadPassword','');
bidix.initOption('chkUploadLog',true);
bidix.initOption('txtUploadLogMaxLine','10');
// Backstage
merge(config.tasks,{
uploadOptions: {text: "upload", tooltip: "Change UploadOptions and Upload", content: '<<uploadOptions>>'}
});
config.backstageTasks.push("uploadOptions");
//}}}
//{{{
/*****
*
* Intersection.js
* Stripped down version for rectangles, by YBA
*
* copyright 2002-2003, Kevin Lindsey
*
*****/
function Intersection(status) {
if ( arguments.length > 0 ) {
this.init(status);
}
}
Intersection.prototype.init = function(status) {
this.status = status;
this.points = new Array();
};
Intersection.prototype.toString = function () {
var result = this.status;
for (var i=0; i<this.points.length; i++)
result += "- "+this.points[i];
return result;
}
Intersection.prototype.appendPoint = function(point) {
this.points.push(point);
};
Intersection.prototype.appendPoints = function(points) {
this.points = this.points.concat(points);
};
Intersection.intersectLineLine = function(a1, a2, b1, b2) {
var result;
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
if ( u_b != 0 ) {
var ua = ua_t / u_b;
var ub = ub_t / u_b;
if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) {
result = new Intersection("Intersection");
result.points.push(
new Point2D(
a1.x + ua * (a2.x - a1.x),
a1.y + ua * (a2.y - a1.y)
)
);
} else {
result = new Intersection("No Intersection");
}
} else {
if ( ua_t == 0 || ub_t == 0 ) {
result = new Intersection("Coincident");
} else {
result = new Intersection("Parallel");
}
}
return result;
};
Intersection.intersectLineRectangle = function(a1, a2, r1, r2) {
var min = r1.min(r2);
var max = r1.max(r2);
var topRight = new Point2D( max.x, min.y );
var bottomLeft = new Point2D( min.x, max.y );
var inter1 = Intersection.intersectLineLine(min, topRight, a1, a2);
var inter2 = Intersection.intersectLineLine(topRight, max, a1, a2);
var inter3 = Intersection.intersectLineLine(max, bottomLeft, a1, a2);
var inter4 = Intersection.intersectLineLine(bottomLeft, min, a1, a2);
var result = new Intersection("No Intersection");
result.appendPoints(inter1.points);
result.appendPoints(inter2.points);
result.appendPoints(inter3.points);
result.appendPoints(inter4.points);
if ( result.points.length > 0 )
result.status = "Intersection";
return result;
};
//}}}
graph.fillStyle:green
graph.endLife:25
//{{{
/*****
*
* Point2D.js
*
* copyright 2001-2002, Kevin Lindsey
*
*****/
/*****
*
* Point2D
*
*****/
/*****
*
* constructor
*
*****/
function Point2D(x, y) {
if ( arguments.length > 0 ) {
this.x = x;
this.y = y;
}
}
/*****
*
* clone
*
*****/
Point2D.prototype.clone = function() {
return new Point2D(this.x, this.y);
};
/*****
*
* add
*
*****/
Point2D.prototype.add = function(that) {
return new Point2D(this.x+that.x, this.y+that.y);
};
/*****
*
* addEquals
*
*****/
Point2D.prototype.addEquals = function(that) {
this.x += that.x;
this.y += that.y;
return this;
};
/*****
*
* offset - used in dom_graph
*
* This method is based on code written by Walter Korman
* http://www.go2net.com/internet/deep/1997/05/07/body.html
* which is in turn based on an algorithm by Sven Moen
*
*****/
Point2D.prototype.offset = function(a, b) {
var result = 0;
if ( !( b.x <= this.x || this.x + a.x <= 0 ) ) {
var t = b.x * a.y - a.x * b.y;
var s;
var d;
if ( t > 0 ) {
if ( this.x < 0 ) {
s = this.x * a.y;
d = s / a.x - this.y;
} else if ( this.x > 0 ) {
s = this.x * b.y;
d = s / b.x - this.y
} else {
d = -this.y;
}
} else {
if ( b.x < this.x + a.x ) {
s = ( b.x - this.x ) * a.y;
d = b.y - (this.y + s / a.x);
} else if ( b.x > this.x + a.x ) {
s = (a.x + this.x) * b.y;
d = s / b.x - (this.y + a.y);
} else {
d = b.y - (this.y + a.y);
}
}
if ( d > 0 ) {
result = d;
}
}
return result;
};
/*****
*
* rmoveto
*
*****/
Point2D.prototype.rmoveto = function(dx, dy) {
this.x += dx;
this.y += dy;
};
/*****
*
* scalarAdd
*
*****/
Point2D.prototype.scalarAdd = function(scalar) {
return new Point2D(this.x+scalar, this.y+scalar);
};
/*****
*
* scalarAddEquals
*
*****/
Point2D.prototype.scalarAddEquals = function(scalar) {
this.x += scalar;
this.y += scalar;
return this;
};
/*****
*
* subtract
*
*****/
Point2D.prototype.subtract = function(that) {
return new Point2D(this.x-that.x, this.y-that.y);
};
/*****
*
* subtractEquals
*
*****/
Point2D.prototype.subtractEquals = function(that) {
this.x -= that.x;
this.y -= that.y;
return this;
};
/*****
*
* scalarSubtract
*
*****/
Point2D.prototype.scalarSubtract = function(scalar) {
return new Point2D(this.x-scalar, this.y-scalar);
};
/*****
*
* scalarSubtractEquals
*
*****/
Point2D.prototype.scalarSubtractEquals = function(scalar) {
this.x -= scalar;
this.y -= scalar;
return this;
};
/*****
*
* multiply
*
*****/
Point2D.prototype.multiply = function(scalar) {
return new Point2D(this.x*scalar, this.y*scalar);
};
/*****
*
* multiplyEquals
*
*****/
Point2D.prototype.multiplyEquals = function(scalar) {
this.x *= scalar;
this.y *= scalar;
return this;
};
/*****
*
* divide
*
*****/
Point2D.prototype.divide = function(scalar) {
return new Point2D(this.x/scalar, this.y/scalar);
};
/*****
*
* divideEquals
*
*****/
Point2D.prototype.divideEquals = function(scalar) {
this.x /= scalar;
this.y /= scalar;
return this;
};
/*****
*
* comparison methods
*
* these were a nice idea, but ... It would be better to define these names
* in two parts so that the first part is the x comparison and the second is
* the y. For example, to test p1.x < p2.x and p1.y >= p2.y, you would call
* p1.lt_gte(p2). Honestly, I only did these types of comparisons in one
* Intersection routine, so these probably could be removed.
*
*****/
/*****
*
* compare
*
*****/
Point2D.prototype.compare = function(that) {
return (this.x - that.x || this.y - that.y);
};
/*****
*
* eq - equal
*
*****/
Point2D.prototype.eq = function(that) {
return ( this.x == that.x && this.y == that.y );
};
/*****
*
* lt - less than
*
*****/
Point2D.prototype.lt = function(that) {
return ( this.x < that.x && this.y < that.y );
};
/*****
*
* lte - less than or equal
*
*****/
Point2D.prototype.lte = function(that) {
return ( this.x <= that.x && this.y <= that.y );
};
/*****
*
* gt - greater than
*
*****/
Point2D.prototype.gt = function(that) {
return ( this.x > that.x && this.y > that.y );
};
/*****
*
* gte - greater than or equal
*
*****/
Point2D.prototype.gte = function(that) {
return ( this.x >= that.x && this.y >= that.y );
};
/*****
*
* utility methods
*
*****/
/*****
*
* lerp
*
*****/
Point2D.prototype.lerp = function(that, t) {
return new Point2D(
this.x + (that.x - this.x) * t,
this.y + (that.y - this.y) * t
);
};
/*****
*
* distanceFrom
*
*****/
Point2D.prototype.distanceFrom = function(that) {
var dx = this.x - that.x;
var dy = this.y - that.y;
return Math.sqrt(dx*dx + dy*dy);
};
/*****
*
* min
*
*****/
Point2D.prototype.min = function(that) {
return new Point2D(
Math.min( this.x, that.x ),
Math.min( this.y, that.y )
);
};
/*****
*
* max
*
*****/
Point2D.prototype.max = function(that) {
return new Point2D(
Math.max( this.x, that.x ),
Math.max( this.y, that.y )
);
};
/*****
*
* toString
*
*****/
Point2D.prototype.toString = function() {
return Math.floor(this.x)+","+Math.floor(this.y);
// return this.x + "," + this.y;
};
/*****
*
* get/set methods
*
*****/
/*****
*
* setXY
*
*****/
Point2D.prototype.setXY = function(x, y) {
this.x = x;
this.y = y;
};
/*****
*
* setFromPoint
*
*****/
Point2D.prototype.setFromPoint = function(that) {
this.x = that.x;
this.y = that.y;
};
/*****
*
* swap
*
*****/
Point2D.prototype.swap = function(that) {
var x = this.x;
var y = this.y;
this.x = that.x;
this.y = that.y;
that.x = x;
that.y = y;
};
//}}}