230 lines
7.0 KiB
PHP
230 lines
7.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlaza;
|
||
|
|
defined( 'ABSPATH' ) || exit;
|
||
|
|
|
||
|
|
class Modal {
|
||
|
|
|
||
|
|
public static bool $css_loaded = false;
|
||
|
|
public static bool $modal_manage_loaded = false;
|
||
|
|
|
||
|
|
public final string $modal_id;
|
||
|
|
public string $modal_title;
|
||
|
|
public string $modal_content;
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
string $modal_id,
|
||
|
|
string $modal_title = "",
|
||
|
|
string $modal_html_content = "",
|
||
|
|
) {
|
||
|
|
$this->modal_id = $modal_id;
|
||
|
|
$this->modal_title = $modal_title;
|
||
|
|
$this->modal_content = $modal_html_content;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function the_modal_css(){
|
||
|
|
|
||
|
|
if( static::$css_loaded === false ){
|
||
|
|
|
||
|
|
?>
|
||
|
|
<style>
|
||
|
|
|
||
|
|
#wpbody {
|
||
|
|
|
||
|
|
--text-color: #454545;
|
||
|
|
--page-background-color: #fff;
|
||
|
|
--link-color: #db7f00;
|
||
|
|
--link-hover-color: #454545;
|
||
|
|
--widget-title-color: #454545;
|
||
|
|
--content-border-color: #454545;
|
||
|
|
--light-border-color: rgba( 0, 0, 0, 15 );
|
||
|
|
--widget-title-font: 'Magra'
|
||
|
|
|
||
|
|
}
|
||
|
|
.rhpz-modal {
|
||
|
|
display: none;
|
||
|
|
position: fixed;
|
||
|
|
z-index: 1;
|
||
|
|
padding-top: 100px;
|
||
|
|
left: 0;
|
||
|
|
top: 0;
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
overflow: auto;
|
||
|
|
background-color: rgb(0,0,0);
|
||
|
|
background-color: rgba(0,0,0,0.4);
|
||
|
|
color: var(--text-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.rhpz-modal-content {
|
||
|
|
position: relative;
|
||
|
|
background-color: var(--page-background-color);
|
||
|
|
margin: auto;
|
||
|
|
padding: 0;
|
||
|
|
border: 1px solid #888;
|
||
|
|
border-radius: 0 0 10px 10px;
|
||
|
|
width: 50%;
|
||
|
|
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
|
||
|
|
-webkit-animation-name: animatetop;
|
||
|
|
-webkit-animation-duration: 0.4s;
|
||
|
|
animation-name: animatetop;
|
||
|
|
animation-duration: 0.4s
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (max-width: 850px) {
|
||
|
|
.rhpz-modal-content {
|
||
|
|
width: 90%;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.close {
|
||
|
|
color: var(--link-color);
|
||
|
|
float: right;
|
||
|
|
font-size: 28px;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
|
||
|
|
.close:hover,
|
||
|
|
.close:focus {
|
||
|
|
color: var(--link-hover-color);
|
||
|
|
text-decoration: none;
|
||
|
|
cursor: pointer;
|
||
|
|
}
|
||
|
|
|
||
|
|
.rhpz-modal-header {
|
||
|
|
padding: 2px 16px;
|
||
|
|
color: var(--widget-title-color);
|
||
|
|
box-shadow: inset 0 2px var(--content-border-color);
|
||
|
|
border-bottom: 1px solid;
|
||
|
|
border-color: var(--light-border-color);
|
||
|
|
font-family: var(--widget-title-font);
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
.rhpz-modal-body {
|
||
|
|
padding: 10px 16px;
|
||
|
|
}
|
||
|
|
|
||
|
|
@-webkit-keyframes animatetop {
|
||
|
|
from {top:-300px; opacity:0}
|
||
|
|
to {top:0; opacity:1}
|
||
|
|
}
|
||
|
|
|
||
|
|
@keyframes animatetop {
|
||
|
|
from {top:-300px; opacity:0}
|
||
|
|
to {top:0; opacity:1}
|
||
|
|
}
|
||
|
|
|
||
|
|
.rhpz-modal-iframe {
|
||
|
|
|
||
|
|
height: 450px !important;
|
||
|
|
/* overflow: hidden; */
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
</style>
|
||
|
|
|
||
|
|
<?php
|
||
|
|
|
||
|
|
static::$css_loaded = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function the_modal_js(){
|
||
|
|
|
||
|
|
if( static::$modal_manage_loaded === false ){
|
||
|
|
|
||
|
|
?>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
|
||
|
|
function romhackplaza_manage_modal(
|
||
|
|
modal_obj,
|
||
|
|
new_css_display = "block",
|
||
|
|
new_title = "",
|
||
|
|
new_content = "",
|
||
|
|
new_html_content = "",
|
||
|
|
){
|
||
|
|
modal_obj.modal.style.display = new_css_display;
|
||
|
|
|
||
|
|
if( new_title !== "" )
|
||
|
|
modal_obj.title.textContent = new_title;
|
||
|
|
|
||
|
|
if( new_content !== "" && new_html_content === "" ){
|
||
|
|
|
||
|
|
modal_obj.html.innerHTML = "";
|
||
|
|
modal_obj.content = document.createElement("p");
|
||
|
|
modal_obj.content.id = modal_obj.id + "-content";
|
||
|
|
modal_obj.html.appendChild( modal_obj.content );
|
||
|
|
modal_obj.content.innerHTML = new_content;
|
||
|
|
|
||
|
|
}
|
||
|
|
else if( new_html_content !== "" )
|
||
|
|
modal_obj.html.innerHTML = new_html_content;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<?php
|
||
|
|
|
||
|
|
static::$modal_manage_loaded = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|
||
|
|
|
||
|
|
<script defer>
|
||
|
|
|
||
|
|
const romhackplaza_modal_<?php echo $this->modal_id; ?> = (function(){
|
||
|
|
|
||
|
|
const MODAL_ID = "<?php echo $this->modal_id; ?>";
|
||
|
|
let modal = document.getElementById( MODAL_ID );
|
||
|
|
let close_button = document.getElementById( MODAL_ID + "-close" );
|
||
|
|
let title = document.getElementById( MODAL_ID + "-title" );
|
||
|
|
let html_iframe = document.getElementById( MODAL_ID + "-html-content" );
|
||
|
|
let content = document.getElementById( MODAL_ID + "-content" );
|
||
|
|
|
||
|
|
let obj = {
|
||
|
|
"id": MODAL_ID,
|
||
|
|
"modal": modal,
|
||
|
|
"title": title,
|
||
|
|
"html": html_iframe,
|
||
|
|
"content": content,
|
||
|
|
"close_button": close_button,
|
||
|
|
}
|
||
|
|
|
||
|
|
close_button.onclick = () => romhackplaza_manage_modal( obj, 'none' );
|
||
|
|
window.addEventListener( 'click', (e) => { if( e.target === modal ) romhackplaza_manage_modal( obj, 'none' ) } );
|
||
|
|
|
||
|
|
return obj;
|
||
|
|
|
||
|
|
})();
|
||
|
|
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<?php
|
||
|
|
}
|
||
|
|
|
||
|
|
public function render() {
|
||
|
|
|
||
|
|
$this->the_modal_css();
|
||
|
|
?>
|
||
|
|
<div id="<?php echo $this->modal_id; ?>" class="rhpz-modal">
|
||
|
|
<div class="rhpz-modal-content">
|
||
|
|
<div class="rhpz-modal-header">
|
||
|
|
<span id="<?php echo $this->modal_id . '-close'; ?>" class="close">×</span>
|
||
|
|
<h2 id="<?php echo $this->modal_id . '-title'; ?>"><?php echo $this->modal_title; ?></h2>
|
||
|
|
</div>
|
||
|
|
<div id="<?php echo $this->modal_id . '-html-content'; ?>" class="rhpz-modal-body">
|
||
|
|
<?php echo $this->modal_content; ?>
|
||
|
|
<p id="<?php echo $this->modal_id . '-content'; ?>"></p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<?php
|
||
|
|
$this->the_modal_js();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|