commit 3a8c396706aad6c7b62021c2f6571984bbe14ec6
parent cd30d257d25f84a5064b626b012d0c9351c0e1d3
Author: Alexander Burger <abu@software-lab.de>
Date: Fri, 15 Mar 2013 19:42:55 +0100
Support "_blank" target in URLs (via "+" prefix character)
Diffstat:
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/lib/form.js b/lib/form.js
@@ -1,4 +1,4 @@
-/* 09mar13abu
+/* 15mar13abu
* (c) Software Lab. Alexander Burger
*/
@@ -71,6 +71,16 @@ function hasElement(form, name) {
return false;
}
+function setHref(fld, url) {
+ var i = url.indexOf("+");
+
+ if (i >= 0) {
+ url = url.substring(0,i) + url.substr(i+1);
+ fld.target = "_blank";
+ }
+ fld.href = decodeURIComponent(url);
+}
+
/*** Form submit ***/
function doPost(form) {
for (var i = 0; ; ++i) {
@@ -134,7 +144,7 @@ function post(form, file) {
else {
var a = document.createElement("A");
- a.href = decodeURIComponent(txt[i++].substr(1));
+ setHref(a, txt[i++].substr(1));
a.appendChild(document.createTextNode(val));
fld.replaceChild(a, fld.firstChild);
}
@@ -148,7 +158,7 @@ function post(form, file) {
}
else {
fld.firstChild.data = val;
- fld.href = decodeURIComponent(txt[i++].substr(1));
+ setHref(fld, txt[i++].substr(1));
}
}
else if (fld.tagName == "IMG") {
@@ -158,7 +168,7 @@ function post(form, file) {
fld.alt = txt[i++];
if (parent.tagName == "A") {
if (txt[i])
- parent.href = decodeURIComponent(txt[i]);
+ setHref(parent, txt[i]);
else {
grand = parent.parentNode;
grand.removeChild(parent);
@@ -171,7 +181,7 @@ function post(form, file) {
parent.removeChild(fld);
parent.appendChild(a);
a.appendChild(fld);
- a.href = decodeURIComponent(txt[i]);
+ setHref(a, txt[i]);
}
++i;
}
@@ -240,7 +250,7 @@ function post(form, file) {
else {
var a = document.createElement("A");
- a.href = decodeURIComponent(txt[i]);
+ setHref(a, txt[i]);
a.appendChild(img);
node.appendChild(a);
}
diff --git a/lib/xhtml.l b/lib/xhtml.l
@@ -1,4 +1,4 @@
-# 14mar13abu
+# 15mar13abu
# (c) Software Lab. Alexander Burger
# *JS "*JS" *Style *Menu *Tab *ID
@@ -200,7 +200,13 @@
(prinl) )
(de <href> (Str Url Tar)
- (prin "<a href=\"" (sesId Url) "\"")
+ (prin "<a href=\""
+ (sesId
+ (ifn (pre? "+" Url)
+ Url
+ (setq Tar "_blank")
+ (pack (cdr (chop Url))) ) )
+ "\"" )
(and Tar (prin " target=\"" Tar "\""))
(and *Style (htStyle @))
(prin '>)
@@ -208,7 +214,13 @@
(prin "</a>") )
(de <img> (Src Alt Url DX DY)
- (and Url (prin "<a href=\"" (sesId Url) "\">"))
+ (when Url
+ (prin "<a href=\""
+ (sesId
+ (ifn (pre? "+" Url)
+ Url
+ (pack (cdr (chop Url)) "\" target=\"_blank") ) )
+ "\">" ) )
(prin "<img src=\"" (sesId Src) "\"")
(when Alt
(prin " alt=\"")