Skip to content
Snippets Groups Projects
Commit a6d0623c authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Fixed OpenURL click handling when loading Combined results with ajax.

parent 35c4bbb1
No related merge requests found
...@@ -111,9 +111,6 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper ...@@ -111,9 +111,6 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper
*/ */
public function renderTemplate() public function renderTemplate()
{ {
// Static counter to ensure that each OpenURL gets a unique ID.
static $counter = 0;
if (null !== $this->config && isset($this->config->url)) { if (null !== $this->config && isset($this->config->url)) {
// Trim off any parameters (for legacy compatibility -- default config // Trim off any parameters (for legacy compatibility -- default config
// used to include extraneous parameters): // used to include extraneous parameters):
...@@ -123,9 +120,6 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper ...@@ -123,9 +120,6 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper
} }
$embed = (isset($this->config->embed) && !empty($this->config->embed)); $embed = (isset($this->config->embed) && !empty($this->config->embed));
if ($embed) {
$counter++;
}
$embedAutoLoad = isset($this->config->embed_auto_load) $embedAutoLoad = isset($this->config->embed_auto_load)
? $this->config->embed_auto_load : false; ? $this->config->embed_auto_load : false;
...@@ -161,8 +155,7 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper ...@@ -161,8 +155,7 @@ class OpenUrl extends \Zend\View\Helper\AbstractHelper
'openUrlGraphicHeight' => empty($this->config->graphic_height) 'openUrlGraphicHeight' => empty($this->config->graphic_height)
? false : $this->config->graphic_height, ? false : $this->config->graphic_height,
'openUrlEmbed' => $embed, 'openUrlEmbed' => $embed,
'openUrlEmbedAutoLoad' => $embedAutoLoad, 'openUrlEmbedAutoLoad' => $embedAutoLoad
'openUrlId' => $counter
]; ];
// Render the subtemplate: // Render the subtemplate:
......
...@@ -18,6 +18,12 @@ function loadResolverLinks($target, openUrl) { ...@@ -18,6 +18,12 @@ function loadResolverLinks($target, openUrl) {
}); });
} }
function embedOpenUrlLinks(element) {
var openUrl = element.children('span.openUrl:first').attr('title');
element.removeClass('openUrlEmbed').hide();
loadResolverLinks(element.next('div.resolver').removeClass('hidden'), openUrl);
}
$(document).ready(function() { $(document).ready(function() {
// assign action to the openUrlWindow link class // assign action to the openUrlWindow link class
$('a.openUrlWindow').click(function(){ $('a.openUrlWindow').click(function(){
...@@ -28,13 +34,10 @@ $(document).ready(function() { ...@@ -28,13 +34,10 @@ $(document).ready(function() {
}); });
// assign action to the openUrlEmbed link class // assign action to the openUrlEmbed link class
$('a.openUrlEmbed').click(function(){ $('a.openUrlEmbed').click(function() {
var params = extractClassParams(this); embedOpenUrlLinks($(this));
var openUrl = $(this).children('span.openUrl:first').attr('title');
$(this).hide();
loadResolverLinks($('#openUrlEmbed'+params.openurl_id).removeClass('hidden'), openUrl);
return false; return false;
}); });
$('a.openUrlEmbed.openUrlEmbedAutoLoad').trigger("click"); $('a.openUrlEmbed.openUrlEmbedAutoLoad').trigger("click");
}); });
\ No newline at end of file
<? <?
$this->headScript()->appendFile("openurl.js"); $this->headScript()->appendFile("openurl.js");
if ($this->openUrlEmbed) { if ($this->openUrlEmbed) {
$classes = "fulltext openUrlEmbed openurl_id:{$this->openUrlId}" $classes = "fulltext openUrlEmbed"
. ($this->openUrlEmbedAutoLoad ? ' openUrlEmbedAutoLoad' : ''); . ($this->openUrlEmbedAutoLoad ? ' openUrlEmbedAutoLoad' : '');
$class = ' class="' . $classes . '"'; $class = ' class="' . $classes . '"';
} elseif ($this->openUrlWindow) { } elseif ($this->openUrlWindow) {
...@@ -29,5 +29,5 @@ ...@@ -29,5 +29,5 @@
<? endif; ?> <? endif; ?>
</a> </a>
<? if ($this->openUrlEmbed): ?> <? if ($this->openUrlEmbed): ?>
<div id="openUrlEmbed<?=$this->openUrlId?>" class="resolver hidden"><?=$this->transEsc('Loading')?>...</div> <div class="resolver hidden"><?=$this->transEsc('Loading')?>...</div>
<? endif; ?> <? endif; ?>
<? <?
// Make sure OpenURL support is loaded
$this->headScript()->appendFile("openurl.js");
$view = $currentSearch['view']; $view = $currentSearch['view'];
$results = $view->results; $results = $view->results;
$params = $results->getParams(); $params = $results->getParams();
$lookfor = $params->getDisplayQuery(); $lookfor = $params->getDisplayQuery();
// Set up Javascript for use below: // Set up Javascript for use below:
$loadJs = 'var url = path + "/Combined/Result?id=' . urlencode($searchClassId) $searchClassIdEncoded = urlencode($searchClassId);
. '&lookfor=' . urlencode($lookfor) . '";' $searchClassIdHtmlEscaped = $this->escapeHtml($searchClassId);
. "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, '', function(responseText) { if (responseText.length == 0) $('#combined_" . $this->escapeHtml($searchClassId) . "').hide(); });"; $lookforEncoded = urlencode($lookfor);
$loadJs = <<<JS
$(document).ready(function(){
var url = path + '/Combined/Result?id=$searchClassIdEncoded&lookfor=$lookforEncoded';
$('#combined_$searchClassIdHtmlEscaped').load(url, '', function(responseText) {
if (responseText.length == 0) {
$('#combined_$searchClassIdHtmlEscaped').hide();
}
$('a.openUrlEmbed').click(function() {
embedOpenUrlLinks($(this));
return false;
});
});
});
JS;
?> ?>
<h2><?=$this->transEsc($currentSearch['label'])?></h2> <h2><?=$this->transEsc($currentSearch['label'])?></h2>
<p><i class="fa fa-spinner fa-spin"></i> <?=$this->transEsc("Loading")?>...</p> <p><i class="fa fa-spinner fa-spin"></i> <?=$this->transEsc("Loading")?>...</p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, '$(document).ready(function(){' . $loadJs . '});', 'SET')?> <?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
<noscript><?=$this->transEsc('Please enable JavaScript.')?></noscript> <noscript><?=$this->transEsc('Please enable JavaScript.')?></noscript>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment