Sha256: 79c4ec9c9dea2a05bb6b93628560c248e0b72cdd0c0a35a73a9ea458271fd506

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

(function($, ns) {
  function isCancelButtonEvent(event) {
    var $target = $(event.target);
    var isExactlyButton = $target.hasClass('js-close-modal');
    var isChildOfButton = $target.parents('.js-close-modal').size() > 0;
    return isExactlyButton || isChildOfButton;
  }

  var Modal = function(target) {
    var self = this;
    this.target = $(target);

    this.target.dialog({
      dialogClass: "uc-modal-fixed-wrapper-frame js-uc-modal-fixed-wrapper-frame",
      autoOpen: false,
      show: "fade",
      hide: "fade",
      modal: true,
      draggable: false,
      resizable: false,
      open: function(event, ui) {
        var modalFixedWrapperFrame = $(event.target.parentElement);
        modalFixedWrapperFrame.wrap("<div class='uc-modal-fixed-wrapper'></div>");
        modalFixedWrapperFrame.wrap("<div class='container'></div>");
        modalFixedWrapperFrame.removeAttr("style");
        $(".ui-dialog-content", modalFixedWrapperFrame).removeAttr("style");
        modalFixedWrapperFrame.css("background", "none");
        $("body").addClass("modal-on");
        $('html, body').animate({ scrollTop: 0 }, 0);
        self.target.removeClass('js-hidden');

        self.target.click(function(event) {
          if(isCancelButtonEvent(event)) {
            self.close();
            event.preventDefault();
          }
        });
      },
      close: function(event, ui) {
        $("body").removeClass("modal-on");
        $('.uc-modal-fixed-wrapper').remove();
        self.target.trigger('closed');
        self.target.addClass('js-hidden');
      }
    })
  };

  Modal.prototype.open = function() {
    this.target.dialog("open");
  };

  Modal.prototype.close = function() {
    this.target.dialog("close");
  }

  ns.modal = Modal;
})(jQuery, window.undercase);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
undercase-0.2.57 app/assets/javascripts/undercase/patterns/modal.js