slide.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. function imageInit() {
  2. if ($(".image_area").length && $(".bigimg_box").length) {
  3. $(".image_area").carousel({
  4. imgType:"thumb"
  5. });
  6. var thumbImg = $(".image_area").find("img");
  7. thumbImg.each(function (i) {
  8. $(this).bind("click", function () {
  9. if ($(".bigimg_box").find("img").size() == 0) {
  10. thumbImg.each(function () {
  11. var _bigSrc = $(this).attr("ref").replace("tiny", "big");
  12. var _bigImg = document.createElement("img");
  13. var _li = document.createElement("li");
  14. _bigImg.src = "template/images/noimg.gif";
  15. _bigImg.setAttribute("ref", _bigSrc);
  16. _li.appendChild(_bigImg);
  17. document.querySelector(".bigimg_box ul").appendChild(_li);
  18. });
  19. }
  20. setTimeout(function () {
  21. window.scrollTo(0, 1);
  22. $(".bigimg_box").carousel({
  23. imgType:"big",
  24. scrollTo:i
  25. });
  26. }, 0);
  27. $(".header").hide();
  28. $("#viewBigImagebg").show().css("height", document.body.clientHeight + "px");
  29. $("#viewBigImage").show();
  30. var path = "/" + ____json4fe.locallist[0].listname + "/" + ____json4fe.rootcatentry.listname + "/" + ____json4fe.catentry.listname + "/detail/click/photo/";
  31. googleAnalytices(path, document.referer);
  32. });
  33. });
  34. $(".btn_back").bind("click", function () {
  35. $("#viewBigImagebg").hide();
  36. $("#viewBigImage").hide();
  37. $(".header").show();
  38. });
  39. }
  40. }
  41. function FastClick(layer) {
  42. 'use strict';
  43. var oldOnClick, self = this;
  44. this.trackingClick = false;
  45. this.trackingClickStart = 0;
  46. this.targetElement = null;
  47. this.touchStartX = 0;
  48. this.touchStartY = 0;
  49. this.lastTouchIdentifier = 0;
  50. this.touchBoundary = 10;
  51. this.layer = layer;
  52. if (!layer || !layer.nodeType) {
  53. throw new TypeError('Layer must be a document node');
  54. }
  55. this.onClick = function() {
  56. return FastClick.prototype.onClick.apply(self, arguments)
  57. };
  58. this.onMouse = function() {
  59. return FastClick.prototype.onMouse.apply(self, arguments)
  60. };
  61. this.onTouchStart = function() {
  62. return FastClick.prototype.onTouchStart.apply(self, arguments)
  63. };
  64. this.onTouchMove = function() {
  65. return FastClick.prototype.onTouchMove.apply(self, arguments)
  66. };
  67. this.onTouchEnd = function() {
  68. return FastClick.prototype.onTouchEnd.apply(self, arguments)
  69. };
  70. this.onTouchCancel = function() {
  71. return FastClick.prototype.onTouchCancel.apply(self, arguments)
  72. };
  73. if (FastClick.notNeeded(layer)) {
  74. return
  75. }
  76. if (this.deviceIsAndroid) {
  77. layer.addEventListener('mouseover', this.onMouse, true);
  78. layer.addEventListener('mousedown', this.onMouse, true);
  79. layer.addEventListener('mouseup', this.onMouse, true)
  80. }
  81. layer.addEventListener('click', this.onClick, true);
  82. layer.addEventListener('touchstart', this.onTouchStart, false);
  83. layer.addEventListener('touchmove', this.onTouchMove, false);
  84. layer.addEventListener('touchend', this.onTouchEnd, false);
  85. layer.addEventListener('touchcancel', this.onTouchCancel, false);
  86. if (!Event.prototype.stopImmediatePropagation) {
  87. layer.removeEventListener = function(type, callback, capture) {
  88. var rmv = Node.prototype.removeEventListener;
  89. if (type === 'click') {
  90. rmv.call(layer, type, callback.hijacked || callback, capture)
  91. } else {
  92. rmv.call(layer, type, callback, capture)
  93. }
  94. };
  95. layer.addEventListener = function(type, callback, capture) {
  96. var adv = Node.prototype.addEventListener;
  97. if (type === 'click') {
  98. adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
  99. if (!event.propagationStopped) {
  100. callback(event)
  101. }
  102. }), capture)
  103. } else {
  104. adv.call(layer, type, callback, capture)
  105. }
  106. }
  107. }
  108. if (typeof layer.onclick === 'function') {
  109. oldOnClick = layer.onclick;
  110. layer.addEventListener('click',
  111. function(event) {
  112. oldOnClick(event)
  113. },
  114. false);
  115. layer.onclick = null
  116. }
  117. }
  118. FastClick.prototype.deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0;
  119. FastClick.prototype.deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent);
  120. FastClick.prototype.deviceIsIOS4 = FastClick.prototype.deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
  121. FastClick.prototype.deviceIsIOSWithBadTarget = FastClick.prototype.deviceIsIOS && (/OS ([6-9]|\d{2})_\d/).test(navigator.userAgent);
  122. FastClick.prototype.needsClick = function(target) {
  123. 'use strict';
  124. switch (target.nodeName.toLowerCase()) {
  125. case 'button':
  126. case 'select':
  127. case 'textarea':
  128. if (target.disabled) {
  129. return true
  130. }
  131. break;
  132. case 'input':
  133. if ((this.deviceIsIOS && target.type === 'file') || target.disabled) {
  134. return true
  135. }
  136. break;
  137. case 'label':
  138. case 'video':
  139. return true
  140. }
  141. return (/\bneedsclick\b/).test(target.className)
  142. };
  143. FastClick.prototype.needsFocus = function(target) {
  144. 'use strict';
  145. switch (target.nodeName.toLowerCase()) {
  146. case 'textarea':
  147. return true;
  148. case 'select':
  149. return ! this.deviceIsAndroid;
  150. case 'input':
  151. switch (target.type) {
  152. case 'button':
  153. case 'checkbox':
  154. case 'file':
  155. case 'image':
  156. case 'radio':
  157. case 'submit':
  158. return false
  159. }
  160. return ! target.disabled && !target.readOnly;
  161. default:
  162. return (/\bneedsfocus\b/).test(target.className)
  163. }
  164. };
  165. FastClick.prototype.sendClick = function(targetElement, event) {
  166. 'use strict';
  167. var clickEvent, touch;
  168. if (document.activeElement && document.activeElement !== targetElement) {
  169. document.activeElement.blur()
  170. }
  171. touch = event.changedTouches[0];
  172. clickEvent = document.createEvent('MouseEvents');
  173. clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
  174. clickEvent.forwardedTouchEvent = true;
  175. targetElement.dispatchEvent(clickEvent)
  176. };
  177. FastClick.prototype.determineEventType = function(targetElement) {
  178. 'use strict';
  179. if (this.deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
  180. return 'mousedown'
  181. }
  182. return 'click'
  183. };
  184. FastClick.prototype.focus = function(targetElement) {
  185. 'use strict';
  186. var length;
  187. if (this.deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time') {
  188. length = targetElement.value.length;
  189. targetElement.setSelectionRange(length, length)
  190. } else {
  191. targetElement.focus()
  192. }
  193. };
  194. FastClick.prototype.updateScrollParent = function(targetElement) {
  195. 'use strict';
  196. var scrollParent, parentElement;
  197. scrollParent = targetElement.fastClickScrollParent;
  198. if (!scrollParent || !scrollParent.contains(targetElement)) {
  199. parentElement = targetElement;
  200. do {
  201. if (parentElement.scrollHeight > parentElement.offsetHeight) {
  202. scrollParent = parentElement;
  203. targetElement.fastClickScrollParent = parentElement;
  204. break
  205. }
  206. parentElement = parentElement.parentElement
  207. } while ( parentElement )
  208. }
  209. if (scrollParent) {
  210. scrollParent.fastClickLastScrollTop = scrollParent.scrollTop
  211. }
  212. };
  213. FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
  214. 'use strict';
  215. if (eventTarget.nodeType === Node.TEXT_NODE) {
  216. return eventTarget.parentNode
  217. }
  218. return eventTarget
  219. };
  220. FastClick.prototype.onTouchStart = function(event) {
  221. 'use strict';
  222. var targetElement, touch, selection;
  223. if (event.targetTouches.length > 1) {
  224. return true
  225. }
  226. targetElement = this.getTargetElementFromEventTarget(event.target);
  227. touch = event.targetTouches[0];
  228. if (this.deviceIsIOS) {
  229. selection = window.getSelection();
  230. if (selection.rangeCount && !selection.isCollapsed) {
  231. return true
  232. }
  233. }
  234. this.trackingClick = true;
  235. this.trackingClickStart = event.timeStamp;
  236. this.targetElement = targetElement;
  237. this.touchStartX = touch.pageX;
  238. this.touchStartY = touch.pageY;
  239. if ((event.timeStamp - this.lastClickTime) < 200) {
  240. event.preventDefault()
  241. }
  242. return true
  243. };
  244. FastClick.prototype.touchHasMoved = function(event) {
  245. 'use strict';
  246. var touch = event.changedTouches[0],
  247. boundary = this.touchBoundary;
  248. if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
  249. return true
  250. }
  251. return false
  252. };
  253. FastClick.prototype.onTouchMove = function(event) {
  254. 'use strict';
  255. if (!this.trackingClick) {
  256. return true
  257. }
  258. if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
  259. this.trackingClick = false;
  260. this.targetElement = null
  261. }
  262. return true
  263. };
  264. FastClick.prototype.findControl = function(labelElement) {
  265. 'use strict';
  266. if (labelElement.control !== undefined) {
  267. return labelElement.control
  268. }
  269. if (labelElement.htmlFor) {
  270. return document.getElementById(labelElement.htmlFor)
  271. }
  272. return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea')
  273. };
  274. FastClick.prototype.onTouchEnd = function(event) {
  275. 'use strict';
  276. var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
  277. if (!this.trackingClick) {
  278. return true
  279. }
  280. if ((event.timeStamp - this.lastClickTime) < 200) {
  281. this.cancelNextClick = true;
  282. return true
  283. }
  284. this.cancelNextClick = false;
  285. this.lastClickTime = event.timeStamp;
  286. trackingClickStart = this.trackingClickStart;
  287. this.trackingClick = false;
  288. this.trackingClickStart = 0;
  289. if (this.deviceIsIOSWithBadTarget) {
  290. touch = event.changedTouches[0];
  291. targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
  292. targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent
  293. }
  294. targetTagName = targetElement.tagName.toLowerCase();
  295. if (targetTagName === 'label') {
  296. forElement = this.findControl(targetElement);
  297. if (forElement) {
  298. this.focus(targetElement);
  299. if (this.deviceIsAndroid) {
  300. return false
  301. }
  302. targetElement = forElement
  303. }
  304. } else if (this.needsFocus(targetElement)) {
  305. if ((event.timeStamp - trackingClickStart) > 100 || (this.deviceIsIOS && window.top !== window && targetTagName === 'input')) {
  306. this.targetElement = null;
  307. return false
  308. }
  309. this.focus(targetElement);
  310. if (!this.deviceIsIOS4 || targetTagName !== 'select') {
  311. this.targetElement = null;
  312. event.preventDefault()
  313. }
  314. return false
  315. }
  316. if (this.deviceIsIOS && !this.deviceIsIOS4) {
  317. scrollParent = targetElement.fastClickScrollParent;
  318. if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
  319. return true
  320. }
  321. }
  322. if (!this.needsClick(targetElement)) {
  323. event.preventDefault();
  324. this.sendClick(targetElement, event)
  325. }
  326. return false
  327. };
  328. FastClick.prototype.onTouchCancel = function() {
  329. 'use strict';
  330. this.trackingClick = false;
  331. this.targetElement = null
  332. };
  333. FastClick.prototype.onMouse = function(event) {
  334. 'use strict';
  335. if (!this.targetElement) {
  336. return true
  337. }
  338. if (event.forwardedTouchEvent) {
  339. return true
  340. }
  341. if (!event.cancelable) {
  342. return true
  343. }
  344. if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
  345. if (event.stopImmediatePropagation) {
  346. event.stopImmediatePropagation()
  347. } else {
  348. event.propagationStopped = true
  349. }
  350. event.stopPropagation();
  351. event.preventDefault();
  352. return false
  353. }
  354. return true
  355. };
  356. FastClick.prototype.onClick = function(event) {
  357. 'use strict';
  358. var permitted;
  359. if (this.trackingClick) {
  360. this.targetElement = null;
  361. this.trackingClick = false;
  362. return true
  363. }
  364. if (event.target.type === 'submit' && event.detail === 0) {
  365. return true
  366. }
  367. permitted = this.onMouse(event);
  368. if (!permitted) {
  369. this.targetElement = null
  370. }
  371. return permitted
  372. };
  373. FastClick.prototype.destroy = function() {
  374. 'use strict';
  375. var layer = this.layer;
  376. if (this.deviceIsAndroid) {
  377. layer.removeEventListener('mouseover', this.onMouse, true);
  378. layer.removeEventListener('mousedown', this.onMouse, true);
  379. layer.removeEventListener('mouseup', this.onMouse, true)
  380. }
  381. layer.removeEventListener('click', this.onClick, true);
  382. layer.removeEventListener('touchstart', this.onTouchStart, false);
  383. layer.removeEventListener('touchmove', this.onTouchMove, false);
  384. layer.removeEventListener('touchend', this.onTouchEnd, false);
  385. layer.removeEventListener('touchcancel', this.onTouchCancel, false)
  386. };
  387. FastClick.notNeeded = function(layer) {
  388. 'use strict';
  389. var metaViewport;
  390. var chromeVersion;
  391. if (typeof window.ontouchstart === 'undefined') {
  392. return true
  393. }
  394. chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1];
  395. if (chromeVersion) {
  396. if (FastClick.prototype.deviceIsAndroid) {
  397. metaViewport = document.querySelector('meta[name=viewport]');
  398. if (metaViewport) {
  399. if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
  400. return true
  401. }
  402. if (chromeVersion > 31 && window.innerWidth <= window.screen.width) {
  403. return true
  404. }
  405. }
  406. } else {
  407. return true
  408. }
  409. }
  410. if (layer.style.msTouchAction === 'none') {
  411. return true
  412. }
  413. return false
  414. };
  415. FastClick.attach = function(layer) {
  416. 'use strict';
  417. return new FastClick(layer)
  418. };
  419. if (typeof define !== 'undefined' && define.amd) {
  420. define(function() {
  421. 'use strict';
  422. return FastClick
  423. })
  424. } else if (typeof module !== 'undefined' && module.exports) {
  425. module.exports = FastClick.attach;
  426. module.exports.FastClick = FastClick
  427. } else {
  428. window.FastClick = FastClick
  429. }
  430. FastClick.attach(document.body); (function() {
  431. if ($('.image_area ul').length > 0) {
  432. $('.bigimg_box ul').html($('.image_area ul').html().replace(/small/g, 'big').replace(/220/g, 300).replace(/155/g, 415))
  433. }
  434. var slideX = (function() {
  435. var _slide = function(node, duration, width, left, clickable) {
  436. this._eleX = 0;
  437. this._index = 0;
  438. this._length = node.children('li').length;
  439. this._main = node;
  440. this._startX = 0;
  441. this._startY = 0;
  442. this._duration = duration;
  443. this._width = width;
  444. this._left = left;
  445. this._clickable = clickable;
  446. $('.total_img').text(this._length)
  447. };
  448. _slide.prototype = {
  449. _bindEvents: function() {
  450. var _this = this;
  451. this._main.bind("touchstart",
  452. function(e) {
  453. _this._touchStart(e, _this)
  454. });
  455. this._main.bind("touchmove",
  456. function(e) {
  457. _this._touchMove(e, _this)
  458. });
  459. this._main.bind("touchend",
  460. function(e) {
  461. _this._touchEnd(e, _this)
  462. })
  463. },
  464. _click: function() {
  465. if (this._clickable) {
  466. var img = $(this._main.find('li img').get(this._index));
  467. this._showImage(this._index);
  468. $('.bigimg_box ul').css('-webkit-transform', 'translateX(-' + this._index * 320 + 'px)');
  469. if (typeof bigimage !== 'undefined') {
  470. bigimage._index = this._index;
  471. bigimage._showImage(this._index);
  472. bigimage._showImage(this._index + 1)
  473. }
  474. $('#viewBigImagebg').css('height', document.body.offsetHeight + 50 + 'px');
  475. $('#viewBigImagebg, #viewBigImage').show();
  476. $(".header").hide();
  477. }
  478. },
  479. _showImage: function(index) {
  480. var img = $(this._main.find('li img').get(index));
  481. var ref = img.attr('ref');
  482. if (ref) {
  483. img.attr('src', ref);
  484. img.removeAttr('ref')
  485. }
  486. },
  487. _moveTo: function(x) {
  488. this._main.css({
  489. '-webkit-transform': 'translateX(' + x + 'px)'
  490. })
  491. },
  492. _touchStart: function(e, _this) {
  493. e.stopPropagation();
  494. var finger0 = e.targetTouches[0];
  495. _this._startX = finger0.pageX;
  496. _this._startY = finger0.screenY;
  497. var transform = _this._main.css('-webkit-transform');
  498. var pattern = /\(|, {0,}|\)/;
  499. _this._eleX = (transform.indexOf('translate') >= 0) ? +transform.split(pattern)[1].replace('px', '') : +transform.split(pattern)[5]
  500. },
  501. _touchMove: function(e, _this) {
  502. var finger0 = e.targetTouches[0];
  503. var endX = finger0.pageX;
  504. var offsetX = endX - _this._startX + _this._eleX;
  505. if (Math.abs(endX - _this._startX) > 10) {
  506. e.preventDefault();
  507. e.stopPropagation();
  508. _this._main.css('-webkit-transition', '0');
  509. _this._moveTo(offsetX)
  510. }
  511. },
  512. _touchEnd: function(e, _this) {
  513. var finger0 = e.changedTouches[0];
  514. var endX = finger0.pageX;
  515. var endY = finger0.screenY;
  516. var offsetX = endX - _this._startX;
  517. var offsetY = endY - _this._startY;
  518. if (Math.abs(offsetX) <= 10) {
  519. if (Math.abs(offsetY) <= 20) {
  520. _this._click()
  521. }
  522. } else {
  523. var index = (offsetX > 0) ? --_this._index: ++_this._index;
  524. if (index < 0) {
  525. index = 0;
  526. _this._index = 0
  527. }
  528. if (index >= _this._length) {
  529. index = _this._length - 1;
  530. _this._index = _this._length - 1
  531. }
  532. _this._showImage(index);
  533. _this._showImage(index + 1);
  534. $('.curr_img').text(index + 1);
  535. _this._main.css('-webkit-transition', '150ms');
  536. _this._moveTo( - index * _this._width + _this._left)
  537. }
  538. },
  539. init: function() {
  540. this._bindEvents();
  541. this._showImage(0);
  542. this._showImage(1)
  543. }
  544. };
  545. _slide.bind = function(node, duration, width, left, clickable) {
  546. var obj = new m58.slideX(node, duration, width, left, clickable);
  547. obj.init();
  548. return obj
  549. };
  550. return _slide
  551. })();
  552. window.m58 = window.m58 || {};
  553. window.m58.slideX = slideX;
  554. if ($('.image_area').length > 0) {
  555. m58.slideX.bind($('.image_area ul'), '300ms', 230, 50, true);
  556. var bigimage = m58.slideX.bind($('.bigimg_box ul'), '300ms', 320, 0, false)
  557. }
  558. $('.btn_back span').bind('click',
  559. function(e) {
  560. $('#viewBigImagebg, #viewBigImage').hide();
  561. $(".header").show();
  562. })
  563. } ());