X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f9f061cab006c95dec8e972ce3989a0215756a81..ec04010fbdf38929ffccbf40853aadba5add81b2:/platforma/static/js/main.js?ds=sidebyside diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index 62ee8ff6..739808df 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -1,5 +1,5 @@ -if (!console) { - console = { +if (!window.console) { + window.console = { log: function() {} } } @@ -64,7 +64,6 @@ function gallery(element, url) { var pn = $('.page-number', element); pn.change(function(event) { - console.log('change!', $(this).val()); event.preventDefault(); var n = normalizeNumber(pn.val()); pn.val(n); @@ -94,7 +93,7 @@ function gallery(element, url) { zoom(); }); $('.change-gallery', element).click(function() { - $('.chosen-gallery').val($('#document-meta .gallery').html() || STATIC_URL + 'gallery/'); + $('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/'); $('.gallery-image').animate({top: 53}, 200); $('.chosen-gallery').focus(); }); @@ -120,7 +119,10 @@ function gallery(element, url) { galleryWidth: $(this).parent().width(), galleryHeight: $(this).parent().height() }; - console.log('load', imageDimensions) + + if (!(imageDimensions.width && imageDimensions.height)) { + setTimeout(function() { $('img', element).load(); }, 100); + } var position = normalizePosition( image.position().left, image.position().top, @@ -182,7 +184,6 @@ function gallery(element, url) { imageDimensions.width, imageDimensions.height ); - console.log(image.position(), imageDimensions, position); image.css({width: imageDimensions.width, height: imageDimensions.height, left: position.x, top: position.y}); @@ -252,7 +253,7 @@ function transform(editor) { }; -function reverseTransform(editor) { +function reverseTransform(editor, cont) { var serializer = new XMLSerializer(); if ($('#html-view .error').length > 0) { return; @@ -264,6 +265,9 @@ function reverseTransform(editor) { success: function(text) { editor.setCode(text); $.unblockUI(); + if (cont) { + cont(); + } }, error: function(text) { $('#source-editor').html('
WystÄ piÅ bÅÄ d:
' + text + ''); $.unblockUI(); @@ -273,14 +277,15 @@ function reverseTransform(editor) { } +// ============= +// = HTML View = +// ============= function html(element) { var element = $(element); function selectTheme(themeId) { var selection = window.getSelection(); - - // remove current selection selection.removeAllRanges(); var range = document.createRange(); @@ -294,52 +299,148 @@ function html(element) { } }; - // 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 // - // if($origin.is(".annotation-inline-box")) - // $box = $("*[x-annotation-box]", $origin); - // else - // $box = $origin; - // - // var x = $box[0].offsetLeft; - // var y = $box[0].offsetTop; - // var w = $box.outerWidth(); - // var h = $box.innerHeight(); - // - // console.log("Edit origin:", $origin, " box:", $box); - // console.log("offsetParent:", $box[0].offsetParent); - // console.log("Dimensions: ", x, y, w , h); - // - // // start edition on this node - // var $overlay = $(''); - // - // h = Math.max(h - 20, 2*parseInt($box.css('line-height'))); - // - // console.log(h); - // - // $overlay.css({ - // position: 'absolute', - // height: h, - // left: x, - // top: y, - // right: 0 - // }); - // - // $($box[0].offsetParent).append($overlay); - // console.log($overlay); - // } - // - // $('.edit-button').live('click', function() { - // openForEdit($(this).parent()); - // }); - // + 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: '