Advertisement
DataCCIW

Dismissible Alert Shortcode Markup

Sep 6th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {% if type == 'standard' %}
  2. <div id='{{alertid}}' class="alert alert-{{ alertclass }} alert-dismissible" role="alert" style="">
  3.   <span onclick="cciwDismissibleAlert()" type="button" class="close" data-dismiss="alert" aria-label="Close"><span
  4.       aria-hidden="true">&times;</span></span>
  5.   <strong>{{ title }}</strong>
  6.   <p>{{ message }}</p>
  7. </div>
  8.  
  9. <script>
  10.   $(document).ready(function () {
  11.  
  12.     var alerted = localStorage.getItem('{{alertid}}') || '';
  13.     // hide the alert if a keyvalue pair of alertid,dismissed is found in local storage
  14.     if (alerted == 'dismissed') {
  15.       $('#{{alertid}}').toggle();
  16.     }
  17.  
  18.   });
  19.   function cciwDismissibleAlert() {
  20.     localStorage.setItem("{{alertid}}", "dismissed");
  21.   }
  22. </script>
  23.  
  24. {% elseif type == 'modal' %}
  25. <!-- Modal -->
  26. <div class="modal" id="CCIWModal" role="dialog">
  27.   <div class="modal-dialog">
  28.  
  29.     <!-- Modal content-->
  30.     <div class="modal-content">
  31.       <div class="modal-header">
  32.         <h4 class="modal-title">{{ title }}</h4>
  33.       </div>
  34.       <div class="modal-body">
  35.         {{ message }}
  36.       </div>
  37.       <div class="modal-footer">
  38.         <button type="button" class="btn btn-default" data-dismiss="modal">Dismiss Notification</button>
  39.       </div>
  40.     </div>
  41.  
  42.   </div>
  43. </div>
  44.  
  45. {% javascript %}
  46. $(document).ready(function() {
  47.  
  48. var storageItemID = '{{alertid}}';
  49.  
  50. // if the modal has not been previously dismissed display it
  51. if(localStorage.getItem('{{alertid}}') != 'dismiss'){
  52.   //https://getbootstrap.com/docs/4.0/components/modal/#via-javascript
  53.   $("#CCIWModal").modal();
  54. }
  55.  
  56. $('#CCIWModal button').click(function(e) // if the close or dismiss button are clicked
  57. {
  58.   // remember they dismissed an alert with the specified id
  59.   localStorage.setItem('{{alertid}}' ,'dismiss')
  60.   });
  61. });
  62. {% endjavascript %}
  63.  
  64. {% else %}
  65.  
  66. Please specify either 'standard' or 'modal' in the type parameter for this lava shortcode
  67.  
  68. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement