Skip to content
Snippets Groups Projects
Unverified Commit b9205d7c authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #1079 from ghalse/enhancement/discopower-inline-js

Remove the inline javascript from discopower-module
parents 379571f1 96104ef1
No related branches found
No related tags found
No related merge requests found
...@@ -283,17 +283,12 @@ class PowerIdPDisco extends \SimpleSAML\XHTML\IdPDisco ...@@ -283,17 +283,12 @@ class PowerIdPDisco extends \SimpleSAML\XHTML\IdPDisco
$t->data['autofocus'] = 'favouritesubmit'; $t->data['autofocus'] = 'favouritesubmit';
} }
$search = '<script type="text/javascript"> /* store the tab list in the session */
$(document).ready(function() { $session = \SimpleSAML\Session::getSessionFromRequest();
$("#tabdiv").tabs({ selected: '.$t->data['defaulttab'].' });'; $session->setData('discopower:tabList', 'faventry', $this->data['faventry']);
$i = 0; $session->setData('discopower:tabList', 'tabs', array_keys($idpList));
foreach ($idpList as $tab => $slist) { $session->setData('discopower:tabList', 'defaulttab', $t->data['defaulttab']);
$search .= "\n".'$("#query_'.$tab.'").liveUpdate("#list_'.$tab.'")'.
(($i++ == 0) && (empty($this->data['faventry'])) ? '.focus()' : '').';';
}
$search .= "});\n</script>";
$t->data['search'] = $search;
$t->data['score'] = $this->discoconfig->getValue('score', 'quicksilver'); $t->data['score'] = $this->discoconfig->getValue('score', 'quicksilver');
$t->data['tabNames'] = $discoPowerTabs; $t->data['tabNames'] = $discoPowerTabs;
$t->data['preferredidp'] = $preferredIdP; $t->data['preferredidp'] = $preferredIdP;
......
...@@ -10,7 +10,8 @@ $this->data['head'] .= '<script type="text/javascript" src="'. ...@@ -10,7 +10,8 @@ $this->data['head'] .= '<script type="text/javascript" src="'.
SimpleSAML\Module::getModuleURL('discopower/assets/js/jquery.livesearch.js').'"></script>'."\n"; SimpleSAML\Module::getModuleURL('discopower/assets/js/jquery.livesearch.js').'"></script>'."\n";
$this->data['head'] .= '<script type="text/javascript" src="'. $this->data['head'] .= '<script type="text/javascript" src="'.
SimpleSAML\Module::getModuleURL('discopower/assets/js/'.$this->data['score'].'.js').'"></script>'."\n"; 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'])) { if (!empty($this->data['faventry'])) {
$this->data['autofocus'] = 'favouritesubmit'; $this->data['autofocus'] = 'favouritesubmit';
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<script src="/{{ baseurlpath }}resources/jquery-ui-1.8.js"></script> <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/jquery.livesearch.js"></script>
<script src="/{{ baseurlpath }}module.php/discopower/js/{{ score }}.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 %} {% endblock %}
{% block content %} {% 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');
echo addslashes($_REQUEST['callback']) . '(';
} else {
$jsonp = false;
header('Content-Type: application/json');
}
echo json_encode(
[
'faventry' => $faventry,
'default' => $defaulttab,
'tabs' => $tabs,
]
);
if ($jsonp) {
echo ');';
}
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