From acdbedc507679be7b35a0fe10990bfb579bdc9d9 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 1 Sep 2011 15:41:38 +0200 Subject: Add the JavaScript magic element to indicate number of comments. --- org/madore/damlengine/Context.java | 1 + org/madore/damlengine/TodoComments.java | 7 ++++++ org/madore/damlengine/TodoCommentsScript.java | 26 ++++++++++++++++++++++ org/madore/damlengine/TodoWeblogElement.java | 8 ++++++- org/madore/damlengine/TodoWeblogSelectElement.java | 6 +++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 org/madore/damlengine/TodoCommentsScript.java diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java index 12e2f1b..6b627a4 100644 --- a/org/madore/damlengine/Context.java +++ b/org/madore/damlengine/Context.java @@ -22,6 +22,7 @@ public class Context implements Cloneable { public String subtitleStr; public String subtitleLang; public ArrayList translations; + public StringBuffer commentsJSParam; } public GeneralContext gc; diff --git a/org/madore/damlengine/TodoComments.java b/org/madore/damlengine/TodoComments.java index 85ce7d3..e5cb04e 100644 --- a/org/madore/damlengine/TodoComments.java +++ b/org/madore/damlengine/TodoComments.java @@ -53,5 +53,12 @@ public final class TodoComments extends TodoElement { + ctx.ent.number + ".numcomments"); p.appendChild(span); span.appendChild(ctx.doc.createComment(" EMPTY ")); + if ( ctx.gc.commentsJSParam == null ) { + ctx.gc.commentsJSParam = new StringBuffer("x=" + ctx.ent.date + "." + + ctx.ent.number); + } else { + ctx.gc.commentsJSParam.append("&x=" + ctx.ent.date + "." + + ctx.ent.number); + } } } diff --git a/org/madore/damlengine/TodoCommentsScript.java b/org/madore/damlengine/TodoCommentsScript.java new file mode 100644 index 0000000..224d547 --- /dev/null +++ b/org/madore/damlengine/TodoCommentsScript.java @@ -0,0 +1,26 @@ +package org.madore.damlengine; + +import org.w3c.dom.*; + +public final class TodoCommentsScript extends TodoElement { + + public TodoCommentsScript(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handle() { + if ( ctx.gc.commentsJSParam == null ) { + node.getParentNode().removeChild(node); + return; + } + Element script = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "script"); + script.setAttributeNS(null, "type", "text/javascript"); + script.setAttributeNS(null, "src", "/cgi-bin/numcomments.pl/x.js?"+ctx.gc.commentsJSParam); + script.setAttributeNS(null, "defer", "defer"); + node.appendChild(ctx.doc.createComment(" EMPTY ")); + node.getParentNode().replaceChild(script, node); + } +} diff --git a/org/madore/damlengine/TodoWeblogElement.java b/org/madore/damlengine/TodoWeblogElement.java index fa537a8..3d457a8 100644 --- a/org/madore/damlengine/TodoWeblogElement.java +++ b/org/madore/damlengine/TodoWeblogElement.java @@ -23,6 +23,7 @@ public final class TodoWeblogElement extends TodoDefaultElement { @Override public void handleNodeOnly() { + System.err.println("warning: weblog element should not be processed this way!"); Node parent = node.getParentNode(); String lang = LangHelper.getLangNorec(node); ArrayList childList = getChildList(this.node); @@ -42,8 +43,13 @@ public final class TodoWeblogElement extends TodoDefaultElement { toProcess.add(it); } } - this.ownerDeque.registerAtStart(toProcess); + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-comments-script"); + node.getParentNode().insertBefore(token, node); + node.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), node); + toProcess.add(new TodoCommentsScript(token, ctx, this)); parent.removeChild(node); + this.ownerDeque.registerAtStart(toProcess); } } diff --git a/org/madore/damlengine/TodoWeblogSelectElement.java b/org/madore/damlengine/TodoWeblogSelectElement.java index 145b938..33c9731 100644 --- a/org/madore/damlengine/TodoWeblogSelectElement.java +++ b/org/madore/damlengine/TodoWeblogSelectElement.java @@ -42,11 +42,17 @@ public final class TodoWeblogSelectElement extends TodoDefaultElement { Document temp = par.parse(input); Node newNode = ctx.doc.adoptNode(temp.getDocumentElement()); node.getParentNode().insertBefore(newNode, node); + node.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), node); TodoElement it = TodoElement.getTodoElement((Element)newNode, this.ctx, this); toProcess.add(it); } + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-comments-script"); + node.getParentNode().insertBefore(token, node); + node.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), node); + toProcess.add(new TodoCommentsScript(token, ctx, this)); node.getParentNode().removeChild(node); this.ownerDeque.registerAtStart(toProcess); } -- cgit v1.2.3