/***\n! Variables you could use in Javascript code called by JsDoIt\n| variable name | description | data type |h\n| macroName |name of macro - 'JsDoIt' | string |\n| params |parameters of this JsDoIt macro | string array |\n| allParams |parameters of this JsDoIt macro | string |\n| button |the JsDoIt button that user clicked on | HTML DOM object |\n| place |container of this JsDoIt button | HTML DOM object |\n| tiddler |tiddler that contains this JsDoIt macro instruction | object |\n| wikifier |wikifier that wikifies the tiddler(described above) contents | object |\n/%\n***/\n\nclearMessage();\n// macroName\ndisplayMessage('macroName=\s"'+macroName+'\s"');\n// params\ndisplayMessage('params='+params);\nfor(var j=0; j<params.length; j++){ \n displayMessage('params['+j+']=\s"'+params[j]+'\s"'); \n}\n// allParams\ndisplayMessage('allParams=\s"'+allParams+'\s"');\n// button\ndisplayMessage('button='+typeof(button));\n// place\ndisplayMessage('place='+place + ',\s"' + + '\s"');\n// tiddler\nif(tiddler){\n displayMessage('tiddler='+typeof(tiddler)+', tiddler.title=\s"' + tiddler.title + '\s"');\n}else{\n displayMessage('tiddler='+typeof(tiddler));\n} \n//wikifier\ndisplayMessage('wikifier='+typeof(wikifier));\n// if(wikifier){\n //displayMessage('wikifier.source='+wikifier.source);\n// }\n\n/***\n%/\n! Variables you SHOULD NOT MODIFY in Javascript code called by JsDoIt\n| variable name | reason |h\n| params |modifying it could break JsDoIt |\n| paramIndex |modifying it could break JsDoIt |\n***/\n\n
JsDoIt is somewhat like Eric Shulman's [[InlineJavascriptPlugin|]]. Both of them let user execute some Javascripts as needed, and this is the goal of JsDoIt. However, they are not all the same stuff. For example:\n*They have different usages\n*They have different appearances\n*They could reside in different places\n\nMy intention to design JsDoIt is providing another way to achieve the goal described above, not replacing InlineJavascriptPlugin. In fact, it's difficult to make some effects of InlineJavascriptPlugin with JsDoIt, such as producing dynamically embedded content within a tiddler. IMHO, InlineJavascriptPlugin is a very tricky and powerful tool, yet JsDoIt could be an easier and straightforward solution for some applications.\n\nTry out for some demos of JsDoIt listed in MainMenu on the left side of this page.\n
/***\n|''Name:''|JsDoIt|\n|''Version:''|1.0.1|\n|''Source:''|[[AiddlyWiki|]]|\n|''Author:''|[[Arphen Lin|]]|\n|''Type:''|Macro extension|\n|''Required:''|TiddlyWiki 2.0.0|\n!Description\nJsDoIt lets you execute Javascript executable codes immediately when you click on a JsDoIt macro button.\n!Syntax\n{{{<<}}}JsDoIt {label} {prompt} {jsEntity} [[jsEntity2] [jsEntity3] ... [jsEntityN]]{{{>>}}}\nparameters:\n* label - caption text of the JsDoIt button\n* prompt - tip text of the JsDoIt button\n* jsEntity - javascript that would be executed\n** javascript code - begin with ''javascript:''\n** javascript tiddler - tiddler that contains javascript code\n** external javascript source - including URIs and local files\n!Example & Demo\n* execute javascript code(s):\n<<<\n{{{<<JsDoIt 'click me!' 'execute javascript code' 'javascript:alert("Hello world!");'>>}}}\n<<JsDoIt 'click me!' 'execute javascript code' 'javascript:alert("Hello world!");'>>\n<<<\n* execute javascript tiddler(s):\n<<<\n{{{<<JsDoIt 'click me!' 'execute javascript tiddler(s)' 'code1.js' 'code2.js'>>}}}\n<<JsDoIt 'click me!' 'execute javascript tiddler(s)' 'code1.js' 'code2.js'>>\n<<<\n* execute external javascript source\n<<<\n{{{<<JsDoIt 'click me!' 'execute external javascript' 'external.js'>>}}}\n<<JsDoIt 'click me!' 'execute external javascript' 'external.js'>>\n{{{<<JsDoIt 'click me!' 'execute external javascript' ''>>}}}\n<<JsDoIt 'click me!' 'execute external javascript' ''>>\n<<<\n!Revision history\n*v1.0.1 (2006/1/6)\n**fixed for(var key in params){} problem\n*v1.0.0 (2006/1/4)\n**Initial release\n!Code\n***/\n//{{{\nconfig.macros.JsDoIt = {major: 1, minor: 0, revision: 1, date: new Date(2006,1,6)};\nconfig.macros.JsDoIt.handler = function(place,macroName,params,wikifier,allParams,tiddler){\n if(params.length<=2){ throw 'not enough parameters'; }\n var button = createTiddlyButton(place, params[0], params[1]);\n button.onclick = function(){\n for(var paramIndex=2; paramIndex<params.length; paramIndex++){\n var p=params[paramIndex];\n if(p.trim().search(/javascript:/gi)===0){\n eval(p.trim().replace(/javascript:/gi,''));\n }else{\n var t=store.getTiddler(p);\n if(t){\n eval(t.text);\n }else{\n var rs=document.createElement('script');\n rs.type = 'text/javascript';\n rs.src = p.trim();\n try{\n document.body.appendChild(rs);\n document.body.removeChild(rs);\n }catch(e){\n displayMessage('load ' + p + ' error: ' + e);\n }\n }\n }\n }\n };\n};\n//}}}
JsDoIt DEMO\n~~<<JsDoIt 'view demo source' 'view demo source' 'editMainMenu.js'>>~~\n----\n<<JsDoIt 'execute js-code' 'execute javascript code(s)' [[javascript:alert("Hello world!");]]>>\n<<JsDoIt 'execute js-tiddler' 'execute javascript tiddler(s)' code1.js code2.js>>\n<<JsDoIt 'load external js' 'execute external javascript' [[javascript: window.globalButton=button; button.innerHTML="waiting...";]]>>\n----\n<<JsDoIt 'list all tags' 'list all tags' listAllTags.js>>\n<<JsDoIt 'refresh all plugins' 'reload all systemConfig plugins without refreshing TW' [[javascript:loadSystemConfig(); clearMessage(); displayMessage("call TW kernel: loadSystemConfig()");]]>>\n----\n<<JsDoIt 'JsDoIt variables' 'list JsDoIt variables' viewDesignTips.js DesignTips>>\n\n
<<search>><<closeAll>><<newTiddler>><<permaview>><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel 'options »' 'Change TiddlyWiki advanced options'>>
click to execute Javascript
JsDoIt for TiddlyWiki <<version>>
<div class='toolbar' macro='toolbar -closeTiddler closeOthers +editTiddler permalink references jump newHere'></div>\n<div class='title' macro='view title'></div>\n<div class='subtitle'><span macro='view modifier link'></span>, <span macro='view modified date [[DD MMM YYYY]]'></span> (created <span macro='view created date [[DD MMM YYYY]]'></span>)</div>\n<div class='tagging' macro='tagging'></div>\n<div class='tagged' macro='tags'></div>\n<div class='viewer' macro='view text wikified'></div>\n<div class='tagClear'></div>
for(var i=0; i<10; i++){\neval('displayMessage(i)');\n}
alert('you are executing code1.js');
alert('you are executing code2.js');
story.closeTiddler('MainMenu');\nstory.displayTiddler(null, 'MainMenu', 'EditTemplate');
var popup = Popup.create(button);\nvar tags = store.getTags();\nfor(var t=0; t<tags.length; t++){\n var theTag = createTiddlyButton(createTiddlyElement(popup,"li"),tags[t][0],null,onClickTag);\n theTag.setAttribute("tag",tags[t][0]);\n}\,false);\n\nalert('the popup will be closed when you press ok\sn\sn(still some bugs...)');\n
while(true){\n displayMessage(apl);\n if(apl){\n apl(); \n break;\n }else{\n displayMessage('waiting...');\n }\n}
/***\n! reload systemConfig tiddlers\n***/\n//{{{\nloadSystemConfig();\n//}}}