diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php index c5ce0a954a091ce38e9a1dbc7b75509fc96b35f0..a25f3df14af75698fa7aa49dbd140221a764f51e 100644 --- a/modules/discopower/lib/PowerIdPDisco.php +++ b/modules/discopower/lib/PowerIdPDisco.php @@ -283,17 +283,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; diff --git a/modules/discopower/templates/disco.tpl.php b/modules/discopower/templates/disco.tpl.php index 3472a6e30387e0e8539e2db65f1bb906a736bb1d..581b819276e11646c7260142c3e4c0cdc97416e3 100644 --- a/modules/discopower/templates/disco.tpl.php +++ b/modules/discopower/templates/disco.tpl.php @@ -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'; diff --git a/modules/discopower/templates/disco.twig b/modules/discopower/templates/disco.twig index bd72483935347cd5dff98220a5f1c082fb9c5108..27febae5b5d64e62d5c15253cde854d10478bde4 100644 --- a/modules/discopower/templates/disco.twig +++ b/modules/discopower/templates/disco.twig @@ -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 %} diff --git a/modules/discopower/www/assets/js/tablist.js b/modules/discopower/www/assets/js/tablist.js new file mode 100644 index 0000000000000000000000000000000000000000..789fb5b28f173480a287bc31bd8c62bed3da463b --- /dev/null +++ b/modules/discopower/www/assets/js/tablist.js @@ -0,0 +1,13 @@ +$(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(); + } + } + }); +}); diff --git a/modules/discopower/www/tablist.php b/modules/discopower/www/tablist.php new file mode 100644 index 0000000000000000000000000000000000000000..9f58fe513bb9d3e9642ab7f347ff7d7dc5927796 --- /dev/null +++ b/modules/discopower/www/tablist.php @@ -0,0 +1,41 @@ +<?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 ');'; +}