whitespace fixes

This commit is contained in:
Mario Vavti 2016-12-01 14:38:04 +01:00
parent adb9f31803
commit 523f7652f2

View File

@ -105,27 +105,27 @@
<script> <script>
window.wiki_resource_id = '{{$resource_id}}'; window.wiki_resource_id = '{{$resource_id}}';
window.wiki_page_name = '{{$page}}'; window.wiki_page_name = '{{$page}}';
window.wiki_page_content = {{if !$mimeType || $mimeType == 'text/markdown'}}{{$content}}{{else}}`{{$content}}`{{/if}}; window.wiki_page_content = {{if !$mimeType || $mimeType == 'text/markdown'}}{{$content}}{{else}}`{{$content}}`{{/if}};
window.wiki_page_commit = '{{$commit}}'; window.wiki_page_commit = '{{$commit}}';
$("#generic-modal-ok-{{$wikiModalID}}").removeClass('btn-primary'); $("#generic-modal-ok-{{$wikiModalID}}").removeClass('btn-primary');
$("#generic-modal-ok-{{$wikiModalID}}").addClass('btn-danger'); $("#generic-modal-ok-{{$wikiModalID}}").addClass('btn-danger');
$('.rename-page').click(function (ev) { $('.rename-page').click(function (ev) {
$('#rename-page-form-wrapper').toggle(); $('#rename-page-form-wrapper').toggle();
ev.preventDefault(); ev.preventDefault();
}); });
$( "#rename-page-form" ).submit(function( event ) { $( "#rename-page-form" ).submit(function( event ) {
$.post("wiki/{{$channel}}/rename/page", $.post("wiki/{{$channel}}/rename/page",
{ {
oldName: window.wiki_page_name, oldName: window.wiki_page_name,
newName: $('#id_pageRename').val(), newName: $('#id_pageRename').val(),
resource_id: window.wiki_resource_id resource_id: window.wiki_resource_id
}, },
function (data) { function (data) {
if (data.success) { if (data.success) {
$('#rename-page-form-wrapper').hide(); $('#rename-page-form-wrapper').hide();
window.console.log('data: ' + JSON.stringify(data)); window.console.log('data: ' + JSON.stringify(data));
@ -135,68 +135,66 @@
} else { } else {
window.console.log('Error renaming page.'); window.console.log('Error renaming page.');
} }
}, 'json'); }, 'json');
event.preventDefault(); event.preventDefault();
}); });
{{if !$mimeType || $mimeType == 'text/markdown'}}
var editor = ace.edit("ace-editor");
editor.setOptions({
theme: "ace/theme/github",
mode: "ace/mode/markdown",
wrap: true,
minLines: 30,
maxLines: Infinity,
printMargin: false
});
editor.getSession().setValue(window.wiki_page_content);
window.editor = editor; // Store the editor in the window object so the anonymous function can use it.
{{else}}
window.editor = editor = $('#editor');
{{/if}}
{{if !$showPageControls}}
{{if !$mimeType || $mimeType == 'text/markdown'}} {{if !$mimeType || $mimeType == 'text/markdown'}}
var editor = ace.edit("ace-editor"); editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission
editor.setOptions({
theme: "ace/theme/github",
mode: "ace/mode/markdown",
wrap: true,
minLines: 30,
maxLines: Infinity,
printMargin: false
});
editor.getSession().setValue(window.wiki_page_content);
window.editor = editor; // Store the editor in the window object so the anonymous function can use it.
{{else}} {{else}}
window.editor = editor = $('#editor'); editor.prop('readonly', true);
{{/if}} {{/if}}
{{/if}}
{{if !$showPageControls}} $('#edit-pane-tab').click(function (ev) {
{{if !$mimeType || $mimeType == 'text/markdown'}} setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry
editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission
{{else}}
editor.prop('readonly', true);
{{/if}}
{{/if}}
$('#edit-pane-tab').click(function (ev) {
setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry
$('#page-tools').show(); $('#page-tools').show();
}); });
$('#wiki-get-preview').click(function (ev) { $('#wiki-get-preview').click(function (ev) {
$.post("wiki/{{$channel}}/preview", { $.post("wiki/{{$channel}}/preview", {
{{if !$mimeType || $mimeType == 'text/markdown'}} {{if !$mimeType || $mimeType == 'text/markdown'}}
content: editor.getValue(), content: editor.getValue(),
{{else}} {{else}}
content: editor.val(), content: editor.val(),
{{/if}} {{/if}}
resource_id: window.wiki_resource_id resource_id: window.wiki_resource_id
}, },
function (data) { function (data) {
if (data.success) { if (data.success) {
$('#wiki-preview').html(data.html); $('#wiki-preview').html(data.html);
$("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"});
$('#page-tools').hide(); $('#page-tools').hide();
} else { } else {
window.console.log('Error previewing page.'); window.console.log('Error previewing page.');
} }
}, 'json'); }, 'json');
ev.preventDefault(); ev.preventDefault();
}); });
$('#wiki-get-history').click(function (ev) { $('#wiki-get-history').click(function (ev) {
$.post("wiki/{{$channel}}/history/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id}, function (data) { $.post("wiki/{{$channel}}/history/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id}, function (data) {
if (data.success) { if (data.success) {
$('#page-history-list').html(data.historyHTML); $('#page-history-list').html(data.historyHTML);
$('#page-tools').hide(); $('#page-tools').hide();
@ -207,109 +205,108 @@
ev.preventDefault(); ev.preventDefault();
}); });
function wiki_refresh_page_list() { function wiki_refresh_page_list() {
if (window.wiki_resource_id === '') { if (window.wiki_resource_id === '') {
return false;
}
$.post("wiki/{{$channel}}/get/page/list/", {resource_id: window.wiki_resource_id}, function (data) {
if (data.success) {
$('#wiki_page_list_container').html(data.pages);
$('#wiki_page_list_container').show();
{{if $showNewPageButton}}
$('#new-page-button').show();
{{else}}
$('#new-page-button').hide();
{{/if}}
} else {
alert('Error fetching page list!');
window.console.log('Error fetching page list!');
}
}, 'json');
return false; return false;
} }
$.post("wiki/{{$channel}}/get/page/list/", {resource_id: window.wiki_resource_id}, function (data) {
if (data.success) {
$('#wiki_page_list_container').html(data.pages);
$('#wiki_page_list_container').show();
{{if $showNewPageButton}}
$('#new-page-button').show();
{{else}}
$('#new-page-button').hide();
{{/if}}
} else {
alert('Error fetching page list!');
window.console.log('Error fetching page list!');
}
}, 'json');
return false;
}
$('#save-page').click(function (ev) { $('#save-page').click(function (ev) {
if (window.wiki_resource_id === '' || window.wiki_page_name === '') { if (window.wiki_resource_id === '' || window.wiki_page_name === '') {
window.console.log('You must have a wiki page open in order to edit pages.'); window.console.log('You must have a wiki page open in order to edit pages.');
ev.preventDefault(); ev.preventDefault();
return false; return false;
} }
{{if !$mimeType || $mimeType == 'text/markdown'}} {{if !$mimeType || $mimeType == 'text/markdown'}}
var currentContent = editor.getValue(); var currentContent = editor.getValue();
{{else}} {{else}}
var currentContent = editor.val(); var currentContent = editor.val();
{{/if}} {{/if}}
if (window.wiki_page_content === currentContent) { if (window.wiki_page_content === currentContent) {
window.console.log('No edits to save.'); window.console.log('No edits to save.');
ev.preventDefault(); ev.preventDefault();
return false; return false;
} }
$.post("wiki/{{$channel}}/save/page", $.post("wiki/{{$channel}}/save/page", {
{ content: currentContent, content: currentContent,
commitMsg: $('#id_commitMsg').val(), commitMsg: $('#id_commitMsg').val(),
name: window.wiki_page_name, name: window.wiki_page_name,
resource_id: window.wiki_resource_id resource_id: window.wiki_resource_id
}, },
function (data) { function (data) {
if (data.success) { if (data.success) {
window.console.log('Page saved successfully.'); window.console.log('Page saved successfully.');
window.wiki_page_content = currentContent; window.wiki_page_content = currentContent;
$('#id_commitMsg').val(''); // Clear the commit message box $('#id_commitMsg').val(''); // Clear the commit message box
{{if !$mimeType || $mimeType == 'text/markdown'}} {{if !$mimeType || $mimeType == 'text/markdown'}}
$('#save-page').addClass('disabled'); // Disable the save button $('#save-page').addClass('disabled'); // Disable the save button
window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor
{{/if}} {{/if}}
window.editor.focus(); // Return focus to the editor for continued editing window.editor.focus(); // Return focus to the editor for continued editing
// $('#wiki-get-history').click(); // $('#wiki-get-history').click();
} else { } else {
alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups
window.console.log('Error saving page.'); window.console.log('Error saving page.');
} }
}, 'json'); }, 'json');
ev.preventDefault(); ev.preventDefault();
}); });
function wiki_revert_page(commitHash) { function wiki_revert_page(commitHash) {
if (window.wiki_resource_id === '' || window.wiki_page_name === '') { if (window.wiki_resource_id === '' || window.wiki_page_name === '') {
window.console.log('You must have a wiki page open in order to revert pages.'); window.console.log('You must have a wiki page open in order to revert pages.');
return false; return false;
}
$.post("wiki/{{$channel}}/revert/page", {commitHash: commitHash, name: window.wiki_page_name, resource_id: window.wiki_resource_id},
function (data) {
if (data.success) {
$('button[id^=revert-]').removeClass('btn-success');
$('button[id^=revert-]').addClass('btn-danger');
$('button[id^=revert-]').html('Revert');
$('#revert-'+commitHash).removeClass('btn-danger');
$('#revert-'+commitHash).addClass('btn-success');
$('#revert-'+commitHash).html('Page reverted<br>but not saved');
window.wiki_page_commit = commitHash;
// put contents in editor
editor.getSession().setValue(data.content);
} else {
window.console.log('Error reverting page.');
}
}, 'json');
} }
$.post("wiki/{{$channel}}/revert/page", {commitHash: commitHash, name: window.wiki_page_name, resource_id: window.wiki_resource_id},
function (data) {
if (data.success) {
$('button[id^=revert-]').removeClass('btn-success');
$('button[id^=revert-]').addClass('btn-danger');
$('button[id^=revert-]').html('Revert');
$('#revert-'+commitHash).removeClass('btn-danger');
$('#revert-'+commitHash).addClass('btn-success');
$('#revert-'+commitHash).html('Page reverted<br>but not saved');
window.wiki_page_commit = commitHash;
// put contents in editor
editor.getSession().setValue(data.content);
} else {
window.console.log('Error reverting page.');
}
}, 'json');
}
function wiki_compare_page(compareCommit) { function wiki_compare_page(compareCommit) {
if (window.wiki_resource_id === '' || window.wiki_page_name === '' || window.wiki_page_commit === '') { if (window.wiki_resource_id === '' || window.wiki_page_name === '' || window.wiki_page_commit === '') {
window.console.log('You must have a wiki page open in order to revert pages.'); window.console.log('You must have a wiki page open in order to revert pages.');
return false; return false;
} }
$.post("wiki/{{$channel}}/compare/page", $.post("wiki/{{$channel}}/compare/page", {
{ compareCommit: compareCommit,
compareCommit: compareCommit, currentCommit: window.wiki_page_commit,
currentCommit: window.wiki_page_commit, name: window.wiki_page_name,
name: window.wiki_page_name, resource_id: window.wiki_resource_id
resource_id: window.wiki_resource_id },
}, function (data) {
function (data) { console.log(data);
console.log(data); if (data.success) {
if (data.success) {
var modalBody = $('#generic-modal-body-{{$wikiModalID}}'); var modalBody = $('#generic-modal-body-{{$wikiModalID}}');
modalBody.html('<div class="descriptive-text">'+data.diff+'</div>'); modalBody.html('<div class="descriptive-text">'+data.diff+'</div>');
$('.modal-dialog').addClass('modal-lg'); $('.modal-dialog').addClass('modal-lg');
@ -319,122 +316,119 @@
$('#generic-modal-{{$wikiModalID}}').modal('hide'); $('#generic-modal-{{$wikiModalID}}').modal('hide');
}); });
$('#generic-modal-{{$wikiModalID}}').modal(); $('#generic-modal-{{$wikiModalID}}').modal();
} else { } else {
window.console.log('Error comparing page.'); window.console.log('Error comparing page.');
} }
}, 'json'); }, 'json');
} }
$('#embed-image').click(function (ev) { $('#embed-image').click(function (ev) {
initializeEmbedPhotoDialog(); initializeEmbedPhotoDialog();
ev.preventDefault(); ev.preventDefault();
});
var initializeEmbedPhotoDialog = function () {
$('.embed-photo-selected-photo').each(function (index) {
$(this).removeClass('embed-photo-selected-photo');
}); });
getPhotoAlbumList();
$('#embedPhotoModalBodyAlbumDialog').off('click');
$('#embedPhotoModal').modal();
};
var choosePhotoFromAlbum = function (album) {
var initializeEmbedPhotoDialog = function () { $.post("embedphotos/album", {name: album},
$('.embed-photo-selected-photo').each(function (index) { function(data) {
$(this).removeClass('embed-photo-selected-photo'); if (data['status']) {
}); $('#embedPhotoModalLabel').html('{{$modalchooseimages}}');
getPhotoAlbumList(); $('#embedPhotoModalBodyAlbumDialog').html('\
$('#embedPhotoModalBodyAlbumDialog').off('click'); <div><ul class="nav">\n\
$('#embedPhotoModal').modal(); <li><a href="#" onclick="initializeEmbedPhotoDialog();return false;">\n\
}; <i class="fa fa-chevron-left"></i>&nbsp;\n\
{{$modaldiffalbum}}\n\
var choosePhotoFromAlbum = function (album) { </a>\n\
$.post("embedphotos/album", {name: album}, </li>\n\
function(data) { </ul><br></div>')
if (data['status']) { $('#embedPhotoModalBodyAlbumDialog').append(data['content']);
$('#embedPhotoModalLabel').html('{{$modalchooseimages}}'); $('#embedPhotoModalBodyAlbumDialog').click(function (evt) {
$('#embedPhotoModalBodyAlbumDialog').html('\ evt.preventDefault();
<div><ul class="nav">\n\ var image = document.getElementById(evt.target.id);
<li><a href="#" onclick="initializeEmbedPhotoDialog();return false;">\n\ if (typeof($(image).parent()[0]) !== 'undefined') {
<i class="fa fa-chevron-left"></i>&nbsp;\n\ var imageparent = document.getElementById($(image).parent()[0].id);
{{$modaldiffalbum}}\n\ $(imageparent).toggleClass('embed-photo-selected-photo');
</a>\n\
</li>\n\
</ul><br></div>')
$('#embedPhotoModalBodyAlbumDialog').append(data['content']);
$('#embedPhotoModalBodyAlbumDialog').click(function (evt) {
evt.preventDefault();
var image = document.getElementById(evt.target.id);
if (typeof($(image).parent()[0]) !== 'undefined') {
var imageparent = document.getElementById($(image).parent()[0].id);
$(imageparent).toggleClass('embed-photo-selected-photo');
}
});
$('#embedPhotoModalBodyAlbumListDialog').addClass('hide');
$('#embedPhotoModalBodyAlbumDialog').removeClass('hide');
$('#embed-photo-OKButton').click(function () {
$('.embed-photo-selected-photo').each(function (index) {
var href = $(this).attr('href');
$.post("embedphotos/photolink", {href: href},
function(ddata) {
if (ddata['status']) {
var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '\n![image]($1)' )
editor.getSession().insert(editor.getCursorPosition(), imgURL)
} else {
window.console.log('{{$modalerrorlink}}' + ':' + ddata['errormsg']);
}
return false;
},
'json');
});
$('#embedPhotoModalBodyAlbumDialog').html('');
$('#embedPhotoModalBodyAlbumDialog').off('click');
$('#embedPhotoModal').modal('hide');
});
} else {
window.console.log('{{$modalerroralbum}} ' + JSON.stringify(album) + ':' + data['errormsg']);
}
return false;
},
'json');
};
var getPhotoAlbumList = function () {
$.post("embedphotos/albumlist", {},
function(data) {
if (data['status']) {
var albums = data['albumlist']; //JSON.parse(data['albumlist']);
$('#embedPhotoModalLabel').html('{{$modalchoosealbum}}');
$('#embedPhotoModalBodyAlbumList').html('<ul class="nav"></ul>');
for(var i=0; i<albums.length; i++) {
var albumName = albums[i].text;
var albumLink = '<li>';
albumLink += '<a href="#" onclick="choosePhotoFromAlbum(\'' + albumName + '\');return false;">' + albumName + '</a>';
albumLink += '</li>';
$('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink);
} }
$('#embedPhotoModalBodyAlbumDialog').addClass('hide'); });
$('#embedPhotoModalBodyAlbumListDialog').removeClass('hide'); $('#embedPhotoModalBodyAlbumListDialog').addClass('hide');
} else { $('#embedPhotoModalBodyAlbumDialog').removeClass('hide');
window.console.log('{{$modalerrorlist}}' + ':' + data['errormsg']); $('#embed-photo-OKButton').click(function () {
$('.embed-photo-selected-photo').each(function (index) {
var href = $(this).attr('href');
$.post("embedphotos/photolink", {href: href},
function(ddata) {
if (ddata['status']) {
var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '\n![image]($1)' )
editor.getSession().insert(editor.getCursorPosition(), imgURL)
} else {
window.console.log('{{$modalerrorlink}}' + ':' + ddata['errormsg']);
}
return false;
},
'json');
});
$('#embedPhotoModalBodyAlbumDialog').html('');
$('#embedPhotoModalBodyAlbumDialog').off('click');
$('#embedPhotoModal').modal('hide');
});
} else {
window.console.log('{{$modalerroralbum}} ' + JSON.stringify(album) + ':' + data['errormsg']);
}
return false;
},
'json');
};
var getPhotoAlbumList = function () {
$.post("embedphotos/albumlist", {},
function(data) {
if (data['status']) {
var albums = data['albumlist']; //JSON.parse(data['albumlist']);
$('#embedPhotoModalLabel').html('{{$modalchoosealbum}}');
$('#embedPhotoModalBodyAlbumList').html('<ul class="nav"></ul>');
for(var i=0; i<albums.length; i++) {
var albumName = albums[i].text;
var albumLink = '<li>';
albumLink += '<a href="#" onclick="choosePhotoFromAlbum(\'' + albumName + '\');return false;">' + albumName + '</a>';
albumLink += '</li>';
$('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink);
} }
return false; $('#embedPhotoModalBodyAlbumDialog').addClass('hide');
}, $('#embedPhotoModalBodyAlbumListDialog').removeClass('hide');
'json'); } else {
}; window.console.log('{{$modalerrorlist}}' + ':' + data['errormsg']);
}
return false;
},
'json');
};
$(document).ready(function () { $(document).ready(function () {
wiki_refresh_page_list(); wiki_refresh_page_list();
$("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"});
// This seems obsolete // This seems obsolete
// Show Edit tab first. Otherwise the Ace editor does not load. // Show Edit tab first. Otherwise the Ace editor does not load.
//$("#wiki-nav-tabs li:eq(1) a").tab('show'); //$("#wiki-nav-tabs li:eq(1) a").tab('show');
{{if !$mimeType || $mimeType == 'text/markdown'}} {{if !$mimeType || $mimeType == 'text/markdown'}}
window.editor.on("input", function() { window.editor.on("input", function() {
if(window.editor.getSession().getUndoManager().isClean()) { if(window.editor.getSession().getUndoManager().isClean()) {
$('#save-page').addClass('disabled'); $('#save-page').addClass('disabled');
} else { } else {
$('#save-page').removeClass('disabled'); $('#save-page').removeClass('disabled');
} }
});
{{else}}
window.editor.bbco_autocomplete('bbcode');
{{/if}}
}); });
{{else}}
window.editor.bbco_autocomplete('bbcode');
{{/if}}
});
</script> </script>