Skip to content

Commit

Permalink
Merge pull request #481 from support-project/feature/issue436_interna…
Browse files Browse the repository at this point in the history
…l_link

Feature/issue436 internal link
  • Loading branch information
koda-masaru authored Oct 5, 2016
2 parents 4e2e286 + e4526c0 commit 9be7797
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

<% JspUtil jspUtil = new JspUtil(request, pageContext); %>

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]},
skipStartupTypeset: true
});
</script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe"></script>

<script type="text/javascript" src="<%= request.getContextPath() %>/bower/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/echojs/dist/echo.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/emoji-parser/main.min.js"></script>
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/WEB-INF/views/protect/knowledge/edit_comment.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@

<link rel="stylesheet" href="<%= jspUtil.mustReloadFile("/css/knowledge-edit.css") %>" />
<link rel="stylesheet" href="<%= jspUtil.mustReloadFile("/css/markdown.css") %>" />
<link rel="stylesheet" href="<%= jspUtil.mustReloadFile("/css/slide.css") %>" />
</c:param>

<c:param name="PARAM_SCRIPTS">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]},
skipStartupTypeset: true
});
</script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe"></script>

<script type="text/javascript" src="<%= jspUtil.mustReloadFile("/js/slide.js") %>"></script>

<script type="text/javascript" src="<%= request.getContextPath() %>/bower/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/jquery-file-upload/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/jquery-file-upload/js/jquery.iframe-transport.js"></script>
Expand Down
310 changes: 152 additions & 158 deletions src/main/webapp/js/comment.js
Original file line number Diff line number Diff line change
@@ -1,176 +1,170 @@
$(document).ready(function() {
$('#emojiPeopleModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiPeopleModal');
});
$('#emojiNatureModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiNatureModal');
});
$('#emojiObjectsModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiObjectsModal');
});
$('#emojiPlacesModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiPlacesModal');
});
$('#emojiSymbolsModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiSymbolsModal');
});
$('#sampleMarkdownCheck').click(function() {
var text = $('#sampleMarkdownText').val();
var textarea = $('#comment');
textarea.val(text);
preview();
$('#helpMarkdownModal').modal('hide');
var p = $("#preview").offset().top - 60;
$('html,body').animate({ scrollTop: p }, 'fast');
});
var url = _CONTEXT + '/protect.file/upload';
$('#fileupload').fileupload({
url : url,
dataType : 'json',
autoUpload: true,
maxFileSize: 5000000, // 5 MB
}).on('fileuploaddone', function (e, data) {
//$('#files').show();
$.each(data.result.files, function(index, file) {
console.log(file);
var filediv = '<div class="filediv" id="file-' + file.fileNo + '">';
filediv += '<div class="file-image">';
filediv += '<img src="' + file.thumbnailUrl + '" />';
filediv += '</div>';
filediv += '<div class="file-label">';
filediv += '<a href="' + file.url + '">';
filediv += file.name;
filediv += '</a>';
filediv += '</div>';
filediv += '<br class="fileLabelBr"/>';
filediv += '<input type="hidden" name="files" value="' + file.fileNo + '" />';
filediv += '&nbsp;&nbsp;&nbsp;';
filediv += '<button type="button" class="btn btn-success" onclick="setImagePath(\'' + file.url + '\', \'' + file.name + '\')">';
filediv += '<i class="fa fa-file-image-o"></i>&nbsp;' + _SET_IMAGE_LABEL;
filediv += '</button>';
filediv += '<button type="button" class="btn btn-danger" onclick="removeAddedFile(' + file.fileNo + ')">';
filediv += '<i class="fa fa-remove"></i>';
filediv += '&nbsp;' + _DELETE_LABEL + '</button>';
filediv += '</div>';
$('#files').append(filediv);
});
$.notify(_UPLOADED, 'success');
setTimeout(function() {
$('#progress').hide();
}, 5000);
}).on('fileuploadprogressall', function (e, data) {
$('#progress').show();
var progress = parseInt(data.loaded / data.total * 100, 10);
console.log('' + progress + '%');
$('.progress .progress-bar').css('width', progress + '%');
$('.progress .progress-bar').text(progress + '%');
}).on('fileuploadfail', function (e, data) {
if (data && data.jqXHR && data.jqXHR.responseJSON && data.jqXHR.responseJSON.msg) {
var msg = data.jqXHR.responseJSON.msg;
$.each(data.files, function (index) {
var filediv = '<div class="alert alert-warning alert-dismissible" role="alert">';
filediv += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
filediv += '<strong>';
filediv += '<i class="fa fa-remove"></i>&nbsp;';
filediv += data.files[index].name;
filediv += '</strong>&nbsp;&nbsp;';
filediv += msg;
filediv += '</div>';
$('#files').append(filediv);
$.notify(_FAIL_UPLOAD, 'warn');
});
} else {
console.log(e);
console.log(data);
$.notify('アップロードに失敗しました', 'warn');
}
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
$('#emojiPeopleModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiPeopleModal');
});
$('#emojiNatureModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiNatureModal');
});
$('#emojiObjectsModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiObjectsModal');
});
$('#emojiPlacesModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiPlacesModal');
});
$('#emojiSymbolsModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiSymbolsModal');
});
$('#sampleMarkdownCheck').click(function() {
var text = $('#sampleMarkdownText').val();
var textarea = $('#comment');
textarea.val(text);
preview();
$('#helpMarkdownModal').modal('hide');
var p = $("#preview").offset().top - 60;
$('html,body').animate({ scrollTop: p }, 'fast');
});
var url = _CONTEXT + '/protect.file/upload';
$('#fileupload').fileupload({
url : url,
dataType : 'json',
autoUpload: true,
maxFileSize: 5000000, // 5 MB
}).on('fileuploaddone', function (e, data) {
//$('#files').show();
$.each(data.result.files, function(index, file) {
console.log(file);
var filediv = '<div class="filediv" id="file-' + file.fileNo + '">';
filediv += '<div class="file-image">';
filediv += '<img src="' + file.thumbnailUrl + '" />';
filediv += '</div>';
filediv += '<div class="file-label">';
filediv += '<a href="' + file.url + '">';
filediv += file.name;
filediv += '</a>';
filediv += '</div>';
filediv += '<br class="fileLabelBr"/>';
filediv += '<input type="hidden" name="files" value="' + file.fileNo + '" />';
filediv += '&nbsp;&nbsp;&nbsp;';
filediv += '<button type="button" class="btn btn-success" onclick="setImagePath(\'' + file.url + '\', \'' + file.name + '\')">';
filediv += '<i class="fa fa-file-image-o"></i>&nbsp;' + _SET_IMAGE_LABEL;
filediv += '</button>';
filediv += '<button type="button" class="btn btn-danger" onclick="removeAddedFile(' + file.fileNo + ')">';
filediv += '<i class="fa fa-remove"></i>';
filediv += '&nbsp;' + _DELETE_LABEL + '</button>';
filediv += '</div>';
$('#files').append(filediv);
});
$.notify(_UPLOADED, 'success');
setTimeout(function() {
$('#progress').hide();
}, 5000);
}).on('fileuploadprogressall', function (e, data) {
$('#progress').show();
var progress = parseInt(data.loaded / data.total * 100, 10);
console.log('' + progress + '%');
$('.progress .progress-bar').css('width', progress + '%');
$('.progress .progress-bar').text(progress + '%');
}).on('fileuploadfail', function (e, data) {
if (data && data.jqXHR && data.jqXHR.responseJSON && data.jqXHR.responseJSON.msg) {
var msg = data.jqXHR.responseJSON.msg;
$.each(data.files, function (index) {
var filediv = '<div class="alert alert-warning alert-dismissible" role="alert">';
filediv += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
filediv += '<strong>';
filediv += '<i class="fa fa-remove"></i>&nbsp;';
filediv += data.files[index].name;
filediv += '</strong>&nbsp;&nbsp;';
filediv += msg;
filediv += '</div>';
$('#files').append(filediv);
$.notify(_FAIL_UPLOAD, 'warn');
});
} else {
console.log(e);
console.log(data);
$.notify('アップロードに失敗しました', 'warn');
}
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
});

