var VOTE_RESULT_DESC = new Array(); VOTE_RESULT_DESC[0] = ""; VOTE_RESULT_DESC[1] = "投票成功"; VOTE_RESULT_DESC[2] = "您已经投票了"; VOTE_RESULT_DESC[3] = "请先登录"; VOTE_RESULT_DESC[4] = "投票点错误"; VOTE_RESULT_DESC[5] = "投票动作错误"; VOTE_RESULT_DESC[6] = "投票状态错误"; VOTE_RESULT_DESC[60] = "投票未开始"; VOTE_RESULT_DESC[62] = "投票已结束"; VOTE_RESULT_DESC[7] = "投票不存在"; VOTE_RESULT_DESC[8] = "请输入验证码"; VOTE_RESULT_DESC[9] = "验证码错误"; VOTE_RESULT_DESC[10] = "投票时间错误"; VOTE_RESULT_DESC[11] = "该投票项已达最大票数"; function _voteNeedJS(fn,src,callback) { if(typeof callback == 'undefined' || callback == null) callback = function(){}; if(typeof fn != 'undefined' && fn != null && fn != '') return callback(); var status = typeof _needJS_ == 'undefined' ? _needJS_ = {loaded:[],loading:[]} : _needJS_; for(var i=0; i < status.loaded.length; i++) { if(status.loaded[i] == src) return callback(); } function idx(src) { //供后面的代码调用 for(var i=0; i < status.loading.length;i++) if(status.loading[i].src==src) return i; } var loading = status.loading[idx(src)]; if(loading != null) { loading.callbacks.push(callback); return; } status.loading.push(loading = {src:src,callbacks:[callback]}); var js = document.createElement('script'); js.src = src; js.onload = js.onreadystatechange = function() { if(typeof js.readyState == 'undefined' || js.readyState == 'loaded' || js.readyState == 'complete') { status.loaded.push(loading.src); var callbacks = loading.callbacks; status.loading.splice(idx(src),1); for(var i = 0; i < callbacks.length; i++) { loading.callbacks[i](); } } } document.getElementsByTagName('head')[0].appendChild(js); } var VOTE_CAPTCHA_URL = new Array(); VOTE_CAPTCHA_URL[5] = "//captchahttps://diy.pconline.com.cn/jczt/agf/18/.com.cn/captcha/v.jpg"; VOTE_CAPTCHA_URL[8] = "//captcha2https://diy.pconline.com.cn/jczt/agf/18/.com.cn/captcha/v.jpg"; var CubeVote = { captchaurl : VOTE_CAPTCHA_URL[5], vote : function(elem,_pagecallback,_callback) { if(!_pagecallback||_pagecallback==null||_pagecallback=="")_pagecallback = "CubeVote.pagecallback"; if(!_callback||_callback==null||_callback=="")_callback = CubeVote.callback; if(elem||elem!=null||elem!=""){ var elemId; var captchaValue = ""; if(elem.srcElement||elem.target){ elem = this; elemId = elem.id; } else if(elem.originalTarget){//事件来源 elem = elem.currentTarget; elemId = elem.id; } else if(elem.id ){ elemId = elem.id; var captcha = document.getElementById("_vote_captcha"); if(captcha){ if(!captcha.value || captcha.value == ""){ alert(CubeVote.resultDesc(8)); return false; } else{ captchaValue = captcha.value; } } } else{ return false; } elemId = elemId.replace('_vote_event_','').replace('cve',''); var tmp = elemId.split("_"); var voteId = 0; if(tmp.length == 2){ voteId = tmp[0]; elemId = tmp[1]; } else if(tmp.length == 1){ voteId = ''; elemId = tmp[0]; } var action = elemId.substring(elemId.length-1); var objId = elemId.substring(0,elemId.length-1); CubeVote.doVote(voteId,objId,action,captchaValue,_pagecallback,_callback); } return false; }, doVote : function(_voteId,_objId,_action,_captcha,_pagecallback,_callback){ if(!_pagecallback||_pagecallback==null||_pagecallback=="")_pagecallback = "CubeVote.pagecallback"; if(!_callback||_callback==null||_callback=="")_callback = CubeVote.callback; if(!_captcha) _captcha = ""; if(typeof(_action) == 'undefined') _action = 0; jQuery.getJSON("//magicube.pconline.com.cn/vote/vote.jsp?do=vote&voteId="+_voteId+"&action="+_action+"&voteObjId="+_objId+"&captcha="+_captcha+"&jsoncallback=?&pagecallback="+_pagecallback,_callback); }, getTop : function (_voteId,_top,_sort,_callback) { if(!_callback||_callback==null||_callback=="")_callback = CubeVote.getTopRenderVotes; jQuery.getJSON("//magicube.pconline.com.cn/vote/vote.jsp?do=getTop&voteId="+_voteId+"&sort="+_sort+"&top="+_top+"&jsoncallback=?",_callback); }, getVotes : function (_voteId,_whichSort,_callback){ if(!_callback||_callback==null||_callback=="")_callback = CubeVote.getVotesRenderVotes; var _oids = ""; var ids = jQuery("[id]").filter(function(index) { if(typeof(this.id) == "string"){ return this.id.match(/_vote_item_\d+(_)?\d+/); } }); ids.each(function (index){ var oid=this.id.split("_")[4]; if(index<(ids.length-1)){ _oids += oid.substring(0,oid.length-1)+",";//_vote_item_448_0 }else{ _oids += oid.substring(0,oid.length-1); } }); jQuery.getJSON("//magicube.pconline.com.cn/vote/vote.jsp?do=getVotes&voteId="+_voteId+"&oids="+_oids+"&whichSort="+_whichSort+"&jsoncallback=?",_callback); }, pagecallback:function(){}, getTopRenderVotes : function(data){ jQuery.each(data.items, function(i, n) { jQuery("#_vote_item_" + n.objId + (n.action + "")).html(n.votes + "" ) ; jQuery("#_vote_item_" + n.voteId + "_" + n.objId + (n.action + "")).html(n.votes + "" ) ; jQuery("#cvi" + n.voteId + "_" + n.objId + (n.action + "")).html(n.votes + "" ) ; }); }, getVotesRenderVotes : function(data){ jQuery.each(data.items, function(i, n) { //统一将总票数放入动作0里面 jQuery("#_vote_item_" + n.voteId + "_" + n.objId+"0").html(n.votes + "" ); }); }, init : function(){ jQuery("[id]").filter(function() {if(typeof(this.id) == "string")return this.id.match(/_vote_event_\d+(_)?\d+/);}).click(CubeVote.vote); jQuery("[id]").filter(function() {if(typeof(this.id) == "string")return this.id.match(/cve\d+(_)?\d+/);}).click(CubeVote.vote); }, status1 : function(data){ var vid = data.voteObjId + (data.action + ""); var vid2 = data.voteId+"_"+vid; jQuery("#_vote_item_" + vid).html(data.votes + ""); jQuery("#_vote_item_" + vid2).html(data.votes + ""); jQuery("#cvi" + vid2).html(data.votes + ""); if(typeof(PCDialog2) != "undefined" && PCDialog2)PCDialog2.hide(); //最后执行页面回调方法 var pagecallback = data.pagecallback; pagecallback = eval(pagecallback); pagecallback(data); }, status8 : function(data){ var vid = data.voteObjId + (data.action + ""); var vid2 = data.voteId+"_"+vid; CubeVote.showCaptcha(vid2); CubeVote.captchaurl = VOTE_CAPTCHA_URL[data.requireCaptcha]; CubeVote.changeCaptcha(); }, status9 : function(data){ alert(CubeVote.resultDesc(data.status)); CubeVote.changeCaptcha(); }, statusDefault : function(data){ alert(CubeVote.resultDesc(data.status)); if(data.requireCaptcha!=0){ CubeVote.changeCaptcha(); } }, callback : function(data){ if (data.status == 1) { CubeVote.status1(data); } else if(data.status == 8){ CubeVote.status8(data); } else if(data.status == 9){ CubeVote.status9(data); } else { CubeVote.statusDefault(data); } }, showCaptcha : function(_vid){ _voteNeedJS(window.PCDialog2,'//magicube.pconline.com.cn/js/dialog.js',function(){ var l = document.createElement("link"); l.setAttribute("type", "text/css"); l.setAttribute("rel", "stylesheet"); l.setAttribute("href","//magicube.pconline.com.cn/css/dialog.css"); document.getElementsByTagName("head")[0].appendChild(l); var PCDialog2 = window.PCDialog2; var html = "text:
"; html += "

请输入下面的验证码:

"; html += "

验证码: "; html += "验证码 "; html += "看不清,换一张

"; html += "

    "; html += "

"; html += "
"; PCDialog2.open("投票",html,"500","250"); }); }, resultDesc : function (code) { return VOTE_RESULT_DESC[code]; }, changeCaptcha : function (){ jQuery("#_vote_captcha").val(""); jQuery("#valid_code").attr("src",CubeVote.captchaurl+"?"+new Date().getTime()); } } _voteNeedJS(window.jQuery,'//magicube.pconline.com.cn/js/jquery.js',function(){ var $=window.jQuery; jQuery(document).ready(function(){ if(true){ CubeVote.init(); var voteIds = []; //votePageCallBack = null; for(var i = 0;i< voteIds.length;i++){ if(false){ CubeVote.getVotes(voteIds[i],'0'); }else{ CubeVote.getTop(voteIds[i],100,0); } } } }); });