Guest User

Untitled

a guest
May 31st, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. (function($) {
  2. $.fn.extend({
  3. leanModal: function(options) {
  4. var defaults = {
  5. top: 100,
  6. overlay: 0.5,
  7. closeButton: null
  8. };
  9. var overlay = $("<div id='lean_overlay'></div>");
  10. $("body").append(overlay);
  11. options = $.extend(defaults, options);
  12. return this.each(function() {
  13. var o = options;
  14. $(this).click(function(e) {
  15. var modal_id = $(this).attr("href");
  16. $("#lean_overlay").click(function() {
  17. close_modal(modal_id)
  18. });
  19. $(o.closeButton).click(function() {
  20. close_modal(modal_id)
  21. });
  22. var modal_height = $(modal_id).outerHeight();
  23. var modal_width = $(modal_id).outerWidth();
  24. $("#lean_overlay").css({
  25. "display": "block",
  26. opacity: 0
  27. });
  28. $("#lean_overlay").fadeTo(200, o.overlay);
  29. $(modal_id).css({
  30. "display": "block",
  31. "position": "fixed",
  32. "opacity": 0,
  33. "z-index": 11000,
  34. "left": 50 + "%",
  35. "margin-left": -(modal_width / 2) + "px",
  36. "top": o.top + "px"
  37. });
  38. $(modal_id).fadeTo(200, 1);
  39. e.preventDefault()
  40. })
  41. });
  42.  
  43. function close_modal(modal_id) {
  44. $("#lean_overlay").fadeOut(200);
  45. $(modal_id).css({
  46. "display": "none"
  47. })
  48. }
  49. }
  50. })
  51. })(jQuery);
Add Comment
Please, Sign In to add comment