afterChange: function(change,source){
if ( source == 'loadData' ) return;
// Find the tiddler containing this table.
var tiddler = store.getTiddler(
story.findContainingTiddler(hot.container).getAttribute("tiddler")
);
// Get the tiddler text.
var text = tiddler.text;
// Find the start and end of table data.
// First, we find the variable name for the table data, assuming it exists.
var p1 = text.indexOf('Handsontable');
p1 = text.indexOf('data',p1);
p1 = text.indexOf(':',p1);
var p2 = text.indexOf(',',p1);
var dataname = text.substring(p1+1,p2).trim();
// Then we look for the beginning of data definition,
p1 = text.indexOf('var');
p1 = text.indexOf(dataname,p1+1)+dataname.length;
// and the end of data definition.
p2 = text.indexOf('];',p1)+2;
// Convert the modified data into the defining string.
var data = hot.getData();
var txtdata = ' = [\n';
for ( var r=0, rlen=data.length-hot.getSettings().minSpareRows; r<rlen; r++ ){
txtdata += '[';
for ( var c=0,clen=data[r].length; c<clen; c++ ){
var wrap = typeof data[r][c] == 'string' ? '"' : '';
txtdata += wrap+data[r][c]+wrap+(c<clen-1?', ':'');
}
txtdata +=']' + (r<rlen-1?',':'') + '\n';
}
txtdata += '];'
// Replace the original definition string with the modified one.
text = text.substring(0,p1)+txtdata+text.substring(p2);
// Set it back to the tiddler,
tiddler.set(
tiddler.title,text,tiddler.modifier,new Date()
);
// and mark it as modified.
store.setDirty(true);
}
afterChange: function(change,source){
if ( source == 'loadData' ) return;
// Find the tiddler containing this table.
var tiddler = store.getTiddler(
story.findContainingTiddler(this.container).getAttribute("tiddler")
);
// Get the tiddler text.
var text = tiddler.text;
// Find the start and end of table data.
// First, we find the variable name for the table data, assuming it exists.
var p1 = text.indexOf('Handsontable');
p1 = text.indexOf('data',p1);
p1 = text.indexOf(':',p1);
var p2 = text.indexOf(',',p1);
var dataname = text.substring(p1+1,p2).trim();
// Then we look for the beginning of data definition,
p1 = text.indexOf('var');
p1 = text.indexOf(dataname,p1+1)+dataname.length;
// and the end of data definition.
p2 = text.indexOf('];',p1)+2;
// Convert the modified data into the defining string.
var data = this.getData();
var txtdata = ' = [\n';
for ( var r=0, rlen=data.length-this.getSettings().minSpareRows; r<rlen; r++ ){
txtdata += '[';
for ( var c=0,clen=data[r].length; c<clen; c++ ){
var wrap = typeof data[r][c] == 'string' ? '"' : '';
txtdata += wrap+data[r][c]+wrap+(c<clen-1?', ':'');
}
txtdata +=']' + (r<rlen-1?',':'') + '\n';
}
txtdata += '];'
// Replace the original definition string with the modified one.
text = text.substring(0,p1)+txtdata+text.substring(p2);
// Set it back to the tiddler,
tiddler.set(
tiddler.title,text,tiddler.modifier,new Date()
);
// and mark it as modified.
store.setDirty(true);
}...