Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.twpopup = (function() {
  2.     console.log("bruh");
  3.  
  4.     function Popup() {
  5.         console.log("Popup()");
  6.     }
  7.  
  8.     var popup = {
  9.         modal: function(title, content, buttons = []) {
  10.  
  11.             let buttons_html = "";
  12.             /*
  13.                 {
  14.                     title: 'Button Title',
  15.                     attributes: [
  16.                         {
  17.                             attr:'',
  18.                             value:''
  19.                         }
  20.                     ],
  21.  
  22.                     onClick: function(){
  23.                        
  24.                     }
  25.                 }
  26.             */
  27.  
  28.             for (var i = buttons.length - 1; i >= 0; i--) {
  29.                 let button = buttons[i];
  30.  
  31.                 let attributes_html = ``;
  32.                 let custom_classes = ``;
  33.  
  34.                 if ("attributes" in button && button.attributes.length > 0) {
  35.                     for (var j = button.attributes.length - 1; j >= 0; j--) {
  36.                         if (button.attributes[j].attr === 'class') {
  37.                             custom_classes += " " + button.attributes[j].value;
  38.                         } else {
  39.                             attributes_html += `${button.attributes[j].attr}="${button.attributes[j].value}" `;
  40.                         }
  41.                     }
  42.                 }
  43.  
  44.                 let unique_id = "twsnipper-click-handler-" + Date.now();
  45.                 let button_html = `<button type='button' id='${unique_id}' ${attributes_html} class='btn btn-primary ${custom_classes}'>${button.title}</button>`;
  46.  
  47.                 if ("onClick" in button) {
  48.                     $(document).on('click', '#' + unique_id, button.onClick);
  49.                 }
  50.  
  51.                 buttons_html += button_html + "\n";
  52.             }
  53.  
  54.             jQuery('body').append(`
  55.                 <div id="create_review_modal" tabindex="0" class="lbox-wrapper ${CLASSES.POPUP}">
  56.                     <div id="overlay1" class="overlay " style="height: 1186px; z-index: 130;"></div>
  57.                     <div id="box1" class="lbox " style="width: 662px; height: 650px; position: fixed; z-index: 131; left: 609px; top: 20%; opacity: 1; margin-top: 0px;">
  58.                         <a class="w-modal-close ${CLASSES.POPUP_CLOSE}">X</a>
  59.                         <div id="boxContents1" class="lboxContents modal">
  60.                             <div class="sectionFormLightbox">
  61.                                 <div class="modal-header">
  62.                                     <h2 class="modal-title">${title}</h2>
  63.                                 </div>
  64.                                 <div class="modal-body">${content}</div>
  65.                                 <div class="modal-footer flex">
  66.                                     ${buttons_html}
  67.                                     <button type="button" class="${CLASSES.POPUP_CLOSE} btn btn-secondary" data-dismiss="modal">Cancel</button>
  68.                                 </div>
  69.                             </div>
  70.                         </div>
  71.                     </div>
  72.                     <div class="modal-tab-catcher" tabindex="0"></div>
  73.                 </div>
  74.             `);
  75.         }
  76.     };
  77.  
  78.     return popup;
  79. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement