This repository was archived by the owner on Jan 20, 2021. It is now read-only.
File tree 2 files changed +29
-11
lines changed
2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " piedweb-cms-js-helpers" ,
3
- "version" : " 0.0.9 " ,
3
+ "version" : " 0.0.10 " ,
4
4
"description" : " PiedWeb/CMS (php)'s javascript functions for ui front end (native)" ,
5
5
"author" :
" Robin D. <[email protected] >" ,
6
6
"license" : " MIT" ,
Original file line number Diff line number Diff line change 12
12
*/
13
13
14
14
/**
15
+ * Live Block Watcher (and button)
16
+ *
15
17
* Fetch (ajax) function permitting to get block via a POST request
16
- * (prevent from spam)
17
18
*
18
19
* @param {string } attribute
19
20
*/
20
21
export function liveBlock ( attribute = "data-live" ) {
21
- document . querySelectorAll ( "[" + attribute + "]" ) . forEach ( item => {
22
+
23
+ var btnToBlock = function ( event , btn ) {
24
+ btn . setAttribute ( attribute , btn . getAttribute ( "src-" + attribute ) ) ;
25
+ getLiveBlock ( btn ) ;
26
+ }
27
+
28
+ var getLiveBlock = function ( item ) {
22
29
fetch ( item . getAttribute ( attribute ) , {
23
30
//headers: { "Content-Type": "application/json", Accept: "text/plain" },
24
31
method : "POST" ,
25
32
credentials : "include"
26
33
} )
27
- . then ( function ( response ) {
28
- return response . text ( ) ;
29
- } )
30
- . then ( function ( body ) {
31
- item . removeAttribute ( attribute ) ;
32
- item . innerHTML = body ;
34
+ . then ( function ( response ) {
35
+ return response . text ( ) ;
36
+ } )
37
+ . then ( function ( body ) {
38
+ item . removeAttribute ( attribute ) ;
39
+ item . outerHTML = body ;
33
40
34
- document . dispatchEvent ( new Event ( "DOMChanged" ) ) ;
35
- } ) ;
41
+ document . dispatchEvent ( new Event ( "DOMChanged" ) ) ;
42
+ } ) ;
43
+ }
44
+
45
+ document . querySelectorAll ( "[" + attribute + "]" ) . forEach ( item => {
46
+ getLiveBlock ( item ) ;
36
47
} ) ;
48
+
49
+ document . querySelectorAll ( "[src-" + attribute + "]" ) . forEach ( item => {
50
+ item . addEventListener ( "click" , event => {
51
+ btnToBlock ( event , item ) ;
52
+ } ) ;
53
+ } ) ;
54
+
37
55
}
38
56
39
57
/**
You can’t perform that action at this time.
0 commit comments