WebOrbiton
v1.0.0.8

Publisium

243 lines · 7.4 KB
  1. document.addEventListener('DOMContentLoaded', function () {
  2. document.querySelectorAll('.js-reject-btn').forEach(function (button) {
  3. button.addEventListener('click', function () {
  4. var row = document.getElementById('reject-row-' + this.dataset.articleId);
  5. if (row) {
  6. row.style.display = row.style.display === 'none' ? 'table-row' : 'none';
  7. }
  8. });
  9. });
  10. ​
  11. var THEME_KEY = 'publisium_dashboard_theme';
  12. ​
  13. function applyTheme(theme) {
  14. document.body.setAttribute('data-theme', theme);
  15. }
  16. ​
  17. var stored = localStorage.getItem(THEME_KEY);
  18. if (stored === 'dark' || stored === 'light') {
  19. applyTheme(stored);
  20. } else {
  21. var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
  22. applyTheme(prefersDark ? 'dark' : 'light');
  23. }
  24. ​
  25. var toggleBtns = document.querySelectorAll('#dash-theme-toggle-btn, .dash-theme-toggle');
  26. toggleBtns.forEach(function (btn) {
  27. btn.addEventListener('click', function () {
  28. var current = document.body.getAttribute('data-theme') || 'dark';
  29. var next = current === 'dark' ? 'light' : 'dark';
  30. applyTheme(next);
  31. localStorage.setItem(THEME_KEY, next);
  32. });
  33. });
  34. ​
  35. var nav = document.querySelector('.dash-nav');
  36. var sidebar = document.querySelector('.dash-sidebar');
  37. if (nav && sidebar) {
  38. var MAX_VISIBLE = 4;
  39. var navLinks = Array.prototype.slice.call(nav.querySelectorAll('a'));
  40. ​
  41. var moreBtn = null;
  42. var sheetBackdrop = null;
  43. var sheet = null;
  44. ​
  45. function buildOverflow() {
  46. if (navLinks.length <= MAX_VISIBLE) {
  47. return;
  48. }
  49. ​
  50. var overflowLinks = navLinks.slice(MAX_VISIBLE - 1);
  51. overflowLinks.forEach(function (a) {
  52. a.classList.add('dash-nav-overflow-item');
  53. });
  54. nav.classList.add('has-overflow');
  55. ​
  56. moreBtn = document.createElement('button');
  57. moreBtn.type = 'button';
  58. moreBtn.className = 'dash-nav-more-btn';
  59. moreBtn.innerHTML = '<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="5" cy="12" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="19" cy="12" r="1.5"/></svg><span>More</span>';
  60. nav.appendChild(moreBtn);
  61. ​
  62. sheetBackdrop = document.createElement('div');
  63. sheetBackdrop.className = 'dash-nav-sheet-backdrop';
  64. ​
  65. sheet = document.createElement('div');
  66. sheet.className = 'dash-nav-sheet';
  67. var handle = document.createElement('div');
  68. handle.className = 'dash-nav-sheet-handle';
  69. sheet.appendChild(handle);
  70. ​
  71. overflowLinks.forEach(function (a) {
  72. sheet.appendChild(a.cloneNode(true));
  73. });
  74. ​
  75. document.body.appendChild(sheetBackdrop);
  76. document.body.appendChild(sheet);
  77. ​
  78. function openSheet() {
  79. sheetBackdrop.classList.add('open');
  80. sheet.classList.add('open');
  81. moreBtn.classList.add('open');
  82. }
  83. ​
  84. function closeSheet() {
  85. sheetBackdrop.classList.remove('open');
  86. sheet.classList.remove('open');
  87. moreBtn.classList.remove('open');
  88. }
  89. ​
  90. moreBtn.addEventListener('click', function () {
  91. if (sheetBackdrop.classList.contains('open')) {
  92. closeSheet();
  93. } else {
  94. openSheet();
  95. }
  96. });
  97. ​
  98. sheetBackdrop.addEventListener('click', closeSheet);
  99. }
  100. ​
  101. buildOverflow();
  102. }
  103. });
  104. ​
  105. (function (global) {
  106. 'use strict';
  107. ​
  108. var SIDEBAR_KEY = 'publisium_dashboard_sidebar_scale';
  109. var MAIN_KEY = 'publisium_dashboard_main_scale';
  110. var VALID_SCALES = [80, 90, 100, 110, 120, 130, 140, 150];
  111. ​
  112. function loadScale(key) {
  113. var stored = parseInt(global.localStorage.getItem(key), 10);
  114. return VALID_SCALES.indexOf(stored) !== -1 ? stored : 100;
  115. }
  116. ​
  117. function supportsZoom() {
  118. return typeof document.body.style.zoom !== 'undefined';
  119. }
  120. ​
  121. function applyScaleTo(el, scale) {
  122. if (!el) {
  123. return;
  124. }
  125. if (scale === 100) {
  126. el.style.zoom = '';
  127. el.style.transform = '';
  128. el.style.width = '';
  129. return;
  130. }
  131. if (supportsZoom()) {
  132. el.style.zoom = (scale / 100).toString();
  133. el.style.transform = '';
  134. el.style.width = '';
  135. } else {
  136. var factor = scale / 100;
  137. el.style.transform = 'scale(' + factor + ')';
  138. el.style.transformOrigin = 'top left';
  139. el.style.width = (100 / factor) + '%';
  140. }
  141. }
  142. ​
  143. var UI_FONT_KEY = 'publisium_dashboard_ui_font';
  144. var CONTENT_FONT_KEY = 'publisium_dashboard_content_font';
  145. ​
  146. function applyFonts() {
  147. var root = document.documentElement.style;
  148. var uiFont = global.localStorage.getItem(UI_FONT_KEY);
  149. var contentFont = global.localStorage.getItem(CONTENT_FONT_KEY);
  150. ​
  151. if (uiFont) {
  152. root.setProperty('--dash-font-ui', '"' + uiFont + '"');
  153. } else {
  154. root.removeProperty('--dash-font-ui');
  155. }
  156. ​
  157. if (contentFont) {
  158. root.setProperty('--dash-font-content', '"' + contentFont + '"');
  159. } else {
  160. root.removeProperty('--dash-font-content');
  161. }
  162. }
  163. ​
  164. var GLASS_KEY = 'publisium_dashboard_glass';
  165. ​
  166. var MINIMAL_KEY = 'publisium_dashboard_minimal';
  167. ​
  168. function applyGlass() {
  169. var minimal = global.localStorage.getItem(MINIMAL_KEY) === '1';
  170. document.body.classList.toggle('dash-minimal', minimal);
  171. document.body.classList.toggle('dash-no-glass', minimal || global.localStorage.getItem(GLASS_KEY) === '0');
  172. }
  173. ​
  174. function apply() {
  175. try {
  176. applyGlass();
  177. applyScaleTo(document.querySelector('.dash-sidebar'), loadScale(SIDEBAR_KEY));
  178. applyScaleTo(document.querySelector('.dash-main'), loadScale(MAIN_KEY));
  179. applyFonts();
  180. } catch (error) {
  181. }
  182. }
  183. ​
  184. global.PublisiumAppearance = {
  185. apply: apply,
  186. };
  187. ​
  188. document.addEventListener('DOMContentLoaded', apply);
  189. })(window);
  190. ​
  191. // Hosting firewalls often block requests whose fields contain HTML or JavaScript (ad code,
  192. // analytics snippets, custom code, code blocks). Send those fields base64-encoded as
  193. // "<name>__b64"; includes/config.php decodes them back before the page reads $_POST.
  194. (function (global) {
  195. 'use strict';
  196. ​
  197. function toBase64(text) {
  198. var bytes = new TextEncoder().encode(text);
  199. var binary = '';
  200. for (var i = 0; i < bytes.length; i += 0x8000) {
  201. binary += String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000));
  202. }
  203. return global.btoa(binary);
  204. }
  205. ​
  206. function restoreFields(form) {
  207. form.querySelectorAll('[data-encoded-copy]').forEach(function (copy) {
  208. copy.remove();
  209. });
  210. form.querySelectorAll('[data-encoded-original]').forEach(function (field) {
  211. field.disabled = false;
  212. field.removeAttribute('data-encoded-original');
  213. });
  214. }
  215. ​
  216. document.addEventListener('submit', function (event) {
  217. var form = event.target;
  218. if (event.defaultPrevented || !(form instanceof HTMLFormElement) || (form.method || '').toLowerCase() !== 'post' || !global.TextEncoder) {
  219. return;
  220. }
  221. ​
  222. restoreFields(form);
  223. ​
  224. form.querySelectorAll('textarea[name], input[type="hidden"][name$="_json"]').forEach(function (field) {
  225. if (field.disabled || field.name.indexOf('[') !== -1 || field.value === '') {
  226. return;
  227. }
  228. var copy = document.createElement('input');
  229. copy.type = 'hidden';
  230. copy.name = field.name + '__b64';
  231. copy.value = toBase64(field.value);
  232. copy.setAttribute('data-encoded-copy', '1');
  233. form.appendChild(copy);
  234. field.setAttribute('data-encoded-original', '1');
  235. field.disabled = true;
  236. });
  237. });
  238. ​
  239. global.addEventListener('pageshow', function () {
  240. document.querySelectorAll('form').forEach(restoreFields);
  241. });
  242. })(window);
  243. ​