game9g.utils.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. if( typeof(game9g)=="undefined"){
  2. game9g={};
  3. }
  4. if(!game9g.utils){
  5. game9g.utils={};
  6. }
  7. var gstyle = document.createElement("style");
  8. str =".game9gdialog {display:none;color: white;background-color: rgb(0,0,0);text-align: center;-moz-border-radius: 8px;-webkit-border-radius: 8px;border-radius: 8px;font-family: Arial,Helvetica,sans-serif;font-weight: normal;font-size: 14px;width: 280px; z-index: 9991; top: 50%; left: 50%; position: fixed; margin-left: -140px; margin-top: -82.5px;}.game9gdialog header {font-weight: bold;margin-top: 10px;text-align: center;height: auto;width:auto;}.game9gdialog section {padding: 0px 20px 20px 20px;text-align: center;font-family: Arial,Helvetica,sans-serif;font-weight: normal;height:auto;width: auto;box-shadow: rgb(178, 178, 178) 0px -1px 1px -1px inset;}.game9gdialog footer {height: 60px;padding: 0px 0px;width: auto;}.game9gdialog footer a {display: inline-block;color: #007afe;text-align: center;line-height: 36px;font-weight: bold;text-decoration: none;Arial,Helvetica,sans-serif;font-size: 16px;width:43%;margin: 8px;border: solid 1px white;}.game9gmake{display:none;z-index: 9990; background-color: rgb(0, 0, 0); position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; opacity: 0.5}";
  9. gstyle.type="text/css";
  10. if(gstyle.styleSheet){ //ie下
  11. gstyle.styleSheet.cssText = str;
  12. } else {
  13. gstyle.innerHTML = str;
  14. }
  15. document.getElementsByTagName("head")[0].appendChild(gstyle);
  16. var game9gmake=document.createElement("div");
  17. game9gmake.id="game9gmake";
  18. game9gmake.className="game9gmake";
  19. document.getElementsByTagName("body")[0].appendChild(game9gmake);
  20. var game9gdialog=document.createElement("div");
  21. game9gdialog.id="game9gdialog";
  22. game9gdialog.className="game9gdialog";
  23. game9gdialog.innerHTML='<header><h2 id="game9gtitle">9G游戏</h2></header><section id="game9gcontent"></section><footer><a href="javascript:void(0)" id="game9gleftbtn">取消</a><a href="javascript:void(0)" id="game9grightbtn">确定</a></footer>';
  24. document.getElementsByTagName("body")[0].appendChild(game9gdialog);
  25. game9g.utils.dialog=function(){
  26. document.getElementById('game9gtitle').innerHTML=game9g.utils.shareConfirmparam.stitle;
  27. document.getElementById('game9gcontent').innerHTML=game9g.utils.shareConfirmparam.scontent;
  28. var game9gleftbtn=document.getElementById('game9gleftbtn');
  29. var game9grightbtn=document.getElementById('game9grightbtn');
  30. game9gleftbtn.removeEventListener('click');
  31. game9grightbtn.removeEventListener('click');
  32. game9gleftbtn.addEventListener('click',function(){
  33. game9g.utils.hideDialog();
  34. })
  35. game9grightbtn.addEventListener('click',function(){
  36. try{
  37. if(game9g.utils.shareConfirmparam.callback&&typeof(game9g.utils.shareConfirmparam.callback)=='function'){
  38. game9g.utils.shareConfirmparam.callback();
  39. }
  40. }catch(e){
  41. console.err("回调方法错误!");
  42. }
  43. game9g.utils.hideDialog();
  44. })
  45. game9g.utils.showDialog();
  46. };
  47. game9g.utils.shareConfirmparam={};
  48. game9g.utils.shareConfirm=function(scontent,callback,stitle){
  49. if(!stitle){
  50. stitle="9G游戏";
  51. }
  52. game9g.utils.shareConfirmparam={
  53. stitle:stitle,
  54. scontent:scontent,
  55. callback:callback
  56. }
  57. setTimeout(delayShareConfirm,1000);
  58. }
  59. function delayShareConfirm(){
  60. game9g.utils.dialog();
  61. }
  62. game9g.utils.hideDialog=function(){
  63. game9g.utils.hide('game9gmake');
  64. game9g.utils.hide('game9gdialog');
  65. }
  66. game9g.utils.showDialog=function(){
  67. game9g.utils.show('game9gmake');
  68. game9g.utils.show('game9gdialog');
  69. }
  70. game9g.utils.show=function(id){
  71. document.getElementById(id).style.display="block";
  72. }
  73. game9g.utils.hide=function(id){
  74. document.getElementById(id).style.display="none";
  75. }
  76. game9g.utils.getParameter=function(name) {
  77. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  78. var r = window.location.search.substr(1).match(reg);
  79. if (r != null) return r[2]; return null;
  80. }
  81. var spid = game9g.utils.getParameter("spid");
  82. // var domains=["caizy.cn", "caizy.cn", "caizy.cn", "frela.cn"];
  83. var domain = domains[parseInt(Math.random() * domains.length)];
  84. if(window.shareData){
  85. window.shareData.timeLineLink = "http://"+ parseInt(Math.random()*100000) +"."+ myData.gameid +"."+domain+"/gamecenter.html?gameid=" + myData.gameid + (spid ? "&spid=" + spid : "") + (localStorage.myuid ? "&uid=" + localStorage.myuid : "");
  86. console.dir("分享url:"+window.shareData.timeLineLink);
  87. }
  88. if (typeof(mebtnopenurl) == "string") {
  89. mebtnopenurl += ((mebtnopenurl.indexOf("?") == -1 ? "?" : "&") + "spid=" + spid);
  90. }
  91. if (typeof(goto9gurl) == "string") {
  92. goto9gurl += ((goto9gurl.indexOf("?") == -1 ? "?" : "&") + "spid=" + spid);
  93. }