popWin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var popWin = {
  2. param: {
  3. title: "",
  4. html: "",
  5. handle: "",
  6. from: "bottom",
  7. },
  8. mod: document.createElement("modernizr").style,
  9. _testPrefix: function() {
  10. var a = ["Webkit", "Moz", "O", "ms"],
  11. c, b = this;
  12. for (c in a) {
  13. if (this._testProps([a[c] + "Transform"])) {
  14. return "-" + a[c].toLowerCase() + "-"
  15. }
  16. }
  17. return ""
  18. },
  19. _testProps: function(b) {
  20. var a;
  21. for (a in b) {
  22. if (this.mod[b[a]] !== undefined) {
  23. return true
  24. }
  25. }
  26. return false
  27. },
  28. init: function(e) {
  29. var b = this._testPrefix(),
  30. g = b.replace(/^\-/, "").replace(/\-$/, "").replace("moz", "Moz"),
  31. d = this,
  32. f = "",
  33. a = "",
  34. e = $.extend({}, this.param, e);
  35. switch (e.from) {
  36. case "top":
  37. f = "translateY(-100%)";
  38. a = "translateY(0)";
  39. break;
  40. case "left":
  41. f = "translateX(-100%)";
  42. a = "translateX(0)";
  43. break;
  44. case "right":
  45. f = "translateX(100%)";
  46. a = "translateX(0)";
  47. break;
  48. default:
  49. f = "translateY(100%)";
  50. a = "translateY(0)";
  51. break
  52. }
  53. if ($("#popWin").length) {
  54. var c = '<div id="popWinSub" style="' + b + "transform: " + f + ';"><div class="popheader"><ul class="clear"><li class="popSubBack"><i class="l_arow"></i></li><li class="poptitle"><p>' + e.title + '</p></li></ul></div><div class="popBody">' + e.html + "</div></div>";
  55. $("body").append(c);
  56. d._lock();
  57. setTimeout(function() {
  58. $("#popWinSub").attr("style", b + "transform: " + a);
  59. if (e.handle && typeof e.handle == "function") {
  60. e.handle()
  61. }
  62. $(".popSubBack").on("click", function() {
  63. d.close("sub", e.from)
  64. });
  65. $(".header").css("z-index", 7)
  66. }, 100)
  67. } else {
  68. var c = '<div id="popWin" style="' + b + "transform: " + f + ';"><div class="popheader"><ul class="clear"><li class="popBack"><i class="l_arow"></i></li><li class="poptitle"><p>' + e.title + '</p></li></ul></div><div class="popBody">' + e.html + "</div></div>";
  69. $("body").append(c);
  70. d._lock();
  71. setTimeout(function() {
  72. $("#popWin").attr("style", b + "transform: " + a);
  73. if (e.handle && typeof e.handle == "function") {
  74. e.handle()
  75. }
  76. $(".popBack").on("click", function() {
  77. d.close()
  78. });
  79. $(".header").css("z-index", 7)
  80. }, 100)
  81. }
  82. $('.js-back').on('click', function () {
  83. history.back();
  84. });
  85. },
  86. _lock: function(a) {
  87. switch (a) {
  88. case "off":
  89. $(".popLock").remove();
  90. break;
  91. default:
  92. $("body").append('<div class="popLock"></div>');
  93. break
  94. }
  95. },
  96. close: function(c, d) {
  97. if (c == "sub") {
  98. var a = this._testPrefix(),
  99. b = "";
  100. switch (d) {
  101. case "top":
  102. b = "translateY(-100%)";
  103. break;
  104. case "left":
  105. b = "translateX(-100%)";
  106. break;
  107. case "right":
  108. b = "translateX(100%)";
  109. break;
  110. default:
  111. b = "translateY(100%)";
  112. break
  113. }
  114. $("#popWinSub").attr("style", a + "transform: " + b);
  115. this._lock("off");
  116. setTimeout(function() {
  117. $("#popWinSub").remove()
  118. }, 300)
  119. } else {
  120. $("#popWin").hide();
  121. this._lock("off");
  122. setTimeout(function() {
  123. $(".header").css("z-index", 999);
  124. $("#popWin").remove()
  125. }, 300)
  126. }
  127. }
  128. };
  129. $(window).on('hashchange', function () {
  130. if (!(location.hash.indexOf('#') === 0)) {
  131. $('#popWin').remove();
  132. $('.popLock').remove();
  133. }
  134. });