PluginProbe
Tag Groups is the Advanced Way to Display Your Taxonomy Terms / trunk
Tag Groups is the Advanced Way to Display Your Taxonomy Terms vtrunk
2.2.2 2.2.1 2.2.0 trunk 1.40.0 1.40.2 1.41.0 1.42.1 1.43.0 1.43.1 1.43.10 1.43.10.1 1.43.2 1.43.3 1.43.4 1.43.5 1.43.6 1.43.7 1.43.9 1.44.0 1.44.1 1.44.3 1.44.3.1 2.0.0 2.0.1 All 36 releases
tag-groups / src / modules / functions.js

functions.js in Tag Groups is the Advanced Way to Display Your Taxonomy Terms trunk, at src/modules/functions.js

195 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const { __ } = wp.i18n;
2
3 export const optionsOrderby = [
4 { value: 'name', label: __('Name') },
5 { value: 'natural', label: __('Natural sorting') },
6 { value: 'count', label: __('Post count') },
7 { value: 'slug', label: __('Slug') },
8 { value: 'term_id', label: __('Term ID') },
9 { value: 'description', label: __('Description') },
10 { value: 'random', label: __('Random') },
11 { value: 'term_order', label: __('Term Order') },
12 ];
13
14 export const optionsOrder = [
15 { value: 'ASC', label: __('Ascending') },
16 { value: 'DESC', label: __('Descending') },
17 ];
18
19 export const optionsTarget = [
20 { value: '_self', label: '_self' },
21 { value: '_blank', label: '_blank' },
22 { value: '_parent', label: '_parent' },
23 { value: '_top', label: '_top' },
24 ];
25
26 export function getIncludeOptions(_this) {
27 let optionsInclude = [];
28
29 if (_this.state.groups && _this.state.groups.length > 0) {
30 _this.state.groups.forEach((group) => {
31 optionsInclude.push({ value: group.term_group, label: group.label });
32 });
33 }
34 return optionsInclude;
35 }
36
37 export function getExcludeOptions(_this) {
38 let optionsExclude = [];
39
40 if (_this.state.groups && _this.state.groups.length > 0) {
41 _this.state.groups.forEach((group) => {
42 if (_this.state.selectedInclude.indexOf(group.term_group) < 0) {
43 optionsExclude.push({ value: group.term_group, label: group.label });
44 }
45 });
46 }
47 return optionsExclude;
48 }
49
50 export function getTaxonomyOptions(_this) {
51 let optionsTaxonomies = [];
52
53 if (_this.state.taxonomies && _this.state.taxonomies.length > 0) {
54 _this.state.taxonomies.forEach((taxonomy) => {
55 optionsTaxonomies.push({ value: taxonomy.slug, label: taxonomy.name });
56 });
57 }
58 return optionsTaxonomies;
59 }
60
61 export function getActiveGroupsOptions(_this) {
62 const { groups_post_id } = _this.props.attributes;
63 let optionsActiveGroups = [];
64 let i = 0;
65 if (
66 (typeof _this.state.selectedInclude !== 'undefined' &&
67 _this.state.selectedInclude.length) ||
68 (typeof _this.state.selectedExclude !== 'undefined' &&
69 _this.state.selectedExclude.length)
70 ) {
71 let expandedInclude, expandedExclude;
72 if (_this.state.selectedInclude.length > 0) {
73 expandedInclude = expandIds(
74 _this.state.selectedInclude,
75 _this.state.groups
76 );
77 } else {
78 let groupIds = [];
79 for (let group of _this.state.groups) {
80 if (0 === group.term_group) {
81 continue; // unassigned group is only included if mentioned in 'include'
82 }
83 groupIds.push(group.term_group);
84 }
85 expandedInclude = expandIds(groupIds, _this.state.groups);
86 }
87 if (typeof _this.state.selectedExclude !== 'undefined') {
88 expandedExclude = expandIds(
89 _this.state.selectedExclude,
90 _this.state.groups
91 );
92 } else {
93 expandedExclude = [];
94 }
95 _this.state.groups.forEach((group) => {
96 if (
97 expandedInclude.indexOf(group.term_group) > -1 &&
98 expandedExclude.indexOf(group.term_group) == -1
99 ) {
100 let label;
101 if (groups_post_id > -1) {
102 label = i;
103 } else {
104 label = group.label;
105 }
106 optionsActiveGroups.push({ value: i, label });
107 i++;
108 }
109 });
110 } else if (_this.state.groups && _this.state.groups.length) {
111 _this.state.groups.forEach((group) => {
112 if (!group.term_group) return; // skipping unassigned
113 if (group.is_parent) return;
114 let label;
115 if (groups_post_id > -1) {
116 label = i;
117 } else {
118 label = group.label;
119 }
120 optionsActiveGroups.push({ value: i, label });
121 i++;
122 });
123 }
124 return optionsActiveGroups;
125 }
126
127 function expandIds(groupIds, allGroups) {
128 let expandedGroups = [];
129 for (let groupId of groupIds) {
130 const group = getGroupById(allGroups, groupId);
131 if (typeof group.is_parent !== 'undefined' && group.is_parent) {
132 if (typeof group.children === 'undefined') {
133 continue;
134 }
135 group.children.forEach((childId) => {
136 if (groupIds.indexOf(childId) === -1) {
137 expandedGroups.push(childId);
138 }
139 });
140 } else {
141 expandedGroups.push(group.term_group);
142 }
143 }
144 return expandedGroups;
145 }
146
147 function getGroupById(allGroups, id) {
148 for (let group of allGroups) {
149 if (group.term_group === id) {
150 return group;
151 }
152 }
153 return { termgroup: -1, label: 'error' };
154 }
155
156 export function renderTabs(_this) {
157 const { active, collapsible, mouseover } = _this.props.attributes;
158
159 let options = {
160 active: active < 0 ? false : active,
161 collapsible: collapsible == 1,
162 };
163
164 if (mouseover) {
165 options.event = 'mouseover';
166 }
167
168 setTimeout(() => {
169 jQuery('#' + _this.state.uniqueId).tabs(options);
170 }, 1000);
171 }
172
173 export function renderAccordion(_this) {
174 const {
175 active,
176 collapsible,
177 mouseover,
178 heightstyle,
179 } = _this.props.attributes;
180
181 let options = {
182 active: active < 0 ? false : active,
183 collapsible: collapsible == 1,
184 heightStyle: heightstyle,
185 };
186
187 if (mouseover) {
188 options.event = 'mouseover';
189 }
190
191 setTimeout(() => {
192 jQuery('#' + _this.state.uniqueId).accordion(options);
193 }, 1000);
194 }
195