PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / betterdocs.js

betterdocs.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/betterdocs.js

218 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 class BetterDocsAdmin {
2 constructor(config) {
3 this.config = config;
4 this.initialize();
5 this.init();
6 }
7
8 init() {
9 this.settingsTab();
10 this.sortable();
11 this.copyToClipboard();
12 this.enableDarkMode();
13 this.generateSampleData();
14 }
15
16 initialize() {
17 var $ = jQuery;
18
19 this.body = $("body");
20 this.droppableUl = $(".betterdocs-single-listing ul");
21 this.copyBtn = $(".betterdocs-settings-input-text span");
22 this.darkModeBtn = $("#betterdocs-mode-toggle");
23 this.settingsMenu = $(".betterdocs-settings-menu li");
24 }
25
26 settingsTab() {
27 this.settingsMenu.on("click", function (e) {
28 var $ = jQuery;
29 var tabToGo = $(this).data("tab");
30
31 $(this).addClass("active").siblings().removeClass("active");
32 $("#betterdocs-" + tabToGo)
33 .addClass("active")
34 .siblings()
35 .removeClass("active");
36 });
37 }
38
39 get_query_vars(name) {
40 var vars = {};
41 window.location.href.replace(
42 /[?&]+([^=&]+)=([^&]*)/gi,
43 (_, key, value) => (vars[key] = value)
44 );
45 return name !== "" ? vars[name] : vars;
46 }
47
48 enableDarkMode() {
49 var $this = this;
50
51 this.darkModeBtn.prop("checked", Boolean(this.config.dark_mode));
52
53 this.darkModeBtn.on("click", function (e) {
54 $this.body.toggleClass("betterdocs-dark-mode");
55
56 jQuery.ajax({
57 type: "POST",
58 url: $this.config.ajaxurl,
59 data: {
60 action: "betterdocs_dark_mode",
61 mode: e.currentTarget.checked ? 1 : 0,
62 nonce: $this.config.doc_cat_order_nonce,
63 },
64 dataType: "JSON",
65 success: function (response) {
66 if (response?.success == false) {
67 $this.body.toggleClass("betterdocs-dark-mode");
68 }
69 },
70 });
71 });
72 }
73
74 permalinkStructure() {
75 var multiple_kb = $("#multiple_kb");
76 var permalink_structure = $("#permalink_structure");
77 var $val = permalink_structure.val();
78 if ($val && !multiple_kb.is(":checked")) {
79 permalink_structure.val($val.replace(/%knowledge_base%\/?/g, ""));
80 }
81 }
82
83 copyToClipboard() {
84 var $this = this;
85
86 this.copyBtn.on("click", function (e) {
87 var previousValue = this.previousSibling;
88 previousValue.select();
89 document.execCommand("copy");
90 this.firstChild.textContent = $this.config.text;
91 previousValue.setSelectionRange(0, 99999);
92 });
93 }
94
95 setView() {}
96
97 sortable() {
98 var $this = this;
99
100 this.droppableUl.each((i, _item) => {
101 var singleDocsList = jQuery(_item),
102 termID = singleDocsList.data("category_id"),
103 droppable = false;
104
105 if (singleDocsList.hasClass("docs-droppable")) {
106 droppable = true;
107 }
108
109 singleDocsList.sortable({
110 connectWith: "ul.docs-droppable",
111 placeholder: "betterdocs-post-list-placeholder",
112 // axis: droppable ? "y" : true,
113 // On start, set a height for the placeholder to prevent table jumps.
114 start: function (event, ui) {
115 const item = jQuery(ui.item[0]);
116 jQuery(".betterdocs-post-list-placeholder").css(
117 "height",
118 item.css("height")
119 );
120 },
121 receive: function (event, ui) {
122 const item = ui.item;
123 item.siblings(".betterdocs-no-docs").remove();
124 if (termID != undefined) {
125 // AJAX Data.
126 const data = {
127 action: "update_docs_term",
128 object_id: item.data("id"),
129 prev_term_id: ui.sender.data("category_id"),
130 list_term_id: termID,
131 doc_cat_order_nonce:
132 $this.config.doc_cat_order_nonce,
133 };
134 // Pass language for WPML/multilingual compatibility
135 if ($this.config.current_admin_language) {
136 data.lang = $this.config.current_admin_language;
137 }
138 // Run the ajax request.
139 jQuery.ajax({
140 type: "POST",
141 url: $this.config.ajaxurl,
142 data: data,
143 dataType: "JSON",
144 success: function (response) {
145 // console.log( response );
146 },
147 });
148 }
149 },
150 update: function (event, ui) {
151 const docs_ordering_data = [];
152 singleDocsList
153 .find("li.ui-sortable-handle")
154 .each(function () {
155 const ele = jQuery(this);
156 docs_ordering_data.push(ele.data("id"));
157 });
158 if (termID != undefined) {
159 // AJAX Data.
160 const data = {
161 action: "update_doc_order_by_category",
162 docs_ordering_data: docs_ordering_data,
163 list_term_id: termID,
164 doc_cat_order_nonce:
165 $this.config.doc_cat_order_nonce,
166 };
167 // Pass language for WPML/multilingual compatibility
168 if ($this.config.current_admin_language) {
169 data.lang = $this.config.current_admin_language;
170 }
171 // Run the ajax request.
172 jQuery.ajax({
173 type: "POST",
174 url: $this.config.ajaxurl,
175 data: data,
176 dataType: "JSON",
177 success: function (response) {
178 // console.log( response );
179 },
180 });
181 }
182 },
183 });
184 });
185 }
186
187 generateSampleData() {
188 let $ = jQuery;
189 let generateButtonDom = $('.generate-sample-data');
190 let apiUrl = this?.config?.generate_data_url;
191 let nonce = this?.config?.nonce;
192 generateButtonDom.on('click', function(e){
193 e.preventDefault();
194 generateButtonDom.text('Generating...');
195 jQuery?.ajax({
196 type:"POST",
197 url: apiUrl,
198 data:{
199 action:'create-dummy-data',
200 _wpnonce:nonce
201 },
202 dataType:"JSON",
203 success:function(response) {
204 if( response?.status == 'success' ) {
205 generateButtonDom?.text('Generated Successfully');
206 window.location.reload();
207 }
208 }
209 })
210 })
211 }
212 }
213
214 (function ($) {
215 "use strict";
216 new BetterDocsAdmin(window?.betterdocs_admin);
217 })(jQuery);
218