PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/k2/js/k2.functions.js

https://bitbucket.org/chileagil/website
JavaScript | 190 lines | 110 code | 34 blank | 46 comment | 27 complexity | 107df11098af254dea2d98d4222daa01 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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. /*
  26. if ( K2.callbacks && K2.callbacks.length > 0 ) {
  27. for ( var i = 0; i < K2.callbacks.length; i++ ) {
  28. K2.callbacks[i]();
  29. }
  30. }
  31. */
  32. }
  33. });
  34. }
  35. function OnLoadUtils() {
  36. jQuery('#comment-personaldetails').hide();
  37. jQuery('#showinfo').show();
  38. jQuery('#hideinfo').hide();
  39. };
  40. function ShowUtils() {
  41. jQuery('#comment-personaldetails').slideDown();
  42. jQuery('#showinfo').hide();
  43. jQuery('#hideinfo').show();
  44. };
  45. function HideUtils() {
  46. jQuery('#comment-personaldetails').slideUp();
  47. jQuery('#showinfo').show();
  48. jQuery('#hideinfo').hide();
  49. };
  50. /* Fix the position of an element when it is about to be scrolled off-screen */
  51. function smartPosition(obj) {
  52. if ( jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 ) return;
  53. jQuery(window).scroll(function() {
  54. // Detect if content is being scroll offscreen.
  55. if ( (document.documentElement.scrollTop || document.body.scrollTop) >= jQuery(obj).offset().top) {
  56. jQuery('body').addClass('smartposition');
  57. } else {
  58. jQuery('body').removeClass('smartposition');
  59. }
  60. });
  61. };
  62. // Set the number of columns based on window size
  63. function dynamicColumns() {
  64. var window_width = jQuery(window).width();
  65. if ( window_width >= (K2.layoutWidths[2] + 20) ) {
  66. jQuery('body').removeClass('columns-one columns-two').addClass('columns-three');
  67. } else if ( window_width >= (K2.layoutWidths[1] + 20) ) {
  68. jQuery('body').removeClass('columns-one columns-three').addClass('columns-two');
  69. } else {
  70. jQuery('body').removeClass('columns-two columns-three').addClass('columns-one');
  71. }
  72. };
  73. function initOverLabels () {
  74. if (!document.getElementById) return;
  75. var labels, id, field;
  76. // Set focus and blur handlers to hide and show
  77. // labels with 'overlabel' class names.
  78. labels = document.getElementsByTagName('label');
  79. for (var i = 0; i < labels.length; i++) {
  80. if (labels[i].className == 'overlabel') {
  81. // Skip labels that do not have a named association
  82. // with another field.
  83. id = labels[i].htmlFor || labels[i].getAttribute('for');
  84. if (!id || !(field = document.getElementById(id))) {
  85. continue;
  86. }
  87. // Change the applied class to hover the label
  88. // over the form field.
  89. labels[i].className = 'overlabel-apply';
  90. // Hide any fields having an initial value.
  91. if (field.value !== '') {
  92. hideLabel(field.getAttribute('id'), true);
  93. }
  94. // Set handlers to show and hide labels.
  95. field.onfocus = function () {
  96. hideLabel(this.getAttribute('id'), true);
  97. };
  98. field.onblur = function () {
  99. if (this.value === '') {
  100. hideLabel(this.getAttribute('id'), false);
  101. }
  102. };
  103. // Handle clicks to label elements (for Safari).
  104. labels[i].onclick = function () {
  105. var id, field;
  106. id = this.getAttribute('for');
  107. if (id && (field = document.getElementById(id))) {
  108. field.focus();
  109. }
  110. };
  111. }
  112. }
  113. };
  114. function hideLabel(field_id, hide) {
  115. var field_for;
  116. var labels = document.getElementsByTagName('label');
  117. for (var i = 0; i < labels.length; i++) {
  118. field_for = labels[i].htmlFor || labels[i].getAttribute('for');
  119. if (field_for == field_id) {
  120. labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
  121. return true;
  122. }
  123. }
  124. };
  125. /*
  126. jQuery('.attachment-image').ready(function(){
  127. resizeImage('.image-link img', '#page', 20);
  128. });
  129. jQuery(window).resize(function(){
  130. resizeImage('.image-link img', '#page', 20);
  131. });
  132. function resizeImage(image, container, padding) {
  133. var imageObj = jQuery(image);
  134. var containerObj = jQuery(container);
  135. var imgWidth = imageObj.width();
  136. var imgHeight = imageObj.height();
  137. var contentWidth = containerObj.width() - padding;
  138. var ratio = contentWidth / imgWidth;
  139. imageObj.width(contentWidth).height(imgHeight * ratio);
  140. console.log('resized to a ratio of ' + ratio);
  141. }
  142. */
  143. function initARIA() {
  144. jQuery('#header').attr('role', 'banner');
  145. jQuery('#header .menu').attr('role', 'navigation');
  146. jQuery('#primary').attr('role', 'main');
  147. jQuery('#rollingcontent').attr('aria-live', 'polite').attr('aria-atomic', 'true');
  148. jQuery('.secondary').attr('role', 'complementary');
  149. jQuery('#footer').attr('role', 'contentinfo');
  150. };