|
1 | 1 | (function($) {
|
| 2 | + var editor; |
2 | 3 | $.fn.setAsEditor = function(selector) {
|
3 | 4 | selector = selector || '.BodyBox,.js-bodybox';
|
4 | 5 |
|
|
194 | 195 | var formData = new FormData();
|
195 | 196 | formData.append('file', file);
|
196 | 197 |
|
| 198 | + var $element = self.element; |
| 199 | + var postForm = $element.closest('form'); |
| 200 | + var commentId = $(postForm).find('#Form_CommentID').val(); |
| 201 | + var discussionId = $(postForm).find('#Form_DiscussionID').val(); |
| 202 | + var categoryId = $(postForm).find('#Form_CategoryID').val(); |
| 203 | + var actionType = $(postForm).find('#Form_ActionType').val(); |
| 204 | + if(actionType != null) { |
| 205 | + formData.append('actionType', actionType); |
| 206 | + } |
| 207 | + if(categoryId != null) { |
| 208 | + formData.append('categoryID', categoryId); |
| 209 | + } |
| 210 | + if(commentId != null) { |
| 211 | + formData.append('commentID', commentId); |
| 212 | + } |
| 213 | + if(discussionId != null) { |
| 214 | + formData.append('discussionID', discussionId); |
| 215 | + } |
| 216 | + |
197 | 217 | var request = new XMLHttpRequest();
|
198 | 218 | request.upload.onprogress = function (event) {
|
199 | 219 | if (event.lengthComputable) {
|
|
453 | 473 | var $currentEditableTextarea = $(textareaObj);
|
454 | 474 | if ($currentEditableTextarea.length) {
|
455 | 475 | // instantiate new editor
|
456 |
| - var editor = new EasyMDE({ |
| 476 | + editor = new EasyMDE({ |
457 | 477 | shortcuts: {
|
458 | 478 | "mentions": "Ctrl-Space",
|
459 | 479 | },
|
|
472 | 492 | className: "fa fa-at",
|
473 | 493 | title: "Mention a Topcoder User",
|
474 | 494 |
|
475 |
| - }, "link", canUpload ? 'upload-image' : "image", "table", "horizontal-rule", "|", "fullscreen", "|", "guide"], |
476 |
| - hideIcons: ["guide", "heading", "preview", "side-by-side"], |
| 495 | + }, "link","upload-image" , "image", "table", "horizontal-rule", "|", "fullscreen", "|", "guide"], |
| 496 | + hideIcons: canUpload ? ["guide", "heading", "preview", "side-by-side"]: ["guide", "heading", "preview", "side-by-side", "upload-image"], |
477 | 497 | insertTexts: {
|
478 | 498 | link: ['[', '](#url#)'],
|
479 | 499 | image: [''],
|
|
493 | 513 | sbOnUploaded: 'Uploaded #image_name#',
|
494 | 514 | sizeUnits: ' B, KB, MB',
|
495 | 515 | },
|
496 |
| - uploadImage: canUpload, |
497 |
| - imageMaxSize: maxUploadSize, //Maximum image size in bytes |
498 |
| - imageAccept: allowedFileMimeTypeWithExts, //A comma-separated list of mime-types and extensions |
499 |
| - imageUploadFunction: customUploadImage, |
500 |
| - beforeUploadingImagesFunction: beforeUploadingImages, |
501 |
| - errorCallback: errorCallback,// A callback function used to define how to display an error message. |
502 |
| - errorMessages: { |
| 516 | + uploadImage: canUpload, |
| 517 | + imageMaxSize: maxUploadSize, //Maximum image size in bytes |
| 518 | + imageAccept: allowedFileMimeTypeWithExts, //A comma-separated list of mime-types and extensions |
| 519 | + imageUploadFunction: customUploadImage, |
| 520 | + beforeUploadingImagesFunction: beforeUploadingImages, |
| 521 | + errorCallback: errorCallback,// A callback function used to define how to display an error message. |
| 522 | + errorMessages: { |
503 | 523 | noFileGiven: 'Select a file.',
|
504 | 524 | typeNotAllowed: 'Uploading #image_name# was failed. The file type (#image_type#) is not supported.',
|
505 | 525 | fileTooLarge: 'Uploading #image_name# was failed. The file is too big (#image_size#).\n' +
|
|
557 | 577 | }
|
558 | 578 | // Multiple editors are supported on a page
|
559 | 579 | $('.BodyBox[format="Markdown"], .BodyBox[format="wysiwyg"],.js-bodybox[format="Markdown"], .js-bodybox[format="wysiwyg"]', e.target).setAsEditor();
|
| 580 | + var categorySelect = $(this).find('#DiscussionForm select'); |
| 581 | + if(categorySelect.length) { |
| 582 | + var selectedOption = categorySelect.find('option:selected'); |
| 583 | + var uploads = selectedOption.attr("uploads"); |
| 584 | + editor.enableUploadImages(uploads === "1"); |
| 585 | + } |
| 586 | + editor.updateToolbar(); |
| 587 | + }); |
| 588 | + |
| 589 | + $(document).on('change','#DiscussionForm select', function() { |
| 590 | + var element = $(this).find('option:selected'); |
| 591 | + var categoryID = element.val(); |
| 592 | + if($(this).id != '#Form_CategoryID') { |
| 593 | + var postForm = $(element).closest('form'); |
| 594 | + $(postForm).find('#Form_CategoryID').val(categoryID); |
| 595 | + } |
| 596 | + var uploads = element.attr("uploads"); |
| 597 | + editor.enableUploadImages(uploads === "1"); |
560 | 598 | });
|
561 | 599 |
|
562 | 600 | // Preview mode
|
|
0 commit comments