autodist/webbuild/html/scripts/webbuild.js

105 lines
3.7 KiB
JavaScript
Raw Normal View History

function getCheckedValuesByName(checkboxname) {
var e=document.getElementsByName(checkboxname);
var p="";
for (var j=0;j<e.length;j++) {
if (e[j].checked) p+=e[j].value+" ";
};
return p;
}
function checkAllBoxes(checkboxname,checked) {
var e=document.getElementsByName(checkboxname);
for (var j=0;j<e.length;j++) {
e[j].checked=checked;
};
}
function getSelectedValueById(selectname,idx) {
if (idx == undefined) idx = 0;
var i=document.getElementById(selectname).selectedIndex;
return document.getElementById(selectname).options[i+idx].value;
}
function checkEnter(event) {
event=event || window.event;
getEvent=event.keyCode;
if (getEvent == "13") {
return true;
}
return false;
}
function suggestSpecName(url) {
var version="";
var url=document.getElementById("speccreateurl").value;
if (url.indexOf('&') > 0) url=url.substring(0,url.indexOf('&')+1);
var specname=url.substring(url.lastIndexOf('/')+1);
while (i=specname.lastIndexOf('.')) {
e=specname.substring(i);
if (e != ".tar" && e != ".gz" && e != ".zip" && e != ".bz2" &&
e != ".xz" && e != ".tgz" && e != ".zip" && e != ".src" &&
e != ".orig") break;
specname=specname.substring(0,i);
}
if (specname.lastIndexOf('-') > 0) {
version=specname.substring(specname.lastIndexOf('-')+1);
specname=specname.substring(0,specname.lastIndexOf('-'));
}
document.getElementById("speccreateurl").value=url;
if (url.search("cpan.org") >= 0) {
specname="perl-"+specname;
} else {
specname=specname.toLowerCase();
}
if (url.search("git://") >= 0) {
document.getElementById("speccreategitbranch").disabled=false;
} else {
document.getElementById("speccreategitbranch").disabled=true;
}
document.getElementById("speccreatename").value=specname;
document.getElementById("speccreateversion").value=version;
if (url) {
document.getElementById("speccreatename").disabled=false;
document.getElementById("speccreateversion").disabled=false;
document.getElementById("speccreatetype").disabled=false;
document.getElementById("speccreatebutton").disabled=false;
} else {
document.getElementById("speccreatename").disabled=true;
document.getElementById("speccreateversion").disabled=true;
document.getElementById("speccreatetype").disabled=true;
document.getElementById("speccreatebutton").disabled=true;
}
if (specname.search("perl-") >= 0) {
for (var j=0;j<document.getElementById("speccreatetype").length;j++) {
if (document.getElementById("speccreatetype").options[j].value == "perl")
document.getElementById("speccreatetype").options[j].selected=true;
};
} else if (specname.search("python-") >= 0) {
for (var j=0;j<document.getElementById("speccreatetype").length;j++) {
if (document.getElementById("speccreatetype").options[j].value == "python")
document.getElementById("speccreatetype").options[j].selected=true;
};
} else {
for (var j=0;j<document.getElementById("speccreatetype").length;j++) {
if (document.getElementById("speccreatetype").options[j].value == "library")
document.getElementById("speccreatetype").options[j].selected=true;
};
}
}
function replaceHTML(el, html) {
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
/*@cc_on // Pure innerHTML is slightly faster in IE
oldEl.innerHTML = html;
return oldEl;
@*/
var newEl = oldEl.cloneNode(false);
newEl.innerHTML = html;
oldEl.parentNode.replaceChild(newEl, oldEl);
/* Since we just removed the old element from the DOM, return a reference
to the new element, which can be used to restore variable references. */
return newEl;
};