PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.14.6
Independent Analytics – WordPress Analytics Plugin v2.14.6
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / javascript-source / controllers / refresh_overview_controller.js

refresh_overview_controller.js in Independent Analytics – WordPress Analytics Plugin 2.14.6, at javascript-source/controllers/refresh_overview_controller.js

57 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {Controller} from "@hotwired/stimulus"
2
3 export default class extends Controller {
4 static values = {
5 loadingText: String
6 }
7
8 refresh() {
9 const data = {
10 ...iawpActions.refresh_modules
11 }
12
13 const originalText = this.element.innerText
14 this.element.innerText = this.loadingTextValue
15 this.element.setAttribute('disabled', 'disabled')
16 this.fadeOutModules()
17
18 jQuery.post(ajaxurl, data, (response) => {
19 this.element.innerText = originalText
20 this.element.removeAttribute('disabled')
21 response.data.modules.forEach(module => this.replaceModule(module.id, module.html))
22 document.getElementById('iawp-modules-refreshed-at').innerText = response.data.modulesRefreshedAt
23 }).fail((error) => {
24 this.element.innerText = originalText
25 this.element.removeAttribute('disabled')
26 })
27 }
28
29 fadeOutModules() {
30 const elements = Array.from(document.querySelectorAll('.module:not(.module-picker)'))
31
32 elements.forEach((element) => {
33 element.classList.add('will-be-refreshed')
34 // element.querySelector('[popover]').hidePopover()
35 // element.querySelector('[popovertarget]').setAttribute('disabled', 'disabled')
36 })
37 }
38
39 replaceModule(moduleId, html) {
40 const elementToReplace = document.querySelector(`[data-module-module-id-value="${moduleId}"]`)
41
42 if(!elementToReplace) {
43 return
44 }
45
46 const isDraggable = elementToReplace.classList.contains('draggable-module')
47 elementToReplace.outerHTML = html
48
49 // Update the new module with whatever draggable state the replaced module had
50 setTimeout(() => {
51 const module = document.querySelector(`[data-module-module-id-value="${moduleId}"]`)
52 if(module) {
53 module.classList.toggle('draggable-module', isDraggable)
54 }
55 }, 0)
56 }
57 }