Advertisement
Guest User

test

a guest
Jul 22nd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     $(".panel-body").each(addReadMore);
  3.     $(".panel-body").dotdotdot({
  4.         after: "a.readmore",
  5.         watch: "window",
  6.         height: 150,
  7.         callback: function( isTruncated, orgContent ) {
  8.             if(isTruncated){
  9.                 openModal($(this),orgContent);
  10.             }
  11.         }
  12.  
  13.     });
  14. });
  15.  
  16. /*
  17.     Adds Click Event to the specified element to open modal,
  18.     also calls function to remove and generates the content of the modal
  19. */
  20. function openModal(element,orgContent){
  21.     $(element.find("a.readmore")).on("click",function(){
  22.         modalClear();
  23.         var header = element.parent().children(".panel-heading").html();
  24.         var body = orgContent.html();
  25.         var footer = element.parent().children(".panel-footer").html();
  26.         appendText(header,body,footer);
  27.         $('#myModal').modal("show");
  28.     });
  29. }
  30. //Adds content to the modal
  31. function appendText(header,body,footer){
  32.     $('#myModal .modal-header').append(
  33.         '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>'+
  34.         header
  35.     );
  36.     $('#myModal .modal-body').append(body);
  37.     $('#myModal .modal-footer').append(
  38.         footer+
  39.         '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>'
  40.     );
  41. }
  42. //Removes the content of the modal
  43. function modalClear(){
  44.     $('#myModal .modal-header').empty();
  45.     $('#myModal .modal-body').empty();
  46.     $('#myModal .modal-footer').empty();
  47. }
  48. //Adds modal opener link to the panel if necessary
  49. function addReadMore(){
  50.     if($(this).height()>150){
  51.         $(this).append('<a title="read more" class="readmore">Read more »</a>');
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement