cff-scripts.js
53 lines
| 1 | jQuery(document).ready(function() { |
| 2 | |
| 3 | jQuery('#cff .cff-item').each(function(){ |
| 4 | var $self = jQuery(this); |
| 5 | |
| 6 | //Wpautop fix |
| 7 | if( $self.find('.cff-viewpost').parent('p').length ){ |
| 8 | $self.find('.cff-viewpost').unwrap('p'); |
| 9 | } |
| 10 | if( $self.find('.cff-author').parent('p').length ){ |
| 11 | $self.find('.cff-author').eq(1).unwrap('p'); |
| 12 | $self.find('.cff-author').eq(1).remove(); |
| 13 | } |
| 14 | if( $self.find('#cff .cff-link').parent('p').length ){ |
| 15 | $self.find('#cff .cff-link').unwrap('p'); |
| 16 | } |
| 17 | |
| 18 | //Expand post |
| 19 | var expanded = false, |
| 20 | $post_text = $self.find('.cff-post-text .cff-text'), |
| 21 | text_limit = $self.closest('#cff').attr('rel'); |
| 22 | if (typeof text_limit === 'undefined' || text_limit == '') text_limit = 99999; |
| 23 | |
| 24 | //If the text is linked then use the text within the link |
| 25 | if ( $post_text.find('a.cff-post-text-link').length ) $post_text = $self.find('.cff-post-text .cff-text a'); |
| 26 | var full_text = $post_text.html(); |
| 27 | if(full_text == undefined) full_text = ''; |
| 28 | var short_text = full_text.substring(0,text_limit); |
| 29 | |
| 30 | //Cut the text based on limits set |
| 31 | $post_text.html( short_text ); |
| 32 | //Show the 'See More' link if needed |
| 33 | if (full_text.length > text_limit) $self.find('.cff-expand').show(); |
| 34 | //Click function |
| 35 | $self.find('.cff-expand a').click(function(e){ |
| 36 | e.preventDefault(); |
| 37 | var $expand = jQuery(this), |
| 38 | $more = $expand.find('.cff-more'), |
| 39 | $less = $expand.find('.cff-less'); |
| 40 | if (expanded == false){ |
| 41 | $post_text.html( full_text ); |
| 42 | expanded = true; |
| 43 | $more.hide(); |
| 44 | $less.show(); |
| 45 | } else { |
| 46 | $post_text.html( short_text ); |
| 47 | expanded = false; |
| 48 | $more.show(); |
| 49 | $less.hide(); |
| 50 | } |
| 51 | }); |
| 52 | }); |
| 53 | }); |