var emoji = window.emojiParser;
var preview = function() {
$.post(_CONTEXT + '/open.knowledge/marked', {
title : $('#input_title').val(),
content : $('#comment').val()
}, function(data) {
var html = '<div class="row">';
html += '<div class="col-sm-12">';
html += '<div class="thumbnail">';
html += '<div class="caption">';
html += '[preview]';
html += '<h3>';
html += data.title;
html += '</h3><hr/>';
html += '<div style="word-break:break-all" id="content">';
var content = data.content;
html += content;
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';

var jqObj = $('#preview');
jqObj.html(html);
jqObj.find('code').addClass('hljs');
codeHighlight(jqObj)
.then(function() {
var content = emoji(jqObj.html().trim(), _CONTEXT + '/bower/emoji-parser/emoji', {classes: 'emoji-img'});
jqObj.html(content);
}).then(function () {
jqObj.find('a.oembed').oembed();
});
});
$.post(_CONTEXT + '/open.knowledge/marked', {
title : $('#input_title').val(),
content : $('#comment').val()
}, function(data) {
var html = '<div class="row">';
html += '<div class="col-sm-12">';
html += '<div class="thumbnail">';
html += '<div class="caption">';
html += '[preview]';
html += '<h3>';
html += data.title;
html += '</h3><hr/>';
html += '<div style="word-break:break-all" id="content">';
var content = data.content;
html += content;
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';

var target = '#preview';
var jqObj = $(target);
jqObj.html(html);
processDecoration(target);
});
};
var emojiSelect = function(id) {
$(id).find('.name').each(function(i, block) {
$(this).click(function(event) {
var val = ' :' + $(this).text() + ': ';
var textarea = $('#comment');
textarea.val(textarea.val() + val);
$(id).modal('hide');
});
});
$(id).find('.name').each(function(i, block) {
$(this).click(function(event) {
var val = ' :' + $(this).text() + ': ';
var textarea = $('#comment');
textarea.val(textarea.val() + val);
$(id).modal('hide');
});
});
};

