123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- var imglist = null;
- var dirname = null;
- var filename = null;
- var currId = 0;
- function makeImageUrl(dir, file) {
- var res = scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename;
- if (mode && mode.length > 0) {
- res += '&mode=' + mode;
- }
- }
- function setLinks(e) {
- var doPush = false;
- /* browser navigation handling */
- if (e === undefined || e.type != 'popstate') {
- doPush = true;
- } else {
- currId = e.state;
- }
- /* replace the content */
- filename = imglist[currId].name;
- if (currId > 0) {
- $('#poprz').attr('href', makeImageUrl(dirname, imglist[currId-1].name));
- $('#poprz').show();
- } else {
- $('#poprz').hide();
- }
- if (currId < imglist.length - 1) {
- var url = makeImageUrl(dirname, imglist[currId+1].name);
- $('#nast').attr('href', url);
- $('#imagelink').attr('href', url);
- $('#nast').show();
- } else {
- $('#nast').hide();
- $('#imagelink').removeAttr('href');
- }
- var image = $("#image");
- image.css('opacity', '0.2');
- image.attr('src', imageUrlPrefix + dirname + '/' + filename);
- image.on('load', function() {
- image.css('opacity', '1');
- });
- if (doPush)
- window.history.pushState(currId, '', makeImageUrl(dirname, filename));
- commentsImageReplace(imglist[currId]);
- refreshComments();
- }
- function nextImage(e) {
- if (e)
- e.preventDefault();
- if (currId >= imglist.length - 1)
- return;
- currId++;
- setLinks();
- }
- function prevImage(e) {
- if (e)
- e.preventDefault();
- if (currId == 0)
- return;
- currId--;
- setLinks();
- }
- function imglistReceived(data) {
- imglist = data;
- /* find current id by url */
- var found = false;
- for (var i=0; i<data.length; i++) {
- file = data[i];
- if(file.name == filename) {
- currId = file.ord;
- found = true;
- break;
- }
- }
- if (!found) /* don't know where i am */
- return;
- $('#poprz').click(prevImage);
- $('#imagelink').click(nextImage);
- $('#nast').click(nextImage);
- window.onpopstate = setLinks;
- window.history.replaceState(currId, '', makeImageUrl(dirname, filename));
- }
- function getImgList() {
- var queryString = window.location.search;
- if (URLSearchParams === undefined)
- return; /* browser not supported */
- var urlParams = new URLSearchParams(queryString);
- dirname = urlParams.get('dir');
- filename = urlParams.get('file');
- if (dirname === null || filename === null) /* invalid params */
- return;
- var args = 'dir=' + dirname;
- if (mode && mode.length > 0) {
- args += '&mode=' + mode;
- }
- $.ajax({
- dataType: 'json',
- url: scriptUrlPrefix+'dirlist.php?'+args,
- success: imglistReceived
- });
- }
- $(document).keydown(function(e) {
- switch (e.which) {
- case 37:
- prevImage();
- return false;
- case 39:
- nextImage();
- return false;
- }
- });
- $(document).ready(function() {
- getImgList();
- $('body').on('swipeleft', nextImage);
- $('body').on('swiperight', prevImage);
- });
|