X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/78943ca7de03a0f59b072c71540be92b5a6d433f..b899f6803da3511d0658b14458b7b05f6743be6a:/platforma/static/js/main.js?ds=sidebyside
diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js
index 56160ee1..3f4d30c2 100644
--- a/platforma/static/js/main.js
+++ b/platforma/static/js/main.js
@@ -94,7 +94,7 @@ function gallery(element, url) {
element.data('images', []);
function changePage(pageNumber) {
- $('img', element).attr('src', element.data('images')[pageNumber - 1]);
+ $('.gallery-image img', element).attr('src', element.data('images')[pageNumber - 1]);
}
function normalizeNumber(pageNumber) {
@@ -130,7 +130,7 @@ function gallery(element, url) {
});
- var image = $('img', element).attr('unselectable', 'on');
+ var image = $('.gallery-image img', element).attr('unselectable', 'on');
var origin = {};
var imageOrigin = {};
var zoomFactor = 1;
@@ -145,7 +145,7 @@ function gallery(element, url) {
});
$('.change-gallery', element).click(function() {
$('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/');
- $('.gallery-image').animate({top: 53}, 200);
+ $('.gallery-image').animate({top: 60}, 200);
$('.chosen-gallery').focus();
});
$('.change-gallery-ok', element).click(function() {
@@ -154,13 +154,13 @@ function gallery(element, url) {
}
$('#document-meta .gallery').html($('.chosen-gallery').val());
updateGallery($('.chosen-gallery').val());
- $('.gallery-image').animate({top: 27}, 200);
+ $('.gallery-image').animate({top: 30}, 200);
});
$('.change-gallery-cancel', element).click(function() {
- $('.gallery-image').animate({top: 27}, 200);
+ $('.gallery-image').animate({top: 30}, 200);
});
- $('img', element).load(function() {
+ $('.gallery-image img', element).load(function() {
image.css({width: null, height: null});
imageDimensions = {
width: $(this).width() * zoomFactor,
@@ -172,7 +172,7 @@ function gallery(element, url) {
};
if (!(imageDimensions.width && imageDimensions.height)) {
- setTimeout(function() { $('img', element).load(); }, 100);
+ setTimeout(function() { $('.gallery-image img', element).load(); }, 100);
}
var position = normalizePosition(
image.position().left,
@@ -269,14 +269,14 @@ function gallery(element, url) {
element.data('images', data);
pn.val(1);
pn.change();
- $('img', element).show();
+ $('.gallery-image img', element).show();
},
error: function(data) {
element.data('images', []);
pn.val(1);
pn.change();
- $('img', element).hide();
+ $('.gallery-image img', element).hide();
}
});
}
@@ -301,7 +301,11 @@ function transform(editor, callback) {
callback();
}
}, error: function(text) {
- $('#html-view').html('
WystÄ
piÅ bÅÄ
d:
' + text + '
');
+ var message = $('');
+ message.text(text);
+ $('#html-view').html('WystÄ
piÅ bÅÄ
d:
' +
+ message.html() + '
');
+
$.unblockUI();
if (callback) {
callback();
@@ -324,8 +328,8 @@ function reverseTransform(editor, cont, errorCont, dontBlock) {
$.blockUI({message: 'Åadowanie...'});
}
setTimeout(function() {
- html2xml({
- xml: serializer.serializeToString($('#html-view div').get(0)),
+ html2text({
+ element: $('#html-view div').get(0),
success: function(text) {
editor.setCode(text);
if (!dontBlock) {
@@ -393,6 +397,23 @@ function html(element) {
return true;
}
+
+ var ANNOT_ALLOWED = ['wyroznienie'];
+
+ function html2plainText(fragment) {
+ var text = "";
+
+ $(fragment.childNodes).each(function() {
+ if(this.nodeType == 3) // textNode
+ text += this.nodeValue;
+ else if (this.nodeType == 1
+ && $.inArray($(this).attr('x-node'), ANNOT_ALLOWED) != -1 ){
+ text += html2plainText(this);
+ }
+ });
+
+ return text;
+ }
function addAnnotation()
{
@@ -418,7 +439,10 @@ function html(element) {
return false;
}
- var text = range.toString();
+ // BUG #273 - selected text can contain themes, which should be omited from
+ // defining term
+ var text = html2plainText( range.cloneContents() );
+
var tag = $('');
range.collapse(false);
range.insertNode(tag[0]);
@@ -449,12 +473,20 @@ function html(element) {
// for now allow only 1 range
if(n > 1) {
- window.alert("Zaznacz jeden obszar");
+ window.alert("Zaznacz jeden obszar.");
return false;
}
+
// remember the selected range
var range = selection.getRangeAt(0);
+
+
+ if( $(range.startContainer).is('.html-editarea')
+ || $(range.endContainer).is('.html-editarea') ) {
+ window.alert("Motywy można oznaczaÄ tylko na tekÅcie nie otwartym do edycji. \n Zamknij edytowany fragment i spróbuj ponownie.");
+ return false;
+ }
// verify if the start/end points make even sense -
// they must be inside a x-node (otherwise they will be discarded)
@@ -491,7 +523,7 @@ function html(element) {
etag.replaceWith(text);
xml2html({
xml: '',
- success: function(text) {
+ success: function(text) {
mtag = $('');
spoint.insertNode(mtag[0]);
mtag.replaceWith(text);
@@ -563,9 +595,9 @@ function html(element) {
var serializer = new XMLSerializer();
- html2xml({
- xml: serializer.serializeToString($box[0]),
- inner: true,
+ html2text({
+ element: $box[0],
+ stripOuter: true,
success: function(text) {
$('textarea', $overlay).val($.trim(text));
@@ -575,10 +607,16 @@ function html(element) {
function save(argument) {
var nodeName = $box.attr('x-node') || 'pe';
+ var insertedText = $('textarea', $overlay).val();
+
+ if ($origin.is('.motyw')) {
+ insertedText = insertedText.replace(/,\s*$/, '');
+ }
+
xml2html({
- xml: '<' + nodeName + '>' + $('textarea', $overlay).val() + '' + nodeName + '>',
+ xml: '<' + nodeName + '>' + insertedText + '' + nodeName + '>',
success: function(element) {
- $box.html($(element).html());
+ $origin.html($(element).html());
$overlay.remove();
},
error: function(text) {
@@ -621,6 +659,13 @@ function html(element) {
if (!editable.hasClass('active')) {
editable.addClass('active').append(button);
}
+ if (editable.is('.annotation-inline-box')) {
+ $('*[x-annotation-box]', editable)
+ .css({position: 'absolute', left: event.clientX - editable.offset().left + 5, top: event.clientY - editable.offset().top + 5})
+ .show();
+ } else {
+ $('*[x-annotation-box]').hide();
+ }
});
$('.motyw').live('click', function() {
@@ -638,6 +683,78 @@ function html(element) {
});
}
+/*
+ * History
+ */
+
+function refreshHistory(callback){
+ $.blockUI({
+ message: 'OdÅwieżanie historii...'
+ });
+
+ $.ajax({
+ url: document.location.href + '/history',
+ dataType: 'json',
+ error: function() {
+ $('#history-view .message-box').html('Nie udaÅo siÄ odÅwieżyÄ historii').show();
+ $.unblockUI();
+ },
+ success: function(data) {
+ $('#history-view .message-box').hide();
+ var changes_list = $('#changes-list');
+ changes_list.html('');
+
+ $.each(data, function() {
+ var val = this[0];
+ changes_list.append(''
+ +''
+ + ''
+ +' | '+ this[0]+' | '
+ +''+ this[3]+' | '
+ +''+ this[2]+' | '
+ +''+ this[1]+' |
')
+ });
+ $.unblockUI();
+ callback();
+ }
+ });
+};
+
+function historyDiff(callback) {
+ var changelist = $('#changes-list');
+ var rev_a = $("input[name='rev_from']:checked", changelist);
+ var rev_b = $("input[name='rev_to']:checked", changelist);
+
+ if (rev_a.length != 1 || rev_b.length != 1) {
+ window.alert("Musisz zaznaczyÄ dwie wersje do porównania.");
+ return false;
+ }
+
+ if (rev_a.val() == rev_b.val()) {
+ window.alert("Musisz zaznaczyÄ dwie różne wersje do porównania.");
+ return false;
+ }
+
+ $.blockUI({
+ message: 'Wczytywanie porównania...'
+ });
+
+ $.ajax({
+ url: document.location.href + '/diff/'+rev_a.val() + '/'+ rev_b.val(),
+ dataType: 'html',
+ error: function() {
+ $.unblockUI();
+ window.alert('Nie udaÅo siÄ wykonaÄ porównania :(.')
+ },
+ success: function(data) {
+ $.unblockUI();
+ var diffview = $('#diff-view');
+ diffview.html(data);
+ diffview.show();
+ }
+ });
+}
+
$(function() {
gallery('#sidebar', $('#document-meta .gallery').html());
@@ -650,8 +767,10 @@ $(function() {
parserConfig: {
useHTMLKludges: false
},
- iframeClass: 'xml-iframe',
+ iframeClass: 'xml-iframe',
textWrapping: true,
+ lineNumbers: true,
+ width: "100%",
tabMode: 'spaces',
indentUnit: 0,
initCallback: function(editor) {
@@ -708,37 +827,39 @@ $(function() {
$('#save-cancel').click(function() {
$.unblockUI();
});
-
- function changeTab(callback) {
- if ($('#simple-view-tab').hasClass('active')) {
- return;
- }
- $('#simple-view-tab').addClass('active');
- $('#source-view-tab').removeClass('active');
- $('#source-editor').hide();
- $('#simple-editor').show();
+
+ var tabs = $('ol#tabs li');
+
+ tabs.click(function(event, callback) {
+ tabs.removeClass('active');
+ $('.editor').hide();
+ $(this).addClass('active');
+ $('#' + $(this).attr('ui:related')).show();
+ $(this).trigger('wl:tabload', callback);
+ });
+
+
+ $('#simple-view-tab').bind('wl:tabload', function(event, callback) {
transform(editor, callback);
- }
- $('#simple-view-tab').click(function() { changeTab(); });
-
- $('#source-view-tab').click(function() {
- if ($(this).hasClass('active')) {
- return;
- }
- $(this).addClass('active');
- $('#simple-view-tab').removeClass('active');
- $('#simple-editor').hide();
- $('#source-editor').show();
- reverseTransform(editor);
});
+
+ $('#source-view-tab').bind('wl:tabload', function(event, callback) {
+ reverseTransform(editor, callback);
+ });
+
+ $('#history-view-tab').bind('wl:tabload', function(event, callback) {
+ refreshHistory(callback);
+ });
+
+ $('#make-diff-button').click(historyDiff);
$('#source-editor .toolbar button').click(function(event) {
event.preventDefault();
var params = eval("(" + $(this).attr('ui:action-params') + ")");
scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
- });
+ });
- $('.toolbar select').change(function() {
+ $('.toolbar select').change(function(event) {
var slug = $(this).val();
$('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
@@ -748,7 +869,12 @@ $(function() {
$('.toolbar-buttons-container').hide();
$('.toolbar select').change();
- changeTab(function() { $('#loading-overlay').fadeOut() }, function() { $('#loading-overlay').fadeOut() }, true)
+
+ $('#simple-view-tab').trigger('click',
+ function() {
+ $('#loading-overlay').fadeOut();
+ return false;
+ });
}
});