WUP Updating script for plugin system
This commit is contained in:
parent
44ef555b56
commit
2dae0327c4
71
main.js
71
main.js
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
var _code = {
|
||||
prevodi: [],
|
||||
zgledi: [],
|
||||
vecjez: [],
|
||||
|
@ -7,24 +7,9 @@ xml: null,
|
|||
original: null,
|
||||
freq_start: null,
|
||||
|
||||
prevod_locations: [
|
||||
'pomen > vecjez',
|
||||
'pomen > skladenjske_skupine > skladenjska_struktura > kolokacije > vecjez',
|
||||
'pomen > stalne_zveze > stalna_zveza > vecjez',
|
||||
'skladenjske_zveze > skladenjska_zveza > vecjez',
|
||||
'frazeoloske_zveze > frazeoloska_enota > vecjez',
|
||||
'pomen > podpomen > skladenjske_skupine > skladenjska_struktura > kolokacije > vecjez'
|
||||
],
|
||||
zgledi_locations: [
|
||||
'zgledi > vecjez',
|
||||
'zgledi'
|
||||
],
|
||||
oznake: OZNAKE_JSON,
|
||||
freq_stars_limits: [0, 552, 5206, 8613, 22561],
|
||||
|
||||
empty_prevod: function() {
|
||||
var result = '<prevod>';
|
||||
for(let oznaka_tip in this.oznake) {
|
||||
for(let oznaka_tip in constants.oznake) {
|
||||
result += `<oznaka tip="${ oznaka_tip }"></oznaka>`;
|
||||
}
|
||||
result += '<tekst></tekst><vir></vir></prevod>';
|
||||
|
@ -36,12 +21,12 @@ storeXml: function(xml) {
|
|||
for(let loznaka of xml.find("prevod > oznaka")) {
|
||||
var oznaka = $(loznaka);
|
||||
var tip = oznaka.attr('tip');
|
||||
if (!(tip in this.oznake)) {
|
||||
if (!(tip in constants.oznake)) {
|
||||
oznaka.attr('tip', 'star');
|
||||
}
|
||||
}
|
||||
|
||||
for(let fstring of this.prevod_locations) {
|
||||
for(let fstring of constants.prevod_locations) {
|
||||
for(let vecjez of xml.find(fstring)) {
|
||||
for(let pp of $(vecjez).find('pp')) {
|
||||
$(pp).parent().attr('semicolon', 'true');
|
||||
|
@ -56,7 +41,7 @@ storeXml: function(xml) {
|
|||
prevod.attr('line_num', this.vecjez.length);
|
||||
prevod.attr('semicolon', prevod.attr('semicolon') || false);
|
||||
|
||||
for(let oznaka_tip in this.oznake) {
|
||||
for(let oznaka_tip in constants.oznake) {
|
||||
var old = prevod.find(`oznaka[tip="${ oznaka_tip }"]`);
|
||||
if(!old.length) {
|
||||
to_prepend = `<oznaka tip="${ oznaka_tip }"></oznaka>`;
|
||||
|
@ -72,7 +57,7 @@ storeXml: function(xml) {
|
|||
}
|
||||
}
|
||||
|
||||
for(let fstring of this.zgledi_locations) {
|
||||
for(let fstring of constants.zgledi_locations) {
|
||||
for(let zgledi of xml.find(fstring)) {
|
||||
for(let lzgled of $(zgledi).find('zgled')) {
|
||||
var zgled = $(lzgled);
|
||||
|
@ -113,31 +98,12 @@ storeXml: function(xml) {
|
|||
}
|
||||
}
|
||||
},
|
||||
loadDependencies: function(url) {
|
||||
this.loadJs("https://cdn.jsdelivr.net/npm/sweet-modal@1.3.2/dist/min/jquery.sweet-modal.min.js");
|
||||
this.loadCss('https://cdn.jsdelivr.net/npm/sweet-modal@1.3.2/dist/min/jquery.sweet-modal.min.css');
|
||||
},
|
||||
loadCss: function(url) {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
link.href = url;
|
||||
link.media = 'all';
|
||||
$('head').append(link);
|
||||
},
|
||||
loadJs: function(url) {
|
||||
var newscript = document.createElement('script');
|
||||
newscript.type = 'text/javascript';
|
||||
newscript.async = true;
|
||||
newscript.src = url;
|
||||
$('head').append(newscript);
|
||||
},
|
||||
render_freq_start: function() {
|
||||
var element = $("#myed-freq-start");
|
||||
var freq = element.attr("freq");
|
||||
element.text('FREKVENCA: ' + freq);
|
||||
/*
|
||||
for(let f_lim of this.freq_stars_limits) {
|
||||
for(let f_lim of constants.freq_stars_limits) {
|
||||
var cls = (f_lim > freq) ? "s0" : "s1";
|
||||
element.append($(`<span class=${ cls }>*</span>`));
|
||||
}
|
||||
|
@ -442,7 +408,6 @@ clanekOldCode: function() {
|
|||
$('.myed-zgled-prevod-btn').parent().toggle();
|
||||
},
|
||||
editor: function(div, entry, uneditable) {
|
||||
var xslt_content = new window.DOMParser().parseFromString(this.xslt, "text/xml");
|
||||
var xml = $($.parseXML(entry.content));
|
||||
|
||||
// for "dodajanje prevodov" we need a model div to copy.
|
||||
|
@ -455,7 +420,7 @@ editor: function(div, entry, uneditable) {
|
|||
sessionStorage.myed_original = entry.content;
|
||||
|
||||
var xsltProcessor = new XSLTProcessor();
|
||||
xsltProcessor.importStylesheet(xslt_content);
|
||||
xsltProcessor.importStylesheet(plugin_xslt);
|
||||
resultDocument = xsltProcessor.transformToFragment(xml[0], document);
|
||||
$(div).append(resultDocument);
|
||||
|
||||
|
@ -464,14 +429,8 @@ editor: function(div, entry, uneditable) {
|
|||
$('.myed-prevod-div').first().hide();
|
||||
xml.find('prevod').first().remove();
|
||||
|
||||
var styleTag = document.createElement('style');
|
||||
styleTag.type = 'text/css';
|
||||
styleTag.appendChild(document.createTextNode(this.css));
|
||||
document.head.appendChild(styleTag);
|
||||
|
||||
this.render_freq_start();
|
||||
this.clanekOldCode();
|
||||
this.loadDependencies();
|
||||
this.registerCallbacks();
|
||||
|
||||
// select nothing in all hamburger dropdowns
|
||||
|
@ -515,7 +474,7 @@ show_modal: function(prevedek, razlaga, oznake, callback) {
|
|||
}
|
||||
|
||||
var options = "";
|
||||
for(let [key, value] of Object.entries(this.oznake)) {
|
||||
for(let [key, value] of Object.entries(constants.oznake)) {
|
||||
options += `<div class='myed-oznaka-div'><span class="myed-oznaka-key">${key}</span> <select><option></option>`;
|
||||
for(let option of value) {
|
||||
var optStart = "<option";
|
||||
|
@ -556,7 +515,7 @@ show_modal: function(prevedek, razlaga, oznake, callback) {
|
|||
});
|
||||
},
|
||||
harvester: function(div) {
|
||||
for(let fstring of this.prevod_locations) {
|
||||
for(let fstring of constants.prevod_locations) {
|
||||
for(let vecjez of this.xml.find(fstring)) {
|
||||
for(let pp of $(vecjez).find('pp')) {
|
||||
$(pp).remove();
|
||||
|
@ -593,6 +552,12 @@ harvester: function(div) {
|
|||
|
||||
return (new XMLSerializer()).serializeToString(this.xml[0]);
|
||||
},
|
||||
xslt: XSLFILE,
|
||||
css: CSS,
|
||||
}
|
||||
|
||||
function plugin_render(div, entry) {
|
||||
_code.editor(div, entry, true);
|
||||
}
|
||||
|
||||
function plugin_save(div) {
|
||||
_code.harvester(div, entry, true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user