post-list-quickedit.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
jQuery(function () {
"use strict";
jQuery('.editinline').on(
'click', function () {
var lang, parentDiv, editButton, postLink;
parentDiv = jQuery(this).closest('div');
editButton = parentDiv.find('.edit').find('a');
postLink = editButton.attr('href');
lang = postLink.match(/(?=lang=).*.$/).pop().replace('lang=', '');
parseJSONTerms(lang);
}
);
}
);
/**
* This is only used for hierarchical Taxonomies
*
* @param lang String
*/
function parseJSONTerms(lang) {
"use strict";
var JSONString, allTerms, termsInCorrectLang, taxonomy;
JSONString = jQuery('#icl-terms-by-lang').html();
allTerms = JSON.parse(JSONString);
if (allTerms.hasOwnProperty(lang)) {
termsInCorrectLang = allTerms[lang];
for (taxonomy in termsInCorrectLang) {
if (termsInCorrectLang.hasOwnProperty(taxonomy)) {
removeWrongLanguageTerms(termsInCorrectLang[taxonomy], taxonomy);
}
}
}
}
function removeWrongLanguageTerms(termsList, taxonomy) {
"use strict";
var termsUL, termsListElements;
termsUL = jQuery('.' + taxonomy + '-checklist');
termsListElements = termsUL.children('li[id^="' + taxonomy + '"]');
jQuery.each(
termsListElements, function (index, liElement) {
var termId, domElementID;
domElementID = liElement.id;
termId = domElementID.replace(taxonomy + '-', '');
if (termsList.indexOf(termId) === -1) {
jQuery(liElement).hide();
} else {
jQuery(liElement).show();
}
}
);
}