From ec04010fbdf38929ffccbf40853aadba5add81b2 Mon Sep 17 00:00:00 2001 From: zuber Date: Fri, 15 Jan 2010 01:50:34 +0100 Subject: [PATCH] =?utf8?q?Wstawianie=20przypis=C3=B3w=20w=20HTML.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- platforma/static/js/main.js | 80 ++++++++++++++++++- .../templates/wiki/document_details.html | 2 +- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index a19dc14e..739808df 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -299,13 +299,80 @@ function html(element) { } }; + function verifyTagInsertPoint(node) { + if(node.nodeType == 3) { // Text Node + node = node.parentNode; + } + + if (node.nodeType != 1) { + return false; + } + + console.log('Selection point:', node); + + node = $(node); + var xtype = node.attr('x-node'); + + if (!xtype || (xtype.search(':') >= 0) || + xtype == 'motyw' || xtype == 'begin' || xtype == 'end') { + return false; + } + + // this is hopefully redundant + //if(! node.is('*.utwor *') ) + // return false; + + // don't allow themes inside annotations + if( node.is('*[x-annotation-box] *') ) + return false; + + return true; + } + + function addAnnotation() + { + var selection = window.getSelection(); + var n = selection.rangeCount; + + console.log("Range count:", n); + 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 text = range.toString(); + var tag = $(''); + range.collapse(false); + range.insertNode(tag[0]); + + xml2html({ + xml: ''+text+'', + success: function(text) { + tag.replaceWith(text); + }, + error: function() { + tag.remove(); + alert('Błąd przy dodawaniu przypisu:' + errors); + } + }) + } function openForEdit($origin) { - // if(this.currentOpen && this.currentOpen != $origin) { - // this.closeWithSave(this.currentOpen); - // } - var $box = null // annotations overlay their sub box - not their own box // @@ -386,6 +453,11 @@ function html(element) { $('.motyw').live('click', function() { selectTheme($(this).attr('theme-class')); }); + + $('#insert-annotation-button').click(function() { + addAnnotation(); + return false; + }); } diff --git a/platforma/templates/wiki/document_details.html b/platforma/templates/wiki/document_details.html index 1296dd93..89063fb4 100644 --- a/platforma/templates/wiki/document_details.html +++ b/platforma/templates/wiki/document_details.html @@ -41,7 +41,7 @@