yinheli.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. jQuery.getPos = function (e){
  2. var l = 0;
  3. var t = 0;
  4. var w = jQuery.intval(jQuery.css(e,'width'));
  5. var h = jQuery.intval(jQuery.css(e,'height'));
  6. var wb = e.offsetWidth;
  7. var hb = e.offsetHeight;
  8. while (e.offsetParent){
  9. l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
  10. t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
  11. e = e.offsetParent;
  12. }
  13. l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
  14. t += e.offsetTop + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
  15. return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
  16. };
  17. jQuery.getClient = function(e){
  18. if (e) {
  19. w = e.clientWidth;
  20. h = e.clientHeight;
  21. } else {
  22. w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document
  23. .body.offsetWidth;
  24. h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight :
  25. document.body.offsetHeight;
  26. }
  27. return {w:w,h:h};
  28. };
  29. jQuery.getScroll = function (e){
  30. if (e) {
  31. t = e.scrollTop;
  32. l = e.scrollLeft;
  33. w = e.scrollWidth;
  34. h = e.scrollHeight;
  35. } else {
  36. if (document.documentElement && document.documentElement.scrollTop) {
  37. t = document.documentElement.scrollTop;
  38. l = document.documentElement.scrollLeft;
  39. w = document.documentElement.scrollWidth;
  40. h = document.documentElement.scrollHeight;
  41. } else if (document.body) {
  42. t = document.body.scrollTop;
  43. l = document.body.scrollLeft;
  44. w = document.body.scrollWidth;
  45. h = document.body.scrollHeight;
  46. }
  47. }
  48. return { t: t, l: l, w: w, h: h };
  49. };
  50. jQuery.intval = function (v){
  51. v = parseInt(v);
  52. return isNaN(v) ? 0 : v;
  53. };
  54. jQuery.fn.ScrollTo = function(s){
  55. o = jQuery.speed(s);
  56. return this.each(function(){
  57. new jQuery.fx.ScrollTo(this, o);
  58. });
  59. };
  60. jQuery.fx.ScrollTo = function (e, o){
  61. var z = this;
  62. z.o = o;
  63. z.e = e;
  64. z.p = jQuery.getPos(e);
  65. z.s = jQuery.getScroll();
  66. z.clear = function(){
  67. clearInterval(z.timer);z.timer=null
  68. };
  69. z.t=(new Date).getTime();
  70. z.step = function(){
  71. var t = (new Date).getTime();
  72. var p = (t - z.t) / z.o.duration;
  73. if (t >= z.o.duration+z.t){
  74. z.clear();
  75. setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
  76. } else {
  77. st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
  78. sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
  79. z.scroll(st, sl);
  80. }
  81. };
  82. z.scroll = function (t, l){window.scrollTo(l, t)};
  83. z.timer=setInterval(function(){z.step();},13);
  84. };
  85. $(document).ready(function(){
  86. //switchTab
  87. $('#trackbacktab').click(function(){$(this).addClass('curtab');$('#commenttab').addClass('tab').removeClass('curtab');$('#thecomments').addClass('nodisplay');$('#thetrackbacks').removeClass('nodisplay').addClass('display')});
  88. $('#commenttab').click(function(){$(this).addClass('curtab');$('#trackbacktab').addClass('tab').removeClass('curtab');$('#thecomments').removeClass('nodisplay').addClass('display');$('#thetrackbacks').addClass('nodisplay')});
  89. //toggle-comment-author-info
  90. $('#show_author_info a').toggle(function(){$('#author_info').slideDown();$(this).html(closeMsg);},function(){$('#author_info').slideUp();$(this).html(changeMsg);});
  91. //reply
  92. $('#thecomments li').hover(function(){$(this).find('.reply').css('visibility','visible')},function(){$(this).find('.reply').css('visibility','hidden')});
  93. //Scroll
  94. $('.addcomment').click(function(){$('#respond').ScrollTo(800);return false; });
  95. $('#totop').click(function(){$('#header').ScrollTo(400);return false; });
  96. $('.reply a').click(function(){$($(this).attr('href')).ScrollTo(400);return false; });
  97. //clone tip
  98. var A=/^#comment-/;
  99. var B=/^@/;
  100. $('#thecomments li p a').each(function(){
  101. if($(this).attr('href').match(A)&& $(this).text().match(B)){
  102. $(this).addClass('cool');
  103. }
  104. });
  105. $('.cool').hover(
  106. function(){
  107. $($(this).attr('href')).clone().hide().attr('id','').insertAfter($(this).parents('li')).addClass('tip').fadeIn('fast');
  108. },
  109. function(){
  110. $('.tip').animate({opacity: "hide", top: "+=100px"},500,function(){$(this).remove()});
  111. });
  112. $('.cool').mousemove(
  113. function(e){
  114. $('.tip').css({left:(e.clientX+18),top:(e.pageY+18)});
  115. });
  116. $('.cool').click(function(){
  117. $($(this).attr('href')).ScrollTo(400);return false;
  118. });
  119. /*
  120. //out links
  121. $("a[rel='external']").click(function(){window.open(this.href);return false});
  122. $("a[href*='http://philna.com'],a[href*='javascript'],a:has(img),a[href*=#]").attr("rel","inlinks");
  123. $("a[rel!='inlinks']").click(function(){window.open(this.href);return false;});
  124. */
  125. //ajax reply
  126. if ($('#commentform').length){
  127. $('#commentform').submit(function(){
  128. $.ajax({
  129. url:ajaxCommentsURL,
  130. data: $('#commentform').serialize(),
  131. type: 'POST',
  132. beforeSend: function() {
  133. $('#commentload').hide();
  134. $('#commentload').fadeIn('fast');
  135. $('#submit').attr('disabled', true).css('opacity','0.5');
  136. $('#comment').attr('disabled', true);
  137. },
  138. error: function(request) {
  139. $('#commentload').fadeOut('fast');
  140. alert(request.responseText);
  141. $('#submit').attr('disabled', false).css('opacity','1');
  142. $('#comment').attr('disabled', false);
  143. },
  144. success:function(data){
  145. $('textarea').each(function(){this.value='';});
  146. if (!$('#thecomments').length ){
  147. $('#pinglist').before('<ol class="commentlist"></ol>');
  148. }
  149. $('#thecomments').append(data);
  150. var new_comment = $('#thecomments li:last').hide();
  151. new_comment.animate({backgroundColor: '#B1D0ED'},500).animate({opacity:'show'},500).animate({backgroundColor:'#FFF'},1000);
  152. $('.nub').text(parseInt($('#allcmnub').text())+1).removeClass('nub').addClass('cmnub');
  153. $('#allcmnub').text(parseInt($('#allcmnub').text())+1);
  154. $('#commentload').fadeOut('fast');
  155. setTimeout(function() {$('#submit').attr('disabled', false).css('opacity','1');$('#comment').attr('disabled', false);}, 3000);
  156. }
  157. });
  158. return false;
  159. });
  160. };
  161. })