game9g.utils.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. var game9g={};
  2. if(!game9g.utils){
  3. game9g.utils={};
  4. }
  5. if(!$.os){
  6. $.os={};
  7. }
  8. var probe = {
  9. support: function(key) {
  10. var bln = true;
  11. switch (key) {
  12. case "boxshadow":
  13. bln = this.supportBoxShadow();
  14. break;
  15. default:
  16. break
  17. }
  18. return bln
  19. },
  20. supportBoxShadow: function() {
  21. var $testDiv = $('<div style="box-shadow:inset 0px -1px 1px -1px #b2b2b2;"></div>');
  22. try {
  23. if ($testDiv.css("box-shadow")) {
  24. return true
  25. } else {
  26. return false
  27. }
  28. } catch(e) {
  29. return false
  30. }
  31. }
  32. };
  33. game9g.utils.dialog= {
  34. alert: function(options, callback) {
  35. var self = this;
  36. var closebtn = {
  37. title: "\u5173\u95ed",
  38. click: function() {}
  39. };
  40. var opt = {
  41. title: null,
  42. content: null,
  43. zindex: 4200,
  44. bgcolor: "#ccc",
  45. opacity: .5,
  46. topOffset: 0,
  47. width: "280",
  48. loadDefaultCss: true,
  49. buttons: {
  50. close: {
  51. title: "\u5173\u95ed",
  52. click: function() {}
  53. }
  54. }
  55. };
  56. if (typeof options == "string") {
  57. opt.content = options;
  58. if (callback) {
  59. closebtn.click = callback;
  60. opt = $.extend(true, opt, {
  61. buttons: {
  62. close: closebtn
  63. }
  64. })
  65. }
  66. } else {
  67. opt = $.extend(true, opt, options)
  68. }
  69. self.dialog(opt)
  70. },
  71. confirm: function(options, callback) {
  72. var self = this;
  73. var confirmbtn = {
  74. title: "\u786e\u5b9a",
  75. click: function() {}
  76. };
  77. var opt = {
  78. title: null,
  79. content: null,
  80. zindex: 4200,
  81. bgcolor: "#ccc",
  82. opacity: .5,
  83. topOffset: 0,
  84. width: "280",
  85. loadDefaultCss: true,
  86. buttons: {
  87. confirm: {
  88. title: "\u786e\u5b9a",
  89. click: function() {}
  90. },
  91. close: {
  92. title: "\u53d6\u6d88",
  93. click: function() {}
  94. }
  95. }
  96. };
  97. if (typeof options == "string") {
  98. opt.content = options;
  99. if (callback) {
  100. confirmbtn.click = callback;
  101. opt = $.extend(true, opt, {
  102. buttons: {
  103. confirm: confirmbtn
  104. }
  105. })
  106. }
  107. } else {
  108. opt = $.extend(true, opt, options)
  109. }
  110. self.dialog(opt)
  111. },
  112. dialog: function(options) {
  113. var self = this;
  114. var id = "dialog_" + (new Date).getTime();
  115. var opt = {
  116. title: null,
  117. content: null,
  118. zindex: 4200,
  119. bgcolor: "rgb(0,0,0)",
  120. opacity: .5,
  121. topOffset: 0,
  122. width: "280",
  123. loadDefaultCss: true,
  124. buttons: {
  125. close: {
  126. title: "\u5173\u95ed",
  127. click: function() {}
  128. }
  129. }
  130. };
  131. opt = $.extend(true, opt, options);
  132. opt.id = id;
  133. if (String(opt.width).indexOf("%") < 0) {
  134. opt.width = opt.width + "px"
  135. }
  136. if (opt.loadDefaultCss == true) {
  137. this.loadDialogCss()
  138. }
  139. var $mask = $('<div id="' + id + '_cover" ></div>');
  140. $mask.css({
  141. "z-index": opt.zindex,
  142. "background-color": "rgb(0,0,0)",
  143. position: "fixed",
  144. left: 0,
  145. top: 0,
  146. width: "100%",
  147. height: "100%",
  148. opacity: opt.opacity
  149. });
  150. $("body").append($mask);
  151. var $dialog = $('<div id="' + id + '" class="amsmobi_dialog" style="width:' + opt.width + ";coclor:white;z-index:" + parseInt(opt.zindex + 1) + ";top:50%;left:50%;position:fixed;_position:absolute;_top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+(document.documentElement.clientHeight - this.offsetHeight)/2+this.offsetHeight/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2);\"></div>");
  152. var $head = $("<header></header>");
  153. var $body = $("<section></section>");
  154. if (probe.support("boxshadow")) {
  155. $body.css("box-shadow", "inset 0px -1px 1px -1px #b2b2b2")
  156. } else {
  157. $body.css("border-bottom", "1px solid #b2b2b2")
  158. }
  159. var $footer = $("<footer></footer>");
  160. var closeDialog = function() {
  161. $dialog.remove();
  162. /*$mask.animate({
  163. opacity: 0
  164. },
  165. 600, "ease-out",
  166. function() {
  167. $mask.remove()
  168. })*/
  169. $mask.remove();
  170. };
  171. if (opt.title) {
  172. $head.append($("<h2>" + opt.title + "</h2>"))
  173. }
  174. $dialog.append($head);
  175. if (opt.content) {
  176. $body.append(opt.content)
  177. }
  178. $dialog.append($body);
  179. var newButtons = new Array;
  180. $.each(opt.buttons,
  181. function(key, btn) {
  182. if (key.toLowerCase() != "close") {
  183. btn.key = key;
  184. newButtons.push(btn)
  185. }
  186. });
  187. if (opt.buttons["close"]) {
  188. var btn = opt.buttons["close"];
  189. btn.key = "close";
  190. newButtons.push(btn)
  191. }
  192. var ibtnWidth = parseFloat((100 - newButtons.length) / newButtons.length);
  193. $.each(newButtons,
  194. function(key, btn) {
  195. var $btn = $('<a href="javascript:;" style="width:' + 43 + '%;margin: 8px;border: solid 1px white;" data-key="' + key + '">' + btn.title + "</a>");
  196. if (btn.key != "close") {
  197. if (probe.support("boxshadow")) {
  198. $btn.css("box-shadow", "inset -1px 0px 1px -1px #b2b2b2")
  199. } else {
  200. $btn.css("border-right", "1px solid #b2b2b2")
  201. }
  202. }
  203. if ($.os.ios) {
  204. $btn.click(function(e) {
  205. e.stopPropagation();
  206. e.preventDefault();
  207. if (btn.click) {
  208. btn.click();
  209. closeDialog()
  210. }
  211. })
  212. } else {
  213. $btn.click(function(e) {
  214. e.stopPropagation();
  215. e.preventDefault();
  216. if (btn.click) {
  217. btn.click();
  218. closeDialog()
  219. }
  220. })
  221. }
  222. $footer.append($btn)
  223. });
  224. $dialog.append($footer);
  225. $("body").append($dialog);
  226. var fixDialog = function() {
  227. var maxHeight = $(window).height() - 40;
  228. if ($dialog.height() > maxHeight) {
  229. var mTop = -(maxHeight / 2) + $(window).scrollTop();
  230. if ($.os.ios) {
  231. $dialog.css({
  232. "margin-left": -($dialog.width() / 2) + "px",
  233. "margin-top": mTop + "px",
  234. position: "absolute"
  235. })
  236. } else {
  237. $mask.css("position", "absolute");
  238. $(window).on("scroll",
  239. function() {
  240. var newHeight = $(window).height() + $(window).scrollTop();
  241. $mask.css("height", newHeight + "px")
  242. });
  243. var left = ($(window).width() - $dialog.width()) / 2;
  244. var style = "width:" + opt.width + ";z-index:" + parseInt(opt.zindex + 1) + ";position:absolute;top:" + ($(window).scrollTop() + 20) + "px;left:" + left + "px;";
  245. $dialog.attr("style", style)
  246. }
  247. } else {
  248. $dialog.css({
  249. "margin-left": -($dialog.width() / 2) + "px",
  250. "margin-top": -($dialog.height() / 2) + "px"
  251. })
  252. }
  253. };
  254. fixDialog();
  255. $(window).on("resize",
  256. function() {
  257. fixDialog()
  258. });
  259. $(window).on("orientationchange",
  260. function() {
  261. fixDialog()
  262. },
  263. false);
  264. return $dialog
  265. },
  266. showLoading: function(options) {
  267. this.loadLoadingCSS();
  268. var opt = {
  269. zindex: 4100,
  270. bgcolor: "#ccc",
  271. opacity: .5
  272. };
  273. opt = $.extend(true, opt, options);
  274. var id = "amsmobi_loading";
  275. if ($("#" + id).length == 0) {
  276. var $mask = $('<div id="' + id + '_cover" style="z-index:' + opt.zindex + ";background-color:" + opt.bgcolor + ";position:fixed;left:0;top:0;width:100%;height:100%;filter:alpha(opacity=" + opt.opacity * 100 + ");opacity:" + opt.opacity + ';_position:absolute;_top:expression(eval(document.compatMode && document.compatMode==\'CSS1Compat\') ? documentElement.scrollTop+(document.documentElement.clientHeight-this.offsetHeight)/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2); "><iframe style="position:fixed;_position:absolute;width:100%;height:100%;border:none;filter:alpha(opacity=0);opacity:0;left:0;top:0;z-index:-1;" src="about:blank"></iframe></div>');
  277. var $dialog = $('<div id="' + id + '" style="background-color:#999;width:106px;height:106px;margin-left:-53px;margin-top:-53px;-moz-border-radius: 8px;-webkit-border-radius: 8px;border-radius:8px; z-index:' + parseInt(opt.zindex + 1) + ";top:50%;left:50%;position:fixed;_position:absolute;_top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+(document.documentElement.clientHeight - this.offsetHeight)/2+this.offsetHeight/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2);\"></div>");
  278. if (probe.support("boxshadow")) {
  279. $dialog.append('<div class="amsmobi_loader" >Loading...</div>')
  280. } else {
  281. $dialog.append('<div style="margin-top:41px;margin-left:15px;color:#666">Loading...</div>')
  282. }
  283. $("body").append($mask).append($dialog)
  284. } else {
  285. $("#" + id + "_cover").show();
  286. $("#" + id).show()
  287. }
  288. },
  289. hideLoading: function() {
  290. $("#amsmobi_loading").hide();
  291. $("#amsmobi_loading_cover").hide()
  292. },
  293. loadLoadingCSS: function() {
  294. var style = ".amsmobi_loader {margin: 4em auto;font-size: 12px;width: 1em;height: 1em;border-radius: 50%;position: relative;text-indent: -9999em;-webkit-animation: amsmobi_load5 1.1s infinite ease;animation: amsmobi_load5 1.1s infinite ease;}" + " @-webkit-keyframes amsmobi_load5 {0%,100% {box-shadow: 0em -2.6em 0em 0em #ffffff, 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.5), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7);}" + " 12.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.7), 1.8em -1.8em 0 0em #ffffff, 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5);}" + " 25% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.5), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7), 2.5em 0em 0 0em #ffffff, 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 37.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5), 2.5em 0em 0 0em rgba(255, 255, 255, 0.7), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 50% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.5), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.7), 0em 2.5em 0 0em #ffffff, -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 62.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.5), 0em 2.5em 0 0em rgba(255, 255, 255, 0.7), -1.8em 1.8em 0 0em #ffffff, -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 75% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.5), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.7), -2.6em 0em 0 0em #ffffff, -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 87.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.5), -2.6em 0em 0 0em rgba(255, 255, 255, 0.7), -1.8em -1.8em 0 0em #ffffff;} }" + " @keyframes amsmobi_load5 {0%,100% { box-shadow: 0em -2.6em 0em 0em #ffffff, 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.5), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7);} " + " 12.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.7), 1.8em -1.8em 0 0em #ffffff, 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5);} " + " 25% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.5), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7), 2.5em 0em 0 0em #ffffff, 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 37.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5), 2.5em 0em 0 0em rgba(255, 255, 255, 0.7), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 50% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.5), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.7), 0em 2.5em 0 0em #ffffff, -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 62.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.5), 0em 2.5em 0 0em rgba(255, 255, 255, 0.7), -1.8em 1.8em 0 0em #ffffff, -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 75% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.5), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.7), -2.6em 0em 0 0em #ffffff, -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 87.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.5), -2.6em 0em 0 0em rgba(255, 255, 255, 0.7), -1.8em -1.8em 0 0em #ffffff;}}";
  295. this.loadCss("mobi_loading_style", style)
  296. },
  297. loadDialogCss: function() {
  298. var style = ".amsmobi_dialog {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;}" + " .amsmobi_dialog header{font-weight:bold;margin-top:10px;line-height:20px;text-align:center;font-family:Arial,Helvetica,sans-serif;height:auto;width:auto;}" + " .amsmobi_dialog footer{height:40px;padding:0px 0px;width:auto;}" + " .amsmobi_dialog footer a{display:block;color:#007afe;float:left;text-align:center;height:40px;line-height:36px;font-weight:bold;text-decoration: none;font-family:Arial,Helvetica,sans-serif;font-size:16px; }" + " .amsmobi_dialog footer a:hover{text-decoration:none;}" + " .amsmobi_dialog footer button{border:none;background:none;}" + " .amsmobi_dialog section{padding:0px 20px 20px 20px ;overflow-x:hidden;text-align:center;font-family:Arial,Helvetica,sans-serif;font-weight:normal;height:auto;width:auto;}";
  299. this.loadCss("mobi_dialog_style", style)
  300. },
  301. loadCss: function(id, style) {
  302. if ($("#" + id).length == 0) {
  303. var newStyle = $('<style id="' + id + '">' + style + "</style>");
  304. $("head").append(newStyle)
  305. }
  306. }
  307. };
  308. game9g.utils.shareConfirmparam={};
  309. game9g.utils.shareConfirm=function(scontent,callback,stitle){
  310. if(!stitle){
  311. stitle="提示";
  312. }
  313. game9g.utils.shareConfirmparam={
  314. stitle:stitle,
  315. scontent:scontent,
  316. callback:callback
  317. }
  318. setTimeout(delayShareConfirm,1000);
  319. }
  320. function delayShareConfirm(){
  321. game9g.utils.dialog.confirm({
  322. title: game9g.utils.shareConfirmparam.stitle,
  323. content: game9g.utils.shareConfirmparam.scontent,
  324. buttons: {
  325. confirm: {
  326. title: "取消",
  327. click: function() {
  328. }
  329. },
  330. close: {
  331. title: "确定",
  332. click: function() {
  333. game9g.utils.shareConfirmparam.callback();
  334. }
  335. }
  336. }
  337. })
  338. }
  339. //转发域名配置
  340. var domains=["oixm.cn", "aross.cn", "lival.cn", "cubbe.cn", "emofo.cn"];
  341. var domain = domains[parseInt(Math.random() * domains.length)];
  342. if(window.shareData){
  343. window.shareData.timeLineLink = thegameurl ;
  344. }