// JavaScript Document by jacy /** 定义基本常量 */ var RESULT_SUCCESS = 'success'; var RESULT_FAIL = 'fail'; var Wei_RAND_COLOR = ["#ff6600","#ff9900","#99cc00","#33cc00","#0099cc","#3399ff","#9933ff","#cc3366","#333333","#339999","#ff6600","#ff9900","#99cc00","#33cc00","#0099cc","#3399ff","#9933ff","#cc3366","#333333","#339999","#ff6600","#ff9900","#99cc00","#33cc00","#0099cc","#3399ff","#9933ff","#cc3366","#333333","#339999"]; /***/ (function(){ //异步请求提交表单 //提交后返回格式json json格式 {'result':'success|fail',data:{....}} function doAjaxSubmit(form,callback){ $.Dialog.loading(); $.ajax({ data:form.serializeArray(), type:'post', dataType:'json', url:form.attr('action'), success:function(data){ $.Dialog.close(); callback(data); } }) } function initFixedLayout(){ var navHeight = $('#fixedNav').height(); $('#fixedContainer').height($(window).height()-navHeight); } //通用banner function banner(isAuto,delayTime){ var screenWidth = $('.container').width(); var count = $('.banner li').size(); $('.banner ul').width(screenWidth*count); $('.banner ul').height(screenWidth/2); $('.banner').height(screenWidth/2); $('.banner li').width(screenWidth).height(screenWidth/2); $('.banner li img').width(screenWidth).height(screenWidth/2); $('.banner li .title').css({'width':'98%','padding-left':'2%'}) // With options $('.banner li .title').each(function(index, element) { $(this).text($(this).text().length>15?$(this).text().substring(0,15)+" ...":$(this).text()); }); var flipsnap = Flipsnap('.banner ul'); flipsnap.element.addEventListener('fstouchend', function(ev) { $('.identify em').eq(ev.newPoint).addClass('cur').siblings().removeClass('cur'); }, false); $('.identify em').eq(0).addClass('cur') if(isAuto){ var point = 1; setInterval(function(){ //console.log(point); flipsnap.moveToPoint(point); $('.identify em').eq(point).addClass('cur').siblings().removeClass('cur'); if(point+1==$('.banner li').size()){ point=0; }else{ point++; } },delayTime) } } //相册效果 function gallery(container,slideContainer){ var screenWidth = $('.container').width(); var count = $(container).find('li').size(); var picWidth = screenWidth/5*3; var paddingleft = screenWidth/5; $(container).find('ul').width(picWidth*count); $(container).find('ul').css('padding-left',paddingleft); $(container).find('ul').height(screenWidth/2); $(container).height(picWidth); $(container).find('li').css({'padding':10,width:picWidth-20,height:picWidth-20}); $(container).find('li img').width("100%").height("100%"); var flipsnap = Flipsnap(slideContainer,{ distance: picWidth }); flipsnap.element.addEventListener('fstouchend', function(ev) { $(container).find('.identify em').eq(ev.newPoint).addClass('cur').siblings().removeClass('cur'); }, false); $(container).find('.identify em').eq(0).addClass('cur') } //正方形图片预览 function squarePicSlide(isAuto,delayTime,width,height,prevBtn,nextBtn){ var count = $('.banner li').size(); $('.banner ul').width(width*count); $('.banner ul').height(height); $('.banner').height(height); $('.banner li').width(width).height(height); $('.banner li img').width(width).css('min-height',height); $('.banner li .title').css({'width':'98%','padding-left':'2%'}) // With options $('.banner li .title').each(function(index, element) { $(this).text($(this).text().length>15?$(this).text().substring(0,15)+" ...":$(this).text()); }); var flipsnap = Flipsnap('.banner ul'); flipsnap.element.addEventListener('fstouchend', function(ev) { $('.identify em').eq(ev.newPoint).addClass('cur').siblings().removeClass('cur'); }, false); $('.identify em').eq(0).addClass('cur'); var point = 0; if(isAuto){ setInterval(function(){ //console.log(point); flipsnap.moveToPoint(point); },delayTime) } flipsnap.element.addEventListener('fstouchend', function(ev) { point = ev.newPoint; $('.identify em').eq(point).addClass('cur').siblings().removeClass('cur'); }, false); $(prevBtn).click(function(){ if(flipsnap.hasPrev()){ flipsnap.toPrev(); point = point-1; }else{ flipsnap.moveToPoint(count-1); point = count-1; } $('.identify em').eq(point).addClass('cur').siblings().removeClass('cur'); }); $(nextBtn).click(function(){ if(flipsnap.hasNext()){ flipsnap.toNext(); point = point+1; }else{ flipsnap.moveToPoint(0); point = 0; } $('.identify em').eq(point).addClass('cur').siblings().removeClass('cur'); }); } //随机颜色 function setRandomColor(selector){ $(selector).each(function(index, element) { $(this).css('background-color',Wei_RAND_COLOR[index]); });; } //显示分享提示 function showShareTips(callback){ var tempHtml = $('
'); $('body').append(tempHtml); $('.shareTips').click(function(){ closeShareTips(callback); }) } function showShareFriend(callback){ var tempHtml = $(''); $('body').append(tempHtml); $('.shareTips').click(function(){ closeShareTips(callback); }) } function showSubscribeTips(opts){ if(opts.qrcode.length>5){ var tempHtml = $(''); }else{ var tempHtml = $(''); } $('body').append(tempHtml); $('.shareTips').click(function(){ $('.shareTips').remove(); if(opts.caalback)closeShareTips(opts.callback); }) } function closeShareTips(callback){ $('.shareTips').remove(); if(callback){ callback(); } } //初始化分享数据 /*参数 *desc *link *title *imgUrl * */ function initWxShare(shareData){ wx.ready(function(res){ //alert('res:'+res); //分享 wx.onMenuShareTimeline({ title: shareData.desc, // 分享标题 link: shareData.link, // 分享链接 imgUrl: shareData.imgUrl, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.onMenuShareAppMessage({ title: shareData.title, // 分享标题 desc: shareData.desc, // 分享描述 link: shareData.link, // 分享链接 imgUrl: shareData.imgUrl, // 分享图标 type: shareData.type, // 分享类型,music、video或link,不填默认为link dataUrl: shareData.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.onMenuShareQQ({ title: shareData.title, // 分享标题 desc: shareData.desc, // 分享描述 link: shareData.link, // 分享链接 imgUrl: shareData.imgurl, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); }) } function back(){ var hisLen = window.history.length; if(hisLen == 1){ wx.closeWindow(); }else{ window.history.back(); } } function showQrcode(title,url){ var qrHtml = $(''); $('img',qrHtml).attr('src','http://qr.liantu.com/api.php?text='+url); $('p',qrHtml).html(title); $('body').append(qrHtml); $('.close',qrHtml).click(function(){ qrHtml.remove(); }) } //利用微信接口上传图片 function wxChooseImg(_this,num,name,callback){ wx.chooseImage({ count: num, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res0) { var localIds = res0.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片 if(callback){ callback(localIds); }else{ wxUploadImg(localIds,name,_this); } } }); } //利用微信接口上传图片到微信服务器 function wxUploadImg(localIds,name,target){ var localId = localIds.pop(); $.Dialog.loading(); wx.uploadImage({ localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得 isShowProgressTips: 0, // 默认为1,显示进度提示 success: function (res) { $('textarea').val(); $.get(SITE_URL+"/index.php?s=/Home/Weixin/downloadPic/media_id/"+res.serverId+".html",function(data){ $.Dialog.close(); if(data.result=="success"){ var addImg = $('