common.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. var priceshow = false;
  2. var timeshow = false;
  3. function priceTime(){
  4. $(".pricefat").mouseover(function(){
  5. if(!$(".pricefat").hasClass("active")){
  6. $("#minprice").css({"border-color":"#2cb7ca"});
  7. $("#maxprice").css({"border-color":"#2cb7ca"});
  8. $(".pricebut").show();
  9. $(".pricefat").addClass("customtime-active");
  10. }
  11. }).mouseout(function(){
  12. if(!$(".pricefat").hasClass("active")){
  13. if(!priceshow){
  14. $("#minprice").css({"border-color":""});
  15. $("#maxprice").css({"border-color":""});
  16. $(".pricebut").hide();
  17. $(".pricefat").removeClass("customtime-active");
  18. }
  19. }
  20. })
  21. $("#minprice,#maxprice").blur(function(){
  22. if(!priceshow&&!$(".pricefat").hasClass("active")){
  23. $("#minprice").css({"border-color":""});
  24. $("#maxprice").css({"border-color":""});
  25. $(".pricebut").hide();
  26. $(".pricefat").removeClass("customtime-active");
  27. }
  28. })
  29. $("#minprice").click(function(){
  30. priceshow=true;
  31. $(".pricebut").show();
  32. $(".pricefat").addClass("customtime-active");
  33. })
  34. $("#maxprice").click(function(){
  35. priceshow=true;
  36. $(".pricebut").show();
  37. $(".pricefat").addClass("customtime-active");
  38. })
  39. //
  40. $(".timerInput").mouseover(function(){
  41. if(!$(".timerInput").hasClass("active")){
  42. $("#starttime").css({"border-color":"#2cb7ca"});
  43. $("#endtime").css({"border-color":"#2cb7ca"});
  44. $("#timebut").show();
  45. $(".timerInput").addClass("customtime-active");
  46. }
  47. }).mouseout(function(){
  48. if(!$(".timerInput").hasClass("active")){
  49. if(!timeshow){
  50. $("#starttime").css({"border-color":""});
  51. $("#endtime").css({"border-color":""});
  52. $("#timebut").hide();
  53. $(".timerInput").removeClass("customtime-active");
  54. }
  55. }
  56. })
  57. //
  58. $("#starttime").click(function(){
  59. timeshow = true;
  60. $("#timebut").show();
  61. $(".timerInput").addClass("customtime-active");
  62. })
  63. $("#endtime").click(function(){
  64. timeshow = true;
  65. $("#timebut").show();
  66. $(".timerInput").addClass("customtime-active");
  67. })
  68. }
  69. //
  70. var EasyAlert = {
  71. timeout: null,
  72. waitTime: 1000,
  73. show: function(text,css,waitTime){
  74. if(this.timeout != null){
  75. clearTimeout(this.timeout);
  76. this.hide();
  77. this.timeout = null;
  78. }
  79. var thisClass = this;
  80. this.timeout = setTimeout(function(){
  81. thisClass.hide();
  82. thisClass.timeout = null;
  83. },waitTime?waitTime:this.waitTime);
  84. $("body").append('<div class="easyalert" id="easyAlert">'+text+'</div>');
  85. if(typeof(css) != "undefined"&&css!=""){
  86. $("#easyAlert").css(css);
  87. }
  88. $("#easyAlert").css({"left":"50%","margin-top":-($("#easyAlert").outerHeight()/2),"margin-left":-($("#easyAlert").outerWidth()/2)}).show();
  89. },
  90. hide: function(){
  91. $("#easyAlert").remove();
  92. }
  93. }
  94. var EasyPopup = function(id){
  95. this.id = id;
  96. var thisClass = this;
  97. document.getElementById(id).ontap = function(e){
  98. if(e.target.id == id){
  99. thisClass.hide();
  100. }
  101. }
  102. this.show = function(){
  103. $("#"+this.id).fadeIn();
  104. var mainObj = $("#"+id+">div:first");
  105. mainObj.css({"margin-top":-(mainObj.outerHeight()/2 + 35)});
  106. },
  107. this.hide = function(){
  108. $("#"+this.id).fadeOut();
  109. }
  110. }
  111. //计算时差
  112. function timeDiff(date){
  113. var date1 = date;//开始时间
  114. var date2 = new Date();//结束时间
  115. var date3 = date2.getTime()-date1.getTime();//时间差的毫秒数
  116. //计算出相差天数
  117. var days = Math.floor(date3/(24*3600*1000));
  118. //计算出小时数
  119. var leave1 = date3%(24*3600*1000);//计算天数后剩余的毫秒数
  120. var hours = Math.floor(leave1/(3600*1000));
  121. //计算相差分钟数
  122. var leave2 = leave1%(3600*1000);//计算小时数后剩余的毫秒数
  123. var minutes = Math.floor(leave2/(60*1000));
  124. //计算相差秒数
  125. var td = "30秒前";
  126. if(days > 0){
  127. if (days > 10) {
  128. var date1year = date1.getFullYear();
  129. var date2year = date2.getFullYear();
  130. var date1month = date1.getMonth()+1;
  131. var date1day = date1.getDate();
  132. if(date1month < 10){
  133. date1month ="0"+date1month;
  134. }
  135. if(date1day < 10){
  136. date1day ="0"+date1day;
  137. }
  138. if (date1year<date2year){
  139. td = date1.getFullYear()+"-"+date1month+"-"+date1day;
  140. }else{
  141. td = date1month+"-"+date1day;
  142. }
  143. } else {
  144. td = days+"天前"
  145. }
  146. }else if(hours > 0){
  147. td = hours+"小时前";
  148. }else if(minutes > 0){
  149. td = minutes+"分钟前";
  150. }
  151. return td;
  152. }
  153. function redirect(zbadd,link,sid,sds){
  154. if(link != null && typeof(link) != "undefined"){
  155. link = link.replace(/\n/g,"");
  156. if(!/^http/.test(link)){
  157. link="http://"+link
  158. }
  159. }
  160. if(sds){
  161. window.location.href=zbadd+"/article/content/"+sid+".html?keywords="+encodeURIComponent(sds);
  162. }else{
  163. window.location.href=zbadd+"/article/content/"+sid+".html";
  164. }
  165. }
  166. function newredirect(zbadd,link,sid,sds,index){
  167. if(link != null && typeof(link) != "undefined"){
  168. link = link.replace(/\n/g,"");
  169. if(!/^http/.test(link)){
  170. link="http://"+link
  171. }
  172. }
  173. var pt = ""
  174. if (index==1){
  175. pt="projectMatch=项目匹配"
  176. }
  177. if(sds){
  178. pt = "&"+pt
  179. window.location.href=zbadd+"/article/content/"+sid+".html?keywords="+encodeURIComponent(sds)+pt;
  180. }else{
  181. window.location.href=zbadd+"/article/content/"+sid+".html"+pt;
  182. }
  183. }
  184. function pcredirect(link,sid){
  185. window.open("/pcdetail/"+sid+".html");
  186. }
  187. function keyWordHighlight(value,oldChars,newChar){
  188. if(typeof(oldChars) == "undefined" || oldChars == null || typeof(newChar) == "undefined" || newChar == null || newChar == ""){
  189. return value;
  190. }
  191. var array = [];
  192. if(oldChars instanceof Array){
  193. array = oldChars.concat();
  194. }else{
  195. array.push(oldChars);
  196. }
  197. try{
  198. var map = {};
  199. for(var i=0;i<array.length;i++){
  200. var oldChar = array[i];
  201. if(oldChar.replace(/\s+/g,"") == "" || map[oldChar]){
  202. continue;
  203. }
  204. map[oldChar] = true;
  205. oldChar = oldChar.replace(/\$/g,"\\$");
  206. oldChar = oldChar.replace(/\(/g,"\\(");
  207. oldChar = oldChar.replace(/\)/g,"\\)");
  208. oldChar = oldChar.replace(/\*/g,"\\*");
  209. oldChar = oldChar.replace(/\+/g,"\\+");
  210. oldChar = oldChar.replace(/\./g,"\\.");
  211. oldChar = oldChar.replace(/\[/g,"\\[");
  212. oldChar = oldChar.replace(/\]/g,"\\]");
  213. oldChar = oldChar.replace(/\?/g,"\\?");
  214. oldChar = oldChar.replace(/\\/g,"\\");
  215. oldChar = oldChar.replace(/\//g,"\\/");
  216. oldChar = oldChar.replace(/\^/g,"\\^");
  217. oldChar = oldChar.replace(/\{/g,"\\{");
  218. oldChar = oldChar.replace(/\}/g,"\\}");
  219. oldChar = oldChar.replace(/\|/g,"\\|");
  220. value = value.replace(new RegExp("("+oldChar+")",'gmi'),newChar);
  221. }
  222. }catch(e){}
  223. return value;
  224. }
  225. function getWxVersion(){
  226. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
  227. if(!wechatInfo) {
  228. return null;
  229. }
  230. return wechatInfo[1];
  231. }
  232. /**
  233. * 设置光标在短连接输入框中的位置
  234. * @param inpObj 输入框
  235. * @param pos
  236. */
  237. function setCursorPos(inpObj, pos){
  238. if(navigator.userAgent.indexOf("MSIE") > -1){
  239. var range = document.selection.createRange();
  240. var textRange = inpObj.createTextRange();
  241. textRange.moveStart('character',pos);
  242. textRange.collapse();
  243. textRange.select();
  244. }else{
  245. inpObj.setSelectionRange(pos,pos);
  246. }
  247. }
  248. /**
  249. * 获取光标在短连接输入框中的位置
  250. * @param inpObj 输入框
  251. */
  252. function getCursorPos(inpObj){
  253. if(navigator.userAgent.indexOf("MSIE") > -1) { // IE
  254. var range = document.selection.createRange();
  255. range.text = '';
  256. range.setEndPoint('StartToStart',inpObj.createTextRange());
  257. return range.text.length;
  258. } else {
  259. return inpObj.selectionStart;
  260. }
  261. }
  262. //获取url中参数
  263. function getUrlParam(name){
  264. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  265. var r = window.location.search.substr(1).match(reg);
  266. if(r != null)
  267. return unescape(r[2]);
  268. return null;
  269. }
  270. /******* 获取url参数(正则)********/
  271. function getParam(name) {
  272. var search = document.location.search;
  273. // alert(search);
  274. var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
  275. var matcher = pattern.exec(search);
  276. var items = null;
  277. if (null != matcher) {
  278. try {
  279. items = decodeURIComponent(decodeURIComponent(matcher[1]));
  280. } catch (e) {
  281. try {
  282. items = decodeURIComponent(matcher[1]);
  283. } catch (e) {
  284. items = matcher[1];
  285. }
  286. }
  287. }
  288. return items;
  289. };
  290. //获取滚动条宽度
  291. function getScrollWidth() {
  292. var noScroll, scroll, oDiv = document.createElement("DIV");
  293. oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
  294. noScroll = document.body.appendChild(oDiv).clientWidth;
  295. oDiv.style.overflowY = "scroll";
  296. scroll = oDiv.clientWidth;
  297. document.body.removeChild(oDiv);
  298. return noScroll-scroll;
  299. }
  300. //表头固定
  301. var TableHeadFixed = function(className,isminus,flag,pageName){
  302. if(typeof(className) == "undefined"){
  303. className = "tabContainer-2";
  304. }
  305. if(typeof(isminus) == "undefined"){
  306. isminus = true;
  307. }
  308. if(typeof(flag) == "undefined"){
  309. flag = true;
  310. }
  311. var cHeight = document.body.clientHeight;
  312. if(cHeight <= 0){
  313. cHeight = 500;
  314. }
  315. var thisFlag = false;
  316. var prevSelectType = null;
  317. $(window).scroll(function(event){
  318. if(!$("#right-table").hasClass("active") && flag){
  319. return;
  320. }
  321. //超级搜索页面增加处理逻辑
  322. if(pageName == "supsearch"){
  323. if(prevSelectType != selectType){
  324. thisFlag = false;
  325. }
  326. prevSelectType = selectType;
  327. if(selectType == "all"){
  328. className = "tabContainer"
  329. }else{
  330. className = "tabContainer-2";
  331. }
  332. }
  333. var tableHeight = $("."+className).outerHeight();
  334. if(tableHeight <= cHeight){
  335. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  336. $("."+className+" .lucene-table>table:first").css("top",0);
  337. thisFlag = false;
  338. return;
  339. }
  340. var offsetTop = $("."+className).offset().top;
  341. var scrollTop = $(this).scrollTop();
  342. var oTop = offsetTop;
  343. var ooTop = offsetTop;
  344. if(isminus){
  345. oTop+=20;
  346. ooTop-=20;
  347. }
  348. if(scrollTop >= oTop){
  349. if(ooTop + tableHeight - scrollTop -20 <= cHeight){
  350. if(!thisFlag){
  351. $("."+className+" .lucene-table").addClass("tababsolute");
  352. $("."+className+" .lucene-table>table:first").css("top",scrollTop);
  353. }
  354. thisFlag = true;
  355. }else{
  356. if(thisFlag){
  357. $("."+className+" .lucene-table").removeClass("tababsolute");
  358. $("."+className+" .lucene-table>table:first").css("top",0);
  359. }
  360. thisFlag = false;
  361. }
  362. $("."+className+" .lucene-table").addClass("tabfixed");
  363. }else{
  364. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  365. $("."+className+" .lucene-table>table:first").css("top",0);
  366. thisFlag = false;
  367. }
  368. });
  369. }
  370. //页面跳转输入框光标位置
  371. function moveEnd(obj) {
  372. obj.focus();
  373. var len = obj.value.length;
  374. if (document.selection) {
  375. var sel = obj.createTextRange();
  376. sel.moveStart('character', len);
  377. sel.collapse();
  378. sel.select();
  379. } else if (typeof obj.selectionStart == 'number'
  380. && typeof obj.selectionEnd == 'number') {
  381. obj.selectionStart = obj.selectionEnd = len;
  382. }
  383. }
  384. function mySysIsIos(){
  385. return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  386. }
  387. $(function(){
  388. //自定义tap
  389. if("ontouchend" in document){
  390. $(document).on("touchstart", function(e) {
  391. var $target = $(e.target);
  392. $target.data("isMoved", 0);
  393. $target.data("startTime", Date.now());
  394. });
  395. $(document).on("touchmove", function(e) {
  396. var $target = $(e.target);
  397. $target.data("isMoved", 1);
  398. });
  399. $(document).on("touchend", function(e) {
  400. var $target = $(e.target);
  401. var startTime = $target.data("startTime");
  402. if(Date.now()-startTime>200){
  403. return;
  404. }
  405. if($target.data("isMoved") == 1){
  406. return;
  407. }
  408. $target.trigger("tap");
  409. });
  410. }else{
  411. $(document).on("click", function(e) {
  412. var $target = $(e.target);
  413. $target.trigger("tap");
  414. });
  415. }
  416. });