yylive.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. $(function() {
  2. var report = {
  3. getBrowserInfo : function () {
  4. var explorer = window.navigator.userAgent.toLowerCase();
  5. //ie
  6. if (explorer.indexOf("msie") >= 0) {
  7. var ver = explorer.match(/msie ([\d.]+)/)[1];
  8. return { type: "IE", version: ver };
  9. } else if (explorer.indexOf("trident") >= 0) {
  10. return { type: "IE", version: 'unknow' };
  11. }
  12. //firefox
  13. else if (explorer.indexOf("firefox") >= 0) {
  14. var ver = explorer.match(/firefox\/([\d.]+)/)[1];
  15. return { type: "Firefox", version: ver };
  16. }
  17. //Chrome
  18. else if (explorer.indexOf("chrome") >= 0) {
  19. var ver = explorer.match(/chrome\/([\d.]+)/)[1];
  20. return { type: "Chrome", version: ver };
  21. }
  22. //Opera
  23. else if (explorer.indexOf("opera") >= 0) {
  24. var ver = explorer.match(/opera.([\d.]+)/)[1];
  25. return { type: "Opera", version: ver };
  26. }
  27. //Safari
  28. else if (explorer.indexOf("Safari") >= 0) {
  29. var ver = explorer.match(/version\/([\d.]+)/)[1];
  30. return { type: "Safari", version: ver };
  31. } else {
  32. return { type: "unknow", version: "unknow" };
  33. }
  34. },
  35. /**上传数据
  36. * reportType : 1为展示 2为点击
  37. */
  38. reportData : function (type, param) {
  39. var reportType = type,
  40. reportUrl = 'http://dastat.duowan.com/?r=api/stat',
  41. browserInfo = this.getBrowserInfo(),
  42. data = {
  43. loc: param.locid,
  44. pid: param.pid,
  45. type: reportType,
  46. url: window.location.href,
  47. os: window.navigator.platform,
  48. browser: browserInfo.type + browserInfo.version,
  49. px: window.screen.width + "*" + window.screen.height
  50. };
  51. if (typeof data.loc != 'undefined' && typeof data.pid != 'undefined' && data.type) {
  52. this.sendData(reportUrl, data);
  53. }
  54. },
  55. sendData : function (url, data) {
  56. var img = new Image();
  57. for (var key in data) {
  58. url += "&" + key + "=" + data[key];
  59. }
  60. img.src = url;
  61. img = null;
  62. },
  63. /**绑定点击上报数据事件
  64. * ele : 被点击的选择器
  65. **/
  66. bindEvent: function(ele) {
  67. var self = this
  68. $('body').on('click',ele, function() {
  69. var param = {
  70. locid: $(this).attr('locid'),
  71. pid: $(this).attr('pid')
  72. }
  73. self.reportData(2,param)
  74. })
  75. }
  76. }
  77. function getURLParam(name) {
  78. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  79. return value ? decodeURIComponent(value[1]) : value;
  80. }
  81. var listTpl = __inline("../tpl/yylive.tmpl")
  82. var locid1, locid2;
  83. var gtype = getURLParam('gtype')
  84. if(gtype == 'lol') {
  85. locid1 = 154
  86. locid2 = 155
  87. } else if(gtype == 'dnf') {
  88. locid1 = 156
  89. locid2 = 157
  90. }
  91. var boxtype = getURLParam('boxtype')
  92. if(boxtype == 'newdnf') {
  93. $('.o-wrap').addClass("newdnf")
  94. }
  95. $.ajax({
  96. url: 'http://da.duowan.com/loc/'+locid1,
  97. type: 'GET',
  98. dataType: 'jsonp',
  99. success: function(ret) {
  100. $(".loading-tips").hide()
  101. var hasBanner = false
  102. if(ret.extraJson && ret.extraJson.list.length > 0) {
  103. hasBanner = true
  104. var item = ret.extraJson.list[0]
  105. var img = item.image ? item.image : item.img
  106. $(".yylive-banner").html('<a href="'+item.url+'" title="'+item.title+'" locid="'+ret.locid+'" pid="'+ret.pid+'" target="_blank"><img src="'+img+'"/></a>')
  107. report.reportData(1,{locid: ret.locid,pid: ret.pid})
  108. report.bindEvent('.yylive-banner a')
  109. }
  110. $.ajax({
  111. url: 'http://da.duowan.com/loc/'+locid2,
  112. type: 'GET',
  113. dataType: 'jsonp',
  114. success: function(ret2) {
  115. $(".loading-tips").hide()
  116. var dom = listTpl({
  117. list: hasBanner ? ret2.extraJson.list.slice(0, 8) : ret2.extraJson.list,
  118. locid: ret2.locid,
  119. pid: ret2.pid,
  120. more: ret2.extraJson.more
  121. })
  122. $(".yylive-list").html(dom)
  123. if(!hasBanner) {
  124. $(".yylive-list").addClass("tp2")
  125. }
  126. report.reportData(1,{locid: ret2.locid,pid: ret2.pid})
  127. report.bindEvent('.yylive-list a')
  128. }
  129. })
  130. }
  131. })
  132. })