gameCommonAD.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * [盒子下拉广告]
  3. * author: zikkeung
  4. */
  5. $(function(){
  6. var MODE_DEV='dev',
  7. MODE_RELEASE='release',
  8. optionsDev = {
  9. allowOrigin: [
  10. '127.0.0.1:8080'
  11. ],
  12. excludeList: [
  13. 'v',
  14. 'd',
  15. 's',
  16. 'tag',
  17. 'hezi',
  18. /\d{4}/
  19. ],
  20. imgRoot: 'http://127.0.0.1:8080/img/',
  21. swf: 'http://127.0.0.1:8080/img/adtop-on.swf',
  22. isShowTpAD: true,
  23. isShowFtAD: false
  24. },
  25. optionsRelease = {
  26. allowOrigin: [
  27. // 'lol.duowan.com',
  28. 'ls.duowan.com',
  29. 'dnf.duowan.com',
  30. // 'wow.duowan.com',
  31. 'bns.duowan.com',
  32. 'wot.duowan.com'
  33. ],
  34. excludeList: [
  35. 'v',
  36. 'd',
  37. 's',
  38. 'tag',
  39. 'hezi',
  40. /\d{4}/
  41. ],
  42. imgRoot: 'http://assets.dwstatic.com/game/dropdown/img/',
  43. swf: 'http://assets.dwstatic.com/game/dropdown/img/adtop-on.swf',
  44. isShowTpAD: true,
  45. isShowFtAD: false
  46. },
  47. options,
  48. mode;
  49. mode = MODE_DEV;
  50. options = (mode === MODE_RELEASE? optionsRelease:optionsDev);
  51. if (options.allowOrigin.join(',').indexOf(window.location.host) === -1){
  52. return ;
  53. }
  54. if(options.excludeList && options.excludeList.length>0){
  55. var isInExcludeList = false;
  56. subexcludeList= [],
  57. pageReg = /http:\/\/[^\/]*\/([^\/]*)/,
  58. pageMatch = pageReg.exec(window.location.href),
  59. pageType = pageMatch? pageMatch[1]:'';
  60. if (pageType!=='') {
  61. $.each(options.excludeList, function(i, item){
  62. isInExcludeList = isInExcludeList || (item.test? item.test(pageType):(item === pageType)) ;
  63. });
  64. if (isInExcludeList) { return; }
  65. };
  66. }
  67. if (options.isShowTpAD || options.isShowFtAD){
  68. var style = '<style type="text\/css">';
  69. style += 'body{padding-top: 36px !important;}';
  70. style += '.top-hezi-ad {position: relative;height:auto;_height:0; z-index: 12;background:#2f3646 url('+options.imgRoot+'adtop-bg.jpg) 50% no-repeat;}';
  71. style += '.top-hezi-ad-bd { height:0; width:1000px;margin: 0 auto; position: relative; overflow: hidden;}';
  72. style += '.top-hezi-ad .top-hezi-index { position: absolute; left:0; top:0; width:1000px; height:120px; }';
  73. style += '.top-hezi-ad .top-hezi-ios { position: absolute; left:642px; top:8px; width:216px; height:50px; }';
  74. style += '.top-hezi-ad .top-hezi-android { position: absolute; left:642px; top:62px; width:216px; height:50px; cursor: pointer;}';
  75. style += '.top-hezi-ad .top-hezi-qrcode { position: absolute; left:874px; top:7px; width:107px; height:107px; }';
  76. style += '.top-hezi-ad .top-hezi-ios:hover {background-position: -110px 0;}';
  77. style += '.top-hezi-ad .top-hezi-android:hover {background-position: -110px -36px;}';
  78. style += '.top-hezi-ad-trigger{width:140px; height:140px; position: absolute; top: 20px; left:54%; margin:0 0 0 290px; z-index: 10; overflow: hidden;}';
  79. style += '.top-hezi-ad-trigger a {display: block;height:100%; background: url('+options.imgRoot+'adtop-arrow.png) no-repeat center; _background: url('+options.imgRoot+'adtop-arrow.png) no-repeat center; display: none;}';
  80. style += '.top-hezi-ad-trigger embed { pointer-events: none;}';
  81. style += '.top-hezi-ad-trigger-opened a { display: block;}';
  82. style += '.top-hezi-ad-trigger-opened embed { display: none;}';
  83. style += '.top-hezi-ad-trigger img {position: absolute; width:100%; height:100%; cursor:pointer;left:0;top:0;}';
  84. style += '.qrcode-download-bar {background-color:transparent;background-color:rgba(0,0,0,0.85);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#d8000000,endColorstr=#d8000000);position: fixed;_position: absolute;bottom: 0;left: 0;width: 100%;_filter: none;_background-color: #4c4c4c;z-index: 444;}';
  85. style += '.qrcode-download-bar .qrcode-download-inner {height: 92px;width: 1000px;margin: 0 auto;overflow: hidden;}';
  86. style += ':root .qrcode-download-bar{filter:none\9}';
  87. style += '.qrcode-download-bar .close {position: absolute;left: 50%;top: 10px;margin-left: 480px;height: 15px;width: 15px;overflow: hidden;text-indent: -99em;background: url('+options.imgRoot+'qr_code_download_bar.png) no-repeat 0 -257px;_background-image: url('+options.imgRoot+'qr_code_download_bar_ie6.png);}';
  88. style += '.qrcode-download-bar .slogan {width: 446px;background: url('+options.imgRoot+'qr_code_download_bar.png) no-repeat 0 0;_background-image: url('+options.imgRoot+'qr_code_download_bar_ie6.png);margin: 10px 0 0 28px;height: 70px;float: left;color: #fff;line-height: 26px;}';
  89. style += '.qrcode-download-bar .slogan a {color: #fff;font-size: 16px;padding: 10px 0 0 86px;display: block;font-family: "Microsoft Yahei"!important;}';
  90. style += '.qrcode-download-bar .slogan a:hover {text-decoration: none;}';
  91. style += '.qrcode-download-bar .slogan em {color: #f5f74c;font-family: "Microsoft Yahei"!important;}';
  92. style += '.qrcode-download-bar .mo-download-btn {float: left;padding: 25px 0 0 0;}';
  93. style += '.qrcode-download-bar .mo-download-btn a{float: left;width: 197px;height: 46px;background: url('+options.imgRoot+'qr_code_download_bar.png) no-repeat 0 -116px;_background-image: url('+options.imgRoot+'qr_code_download_bar_ie6.png);text-indent: -99em;overflow:hidden;display: inline;}';
  94. style += '.qrcode-download-bar .mo-download-btn .bbs-android-dl:hover {background-position: 0 -70px;}';
  95. style += '.qrcode-download-bar .mo-download-btn .bbs-iphone-dl {background-position: 0 -180px;margin: 0 0 0 12px;}';
  96. style += '.qrcode-download-bar .mo-download-btn .bbs-iphone-dl:hover {background-position: 0 -92px;}';
  97. style += '.qrcode-download-bar .qrcode-block {float:left;}';
  98. style += '.qrcode-download-bar .qrcode-block .qrcode-tips{float: left;color: #fff;line-height: 15px;padding: 0 15px 0 16px;margin-top: 24px;font-family: "Microsoft Yahei"!important;}';
  99. style += '.qrcode-download-bar .qrcode-block .qrcode-tips a {color: #fff;line-height: 22px;}';
  100. style += '.qrcode-download-bar .qrcode-block .qrcode-tips a:hover {text-decoration: none;color: #fff;}';
  101. style += '.qrcode-download-bar .qrcode-block .qrcode-img{float: left;margin:10px 0 0 0;}';
  102. style += '.qrcode-download-bar .qrcode-block .qrcode-market{float: left;margin:10px 0 0 18px;width: 100px;height: 85px;background: url('+options.imgRoot+'qr_code_download_bar.png) no-repeat 0 -172px;_background-image: url('+options.imgRoot+'qr_code_download_bar_ie6.png);}';
  103. style += '.qrcode-download-bar .qrcode-block .qrcode-market a {display: block;height: 100%;}';
  104. style += '<\/style>';
  105. $('head').append(style);
  106. }
  107. if (options.isShowTpAD) {
  108. var fragment = format(
  109. String(function(){/*!
  110. <div class="top-hezi-ad" id="topHeziAd">
  111. <div class="top-hezi-ad-bd">
  112. <a href="http://shua.duowan.com/?icfa=1010#game" class="top-hezi-index" ></a>
  113. </div>
  114. <div class="top-hezi-ad-trigger" id="heziADTrigger"><embed src="#{options_swf}" width="100%" height="100%" border="0" wmode="transparent"><a href="javascript:void(0);"></a><img src="http://lol.duowan.com/s/v2/top-hezi-ad-trigger_bg.png" /></div>
  115. </div>
  116. */}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, ''),
  117. {
  118. options_swf: options.swf
  119. }
  120. );
  121. $("body").prepend(fragment);
  122. var heziADTrigger = $("#heziADTrigger"),
  123. topHeziAd = $("#topHeziAd .top-hezi-ad-bd");
  124. heziADTrigger.on("click", function(event){
  125. event.preventDefault();
  126. var isOpened = heziADTrigger.data("opened");
  127. if(!!!isOpened){
  128. topHeziAd.stop().animate({height: "120px"}, 300);
  129. heziADTrigger
  130. .data("opened", true)
  131. .addClass('top-hezi-ad-trigger-opened')
  132. .animate({top: '140px'}, 300);
  133. }else{
  134. topHeziAd.stop().animate({height: 0}, 300);
  135. heziADTrigger
  136. .data("opened", false)
  137. .removeClass('top-hezi-ad-trigger-opened')
  138. .animate({top: '20px'}, 300);
  139. }
  140. });
  141. };
  142. if (options.isShowFtAD) {
  143. if (!$.cookie) {
  144. !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?a(require("jquery")):a(jQuery)}(function(a){function b(a){return h.raw?a:encodeURIComponent(a)}function c(a){return h.raw?a:decodeURIComponent(a)}function d(a){return b(h.json?JSON.stringify(a):String(a))}function e(a){0===a.indexOf('"')&&(a=a.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return a=decodeURIComponent(a.replace(g," ")),h.json?JSON.parse(a):a}catch(b){}}function f(b,c){var d=h.raw?b:e(b);return a.isFunction(c)?c(d):d}var g=/\+/g,h=a.cookie=function(e,g,i){if(void 0!==g&&!a.isFunction(g)){if(i=a.extend({},h.defaults,i),"number"==typeof i.expires){var j=i.expires,k=i.expires=new Date;k.setTime(+k+864e5*j)}return document.cookie=[b(e),"=",d(g),i.expires?"; expires="+i.expires.toUTCString():"",i.path?"; path="+i.path:"",i.domain?"; domain="+i.domain:"",i.secure?"; secure":""].join("")}for(var l=e?void 0:{},m=document.cookie?document.cookie.split("; "):[],n=0,o=m.length;o>n;n++){var p=m[n].split("="),q=c(p.shift()),r=p.join("=");if(e&&e===q){l=f(r,g);break}e||void 0===(r=f(r))||(l[q]=r)}return l};h.defaults={},a.removeCookie=function(b,c){return void 0===a.cookie(b)?!1:(a.cookie(b,"",a.extend({},c,{expires:-1})),!a.cookie(b))}});
  145. };
  146. var fragment = format(
  147. String(function(){/*!
  148. <div class="qrcode-download-bar" id="qrcodeDownloadBar" style="display:none">
  149. <div class="qrcode-download-inner">
  150. <div class="slogan">
  151. <a href="http://m.duowan.com/?ref=DB">多玩游戏 安卓版首发!<br/>
  152. 大神攻略、美女囧图、解说视频 不再错过!</a>
  153. </div>
  154. <div class="mo-download-btn">
  155. <a href="http://szhuodong.duowan.com/s/duowanapp/apk/Duowan-DWbannercode.apk" class="bbs-android-dl" title="android lol 盒子下载">Android 下载</a>
  156. </div>
  157. <div class="qrcode-block">
  158. <div class="qrcode-tips"><a href="http://m.duowan.com/?ref=DB">多玩游戏安卓版<br/>点击或扫瞄下载</a></div>
  159. <div class="qrcode-img">
  160. <a href="http://bbs.duowan.com/thread-37619977-1-1.html" ><img src="#{options_imgRoot}apk_qrcode.png" alt="" /></a>
  161. </div>
  162. <div class="qrcode-market"><a href="http://m.duowan.com/?ref=DB"></a></div>
  163. </div>
  164. </div>
  165. <a href="javascript:void(0)" class="close">关闭</a>
  166. </div>
  167. */}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, ''),
  168. {
  169. options_imgRoot: options.imgRoot
  170. }
  171. );
  172. $("body").prepend(fragment);
  173. $("#qrcodeDownloadBar .close").on("click", function(event){
  174. event.preventDefault();
  175. closeBar();
  176. });
  177. var isClose = $.cookie("qrcodeDownloadBar") ;
  178. if(!isClose){
  179. openBar();
  180. }
  181. // http://feilong.org/shortest-ie6-judge-js
  182. var isIE6 = !!window.ActiveXObject && !window.XMLHttpRequest;
  183. if (isIE6) {
  184. var timer = null;
  185. $(window).bind("scroll", function(){
  186. clearTimeout(timer);
  187. $("#qrcodeDownloadBar").hide();
  188. timer = setTimeout(function(){
  189. showBar();
  190. }, 200);
  191. });
  192. $(window).bind("resize", function(){
  193. showBar();
  194. });
  195. function showBar(){
  196. var isClose = $.cookie("qrcodeDownloadBar") ;
  197. if(!isClose){
  198. var top = document.documentElement.scrollTop - 92 + $(window).height();
  199. $("#qrcodeDownloadBar").css("top", top);
  200. $("#qrcodeDownloadBar").show();
  201. }
  202. }
  203. };
  204. function openBar(){
  205. $("#qrcodeDownloadBar").show();
  206. }
  207. function closeBar(){
  208. $.cookie('qrcodeDownloadBar', '1', { expires: 1, path: "/" });
  209. $("#qrcodeDownloadBar").hide();
  210. }
  211. };
  212. function format(template, json) {
  213. return template.replace(/#\{(.*?)\}/g, function(all, key) {
  214. return json && (key in json) ? json[key] : "";
  215. });
  216. }
  217. });