|
1 | 1 | jQuery(document).ready(function() { |
2 | | - Omeka.wysiwyg(params); |
3 | | - updateFootnotes(); |
| 2 | + displayFootnotes(); |
4 | 3 | }); |
5 | 4 |
|
6 | 5 | jQuery(window).load(function() { |
7 | | - Omeka.wysiwyg(params); |
8 | | - updateFootnotes(); |
| 6 | + displayFootnotes(); |
9 | 7 | }); |
10 | 8 |
|
11 | | -params = { |
12 | | - toolbar: [ |
13 | | - "bold italic underline | alignleft aligncenter alignright | bullist numlist | link formatselect | code ", |
14 | | - "addFootnoteButton | deleteFootnotesButton | updateFootnotesButton | addTranscriptionLinkButton" |
15 | | -], |
16 | | - setup: function (editor) { |
17 | | - editor.addButton('addFootnoteButton', { |
18 | | - text: 'Add Footnote', |
19 | | - onclick: function () { |
20 | | - // Add the new footnote link |
21 | | - var tinymceBody = getTinyMCEDOMObject(); |
22 | | - addFootnoteLinkClassToFootnoteLinks(tinymceBody); |
23 | | - updateFootnotes(); |
24 | | - var fnNextNum = getFnNextNum(tinymceBody); |
25 | | - addNewFootnoteLink(editor, fnNextNum); |
26 | | - var tinymceBody = getTinyMCEDOMObject(); |
27 | | - // Add the new footnote citation |
28 | | - if(getNumberOfFootnoteDivs(tinymceBody) == 0){ |
29 | | - addFootnoteDiv(tinymceBody); |
30 | | - } |
31 | | - addFootnoteCitation(tinymceBody, fnNextNum); |
32 | | - // Move cursor to bottom of the editor |
33 | | - tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true); |
34 | | - tinyMCE.activeEditor.selection.collapse(false); |
35 | | - updateFootnotes(); |
36 | | - } |
37 | | - }); |
38 | | - editor.addButton('updateFootnotesButton', { |
39 | | - text: 'Update Footnotes', |
40 | | - onclick: function () { |
41 | | - var currentTinymceBody = getTinyMCEDOMObject(); |
42 | | - if(!(currentTinymceBody.getAttribute("data-id").toString().includes("block"))){ |
43 | | - alert("Click inside the box you are editing before using buttons."); |
44 | | - } else{ |
| 9 | +function displayFootnotes() { |
| 10 | + var selector; |
| 11 | + if (jQuery('#simple-pages-use-tiny-mce').is(':checked')) { |
| 12 | + selector = '#simple-pages-text'; |
| 13 | + } else if (jQuery('#simple-pages-use-tiny-mce').is(":not(:checked)")) { |
| 14 | + selector = false; |
| 15 | + } else { |
| 16 | + selector = 'textarea'; |
| 17 | + } |
| 18 | + params = { |
| 19 | + selector: selector, |
| 20 | + menubar: 'edit view insert format table', |
| 21 | + toolbar: [ |
| 22 | + "bold italic underline | alignleft aligncenter alignright | bullist numlist | link formatselect | code ", |
| 23 | + "addFootnoteButton | deleteFootnotesButton | updateFootnotesButton" |
| 24 | + ], |
| 25 | + setup: function (editor) { |
| 26 | + editor.addButton('addFootnoteButton', { |
| 27 | + text: 'Add Footnote', |
| 28 | + onclick: function () { |
| 29 | + // Add the new footnote link |
| 30 | + var tinymceBody = getTinyMCEDOMObject(); |
| 31 | + addFootnoteLinkClassToFootnoteLinks(tinymceBody); |
| 32 | + updateFootnotes(); |
| 33 | + var fnNextNum = getFnNextNum(tinymceBody); |
| 34 | + addNewFootnoteLink(editor, fnNextNum); |
| 35 | + var tinymceBody = getTinyMCEDOMObject(); |
| 36 | + // Add the new footnote citation |
| 37 | + if(getNumberOfFootnoteDivs(tinymceBody) == 0){ |
| 38 | + addFootnoteDiv(tinymceBody); |
| 39 | + } |
| 40 | + addFootnoteCitation(tinymceBody, fnNextNum); |
| 41 | + // Move cursor to bottom of the editor |
| 42 | + tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true); |
| 43 | + tinyMCE.activeEditor.selection.collapse(false); |
45 | 44 | updateFootnotes(); |
46 | 45 | } |
47 | | - } |
48 | | - }); |
49 | | - editor.addButton('deleteFootnotesButton', { |
50 | | - text: 'Delete Selected Footnotes', |
| 46 | + }); |
| 47 | + editor.addButton('updateFootnotesButton', { |
| 48 | + text: 'Update Footnotes', |
51 | 49 | onclick: function () { |
52 | 50 | updateFootnotes(); |
53 | | - var tinymceBody = getTinyMCEDOMObject(); |
54 | | - node = editor.selection.getNode(); |
55 | | - parent = node.parentNode; |
56 | | - var selectedHTML = editor.selection.getContent({format : 'html'}).toString(); |
57 | | - if(selectedHTML.length <= 1){ |
58 | | - //if the highlighted text is the single number of the footnote, the outerHTML will let us access the whole node. |
59 | | - //Note: we can't just use the single number of innerHTML because then any time someone highlights a regular text number, |
60 | | - // the footnote with that number will be deleted |
61 | | - selectedHTML = editor.selection.getNode().outerHTML.toString(); |
62 | | - } |
63 | | - var idsFootnotesToDelete = getListOfFootnotesToDelete(selectedHTML); |
64 | | - var fnLinks = getFnLinks(tinymceBody); |
65 | | - var fnCitations = getFnCitations(tinymceBody); |
66 | | - for(j = 0; j < idsFootnotesToDelete.length; j++){ |
67 | | - var fnLinkIDs = getFnLinkIDs(fnLinks); |
68 | | - var indexDel = fnLinkIDs.indexOf(idsFootnotesToDelete[j]); |
69 | | - fnLinkToDelete = fnLinks.item(indexDel); |
70 | | - fnLinkParent = fnLinkToDelete.parentNode; |
71 | | - fnLinkParent.removeChild(fnLinkToDelete); |
72 | | - if(fnCitations.length == 1){ |
73 | | - tinymceBody.removeChild(getExistingFootnoteDiv(tinymceBody)); |
74 | | - } else { |
75 | | - fnCitToDelete = fnCitations.item(indexDel); |
76 | | - fnCitParent = fnCitToDelete.parentNode; |
77 | | - fnCitParent.removeChild(fnCitToDelete); |
| 51 | + } |
| 52 | + }); |
| 53 | + editor.addButton('deleteFootnotesButton', { |
| 54 | + text: 'Delete Selected Footnotes', |
| 55 | + onclick: function () { |
| 56 | + updateFootnotes(); |
| 57 | + var tinymceBody = getTinyMCEDOMObject(); |
| 58 | + node = editor.selection.getNode(); |
| 59 | + parent = node.parentNode; |
| 60 | + var selectedHTML = editor.selection.getContent({format : 'html'}).toString(); |
| 61 | + if(selectedHTML.length <= 1){ |
| 62 | + //if the highlighted text is the single number of the footnote, the outerHTML will let us access the whole node. |
| 63 | + //Note: we can't just use the single number of innerHTML because then any time someone highlights a regular text number, |
| 64 | + // the footnote with that number will be deleted |
| 65 | + selectedHTML = editor.selection.getNode().outerHTML.toString(); |
78 | 66 | } |
79 | | - } |
80 | | - updateFootnotes(); |
81 | | - } |
82 | | - }); |
83 | | - editor.addButton('addTranscriptionLinkButton', { |
84 | | - text: 'Add Transcription Link', |
85 | | - onclick: function () { |
86 | | - var tinymceBody = getTinyMCEDOMObject(); |
87 | | - editor.insertContent("<p><a class='show-transcription' href='#'>Show Transcription</a></p>"); |
88 | | - } |
89 | | - }); |
90 | | - }, |
| 67 | + var idsFootnotesToDelete = getListOfFootnotesToDelete(selectedHTML); |
| 68 | + var fnLinks = getFnLinks(tinymceBody); |
| 69 | + var fnCitations = getFnCitations(tinymceBody); |
| 70 | + for(j = 0; j < idsFootnotesToDelete.length; j++){ |
| 71 | + var fnLinkIDs = getFnLinkIDs(fnLinks); |
| 72 | + var indexDel = fnLinkIDs.indexOf(idsFootnotesToDelete[j]); |
| 73 | + fnLinkToDelete = fnLinks.item(indexDel); |
| 74 | + fnLinkParent = fnLinkToDelete.parentNode; |
| 75 | + fnLinkParent.removeChild(fnLinkToDelete); |
| 76 | + if(fnCitations.length == 1){ |
| 77 | + tinymceBody.removeChild(getExistingFootnoteDiv(tinymceBody)); |
| 78 | + } else { |
| 79 | + fnCitToDelete = fnCitations.item(indexDel); |
| 80 | + fnCitParent = fnCitToDelete.parentNode; |
| 81 | + fnCitParent.removeChild(fnCitToDelete); |
| 82 | + } |
| 83 | + } |
| 84 | + updateFootnotes(); |
| 85 | + } |
| 86 | + }); |
| 87 | + }, |
| 88 | + } |
| 89 | + if (typeof tinyMCE != "undefined") { |
| 90 | + tinyMCE.remove(); |
| 91 | + } |
| 92 | + Omeka.wysiwyg(params); |
| 93 | + updateFootnotes(); |
| 94 | + |
| 95 | + // adds footnote functionality to new exhibit builder text blocks |
| 96 | + jQuery(document).on('exhibit-builder-refresh-wysiwyg', function () { |
| 97 | + Omeka.wysiwyg(params); |
| 98 | + updateFootnotes(); |
| 99 | + }); |
91 | 100 | } |
92 | 101 |
|
93 | 102 | function getListOfFootnotesToDelete(selectedHTML){ |
@@ -243,7 +252,7 @@ function getLinkHTML(fnNextNum){ |
243 | 252 | var str4 = fnNextNum.toString(); |
244 | 253 | var str5 = '">'; |
245 | 254 | var str6 = fnNextNum.toString(); |
246 | | - var str7 = '</a></sup>'; |
| 255 | + var str7 = '</a></sup> '; |
247 | 256 | var linkHTML = str1.concat(str2).concat(str3).concat(str4).concat(str5).concat(str6).concat(str7); |
248 | 257 | return linkHTML; |
249 | 258 | } |
|
0 commit comments