diff --git a/include/staff/header.inc.php b/include/staff/header.inc.php index 648bc13e215a1b1ece7783f6ad84e3799b7e70ea..4bbd8fa2c2981f1623ce649c74f157dedb028833 100644 --- a/include/staff/header.inc.php +++ b/include/staff/header.inc.php @@ -65,11 +65,17 @@ </p> </div> <div id="pjax-container"> -<?php } elseif ($pjax = $ost->getExtraPjax()) { # endif X_PJAX ?> +<?php } else { + if ($pjax = $ost->getExtraPjax()) { ?> <script type="text/javascript"> <?php foreach (array_filter($pjax) as $s) echo $s.";"; ?> </script> -<?php } # endif X_PJAX ?> + <?php } + foreach ($ost->getExtraHeaders() as $h) { + if (strpos($h, '<script ') !== false) + echo $h; + } +} # endif X_PJAX ?> <ul id="nav"> <?php include STAFFINC_DIR . "templates/navigation.tmpl.php"; ?> </ul> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index fe40708bfc9f0a45870ac2624cd25478160e6818..c183c7b4e11c9c3d847a2e316e6424806c540ebd 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -389,9 +389,10 @@ $tcount+= $ticket->getNumNotes(); } if ($urls) { ?> <script type="text/javascript"> - $(function() { showImagesInline(<?php echo - JsonDataEncoder::encode($urls); ?>, <?php echo - $entry['id']; ?>); }); + $('#thread-id-<?php echo $entry['id']; ?>') + .data('urls', <?php + echo JsonDataEncoder::encode($urls); ?>) + .data('id', <?php echo $entry['id']; ?>); </script> <?php } ?> diff --git a/scp/js/ticket.js b/scp/js/ticket.js index b590e5c017adfffcdcd8360b55ce58c8c1aacbb1..7e697f24a9964c2c09e8361b626cd0b728fec739 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -264,6 +264,52 @@ $.autoLock = autoLock; /* UI & form events */ +$.showNonLocalImage = function(div) { + var $div = $(div), + $img = $div.append($('<img>') + .attr('src', $div.data('src')) + .attr('alt', $div.attr('alt')) + .attr('title', $div.attr('title')) + .attr('style', $div.data('style')) + ); + if ($div.attr('width')) + $img.width($div.attr('width')); + if ($div.attr('height')) + $img.height($div.attr('height')); +}; + +$.showImagesInline = function(urls, thread_id) { + var selector = (thread_id == undefined) + ? '.thread-body img[data-cid]' + : '.thread-body#thread-id-'+thread_id+' img[data-cid]'; + $(selector).each(function(i, el) { + var e = $(el), + cid = e.data('cid').toLowerCase(), + info = urls[cid]; + if (info && !e.data('wrapped')) { + // Add a hover effect with the filename + var timeout, caption = $('<div class="image-hover">') + .css({'float':e.css('float')}); + e.wrap(caption).parent() + .hover( + function() { + var self = this; + timeout = setTimeout( + function() { $(self).find('.caption').slideDown(250); }, + 500); + }, + function() { + clearTimeout(timeout); + $(this).find('.caption').slideUp(250); + } + ).append($('<div class="caption">') + .append('<span class="filename">'+info.filename+'</span>') + .append('<a href="'+info.download_url+'" class="action-button no-pjax"><i class="icon-download-alt"></i> Download</a>') + ); + e.data('wrapped', true); + } + }); +}; var ticket_onload = function($) { $('#response_options form').hide(); @@ -352,20 +398,6 @@ var ticket_onload = function($) { $cc.show(); }); - var showNonLocalImage = function(div) { - var $div = $(div), - $img = $div.append($('<img>') - .attr('src', $div.data('src')) - .attr('alt', $div.attr('alt')) - .attr('title', $div.attr('title')) - .attr('style', $div.data('style')) - ); - if ($div.attr('width')) - $img.width($div.attr('width')); - if ($div.attr('height')) - $img.height($div.attr('height')); - }; - // Optionally show external images $('.thread-entry').each(function(i, te) { var extra = $(te).find('.textra'), @@ -378,7 +410,7 @@ var ticket_onload = function($) { .text(' Show Images') .click(function(ev) { imgs.each(function(i, img) { - showNonLocalImage(img); + $.showNonLocalImage(img); $(img).removeClass('non-local-image') // Remove placeholder sizing .css({'display':'inline-block'}) @@ -407,39 +439,12 @@ var ticket_onload = function($) { // TODO: Add a hover-button to show just one image }); }); + + $('.thread-body').each(function() { + var urls = $(this).data('urls'); + if (urls) + $.showImagesInline(urls, $(this).data('id')); + }); }; $(ticket_onload); $(document).on('pjax:success', function() { ticket_onload(jQuery); }); - -showImagesInline = function(urls, thread_id) { - var selector = (thread_id == undefined) - ? '.thread-body img[data-cid]' - : '.thread-body#thread-id-'+thread_id+' img[data-cid]'; - $(selector).each(function(i, el) { - var e = $(el), - cid = e.data('cid').toLowerCase(), - info = urls[cid]; - if (info && !e.data('wrapped')) { - // Add a hover effect with the filename - var timeout, caption = $('<div class="image-hover">') - .css({'float':e.css('float')}); - e.wrap(caption).parent() - .hover( - function() { - var self = this; - timeout = setTimeout( - function() { $(self).find('.caption').slideDown(250); }, - 500); - }, - function() { - clearTimeout(timeout); - $(this).find('.caption').slideUp(250); - } - ).append($('<div class="caption">') - .append('<span class="filename">'+info.filename+'</span>') - .append('<a href="'+info.download_url+'" class="action-button no-pjax"><i class="icon-download-alt"></i> Download</a>') - ); - e.data('wrapped', true); - } - }); -}