Skip to content

Commit

Permalink
Update references when a biblioentry is removed #97
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Spinaci authored and Gianmarco Spinaci committed Jun 23, 2017
1 parent 753f194 commit bfe040c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
49 changes: 29 additions & 20 deletions sources/raje/app/js/rajemce/plugin/raje_crossref.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ tinymce.PluginManager.add('raje_crossref', function (editor, url) {
}
})

editor.on('nodeChange', function (e) {
$('span.cgen[data-rash-original-content]').each(function () {

let position = $(this).text().replace('[', '').replace(']', '')
let id =

$(this).replaceWith(`<a>${$(this).attr('data-rash-original-content')}</a>`)
})
})

crossref = {
getAllReferenceableSections: function () {
let sections = []
Expand Down Expand Up @@ -273,14 +263,14 @@ function references() {
footnote_element.parent("section[role=doc-endnotes], section[role=doc-footnotes]").length > 0) {
var count = $(current_id).prevAll("section").length + 1;
if (prev_el.find("sup").hasClass("fn")) {
$(this).before("<sup class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"\">,</sup>");
$(this).before("<sup class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"\">,</sup>");
}
$(this).html("<sup class=\"fn cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content + "\">" +
$(this).html("<sup class=\"fn cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content + "\">" +
"<a name=\"fn_pointer_" + current_id.replace("#", "") +
"\" title=\"Footnote " + count + ": " +
$(current_id).text().replace(/\s+/g, " ").trim() + "\">" + count + "</a></sup>");
} else {
$(this).html("<span class=\"error cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"error cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">ERR: footnote '" + current_id.replace("#", "") + "' does not exist</span>");
}
/* Common sections */
Expand All @@ -289,47 +279,66 @@ function references() {
"section:not([role=doc-abstract]):not([role=doc-bibliography]):" +
"not([role=doc-endnotes]):not([role=doc-footnotes]):not([role=doc-acknowledgements])");
if (cur_count != null && cur_count != "") {
$(this).html("<span class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">Section " + cur_count + "</span>");
}
/* Reference to figure boxes */
} else if (referenced_element_figure.length > 0) {
var cur_count = referenced_element_figure.findNumber(figurebox_selector);
if (cur_count != 0) {
$(this).html("<span class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">Figure " + cur_count + "</span>");
}
/* Reference to table boxes */
} else if (referenced_element_table.length > 0) {
var cur_count = referenced_element_table.findNumber(tablebox_selector);
if (cur_count != 0) {
$(this).html("<span class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">Table " + cur_count + "</span>");
}
/* Reference to formula boxes */
} else if (referenced_element_formula.length > 0) {
var cur_count = referenced_element_formula.findNumber(formulabox_selector);
if (cur_count != 0) {
$(this).html("<span class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">Formula " + cur_count + "</span>");
}
/* Reference to listing boxes */
} else if (referenced_element_listing.length > 0) {
var cur_count = referenced_element_listing.findNumber(listingbox_selector);
if (cur_count != 0) {
$(this).html("<span class=\"cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">Listing " + cur_count + "</span>");
}
} else {
$(this).html("<span class=\"error cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).html("<span class=\"error cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">ERR: referenced element '" + cur_id.replace("#", "") +
"' has not the correct type (it should be either a figure, a table, a formula, a listing, or a section)</span>");
}
} else {
$(this).replaceWith("<span class=\"error cgen\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
$(this).replaceWith("<span class=\"error cgen\" contenteditable=\"false\" data-rash-original-reference=\"" + original_reference + "\" data-rash-original-content=\"" + original_content +
"\">ERR: referenced element '" + cur_id.replace("#", "") + "' does not exist</span>");
}
}
});
/* /END References */
}

function updateReferences() {
tinymce.triggerSave()

if ($('span.cgen[data-rash-original-reference]').length) {

// Restore all saved content
$('span.cgen[data-rash-original-reference]').each(function () {

// Save original content and reference
let original_content = $(this).attr('data-rash-original-content')
let original_reference = $(this).attr('data-rash-original-reference')

$(this).replaceWith(`<a href="${original_reference}">${original_content}</a>`)
})

references()
}
}
7 changes: 4 additions & 3 deletions sources/raje/app/js/rajemce/plugin/raje_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ tinymce.PluginManager.add('raje_section', function (editor, url) {
tinymce.activeEditor.undoManager.transact(function () {
tinymce.activeEditor.execCommand('delete')
section.updateBibliographySection()
updateReferences()

// update iframe
updateIframeFromSavedContent()
})

return false
Expand Down Expand Up @@ -741,9 +745,6 @@ section = {
$(`${BIBLIOENTRY_SELECTOR}:not(:has(p))`).each(function () {
$(this).remove()
})

// update iframe
updateIframeFromSavedContent()
},

/**
Expand Down

0 comments on commit bfe040c

Please sign in to comment.