Created
December 8, 2011 13:08
-
-
Save rlemon/1446948 to your computer and use it in GitHub Desktop.
nitstorm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function codeRunner(){ | |
var cb = document.getElementById("checkbox"), ppab = document.getElementById("ppa-box"); // checkbox is used twice, no need to select it twice. Same for ppa-box (referenced three times, called twice) | |
// Unlock PPA when Checkbox is ticked | |
cb.onclick = function(){ | |
if(cb.checked){ | |
ppab.disabled=false; | |
} | |
else | |
{ | |
ppab.disabled=true; | |
ppab.value=""; | |
} | |
} | |
//Form submission | |
document.getElementById("main-form").onsubmit = function(){ | |
// Get Value from Form | |
var packageValue = document.getElementById("package-box").value; | |
var ppaValue = ppab.value; | |
// Code Mangling to achieve Markdown | |
var imageCode = "<b> [" + packageValue + " ![software_center_icon](http://i.imgur.com/puwkM.png)](http://apt.ubuntu.com/p/" + packageValue + ") </b><br /><br />"; | |
var mandatoryLine = "<i>Run the following to install the package via a terminal (Default keyboard shortcut: <kbd>Ctrl</kbd><kbd>Alt</kbd><kbd>T</kbd>) </i><br />"; | |
var packageInstruc = "sudo apt-get update && sudo apt-get install " + packageValue; | |
var ppaInstruc = "sudo add-apt-repository " + ppaValue | |
// Final Usage Variables | |
var packageOnly = imageCode + mandatoryLine + "<pre>" + packageInstruc + "</pre>"; | |
var ppaPackage = mandatoryLine + "<pre>" + ppaInstruc + "<br />" + packageInstruc + "</pre>"; | |
// Code output into text area | |
var code = document.getElementById("code"); // this doesn't really need to be done, but save yourself a few bytes. | |
if(ppaValue == ""){ | |
code.appendChild(document.createTextNode(packageOnly)); | |
} | |
else{ | |
code.appendChild(document.createTextNode(ppaPackage)); | |
} | |
return false; | |
} | |
} | |
window.onload = function(){ | |
codeRunner(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment