X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b9166b62220208f49bfd3521e547d60d377ab7c1..82b3920c64a77f00e2b38d8f0e1601cd74e427e4:/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 4554bbe7..bd67db6c 100644
--- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js
+++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js
@@ -6,8 +6,8 @@
selection.removeAllRanges();
var range = document.createRange();
- var s = $(".motyw[theme-class='" + themeId + "']")[0];
- var e = $(".end[theme-class='" + themeId + "']")[0];
+ var s = $("[x-node='motyw'][theme-class='" + themeId + "']")[0];
+ var e = $("[x-node='end'][theme-class='" + themeId + "']")[0];
if (s && e) {
range.setStartAfter(s);
@@ -18,15 +18,21 @@
/* Verify insertion port for annotation or theme */
function verifyTagInsertPoint(node){
- if (node.nodeType == 3) { // Text Node
+ if (node.nodeType == Node.TEXT_NODE) {
node = node.parentNode;
}
- if (node.nodeType != 1) {
+ if (node.nodeType != Node.ELEMENT_NODE) {
return false;
}
node = $(node);
+ if (node.attr('id') == 'caret') {
+ node = node.parent();
+ }
+ while (node.attr('x-pass-thru')) {
+ node = node.parent();
+ }
var xtype = node.attr('x-node');
if (!xtype || (xtype.search(':') >= 0) ||
@@ -36,6 +42,12 @@
return false;
}
+ return true;
+ }
+
+ function verifyThemeBoundaryPoint(node) {
+ if (!verifyTagInsertPoint(node)) return false;
+ node = $(node);
// don't allow themes inside annotations
if (node.closest('[x-node="pe"]').length > 0)
return false;
@@ -50,10 +62,10 @@
var text = "";
$(fragment.childNodes).each(function(){
- if (this.nodeType == 3) // textNode
+ if (this.nodeType == Node.TEXT_NODE)
text += this.nodeValue;
else {
- if (this.nodeType == 1 &&
+ if (this.nodeType == Node.ELEMENT_NODE &&
$.inArray($(this).attr('x-node'), ANNOT_FORBIDDEN) == -1) {
text += html2plainText(this);
}
@@ -69,28 +81,26 @@
var selection = window.getSelection();
var n = selection.rangeCount;
- if (n == 0) {
+ if (selection.isCollapsed) {
window.alert("Nie zaznaczono żadnego obszaru");
return false;
}
- // for now allow only 1 range
- if (n > 1) {
- window.alert("Zaznacz jeden obszar");
- return false;
- }
-
- // remember the selected range
- var range = selection.getRangeAt(0);
+ var range = selection.getRangeAt(n - 1);
if (!verifyTagInsertPoint(range.endContainer)) {
window.alert("Nie można wstawiÄ w to miejsce przypisu.");
return false;
}
- // BUG #273 - selected text can contain themes, which should be omitted from
- // defining term
- var text = html2plainText(range.cloneContents());
+ text = '';
+ for (let i = 0; i < n; ++ i) {
+ let rangeI = selection.getRangeAt(i);
+ if (verifyTagInsertPoint(rangeI.startContainer) &&
+ verifyTagInsertPoint(rangeI.endContainer)) {
+ text += html2plainText(rangeI.cloneContents());
+ }
+ }
var tag = $('');
range.collapse(false);
range.insertNode(tag[0]);
@@ -110,46 +120,6 @@
}
- function addReference(){
- var selection = window.getSelection();
- var n = selection.rangeCount;
-
- if (n == 0) {
- window.alert("Nie zaznaczono żadnego obszaru");
- return false;
- }
-
- // for now allow only 1 range
- if (n > 1) {
- window.alert("Zaznacz jeden obszar");
- return false;
- }
-
- // remember the selected range
- var range = selection.getRangeAt(0);
-
- if (!verifyTagInsertPoint(range.endContainer)) {
- window.alert("Nie można wstawiÄ w to miejsce przypisu.");
- return false;
- }
-
- var tag = $('');
- range.collapse(false);
- range.insertNode(tag[0]);
-
- xml2html({
- xml: '',
- success: function(text){
- var t = $(text);
- tag.replaceWith(t);
- openForEdit(t);
- },
- error: function(){
- tag.remove();
- alert('BÅÄ
d przy dodawaniu referncji:' + errors);
- }
- })
- }
@@ -185,12 +155,12 @@
// verify if the start/end points make even sense -
// they must be inside a x-node (otherwise they will be discarded)
// and the x-node must be a main text
- if (!verifyTagInsertPoint(range.startContainer)) {
+ if (!verifyThemeBoundaryPoint(range.startContainer)) {
window.alert("Motyw nie może siÄ zaczynaÄ w tym miejscu.");
return false;
}
- if (!verifyTagInsertPoint(range.endContainer)) {
+ if (!verifyThemeBoundaryPoint(range.endContainer)) {
window.alert("Motyw nie może siÄ koÅczyÄ w tym miejscu.");
return false;
}
@@ -237,7 +207,7 @@
spoint.insertNode(btag[0])
btag.replaceWith(text);
selection.removeAllRanges();
- openForEdit($('.motyw[theme-class="' + id + '"]'));
+ openForEdit($('[x-node="motyw"][theme-class="' + id + '"]'));
}
});
}
@@ -465,11 +435,11 @@
$('.akap-edit-button').remove();
}
- if ($origin.is('.motyw')) {
+ if ($origin.is('[x-node="motyw"]')) {
$.themes.autocomplete($('textarea', $overlay));
}
- if ($origin.is('.motyw')){
+ if ($origin.is('[x-node="motyw"]')){
$('.delete-button', $overlay).click(function(){
if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ
Ä ten motyw?")) {
$('[theme-class="' + $origin.attr('theme-class') + '"]').remove();
@@ -479,9 +449,20 @@
};
});
}
- else if($box.is('*[x-annotation-box]') || $origin.is('*[x-edit-attribute]')) {
+ else if($box.is('*[x-annotation-box]') || $origin.is('*[x-edit-attribute]') || $origin.is('*[x-node="uwaga"]')) {
+ let q;
+ switch ($origin.attr('x-node')) {
+ case 'uwaga':
+ q = 'tÄ uwagÄ';
+ break;
+ case 'ref':
+ q = 'tÄ referencjÄ';
+ break
+ default:
+ q = 'ten przypis';
+ }
$('.delete-button', $overlay).click(function(){
- if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ
Ä ten przypis?")) {
+ if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ
Ä " + q + "?")) {
$origin.remove();
$overlay.remove();
$(document).unbind('click.blur-overlay');
@@ -505,7 +486,7 @@
if($box.attr("x-edit-attribute")) {
source = $('');
- source.text($box.attr("data-wlf-" + $box.attr("x-edit-attribute")));
+ source.text($box.attr("x-a-wl-" + $box.attr("x-edit-attribute")));
source = source[0];
} else {
source = $box[0];
@@ -525,7 +506,7 @@
var nodeName = $box.attr('x-node') || 'pe';
var insertedText = $('textarea', $overlay).val();
- if ($origin.is('.motyw')) {
+ if ($origin.is('[x-node="motyw"]')) {
insertedText = insertedText.replace(/,\s*$/, '');
}
@@ -621,40 +602,52 @@
});
}
+ function createUwagaBefore(before) {
+ xml2html({
+ xml: '',
+ success: function(element){
+ let $element = $(element);
+ $element.insertBefore(before);
+ openForEdit($element);
+ }
+ });
+ }
function VisualPerspective(options){
- perspective = this;
+ perspective = self = this;
var old_callback = options.callback;
options.callback = function(){
var element = $("#html-view");
- var button = $('');
+ var button = $('');
+ var uwagaButton = $('');
if (!CurrentDocument.readonly) {
$('#html-view').bind('mousemove', function(event){
var editable = $(event.target).closest('*[x-editable]');
- $('.active', element).not(editable).removeClass('active').children('.edit-button').remove();
+ $('.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({
-// left: event.clientX - editable.offset().left + 5,
-// top: event.clientY - editable.offset().top + 5
}).show();
}
- else {
-// $('*[x-annotation-box]').hide();
- }
});
perspective.caret = new Caret(element);
$('#insert-reference-button').click(function(){
- addReference();
+ self.addReference();
return false;
});
@@ -675,7 +668,6 @@
});
$(".insert-char").click(function() {
- console.log('perspective', perspective);
addSymbol(caret=perspective.caret);
return false;
});
@@ -685,16 +677,21 @@
openForEdit($(this).parent());
});
+ $(document).on('click', '.uwaga-button', function(event){
+ event.preventDefault();
+ createUwagaBefore($(this).parent());
+ });
}
- $(document).on('click', '.motyw', function(){
+ $(document).on('click', '[x-node="motyw"]', function(){
selectTheme($(this).attr('theme-class'));
});
element.on('click', '.annotation', function(event) {
event.preventDefault();
+ event.redakcja_caret_ignore = true;
$('[x-annotation-box]', $(this).parent()).toggleClass('editing');
-
+ perspective.caret.detach();
});
old_callback.call(this);
@@ -727,14 +724,6 @@
var htmlView = $('#html-view');
htmlView.html(element);
- htmlView.find('*[x-node]').dblclick(function(e) {
- if($(e.target).is('textarea'))
- return;
- var selection = window.getSelection();
- selection.collapseToStart();
- selection.modify('extend', 'forward', 'word');
- e.stopPropagation();
- });
_finalize(success);
},
error: function(text, source){
@@ -751,6 +740,8 @@
var self = this;
self.caret.detach();
+
+ $.wiki.exitTab('#PropertiesPerspective');
$.blockUI({
message: 'Zapisywanie widoku...'
@@ -784,7 +775,7 @@
let selection = window.getSelection();
var n = selection.rangeCount;
- if (n != 1) {
+ if (n != 1 || selection.isCollapsed) {
window.alert("Nie zaznaczono obszaru");
return false
}
@@ -844,6 +835,52 @@
});
};
+ VisualPerspective.prototype.insertAtRange = function(range, elem) {
+ let self = this;
+ let $end = $(range.endContainer);
+ if ($end.attr('id') == 'caret') {
+ self.caret.insert(elem);
+ } else {
+ range.insertNode(elem[0]);
+ }
+ }
+
+ VisualPerspective.prototype.addReference = function() {
+ let self = this;
+ var selection = window.getSelection();
+ var n = selection.rangeCount;
+
+ // TODO: if no selection, take caret position..
+ if (n == 0) {
+ window.alert("Nie zaznaczono żadnego obszaru");
+ return false;
+ }
+
+ var range = selection.getRangeAt(n - 1);
+ if (!verifyTagInsertPoint(range.endContainer)) {
+ window.alert("Nie można wstawiÄ w to miejsce referencji.");
+ return false;
+ }
+
+ var tag = $('');
+
+ range.collapse(false);
+ self.insertAtRange(range, tag);
+
+ xml2html({
+ xml: '',
+ success: function(text){
+ var t = $(text);
+ tag.replaceWith(t);
+ openForEdit(t);
+ },
+ error: function(){
+ tag.remove();
+ alert('BÅÄ
d przy dodawaniu referncji:' + errors);
+ }
+ })
+ }
+
$.wiki.VisualPerspective = VisualPerspective;
})(jQuery);