Hi Eric,
Below is a proposed proof-of-concept snippet for EditSectionPlugin, to put the edit section button in a separate div outside the heading, so not to be covered by the fold heading onclick event:
----
// // EDIT SECTIONS MACRO
//{{{
config.macros.editSections = {
label: 'edit...',
tip: 'edit this section',
command: '~~<<editSection [[##%0]] "%1" "%2">>~~',
//GJRobert Ciang: insertAfter function from
http://snipplr.com/view/2107/insertafter-function-for-the-dom/ insertAfter: function (newElement,targetElement) {
//target is what you want it to go after. Look for this elements parent.
var parent = targetElement.parentNode;
//if the parents lastchild is the targetElement...
if(parent.lastchild == targetElement) {
//add the newElement after the target element.
parent.appendChild(newElement);
} else {
// else the target has siblings, insert the new element between the target and it's next sibling.
parent.insertBefore(newElement, targetElement.nextSibling);
}
},
handler: function(place,macroName,params,wikifier,paramString,tiddler) {
if (readOnly) return;
var elems=place.parentNode.getElementsByTagName("*");
for (var i=0; i<elems.length; i++) { var e=elems[i]; // for each heading element
if (!['H1','H2','H3','H4','H5'].contains(e.nodeName)) continue;
var section=e.textContent;
var label=(params[0]||this.label).format([section]);
var tip =(params[1]||this.tip ).format([section]);
var btn = document.createElement("div"); //Added by GJRobert Ciang
btn.setAttribute("class","editSectionBtn"); //Added by GJRobert Ciang
this.insertAfter(btn,e); //Added by GJRobert Ciang
// e.parentNode.insertBefore(btn,e); //Added by GJRobert Ciang
wikify(this.command.format([section,label,tip]),btn); //Modified by GJRobert Ciang, using a separate "btn" as the container instead of "e" (the heading element)
}
}
}
//G.J.Robert Ciang
setStylesheet (
".editSectionBtn {float: right;}\n"+
"\n","editSectionButtonStyles");
//}}}
----
Right now I can only insert the button after the heading element, and make it float to right. When I wanted to insert them before the headings, TW would hang. Perhaps the buttons draw the content of the element right after it so there would be indefinite loops (I'm not sure).
The snippet above can make <<editSection>> and <<foldHeadings>> announcements both effective in tiddler contents. But one limitation: if we put editSection macro in ViewTemplate directly to affect *every* tiddler by default, the title of the headings would be appended with the "fold" texts, and also the content of sections would be hidden.
Again, this is very immature and ugly so feel free to treat it in any way.
Cheers,
G.J.Robert Ciang
G.J.Robert於 2012年10月22日星期一UTC+8上午11時27分50秒寫道: