8 function highlight(colour) {
10 if (window.getSelection) {
12 sel = window.getSelection();
14 range = sel.getRangeAt(0);
16 document.designMode = "on";
18 sel.removeAllRanges();
21 // Use HiliteColor since some browsers apply BackColor to the whole block
22 if ( !document.execCommand("HiliteColor", false, colour) ) {
23 document.execCommand("BackColor", false, colour);
25 document.designMode = "off";
26 } else if (document.selection && document.selection.createRange) {
28 range = document.selection.createRange();
29 range.execCommand("BackColor", false, colour);
33 // function unselectThemes(themeId) {
34 // $('.Apple-style-span').each(function() {
35 // $(this).after($(this).html());
40 function gallery(element, url) {
41 var element = $(element);
42 var imageDimensions = {};
43 element.data('images', []);
45 function changePage(pageNumber) {
46 $('img', element).attr('src', element.data('images')[pageNumber - 1]);
49 function normalizeNumber(pageNumber) {
50 // Numer strony musi być pomiędzy 1 a najwyższym numerem
51 var pageCount = element.data('images').length;
52 pageNumber = parseInt(pageNumber, 10);
54 if (!pageNumber || pageNumber == NaN || pageNumber == Infinity || pageNumber == -Infinity) {
56 } else if (pageNumber < 1) {
58 } else if (pageNumber > pageCount) {
65 var pn = $('.page-number', element);
66 pn.change(function(event) {
67 event.preventDefault();
68 var n = normalizeNumber(pn.val());
72 $('.previous-page', element).click(function() {
73 pn.val(normalizeNumber(pn.val()) - 1);
76 $('.next-page', element).click(function() {
77 pn.val(normalizeNumber(pn.val()) + 1);
82 var image = $('img', element).attr('unselectable', 'on');
87 $('.zoom-in', element).click(function() {
88 zoomFactor = Math.min(2, zoomFactor + 0.2);
91 $('.zoom-out', element).click(function() {
92 zoomFactor = Math.max(0.2, zoomFactor - 0.2);
95 $('.change-gallery', element).click(function() {
96 $('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/');
97 $('.gallery-image').animate({top: 53}, 200);
98 $('.chosen-gallery').focus();
100 $('.change-gallery-ok', element).click(function() {
101 if ($('#document-meta .gallery').length == 0) {
102 $('<div class="gallery"></div>').appendTo('#document-meta');
104 $('#document-meta .gallery').html($('.chosen-gallery').val());
105 updateGallery($('.chosen-gallery').val());
106 $('.gallery-image').animate({top: 27}, 200);
108 $('.change-gallery-cancel', element).click(function() {
109 $('.gallery-image').animate({top: 27}, 200);
112 $('img', element).load(function() {
113 image.css({width: null, height: null});
115 width: $(this).width() * zoomFactor,
116 height: $(this).height() * zoomFactor,
117 originWidth: $(this).width(),
118 originHeight: $(this).height(),
119 galleryWidth: $(this).parent().width(),
120 galleryHeight: $(this).parent().height()
123 if (!(imageDimensions.width && imageDimensions.height)) {
124 setTimeout(function() { $('img', element).load(); }, 100);
126 var position = normalizePosition(
127 image.position().left,
128 image.position().top,
129 imageDimensions.galleryWidth,
130 imageDimensions.galleryHeight,
131 imageDimensions.width,
132 imageDimensions.height
134 image.css({left: position.x, top: position.y, width: $(this).width() * zoomFactor, height: $(this).height() * zoomFactor});
137 $(window).resize(function() {
138 imageDimensions.galleryWidth = image.parent().width();
139 imageDimensions.galleryHeight = image.parent().height();
142 function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
146 minX: galleryWidth - imageWidth,
147 minY: galleryHeight - imageHeight
151 function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
152 var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
154 x: Math.min(b.maxX, Math.max(b.minX, x)),
155 y: Math.min(b.maxY, Math.max(b.minY, y))
159 function onMouseMove(event) {
160 var position = normalizePosition(
161 event.clientX - origin.x + imageOrigin.left,
162 event.clientY - origin.y + imageOrigin.top,
163 imageDimensions.galleryWidth,
164 imageDimensions.galleryHeight,
165 imageDimensions.width,
166 imageDimensions.height
168 image.css({position: 'absolute', top: position.y, left: position.x});
172 function setZoom(factor) {
177 imageDimensions.width = imageDimensions.originWidth * zoomFactor;
178 imageDimensions.height = imageDimensions.originHeight * zoomFactor;
179 var position = normalizePosition(
180 image.position().left,
181 image.position().top,
182 imageDimensions.galleryWidth,
183 imageDimensions.galleryHeight,
184 imageDimensions.width,
185 imageDimensions.height
187 image.css({width: imageDimensions.width, height: imageDimensions.height,
188 left: position.x, top: position.y});
192 function onMouseUp(event) {
194 .unbind('mousemove.gallery')
195 .unbind('mouseup.gallery');
199 image.bind('mousedown', function(event) {
204 imageOrigin = image.position();
206 .bind('mousemove.gallery', onMouseMove)
207 .bind('mouseup.gallery', onMouseUp);
211 function updateGallery(url) {
217 success: function(data) {
218 element.data('images', data);
221 $('img', element).show();
224 error: function(data) {
225 element.data('images', []);
228 $('img', element).hide();
239 function transform(editor) {
240 $.blockUI({message: 'Ładowanie...'});
241 setTimeout(function() {
243 xml: editor.getCode(),
244 success: function(element) {
245 $('#html-view').html(element);
247 }, error: function(text) {
248 $('#html-view').html('<p class="error">Wystąpił błąd:</p><pre>' + text + '</pre>');
256 function reverseTransform(editor) {
257 var serializer = new XMLSerializer();
258 if ($('#html-view .error').length > 0) {
261 $.blockUI({message: 'Ładowanie...'});
262 setTimeout(function() {
264 xml: serializer.serializeToString($('#html-view div').get(0)),
265 success: function(text) {
266 editor.setCode(text);
268 }, error: function(text) {
269 $('#source-editor').html('<p>Wystąpił błąd:</p><pre>' + text + '</pre>');
277 function html(element) {
278 var element = $(element);
280 function selectTheme(themeId)
282 var selection = window.getSelection();
284 // remove current selection
285 selection.removeAllRanges();
287 var range = document.createRange();
288 var s = $(".motyw[theme-class='"+themeId+"']")[0];
289 var e = $(".end[theme-class='"+themeId+"']")[0];
292 range.setStartAfter(s);
293 range.setEndBefore(e);
294 selection.addRange(range);
298 // function openForEdit($origin)
300 // // if(this.currentOpen && this.currentOpen != $origin) {
301 // // this.closeWithSave(this.currentOpen);
306 // // annotations overlay their sub box - not their own box //
307 // if($origin.is(".annotation-inline-box"))
308 // $box = $("*[x-annotation-box]", $origin);
312 // var x = $box[0].offsetLeft;
313 // var y = $box[0].offsetTop;
314 // var w = $box.outerWidth();
315 // var h = $box.innerHeight();
317 // console.log("Edit origin:", $origin, " box:", $box);
318 // console.log("offsetParent:", $box[0].offsetParent);
319 // console.log("Dimensions: ", x, y, w , h);
321 // // start edition on this node
322 // var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
324 // h = Math.max(h - 20, 2*parseInt($box.css('line-height')));
329 // position: 'absolute',
336 // $($box[0].offsetParent).append($overlay);
337 // console.log($overlay);
340 // $('.edit-button').live('click', function() {
341 // openForEdit($(this).parent());
344 var button = $('<button class="edit-button">Edytuj</button>');
345 $(element).bind('mousemove', function(event) {
346 var editable = $(event.target).closest('*[x-editable]');
347 $('.active[x-editable]', element).not(editable).removeClass('active').children('.edit-button').remove();
348 if (!editable.hasClass('active')) {
349 editable.addClass('active').append(button);
353 $('.motyw').live('click', function() {
354 selectTheme($(this).attr('theme-class'));
360 gallery('#sidebar', $('#document-meta .gallery').html());
363 CodeMirror.fromTextArea('id_text', {
364 parserfile: 'parsexml.js',
365 path: STATIC_URL + "js/lib/codemirror/",
366 stylesheet: STATIC_URL + "css/xmlcolors.css",
368 useHTMLKludges: false
370 iframeClass: 'xml-iframe',
374 initCallback: function(editor) {
375 $('#save-button').click(function(event) {
376 event.preventDefault();
377 $.blockUI({message: $('#save-dialog')});
380 $('#save-ok').click(function() {
381 $.blockUI({message: 'Zapisywanie...'});
383 var metaComment = '<!--';
384 $('#document-meta div').each(function() {
385 metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
387 metaComment += '\n-->'
390 name: $('#document-name').html(),
391 text: metaComment + editor.getCode(),
392 revision: $('#document-revision').html(),
393 author: 'annonymous',
394 comment: $('#komentarz').val()
400 url: document.location.href,
404 success: function(data) {
406 editor.setCode(data.text);
407 $('#document-revision').html(data.revision);
409 console.log(data.errors);
414 error: function(xhr, textStatus, errorThrown) {
415 alert('error: ' + textStatus + ' ' + errorThrown);
420 $('#save-cancel').click(function() {
424 $('#simple-view-tab').click(function() {
425 if ($(this).hasClass('active')) {
428 $(this).addClass('active');
429 $('#source-view-tab').removeClass('active');
430 $('#source-editor').hide();
431 $('#simple-editor').show();
435 $('#source-view-tab').click(function() {
436 if ($(this).hasClass('active')) {
439 $(this).addClass('active');
440 $('#simple-view-tab').removeClass('active');
441 $('#simple-editor').hide();
442 $('#source-editor').show();
443 reverseTransform(editor);
446 $('#source-editor .toolbar button').click(function(event) {
447 event.preventDefault();
448 var params = eval("(" + $(this).attr('ui:action-params') + ")");
449 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
452 $('.toolbar select').change(function() {
453 var slug = $(this).val();
455 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
459 $('.toolbar-buttons-container').hide();
460 $('.toolbar select').change();
462 $('#simple-view-tab').click();
466 $(window).resize(function() {
467 $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
472 $('.vsplitbar').click(function() {
473 if ($('#sidebar').width() == 0) {
474 $('#sidebar').width(480).css({right: 0}).show();
475 $('#source-editor, #simple-editor').css({right: 495});
476 $('.vsplitbar').css({right: 480}).addClass('active');
478 $('#sidebar').width(0).hide();
479 $('#source-editor, #simple-editor').css({right: 15});
480 $('.vsplitbar').css({right: 0}).removeClass('active');