X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9d566b4741eb66bf09b5c7d213aa8541886e100a..fbb8f42993d02108b506028dc85466a0541be359:/src/redakcja/static/js/wiki/view_gallery.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_gallery.js b/src/redakcja/static/js/wiki/view_gallery.js index ac91d79b..c238ebfd 100644 --- a/src/redakcja/static/js/wiki/view_gallery.js +++ b/src/redakcja/static/js/wiki/view_gallery.js @@ -45,120 +45,111 @@ * Perspective */ class ScanGalleryPerspective extends $.wiki.SidebarPerspective { - constructor(options){ - var old_callback = options.callback || function() { }; - - options.callback = function(){ - var self = this; - - this.vsplitbar = 'GALERIA'; - this.dimensions = {}; - this.zoomFactor = 1; - if (this.config().page == undefined) - this.config().page = CurrentDocument.galleryStart; - this.$element = $("#side-gallery"); - this.$numberInput = $('.page-number', this.$element); - - // ... - var origin = {}; - var imageOrigin = {}; - - this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on'); - - // button handlers - this.$numberInput.change(function(event){ - event.preventDefault(); - self.setPage($(this).val()); - }); + vsplitbar = 'GALERIA'; + dimensions = {}; + zoomFactor = 1; + origin = {}; + imageOrigin = {}; - $('.start-page', this.$element).click(function(){ - self.setPage(CurrentDocument.galleryStart); - }); + constructor(options) { + super(options); + var self = this; + if (this.config().page == undefined) + this.config().page = CurrentDocument.galleryStart; + this.$element = $("#side-gallery"); + this.$numberInput = $('.page-number', this.$element); - $('.previous-page', this.$element).click(function(){ - self.setPage(parseInt(self.$numberInput.val(),10) - 1); - }); + this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on'); - $('.next-page', this.$element).click(function(){ - self.setPage(parseInt(self.$numberInput.val(),10) + 1); - }); + // button handlers + this.$numberInput.change(function(event){ + event.preventDefault(); + self.setPage($(this).val()); + }); - $('.zoom-in', this.$element).click(function(){ - self.alterZoom(0.2); - }); + $('.start-page', this.$element).click(function(){ + self.setPage(CurrentDocument.galleryStart); + }); - $('.zoom-out', this.$element).click(function(){ - self.alterZoom((-0.2)); - }); + $('.previous-page', this.$element).click(function(){ + self.setPage(parseInt(self.$numberInput.val(),10) - 1); + }); - $('.ctrl-gallery-setstart', this.$element).click(function(e) { - e.preventDefault(); - CurrentDocument.setGalleryStart(self.config().page); - }); - $('.ctrl-gallery-edit', this.$element).click(function(e) { - e.preventDefault(); - CurrentDocument.openGalleryEdit(); - }); - $('.ctrl-gallery-refresh', this.$element).click(function(e) { - e.preventDefault(); - self.refreshGallery(); - }); - $('#gallery-chooser').on('show.bs.modal', function (event) { - var modal = $(this); - var datalist = modal.find('.modal-body'); - datalist.html(''); - self.doc.withGalleryList(function(galleries) { - let item; - $.each(galleries, (i, gallery) => { - item = $('
'); - $('input', item).val(gallery); - $('label', item).append(gallery); - if (gallery == self.doc.galleryLink) { - item.addClass('text-primary') - $('input', item).prop('checked', true); - } - item.appendTo(datalist); - }); - item = $(''); - item.appendTo(datalist); - item = $(''); + $('.next-page', this.$element).click(function(){ + self.setPage(parseInt(self.$numberInput.val(),10) + 1); + }); + + $('.zoom-in', this.$element).click(function(){ + self.alterZoom(0.2); + }); + + $('.zoom-out', this.$element).click(function(){ + self.alterZoom((-0.2)); + }); + + $('.ctrl-gallery-setstart', this.$element).click(function(e) { + e.preventDefault(); + CurrentDocument.setGalleryStart(self.config().page); + }); + $('.ctrl-gallery-edit', this.$element).click(function(e) { + e.preventDefault(); + CurrentDocument.openGalleryEdit(); + }); + $('.ctrl-gallery-refresh', this.$element).click(function(e) { + e.preventDefault(); + self.refreshGallery(); + }); + $('#gallery-chooser').on('show.bs.modal', function (event) { + var modal = $(this); + var datalist = modal.find('.modal-body'); + datalist.html(''); + self.doc.withGalleryList(function(galleries) { + let item; + $.each(galleries, (i, gallery) => { + item = $(''); + $('input', item).val(gallery); + $('label', item).append(gallery); + if (gallery == self.doc.galleryLink) { + item.addClass('text-primary') + $('input', item).prop('checked', true); + } item.appendTo(datalist); }); - }) - $('#gallery-chooser .ctrl-ok').on('click', function (event) { - let item = $('#gallery-chooser :checked'); - let name; - if (item.hasClass('ctrl-none')) { - name = ''; - } - else if (item.hasClass('ctrl-new')) { - name = $('#gallery-chooser .ctrl-name').val(); - } else { - name = item.val(); - } - - self.doc.setGallery(name); - $('#gallery-chooser').modal('hide'); - self.refreshGallery(function() { - self.setPage(1); - }); - }); - - $(window).resize(function(){ - self.dimensions.galleryWidth = self.$image.parent().width(); - self.dimensions.galleryHeight = self.$image.parent().height(); + item = $(''); + item.appendTo(datalist); + item = $(''); + item.appendTo(datalist); }); + }); + $('#gallery-chooser .ctrl-ok').on('click', function (event) { + let item = $('#gallery-chooser :checked'); + let name; + if (item.hasClass('ctrl-none')) { + name = ''; + } + else if (item.hasClass('ctrl-new')) { + name = $('#gallery-chooser .ctrl-name').val(); + } else { + name = item.val(); + } - this.$image.load(function(){ - self._resizeImage(); - }).bind('mousedown', function() { - self.imageMoveStart.apply(self, arguments); + self.doc.setGallery(name); + $('#gallery-chooser').modal('hide'); + self.refreshGallery(function() { + self.setPage(1); }); + }); - old_callback.call(this); - }; + $(window).resize(function(){ + self.dimensions.galleryWidth = self.$image.parent().width(); + self.dimensions.galleryHeight = self.$image.parent().height(); + }); - super(options); + this.$image.load(function(){ + self._resizeImage(); + }).bind('mousedown', function() { + self.imageMoveStart.apply(self, arguments); + }); } _resizeImage() { @@ -195,10 +186,10 @@ } setPage(newPage) { - newPage = normalizeNumber(newPage, this.doc.galleryImages.length); + newPage = normalizeNumber(newPage, this.galleryImages.length); this.$numberInput.val(newPage); this.config().page = newPage; - $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1].url); + $('.gallery-image img', this.$element).attr('src', this.galleryImages[newPage - 1].url); } alterZoom(delta) { @@ -271,17 +262,19 @@ */ refreshGallery(success, failure) { var self = this; - this.doc.refreshGallery({ - success: function(doc, data){ + this.doc.refreshScansGallery({ + + success: function(galleryImages) { + self.galleryImages = galleryImages; self.$image.show(); console.log("gconfig:", self.config().page ); self.setPage( self.config().page ); - $('#imagesCount').html("/" + doc.galleryImages.length); + $('#imagesCount').html("/" + galleryImages.length); $('.error_message', self.$element).hide(); if(success) success(); }, - failure: function(doc, message){ + failure: function(message) { self.$image.hide(); $('.error_message', self.$element).show().html(message); if(failure) failure();