Skip to content
Snippets Groups Projects
Commit 8c8db5d4 authored by Guy Halse's avatar Guy Halse
Browse files

Remove the inline javascript from discopower

parent 7549a37a
No related branches found
No related tags found
No related merge requests found
......@@ -268,6 +268,7 @@ class PowerIdPDisco extends \SimpleSAML\XHTML\IdPDisco
$t->data['returnIDParam'] = $this->returnIdParam;
$t->data['entityID'] = $this->spEntityId;
$t->data['defaulttab'] = $this->discoconfig->getValue('defaulttab', 0);
$t->data['pageid'] = 'discopower';
$idpList = $this->processMetadata($t, $idpList, $preferredIdP);
......@@ -283,17 +284,12 @@ class PowerIdPDisco extends \SimpleSAML\XHTML\IdPDisco
$t->data['autofocus'] = 'favouritesubmit';
}
$search = '<script type="text/javascript">
$(document).ready(function() {
$("#tabdiv").tabs({ selected: '.$t->data['defaulttab'].' });';
$i = 0;
foreach ($idpList as $tab => $slist) {
$search .= "\n".'$("#query_'.$tab.'").liveUpdate("#list_'.$tab.'")'.
(($i++ == 0) && (empty($this->data['faventry'])) ? '.focus()' : '').';';
}
$search .= "});\n</script>";
/* store the tab list in the session */
$session = \SimpleSAML\Session::getSessionFromRequest();
$session->setData('discopower:tabList', 'faventry', $this->data['faventry']);
$session->setData('discopower:tabList', 'tabs', array_keys($idpList));
$session->setData('discopower:tabList', 'defaulttab', $t->data['defaulttab']);
$t->data['search'] = $search;
$t->data['score'] = $this->discoconfig->getValue('score', 'quicksilver');
$t->data['tabNames'] = $discoPowerTabs;
$t->data['preferredidp'] = $preferredIdP;
......
......@@ -10,7 +10,8 @@ $this->data['head'] .= '<script type="text/javascript" src="'.
SimpleSAML\Module::getModuleURL('discopower/assets/js/jquery.livesearch.js').'"></script>'."\n";
$this->data['head'] .= '<script type="text/javascript" src="'.
SimpleSAML\Module::getModuleURL('discopower/assets/js/'.$this->data['score'].'.js').'"></script>'."\n";
$this->data['head'] .= $this->data['search'];
$this->data['head'] .= '<script type="text/javascript" src="'.
SimpleSAML\Module::getModuleURL('discopower/assets/js/tablist.js').'"></script>'."\n";
if (!empty($this->data['faventry'])) {
$this->data['autofocus'] = 'favouritesubmit';
......
......@@ -9,7 +9,7 @@
<script src="/{{ baseurlpath }}resources/jquery-ui-1.8.js"></script>
<script src="/{{ baseurlpath }}module.php/discopower/js/jquery.livesearch.js"></script>
<script src="/{{ baseurlpath }}module.php/discopower/js/{{ score }}.js"></script>
{{ search|raw }}
<script src="/{{ baseurlpath }}module.php/discopower/js/tablist.js"></script>
{% endblock %}
{% block content %}
......
$(document).ready(function() {
$("#tabdiv").tabs();
$.getJSON("tablist.php", function(data) {
$("#tabdiv").select(data["default"]);
for (var i = 0; i < data["tabs"].length; i++) {
var tab = data["tabs"][i];
$("#query_"+tab).liveUpdate("#list_"+tab);
if (data["faventry"] == null && i == 0) {
$("#query_"+tab).focus();
}
}
});
});
<?php
/**
* An AJAX handler to retrieve a list of disco tabs from the session.
* This allows us to dynamically update the tab list without inline javascript.
*
* @author Guy Halse, http://orcid.org/0000-0002-9388-8592
* @package SimpleSAMLphp
*/
$session = \SimpleSAML\Session::getSessionFromRequest();
$tabs = $session->getData('discopower:tabList', 'tabs');
$faventry = $session->getData('discopower:tabList', 'faventry');
$defaulttab = $session->getData('discopower:tabList', 'defaulttab');
if (!is_array($tabs)) {
throw new \SimpleSAML\Error\Exception('Could not get tab list from session');
}
// handle JSON vs JSONP requests
if (isset($_REQUEST['callback'])) {
if (!preg_match('/^[a-z0-9_]+$/i', $_REQUEST['callback'])) {
throw new \SimpleSAML\Error\Exception('Unsafe JSONP callback function name "'.$_REQUEST['callback'].'"');
}
$jsonp = true;
header('Content-Type: application/javascript');
print addslashes($_REQUEST['callback']) . '(';
} else {
$jsonp = false;
header('Content-Type: application/json');
}
print json_encode(
[
'faventry' => $faventry,
'default' => $defaulttab,
'tabs' => $tabs,
]
);
if ($jsonp) {
print ');';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment