Blogging Module - prettier settings added and js files reformatted

pull/4706/head
Ahmet Çotur 5 years ago
parent f2032ff7a4
commit 2606520715

@ -0,0 +1,4 @@
{
"singleQuote": true,
"useTabs": true
}

@ -1,14 +1,12 @@
var abp = abp || {};
$(function () {
abp.modals.blogCreate = function () {
var initModal = function (publicApi, args) {
var $form = publicApi.getForm();
abp.modals.blogCreate = function () {
var initModal = function (publicApi, args) {
var $form = publicApi.getForm();
};
};
return {
initModal: initModal
}
};
});
return {
initModal: initModal,
};
};
});

@ -1,14 +1,12 @@
var abp = abp || {};
$(function () {
abp.modals.blogEdit = function () {
var initModal = function (publicApi, args) {
var $form = publicApi.getForm();
abp.modals.blogEdit = function () {
var initModal = function (publicApi, args) {
var $form = publicApi.getForm();
};
};
return {
initModal: initModal
}
};
});
return {
initModal: initModal,
};
};
});

@ -1,82 +1,88 @@
$(function () {
var l = abp.localization.getResource('Blogging');
var _createModal = new abp.ModalManager(
abp.appPath + 'Blogging/Admin/Blogs/Create'
);
var _editModal = new abp.ModalManager(
abp.appPath + 'Blogging/Admin/Blogs/Edit'
);
var l = abp.localization.getResource('Blogging');
var _createModal = new abp.ModalManager(abp.appPath + 'Blogging/Admin/Blogs/Create');
var _editModal = new abp.ModalManager(abp.appPath + 'Blogging/Admin/Blogs/Edit');
var _dataTable = $('#BlogsTable').DataTable(
abp.libs.datatables.normalizeConfiguration({
processing: true,
serverSide: true,
paging: false,
info: false,
scrollX: true,
searching: false,
autoWidth: false,
scrollCollapse: true,
order: [[3, 'desc']],
ajax: abp.libs.datatables.createAjax(
volo.blogging.admin.blogManagement.getList
),
columnDefs: [
{
rowAction: {
items: [
{
text: l('Edit'),
visible: abp.auth.isGranted('Blogging.Blog.Update'),
action: function (data) {
_editModal.open({
blogId: data.record.id,
});
},
},
{
text: l('Delete'),
visible: abp.auth.isGranted('Blogging.Blog.Delete'),
confirmMessage: function (data) {
return l('BlogDeletionWarningMessage');
},
action: function (data) {
volo.blogging.admin.blogManagement
.delete(data.record.id)
.then(function () {
_dataTable.ajax.reload();
});
},
},
],
},
},
{
target: 1,
data: 'name',
},
{
target: 2,
data: 'shortName',
},
{
target: 3,
data: 'creationTime',
render: function (date) {
return date;
},
},
{
target: 4,
data: 'description',
},
],
})
);
var _dataTable = $('#BlogsTable').DataTable(abp.libs.datatables.normalizeConfiguration({
processing: true,
serverSide: true,
paging: false,
info: false,
scrollX: true,
searching: false,
autoWidth: false,
scrollCollapse: true,
order: [[3, "desc"]],
ajax: abp.libs.datatables.createAjax(volo.blogging.admin.blogManagement.getList),
columnDefs: [
{
rowAction: {
items:
[
{
text: l('Edit'),
visible: abp.auth.isGranted('Blogging.Blog.Update'),
action: function (data) {
_editModal.open({
blogId: data.record.id
});
}
},
{
text: l('Delete'),
visible: abp.auth.isGranted('Blogging.Blog.Delete'),
confirmMessage: function (data) { return l('BlogDeletionWarningMessage') },
action: function (data) {
volo.blogging.admin.blogManagement
.delete(data.record.id)
.then(function () {
_dataTable.ajax.reload();
});
}
}
]
}
},
{
target: 1,
data: "name"
},
{
target: 2,
data: "shortName"
},
{
target: 3,
data: "creationTime",
render: function (date) {
return date;
}
},
{
target: 4,
data: "description"
}
]
}));
$('#CreateNewBlogButtonId').click(function () {
_createModal.open();
});
_createModal.onClose(function () {
_dataTable.ajax.reload();
});
$("#CreateNewBlogButtonId").click(function () {
_createModal.open();
});
_createModal.onClose(function () {
_dataTable.ajax.reload();
});
_editModal.onResult(function () {
_dataTable.ajax.reload();
});
_editModal.onResult(function () {
_dataTable.ajax.reload();
});
});

