Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $episodes = [
- [
- 'episode_title' => 'Lorem Ipsum',
- 'description' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, whe<p>n an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."],
- [
- 'episode_title' => "The standard 'Lorem Ipsum' passage, used since the 1500s",
- 'description' => '"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud <p>exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."'
- ]
- ];
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <style>
- body {font-family: Arial, Helvetica, sans-serif;}
- .box {
- padding: 50px;
- border: solid 2px black;
- margin: 50px;
- }
- .triggersModal {
- cursor: pointer;
- }
- /* The Modal (background) */
- #myModal {
- display: none; /* Hidden by default */
- position: fixed; /* Stay in place */
- z-index: 1; /* Sit on top */
- padding-top: 100px; /* Location of the box */
- left: 0;
- top: 0;
- width: 100%; /* Full width */
- height: 100%; /* Full height */
- overflow: auto; /* Enable scroll if needed */
- background-color: rgb(0,0,0); /* Fallback color */
- background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
- }
- /* Modal Content */
- .modal-content {
- background-color: #fefefe;
- margin: auto;
- padding: 20px;
- border: 1px solid #888;
- width: 80%;
- }
- /* The Close Button */
- #modalCloser {
- color: #aaaaaa;
- float: right;
- font-size: 28px;
- font-weight: bold;
- }
- #modalCloser:hover,
- #modalCloser:focus {
- color: #000;
- text-decoration: none;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <?php
- foreach ($episodes as $index => $episode) {
- echo "<div class=\"box\">";
- echo "<div class=\"triggersModal\" data-index=\"{$index}\" data-content=\"episode_title\">";
- echo strlen($episode['episode_title']) <= 50
- ? htmlspecialchars($episode['episode_title'])
- : htmlspecialchars(substr($episode['episode_title'], 0, 50)) , "(...)";
- echo "</div>";
- echo "<div class=\"triggersModal\" data-index=\"{$index}\" data-content=\"description\">";
- echo strlen($episode['description']) <= 100
- ? htmlspecialchars($episode['description'])
- : htmlspecialchars(substr($episode['description'], 0, 100)) , "(...)";
- echo "</div>";
- echo "</div>";
- $episodes[$index] = ['episode_title' => htmlspecialchars($episode['episode_title']), 'description' => htmlspecialchars($episode['description'])];
- }
- ?>
- <!-- The Modal -->
- <div id="myModal" class="modal">
- <!-- Modal content -->
- <div class="modal-content">
- <span id="modalCloser">×</span>
- <p id="modalText"></p>
- </div>
- </div>
- <script>
- // Transfer data from php to javascript
- let lookup = <?php echo json_encode($episodes); ?>,
- classname = document.getElementsByClassName("triggersModal"),
- modal = document.getElementById("myModal");
- // Bind value insertion and modal display to onclick event of every element with named class
- for (let i = 0, len = classname.length; i < len; ++i) {
- classname[i].onclick = function() {
- document.getElementById("modalText").innerHTML = lookup[this.getAttribute('data-index')][this.getAttribute('data-content')];
- modal.style.display = "block";
- }
- }
- // Close the modal
- document.getElementById("modalCloser").onclick = function() {
- modal.style.display = "none";
- }
- // When the user clicks anywhere outside of the modal, close it
- window.onclick = function(event) {
- if (event.target == modal) {
- modal.style.display = "none";
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment