Welcome to TiddlyWiki created by Jeremy Ruston; Copyright © 2004-2007 Jeremy Ruston, Copyright © 2007-2011 UnaMesa Association
/***
|''Description''|This patch makes ForEachTiddlerPlugin v 1.0.9+ compatible with ~TiddlyWikis v1.2.x and above|
***/
//{{{
//====================================================================================
// TiddlyWiki.forEachTiddler Function, adapted from ForEachTiddlerPlugin v 1.0.8
//====================================================================================
//
// Calls the callback for each tiddler
//
// @param callback
//
if(!TiddlyWiki.prototype.forEachTiddler) {
TiddlyWiki.prototype.forEachTiddler = function(callback) {
for(var t in this.tiddlers)
callback.call(this,t,this.tiddlers[t]);
};
}
//====================================================================================
// TiddlyWiki.importTiddlyWiki Function, adapted from ForEachTiddlerPlugin v 1.0.8
//====================================================================================
//
// adds all tiddlers from the TiddlyWiki represented in content as ..., returns the TiddlyWiki itself on sucess or null otherwise
//
// @param content
//
if(!TiddlyWiki.prototype.importTiddlyWiki)
TiddlyWiki.prototype.importTiddlyWiki = function(content) {
// The legacy code, for TW < 2.2
// Locate the storeArea div's
var posOpeningDiv = content.indexOf(startSaveArea);
var posClosingDiv = content.lastIndexOf(endSaveArea);
if((posOpeningDiv == -1) || (posClosingDiv == -1)) {
throw "File '"+path+"' is not a TiddlyWiki.";
}
var storageText = content.substr(posOpeningDiv + startSaveArea.length, posClosingDiv);
// Create a "div" element that contains the storage text
var myStorageDiv = document.createElement("div");
myStorageDiv.innerHTML = storageText;
myStorageDiv.normalize();
// Create all tiddlers in a new TiddlyWiki
// (following code is modified copy of TiddlyWiki.prototype.loadFromDiv)
var store = myStorageDiv.childNodes;
for(var t = 0; t < store.length; t++) {
var e = store[t];
var title = null;
if(e.getAttribute)
title = e.getAttribute("tiddler");
if(!title && e.id && e.id.substr(0,lenPrefix) == idPrefix)
title = e.id.substr(lenPrefix);
if(title && title !== "") {
var tiddler = tiddlyWiki.createTiddler(title);
tiddler.loadFromDiv(e,title);
}
}
return this;
}
//====================================================================================
// Array methods: these are adapted from the TW core v2.7.0
//====================================================================================
//====================================================================================
// Array.indexOf Function
//====================================================================================
//
// Returns the index of the first occurance of the given item in the array or
// -1 when no such item exists.
//
// @param item [may be null]
//
// @param from [optional]
// value: if specified, not the entire array is searched
//
if(!Array.prototype.indexOf)
Array.prototype.indexOf = function(item,from) {
if(!from)
from = 0;
var i;
for(i = from; i < this.length; i++) {
if(this[i] === item)
return i;
}
return -1;
};
//====================================================================================
// Array.contains Function
//====================================================================================
//
// Returns true when the array contains the given item, otherwise false.
//
// @param item [may be null]
//
if(!Array.prototype.contains)
Array.prototype.contains = function(item) {
return this.indexOf(item) != -1;
};
//====================================================================================
// Array.containsAny Function
//====================================================================================
//
// Returns true when the array contains at least one of the elements
// of the item. Otherwise (or when items contains no elements) false is returned.
//
if(!Array.prototype.containsAny)
Array.prototype.containsAny = function(items) {
var i;
for(i=0; i < items.length; i++)
if(this.indexOf(items[i]) != -1)
return true;
return false;
};
//====================================================================================
// Array.containsAll Function
//====================================================================================
//
// Returns true when the array contains all the items, otherwise false.
//
// When items is null false is returned (even if the array contains a null).
//
// @param items [may be null]
//
if(!Array.prototype.containsAll)
Array.prototype.containsAll = function(items) {
var i;
for(i = 0; i < items.length; i++)
if(this.indexOf(items[i]) == -1)
return false;
return true;
};
//}}}
[[ForEachTiddlerPluginHere]]
''Syntax:''
|>|{{{<<}}}''forEachTiddler'' [''in'' //tiddlyWikiPath//] [''where'' //whereCondition//] [''sortBy'' //sortExpression// [''ascending'' //or// ''descending'']] [''script'' //scriptText//] [//action// [//actionParameters//]]{{{>>}}}|
|//tiddlyWikiPath//|The filepath to the ~TiddlyWiki the macro should work on. When missing the current ~TiddlyWiki is used.|
|//whereCondition//|(quoted) ~JavaScript boolean expression. May refer to the build-in variables {{{tiddler}}} and {{{context}}}.|
|//sortExpression//|(quoted) ~JavaScript expression returning "comparable" objects (using '{{{<}}}','{{{>}}}','{{{==}}}'. May refer to the build-in variables {{{tiddler}}} and {{{context}}}.|
|//scriptText//|(quoted) ~JavaScript text. Typically defines ~JavaScript functions that are called by the various ~JavaScript expressions (whereClause, sortClause, action arguments,...)|
|//action//|The action that should be performed on every selected tiddler, in the given order. By default the actions [[addToList|AddToListAction]] and [[write|WriteAction]] are supported. When no action is specified [[addToList|AddToListAction]] is used.|
|//actionParameters//|(action specific) parameters the action may refer while processing the tiddlers (see action descriptions for details). <<tiddler [[JavaScript in actionParameters]]>>|
|>|~~Syntax formatting: Keywords in ''bold'', optional parts in [...]. 'or' means that exactly one of the two alternatives must exist.~~|
See details see [[ForEachTiddlerMacro]] and [[ForEachTiddlerExamples]].
Create customizable lists, tables etc. for your selections of tiddlers. Specify the tiddlers to include and their order through a powerful language.
''Syntax:''
|>|{{{<<}}}''forEachTiddler'' [''in'' //tiddlyWikiPath//] [''where'' //whereCondition//] [''sortBy'' //sortExpression// [''ascending'' //or// ''descending'']] [''script'' //scriptText//] [//action// [//actionParameters//]]{{{>>}}}|
|//tiddlyWikiPath//|The filepath to the TiddlyWiki the macro should work on. When missing the current TiddlyWiki is used.|
|//whereCondition//|(quoted) JavaScript boolean expression. May refer to the build-in variables {{{tiddler}}} and {{{context}}}.|
|//sortExpression//|(quoted) JavaScript expression returning "comparable" objects (using '{{{<}}}','{{{>}}}','{{{==}}}'. May refer to the build-in variables {{{tiddler}}} and {{{context}}}.|
|//scriptText//|(quoted) JavaScript text. Typically defines JavaScript functions that are called by the various JavaScript expressions (whereClause, sortClause, action arguments,...)|
|//action//|The action that should be performed on every selected tiddler, in the given order. By default the actions [[addToList|AddToListAction]] and [[write|WriteAction]] are supported. When no action is specified [[addToList|AddToListAction]] is used.|
|//actionParameters//|(action specific) parameters the action may refer while processing the tiddlers (see action descriptions for details). <<tiddler [[JavaScript in actionParameters]]>>|
|>|~~Syntax formatting: Keywords in ''bold'', optional parts in [...]. 'or' means that exactly one of the two alternatives must exist.~~|
''Using ~JavaScript''
To give you a lot of flexibility the [[ForEachTiddlerMacro]] uses ~JavaScript in its arguments. Even if you are not that familiar with ~JavaScript you may find forEachTiddler useful. Just have a look at the various ready-to-use [[ForEachTiddlerExamples]] and adapt them to your needs.
''The Elements of the Macro''
The arguments of the ForEachTiddlerMacro consist of multiple parts, each of them being optional.
<<slider chkFETInClause [[inClause]] "inClause" "inClause">>
<<slider chkFETWhereClause [[whereClause]] "whereClause" "whereClause">>
<<slider chkFETSortClause [[sortClause]] "sortClause" "sortClause">>
<<slider chkFETScriptClause [[scriptClause]] "scriptClause" "scriptClause">>
<<slider chkFETActions [[Action Specification]] "Action Specification" "Action Specification">>
''Using Macros and ">" inside the forEachTiddler Macro''
You may use other macro calls into the expression, especially in the actionParameters. To avoid that the {{{>>}}} of such a macro call is misinterpreted as the end of the {{{<<forEachTiddler...>>}}} macro you must escape the {{{>>}}} of the inner macro with {{{$))}}} E.g. if you want to use {{{<<tiddler ...>>}}} inside the {{{forEachTiddler}}} macro you have to write {{{<<tiddler ...$))}}}.
In addition it is necessary to escape single {{{>}}} with the text {{{$)}}}.
''Using {{{<<tiddler ... with: ...>>}}} to re-use ~ForEachTiddler definitions''
Sometimes you may want to use a certain ~ForEachTiddler definition in slight variations. E.g. you may want to list either the tiddlers tagged with "ToDo" and in the other case with "Done". To do so you may use "Tiddler parameters". Here an example:
Replace the variable part of the ~ForEachTiddler definition with $1 ($2,... $9 are supported). E.g. you may create the tiddler "ListTaggedTiddlers" like this
{{{
<<forEachTiddler
where
'tiddler.tags.contains("$1")'
>>
}}}
Now you can use the ~ListTaggedTiddlers for various specific tags, using the {{{<<tiddler ...>>}}} macro:
{{{
<<tiddler ListTaggedTiddlers with: "systemConfig">>
}}}
{{{
<<tiddler ListTaggedTiddlers with: "Plugin">>
}}}
See also [[ForEachTiddlerExamples]].
/***
|''Name:''|ForEachTiddlerPlugin|
|''Version:''|1.0.8 (2007-04-12)|
|''Source:''|http://tiddlywiki.abego-software.de/#ForEachTiddlerPlugin|
|''Author:''|UdoBorkowski (ub [at] abego-software [dot] de)|
|''Licence:''|[[BSD open source license (abego Software)|http://www.abego-software.de/legal/apl-v10.html]]|
|''Copyright:''|© 2005-2007 [[abego Software|http://www.abego-software.de]]|
|''TiddlyWiki:''|1.2.38+, 2.0|
|''Browser:''|Firefox 1.0.4+; Firefox 1.5; ~InternetExplorer 6.0|
|''Description:''|Create customizable lists, tables etc. for your selections of tiddlers. Specify the tiddlers to include and their order through a powerful language.|
***/
//{{{
//============================================================================
//============================================================================
// ForEachTiddlerPlugin
//============================================================================
//============================================================================
// Only install once
if (!version.extensions.ForEachTiddlerPlugin) {
if (!window.abego) window.abego = {};
version.extensions.ForEachTiddlerPlugin = {
major: 1, minor: 0, revision: 8,
date: new Date(2007,3,12),
source: "http://tiddlywiki.abego-software.de/#ForEachTiddlerPlugin",
licence: "[[BSD open source license (abego Software)|http://www.abego-software.de/legal/apl-v10.html]]",
copyright: "Copyright (c) abego Software GmbH, 2005-2007 (www.abego-software.de)"
};
// For backward compatibility with TW 1.2.x
//
if (!TiddlyWiki.prototype.forEachTiddler) {
TiddlyWiki.prototype.forEachTiddler = function(callback) { // YL: better be updated or may be removed
for(var t in this.tiddlers)
callback.call(this,t,this.tiddlers[t]);
};
}
//============================================================================
// forEachTiddler Macro
//============================================================================
version.extensions.forEachTiddler = {
major: 1, minor: 0, revision: 8, date: new Date(2007,3,12), provider: "http://tiddlywiki.abego-software.de"};
// ---------------------------------------------------------------------------
// Configurations and constants
// ---------------------------------------------------------------------------
config.macros.forEachTiddler = {
// Standard Properties
label: "forEachTiddler",
prompt: "Perform actions on a (sorted) selection of tiddlers",
// actions
actions: {
addToList: {},
write: {}
}
};
// ---------------------------------------------------------------------------
// The forEachTiddler Macro Handler
// ---------------------------------------------------------------------------
config.macros.forEachTiddler.getContainingTiddler = function(e) {
while(e && !hasClass(e,"tiddler"))
e = e.parentNode;
var title = e ? e.getAttribute("tiddler") : null;
return title ? store.getTiddler(title) : null;
};
config.macros.forEachTiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler) {
// config.macros.forEachTiddler.traceMacroCall(place,macroName,params,wikifier,paramString,tiddler);
if (!tiddler) tiddler = config.macros.forEachTiddler.getContainingTiddler(place);
// --- Parsing ------------------------------------------
var i = 0; // index running over the params
// Parse the "in" clause
var tiddlyWikiPath = undefined;
if ((i < params.length) && params[i] == "in") {
i++;
if (i >= params.length) {
this.handleError(place, "TiddlyWiki path expected behind 'in'.");
return;
}
tiddlyWikiPath = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the where clause
var whereClause ="true";
if ((i < params.length) && params[i] == "where") {
i++;
whereClause = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the sort stuff
var sortClause = null;
var sortAscending = true;
if ((i < params.length) && params[i] == "sortBy") {
i++;
if (i >= params.length) {
this.handleError(place, "sortClause missing behind 'sortBy'.");
return;
}
sortClause = this.paramEncode(params[i]);
i++;
if ((i < params.length) && (params[i] == "ascending" || params[i] == "descending")) {
sortAscending = params[i] == "ascending";
i++;
}
}
// Parse the script
var scriptText = null;
if ((i < params.length) && params[i] == "script") {
i++;
scriptText = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the action.
// When we are already at the end use the default action
var actionName = "addToList";
if (i < params.length) {
if (!config.macros.forEachTiddler.actions[params[i]]) {
this.handleError(place, "Unknown action '"+params[i]+"'.");
return;
} else {
actionName = params[i];
i++;
}
}
// Get the action parameter
// (the parsing is done inside the individual action implementation.)
var actionParameter = params.slice(i);
// --- Processing ------------------------------------------
try {
this.performMacro({
place: place,
inTiddler: tiddler,
whereClause: whereClause,
sortClause: sortClause,
sortAscending: sortAscending,
actionName: actionName,
actionParameter: actionParameter,
scriptText: scriptText,
tiddlyWikiPath: tiddlyWikiPath});
} catch (e) {
this.handleError(place, e);
}
};
// Returns an object with properties "tiddlers" and "context".
// tiddlers holds the (sorted) tiddlers selected by the parameter,
// context the context of the execution of the macro.
//
// The action is not yet performed.
//
// @parameter see performMacro
//
config.macros.forEachTiddler.getTiddlersAndContext = function(parameter) {
var context = config.macros.forEachTiddler.createContext(parameter.place, parameter.whereClause, parameter.sortClause, parameter.sortAscending, parameter.actionName, parameter.actionParameter, parameter.scriptText, parameter.tiddlyWikiPath, parameter.inTiddler);
var tiddlyWiki = parameter.tiddlyWikiPath ? this.loadTiddlyWiki(parameter.tiddlyWikiPath) : store;
context["tiddlyWiki"] = tiddlyWiki;
// Get the tiddlers, as defined by the whereClause
var tiddlers = this.findTiddlers(parameter.whereClause, context, tiddlyWiki);
context["tiddlers"] = tiddlers;
// Sort the tiddlers, when sorting is required.
if (parameter.sortClause) {
this.sortTiddlers(tiddlers, parameter.sortClause, parameter.sortAscending, context);
}
return {tiddlers: tiddlers, context: context};
};
// Returns the (sorted) tiddlers selected by the parameter.
//
// The action is not yet performed.
//
// @parameter see performMacro
//
config.macros.forEachTiddler.getTiddlers = function(parameter) {
return this.getTiddlersAndContext(parameter).tiddlers;
};
// Performs the macros with the given parameter.
//
// @param parameter holds the parameter of the macro as separate properties.
// The following properties are supported:
//
// place
// whereClause
// sortClause
// sortAscending
// actionName
// actionParameter
// scriptText
// tiddlyWikiPath
//
// All properties are optional.
// For most actions the place property must be defined.
//
config.macros.forEachTiddler.performMacro = function(parameter) {
var tiddlersAndContext = this.getTiddlersAndContext(parameter);
// Perform the action
var actionName = parameter.actionName ? parameter.actionName : "addToList";
var action = config.macros.forEachTiddler.actions[actionName];
if (!action) {
this.handleError(parameter.place, "Unknown action '"+actionName+"'.");
return;
}
var actionHandler = action.handler;
actionHandler(parameter.place, tiddlersAndContext.tiddlers, parameter.actionParameter, tiddlersAndContext.context);
};
// ---------------------------------------------------------------------------
// The actions
// ---------------------------------------------------------------------------
// Internal.
//
// --- The addToList Action -----------------------------------------------
//
config.macros.forEachTiddler.actions.addToList.handler = function(place, tiddlers, parameter, context) {
// Parse the parameter
var p = 0;
// Check for extra parameters
if (parameter.length > p) {
config.macros.forEachTiddler.createExtraParameterErrorElement(place, "addToList", parameter, p);
return;
}
// Perform the action.
var list = document.createElement("ul");
place.appendChild(list);
for (var i = 0; i < tiddlers.length; i++) {
var tiddler = tiddlers[i];
var listItem = document.createElement("li");
list.appendChild(listItem);
createTiddlyLink(listItem, tiddler.title, true);
}
};
abego.parseNamedParameter = function(name, parameter, i) {
var beginExpression = null;
if ((i < parameter.length) && parameter[i] == name) {
i++;
if (i >= parameter.length) {
throw "Missing text behind '%0'".format([name]);
}
return config.macros.forEachTiddler.paramEncode(parameter[i]);
}
return null;
}
// Internal.
//
// --- The write Action ---------------------------------------------------
//
config.macros.forEachTiddler.actions.write.handler = function(place, tiddlers, parameter, context) {
// Parse the parameter
var p = 0;
if (p >= parameter.length) {
this.handleError(place, "Missing expression behind 'write'.");
return;
}
var textExpression = config.macros.forEachTiddler.paramEncode(parameter[p]);
p++;
// Parse the "begin" option
var beginExpression = abego.parseNamedParameter("begin", parameter, p);
if (beginExpression !== null)
p += 2;
var endExpression = abego.parseNamedParameter("end", parameter, p);
if (endExpression !== null)
p += 2;
var noneExpression = abego.parseNamedParameter("none", parameter, p);
if (noneExpression !== null)
p += 2;
// Parse the "toFile" option
var filename = null;
var lineSeparator = undefined;
if ((p < parameter.length) && parameter[p] == "toFile") {
p++;
if (p >= parameter.length) {
this.handleError(place, "Filename expected behind 'toFile' of 'write' action.");
return;
}
filename = config.macros.forEachTiddler.getLocalPath(config.macros.forEachTiddler.paramEncode(parameter[p]));
p++;
if ((p < parameter.length) && parameter[p] == "withLineSeparator") {
p++;
if (p >= parameter.length) {
this.handleError(place, "Line separator text expected behind 'withLineSeparator' of 'write' action.");
return;
}
lineSeparator = config.macros.forEachTiddler.paramEncode(parameter[p]);
p++;
}
}
// Check for extra parameters
if (parameter.length > p) {
config.macros.forEachTiddler.createExtraParameterErrorElement(place, "write", parameter, p);
return;
}
// Perform the action.
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(textExpression, context);
var count = tiddlers.length;
var text = "";
if (count > 0 && beginExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(beginExpression, context)(undefined, context, count, undefined);
for (var i = 0; i < count; i++) {
var tiddler = tiddlers[i];
text += func(tiddler, context, count, i);
}
if (count > 0 && endExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(endExpression, context)(undefined, context, count, undefined);
if (count == 0 && noneExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(noneExpression, context)(undefined, context, count, undefined);
if (filename) {
if (lineSeparator !== undefined) {
lineSeparator = lineSeparator.replace(/\\n/mg, "\n").replace(/\\r/mg, "\r");
text = text.replace(/\n/mg,lineSeparator);
}
saveFile(filename, convertUnicodeToUTF8(text));
} else {
var wrapper = createTiddlyElement(place, "span");
wikify(text, wrapper, null/* highlightRegExp */, context.inTiddler);
}
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
// Internal.
//
config.macros.forEachTiddler.createContext = function(placeParam, whereClauseParam, sortClauseParam, sortAscendingParam, actionNameParam, actionParameterParam, scriptText, tiddlyWikiPathParam, inTiddlerParam) {
return {
place : placeParam,
whereClause : whereClauseParam,
sortClause : sortClauseParam,
sortAscending : sortAscendingParam,
script : scriptText,
actionName : actionNameParam,
actionParameter : actionParameterParam,
tiddlyWikiPath : tiddlyWikiPathParam,
inTiddler : inTiddlerParam, // the tiddler containing the <<forEachTiddler ...>> macro call.
viewerTiddler : config.macros.forEachTiddler.getContainingTiddler(placeParam) // the tiddler showing the forEachTiddler result
};
};
// Internal.
//
// Returns a TiddlyWiki with the tiddlers loaded from the TiddlyWiki of
// the given path.
//
config.macros.forEachTiddler.loadTiddlyWiki = function(path, idPrefix) {
if (!idPrefix) {
idPrefix = "store";
}
var lenPrefix = idPrefix.length;
// Read the content of the given file
var content = loadFile(this.getLocalPath(path));
if(content === null) {
throw "TiddlyWiki '"+path+"' not found.";
}
var tiddlyWiki = new TiddlyWiki();
// Starting with TW 2.2 there is a helper function to import the tiddlers
if (tiddlyWiki.importTiddlyWiki) {
if (!tiddlyWiki.importTiddlyWiki(content))
throw "File '"+path+"' is not a TiddlyWiki.";
tiddlyWiki.dirty = false;
return tiddlyWiki;
}
// The legacy code, for TW < 2.2
// Locate the storeArea div's
var posOpeningDiv = content.indexOf(startSaveArea);
var posClosingDiv = content.lastIndexOf(endSaveArea);
if((posOpeningDiv == -1) || (posClosingDiv == -1)) {
throw "File '"+path+"' is not a TiddlyWiki.";
}
var storageText = content.substr(posOpeningDiv + startSaveArea.length, posClosingDiv);
// Create a "div" element that contains the storage text
var myStorageDiv = document.createElement("div");
myStorageDiv.innerHTML = storageText;
myStorageDiv.normalize();
// Create all tiddlers in a new TiddlyWiki
// (following code is modified copy of TiddlyWiki.prototype.loadFromDiv)
var store = myStorageDiv.childNodes;
for(var t = 0; t < store.length; t++) {
var e = store[t];
var title = null;
if(e.getAttribute)
title = e.getAttribute("tiddler");
if(!title && e.id && e.id.substr(0,lenPrefix) == idPrefix)
title = e.id.substr(lenPrefix);
if(title && title !== "") {
var tiddler = tiddlyWiki.createTiddler(title);
tiddler.loadFromDiv(e,title);
}
}
tiddlyWiki.dirty = false;
return tiddlyWiki;
};
// Internal.
//
// Returns a function that has a function body returning the given javaScriptExpression.
// The function has the parameters:
//
// (tiddler, context, count, index)
//
config.macros.forEachTiddler.getEvalTiddlerFunction = function (javaScriptExpression, context) {
var script = context["script"];
var functionText = "var theFunction = function(tiddler, context, count, index) { return "+javaScriptExpression+"}";
var fullText = (script ? script+";" : "")+functionText+";theFunction;";
return eval(fullText);
};
// Internal.
//
config.macros.forEachTiddler.findTiddlers = function(whereClause, context, tiddlyWiki) {
var result = [];
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(whereClause, context);
tiddlyWiki.forEachTiddler(function(title,tiddler) {
if (func(tiddler, context, undefined, undefined)) {
result.push(tiddler);
}
});
return result;
};
// Internal.
//
config.macros.forEachTiddler.createExtraParameterErrorElement = function(place, actionName, parameter, firstUnusedIndex) {
var message = "Extra parameter behind '"+actionName+"':";
for (var i = firstUnusedIndex; i < parameter.length; i++) {
message += " "+parameter[i];
}
this.handleError(place, message);
};
// Internal.
//
config.macros.forEachTiddler.sortAscending = function(tiddlerA, tiddlerB) {
var result =
(tiddlerA.forEachTiddlerSortValue == tiddlerB.forEachTiddlerSortValue)
? 0
: (tiddlerA.forEachTiddlerSortValue < tiddlerB.forEachTiddlerSortValue)
? -1
: +1;
return result;
};
// Internal.
//
config.macros.forEachTiddler.sortDescending = function(tiddlerA, tiddlerB) {
var result =
(tiddlerA.forEachTiddlerSortValue == tiddlerB.forEachTiddlerSortValue)
? 0
: (tiddlerA.forEachTiddlerSortValue < tiddlerB.forEachTiddlerSortValue)
? +1
: -1;
return result;
};
// Internal.
//
config.macros.forEachTiddler.sortTiddlers = function(tiddlers, sortClause, ascending, context) {
// To avoid evaluating the sortClause whenever two items are compared
// we pre-calculate the sortValue for every item in the array and store it in a
// temporary property ("forEachTiddlerSortValue") of the tiddlers.
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(sortClause, context);
var count = tiddlers.length;
var i;
for (i = 0; i < count; i++) {
var tiddler = tiddlers[i];
tiddler.forEachTiddlerSortValue = func(tiddler,context, undefined, undefined);
}
// Do the sorting
tiddlers.sort(ascending ? this.sortAscending : this.sortDescending);
// Delete the temporary property that holds the sortValue.
for (i = 0; i < tiddlers.length; i++) {
delete tiddlers[i].forEachTiddlerSortValue;
}
};
// Internal.
//
config.macros.forEachTiddler.trace = function(message) {
displayMessage(message);
};
// Internal.
//
config.macros.forEachTiddler.traceMacroCall = function(place,macroName,params) {
var message ="<<"+macroName;
for (var i = 0; i < params.length; i++) {
message += " "+params[i];
}
message += ">>";
displayMessage(message);
};
// Internal.
//
// Creates an element that holds an error message
//
config.macros.forEachTiddler.createErrorElement = function(place, exception) {
var message = (exception.description) ? exception.description : exception.toString();
return createTiddlyElement(place,"span",null,"forEachTiddlerError","<<forEachTiddler ...>>: "+message);
};
// Internal.
//
// @param place [may be null]
//
config.macros.forEachTiddler.handleError = function(place, exception) {
if (place) {
this.createErrorElement(place, exception);
} else {
throw exception;
}
};
// Internal.
//
// Encodes the given string.
//
// Replaces
// "$))" to ">>"
// "$)" to ">"
//
config.macros.forEachTiddler.paramEncode = function(s) {
var reGTGT = new RegExp("\\$\\)\\)","mg");
var reGT = new RegExp("\\$\\)","mg");
return s.replace(reGTGT, ">>").replace(reGT, ">");
};
// Internal.
//
// Returns the given original path (that is a file path, starting with "file:")
// as a path to a local file, in the systems native file format.
//
// Location information in the originalPath (i.e. the "#" and stuff following)
// is stripped.
//
config.macros.forEachTiddler.getLocalPath = function(originalPath) {
// Remove any location part of the URL
var hashPos = originalPath.indexOf("#");
if(hashPos != -1)
originalPath = originalPath.substr(0,hashPos);
// Convert to a native file format assuming
// "file:///x:/path/path/path..." - pc local file --> "x:\path\path\path..."
// "file://///server/share/path/path/path..." - FireFox pc network file --> "\\server\share\path\path\path..."
// "file:///path/path/path..." - mac/unix local file --> "/path/path/path..."
// "file://server/share/path/path/path..." - pc network file --> "\\server\share\path\path\path..."
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;
};
// ---------------------------------------------------------------------------
// Stylesheet Extensions (may be overridden by local StyleSheet)
// ---------------------------------------------------------------------------
//
setStylesheet(
".forEachTiddlerError{color: #ffffff;background-color: #880000;}",
"forEachTiddler");
//============================================================================
// End of forEachTiddler Macro
//============================================================================
//============================================================================
// String.startsWith Function
//============================================================================
//
// Returns true if the string starts with the given prefix, false otherwise.
//
version.extensions["String.startsWith"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.startsWith = function(prefix) {
var n = prefix.length;
return (this.length >= n) && (this.slice(0, n) == prefix);
};
//============================================================================
// String.endsWith Function
//============================================================================
//
// Returns true if the string ends with the given suffix, false otherwise.
//
version.extensions["String.endsWith"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.endsWith = function(suffix) {
var n = suffix.length;
return (this.length >= n) && (this.right(n) == suffix);
};
//============================================================================
// String.contains Function
//============================================================================
//
// Returns true when the string contains the given substring, false otherwise.
//
version.extensions["String.contains"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.contains = function(substring) {
return this.indexOf(substring) >= 0;
};
//============================================================================
// Array.indexOf Function
//============================================================================
//
// Returns the index of the first occurance of the given item in the array or
// -1 when no such item exists.
//
// @param item [may be null]
//
version.extensions["Array.indexOf"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
Array.prototype.indexOf = function(item) {
for (var i = 0; i < this.length; i++) {
if (this[i] == item) {
return i;
}
}
return -1;
};
//============================================================================
// Array.contains Function
//============================================================================
//
// Returns true when the array contains the given item, otherwise false.
//
// @param item [may be null]
//
version.extensions["Array.contains"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
Array.prototype.contains = function(item) {
return (this.indexOf(item) >= 0);
};
//============================================================================
// Array.containsAny Function
//============================================================================
//
// Returns true when the array contains at least one of the elements
// of the item. Otherwise (or when items contains no elements) false is returned.
//
version.extensions["Array.containsAny"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
Array.prototype.containsAny = function(items) {
for(var i = 0; i < items.length; i++) {
if (this.contains(items[i])) {
return true;
}
}
return false;
};
//============================================================================
// Array.containsAll Function
//============================================================================
//
// Returns true when the array contains all the items, otherwise false.
//
// When items is null false is returned (even if the array contains a null).
//
// @param items [may be null]
//
version.extensions["Array.containsAll"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
Array.prototype.containsAll = function(items) {
for(var i = 0; i < items.length; i++) {
if (!this.contains(items[i])) {
return false;
}
}
return true;
};
} // of "install only once"
// Used Globals (for JSLint) ==============
// ... DOM
/*global document */
// ... TiddlyWiki Core
/*global convertUnicodeToUTF8, createTiddlyElement, createTiddlyLink,
displayMessage, endSaveArea, hasClass, loadFile, saveFile,
startSaveArea, store, wikify */
//}}}
/***
|''Requires''|Backward compability patch for ForEachTiddlerPlugin|
|''Version''|1.0.10|
Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑÑÐ°Ð²Ð½ÐµÐ½Ð¸Ñ Ñ Ð¾Ñигиналом (1.0.8):
* добавлена "Ð°Ð½Ð¾Ð½Ð¸Ð¼Ð½Ð°Ñ Ð¾Ð±Ð¾Ð»Ð¾Ñка" кода, меÑ
анизм "install only once" вÑнеÑен в наÑало кода
* добавлено пÑедÑпÑеждение в ÑлÑÑае, когда ÑÑÑановка пÑоиÑÑ
Ð¾Ð´Ð¸Ñ Ð¿Ñи Ñже ÑÑÑановленной копии ~ForEachTiddlerPlugin
* в [[Backward compability patch for ForEachTiddlerPlugin]] вÑнеÑенÑ:
** опÑеделение {{{TiddlyWiki.prototype.forEachTiddler}}}
** опÑÐµÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð¼ÐµÑодов {{{Array.prototype}}}: {{{indexOf}}}, {{{contains}}}, {{{containsAny}}}, {{{containsAll}}}
* пÑевÑаÑил {{{abego.parseNamedParameter}}} в "пеÑеменнÑÑ" {{{var parseNamedParameter}}}
* ''добавлен {{{config.macros.fet}}}''
** [~DDn][@@color:purple;пока пÑоÑеÑÑиÑован Ñлабо@@]
* код {{{.importTiddlyWiki}}} вÑнеÑен в паÑÑ
** [~DDn][@@color:purple;не пÑоÑеÑÑиÑован@@]
***/
//{{{
(function(){
//============================================================================
//============================================================================
// ForEachTiddlerPlugin
//============================================================================
//============================================================================
// Only install once
if (version.extensions.ForEachTiddlerPlugin) {
alert("Warning: more than one copy of ForEachTiddlerPlugin is set to be launched");
return;
} else
version.extensions.ForEachTiddlerPlugin = {
major: 1, minor: 0, revision: 8,
date: new Date(2007,3,12),
source: "http://tiddlywiki.abego-software.de/#ForEachTiddlerPlugin",
licence: "[[BSD open source license (abego Software)|http://www.abego-software.de/legal/apl-v10.html]]",
copyright: "Copyright (c) abego Software GmbH, 2005-2007 (www.abego-software.de)"
};
if (!window.abego) window.abego = {};
//============================================================================
// forEachTiddler Macro
//============================================================================
version.extensions.forEachTiddler = {
major: 1, minor: 0, revision: 8, date: new Date(2007,3,12), provider: "http://tiddlywiki.abego-software.de"
};
// ---------------------------------------------------------------------------
// Configurations and constants
// ---------------------------------------------------------------------------
config.macros.forEachTiddler = {
// Standard Properties
label: "forEachTiddler",
prompt: "Perform actions on a (sorted) selection of tiddlers",
// actions
actions: {
addToList: {},
write: {}
}
};
// ---------------------------------------------------------------------------
// The forEachTiddler Macro Handler
// ---------------------------------------------------------------------------
config.macros.forEachTiddler.getContainingTiddler = function(e) {
while(e && !hasClass(e,"tiddler"))
e = e.parentNode;
var title = e ? e.getAttribute("tiddler") : null;
return title ? store.getTiddler(title) : null;
};
config.macros.forEachTiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler) {
// config.macros.forEachTiddler.traceMacroCall(place,macroName,params,wikifier,paramString,tiddler);
if (!tiddler) tiddler = config.macros.forEachTiddler.getContainingTiddler(place);
// --- Parsing ------------------------------------------
var i = 0; // index running over the params
// Parse the "in" clause
var tiddlyWikiPath = undefined;
if ((i < params.length) && params[i] == "in") {
i++;
if (i >= params.length) {
this.handleError(place, "TiddlyWiki path expected behind 'in'.");
return;
}
tiddlyWikiPath = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the where clause
var whereClause ="true";
if ((i < params.length) && params[i] == "where") {
i++;
whereClause = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the sort stuff
var sortClause = null;
var sortAscending = true;
if ((i < params.length) && params[i] == "sortBy") {
i++;
if (i >= params.length) {
this.handleError(place, "sortClause missing behind 'sortBy'.");
return;
}
sortClause = this.paramEncode(params[i]);
i++;
if ((i < params.length) && (params[i] == "ascending" || params[i] == "descending")) {
sortAscending = params[i] == "ascending";
i++;
}
}
// Parse the script
var scriptText = null;
if ((i < params.length) && params[i] == "script") {
i++;
scriptText = this.paramEncode((i < params.length) ? params[i] : "");
i++;
}
// Parse the action.
// When we are already at the end use the default action
var actionName = "addToList";
if (i < params.length) {
if (!config.macros.forEachTiddler.actions[params[i]]) {
this.handleError(place, "Unknown action '"+params[i]+"'.");
return;
} else {
actionName = params[i];
i++;
}
}
// Get the action parameter
// (the parsing is done inside the individual action implementation.)
var actionParameter = params.slice(i);
// --- Processing ------------------------------------------
try {
this.performMacro({
place: place,
inTiddler: tiddler,
whereClause: whereClause,
sortClause: sortClause,
sortAscending: sortAscending,
actionName: actionName,
actionParameter: actionParameter,
scriptText: scriptText,
tiddlyWikiPath: tiddlyWikiPath});
} catch (e) {
this.handleError(place, e);
}
};
// Returns an object with properties "tiddlers" and "context".
// tiddlers holds the (sorted) tiddlers selected by the parameter,
// context the context of the execution of the macro.
//
// The action is not yet performed.
//
// @parameter see performMacro
//
config.macros.forEachTiddler.getTiddlersAndContext = function(parameter) {
var context = config.macros.forEachTiddler.createContext(parameter.place, parameter.whereClause, parameter.sortClause, parameter.sortAscending, parameter.actionName, parameter.actionParameter, parameter.scriptText, parameter.tiddlyWikiPath, parameter.inTiddler);
var tiddlyWiki = parameter.tiddlyWikiPath ? this.loadTiddlyWiki(parameter.tiddlyWikiPath) : store;
context["tiddlyWiki"] = tiddlyWiki;
// Get the tiddlers, as defined by the whereClause
var tiddlers = this.findTiddlers(parameter.whereClause, context, tiddlyWiki);
context["tiddlers"] = tiddlers;
// Sort the tiddlers, when sorting is required.
if (parameter.sortClause) {
this.sortTiddlers(tiddlers, parameter.sortClause, parameter.sortAscending, context);
}
return {tiddlers: tiddlers, context: context};
};
// Returns the (sorted) tiddlers selected by the parameter.
//
// The action is not yet performed.
//
// @parameter see performMacro
//
config.macros.forEachTiddler.getTiddlers = function(parameter) {
return this.getTiddlersAndContext(parameter).tiddlers;
};
// Performs the macros with the given parameter.
//
// @param parameter holds the parameter of the macro as separate properties.
// The following properties are supported:
//
// place
// whereClause
// sortClause
// sortAscending
// actionName
// actionParameter
// scriptText
// tiddlyWikiPath
//
// All properties are optional.
// For most actions the place property must be defined.
//
config.macros.forEachTiddler.performMacro = function(parameter) {
var tiddlersAndContext = this.getTiddlersAndContext(parameter);
// Perform the action
var actionName = parameter.actionName ? parameter.actionName : "addToList";
var action = config.macros.forEachTiddler.actions[actionName];
if (!action) {
this.handleError(parameter.place, "Unknown action '"+actionName+"'.");
return;
}
var actionHandler = action.handler;
actionHandler(parameter.place, tiddlersAndContext.tiddlers, parameter.actionParameter, tiddlersAndContext.context);
};
// ---------------------------------------------------------------------------
// The actions
// ---------------------------------------------------------------------------
// Internal.
//
// --- The addToList Action -----------------------------------------------
//
config.macros.forEachTiddler.actions.addToList.handler = function(place, tiddlers, parameter, context) {
// Parse the parameter
var p = 0;
// Check for extra parameters
if (parameter.length > p) {
config.macros.forEachTiddler.createExtraParameterErrorElement(place, "addToList", parameter, p);
return;
}
// Perform the action.
var list = document.createElement("ul");
place.appendChild(list);
for (var i = 0; i < tiddlers.length; i++) {
var tiddler = tiddlers[i];
var listItem = document.createElement("li");
list.appendChild(listItem);
createTiddlyLink(listItem, tiddler.title, true);
}
};
var parseNamedParameter = function(name, parameter, i) {
var beginExpression = null;
if ((i < parameter.length) && parameter[i] == name) {
i++;
if (i >= parameter.length) {
throw "Missing text behind '%0'".format([name]);
}
return config.macros.forEachTiddler.paramEncode(parameter[i]);
}
return null;
}
// Internal.
//
// --- The write Action ---------------------------------------------------
//
config.macros.forEachTiddler.actions.write.handler = function(place, tiddlers, parameter, context) {
// Parse the parameter
var p = 0;
if (p >= parameter.length) {
this.handleError(place, "Missing expression behind 'write'.");
return;
}
var textExpression = config.macros.forEachTiddler.paramEncode(parameter[p]);
p++;
// Parse the "begin" option
var beginExpression = parseNamedParameter("begin", parameter, p);
if (beginExpression !== null)
p += 2;
var endExpression = parseNamedParameter("end", parameter, p);
if (endExpression !== null)
p += 2;
var noneExpression = parseNamedParameter("none", parameter, p);
if (noneExpression !== null)
p += 2;
// Parse the "toFile" option
var filename = null;
var lineSeparator = undefined;
if ((p < parameter.length) && parameter[p] == "toFile") {
p++;
if (p >= parameter.length) {
this.handleError(place, "Filename expected behind 'toFile' of 'write' action.");
return;
}
filename = config.macros.forEachTiddler.getLocalPath(config.macros.forEachTiddler.paramEncode(parameter[p]));
p++;
if ((p < parameter.length) && parameter[p] == "withLineSeparator") {
p++;
if (p >= parameter.length) {
this.handleError(place, "Line separator text expected behind 'withLineSeparator' of 'write' action.");
return;
}
lineSeparator = config.macros.forEachTiddler.paramEncode(parameter[p]);
p++;
}
}
// Check for extra parameters
if (parameter.length > p) {
config.macros.forEachTiddler.createExtraParameterErrorElement(place, "write", parameter, p);
return;
}
// Perform the action.
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(textExpression, context);
var count = tiddlers.length;
var text = "";
if (count > 0 && beginExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(beginExpression, context)(undefined, context, count, undefined);
for (var i = 0; i < count; i++) {
var tiddler = tiddlers[i];
text += func(tiddler, context, count, i);
}
if (count > 0 && endExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(endExpression, context)(undefined, context, count, undefined);
if (count == 0 && noneExpression)
text += config.macros.forEachTiddler.getEvalTiddlerFunction(noneExpression, context)(undefined, context, count, undefined);
if (filename) {
if (lineSeparator !== undefined) {
lineSeparator = lineSeparator.replace(/\\n/mg, "\n").replace(/\\r/mg, "\r");
text = text.replace(/\n/mg,lineSeparator);
}
saveFile(filename, convertUnicodeToUTF8(text));
} else {
var wrapper = createTiddlyElement(place, "span");
wikify(text, wrapper, null/* highlightRegExp */, context.inTiddler);
}
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
// Internal.
//
config.macros.forEachTiddler.createContext = function(placeParam, whereClauseParam, sortClauseParam, sortAscendingParam, actionNameParam, actionParameterParam, scriptText, tiddlyWikiPathParam, inTiddlerParam) {
return {
place : placeParam,
whereClause : whereClauseParam,
sortClause : sortClauseParam,
sortAscending : sortAscendingParam,
script : scriptText,
actionName : actionNameParam,
actionParameter : actionParameterParam,
tiddlyWikiPath : tiddlyWikiPathParam,
inTiddler : inTiddlerParam, // the tiddler containing the <<forEachTiddler ...>> macro call.
viewerTiddler : config.macros.forEachTiddler.getContainingTiddler(placeParam) // the tiddler showing the forEachTiddler result
};
};
// Internal.
//
// Returns a TiddlyWiki with the tiddlers loaded from the TiddlyWiki of
// the given path.
//
config.macros.forEachTiddler.loadTiddlyWiki = function(path, idPrefix) {
if (!idPrefix) {
idPrefix = "store";
}
var lenPrefix = idPrefix.length;
// Read the content of the given file
var content = loadFile(this.getLocalPath(path));
if(content === null) {
throw "TiddlyWiki '"+path+"' not found.";
}
var tiddlyWiki = new TiddlyWiki();
if (!tiddlyWiki.importTiddlyWiki(content))
throw "File '"+path+"' is not a TiddlyWiki.";
tiddlyWiki.dirty = false;
return tiddlyWiki;
};
// Internal.
//
// Returns a function that has a function body returning the given javaScriptExpression.
// The function has the parameters:
//
// (tiddler, context, count, index)
//
config.macros.forEachTiddler.getEvalTiddlerFunction = function (javaScriptExpression, context) {
var script = context["script"];
var functionText = "var theFunction = function(tiddler, context, count, index) { return "+javaScriptExpression+"}";
var fullText = (script ? script+";" : "")+functionText+";theFunction;";
return eval(fullText);
};
// Internal.
//
config.macros.forEachTiddler.findTiddlers = function(whereClause, context, tiddlyWiki) {
var result = [];
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(whereClause, context);
tiddlyWiki.forEachTiddler(function(title,tiddler) {
if (func(tiddler, context, undefined, undefined)) {
result.push(tiddler);
}
});
return result;
};
// Internal.
//
config.macros.forEachTiddler.createExtraParameterErrorElement = function(place, actionName, parameter, firstUnusedIndex) {
var message = "Extra parameter behind '"+actionName+"':";
for (var i = firstUnusedIndex; i < parameter.length; i++) {
message += " "+parameter[i];
}
this.handleError(place, message);
};
// Internal.
//
config.macros.forEachTiddler.sortAscending = function(tiddlerA, tiddlerB) {
var result =
(tiddlerA.forEachTiddlerSortValue == tiddlerB.forEachTiddlerSortValue)
? 0
: (tiddlerA.forEachTiddlerSortValue < tiddlerB.forEachTiddlerSortValue)
? -1
: +1;
return result;
};
// Internal.
//
config.macros.forEachTiddler.sortDescending = function(tiddlerA, tiddlerB) {
var result =
(tiddlerA.forEachTiddlerSortValue == tiddlerB.forEachTiddlerSortValue)
? 0
: (tiddlerA.forEachTiddlerSortValue < tiddlerB.forEachTiddlerSortValue)
? +1
: -1;
return result;
};
// Internal.
//
config.macros.forEachTiddler.sortTiddlers = function(tiddlers, sortClause, ascending, context) {
// To avoid evaluating the sortClause whenever two items are compared
// we pre-calculate the sortValue for every item in the array and store it in a
// temporary property ("forEachTiddlerSortValue") of the tiddlers.
var func = config.macros.forEachTiddler.getEvalTiddlerFunction(sortClause, context);
var count = tiddlers.length;
var i;
for (i = 0; i < count; i++) {
var tiddler = tiddlers[i];
tiddler.forEachTiddlerSortValue = func(tiddler,context, undefined, undefined);
}
// Do the sorting
tiddlers.sort(ascending ? this.sortAscending : this.sortDescending);
// Delete the temporary property that holds the sortValue.
for (i = 0; i < tiddlers.length; i++) {
delete tiddlers[i].forEachTiddlerSortValue;
}
};
// Internal.
//
config.macros.forEachTiddler.trace = function(message) {
displayMessage(message);
};
// Internal.
//
config.macros.forEachTiddler.traceMacroCall = function(place,macroName,params) {
var message ="<<"+macroName;
for (var i = 0; i < params.length; i++) {
message += " "+params[i];
}
message += ">>";
displayMessage(message);
};
// Internal.
//
// Creates an element that holds an error message
//
config.macros.forEachTiddler.createErrorElement = function(place, exception) {
var message = (exception.description) ? exception.description : exception.toString();
return createTiddlyElement(place,"span",null,"forEachTiddlerError","<<forEachTiddler ...>>: "+message);
};
// Internal.
//
// @param place [may be null]
//
config.macros.forEachTiddler.handleError = function(place, exception) {
if (place) {
this.createErrorElement(place, exception);
} else {
throw exception;
}
};
// Internal.
//
// Encodes the given string.
//
// Replaces
// "$))" to ">>"
// "$)" to ">"
//
config.macros.forEachTiddler.paramEncode = function(s) {
var reGTGT = new RegExp("\\$\\)\\)","mg");
var reGT = new RegExp("\\$\\)","mg");
return s.replace(reGTGT, ">>").replace(reGT, ">");
};
// Internal.
//
// Returns the given original path (that is a file path, starting with "file:")
// as a path to a local file, in the systems native file format.
//
// Location information in the originalPath (i.e. the "#" and stuff following)
// is stripped.
//
config.macros.forEachTiddler.getLocalPath = function(originalPath) {
// Remove any location part of the URL
var hashPos = originalPath.indexOf("#");
if(hashPos != -1)
originalPath = originalPath.substr(0,hashPos);
// Convert to a native file format assuming
// "file:///x:/path/path/path..." - pc local file --> "x:\path\path\path..."
// "file://///server/share/path/path/path..." - FireFox pc network file --> "\\server\share\path\path\path..."
// "file:///path/path/path..." - mac/unix local file --> "/path/path/path..."
// "file://server/share/path/path/path..." - pc network file --> "\\server\share\path\path\path..."
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;
};
// ---------------------------------------------------------------------------
// Stylesheet Extensions (may be overridden by local StyleSheet)
// ---------------------------------------------------------------------------
//
setStylesheet(
".forEachTiddlerError{color: #ffffff;background-color: #880000;}",
"forEachTiddler");
//============================================================================
// fet alias for the the forEachTiddler Macro
//============================================================================
config.macros.fet = config.macros.forEachTiddler;
//============================================================================
// End of forEachTiddler Macro
//============================================================================
//============================================================================
// String.startsWith Function
//============================================================================
//
// Returns true if the string starts with the given prefix, false otherwise.
//
version.extensions["String.startsWith"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.startsWith = function(prefix) {
var n = prefix.length;
return (this.length >= n) && (this.slice(0, n) == prefix);
};
//============================================================================
// String.endsWith Function
//============================================================================
//
// Returns true if the string ends with the given suffix, false otherwise.
//
version.extensions["String.endsWith"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.endsWith = function(suffix) {
var n = suffix.length;
return (this.length >= n) && (this.right(n) == suffix);
};
//============================================================================
// String.contains Function
//============================================================================
//
// Returns true when the string contains the given substring, false otherwise.
//
version.extensions["String.contains"] = {major: 1, minor: 0, revision: 0, date: new Date(2005,11,20), provider: "http://tiddlywiki.abego-software.de"};
//
String.prototype.contains = function(substring) {
return this.indexOf(substring) >= 0;
};
})();
// Used Globals (for JSLint) ==============
// ... DOM
/*global document */
// ... TiddlyWiki Core
/*global convertUnicodeToUTF8, createTiddlyElement, createTiddlyLink,
displayMessage, endSaveArea, hasClass, loadFile, saveFile,
startSaveArea, store, wikify */
//}}}
* [[Ñам плагин|ForEachTiddlerPlugin]] (оÑигиналÑÐ½Ð°Ñ Ð²ÐµÑÑÐ¸Ñ Ñ Ð¾Ð±ÑезаннÑми меÑаданнÑми, лиÑÐµÐ½Ð·Ð¸Ñ Ð¾Ñделена, но еÑÑÑ ÑÑÑлка на веÑÑÐ¸Ñ Ð² веб)
* докÑменÑаÑиÑ
** [[наÑало докÑменÑаÑии|ForEachTiddlerInfo]] [~DDn][@@color:purple;замеÑÐ½Ð°Ñ ÑаÑÑÑ ÐµÑÑ [[в ÑеÑи|http://tiddlywiki.abego-software.de/#WriteAction%20AddToListAction%20%5B%5BAction%20Specification%5D%5D%20scriptClause%20sortClause%20whereClause%20inClause%20ForEachTiddlerExamples]]@@]
** мин. ÑÑÑановка -- обÑÑÐ½Ð°Ñ Ð¼Ð¸Ð½Ð¸Ð¼Ð°Ð»ÑнаÑ
** нÑжно опиÑаÑÑ ÐºÐ°Ð¶Ð´Ñй паÑамеÑÑ
** [[иÑÑоÑÐ¸Ñ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ð¹ ForEachTiddlerPlugin]]
* Ðлагин минималÑно [[пÑоÑеÑÑиÑован|ТеÑÑÑ]], вÑоде ÑабоÑÐ°ÐµÑ Ð½Ð¾ÑмалÑно
* доÑабоÑаÑÑ ÑепозиÑоÑий:
** [пеÑвоÑÑепенное] задаÑÑ Ð°Ð²ÑоимпоÑÑ ÑеманÑиÑеÑкиÑ
ÑÑилей, добавиÑÑ ~DDn, где надо
** задаÑÑ Ð°Ð²Ñообновление [[STP|SharedTiddlersPlugin]]
** пеÑеделаÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ Ñ Ð¸ÑполÑзованием commons Ð´Ð»Ñ Ð¼Ð¸ÐºÑоÑепозиÑоÑиев (ÑÑо еÑÑ); пÑодÑмаÑÑ, нÑÐ¶Ð½Ñ Ð»Ð¸ fallback'и (SideBarTabs, ÑÑили)
!!!ÐоÑабоÑка и внедÑение ~ForEachTiddlerPlugin
[пÑежде Ñем доÑабаÑÑваÑÑ Ð¿Ð»Ð°Ð³Ð¸Ð½, ÑобÑаÑÑ Ð´Ð¾ÐºÑменÑаÑÐ¸Ñ Ð¸ доÑабоÑаÑÑ ÑепозиÑоÑий [пеÑвоÑÑепенное]]
* Ð¶ÐµÐ»Ð°ÐµÐ¼Ð°Ñ Ð´Ð¾ÑабоÑка [[плагина|ForEachTiddlerPluginDev]]:
** добавиÑÑ {{{refresher}}} (Ñм. как ÑÑо делаеÑÑÑ Ñ Ð¼Ð°ÐºÑоÑа {{{list}}})
** ÑдалиÑÑ Ð»Ð¸Ñний код:
*** пеÑенеÑÑи опÑеделение меÑодов, коÑоÑÑе Ñже в ÑдÑе (Ñакие как {{{String.startsWith}}}, ...), в [[паÑÑ|Backward compability patch for ForEachTiddlerPlugin]]
**** Ñм. [[код|https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/TiddlyWiki.js#L419]] {{{.importTiddlyWiki}}}, иÑполÑзÑемÑй в нÑнеÑнем ÑдÑе (можно попÑобоваÑÑ ÑлÑÑÑиÑÑ)
*** обеÑпеÑение обÑаÑной ÑовмеÑÑимоÑÑи Ñ Ð´Ñевними веÑÑиÑми ÑдÑа (еÑÑÑ Ð¼Ð¸Ð½Ð¸Ð¼Ñм одно меÑÑо, иÑкаÑÑ Ð½Ð° {{{1.2.}}})
** добавиÑÑ Ð¿Ð¾Ð´Ð´ÐµÑÐ¶ÐºÑ ÑилÑÑÑов
* поÑле Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑказаннÑÑ
оÑобенноÑÑей макÑоÑа {{{list}}} можно акÑивно внедÑÑÑÑ {{{fET}}} как его заменÑ
* еÑÑ ÐºÐ¾Ð½ÑепÑии, коÑоÑÑе Ñ
оÑелоÑÑ Ð±Ñ Ð½Ð°ÑÑиÑÑÑÑ ÑеализовÑваÑÑ Ð½Ð° оÑнове fET:
** manual sorting Ð´Ð»Ñ ÑпиÑков
*** веÑоÑÑнее вÑего, нÑжно ÑеализовÑваÑÑ Ð¾ÑделÑнÑм макÑоÑом, коÑоÑÑй пиÑеÑÑÑ Ð¿ÐµÑед ÑпиÑком, а единÑÑвеннÑй паÑамеÑÑ Ð·Ð°Ð´Ð°ÑÑ Ð¸Ð¼Ñ ÐºÑки-паÑамеÑÑа, ÑодеÑжаÑего ÑекÑÑее ÑоÑÑоÑние ÑоÑÑиÑовки
** inline-editing авÑоагÑегиÑованной ÑаблиÑÑ
*** Ñоже задаÑа ÑкоÑее внеÑнÑÑ Ð¿Ð¾ оÑноÑÐµÐ½Ð¸Ñ Ðº плагинÑ: надо Ñм. ~TWtid, ~GridPlugin, ~PasteUpPlugin
** ÑлиÑние inline- и авÑоагÑегиÑованного конÑенÑа
*** Ñм. [[ÑеÑÑ|СмеÑаннÑе (авÑоагÑегиÑованнÑе + inline) ÑпиÑки и ÑаблиÑÑ (пока клеÑÑÑÑ ÑолÑко внÑÑÑи ÑкÑипÑа)]] -- когда ÑпиÑок и ÑаблиÑа бÑдÑÑ ÐµÐ´Ð¸Ð½Ñми, а не ÑазбиÑÑми, ÑÐµÐ»Ñ Ð±ÑÐ´ÐµÑ Ð´Ð¾ÑÑигнÑÑа (Ñ Ð¿Ð¾Ð¿Ñавкой на Ñо, ÑÑо inline-конÑÐµÐ½Ñ Ð±ÑÐ´ÐµÑ Ð½Ð°Ñ
одиÑÑÑÑ Ð²Ð½Ðµ кода макÑоÑа)
<<include {{window.microrepCommons = "zz microrep commons.html";}} filters:"[tag[shared]]" substituteShadows>>
<<wikifyIncluded {{window.microrepCommons;}} "SharedStuffEnabler">>
[[ForEachTiddler|ForEachTiddlerPluginHere]]
----
~TiddlyWiki v<<version>>
/***
|''Name''|SharedTiddlersPlugin|
|''Version''|1.5.0|
|''Type''|plugin|
|''~CoreVersion''|2.2.6|
|''Recommended core version''|2.6.2 (to be able to define custom filters in {{{config.filters}}})|
|''Description''|Introduces a possibility to use tiddlers from other ~TiddlyWikis (without importing them)|
|''Documentation''|http://yakovl.bplaced.net/TW/STP/STP.html/#SharedTiddlersPluginInfo|
|''Source''|http://yakovl.bplaced.net/TW/STP/STP.html/#SharedTiddlersPlugin|
|''Author''|Yakov Litvin|
|''Forked from''|[[IncludePlugin|http://tiddlywiki.abego-software.de/#IncludePlugin]], by Udo Borkowski|
|''Contact''|see [[docs|SharedTiddlersPluginInfo]]|
|''Copyright''|Yakov Litvin, 2012|
|''Licence''|[[BSD-like open source license|http://yakovl.bplaced.net/TW/STP/STP.html/#%5B%5BYakov%20Litvin%20Public%20Licence%5D%5D]], see [[here|Yakov Litvin Public Licence]] if imported|
|>| In this tiddler, the code is minified and hidden; the full code can be found [[here|http://yakovl.bplaced.net/TW/STP/STP.html/#SharedTiddlersPluginCode]]. |
/%
***/
(function(){function I(){var a={},b={},e=function(a){return{subs:a,warned:!1}};this.init=function(){void 0==config.options.chkWarnOnSharedTiddlersConflicts&&(config.options.chkWarnOnSharedTiddlersConflicts=!0);void 0==config.options.chkAlertOnSharedTiddlersConflicts&&(config.options.chkAlertOnSharedTiddlersConflicts=!1)};this.checkNew=function(c,f,d,h){var g=store.fetchTiddler(c);if(null!=g&&g.includeURL!=f){g=j.getSubsUrl(c)?!0:!1;if(d==g)if(a[c])void 0==a[c][f]&&(a[c][f]=e(d));else if(d)a[c]={},
a[c][f]=e(d),a[c][j.getSubsUrl(c)]=e(d);else{var k=v(function(a,b){return a.fetchTiddler(c)?b:null});k?(a[c]={},a[c][f]=e(d),a[c][k]=e(d)):window.sharedTiddlersAPI.orig_fetchTiddler(c)&&(a[c]={},a[c][f]=e(d),a[c]["main store"]=e(!1))}d&&(!g&&a[c])&&delete a[c];g=j.getSubsShUrl(c);h&&g&&(h=j.containSubsUrl(c,g),d==h&&(b[c]?void 0==b[c][f]&&(b[c][f]=e(d)):(b[c]={},b[c][f]=e(d),b[c][g]=e(d))),d&&(!h&&b[c])&&delete b[c])}};var f=function(a,b){var d="",e=function(a){d+="\n"+a;b&&q(a)},f;for(tName in a){f=
!1;e("* "+tName+" in:");for(tUrl in a[tName])e(" * "+tUrl),a[tName][tUrl].subs&&(f=!0);f&&e(" (with the subsitute priority)")}return d};this.notify=function(){var c=config.options.chkWarnOnSharedTiddlersConflicts,e=config.options.chkAlertOnSharedTiddlersConflicts;if(e||c){var d,g,j={},k=!1;for(d in a)for(g in a[d])!1==a[d][g].warned&&(k=!0,null==j[d]&&(j[d]={}),j[d][g]={subs:a[d][g].subs},a[d][g].warned=!0);var m={},B=!1;for(d in b)for(g in b[d])!1==b[d][g].warned&&(B=!0,null==m[d]&&(m[d]={}),m[d][g]=
{subs:b[d][g].subs},b[d][g].warned=!0);d="";k&&(d+="New conflicts:",c&&q(d),d+=f(j,c));B&&(d&&(d+="\n"),d+="New conflicts between those competing for substituting shadows:",c&&q("New conflicts between those competing for substituting shadows:"),d+=f(j,c));e&&d&&alert(d)}}}function J(){var a={};this.add=function(b,e,f,c){if(f||c)void 0==a[b]&&(a[b]={urlsSubs:[],urlsSubsSh:[]}),f&&a[b].urlsSubs.pushUnique(e),c&&a[b].urlsSubsSh.pushUnique(e)};this.getSubsUrl=function(b){b=a[b];return null==b||0==b.urlsSubs.length?
null:b.urlsSubs[0]};this.getSubsShUrl=function(b){b=a[b];if(null==b||0==b.urlsSubsSh.length)return null;var e,f;for(e=0;e<b.urlsSubs.length;e++)for(f=0;e<b.urlsSubsSh.length;f++)if(b.urlsSubs[e]==b.urlsSubsSh[f])return b.urlsSubs[e];return b.urlsSubsSh[0]};this.containSubsUrl=function(b,e){var f=a[b];return null==f?!1:f.urlsSubs.contains(e)};this.getPrefs=function(b){return a[b]}}function K(){var a={};this.isUsed=function(b){return a[b]?!0:!1};this.setUsed=function(b){a[b]=1}}var q=function(a,b){displayMessage(a,
b);console.log(a)};window.abego||(window.abego={});if(abego.TiddlyWikiIncluder)alert("Warning: abego.TiddlyWikiIncluder is already exists, so probably two copies of SharedTiddlersPlugin and/or IncludePlugin are installed and activated. It is highly recommended to deactivate all but one copy. You can find those by searching 'abego.TiddlyWikiIncluder'.");else{window.sharedTiddlersAPI={};var w,n=[],g={},x=[],p,y=[],r;conflicts=new I;conflicts.init();var j=new J,C=function(a){return"No include specified for %0".format([a])},
L=function(){var a=x;x=[];if(a.length)for(var b=0;b<y.length;b++)y[b](a)},t,D=function(){void 0!==p&&clearInterval(p);t=0;var a=function(){config.extensions.SharedTiddlersPlugin.sendProgress("","","Done")};p=setInterval(function(){t++;10>=t||(clearInterval(p),p=void 0,config.extensions.SharedTiddlersPlugin.sendProgress("Refreshing...","",""),refreshDisplay(),setTimeout(a,0))},1)},v=function(a){for(var b,e=0;e<n.length;e++){var f=config.extensions.SharedTiddlersPlugin.getStore(n[e]);if(f&&(b=a(f,n[e])))return b}},
E=function(){if(!window.store)return setTimeout(E,100);var a=store.fetchTiddler;window.sharedTiddlersAPI.orig_fetchTiddler=a;store.fetchTiddler=function(b){var e;if(e=j.getSubsUrl(b))return g[e].fetchTiddler(b);if(e=a.apply(this,arguments))return e;if(void 0!==config.shadowTiddlers[b]){if(e=j.getSubsShUrl(b))return g[e].fetchTiddler(b)}else return b==config.macros.newTiddler.title?void 0:v(function(a){return a.fetchTiddler(b)})};n.length&&D()},F=function(){if(!window.store)return setTimeout(F,100);
var a=store.getTiddlerText("IncludeList");a&&wikify(a,document.createElement("div"))},z=function(a){return function(){var b=store.forEachTiddler;store.forEachTiddler=function(a){var f={},c=function(b,c){if(!f[b]&&(!j.getSubsUrl(b)||j.getSubsUrl(b)==c.getIncludeURL()))f[b]=1,a.apply(this,arguments)};b.call(store,c);for(var g in config.shadowTiddlers)j.getSubsShUrl(g)||(f[g]=1);f[config.macros.newTiddler.title]=1;v(function(a){a.forEachTiddler(c)})};try{return a.apply(this,arguments)}finally{store.forEachTiddler=
b}}},G=function(a,b){return a[b]=z(a[b])};config.extensions.SharedTiddlersPlugin={setProgressFunction:function(a){r=a},getProgressFunction:function(){return r},sendProgress:function(a,b,e){r&&r.apply(this,arguments)},onError:function(a,b){q("Error when including '%0':\n%1".format([a,b]))},hasPendingIncludes:function(){for(var a=0;a<n.length;a++){var b=config.extensions.SharedTiddlersPlugin.getState(n[a]);if("waiting"==b||"loading"==b)return!0}return!1},getIncludes:function(){return n.slice()},getState:function(a){var b=
g[a];return!b?C(a):"string"==typeof b?b:null},getStore:function(a){var b=g[a];return!b?C(a):b instanceof TiddlyWiki?b:null},getFunctionUsingForReallyEachTiddler:z,useForReallyEachTiddler:G,addListener:function(a){y.push(a)},importIncluded:function(a,b){b=void 0==b?1:parseInt(b);var e,f,c={tiddler:null},g=function(a){store.addTiddler(a);store.setDirty(!0);c.status=0;c.tiddler=a;c.from=d};if(a instanceof Tiddler)c.tiddler=window.sharedTiddlersAPI.orig_fetchTiddler(a.title),e=jQuery.extend(!0,new Tiddler,
a);else return c.status=-1,c.errorText="not a Tiddler instance",c;var d;(d=e.includeURL)&&delete e.includeURL;switch(b){case 1:g(e);break;case 4:f=window.sharedTiddlersAPI.orig_fetchTiddler(e.title);(!f||f.modified<e.modified)&&confirm("Up-to-date "+e.title+" from "+d+" is availabe, import?")&&g(e);break;default:c.status=-1,c.errorText="unknown import mode"}return c},importAndLog:function(a,b){var e=a.title,f=this.importIncluded(a,b);switch(f.status){case 0:console.log("imported: "+e+" from "+f.from);
break;case -1:console.log("error importing "+e+": "+f.errorText)}}};window.sharedTiddlersAPI.forReallyEachTiddler=function(a){z(function(){store.forEachTiddler(a)}).call(store)};abego.TiddlyWikiIncluder={getIncludes:config.extensions.SharedTiddlersPlugin.getIncludes,getState:config.extensions.SharedTiddlersPlugin.getState,getStore:config.extensions.SharedTiddlersPlugin.getStore};window.sharedTiddlersAPI.getIncludes=config.extensions.SharedTiddlersPlugin.getIncludes;window.sharedTiddlersAPI.getState=
config.extensions.SharedTiddlersPlugin.getState;window.sharedTiddlersAPI.getStore=config.extensions.SharedTiddlersPlugin.getStore;window.sharedTiddlersAPI.importAndLog=config.extensions.SharedTiddlersPlugin.importAndLog;config.extensions.SharedTiddlersPlugin.include=function(a,b,e,f,c,u,d){void 0===w&&(w=void 0===config.options.chkUseInclude||config.options.chkUseInclude);if(w){var h=this;b&&(n.push(a),g[a]="waiting");var p=function(b,c,d,f){void 0===b?(g[a]=f,h.onError(a,f)):(g[a]=b,""!=e?(g[a].orig_store=
new TiddlyWiki,g[a].forEachTiddler(function(b,c){c.includeURL=a;g[a].orig_store.addTiddler(c)}),g[a].clear(),g[a].allTiddlersAreLoaded=!1):g[a].allTiddlersAreLoaded=!0,k(),x.push(a),setTimeout(L,void 0))},k=function(){if(!g[a].allTiddlersAreLoaded||f||c||d)if(null===config.extensions.SharedTiddlersPlugin.getStore(a))setTimeout(k,100);else{var b;if(""==e)if(d){var h=g[a].allTiddlersAreLoaded?g[a]:g[a].orig_store;h.forEachTiddler(function(a,b){config.extensions.SharedTiddlersPlugin.importAndLog(b,d)})}else g[a].allTiddlersAreLoaded||
(g[a].orig_store.forEachTiddler(function(b){conflicts.checkNew(b,a,f,c)}),g[a]=g[a].orig_store,g[a].allTiddlersAreLoaded=!0);else if(!g[a].allTiddlersAreLoaded||d){h=g[a].allTiddlersAreLoaded?g[a]:g[a].orig_store;b=h.filterTiddlers(e);var l,s;for(l=0;l<b.length;l++)s=jQuery.extend(!0,new Tiddler,b[l]),h.fetchTiddler(s.title)&&(d?config.extensions.SharedTiddlersPlugin.importAndLog(s,d):(conflicts.checkNew(s.title,a,f,c),g[a].addTiddler(s)))}if(!d&&(f||c))if(""==e)q('Including all tiddlers from a TW document with "substitute" or "substituteShadows" option is not allowed for stability reasons. Tiddlers from '+
a+" are included without substituting.");else{if(g[a].allTiddlersAreLoaded){b=g[a].filterTiddlers(e);for(l=0;l<b.length;l++)conflicts.checkNew(b[l].title,a,f,c)}for(l=0;l<b.length;l++)j.add(b[l].title,a,f,c)}conflicts.notify();store.slices={};refreshAll();story.refreshAllTiddlers()}},m=function(){g[a]="loading";var b=r,c=function(c,d){b&&b(c,"stp_loadTiddlyWikiStore",d,a,null)},e=function(b){c("Error when loading %0".format([a]),"Failed");p(void 0,a,null,b);return b};c("Start loading %0".format([a]),
"Started");var d=a,f=function(b,d,f,g){if(void 0===b)e(g);else{c("Processing %0".format([a]),"Processing");d=config.messages.invalidFileError;config.messages.invalidFileError="The file '%0' does not appear to be a valid TiddlyWiki file";try{var h=new TiddlyWiki,j=h.importTiddlyWiki(b)?null:"Problem with importing TiddlyWiki, probable reason is: "+config.messages.invalidFileError.format([a]);j?e(j):(c("Loaded %0".format([a]),"Done"),p(h,a,null))}catch(k){e(exceptionText(k))}finally{config.messages.invalidFileError=
d}}};if(0!=d.search(/^((http(s)?)|(file)):/)){if(0==d.search(/^((.\:\\)|(\\\\)|(\/))/))d="file://"+d;else var h=document.location.toString(),j=h.lastIndexOf("/"),d=h.substr(0,j+1)+d;d=d.replace(/\\/mg,"/")}var k=d,m=function(a,b,c,d){return a?f(c,d,b):f(void 0,d,b,"Error loading %0".format([d]))};if(2>version.major||2==version.major&&7>version.minor){d={type:"GET",url:k,processData:!1,data:void 0,cache:!1,beforeSend:function(){},complete:function(a){var b;a:{try{b=!a.status&&"file:"===location.protocol||
200<=a.status&&300>a.status||304===a.status||1223===a.status;break a}catch(c){}b=!1}b?m(!0,null,a.responseText,k,a):m(!1,null,null,k,a)}};try{window.Components&&(window.netscape&&window.netscape.security&&-1==document.location.protocol.indexOf("http"))&&window.netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")}catch(u){}jQuery.ajax(d)}else httpReq("GET",k,m,null)};b?u?setTimeout(m,u):m():k()}};config.extensions.SharedTiddlersPlugin.addListener(D);config.shadowTiddlers.AdvancedOptions+=
"\n~IncludePlugin settings:\n<<option chkUseInclude>> Include ~TiddlyWikis\n<<option chkAlertOnSharedTiddlersConflicts>> Alert on tiddler name conflicts\n<<option chkWarnOnSharedTiddlersConflicts>> Display messages and write log in the browser console on conflicts\nIncludeList | IncludeState | ImportIncluded | [[help|http://yakovl.bplaced.net/TW/SharedTiddlersPlugin.html/#SharedTiddlersPluginInfo]]\n^^(Reload this ~TiddlyWiki to make changes become effective)^^";config.shadowTiddlers.IncludeState=
"<<includeState>>";config.shadowTiddlers.ImportIncluded='| the url of the document to import from | <<option txtStoreUrl>> |\n| the filter of tiddlers to import | <<option txtFilterTiddlersToImport>> |\n<html><a href=\'javascript:;\' onclick=\'\n\tvar storeUrl = config.options.txtStoreUrl;\n\tvar theStore = sharedTiddlersAPI.getStore(storeUrl);\n\tvar t;\n\tif(!theStore)\n\t\tdisplayMessage("no store loaded from "+storeUrl);\n\telse{\n\t\tvar tiddlersToImport = theStore.filterTiddlers(config.options.txtFilterTiddlersToImport);\n\t\tconsole.log(tiddlersToImport.length+" tiddlers imported"+ ((tiddlersToImport.length > 0)? ":" : ""));\n\t\t\n\t\tfor(var i = 0; i < tiddlersToImport.length; i++)\n\t\t\twindow.sharedTiddlersAPI.importAndLog(tiddlersToImport[i]);\n\t};\n\'>import (without saving)<a/></html>';
var A=function(a,b,e){!anim||!abego.ShowAnimation?a.style.display=b?"block":"none":anim.startAnimating(new abego.ShowAnimation(a,b,e))};config.extensions.SharedTiddlersPlugin.getDefaultProgressFunction=function(){setStylesheet(".includeProgressState{\nbackground-color:#FFCC00;\nposition:absolute;\nright:0.2em;\ntop:0.2em;\nwidth:7em;\npadding-left:0.2em;\npadding-right:0.2em\n}\n","stp_Include");var a=document.createElement("div");a.className="includeProgressState";a.style.display="none";document.body.appendChild(a);
return function(b,e,f){"Done"==f||"Failed"==f?setTimeout(function(){A(a,!1,1E3)},100):"stp_loadTiddlyWikiStore"==e?(t=0,"Processing"==f&&(removeChildren(a),createTiddlyText(a,"Including..."),A(a,!0,0))):(removeChildren(a),createTiddlyText(a,b),A(a,!0,0))}};config.extensions.SharedTiddlersPlugin.setProgressFunction(config.extensions.SharedTiddlersPlugin.getDefaultProgressFunction());config.macros.include=new K;config.macros.include.handler=function(a,b,e,f,c){b=f.source.substring(f.matchStart,f.nextMatch);
pParams=c.parseParams("url",null,!0,!1,!0);getFlag(pParams,"hide",!1)||createTiddlyText(createTiddlyElement(a,"code"),b);if(!config.macros.include.isUsed(b)){config.macros.include.setUsed(b);a=parseInt(getParam(pParams,"delay","0"));c=pParams[0].url;b=getParam(pParams,"filters","");f=e.contains("substituteShadows");e=e.contains("substitute");for(var g=getParam(pParams,"import",void 0),d,h=0;c&&h<c.length;h++)d=!n.contains(c[h]),config.extensions.SharedTiddlersPlugin.include(c[h],d,b,e,f,a,g)}};config.macros.includeState=
{};config.macros.includeState.handler=function(a){var b=function(){removeChildren(e);var a=wikify,c;c="";var g=config.extensions.SharedTiddlersPlugin.getIncludes();if(g.length){c+="|!Address|!State|\n";for(var d=0;d<g.length;d++){var h=g[d];c+="|{{{"+h+"}}}|";h=config.extensions.SharedTiddlersPlugin.getState(h);c+=h?"{{{"+h+"}}}":"included";c+="|\n"}c+="|includeState|k\n"}else c="{{noIncludes{\nNo TiddlyWiki is included or including is disabled (see AdvancedOptions)\n}}}\n";a(c,e);config.extensions.SharedTiddlersPlugin.hasPendingIncludes()&&
setTimeout(b,500)},e=createTiddlyElement(a,"div");setTimeout(b,0)};config.macros.wikifyIncluded={};config.macros.wikifyIncluded.handler=function(a,b,e,f,c){createTiddlyText(createTiddlyElement(a,"code"),f.source.substring(f.matchStart,f.nextMatch));pParams=c.parseParams("url",null,!0,!1,!0);var g=e[0],d=e[1],h=e[2]?parseInt(e[2]):100,j=e[3]?parseInt(e[3]):100,k=function(){var a=sharedTiddlersAPI.getStore(g);if(a&&(a=a.getTiddlerText(d))){wikify(a,document.createElement("div"));return}h--;0<h&&setTimeout(k,
j)};k()};var M=Tiddler.prototype.isReadOnly;Tiddler.prototype.isReadOnly=function(){return M.apply(this,arguments)||this.isIncluded()};Tiddler.prototype.isIncluded=function(){return void 0!=this.includeURL};Tiddler.prototype.getIncludeURL=function(){return this.includeURL};var N={getMissingLinks:1,getOrphans:1,getTags:1,reverseLookup:1,updateTiddlers:1},H;for(H in N)G(TiddlyWiki.prototype,H);E();setTimeout(F,100)}})();
// //%/
<<search>><<closeAll>><<permaview>><<newTiddler>><<saveChanges>> [[ÐаÑÑÑойка]] [[ТеÑ
ниÑеÑкие логи: дÑÑгие ÑаÑÑиÑÐµÐ½Ð¸Ñ Ð·Ð´ÐµÑÑ]] <<slider chkSliderOptionsPanel OptionsPanel "options »" "Change TiddlyWiki advanced options">>
по-видимомÑ, ÑнивеÑÑалÑнÑй инÑÑÑÑÐ¼ÐµÐ½Ñ Ð°Ð³ÑегаÑии
|~ViewToolbar|closeTiddler closeOthers +editTiddler jump > fields permalink references deleteTiddler|
|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|
ÐÑо деÑево Ñоздано Ð´Ð»Ñ Ð½Ð°ÑÑÑойки дополниÑелÑного менÑ. Ðно опиÑÑÐ²Ð°ÐµÑ ÐµÐ³Ð¾ ÑодеÑжимое, ÑоÑÑавленное из многоÑÑовневого вклÑÑÐµÐ½Ð¸Ñ tw-запиÑей Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ Ð¼Ð°ÐºÑоÑов:
* веÑÑ
нÑÑ ÑаÑÑÑ: SideBarOptions -- ÑодеÑÐ¶Ð¸Ñ Ð½Ð°Ð±Ð¾Ñ Ð¿ÑимиÑивов и ÑÐ»Ð°Ð¹Ð´ÐµÑ Ð½Ð° tw-запиÑÑ Ð½Ð¸Ð¶Ðµ
** OptionsPanel -- вÑÑкие ÑобÑаннÑе изнаÑалÑно наÑÑÑойки
* нижнÑÑ ÑаÑÑÑ: SideBarTabs -- здеÑÑ ÑлайдеÑ, оÑкÑÑваÑÑий вкладки Ñо ÑпеÑиалÑнÑми ÑпиÑками (tw-запиÑи ниже).
** ÐеÑколÑко tw-запиÑей, ÑодеÑжаÑиÑ
пÑимиÑивнÑе макÑоÑÑ (менÑÑÑ Ð¸Ñ
ÑодеÑжимое беÑÑмÑÑленно)
** TabMore
*** ÐеÑколÑко tw-запиÑей, ÑодеÑжаÑиÑ
пÑимиÑивнÑе макÑоÑÑ (менÑÑÑ Ð¸Ñ
ÑодеÑжимое беÑÑмÑÑленно)
пÑоÑÑо запиÑÑ
<<fet where 'tiddler.tags.contains("test")'>>
* before
<<forEachTiddler where 'tiddler.tags.contains("test")'>>
* after
||before|
<<forEachTiddler
where 'tiddler.tags.contains("test")'
write '"|||\n"'
begin '"|before||\n"'
end '"|after||\n"'>>
||after|
<<forEachTiddler where 'tiddler.tags.contains("test")'>>
<<list filter "[tag[test]]">> <<newTiddler tag:"test" label:"добавиÑÑ ÑеÑÑÂ" text:"">>
* SharedTiddlersPlugin
** ÑÑо-Ñо Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ ÑÑеди [[вклÑÑÑнного|IncludeList]] (Ñм. <<tag [[shared]]>>, <<tag [[sharedNotByTag]]>>)
* v1.0.8 (2007-04-12)
** Adapted to latest ~TiddlyWiki 2.2 Beta importTiddlyWiki API (introduced with changeset 2004). ~TiddlyWiki 2.2 Beta builds prior to changeset 2004 are no longer supported (but ~TiddlyWiki 2.1 and earlier, of cause)
* v1.0.7 (2007-03-28)
** Also support "pre" formatted ~TiddlyWikis (introduced with TW 2.2) (when using "in" clause to work on external tiddlers)
* v1.0.6 (2006-09-16)
** Context provides "viewerTiddler", i.e. the tiddler used to view the macro. Most times this is equal to the "inTiddler", but when using the "tiddler" macro both may be different.
** Support "begin", "end" and "none" expressions in "write" action
* v1.0.5 (2006-02-05)
** Pass tiddler containing the macro with wikify, context object also holds reference to tiddler containing the macro ("inTiddler"). Thanks to Simon Baird.
** Support Firefox 1.5.0.1
** Internal
*** Make "~JSLint" conform
*** "Only install once"
* v1.0.4 (2006-01-06)
** Support ~TiddlyWiki 2.0
* v1.0.3 (2005-12-22)
** Features:
*** Write output to a file supports multi-byte environments (Thanks to Bram Chen)
*** Provide API to access the forEachTiddler functionality directly through ~JavaScript (see getTiddlers and performMacro)
** Enhancements:
*** Improved error messages on ~InternetExplorer.
* v1.0.2 (2005-12-10)
** Features:
*** context object also holds reference to store (~TiddlyWiki)
** Fixed Bugs:
*** ~ForEachTiddler 1.0.1 has broken support on win32 Opera 8.51 (Thanks to ~BrunoSabin for reporting)
* v1.0.1 (2005-12-08)
** Features:
*** Access tiddlers stored in separated ~TiddlyWikis through the "in" option. I.e. you are no longer limited to only work on the "current ~TiddlyWiki".
*** Write output to an external file using the "toFile" option of the "write" action. With this option you may write your customized tiddler exports.
*** Use the "script" section to define "helper" ~JavaScript functions etc. to be used in the various ~JavaScript expressions (whereClause, sortClause, action arguments,...).
*** Access and store context information for the current forEachTiddler invocation (through the build-in "context" object) .
*** Improved script evaluation (for where/sort clause and write scripts).
* v1.0.0 (2005-11-20)
** initial version