@ -1,170 +1,184 @@
(function ($) {
var l = abp.localization.getResource('Blogging');
var initSocialShareLinks = function () {
var re = new RegExp(/^.*\//);
var rootUrl = re.exec(window.location.href);
var pageHeader = $("#PostTitle").text();
var blogName = $('#BlogFullName').attr('name');
$('#TwitterShareLink').attr('href',
'https://twitter.com/intent/tweet?text=' + encodeURI(pageHeader + " | " + blogName + " | " + window.location.href)
);
$('#LinkedinShareLink').attr('href',
'https://www.linkedin.com/shareArticle?'
+ 'url=' + encodeURI(window.location.href) + '&'
+ 'mini=true&'
+ "summary=" + encodeURI(blogName) + '&'
+ "title=" + encodeURI(pageHeader) + '&'
+ "source=" + encodeURI(rootUrl)
);
$('#EmailShareLink').attr('href',
'mailto:?'
+ 'body=' + encodeURI('I want you to look at ' + window.location.href) + '&'
+ "subject=" + encodeURI(pageHeader + ' | ' + blogName) + '&'
);
};
$('div .replyForm').hide();
$('div .editForm').hide();
$('form[class="editFormClass"]').submit(function (event) {
event.preventDefault();
var form = $(this).serializeFormToObject();
$.ajax({
type: "POST",
url: "/Blog/Comments/Update",
data: {
id: form.commentId,
commentDto: {
text: form.text
}
},
success: function (response) {
$('div .editForm').hide();
$('#' + form.commentId).text(form.text);
}
});
});
$('.editCancelButton').click(function (event) {
event.preventDefault();
$('div .editForm').hide();
});
$('.replyCancelButton').click(function (event) {
event.preventDefault();
$('div .replyForm').hide();
});
$('.replyLink').click(function (event) {
event.preventDefault();
$('div .editForm').hide();
var linkElement = $(this);
var replyCommentId = linkElement.attr('data-relpyid');
if (replyCommentId != '' && replyCommentId !== undefined) {
var div = linkElement.parent().next();
if (div.is(":hidden")) {
$('div .replyForm').hide();
div.show();
} else {
div.hide();
}
return;
}
});
$('.deleteLink').click(function (event) {
event.preventDefault();
var linkElement = $(this);
var deleteCommentId = linkElement.attr('data-deleteid');
if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm(
l('CommentDeletionWarningMessage'), // TODO: localize
l('Are you sure?'),
function (isConfirmed) {
if (isConfirmed) {
$.ajax({
type: "POST",
url: "/Blog/Comments/Delete",
data: { id: deleteCommentId },
success: function (response) {
linkElement.parent().parent().parent().remove();
}
});
}
}
);
}
});
$('#DeletePostLink').click(function (event) {
event.preventDefault();
var linkElement = $(this);
var deleteCommentId = linkElement.attr('data-postid');
var blogShortName = linkElement.attr('data-blogShortName');
if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm(
l('PostDeletionWarningMessage'),
l('AreYouSure'),
function (isConfirmed) {
if (isConfirmed) {
$.ajax({
type: "POST",
url: "/Blog/Posts/Delete",
data: { id: deleteCommentId },
success: function () {
var url = window.location.pathname;
var postNameBeginning = url.lastIndexOf('/');
window.location.replace(url.substring(0, postNameBeginning));
}
});
}
}
);
}
});
$('.updateLink').click(function (event) {
event.preventDefault();
$('div .replyForm').hide();
var linkElement = $(this);
var updateCommentId = $(this).attr('data-updateid');
if (updateCommentId != '' && updateCommentId !== undefined) {
var div = linkElement.parent().next().next();
if (div.is(":hidden")) {
$('div .editForm').hide();
div.show();
} else {
div.hide();
}
return;
}
});
if ($('#FocusCommentId').val() != '00000000-0000-0000-0000-000000000000') {
$('html, body').animate({
scrollTop: ($('#' + $('#FocusCommentId').val()).offset().top - 150)
}, 500);
}
$(".post-content a[href^='http']").attr('target', '_blank');
initSocialShareLinks();
var l = abp.localization.getResource('Blogging');
var initSocialShareLinks = function () {
var re = new RegExp(/^.*\//);
var rootUrl = re.exec(window.location.href);
var pageHeader = $('#PostTitle').text();
var blogName = $('#BlogFullName').attr('name');
$('#TwitterShareLink').attr(
'href',
'https://twitter.com/intent/tweet?text=' +
encodeURI(pageHeader + ' | ' + blogName + ' | ' + window.location.href)
);
$('#LinkedinShareLink').attr(
'href',
'https://www.linkedin.com/shareArticle?' +
'url=' +
encodeURI(window.location.href) +
'&' +
'mini=true&' +
'summary=' +
encodeURI(blogName) +
'&' +
'title=' +
encodeURI(pageHeader) +
'&' +
'source=' +
encodeURI(rootUrl)
);
$('#EmailShareLink').attr(
'href',
'mailto:?' +
'body=' +
encodeURI('I want you to look at ' + window.location.href) +
'&' +
'subject=' +
encodeURI(pageHeader + ' | ' + blogName) +
'&'
);
};
$('div .replyForm').hide();
$('div .editForm').hide();
$('form[class="editFormClass"]').submit(function (event) {
event.preventDefault();
var form = $(this).serializeFormToObject();
$.ajax({
type: 'POST',
url: '/Blog/Comments/Update',
data: {
id: form.commentId,
commentDto: {
text: form.text,
},
},
success: function (response) {
$('div .editForm').hide();
$('#' + form.commentId).text(form.text);
},
});
});
$('.editCancelButton').click(function (event) {
event.preventDefault();
$('div .editForm').hide();
});
$('.replyCancelButton').click(function (event) {
event.preventDefault();
$('div .replyForm').hide();
});
$('.replyLink').click(function (event) {
event.preventDefault();
$('div .editForm').hide();
var linkElement = $(this);
var replyCommentId = linkElement.attr('data-relpyid');
if (replyCommentId != '' && replyCommentId !== undefined) {
var div = linkElement.parent().next();
if (div.is(':hidden')) {
$('div .replyForm').hide();
div.show();
} else {
div.hide();
}
return;
}
});
$('.deleteLink').click(function (event) {
event.preventDefault();
var linkElement = $(this);
var deleteCommentId = linkElement.attr('data-deleteid');
if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm(
l('CommentDeletionWarningMessage'), // TODO: localize
l('Are you sure?'),
function (isConfirmed) {
if (isConfirmed) {
$.ajax({
type: 'POST',
url: '/Blog/Comments/Delete',
data: { id: deleteCommentId },
success: function (response) {
linkElement.parent().parent().parent().remove();
},
});
}
}
);
}
});
$('#DeletePostLink').click(function (event) {
event.preventDefault();
var linkElement = $(this);
var deleteCommentId = linkElement.attr('data-postid');
var blogShortName = linkElement.attr('data-blogShortName');
if (deleteCommentId != '' && deleteCommentId !== undefined) {
abp.message.confirm(
l('PostDeletionWarningMessage'),
l('AreYouSure'),
function (isConfirmed) {
if (isConfirmed) {
$.ajax({
type: 'POST',
url: '/Blog/Posts/Delete',
data: { id: deleteCommentId },
success: function () {
var url = window.location.pathname;
var postNameBeginning = url.lastIndexOf('/');
window.location.replace(url.substring(0, postNameBeginning));
},
});
}
}
);
}
});
$('.updateLink').click(function (event) {
event.preventDefault();
$('div .replyForm').hide();
var linkElement = $(this);
var updateCommentId = $(this).attr('data-updateid');
if (updateCommentId != '' && updateCommentId !== undefined) {
var div = linkElement.parent().next().next();
if (div.is(':hidden')) {
$('div .editForm').hide();
div.show();
} else {
div.hide();
}
return;
}
});
if ($('#FocusCommentId').val() != '00000000-0000-0000-0000-000000000000') {
$('html, body').animate(
{
scrollTop: $('#' + $('#FocusCommentId').val()).offset().top - 150,
},
500
);
}
$(".post-content a[href^='http']").attr('target', '_blank');
initSocialShareLinks();
})(jQuery);

