formatting js code to vim standards.
This commit is contained in:
parent
fbeff36687
commit
273fd25c06
296
vsms.js
296
vsms.js
|
@ -1,24 +1,24 @@
|
||||||
var _code = {
|
var plugin_code = {
|
||||||
prevodi: [],
|
prevodi: [],
|
||||||
zgledi: [],
|
zgledi: [],
|
||||||
vecjez: [],
|
vecjez: [],
|
||||||
indikatorji: [],
|
indikatorji: [],
|
||||||
xml: null,
|
xml: null,
|
||||||
original: null,
|
original: null,
|
||||||
freq_start: null,
|
freq_start: null,
|
||||||
|
|
||||||
empty_prevod: function() {
|
empty_prevod: function () {
|
||||||
var result = '<prevod>';
|
var result = '<prevod>';
|
||||||
for(let oznaka_tip in constants.oznake) {
|
for (let oznaka_tip in constants.oznake) {
|
||||||
result += `<oznaka tip="${ oznaka_tip }"></oznaka>`;
|
result += `<oznaka tip="${oznaka_tip}"></oznaka>`;
|
||||||
}
|
}
|
||||||
result += '<tekst></tekst><vir></vir></prevod>';
|
result += '<tekst></tekst><vir></vir></prevod>';
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
storeXml: function(xml) {
|
storeXml: function (xml) {
|
||||||
this.xml = xml;
|
this.xml = xml;
|
||||||
|
|
||||||
for(let loznaka of xml.find("prevod > oznaka")) {
|
for (let loznaka of xml.find("prevod > oznaka")) {
|
||||||
var oznaka = $(loznaka);
|
var oznaka = $(loznaka);
|
||||||
var tip = oznaka.attr('tip');
|
var tip = oznaka.attr('tip');
|
||||||
if (!(tip in constants.oznake)) {
|
if (!(tip in constants.oznake)) {
|
||||||
|
@ -26,30 +26,30 @@ storeXml: function(xml) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let fstring of constants.prevod_locations) {
|
for (let fstring of constants.prevod_locations) {
|
||||||
for(let vecjez of xml.find(fstring)) {
|
for (let vecjez of xml.find(fstring)) {
|
||||||
for(let pp of $(vecjez).find('pp')) {
|
for (let pp of $(vecjez).find('pp')) {
|
||||||
$(pp).parent().attr('semicolon', 'true');
|
$(pp).parent().attr('semicolon', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let lprevod of $(vecjez).find("prevod")) {
|
for (let lprevod of $(vecjez).find("prevod")) {
|
||||||
var prevod = $(lprevod);
|
var prevod = $(lprevod);
|
||||||
if(true) {
|
if (true) {
|
||||||
prevod.attr('prevod_id', this.prevodi.length);
|
prevod.attr('prevod_id', this.prevodi.length);
|
||||||
this.prevodi.push(prevod);
|
this.prevodi.push(prevod);
|
||||||
}
|
}
|
||||||
prevod.attr('line_num', this.vecjez.length);
|
prevod.attr('line_num', this.vecjez.length);
|
||||||
prevod.attr('semicolon', prevod.attr('semicolon') || false);
|
prevod.attr('semicolon', prevod.attr('semicolon') || false);
|
||||||
|
|
||||||
for(let oznaka_tip in constants.oznake) {
|
for (let oznaka_tip in constants.oznake) {
|
||||||
var old = prevod.find(`oznaka[tip="${ oznaka_tip }"]`);
|
var old = prevod.find(`oznaka[tip="${oznaka_tip}"]`);
|
||||||
if(!old.length) {
|
if (!old.length) {
|
||||||
to_prepend = `<oznaka tip="${ oznaka_tip }"></oznaka>`;
|
to_prepend = `<oznaka tip="${oznaka_tip}"></oznaka>`;
|
||||||
prevod.prepend($(to_prepend, xml));
|
prevod.prepend($(to_prepend, xml));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prevod.find('rzg').length == 0) {
|
if (prevod.find('rzg').length == 0) {
|
||||||
prevod.append($("<rzg />", xml));
|
prevod.append($("<rzg />", xml));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,26 +57,26 @@ storeXml: function(xml) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let fstring of constants.zgledi_locations) {
|
for (let fstring of constants.zgledi_locations) {
|
||||||
for(let zgledi of xml.find(fstring)) {
|
for (let zgledi of xml.find(fstring)) {
|
||||||
for(let lzgled of $(zgledi).find('zgled')) {
|
for (let lzgled of $(zgledi).find('zgled')) {
|
||||||
var zgled = $(lzgled);
|
var zgled = $(lzgled);
|
||||||
zgled.attr('jezik', zgled.attr('ime_korpusa') == "hunTenTen12" ? "hun" : "slo");
|
zgled.attr('jezik', zgled.attr('ime_korpusa') == "hunTenTen12" ? "hun" : "slo");
|
||||||
zgled.attr('zgled_id', this.zgledi.length);
|
zgled.attr('zgled_id', this.zgledi.length);
|
||||||
this.zgledi.push(zgled);
|
this.zgledi.push(zgled);
|
||||||
}
|
}
|
||||||
for(let lprevod of $(zgledi).find('prevod')) {
|
for (let lprevod of $(zgledi).find('prevod')) {
|
||||||
if(!$(lprevod).text().trim().length) {
|
if (!$(lprevod).text().trim().length) {
|
||||||
$(lprevod).remove();
|
$(lprevod).remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let lpomen of xml.find("pomen")) {
|
for (let lpomen of xml.find("pomen")) {
|
||||||
var pomen = $(lpomen);
|
var pomen = $(lpomen);
|
||||||
var indikator = pomen.children(':first');
|
var indikator = pomen.children(':first');
|
||||||
if(indikator.prop("tagName") != "indikator") {
|
if (indikator.prop("tagName") != "indikator") {
|
||||||
indikator = $(`<indikator />`, xml)
|
indikator = $(`<indikator />`, xml)
|
||||||
pomen.prepend(indikator);
|
pomen.prepend(indikator);
|
||||||
}
|
}
|
||||||
|
@ -86,19 +86,19 @@ storeXml: function(xml) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var opomba = xml.find('glava > opomba');
|
var opomba = xml.find('glava > opomba');
|
||||||
if(!opomba.length) {
|
if (!opomba.length) {
|
||||||
var zaglavje = xml.find('glava > zaglavje');
|
var zaglavje = xml.find('glava > zaglavje');
|
||||||
zaglavje.after($('<opomba></opomba>', xml));
|
zaglavje.after($('<opomba></opomba>', xml));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let lclanek of xml.find('clanek')) {
|
for (let lclanek of xml.find('clanek')) {
|
||||||
var clanek = $(lclanek);
|
var clanek = $(lclanek);
|
||||||
if(!clanek.find('status').length) {
|
if (!clanek.find('status').length) {
|
||||||
clanek.prepend($("<status>A-HU</status>", xml));
|
clanek.prepend($("<status>A-HU</status>", xml));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render_freq_start: function() {
|
render_freq_start: function () {
|
||||||
var element = $("#myed-freq-start");
|
var element = $("#myed-freq-start");
|
||||||
var freq = element.attr("freq");
|
var freq = element.attr("freq");
|
||||||
element.text('FREKVENCA: ' + freq);
|
element.text('FREKVENCA: ' + freq);
|
||||||
|
@ -108,73 +108,73 @@ render_freq_start: function() {
|
||||||
element.append($(`<span class=${ cls }>*</span>`));
|
element.append($(`<span class=${ cls }>*</span>`));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
},
|
},
|
||||||
isLast: function(el) {
|
isLast: function (el) {
|
||||||
return el.next().hasClass("myed-prevod-add") || el.next().hasClass('myed-prevod-bin');
|
return el.next().hasClass("myed-prevod-add") || el.next().hasClass('myed-prevod-bin');
|
||||||
},
|
},
|
||||||
isFirst: function(el) {
|
isFirst: function (el) {
|
||||||
return !el.prev().hasClass('myed-prevod-div') || el.prev().is(':hidden');
|
return !el.prev().hasClass('myed-prevod-div') || el.prev().is(':hidden');
|
||||||
},
|
},
|
||||||
moveLeft: function(el) {
|
moveLeft: function (el) {
|
||||||
if(!this.isFirst(el)) {
|
if (!this.isFirst(el)) {
|
||||||
var xml_el = this.prevodi[el.attr('prevod_id')];
|
var xml_el = this.prevodi[el.attr('prevod_id')];
|
||||||
|
|
||||||
el.prev().before(el);
|
el.prev().before(el);
|
||||||
xml_el.prev().before(xml_el);
|
xml_el.prev().before(xml_el);
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
moveRight: function(el) {
|
moveRight: function (el) {
|
||||||
if(el.next().length && !this.isLast(el)) {
|
if (el.next().length && !this.isLast(el)) {
|
||||||
var xml_el = this.prevodi[el.attr('prevod_id')];
|
var xml_el = this.prevodi[el.attr('prevod_id')];
|
||||||
|
|
||||||
el.next().after(el);
|
el.next().after(el);
|
||||||
xml_el.next().after(xml_el);
|
xml_el.next().after(xml_el);
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cut: function(el) {
|
cut: function (el) {
|
||||||
var xml_el = this.prevodi[el.attr('prevod_id')];
|
var xml_el = this.prevodi[el.attr('prevod_id')];
|
||||||
el.toggleClass('myed-prevod-cut');
|
el.toggleClass('myed-prevod-cut');
|
||||||
xml_el.attr('cut', el.hasClass('myed-prevod-cut'));
|
xml_el.attr('cut', el.hasClass('myed-prevod-cut'));
|
||||||
|
|
||||||
// move to end if cutted
|
// move to end if cutted
|
||||||
if(el.hasClass('myed-prevod-cut')) {
|
if (el.hasClass('myed-prevod-cut')) {
|
||||||
this.move_to_end(el);
|
this.move_to_end(el);
|
||||||
}
|
}
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
},
|
},
|
||||||
move_to_end: function(el) {
|
move_to_end: function (el) {
|
||||||
var xml_el = this.prevodi[el.attr('prevod_id')];
|
var xml_el = this.prevodi[el.attr('prevod_id')];
|
||||||
while(el.next().length && !this.isLast(el)) {
|
while (el.next().length && !this.isLast(el)) {
|
||||||
el.next().after(el);
|
el.next().after(el);
|
||||||
xml_el.next().after(xml_el);
|
xml_el.next().after(xml_el);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bin: function(el) {
|
bin: function (el) {
|
||||||
el.toggleClass('myed-prevod-bin');
|
el.toggleClass('myed-prevod-bin');
|
||||||
this.move_to_end(el);
|
this.move_to_end(el);
|
||||||
this.prevodi[el.attr('prevod_id')].attr('bin', el.hasClass('myed-prevod-bin'));
|
this.prevodi[el.attr('prevod_id')].attr('bin', el.hasClass('myed-prevod-bin'));
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
},
|
},
|
||||||
change: function(el, func_after) {
|
change: function (el, func_after) {
|
||||||
var text_el = el.find('.myed-prevod-text');
|
var text_el = el.find('.myed-prevod-text');
|
||||||
var razlaga_el = el.find('.myed-prevod-razlaga');
|
var razlaga_el = el.find('.myed-prevod-razlaga');
|
||||||
var oznake_el = el.find('.myed-oznaka').map(function() {
|
var oznake_el = el.find('.myed-oznaka').map(function () {
|
||||||
var result = $(this).text();
|
var result = $(this).text();
|
||||||
if(result.length)
|
if (result.length)
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.show_modal(text_el.text(), razlaga_el, oznake_el, function(status, data) {
|
self.show_modal(text_el.text(), razlaga_el, oznake_el, function (status, data) {
|
||||||
var text = data["prevedek"];
|
var text = data["prevedek"];
|
||||||
var razlaga = data['razlaga'];
|
var razlaga = data['razlaga'];
|
||||||
var razlaga_tax = data['razlaga_tax'];
|
var razlaga_tax = data['razlaga_tax'];
|
||||||
var deleteOld = data['remove_old'];
|
var deleteOld = data['remove_old'];
|
||||||
var oznake = data['oznake'];
|
var oznake = data['oznake'];
|
||||||
|
|
||||||
if(status) {
|
if (status) {
|
||||||
text_el.text(text);
|
text_el.text(text);
|
||||||
razlaga_el.text(razlaga);
|
razlaga_el.text(razlaga);
|
||||||
razlaga_el.attr('taksonomija', razlaga_tax);
|
razlaga_el.attr('taksonomija', razlaga_tax);
|
||||||
|
@ -182,7 +182,7 @@ change: function(el, func_after) {
|
||||||
var xml_el = self.prevodi[el.attr('prevod_id')];
|
var xml_el = self.prevodi[el.attr('prevod_id')];
|
||||||
xml_el.find('tekst').text(text);
|
xml_el.find('tekst').text(text);
|
||||||
|
|
||||||
if(xml_el.find('rzg').length == 0) {
|
if (xml_el.find('rzg').length == 0) {
|
||||||
xml_el.append("<rzg />", this.xml);
|
xml_el.append("<rzg />", this.xml);
|
||||||
}
|
}
|
||||||
xml_el.find('rzg').text(razlaga);
|
xml_el.find('rzg').text(razlaga);
|
||||||
|
@ -193,20 +193,20 @@ change: function(el, func_after) {
|
||||||
var value = oznaka[1];
|
var value = oznaka[1];
|
||||||
|
|
||||||
// remove --
|
// remove --
|
||||||
while(value.startsWith('-') || value.startsWith(' ')) {
|
while (value.startsWith('-') || value.startsWith(' ')) {
|
||||||
value = value.substring(1, );
|
value = value.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write into xml
|
// write into xml
|
||||||
var oznaka_xml = xml_el.find(`oznaka[tip="${ tip }"]`);
|
var oznaka_xml = xml_el.find(`oznaka[tip="${tip}"]`);
|
||||||
oznaka_xml.text(value);
|
oznaka_xml.text(value);
|
||||||
|
|
||||||
// write into html
|
// write into html
|
||||||
var oznaka_html = el.find(`span[title="${ tip }"]`);
|
var oznaka_html = el.find(`span[title="${tip}"]`);
|
||||||
oznaka_html.text(value);
|
oznaka_html.text(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deleteOld) {
|
if (deleteOld) {
|
||||||
xml_el.find(`oznaka[tip="star"]`).text("");
|
xml_el.find(`oznaka[tip="star"]`).text("");
|
||||||
el.find(`span[title="star"]`).text("");
|
el.find(`span[title="star"]`).text("");
|
||||||
}
|
}
|
||||||
|
@ -214,13 +214,13 @@ change: function(el, func_after) {
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(func_after) {
|
if (func_after) {
|
||||||
func_after(status);
|
func_after(status);
|
||||||
}
|
}
|
||||||
el.focus();
|
el.focus();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
add: function(el) {
|
add: function (el) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var to_clone = $('.myed-prevod-div').first();
|
var to_clone = $('.myed-prevod-div').first();
|
||||||
|
@ -235,58 +235,58 @@ add: function(el) {
|
||||||
|
|
||||||
xml_container.append(new_child);
|
xml_container.append(new_child);
|
||||||
this.prevodi.push(new_child);
|
this.prevodi.push(new_child);
|
||||||
this.change(clone, function(result) { if(!result) { self.bin(clone); }});
|
this.change(clone, function (result) { if (!result) { self.bin(clone); } });
|
||||||
},
|
},
|
||||||
semicolon: function(el) {
|
semicolon: function (el) {
|
||||||
var scel = el.find('.myed-prevod-semicolon');
|
var scel = el.find('.myed-prevod-semicolon');
|
||||||
|
|
||||||
scel.toggleClass('myed-prevod-semicolon-hidden');
|
scel.toggleClass('myed-prevod-semicolon-hidden');
|
||||||
var xml_el = this.prevodi[el.attr('prevod_id')];
|
var xml_el = this.prevodi[el.attr('prevod_id')];
|
||||||
xml_el.attr('semicolon', !scel.hasClass('myed-prevod-semicolon-hidden'));
|
xml_el.attr('semicolon', !scel.hasClass('myed-prevod-semicolon-hidden'));
|
||||||
},
|
},
|
||||||
action: function(el, action) {
|
action: function (el, action) {
|
||||||
if(action == 'left') {
|
if (action == 'left') {
|
||||||
this.moveLeft(el);
|
this.moveLeft(el);
|
||||||
}
|
}
|
||||||
else if(action == 'right') {
|
else if (action == 'right') {
|
||||||
this.moveRight(el);
|
this.moveRight(el);
|
||||||
}
|
}
|
||||||
else if(action == "cut") {
|
else if (action == "cut") {
|
||||||
this.cut(el);
|
this.cut(el);
|
||||||
}
|
}
|
||||||
else if(action == "bin") {
|
else if (action == "bin") {
|
||||||
this.bin(el);
|
this.bin(el);
|
||||||
}
|
}
|
||||||
else if(action == "edit") {
|
else if (action == "edit") {
|
||||||
this.change(el, null);
|
this.change(el, null);
|
||||||
}
|
}
|
||||||
else if(action == "semicolon") {
|
else if (action == "semicolon") {
|
||||||
this.semicolon(el);
|
this.semicolon(el);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
indikatorEdit: function(el, val) {
|
indikatorEdit: function (el, val) {
|
||||||
this.indikatorji[$(el).attr('indikator_id')].text(val);
|
this.indikatorji[$(el).attr('indikator_id')].text(val);
|
||||||
$(el).text(val);
|
$(el).text(val);
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
},
|
},
|
||||||
zgledPrevod: function(el, val) {
|
zgledPrevod: function (el, val) {
|
||||||
var zgled_id = el.attr('zgled_id');
|
var zgled_id = el.attr('zgled_id');
|
||||||
var zgled = this.zgledi[zgled_id];
|
var zgled = this.zgledi[zgled_id];
|
||||||
var new_el = $(`<prevod><tekst>${ val }</tekst></prevod>`);
|
var new_el = $(`<prevod><tekst>${val}</tekst></prevod>`);
|
||||||
|
|
||||||
el.parent().text(val);
|
el.parent().text(val);
|
||||||
el.remove();
|
el.remove();
|
||||||
|
|
||||||
zgled.after(new_el);
|
zgled.after(new_el);
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
},
|
},
|
||||||
registerCallbacks: function() {
|
registerCallbacks: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
var root = $(".clanek");
|
var root = $(".clanek");
|
||||||
|
|
||||||
function get_prevod_div(element) {
|
function get_prevod_div(element) {
|
||||||
while(element.parent().length) {
|
while (element.parent().length) {
|
||||||
if(element.hasClass('myed-prevod-div')) {
|
if (element.hasClass('myed-prevod-div')) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
element = element.parent();
|
element = element.parent();
|
||||||
|
@ -294,25 +294,25 @@ registerCallbacks: function() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
root.on('change', '.myed-clanek-select', function(e) {
|
root.on('change', '.myed-clanek-select', function (e) {
|
||||||
var el = get_prevod_div($(this));
|
var el = get_prevod_div($(this));
|
||||||
var action = $(this).find(":selected").val();
|
var action = $(this).find(":selected").val();
|
||||||
self.action(el, action);
|
self.action(el, action);
|
||||||
$(this).prop("selectedIndex", -1);
|
$(this).prop("selectedIndex", -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
root.on('click', '.myed-prevod-add', function(e) {
|
root.on('click', '.myed-prevod-add', function (e) {
|
||||||
self.add($(this));
|
self.add($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
root.on('click', '.myed-indikator', function() {
|
root.on('click', '.myed-indikator', function () {
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
$.sweetModal.prompt('Indikator', 'Vstavi:', el.text(), function(val) {
|
$.sweetModal.prompt('Indikator', 'Vstavi:', el.text(), function (val) {
|
||||||
self.indikatorEdit(el, val);
|
self.indikatorEdit(el, val);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
root.on('keydown', '.myed-prevod-div', function(e) {
|
root.on('keydown', '.myed-prevod-div', function (e) {
|
||||||
var action = {
|
var action = {
|
||||||
13: "edit",
|
13: "edit",
|
||||||
37: "left",
|
37: "left",
|
||||||
|
@ -320,22 +320,22 @@ registerCallbacks: function() {
|
||||||
46: "cut"
|
46: "cut"
|
||||||
}[e.keyCode];
|
}[e.keyCode];
|
||||||
|
|
||||||
if(action) {
|
if (action) {
|
||||||
self.action($(this), action);
|
self.action($(this), action);
|
||||||
$(this).focus();
|
$(this).focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
root.on('click', '.myed-zgled-prevod-btn', function(e) {
|
root.on('click', '.myed-zgled-prevod-btn', function (e) {
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
$.sweetModal.prompt('Prevod Zgleda', 'Vstavi:', '', function(val) {
|
$.sweetModal.prompt('Prevod Zgleda', 'Vstavi:', '', function (val) {
|
||||||
self.zgledPrevod(el, val);
|
self.zgledPrevod(el, val);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
root.on('click', '#myed-opomba', function() {
|
root.on('click', '#myed-opomba', function () {
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
$.sweetModal.prompt('Opomba', 'Opomba', el.text(), function(val) {
|
$.sweetModal.prompt('Opomba', 'Opomba', el.text(), function (val) {
|
||||||
el.text(val);
|
el.text(val);
|
||||||
self.xml.find('glava > opomba').text(val);
|
self.xml.find('glava > opomba').text(val);
|
||||||
Screenful.Editor.changed();
|
Screenful.Editor.changed();
|
||||||
|
@ -343,21 +343,21 @@ registerCallbacks: function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// fixing modal stuff
|
// fixing modal stuff
|
||||||
$('body').on('keydown', '.sweet-modal-prompt', function(e) {
|
$('body').on('keydown', '.sweet-modal-prompt', function (e) {
|
||||||
if(e.keyCode == 13) {
|
if (e.keyCode == 13) {
|
||||||
$('.greenB').first().trigger('click')
|
$('.greenB').first().trigger('click')
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(e.keyCode == 27) {
|
else if (e.keyCode == 27) {
|
||||||
$('.redB').first().trigger('click')
|
$('.redB').first().trigger('click')
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
clanekOldCode: function() {
|
clanekOldCode: function () {
|
||||||
// script from original xslt, don't really wanna touch this!
|
// script from original xslt, don't really wanna touch this!
|
||||||
var clanekShowHide = function(button) {
|
var clanekShowHide = function (button) {
|
||||||
if(button.target.tagName !== "INPUT") {
|
if (button.target.tagName !== "INPUT") {
|
||||||
// this actually triggers a few times, so...
|
// this actually triggers a few times, so...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -366,13 +366,13 @@ clanekOldCode: function() {
|
||||||
var boolCollocations = clanek.find(".lblCollocations input").prop("checked");
|
var boolCollocations = clanek.find(".lblCollocations input").prop("checked");
|
||||||
var boolExamples = clanek.find(".lblExamples input").prop("checked");
|
var boolExamples = clanek.find(".lblExamples input").prop("checked");
|
||||||
|
|
||||||
if(boolExamples) {
|
if (boolExamples) {
|
||||||
clanek.find(".hiddenExample").slideDown();
|
clanek.find(".hiddenExample").slideDown();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
clanek.find(".hiddenExample").slideUp();
|
clanek.find(".hiddenExample").slideUp();
|
||||||
}
|
}
|
||||||
if(boolCollocations) {
|
if (boolCollocations) {
|
||||||
clanek.find(".hiddenBlock").slideDown();
|
clanek.find(".hiddenBlock").slideDown();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -387,27 +387,27 @@ clanekOldCode: function() {
|
||||||
lblExamples.hide();
|
lblExamples.hide();
|
||||||
lblCollocations.hide()
|
lblCollocations.hide()
|
||||||
|
|
||||||
if(clanek.find(".hiddenBlock").length > 0) {
|
if (clanek.find(".hiddenBlock").length > 0) {
|
||||||
lblCollocations.show()
|
lblCollocations.show()
|
||||||
lblCollocations.first().on("click", clanekShowHide);
|
lblCollocations.first().on("click", clanekShowHide);
|
||||||
clanek.find(".buttons").show();
|
clanek.find(".buttons").show();
|
||||||
}
|
}
|
||||||
if(clanek.find("*:visible > .hiddenExample").length > 0) {
|
if (clanek.find("*:visible > .hiddenExample").length > 0) {
|
||||||
lblExamples.show()
|
lblExamples.show()
|
||||||
lblExamples.first().on("click", clanekShowHide);
|
lblExamples.first().on("click", clanekShowHide);
|
||||||
clanek.find(".buttons").show();
|
clanek.find(".buttons").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is actually new but belongs here
|
// this is actually new but belongs here
|
||||||
$(".lblPrevodi").first().on('click', function(e) {
|
$(".lblPrevodi").first().on('click', function (e) {
|
||||||
if(e.target.tagName !== "INPUT") {
|
if (e.target.tagName !== "INPUT") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('.myed-zgled-prevod-btn').parent().toggle();
|
$('.myed-zgled-prevod-btn').parent().toggle();
|
||||||
});
|
});
|
||||||
$('.myed-zgled-prevod-btn').parent().toggle();
|
$('.myed-zgled-prevod-btn').parent().toggle();
|
||||||
},
|
},
|
||||||
editor: function(div, entry, uneditable) {
|
editor: function (div, entry, uneditable) {
|
||||||
var xml = $($.parseXML(entry.content));
|
var xml = $($.parseXML(entry.content));
|
||||||
|
|
||||||
// for "dodajanje prevodov" we need a model div to copy.
|
// for "dodajanje prevodov" we need a model div to copy.
|
||||||
|
@ -435,18 +435,18 @@ editor: function(div, entry, uneditable) {
|
||||||
|
|
||||||
// select nothing in all hamburger dropdowns
|
// select nothing in all hamburger dropdowns
|
||||||
$('.myed-clanek-select').prop("selectedIndex", -1);
|
$('.myed-clanek-select').prop("selectedIndex", -1);
|
||||||
},
|
},
|
||||||
oznaka_callback: function(el) {
|
oznaka_callback: function (el) {
|
||||||
var select = el.parent().find('select');
|
var select = el.parent().find('select');
|
||||||
var text = window.prompt("Nova oznaka");
|
var text = window.prompt("Nova oznaka");
|
||||||
select.append($('<option>', { text: text, selected: "selected" }));
|
select.append($('<option>', { text: text, selected: "selected" }));
|
||||||
},
|
},
|
||||||
show_modal: function(prevedek, razlaga, oznake, callback) {
|
show_modal: function (prevedek, razlaga, oznake, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
function grabContent(status) {
|
function grabContent(status) {
|
||||||
if(!callback) return;
|
if (!callback) return;
|
||||||
var oznake_t = $('.myed-oznaka-div').map(function() {
|
var oznake_t = $('.myed-oznaka-div').map(function () {
|
||||||
var selected = $(this).find(":selected").text();
|
var selected = $(this).find(":selected").text();
|
||||||
var tip = $.trim($(this).find('.myed-oznaka-key').first().text());
|
var tip = $.trim($(this).find('.myed-oznaka-key').first().text());
|
||||||
return [[tip, selected]];
|
return [[tip, selected]];
|
||||||
|
@ -454,19 +454,19 @@ show_modal: function(prevedek, razlaga, oznake, callback) {
|
||||||
var callback_data = {
|
var callback_data = {
|
||||||
"prevedek": $('#myed-sm-prevedek').val(),
|
"prevedek": $('#myed-sm-prevedek').val(),
|
||||||
"razlaga": $('#myed-sm-razlaga').val(),
|
"razlaga": $('#myed-sm-razlaga').val(),
|
||||||
"razlaga_tax": $('#myed-tax').prop( "checked" ),
|
"razlaga_tax": $('#myed-tax').prop("checked"),
|
||||||
"remove_old": $( ".myed-old-oznaka-delete" ).prop( "checked" ),
|
"remove_old": $(".myed-old-oznaka-delete").prop("checked"),
|
||||||
"oznake": oznake_t
|
"oznake": oznake_t
|
||||||
};
|
};
|
||||||
callback(status, callback_data);
|
callback(status, callback_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
function isOznakaChosen(opt) {
|
function isOznakaChosen(opt) {
|
||||||
for(let o of oznake) {
|
for (let o of oznake) {
|
||||||
var idx = opt.indexOf(o);
|
var idx = opt.indexOf(o);
|
||||||
// either the whole word or after '-- '
|
// either the whole word or after '-- '
|
||||||
// solving the problem of "-- biokemija" and "kemija" and simmilar (i know, a bad solution)
|
// solving the problem of "-- biokemija" and "kemija" and simmilar (i know, a bad solution)
|
||||||
if(idx == 0 || idx == 3) {
|
if (idx == 0 || idx == 3) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,14 +474,14 @@ show_modal: function(prevedek, razlaga, oznake, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = "";
|
var options = "";
|
||||||
for(let [key, value] of Object.entries(constants.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>`;
|
options += `<div class='myed-oznaka-div'><span class="myed-oznaka-key">${key}</span> <select><option></option>`;
|
||||||
for(let option of value) {
|
for (let option of value) {
|
||||||
var optStart = "<option";
|
var optStart = "<option";
|
||||||
if(isOznakaChosen(option)) {
|
if (isOznakaChosen(option)) {
|
||||||
optStart += " selected";
|
optStart += " selected";
|
||||||
}
|
}
|
||||||
options += `${optStart}>${ option }</option>`;
|
options += `${optStart}>${option}</option>`;
|
||||||
}
|
}
|
||||||
options += "</select><input class='myed-oznaka-input' type='button' value='drugo' /></div>";
|
options += "</select><input class='myed-oznaka-input' type='button' value='drugo' /></div>";
|
||||||
}
|
}
|
||||||
|
@ -492,51 +492,51 @@ show_modal: function(prevedek, razlaga, oznake, callback) {
|
||||||
$.sweetModal({
|
$.sweetModal({
|
||||||
title: 'Spreminjanje Prevedka',
|
title: 'Spreminjanje Prevedka',
|
||||||
content: `
|
content: `
|
||||||
Prevedek: <div class="sweet-modal-prompt"><input id="myed-sm-prevedek" type="text" value="${ prevedek }" /></div><br />
|
Prevedek: <div class="sweet-modal-prompt"><input id="myed-sm-prevedek" type="text" value="${ prevedek}" /></div><br />
|
||||||
Razlaga: <div class="sweet-modal-prompt"><input id="myed-sm-razlaga" type="text" value="${ razlaga.text() }" /></div><br />
|
Razlaga: <div class="sweet-modal-prompt"><input id="myed-sm-razlaga" type="text" value="${ razlaga.text()}" /></div><br />
|
||||||
<input id="myed-tax" type="checkbox" name="taksonomija" value="taksonomija" ${ tax }><label for="taksonomija">Razlaga je taksonomija</label><br />
|
<input id="myed-tax" type="checkbox" name="taksonomija" value="taksonomija" ${ tax}><label for="taksonomija">Razlaga je taksonomija</label><br />
|
||||||
Oznake: ${ options }<br />${ izbrisiStareOznake }`,
|
Oznake: ${ options}<br />${izbrisiStareOznake}`,
|
||||||
buttons: {
|
buttons: {
|
||||||
save: {
|
save: {
|
||||||
label: 'Shrani',
|
label: 'Shrani',
|
||||||
classes: 'greenB',
|
classes: 'greenB',
|
||||||
action: function() { grabContent(true); },
|
action: function () { grabContent(true); },
|
||||||
},
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
label: 'Preklici',
|
label: 'Preklici',
|
||||||
classes: 'redB',
|
classes: 'redB',
|
||||||
action: function() { grabContent(false); },
|
action: function () { grabContent(false); },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onOpen: function() {
|
onOpen: function () {
|
||||||
$('#myed-sm-prevedek').focus();
|
$('#myed-sm-prevedek').focus();
|
||||||
$('.myed-oznaka-input').on('click', function(e) { self.oznaka_callback($(this)); });
|
$('.myed-oznaka-input').on('click', function (e) { self.oznaka_callback($(this)); });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
harvester: function(div) {
|
harvester: function (div) {
|
||||||
for(let fstring of constants.prevod_locations) {
|
for (let fstring of constants.prevod_locations) {
|
||||||
for(let vecjez of this.xml.find(fstring)) {
|
for (let vecjez of this.xml.find(fstring)) {
|
||||||
for(let pp of $(vecjez).find('pp')) {
|
for (let pp of $(vecjez).find('pp')) {
|
||||||
$(pp).remove();
|
$(pp).remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
var all_prevod = $(vecjez).find("prevod");
|
var all_prevod = $(vecjez).find("prevod");
|
||||||
// if only one prevod and that one is deleted, just create an empty one.
|
// if only one prevod and that one is deleted, just create an empty one.
|
||||||
if(all_prevod.length == 1 && $(all_prevod[0]).attr('bin') == 'true') {
|
if (all_prevod.length == 1 && $(all_prevod[0]).attr('bin') == 'true') {
|
||||||
var empty = this.empty_prevod();
|
var empty = this.empty_prevod();
|
||||||
all_prevod.append(empty);
|
all_prevod.append(empty);
|
||||||
$(all_prevod[0]).after(empty);
|
$(all_prevod[0]).after(empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let lprevod of all_prevod) {
|
for (let lprevod of all_prevod) {
|
||||||
var prevod = $(lprevod);
|
var prevod = $(lprevod);
|
||||||
if(prevod.attr('bin') == 'true') {
|
if (prevod.attr('bin') == 'true') {
|
||||||
prevod.remove();
|
prevod.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prevod.attr('semicolon') == 'true') {
|
if (prevod.attr('semicolon') == 'true') {
|
||||||
prevod.append($("<pp/>", this.xml));
|
prevod.append($("<pp/>", this.xml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,13 +551,13 @@ harvester: function(div) {
|
||||||
this.xml.find('status').text(status_txt);
|
this.xml.find('status').text(status_txt);
|
||||||
|
|
||||||
return (new XMLSerializer()).serializeToString(this.xml[0]);
|
return (new XMLSerializer()).serializeToString(this.xml[0]);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin_render(div, entry) {
|
function plugin_render(div, entry) {
|
||||||
_code.editor(div, entry, true);
|
plugin_code.editor(div, entry, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin_save(div) {
|
function plugin_save(div) {
|
||||||
_code.harvester(div, entry, true);
|
plugin_code.harvester(div, entry, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user