function deleteComment() {
bootbox.confirm(_CONFIRM, function(result) {
if (result) {
$('#commentForm').attr('action', _CONTEXT + '/protect.knowledge/delete_comment/' + $('#commentNo').val());
$('#commentForm').attr('method', 'GET');
$('#commentForm').submit();
}
});
bootbox.confirm(_CONFIRM, function(result) {
if (result) {
$('#commentForm').attr('action', _CONTEXT + '/protect.knowledge/delete_comment/' + $('#commentNo').val());
$('#commentForm').attr('method', 'GET');
$('#commentForm').submit();
}
});
};

var removeAddedFile = function(fileNo) {
var url = _CONTEXT + '/protect.file/delete';
$.ajax({
type : 'GET',
url : url,
data : 'fileNo=' + fileNo,
success : function(data, dataType) {
$.notify(_REMOVE_FILE, 'info');
$('#file-' + fileNo).remove();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
//alert("error: " + textStatus);
$.notify(_FAIL_REMOVE_FILE, 'warn');
}
});
var url = _CONTEXT + '/protect.file/delete';
$.ajax({
type : 'GET',
url : url,
data : 'fileNo=' + fileNo,
success : function(data, dataType) {
$.notify(_REMOVE_FILE, 'info');
$('#file-' + fileNo).remove();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
//alert("error: " + textStatus);
$.notify(_FAIL_REMOVE_FILE, 'warn');
}
});
};

var setImagePath = function(url, name) {
var text = '\n![' + name + '](' + url + ')\n';
var textarea = $('#comment');
textarea.val(textarea.val() + text);
var text = '\n![' + name + '](' + url + ')\n';
var textarea = $('#comment');
textarea.val(textarea.val() + text);
}

3 changes: 3 additions & 0 deletions src/main/webapp/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ function insertAtCaret(target, str) {
obj.get(0).setSelectionRange(np, np);
}
}
function isString(obj) {
return typeof (obj) == "string" || obj instanceof String;
};
Loading

0 comments on commit 9be7797

Please sign in to comment.