PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/media/themes/fusion-xhtml/js/fusion.js

https://github.com/calvinchengx/O-Kay-Blog-wih-Kay-0.10.0
JavaScript | 219 lines | 184 code | 19 blank | 16 comment | 53 complexity | 444dd549577906da61e5dad54cd2308d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // cookie functions
  2. jQuery.cookie = function(name, value, options) {
  3. if (typeof value != 'undefined') { // name and value given, set cookie
  4. options = options || {};
  5. if (value === null) {
  6. value = '';
  7. options = jQuery.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
  8. options.expires = -1;
  9. }
  10. var expires = '';
  11. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  12. var date;
  13. if (typeof options.expires == 'number') {
  14. date = new Date();
  15. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  16. } else {
  17. date = options.expires;
  18. }
  19. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  20. }
  21. // NOTE Needed to parenthesize options.path and options.domain
  22. // in the following expressions, otherwise they evaluate to undefined
  23. // in the packed version for some reason...
  24. var path = options.path ? '; path=' + (options.path) : '';
  25. var domain = options.domain ? '; domain=' + (options.domain) : '';
  26. var secure = options.secure ? '; secure' : '';
  27. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  28. } else { // only name given, get cookie
  29. var cookieValue = null;
  30. if (document.cookie && document.cookie != '') {
  31. var cookies = document.cookie.split(';');
  32. for (var i = 0; i < cookies.length; i++) {
  33. var cookie = jQuery.trim(cookies[i]);
  34. // Does this cookie string begin with the name we want?
  35. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  36. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  37. break;
  38. }
  39. }
  40. }
  41. return cookieValue;
  42. }
  43. };
  44. // /cookie functions
  45. // fixes for IE-7 cleartype bug on fade in/out
  46. jQuery.fn.fadeIn = function(speed, callback) {
  47. return this.animate({opacity: 'show'}, speed, function() {
  48. if (jQuery.browser.msie) this.style.removeAttribute('filter');
  49. if (jQuery.isFunction(callback)) callback();
  50. });
  51. };
  52. jQuery.fn.fadeOut = function(speed, callback) {
  53. return this.animate({opacity: 'hide'}, speed, function() {
  54. if (jQuery.browser.msie) this.style.removeAttribute('filter');
  55. if (jQuery.isFunction(callback)) callback();
  56. });
  57. };
  58. jQuery.fn.fadeTo = function(speed,to,callback) {
  59. return this.animate({opacity: to}, speed, function() {
  60. if (to == 1 && jQuery.browser.msie) this.style.removeAttribute('filter');
  61. if (jQuery.isFunction(callback)) callback();
  62. });
  63. };
  64. // liquid <> fixed
  65. function setPageWidth(){
  66. var currentWidth = jQuery('#page').css('width');
  67. if (currentWidth=="95%") newWidth = "960px"; else if (currentWidth=="960px") newWidth = "95%"; else newWidth = "960px";
  68. jQuery("#page").animate({width: newWidth}, 333).fadeIn("slow");
  69. jQuery.cookie('pageWidth', newWidth);
  70. }
  71. // body font size
  72. function setFontSize() {
  73. var size = jQuery.cookie('fontSize');
  74. if (size=='.8em') newSize = '.95em';
  75. else if (size=='.95em') newSize = '.7em';
  76. else if (size=='.7em') newSize = '.8em';
  77. else newSize = '.95em';
  78. jQuery("body").animate({fontSize: newSize}, 333).fadeIn("slow");
  79. jQuery.cookie('fontSize',newSize)
  80. }
  81. // minitabs
  82. jQuery.fn.minitabs = function(speed,effect) {
  83. id = "#" + this.attr('id')
  84. jQuery(id + ">DIV:gt(0)").hide();
  85. jQuery(id + ">UL>LI>A:first").addClass("current");
  86. jQuery(id + ">UL>LI>A").click(
  87. function(){
  88. jQuery(id + ">UL>LI>A").removeClass("current");
  89. jQuery(this).addClass("current");
  90. jQuery(this).blur();
  91. var re = /([_\-\w]+$)/i;
  92. var target = jQuery('#' + re.exec(this.href)[1]);
  93. var old = jQuery(id + ">DIV");
  94. switch (effect) {
  95. case 'fade':
  96. old.fadeOut(speed).fadeOut(speed);
  97. target.fadeIn(speed);
  98. break;
  99. case 'slide':
  100. old.slideUp(speed);
  101. target.fadeOut(speed).fadeIn(speed);
  102. break;
  103. default :
  104. old.hide(speed);
  105. target.show(speed)
  106. }
  107. return false;
  108. }
  109. );
  110. }
  111. function initTooltips(o) {
  112. var showTip = function() {
  113. var el = jQuery('.tip', this).css('display', 'block')[0];
  114. var ttHeight = jQuery(el).height();
  115. var ttOffset = el.offsetHeight;
  116. var ttTop = ttOffset + ttHeight;
  117. jQuery('.tip', this)
  118. .stop()
  119. .css({'opacity': 0, 'top': 2 - ttOffset})
  120. .animate({'opacity': 1, 'top': 18 - ttOffset}, 250);
  121. };
  122. var hideTip = function() {
  123. var self = this;
  124. var el = jQuery('.tip', this).css('display', 'block')[0];
  125. var ttHeight = jQuery(el).height();
  126. var ttOffset = el.offsetHeight;
  127. var ttTop = ttOffset + ttHeight;
  128. jQuery('.tip', this)
  129. .stop()
  130. .animate({'opacity': 0,'top': 10 - ttOffset}, 250, function() {
  131. el.hiding = false;
  132. jQuery(this).css('display', 'none');
  133. }
  134. );
  135. };
  136. jQuery('.tip').hover(
  137. function() { return false; },
  138. function() { return true; }
  139. );
  140. jQuery('.tiptrigger, #sidebar .cat-item').hover(
  141. function(){
  142. var self = this;
  143. showTip.apply(this);
  144. if (o.timeout) this.tttimeout = setTimeout(function() { hideTip.apply(self) } , o.timeout);
  145. },
  146. function() {
  147. clearTimeout(this.tttimeout);
  148. hideTip.apply(this);
  149. }
  150. );
  151. }
  152. function tabmenudropdowns(){
  153. jQuery(" #tabs ul ul ").css({display: "none"}); // Opera Fix
  154. jQuery(" #tabs li").hover(function(){
  155. jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(333);
  156. },function(){
  157. jQuery(this).find('ul:first').css({visibility: "hidden"});
  158. });
  159. }
  160. jQuery(document).ready(function(){
  161. // body .safari class
  162. if (jQuery.browser.safari) jQuery('body').addClass('safari');
  163. // layout controls
  164. jQuery("#layoutcontrol a").click(function() {
  165. switch (jQuery(this).attr("class")) {
  166. case 'setFont' : setFontSize(); break;
  167. case 'setLiquid' : setPageWidth(); break;
  168. }
  169. return false;
  170. });
  171. // set the font size from cookie
  172. var font_size = jQuery.cookie('fontSize');
  173. if (font_size == '.7em') { jQuery('body').css("font-size",".7em"); }
  174. if (font_size == '.95em') { jQuery('body').css("font-size",".95em"); }
  175. if (font_size == '.8em') { jQuery('body').css("font-size",".8em"); }
  176. // set the page width from cookie
  177. var page_width = jQuery.cookie('pageWidth');
  178. if (page_width) jQuery('#page').css('width', page_width);
  179. jQuery('#secondary-tabs').minitabs(333, 'slide');
  180. if (document.all && !window.opera && !window.XMLHttpRequest && jQuery.browser.msie) { var isIE6 = true; }
  181. else { var isIE6 = false;} ;
  182. jQuery.browser.msie6 = isIE6;
  183. if (!isIE6) {
  184. initTooltips({
  185. timeout: 6000
  186. });
  187. }
  188. tabmenudropdowns();
  189. // some jquery effects...
  190. jQuery('#sidebar ul.nav li ul li a').mouseover(function () {
  191. jQuery(this).animate({ marginLeft: "4px" }, 100 );
  192. });
  193. jQuery('#sidebar ul.nav li ul li a').mouseout(function () {
  194. jQuery(this).animate({ marginLeft: "0px" }, 100 );
  195. });
  196. // scroll to top
  197. jQuery("a#toplink").click(function(){
  198. jQuery('html, body').animate({scrollTop:0}, 'slow');
  199. });
  200. });