PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/content/src/main/content/jcr_root/etc/clientlibs/hdscorp/main/js/press-release.js

https://gitlab.com/amishra3/hdssvnrepo
JavaScript | 167 lines | 161 code | 5 blank | 1 comment | 26 complexity | 8199d8a176fc7699f34138ddfb1236c9 MD5 | raw file
  1. /*Global Namespace*/
  2. var hds = window.hds || {};
  3. (function(window, document, $, hds) {
  4. hds.pressrelease = {
  5. init: function(options) {
  6. var defaults = {
  7. countRelease: 10,
  8. }
  9. this.options = $.extend(defaults, options);
  10. hds.pressrelease.bindHTMLLoad();
  11. hds.pressrelease.bindEventsOnResize();
  12. hds.pressrelease.bindClick();
  13. hds.pressrelease.loadSubContent();
  14. hds.pressrelease.search();
  15. },
  16. loadCatagoryHTML: function() {
  17. hds.pressrelease.processHTML($('.archiveslinkLeft a').eq(0).attr('data-loadhtml'), 0);
  18. $('.archiveslinkLeft a').eq(0).addClass('active');
  19. $('.archiveslinkLeft a').eq(0).parent().addClass('active');
  20. },
  21. processHTML: function(url, index) {
  22. $("#loadPressAwrads").html(" ").load(url + " .load-pr-archives-list", function(responseText, textStatus) {
  23. if (textStatus === 'success' || textStatus === 'notmodified') {
  24. hds.pressrelease.loadSubContent();
  25. hds.pressrelease.bindHTMLLoad();
  26. }
  27. });
  28. },
  29. bindHTMLLoad: function() {
  30. if ($(window).width() < 991) {
  31. $('.archiveslinkLeft a').each(function() {
  32. if ($(this).hasClass('active')) {
  33. $(this).parent('li').find('.MobileHolderWrapper').append($('#contentCatagory').html());
  34. $('#contentCatagory').empty();
  35. }
  36. });
  37. } else {
  38. $('.archiveslinkLeft a').each(function() {
  39. if ($(this).hasClass('active')) {
  40. $('#contentCatagory').append($(this).parent('li').find('.MobileHolderWrapper').html());
  41. $('.MobileHolderWrapper').empty();
  42. }
  43. })
  44. }
  45. },
  46. loadSubContent: function() {
  47. var sizeCatagoryList = $(".pr-list-container .pr").size(),
  48. x = this.options.countRelease;
  49. $('.pr:lt(' + x + ')').show();
  50. if (sizeCatagoryList <= x ) {
  51. $('#loadMorePrBtn').hide();
  52. }else{
  53. $('#loadMorePrBtn').show();
  54. }
  55. },
  56. loadMorePressRelease: function() {
  57. sizePrList = $(".pr-list-container .pr").size();
  58. var x = $(".pr:visible").size();
  59. x = (x + 10 <= sizePrList) ? x + 10 : sizePrList;
  60. $('.pr:lt(' + x + ')').show('medium');
  61. if (x == sizePrList) {
  62. $('#loadMorePrBtn').hide();
  63. }
  64. },
  65. bindEventsOnResize: function() {
  66. $(window).resize(function() {
  67. hds.pressrelease.bindHTMLLoad();
  68. });
  69. },
  70. search:function(){
  71. var searchTermPreValue="";
  72. var searchTerm = $.trim($('#fulltext').val());
  73. if(searchTerm!=searchTermPreValue){
  74. var activeFilterURL = $('#archivesLinks li.active a').attr('data-loadhtml');
  75. var loadIndec = $('#archivesLinks li.active a').parent().index();
  76. var fulltextSearchURL = activeFilterURL+"?fulltext="+encodeURIComponent(searchTerm);
  77. hds.pressrelease.processHTML(fulltextSearchURL, loadIndec);
  78. }
  79. searchTermPreValue = searchTerm;
  80. },
  81. setHTMLContainer: function() {
  82. if ($(window).width() < 991) {
  83. $('#archivesLinks li').each(function() {
  84. if ($.trim($(this).find('.MobileHolderWrapper').html())) {
  85. $('#contentCatagory').append($(this).find('.MobileHolderWrapper').html());
  86. $(this).find('.MobileHolderWrapper').slideUp('slow').empty();
  87. $('.MobileHolderWrapper').removeAttr('style');
  88. }
  89. });
  90. }
  91. },
  92. bindClick: function() {
  93. $(document).on('click','.archiveslinkLeft > a', function(event) {
  94. $('#fulltext').val('');
  95. var self = $(this);
  96. if (!$(this).hasClass('active')) {
  97. hds.pressrelease.setHTMLContainer();
  98. $('.archiveslinkLeft a').removeClass('active');
  99. $('.archiveslinkLeft a').parent().removeClass('active');
  100. var loadUrl = $(this).attr('data-loadhtml'),
  101. loadIndec = $(this).parent().index();
  102. $(this).addClass('active');
  103. $(this).parent().addClass('active');
  104. var offsetFirst=$($('.archiveslinkLeft:eq(0)')).offset().top;
  105. var clickedIndexHeight= $(this).outerHeight();
  106. var clickedIndex= $(this).parent().index();
  107. var finalIndex=offsetFirst+(clickedIndexHeight*clickedIndex);
  108. if($(window).width() < 991){
  109. $("body, html").animate({
  110. scrollTop: finalIndex
  111. }, 600);
  112. }
  113. hds.pressrelease.processHTML(loadUrl, loadIndec);
  114. } else{
  115. return false;
  116. }
  117. event.preventDefault();
  118. });
  119. $(document).on('click','.pr-search .glyphicon-search', function(event) {
  120. hds.pressrelease.search();
  121. setTimeout(function() {
  122. if ($(".pr:visible").length === 0) {
  123. $('#loadPressAwrads').find('.no-matched-result').remove();
  124. $('#loadPressAwrads').append('<div class="no-matched-result" style="padding: 50px 0; text-align: center;"><strong>Can’t Find What You’re Looking For?</strong><br>Please change your search criteria and try again.</div>');
  125. }
  126. }, 1000);
  127. });
  128. $(document).on('keypress', '#fulltext', function(event) {
  129. var keycode = (event.keyCode ? event.keyCode : event.which);
  130. if(keycode == 13){
  131. hds.pressrelease.search();
  132. setTimeout(function() {
  133. if ($(".pr:visible").length === 0) {
  134. $('#loadPressAwrads').find('.no-matched-result').remove();
  135. $('#loadPressAwrads').append('<div class="no-matched-result" style="padding: 50px 0; text-align: center;"><strong>Can’t Find What You’re Looking For?</strong><br>Please change your search criteria and try again.</div>');
  136. }
  137. }, 1000);
  138. }
  139. });
  140. $(document).on('keydown', '#fulltext', function(event) {
  141. var key = event.keyCode || event.charCode;
  142. var getSearchFilter = $.trim($(this).val());
  143. if( key == 8 || key == 46 ){
  144. if (getSearchFilter.length <= 1) {
  145. var activeFilterURL = $('#archivesLinks li.active a').attr('data-loadhtml');
  146. var loadIndec = $('#archivesLinks li.active a').parent().index();
  147. var fulltextSearchURL = activeFilterURL;
  148. hds.pressrelease.processHTML(fulltextSearchURL, loadIndec);
  149. }
  150. }
  151. })
  152. $(document).on('click','#loadMorePrBtn', function() {
  153. hds.pressrelease.loadMorePressRelease();
  154. })
  155. }
  156. }
  157. }(window, document, jQuery, hds));
  158. $(function() {
  159. if ( $('.pr-list-container').length > 0){
  160. hds.pressrelease.init();
  161. }
  162. })