Guest User

Untitled

a guest
Nov 17th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <% @posts.each do |post| %>
  2.   <div class="row">
  3.     <div class="leftcolumn">
  4.       <div class="card">
  5.         <%# javascript_path 'custom/tr' %>
  6.         <h2 lang="ru"><%= post.title %></h2>
  7.         <p lang="ru"><%= post.body %></p>
  8.         <button id="myBtn">Open Modal</button>
  9.  
  10.         <!-- The Modal -->
  11.         <div id="myModal" class="modal">
  12.  
  13.           <!-- Modal content -->
  14.           <div class="modal-content">
  15.             <span class="close">&times;</span>
  16.             <p><%= post.translation %></p>
  17.           </div>
  18.  
  19.         </div>
  20.       </div>
  21.     </div>
  22.   </div>
  23. <% end %>
  24. <%= will_paginate class: "apple_pagination" %>
  25. <script>
  26. // Get the modal
  27. var modal = document.getElementById("myModal");
  28.  
  29. // Get the button that opens the modal
  30. var btn = document.getElementById("myBtn");
  31.  
  32. // Get the <span> element that closes the modal
  33. var span = document.getElementsByClassName("close")[0];
  34.  
  35. // When the user clicks on the button, open the modal
  36. btn.onclick = function() {
  37.   modal.style.display = "block";
  38. }
  39.  
  40. // When the user clicks on <span> (x), close the modal
  41. span.onclick = function() {
  42.   modal.style.display = "none";
  43. }
  44.  
  45. // When the user clicks anywhere outside of the modal, close it
  46. window.onclick = function(event) {
  47.   if (event.target == modal) {
  48.     modal.style.display = "none";
  49.   }
  50. }
  51. </script>
Add Comment
Please, Sign In to add comment