From 2dae0327c4fb10dc227eacb15e32bb6e0259c474 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Mon, 16 Sep 2019 18:36:43 +0200 Subject: [PATCH] WUP Updating script for plugin system --- main.js | 71 +++++++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 53 deletions(-) diff --git a/main.js b/main.js index e9d9ebb..dfdc848 100644 --- a/main.js +++ b/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 = ''; - for(let oznaka_tip in this.oznake) { + for(let oznaka_tip in constants.oznake) { result += ``; } result += ''; @@ -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 = ``; @@ -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($(`*`)); } @@ -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 += `
${key}