note_id = 0; win_height = 0; music_player = new Audio(); pop_up_note_mode = true; text_prepared = false; font_img = null; // pure_card_text // --------------------------------------------------------------------- // sdk function add_keyframes(name, cssbody) { csstext = '@-webkit-keyframes ' + name + '{' + cssbody + '}'; style = document.createElement('style'); document.head.appendChild(style); sheet = style.sheet; sheet.insertRule(csstext, 0); } function create_imgdiv(url, idname, visible, x, y) { imgdiv = document.createElement('div'); } function objid(idname) { return document.getElementById(idname); } function _kv(value) { if(typeof(value) == 'undefined') { return false; } if(value == '') { return false; } if(value.charAt(0) == '#') { return false; } return true; } function _v(keyname) { if(typeof(kawa_data[keyname]) == 'undefined') { return ''; } return kawa_data[keyname]; } // --------------------------------------------------------------------- // text function kawa_init_async() { read_base(); create_textdiv(); add_kawa_icon(); create_music(); //create_modify(); zk_create_modify(); } function kawa_init() { document.body.style.margin = '0px'; create_base(); setTimeout("kawa_init_async()", 100); } function is_show_words() { if(typeof(kawa_data.show_words) == 'undefined') { return true; } if(kawa_data.show_words != 'no') { return true; } return false; } function read_base() { win_height = objid('basepoint').offsetTop; } function create_base() { div = document.createElement('div'); div.style.position = 'fixed'; div.style.bottom = '0px'; div.style.width = '1px'; div.style.height = '1px'; div.style.left = '-100px'; div.id = 'basepoint'; document.body.appendChild(div); } function make_text_animation() { //if(!is_show_words()) // return; var mask = objid('textmask'); var textdiv = objid('textdiv'); if(kawa_data.mode == 'up') { var keycss = 'from{-webkit-transform:translate(0px, ' + mask.offsetHeight + 'px);}' + 'to{-webkit-transform:translate(0px, -' + textdiv.offsetHeight + 'px);}' add_keyframes('textdivani', keycss); var dt = (mask.offsetHeight + textdiv.offsetHeight) / kawa_data.speed; textdiv.style.webkitAnimation = 'textdivani ' + dt + 's linear infinite'; } else if(kawa_data.mode == 'left') { var keycss = 'from{-webkit-transform:translate(' + mask.offsetWidth + 'px, 0px);}' + 'to{-webkit-transform:translate(-' + textdiv.offsetWidth + 'px, 0px);}' add_keyframes('textdivani', keycss); var dt = (mask.offsetWidth + textdiv.offsetWidth) / kawa_data.speed; textdiv.style.webkitAnimation = 'textdivani ' + dt + 's linear infinite'; } else if (kawa_data.mode == 'print') { onPrint(); setTimeout("onPrintAni()", 1500); } } function onPrint() { objid('textdiv').style.top = objid('textmask').offsetHeight; gPrText = card_text(); gOrgCardText = card_text(); } function onPrintAni() { pushText = ''; var reachEnd = 0; if(gPrText.length <1) { reachEnd = 1; } var cutlen = 0; if(gPrText.length >= 4 && gPrText.substring(0, 4) == '
') { gPrText = gPrText .substring(4); pushText = '
'; cutlen = 4; } else if(gPrText.substring(0, 2) == '/:') { result = ConvFaceOnBegin(gPrText ); cutlen = result[1]; if(cutlen > 0) { gPrText = gPrText .substring(cutlen); pushText = result[0]; } } if(cutlen == 0 && gPrText.length >= 1) { pushText = gPrText.substring(0, 1); gPrText = gPrText.substring(1); } objid('textdiv').innerHTML = objid('textdiv').innerHTML + pushText; //alert(objid('textmask').offsetHeight); if((objid('textdiv').offsetTop + objid('textdiv').offsetHeight)> objid('textmask').offsetHeight) { trans = objid('textmask').offsetHeight - objid('textdiv').offsetHeight; objid('textdiv').style.top = trans+ 'px'; //alert(objid('textdiv').style.top); } if(reachEnd == 1) { //setTimeout("", 2000); setTimeout("pauseShow()",2000); } else { var gSpeed = kawa_data.speed; setTimeout("onPrintAni()", gSpeed); } } function pauseShow() { reachEnd=0; trans = 0; objid('textdiv').style.top =trans+'px'; gPrText = gOrgCardText; objid('textdiv').innerHTML = ""; setTimeout("onPrintAni()",1000); } function show_textdiv() { var box = kawa_data.text_box.split(' '); var mask = document.createElement('div'); mask.id = 'textmask'; mask.style.position = 'absolute'; mask.style.left = box[0] + 'px'; mask.style.top = box[1] + 'px'; mask.style.width = box[2] + 'px'; mask.style.height = box[3] + 'px'; mask.style.overflow = 'hidden'; var textdiv = document.createElement('div'); textdiv.id = 'textdiv'; textdiv.style.position = 'absolute'; textdiv.style.color = kawa_data.text_color; textdiv.style.fontSize = kawa_data.font_size; textdiv.style.lineHeight = kawa_data.line_height; textdiv.style.fontWeight = '600'; textdiv.style.fontFamily = 'Microsoft YaHei'; textdiv.style.zIndex = 50000; if(_kv(kawa_data.text_align)) { textdiv.style.textAlign = kawa_data.text_align; } if(_kv(kawa_data.font_weight)) { textdiv.style.fontWeight = kawa_data.font_weight; } if(kawa_data.mode == 'left') { textdiv.style.float = 'left'; } document.getElementById('content').appendChild(mask); mask.appendChild(textdiv); set_up_words(); } function create_textdiv() { if(is_show_words()) { show_textdiv(); } } function set_up_words() { textdiv = objid('textdiv'); if (kawa_data.mode=='print') textdiv.innerHTML = ''; else textdiv.innerHTML = card_text(); make_text_animation(); } function pure_card_text() { text = kawa_data.words; //alert(text); if(kawa_data.replace_words != '#replace_words#') { text = kawa_data.replace_words; } return text; } function card_text() { text = pure_card_text(); if((kawa_data.mode == 'up')||(kawa_data.mode == 'print')) { text = wrap_text(text); } else if(kawa_data.mode == 'left') { text = '' + text + ''; } return text; } function wrap_text(in_text) { text = in_text.replace(/,/g, ',
'); text = text.replace(/,/g, ',
'); text = text.replace(/\./g, '.
'); text = text.replace(/。/g, '。
'); text = text.replace(/;/g, ';
'); text = text.replace(/;/g, ';
'); text = text.replace(/!/g, '!
'); text = text.replace(/!/g, '!
'); text = text.replace(/~/g, '~
'); text = text.replace(/:/g, ':
'); text = text.replace(/:/g, ':
'); text = text.replace(/?/g, ':
'); text = text.replace(/\?/g, ':
'); return text; } // --------------------------------------------------------------------- // kawa icon function add_kawa_icon() { url = 'http://www.ipa361.com/Public/images/card/zhuzhu.gif'; div = document.createElement('div'); img = document.createElement('img'); img.src = url; div.appendChild(img); div.style.position = 'absolute'; //div.style.top = (win_height - 100) + 'px'; div.style.bottom = '5%'; div.style.marginLeft='10px'; div.style.zIndex = '10000'; div.onclick = xialaClick; document.getElementById('content').appendChild(div); } function goto_kawa() { location.href = 'http://www.ipa361.com/Wzf/gbj'; } // --------------------------------------------------------------------- // kawa music var bplay = 0; //记录是否要播放音乐 function switchsound() { au = music_player ai = objid('sound_image'); if(au.paused) { bplay = 1; au.play(); ai.src = "http://www.ipa361.com/Public/images/card/music_note_big.png"; pop_up_note_mode = true; popup_note(); objid("music_txt").innerHTML = "打开"; objid("music_txt").style.visibility = "visible"; setTimeout(function(){objid("music_txt").style.visibility="hidden"}, 2500); } else { bplay = 0; pop_up_note_mode = false; au.pause(); ai.src = "http://www.ipa361.com/Public/images/card/music_note_big.png"; objid("music_txt").innerHTML = "关闭"; objid("music_txt").style.visibility = "visible"; setTimeout(function(){objid("music_txt").style.visibility="hidden"}, 2500); } } function play_music() { if(typeof(kawa_data) != 'undefined') { music = kawa_data.music; if(kawa_data.replace_music != '#replace_music#') { music = kawa_data.replace_music; } music_player.src = music; music_player.loop = 'loop'; music_player.play(); bplay = 1; } } function create_music() { play_music(); sound_div = document.createElement("div"); sound_div.setAttribute("ID", "cardsound"); sound_div.style.cssText = "position:fixed;right:20px;top:25px;z-index:50000;visibility:visible;"; sound_div.onclick = switchsound; bg_htm = ""; box_htm = "
"; txt_htm = "
" sound_div.innerHTML = bg_htm + box_htm + txt_htm; document.body.appendChild(sound_div); setTimeout("popup_note()", 100); } function on_pop_note_end(event) { note = event.target; if(note.parentNode == objid("note_box")) { objid("note_box").removeChild(note); } } function popup_note() { box = objid("note_box"); note = document.createElement("span"); note.style.cssText = "visibility:visible;position:absolute;background-image:url('http://www.ipa361.com/Public/images/card/music_note_small.png');width:15px;height:25px"; note.style.left = Math.random() * 20 + 20; note.style.top = "75px"; this_node = "music_note_" + note_id; note.setAttribute("ID", this_node); note_id += 1; scale = Math.random() * 0.4 + 0.4; note.style.webkitTransform = "rotate(" + Math.floor(360 * Math.random()) + "deg) scale(" + scale + "," + scale + ")"; note.style.webkitTransition = "top 2s ease-in, opacity 2s ease-in, left 2s ease-in"; note.addEventListener("webkitTransitionEnd", on_pop_note_end); box.appendChild(note); setTimeout("document.getElementById('" + this_node + "').style.left = '0px';", 100); setTimeout("document.getElementById('" + this_node + "').style.top = '0px';", 100); setTimeout("document.getElementById('" + this_node + "').style.opacity = '0';", 100); if(pop_up_note_mode) { setTimeout("popup_note()", 600); } } // --------------------------------------------------------------------- // weixin function share_url() { url = 'http://www.ipa361.com/Wzf'; return url; } function share_data() { var desc = ''; if(_v('user_desc') != '') { desc = _v('user_desc'); } else { desc = kawa_data.desc; if(kawa_data.replace_words != '#replace_words#') { desc = kawa_data.replace_words; } } //alert(desc); return{ 'img_url' : kawa_data.icon, 'img_width' : '640', 'img_height' : '640', 'link' : share_url(), 'desc' : desc, 'title' : kawa_data.title } } function share_data_timeline() { var desc = ''; if(_v('user_desc') != '') { desc = _v('user_desc'); } else { desc = kawa_data.desc; if(kawa_data.replace_words != '#replace_words#') { desc = kawa_data.replace_words; } } return{ 'img_url' : kawa_data.icon, 'img_width' : '640', 'img_height' : '640', 'link' : share_url(), 'desc' : desc, 'title' : desc } } function on_weixin_ready() { play_music(); WeixinJSBridge.on('menu:share:appmessage', function(argv){ WeixinJSBridge.invoke('sendAppMessage',share_data(), function(res) { WeixinJSBridge.log(res.err_msg); }); }); WeixinJSBridge.on('menu:share:timeline', function(argv){ //WeixinJSBridge.invoke('shareTimeline', share_data_timeline(), on_weixin_reply); WeixinJSBridge.invoke("shareTimeline",share_data_timeline(),function(e){ alert(e.err_msg); }) }); } document.addEventListener('WeixinJSBridgeReady', on_weixin_ready, false); // --------------------------------------------------------------------- function initViewport() { if(/Android (\d+\.\d+)/.test(navigator.userAgent)) { var version = parseFloat(RegExp.$1); if(version>2.3) { var phoneScale = parseInt(window.screen.width)/500; document.write(''); } else { document.write(''); } } else if(navigator.userAgent.indexOf('iPhone') != -1) { var phoneScale = parseInt(window.screen.width)/500; document.write(' '); //0.75 0.82 } else if(navigator.userAgent.indexOf('iPad') != -1) { var phoneScale = parseInt(window.screen.width)/500; document.write(' '); //0.75 0.82 } else { document.write(''); //document.write(' '); //0.75 0.82 } document.write(''); } function wordchange() { zkid('words').value = zkid('wordselect').value; //txtChange(); } function zkid(idname) { return document.getElementById(idname); } var xiala = 0; function closexiala() { if(xiala == 1) { zkid('menu').style.webkitTransform = 'translateY(0px)'; setTimeout("zkid('menu').style.webkitTransform = 'translateX(70px)'",1000); //setTimeout("zkid('xiala_div').style.webkitTransform = 'translateY(60px)'",1000); //zkid('xiala_div').style.webkitTransform = 'translateY(0px)'; xiala = 0; } } function xialaClick() { if(xiala == 0) { zkid('menu').style.webkitTransform = 'translateX(0px)'; //zkid('xiala_div').style.webkitTransform = 'translateY(0px)'; xiala = 1; } else { zkid('menu').style.webkitTransform = 'translateX(70px)'; //zkid('xiala_div').style.webkitTransform = 'translateY(60px)'; xiala = 0; } } function zk_create_modify() { if(kawa_data.modify == 'yes' || kawa_data.replace_modify == 'yes') { var u = navigator.userAgent; var ios = (u.indexOf('iPad')>-1 || u.indexOf('iPhone') > -1) && u.match(/(i[^;]+\;(U;)? CPU.+Mac OS X)/); if(ios != false) { div.style.position = 'absolute'; } else { div.style.position = 'fixed'; } /* document.body.appendChild(div); var divla = document.createElement('div'); divla.style.position = 'fixed'; divla.style.height = "45px"; divla.style.width = "45px"; divla.style.right = '90px'; divla.style.top = '-38px'; divla.style.zIndex = '80000'; divla.style.display = 'inline'; divla.id = 'xiala_div'; divla.onclick = xialaClick; divla.style.webkitTransition = '-webkit-transform 2s ease'; divla.innerHTML = '
'; document.body.appendChild(divla); */ setTimeout("zkid('menu').style.webkitTransform = 'translateX(70px)'",2500); //setTimeout("zkid('xiala_div').style.webkitTransform = 'translateY(60px)'",2500); } }