fs_forse.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. (function(d, m, g) {
  2. function t(a, c, d, b) {
  3. if (a > d || c > b) {
  4. var f = a / d,
  5. e = c / b;
  6. f > e ? (a = d, c /= f) : (a /= e, c = b)
  7. }
  8. return {
  9. width: a,
  10. height: c
  11. }
  12. }
  13. function p(a, c) {
  14. var d = ["-webkit-", "-moz-", "-o-", "-ms-", ""],
  15. b = {},
  16. f, e = d.length;
  17. for (f = 0; f < e; f++) b[d[f] + a] = c;
  18. return b
  19. }
  20. function u(a) {
  21. return css3 ? p("transform", "translate(" + a + "px, 0)") : {
  22. left: a
  23. }
  24. }
  25. var h = 0,
  26. v = function(a, c, d) {
  27. function b(b, a) {
  28. for (var c in b)
  29. if (g[b[c]] !== d) return "pfx" == a ? b[c] : !0;
  30. return !1
  31. }
  32. function f(a, c, f) {
  33. var e = a.charAt(0).toUpperCase() + a.substr(1),
  34. g = (a + " " + m.join(e + " ") + e).split(" ");
  35. if ("string" === typeof c || "undefined" === typeof c) c = b(g, c);
  36. else a: {
  37. g = (a + " " + l.join(e + " ") + e).split(" "), a = g;
  38. for (var n in a)
  39. if (e = c[a[n]], e !== d) {
  40. c = !1 === f ? a[n] : "function" === typeof e ? e.bind(f || c) : e;
  41. break a
  42. }
  43. c = !1
  44. }
  45. return c
  46. }
  47. a = {};
  48. var e = c.createElement("modernizr"),
  49. g = e.style,
  50. m = ["Webkit", "Moz", "O", "ms"],
  51. l = ["webkit", "moz", "o", "ms"],
  52. e = {},
  53. n = [],
  54. r = n.slice,
  55. q, h = {}.hasOwnProperty,
  56. k;
  57. "undefined" === typeof h || "undefined" === typeof h.call ? k = function(b, a) {
  58. return a in b && "undefined" === typeof b.constructor.prototype[a]
  59. } : k = function(b, a) {
  60. return h.call(b, a)
  61. };
  62. Function.prototype.bind || (Function.prototype.bind = function(b) {
  63. var a = this;
  64. if ("function" != typeof a) throw new TypeError;
  65. var c = r.call(arguments, 1),
  66. d = function() {
  67. if (this instanceof d) {
  68. var l = function() {};
  69. l.prototype = a.prototype;
  70. var l = new l,
  71. e = a.apply(l, c.concat(r.call(arguments)));
  72. return Object(e) === e ? e : l
  73. }
  74. return a.apply(b, c.concat(r.call(arguments)))
  75. };
  76. return d
  77. });
  78. e.canvas = function() {
  79. var b = c.createElement("canvas");
  80. return !!b.getContext && !!b.getContext("2d")
  81. };
  82. e.csstransforms = function() {
  83. return !!f("transform")
  84. };
  85. e.csstransitions = function() {
  86. return f("transition")
  87. };
  88. for (var s in e) k(e, s) && (q = s.toLowerCase(), a[q] = e[s](), n.push((a[q] ? "" : "no-") + q));
  89. g.cssText = "";
  90. return e = null, a._version = "2.5.3", a._domPrefixes = l, a._cssomPrefixes = m, a.testProp = function(a) {
  91. return b([a])
  92. }, a.testAllProps = f, a
  93. }(this, this.document);
  94. css3 = v.csstransforms && v.csstransitions;
  95. touch = "ontouchstart" in m;
  96. mobile = navigator.userAgent.toLowerCase().match(/(android|iphone|ipod|ipad|iemobile|windows ce|netfront|playstation|midp|up\.browser|symbian|nintendo|wii)/);
  97. var k = function(a, c) {
  98. this.e = d(a);
  99. this.o = d.extend({}, d.fn.fsgallery.defaults, c);
  100. this.i = 0;
  101. this.w = g.innerWidth || d(g).innerWidth();
  102. this.h = g.innerHeight || d(g).innerHeight();
  103. this.createArray();
  104. this.createHtml();
  105. this.createImages();
  106. this.events()
  107. };
  108. k.prototype = {
  109. constructor: k,
  110. createArray: function() {
  111. var a = this;
  112. a.images = [];
  113. a.e.parent("a").length ? a.e.parent("a").each(function() {
  114. a.images.push({
  115. src: this.href,
  116. alt: d(this).find("img")[0].alt
  117. })
  118. }) : a.e.each(function() {
  119. a.images.push({
  120. src: this.src,
  121. alt: this.alt
  122. })
  123. })
  124. },
  125. createHtml: function() {
  126. d("body").append(this.gallery = d('<div class="fs_gallery">').hide().append(mobile ? "" : this.prev = d('<div class="fs_gallery_prev">'), mobile ? "" : this.next = d('<div class="fs_gallery_next">'), this.close = d('<div class="fs_gallery_close">'), this.shuft = d('<div class="fs_gallery_shuft">'), d('<div class="fs_gallery_thumbs">').append(this.fs_thumbs_list = d('<div class="fs_gallery_thumbs_list">'))))
  127. },
  128. createImages: function() {
  129. var a, c = this.images.length;
  130. for (a = 0; a < c; a++) this.shuft.append(d('<div class="fs_gallery_shuft_item">').css({
  131. width: this.w,
  132. height: this.h
  133. }))
  134. },
  135. loadImg: function(a, c) {
  136. d("<img>", {
  137. src: this.images[a].src,
  138. alt: this.images[a].alt
  139. }).on("load", function() {
  140. c(a, d(this))
  141. })
  142. },
  143. events: function() {
  144. function a(a) {
  145. a.preventDefault();
  146. f = (a.pageX || a.targetTouches[0].pageX) - b.pos;
  147. touch ? b.shuft[0].addEventListener("touchmove", c, !1).addEventListener("touchend", h, !1) : d(m).mousemove(c).mouseup(h)
  148. }
  149. function c(a) {
  150. a.preventDefault();
  151. e = !0;
  152. b.pos = (a.pageX || a.targetTouches[0].pageX) - f;
  153. clearInterval(k);
  154. b.animate(b.pos, 0);
  155. b.pos - -(b.i * b.w) > b.w / 4 && (b.goTo(-1), d(this).unbind("mousemove touchmove"));
  156. b.pos - -(b.i * b.w) < -b.w / 4 && (b.goTo(1), d(this).unbind("mousemove touchmove"))
  157. }
  158. function h(a) {
  159. e || b.goTo(1);
  160. b.pos - -(b.i * b.w) > -b.w / 4 && b.animate(-b.i * b.w, p);
  161. d(this).unbind("mousemove mouseup touchend");
  162. e = !1
  163. }
  164. var b = this,
  165. f = 0,
  166. e = !1,
  167. k, p = b.o.duration;
  168. b.pos = 0;
  169. touch ? b.shuft[0].addEventListener("touchstart", a, !1) : d(b.shuft).delegate("img", "mousedown", a);
  170. mobile || (b.prev.click(function() {
  171. b.goTo(-1)
  172. }), b.next.click(function() {
  173. b.goTo(1)
  174. }));
  175. d(g).resize(function() {
  176. b.w = g.innerWidth || d(g).innerWidth();
  177. b.h = g.innerHeight || d(g).innerHeight();
  178. var a = b.images[b.i],
  179. a = t(a.width, a.height, b.w, b.h);
  180. b.shuft.find("div").css({
  181. width: b.w,
  182. height: b.h
  183. }).find("img").css({
  184. width: a.width,
  185. height: a.height,
  186. marginLeft: -a.width / 2,
  187. marginTop: -a.height / 2
  188. });
  189. b.animate(-b.i * b.w, 0)
  190. });
  191. (b.e.parent("a").length ? b.e.parent("a") : b.e).click(function(a) {
  192. a.preventDefault();
  193. a = b;
  194. var c;
  195. a: {
  196. var d = this.src || this.href;
  197. for (c in b.images)
  198. if (b.images[c].src == d) {
  199. c = parseInt(c);
  200. break a
  201. }
  202. c = void 0
  203. }
  204. a.i = c;
  205. b.checkLoad();
  206. b.animate(-b.i * b.w, 0);
  207. b.show()
  208. });
  209. b.close.click(function() {
  210. b.hide()
  211. });
  212. b.gallery.click(function(a) {
  213. d(a.target).hasClass("fs_gallery_shuft_item") && b.hide()
  214. });
  215. d(m).keydown(function(a) {
  216. 27 == a.keyCode ? b.hide() : 37 == a.keyCode && b.gallery.is(":visible") ? b.goTo(-1) : 39 == a.keyCode && b.gallery.is(":visible") && b.goTo(1)
  217. })
  218. },
  219. checkLoad: function() {
  220. var a = this.images.length - 1,
  221. c;
  222. for (c = this.i - this.o.preload; c <= this.i + this.o.preload; c++) 0 > c ? this.o.loop && this.preload(a + c + 1) : c > a ? this.o.loop && this.preload(c - a) : this.preload(c)
  223. },
  224. preload: function(a) {
  225. var c = this,
  226. d = c.shuft.children("div").eq(a);
  227. d.data().loaded || (d.data({
  228. loaded: !0
  229. }), c.loadImg(a, function(a, f) {
  230. size = t(f[0].width, f[0].height, c.w, c.h);
  231. c.images[a].width = f[0].width;
  232. c.images[a].height = f[0].height;
  233. d.append(f.css({
  234. width: size.width,
  235. height: size.height,
  236. marginLeft: -size.width / 2,
  237. marginTop: -size.height / 2
  238. }).fadeIn(c.o.fadeTime))
  239. }))
  240. },
  241. show: function() {
  242. this.gallery.fadeIn(500)
  243. },
  244. hide: function() {
  245. this.gallery.fadeOut(500)
  246. },
  247. animate: function(a, c) {
  248. css3 ? this.shuft.css(p("transition-duration", c + "ms")).css(u(a)) : this.shuft.animate(u(a), c);
  249. this.pos = a
  250. },
  251. getIndex: function(a) {
  252. 0 > a && (a = this.o.loop ? this.images.length - 1 : 0);
  253. a > this.images.length - 1 && (a = this.o.loop ? 0 : this.images.length - 1);
  254. return a
  255. },
  256. goTo: function(a) {
  257. this.i = this.getIndex(this.i + a);
  258. this.animate(-this.i * this.w, this.o.duration);
  259. this.checkLoad()
  260. }
  261. };
  262. d.fn.fsgallery = function(a) {
  263. h++;
  264. var c = d(m.body);
  265. c.data("fsgallery_" + h) || c.data("fsgallery_" + h, new k(this, a));
  266. return this
  267. };
  268. d.fn.fsgallery.defaults = {
  269. duration: 500,
  270. loop: !1,
  271. preload: 2,
  272. fadeTime: 1E3
  273. }
  274. })(jQuery, document, window);
  275. $(document).ready(function() {
  276. $('.a_ryzz_ul img,.a_zpdiv1_t a img').fsgallery()
  277. })