index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. //lang
  2. function lang(str, re){
  3. if(typeof langs == 'undefined') langs = false;
  4. if(langs && typeof langs[str] != 'undefined'){
  5. str = langs[str];
  6. }
  7. if(re) for(var r in re){
  8. str = str.replace(r, re[r]);
  9. }
  10. return str;
  11. }
  12. //格式化保留2位
  13. function formatCount(count){
  14. var countokuu=(count/100000000).toFixed(3);
  15. var countwan = (count/10000).toFixed(3);
  16. if(count> 100000000)
  17. return countokuu.substring(0,countokuu.lastIndexOf('.')+3) + '亿';
  18. if(count > 10000)
  19. return countwan.substring(0,countwan.lastIndexOf('.')+3)+'万';
  20. else
  21. return count
  22. }
  23. // 格式化时间戳
  24. function dateformat(d){
  25. if(!d) return '刚刚';
  26. var time = new Date((parseInt(d)+28800)*1000);
  27. var ymd = time.getUTCFullYear() + "-" + (time.getUTCMonth()+1) + "-" + time.getUTCDate() + ' ';
  28. var his = time.getUTCHours() + ":" + (time.getUTCMinutes()<10?'0':'') + time.getUTCMinutes();
  29. return ymd + his;
  30. }
  31. //谷歌验证时间提示
  32. function timer(timestamp){
  33. setInterval(function(){
  34. timestamp+=1;
  35. $('#bjtime').html(t(timestamp));
  36. },1000)
  37. }
  38. //时间戳函数
  39. function t(timestamp, ymd) {
  40. var d= new Date((parseInt(timestamp)+28800)*1000);
  41. var time =d.getUTCFullYear()+"-"+p((d.getUTCMonth()+1))+"-"+p(d.getUTCDate())+" "+p(d.getUTCHours())+":"+p(d.getUTCMinutes())+":"+p(d.getUTCSeconds());
  42. if(ymd) return ymd = d.getUTCFullYear() + "-" + (d.getUTCMonth()+1) + "-" + d.getUTCDate() + ' ';
  43. return time;
  44. }
  45. //补0函数
  46. function p(s) {
  47. return s < 10 ? '0' + s: s;
  48. }
  49. //弹出时间提示
  50. function timealert(){
  51. return alert(lang('双重密码错误,确保您的手机时间与北京时间\n{time}一致',{'{time}':t(timestamp)}));
  52. }
  53. //获取价格间隔时间
  54. ALLCOIN = {btc:[lang('比特币')],ltc:[lang('莱特币')],doge:[lang('狗狗币')],ybc:[lang('元宝币')],eth:[lang('以太币')]};
  55. rate_timer = 10;
  56. IS_LOGIN = 0;
  57. title = document.title; titleprice = 0;
  58. coin = {name: 'btc', sign: ''};
  59. pricemsg = lang('此出价为1个币的价格');
  60. nice_price = {sale: pricemsg, buy: pricemsg};
  61. BSConfig = {
  62. limit:50, sort:0, timeid:0,size:(coin.name=='doge'?5:2),
  63. setlimit:function(){
  64. var html = '<tr><td colspan="3">'+lang('数据加载中')+'...</td></tr>';
  65. $('#salelist').html(html);$('#buylist').html(html);
  66. if(BSConfig.limit==10){BSConfig.limit=20;$.cookie('bslimit',20);$('#bssetlink').html(lang('点击收起')).attr('class', 'up');}
  67. else{BSConfig.limit=10;$.cookie('bslimit',10);$('#bssetlink').html(lang('展开查看更多')).attr('class', '');}}
  68. };
  69. function bgline(){
  70. $('.trade_list .item tr, .pay_record tr, .trade_entrust tr, .trade_record tr, .entrust_list tr, .plan_manage .table_list tr,.new_strike table tr').hover(function(){$(this).addClass('selected');},function(){$(this).removeClass('selected');});
  71. }
  72. //坏数字
  73. function badFloat(num, size){
  74. if(isNaN(num)) return true;
  75. num += '';
  76. if(-1 == num.indexOf('.')) return false;
  77. var f_arr = num.split('.');
  78. if(f_arr[1].length > size){
  79. return true;
  80. }
  81. return false;
  82. }
  83. //按钮效果
  84. function tabFn(id, cn){
  85. var o = Dom(id), cls = o.className;
  86. o.onmouseover = function(){this.className = cn;}
  87. o.onmouseout = function(){this.className = cls;}
  88. }
  89. //浮层
  90. function Maskfn(id){
  91. var MaskBg = Dom('MaskBg');
  92. Dom(id).onclick = function(){
  93. MaskBg.style.height = Math.max(document.body.offsetHeight, document.documentElement.clientHeight) + 'px';
  94. MaskBg.style.display = "block";
  95. Dom('Mask1').style.display = "block";
  96. }
  97. Dom('closeBtn').onclick = Dom('mBtn1').onclick = Dom('mBtn2').onclick = function(){
  98. MaskBg.style.display = "none";
  99. Dom('Mask1').style.display = "none";
  100. }
  101. }
  102. function btvs(s,n){if(n)btvsn=n;btvsn+=s;setTimeout("btvs("+s+")",s*1000);}
  103. //格式化小数
  104. //@f float 传入小数: 123; 1.1234; 1.000001;
  105. //@size int 保留位数
  106. //@add bool 进位: 0舍 1进
  107. ffconf = [[],[],[100, 0.01],[1000, 0.001],[10000, 0.0001],[100000, 0.00001]];
  108. function formatfloat(f, size, add){
  109. f = parseFloat(f);
  110. var ff = Math.floor(f * ffconf[size][0]) / ffconf[size][0];
  111. if(add && f > ff) ff += ffconf[size][1];
  112. return isNaN(ff)? 0: ff;
  113. }
  114. // 浮点数精确加法
  115. function FloatAdd(arg1,arg2){
  116. var r1, r2, m;
  117. try {r1 = arg1.toString().split(".")[1].length} catch (e) {r1 = 0}
  118. try {r2 = arg2.toString().split(".")[1].length} catch (e) {r2 = 0}
  119. m = Math.pow(10, Math.max(r1, r2));
  120. return (arg1 * m + arg2 * m) / m;
  121. }
  122. // 浮点数减法
  123. function FloatSub(arg1,arg2){
  124. var r1,r2,m,n;
  125. try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
  126. try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
  127. m=Math.pow(10,Math.max(r1,r2));
  128. //动态控制精度长度
  129. n=(r1>=r2)?r1:r2;
  130. return ((arg1*m-arg2*m)/m).toFixed(n);
  131. }
  132. // 精确乘法
  133. function FloatMul(arg1,arg2)
  134. {
  135. var m=0,s1=arg1.toString(),s2=arg2.toString();
  136. try{m+=s1.split(".")[1].length}catch(e){}
  137. try{m+=s2.split(".")[1].length}catch(e){}
  138. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
  139. }
  140. //Dom
  141. function Dom(o){return document.getElementById(o);}
  142. //用户更新
  143. function ua_refresh(){
  144. if(rate_timer == 10){
  145. $.get('/coin/'+moneyconfig.coin+'/rate.js?t=' + btvsn, function(d){
  146. for(var coin in d) {
  147. CoinRate[coin] = parseFloat(d[coin]);
  148. var dom = $('#rate-'+coin);
  149. var c = coin+'-logo' +' '+moneyconfig.coin+'-'+coin;
  150. dom.parent().attr('class' ,dom.html()==CoinRate[coin]?c: (dom.html()>CoinRate[coin]?'down '+c:'up '+c));
  151. dom.html(CoinRate[coin]);
  152. }
  153. }, 'json');
  154. rate_timer = 0;
  155. } else rate_timer++;
  156. if(!user.uid) return;
  157. //资产统计
  158. var o=formatfloat(user[moneyconfig.coin+'_over'], 2);
  159. var l=formatfloat(user[moneyconfig.coin+'_lock'], 2);
  160. $('.ua_rmb_over').html(o);$('.ua_rmb_lock').html(l);
  161. var money = l+o, coins = ['btc','ltc','ybc','doge','eth'];
  162. for(var i = 0;i<coins.length;i++){
  163. o = formatfloat(user[coins[i]+'_over'], 3);l = formatfloat(user[coins[i]+'_lock'], 3);
  164. $('.ua_'+coins[i]+'_over').html(o); $('.ua_'+coins[i]+'_lock').html(l); $('.ua_'+coins[i]).html(formatfloat(o+l, 3));
  165. if(typeof CoinRate[coins[i]] != 'undefined') money += (l+o)*CoinRate[coins[i]];
  166. }
  167. $('.ua_rmb').html(formatfloat(money, 2));
  168. //最大可卖
  169. $('#sale_max').html(formatfloat(user[coin.name+'_over'], 3));
  170. finance();
  171. }
  172. //全站委托
  173. function btcsum(){
  174. var b2width = coin.name=='btc'? 3.3: 0.3;
  175. clearTimeout(BSConfig.timeid);
  176. $.get('/coin/' + moneyconfig.coin + '/' + coin.name + '/trust.js?t=' + btvsn, function(data){
  177. var maxnum = 0;
  178. for(var type in data){
  179. var d = data[type];
  180. var html = '';
  181. var idhtml = '';
  182. if(BSConfig.sort && type == 'sale'){
  183. var dsort = [];
  184. var dmax = d.length > BSConfig.limit? BSConfig.limit: d.length;
  185. for(var j = dmax; j > 0; j--) dsort[dmax - j] = d[j - 1];
  186. d = dsort;
  187. }
  188. for(var i in d){
  189. if(BSConfig.limit && i == BSConfig.limit) break;
  190. if(parseFloat(d[i].n)>maxnum) maxnum = parseFloat(d[i].n);
  191. i = parseInt(i);
  192. idhtml = type == 'buy'? lang('买')+'(' + (i + 1) + ')': lang('卖')+'(' + (BSConfig.sort? dmax--: i + 1) + ')';
  193. html += '<tr onclick="autotrust(this,\''+type+'\')" style="cursor: pointer;"><td width="40" style="padding-right:0;">' + idhtml + '</td><td style="padding-right:10px;padding-left: 10px;width: 50px">' + moneyconfig.sign +'<span class="oprice">'+ parseFloat(d[i].p) + '</span></td><td width="40" style="padding-left: 10px;padding-right: 10px;width:50px;">'+ d[i].n +'</td><td style="padding-left: 10px;padding-right: 10px;"><div class="progress progress_'+(type == 'buy'?'red':'green')+'"><div class="bar" data="'+d[i].n+'"></div></div></td></tr>';
  194. }
  195. $('#' + type + 'list').html(html);
  196. if(type == 'buy'){
  197. $('#btc_buyone').html(typeof d[0] == 'undefined'? 0: parseFloat(d[0].p));
  198. } else {
  199. $('#btc_saleone').html(typeof d[0] == 'undefined'? 0: parseFloat(d[BSConfig.sort && type == 'sale'?d.length-1:0].p));
  200. }
  201. }
  202. $('.bar').each(function(){
  203. $(this).css('width', (parseFloat($(this).attr('data')) * 100 / maxnum)+'%');
  204. });
  205. nice_price = {sale: data['buy'].length? data['buy'][0].p: 0, buy: data['sale'].length? data['sale'][0].p: 0};
  206. $('#sale_nice').html(nice_price.sale); $('#buy_nice').html(nice_price.buy);
  207. if(typeof saleone =='undefined') {$('#pricein').val(parseFloat(nice_price.buy));$('#priceout').val(parseFloat(nice_price.sale)); saleone = 1;}
  208. bgline();
  209. BSConfig.timeid = setTimeout("btcsum()", 5000);
  210. }, 'json');
  211. }
  212. //全站成交
  213. bttimeid = 0;
  214. function btcorder(limit){
  215. clearTimeout(bttimeid);
  216. $.get('/coin/' + moneyconfig.coin + '/' + coin.name + '/order.js?t=' + btvsn, function(d){
  217. var html = '';
  218. for(var i in d.d){
  219. if(limit && i > limit) break;
  220. if(30 == limit){
  221. html += '<tr><td width="19%">' + d.d[i].t + '</td><td width="21%"><span class="' + (d.d[i].s == 'buy'? 'color_red': 'color_green') + '">' + (d.d[i].s == 'buy'? lang('买入'): lang('卖出')) + '</span></td><td width="20%">' + moneyconfig.sign + d.d[i].p + '</td><td width="19%">' + coin.sign + formatfloat(d.d[i].n, 3) + '</td><td width="21%">' + moneyconfig.sign + formatfloat(d.d[i].n * d.d[i].p, 2) + '</td></tr>';
  222. }else{
  223. html += '<tr><td>' + d.d[i].t + '</td><td width="21%" class="' + (d.d[i].s == 'buy'? 'color_red': 'color_green') + '">' + (d.d[i].s == 'buy'? lang('买入'): lang('卖出')) + '</td><td class="' + d.d[i].s + '">' + moneyconfig.sign + d.d[i].p + '</td><td>' + coin.sign + formatfloat(d.d[i].n, 3) + '</td></tr>';
  224. }
  225. }
  226. $('#orderlist').html(html);
  227. // 更新价格
  228. if(typeof d.d[0] == 'undefined') d.d[0] = {p: 0.0};
  229. d.d[0].p = d.d[0].p + '';
  230. var price = d.d[0].p.split('.');
  231. if(price.length == 1)price[1] = '00';
  232. $('#btc_rmb_box').html(moneyconfig.sign + price[0] + "<b>." + (price[1].substring(0, 2)) + "</b>");
  233. $('#btc_rmb_new').html(parseFloat(d.d[0].p));
  234. $('#btc_min_box').html(parseFloat(d.min));
  235. $('#btc_max_box').html(parseFloat(d.max));
  236. $('#btc_sum_box').html(coin.name == 'doge' ? parseInt(d.sum) : parseFloat(d.sum));
  237. var zd_rmb = (parseFloat(d.min) + parseFloat(d.max)) / 2;
  238. zd_rmb = ((formatfloat(d.d[0].p, 2) - zd_rmb) / zd_rmb * 100).toString().split('.');
  239. if(typeof zd_rmb[1] == 'undefined'){
  240. zd_rmb = ['0', '0'];
  241. }
  242. $('#btc_zd_box').html(zd_rmb[0] + '.' + zd_rmb[1].substr(0, 2) + '%');
  243. //改标题
  244. var tp = titleprice && d.d[0].p != titleprice? (d.d[0].p > titleprice? '↑': '↓'): '';
  245. titleprice = d.d[0].p;
  246. document.title = moneyconfig.sign+d.d[0].p+tp+' - '+title;
  247. bgline();
  248. finance();
  249. bttimeid = setTimeout("btcorder(" + limit + ")", 5000);
  250. }, 'json');
  251. }
  252. function cointab(c){
  253. coin={name:c,sign:''};
  254. $('#tab-allcoin li').removeClass('selected');$('#tab-'+c).addClass('selected');btcsum(); btcorder();
  255. $('#trade-link').attr('href', '/'+c+'/');
  256. kline($("#chart-control > a.selected").attr('data-time'));
  257. }
  258. //取消委托
  259. function trustcancel(id){
  260. $.get('/ajax/trustcancel/id/' + id, function(d){
  261. alert(d.msg);
  262. if(d.status){
  263. for(var i in d.data) user[i] = d.data[i];
  264. $('#t_n_o_' + id).html(coin.sign + '0.000');
  265. $('#t_s_' + id).removeClass('color_red').html(lang('已经撤销'));
  266. $('#t_opt_'+id).remove();
  267. if(typeof coinorder == 'undefined') $('#t_s_' + id).parent().remove();
  268. }
  269. }, 'json');
  270. }
  271. //最大可买
  272. function buy_max(price, len){
  273. len = len || 2;
  274. var add = 0;
  275. if(len == 5) add = 1;
  276. price = formatfloat(price, len, add);
  277. if(user[moneyconfig.coin+'_over'] > 0 && price > 0){
  278. $('#buy_max').html(formatfloat(parseInt(parseInt(user[moneyconfig.coin+'_over'] * 100) / price * 10000000) / 1000000000, 3));
  279. } else {
  280. $('#buy_max').html(0);
  281. }
  282. }
  283. // 资产
  284. function finance() {
  285. if (user.uid) {
  286. var all = 0;
  287. for (var i in ALLCOIN) {
  288. var f = FloatAdd(user[i + '_over'], user[i + '_lock']) * parseFloat($('#rate-' + i).html());
  289. all = FloatAdd(f,all);
  290. }
  291. all = FloatAdd(FloatAdd(user[moneyconfig.coin + '_over'], user[moneyconfig.coin + '_lock']),all);
  292. $('.ufinance').html(moneyconfig.sign+formatfloat(all,2));
  293. //净资产
  294. if(parseFloat($('#uloan').html()) == 0){
  295. $('.una').html(moneyconfig.sign+formatfloat(all,2));
  296. } else {
  297. $('.una').html(moneyconfig.sign+formatfloat(all-parseFloat($('#uloan').html()),2));
  298. }
  299. }
  300. }
  301. //总价
  302. function sumprice(type){
  303. var inputtype = type == 'buy'? 'in': 'out';
  304. if ($('#number' + inputtype).length > 0) Dom(type + '_sumprice').innerHTML = formatfloat(FloatMul(Dom('number' + inputtype).value, Dom('price' + inputtype).value), 5);
  305. }
  306. //委托提交处理
  307. function tbtcSubmit(type){
  308. // 最小下单
  309. var min = {'btc':0.01,'ltc':0.1,'ybc':1,'doge':100,'eth':0.1};
  310. var number = parseFloat($('#number' + type).val());
  311. if(isNaN(number)) return tm_show(type,{status:0,data:'',msg:lang('数量有误,请重新输入')});
  312. if(number < min[coin.name]) return tm_show(type,{status:0,data:'',msg:lang('最小下单')+min[coin.name]+coin.name.toUpperCase()});
  313. $('#trustbtn' + type).attr('onclick', '');
  314. $.post("/ajax/trustbtc/", {type: type, coin: coin.name, price: parseFloat($('#price' + type).val()), number: parseFloat($('#number' + type).val()), pwdtrade: $('#pwdtrade' + type).val(), hotp: $('#hotp' + type).val()},
  315. function(d){
  316. $('#trustbtn' + type).attr('onclick', 'tbtcSubmit("' + type + '")');
  317. if(d.status) {
  318. for(var i in d.data) user[i] = d.data[i];
  319. if($('#norecord')) $('#norecord').remove();
  320. if(typeof coinorder != 'undefined'){
  321. page(0,'trust');
  322. }else{
  323. opentrades();
  324. }
  325. }
  326. if(d.data=='ga') {timealert();}else{tm_show(type,d);}
  327. }, 'json');
  328. }
  329. //提示效果
  330. function tm_hide(type){$('#trustmsg'+type).fadeOut()}
  331. function tm_show(type, d){
  332. $('#trustmsg'+type).html(d.status == 1? '<i></i>' + d.msg: '<i style="background-position: -84px 0;"></i><span style="color:red;">'+d.msg+'</span>');
  333. $('#trustmsg'+type).show();setTimeout("tm_hide('"+type+"')",3000);
  334. }
  335. //验证价格
  336. function vNum(o, len){
  337. if (isNaN(o.value)) o.value = '';
  338. var value = len?formatfloat(o.value, len, 0):parseInt(o.value);
  339. if(badFloat(o.value, len)) o.value = value
  340. }
  341. // 借贷数量
  342. function vloan(o, len) {
  343. vNum(o, len);
  344. var vi = parseFloat(o.value);
  345. var max = parseFloat($('#borrow_max').html());
  346. if(vi > max){
  347. o.value = max;
  348. }
  349. }
  350. //SHOW GA PW
  351. function showGA(v,l,type){
  352. if(!v) return;
  353. $.get('/ajax/user2ga/email/' + v, function(d){
  354. type = type||'';
  355. if(d.status == 1){
  356. // GA
  357. $('#ga_pwd'+type).show();$('#ga_isclosed').hide();
  358. }else if(d.status == 2){
  359. // verify code
  360. $('#code').show();$('#ga_isclosed'+type).show();
  361. $('#captchaimg'+type).attr('src', '/index/captcha?t='+Math.random());
  362. }else if(d.msg){
  363. if(l == 1){
  364. $('.quick_login_x .tip').html(d.msg).show();
  365. }else if(l == 2){
  366. $('#emailmsg').html(d.msg).show();
  367. }else{
  368. if($('.z1 .tip').length == 0) $('.z1').append('<div class="tip"><b class="false">'+ d.msg+'</b></div>');
  369. }
  370. }
  371. }, 'json');
  372. }
  373. //单币价格提示
  374. function pricemsgfn(){
  375. if($(this).val() == pricemsg){
  376. $(this).val('');
  377. }
  378. }
  379. //借贷
  380. function loanSubmit(){
  381. // 借款金额
  382. var amount = parseFloat($('#borrow_Money').val());
  383. // 费率
  384. $.post('/ajax/loanorder/',{coin:loancoin.id,amount:amount,fee:loancoin.fee,is_agree:$('#is_agree').is(':checked')?1:0},function(d){
  385. if ((!d.status) && (d.data == 'bind')) return showDialog('cy-dialog');
  386. alert(d.msg);window.location.reload();
  387. },'json')
  388. }
  389. $(function(){
  390. bgline();
  391. /*首页选项卡*/
  392. $('.home_tab .thead li').click(function(){$('.home_tab .tbody').hide();$('.home_tab #' + $(this).attr('data-target')).show();$('.home_tab .thead li').removeClass('selected');$(this).addClass('selected');return false;},function(){});
  393. /*通用弹窗*/
  394. $('.popup em').click(function(){$(this).parent('.popup').hide();},function(){});
  395. /*交易中心-1*/
  396. $('.max_buy, .max_sale').click(function(){$('#'+$(this).attr('class')).val($(this).html());},function(){});
  397. /*qq群*/
  398. $('.qqgroup').hover(function(){$(this).addClass('selected');},function(){$(this).removeClass('selected');});
  399. /*fuck IE*/
  400. placeholder();
  401. });
  402. (function(e){typeof define=="function"&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function n(e){return u.raw?e:encodeURIComponent(e)}function r(e){return u.raw?e:decodeURIComponent(e)}function i(e){return n(u.json?JSON.stringify(e):String(e))}function s(e){e.indexOf('"')===0&&(e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return e=decodeURIComponent(e.replace(t," ")),u.json?JSON.parse(e):e}catch(n){}}function o(t,n){var r=u.raw?t:s(t);return e.isFunction(n)?n(r):r}var t=/\+/g,u=e.cookie=function(t,s,a){if(s!==undefined&&!e.isFunction(s)){a=e.extend({},u.defaults,a);if(typeof a.expires=="number"){var f=a.expires,l=a.expires=new Date;l.setTime(+l+f*864e5)}return document.cookie=[n(t),"=",i(s),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var c=t?undefined:{},h=document.cookie?document.cookie.split("; "):[];for(var p=0,d=h.length;p<d;p++){var v=h[p].split("="),m=r(v.shift()),g=v.join("=");if(t&&t===m){c=o(g,s);break}!t&&(g=o(g))!==undefined&&(c[m]=g)}return c};u.defaults={},e.removeCookie=function(t,n){return e.cookie(t)===undefined?!1:(e.cookie(t,"",e.extend({},n,{expires:-1})),!e.cookie(t))}});
  403. function placeholder(){
  404. if('placeholder' in document.createElement('input')) return;
  405. $(':text[placeholder],:password[placeholder]').each(function(){
  406. $(this).val($(this).attr('placeholder'));
  407. $(this).bind('blur', function(){
  408. if($(this).val() == '') $(this).val($(this).attr('placeholder'));
  409. });
  410. $(this).bind('focus', function(){
  411. if($(this).val() == $(this).attr('placeholder')) $(this).val('');
  412. });
  413. });
  414. }
  415. //获取指定名称的cookie的值
  416. function getCookie(objName) {
  417. var arrStr = document.cookie.split("; ");
  418. for (var i = 0; i < arrStr.length; i++) {
  419. var temp = arrStr[i].split("=");
  420. if (temp[0] == objName) return unescape(temp[1]);
  421. }
  422. }
  423. // 买入/卖出 比例
  424. function slider(){
  425. var type = ['sale','buy','borrow'];
  426. for(var i in type){
  427. $("#slider_"+type[i]).slider({
  428. value: 0,min: 0, max: 100,step: 10,range: "min",slide: function(a, t) {
  429. var type = $(t.handle).attr('data_slide');
  430. var e = $("#"+type+'_max').text();
  431. $("#"+type+' .ui-slider-handle').addClass('ui-state-focus ui-state-active');
  432. if(type == 'buy') {
  433. $("#numberin").val((e / 100 * t.value).toFixed(3));
  434. }else if(type =='sale'){
  435. $("#numberout").val((e / 100 * t.value).toFixed(3));
  436. }else{
  437. $("#borrow_Money").val((e / 100 * t.value).toFixed(loancoin.decimal-2));
  438. }
  439. $("#ratio_num_"+type).text(t.value + "%");
  440. }
  441. })
  442. }
  443. }
  444. // 根据委托填价格
  445. function autotrust(_this,type){
  446. $(_this).children().each(function(i , d){
  447. if(type == 'sale'){
  448. if(i == 1) {
  449. $('#pricein').val($(d).find('.oprice').html()).css({
  450. 'color':'#333',
  451. 'font-size':'14px'
  452. });
  453. }
  454. }
  455. if(type == 'buy'){
  456. if(i == 1) {
  457. $('#priceout').val($(d).find('.oprice').html()).css({
  458. 'color':'#333',
  459. 'fontSize':'14px'
  460. });
  461. }
  462. }
  463. })
  464. }
  465. //弹出层
  466. function showDialog(id) {
  467. // 遮罩
  468. $('#'+id).removeClass('modal-out').addClass('styled-pane');
  469. var dialog = Dom(id);
  470. dialog.style.display = 'block';
  471. if (Dom('mask') == null) {
  472. $('body').prepend('<div class="ui-mask" id="mask" onselectstart="return false"></div>');
  473. $('#mask').bind('click',function(){hideDialog(id)})
  474. }
  475. var mask = Dom('mask');
  476. mask.style.display = 'inline-block';
  477. mask.style.width = document.body.offsetWidth + 'px';
  478. mask.style.height = document.body.scrollHeight + 'px';
  479. //居中
  480. var bodyW = document.documentElement.clientWidth;
  481. var bodyH = document.documentElement.clientHeight;
  482. var elW = dialog.offsetWidth;
  483. var elH = dialog.offsetHeight;
  484. dialog.style.left = (bodyW - elW) / 2 + 'px';
  485. dialog.style.top = (bodyH - elH) / 2 + 'px';
  486. dialog.style.position = 'fixed';
  487. }
  488. // 关闭弹出框
  489. function hideDialog(id, fn) {
  490. $('#'+id).removeClass('styled-pane').addClass('modal-out');
  491. $('#mask').addClass('out');
  492. setTimeout(function(){$('#'+id).hide();$('#mask').remove();},300);
  493. if (typeof fn == 'function') fn();
  494. }
  495. // 登录跳转
  496. function jump(url) {
  497. if($.cookie('NICKNAME')){
  498. top.location=url;
  499. }else{
  500. showDialog('log-in-dialog');
  501. GO_URL=url;
  502. }
  503. }
  504. // ajax 登录
  505. function ajaxlogin() {
  506. $.get('/user/ajaxlogin/',$('#ajaxlogin').serialize(), function (d) {
  507. if(d.status) {
  508. if (typeof GO_URL != 'undefined') top.location.href = GO_URL; else {
  509. location.reload();
  510. }
  511. }else{
  512. $('#' + d.data).html(d.msg).show();
  513. }
  514. },'json');
  515. }
  516. // 挂单
  517. function opentrades(){
  518. $.post('/ajax/opentrades/coin/'+coin.id,{},function(d){
  519. var ts= d.data;
  520. var html = '';
  521. for(var tk in ts.datas){
  522. html += '<tr>';
  523. html += ts.datas[tk].flag == 'buy'?'<td class="color_red">'+lang('买入')+'</td>':'<td class="color_green">'+lang('卖出')+'</td>';
  524. html += '<td>'+ts.datas[tk].price+'</td><td>'+ts.datas[tk].number+'</td><td>'+(parseInt(ts.datas[tk].number*1000)-parseInt(ts.datas[tk].numberover*1000))/1000+'</td>';
  525. html += '<td class="color_'+(ts.datas[tk].status==1?'green':'red')+'" id="t_s_'+ts.datas[tk].id+'">'+lang(ts.datas[tk].status==1?'部分成交':'未成交')+'</td>';
  526. html += '<td>'+ts.datas[tk].numberover+'</td><td align="center" id="t_opt_'+ts.datas[tk].id+'">';
  527. html += '<input type="button" value="'+lang('撤销')+'" class="btn btn_inverse btn_small" onclick="trustcancel('+ts.datas[tk].id+')">';
  528. html += '</td></tr>';
  529. }
  530. $('#user-trusts').html(html);
  531. opentrades_cb(d);
  532. },'json');
  533. }
  534. function opentrades_cb(d) {
  535. if ('undefined' != typeof(otTimerId)) clearTimeout(otTimerId);
  536. if ('undefined' == typeof(d.data.intervalTime) || parseInt(d.data.intervalTime) < 1) return;
  537. otTimerId = setTimeout("opentrades()", parseInt(d.data.intervalTime) * 1000);
  538. }
  539. function priceTip(type){
  540. bprice = parseFloat($('.price'+type).val());
  541. bp = parseFloat($('#' + type + '_nice').text());
  542. price = (bprice-bp)/bp*100
  543. if(Math.abs(price) > 50 && bprice !=''){
  544. $('.price'+type).prev().fadeIn(1000).delay(3000).fadeOut(400)
  545. }
  546. }
  547. // jquery 选dom
  548. function jdom(selector){
  549. return $(selector);
  550. }
  551. function Vipshow(){
  552. var html = '';
  553. html += '<div class="ui-dialog" id="vipdialog" style="width: 470px;border-radius:0;border:none;">'
  554. html += '<div class="ui-dialog-title" style=" background-color: #aa5800;color:#fff;border-bottom:none;">我的VIP权限 <span style="color:#fff;float:right;cursor: pointer;font-size:24px;" onclick="hideDialog(\'vipdialog\')">&times;</span></div>'
  555. html += ' <div class="ui-dialog-content" style="border-radius:0;">亲爱的VIP用户:'
  556. html += ' <p>您好!</p>'
  557. html += ' <p>感谢您一直以来对BtcTrade的支持!根据您在BtcTrade充值、交易等状况及活跃程度,祝贺您已升级为比特币 交易网VIP用户!</p>'
  558. html += ' <p>您的BtcTrade账号将增加<img height="15" style="vertical-align:text-top;margin:0 3px;" src="/images/trade/vip.gif" alt=""/>标识,同时您将享受到以下所有VIP待遇:</p>'
  559. html += ' <ol>'
  560. html += ' <li>VIP专享杠杆<em>借贷倍数</em></li>'
  561. html += ' <li>VIP用户的充值提现申请将被<em>优先受理</em></li>'
  562. html +='<li>能<em>优先参与</em>BtcTrade各类活动、评测体验及新产品</li>'
  563. html +=' <li>VIP专享由BtcTrade官方提供的节假日、生日<em>纪念礼品</em></li>'
  564. html +='<li>在同等条件下,VIP用户享有与比特币交易网相关合作的优先权。</li>'
  565. html += '</ol>'
  566. html += ' <p style="margin-top:20px;font-size:13px;color:#666;">感谢您一直以来对比特币交易网的支持,我们会用优质与专业的服务回馈您对我们的信任。如有疑问请随时咨询客服,电话:400-990-8880</p>'
  567. html += '</div>'
  568. html += '</div>'
  569. $('body').prepend(html);
  570. showDialog('vipdialog');
  571. }
  572. function checkmobile(mobile) {
  573. var patrn=/^13[0-9]{9}|15[0-9]{9}|18[0-9]{9}|147[0-9]{8}|17[0-9]{9}$/;
  574. if(!patrn.exec(mobile)) return false;
  575. return true;
  576. }
  577. function addemail() {
  578. $.post('/ajax/addmail',{'email':$('#addemail').val()},function(d){
  579. if(d.status){
  580. location.reload();
  581. }else{
  582. alert(d.msg);
  583. }
  584. },'json')
  585. }
  586. function sendmail(type){
  587. $.post('/ajax/mail', {type:type}, function (d) {
  588. if(d.status) alert('邮件发送成功');else alert(d.msg);
  589. }, 'json');
  590. }
  591. (function($) {
  592. $.fn.watch = function(callback) {
  593. return this.each(function() {
  594. //缓存以前的值
  595. $.data(this, 'originVal', $(this).val());
  596. //event
  597. $(this).on('keyup paste', function() {
  598. var originVal = $(this, 'originVal');
  599. var currentVal = $(this).val();
  600. if (originVal !== currentVal) {
  601. $.data(this, 'originVal', $(this).val());
  602. callback(currentVal);
  603. }
  604. });
  605. });
  606. }
  607. })(jQuery);