tu-detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*!
  2. * @project :
  3. * @version : 1.0.0
  4. * @author :
  5. * @update : 2015-06-12 10:12:50 am
  6. */
  7. console.log("dsad")
  8. var Util = {
  9. getParam : function(name) {
  10. //先获取#后面的参数
  11. var str = document.location.hash.substr(2);
  12. var value = this.getParam2(name, str);
  13. if (value == null) {
  14. str = document.location.search.substr(1);
  15. value = this.getParam2(name, str);
  16. }
  17. return value;
  18. },
  19. getParam2 : function(name, str) {
  20. //获取参数name的值
  21. var reg = new RegExp("(^|!|&|\\?)" + name + "=([^&]*)(&|$)");
  22. //再获取?后面的参数
  23. var r = str.match(reg);
  24. if (r != null) {
  25. try {
  26. return decodeURIComponent(r[2]);
  27. } catch (e) {
  28. console.log(e + "r[2]:" + r[2]);
  29. return null;
  30. }
  31. }
  32. return null;
  33. },
  34. isFunction: function (obj) {
  35. return Object.prototype.toString.call(obj) === "[object Function]";
  36. },
  37. getScript: function (url, callback) {
  38. var head = document.getElementsByTagName("head")[0] || document.documentElement;
  39. var script = document.createElement("script");
  40. script.type = "text/javascript";
  41. script.async = true;
  42. script.charset = "utf-8";
  43. script.src = url;
  44. script.onload = script.onreadystatechange = function () {
  45. if (!script.readyState || /loaded|complete/.test(script.readyState)) {
  46. if (Util.isFunction(callback)) {
  47. callback();
  48. }
  49. script.onload = script.onreadystatechange = null;
  50. if (script.parentNode) {
  51. script.parentNode.removeChild(script);
  52. }
  53. }
  54. };
  55. head.insertBefore(script,null);
  56. }
  57. }
  58. var adv = {
  59. isiOS : navigator.userAgent.match(/(iPhone|iPod|iPad);?/i), //ios终端
  60. swipeLocid : 166, //大图locid
  61. picsLocid : 167, //图集locid
  62. swiperAdvPos : false, //大图swiper id
  63. swiperGameInfo : {},
  64. cssTmpl : '#rec-imgs{overflow: scroll;}\
  65. .swiper-wrapper div.m-container{overflow: inherit;height: auto;}\
  66. .ui-picHeader__adv{position: absolute;right: 10px;top: 2px;height: 44px;padding-left: 28px;line-height: 44px;font-size: 18px;color: #fff;}\
  67. .ui-picShow__item .gameLink{position: absolute;top: 0;left: 0;width: 100%;height: 100%; z-index: 2;}\
  68. .rec-list{overflow:hidden}\
  69. .img-info-n .da-title-link{position: absolute;bottom: 0;left: 0;z-index: 999;width: 100%;height: 100%;}',
  70. swipeItemTmpl : '<div class="swiper-slide swiper-item ui-picShow__item" id="swipeGame1">\
  71. <img name="imgItems" data-original="">\
  72. <a href="" target="_blank" class="gameLink da-block-wrapper" not-auto-report="1"></a>\
  73. </div>',
  74. init : function (){
  75. var self = this
  76. if(Util.getParam("isdebug")!=1) return
  77. $("head").append('<style>'+this.cssTmpl+'</style>')
  78. this.initSwiperAdvPos()
  79. this.getPicsDa()
  80. Util.getScript("//pub.dwstatic.com/common/js/dastat.js",function(){});
  81. //滑动大图第二个链接-点击上报
  82. $("body").on("click","#swContGameInfo",function(){
  83. if(window.dwDaStat) window.dwDaStat.reportData($(this).get(0))
  84. })
  85. },
  86. //大图广告
  87. getSwipeDa : function(){
  88. var self = this;
  89. console.log("获取大图广告")
  90. this.getDa(this.swipeLocid,function(ret){
  91. self.swiperGameInfo = ret[0]
  92. $("#swipeGame1 img").attr({
  93. "src" : self.swiperGameInfo.adSrc,
  94. "data-original":self.swiperGameInfo.adSrc
  95. })
  96. $("#swipeGame1 .gameLink").attr({
  97. "href":self.swiperGameInfo.adLink,
  98. "locid" : self.swipeLocid,
  99. "pid" : self.swiperGameInfo.adPid
  100. })
  101. imgJson.picInfo[self.swiperAdvPos]={
  102. add_intro : self.swiperGameInfo.title,
  103. title : self.swiperGameInfo.title
  104. }
  105. })
  106. },
  107. //图集广告
  108. getPicsDa : function(){
  109. // return;
  110. var self = this,
  111. $items = $(".rec-list").find("a"),
  112. advPos = [1,3];
  113. this.getDa(this.picsLocid,function(ret){
  114. for(var i=0;i<ret.length;i++) {
  115. $items.eq(advPos[i]).before(self.getPicsDaDom(ret[i]))
  116. }
  117. })
  118. },
  119. setDaTitleLink : function(t){
  120. var i = '<a href="'+t.adLink+'" target="_blank" id="swContGameInfo" class="da-title-link" locid="'+t.adId+'" pid="'+t.adPid+'" not-auto-report="1"></a>'
  121. return i;
  122. },
  123. getPicsDaDom : function(t){
  124. var i = '<li style="background-image: url('+t.adSrc+')"><a href="'+t.adLink+'" target="_blank" class="da-block-wrapper" locid="'+t.adId+'" pid="'+t.adPid+'" not-auto-report="1">\
  125. <li style="background-image: url('+t.adSrc+')">\
  126. <span class="r-l-txt">'+t.title+'</span>\
  127. </li>\
  128. </a>'
  129. return i;
  130. },
  131. getDa(locid,callback){
  132. var platform = this.isiOS ? "ios" : "android"
  133. $.ajax({
  134. url: "http://da.duowan.com/loc/"+locid+"?platform="+platform,
  135. dataType: 'jsonp',
  136. success: function(ret) {
  137. callback && callback(ret)
  138. }
  139. })
  140. },
  141. //初始化swipe
  142. initSwiperAdvPos : function(){
  143. var len = imgJson.picInfo.length
  144. if(len>=10) {
  145. var random = len > 15 ? 9+Math.floor(Math.random() * 5) : 9+Math.floor(Math.random() * (len-10))
  146. console.log("广告位置:"+random)
  147. this.swiperAdvPos = random
  148. this.getSwipeDa()
  149. imgJson.picInfo.splice(random,0,{})
  150. $(".swiper-wrapper").children(".swiper-item").eq(random).before(this.swipeItemTmpl);
  151. }
  152. },
  153. //展示上报
  154. showReport : function(curSwipe){
  155. if(Util.getParam("isdebug")!=1) return
  156. //图集-广告
  157. if (this.swiperAdvPos && curSwipe==this.swiperAdvPos) {
  158. $(".img-info-n").append(this.setDaTitleLink(this.swiperGameInfo))
  159. $("#comment_url").before('<div class="ui-picHeader__adv" id="swHeaderGameTag">广告</div>')
  160. $("#comment_url,#imgInfoContent,.img-info-n .m-img_num").hide()
  161. console.log("上报统计-swipeItem")
  162. if(window.dwDaStat) window.dwDaStat.reportData($("#swipeGame1 a").get(0),'loaded')
  163. //图集推荐-广告
  164. } else if(curSwipe==imgJson.picInfo.length){
  165. console.log("上报统计-图集")
  166. $(".rec-list .da-block-wrapper").each(function(){
  167. if(window.dwDaStat) window.dwDaStat.reportData($(this).get(0),'loaded')
  168. })
  169. }else {
  170. $("#swHeaderGameTag,#swContGameInfo").remove()
  171. $("#comment_url,#imgInfoContent,.img-info-n .m-img_num").show()
  172. }
  173. }
  174. }
  175. seajs.use(["zepto", "touch", "swiper", "iscroll", "hammer", "hbURL"], function() {
  176. function e(e) {
  177. $(".rec-list").css("visibility", "visible"),
  178. $("#comment_url").attr("href", imgJson.picInfo[e].comment_url),
  179. $(".ui-picHeader__reply").text(imgJson.picInfo[e].num),
  180. $(".ui-picHeader__title").hide(),
  181. $(".ui-picHeader__reply").show(),
  182. $(".ui-picHeader__backBtn").show(),
  183. $(".img-info-title").text(imgJson.picInfo[e].title),
  184. $(".m-img_num").html("<span>" + (e + 1) + "</span>/" + imgJson.picInfo.length),
  185. $("#imgInfoContent").html(imgJson.picInfo[e].add_intro),
  186. $(".ui-picHeader").show(),
  187. $(".img-info-n").show(),
  188. o && o.refresh()
  189. }
  190. function t() {
  191. transform = {
  192. scale: 1,
  193. startX: 0,
  194. startY: 0,
  195. endX: 0,
  196. endY: 0
  197. },
  198. r()
  199. }
  200. function n(e) {
  201. $('[name="imgItems"]').eq(e).attr("src", $('[name="imgItems"]').eq(e).attr("data-original")),
  202. $('[name="imgItems"]').eq(e + 1).attr("src", $('[name="imgItems"]').eq(e + 1).attr("data-original")),
  203. c = new Hammer($('[name="imgItems"]').eq(e)[0]),
  204. c.add(new Hammer.Pinch),
  205. c.add(new Hammer.Pan),
  206. c.on("pinchmove", function(e) {
  207. var t = $(e.target);
  208. $(t).removeClass("imgBackMin imgBackMax dbTap backTap"),
  209. e.scale >= 1 ? transform.scale < 3.5 && (transform.scale = transform.scale + .2 * (e.scale - 1)) : transform.scale >= .8 && (f.unlockSwipes(),
  210. transform.scale = transform.scale - .1 * (1 - e.scale)),
  211. r(t)
  212. }),
  213. c.on("pinchend", function(e) {
  214. if (transform.scale < 1)
  215. transform.scale = 1,
  216. $(e.target).addClass("imgBackMin"),
  217. setTimeout(function() {
  218. t()
  219. }, 200);
  220. else if (transform.scale > 2.8) {
  221. transform.scale = 2.8,
  222. $(e.target).addClass("imgBackMax");
  223. var n = $(e.target);
  224. setTimeout(function() {
  225. r(n)
  226. }, 200)
  227. }
  228. }),
  229. c.on("panmove", function(e) {
  230. $(e.target).removeClass("imgBackMin imgBackMax dbTap backTap");
  231. var t = e.target;
  232. if (transform.scale > 1 || $(t).width() <= $(document).width() && $(t).height() >= $(document).height()) {
  233. f.lockSwipes();
  234. var n = ($(t).offset().top,
  235. $(document).height())
  236. , a = $(t).height()
  237. , s = (a - n) / 2 + 100
  238. , i = -(a - n) / 2 - 200
  239. , o = ($(t).offset().left,
  240. $(document).width())
  241. , m = $(t).width()
  242. , c = (m - o) / 4
  243. , d = -c;
  244. if ($(t).width() <= $(document).width() && $(t).height() >= $(document).height()) {
  245. f.unlockSwipes();
  246. var l = $(t);
  247. transform.endY = transform.startY + .8 * e.deltaY,
  248. transform.endY < s && transform.startY < transform.endY ? r(l) : transform.endY > i && transform.startY > transform.endY ? r(l) : transform.endY = transform.startY < transform.endY ? s : i
  249. } else if ($(t).width() > $(document).width() && $(t).height() <= $(document).height()) {
  250. var l = $(t);
  251. transform.endX = transform.startX + .8 * e.deltaX,
  252. transform.endX < c && transform.startX < transform.endX ? r(l) : transform.endX > d && transform.startX > transform.endX ? r(l) : (transform.endX = transform.startX < transform.endX ? c : d,
  253. f.unlockSwipes())
  254. } else if ($(document).width() - ($(t).width() + $(t).offset().left) >= 0)
  255. f.unlockSwipes();
  256. else if ($(t).offset().left >= 0)
  257. f.unlockSwipes();
  258. else {
  259. var l = $(t);
  260. transform.endX = transform.startX + .8 * e.deltaX,
  261. transform.endY = transform.startY + .8 * e.deltaY,
  262. transform.endY < s && transform.startY < transform.endY ? r(l) : transform.endY > i && transform.startY > transform.endY ? r(l) : transform.endY = transform.startY < transform.endY ? s : i
  263. }
  264. }
  265. }),
  266. c.on("panend", function() {
  267. transform.startX = transform.endX,
  268. transform.startY = transform.endY
  269. })
  270. }
  271. function r(e) {
  272. ("" === e || "undefined" == typeof e) && $('[name="imgItems"]').css({
  273. "-webkit-transform": "scale3d(" + transform.scale + "," + transform.scale + "," + transform.scale + ") translate3d(" + transform.endX + "px," + transform.endY + "px,0)"
  274. }),
  275. $(e).css({
  276. "-webkit-transform": "scale3d(" + transform.scale + "," + transform.scale + "," + transform.scale + ") translate3d(" + transform.endX + "px," + transform.endY + "px,0)"
  277. })
  278. }
  279. document.ontouchmove = function() {
  280. return !1
  281. }
  282. ,
  283. $(".ui-picShow").css("height", $(document).height() - 30);
  284. for (var a = "", s = 0, i = imgJson.picInfo.length; i > s; s++)
  285. a += '<div class="swiper-slide swiper-item ui-picShow__item">\
  286. <img name="imgItems" data-original="' + imgJson.picInfo[s].url + '">\
  287. </div>';
  288. $(".swiper-wrapper").children(".swiper-item").first().before(a);
  289. //swipe广告位
  290. adv.init()
  291. new IScroll("#rec-imgs",{
  292. scrollbars: !0,
  293. mouseWheel: !0,
  294. shrinkScrollbars: "scale"
  295. })
  296. var o, m, f = new Swiper(".ui-picShow",{
  297. resizeReInit: !0,
  298. onInit: function() {
  299. var n = $(".swiper-slide ");
  300. $(".swiper-wrapper").width(n.width() * n.length),
  301. t(),
  302. e(0),
  303. o = new IScroll("#infoContent",{
  304. scrollbars: !0,
  305. mouseWheel: !0,
  306. shrinkScrollbars: "scale"
  307. })
  308. },
  309. onSlideChangeEnd: function() {
  310. t(),
  311. f.activeIndex >= f.slides.length - 1 ? ($(".ui-picHeader").show(),
  312. $(".ui-picHeader__title").show(),
  313. $(".img-info-n").hide(),
  314. $(".ui-picHeader__reply").hide(),
  315. $(".ui-picHeader__backBtn").hide()) : (e(f.activeIndex),
  316. n(f.activeIndex)),
  317. $(".swiper-slide-active").find("img").attr("id", "onImg")
  318. adv.showReport(f.activeIndex)
  319. }
  320. });
  321. $(".swiper-container").find("img").on("touchstart", function() {
  322. m = setTimeout(function() {
  323. "none" !== $(".ui-picHeader").css("display") ? ($(".ui-picHeader").hide(),
  324. $(".img-info-n").hide()) : ($(".ui-picHeader").show(),
  325. $(".img-info-n").show())
  326. }, 100)
  327. }),
  328. $(".swiper-container").on("touchmove", function() {
  329. clearTimeout(m)
  330. }),
  331. $(".swiper-slide").find("img").on("doubleTap", function() {
  332. if (clearTimeout(m),
  333. 1 === transform.scale && 0 === transform.endX && 0 === transform.endY) {
  334. transform.scale = 2,
  335. $(this).removeClass("backTap").addClass("dbTap");
  336. var e = $(this);
  337. setTimeout(function() {
  338. r(e)
  339. }, 200)
  340. } else
  341. f.unlockSwipes(),
  342. $(this).removeClass("dbTap").addClass("backTap"),
  343. setTimeout(function() {
  344. t()
  345. }, 200)
  346. });
  347. var c;
  348. n(0)
  349. });