|
490 | 490 | return true;
|
491 | 491 | }
|
492 | 492 |
|
| 493 | + function _toggleBlock(editor, type, start_chars, end_chars) { |
| 494 | + if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className)) |
| 495 | + return; |
| 496 | + |
| 497 | + end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars; |
| 498 | + var cm = editor.codemirror; |
| 499 | + var stat = getState(cm); |
| 500 | + |
| 501 | + var text; |
| 502 | + var start = start_chars; |
| 503 | + var end = end_chars; |
| 504 | + |
| 505 | + var startPoint = cm.getCursor('start'); |
| 506 | + var endPoint = cm.getCursor('end'); |
| 507 | + |
| 508 | + if (stat[type]) { |
| 509 | + text = cm.getLine(startPoint.line); |
| 510 | + start = text.slice(0, startPoint.ch); |
| 511 | + end = text.slice(startPoint.ch); |
| 512 | + if (type == 'bold') { |
| 513 | + start = start.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/, ''); |
| 514 | + end = end.replace(/(\*\*|__)/, ''); |
| 515 | + } else if (type == 'italic') { |
| 516 | + start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, ''); |
| 517 | + end = end.replace(/(\*|_)/, ''); |
| 518 | + } else if (type == 'strikethrough') { |
| 519 | + start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, ''); |
| 520 | + end = end.replace(/(\*\*|~~)/, ''); |
| 521 | + } |
| 522 | + cm.replaceRange(start + end, { |
| 523 | + line: startPoint.line, |
| 524 | + ch: 0, |
| 525 | + }, { |
| 526 | + line: startPoint.line, |
| 527 | + ch: 99999999999999, |
| 528 | + }); |
| 529 | + |
| 530 | + if (type == 'bold' || type == 'strikethrough') { |
| 531 | + startPoint.ch -= 2; |
| 532 | + if (startPoint !== endPoint) { |
| 533 | + endPoint.ch -= 2; |
| 534 | + } |
| 535 | + } else if (type == 'italic') { |
| 536 | + startPoint.ch -= 1; |
| 537 | + if (startPoint !== endPoint) { |
| 538 | + endPoint.ch -= 1; |
| 539 | + } |
| 540 | + } |
| 541 | + } else { |
| 542 | + text = cm.getSelection(); |
| 543 | + if (type == 'bold') { |
| 544 | + text = text.split('**').join(''); |
| 545 | + //text = text.split('__').join(''); |
| 546 | + } else if (type == 'italic') { |
| 547 | + text = text.split('*').join(''); |
| 548 | + // text = text.split('_').join(''); |
| 549 | + } else if (type == 'strikethrough') { |
| 550 | + text = text.split('~~').join(''); |
| 551 | + } |
| 552 | + cm.replaceSelection(start + text + end); |
| 553 | + |
| 554 | + startPoint.ch += start_chars.length; |
| 555 | + endPoint.ch = startPoint.ch + text.length; |
| 556 | + } |
| 557 | + |
| 558 | + cm.setSelection(startPoint, endPoint); |
| 559 | + cm.focus(); |
| 560 | + } |
493 | 561 | /**
|
494 | 562 | * Initialize editor on the page.
|
495 | 563 | *
|
|
507 | 575 | placeholder: '',
|
508 | 576 | element: $currentEditableTextarea[0],
|
509 | 577 | hintOptions: { hint: topcoderHandles },
|
510 |
| - toolbar: ["bold", "italic", "strikethrough", "|", |
| 578 | + toolbar: [{ name: "bold", |
| 579 | + action: function format(editor) { |
| 580 | + _toggleBlock(editor, 'bold', editor.options.blockStyles.bold); |
| 581 | + }, |
| 582 | + className: 'fa fa-bold', |
| 583 | + title: 'Bold', |
| 584 | + } |
| 585 | + , { name: "italic", |
| 586 | + action: function format(editor) { |
| 587 | + _toggleBlock(editor, 'italic', editor.options.blockStyles.italic); |
| 588 | + }, |
| 589 | + className: 'fa fa-italic', |
| 590 | + title: 'Italic', |
| 591 | + } |
| 592 | + , "strikethrough", "|", |
511 | 593 | "heading-1", "heading-2", "heading-3", "|", "code", "quote", "|", "unordered-list",
|
512 | 594 | "ordered-list", "clean-block", "|", {
|
513 | 595 | name: "mentions",
|
|
609 | 691 | } else if(text.length > maxCommentLength) {
|
610 | 692 | $(editorContainer).addClass('error');
|
611 | 693 | var count = text.length - maxCommentLength;
|
612 |
| - $(messageContainer).text('Comment is '+ count + ' characters too long'); |
| 694 | + if($(frm).find('#Form_CommentID').length > 0) { |
| 695 | + $(messageContainer).text('Comment is '+ count + ' characters too long'); |
| 696 | + } else if($(frm).find('#Form_DiscussionID').length > 0) { |
| 697 | + $(messageContainer).text('Discussion is '+ count + ' characters too long'); |
| 698 | + } else { |
| 699 | + $(messageContainer).text('Text is '+ count + ' characters too long'); |
| 700 | + } |
| 701 | + |
613 | 702 | $(frm).find(':submit').attr('disabled', 'disabled');
|
614 | 703 | $(frm).find('.Buttons a.Button:not(.Cancel)').addClass('Disabled');
|
615 | 704 | }
|
|
0 commit comments