@ -1,127 +1,124 @@
$(function () {
var $container = $("#edit-post-container");
var $editorContainer = $container.find(".edit-post-editor");
var $submitButton = $container.find("button[type=submit]");
var $form = $container.find("form#edit-post-form");
var editorDataKey = "tuiEditor";
var $titleLengthWarning = $("#title-length-warning");
var maxTitleLength = parseInt($titleLengthWarning.data("max-length"));
var $title = $('#Post_Title');
var $coverImage = $("#CoverImage");
var $postCoverImage = $('#Post_CoverImage');
var $coverImageFile = $('#CoverImageFile');
var $postFormSubmitButton = $('#PostFormSubmitButton');
var setCoverImage = function (file) {
$postCoverImage.val(file.fileUrl);
$coverImage.attr("src", file.fileUrl);
$postFormSubmitButton.removeAttr('disabled');
};
var uploadCoverImage = function (file) {
var formData = new FormData();
formData.append('file', file);
$.ajax({
type: "POST",
url: "/api/blogging/files/images/upload",
data: formData,
contentType: false,
processData: false,
success: function (response) {
setCoverImage(response);
}
});
};
var checkTitleLength = function () {
var title = $title.val();
if (title.length > maxTitleLength) {
$titleLengthWarning.show();
} else {
$titleLengthWarning.hide();
}
};
checkTitleLength();
$title.on("change paste keyup", function () {
checkTitleLength();
});
$coverImageFile.change(function () {
if (!$coverImageFile.prop('files').length) {
return;
}
$postFormSubmitButton.attr('disabled',true);
var file = $coverImageFile.prop('files')[0];
uploadCoverImage(file);
});
var uploadImage = function (file, callbackFn) {
var formData = new FormData();
formData.append('file', file);
$.ajax({
type: "POST",
url: "/api/blogging/files/images/upload",
data: formData,
contentType: false,
processData: false,
success: function (response) {
callbackFn(response.fileUrl);
}
});
};
var newPostEditor = $editorContainer.tuiEditor({
usageStatistics: false,
initialEditType: 'markdown',
previewStyle: 'tab',
height: "auto",
initialValue: $form.find("input[name='Post.Content']").val(),
hooks: {
addImageBlobHook: function (blob, callback, source) {
var imageAltText = blob.name;
uploadImage(blob,
function (fileUrl) {
callback(fileUrl, imageAltText);
});
}
},
events: {
load: function () {
$editorContainer.find(".loading-cover").remove();
$submitButton.prop("disabled", false);
$form.data("validator").settings.ignore = '.ignore';
$editorContainer.find(':input').addClass('ignore');
}
}
}).data(editorDataKey);
$container.find("form#edit-post-form").submit(function (e) {
var $postTextInput = $form.find("input[name='Post.Content']");
var postText = newPostEditor.getMarkdown();
$postTextInput.val(postText);
if (!$form.valid()) {
var validationResult = $form.validate();
abp.message.warn(validationResult.errorList[0].message); //TODO: errors can be merged into lines. make sweetalert accept HTML.
e.preventDefault();
return false; //for old browsers
}
$submitButton.buttonBusy();
$(this).off('submit').submit();
return true;
});
var $container = $('#edit-post-container');
var $editorContainer = $container.find('.edit-post-editor');
var $submitButton = $container.find('button[type=submit]');
var $form = $container.find('form#edit-post-form');
var editorDataKey = 'tuiEditor';
var $titleLengthWarning = $('#title-length-warning');
var maxTitleLength = parseInt($titleLengthWarning.data('max-length'));
var $title = $('#Post_Title');
var $coverImage = $('#CoverImage');
var $postCoverImage = $('#Post_CoverImage');
var $coverImageFile = $('#CoverImageFile');
var $postFormSubmitButton = $('#PostFormSubmitButton');
var setCoverImage = function (file) {
$postCoverImage.val(file.fileUrl);
$coverImage.attr('src', file.fileUrl);
$postFormSubmitButton.removeAttr('disabled');
};
var uploadCoverImage = function (file) {
var formData = new FormData();
formData.append('file', file);
$.ajax({
type: 'POST',
url: '/api/blogging/files/images/upload',
data: formData,
contentType: false,
processData: false,
success: function (response) {
setCoverImage(response);
},
});
};
var checkTitleLength = function () {
var title = $title.val();
if (title.length > maxTitleLength) {
$titleLengthWarning.show();
} else {
$titleLengthWarning.hide();
}
};
checkTitleLength();
$title.on('change paste keyup', function () {
checkTitleLength();
});
$coverImageFile.change(function () {
if (!$coverImageFile.prop('files').length) {
return;
}
$postFormSubmitButton.attr('disabled', true);
var file = $coverImageFile.prop('files')[0];
uploadCoverImage(file);
});
var uploadImage = function (file, callbackFn) {
var formData = new FormData();
formData.append('file', file);
$.ajax({
type: 'POST',
url: '/api/blogging/files/images/upload',
data: formData,
contentType: false,
processData: false,
success: function (response) {
callbackFn(response.fileUrl);
},
});
};
var newPostEditor = $editorContainer
.tuiEditor({
usageStatistics: false,
initialEditType: 'markdown',
previewStyle: 'tab',
height: 'auto',
initialValue: $form.find("input[name='Post.Content']").val(),
hooks: {
addImageBlobHook: function (blob, callback, source) {
var imageAltText = blob.name;
uploadImage(blob, function (fileUrl) {
callback(fileUrl, imageAltText);
});
},
},
events: {
load: function () {
$editorContainer.find('.loading-cover').remove();
$submitButton.prop('disabled', false);
$form.data('validator').settings.ignore = '.ignore';
$editorContainer.find(':input').addClass('ignore');
},
},
})
.data(editorDataKey);
$container.find('form#edit-post-form').submit(function (e) {
var $postTextInput = $form.find("input[name='Post.Content']");
var postText = newPostEditor.getMarkdown();
$postTextInput.val(postText);
if (!$form.valid()) {
var validationResult = $form.validate();
abp.message.warn(validationResult.errorList[0].message); //TODO: errors can be merged into lines. make sweetalert accept HTML.
e.preventDefault();
return false; //for old browsers
}
$submitButton.buttonBusy();
$(this).off('submit').submit();
return true;
});
});

