Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. //-----------------------------------
  2. // Function - Expandable Icon Box
  3. //-----------------------------------
  4. function expandableIconBox(){
  5. ?>
  6. <script>
  7. jQuery(document).ready(function() {
  8.  
  9. // Configuration
  10. var excerptLength = 140; // Excerpt text length
  11. var ellipses = "...";
  12. var moreTxt = "Show more >";
  13. var lessTxt = "Show less";
  14. var iconBox = jQuery(".iconbox_content_container");
  15.  
  16. jQuery('.iconbox_content_container p').each(function(){
  17.  
  18. var shortTxt = jQuery(this).text().substring(0, excerptLength);
  19. var hiddenTxt = jQuery(this).text().substring(excerptLength);
  20. var fullText = jQuery(this).text();
  21.  
  22. if(fullText.length > excerptLength) {
  23. jQuery(this).html( shortTxt + '<span class="ellipses">' + ellipses + '</span>' + '<span class="hiddenTxt hideThis">' + hiddenTxt + '</span> </br> <span class="toggleTxt"> ' + moreTxt + '</span> ');
  24. }
  25. else {
  26. jQuery(this).text(shortTxt);
  27. }
  28.  
  29. });
  30.  
  31. jQuery('.toggleTxt').on('click', function(){
  32. jQuery(this).parentsUntil(iconBox).find('.hiddenTxt').toggleClass('hideThis');
  33. jQuery(this).parentsUntil(iconBox).find('.ellipses').toggleClass("hideThis");
  34. jQuery(this).text(function(i, text){
  35. return text === lessTxt ? moreTxt : lessTxt ;
  36. });
  37. });
  38.  
  39. });
  40. </script>
  41. <?php
  42. }
  43. add_action('wp_footer', 'expandableIconBox');
Add Comment
Please, Sign In to add comment