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
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 = $('<li class="nav-item" id="'+id+'" data-ui-related="'+base_id+'" data-ui-jsclass="'+klass+'" ><a href="#" class="nav-link">'
+ title + ' <span class="badge badge-danger tabclose">x</span></a></li>');
$.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
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);
*/
$.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() {
destroy() {
// pass
}
-
- freezeState() {
- // free UI state (don't store data here)
- }
-
- unfreezeState(frozenState) {
- // restore UI state
- }
}
/*
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 */
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 */
(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 */
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'),
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
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();
});
* 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() {
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);
-
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');
class VisualPerspective extends $.wiki.Perspective {
constructor(options) {
- var old_callback = options.callback;
-
- options.callback = function(){
- let self = this;
- var element = $("#html-view");
- var button = $('<button class="edit-button active-block-button">Edytuj</button>');
- var uwagaButton = $('<button class="uwaga-button active-block-button">Uwaga</button>');
-
- 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 = $('<button class="edit-button active-block-button">Edytuj</button>');
+ var uwagaButton = $('<button class="uwaga-button active-block-button">Uwaga</button>');
+
+ 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) {
* 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 = $('<div class="form-check"><label class="form-check-label"><input class="form-check-input" type="radio" name="gallery"></label></div>');
- $('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 = $('<div class="form-check"><label class="form-check-label"><input class="ctrl-none form-check-input" type="radio" name="gallery"><em class="text-secondary">brak</em></label></div>');
- item.appendTo(datalist);
- item = $('<div class="form-check"><label class="form-check-label"><input class="ctrl-new form-check-input" type="radio" name="gallery"><input class="ctrl-name form-control" placeholder="nowa"></label></div>');
+ $('.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 = $('<div class="form-check"><label class="form-check-label"><input class="form-check-input" type="radio" name="gallery"></label></div>');
+ $('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 = $('<div class="form-check"><label class="form-check-label"><input class="ctrl-none form-check-input" type="radio" name="gallery"><em class="text-secondary">brak</em></label></div>');
+ item.appendTo(datalist);
+ item = $('<div class="form-check"><label class="form-check-label"><input class="ctrl-new form-check-input" type="radio" name="gallery"><input class="ctrl-name form-control" placeholder="nowa"></label></div>');
+ 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() {
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) {
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() {
};
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) {
self.$pane.on('click', '#current-delete', function() {
self.delete();
});
-
- oldCallback.call(this);
- };
-
- super(options);
}
edit(element) {
* 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) {
(function($) {
class SidebarPerspective extends $.wiki.Perspective {
- constructor(options) {
- super(options);
- this.noupdate_hash_onenter = true;
- }
+ noupdate_hash_onenter = true;
onEnter(success, failure) {
super.onEnter();
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() {
}
}
- freezeState = function() {
- // must
- }
-
onEnter(success, failure){
super.onEnter();
this.showCharCount();
-
- console.log("Entered summery view");
}
}
$.wiki.SummaryPerspective = SummaryPerspective;
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;
<span data-key="gallery">{{ chunk.book.gallery }}</span>
<span data-key="gallery-start">{% if chunk.gallery_start %}{{ chunk.gallery_start }}{% endif %}</span>
<span data-key="revision">{{ revision }}</span>
- <span data-key="diff">{{ request.GET.diff }}</span>
{% block meta-extra %} {% endblock %}
</div>