diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /resources/assets/javascripts/bootstrap/opengraph.js | |
current code from svn, revision 62608
Diffstat (limited to 'resources/assets/javascripts/bootstrap/opengraph.js')
| -rw-r--r-- | resources/assets/javascripts/bootstrap/opengraph.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/resources/assets/javascripts/bootstrap/opengraph.js b/resources/assets/javascripts/bootstrap/opengraph.js new file mode 100644 index 0000000..9b4ce3c --- /dev/null +++ b/resources/assets/javascripts/bootstrap/opengraph.js @@ -0,0 +1,55 @@ +function handleOpenGraphSections() { + $('.opengraph-area:not(.handled)').each(function() { + var items = $('.opengraph', this), + switcher; + if (items.length > 1) { + items.filter(':gt(0)').addClass('hidden'); + + switcher = $('<ul class="switcher">'); + $('<li><button class="switch-left" disabled><</button></li>').appendTo(switcher); + $('<li><button class="switch-right">></button></li>').appendTo(switcher); + switcher.prependTo(this); + } + + $(this).addClass('handled'); + }); +} + +STUDIP.ready(handleOpenGraphSections); +$(document).on('ajaxComplete', handleOpenGraphSections); + +$(document).on('click', '.opengraph-area .switcher button', function (event) { + var direction = $(this).is('.switch-left') ? 'left' : 'right', + current = $(this) + .closest('.opengraph-area') + .find('.opengraph:visible'), + switcher = $(this).closest('.switcher'), + buttons = { + left: $('.switch-left', switcher), + right: $('.switch-right', switcher) + }; + + if (direction === 'left') { + current = current + .addClass('hidden') + .prev() + .removeClass('hidden'); + buttons.left.attr('disabled', current.prev('.opengraph').length === 0); + buttons.right.attr('disabled', false); + } else { + current = current + .addClass('hidden') + .next() + .removeClass('hidden'); + buttons.left.attr('disabled', false); + buttons.right.attr('disabled', current.next('.opengraph').length === 0); + } + + event.preventDefault(); +}).on('click', '.opengraph a.flash-embedder', function (event) { + let url = $(this).attr('href'); + let template = _.template('<iframe width="100%" height="200px" frameborder="0" src="<%= url %>" allowfullscreen></iframe>'); + $(this).replaceWith(template({ url: url })); + + event.preventDefault(); +}); |
