common.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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"){
  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).onclick = 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. link = link.replace(/\n/g,"");
  155. if(!/^http/.test(link)){
  156. link="http://"+link
  157. }
  158. if(sds){
  159. window.location.href=zbadd+"/article/content/"+sid+".html?keywords="+encodeURIComponent(sds);
  160. }else{
  161. window.location.href=zbadd+"/article/content/"+sid+".html?";
  162. }
  163. }
  164. function newredirect(zbadd,link,sid,sds){
  165. if(link != null && typeof(link) != "undefined"){
  166. link = link.replace(/\n/g,"");
  167. if(!/^http/.test(link)){
  168. link="http://"+link
  169. }
  170. }
  171. if(sds){
  172. window.location.href=zbadd+"/article/content/"+sid+".html?keywords="+encodeURIComponent(sds);
  173. }else{
  174. window.location.href=zbadd+"/article/content/"+sid+".html";
  175. }
  176. }
  177. function pcredirect(link,sid){
  178. window.open("/pcdetail/"+sid+".html");
  179. }
  180. function keyWordHighlight(value,oldChars,newChar){
  181. if(typeof(oldChars) == "undefined" || oldChars == null || typeof(newChar) == "undefined" || newChar == null || newChar == ""){
  182. return value;
  183. }
  184. var array = [];
  185. if(oldChars instanceof Array){
  186. array = oldChars.concat();
  187. }else{
  188. array.push(oldChars);
  189. }
  190. try{
  191. var map = {};
  192. for(var i=0;i<array.length;i++){
  193. var oldChar = array[i];
  194. if(oldChar.replace(/\s+/g,"") == "" || map[oldChar]){
  195. continue;
  196. }
  197. map[oldChar] = true;
  198. oldChar = oldChar.replace(/\$/g,"\\$");
  199. oldChar = oldChar.replace(/\(/g,"\\(");
  200. oldChar = oldChar.replace(/\)/g,"\\)");
  201. oldChar = oldChar.replace(/\*/g,"\\*");
  202. oldChar = oldChar.replace(/\+/g,"\\+");
  203. oldChar = oldChar.replace(/\./g,"\\.");
  204. oldChar = oldChar.replace(/\[/g,"\\[");
  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. value = value.replace(new RegExp("("+oldChar+")",'gmi'),newChar);
  214. }
  215. }catch(e){}
  216. return value;
  217. }
  218. function getWxVersion(){
  219. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
  220. if(!wechatInfo) {
  221. return null;
  222. }
  223. return wechatInfo[1];
  224. }
  225. /**
  226. * 设置光标在短连接输入框中的位置
  227. * @param inpObj 输入框
  228. * @param pos
  229. */
  230. function setCursorPos(inpObj, pos){
  231. if(navigator.userAgent.indexOf("MSIE") > -1){
  232. var range = document.selection.createRange();
  233. var textRange = inpObj.createTextRange();
  234. textRange.moveStart('character',pos);
  235. textRange.collapse();
  236. textRange.select();
  237. }else{
  238. inpObj.setSelectionRange(pos,pos);
  239. }
  240. }
  241. /**
  242. * 获取光标在短连接输入框中的位置
  243. * @param inpObj 输入框
  244. */
  245. function getCursorPos(inpObj){
  246. if(navigator.userAgent.indexOf("MSIE") > -1) { // IE
  247. var range = document.selection.createRange();
  248. range.text = '';
  249. range.setEndPoint('StartToStart',inpObj.createTextRange());
  250. return range.text.length;
  251. } else {
  252. return inpObj.selectionStart;
  253. }
  254. }
  255. //获取url中参数
  256. function getUrlParam(name){
  257. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  258. var r = window.location.search.substr(1).match(reg);
  259. if(r != null)
  260. return unescape(r[2]);
  261. return null;
  262. }
  263. //获取滚动条宽度
  264. function getScrollWidth() {
  265. var noScroll, scroll, oDiv = document.createElement("DIV");
  266. oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
  267. noScroll = document.body.appendChild(oDiv).clientWidth;
  268. oDiv.style.overflowY = "scroll";
  269. scroll = oDiv.clientWidth;
  270. document.body.removeChild(oDiv);
  271. return noScroll-scroll;
  272. }
  273. //表头固定
  274. var TableHeadFixed = function(className,isminus,flag,pageName){
  275. if(typeof(className) == "undefined"){
  276. className = "tabContainer-2";
  277. }
  278. if(typeof(isminus) == "undefined"){
  279. isminus = true;
  280. }
  281. if(typeof(flag) == "undefined"){
  282. flag = true;
  283. }
  284. var cHeight = document.body.clientHeight;
  285. if(cHeight <= 0){
  286. cHeight = 500;
  287. }
  288. var thisFlag = false;
  289. var prevSelectType = null;
  290. $(window).scroll(function(event){
  291. if(!$("#right-table").hasClass("active") && flag){
  292. return;
  293. }
  294. //超级搜索页面增加处理逻辑
  295. if(pageName == "supsearch"){
  296. if(prevSelectType != selectType){
  297. thisFlag = false;
  298. }
  299. prevSelectType = selectType;
  300. if(selectType == "all"){
  301. className = "tabContainer"
  302. }else{
  303. className = "tabContainer-2";
  304. }
  305. }
  306. var tableHeight = $("."+className).outerHeight();
  307. if(tableHeight <= cHeight){
  308. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  309. $("."+className+" .lucene-table>table:first").css("top",0);
  310. thisFlag = false;
  311. return;
  312. }
  313. var offsetTop = $("."+className).offset().top;
  314. var scrollTop = $(this).scrollTop();
  315. var oTop = offsetTop;
  316. var ooTop = offsetTop;
  317. if(isminus){
  318. oTop+=20;
  319. ooTop-=20;
  320. }
  321. if(scrollTop >= oTop){
  322. if(ooTop + tableHeight - scrollTop -20 <= cHeight){
  323. if(!thisFlag){
  324. $("."+className+" .lucene-table").addClass("tababsolute");
  325. $("."+className+" .lucene-table>table:first").css("top",scrollTop);
  326. }
  327. thisFlag = true;
  328. }else{
  329. if(thisFlag){
  330. $("."+className+" .lucene-table").removeClass("tababsolute");
  331. $("."+className+" .lucene-table>table:first").css("top",0);
  332. }
  333. thisFlag = false;
  334. }
  335. $("."+className+" .lucene-table").addClass("tabfixed");
  336. }else{
  337. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  338. $("."+className+" .lucene-table>table:first").css("top",0);
  339. thisFlag = false;
  340. }
  341. });
  342. }
  343. //页面跳转输入框光标位置
  344. function moveEnd(obj) {
  345. obj.focus();
  346. var len = obj.value.length;
  347. if (document.selection) {
  348. var sel = obj.createTextRange();
  349. sel.moveStart('character', len);
  350. sel.collapse();
  351. sel.select();
  352. } else if (typeof obj.selectionStart == 'number'
  353. && typeof obj.selectionEnd == 'number') {
  354. obj.selectionStart = obj.selectionEnd = len;
  355. }
  356. }