home.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. String.prototype.replaceAll = function(s1,s2){ return this.replace(new RegExp(s1,"gm"),s2); }
  2. String.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }
  3. var base64EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var base64DecodeChars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);function base64encode(str){var out,i,len;var c1,c2,c3;len=str.length;i=0;out="";while(i<len){c1=str.charCodeAt(i++)&0xff;if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt((c1&0x3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));out+=base64EncodeChars.charAt((c2&0xF)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));out+=base64EncodeChars.charAt(((c2&0xF)<<2)|((c3&0xC0)>>6));out+=base64EncodeChars.charAt(c3&0x3F)}return out}function base64decode(str){var c1,c2,c3,c4;var i,len,out;len=str.length;i=0;out="";while(i<len){do{c1=base64DecodeChars[str.charCodeAt(i++)&0xff]}while(i<len&&c1==-1);if(c1==-1)break;do{c2=base64DecodeChars[str.charCodeAt(i++)&0xff]}while(i<len&&c2==-1);if(c2==-1)break;out+=String.fromCharCode((c1<<2)|((c2&0x30)>>4));do{c3=str.charCodeAt(i++)&0xff;if(c3==61)return out;c3=base64DecodeChars[c3]}while(i<len&&c3==-1);if(c3==-1)break;out+=String.fromCharCode(((c2&0XF)<<4)|((c3&0x3C)>>2));do{c4=str.charCodeAt(i++)&0xff;if(c4==61)return out;c4=base64DecodeChars[c4]}while(i<len&&c4==-1);if(c4==-1)break;out+=String.fromCharCode(((c3&0x03)<<6)|c4)}return out}function utf16to8(str){var out,i,len,c;out="";len=str.length;for(i=0;i<len;i++){c=str.charCodeAt(i);if((c>=0x0001)&&(c<=0x007F)){out+=str.charAt(i)}else if(c>0x07FF){out+=String.fromCharCode(0xE0|((c>>12)&0x0F));out+=String.fromCharCode(0x80|((c>>6)&0x3F));out+=String.fromCharCode(0x80|((c>>0)&0x3F))}else{out+=String.fromCharCode(0xC0|((c>>6)&0x1F));out+=String.fromCharCode(0x80|((c>>0)&0x3F))}}return out}function utf8to16(str){var out,i,len,c;var char2,char3;out="";len=str.length;i=0;while(i<len){c=str.charCodeAt(i++);switch(c>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:out+=str.charAt(i-1);break;case 12:case 13:char2=str.charCodeAt(i++);out+=String.fromCharCode(((c&0x1F)<<6)|(char2&0x3F));break;case 14:char2=str.charCodeAt(i++);char3=str.charCodeAt(i++);out+=String.fromCharCode(((c&0x0F)<<12)|((char2&0x3F)<<6)|((char3&0x3F)<<0));break}}return out}
  4. var MAC={
  5. 'Url': document.URL,
  6. 'Title': document.title,
  7. 'UserAgent' : function(){
  8. var ua = navigator.userAgent;//navigator.appVersion
  9. return {
  10. 'mobile': !!ua.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  11. 'ios': !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  12. 'android': ua.indexOf('Android') > -1 || ua.indexOf('Linux') > -1, //android终端或者uc浏览器
  13. 'iPhone': ua.indexOf('iPhone') > -1 || ua.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
  14. 'iPad': ua.indexOf('iPad') > -1, //是否iPad
  15. 'trident': ua.indexOf('Trident') > -1, //IE内核
  16. 'presto': ua.indexOf('Presto') > -1, //opera内核
  17. 'webKit': ua.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  18. 'gecko': ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') == -1, //火狐内核
  19. 'weixin': ua.indexOf('MicroMessenger') > -1 //是否微信 ua.match(/MicroMessenger/i) == "micromessenger",
  20. };
  21. }(),
  22. 'Copy': function(s){
  23. if (window.clipboardData){ window.clipboardData.setData("Text",s); }
  24. else{
  25. if( $("#mac_flash_copy").get(0) ==undefined ){ $('<div id="mac_flash_copy"></div>'); } else {$('#mac_flash_copy').html(''); }
  26. $('#mac_flash_copy').html('<embed src='+maccms.path+'"images/_clipboard.swf" FlashVars="clipboard='+escape(s)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>');
  27. }
  28. MAC.Pop.Msg(100,20,'复制成功',1000);
  29. },
  30. 'Home': function(o,u){
  31. try{
  32. o.style.behavior='url(#default#homepage)'; o.setHomePage(u);
  33. }
  34. catch(e){
  35. if(window.netscape){
  36. try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
  37. catch(e){ MAC.Pop.Msg(150,40,'此操作被浏览器拒绝!请手动设置',1000); }
  38. var moz = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  39. moz.setCharPref('browser.startup.homepage',u);
  40. }
  41. }
  42. },
  43. 'Fav': function(u,s){
  44. try{ window.external.addFavorite(u, s);}
  45. catch (e){
  46. try{window.sidebar.addPanel(s, u, "");}catch (e){ MAC.Pop.Msg(150,40,'加入收藏出错,请使用键盘Ctrl+D进行添加',1000); }
  47. }
  48. },
  49. 'Open': function(u,w,h){
  50. window.open(u,'macopen1','toolbars=0, scrollbars=0, location=0, statusbars=0,menubars=0,resizable=yes,width='+w+',height='+h+'');
  51. },
  52. 'Cookie': {
  53. 'Set': function(name,value,days){
  54. var exp = new Date();
  55. exp.setTime(exp.getTime() + days*24*60*60*1000);
  56. var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  57. document.cookie=name+"="+encodeURIComponent(value)+";path=/;expires="+exp.toUTCString();
  58. },
  59. 'Get': function(name){
  60. var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  61. if(arr != null){ return decodeURIComponent(arr[2]); return null; }
  62. },
  63. 'Del': function(name){
  64. var exp = new Date();
  65. exp.setTime(exp.getTime()-1);
  66. var cval = this.Get(name);
  67. if(cval != null){ document.cookie = name+"="+encodeURIComponent(cval)+";path=/;expires="+exp.toUTCString(); }
  68. }
  69. },
  70. 'GoBack':function(){
  71. var ldghost=document.domain;
  72. if(document.referrer.indexOf(ldghost)>0) {
  73. history.back();
  74. }
  75. else{
  76. window.location ="//"+ldghost;
  77. }
  78. },
  79. 'Adaptive':function(){
  80. if(maccms.mob_status=='1' && maccms.url != maccms.wapurl){
  81. if(document.domain ==maccms.url && MAC.UserAgent.mobile){
  82. location.href = location.href.replace(maccms.url,maccms.wapurl);
  83. }
  84. else if(document.domain ==maccms.wapurl && !MAC.UserAgent.mobile){
  85. location.href = location.href.replace(maccms.wapurl,maccms.url);
  86. }
  87. }
  88. },
  89. 'CheckBox':{
  90. 'All':function(n){
  91. $("input[name='"+n+"']").each(function() {
  92. this.checked = true;
  93. });
  94. },
  95. 'Other':function(n){
  96. $("input[name='"+n+"']").each(function() {
  97. this.checked = !this.checked;
  98. });
  99. },
  100. 'Count':function(n){
  101. var res=0;
  102. $("input[name='"+n+"']").each(function() {
  103. if(this.checked){ res++; }
  104. });
  105. return res;
  106. },
  107. 'Ids':function(n){
  108. var res=[];
  109. $("input[name='"+n+"']").each(function() {
  110. if(this.checked){ res.push(this.value); }
  111. });
  112. return res.join(",");
  113. }
  114. },
  115. 'Ajax':function(url,type,dataType,data,sfun,efun,cfun){
  116. type=type||'get';
  117. dataType=dataType||'json';
  118. data=data||'';
  119. efun=efun||'';
  120. cfun=cfun||'';
  121. $.ajax({
  122. url:url,
  123. type:type,
  124. dataType:dataType,
  125. data:data,
  126. timeout: 5000,
  127. beforeSend:function(XHR){
  128. },
  129. error:function(XHR,textStatus,errorThrown){
  130. if(efun) efun(XHR,textStatus,errorThrown);
  131. },
  132. success:function(data){
  133. sfun(data);
  134. },
  135. complete:function(XHR, TS){
  136. if(cfun) cfun(XHR, TS);
  137. }
  138. })
  139. },
  140. 'Qrcode':{
  141. 'Init':function(){
  142. $('.mac_qrcode').attr('src', maccms.path +'/index.php/qrcode/index.html?url='+ MAC.Url);
  143. }
  144. },
  145. 'Shorten': {
  146. 'Init':function(){
  147. if($('.mac_shorten').length==0){
  148. return;
  149. }
  150. MAC.Shorten.Get();
  151. },
  152. 'Get':function(url,call){
  153. url=url||location.href;
  154. MAC.Ajax('//api.maccms.la/shorten/index/url/'+ encodeURIComponent(url),'get','jsonp','',function(r){
  155. if (r.code == 1) {
  156. if($('.mac_shorten').length>0) {
  157. $('.mac_shorten').val(r.data.url_short);
  158. $('.mac_shorten').html(r.data.url_short);
  159. }
  160. if(call){
  161. call(r);
  162. }
  163. }
  164. });
  165. }
  166. },
  167. 'Image':{
  168. 'Lazyload':{
  169. 'Show': function(){
  170. try { $("img.lazy").lazyload(); }catch(e){};
  171. },
  172. 'Box': function($id){
  173. $("img.lazy").lazyload({
  174. container: $("#"+$id)
  175. });
  176. }
  177. }
  178. },
  179. 'Verify': {
  180. 'Init': function(){
  181. MAC.Verify.Focus();
  182. MAC.Verify.Click();
  183. },
  184. 'Focus': function(){//验证码框焦点
  185. $('body').on("focus", ".mac_verify", function(){
  186. $(this).removeClass('mac_verify').after(MAC.Verify.Show());
  187. $(this).unbind();
  188. });
  189. },
  190. 'Click': function(){//点击刷新
  191. $('body').on('click', 'img.mac_verify_img', function(){
  192. $(this).attr('src', maccms.path +'/index.php/verify/index.html?r='+Math.random());
  193. });
  194. },
  195. 'Refresh':function(){
  196. $('.mac_verify_img').attr('src', maccms.path +'/index.php/verify/index.html?r='+Math.random());
  197. },
  198. 'Show':function(){
  199. return '<img class="mac_verify_img" src="'+ maccms.path +'/index.php/verify/index.html?" title="看不清楚? 换一张!">';
  200. }
  201. },
  202. 'PageGo':{
  203. 'Init':function() {
  204. $('.mac_page_go').click(function () {
  205. var that =$(this);
  206. var url = that.attr('data-url');
  207. var total = parseInt(that.attr('data-total'));
  208. var sp = that.attr('data-sp');
  209. var page= parseInt($('#page').val());
  210. if(page>0&&(page<=total)){
  211. url=url.replace(sp + 'PAGELINK',sp + page).replace('PAGELINK',page);
  212. location.href=url;
  213. }
  214. return false;
  215. });
  216. }
  217. },
  218. 'Hits': {
  219. 'Init':function() {
  220. if($('.mac_hits').length==0){
  221. return;
  222. }
  223. var $that = $(".mac_hits");
  224. MAC.Ajax(maccms.path + '/index.php/ajax/hits?mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type=update','get','json','',function(r){
  225. if (r.code == 1) {
  226. $(".mac_hits").each(function(i){
  227. $type = $(".mac_hits").eq(i).attr('data-type');
  228. if($type != 'insert'){
  229. $('.'+$type).html(eval('(r.data.' + $type + ')'));
  230. }
  231. });
  232. }
  233. });
  234. }
  235. },
  236. 'Score': {
  237. 'Init':function(){
  238. if($('.mac_score').length==0){
  239. return;
  240. }
  241. $('body').on('click', '.score_btn', function(e){
  242. MAC.Score.Submit();
  243. });
  244. MAC.Ajax(maccms.path+'/index.php/ajax/score?mid='+ $('.mac_score').attr('data-mid') +'&id=' +$('.mac_score').attr('data-id'),'post','json','',function(r){
  245. MAC.Score.View(r);
  246. },function(){
  247. $(".mac_score").html('评分加载失败');
  248. });
  249. },
  250. 'Submit':function(){
  251. var $s = $('.mac_score').find("input[name='score']").val();
  252. MAC.Ajax(maccms.path+'/index.php/ajax/score?mid='+$('.mac_score').attr('data-mid')+'&id='+$('.mac_score').attr('data-id') + '&score='+ $s,'get','json','',function(r){
  253. MAC.Pop.Msg(100,20,r.msg,1000);
  254. if(r.code==1){
  255. MAC.Score.View(r);
  256. }
  257. });
  258. },
  259. 'View':function(r){
  260. $(".rating"+Math.floor(r.data.score)).attr('checked',true);
  261. $(".score_num").text(r.data.score_num);
  262. $(".score_all").text(r.data.score_all);
  263. $(".score_pjf").text(r.data.score);
  264. }
  265. },
  266. 'Star': {
  267. 'Init':function(){
  268. if($('.mac_star').length==0){
  269. return;
  270. }
  271. $('.mac_star').raty({
  272. starType: 'i',
  273. number: 5,
  274. numberMax : 5,
  275. half: true,
  276. score : function(){
  277. return $(this).attr('data-score');
  278. },
  279. click: function(score, evt) {
  280. MAC.Ajax(maccms.path+'/index.php/ajax/score?mid='+$('.mac_star').attr('data-mid')+'&id='+$('.mac_star').attr('data-id')+'&score='+(score*2),'get','json','',function(r){
  281. if(json.status == 1){
  282. $('.star_tips').html(r.data.score);
  283. }else{
  284. $('.star_box').attr('title', r.msg);
  285. }
  286. },function(){
  287. $('.star_box').attr('title', '网络异常!');
  288. });
  289. }
  290. });
  291. }
  292. },
  293. 'Digg': {
  294. 'Init':function(){
  295. $('body').on('click', '.digg_link', function(e){
  296. var $that = $(this);
  297. if($that.attr("data-id")){
  298. MAC.Ajax(maccms.path + '/index.php/ajax/digg.html?mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type='+$that.attr("data-type"),'get','json','',function(r){
  299. $that.addClass('disabled');
  300. if(r.code == 1){
  301. if($that.attr("data-type")=='up'){
  302. $that.find('.digg_num').html(r.data.up);
  303. }
  304. else{
  305. $that.find('.digg_num').html(r.data.down);
  306. }
  307. }
  308. else{
  309. $that.attr('title', r.msg);
  310. }
  311. });
  312. }
  313. });
  314. }
  315. },
  316. 'Gbook':{
  317. 'Login':0,
  318. 'Verify':0,
  319. 'Init':function(){
  320. $('body').on('keyup', '.gbook_content', function(e){
  321. MAC.Remaining($(this),200,'.gbook_remaining')
  322. });
  323. $('body').on('focus', '.gbook_content', function(e){
  324. if(MAC.Gbook.Login==1 && MAC.User.IsLogin!=1){
  325. MAC.User.Login();
  326. }
  327. });
  328. $('body').on('click', '.gbook_submit', function(e){
  329. MAC.Gbook.Submit();
  330. });
  331. },
  332. 'Show':function($page){
  333. MAC.Ajax(maccms.path+'/index.php/gbook/index?page='+$page,'post','json','',function(r){
  334. $(".mac_gbook_box").html(r);
  335. },function(){
  336. $(".mac_gbook_box").html('留言加载失败,请刷新...');
  337. });
  338. },
  339. 'Submit':function(){
  340. if($(".gbook_content").val() == ''){
  341. MAC.Pop.Msg(100,20,'请输入您的留言!',1000);
  342. return false;
  343. }
  344. MAC.Ajax(maccms.path + '/index.php/gbook/saveData','post','json',$('.gbook_form').serialize(),function(r){
  345. MAC.Pop.Msg(100,20,r.msg,1000);
  346. if(r.code == 1){
  347. location.reload();
  348. }
  349. else{
  350. if(MAC.Gbook.Verify==1){
  351. MAC.Verify.Refresh();
  352. }
  353. }
  354. });
  355. },
  356. 'Report':function(name,id){
  357. MAC.Pop.Show(400,300,'数据报错',maccms.path+'/index.php/gbook/report.html?id='+id+'&name='+ encodeURIComponent(name),function(r){
  358. });
  359. }
  360. },
  361. 'Search':{
  362. 'Init':function(){
  363. $('.mac_search').click(function(){
  364. var that=$(this);
  365. var url = that.attr('data-href') ? that.attr('data-href') : maccms.path + '/index.php/vod/search.html';
  366. location.href = url + '?wd='+ encodeURIComponent($("#wd").val());
  367. });
  368. },
  369. 'Submit':function(){
  370. return false;
  371. }
  372. },
  373. 'Suggest':{
  374. 'Init':function($obj,$mid,$jumpurl){
  375. try {
  376. $($obj).autocomplete(maccms.path + '/index.php/ajax/suggest?mid=' + $mid, {
  377. inputClass: "mac_input",
  378. resultsClass: "mac_results",
  379. loadingClass: "mac_loading",
  380. width: 175, scrollHeight: 300, minChars: 1, matchSubset: 0,
  381. cacheLength: 10, multiple: false, matchContains: true, autoFill: false,
  382. dataType: "json",
  383. parse: function (r) {
  384. if (r.code == 1) {
  385. var parsed = [];
  386. $.each(r['list'], function (index, row) {
  387. row.url = r.url;
  388. parsed[index] = {
  389. data: row
  390. };
  391. });
  392. return parsed;
  393. } else {
  394. return {data: ''};
  395. }
  396. },
  397. formatItem: function (row, i, max) {
  398. return row.name;
  399. },
  400. formatResult: function (row, i, max) {
  401. return row.text;
  402. }
  403. }).result(function (event, data, formatted) {
  404. $($obj).val(data.name);
  405. location.href = data.url.replace('mac_wd', encodeURIComponent(data.name));
  406. });
  407. }
  408. catch(e){}
  409. }
  410. },
  411. 'History': {
  412. 'BoxShow':0,
  413. 'Limit':10,
  414. 'Days':7,
  415. 'Json':'',
  416. 'Init':function(){
  417. if($('.mac_history').length ==0){
  418. return;
  419. }
  420. $('.mac_history').hover(function(e){
  421. $('.mac_history_box').show();
  422. }, function(){
  423. $('.mac_history_box').hover(function(){
  424. MAC.History.BoxShow=1;
  425. }, function(){
  426. MAC.History.BoxShow=0;
  427. $('.mac_history_box').hide();
  428. });
  429. });
  430. var jsondata = [];
  431. if(this.Json){
  432. jsondata = this.Json;
  433. }else{
  434. var jsonstr = MAC.Cookie.Get('mac_history');
  435. if(jsonstr != undefined){
  436. jsondata = eval(jsonstr);
  437. }
  438. }
  439. html = '<dl class="mac_drop_box mac_history_box" style="display:none;">';
  440. html +='<dt><a target="_self" href="javascript:void(0)" onclick="MAC.History.Clear();">清空</a></dt>';
  441. if(jsondata.length > 0){
  442. for($i=0; $i<jsondata.length; $i++){
  443. if($i%2==1){
  444. html +='<dd class="odd">';
  445. }else{
  446. html +='<dd class="even">';
  447. }
  448. html +='<a href="'+jsondata[$i].link+'" class="hx_title">'+jsondata[$i].name+'</a></dd>';
  449. }
  450. }else{
  451. html +='<dd class="hide">暂无浏览记录</dd>';
  452. }
  453. html += '</dl>';
  454. $('.mac_history').after(html);
  455. var h = $('.mac_history').height();
  456. var position = $('.mac_history').position();
  457. $('.mac_history_box').css({'left':position.left,'top':(position.top+h)});
  458. if($(".mac_history_set").attr('data-name')){
  459. var $that = $(".mac_history_set");
  460. MAC.History.Set($that.attr('data-name'),$that.attr('data-link'),$that.attr('data-pic'));
  461. }
  462. },
  463. 'Set':function(name,link,pic){
  464. if(!link){ link = document.URL; }
  465. var jsondata = MAC.Cookie.Get('mac_history');
  466. if(jsondata != undefined){
  467. this.Json = eval(jsondata);
  468. for($i=0;$i<this.Json.length;$i++){
  469. if(this.Json[$i].link == link){
  470. return false;
  471. }
  472. }
  473. jsonstr = '{log:[{"name":"'+name+'","link":"'+link+'","pic":"'+pic+'"},';
  474. for($i=0; $i<this.Json.length; $i++){
  475. if($i<= this.Limit && this.Json[$i]){
  476. jsonstr += '{"name":"'+this.Json[$i].name+'","link":"'+this.Json[$i].link+'","pic":"'+this.Json[$i].pic+'"},';
  477. }else{
  478. break;
  479. }
  480. }
  481. jsonstr = jsonstr.substring(0,jsonstr.lastIndexOf(','));
  482. jsonstr += "]}";
  483. }else{
  484. jsonstr = '{log:[{"name":"'+name+'","link":"'+link+'","pic":"'+pic+'"}]}';
  485. }
  486. this.Json = eval(jsonstr);
  487. MAC.Cookie.Set('mac_history',jsonstr,this.Days);
  488. },
  489. 'Clear': function(){
  490. MAC.Cookie.Del('mac_history');
  491. $('.mac_history_box').html('<li class="hx_clear">已清空观看记录。</li>');
  492. },
  493. },
  494. 'Ulog':{
  495. 'Init':function(){
  496. MAC.Ulog.Set();
  497. MAC.Ulog.Click();
  498. },
  499. 'Get':function(mid,id,type,page,limit,call){
  500. MAC.Ajax(maccms.path+'/index.php/user/ajax_ulog/?ac=list&mid='+mid+'&id='+id+'&type='+type+'&page='+page+'&limit='+limit,'get','json','',call);
  501. },
  502. 'Set':function(){
  503. if($(".mac_ulog_set").attr('data-mid')){
  504. var $that = $(".mac_ulog_set");
  505. $.get(maccms.path+'/index.php/user/ajax_ulog/?ac=set&mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&sid='+$that.attr("data-sid")+'&nid='+$that.attr("data-nid")+'&type='+$that.attr("data-type"));
  506. }
  507. },
  508. 'Click':function(){
  509. $('body').on('click', 'a.mac_ulog', function(e){
  510. //是否需要验证登录
  511. if(MAC.User.IsLogin == 0){
  512. MAC.User.Login();
  513. return;
  514. }
  515. var $that = $(this);
  516. if($that.attr("data-id")){
  517. MAC.Ajax(maccms.path+'/index.php/user/ajax_ulog/?ac=set&mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type='+$that.attr("data-type"),'get','json','',function(r){
  518. MAC.Pop.Msg(100,20,r.msg,1000);
  519. if(r.code == 1){
  520. $that.addClass('disabled');
  521. }else{
  522. $that.attr('title', r.msg);
  523. }
  524. });
  525. }
  526. });
  527. }
  528. },
  529. 'Website':{
  530. 'Referer':function() {
  531. if($('.mac_referer').length==0){
  532. return;
  533. }
  534. var url = document.referrer
  535. ,domain=''
  536. ,host = window.location.host
  537. ,reg = /^http(s)?:\/\/(.*?)\//i
  538. ,mc = url.match(reg);
  539. if(url=='' || url.indexOf(host)!=-1 || mc ==null){
  540. return;
  541. }
  542. domain = mc[2];
  543. MAC.Ajax(maccms.path + '/index.php/ajax/referer?domain='+encodeURIComponent(domain)+'&url='+encodeURIComponent(url)+'&type=update','get','json','',function(r){
  544. if (r.code == 1) {
  545. }
  546. console.log(r);
  547. });
  548. }
  549. },
  550. 'User':{
  551. 'BoxShow':0,
  552. 'IsLogin':0,
  553. 'UserId':'',
  554. 'UserName':'',
  555. 'GroupId':'',
  556. 'GroupName':'',
  557. 'Portrait':'',
  558. 'Init':function(){
  559. if($('.mac_user').length >0){
  560. $('body').on('click', '.mac_user', function(e){
  561. MAC.User.Login();
  562. });
  563. $('.mac_user').hover(function(e){
  564. $('.mac_user_box').show();
  565. }, function(){
  566. $('.mac_user_box').hover(function(){
  567. MAC.User.BoxShow = 1;
  568. }, function(){
  569. MAC.User.BoxShow = 0;
  570. $('.mac_user_box').hide();
  571. });
  572. });
  573. }
  574. if(MAC.Cookie.Get('user_id') !=undefined && MAC.Cookie.Get('user_id')!=''){
  575. var url = maccms.path + '/index.php/user';
  576. MAC.User.UserId = MAC.Cookie.Get('user_id');
  577. MAC.User.UserName = MAC.Cookie.Get('user_name');
  578. MAC.User.GroupId = MAC.Cookie.Get('group_id');
  579. MAC.User.GroupName = MAC.Cookie.Get('group_name');
  580. MAC.User.Portrait = MAC.Cookie.Get('user_portrait');
  581. MAC.User.IsLogin = 1;
  582. if($('.mac_user').length >0) {
  583. if ($('.mac_user').prop("outerHTML").substr(0, 2) == '<a') {
  584. $('.mac_user').attr('href', url);
  585. $('.mac_user').text(MAC.User.UserName);
  586. }
  587. else {
  588. //$('.mac_user').html('<a class="mac_text" href="'+ url +'">'+ name +'</a>');
  589. }
  590. var html = '<div class="mac_drop_box mac_user_box" style="display: none;">';
  591. html += '<ul class="logged"><li><a target="_blank" href="' + url + '">用户中心</a></li><li class="logout"><a class="logoutbt" href="javascript:;" onclick="MAC.User.Logout();" target="_self"><i class="user-logout"></i>退出</a></li></ul>'
  592. $('.mac_user').after(html);
  593. var h = $('.mac_user').height();
  594. var position = $('.mac_user').position();
  595. $('.mac_user_box').css({'left': position.left, 'top': (position.top + h)});
  596. }
  597. }
  598. else{
  599. }
  600. },
  601. 'CheckLogin':function(){
  602. if(MAC.User.IsLogin == 0){
  603. MAC.User.Login();
  604. }
  605. },
  606. 'Login':function(){
  607. var ac='ajax_login';
  608. if(MAC.Cookie.Get('user_id') !=undefined && MAC.Cookie.Get('user_id')!=''){
  609. ac= 'ajax_info';
  610. }
  611. MAC.Pop.Show(400,380,'用户登录',maccms.path+'/index.php/user/'+ac,function(r){
  612. $('body').off('click', '.login_form_submit');
  613. $('body').on('click', '.login_form_submit', function(e){
  614. $(this).unbind('click');
  615. MAC.Ajax(maccms.path + '/index.php/user/login','post','json',$('.mac_login_form').serialize(),function(r){
  616. alert(r.msg);
  617. if(r.code == 1){
  618. location.reload();
  619. }
  620. });
  621. });
  622. });
  623. },
  624. 'Logout':function(){
  625. MAC.Ajax(maccms.path + '/index.php/user/logout','post','json','',function(r){
  626. MAC.Pop.Msg(100,20,r.msg,1000);
  627. if(r.code == 1){
  628. location.reload();
  629. }
  630. });
  631. },
  632. 'PopedomCallBack':function(trysee,h) {
  633. window.setTimeout(function(){
  634. $(window.frames["player_if"].document).find(".MacPlayer").html(h);
  635. },1000*10*trysee);
  636. },
  637. 'BuyPopedom':function(o){
  638. var $that = $(o);
  639. if($that.attr("data-id")){
  640. if (confirm('您确认购买此条数据访问权限吗?')) {
  641. MAC.Ajax(maccms.path + '/index.php/user/ajax_buy_popedom.html?id=' + $that.attr("data-id") + '&mid=' + $that.attr("data-mid") + '&sid=' + $that.attr("data-sid") + '&nid=' + $that.attr("data-nid") + '&type=' + $that.attr("data-type"),'get','json','',function(r){
  642. $that.addClass('disabled');
  643. MAC.Pop.Msg(300, 50, r.msg, 2000);
  644. if (r.code == 1) {
  645. top.location.reload();
  646. }
  647. $that.removeClass('disabled');
  648. });
  649. }
  650. }
  651. }
  652. },
  653. 'Pop':{
  654. 'Remove':function(){
  655. $('.mac_pop_bg').remove();
  656. $('.mac_pop').remove();
  657. },
  658. 'RemoveMsg':function(){
  659. $('.mac_pop_msg_bg').remove();
  660. $('.mac_pop_msg').remove();
  661. },
  662. 'Msg':function($w,$h,$msg,$timeout){
  663. if($('.mac_pop_bg').length !=1) {
  664. MAC.Pop.Remove();
  665. }
  666. $('body').append('<div class="mac_pop_msg_bg"></div><div class="mac_pop_msg"><div class="pop-msg"></div></div>');
  667. $('.mac_pop_msg .pop_close').click(function(){
  668. $('.mac_pop_msg').remove();
  669. });
  670. $('.mac_pop_msg').width($w);
  671. $('.mac_pop_msg').height($h);
  672. $('.mac_pop_msg .pop-msg').html($msg);
  673. $('.mac_pop_msg_bg,.mac_pop_msg').show();
  674. setTimeout(MAC.Pop.RemoveMsg,$timeout);
  675. },
  676. 'Show':function($w,$h,$title,$url,$callback) {
  677. if($('.mac_pop_bg').length !=1) {
  678. MAC.Pop.Remove();
  679. }
  680. $('body').append('<div class="mac_pop_bg"></div><div class="mac_pop"><div class="pop_top"><h2></h2><span class="pop_close">X</span></div><div class="pop_content"></div></div>');
  681. $('.mac_pop .pop_close').click(function(){
  682. $('.mac_pop_bg,.mac_pop').remove();
  683. });
  684. $('.mac_pop').width($w);
  685. $('.mac_pop').height($h);
  686. $('.pop_content').html('');
  687. $('.pop_top').find('h2').html($title);
  688. MAC.Ajax($url,'post','json','',function(r){
  689. $(".pop_content").html(r);
  690. $callback(r);
  691. },function(){
  692. $(".pop_content").html('加载失败,请刷新...');
  693. });
  694. $('.mac_pop_bg,.mac_pop').show();
  695. }
  696. },
  697. 'Pwd':{
  698. 'Check':function(o){
  699. var $that = $(o);
  700. if($that.attr("data-id")){
  701. MAC.Ajax(maccms.path + '/index.php/ajax/pwd.html?id=' + $that.attr("data-id") + '&mid=' + $that.attr("data-mid") + '&type=' + $that.attr("data-type") + '&pwd='+ $that.parents('form').find('input[name="pwd"]').val() ,'get','json','',function(r){
  702. $that.addClass('disabled');
  703. MAC.Pop.Msg(300, 50, r.msg, 2000);
  704. if (r.code == 1) {
  705. location.reload();
  706. }
  707. $that.removeClass('disabled');
  708. });
  709. }
  710. }
  711. },
  712. 'AdsWrap':function(w,h,n){
  713. document.writeln('<img width="'+w+'" height="'+h+'" alt="'+n+'" style="background-color: #CCCCCC" />');
  714. },
  715. 'Css':function($url){
  716. $("<link>").attr({ rel: "stylesheet",type: "text/css",href: $url}).appendTo("head");
  717. },
  718. 'Js':function($url){
  719. $.getScript($url, function(response, status) {
  720. });
  721. },
  722. 'Desktop':function(s){
  723. location.href= maccms.path + '/index.php/ajax/desktop?name='+encodeURI(s)+'&url=' + encodeURI(location.href);
  724. },
  725. 'Timming':function(){
  726. if($('.mac_timming').length==0){
  727. return;
  728. }
  729. var infile = $('.mac_timming').attr("data-file");
  730. if(infile==undefined || infile == ''){
  731. infile = 'api.php';
  732. }
  733. var t=(new Image());t.src=maccms.path + '/'+infile+'/timming/index?t='+Math.random();
  734. },
  735. 'Error':function(tab,id,name){
  736. },
  737. 'AddEm':function(obj,i){
  738. var oldtext = $(obj).val();
  739. $(obj).val( oldtext + '[em:' + i +']' );
  740. },
  741. 'Remaining':function(obj,len,show){
  742. var count = len - $(obj).val().length;
  743. if(count < 0){
  744. count = 0;
  745. $(obj).val($(obj).val().substr(0,200));
  746. }
  747. $(show).text(count);
  748. },
  749. 'Comment':{
  750. 'Login':0,
  751. 'Verify':0,
  752. 'Init':function(){
  753. $('body').on('click', '.comment_face_box img', function(e){
  754. var obj = $(this).parent().parent().parent().find('.comment_content');
  755. MAC.AddEm(obj,$(this).attr('data-id'));
  756. });
  757. $('body').on('click', '.comment_face_panel', function(e){
  758. // $('.comment_face_box').toggle();
  759. $(this).parent().find('.comment_face_box').toggle();
  760. });
  761. $('body').on('keyup', '.comment_content', function(e){
  762. var obj = $(this).parent().parent().parent().parent().find('.comment_remaining');
  763. MAC.Remaining($(this),200,obj)
  764. });
  765. $('body').on('focus', '.comment_content', function(e){
  766. if(MAC.Comment.Login==1 && MAC.User.IsLogin!=1){
  767. MAC.User.Login();
  768. }
  769. });
  770. $('body').on('click', '.comment_report', function(e){
  771. var $that = $(this);
  772. if($(this).attr("data-id")){
  773. MAC.Ajax(maccms.path + '/index.php/comment/report.html?id='+$that.attr("data-id"),'get','json','',function(r){
  774. $that.addClass('disabled');
  775. MAC.Pop.Msg(100,20,r.msg,1000);
  776. if(r.code == 1){
  777. }
  778. });
  779. }
  780. });
  781. $('body').on('click', '.comment_reply', function(e){
  782. var $that = $(this);
  783. if($that.attr("data-id")){
  784. var str = $that.html();
  785. $('.comment_reply_form').remove();
  786. if (str == '取消回复') {
  787. $that.html('回复');
  788. return false;
  789. }
  790. if (str == '回复') {
  791. $('.comment_reply').html('回复');
  792. }
  793. var html = $('.comment_form').prop("outerHTML");
  794. var oo = $(html);
  795. oo.addClass('comment_reply_form');
  796. oo.find('input[name="comment_pid"]').val( $that.attr("data-id") );
  797. $that.parent().after(oo);
  798. $that.html('取消回复');
  799. }
  800. });
  801. $('body').on('click', '.comment_submit', function(e){
  802. var $that = $(this);
  803. MAC.Comment.Submit($that);
  804. });
  805. },
  806. 'Show':function($page){
  807. if($(".mac_comment").length>0){
  808. MAC.Ajax(maccms.path + '/index.php/comment/ajax.html?rid='+$('.mac_comment').attr('data-id')+'&mid='+ $('.mac_comment').attr('data-mid') +'&page='+$page,'get','json','',function(r){
  809. $(".mac_comment").html(r);
  810. },function(){
  811. $(".mac_comment").html('<a href="javascript:void(0)" onclick="MAC.Comment.Show('+$page+')">评论加载失败,点击我刷新...</a>');
  812. });
  813. }
  814. },
  815. 'Reply':function($o){
  816. },
  817. 'Submit':function($o){
  818. var form = $o.parents('form');
  819. if($(form).find(".comment_content").val() == ''){
  820. MAC.Pop.Msg(100,20,'请输入您的评论!',1000);
  821. return false;
  822. }
  823. if($('.mac_comment').attr('data-mid') == ''){
  824. MAC.Pop.Msg(100,20,'模块mid错误!',1000);
  825. return false;
  826. }
  827. if($('.mac_comment').attr('data-id') == ''){
  828. MAC.Pop.Msg(100,20,'关联id错误!',1000);
  829. return false;
  830. }
  831. MAC.Ajax(maccms.path + '/index.php/comment/saveData','post','json',$(form).serialize() + '&comment_mid='+ $('.mac_comment').attr('data-mid') + '&comment_rid=' + $('.mac_comment').attr('data-id'),function(r){
  832. MAC.Pop.Msg(100,20,r.msg,1000);
  833. if(r.code == 1){
  834. MAC.Comment.Show(1);
  835. }
  836. else{
  837. if(MAC.Comment.Verify==1){
  838. MAC.Verify.Refresh();
  839. }
  840. }
  841. });
  842. }
  843. }
  844. }
  845. $(function(){
  846. //异步加载图片初始化
  847. MAC.Image.Lazyload.Show();
  848. //自动跳转手机和pc网页地址
  849. MAC.Adaptive();
  850. //验证码初始化
  851. MAC.Verify.Init();
  852. //分页跳转初始化
  853. MAC.PageGo.Init();
  854. //用户部分初始化
  855. MAC.User.Init();
  856. //二维码初始化
  857. MAC.Qrcode.Init();
  858. //顶和踩初始化
  859. MAC.Digg.Init();
  860. //评分初始化
  861. MAC.Score.Init();
  862. //星星评分初始化
  863. MAC.Star.Init();
  864. //点击数量
  865. MAC.Hits.Init();
  866. //短网址
  867. MAC.Shorten.Init();
  868. //历史记录初始化
  869. MAC.History.Init();
  870. //用户访问记录初始化
  871. MAC.Ulog.Init();
  872. //联想搜索初始化
  873. MAC.Suggest.Init('.mac_wd',1,'');
  874. //网址导航来路统计
  875. MAC.Website.Referer();
  876. //定时任务初始化
  877. MAC.Timming();
  878. });