popWin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(d)
  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(d)
  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. d.close()
  85. });
  86. },
  87. _lock: function(a) {
  88. switch (a) {
  89. case "off":
  90. $(".popLock").remove();
  91. break;
  92. default:
  93. $("body").append('<div class="popLock"></div>');
  94. break
  95. }
  96. },
  97. close: function(c, d) {
  98. if (c == "sub") {
  99. var a = this._testPrefix(),
  100. b = "";
  101. switch (d) {
  102. case "top":
  103. b = "translateY(-100%)";
  104. break;
  105. case "left":
  106. b = "translateX(-100%)";
  107. break;
  108. case "right":
  109. b = "translateX(100%)";
  110. break;
  111. default:
  112. b = "translateY(100%)";
  113. break
  114. }
  115. $("#popWinSub").attr("style", a + "transform: " + b);
  116. this._lock("off");
  117. setTimeout(function() {
  118. $("#popWinSub").remove()
  119. }, 300)
  120. } else {
  121. $("#popWin").hide();
  122. this._lock("off");
  123. setTimeout(function() {
  124. $(".header").css("z-index", 999);
  125. $("#popWin").remove()
  126. }, 300)
  127. }
  128. }
  129. };
  130. $(window).on('hashchange', function () {
  131. if (!(location.hash.indexOf('#') === 0)) {
  132. $('#popWin').remove();
  133. $('.popLock').remove();
  134. }
  135. });