mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 05:18:01 +08:00
(fix) TinyMCE issues - Code samples & Wide tables [SCI-10076]
This commit is contained in:
parent
4a13476b90
commit
7c4e4a8ee7
5 changed files with 57 additions and 20 deletions
|
@ -8,7 +8,6 @@
|
||||||
// Currently selected row in "load from protocol" modal
|
// Currently selected row in "load from protocol" modal
|
||||||
var selectedRow = null;
|
var selectedRow = null;
|
||||||
|
|
||||||
|
|
||||||
function initEditMyModuleDescription() {
|
function initEditMyModuleDescription() {
|
||||||
var viewObject = $('#my_module_description_view');
|
var viewObject = $('#my_module_description_view');
|
||||||
viewObject.on('click', function(e) {
|
viewObject.on('click', function(e) {
|
||||||
|
@ -361,3 +360,11 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
const viewMode = new URLSearchParams(window.location.search).get('view_mode');
|
||||||
|
if (viewMode === 'archived') {
|
||||||
|
setTimeout(() => {
|
||||||
|
const notesContainerEl = document.getElementById('notes-container');
|
||||||
|
window.wrapTables(notesContainerEl);
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
|
@ -135,3 +135,30 @@ $.fn.initSubmitModal = function(modalID, modelName) {
|
||||||
})
|
})
|
||||||
.animateSpinner();
|
.animateSpinner();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps tables in HTML with a specified wrapper.
|
||||||
|
* @param {string || Element} htmlStringOrDomEl - HTML containing tables to be wrapped.
|
||||||
|
* @returns {string} - HTML with tables wrapped.
|
||||||
|
*/
|
||||||
|
function wrapTables(htmlStringOrDomEl) {
|
||||||
|
if (typeof htmlStringOrDomEl === 'string') {
|
||||||
|
const container = $(`<span class="text-base">${htmlStringOrDomEl}</span>`);
|
||||||
|
container.find('table').toArray().forEach((table) => {
|
||||||
|
if ($(table).parent().hasClass('table-wrapper')) return;
|
||||||
|
$(table).css('float', 'none').wrapAll(`
|
||||||
|
<div class="table-wrapper" style="overflow: auto; width: 100%"></div>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
return container.prop('outerHTML');
|
||||||
|
}
|
||||||
|
// Check if the value is a DOM element
|
||||||
|
if (htmlStringOrDomEl instanceof Element) {
|
||||||
|
const tableElement = $(htmlStringOrDomEl).find('table');
|
||||||
|
if (tableElement.length > 0) {
|
||||||
|
tableElement.wrap('<div class="table-wrapper" style="overflow: auto; width: 100%"></div>');
|
||||||
|
const updatedHtml = $(htmlStringOrDomEl).html();
|
||||||
|
$(htmlStringOrDomEl).replaceWith(updatedHtml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,12 @@ import { mountWithTurbolinks } from '../helpers/turbolinks.js';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.initDateTimePickerComponent = (id) => {
|
window.initDateTimePickerComponent = (id) => {
|
||||||
|
const elementWithIdPresent = document.querySelector(id);
|
||||||
|
if (!elementWithIdPresent) {
|
||||||
|
console.warn("datetime_picker.js -> window.initDateTimePickerComponent: couldn't find element with id: ", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const app = createApp({
|
const app = createApp({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -78,4 +84,4 @@ document.addEventListener('turbolinks:load', () => {
|
||||||
dateTimePickers.forEach((dateTimePicker) => {
|
dateTimePickers.forEach((dateTimePicker) => {
|
||||||
window.initDateTimePickerComponent(`#${dateTimePicker.id}`);
|
window.initDateTimePickerComponent(`#${dateTimePicker.id}`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
@update="updateDescription"
|
@update="updateDescription"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="protocol.attributes.description_view" v-html="protocol.attributes.description_view"></div>
|
<div v-else-if="protocol.attributes.description_view" v-html="wrappedTables" class="view-text-element"></div>
|
||||||
<div v-else class="empty-protocol-description">
|
<div v-else class="empty-protocol-description">
|
||||||
{{ i18n.t("protocols.no_text_placeholder") }}
|
{{ i18n.t("protocols.no_text_placeholder") }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -252,6 +252,9 @@ export default {
|
||||||
},
|
},
|
||||||
mixins: [UtilsMixin, stackableHeadersMixin, moduleNameObserver, AssetPasteMixin],
|
mixins: [UtilsMixin, stackableHeadersMixin, moduleNameObserver, AssetPasteMixin],
|
||||||
computed: {
|
computed: {
|
||||||
|
wrappedTables() {
|
||||||
|
return window.wrapTables(this.protocol.attributes.description_view);
|
||||||
|
},
|
||||||
inRepository() {
|
inRepository() {
|
||||||
return this.protocol.attributes.in_repository;
|
return this.protocol.attributes.in_repository;
|
||||||
},
|
},
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
@editingDisabled="disableEditMode"
|
@editingDisabled="disableEditMode"
|
||||||
@editingEnabled="enableEditMode"
|
@editingEnabled="enableEditMode"
|
||||||
/>
|
/>
|
||||||
<div class="view-text-element" v-else-if="element.attributes.orderable.text_view" v-html="wrapTables"></div>
|
<div class="view-text-element" v-else-if="element.attributes.orderable.text_view" v-html="wrappedTables"></div>
|
||||||
<div v-else class="text-sn-grey">
|
<div v-else class="text-sn-grey">
|
||||||
{{ i18n.t("protocols.steps.text.empty_text") }}
|
{{ i18n.t("protocols.steps.text.empty_text") }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -108,21 +108,18 @@ export default {
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
this.enableEditMode();
|
this.enableEditMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.highlightText();
|
const textElements = document.querySelectorAll('.view-text-element');
|
||||||
|
if (textElements.length > 0) {
|
||||||
|
textElements.forEach((textElement) => {
|
||||||
|
this.highlightText(textElement);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
wrapTables() {
|
wrappedTables() {
|
||||||
const container = $(`<span class="text-base">${this.element.attributes.orderable.text_view}</span>`);
|
return window.wrapTables(this.element.attributes.orderable.text_view);
|
||||||
container.find('table').toArray().forEach((table) => {
|
|
||||||
if ($(table).parent().hasClass('table-wrapper')) return;
|
|
||||||
$(table).css('float', 'none').wrapAll(`
|
|
||||||
<div class="table-wrapper" style="overflow: auto; width: 100%"></div>
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
return container.prop('outerHTML');
|
|
||||||
},
|
},
|
||||||
actionMenu() {
|
actionMenu() {
|
||||||
const menu = [];
|
const menu = [];
|
||||||
|
@ -184,11 +181,8 @@ export default {
|
||||||
this.element.attributes.orderable.updated_at = data.attributes.updated_at;
|
this.element.attributes.orderable.updated_at = data.attributes.updated_at;
|
||||||
this.$emit('update', this.element, true);
|
this.$emit('update', this.element, true);
|
||||||
},
|
},
|
||||||
highlightText() {
|
highlightText(textElToHighlight) {
|
||||||
const textElement = $('.results-list')[0];
|
Prism.highlightAllUnder(textElToHighlight);
|
||||||
if (textElement) {
|
|
||||||
Prism.highlightAllUnder(textElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue