string.prototype.replaceall = function(s1,s2){ return this.replace(new regexp(s1,"gm"),s2); } string.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); } 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>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>4));do{c3=str.charcodeat(i++)&0xff;if(c3==61)return out;c3=base64decodechars[c3]}while(i>2));do{c4=str.charcodeat(i++)&0xff;if(c4==61)return out;c4=base64decodechars[c4]}while(i=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>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} var mac={ 'url': document.url, 'title': document.title, 'useragent' : function(){ var ua = navigator.useragent;//navigator.appversion return { 'mobile': !!ua.match(/applewebkit.*mobile.*/), //是否为移动终端 'ios': !!ua.match(/\(i[^;]+;( u;)? cpu.+mac os x/), //ios终端 'android': ua.indexof('android') > -1 || ua.indexof('linux') > -1, //android终端或者uc浏览器 'iphone': ua.indexof('iphone') > -1 || ua.indexof('mac') > -1, //是否为iphone或者qqhd浏览器 'ipad': ua.indexof('ipad') > -1, //是否ipad 'trident': ua.indexof('trident') > -1, //ie内核 'presto': ua.indexof('presto') > -1, //opera内核 'webkit': ua.indexof('applewebkit') > -1, //苹果、谷歌内核 'gecko': ua.indexof('gecko') > -1 && ua.indexof('khtml') == -1, //火狐内核 'weixin': ua.indexof('micromessenger') > -1 //是否微信 ua.match(/micromessenger/i) == "micromessenger", }; }(), 'copy': function(s){ if (window.clipboarddata){ window.clipboarddata.setdata("text",s); } else{ if( $("#mac_flash_copy").get(0) ==undefined ){ $('
'); } else {$('#mac_flash_copy').html(''); } $('#mac_flash_copy').html(''); } alert("复制成功") }, 'home': function(o,u){ try{ o.style.behavior='url(#default#homepage)'; o.sethomepage(u); } catch(e){ if(window.netscape){ try{netscape.security.privilegemanager.enableprivilege("universalxpconnect");} catch(e){ alert("此操作被浏览器拒绝!请手动设置");} var moz = components.classes['@mozilla.org/preferences-service;1'].getservice(components.interfaces.nsiprefbranch); moz.setcharpref('browser.startup.homepage',u); } } }, 'fav': function(u,s){ try{ window.external.addfavorite(u, s);} catch (e){ try{window.sidebar.addpanel(s, u, "");}catch (e){ alert("加入收藏出错,请使用键盘ctrl+d进行添加"); } } }, 'open': function(u,w,h){ window.open(u,'macopen1','toolbars=0, scrollbars=0, location=0, statusbars=0,menubars=0,resizable=yes,width='+w+',height='+h+''); }, 'cookie': { 'set': function(name,value,days){ var exp = new date(); exp.settime(exp.gettime() + days*24*60*60*1000); var arr=document.cookie.match(new regexp("(^| )"+name+"=([^;]*)(;|$)")); document.cookie=name+"="+encodeuricomponent(value)+";path=/;expires="+exp.toutcstring(); }, 'get': function(name){ var arr = document.cookie.match(new regexp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null){ return decodeuricomponent(arr[2]); return null; } }, 'del': function(name){ var exp = new date(); exp.settime(exp.gettime()-1); var cval = this.get(name); if(cval != null){ document.cookie = name+"="+encodeuricomponent(cval)+";path=/;expires="+exp.toutcstring(); } } }, 'goback':function(){ var ldghost=document.domain; if(document.referrer.indexof(ldghost)>0) { history.back(); } else{ window.location ="http://"+ldghost; } }, 'adaptive':function(){ if(maccms.mob_status=='1'&& maccms.url != maccms.wapurl){ if(document.domain ==maccms.url && mac.useragent.mobile){ location.href = location.href.replace(maccms.url,maccms.wapurl); } else if(document.domain ==maccms.wapurl && !mac.useragent.mobile){ location.href = location.href.replace(maccms.wapurl,maccms.url); } } }, 'checkbox':{ 'all':function(n){ $("input[name='"+n+"']").each(function() { this.checked = true; }); }, 'other':function(n){ $("input[name='"+n+"']").each(function() { this.checked = !this.checked; }); }, 'count':function(n){ var res=0; $("input[name='"+n+"']").each(function() { if(this.checked){ res++; } }); return res; }, 'ids':function(n){ var res=[]; $("input[name='"+n+"']").each(function() { if(this.checked){ res.push(this.value); } }); return res.join(","); } }, 'qrcode':function(){ $('.mac_qrcode').attr('src','//api.maccms.com/qrcode/?w=150&h=150&url=' + mac.url); }, 'image':{ 'lazyload':{ 'show': function(){ try { $("img.lazy").lazyload(); }catch(e){}; }, 'box': function($id){ $("img.lazy").lazyload({ container: $("#"+$id) }); } } }, 'verify': { 'init': function(){ mac.verify.focus(); mac.verify.click(); }, 'focus': function(){//验证码框焦点 $('body').on("focus", ".mac_verify", function(){ $(this).removeclass('mac_verify').after(mac.verify.show()); $(this).unbind(); }); }, 'click': function(){//点击刷新 $('body').on('click', 'img.mac_verify_img', function(){ $(this).attr('src', maccms.path +'/index.php/verify/index.html?'); }); }, 'refresh':function(){ $('.mac_verify_img').attr('src', maccms.path +'/index.php/verify/index.html?'); }, 'show':function(){ return ''; } }, 'pagego':{ 'init':function() { $('.mac_page_go').click(function () { var that =$(this); var url = that.attr('data-url'); var total = that.attr('data-total'); var sp = that.attr('data-sp'); var page= $('#page').val(); if(page>0&&(page<=total)){ url=url.replace(sp + 'pagelink',page).replace('pagelink',page); location.href=url; } return false; }); } }, 'hits': { 'init':function() { if($('.mac_hits').length==0){ return; } var $that = $(".mac_hits"); $.ajax({ type: 'get', url: maccms.path + '/index.php/ajax/hits?mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type=update', timeout: 5000, datatype: 'json', error: function () { }, success: function (json) { if (json.code == 1) { $(".mac_hits").each(function(i){ $type = $(".mac_hits").eq(i).attr('data-type'); if($type != 'insert'){ $('.'+$type).html(eval('(json.data.' + $type + ')')); } }); } } }); } }, 'score': { 'init':function(){ if($('.mac_score').length==0){ return; } $('body').on('click', '.score_btn', function(e){ mac.score.submit(); }); $.ajax({ type: 'post', url: maccms.path+'/index.php/ajax/score?mid='+ $('.mac_score').attr('data-mid') +'&id=' +$('.mac_score').attr('data-id'), timeout: 5000, error: function(){ $(".mac_score").html('评分加载失败'); }, success: function($r){ mac.score.view($r); } }); }, 'submit':function(){ var $s = $('.mac_score').find("input[name='score']").val(); $.ajax({ type: 'post', url: maccms.path+'/index.php/ajax/score?mid='+$('.mac_score').attr('data-mid')+'&id='+$('.mac_score').attr('data-id') + '&score='+ $s, timeout: 5000, error: function(){ }, success: function($r){ alert($r.msg) if($r.code==1){ mac.score.view($r); } } }); }, 'view':function($r){ $(".rating"+math.floor($r.data.score)).attr('checked',true); $(".score_num").text( $r.data.score_num ); $(".score_all").text( $r.data.score_all ); $(".score_pjf").text( $r.data.score ); } }, 'star': { 'init':function(){ if($('.mac_star').length==0){ return; } $('.mac_star').raty({ startype: 'i', number: 5, numbermax : 5, half: true, score : function(){ return $(this).attr('data-score'); }, click: function(score, evt) { $.ajax({ type: 'get', url: maccms.path+'/index.php/ajax/score?mid='+$('.mac_star').attr('data-mid')+'&id='+$('.mac_star').attr('data-id')+'&score='+(score*2), timeout: 5000, datatype:'json', error: function(){ $('.star_box').attr('title', '网络异常!'); }, success: function(json){ if(json.status == 1){ $('.star_tips').html(json.data.score); }else{ $('.star_box').attr('title', json.msg); } } }); } }); } }, 'digg': { 'init':function(){ $('body').on('click', '.digg_link', function(e){ var $that = $(this); if($that.attr("data-id")){ $.ajax({ url: maccms.path + '/index.php/ajax/digg.html?mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type='+$that.attr("data-type"), cache: false, datatype: 'json', success: function($r){ $that.addclass('disabled'); if($r.code == 1){ if($that.attr("data-type")=='up'){ $that.find('.digg_num').html($r.data.up); } else{ $that.find('.digg_num').html($r.data.down); } } else{ $that.attr('title', $r.msg); } } }); } }); } }, 'gbook':{ 'login':0, 'verify':0, 'init':function(){ $('body').on('keyup', '.gbook_content', function(e){ mac.remaining($(this),200,'.gbook_remaining') }); $('body').on('focus', '.gbook_content', function(e){ if(mac.gbook.login==1 && mac.user.islogin!=1){ mac.user.login(); } }); $('body').on('click', '.gbook_submit', function(e){ mac.gbook.submit(); }); }, 'show':function($page){ $.ajax({ type: 'post', url: maccms.path+'/index.php/gbook/index?page='+$page, timeout: 3000, error: function(){ $(".mac_gbook_box").html('留言加载失败,请刷新...'); }, success:function($html){ $(".mac_gbook_box").html($html); } }); }, 'submit':function(){ if($(".gbook_content").val() == ''){ alert("请输入留言内容"); return false; } $.ajax({ type: 'post', url: maccms.path + '/index.php/gbook/savedata', data: $('.gbook_form').serialize(), success:function($r){ alert($r.msg); if($r.code == 1){ location.reload(); } else{ if(mac.gbook.verify==1){ mac.verify.refresh(); } } } }); }, 'report':function(name){ mac.pop.show('#modal-seport',maccms.path+'/index.php/gbook/report?name=' + encodeuricomponent(name),function($r){ $('body').on('click', '#gbook_submit', function(e){ mac.gbook.submit(); }); }); } }, 'search':{ 'init':function(){ $('.mac_search').click(function(){ var that=$(this); var url = that.attr('data-href') ? that.attr('data-href') : maccms.path + '/index.php/vod/search.html'; location.href = url + '?wd='+ encodeuricomponent($("#wd").val()); }); }, 'submit':function(){ return false; } }, 'suggest':{ 'init':function($obj,$mid,$jumpurl){ try { $($obj).autocomplete(maccms.path + '/index.php/ajax/suggest?mid=' + $mid, { inputclass: "mac_input", resultsclass: "mac_results", loadingclass: "mac_loading", width: 175, scrollheight: 300, minchars: 1, matchsubset: 1, cachelength: 10, multiple: false, matchcontains: true, autofill: false, datatype: "json", parse: function ($r) { if ($r.code == 1) { var parsed = []; $.each($r['list'], function (index, row) { row.url = $r.url; parsed[index] = { data: row }; }); return parsed; } else { return {data: ''}; } }, formatitem: function (row, i, max) { return row.name; }, formatresult: function (row, i, max) { return row.text; } }).result(function (event, data, formatted) { $($obj).val(data.name); location.href = data.url.replace('mac_wd', encodeuricomponent(data.name)); }); } catch(e){} } }, 'ulog':{ 'init':function(){ mac.ulog.set(); mac.ulog.click(); }, 'get':function(){ $.ajax({ url: maccms.path+'/index.php/user/ajax_ulog/?ac=list', type:'get', cache: false, datatype: 'json', success: function($r){ if($r.code == 1){ $.each($r['list'],function(index,row){ alert(row.ulog_id); }); }else{ } } }); }, 'set':function(){ if($(".mac_ulog_set").attr('data-mid')){ var $that = $(".mac_ulog_set"); $.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")); } }, 'click':function(){ $('body').on('click', 'a.mac_ulog', function(e){ //是否需要验证登录 if(mac.user.islogin == 0){ mac.user.login(); return; } var $that = $(this); if($that.attr("data-id")){ $.ajax({ url: maccms.path+'/index.php/user/ajax_ulog/?ac=set&mid='+$that.attr("data-mid")+'&id='+$that.attr("data-id")+'&type='+$that.attr("data-type"), cache: false, datatype: 'json', success: function($r){ alert($r.msg); if($r.code == 1){ $that.addclass('disabled'); }else{ $that.attr('title', $r.msg); } } }); } }); } }, 'user':{ 'boxshow':0, 'islogin':0, 'userid':'', 'username':'', 'groupid':'', 'groupname':'', 'portrait':'', 'init':function(){ if($('.mac_user').length >0){ $('body').on('click', '.mac_user', function(e){ mac.user.login(); }); } if(mac.cookie.get('user_id') !=undefined && mac.cookie.get('user_id')!=''){ var url = maccms.path + '/index.php/user'; mac.user.userid = mac.cookie.get('user_id'); mac.user.username = mac.cookie.get('user_name'); mac.user.groupid = mac.cookie.get('group_id'); mac.user.groupname = mac.cookie.get('group_name'); mac.user.portrait = mac.cookie.get('user_portrait'); mac.user.islogin = 1; $('.mac_user').removeclass('mac_user').attr('href',url); $('.user_name').show().find('.name').text(mac.user.username); $('.user_url').show().attr('href',url); $('.user_img').show().attr('src',mac.user.portrait); } else{ } }, 'checklogin':function(){ if(mac.user.islogin == 0){ mac.user.login(); } }, 'login':function(){ var ac='ajax_login'; if(mac.cookie.get('user_id') !=undefined && mac.cookie.get('user_id')!=''){ ac= 'ajax_info'; } mac.pop.show('#modal-login',maccms.path+'/index.php/user/'+ac,function($r){ $('body').on('click', '#login_form_submit', function(e){ $.ajax({ type: 'post', url: maccms.path + '/index.php/user/login', data: $('.mac_login_form').serialize(), success:function($r){ if($r.code == 1){ location.reload(); } } }); }); }); }, 'logout':function(){ $.ajax({ type: 'post', url: maccms.path + '/index.php/user/logout', success:function($r){ alert($r.msg) if($r.code == 1){ location.reload(); } } }); }, 'popedomcallback':function(trysee,h) { window.settimeout(function(){ $(window.frames["player_if"].document).find(".macplayer").html(h); },1000*60*trysee); }, 'buypopedom':function(o){ var $that = $(o); if($that.attr("data-id")){ if (confirm('您确认购买此条数据播放权限吗?')) { $.ajax({ url: maccms.path + '/index.php/user/ajax_buy_popedom.html?id=' + $that.attr("data-id") + '&sid=' + $that.attr("data-sid") + '&nid=' + $that.attr("data-nid") + '&type=' + $that.attr("data-type"), cache: false, datatype: 'json', success: function ($r) { $that.addclass('disabled'); alert($r.msg) if ($r.code == 1) { top.location.reload(); } }, complete: function () { $that.removeclass('disabled'); } }); } } } }, 'pop':{ 'show':function($modalid,$url,$callback) { $.ajax({ type: 'post', url: $url, timeout: 3000, error: function(){ $('body').append(alert("加载失败,请刷新")); }, success:function($r){ $('body').append($r); $($modalid).modal('show'); $('.macplayer').hide(); $($modalid).on('hide.bs.modal', function () { $('.macplayer').show(); }) $callback($r); } }); } }, 'adswrap':function(w,h,n){ document.writeln(''+n+''); }, 'css':function($url){ $("").attr({ rel: "stylesheet",type: "text/css",href: $url}).appendto("head"); }, 'js':function($url){ $.getscript($url, function(response, status) { }); }, 'desktop':function(s){ location.href= maccms.path + '/index.php/ajax/desktop?name='+encodeuri(s)+'&url=' + encodeuri(location.href); }, 'timming':function(){ }, 'error':function(tab,id,name){ }, 'addem':function(obj,i){ var oldtext = $(obj).val(); $(obj).val( oldtext + '[em:' + i +']' ); }, 'remaining':function(obj,len,show){ var count = len - $(obj).val().length; if(count < 0){ count = 0; $(obj).val($(obj).val().substr(0,200)); } $(show).text(count); }, 'comment':{ 'login':0, 'verify':0, 'init':function(){ $('body').on('click', '.comment_face_box img', function(e){ var obj = $(this).parent().parent().parent().find('.comment_content'); mac.addem(obj,$(this).attr('data-id')); }); $('body').on('click', '.comment_face_panel', function(e){ // $('.comment_face_box').toggle(); $(this).parent().find('.comment_face_box').toggle(); }); $('body').on('keyup', '.comment_content', function(e){ var obj = $(this).parent().parent().parent().parent().find('.comment_remaining'); mac.remaining($(this),200,obj) }); $('body').on('focus', '.comment_content', function(e){ if(mac.comment.login==1 && mac.user.islogin!=1){ mac.user.login(); } }); $('body').on('click', '.comment_report', function(e){ var $that = $(this); if($(this).attr("data-id")){ $.ajax({ url: maccms.path + '/index.php/comment/report.html?id='+$that.attr("data-id"), cache: false, datatype: 'json', success: function($r){ $that.addclass('disabled'); alert($r.msg) if($r.code == 1){ } } }); } }); $('body').on('click', '.comment_reply', function(e){ var $that = $(this); if($that.attr("data-id")){ var str = $that.html(); $('.comment_reply_form').remove(); if (str == '取消回复') { $that.html('回复'); return false; } if (str == '回复') { $('.comment_reply').html('回复'); } var html = $('.comment_form').prop("outerhtml"); var oo = $(html); oo.addclass('comment_reply_form'); oo.find('input[name="comment_pid"]').val( $that.attr("data-id") ); $that.parent().after(oo); $that.html('取消回复'); } }); $('body').on('click', '.comment_submit', function(e){ var $that = $(this); mac.comment.submit($that); }); }, 'show':function($page){ if($(".mac_comment").length>0){ $.ajax({ type: 'get', url: maccms.path + '/index.php/comment/ajax.html?rid='+$('.mac_comment').attr('data-id')+'&mid='+ $('.mac_comment').attr('data-mid') +'&page='+$page, timeout: 5000, error: function(){ $(".mac_comment").html('评论加载失败,请刷新...'); }, success:function($r){ $(".mac_comment").html($r); } }); } }, 'reply':function($o){ }, 'submit':function($o){ var form = $o.parents('form'); if($(form).find(".comment_content").val() == ''){ alert("请输入您的评论!") return false; } if($('.mac_comment').attr('data-mid') == ''){ alert("模块mid错误!") return false; } if($('.mac_comment').attr('data-id') == ''){ alert("关联id错误!") return false; } $.ajax({ type: 'post', url: maccms.path + '/index.php/comment/savedata', data: $(form).serialize() + '&comment_mid='+ $('.mac_comment').attr('data-mid') + '&comment_rid=' + $('.mac_comment').attr('data-id'), success:function($r){ alert($r.msg) if($r.code == 1){ mac.comment.show(1); } else{ if(mac.comment.verify==1){ mac.verify.refresh(); } } } }); } } } $(function(){ //自动跳转手机和pc网页地址 mac.adaptive(); //验证码初始化 mac.verify.init(); //分页跳转初始化 mac.pagego.init(); //用户部分初始化 mac.user.init(); //顶和踩初始化 mac.digg.init(); //评分初始化 mac.score.init(); //星星评分初始化 mac.star.init(); //点击数量 mac.hits.init(); //历史记录初始化 mac.ulog.init(); //联想搜索初始化 mac.suggest.init('.mac_wd',1,''); //定时任务初始化 mac.timming(); });