2 function highlight(colour) {
4 if (window.getSelection) {
6 sel = window.getSelection();
8 range = sel.getRangeAt(0);
10 document.designMode = "on";
12 sel.removeAllRanges();
15 // Use HiliteColor since some browsers apply BackColor to the whole block
16 if ( !document.execCommand("HiliteColor", false, colour) ) {
17 document.execCommand("BackColor", false, colour);
19 document.designMode = "off";
20 } else if (document.selection && document.selection.createRange) {
22 range = document.selection.createRange();
23 range.execCommand("BackColor", false, colour);
27 // function unselectThemes(themeId) {
28 // $('.Apple-style-span').each(function() {
29 // $(this).after($(this).html());
34 function gallery(element, url) {
39 var element = $(element);
40 var imageDimensions = {};
42 function changePage(pageNumber) {
43 $('img', element).attr('src', element.data('images')[pageNumber - 1]);
46 function normalizeNumber(pageNumber) {
47 // Numer strony musi być pomiędzy 1 a najwyższym numerem
48 var pageCount = element.data('images').length;
49 pageNumber = parseInt(pageNumber, 10);
51 if (!pageNumber || pageNumber == NaN || pageNumber == Infinity || pageNumber == -Infinity) {
53 } else if (pageNumber < 1) {
55 } else if (pageNumber > pageCount) {
67 success: function(data) {
68 element.data('images', data);
69 var pn = $('.page-number', element);
70 pn.change(function(event) {
71 console.log('change!', $(this).val());
72 event.preventDefault();
73 var n = normalizeNumber(pn.val());
77 $('.previous-page', element).click(function() {
78 pn.val(normalizeNumber(pn.val()) - 1);
81 $('.next-page', element).click(function() {
82 pn.val(normalizeNumber(pn.val()) + 1);
87 var image = $('img', element).attr('unselectable', 'on');
92 $('.zoom-in', element).click(function() {
93 zoomFactor = Math.min(2, zoomFactor + 0.2);
96 $('.zoom-out', element).click(function() {
97 zoomFactor = Math.max(0.2, zoomFactor - 0.2);
101 $('img', element).load(function() {
102 image.css({width: null, height: null});
104 width: $(this).width() * zoomFactor,
105 height: $(this).height() * zoomFactor,
106 originWidth: $(this).width(),
107 originHeight: $(this).height(),
108 galleryWidth: $(this).parent().width(),
109 galleryHeight: $(this).parent().height()
111 console.log('load', imageDimensions)
112 var position = normalizePosition(
113 image.position().left,
114 image.position().top,
115 imageDimensions.galleryWidth,
116 imageDimensions.galleryHeight,
117 imageDimensions.width,
118 imageDimensions.height
120 image.css({left: position.x, top: position.y, width: $(this).width() * zoomFactor, height: $(this).height() * zoomFactor});
123 $(window).resize(function() {
124 imageDimensions.galleryWidth = image.parent().width();
125 imageDimensions.galleryHeight = image.parent().height();
128 function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
132 minX: galleryWidth - imageWidth,
133 minY: galleryHeight - imageHeight
137 function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
138 var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
140 x: Math.min(b.maxX, Math.max(b.minX, x)),
141 y: Math.min(b.maxY, Math.max(b.minY, y))
145 function onMouseMove(event) {
146 var position = normalizePosition(
147 event.clientX - origin.x + imageOrigin.left,
148 event.clientY - origin.y + imageOrigin.top,
149 imageDimensions.galleryWidth,
150 imageDimensions.galleryHeight,
151 imageDimensions.width,
152 imageDimensions.height
154 image.css({position: 'absolute', top: position.y, left: position.x});
158 function setZoom(factor) {
163 imageDimensions.width = imageDimensions.originWidth * zoomFactor;
164 imageDimensions.height = imageDimensions.originHeight * zoomFactor;
165 var position = normalizePosition(
166 image.position().left,
167 image.position().top,
168 imageDimensions.galleryWidth,
169 imageDimensions.galleryHeight,
170 imageDimensions.width,
171 imageDimensions.height
173 console.log(image.position(), imageDimensions, position);
174 image.css({width: imageDimensions.width, height: imageDimensions.height,
175 left: position.x, top: position.y});
179 window.setZoom = setZoom;
181 function onMouseUp(event) {
183 .unbind('mousemove.gallery')
184 .unbind('mouseup.gallery');
188 image.bind('mousedown', function(event) {
193 imageOrigin = image.position();
195 .bind('mousemove.gallery', onMouseMove)
196 .bind('mouseup.gallery', onMouseUp);
204 function html(element) {
205 var element = $(element);
207 function selectTheme(themeId)
209 var selection = window.getSelection();
211 // remove current selection
212 selection.removeAllRanges();
214 var range = document.createRange();
215 var s = $(".motyw[theme-class='"+themeId+"']")[0];
216 var e = $(".end[theme-class='"+themeId+"']")[0];
219 range.setStartAfter(s);
220 range.setEndBefore(e);
221 selection.addRange(range);
225 // function openForEdit($origin)
227 // // if(this.currentOpen && this.currentOpen != $origin) {
228 // // this.closeWithSave(this.currentOpen);
233 // // annotations overlay their sub box - not their own box //
234 // if($origin.is(".annotation-inline-box"))
235 // $box = $("*[x-annotation-box]", $origin);
239 // var x = $box[0].offsetLeft;
240 // var y = $box[0].offsetTop;
241 // var w = $box.outerWidth();
242 // var h = $box.innerHeight();
244 // console.log("Edit origin:", $origin, " box:", $box);
245 // console.log("offsetParent:", $box[0].offsetParent);
246 // console.log("Dimensions: ", x, y, w , h);
248 // // start edition on this node
249 // var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
251 // h = Math.max(h - 20, 2*parseInt($box.css('line-height')));
256 // position: 'absolute',
263 // $($box[0].offsetParent).append($overlay);
264 // console.log($overlay);
267 // $('.edit-button').live('click', function() {
268 // openForEdit($(this).parent());
271 var button = $('<button class="edit-button">Edytuj</button>');
272 $(element).bind('mousemove', function(event) {
273 var editable = $(event.target).closest('*[x-editable]');
274 $('.active[x-editable]', element).not(editable).removeClass('active').children('.edit-button').remove();
275 if (!editable.hasClass('active')) {
276 editable.addClass('active').append(button);
280 $('.motyw').live('click', function() {
281 selectTheme($(this).attr('theme-class'));
287 gallery('#sidebar', $('#document-meta .gallery').html());
290 CodeMirror.fromTextArea('id_text', {
291 parserfile: 'parsexml.js',
292 path: "/static/js/lib/codemirror/",
293 stylesheet: "/static/css/xmlcolors.css",
295 useHTMLKludges: false
297 iframeClass: 'xml-iframe',
301 initCallback: function(editor) {
302 $('#save-button').click(function(event) {
303 event.preventDefault();
304 $.blockUI({message: $('#save-dialog')});
307 $('#save-ok').click(function() {
308 $.blockUI({message: 'Zapisywanie...'});
310 var metaComment = '<!--';
311 $('#document-meta div').each(function() {
312 metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
314 metaComment += '\n-->'
317 name: $('#document-name').html(),
318 text: metaComment + editor.getCode(),
319 revision: $('#document-revision').html(),
320 author: 'annonymous',
321 comment: $('#komentarz').val()
327 url: document.location.href,
331 success: function(data) {
333 editor.setCode(data.text);
334 $('#document-revision').html(data.revision);
336 console.log(data.errors);
341 error: function(xhr, textStatus, errorThrown) {
342 alert('error: ' + textStatus + ' ' + errorThrown);
347 $('#save-cancel').click(function() {
351 $('#simple-view-tab').click(function() {
352 if ($(this).hasClass('active')) {
355 $(this).addClass('active');
356 $('#source-view-tab').removeClass('active');
357 $('#source-editor').hide();
358 $('#simple-editor').show();
362 $('#source-view-tab').click(function() {
363 if ($(this).hasClass('active')) {
366 $(this).addClass('active');
367 $('#simple-view-tab').removeClass('active');
368 $('#simple-editor').hide();
369 $('#source-editor').show();
370 reverseTransform(editor);
373 $('.toolbar button').click(function(event) {
374 event.preventDefault();
375 var params = eval("(" + $(this).attr('ui:action-params') + ")");
376 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
379 $('.toolbar select').change(function() {
380 var slug = $(this).val();
382 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
386 $('.toolbar-buttons-container').hide();
387 $('.toolbar select').change();
389 $('#simple-view-tab').click();
393 $(window).resize(function() {
394 $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
399 $('.vsplitbar').click(function() {
400 if ($('#sidebar').width() == 0) {
401 $('#sidebar').width(480).css({right: 0}).show();
402 $('#source-editor, #simple-editor').css({right: 495});
403 $('.vsplitbar').css({right: 480}).addClass('active');
405 $('#sidebar').width(0).hide();
406 $('#source-editor, #simple-editor').css({right: 15});
407 $('.vsplitbar').css({right: 0}).removeClass('active');