Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $(".panel-body").each(addReadMore);
- $(".panel-body").dotdotdot({
- after: "a.readmore",
- watch: "window",
- height: 150,
- callback: function( isTruncated, orgContent ) {
- if(isTruncated){
- openModal($(this),orgContent);
- }
- }
- });
- });
- /*
- Adds Click Event to the specified element to open modal,
- also calls function to remove and generates the content of the modal
- */
- function openModal(element,orgContent){
- $(element.find("a.readmore")).on("click",function(){
- modalClear();
- var header = element.parent().children(".panel-heading").html();
- var body = orgContent.html();
- var footer = element.parent().children(".panel-footer").html();
- appendText(header,body,footer);
- $('#myModal').modal("show");
- });
- }
- //Adds content to the modal
- function appendText(header,body,footer){
- $('#myModal .modal-header').append(
- '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'+
- header
- );
- $('#myModal .modal-body').append(body);
- $('#myModal .modal-footer').append(
- footer+
- '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>'
- );
- }
- //Removes the content of the modal
- function modalClear(){
- $('#myModal .modal-header').empty();
- $('#myModal .modal-body').empty();
- $('#myModal .modal-footer').empty();
- }
- //Adds modal opener link to the panel if necessary
- function addReadMore(){
- if($(this).height()>150){
- $(this).append('<a title="read more" class="readmore">Read more »</a>');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement