git.fiddlerwoaroof.com
js/handyModal.jquery.js
7166c650
 scriptTag = null;
523cbe71
 (function ($) {
 
278628b9
   var currentModal = null;
7166c650
   $.fn.handyModal = function() {
2ebc712b
       'use strict';
       var self=this;
       var $self = $(self);
 
7166c650
       if ($self.length === 1 && $self[0].handyModal !== undefined) { return $self[0].handyModal; }
2ebc712b
 
       $(self).each(function() {
7166c650
           if (this.handyModal === undefined) {
2ebc712b
               var target = $(this.dataset.target);
7166c650
               var targetModal = target.data('handyModal');
2ebc712b
               var action = this.dataset.action;
7166c650
               var wrapper = target.closest('.handyModal-wrapper');
2ebc712b
 
               if (targetModal === undefined) {
                   var modal = $('<div></div>');
7166c650
                   wrapper = $('<div class="handyModal-wrapper"></div>').append(modal);
2ebc712b
 
                   modal.append(target);
7166c650
                   modal.wrap('<div class="handyModal">');
2ebc712b
                   $('body').append(wrapper);
 
                   wrapper.click(function() {
                       wrapper.removeClass('open');
                       currentModal = null;
                   });
 
                   if (! target.hasClass('close-on-click')) {
                       modal.click(function(ev) {
                           ev.stopPropagation();
                       });
                   }
 
                   target.removeClass('preinit');
               }
 
7166c650
               this.handyModal = {
2ebc712b
                   target: target,
                   action: action,
                   wrapper: wrapper,
 
                   open: function() {
                       this.wrapper.addClass('open');
                       if (currentModal !== null) { currentModal.removeClass('open'); }
                       currentModal = wrapper;
                   },
                   close: function() {
                       currentModal = null;
                       this.wrapper.removeClass('open');
                   }
               };
 
               if (targetModal === undefined) {
7166c650
                   target.data('handyModal', this.handyModal);
2ebc712b
               }
4327ebe2
 
2ebc712b
               $(this).click(function() {
                   console.log('this should happen');
7166c650
                   if (action === 'open') { this.handyModal.open(); }
                   else if (action === 'close') { this.handyModal.close(); }
2ebc712b
               });
7166c650
           }
523cbe71
       });
01e32cd3
       return this;
2ebc712b
   };
7166c650
 
   $(document).ready(function() {
     scriptTag = document.querySelector('script#handyModal');
 
     if (scriptTag && scriptTag.dataset.hasOwnProperty('initialize')) {
       $('[data-target]').handyModal();
     }
   });
523cbe71
 }( jQuery ));