X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9d566b4741eb66bf09b5c7d213aa8541886e100a..87bd94a94dc6cc3dbf47db2bdd17761b3f400138:/src/redakcja/static/js/wiki/base.js?ds=sidebyside diff --git a/src/redakcja/static/js/wiki/base.js b/src/redakcja/static/js/wiki/base.js index 7018b1a6..d9141687 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 @@ -107,7 +103,7 @@ $.wiki.exitTab = function(tab){ var self = this; var $tab = $(tab); - if (!('.active', $tab)) return; + if (!('.active', $tab).length) return; $('.active', $tab).removeClass('active'); self.perspectives[$tab.attr('id')].onExit(); $('#' + $tab.attr('data-ui-related')).hide(); @@ -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 - } } /*