[svn r11046] Bugfix: .substr(-3) works in Firefox, but not in IE

skala
Bart Mollet 18 years ago
parent 5f6503a8aa
commit ef415f9830
  1. 311
      main/metadata/md_script.js

@ -10,23 +10,23 @@
{ {
return this.replace(/^\s*/,"").replace(/\s*$/,""); // \f\n\r\t\v return this.replace(/^\s*/,"").replace(/\s*$/,""); // \f\n\r\t\v
} // Dave Anderson, dbforums.com/arch/195/2003/3/724117 } // Dave Anderson, dbforums.com/arch/195/2003/3/724117
String.prototype.removeExtraSpaces = function() String.prototype.removeExtraSpaces = function()
{ {
return this.replace(/\s+/g, ' ').trim(); return this.replace(/\s+/g, ' ').trim();
} }
function makeWindow(url, htmlText) function makeWindow(url, htmlText)
{ {
var newWindow = window.open(url, '', var newWindow = window.open(url, '',
'toolbar=no, location=no, directories=no, status=yes, '+ 'toolbar=no, location=no, directories=no, status=yes, '+
'menubar=yes, scrollbars=yes, resizable=yes, ' + 'menubar=yes, scrollbars=yes, resizable=yes, ' +
'width=800, height=600, left=10, top=10'); 'width=800, height=600, left=10, top=10');
if (url == '') newWindow.document.write('<html><body>' + if (url == '') newWindow.document.write('<html><body>' +
htmlText + '</body></html>'); htmlText + '</body></html>');
return newWindow; return newWindow;
} }
function isNotW3C() function isNotW3C()
{ {
if (!document.getElementById) if (!document.getElementById)
@ -34,36 +34,36 @@
'Use FireFox or IE6 or Moz1.7 or type in keywords manually...'); 'Use FireFox or IE6 or Moz1.7 or type in keywords manually...');
return !document.getElementById; return !document.getElementById;
} }
function openOrCloseHelp(btn) function openOrCloseHelp(btn)
{ {
if (isNotW3C()) return false; if (isNotW3C()) return false;
document.getElementById('moreHelp').className = document.getElementById('moreHelp').className =
(btn.value == "?") ? "dvo" : "dvc"; (btn.value == "?") ? "dvo" : "dvc";
btn.value = (btn.value == "?") ? "¿" : "?"; btn.value = (btn.value == "?") ? "¿" : "?";
} }
function hasTagAndClass(obj, tag, cl) function hasTagAndClass(obj, tag, cl)
{ {
return obj.tagName && (obj.tagName.toUpperCase() == tag) && return obj.tagName && (obj.tagName.toUpperCase() == tag) &&
(obj.className == cl); (obj.className == cl);
} }
function openOrClose(btn) // show or hide part of keyword-tree function openOrClose(btn) // show or hide part of keyword-tree
{ {
var oldcl = (btn.value == "-") ? "dvo" : "dvc"; var oldcl = (btn.value == "-") ? "dvo" : "dvc";
var newcl = (oldcl == "dvo") ? "dvc" : "dvo"; var newcl = (oldcl == "dvo") ? "dvc" : "dvo";
btn.value = (oldcl == "dvo") ? "+" : "-" ; btn.value = (oldcl == "dvo") ? "+" : "-" ;
var ch = btn.parentNode.childNodes; // opera crashes on with() var ch = btn.parentNode.childNodes; // opera crashes on with()
for (var i = 0; i < ch.length; i++) // netscape requires .item for (var i = 0; i < ch.length; i++) // netscape requires .item
if (hasTagAndClass(ch.item(i), 'DIV', oldcl)) if (hasTagAndClass(ch.item(i), 'DIV', oldcl))
ch.item(i).className = newcl; ch.item(i).className = newcl;
} }
function openOrCloseHere(div, wrong) // show or hide recursively function openOrCloseHere(div, wrong) // show or hide recursively
{ {
var ch = div.childNodes; var ch = div.childNodes;
@ -76,25 +76,25 @@
openOrCloseHere(thisCh, wrong); openOrCloseHere(thisCh, wrong);
} }
} }
function openOrCloseAll(btn) // show or hide whole keyword-tree function openOrCloseAll(btn) // show or hide whole keyword-tree
{ {
if (isNotW3C()) return false; if (isNotW3C()) return false;
var wrong = (btn.value == "--") ? "-" : "+" ; var wrong = (btn.value == "--") ? "-" : "+" ;
btn.value = (wrong == "-") ? "++" : "--"; btn.value = (wrong == "-") ? "++" : "--";
openOrCloseHere(btn.parentNode, wrong); openOrCloseHere(btn.parentNode, wrong);
} }
var selspans = new Array; // selected SPANs with keywords var selspans = new Array; // selected SPANs with keywords
function deselect(span) function deselect(span)
{ {
for (var s in selspans) if (selspans[s] == span) delete selspans[s]; for (var s in selspans) if (selspans[s] == span) delete selspans[s];
} }
function copyToClipboard(allKwds) // md_script: not used function copyToClipboard(allKwds) // md_script: not used
{ {
if (window.clipboardData) if (window.clipboardData)
@ -102,35 +102,35 @@
window.clipboardData.setData("Text", '<' + allKwds + '>\r\n'); window.clipboardData.setData("Text", '<' + allKwds + '>\r\n');
return; return;
} }
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var gClipboardHelper = Components.classes['@mozilla.org/widget/clipboardhelper;1'] var gClipboardHelper = Components.classes['@mozilla.org/widget/clipboardhelper;1']
.getService(Components.interfaces.nsIClipboardHelper); .getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString('<' + allKwds + '>\n'); gClipboardHelper.copyString('<' + allKwds + '>\n');
} }
function getSelectedKeywords() function getSelectedKeywords()
{ {
var sortedKwds = new Array, allKwds = ''; var sortedKwds = new Array, allKwds = '';
for (var s in selspans) for (var s in selspans)
sortedKwds.push(selspans[s].parentNode.getAttribute('level') sortedKwds.push(selspans[s].parentNode.getAttribute('level')
+ '.' + selspans[s].innerHTML) + '.' + selspans[s].innerHTML)
sortedKwds.sort(); // according to level, which follows the tree sortedKwds.sort(); // according to level, which follows the tree
for (var k in sortedKwds) for (var k in sortedKwds)
{ {
var someWords = sortedKwds[k]; var someWords = sortedKwds[k];
allKwds += ', ' + someWords.substr(someWords.indexOf('.')+1); allKwds += ', ' + someWords.substr(someWords.indexOf('.')+1);
} }
return allKwds.replace(/[,_\s]+/g, ', ').substr(2); // strip ', ' return allKwds.replace(/[,_\s]+/g, ', ').substr(2); // strip ', '
} }
var orkwds; // array of ', kw, ' strings var orkwds; // array of ', kw, ' strings
function selectOriginal(div) function selectOriginal(div)
{ {
var ch = div.childNodes; var ch = div.childNodes;
@ -138,17 +138,17 @@
{ {
var thisCh = ch.item(i); if (!thisCh.tagName) continue; var thisCh = ch.item(i); if (!thisCh.tagName) continue;
thisTag = thisCh.tagName.toUpperCase(); thisTag = thisCh.tagName.toUpperCase();
if (thisTag == 'SPAN') if (thisTag == 'SPAN')
{ {
var parkwds = ','+ thisCh.innerHTML.replace(/\s*/g,"") +','; var parkwds = ','+ thisCh.innerHTML.replace(/\s*/g,"") +',';
for (var k = 0; k < orkwds.length; k++) for (var k = 0; k < orkwds.length; k++)
if (parkwds.indexOf(orkwds[k]) >=0 ) if (parkwds.indexOf(orkwds[k]) >=0 )
{ {
deselect(thisCh); selspans.push(thisCh); deselect(thisCh); selspans.push(thisCh);
thisCh.className = "lbs"; thisCh.className = "lbs";
openToTop(div, div.className); break; openToTop(div, div.className); break;
} }
} }
@ -158,14 +158,14 @@
} }
} }
} }
function openToTop(div, divclass) function openToTop(div, divclass)
{ {
if (!div.parentNode) return; var pdiv = div.parentNode; if (!div.parentNode) return; var pdiv = div.parentNode;
if (!pdiv.className) return; var pclass = pdiv.className; if (!pdiv.className) return; var pclass = pdiv.className;
if (pclass != 'dvo' && pclass != 'dvc') return; if (pclass != 'dvo' && pclass != 'dvc') return;
if (divclass == 'dvc') if (divclass == 'dvc')
{ {
var ch = pdiv.childNodes; var ch = pdiv.childNodes;
@ -176,59 +176,59 @@
if (btn.value == '+') openOrClose(btn); if (btn.value == '+') openOrClose(btn);
} }
} }
openToTop(pdiv, pclass); openToTop(pdiv, pclass);
} }
function deselectAll(ev, btn) function deselectAll(ev, btn)
{ {
if (isNotW3C()) return false; if (isNotW3C()) return false;
if (!ev) var ev = window.event; if (!ev) var ev = window.event;
var kws = document.getElementById('kwds_string'); var kws = document.getElementById('kwds_string');
for (var s in selspans) selspans[s].className = "lbl"; for (var s in selspans) selspans[s].className = "lbl";
selspans = new Array; selspans = new Array;
document.getElementById('btnOpenOrCloseAll').value = "--"; document.getElementById('btnOpenOrCloseAll').value = "--";
if (!ev.altKey) { kws.value = ''; return; } if (!ev.altKey) { kws.value = ''; return; }
// md_script: the calling HTML should define var kwdswere! // md_script: the calling HTML should define var kwdswere!
// in SelKwds.xsl, they are typed in by user or fetched from PPT // in SelKwds.xsl, they are typed in by user or fetched from PPT
var kwdsarray = kwdswere.split(','), allKwds = ''; var kwdsarray = kwdswere.split(','), allKwds = '';
for (var k = 0; k < kwdsarray.length; k++) for (var k = 0; k < kwdsarray.length; k++)
{ {
var kwd = kwdsarray[k].trim(); var kwd = kwdsarray[k].trim();
if (kwd.substr(0,1) == '-') kwd = kwd.substr(1); if (kwd.substr(0,1) == '-') kwd = kwd.substr(1);
if (kwd != '') allKwds += '§,' + kwd + ','; if (kwd != '') allKwds += '§,' + kwd + ',';
} }
if (allKwds == '') return; if (allKwds == '') return;
orkwds = allKwds.substr(1).split('§'); orkwds = allKwds.substr(1).split('§');
selectOriginal(btn.parentNode); selectOriginal(btn.parentNode);
allKwds = getSelectedKeywords(); kws.value = allKwds; allKwds = getSelectedKeywords(); kws.value = allKwds;
// no copyToClipboard(allKwds); // no copyToClipboard(allKwds);
allKwds = ','+ allKwds.replace(/\s*/g,"") +','; var missing = ''; allKwds = ','+ allKwds.replace(/\s*/g,"") +','; var missing = '';
for (k = 0; k < orkwds.length; k++) for (k = 0; k < orkwds.length; k++)
if (allKwds.indexOf(orkwds[k]) < 0 ) missing += orkwds[k]; if (allKwds.indexOf(orkwds[k]) < 0 ) missing += orkwds[k];
if (missing != '') alert('!= ' + missing.replace(/,+/g," ")); if (missing != '') alert('!= ' + missing.replace(/,+/g," "));
} }
function selectOrDeselect(span, newcl) function selectOrDeselect(span, newcl)
{ {
span.className = newcl; deselect(span); span.className = newcl; deselect(span);
if (newcl == "lbs") selspans.push(span); if (newcl == "lbs") selspans.push(span);
} }
function alsoParents(div, oldcl, newcl) function alsoParents(div, oldcl, newcl)
{ {
while (div.parentNode) while (div.parentNode)
@ -239,7 +239,7 @@
selectOrDeselect(ch.item(i), newcl); selectOrDeselect(ch.item(i), newcl);
} }
} }
function spanClick(span, ev) // md_script: no parents in search function spanClick(span, ev) // md_script: no parents in search
{ {
var mda = getObj("mda"); if (!ev) ev = window.event; var mda = getObj("mda"); if (!ev) ev = window.event;
@ -251,7 +251,7 @@
.replace(/</g, "&lt;") .replace(/>/g, "&gt;") + '</pre>'); .replace(/</g, "&lt;") .replace(/>/g, "&gt;") + '</pre>');
return; // debugging... return; // debugging...
} }
if (ev.ctrlKey || span.className == "lbs") if (ev.ctrlKey || span.className == "lbs")
{ {
selectOrDeselect(span, "lbl"); // deselect selectOrDeselect(span, "lbl"); // deselect
@ -267,14 +267,14 @@
span.innerHTML = (', ' + span.innerHTML).replace(/, -/g, ", ").substr(2); span.innerHTML = (', ' + span.innerHTML).replace(/, -/g, ", ").substr(2);
else span.innerHTML = (', ' + span.innerHTML).replace(/, /g, ", -").substr(2); else span.innerHTML = (', ' + span.innerHTML).replace(/, /g, ", -").substr(2);
} }
var allKwds = getSelectedKeywords(); // no copyToClipboard(allKwds); var allKwds = getSelectedKeywords(); // no copyToClipboard(allKwds);
document.getElementById('kwds_string').value = allKwds; document.getElementById('kwds_string').value = allKwds;
} }
var KWDS_ARRAY = new Array, nkw = 0, pU; // alphabetic list popup var KWDS_ARRAY = new Array, nkw = 0, pU; // alphabetic list popup
function makeAlphaList(div) // md_script: not used (hopefully) function makeAlphaList(div) // md_script: not used (hopefully)
{ {
var ch = div.childNodes; var ch = div.childNodes;
@ -282,7 +282,7 @@
{ {
var thisCh = ch.item(i); if (!thisCh.tagName) continue; var thisCh = ch.item(i); if (!thisCh.tagName) continue;
thisTag = thisCh.tagName.toUpperCase(); thisTag = thisCh.tagName.toUpperCase();
if (thisTag == 'SPAN') if (thisTag == 'SPAN')
{ {
var parkwds= thisCh.innerHTML.replace(/\s*/g,"").split(','); var parkwds= thisCh.innerHTML.replace(/\s*/g,"").split(',');
@ -291,20 +291,20 @@
else if (thisTag == 'DIV') makeAlphaList(thisCh); else if (thisTag == 'DIV') makeAlphaList(thisCh);
} }
} }
function pU_show(anchor, offsetX, offsetY, defH) // XY: rel. to anchor function pU_show(anchor, offsetX, offsetY, defH) // XY: rel. to anchor
{ {
if (!anchor) return; if (!anchor) return;
thisx = anchor.offsetLeft; thisy = anchor.offsetTop; thisx = anchor.offsetLeft; thisy = anchor.offsetTop;
while ((anchor = anchor.offsetParent)) while ((anchor = anchor.offsetParent))
{ {
thisx += anchor.offsetLeft; thisy += anchor.offsetTop; thisx += anchor.offsetLeft; thisy += anchor.offsetTop;
} }
thisx += offsetX; thisy += offsetY; thisx += offsetX; thisy += offsetY;
pU.style.left = thisx + "px"; pU.style.left = thisx + "px";
pU.style.top = thisy + "px"; pU.style.top = thisy + "px";
pU.style.height = defH; var maxH = pU.offsetHeight; pU.style.height = defH; var maxH = pU.offsetHeight;
@ -316,63 +316,63 @@
// scrollHeight can be smaller than current in IE, not in Moz // scrollHeight can be smaller than current in IE, not in Moz
pU.style.visibility = "visible"; pU.style.visibility = "visible";
} }
function pU_hide() function pU_hide()
{ {
if (pU) pU.style.visibility = "hidden"; if (pU) pU.style.visibility = "hidden";
} }
function takeTypeIn(kws, oX, oY, defH) function takeTypeIn(kws, oX, oY, defH)
{ {
if (isNotW3C()) return; if (isNotW3C()) return;
if (!pU) if (!pU)
{ {
pU = document.getElementById('popup'); pU = document.getElementById('popup');
if (!KWDS_ARRAY.length) if (!KWDS_ARRAY.length)
{ {
makeAlphaList(document.getElementById('maindiv')); makeAlphaList(document.getElementById('maindiv'));
KWDS_ARRAY.sort(); KWDS_ARRAY.sort();
} }
} }
if (!(curValue = kws.value.toLowerCase())) return; if (!(curValue = kws.value.toLowerCase())) return;
var kwLines = ''; var kwLines = '';
for (pos = 0; pos < KWDS_ARRAY.length; pos++) for (pos = 0; pos < KWDS_ARRAY.length; pos++)
if (KWDS_ARRAY[pos].toLowerCase().indexOf(curValue) == 0) if (KWDS_ARRAY[pos].toLowerCase().indexOf(curValue) == 0)
kwLines += '<div class="pul" onMouseOver="this.className=' + kwLines += '<div class="pul" onMouseOver="this.className=' +
"'lbl'" + '"; onMouseOut="this.className=' + "'pul'" + "'lbl'" + '"; onMouseOut="this.className=' + "'pul'" +
'">' + KWDS_ARRAY[pos] + '</div>'; '">' + KWDS_ARRAY[pos] + '</div>';
if (kwLines == '') {pU_hide(); return; } if (kwLines == '') {pU_hide(); return; }
pU.innerHTML = kwLines; pU_show(kws, oX, oY, defH); pU.innerHTML = kwLines; pU_show(kws, oX, oY, defH);
} }
function pU_clicked(ev) function pU_clicked(ev)
{ {
if (!pU) return false; if (!ev) var ev = window.event; if (!pU) return false; if (!ev) var ev = window.event;
var t = (ev.srcElement) ? ev.srcElement : ev.originalTarget; var t = (ev.srcElement) ? ev.srcElement : ev.originalTarget;
try {var kw = t.innerHTML;} catch(exc) {return false;} // Moz try {var kw = t.innerHTML;} catch(exc) {return false;} // Moz
while (true) try while (true) try
{ {
if (t.id == pU.id) return kw ? kw : true; t = t.parentNode; if (t.id == pU.id) return kw ? kw : true; t = t.parentNode;
} }
catch(exc) {return false;} // Moz: t.parentNode uncatched exc. catch(exc) {return false;} // Moz: t.parentNode uncatched exc.
} }
function pU_select(kw) function pU_select(kw)
{ {
if (kw === true) return; if (kw === true) return;
var kws = document.getElementById('kwds_string'); var kws = document.getElementById('kwds_string');
var maindiv = document.getElementById('maindiv'); var maindiv = document.getElementById('maindiv');
var ch = maindiv.childNodes; var ch = maindiv.childNodes;
for (var i = 0; i < ch.length; i++) for (var i = 0; i < ch.length; i++)
{ {
@ -381,46 +381,46 @@
if (btn.value == '+') openOrClose(btn); if (btn.value == '+') openOrClose(btn);
} }
orkwds = new Array(',' + kw + ','); selectOriginal(maindiv); orkwds = new Array(',' + kw + ','); selectOriginal(maindiv);
kws.value = getSelectedKeywords(); // no copyToClipboard(kws.value); kws.value = getSelectedKeywords(); // no copyToClipboard(kws.value);
pU_hide(); pU_hide();
} }
// Part 2: Metadata Updates: W3C, IE4 and NS4 browsers // Part 2: Metadata Updates: W3C, IE4 and NS4 browsers
function isValidChar(ev, pattern, flags) function isValidChar(ev, pattern, flags)
{ {
// e.g. onKeyPress="return isValidChar(event, '[a-z]', 'i');" // e.g. onKeyPress="return isValidChar(event, '[a-z]', 'i');"
if (!ev) var ev = window.event; // PPK, see below if (!ev) var ev = window.event; // PPK, see below
var kc = (ev.keyCode) ? ev.keyCode : ev.which; // PPK var kc = (ev.keyCode) ? ev.keyCode : ev.which; // PPK
return (new RegExp(pattern, flags)).test(String.fromCharCode(kc)); return (new RegExp(pattern, flags)).test(String.fromCharCode(kc));
// PPK= Peter-Paul Koch, www.quirksmode.org // PPK= Peter-Paul Koch, www.quirksmode.org
} }
function checkValid(inputField, pattern, flags) function checkValid(inputField, pattern, flags)
{ {
// e.g. onKeyUp="checkValid(this, '^[a-z]{2,8}$', 'i');" // e.g. onKeyUp="checkValid(this, '^[a-z]{2,8}$', 'i');"
var fieldColor = (new RegExp(pattern, flags)).test(inputField.value) ? '#000000' : '#D8366C'; var fieldColor = (new RegExp(pattern, flags)).test(inputField.value) ? '#000000' : '#D8366C';
var fieldStyle = (document.getElementById || document.all) ? var fieldStyle = (document.getElementById || document.all) ?
inputField.style : inputField; inputField.style : inputField;
if (fieldStyle) fieldStyle.color = fieldColor; if (fieldStyle) fieldStyle.color = fieldColor;
// OK for all browsers (see devedge.netscape.com // OK for all browsers (see devedge.netscape.com
// /library/xref/2003/css-support/css1/mastergrid.html): // /library/xref/2003/css-support/css1/mastergrid.html):
// color, background-color (not on NN4), display block/none (NN4?), // color, background-color (not on NN4), display block/none (NN4?),
// overflow hidden/scroll/auto (not on NN4), // overflow hidden/scroll/auto (not on NN4),
// position relative/static, // position relative/static,
// text-align left/right/center, text-indent, // text-align left/right/center, text-indent,
// font-style normal/italic, font-weight normal/bold, // font-style normal/italic, font-weight normal/bold,
// font-family serif/sans-serif/monospace, // font-family serif/sans-serif/monospace,
// border-style none/solid/double/groove/ridge/inset/outset. // border-style none/solid/double/groove/ridge/inset/outset.
} }
function getObj(name) // PPK function getObj(name) // PPK
{ {
return (document.getElementById) ? document.getElementById(name) return (document.getElementById) ? document.getElementById(name)
@ -428,147 +428,148 @@
: (document.layers) ? document.layers[name] // NS4 : (document.layers) ? document.layers[name] // NS4
: null; // With NS4, nested layers are not supported! : null; // With NS4, nested layers are not supported!
} }
function spc(path, value) // set pending change in form field mda function spc(path, value) // set pending change in form field mda
{ {
var mda = getObj("mda"); var mda = getObj("mda");
if (mda) mda.value += "\n" + path + '=' + value; if (mda) mda.value += "\n" + path + '=' + value;
} }
function spcSel(path, selbox) // set pending change, language selection function spcSel(path, selbox) // set pending change, language selection
{ {
var mda = getObj("mda"); var mda = getObj("mda");
if (mda) mda.value += "\n" + path + '=' + if (mda) mda.value += "\n" + path + '=' +
selbox.options[selbox.selectedIndex].value; selbox.options[selbox.selectedIndex].value;
} }
function checkBeforeSubmit(ev) function checkBeforeSubmit(ev)
{ {
if (!ev) var ev = window.event; if (!ev) var ev = window.event;
if (ev.ctrlKey && ev.altKey) if (ev.ctrlKey && ev.altKey)
{ {
var mdt = getObj("mdt"); if (!mdt) return false; var mdt = getObj("mdt"); if (!mdt) return false;
makeWindow('', '<pre>' + makeWindow('', '<pre>' +
('<?xml version="1.0" encoding="UTF-16"?>' + ('<?xml version="1.0" encoding="UTF-16"?>' +
' <!-- From browser, save as Text/Unicode -->\n\n' + ' <!-- From browser, save as Text/Unicode -->\n\n' +
mdt.value) mdt.value)
.replace(/&/g, '&amp;').replace(/"/g, '&quot;') .replace(/&/g, '&amp;').replace(/"/g, '&quot;')
.replace(/</g, '&lt;').replace(/>/g, '&gt;') + .replace(/</g, '&lt;').replace(/>/g, '&gt;') +
'</pre>'); '</pre>');
return false; return false;
} }
var kwdsnow = getObj("kwds_string"); if (!kwdsnow) return true; var kwdsnow = getObj("kwds_string"); if (!kwdsnow) return true;
if (kwdsnow.value == kwdswere) return true; // unchanged if (kwdsnow.value == kwdswere) return true; // unchanged
// note: calling HTML should define var kwdswere! // note: calling HTML should define var kwdswere!
var language = kwdsnow.title; var language = kwdsnow.title;
var mda = getObj("mda"); var mda = getObj("mda");
if (!mda) { alert('? Form does not contain mda'); return false; } if (!mda) { alert('? Form does not contain mda'); return false; }
var kwdsarray = kwdswere.split(','); var kwdsarray = kwdswere.split(',');
for (var k = 0; k < kwdsarray.length; k++) // delete old for (var k = 0; k < kwdsarray.length; k++) // delete old
if (kwdsarray[k].trim() != '') if (kwdsarray[k].trim() != '')
mda.value += "\nmetadata/lom/general/keyword[-1]~"; mda.value += "\nmetadata/lom/general/keyword[-1]~";
kwdsarray = kwdsnow.value kwdsarray = kwdsnow.value
.replace(/[!-,:-@\[-\^{-~\s]+/g, ',').split(','); .replace(/[!-,:-@\[-\^{-~\s]+/g, ',').split(',');
for (k = 0; k < kwdsarray.length; k++) for (k = 0; k < kwdsarray.length; k++)
{ {
var newkw = kwdsarray[k].trim(); var newkw = kwdsarray[k].trim();
if (newkw != '') mda.value += if (newkw != '') mda.value +=
"\nmetadata/lom/general!keyword" + "\nmetadata/lom/general!keyword" +
"\nmetadata/lom/general/keyword[-1]!string=" + newkw + "\nmetadata/lom/general/keyword[-1]!string=" + newkw +
"\nmetadata/lom/general/keyword[-1]/string/@language=" + language; "\nmetadata/lom/general/keyword[-1]/string/@language=" + language;
} }
return true; return true;
} }
function setPendingOperation(op, ev) function setPendingOperation(op, ev)
{ {
if (!ev) var ev = window.event; if (!ev) var ev = window.event;
var mda = getObj("mda"); var mda = getObj("mda");
if (!mda) { alert('? Form does not contain mda'); return false; } if (!mda) { alert('? Form does not contain mda'); return false; }
if (op == '!!' || (op == '~~' && confirm(mda.title))) if (op == '!!' || (op == '~~' && confirm(mda.title)))
{ {
mda.value = op; return true; mda.value = op; return true;
} }
return false; return false;
} }
function prepSearch(ev) function prepSearch(ev)
{ {
if (!ev) var ev = window.event; if (!ev) var ev = window.event;
var mdsc = getObj("mdsc"); var mdsc = getObj("mdsc");
if (!mdsc) { alert('? Form does not contain mdsc'); return false; } if (!mdsc) { alert('? Form does not contain mdsc'); return false; }
var kwdsnow = getObj("kwds_string"); if (!kwdsnow) return true; var kwdsnow = getObj("kwds_string"); if (!kwdsnow) return true;
if (kwdsnow.value == '') return true; if (kwdsnow.value == '') return true;
if (!KWDS_ARRAY.length) if (!KWDS_ARRAY.length)
{ {
makeAlphaList(getObj('maindiv')); makeAlphaList(getObj('maindiv'));
KWDS_ARRAY.sort(); KWDS_ARRAY.sort();
} }
var restricttokwds = false, checkbox = getObj("restricttokwds"); var restricttokwds = false, checkbox = getObj("restricttokwds");
if (checkbox) restricttokwds = checkbox.checked; if (checkbox) restricttokwds = checkbox.checked;
var kwdsarray = kwdsnow.value var kwdsarray = kwdsnow.value
.replace(/[!-,:-@\[-\^{-~\s]+/g, ',').split(','); .replace(/[!-,:-@\[-\^{-~\s]+/g, ',').split(',');
for (var k = 0; k < kwdsarray.length; k++) for (var k = 0; k < kwdsarray.length; k++)
{ {
var newkw = kwdsarray[k].trim().toLowerCase(); var newkw = kwdsarray[k].trim().toLowerCase();
if (newkw != '') if (newkw != '')
{ {
var realkw = false; var realkw = false;
if (restricttokwds) if (restricttokwds)
for (pos = 0; pos < KWDS_ARRAY.length; pos++) for (pos = 0; pos < KWDS_ARRAY.length; pos++)
if (KWDS_ARRAY[pos].toLowerCase() == newkw) if (KWDS_ARRAY[pos].toLowerCase() == newkw)
{ realkw = true; break; } { realkw = true; break; }
mdsc.value += "\n" + newkw + (realkw ? '-kw' : ''); mdsc.value += "\n" + newkw + (realkw ? '-kw' : '');
} }
} }
return true; return true;
} }
var CRLF = "\n"; // generates clickable tree and populates KWDS_ARRAY var CRLF = "\n"; // generates clickable tree and populates KWDS_ARRAY
function traverseKwObj(node, parlev, num) // see KWTREE_OBJECT in md_funcs function traverseKwObj(node, parlev, num) // see KWTREE_OBJECT in md_funcs
{ {
var curlev = parlev + ('00' + (num+1)).substr(-3), kwn = '', html = ''; var curlev = '00' + (num+1), kwn = '', html = '';
curlev = parlev + curlev.substr(curlev.length-3);
for (i in (names = node.n.split("_")))
for (i in (names = node.n.split("_")))
if (nn = names[i]) { KWDS_ARRAY.push(nn); kwn += ', ' + nn; } if (nn = names[i]) { KWDS_ARRAY.push(nn); kwn += ', ' + nn; }
for (j in node.c) html += traverseKwObj(node.c[j], curlev, Math.abs(j)); for (j in node.c) html += traverseKwObj(node.c[j], curlev, Math.abs(j));
return (parlev == '') ? html : return (parlev == '') ? html :
'<div noWrap="1" class="dvc" level="' + curlev + '">' + CRLF + '<div noWrap="1" class="dvc" level="' + curlev + '">' + CRLF +
'<input type="button" class="' + '<input type="button" class="' +
(html ? 'btn" value="+" onClick="openOrClose(this);"/>' : (html ? 'btn" value="+" onClick="openOrClose(this);"/>' :
'lfn" value=" "/>') + '&#xa0;' + CRLF + 'lfn" value=" "/>') + '&#xa0;' + CRLF +
'<span class="lbl" onClick="spanClick(this, event);"' + '<span class="lbl" onClick="spanClick(this, event);"' +
(node.pt ? ' title="' + node.pt + '">' : '>') + (node.pt ? ' title="' + node.pt + '">' : '>') +
kwn.substr(2) + '</span>' + CRLF + kwn.substr(2) + '</span>' + CRLF +
(node.cm ? '<i>' + node.cm + '</i>' : '') + (node.cm ? '<i>' + node.cm + '</i>' : '') +
html + html +
'</div>' + CRLF; '</div>' + CRLF;
} }

Loading…
Cancel
Save