success: function(text){
var t = $(text);
tag.replaceWith(t);
- openForEdit(t);
+ openForEdit(t, trim=false);
},
error: function(){
tag.remove();
}
/* 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 //
}
// start edition on this node
- var $overlay = $('<div class="html-editarea"><button class="accept-button">Zapisz</button><button class="delete-button">Usuń</button><button class="tytul-button akap-edit-button">tytuł dzieła</button><button class="wyroznienie-button akap-edit-button">wyróżnienie</button><button class="slowo-button akap-edit-button">słowo obce</button><button class="znak-button akap-edit-button">znak spec.</button><textarea></textarea></div>').css({
+ var $overlay = $('<div class="html-editarea"><div class="html-editarea-toolbar"><div class="html-editarea-toolbar-left"><button class="accept-button">Zapisz</button><button class="delete-button">Usuń</button></div><div class="html-editarea-toolbar-right"><button class="akap-edit-button" data-tag="tytul_dziela">tytuł dzieła</button><button class="akap-edit-button" data-tag="wyroznienie">wyróżnienie</button><button class="akap-edit-button" data-tag="slowo_obce">słowo obce</button><button class="akap-edit-button" data-tag-selfclosing="br">br</button><button class="akap-edit-button" data-act="spec">znak spec.</button></div></div><textarea></textarea></div>').css({
position: 'absolute',
height: h,
left: x,
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();
var textAreaOpened = $('textarea', $overlay)[0];
var startTag = "";
var endTag = "";
- var buttonName = this.innerHTML;
-
- if(buttonName == "słowo obce") {
- startTag = "<slowo_obce>";
- endTag = "</slowo_obce>";
- } else if (buttonName == "wyróżnienie") {
- startTag = "<wyroznienie>";
- endTag = "</wyroznienie>";
- } else if (buttonName == "tytuł dzieła") {
- startTag = "<tytul_dziela>";
- endTag = "</tytul_dziela>";
- } else if(buttonName == "znak spec."){
- addSymbol();
+ var tag = "";
+ var $this = $(this);
+
+ if ($this.data('tag')) {
+ tag = $this.data('tag');
+ startTag = "<" + $this.data('tag') + ">";
+ endTag = "</" + $this.data('tag') + ">";
+ } else if ($this.data('tag-selfclosing')){
+ startTag = "<" + $this.data('tag-selfclosing') + "/>";
+ } else if ($this.data('act')) {
+ if ($this.data('act') == 'spec') {
+ addSymbol();
+ }
return false;
}
$('#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);
+ var toolbar = $("<div class='html-editarea-toolbar'><div class='html-editarea-toolbar-left'></div></div>")
+ editable.append(toolbar);
+ var buttonSpace = $('.html-editarea-toolbar-left', toolbar);
+ 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);
$(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());
});
}
callback();
}
+ let self = this;
xml2html({
xml: this.doc.text,
base: this.doc.getBase(),
var htmlView = $('#html-view');
htmlView.html(element);
+ self.renumber();
if ('PropertiesPerspective' in $.wiki.perspectives)
$.wiki.perspectives.PropertiesPerspective.enable();
}
})
}
+
+ 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;