| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
|
| 5 |
import { RawHTML } from '@wordpress/element'; |
| 6 |
|
| 7 |
const save = ({ attributes }) => { |
| 8 |
const { |
| 9 |
countStyles, |
| 10 |
timerType, |
| 11 |
datetime, |
| 12 |
thour, |
| 13 |
tmin, |
| 14 |
tsec, |
| 15 |
hide, |
| 16 |
url, |
| 17 |
unitNum, |
| 18 |
unitTime, |
| 19 |
repeats, |
| 20 |
news, |
| 21 |
} = attributes; |
| 22 |
|
| 23 |
const isHide = hide ? 'true' : 'false'; |
| 24 |
|
| 25 |
const tim = timerType === 'repeat' && thour && tmin && tsec ? true : false; |
| 26 |
const exp = datetime ? datetime.replace(/\//g, '-') : ''; |
| 27 |
const expTime = |
| 28 |
timerType === 'onetime' && exp && !tim ? 'expire="' + exp + '"' : ''; |
| 29 |
const timerTime = tim |
| 30 |
? 'timer="' + thour + ':' + tmin + ':' + tsec + '"' |
| 31 |
: ''; |
| 32 |
const isNews = news ? ' subscr="' + news : ' subscr="undefined"'; |
| 33 |
|
| 34 |
const rectype = unitNum && repeats ? unitTime : ''; |
| 35 |
|
| 36 |
// [ujicountdown id="test" expire="2020/04/30 06:04" hide="true" url="" subscr="undefined" recurring="" rectype="second" repeats=""] |
| 37 |
const myShortcode = |
| 38 |
'[ujicountdown id="' + |
| 39 |
countStyles + |
| 40 |
'" ' + |
| 41 |
expTime + |
| 42 |
' ' + |
| 43 |
timerTime + |
| 44 |
' hide="' + |
| 45 |
isHide + |
| 46 |
'" url="' + |
| 47 |
url + |
| 48 |
'"' + |
| 49 |
isNews + |
| 50 |
'" recurring="' + |
| 51 |
repeats + |
| 52 |
'" rectype="' + |
| 53 |
rectype + |
| 54 |
'" repeats="' + |
| 55 |
repeats + |
| 56 |
'"]'; |
| 57 |
|
| 58 |
return <RawHTML>{myShortcode}</RawHTML>; |
| 59 |
}; |
| 60 |
|
| 61 |
export default save; |
| 62 |
|