2 dramat_wierszowany_l: 4,
3 dramat_wierszowany_lp: 4,
34 MARGIN['rdf:RDF'] = 3;
35 MARGIN['rdf:Description'] = 2;
37 function elementType(element) {
38 if ($.inArray(element.tagName, ['akap', 'akap_cd', 'akap_dialog', 'strofa', 'didaskalia', 'wers', 'wers_cd', 'wers_akap', 'wers_wciety', 'autor_utworu', 'nazwa_utworu', 'dzielo_nadrzedne', 'podpis'])) {
44 // Serializuje XML, wstawiając odpowiednie ilości białych znaków między elementami
45 function serialize(element, mode) {
50 if (element.nodeType == 3) { // tekst
51 if (mode == 'block') {
52 return [$.trim(element.nodeValue)];
54 return [element.nodeValue];
56 } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
61 var hasContent = false;
63 if (MARGIN[element.tagName]) {
64 for (var i=0; i < MARGIN[element.tagName]; i++) {
67 } else if (element.tagName.indexOf('dc:') != -1) {
72 result.push(element.tagName);
74 // Mozilla nie uważa deklaracji namespace za atrybuty
75 var ns = element.tagName.indexOf(':');
76 if (ns != -1 && $.browser.mozilla) {
77 result.push(' xmlns:');
78 result.push(element.tagName.substring(0, ns));
80 result.push(element.namespaceURI);
84 if (element.attributes) {
85 for (var i=0; i < element.attributes.length; i++) {
86 var attr = element.attributes[i];
88 result.push(attr.name);
90 result.push(attr.value);
96 if (element.childNodes.length == 0) {
101 for (var i=0; i < element.childNodes.length; i++) {
102 result = result.concat(serialize(element.childNodes[i],
103 mode == 'inline' ? 'inline' : elementType(element.childNodes[i])));
107 result.push(element.tagName);
116 function highlight(colour) {
118 if (window.getSelection) {
120 sel = window.getSelection();
121 if (sel.getRangeAt) {
122 range = sel.getRangeAt(0);
124 document.designMode = "on";
126 sel.removeAllRanges();
129 // Use HiliteColor since some browsers apply BackColor to the whole block
130 if ( !document.execCommand("HiliteColor", false, colour) ) {
131 document.execCommand("BackColor", false, colour);
133 document.designMode = "off";
134 } else if (document.selection && document.selection.createRange) {
136 range = document.selection.createRange();
137 range.execCommand("BackColor", false, colour);
141 // function unselectThemes(themeId) {
142 // $('.Apple-style-span').each(function() {
143 // $(this).after($(this).html());
148 function gallery(element) {
149 var element = $(element);
150 var imageDimensions = {};
152 function changePage(pageNumber) {
153 $('img', element).attr('src', element.data('images')[pageNumber - 1]);
156 function normalizeNumber(pageNumber) {
157 // Numer strony musi być pomiędzy 1 a najwyższym numerem
158 var pageCount = element.data('images').length;
159 pageNumber = parseInt(pageNumber, 10);
161 if (!pageNumber || pageNumber == NaN || pageNumber == Infinity || pageNumber == -Infinity) {
163 } else if (pageNumber < 1) {
165 } else if (pageNumber > pageCount) {
173 url: '/gallery/sample',
177 success: function(data) {
178 element.data('images', data);
179 var pn = $('.page-number', element);
180 pn.change(function(event) {
181 console.log('change!', $(this).val());
182 event.preventDefault();
183 var n = normalizeNumber(pn.val());
187 $('.previous-page', element).click(function() {
188 pn.val(normalizeNumber(pn.val()) - 1);
191 $('.next-page', element).click(function() {
192 pn.val(normalizeNumber(pn.val()) + 1);
197 var image = $('img', element).attr('unselectable', 'on');
199 var imageOrigin = {};
202 $('.zoom-in', element).click(function() {
203 zoomFactor = Math.min(2, zoomFactor + 0.2);
206 $('.zoom-out', element).click(function() {
207 zoomFactor = Math.max(0.2, zoomFactor - 0.2);
211 $('img', element).load(function() {
212 image.css({width: null, height: null});
214 width: $(this).width() * zoomFactor,
215 height: $(this).height() * zoomFactor,
216 originWidth: $(this).width(),
217 originHeight: $(this).height(),
218 galleryWidth: $(this).parent().width(),
219 galleryHeight: $(this).parent().height()
221 console.log('load', imageDimensions)
222 var position = normalizePosition(
223 image.position().left,
224 image.position().top,
225 imageDimensions.galleryWidth,
226 imageDimensions.galleryHeight,
227 imageDimensions.width,
228 imageDimensions.height
230 image.css({left: position.x, top: position.y, width: $(this).width() * zoomFactor, height: $(this).height() * zoomFactor});
233 $(window).resize(function() {
234 imageDimensions.galleryWidth = image.parent().width();
235 imageDimensions.galleryHeight = image.parent().height();
238 function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
242 minX: galleryWidth - imageWidth,
243 minY: galleryHeight - imageHeight
247 function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
248 var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
250 x: Math.min(b.maxX, Math.max(b.minX, x)),
251 y: Math.min(b.maxY, Math.max(b.minY, y))
255 function onMouseMove(event) {
256 var position = normalizePosition(
257 event.clientX - origin.x + imageOrigin.left,
258 event.clientY - origin.y + imageOrigin.top,
259 imageDimensions.galleryWidth,
260 imageDimensions.galleryHeight,
261 imageDimensions.width,
262 imageDimensions.height
264 image.css({position: 'absolute', top: position.y, left: position.x});
268 function setZoom(factor) {
273 imageDimensions.width = imageDimensions.originWidth * zoomFactor;
274 imageDimensions.height = imageDimensions.originHeight * zoomFactor;
275 var position = normalizePosition(
276 image.position().left,
277 image.position().top,
278 imageDimensions.galleryWidth,
279 imageDimensions.galleryHeight,
280 imageDimensions.width,
281 imageDimensions.height
283 console.log(image.position(), imageDimensions, position);
284 image.css({width: imageDimensions.width, height: imageDimensions.height,
285 left: position.x, top: position.y});
289 window.setZoom = setZoom;
291 function onMouseUp(event) {
293 .unbind('mousemove.gallery')
294 .unbind('mouseup.gallery');
298 image.bind('mousedown', function(event) {
303 imageOrigin = image.position();
305 .bind('mousemove.gallery', onMouseMove)
306 .bind('mouseup.gallery', onMouseUp);
314 function html(element) {
315 var element = $(element);
317 function selectTheme(themeId)
319 var selection = window.getSelection();
321 // remove current selection
322 selection.removeAllRanges();
324 var range = document.createRange();
325 var s = $(".motyw[theme-class='"+themeId+"']")[0];
326 var e = $(".end[theme-class='"+themeId+"']")[0];
329 range.setStartAfter(s);
330 range.setEndBefore(e);
331 selection.addRange(range);
335 // function openForEdit($origin)
337 // // if(this.currentOpen && this.currentOpen != $origin) {
338 // // this.closeWithSave(this.currentOpen);
343 // // annotations overlay their sub box - not their own box //
344 // if($origin.is(".annotation-inline-box"))
345 // $box = $("*[x-annotation-box]", $origin);
349 // var x = $box[0].offsetLeft;
350 // var y = $box[0].offsetTop;
351 // var w = $box.outerWidth();
352 // var h = $box.innerHeight();
354 // console.log("Edit origin:", $origin, " box:", $box);
355 // console.log("offsetParent:", $box[0].offsetParent);
356 // console.log("Dimensions: ", x, y, w , h);
358 // // start edition on this node
359 // var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
361 // h = Math.max(h - 20, 2*parseInt($box.css('line-height')));
366 // position: 'absolute',
373 // $($box[0].offsetParent).append($overlay);
374 // console.log($overlay);
377 // $('.edit-button').live('click', function() {
378 // openForEdit($(this).parent());
381 var button = $('<button class="edit-button">Edytuj</button>');
382 $(element).bind('mousemove', function(event) {
383 var editable = $(event.target).closest('*[x-editable]');
384 $('.active[x-editable]', element).not(editable).removeClass('active').children('.edit-button').remove();
385 if (!editable.hasClass('active')) {
386 editable.addClass('active').append(button);
390 $('.motyw').live('click', function() {
391 selectTheme($(this).attr('theme-class'));
400 CodeMirror.fromTextArea('id_text', {
401 parserfile: 'parsexml.js',
402 path: "/static/js/lib/codemirror/",
403 stylesheet: "/static/css/xmlcolors.css",
405 useHTMLKludges: false
407 iframeClass: 'xml-iframe',
411 initCallback: function(editor) {
413 function createXSLT(xsl) {
414 var p = new XSLTProcessor();
415 p.importStylesheet(xsl);
419 function transform() {
420 $('#simple-editor').block({message: 'Ładowanie...'});
421 setTimeout(function() {
423 url: '/static/xsl/wl2html_client.xsl',
425 success: function(data) {
427 var parser = new DOMParser();
428 var serializer = new XMLSerializer();
429 var htmlXSL = createXSLT(data);
431 doc = editor.getCode().replace(/\/\s+/g, '<br />');
432 doc = parser.parseFromString(doc, 'text/xml');
433 var error = $('parsererror', doc);
435 if (error.length == 0) {
436 doc = htmlXSL.transformToFragment(doc, document);
437 error = $('parsererror', doc);
439 console.log('xml', doc);
440 if (error.length > 0) {
442 $('#html-view').html('<p class="error">Wystąpił błąd:</p><pre>' + error.text() + '</pre>');
444 console.log('after transform', doc);
445 $('#html-view').html(doc.firstChild);
448 $('#simple-editor').unblock();
450 error: function() {alert('Error loading XSL!')}
455 function reverseTransform () {
456 $('#source-editor').block({message: 'Ładowanie...'});
457 setTimeout(function() {
459 url: '/static/xsl/html2wl_client.xsl',
461 success: function(data) {
463 var parser = new DOMParser();
464 var serializer = new XMLSerializer();
465 var xsl = createXSLT(data);
467 if ($('#html-view .error').length > 0) {
468 $('#source-editor').unblock();
471 doc = serializer.serializeToString($('#html-view div').get(0))
472 doc = parser.parseFromString(doc, 'text/xml');
473 console.log('xml',doc, doc.documentElement);
474 // TODO: Sprawdzenie błędów
475 var error = $('parsererror', doc.documentElement);
477 if (error.length == 0) {
478 doc = xsl.transformToDocument(doc, document);
479 error = $('parsererror', doc.documentElement);
482 if (error.length > 0) {
484 $('#source-editor').html('<p>Wystąpił błąd:</p>' + error.text());
486 doc = serialize(doc.documentElement).join('');
490 console.log('after transform', doc, doc.documentElement);
491 $('#source-editor').unblock();
493 error: function() {alert('Error loading XSL!')}
498 $('#save-button').click(function(event) {
499 event.preventDefault();
500 $.blockUI({message: $('#save-dialog')});
503 $('#save-ok').click(function() {
504 $.blockUI({message: 'Zapisywanie...'});
507 name: $('#document-name').html(),
508 text: editor.getCode(),
509 revision: $('#document-revision').html(),
510 author: 'annonymous',
511 comment: $('#komentarz').val()
517 url: document.location.href,
521 success: function(data) {
523 editor.setCode(data.text);
524 $('#document-revision').html(data.revision);
526 console.log(data.errors);
531 error: function(xhr, textStatus, errorThrown) {
532 alert('error: ' + textStatus + ' ' + errorThrown);
537 $('#save-cancel').click(function() {
541 $('#simple-view-tab').click(function() {
542 if ($(this).hasClass('active')) {
545 $(this).addClass('active');
546 $('#source-view-tab').removeClass('active');
547 $('#source-editor').hide();
548 $('#simple-editor').show();
552 $('#source-view-tab').click(function() {
553 if ($(this).hasClass('active')) {
556 $(this).addClass('active');
557 $('#simple-view-tab').removeClass('active');
558 $('#simple-editor').hide();
559 $('#source-editor').show();
563 $('.toolbar button').click(function(event) {
564 event.preventDefault();
565 var params = eval("(" + $(this).attr('ui:action-params') + ")");
566 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
569 $('.toolbar select').change(function() {
570 var slug = $(this).val();
572 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
576 $('.toolbar-buttons-container').hide();
577 $('.toolbar select').change();
579 $('#simple-view-tab').click();
583 $(window).resize(function() {
584 $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
589 $('.vsplitbar').click(function() {
590 if ($('#sidebar').width() == 0) {
591 $('#sidebar').width(480).css({right: 0}).show();
592 $('#source-editor, #simple-editor').css({right: 495});
593 $('.vsplitbar').css({right: 480}).addClass('active');
594 // $('#splitter').trigger('resize', [$(window).width() - 480]);
596 $('#sidebar').width(0).hide();
597 $('#source-editor, #simple-editor').css({right: 15});
598 $('.vsplitbar').css({right: 0}).removeClass('active');
599 // $('#splitter').trigger('resize', [$(window).width()]);