Created
January 17, 2018 06:07
-
-
Save sijpkes/a2f9621e007c7591e512d0b6c55215f8 to your computer and use it in GitHub Desktop.
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() { | |
var params; | |
function eventFire(el, etype){ | |
if (el.fireEvent) { | |
el.fireEvent('on' + etype); | |
} else { | |
var evObj = document.createEvent('Events'); | |
evObj.initEvent(etype, true, false); | |
el.dispatchEvent(evObj); | |
} | |
} | |
function init() { | |
var url = 'https://my.url.to.my.params/params.php'; | |
new Ajax.Request(url, { | |
onSuccess: function(res) { | |
params = res.responseJSON; | |
main(); | |
} | |
}); | |
} | |
function main() { | |
var bc_el = null, to = null; | |
bc_el = document.getElementById("bcMenu_actionButton"); | |
if(bc_el) | |
eventFire(bc_el, "mouseover"); | |
bc_el = document.getElementById("content-handler-resource/x-bb-externallink"); | |
if(bc_el) | |
bc_el.click(); | |
bc_el = document.getElementById("user_title"); | |
if(bc_el) | |
bc_el.setAttribute("value", params.general.name); | |
var lti_el = document.getElementById("bltiToolProvider"); | |
if(lti_el) { | |
var url_el = document.getElementById("url"); | |
var p = document.getElementById("apeg_select"); | |
if(!p) { | |
p = document.createElement("p"); | |
p.id = "apeg_select"; | |
} | |
var button = document.getElementById("apeg_button"); | |
if(!button) { | |
button = document.createElement("button"); | |
button.id = "apeg_button"; | |
button.setAttribute("style", "margin-left: 0.3em; width: 80px; height: 35px"); | |
button.textContent = "Change Setup"; | |
} | |
var select = document.createElement("select"); | |
var option = []; | |
params.options.forEach(function(v, i) { | |
option[i] = document.createElement("option"); | |
option[i].textContent = v.title; | |
option[i].data = v; | |
}); | |
option[0].defaultSelected = true; | |
option.forEach(function(v,i) { | |
select.appendChild(v); | |
}); | |
p.textContent = "APEG Setup Type: "; | |
p.appendChild(select); | |
p.appendChild(button); | |
document.getElementById("pageTitleDiv").appendChild(p); | |
var fillFields = function() { | |
var o = select.options[select.selectedIndex]; | |
url_el.setAttribute("value", o.data.url); | |
if(!lti_el.checked) | |
lti_el.click(); | |
// wait until server has returned LTI status | |
var _to = null; | |
var wait = function() { | |
if(_to !== null) return false; | |
_to = setTimeout(function() { | |
$$("#bltiKey")[0].value = o.data.key; | |
$$("#bltiSecret")[0].value = o.data.secret; | |
$$("#bltiCustomParameters")[0].value = params.general.custom_params; | |
clearTimeout(_to); | |
_to = null; | |
if($$("#bltiKey")[0].value.length == 0) { | |
wait(); | |
} | |
}, 100); | |
}; | |
wait(); | |
}; | |
button.addEventListener("click", function(e) { | |
var ok = confirm("This will add the "+select.options[select.selectedIndex].textContent+" template."); | |
if(ok) { | |
fillFields(); | |
} | |
}); | |
fillFields(); | |
} | |
} | |
init(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment