From: Radek Czajka Date: Wed, 19 Jul 2023 15:51:25 +0000 (+0200) Subject: Untangle the callbacks; Add linkable diff tabs. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/573b9004c7bc2a6a2b29335155b4ff55d142c6b6?hp=cb900d10b9d0d42b0b6aa035be45dcbaa2f61af6 Untangle the callbacks; Add linkable diff tabs. --- diff --git a/src/documents/templatetags/wall.py b/src/documents/templatetags/wall.py index 486a2d6a..25bda8b4 100644 --- a/src/documents/templatetags/wall.py +++ b/src/documents/templatetags/wall.py @@ -51,8 +51,8 @@ def changes_wall(user=None, max_len=None, day=None): w.header = _('Edit') w.title = chunk.pretty_name() w.summary = item.description - w.url = reverse('wiki_editor', - args=[chunk.book.slug, chunk.slug]) + '?diff=%d' % item.revision + w.url = reverse('wiki_editor', args=[chunk.book.slug, chunk.slug]) + \ + '#DiffPerspective_R%d-%d' % (item.revision - 1, item.revision) w.timestamp = item.created_at w.user = item.author w.user_name = item.author_name diff --git a/src/redakcja/static/js/wiki/base.js b/src/redakcja/static/js/wiki/base.js index 7018b1a6..4d3a062f 100644 --- a/src/redakcja/static/js/wiki/base.js +++ b/src/redakcja/static/js/wiki/base.js @@ -65,8 +65,7 @@ return (!!CurrentDocument && CurrentDocument.has_local_changes) || ap.dirty(); }; - $.wiki.newTab = function(doc, title, klass) { - var base_id = 'id' + Math.floor(Math.random()* 5000000000); + $.wiki.newTab = function(doc, title, klass, base_id) { var id = (''+klass)+'_' + base_id; var $tab = $(''); @@ -89,15 +88,12 @@ $.wiki.initTab = function(options) { var klass = $(options.tab).attr('data-ui-jsclass'); - return new $.wiki[klass]({ + let perspective = new $.wiki[klass]({ doc: options.doc, id: $(options.tab).attr('id'), - callback: function() { - $.wiki.perspectives[this.perspective_id] = this; - if(options.callback) - options.callback.call(this); - } }); + $.wiki.perspectives[perspective.perspective_id] = perspective; + return perspective; }; $.wiki.perspectiveForTab = function(tab) { // element or id @@ -117,6 +113,17 @@ var self = this; var $tab = $(tab); + // Create dynamic tabs (for diffs). + if ($tab.length != 1) { + let parts = tab.split('_'); + if (parts.length > 1) { + // TODO: register perspectives for it. + if (parts[0] == '#DiffPerspective') { + $tab = $($.wiki.DiffPerspective.openId(parts[1])); + } + } + } + if($tab.length != 1) $tab = $(DEFAULT_PERSPECTIVE); @@ -144,18 +151,8 @@ */ $.wiki.Perspective = class Perspective { constructor(options) { - if(!options) return; - this.doc = options.doc; - if (options.id) { - this.perspective_id = options.id; - } - else { - this.perspective_id = ''; - } - - if(options.callback) - options.callback.call(this); + this.perspective_id = options.id || '' }; config() { @@ -187,14 +184,6 @@ destroy() { // pass } - - freezeState() { - // free UI state (don't store data here) - } - - unfreezeState(frozenState) { - // restore UI state - } } /* diff --git a/src/redakcja/static/js/wiki/dialog_pubmark.js b/src/redakcja/static/js/wiki/dialog_pubmark.js index 02493841..6d20493c 100644 --- a/src/redakcja/static/js/wiki/dialog_pubmark.js +++ b/src/redakcja/static/js/wiki/dialog_pubmark.js @@ -9,8 +9,9 @@ if (!options.revision && options.revision != 0) throw "PubmarkDialog needs a revision number."; + let ctx = $.wiki.exitContext(); super(element); - this.ctx = $.wiki.exitContext(); + this.ctx = ctx; this.clearForm(); /* fill out hidden fields */ diff --git a/src/redakcja/static/js/wiki/dialog_revert.js b/src/redakcja/static/js/wiki/dialog_revert.js index 0771088f..2af642e7 100644 --- a/src/redakcja/static/js/wiki/dialog_revert.js +++ b/src/redakcja/static/js/wiki/dialog_revert.js @@ -6,8 +6,9 @@ class RevertDialog extends $.wiki.cls.GenericDialog { constructor(element, options) { + let ctx = $.wiki.exitContext(); super(element); - this.ctx = $.wiki.exitContext(); + this.ctx = ctx; this.clearForm(); /* fill out hidden fields */ diff --git a/src/redakcja/static/js/wiki/dialog_save.js b/src/redakcja/static/js/wiki/dialog_save.js index e3402b17..03baa0ff 100644 --- a/src/redakcja/static/js/wiki/dialog_save.js +++ b/src/redakcja/static/js/wiki/dialog_save.js @@ -5,9 +5,10 @@ (function($) { class SaveDialog extends $.wiki.cls.GenericDialog { - constructor(element) { + constructor(element, options) { + let ctx = $.wiki.exitContext(); super(element); - this.ctx = $.wiki.exitContext(); + this.ctx = ctx; this.clearForm(); /* fill out hidden fields */ diff --git a/src/redakcja/static/js/wiki/loader.js b/src/redakcja/static/js/wiki/loader.js index 7f7d1b11..7ea9b407 100644 --- a/src/redakcja/static/js/wiki/loader.js +++ b/src/redakcja/static/js/wiki/loader.js @@ -7,19 +7,17 @@ if (!window.console) { var DEFAULT_PERSPECTIVE = "#VisualPerspective"; -$(function() -{ +$(function() { var tabs = $('ol#tabs li'); var gallery = null; var MIN_SIDEBAR_WIDTH = 50, DEFAULT_SIDEBAR_WIDTH = 480; - CurrentDocument = new $.wikiapi.WikiDocument("document-meta"); + CurrentDocument = new $.wikiapi.WikiDocument("document-meta"); - $.blockUI.defaults.baseZ = 10000; + $.blockUI.defaults.baseZ = 10000; - function initialize() - { + function initialize() { var splitter = $('#splitter'), vsplitbar = $('#vsplitbar'), sidebar = $('#sidebar'), @@ -27,64 +25,61 @@ $(function() vsplitbarWidth = vsplitbar.outerWidth(), isHolding = false; - function setSidebarWidth(x) { - if (x < MIN_SIDEBAR_WIDTH) { - x = 0; - vsplitbar.removeClass('active'); - } else { - vsplitbar.addClass('active'); - } - $.wiki.state.perspectives.ScanGalleryPerspective.width = x; - sidebar[0].style.width = x + 'px'; - }; - - - /* The save button */ + function setSidebarWidth(x) { + if (x < MIN_SIDEBAR_WIDTH) { + x = 0; + vsplitbar.removeClass('active'); + } else { + vsplitbar.addClass('active'); + } + $.wiki.state.perspectives.ScanGalleryPerspective.width = x; + sidebar[0].style.width = x + 'px'; + }; + + /* The save button */ $('#save-button').click(function(event){ event.preventDefault(); - $.wiki.showDialog('#save_dialog'); + $.wiki.showDialog('#save_dialog'); }); - $('.editor').hide(); + $('.editor').hide(); - /* - * TABS - */ - $(document).on('click', '.tabs li', function(event, callback) { + /* + * TABS + */ + $(document).on('click', '.tabs li', function(event, callback) { event.preventDefault(); - $.wiki.switchToTab(this); + $.wiki.switchToTab(this); }); - $(document).on('click', '#tabs li .tabclose', function(event, callback) { - var $tab = $(this).parent().parent(); + $(document).on('click', '#tabs li .tabclose', function(event, callback) { + var $tab = $(this).parent().parent(); - if($('a', $tab).is('.active')) - $.wiki.switchToTab(DEFAULT_PERSPECTIVE); + if($('a', $tab).is('.active')) + $.wiki.switchToTab(DEFAULT_PERSPECTIVE); - var p = $.wiki.perspectiveForTab($tab); - p.destroy(); + var p = $.wiki.perspectiveForTab($tab); + p.destroy(); - return false; + return false; }); - $(window).resize(function(){ splitterWidth = splitter.width(); }); $(window).resize(); - $.wiki.perspectiveForTab($('#tabs-right .active').parent()).onEnter(); - - vsplitbar.on('click', function() { - var $this = $(this); - if ($this.hasClass('active')) { - $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width(); - setSidebarWidth(0); - } else { - setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.lastWidth); - } - }); - + $.wiki.perspectiveForTab($('#tabs-right .active').parent()).onEnter(); + + vsplitbar.on('click', function() { + var $this = $(this); + if ($this.hasClass('active')) { + $.wiki.state.perspectives.ScanGalleryPerspective.lastWidth = sidebar.width(); + setSidebarWidth(0); + } else { + setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.lastWidth); + } + }); /* Splitbar dragging support */ vsplitbar @@ -100,91 +95,76 @@ $(function() dragLayer.show(); // We don't show it up until now so that we don't lose single click events on vsplitbar } }); - dragLayer.mousemove(function(e) { - setSidebarWidth(splitterWidth - e.clientX - vsplitbarWidth / 2); - }); - $('body').mouseup(function(e) { - dragLayer.hide(); - isHolding = false; - }); + dragLayer.mousemove(function(e) { + setSidebarWidth(splitterWidth - e.clientX - vsplitbarWidth / 2); + }); + $('body').mouseup(function(e) { + dragLayer.hide(); + isHolding = false; + }); - setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.width); + setSidebarWidth($.wiki.state.perspectives.ScanGalleryPerspective.width); - window.onbeforeunload = function(e) { + window.onbeforeunload = function(e) { if($.wiki.isDirty()) { - e.returnValue = "Na stronie mogą być nie zapisane zmiany."; - return "Na stronie mogą być nie zapisane zmiany."; - }; - - - + e.returnValue = "Na stronie mogą być nie zapisane zmiany."; + return "Na stronie mogą być nie zapisane zmiany."; }; + }; - $('body').mousemove(function(e) { - CurrentDocument.active = true; - }); - $('body').keydown(function(e) { - CurrentDocument.active = true; - }); - + $('body').mousemove(function(e) { + CurrentDocument.active = true; + }); + $('body').keydown(function(e) { + CurrentDocument.active = true; + }); - console.log("Fetching document's text"); + console.log("Fetching document's text"); - $(document).bind('wlapi_document_changed', function(event, doc) { - try { - $('#document-revision').text(doc.revision); - } catch(e) { - console.log("Failed handler", e); - } - }); + $(document).bind('wlapi_document_changed', function(event, doc) { + try { + $('#document-revision').text(doc.revision); + } catch(e) { + console.log("Failed handler", e); + } + }); - CurrentDocument.fetch({ - success: function(){ - console.log("Fetch success"); - $('#loading-overlay').fadeOut(); - var active_tab = document.location.hash || DEFAULT_PERSPECTIVE; + CurrentDocument.fetch({ + success: function(){ + console.log("Fetch success"); + $('#loading-overlay').fadeOut(); + var active_tab = document.location.hash || DEFAULT_PERSPECTIVE; - if(active_tab == "#ScanGalleryPerspective") - active_tab = DEFAULT_PERSPECTIVE; + if(active_tab == "#ScanGalleryPerspective") + active_tab = DEFAULT_PERSPECTIVE; - console.log("Initial tab is:", active_tab) - $.wiki.switchToTab(active_tab); + console.log("Initial tab is:", active_tab) + $.wiki.switchToTab(active_tab); - /* every 5 minutes check for a newer version */ + /* every minute check for a newer version */ var revTimer = setInterval(function() { - CurrentDocument.checkRevision({outdated: function(){ - $('#header').addClass('out-of-date'); - clearInterval(revTimer); - }}); - }, 60 * 1000); - }, - failure: function() { - $('#loading-overlay').fadeOut(); - alert("FAILURE"); - } - }); + CurrentDocument.checkRevision({outdated: function(){ + $('#header').addClass('out-of-date'); + clearInterval(revTimer); + }}); + }, 60 * 1000); + }, + failure: function() { + $('#loading-overlay').fadeOut(); + alert("FAILURE"); + } + }); }; /* end of initialize() */ - /* Load configuration */ - $.wiki.loadConfig(); - - var initAll = function(a, f) { - if (a.length == 0) return f(); - - $.wiki.initTab({ - tab: a.pop(), - doc: CurrentDocument, - callback: function(){ - initAll(a, f); - } - }); - }; - + /* Load configuration */ + $.wiki.loadConfig(); - /* - * Initialize all perspectives - */ - initAll( $.makeArray($('.tabs li')), initialize); - console.log(location.hash); + /* + * Initialize all perspectives + */ + $('.tabs li').each((i, e) => { + $.wiki.initTab({tab: e, doc: CurrentDocument}); + }); + initialize(); }); diff --git a/src/redakcja/static/js/wiki/view_annotations.js b/src/redakcja/static/js/wiki/view_annotations.js index e7f62391..97479cd0 100644 --- a/src/redakcja/static/js/wiki/view_annotations.js +++ b/src/redakcja/static/js/wiki/view_annotations.js @@ -4,37 +4,31 @@ * Perspective */ class AnnotationsPerspective extends $.wiki.SidebarPerspective { - constructor(options) { - var old_callback = options.callback || function() { }; + vsplitbar = 'PRZYPISY'; - options.callback = function(){ - var self = this; + constructor(options) { + super(options); - this.vsplitbar = 'PRZYPISY'; - this.$element = $("#side-annotations"); - this.$error = $('.error-message', this.$element); - this.$annos = $('.annotations-list', this.$element); - this.$spinner = $('.spinner', this.$element); - this.$refresh = $('.refresh', this.$element); + var self = this; + this.$element = $("#side-annotations"); + this.$error = $('.error-message', this.$element); + this.$annos = $('.annotations-list', this.$element); + this.$spinner = $('.spinner', this.$element); + this.$refresh = $('.refresh', this.$element); - this.$refresh.click(function() { - var $this = $(this); + this.$refresh.click(function() { + var $this = $(this); - self.$refresh.removeClass('active'); - $this.addClass('active'); - var atype = $this.attr('data-tag'); + self.$refresh.removeClass('active'); + $this.addClass('active'); + var atype = $this.attr('data-tag'); - self.$annos.hide(); - self.$error.hide(); - self.$spinner.fadeIn(100, function() { - self.refresh(atype); - }); + self.$annos.hide(); + self.$error.hide(); + self.$spinner.fadeIn(100, function() { + self.refresh(atype); }); - - old_callback.call(this); - }; - - super(options); + }); } updateAnnotationIds() { diff --git a/src/redakcja/static/js/wiki/view_column_diff.js b/src/redakcja/static/js/wiki/view_column_diff.js index beb36ed5..30ef1bd4 100644 --- a/src/redakcja/static/js/wiki/view_column_diff.js +++ b/src/redakcja/static/js/wiki/view_column_diff.js @@ -2,27 +2,50 @@ class DiffPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback || function() {}; + super(options); + this.base_id = options.base_id; + } - options.callback = function() { - var self = this; - self.base_id = options.base_id; - old_callback.call(this); - }; - super(options); + static openId(id) { + let match = id.match(/R(\d+)-(\d+)/); + if (!match) + return []; + return this.open(match[1], match[2]); } - freezeState() { - // must - }; + static open(revFrom, revTo) { + let tabId = 'R' + revFrom + '-' + revTo; + let tab = $(".tabs #DiffPerspective_" + tabId); + if (tab.length) { + $.wiki.switchToTab(tab); + } else { + let result = $.wiki.newTab(CurrentDocument, ''+revFrom +' → ' + revTo, 'DiffPerspective', tabId); + $.blockUI({ + message: 'Wczytywanie porównania...' + }); + + CurrentDocument.fetchDiff({ + from: revFrom, + to: revTo, + success: function(doc, data){ + $(result.view).html(data); + $.wiki.switchToTab(result.tab); + $.unblockUI(); + }, + failure: function(doc){ + $.unblockUI(); + } + }); + return result.tab; + } + } - destroy() { + destroy() { $.wiki.switchToTab('#HistoryPerspective'); $('#' + this.base_id).remove(); $('#' + this.perspective_id).remove(); - } + } } $.wiki.DiffPerspective = DiffPerspective; })(jQuery); - diff --git a/src/redakcja/static/js/wiki/view_editor_source.js b/src/redakcja/static/js/wiki/view_editor_source.js index 0766acfb..478cb11b 100644 --- a/src/redakcja/static/js/wiki/view_editor_source.js +++ b/src/redakcja/static/js/wiki/view_editor_source.js @@ -2,64 +2,49 @@ class CodeMirrorPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback; - options.callback = function(){ - var self = this; - - this.codemirror = CodeMirror.fromTextArea($( - '#codemirror_placeholder').get(0), { - mode: 'xml', - lineWrapping: true, - lineNumbers: true, - readOnly: CurrentDocument.readonly || false, - identUnit: 0, - }); - - $('#source-editor').keydown(function(event) { - if(!event.altKey) - return; - - var c = event.key; - var button = $("#source-editor button[data-ui-accesskey='"+c+"']"); - if(button.length == 0) - return; - button.get(0).click(); - event.preventDefault(); + super(options); + var self = this; + + this.codemirror = CodeMirror.fromTextArea($( + '#codemirror_placeholder').get(0), { + mode: 'xml', + lineWrapping: true, + lineNumbers: true, + readOnly: CurrentDocument.readonly || false, + identUnit: 0, }); - $('#source-editor .toolbar').toolbarize({ - actionContext: self.codemirror - }); + $('#source-editor').keydown(function(event) { + if(!event.altKey) + return; - // textarea is no longer needed - $('#codemirror_placeholder').remove(); - old_callback.call(self); - } - super(options); - } + var c = event.key; + var button = $("#source-editor button[data-ui-accesskey='"+c+"']"); + if(button.length == 0) + return; + button.get(0).click(); + event.preventDefault(); + }); - freezeState() { - this.config().position = this.codemirror.getScrollInfo().top; - } + $('#source-editor .toolbar').toolbarize({ + actionContext: self.codemirror + }); - unfreezeState () { - this.codemirror.scrollTo(0, this.config().position || 0); + // textarea is no longer needed + $('#codemirror_placeholder').remove(); } onEnter(success, failure) { super.onEnter(); - this.codemirror.setValue(this.doc.text); - - this.unfreezeState(this._uistate); + this.codemirror.scrollTo(0, this.config().position || 0); if(success) success(); } onExit(success, failure) { - this.freezeState(); - super.onExit(); + this.config().position = this.codemirror.getScrollInfo().top; this.doc.setText(this.codemirror.getValue()); $.wiki.exitTab('#SearchPerspective'); diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js index c8f84e1f..f39f7a87 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -609,89 +609,81 @@ class VisualPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback; - - options.callback = function(){ - let self = this; - var element = $("#html-view"); - var button = $(''); - var uwagaButton = $(''); - - if (!CurrentDocument.readonly) { - - $('#html-view').bind('mousemove', function(event){ - var editable = $(event.target).closest('*[x-editable]'); - $('.active', element).not(editable).removeClass('active').children('.active-block-button').remove(); - - if (!editable.hasClass('active')) { - editable.addClass('active').append(button); - if (!editable.is('[x-edit-attribute]') && - !editable.is('.annotation-inline-box') && - !editable.is('[x-edit-no-format]') - ) { - editable.append(uwagaButton); - } - } - if (editable.is('.annotation-inline-box')) { - $('*[x-annotation-box]', editable).css({ - }).show(); + super(options); + let self = this; + var element = $("#html-view"); + var button = $(''); + var uwagaButton = $(''); + + if (!CurrentDocument.readonly) { + + $('#html-view').bind('mousemove', function(event){ + var editable = $(event.target).closest('*[x-editable]'); + $('.active', element).not(editable).removeClass('active').children('.active-block-button').remove(); + + if (!editable.hasClass('active')) { + editable.addClass('active').append(button); + if (!editable.is('[x-edit-attribute]') && + !editable.is('.annotation-inline-box') && + !editable.is('[x-edit-no-format]') + ) { + editable.append(uwagaButton); } - }); - - self.caret = new Caret(element); - - $('#insert-reference-button').click(function(){ - self.addReference(); - return false; - }); - - $('#insert-annotation-button').click(function(){ - addAnnotation(); - return false; - }); + } + if (editable.is('.annotation-inline-box')) { + $('*[x-annotation-box]', editable).css({ + }).show(); + } + }); - $('#insert-theme-button').click(function(){ - addTheme(); - return false; - }); + self.caret = new Caret(element); + $('#insert-reference-button').click(function(){ + self.addReference(); + return false; + }); - $(".insert-inline-tag").click(function() { - self.insertInlineTag($(this).attr('data-tag')); - return false; - }); + $('#insert-annotation-button').click(function(){ + addAnnotation(); + return false; + }); - $(".insert-char").click(function() { - addSymbol(caret=self.caret); - return false; - }); + $('#insert-theme-button').click(function(){ + addTheme(); + return false; + }); - $(document).on('click', '.edit-button', function(event){ - event.preventDefault(); - openForEdit($(this).parent()); - }); + $(".insert-inline-tag").click(function() { + self.insertInlineTag($(this).attr('data-tag')); + return false; + }); - $(document).on('click', '.uwaga-button', function(event){ - event.preventDefault(); - createUwagaBefore($(this).parent()); - }); - } + $(".insert-char").click(function() { + addSymbol(caret=self.caret); + return false; + }); - $(document).on('click', '[x-node="motyw"]', function(){ - selectTheme($(this).attr('theme-class')); + $(document).on('click', '.edit-button', function(event){ + event.preventDefault(); + openForEdit($(this).parent()); }); - element.on('click', '.annotation', function(event) { + $(document).on('click', '.uwaga-button', function(event){ event.preventDefault(); - event.redakcja_caret_ignore = true; - $('[x-annotation-box]', $(this).parent()).toggleClass('editing'); - self.caret.detach(); + createUwagaBefore($(this).parent()); }); + } - old_callback.call(this); - }; + $(document).on('click', '[x-node="motyw"]', function(){ + selectTheme($(this).attr('theme-class')); + }); - super(options); + element.on('click', '.annotation', function(event) { + event.preventDefault(); + event.redakcja_caret_ignore = true; + $('[x-annotation-box]', $(this).parent()).toggleClass('editing'); + self.caret.detach(); + }); } onEnter(success, failure) { diff --git a/src/redakcja/static/js/wiki/view_gallery.js b/src/redakcja/static/js/wiki/view_gallery.js index ac91d79b..64bb46f1 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() { diff --git a/src/redakcja/static/js/wiki/view_history.js b/src/redakcja/static/js/wiki/view_history.js index e9693b71..def2bb6e 100644 --- a/src/redakcja/static/js/wiki/view_history.js +++ b/src/redakcja/static/js/wiki/view_history.js @@ -2,94 +2,69 @@ class HistoryPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback || function() {}; - - options.callback = function() { - var self = this; - if (CurrentDocument.diff) { - rev_from = CurrentDocument.diff[0]; - rev_to = CurrentDocument.diff[1]; - this.doc.fetchDiff({ - from: rev_from, - to: rev_to, - success: function(doc, data){ - var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); - - $(result.view).html(data); - $.wiki.switchToTab(result.tab); - } - }); - } + super(options); + var self = this; - // first time page is rendered - $('#make-diff-button').click(function() { - self.makeDiff(); - }); + // first time page is rendered + $('#make-diff-button').click(function() { + self.makeDiff(); + }); - $('#pubmark-changeset-button').click(function() { - self.showPubmarkForm(); - }); + $('#pubmark-changeset-button').click(function() { + self.showPubmarkForm(); + }); - $('#doc-revert-button').click(function() { - self.revertDialog(); - }); + $('#doc-revert-button').click(function() { + self.revertDialog(); + }); - $('#open-preview-button').click(function(event) { - var selected = $('#changes-list .entry.selected'); + $('#open-preview-button').click(function(event) { + var selected = $('#changes-list .entry.selected'); - if (selected.length != 1) { - window.alert("Wybierz dokładnie *jedną* wersję."); - return; - } + if (selected.length != 1) { + window.alert("Wybierz dokładnie *jedną* wersję."); + return; + } - var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); - window.open($(this).attr('data-basehref') + "?revision=" + version); + var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); + window.open($(this).attr('data-basehref') + "?revision=" + version); - event.preventDefault(); - }); + event.preventDefault(); + }); - $(document).on('click', '#changes-list .entry', function(){ - var $this = $(this); + $(document).on('click', '#changes-list .entry', function(){ + var $this = $(this); - var selected_count = $("#changes-list .entry.selected").length; + var selected_count = $("#changes-list .entry.selected").length; - if ($this.hasClass('selected')) { - $this.removeClass('selected'); - selected_count -= 1; - } - else { - if (selected_count < 2) { - $this.addClass('selected'); - selected_count += 1; - }; + if ($this.hasClass('selected')) { + $this.removeClass('selected'); + selected_count -= 1; + } + else { + if (selected_count < 2) { + $this.addClass('selected'); + selected_count += 1; }; + }; - $('#history-view-editor .toolbar button').attr('disabled', 'disabled'). - filter('*[data-enabled-when~="' + selected_count + '"]'). - attr('disabled', null); - }); - - $(document).on('click', '#changes-list span.tag', function(event){ - return false; - }); - - $('#history-view').on('scroll', function() { - if (self.finished || self.fetching) return; - var elemTop = $('#history-view .message-box').offset().top; - var windowH = $(window).innerHeight(); - if (elemTop - 20 < windowH) { - self.triggerFetch(); - } - }); - - old_callback.call(this); - } + $('#history-view-editor .toolbar button').attr('disabled', 'disabled'). + filter('*[data-enabled-when~="' + selected_count + '"]'). + attr('disabled', null); + }); - super(options); - } + $(document).on('click', '#changes-list span.tag', function(event){ + return false; + }); - freezeState() { - // must + $('#history-view').on('scroll', function() { + if (self.finished || self.fetching) return; + var elemTop = $('#history-view .message-box').offset().top; + var windowH = $(window).innerHeight(); + if (elemTop - 20 < windowH) { + self.triggerFetch(); + } + }); } onEnter(success, failure) { @@ -175,26 +150,10 @@ return; } - $.blockUI({ - message: 'Wczytywanie porównania...' - }); - var rev_from = $("*[data-stub-value='version']", selected[1]).text(); var rev_to = $("*[data-stub-value='version']", selected[0]).text(); - return this.doc.fetchDiff({ - from: rev_from, - to: rev_to, - success: function(doc, data){ - var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); - $(result.view).html(data); - $.wiki.switchToTab(result.tab); - $.unblockUI(); - }, - failure: function(doc){ - $.unblockUI(); - } - }); + $.wiki.DiffPerspective.open(rev_from, rev_to); } revertDialog() { diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js index 35d00690..5c4c0e8b 100644 --- a/src/redakcja/static/js/wiki/view_properties.js +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -39,13 +39,12 @@ }; class PropertiesPerspective extends $.wiki.SidebarPerspective { - constructor(options) { - let oldCallback = options.callback || function() {}; + vsplitbar = 'WŁAŚCIWOŚCI'; - options.callback = function() { + constructor(options) { + super(options); let self = this; - self.vsplitbar = 'WŁAŚCIWOŚCI'; self.$pane = $("#side-properties"); $("#simple-editor").on('click', '[x-node]', function(e) { @@ -180,11 +179,6 @@ self.$pane.on('click', '#current-delete', function() { self.delete(); }); - - oldCallback.call(this); - }; - - super(options); } edit(element) { diff --git a/src/redakcja/static/js/wiki/view_search.js b/src/redakcja/static/js/wiki/view_search.js index cad64fba..1421aa91 100644 --- a/src/redakcja/static/js/wiki/view_search.js +++ b/src/redakcja/static/js/wiki/view_search.js @@ -4,57 +4,51 @@ * Perspective */ class SearchPerspective extends $.wiki.SidebarPerspective { + vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; + options = Array(); + constructor(options) { - var old_callback = options.callback || function() { }; + super(options); + var self = this; - options.callback = function(){ - var self = this; + this.editor = null; + this.$element = $("#side-search"); + this.$searchInput = $('#search-input', this.$element); + this.$replaceInput = $('#replace-input', this.$element); + this.$searchButton = $('#search-button', this.$element); + this.$searchPrevButton = $('#search-prev-button', this.$element); + this.$replaceButton = $('#replace-button', this.$element); - this.vsplitbar = 'ZNAJDŹ I ZAMIEŃ'; - this.editor = null; - this.$element = $("#side-search"); - this.$searchInput = $('#search-input', this.$element); - this.$replaceInput = $('#replace-input', this.$element); - this.$searchButton = $('#search-button', this.$element); - this.$searchPrevButton = $('#search-prev-button', this.$element); - this.$replaceButton = $('#replace-button', this.$element); + this.$replaceButton.attr("disabled","disabled"); - this.$replaceButton.attr("disabled","disabled"); - this.options = Array(); - - // handlers - this.$searchInput.change(function(event){ - self.searchCursor = null; - }); - this.$replaceInput.change(function(event){ - self.searchCursor = null; - }); - - $("#side-search input:checkbox").each(function() { - self.options[this.id] = this.checked; - }).change(function(){ - self.options[this.id] = this.checked; - self.searchCursor = null; - }); - - this.$searchButton.click(function(){ - if (!self.search()) - alert('Brak wyników.'); - }); - - this.$searchPrevButton.click(function(){ - if (!self.search(false)) - alert('Brak wyników.'); - }); - - this.$replaceButton.click(function(){ - self.replace(); - }); - - old_callback.call(this); - }; + // handlers + this.$searchInput.change(function(event){ + self.searchCursor = null; + }); + this.$replaceInput.change(function(event){ + self.searchCursor = null; + }); - super(options); + $("#side-search input:checkbox").each(function() { + self.options[this.id] = this.checked; + }).change(function(){ + self.options[this.id] = this.checked; + self.searchCursor = null; + }); + + this.$searchButton.click(function(){ + if (!self.search()) + alert('Brak wyników.'); + }); + + this.$searchPrevButton.click(function(){ + if (!self.search(false)) + alert('Brak wyników.'); + }); + + this.$replaceButton.click(function(){ + self.replace(); + }); } search(forward=true) { diff --git a/src/redakcja/static/js/wiki/view_sidebar.js b/src/redakcja/static/js/wiki/view_sidebar.js index e9e712bd..0adb2494 100644 --- a/src/redakcja/static/js/wiki/view_sidebar.js +++ b/src/redakcja/static/js/wiki/view_sidebar.js @@ -1,10 +1,7 @@ (function($) { class SidebarPerspective extends $.wiki.Perspective { - constructor(options) { - super(options); - this.noupdate_hash_onenter = true; - } + noupdate_hash_onenter = true; onEnter(success, failure) { super.onEnter(); diff --git a/src/redakcja/static/js/wiki/view_summary.js b/src/redakcja/static/js/wiki/view_summary.js index 171e9b72..bb655303 100644 --- a/src/redakcja/static/js/wiki/view_summary.js +++ b/src/redakcja/static/js/wiki/view_summary.js @@ -2,20 +2,13 @@ class SummaryPerspective extends $.wiki.Perspective { constructor(options) { - var old_callback = options.callback || function() {}; - - options.callback = function() { - var self = this; - - // first time page is rendered - $('#summary-cover-refresh').click(function() { - self.refreshCover(); - }); - - old_callback.call(this); - } - super(options); + var self = this; + + // first time page is rendered + $('#summary-cover-refresh').click(function() { + self.refreshCover(); + }); } refreshCover() { @@ -50,16 +43,10 @@ } } - freezeState = function() { - // must - } - onEnter(success, failure){ super.onEnter(); this.showCharCount(); - - console.log("Entered summery view"); } } $.wiki.SummaryPerspective = SummaryPerspective; diff --git a/src/redakcja/static/js/wiki/wikiapi.js b/src/redakcja/static/js/wiki/wikiapi.js index 426c7f62..53b2a9da 100644 --- a/src/redakcja/static/js/wiki/wikiapi.js +++ b/src/redakcja/static/js/wiki/wikiapi.js @@ -121,18 +121,6 @@ this.galleryStart = parseInt($("*[data-key='gallery-start']", meta).text()); this.fullUri = $("*[data-key='full-uri']", meta).text(); - var diff = $("*[data-key='diff']", meta).text(); - if (diff) { - diff = diff.split(','); - if (diff.length == 2 && diff[0] < diff[1]) - this.diff = diff; - else if (diff.length == 1) { - diff = parseInt(diff); - if (diff != NaN) - this.diff = [diff - 1, diff]; - } - } - this.galleryImages = []; this.text = null; this.has_local_changes = false; diff --git a/src/wiki/templates/wiki/document_details_base.html b/src/wiki/templates/wiki/document_details_base.html index 3bc94e41..2b3ee91a 100644 --- a/src/wiki/templates/wiki/document_details_base.html +++ b/src/wiki/templates/wiki/document_details_base.html @@ -29,7 +29,6 @@ {{ chunk.book.gallery }} {% if chunk.gallery_start %}{{ chunk.gallery_start }}{% endif %} {{ revision }} - {{ request.GET.diff }} {% block meta-extra %} {% endblock %}