X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..7c12614b8a982578f1e98a29d35ba300eb229681:/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 3ec4f701..517c878e 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -110,6 +110,50 @@ } + 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); + } + }) + } + + + + /* Insert theme using current selection */ function addTheme(){ @@ -193,7 +237,7 @@ spoint.insertNode(btag[0]) btag.replaceWith(text); selection.removeAllRanges(); - openForEdit($('.motyw[theme-class=' + id + ']')); + openForEdit($('.motyw[theme-class="' + id + '"]')); } }); } @@ -239,7 +283,7 @@ } tableContent += ""; - $("#content").append(specialCharsContainer); + $("body").append(specialCharsContainer); // localStorage for recently used characters - reading @@ -386,6 +430,15 @@ x = 100; } } + if ($origin.is('.reference-inline-box')) { + w = 400; + h = 32; + y -= 32; + x = Math.min( + x, + $('.htmlview div').offset().left + $('.htmlview div').width() - 400 + ); + } // start edition on this node var $overlay = $('
').css({ @@ -397,29 +450,25 @@ }).appendTo($box[0].offsetParent || $box.parent()).show(); - if ($origin.is('.motyw')) { + if ($origin.is('*[x-edit-no-format]')) { $('.akap-edit-button').remove(); - withThemes(function(canonThemes){ - $('textarea', $overlay).autocomplete(canonThemes, { - autoFill: true, - multiple: true, - selectFirst: true, - highlight: false - }); - }) + } + + if ($origin.is('.motyw')) { + $.themes.autocomplete($('textarea', $overlay)); } if ($origin.is('.motyw')){ $('.delete-button', $overlay).click(function(){ - if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ Ä ten motyw ?")) { - $('[theme-class=' + $origin.attr('theme-class') + ']').remove(); + if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ Ä ten motyw?")) { + $('[theme-class="' + $origin.attr('theme-class') + '"]').remove(); $overlay.remove(); $(document).unbind('click.blur-overlay'); return false; }; }); } - else if($box.is('*[x-annotation-box]')) { + else if($box.is('*[x-annotation-box]') || $origin.is('*[x-edit-attribute]')) { $('.delete-button', $overlay).click(function(){ if (window.confirm("Czy jesteÅ pewien, że chcesz usunÄ Ä ten przypis?")) { $origin.remove(); @@ -443,8 +492,16 @@ var serializer = new XMLSerializer(); + if($box.attr("x-edit-attribute")) { + source = $(''); + source.text($box.attr("data-wlf-" + $box.attr("x-edit-attribute"))); + source = source[0]; + } else { + source = $box[0]; + } + html2text({ - element: $box[0], + element: source, stripOuter: true, success: function(text){ $('textarea', $overlay).val($.trim(text)); @@ -461,13 +518,24 @@ insertedText = insertedText.replace(/,\s*$/, ''); } + if($box.attr("x-edit-attribute")) { + xml = '<' + nodeName + ' ' + $box.attr("x-edit-attribute") + '="' + insertedText + '"/>'; + } else { + xml = '<' + nodeName + '>' + insertedText + '' + nodeName + '>'; + } + + xml2html({ - xml: '<' + nodeName + '>' + insertedText + '' + nodeName + '>', + xml: xml, success: function(element){ if (nodeName == 'out-of-flow-text') { $(element).children().insertAfter($origin); $origin.remove() } + else if ($box.attr('x-edit-attribute')) { + $(element).insertAfter($origin); + $origin.remove(); + } else { $origin.html($(element).html()); } @@ -542,6 +610,7 @@ }); } + function VisualPerspective(options){ var old_callback = options.callback; @@ -570,6 +639,11 @@ } }); + $('#insert-reference-button').click(function(){ + addReference(); + return false; + }); + $('#insert-annotation-button').click(function(){ addAnnotation(); return false; @@ -580,14 +654,14 @@ return false; }); - $('.edit-button').live('click', function(event){ + $(document).on('click', '.edit-button', function(event){ event.preventDefault(); openForEdit($(this).parent()); }); } - $('.motyw').live('click', function(){ + $(document).on('click', '.motyw', function(){ selectTheme($(this).attr('theme-class')); }); @@ -618,6 +692,7 @@ xml2html({ xml: this.doc.text, + base: this.doc.getBase(), success: function(element){ var htmlView = $('#html-view'); htmlView.html(element);