common.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /**
  2. * Created by quanchen on 2014/8/26.
  3. */
  4. /*
  5. window.onload=function()
  6. {
  7. //加载js文件;
  8. function loadJS(url,callback){var script=document.createElement('script');script.type="text/javascript";if(script.readyState){script.onreadystatechange=function(){if(script.readyState=="loaded"||script.readyState=="complete"){script.onreadystatechange=null;if(callback){callback()}}}}else{script.onload=function(){if(callback){callback()}}}script.src=url;document.body.appendChild(script)};
  9. loadJS('http://pingjs.qq.com/ping_tcss_ied.js',tcssComplete);
  10. }*/
  11. //分享;
  12. var SHARE_ICON_URL='';//jpg 120*120;
  13. var SHARE_URL='';//分享地址;
  14. var SHARE_STR='';//分享文案;
  15. //朋友圈分享;
  16. function onBridgeInit()
  17. {
  18. //执行
  19. try{
  20. document.addEventListener('WeixinJSBridgeReady', function() {
  21. onBridgeReady();
  22. });
  23. }catch(e){}
  24. };
  25. function onBridgeReady()
  26. {
  27. //转发朋友圈
  28. WeixinJSBridge.on("menu:share:timeline", function(e) {
  29. var url = SHARE_URL;
  30. var data = {
  31. img_url: SHARE_ICON_URL,
  32. img_width: "120",
  33. img_height: "120",
  34. link: url,
  35. //desc这个属性要加上,虽然不会显示,但是不加暂时会导致无法转发至朋友圈,
  36. desc:SHARE_STR,
  37. title: SHARE_STR
  38. };
  39. WeixinJSBridge.invoke("shareTimeline", data, function(res) {
  40. WeixinJSBridge.log(res.err_msg)
  41. });
  42. });
  43. //同步到微博
  44. WeixinJSBridge.on("menu:share:weibo", function() {
  45. var url = SHARE_URL;
  46. WeixinJSBridge.invoke("shareWeibo", {
  47. "content": SHARE_STR,
  48. "url": url
  49. }, function(res) {
  50. WeixinJSBridge.log(res.err_msg);
  51. });
  52. });
  53. //分享给朋友
  54. WeixinJSBridge.on('menu:share:appmessage', function(argv) {
  55. var url = SHARE_URL;
  56. WeixinJSBridge.invoke("sendAppMessage", {
  57. img_url: SHARE_ICON_URL,
  58. img_width: "120",
  59. img_height: "120",
  60. link: url,
  61. desc: SHARE_STR,
  62. title: SHARE_STR
  63. }, function(res) {
  64. WeixinJSBridge.log(res.err_msg)
  65. });
  66. });
  67. WeixinJSBridge.invoke("showOptionMenu");
  68. };
  69. function isAndroid()
  70. {
  71. return (/Android/i.test(navigator.userAgent));
  72. };
  73. //点击流;
  74. function tcssComplete()
  75. {
  76. console.log('tcssComplete');
  77. try{
  78. if(typeof(pgvMain) == 'function') pgvMain();
  79. //alert('pgvMain')
  80. }catch(e){}
  81. }
  82. function clickBtnPgv(arg)
  83. {
  84. try{
  85. pgvSendClick({hottag:arg});
  86. }catch(e){}
  87. //alert(arg);
  88. }
  89. var wrongx=0;
  90. //单个按钮检测代码;
  91. function checkClick(touch,mc)
  92. {
  93. var obj={click:false,mcname:null};
  94. var mx,my;
  95. //mx=(touch.pageX-(wrongx/2))/scale;
  96. mx=touch.pageX/scale;
  97. my=touch.pageY/scale;
  98. var mcx,mcy,mcwidth,mcheight;
  99. mcx=mc._matrix.tx;
  100. mcy=mc._matrix.ty;
  101. mcwidth=mc.nominalBounds.width
  102. mcheight=mc.nominalBounds.height;
  103. var parentmc=mc;
  104. for(var i=0;i<2;i++)
  105. {
  106. parentmc=parentmc.parent;
  107. //console.log('run:',i,parentmc);
  108. if(parentmc!=null)
  109. {
  110. mcx+=parentmc._matrix.tx;
  111. mcy+=parentmc._matrix.ty;
  112. i=0;
  113. }
  114. }
  115. //console.log(mcx,mcwidth,mcy,mcheight,mx,my);
  116. if((mx>mcx&&mx<(mcx+mcwidth))&&(my>mcy&&my<(mcy+mcheight)))
  117. {
  118. obj.click=true;
  119. obj.mcname=mc.name;
  120. //console.log('click in mc area!');
  121. }
  122. else
  123. {
  124. obj.click=false;
  125. }
  126. return obj;
  127. }
  128. //多个按钮检测代码;
  129. function checkClickArr(touch,arr)
  130. {
  131. var obj={click:false,mcname:null};
  132. var tmp={};
  133. for(var i=0;i<arr.length;i++)
  134. {
  135. tmp=checkClick(touch,arr[i]);
  136. if(tmp.click==true)
  137. {
  138. obj=tmp;
  139. }
  140. }
  141. return obj;
  142. }
  143. //返回mc当前坐标的全局坐标;
  144. function localPosToGlobal(mc)
  145. {
  146. obj={x:0,y:0};
  147. var mcx,mcy;
  148. mcx=mc._matrix.tx;
  149. mcy=mc._matrix.ty;
  150. var parentmc=mc;
  151. for(var i=0;i<2;i++)
  152. {
  153. parentmc=parentmc.parent;
  154. //console.log('run:',i,parentmc);
  155. if(parentmc!=null)
  156. {
  157. mcx+=parentmc._matrix.tx;
  158. mcy+=parentmc._matrix.ty;
  159. i=0;
  160. }
  161. }
  162. obj.x=mcx;
  163. obj.y=mcy;
  164. return obj;
  165. }
  166. //正则分析法 js获取当前url参数;
  167. function getQueryString(name) {
  168. //console.log('window.location:'+window.location);
  169. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  170. var r = window.location.search.substr(1).match(reg);
  171. if (r != null) return unescape(r[2]); return null;
  172. }
  173. /*
  174. * 如果无参数 则是默认分享,则直接进入到游戏规则画面;
  175. *
  176. * QQ用户登录;
  177. *
  178. * 如果有带参数
  179. * 参数0 好友分值;
  180. * 参数1 好友机型[自定义参数];
  181. *
  182. * 参数2 通过参数0推导出百分比
  183. * 拉取助阵数据;
  184. *
  185. * top排行榜;
  186. * 拉取{用户名,用户头像,用户分值};
  187. *
  188. * 为ta助阵;
  189. * 发送数据;
  190. *
  191. *
  192. * */
  193. function creatAjax(){
  194. var ajax=null;
  195. if (window.XMLHttpRequest){
  196. ajax = new XMLHttpRequest();
  197. } else if (window.ActiveXObject){
  198. try{
  199. ajax = new ActiveXObject("Msxml2.XMLHTTP");
  200. } catch (e){
  201. try{
  202. ajax = new ActiveXObject("Microsoft.XMLHTTP");
  203. } catch (e){}
  204. }
  205. }
  206. if (!ajax){
  207. alert("无法创建 XMLHttpRequest");
  208. }
  209. return ajax;
  210. }
  211. function loadUrl(url,completeFun) {
  212. var ajax = creatAjax();
  213. if(!ajax) return;
  214. ajax.open("GET", url, true);
  215. ajax.send('');
  216. ajax.onreadystatechange = function(){
  217. if (ajax.readyState == 4 && ajax.status == 200){
  218. completeFun(ajax.responseText);
  219. }
  220. }
  221. }
  222. //震动;
  223. function Shake(target)
  224. {
  225. this.target = target;
  226. this.shakeX = 0;
  227. this.shakeY = 0;
  228. this.time = 0
  229. this.start = function(x,y,posX)
  230. {
  231. this.time = 0
  232. var rx = x != null? x:0;
  233. var ry = y != null? y:0;
  234. //console.log(this.shakeX);
  235. this.shakeX = this.target.x;
  236. //this.shakeX = posX;
  237. //this.shakeY = this.target.y
  238. this.target.x = this.shakeX - rx
  239. this.target.y = this.shakeY - ry * 3
  240. this.target.addEventListener("tick",this.enterFrameEvent)
  241. }
  242. this.enterFrame = function()
  243. {
  244. this.time++;
  245. this.target.x += 1.7*(this.shakeX -this.target.x)
  246. this.target.y += 1.7*(this.shakeY -this.target.y)
  247. if (this.time >=15)
  248. {
  249. this.target.removeEventListener("tick",this.enterFrameEvent)
  250. }
  251. }
  252. this.enterFrameEvent = getProxy(this,this.enterFrame)
  253. }
  254. //震动配套函数;
  255. function getProxy(value,funF)
  256. {
  257. var f = function(event)
  258. {
  259. funF.apply(value,[event])
  260. }
  261. return f;
  262. }
  263. function getRandom(a , b){
  264. return Math.random()*(b-a)+a;
  265. }
  266. //取整;
  267. function getZ(num){
  268. var rounded;
  269. rounded = (0.5 + num) | 0;
  270. // A double bitwise not.
  271. rounded = ~~ (0.5 + num);
  272. // Finally, a left bitwise shift.
  273. rounded = (0.5 + num) << 0;
  274. return rounded;
  275. }
  276. //合成图获取小图;
  277. function setImgItem(arg,libArg,imagesArg)
  278. {
  279. var gamePieces = new createjs.SpriteSheet(arg);
  280. for(var i=0;i<libArg.properties.manifest.length;i++){
  281. var id=libArg.properties.manifest[i]["id"]
  282. if(arg.animations[id])
  283. {
  284. imagesArg[id]=new createjs.SpriteSheetUtils.extractFrame(gamePieces,id);
  285. //console.log(id);
  286. }
  287. }
  288. }
  289. //clone obj
  290. function clone(obj) {
  291. var copy;
  292. // Handle the 3 simple types, and null or undefined
  293. if (null == obj || "object" != typeof obj) return obj;
  294. // Handle Date
  295. if (obj instanceof Date) {
  296. copy = new Date();
  297. copy.setTime(obj.getTime());
  298. return copy;
  299. }
  300. // Handle Array
  301. if (obj instanceof Array) {
  302. copy = [];
  303. for (var i = 0, len = obj.length; i < len; i++) {
  304. copy[i] = clone(obj[i]);
  305. }
  306. return copy;
  307. }
  308. // Handle Object
  309. if (obj instanceof Object) {
  310. copy = {};
  311. for (var attr in obj) {
  312. if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
  313. }
  314. return copy;
  315. }
  316. throw new Error("Unable to copy obj! Its type isn't supported.");
  317. }/* |xGv00|601ec080d2820f7b853a243696b30fba */