if(!document.getelementbyclassname){ function hasclass(elem, cls) { cls = cls || ''; if (cls.replace(/\s/g, '').length == 0) return false; //��clsû�в���ʱ������false var ret = new regexp(' ' + cls + ' ').test(' ' + elem.classname + ' '); return ret; } document.getelementbyclassname = function(classname,index){ var nodes=document.getelementsbytagname("*");//��ȡҳ��������Ԫ�أ���ϊ����ƥ��ȫҳ��Ԫ�أ�������������ȱ�ݣ����ǿ���լ������������χ�� var arr=[];//����������ϵ�classname�� for(var i=0;imax_off){ offset = max_off; } var obj = document.getelementbyclassname('slide_block'); obj.style.csstext = "transform: translate("+offset+"px, 0px)"; tncode._mark_offset = offset/max_off*(tncode._img_w-tncode._mark_w); tncode._draw_bg(); tncode._draw_mark(); }, _block_on_end:function(e){ if(!tncode._doing)return true; e.preventdefault(); var theevent = window.event || e; if(theevent.touches){ theevent = theevent.touches[0]; } tncode._is_moving = false; tncode._send_result(); }, _send_result:function(){ var haddle = {success:tncode._send_result_success,failure:tncode._send_result_failure}; tncode._result = false; var re = new _ajax(); var timestamp = date.parse(new date()); re.request('get','/dom/verify_check.php?username='+user_name+'×tamp='+timestamp+'&ajax=2&tn_r='+tncode._mark_offset,haddle); }, _send_result_success:function(responsetext,responsexml){ tncode._doing = false; if(responsetext=='ok'){ var notic_msg = ''; if(_check_type == 1){ notic_msg = $weisitela.yanzhengtongguosub+'....'; } tncode._tncode.innerhtml = notic_msg; tncode._showmsg($weisitela.yanzhengtongguo,1); tncode._result = true; document.getelementbyclassname('hgroup').style.display="block"; settimeout(tncode.hide,3000); if(tncode._onsuccess){ tncode._onsuccess(); } }else{ var obj = document.getelementbyid('tncode_div'); addclass( obj,'dd'); settimeout(function(){ removeclass( obj,'dd'); },200); tncode._result = false; tncode._showmsg($weisitela.yanzhengshibai); tncode._err_c++; if(tncode._err_c>5){ tncode.refresh(); } } }, _send_result_failure:function(xhr,status){ }, _draw_fullbg:function(){ var canvas_bg = document.getelementbyclassname('tncode_canvas_bg'); var ctx_bg = canvas_bg.getcontext('2d'); ctx_bg.drawimage(tncode._img, 0, tncode._img_h*2, tncode._img_w, tncode._img_h, 0, 0, tncode._img_w, tncode._img_h); }, _draw_bg:function(){ if(tncode._is_draw_bg){ return; } tncode._is_draw_bg = true; var canvas_bg = document.getelementbyclassname('tncode_canvas_bg'); var ctx_bg = canvas_bg.getcontext('2d'); ctx_bg.drawimage(tncode._img, 0, 0, tncode._img_w, tncode._img_h, 0, 0, tncode._img_w, tncode._img_h); }, _draw_mark:function(){ var canvas_mark = document.getelementbyclassname('tncode_canvas_mark'); var ctx_mark = canvas_mark.getcontext('2d'); //������� ctx_mark.clearrect(0,0,canvas_mark.width,canvas_mark.height); ctx_mark.drawimage(tncode._img, 0, tncode._img_h, tncode._mark_w,tncode._img_h,tncode._mark_offset,0,tncode._mark_w, tncode._img_h); var imagedata = ctx_mark.getimagedata(0, 0, tncode._img_w, tncode._img_h); // ��ȡ������������ϣ // ��һ��һά���飬������ rgba ˳������ݣ�����ʹ�� 0 �� 255����������������ʾ // �磺ͼƭ���������ع��ɣ�һ�������ǰ�ɫ��һ�������ǻ�ɫ����ô data ϊ // [255,255,255,255,0,0,0,255] // ���һά������կ���������������rbgaͨ��������ļ��ϼ�: // [r,g,b,a].concat([r,g,b,a]) var data = imagedata.data; //alert(data.length/4); var x = tncode._img_h,y=tncode._img_w; for(var j = 0; j < x; j++) { var ii = 1,k1=-1; for(var k=0;k=0&&k>k1;){ // �õ� rgba ͨ����ֵ var i = (j*y+k)*4; k+=ii; var r = data[i] , g = data[i+1] , b = data[i+2]; // ���ǵ�������������ɫ�������п��կ�����ͼƭ�����ͻ�������һс���� // ���۵ĺ۲��»������ǰ�ɫ�ģ�������������� rgb ֵ���� 245 ���ϵ� // �ķ���ϊ��ɫ // ���ҳ�����լ�����ĸ���ȷ�����߸����һщ if(r+g+b<200) data[i+3] = 0; else{ var arr_pix = [1,-5]; var arr_op = [250,0]; for (var i =1; i opacity) { v -= avg; setopacity(ele, v); } else { setopacity(ele, 0); if(status==0){ tncode._reset(); } clearinterval(timer); } }, 100); } } function fadein(ele, opacity, speed) { if (ele) { var v = ele.style.filter.replace("alpha(opacity=", "").replace(")", "") || ele.style.opacity; v < 1 && (v = v * 100); var count = speed / 1000; var avg = count < 2 ? (opacity / count) : (opacity / count - 1); var timer = null; timer = setinterval(function() { if (v < opacity) { v += avg; setopacity(ele, v); } else { clearinterval(timer); settimeout(function() {fadeout(obj, 0, 6000);},1000); } }, 100); } } fadein(obj, 80, 4000); }, _html:function(){ var d = document.getelementbyid('tncode_div_bg'); if(d)return; //拖动左边滑块完成上方拼图 var html = '
'+$weisitela.jiazaizhong+'
'+$weisitela.huadongyanzheng+'
'; var bo = document.getelementsbytagname('body'); appendhtml(bo[0],html); }, _currenturl:function(){ var list = document.getelementsbytagname('script'); for (var i in list) { var d=list[i]; if(d.src.indexof('tn_code')!==-1){//js�ļ���һ��ҫ������ַ� var arr = d.src.split('tn_code'); return arr[0]; } } }, refresh:function(){ var issupportwebp = !![].map && document.createelement('canvas').todataurl('image/webp').indexof('data:image/webp') == 0; var _this = this; tncode._err_c = 0; tncode._is_draw_bg = false; tncode._result = false; tncode._img_loaded = false; var obj = document.getelementbyclassname('tncode_canvas_bg'); obj.style.display="none"; obj = document.getelementbyclassname('tncode_canvas_mark'); obj.style.display="none"; tncode._img = new image(); var timestamp = date.parse(new date()); var img_url = "/dom/verify_check.php?username="+user_name+"×tamp"+timestamp+"&ajax=1&t="+math.random(); // var img_url = tncode._currenturl()+"tncode.php?t="+math.random(); if(!issupportwebp){//�������֧��webp img_url+="&nowebp=1"; } tncode._img.src = img_url; tncode._img.onload = function(){ tncode._draw_fullbg(); var canvas_mark = document.getelementbyclassname('tncode_canvas_mark'); var ctx_mark = canvas_mark.getcontext('2d'); //������� ctx_mark.clearrect(0,0,canvas_mark.width,canvas_mark.height); tncode._img_loaded = true; obj = document.getelementbyclassname('tncode_canvas_bg'); obj.style.display=""; obj = document.getelementbyclassname('tncode_canvas_mark'); obj.style.display=""; }; //alert("hong kong forharvest technology and culture development co. limited".length); obj = document.getelementbyclassname('slide_block'); obj.style.csstext = "transform: translate(0px, 0px)"; obj = document.getelementbyclassname('slide_block_text'); obj.style.display="block"; }, init:function(classobj,type,j){ var _this = this; _check_type = type; if(!tncode._img){ tncode._html(); var obj = document.getelementbyclassname('slide_block'); tncode._bind(obj,'mousedown',_this._block_start_move); tncode._bind(document,'mousemove',_this._block_on_move); tncode._bind(document,'mouseup',_this._block_on_end); tncode._bind(obj,'touchstart',_this._block_start_move); tncode._bind(document,'touchmove',_this._block_on_move); tncode._bind(document,'touchend',_this._block_on_end); var obj = document.getelementbyclassname('tncode_close'); tncode._bind(obj,'touchstart', function(){ _this.hide((j && j.hidefun && j.hidefun)) }); tncode._bind(obj,'click', function(){ _this.hide((j && j.hidefun && j.hidefun)); }); var obj = document.getelementbyclassname('tncode_refresh'); tncode._bind(obj,'touchstart',_this.refresh); tncode._bind(obj,'click',_this.refresh); var objs = document.getelementbyclassname(classobj); _this.show(); // for (var i in objs) { // var o = objs[i]; // //o.innerhtml = '�϶���ť������֤'; // // tncode._bind(o,'touchstart',_this.show); // _this.show(); // // tncode._bind(o,'click',_this.show); // } } }, result:function(){ return tncode._result; }, onsuccess:function(fn){ tncode._onsuccess = fn; } }; var $tn = tncode; var _old_onload = window.onload; window.onload = function(){ if(typeof _old_onload == 'function'){ _old_onload(); } // tncode.init(tncode_class); };