I've done some basic fix up of Math Cell to create a table editing
procedure that seems to work.
There are two new tiddlers each copied at the end of this message:
1. EditableTable: a cleaned up Math Cell, which does
no math, has no header rows or columns and auto sizes and auto loads
2 TableScript: which makes the call create a table
editor.
You must have the inline javascript plugin installed.
To edit a table, you create the table where you want it and place the
following text in the line immediately following the table:
<<tiddler TableScript>>
This will create a button that reads "Edit this Table."
Click it and a new tiddler will open, with the table presented in
editable form. Make your changes and click "save" and then close.
That's it.
The tiddlers are:
-------------------------------------------------------------------
TableScript (which should be tagged "Script")
<script label="Edit This Table">
if (!window.story) window.story=window;
var title=story.findContainingTiddler(place).getAttribute("tiddler");
var str= "<<EditableTable " + "\"" + title + "\"" + ">>";
var editor = "Table Editor";
store.saveTiddler(editor,editor, str, config.options.txtUserName,new
Date(),["spreadsheet"]);
story.displayTiddler(null,editor);
return false;
</script>
----------------------------------------------------
EditableTable, which should have a sysconfig tag.
/***
<code>
/***
Editable Table by Steve Millman, adapted from MATHCELL SPREADSHEET
Written by Bradley Meck
No idea what license apply.
***/
config.macros.EditableTable = {
caretPosition: function(element){
var selelected, range, r2, collapsed = false, i=-1;
if(typeof element.selectionStart=="number") {
i=element.selectionStart;
if(element.selectionStart ==
element.selectionEnd){collapsed =
true};
}
else if(document.selection && element.createTextRange) {
selelected=document.selection;
if(selelected){
r2=selelected.createRange();
if(r2.text.length == 0){collapsed = true;}
range=element.createTextRange();
range.setEndPoint("EndToStart", r2);
i=range.text.length;
}
}
else {
el.onkeyup=null;
el.onclick=null;
}
return [i,collapsed];
},
functions: {
},
handler: function(place,macroName,params){
var row = createTiddlyElement(place,"div");
createTiddlyButton(row,"save","save data back to
table",function(){
var str = "";
for(var i = 0; i <
this.parentNode.nextSibling.childNodes.length; i
++){
str+="|"
for(var j = 0; j <
this.parentNode.nextSibling.childNodes
[i].childNodes.length; j++){
str +=
this.parentNode.nextSibling.childNodes[i].childNodes
[j].title.replace("\\","\\\\").replace(",","\\,")+"|";
}str += "\n";
}
var tiddler = params[0];
var tiddlerdata = store.getTiddler(params[0]);
var rindex= tiddlerdata.text.indexOf("<<");
var rows = tiddlerdata.text.substring(0,rindex);
var append = tiddlerdata.text.substring(rindex);
if (append.length == 0) append = "<<tiddler
\"TableScript\">>";
str+=append;
store.saveTiddler
(tiddler,tiddler,str,config.options.txtUserName,new Date(),
["spreadsheet"]);
return false;
});
createTiddlyButton(row,"reload","revert to saved
table",function(){
var tiddler = store.getTiddler(params[0]);
var rows = tiddler.text.split("\n");
var rindex= tiddler.text.indexOf("<<");
var rows = tiddler.text.substring(0,rindex);
rows= tiddler.text.split("\n");
rows=rows.slice(0,-1);
for(var i = 0; i < rows.length; i++){
var cells = rows[i].split("|");
cells =cells.slice(1);
for(var j = 0; j < cells.length-1; j++){
if(j < cells.length -2 &&
cells[j].match(/\\{1,1}$/)){
cells.splice(j,2,cells[j]+","+cells[j+1]); j--;
}
cells[j] =
cells[j].replace(/\\,/g,",").replace(/\\\\/g,"\\");
this.parentNode.nextSibling.childNodes[i].childNodes[j].title =
cells[j];
this.parentNode.nextSibling.childNodes[i].childNodes[j].focus();
this.parentNode.nextSibling.childNodes[i].childNodes[j].blur();
}rows[i] = cells;
}
return false;
});
// ADDING for rownum and colnum
var tiddler = store.getTiddler(params[0]);
var rindex= tiddler.text.indexOf("<<");
var rows = tiddler.text.substring(0,rindex);
rows=rows.split("\n");
var rownum = rows.length-1;
var cells = rows[0].split("|");
var colnum = cells.length - 2;
// var place = createTiddlyElement(place,"form",null,
("mathCellContainer "+params[0]+" "+params[1]));
var place = createTiddlyElement(place,"form",null,
("mathCellContainer "+rownum+" "+colnum));
var tiddler = store.getTiddler(params[0]);
var rows = tiddler.text.split("\n"); //ADDED
// for(var i = 1; i <= Number(params[0]); i++){
for(var i = 1; i <= rownum; i++){
row = createTiddlyElement(place,"div");
if(i % 2 == 0) row.className = "evenRow";
else row.className = "oddRow";
// for(var j = 0; j < Number(params[1]); j++){
for(var j = 0; j < colnum; j++){
var cells = rows[i-1].split("|"); //ADDED
var cell = document.createElement('input');
cell.type = 'text';
cell.className = "unselected";
// cell.title = "";
cell.value=cells[j+1];
cell.title = cells[j+1];
cell.onkeydown = function(event){
if(!event) var event = window.event;
var caret =
config.macros.MathCell.caretPosition(this)
switch(event.keyCode){
case 37:
if(this.previousSibling
&& this.previousSibling.previousSibling
&&
this.previousSibling.tagName == "INPUT" && caret[1] && caret
[0] == 0)
this.previousSibling.focus();
break;
case 39:
if(this.nextSibling &&
this.nextSibling .tagName == "INPUT"
&& caret[1] &&
caret[0] == this.value.length)
this.nextSibling .focus();
break;
case 38:
if(this.parentNode.previousSibling.previousSibling){
var elem = this;
var i = 0;
while((elem =
elem.previousSibling)){
i++;
}
if(this.parentNode.previousSibling.childNodes[i].tagName ==
"INPUT"){
this.parentNode.previousSibling.childNodes[i].focus();
}
}
break;
case 40:
if(this.parentNode.nextSibling){
var elem = this;
var i = 0;
while((elem =
elem.previousSibling)){
i++;
}
if(this.parentNode.nextSibling.childNodes[i].tagName ==
"INPUT"){
this.parentNode.nextSibling.childNodes[i].focus();
}
}
break;
return false;
}
};
cell.onfocus = function(){
this.value = this.title;
this.className = "selected";
return false;
}
cell.onblur = function(){
this.title = this.value;
this.className = "unselected";
if(0){
/*SEPERATE PARETHESIS WITH FUNCTION
NAMES CELL ABBREVIATIONS AND
OTHER*/
var parts =
this.value.replace(/\s+/g,"").match(/(?:[a-zA-Z][a-zA-
Z0-9]*[\(]|[\(]|[\)]|[0-9\+\-\/\*\^\!\^\%\.\,\:]+|[A-Z]+[0-9]+)/g);
// DEBUG WITH THIS BEFORE MESSING WITH
THE CODE! FOR THE LOVE OF
ALL THAT IS HOLY!
//alert(parts.join("\n"));
if(parts){
for(var i = 0; i <
parts.length; i++){
/*HANDLE [A-Z]+[0-9]+ CELL
ABBREVIATIONS*/
if(parts[i].match(/^[A-Z]+[0-9+]$/) && parts[i].indexOf("(") ==
-1){
var gobehind =
i;var size = 1;var result = "",getRow,number =
0,letters;
if(i > 0 &&
!parts[i-1].match(/[\(]/)){
size ++;
result
= parts[--gobehind];
if(!parts[gobehind].match(/[\+\-\^\%\*\/][\s]*$/)){result +=
"*";}
}
getRow =
parts[i].match(/[0-9]+/)[0];
if(getRow ==
"0"){
break;
}
getRow =
this.parentNode.parentNode.childNodes[getRow];
letters =
parts[i].match(/[A-Z]+/)[0];
for(var j = 0;
j < letters.length; j++){
number
+= (letters.charCodeAt(j) -64)*(Math.pow
(26,letters.length-1-j));
}
if(getRow.childNodes[number] == this){
displayMessage("cannot reference self node "+parts[i]);
return;
}
result +=
getRow.childNodes[number].value;
if(i <
parts.length -1 && parts[i+1] != ")"){
result
+= parts[gobehind+(++size)-1];
}
i--;
parts.splice(gobehind,size,result);
}
}
/*HANDLE PARENTHESIS AND
FUNCTION CALLS*/
var index;
//SHOULD CHANGE THIS TO A FOR
LOOP TO IMPROVE PERFOMANCE
while(parts.length > 1 &&
(index = parts.find(")")) != null){
if(index > 0){
parts[index-1]
= parts[index-1].toString();
if(!parts[index-1].match(/[\(]/) &&
config.macros.MathCell.functions[parts[index-2]]){
parts.splice(index-2,3,config.macros.MathCell.functions[parts[index-2]]
(parts[--index],this));
}
else
if(config.macros.MathCell.functions[parts[index-1]]){
parts.splice(index-1,2,config.macros.MathCell.functions[parts
[index-1]]("",this));
}
else{
displayMessage("function used in equation does not exist");
displayMessage("error: malformed mathCell equation.");
displayMessage("index : "+index);
return;
}
if(index <
parts.length && !parts[index].match(/[\)\(]/)){
if(!parts[index].toString().match(/^[\s]*[\)\*\/\+\-\%\^
\!]/))
parts[index] = "*"+parts[index]
parts.splice(index-1,2,parts[index-1]+parts[index--]);;
}
if(index > 1
&&!parts[index-2].toString().match(/[\(]/) && !
parts[index-2].toString().match(/[\+\-\^\%\*\/][\s]*$/) && index <=
parts.length){
parts.splice(index-2,2,parts[index-2]+"*"+parts[index-1]);
}
}
else{
displayMessage("parenthesis do not match up.");
displayMessage("error: malformed mathCell equation.");
return;
}
}
var result =
config.macros.MathCell.parseMath(parts.join(""));
if(!isNaN(result))
this.value = result;
else{
displayMessage("error:
malformed mathCell equation.");
}
return false;
}
}
}
row.appendChild(cell);
}
}
},
parseMath: function(equation){
return false;
}
}
/***
</code>
***/
On Nov 16, 5:10 am, "[email protected]" <[email protected]> wrote:
> I gave MathCell with Quikedit convert a try, but MathCell puts commas
> at the end of each line, and QuickEdit Convert sees these as extra
> empty cells, which, of course, is not useful.
>
> So for now, I can not use these together. I I doubt I will keep
> MathCell because it seems a bit cludgy since you have to manually load
> the data tiddler into another Tiddlier with the correct sized MathCell
> table defined by the macro each time you want to see it.
>
> So, I am still hoping someone out thinks its easier to edit tables in
> WYSIWYG format rather than with vertical lines or commas. I dont even
> need the math capabilities, just tools to create, fill and format a
> nice looking table with text or numbers
>
> Cheers,
>
> Grant
>
> On Nov 2, 4:37 pm, wolfgang <[email protected]> wrote:
>
> > Hi Grant,
>
> > see this thread for a request to update MathCell, which - though
> > having lost its advanced spreadsheet calculation abilities with the
> > latest TW version - is still capable of inline editing of TW format
> > tables. If used in combination with QuickEdit_convert for quick
> > conversion of a TW table to MathCell's csv format and back again:
>
> >http://groups.google.com/group/tiddlywiki/browse_thread/thread/7a6f68...
>
> > Regards..
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/tiddlywiki?hl=en.