@ -1,67 +1,67 @@
(function() {
function handleArrows() {
var herosWidth = $(".hero-articles").width();
var arrowsPosition = (herosWidth / 2 - 90);
$(".owl-next").css("right", arrowsPosition);
$(".owl-prev").css("left", arrowsPosition);
}
(function () {
function handleArrows() {
var herosWidth = $('.hero-articles').width();
var arrowsPosition = herosWidth / 2 - 90;
$('.owl-next').css('right', arrowsPosition);
$('.owl-prev').css('left', arrowsPosition);
}
function handleImages() {
//if ($(window).width() > 767) {
// $(".box-articles .img-container").each(function () {
// var squareWidth = $(this).width();
// $(this).css("height", squareWidth);
// });
//}
//else {
// $(".box-articles .img-container").css("height", "auto");
//}
}
function handleImages() {
//if ($(window).width() > 767) {
// $(".box-articles .img-container").each(function () {
// var squareWidth = $(this).width();
// $(this).css("height", squareWidth);
// });
//}
//else {
// $(".box-articles .img-container").css("height", "auto");
//}
}
function handleOwlCarousel() {
$('.hero-section .owl-carousel').owlCarousel({
loop: true,
margin: 0,
nav: false,
dots: false,
//center: true,
autoplay: true,
autoHeight: true,
autoplaySpeed: 1000,
items: 1,
});
$('.card-article-container .owl-carousel').owlCarousel({
loop: true,
margin: 0,
nav: false,
dots: false,
autoplay: true,
autoplaySpeed: 1000,
responsive: {
0: {
items: 1
}
}
});
}
function handleOwlCarousel() {
$('.hero-section .owl-carousel').owlCarousel({
loop: true,
margin: 0,
nav: false,
dots: false,
//center: true,
autoplay: true,
autoHeight: true,
autoplaySpeed: 1000,
items: 1,
});
$('.card-article-container .owl-carousel').owlCarousel({
loop: true,
margin: 0,
nav: false,
dots: false,
autoplay: true,
autoplaySpeed: 1000,
responsive: {
0: {
items: 1,
},
},
});
}
$(function () {
handleImages();
handleOwlCarousel();
$(function () {
handleImages();
handleOwlCarousel();
$(".nav-link").on("click", function () {
$(this).parent().parent();
});
$('.nav-link').on('click', function () {
$(this).parent().parent();
});
$(window).resize(function () {
setTimeout(function () {
handleArrows();
handleImages();
}, 500);
});
$(window).resize(function () {
setTimeout(function () {
handleArrows();
handleImages();
}, 500);
});
setTimeout(function () {
handleArrows();
}, 500);
});
})();
setTimeout(function () {
handleArrows();
}, 500);
});
})();

Loading…
Cancel
Save