/usr/share/bibledit/edit/index.js is in bibledit-data 5.0.453-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | /*
Copyright (©) 2003-2017 Teus Benschop.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
var quill = undefined;
var Delta = Quill.import ("delta");
$ (document).ready (function ()
{
// Reposition the editor's menu so it never scrolls out of view.
var bar = $ ("#editorheader").remove ();
$ ("#workspacemenu").append (bar);
editorInitializeOnce ();
editorInitialize ();
navigationNewPassage ();
$ (window).on ("unload", editorUnload);
editorIdPollerTimeoutStart ();
editorBindUnselectable ();
$ ("#stylebutton").on ("click", editorStylesButtonHandler);
$ (window).on ("keydown", editorWindowKeyHandler);
positionCaretViaAjax ();
if (swipe_operations) {
$ ("body").swipe ( {
swipeLeft:function (event, direction, distance, duration, fingerCount, fingerData) {
editorSwipeLeft (event);
},
swipeRight:function (event, direction, distance, duration, fingerCount, fingerData) {
editorSwipeRight (event);
}
});
}
$ ("#editor").on ("click", editorNoteCitationClicked);
});
function editorInitializeOnce ()
{
var Parchment = Quill.import ('parchment');
// Register block formatting class.
var ParagraphClass = new Parchment.Attributor.Class ('paragraph', 'b', { scope: Parchment.Scope.BLOCK });
Quill.register (ParagraphClass, true);
// Register inline formatting class.
var CharacterClass = new Parchment.Attributor.Class ('character', 'i', { scope: Parchment.Scope.INLINE });
Quill.register (CharacterClass, true);
}
function editorInitialize ()
{
// Work around https://github.com/quilljs/quill/issues/1116
// It sets the margins to 0 by adding an overriding class.
// The Quill editor will remove that class again.
$ ("#editor > p").each (function (index) {
var element = $(this);
element.addClass ("nomargins");
});
// Instantiate editor.
quill = new Quill ('#editor', { });
// Cause it to paste plain text only.
quill.clipboard.addMatcher (Node.ELEMENT_NODE, function (node, delta) {
var plaintext = $ (node).text ();
return new Delta().insert (plaintext);
});
if (!quill.hasFocus ()) quill.focus ();
// Event handlers.
quill.on ("text-change", editorTextChangeHandler);
quill.on ("selection-change", editorSelectionChangeHandler);
}
/*
Section for the new Passage event from the Navigator.
*/
var editorNavigationBook;
var editorNavigationChapter;
var editorNavigationVerse;
function navigationNewPassage ()
{
if (typeof navigationBook != 'undefined') {
editorNavigationBook = navigationBook;
editorNavigationChapter = navigationChapter;
editorNavigationVerse = navigationVerse;
} else if (parent.window.navigationBook != 'undefined') {
editorNavigationBook = parent.window.navigationBook;
editorNavigationChapter = parent.window.navigationChapter;
editorNavigationVerse = parent.window.navigationVerse;
} else {
return;
}
if ((editorNavigationBook != editorLoadedBook) || (editorNavigationChapter != editorLoadedChapter)) {
editorSaveChapter ();
editorLoadChapter (false);
} else {
editorScheduleCaretPositioning ();
}
editorHighlightVerseNumber ();
}
/*
Section for editor load and save.
Notes:
* It remembers the Bible, book, and chapter loaded.
The reason for remembering these is, among others, that the active Bible / book / chapter
on the server may change due to user actions, so when saving this chapter to the server,
it passes the correct Bible / book / chapter to the server along with the updated text.
* While loading the chapter, do not set the "contenteditable" to false, then to true,
because Google Chrome gets confused then. This was seen on version 33.
Other types of browsers and other versions were not tested on this behaviour.
*/
var editorLoadedBible;
var editorLoadedBook;
var editorLoadedChapter;
var editorReferenceText;
var editorTextChanged = false;
var editorCaretPosition = 0;
var editorSaveAsync;
var editorSaving = false;
var editorWriteAccess = false;
function editorLoadChapter (reload)
{
editorLoadedBible = navigationBible;
editorLoadedBook = editorNavigationBook;
editorLoadedChapter = editorNavigationChapter;
editorChapterIdOnServer = 0;
editorCaretPosition = getCaretPosition ();
editorCaretInitialized = false;
$.ajax ({
url: "load",
type: "GET",
data: { bible: editorLoadedBible, book: editorLoadedBook, chapter: editorLoadedChapter },
success: function (response) {
// Set the editor read-write or read-only.
editorWriteAccess = checksum_readwrite (response);
// Checksumming.
response = checksum_receive (response);
if (response !== false) {
// Only load new text when it is different.
if (response != editorGetHtml ()) {
// Destroy existing editor.
if (quill) delete quill;
// Load the html in the DOM.
$ ("#editor").empty ();
$ ("#editor").append (response);
// Create the editor based on the DOM's content.
editorInitialize ();
quill.enable (editorWriteAccess);
// CSS for embedded styles.
css4embeddedstyles ();
// Feedback.
editorStatus (editorChapterLoaded);
}
// Reference for comparison at save time.
editorReferenceText = editorGetHtml ();
// Position caret straightaway.
if (reload) {
positionCaret (editorCaretPosition);
}
editorScheduleCaretPositioning ();
} else {
// Checksum error: Reload.
editorLoadChapter (false);
}
editorCaretInitialized = false;
},
});
}
function editorSaveChapter (sync)
{
if (editorSaving) {
editorContentChangedTimeoutStart ();
return;
}
if (!editorWriteAccess) return;
editorTextChanged = false;
if (!editorLoadedBible) return;
if (!editorLoadedBook) return;
var html = editorGetHtml ();
if (html == editorReferenceText) return;
editorStatus (editorChapterSaving);
editorReferenceText = html;
editorChapterIdOnServer = 0;
editorIdPollerTimeoutStop ();
editorSaveAsync = true;
if (sync) editorSaveAsync = false;
var encodedHtml = filter_url_plus_to_tag (html);
var checksum = checksum_get (encodedHtml);
editorSaving = true;
$.ajax ({
url: "save",
type: "POST",
async: editorSaveAsync,
data: { bible: editorLoadedBible, book: editorLoadedBook, chapter: editorLoadedChapter, html: encodedHtml, checksum: checksum },
success: function (response) {
editorStatus (response);
if (response == editorChapterReformat) {
editorLoadChapter (true);
}
},
error: function (jqXHR, textStatus, errorThrown) {
editorStatus (editorChapterRetrying);
editorReferenceText = "";
editorContentChanged ();
if (!editorSaveAsync) editorSaveChapter (true);
},
complete: function (xhr, status) {
editorIdPollerTimeoutStart ();
editorSaveAsync = true;
editorSaving = false;
},
});
}
function editorGetHtml ()
{
var html = $ (".ql-editor").html ();
// Remove verse focus class name, if it is:
// * the only class name.
html = html.split (' class="versebeam"').join ('');
// * between two more class names.
html = html.split (' versebeam ').join ('');
// * the first class name.
html = html.split ('versebeam ').join ('');
// * the last class name.
html = html.split (' versebeam').join ('');
// Remove class applied to caret.
html = html.split ('<span class="ql-cursor">' + String.fromCharCode(65279) + '</span>').join ('');
// Done.
return html;
}
/*
Portion dealing with triggers for editor's content change.
*/
var editorContentChangedTimeoutId;
// Arguments: delta: Delta, oldContents: Delta, source: String
function editorTextChangeHandler (delta, oldContents, source)
{
editorContentChanged ();
}
function editorContentChanged ()
{
if (!editorWriteAccess) return;
editorTextChanged = true;
editorStatus (editorWillSave);
editorContentChangedTimeoutStart ();
}
function editorContentChangedTimeoutStart ()
{
if (editorContentChangedTimeoutId) clearTimeout (editorContentChangedTimeoutId);
editorContentChangedTimeoutId = setTimeout (editorSaveChapter, 1000);
}
function editorUnload ()
{
editorSaveChapter (true);
}
/*
Section for polling the server for updates on the loaded chapter.
*/
var editorChapterIdOnServer = 0;
var editorChapterIdPollerTimeoutId;
function editorIdPollerTimeoutStart ()
{
editorIdPollerTimeoutStop ();
editorChapterIdPollerTimeoutId = setTimeout (editorEditorPollId, 1000);
}
function editorIdPollerTimeoutStop ()
{
if (editorChapterIdPollerTimeoutId) clearTimeout (editorChapterIdPollerTimeoutId);
}
function editorEditorPollId ()
{
$.ajax ({
url: "id",
type: "GET",
data: { bible: editorLoadedBible, book: editorLoadedBook, chapter: editorLoadedChapter },
success: function (response) {
if (!editorSaving) {
if (editorChapterIdOnServer != 0) {
if (response != editorChapterIdOnServer) {
editorLoadChapter (true);
editorChapterIdOnServer = 0;
}
}
editorChapterIdOnServer = response;
}
},
complete: function (xhr, status) {
editorIdPollerTimeoutStart ();
}
});
}
/*
Section responding to a moved caret.
*/
// Responds to a changed selection or caret.
// range: { index: Number, length: Number }
// oldRange: { index: Number, length: Number }
// source: String
function editorSelectionChangeHandler (range, oldRange, source)
{
editorHighlightVerseNumber ();
// Bail out if editor not focused.
if (!range) return;
// Bail out if text was selected.
if (range.length != 0) return;
editorCaretMovedTimeoutStart ();
}
var editorCaretMovedTimeoutId;
var editorCaretMovedAjaxRequest;
var editorCaretMovedAjaxOffset;
var editorCaretInitialized = false;
function editorCaretMovedTimeoutStart ()
{
if (editorCaretMovedTimeoutId) clearTimeout (editorCaretMovedTimeoutId);
editorCaretMovedTimeoutId = setTimeout (editorHandleCaretMoved, 200);
}
function editorHandleCaretMoved ()
{
// If the text in the editor has been changed, and therefore not saved,
// or is being saved now, postpone handling the moved caret.
// It is important to also delay the handler "while" the text is being saved,
// because there have been situations that javascript initiated the save operation,
// shortly after that the moved caret handler via AJAX,
// and that the server completed processing the caret handler before it had completed the save operations,
// which led to inaccurate caret position calculations, which caused symptoms like a "jumping caret".
if (editorTextChanged || editorSaving) {
editorCaretMovedTimeoutStart ();
return;
}
// If the caret has not yet been positioned, postpone the action.
if (!editorCaretInitialized) {
editorCaretMovedTimeoutStart ();
positionCaretViaAjax ();
return;
}
if (quill.hasFocus ()) {
// Cancel any previous ajax request that might still be incompleted.
// This is to avoid the caret jumping on slower or unstable connections.
if (editorCaretMovedAjaxRequest && editorCaretMovedAjaxRequest.readystate != 4) {
editorCaretMovedAjaxRequest.abort();
}
// Record the offset of the caret at the start of the ajax request.
editorCaretMovedAjaxOffset = getCaretPosition ();
// Initiate a new ajax request.
editorCaretMovedAjaxRequest = $.ajax ({
url: "navigate",
type: "GET",
data: { bible: editorLoadedBible, book: editorLoadedBook, chapter: editorLoadedChapter, offset: editorCaretMovedAjaxOffset },
success: function (response) {
if (response != "") {
var offset = getCaretPosition ();
// Take action only when the caret is still at the same position as it was when this ajax request was initiated.
if (offset == editorCaretMovedAjaxOffset) {
// Set the focused verse immediately,
// rather than waiting on the Navigator signal that likely will come later.
// This fixes a clicking / scrolling problem.
editorNavigationVerse = response;
editorScheduleWindowScrolling ();
editorHighlightVerseNumber ();
} else {
// Caret was moved during this AJAX operation: Reschedule it.
editorCaretMovedTimeoutStart ();
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
// On (network) failure, reschedule the update.
editorCaretMovedTimeoutStart ();
}
});
} else {
editorCaretMovedTimeoutStart ();
}
editorActiveStylesFeedback ();
}
/*
Section with window events and their basic handlers.
*/
function editorWindowKeyHandler (event)
{
if (!editorWriteAccess) return;
// Ctrl-S: Style.
if ((event.ctrlKey == true) && (event.keyCode == 83)) {
editorStylesButtonHandler ();
return false;
}
// Escape.
if (event.keyCode == 27) {
editorClearStyles ();
}
}
/*
Section for user interface updates and feedback.
*/
function editorStatus (text)
{
$ ("#editorstatus").empty ();
$ ("#editorstatus").append (text);
editorSelectiveNotification (text);
}
function editorActiveStylesFeedback ()
{
var caret = getCaretPosition ();
if (caret == undefined) return;
var format = quill.getFormat ();
var paragraph = "";
if (format.paragraph) paragraph = format.paragraph;
var character = "";
if (format.character) character = format.character;
if (character.search ("note") >= 0) character = "";
character = character.split ("0").join (" ");
var styles = paragraph + " " + character;
styles = styles.replace ("versebeam", "");
var element = $ ("#activestyles");
element.text (styles);
}
function editorSelectiveNotification (message)
{
if (message == editorChapterLoaded) return;
if (message == editorWillSave) return;
if (message == editorChapterSaving) return;
if (message == editorChapterSaved) return;
if (message == editorChapterReformat) return;
notifyItError (message);
}
/*
Section for getting and setting the caret position.
*/
function getCaretPosition ()
{
var position = undefined;
var range = quill.getSelection();
if (range) position = range.index;
return position;
}
function positionCaret (position)
{
if (position == undefined) return;
var currentPosition = getCaretPosition ();
if (currentPosition == undefined) return;
position = parseInt (position);
if (position == currentPosition) return;
quill.setSelection (position, 0, "silent");
editorActiveStylesFeedback ();
}
var editorPositionCaretViaAjaxTimerId;
function positionCaretViaAjax ()
{
// Very frequent positioning calls have been seen in some browsers, so they are filtered here.
if (editorPositionCaretViaAjaxTimerId) clearTimeout (editorPositionCaretViaAjaxTimerId);
editorPositionCaretViaAjaxTimerId = setTimeout (positionCaretViaAjaxExecute, 100);
}
function positionCaretViaAjaxExecute ()
{
if (isNoVerseBook (editorLoadedBook)) return;
$.ajax ({
url: "position",
type: "GET",
data: { bible: editorLoadedBible, book: editorLoadedBook, chapter: editorLoadedChapter },
success: function (response) {
if (response != "") {
response = response.split ("\n");
var start = response [0];
var end = response [1];
var offset = getCaretPosition ();
if ((offset < start) || (offset > end)) {
positionCaret (start);
}
editorCaretInitialized = true;
}
editorScheduleWindowScrolling ();
},
error: function (jqXHR, textStatus, errorThrown) {
// Network error: Reschedule.
editorScheduleCaretPositioning ();
}
});
}
/*
Section for highlighting the focused verse.
*/
var editorHighlightVerseNumberTimeoutId;
function editorHighlightVerseNumber ()
{
if (editorHighlightVerseNumberTimeoutId) clearTimeout (editorHighlightVerseNumberTimeoutId);
editorHighlightVerseNumberTimeoutId = setTimeout (editorHighlightVerseNumberExecute, 200);
}
function editorHighlightVerseNumberExecute ()
{
$ (".i-v").each (function (index) {
var element = $(this);
var verseNumber = element.text ();
if (verseNumber == editorNavigationVerse) {
element.addClass ("versebeam");
} else {
element.removeClass ("versebeam");
}
});
}
/*
Section for scrolling the caret into view.
*/
function editorScrollVerseIntoView ()
{
if (isNoVerseBook (editorLoadedBook)) return;
var position = getCaretPosition ();
if (position == undefined) return;
var bounds = quill.getBounds (position);
var workspaceHeight = $("#workspacewrapper").height();
var currentScrollTop = $("#workspacewrapper").scrollTop();
var scrollTo = bounds.top - (workspaceHeight / 2);
scrollTo = parseInt (scrollTo);
var lowerBoundary = currentScrollTop - (workspaceHeight / 10);
var upperBoundary = currentScrollTop + (workspaceHeight / 10);
if ((scrollTo < lowerBoundary) || (scrollTo > upperBoundary)) {
$("#workspacewrapper").animate({ scrollTop: scrollTo }, 500);
}
}
/*
Section for the styles handling.
*/
function editorStylesButtonHandler ()
{
if (!editorWriteAccess) return;
$.ajax ({
url: "styles",
type: "GET",
cache: false,
success: function (response) {
editorShowResponse (response);
editorBindUnselectable ();
dynamicClickHandlers ();
},
});
return false;
}
function editorBindUnselectable ()
{
var elements = $ (".unselectable");
elements.off ("mousedown");
elements.on ("mousedown", function (event) {
event.preventDefault();
});
}
function editorShowResponse (response)
{
if (!editorWriteAccess) return;
$ ("#stylebutton").hide ();
$ ("#nostyles").hide ();
var area = $ ("#stylesarea");
area.empty ();
area.append (response);
}
function editorClearStyles ()
{
var area = $ ("#stylesarea");
area.empty ();
$ ("#stylebutton").show ();
$ ("#nostyles").show ();
}
function dynamicClickHandlers ()
{
var elements = $ ("#stylesarea > a");
elements.on ("click", function (event) {
event.preventDefault();
editorClearStyles ();
//$ ("#editor").focus ();
var href = event.currentTarget.href;
href = href.substring (href.lastIndexOf ('/') + 1);
if (href == "cancel") return;
if (href == "all") {
displayAllStyles ();
} else {
requestStyle (href);
}
});
$ ("#styleslist").on ("change", function (event) {
var selection = $ ("#styleslist option:selected").text ();
var style = selection.substring (0, selection.indexOf (" "));
event.preventDefault();
editorClearStyles ();
//$ ("#editor").focus ();
requestStyle (style);
});
}
function requestStyle (style)
{
$.ajax ({
url: "styles",
type: "GET",
data: { style: style },
cache: false,
success: function (response) {
response = response.split ("\n");
var style = response [0];
var action = response [1];
if (action == "p") {
applyParagraphStyle (style);
} else if (action == 'c') {
applyCharacterStyle (style);
} else if (action == 'n') {
applyNotesStyle (style);
editorContentChanged ();
} else if (action == "m") {
applyMonoStyle (style);
editorContentChanged ();
}
},
});
}
function displayAllStyles ()
{
$.ajax ({
url: "styles",
type: "GET",
data: { all: "" },
cache: false,
success: function (response) {
editorShowResponse (response);
editorBindUnselectable ();
dynamicClickHandlers ();
},
});
}
function applyParagraphStyle (style)
{
if (!editorWriteAccess) return;
if (!quill.hasFocus ()) quill.focus ();
quill.format ("paragraph", style, "user");
editorActiveStylesFeedback ();
}
function applyCharacterStyle (style)
{
if (!editorWriteAccess) return;
if (!quill.hasFocus ()) quill.focus ();
// No formatting of a verse.
var range = quill.getSelection();
if (range) {
for (i = range.index; i < range.index + range.length; i++) {
var format = quill.getFormat (i);
if (format.character && format.character == "v") {
return;
}
}
}
// Apply style.
var format = quill.getFormat ();
style = editor_determine_character_style (format.character, style)
quill.format ("character", style, "user");
// Check on embedded style applied.
post_embedded_style_application (style);
// Feedback.
editorActiveStylesFeedback ();
}
function applyMonoStyle (style)
{
if (!editorWriteAccess) return;
quill.focus ();
var caret = getCaretPosition ();
var start = caret;
var text = quill.getText (start, 1);
if (text == "\n") caret--;
for (i = caret; i >= 0; i--) {
var text = quill.getText (i, 1);
if (text == "\n") break;
start = i;
}
var end = caret;
for (i = caret; true; i++) {
end = i;
var text = quill.getText (i, 1);
if (text == "\n") break;
}
text = quill.getText (start, end - start);
var char = text.substring (0, 1);
if (char == "\\") {
text = text.substring (1);
var pos = text.indexOf (' ');
text = text.substring (pos + 1);
}
text = "\\" + style + " " + text;
quill.deleteText (start, end - start);
quill.insertText (start, text, "paragraph", "mono");
editorActiveStylesFeedback ();
}
/*
Section for the notes.
*/
var editorInsertedNotesCount = 0;
function applyNotesStyle (style)
{
if (!editorWriteAccess) return;
quill.focus ();
// Check for and optionally append the gap between text body and notes.
var notes = $ (".b-notes");
if (notes.length == 0) {
var length = quill.getLength ();
quill.insertText (length, "\n", "paragraph", "notes", "user")
}
// Get a new note identifier.
var date = new Date();
var noteId = String (date.getTime());
var caller = String ((editorInsertedNotesCount % 9) + 1);
// Insert note caller at caret.
var caret = getCaretPosition ();
quill.setSelection (caret, 0);
quill.insertText (caret, caller, "character", "notecall" + noteId, "user");
// Append note text to notes section:
// <p class="b-f"><span class="i-notebody1">1</span> + .</p>
var length = quill.getLength ();
quill.insertText (length, "\n", "paragraph", style, "user");
quill.insertText (length, caller, "character", "notebody" + noteId, "user");
length++;
quill.insertText (length, " + .", "character", "", "user");
editorInsertedNotesCount++;
editorActiveStylesFeedback ();
}
function editorNoteCitationClicked (event)
{
var target = $(event.target);
var cls = target.attr ("class");
if (cls.substr (0, 6) != "i-note") return;
cls = cls.substr (2);
var length = quill.getLength ();
if (cls.search ("call") > 0) {
cls = cls.replace ("call", "body");
// Start searching for note bodies at the end.
for (i = length; i >= 0; i--) {
var format = quill.getFormat (i, 1);
if (format.character && format.character == cls) {
quill.setSelection (i + 4, 0);
editorScrollVerseIntoView ();
editorActiveStylesFeedback ();
return;
}
}
}
if (cls.search ("body") > 0) {
cls = cls.replace ("body", "call");
// Start searching for note callers at the start.
for (i = 0; i < length; i++) {
var format = quill.getFormat (i, 1);
if (format.character && format.character == cls) {
quill.setSelection (i + 1, 0);
editorScrollVerseIntoView ();
editorActiveStylesFeedback ();
return;
}
}
}
}
/*
Caret positioning and subsequent window scrolling.
The purpose of this section is to coordinate the two events,
so that caret positioning is done first,
and window scrolling last.
*/
var editorPositioningTimerId;
var editorPendingCaretPositioning = false;
var editorPendingWindowScrolling = false;
function editorScheduleCaretPositioning ()
{
editorPendingCaretPositioning = true;
editorPendingWindowScrolling = false;
editorPositioningTimerStart ();
}
function editorScheduleWindowScrolling ()
{
editorPendingWindowScrolling = true;
editorPositioningTimerStart ();
}
function editorPositioningTimerStart ()
{
if (editorPositioningTimerId) clearTimeout (editorPositioningTimerId);
editorPositioningTimerId = setTimeout (editorPositioningRun, 200);
}
function editorPositioningRun ()
{
if (editorPendingCaretPositioning) {
positionCaretViaAjax ();
editorPendingCaretPositioning = false;
editorPendingWindowScrolling = false;
}
if (editorPendingWindowScrolling) {
editorPendingWindowScrolling = false;
editorScrollVerseIntoView ();
}
}
// Debug
function editorLog (msg)
{
var date = new Date();
var seconds = date.getSeconds();
var milliseconds = date.getMilliseconds();
console.log (seconds + " " + milliseconds + ": " + msg);
}
/*
Section for swipe navigation.
*/
function editorSwipeLeft (event)
{
if (typeof navigateNextChapter != 'undefined') {
navigateNextChapter (event);
} else if (parent.window.navigateNextChapter != 'undefined') {
parent.window.navigateNextChapter (event);
}
}
function editorSwipeRight (event)
{
if (typeof navigatePreviousChapter != 'undefined') {
navigatePreviousChapter (event);
} else if (parent.window.navigatePreviousChapter != 'undefined') {
parent.window.navigatePreviousChapter (event);
}
}
|