PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/js/k2.functions.js

http://adadvantage.googlecode.com/
JavaScript | 227 lines | 130 code | 45 blank | 52 comment | 34 complexity | f29c97d30ae1176ad68ce703772cd9a5 MD5 | raw file
  1. jQuery.noConflict();
  2. if (typeof K2 == 'undefined') var K2 = {};
  3. K2.debug = false;
  4. //
  5. //K2.prototype.ajaxComplete = [];
  6. K2.ajaxGet = function(data, complete_fn) {
  7. jQuery.ajax({
  8. url: K2.AjaxURL,
  9. data: data,
  10. dataType: 'html',
  11. error: function(request) {
  12. jQuery('#notices')
  13. .show()
  14. .append('<p class="alert">Error ' + request.status + ': ' + request.statusText + '</p>');
  15. },
  16. success: function() {
  17. jQuery('#notices').hide().html();
  18. },
  19. complete: function(request) {
  20. // Disable obtrusive document.write
  21. document.write = function(str) {};
  22. if ( complete_fn ) {
  23. complete_fn( request.responseText );
  24. }
  25. // Lightbox v2.03.3 - Adds new images to lightbox
  26. if (typeof myLightbox != "undefined" && myLightbox instanceof Lightbox && myLightbox.updateImageList) {
  27. myLightbox.updateImageList();
  28. }
  29. /*
  30. if ( K2.callbacks && K2.callbacks.length > 0 ) {
  31. for ( var i = 0; i < K2.callbacks.length; i++ ) {
  32. K2.callbacks[i]();
  33. }
  34. }
  35. */
  36. // Inform JAWS
  37. updateBuffer();
  38. }
  39. });
  40. }
  41. function OnLoadUtils() {
  42. jQuery('#comment-personaldetails').hide();
  43. jQuery('#showinfo').show();
  44. jQuery('#hideinfo').hide();
  45. };
  46. function ShowUtils() {
  47. jQuery('#comment-personaldetails').slideDown();
  48. jQuery('#showinfo').hide();
  49. jQuery('#hideinfo').show();
  50. };
  51. function HideUtils() {
  52. jQuery('#comment-personaldetails').slideUp();
  53. jQuery('#showinfo').show();
  54. jQuery('#hideinfo').hide();
  55. };
  56. /* Fix the position of an element when it is about to be scrolled off-screen */
  57. function smartPosition(obj) {
  58. if ( jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 ) {
  59. return;
  60. }
  61. jQuery(window).scroll(function() {
  62. // Detect if content is being scroll offscreen.
  63. if ( (document.documentElement.scrollTop || document.body.scrollTop) >= jQuery(obj).offset().top) {
  64. jQuery('body').addClass('smartposition');
  65. } else {
  66. jQuery('body').removeClass('smartposition');
  67. }
  68. });
  69. };
  70. // Set the number of columns based on window size
  71. function dynamicColumns() {
  72. var window_width = jQuery(window).width();
  73. if ( window_width >= (K2.layoutWidths[2] + 20) ) {
  74. jQuery('body').removeClass('columns-one columns-two').addClass('columns-three');
  75. } else if ( window_width >= (K2.layoutWidths[1] + 20) ) {
  76. jQuery('body').removeClass('columns-one columns-three').addClass('columns-two');
  77. } else {
  78. jQuery('body').removeClass('columns-two columns-three').addClass('columns-one');
  79. }
  80. };
  81. /*
  82. Improving Ajax applications for JAWS users
  83. http://juicystudio.com/article/improving-ajax-applications-for-jaws-users.php
  84. */
  85. function prepareBuffer() {
  86. var objNew = document.createElement('p');
  87. var objHidden = document.createElement('input');
  88. objHidden.setAttribute('type', 'hidden');
  89. objHidden.setAttribute('value', '1');
  90. objHidden.setAttribute('id', 'virtualbufferupdate');
  91. objHidden.setAttribute('name', 'virtualbufferupdate');
  92. objNew.appendChild(objHidden);
  93. document.body.appendChild(objNew);
  94. };
  95. function updateBuffer() {
  96. var objHidden = document.getElementById('virtualbufferupdate');
  97. if (objHidden) {
  98. if (objHidden.getAttribute('value') == '1')
  99. objHidden.setAttribute('value', '0');
  100. else
  101. objHidden.setAttribute('value', '1');
  102. }
  103. };
  104. jQuery(document).ready(function(){
  105. prepareBuffer();
  106. });
  107. function initOverLabels () {
  108. if (!document.getElementById) return;
  109. var labels, id, field;
  110. // Set focus and blur handlers to hide and show
  111. // labels with 'overlabel' class names.
  112. labels = document.getElementsByTagName('label');
  113. for (var i = 0; i < labels.length; i++) {
  114. if (labels[i].className == 'overlabel') {
  115. // Skip labels that do not have a named association
  116. // with another field.
  117. id = labels[i].htmlFor || labels[i].getAttribute('for');
  118. if (!id || !(field = document.getElementById(id))) {
  119. continue;
  120. }
  121. // Change the applied class to hover the label
  122. // over the form field.
  123. labels[i].className = 'overlabel-apply';
  124. // Hide any fields having an initial value.
  125. if (field.value !== '') {
  126. hideLabel(field.getAttribute('id'), true);
  127. }
  128. // Set handlers to show and hide labels.
  129. field.onfocus = function () {
  130. hideLabel(this.getAttribute('id'), true);
  131. };
  132. field.onblur = function () {
  133. if (this.value === '') {
  134. hideLabel(this.getAttribute('id'), false);
  135. }
  136. };
  137. // Handle clicks to label elements (for Safari).
  138. labels[i].onclick = function () {
  139. var id, field;
  140. id = this.getAttribute('for');
  141. if (id && (field = document.getElementById(id))) {
  142. field.focus();
  143. }
  144. };
  145. }
  146. }
  147. };
  148. function hideLabel(field_id, hide) {
  149. var field_for;
  150. var labels = document.getElementsByTagName('label');
  151. for (var i = 0; i < labels.length; i++) {
  152. field_for = labels[i].htmlFor || labels[i].getAttribute('for');
  153. if (field_for == field_id) {
  154. labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
  155. return true;
  156. }
  157. }
  158. };
  159. /*
  160. jQuery('.attachment-image').ready(function(){
  161. resizeImage('.image-link img', '#page', 20);
  162. });
  163. jQuery(window).resize(function(){
  164. resizeImage('.image-link img', '#page', 20);
  165. });
  166. function resizeImage(image, container, padding) {
  167. var imageObj = jQuery(image);
  168. var containerObj = jQuery(container);
  169. var imgWidth = imageObj.width();
  170. var imgHeight = imageObj.height();
  171. var contentWidth = containerObj.width() - padding;
  172. var ratio = contentWidth / imgWidth;
  173. imageObj.width(contentWidth).height(imgHeight * ratio);
  174. console.log('resized to a ratio of ' + ratio);
  175. }
  176. */