main.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /**
  2. * Template Name: NiceAdmin - v2.2.0
  3. * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  4. * Author: BootstrapMade.com
  5. * License: https://bootstrapmade.com/license/
  6. */
  7. (function() {
  8. "use strict";
  9. /**
  10. * Easy selector helper function
  11. */
  12. const select = (el, all = false) => {
  13. el = el.trim()
  14. if (all) {
  15. return [...document.querySelectorAll(el)]
  16. } else {
  17. return document.querySelector(el)
  18. }
  19. }
  20. /**
  21. * Easy event listener function
  22. */
  23. const on = (type, el, listener, all = false) => {
  24. if (all) {
  25. select(el, all).forEach(e => e.addEventListener(type, listener))
  26. } else {
  27. select(el, all).addEventListener(type, listener)
  28. }
  29. }
  30. /**
  31. * Easy on scroll event listener
  32. */
  33. const onscroll = (el, listener) => {
  34. el.addEventListener('scroll', listener)
  35. }
  36. /**
  37. * Sidebar toggle
  38. */
  39. if (select('.toggle-sidebar-btn')) {
  40. on('click', '.toggle-sidebar-btn', function(e) {
  41. select('body').classList.toggle('toggle-sidebar')
  42. })
  43. }
  44. /**
  45. * Search bar toggle
  46. */
  47. if (select('.search-bar-toggle')) {
  48. on('click', '.search-bar-toggle', function(e) {
  49. select('.search-bar').classList.toggle('search-bar-show')
  50. })
  51. }
  52. /**
  53. * Navbar links active state on scroll
  54. */
  55. let navbarlinks = select('#navbar .scrollto', true)
  56. const navbarlinksActive = () => {
  57. let position = window.scrollY + 200
  58. navbarlinks.forEach(navbarlink => {
  59. if (!navbarlink.hash) return
  60. let section = select(navbarlink.hash)
  61. if (!section) return
  62. if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) {
  63. navbarlink.classList.add('active')
  64. } else {
  65. navbarlink.classList.remove('active')
  66. }
  67. })
  68. }
  69. window.addEventListener('load', navbarlinksActive)
  70. onscroll(document, navbarlinksActive)
  71. /**
  72. * Toggle .header-scrolled class to #header when page is scrolled
  73. */
  74. let selectHeader = select('#header')
  75. if (selectHeader) {
  76. const headerScrolled = () => {
  77. if (window.scrollY > 100) {
  78. selectHeader.classList.add('header-scrolled')
  79. } else {
  80. selectHeader.classList.remove('header-scrolled')
  81. }
  82. }
  83. window.addEventListener('load', headerScrolled)
  84. onscroll(document, headerScrolled)
  85. }
  86. /**
  87. * Back to top button
  88. */
  89. let backtotop = select('.back-to-top')
  90. if (backtotop) {
  91. const toggleBacktotop = () => {
  92. if (window.scrollY > 100) {
  93. backtotop.classList.add('active')
  94. } else {
  95. backtotop.classList.remove('active')
  96. }
  97. }
  98. window.addEventListener('load', toggleBacktotop)
  99. onscroll(document, toggleBacktotop)
  100. }
  101. /**
  102. * Initiate tooltips
  103. */
  104. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  105. var tooltipList = tooltipTriggerList.map(function(tooltipTriggerEl) {
  106. return new bootstrap.Tooltip(tooltipTriggerEl)
  107. })
  108. /**
  109. * Initiate quill editors
  110. */
  111. if (select('.quill-editor-default')) {
  112. new Quill('.quill-editor-default', {
  113. theme: 'snow'
  114. });
  115. }
  116. if (select('.quill-editor-bubble')) {
  117. new Quill('.quill-editor-bubble', {
  118. theme: 'bubble'
  119. });
  120. }
  121. if (select('.quill-editor-full')) {
  122. new Quill(".quill-editor-full", {
  123. modules: {
  124. toolbar: [
  125. [{
  126. font: []
  127. }, {
  128. size: []
  129. }],
  130. ["bold", "italic", "underline", "strike"],
  131. [{
  132. color: []
  133. },
  134. {
  135. background: []
  136. }
  137. ],
  138. [{
  139. script: "super"
  140. },
  141. {
  142. script: "sub"
  143. }
  144. ],
  145. [{
  146. list: "ordered"
  147. },
  148. {
  149. list: "bullet"
  150. },
  151. {
  152. indent: "-1"
  153. },
  154. {
  155. indent: "+1"
  156. }
  157. ],
  158. ["direction", {
  159. align: []
  160. }],
  161. ["link", "image", "video"],
  162. ["clean"]
  163. ]
  164. },
  165. theme: "snow"
  166. });
  167. }
  168. /**
  169. * Initiate TinyMCE Editor
  170. */
  171. var useDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
  172. tinymce.init({
  173. selector: 'textarea.tinymce-editor',
  174. plugins: 'print preview paste importcss searchreplace autolink autosave save directionality code visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount imagetools textpattern noneditable help charmap quickbars emoticons',
  175. imagetools_cors_hosts: ['picsum.photos'],
  176. menubar: 'file edit view insert format tools table help',
  177. toolbar: 'undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample | ltr rtl',
  178. toolbar_sticky: true,
  179. autosave_ask_before_unload: true,
  180. autosave_interval: '30s',
  181. autosave_prefix: '{path}{query}-{id}-',
  182. autosave_restore_when_empty: false,
  183. autosave_retention: '2m',
  184. image_advtab: true,
  185. link_list: [{
  186. title: 'My page 1',
  187. value: 'https://www.tiny.cloud'
  188. },
  189. {
  190. title: 'My page 2',
  191. value: 'http://www.moxiecode.com'
  192. }
  193. ],
  194. image_list: [{
  195. title: 'My page 1',
  196. value: 'https://www.tiny.cloud'
  197. },
  198. {
  199. title: 'My page 2',
  200. value: 'http://www.moxiecode.com'
  201. }
  202. ],
  203. image_class_list: [{
  204. title: 'None',
  205. value: ''
  206. },
  207. {
  208. title: 'Some class',
  209. value: 'class-name'
  210. }
  211. ],
  212. importcss_append: true,
  213. file_picker_callback: function(callback, value, meta) {
  214. /* Provide file and text for the link dialog */
  215. if (meta.filetype === 'file') {
  216. callback('https://www.google.com/logos/google.jpg', {
  217. text: 'My text'
  218. });
  219. }
  220. /* Provide image and alt text for the image dialog */
  221. if (meta.filetype === 'image') {
  222. callback('https://www.google.com/logos/google.jpg', {
  223. alt: 'My alt text'
  224. });
  225. }
  226. /* Provide alternative source and posted for the media dialog */
  227. if (meta.filetype === 'media') {
  228. callback('movie.mp4', {
  229. source2: 'alt.ogg',
  230. poster: 'https://www.google.com/logos/google.jpg'
  231. });
  232. }
  233. },
  234. templates: [{
  235. title: 'New Table',
  236. description: 'creates a new table',
  237. content: '<div class="mceTmpl"><table width="98%%" border="0" cellspacing="0" cellpadding="0"><tr><th scope="col"> </th><th scope="col"> </th></tr><tr><td> </td><td> </td></tr></table></div>'
  238. },
  239. {
  240. title: 'Starting my story',
  241. description: 'A cure for writers block',
  242. content: 'Once upon a time...'
  243. },
  244. {
  245. title: 'New list with dates',
  246. description: 'New List with dates',
  247. content: '<div class="mceTmpl"><span class="cdate">cdate</span><br /><span class="mdate">mdate</span><h2>My List</h2><ul><li></li><li></li></ul></div>'
  248. }
  249. ],
  250. template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
  251. template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
  252. height: 600,
  253. image_caption: true,
  254. quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
  255. noneditable_noneditable_class: 'mceNonEditable',
  256. toolbar_mode: 'sliding',
  257. contextmenu: 'link image imagetools table',
  258. skin: useDarkMode ? 'oxide-dark' : 'oxide',
  259. content_css: useDarkMode ? 'dark' : 'default',
  260. content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
  261. });
  262. /**
  263. * Initiate Bootstrap validation check
  264. */
  265. var needsValidation = document.querySelectorAll('.needs-validation')
  266. Array.prototype.slice.call(needsValidation)
  267. .forEach(function(form) {
  268. form.addEventListener('submit', function(event) {
  269. if (!form.checkValidity()) {
  270. event.preventDefault()
  271. event.stopPropagation()
  272. }
  273. form.classList.add('was-validated')
  274. }, false)
  275. })
  276. /**
  277. * Initiate Datatables
  278. */
  279. const datatables = select('.datatable', true)
  280. datatables.forEach(datatable => {
  281. new simpleDatatables.DataTable(datatable);
  282. })
  283. /**
  284. * Autoresize echart charts
  285. */
  286. const mainContainer = select('#main');
  287. if (mainContainer) {
  288. setTimeout(() => {
  289. new ResizeObserver(function() {
  290. select('.echart', true).forEach(getEchart => {
  291. echarts.getInstanceByDom(getEchart).resize();
  292. })
  293. }).observe(mainContainer);
  294. }, 200);
  295. }
  296. })();