X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/166e471ceb2a6a051abf3458d19b92d75496bfaf..f3ad190e972476589cc8aeb7e67ed24d091ce6c0:/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..bc498ce1 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 = "";
@@ -110,7 +110,7 @@
success: function(text){
var t = $(text);
tag.replaceWith(t);
- openForEdit(t);
+ openForEdit(t, trim=false);
},
error: function(){
tag.remove();
@@ -405,7 +405,7 @@
}
/* open edition window for selected fragment */
- function openForEdit($origin){
+ function openForEdit($origin, trim=true){
var $box = null
// annotations overlay their sub box - not their own box //
@@ -441,7 +441,7 @@
}
// start edition on this node
- var $overlay = $('
').css({
+ var $overlay = $('').css({
position: 'absolute',
height: h,
left: x,
@@ -515,7 +515,11 @@
element: source,
stripOuter: true,
success: function(text){
- $('textarea', $overlay).val($.trim(text));
+ let ttext = text;
+ if (trim) {
+ ttext = ttext.trim();
+ }
+ $('textarea', $overlay).val(ttext);
setTimeout(function(){
$('textarea', $overlay).elastic().focus();
@@ -579,9 +583,12 @@
} else if (buttonName == "tytuÅ dzieÅa") {
startTag = "";
endTag = "";
- } else if(buttonName == "znak spec."){
+ } else if (buttonName == "znak spec."){
addSymbol();
return false;
+ } else if (buttonName == "br") {
+ startTag = "
";
+ endTag = "";
}
var myField = textAreaOpened;
@@ -644,21 +651,44 @@
$('#html-view').bind('mousemove', function(event){
var editable = $(event.target).closest('*[x-editable]');
- $('.active', element).not(editable).removeClass('active').children('.active-block-button').remove();
+ $('.active', element).not(editable).removeClass('active').children('.html-editarea-toolbar').remove();
if (!editable.hasClass('active')) {
- editable.addClass('active').append(button);
+ editable.append($(""));
+ var buttonSpace = $('.html-editarea-toolbar-left', editable);
+ editable.addClass('active');
+ buttonSpace.append(button);
if (!editable.is('[x-edit-attribute]') &&
!editable.is('.annotation-inline-box') &&
!editable.is('[x-edit-no-format]')
) {
- editable.append(uwagaButton);
+ buttonSpace.append(uwagaButton);
}
}
if (editable.is('.annotation-inline-box')) {
$('*[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);
@@ -696,13 +726,13 @@
$(document).on('click', '.edit-button', function(event){
self.flush();
event.preventDefault();
- openForEdit($(this).parent());
+ openForEdit($(this).closest('.html-editarea-toolbar').parent());
});
$(document).on('click', '.uwaga-button', function(event){
self.flush();
event.preventDefault();
- createUwagaBefore($(this).parent());
+ createUwagaBefore($(this).closest('.html-editarea-toolbar').parent());
});
}
@@ -732,6 +762,7 @@
callback();
}
+ let self = this;
xml2html({
xml: this.doc.text,
base: this.doc.getBase(),
@@ -739,6 +770,7 @@
var htmlView = $('#html-view');
htmlView.html(element);
+ self.renumber();
if ('PropertiesPerspective' in $.wiki.perspectives)
$.wiki.perspectives.PropertiesPerspective.enable();
@@ -921,6 +953,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;