X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/166e471ceb2a6a051abf3458d19b92d75496bfaf..f216a5268a7e03c010b6abaed1fb29d1e387fa1f:/src/redakcja/static/js/wiki/view_editor_wysiwyg.js diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js index e43905c9..4a3cd6bd 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -56,7 +56,7 @@ } /* Convert HTML fragment to plaintext */ - var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'begin', 'end', 'motyw']; + var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'ptrad', 'begin', 'end', 'motyw']; function html2plainText(fragment){ var text = ""; @@ -515,7 +515,8 @@ element: source, stripOuter: true, success: function(text){ - $('textarea', $overlay).val($.trim(text)); + let ttext = $.trim(text); + $('textarea', $overlay).val(ttext); setTimeout(function(){ $('textarea', $overlay).elastic().focus(); @@ -659,6 +660,26 @@ $('*[x-annotation-box]', editable).css({ }).show(); } + if (editable.is('.reference-inline-box')) { + let preview = $('*[x-preview]', editable); + preview.show(); + let link = $("a", preview); + let href = link.attr('href'); + if (link.attr('title') == '?' && href.startsWith('https://www.wikidata.org/wiki/')) { + link.attr('title', '…'); + let qid = href.split('/').reverse()[0]; + $.ajax({ + url: 'https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/' + qid + '?_fields=labels', + dataType: "json", + success: function(data) { + link.attr( + 'title', + data['labels']['pl'] || data['labels']['en'] + ); + }, + }); + } + } }); self.caret = new Caret(element); @@ -732,6 +753,7 @@ callback(); } + let self = this; xml2html({ xml: this.doc.text, base: this.doc.getBase(), @@ -739,6 +761,7 @@ var htmlView = $('#html-view'); htmlView.html(element); + self.renumber(); if ('PropertiesPerspective' in $.wiki.perspectives) $.wiki.perspectives.PropertiesPerspective.enable(); @@ -921,6 +944,23 @@ } }) } + + renumber() { + let number = 0; + $('#html-view *').each((i, e) => { + let $e = $(e); + if ($e.closest('[x-node="abstrakt"]').length) return; + if ($e.closest('[x-node="nota_red"]').length) return; + if ($e.closest('[x-annotation-box="true"]').length) return; + let node = $e.attr('x-node'); + if (node == 'numeracja') { + number = 0; + } else if (['werset', 'akap', 'wers'].includes(node)) { + number ++; + $e.attr('x-number', number); + } + }) + } } $.wiki.VisualPerspective = VisualPerspective;