// TODO 临时构造plus对象,使得能够在浏览器中进行调试 //var plus = null; // 登录者相关信息(包括userAgent) var loginerInfo = null, // 基础环境信息(包括当前webview) baseEnv = null, self = null, docInfo = null, kw = null, myScroll, chatCode = null, type = null; // 搜索框 var $searchbar = $('.searchbar'), // 搜索输入框 $searchbarInput = $('.searchbar input'), // 搜索取消按钮 $searchCancelBtn = $('.searchbar-cancel'), // 搜索框下面悬浮的搜索提示 $searchSuggest = $('#search_suggest_text'), // 搜索结果展示容器 $searchtResult = $('#search_result'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'), $doingWrapper = $('#doing_wrapper'), $doingList = $('#doing_list'), $moreResult = $('.more-result'); mui.plusReady(function() { self = plus.webview.currentWebview(); docInfo = JSON.parse(plus.storage.getItem("docInfo")); myScroll = $('#search_result').lscroll(); }); // 获取登录相关信息 var getLoginerInfo = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // $el: $('.c-content-warp') getRowProps = function ($el) { var $textEllipsis = $el.find('.j-text-ellipsis'), $text = $textEllipsis.eq(0), $chart = $text.text('a'), enWidth = $chart.width(), $chart = $text.text('中'), zhWidth = $chart.width(), lineHeight = parseFloat($chart.css("lineHeight"), 10), rowHeight = $chart.height(); $chart.text(''); return { chartWidth: { zh: zhWidth, en: enWidth }, rowHeight: Math.max(rowHeight, lineHeight), rowWidth: $el.width() }; }, replaceAll = function (text, arr) { var html = text; _.each(arr,function(kw) { var reg = new RegExp(kw+"(?!>)","gi"); html = html.replace(reg,''+kw+''); }); return html; }, highlineKeyword = function ($el,searchText) { var props = getRowProps($el), chartWidth = props.chartWidth, rowHeight = props.rowHeight, rowWidth = props.rowWidth, // 每行显示字符数(以中文字符为标准计算) chartNum = Math.floor(rowWidth / chartWidth.zh), // 排除“咨询问题:”字符及前后“...”所占宽度 exceptNum = 7, // 行数 rowNum = 1, // 预计显示总字符数 expectedNum = chartNum * rowNum - exceptNum, $target = $el.find('.j-text-ellipsis'), // 目标文本 text = $target.attr('data-text').trim(), length = text.length, // 关键字数组 kws = searchText.trim().replace(/\s+/g," ").split(" "); var fidx = 0,preFidx,diff = 0; $target.html(replaceAll(text, kws)); if(Math.ceil($target.height() / rowHeight) <= rowNum) { return ; } if(text.length > expectedNum) { fidx = text.indexOf(kws[0])+kws[0].length-1; diff = fidx - expectedNum + 1; preFidx = fidx; diff = (diff<0)?0:diff; var preChar = (diff>0)?"...":""; $target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"..."); while((Math.ceil($target.height() / rowHeight) <= rowNum) && (preFidx < length)) { preFidx++; $target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"..."); } if(preFidx == length && (Math.ceil($target.height() / rowHeight) <= rowNum)) { diff = diff>0?(diff - 1):0; $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws)); } else if((Math.ceil($target.height() / rowHeight) > rowNum)) { $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws)+"..."); } } }, ellipsisText = function ($elements, searchText) { //$el.ellipsis({ row: 2}); _.each($elements,function(el) { highlineKeyword($(el),searchText) }); }, // 控制搜索关键字悬浮提示的显示 showSearchSuggest = function(text) { var suggestText = '搜索“'+text+'”'; // 如果text不为空,则显示;否则隐藏 if(text&&text.trim().length) { $searchSuggest.text(suggestText); $searchSuggest.show(); } else { $searchSuggest.text(''); $searchSuggest.hide(); } }, calcAge = function(timestamp){ var date = new Date(timestamp); Y = date.getFullYear() + '-'; M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; D = date.getDate() < 10 ?'0'+date.getDate():date.getDate(); var birthday = Y+M+D; var r = birthday.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); if(r==null)return false; var d= new Date(r[1], r[3]-1, r[4]); if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]){ var Y = new Date().getFullYear(); return (Y-r[1]); } }, setPhoto = function(groupPhoto){ var images = ''; var cssArr=null; if(groupPhoto.length>=5){ cssArr = ["top: 0;left: 50%;margin-left: -8px;","top: 12px;left: 2px;","top: 12px;left: 28px;","top: 27px;left: 5px;","top: 27px;left: 24px;"]; }else if(groupPhoto.length==4){ cssArr = ["top: 5px;left: 3px;","top: 5px;left: 25px;","top: 27px;left: 3px;"," top: 27px;left: 25px;"]; }else if(groupPhoto.length==3){ cssArr = ["top: 5px;left: 50%;margin-left: -10px;","top: 20px;left: 3px;","top: 20px;left: 25px;"]; }else if(groupPhoto.length==2){ cssArr = ["top: 5px;left: 50%;margin-left: -10px;"," top: 19px;left: 24px;"]; }else if(groupPhoto.length==1 || groupPhoto.length==0){ cssArr = ["position: absolute;width: 50px;height: 50px;border-radius: 50px;background-size: 50px;overflow: hidden;"]; } for(var i in groupPhoto){ if(i>4) break; if(groupPhoto[i].avatar){ images+='