It looks like you're new here. If you want to get involved, click one of these buttons!
macros["append"] =
{
handler: function(place, macroName, params, parser)
{
// process the contents of the container macro
var openTag = macroName
, closeTag = "end" + macroName
, start = parser.source.indexOf(">>", parser.matchStart) + 2
, end = -1
, tagBegin = start
, tagEnd = start
, opened = 1;
while ((tagBegin = parser.source.indexOf("<<", tagEnd)) !== -1
&& (tagEnd = parser.source.indexOf(">>", tagBegin)) !== -1)
{
var tagName = parser.source.slice(tagBegin + 2, tagEnd)
, tagDelim = tagName.search(/\s/);
if (tagDelim !== -1)
{
tagName = tagName.slice(0, tagDelim);
}
tagEnd += 2;
switch (tagName)
{
case closeTag:
opened--;
break;
case openTag:
opened++;
break;
}
if (opened === 0)
{
end = tagBegin;
break;
}
}
// if we successfully found an end tag for the macro
if (end !== -1)
{
parser.nextMatch = tagEnd;
// Macrocode
this.a = macroName;
this.b = parser.source.slice(start, end);
this.c = ('<div id="' + this.a + '">' + this.b + '</div>');
new Wikifier(place, this.c);
//endmacrocode
}
else
{
throwError(place, "<<" + macroName + ">>: cannot find a matching close tag");
}
},
};
macros["endappend"] = { handler: function () {} };
I have four macros which all use this code, however, where I have marked //macrocode and //endmacrocode shows where the macro differs each time. The macro names are Append, Question, Answer and Choiceblock. (function () {
version.extensions['dialoguemacro'] = {
major: 1,
minor: 0,
revision: 0
};
macros['append'] = macros['answer'] = macros['question'] = macros['choiceblock'] =
{
handler: function(place, macroName, params, parser)
{
// process the contents of the container macro
var openTag = macroName
, closeTag = "end" + macroName
, start = parser.source.indexOf(">>", parser.matchStart) + 2
, end = -1
, tagBegin = start
, tagEnd = start
, opened = 1;
while ((tagBegin = parser.source.indexOf("<<", tagEnd)) !== -1
&& (tagEnd = parser.source.indexOf(">>", tagBegin)) !== -1)
{
var tagName = parser.source.slice(tagBegin + 2, tagEnd)
, tagDelim = tagName.search(/\s/);
if (tagDelim !== -1)
{
tagName = tagName.slice(0, tagDelim);
}
tagEnd += 2;
switch (tagName)
{
case closeTag:
opened--;
break;
case openTag:
opened++;
break;
}
if (opened === 0)
{
end = tagBegin;
break;
}
}
// if we successfully found an end tag for the macro
if (end !== -1)
{
if (macroName = "append")
{
parser.nextMatch = tagEnd;
// append
this.a = macroName;
this.b = parser.source.slice(start, end);
this.c = ('<div id="' + this.a + '">' + this.b + '</div>');
new Wikifier(place, this.c);
}
else if (macroName = "answer")
{
parser.nextMatch = tagEnd;
// answer
this.a = macroName;
this.b = params[0];
this.c = parser.source.slice(start, end);
this.d = ('<div class="answer-' + this.b + '">' + this.c + '</div>');
new Wikifier(place, this.d);
}
else if (macroName = "question")
{
parser.nextMatch = tagEnd;
// question
this.a = macroName;
this.b = params[0];
this.c = parser.source.slice(start, end);
this.d = ('<a class="question" id="' + this.b + '">' + this.c + '</a>');
new Wikifier(place, this.d);
}
else if (macroName = "choiceblock")
{
parser.nextMatch = tagEnd;
// choiceblock
this.a = macroName;
this.b = params[0];
this.c = parser.source.slice(start, end);
this.d = ('<div class="inlinechoice-' + this.b + '" id="' + this.b + '">' + this.c + '</div>');
new Wikifier(place, this.d);
}
}
else
{
throwError(place, "<<" + macroName + ">>: cannot find a matching close tag");
}
},
};
macros["endappend"] = { handler: function () {} };
macros["endanswer"] = { handler: function () {} };
macros["endquestion"] = { handler: function () {} };
macros["endchoiceblock"] = { handler: function () {} };
}());
Comments
As a suggestion:
The TWS you posted also seems to be missing some external JS (fakechoice1.js), so there's that too.