/*! tncode 1.2 author:weiyingbin email:277612909@qq.com //@ object webiste: http://www.39gs.com/archive/259.html //@ https://github.com/binwind8/tncode */ if(!document.getElementByClassName){ function hasClass(elem, cls) { cls = cls || ''; if (cls.replace(/\s/g, '').length == 0) return false; //褰揷ls娌℃湁鍙傛暟鏃讹紝杩斿洖false var ret = new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' '); return ret; } document.getElementByClassName = function(className,index){ var nodes=document.getElementsByTagName("*");//鑾峰彇椤甸潰閲屾墍鏈夊厓绱狅紝鍥犱负浠栦細鍖归厤鍏ㄩ〉闈㈠厓绱狅紝鎵€浠ユ€ц兘涓婃湁缂洪櫡锛屼絾鏄彲浠ョ害鏉熶粬鐨勬悳绱㈣寖鍥达紱 var arr=[];//鐢ㄦ潵淇濆瓨绗﹀悎鐨刢lassName锛 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]; } // console.log("_block_on_end"); 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 value = $(this._tncode).parents('form').find('.codetype').val() if (value) { re.request('get', '/code/code/check?tn_r=' + tncode._mark_offset + '&codetype=' + value, haddle) } else { re.request('get', '/code/code/check?tn_r=' + tncode._mark_offset, haddle) } }, _send_result_success:function(responseText,responseXML){ tncode._doing = false; if(responseText=='ok'){ tncode._tncode.innerHTML = '鈭 楠岃瘉鎴愬姛'; tncode._showmsg('鈭 楠岃瘉鎴愬姛',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; document.getElementByClassName("tncode").style.background='#E6262F'; tncode._tncode.innerHTML = '楠岃瘉澶辫触,閲嶆柊楠岃瘉'; tncode._showmsg('楠岃瘉澶辫触'); 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] // 杩欎釜涓€缁存暟缁勫彲浠ョ湅鎴愭槸涓や釜鍍忕礌涓璕BGA閫氶亾鐨勬暟缁勭殑闆嗗悎鍗产 // [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]; // 鎴戜滑浠庢渶涓嬮潰閭e紶棰滆壊鐢熸垚鍣ㄤ腑鍙互鐪嬪埌鍦ㄥ浘鐗囩殑鍙充笂瑙掑尯鍩燂紝鏈変竴灏忓潡鍦 // 鑲夌溂鐨勮瀵熶笅鍩烘湰閮芥槸鐧借壊鐨勶紝鎵€浠ユ垜鍦ㄨ繖閲屾妸 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 = '
鍔犺浇涓?/div>
鎷栧姩宸﹁竟婊戝潡瀹屾垚涓婃柟鎷煎浘
'; 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 img_url = "/code/code/index?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(){ var _this = this; 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',_this.hide); tncode._bind(obj,'click',_this.hide); var obj = document.getElementByClassName('tncode_refresh'); tncode._bind(obj,'touchstart',_this.refresh); tncode._bind(obj,'click',_this.refresh); var objs = document.getElementByClassName('tncode',-1); for (var i in objs) { var o = objs[i]; o.innerHTML = '鐐瑰嚮鎸夐挳杩涜楠岃瘉'; tncode._bind(o,'touchstart',_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(); };