learning-opportunities done
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
12 changed files
with
278 additions
and
166 deletions
This diff is collapsed.
Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
| ... | @@ -4,8 +4,8 @@ | ... | @@ -4,8 +4,8 @@ |
| 4 | add_shortcode( 'promos', 'promos' ); | 4 | add_shortcode( 'promos', 'promos' ); |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | function promos() | 7 | function promos(){ |
| 8 | { | 8 | |
| 9 | $custom_args = array( | 9 | $custom_args = array( |
| 10 | 'post_type' => 'promo', | 10 | 'post_type' => 'promo', |
| 11 | 'posts_per_page' => 3, | 11 | 'posts_per_page' => 3, |
| ... | @@ -13,10 +13,11 @@ function promos() | ... | @@ -13,10 +13,11 @@ function promos() |
| 13 | ); | 13 | ); |
| 14 | $custom_query = new \WP_Query($custom_args); | 14 | $custom_query = new \WP_Query($custom_args); |
| 15 | 15 | ||
| 16 | ob_start(); | 16 | ob_start(); |
| 17 | $uniqid = uniqid(); | 17 | $uniqid = uniqid(); |
| 18 | if ($custom_query->have_posts()):?> | 18 | if ($custom_query->have_posts()):?> |
| 19 | <div class="carousel"> | 19 | |
| 20 | <div class="carousel"> | ||
| 20 | <div id="<?php echo $uniqid; ?>" class="promo-carousel carousel-items"> | 21 | <div id="<?php echo $uniqid; ?>" class="promo-carousel carousel-items"> |
| 21 | <div class='swiper-wrapper'> | 22 | <div class='swiper-wrapper'> |
| 22 | <?php while ($custom_query->have_posts()): $custom_query->the_post(); | 23 | <?php while ($custom_query->have_posts()): $custom_query->the_post(); |
| ... | @@ -28,15 +29,15 @@ function promos() | ... | @@ -28,15 +29,15 @@ function promos() |
| 28 | <div class="swiper-button-next" data-id="<?= $uniqid; ?>"></div> | 29 | <div class="swiper-button-next" data-id="<?= $uniqid; ?>"></div> |
| 29 | </div> | 30 | </div> |
| 30 | </div> | 31 | </div> |
| 31 | <?php endif; ?> | 32 | |
| 32 | <?php wp_reset_query(); ?> | 33 | <?php endif; |
| 33 | <?php $output = ob_get_clean(); | 34 | wp_reset_query(); |
| 34 | 35 | $output = ob_get_clean(); | |
| 35 | return $output; | 36 | return $output; |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | function promos_slides($id) | 39 | function promos_slides($id){ |
| 39 | { | 40 | |
| 40 | ob_start(); | 41 | ob_start(); |
| 41 | $post = get_post($id); | 42 | $post = get_post($id); |
| 42 | $link = get_permalink($id); | 43 | $link = get_permalink($id); |
| ... | @@ -49,8 +50,8 @@ function promos_slides($id) | ... | @@ -49,8 +50,8 @@ function promos_slides($id) |
| 49 | } | 50 | } |
| 50 | $text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content))); | 51 | $text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content))); |
| 51 | $excerpt_length = apply_filters( 'excerpt_length', 40 ); | 52 | $excerpt_length = apply_filters( 'excerpt_length', 40 ); |
| 52 | $text = wp_trim_words( $text, $excerpt_length, ' ...' ); | 53 | $text = wp_trim_words( $text, $excerpt_length, ' ...' );?> |
| 53 | ?> | 54 | |
| 54 | <div class="swiper-slide container"> | 55 | <div class="swiper-slide container"> |
| 55 | <div class="promo row align-items-center"> | 56 | <div class="promo row align-items-center"> |
| 56 | <div class="col-lg-4 col-md-12"> | 57 | <div class="col-lg-4 col-md-12"> |
| ... | @@ -75,8 +76,8 @@ return $output; | ... | @@ -75,8 +76,8 @@ return $output; |
| 75 | add_shortcode('share-this', 'share_this'); | 76 | add_shortcode('share-this', 'share_this'); |
| 76 | 77 | ||
| 77 | 78 | ||
| 78 | function share_this($atts) | 79 | function share_this($atts){ |
| 79 | { | 80 | |
| 80 | $atts = shortcode_atts(array( | 81 | $atts = shortcode_atts(array( |
| 81 | 'post_id' => '', | 82 | 'post_id' => '', |
| 82 | ), $atts, 'current-cover-articles'); | 83 | ), $atts, 'current-cover-articles'); |
| ... | @@ -107,8 +108,8 @@ return ob_get_clean(); | ... | @@ -107,8 +108,8 @@ return ob_get_clean(); |
| 107 | add_shortcode('course-list', 'course_list'); | 108 | add_shortcode('course-list', 'course_list'); |
| 108 | 109 | ||
| 109 | 110 | ||
| 110 | function course_list() | 111 | function course_list(){ |
| 111 | { | 112 | |
| 112 | $custom_args = array( | 113 | $custom_args = array( |
| 113 | 'post_type' => 'sfwd-courses', | 114 | 'post_type' => 'sfwd-courses', |
| 114 | 'posts_per_page' => -1, | 115 | 'posts_per_page' => -1, |
| ... | @@ -119,58 +120,68 @@ function course_list() | ... | @@ -119,58 +120,68 @@ function course_list() |
| 119 | ob_start(); | 120 | ob_start(); |
| 120 | $uniqid = uniqid(); | 121 | $uniqid = uniqid(); |
| 121 | if ($custom_query->have_posts()):?> | 122 | if ($custom_query->have_posts()):?> |
| 122 | <p><input type="text" class="quicksearch" placeholder="Search" /></p> | 123 | <div class="course-list"> |
| 123 | 124 | <label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" /> | |
| 124 | <div class="button-group filters-button-group"> | 125 | <div class="filters"> |
| 125 | <button class="button is-checked" data-filter="*">Clear</button> | 126 | <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a> |
| 126 | <button class="button" data-filter=".resilience-and-well-being">Resilience and Well-Being</button> | 127 | <div class="filter-group"> |
| 127 | <button class="button" data-filter=".leadership-and-teamwork">Leadership and Teamwork</button> | 128 | <div class="category-filter-group"> |
| 128 | <button class="button" data-filter=".clinical-skills">Clinical Skills</button> | 129 | <?php $terms = get_terms( array( 'taxonomy' => 'ld_course_category' ,'parent' => 0) ); |
| 129 | <button class="button" data-filter=".coaching-and-mentoring">Coaching and Mentoring</button> | 130 | foreach($terms as $term){ ?> |
| 131 | <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div> | ||
| 132 | <?php }; ?> | ||
| 133 | </div> | ||
| 134 | <div class="btn-group sort-button-group align-self-end"> | ||
| 135 | <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursename" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> | ||
| 136 | <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> | ||
| 137 | </div> | ||
| 138 | </div> | ||
| 130 | </div> | 139 | </div> |
| 131 | <div class="grid"> | 140 | <div class="grid"> |
| 132 | <?php while ($custom_query->have_posts()): $custom_query->the_post(); | 141 | <?php while ($custom_query->have_posts()): $custom_query->the_post(); |
| 133 | echo course_card(get_the_ID()); | 142 | echo course_card(get_the_ID()); |
| 134 | endwhile; ?> | 143 | endwhile; ?> |
| 135 | </div> | 144 | </div> |
| 145 | </div> | ||
| 136 | <?php endif; | 146 | <?php endif; |
| 137 | wp_reset_query(); | 147 | wp_reset_query(); |
| 138 | $output = ob_get_clean(); | 148 | $output = ob_get_clean(); |
| 139 | return $output; | 149 | return $output; |
| 140 | } | 150 | } |
| 141 | 151 | ||
| 142 | 152 | ||
| 143 | 153 | ||
| 144 | function course_card($id) | 154 | function course_card($id){ |
| 145 | { | 155 | |
| 146 | ob_start(); | 156 | ob_start(); |
| 147 | $post = get_post($id); | 157 | $post = get_post($id); |
| 148 | $link = get_permalink($id); | ||
| 149 | $text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content))); | 158 | $text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content))); |
| 150 | $excerpt_length = apply_filters( 'excerpt_length', 40 ); | 159 | $excerpt_length = apply_filters( 'excerpt_length', 20 ); |
| 151 | $text = wp_trim_words( $text, $excerpt_length, ' ...' ); | 160 | $text = wp_trim_words( $text, $excerpt_length, ' ...' ); |
| 152 | $categories = get_the_terms( $id, 'ld_course_category' ); | 161 | $categories = get_the_terms( $id, 'ld_course_category' ); |
| 153 | $cat =""; | 162 | $cat =""; foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?> |
| 154 | foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?> | 163 | |
| 155 | <div class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>"> | 164 | <div class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>"> |
| 156 | <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses"> | 165 | <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses"> |
| 157 | <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div> | 166 | <div class="card"> |
| 158 | <div class="image"> | 167 | <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div> |
| 159 | <a href="<?php echo $link; ?>" rel="bookmark"> <?php echo get_the_post_thumbnail($id, 'full' ); ?></a> | 168 | <div class="image"> |
| 160 | </div> | 169 | <?php echo get_the_post_thumbnail($id, 'full' ); ?> |
| 161 | </div> | 170 | </div> |
| 162 | <div class="content"> | 171 | </div> |
| 163 | <h3 class="entry-title"><a href="<?php echo $link; ?>"><?php echo $post->post_title; ?></a></h3> | 172 | <div class="content"> |
| 164 | <div class="entry-content"> | 173 | <h3 class="entry-title"><?php echo $post->post_title; ?></h3> |
| 165 | <p><?php echo $text; ?></p> | 174 | <div class="entry-content"> |
| 166 | </div> | 175 | <p><?php echo $text; ?></p> |
| 167 | <div class="button"> | 176 | </div> |
| 168 | <a role="button" href="<?php echo $link; ?>" rel="bookmark"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_button_text', true);?></a> | 177 | <a class="btn" role="button" href="<?php echo get_permalink($id); ?>" rel="bookmark">LEARN MORE</a> |
| 169 | </div> | 178 | |
| 170 | </div> | 179 | </div> |
| 180 | </div> | ||
| 171 | </article> | 181 | </article> |
| 172 | </div> | 182 | </div> |
| 183 | |||
| 173 | <?php | 184 | <?php |
| 174 | $output = ob_get_clean(); | 185 | $output = ob_get_clean(); |
| 175 | return $output; | 186 | return $output; |
| 176 | } | 187 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -17634,25 +17634,21 @@ | ... | @@ -17634,25 +17634,21 @@ |
| 17634 | var $grid = $('.grid').isotope({ | 17634 | var $grid = $('.grid').isotope({ |
| 17635 | itemSelector: '.element-item', | 17635 | itemSelector: '.element-item', |
| 17636 | layoutMode: 'fitRows', | 17636 | layoutMode: 'fitRows', |
| 17637 | getSortData: { | ||
| 17638 | coursename: '.name', | ||
| 17639 | date: '[data-ticks]' | ||
| 17640 | }, | ||
| 17637 | filter: function () { | 17641 | filter: function () { |
| 17638 | return qsRegex ? $(this).text().match(qsRegex) : true; | 17642 | var $this = $(this); |
| 17643 | var filterText = qsRegex ? $(this).text().match(qsRegex) : true; | ||
| 17644 | var buttonResult = filterValue ? $this.is(filterValue) : true; | ||
| 17645 | return filterText && buttonResult; | ||
| 17639 | } | 17646 | } |
| 17640 | }); | 17647 | }); |
| 17641 | var filterFns = { | ||
| 17642 | // show if number is greater than 50 | ||
| 17643 | numberGreaterThan50: function () { | ||
| 17644 | var number = $(this).find('.number').text(); | ||
| 17645 | return parseInt(number, 10) > 50; | ||
| 17646 | }, | ||
| 17647 | // show if name ends with -ium | ||
| 17648 | ium: function () { | ||
| 17649 | var name = $(this).find('.name').text(); | ||
| 17650 | return name.match(/ium$/); | ||
| 17651 | } | ||
| 17652 | }; | ||
| 17653 | 17648 | ||
| 17654 | // use value of search field to filter | 17649 | // use value of search field to filter |
| 17655 | var $quicksearch = $('.quicksearch').keyup(debounce(function () { | 17650 | var $quicksearch = $('#quicksearch').keyup(debounce(function () { |
| 17651 | console.log($quicksearch.val()); | ||
| 17656 | qsRegex = new RegExp($quicksearch.val(), 'gi'); | 17652 | qsRegex = new RegExp($quicksearch.val(), 'gi'); |
| 17657 | $grid.isotope(); | 17653 | $grid.isotope(); |
| 17658 | }, 200)); | 17654 | }, 200)); |
| ... | @@ -17672,24 +17668,65 @@ | ... | @@ -17672,24 +17668,65 @@ |
| 17672 | }; | 17668 | }; |
| 17673 | } | 17669 | } |
| 17674 | 17670 | ||
| 17675 | // bind filter button click | 17671 | // filter with selects and checkboxes |
| 17676 | $('.filters-button-group').on('click', 'button', function () { | 17672 | var $checkboxes = $('.category-filter input'); |
| 17677 | var filterValue = $(this).attr('data-filter'); | 17673 | var filterValue; |
| 17678 | // use filterFn if matches value | 17674 | $checkboxes.change(function () { |
| 17679 | filterValue = filterFns[filterValue] || filterValue; | 17675 | // map input values to an array |
| 17680 | $grid.isotope({ | 17676 | var inclusives = []; |
| 17681 | filter: filterValue | 17677 | // inclusive filters from checkboxes |
| 17678 | $checkboxes.each(function (i, elem) { | ||
| 17679 | // if checkbox, use value if checked | ||
| 17680 | if (elem.checked) { | ||
| 17681 | inclusives.push(elem.value); | ||
| 17682 | } | ||
| 17682 | }); | 17683 | }); |
| 17683 | }); | ||
| 17684 | 17684 | ||
| 17685 | // change is-checked class on buttons | 17685 | // combine inclusive filters |
| 17686 | $('.button-group').each(function (i, buttonGroup) { | 17686 | filterValue = inclusives.length ? inclusives.join(', ') : '*'; |
| 17687 | var $buttonGroup = $(buttonGroup); | 17687 | $grid.isotope(); |
| 17688 | $buttonGroup.on('click', 'button', function () { | 17688 | updateFilterCounts(); |
| 17689 | $buttonGroup.find('.is-checked').removeClass('is-checked'); | 17689 | }); |
| 17690 | $(this).addClass('is-checked'); | 17690 | $('.sort-button-group').on('click', 'button', function () { |
| 17691 | var sortValue = $(this).attr('data-sort-value'); | ||
| 17692 | var direction = $(this).attr('data-sort-direction'); | ||
| 17693 | var isAscending = direction == 'asc'; | ||
| 17694 | var newDirection = isAscending ? 'desc' : 'asc'; | ||
| 17695 | $grid.isotope({ | ||
| 17696 | sortBy: sortValue, | ||
| 17697 | sortAscending: isAscending | ||
| 17691 | }); | 17698 | }); |
| 17699 | $(this).attr('data-sort-direction', newDirection); | ||
| 17700 | var span = $(this).find('.glyphicon'); | ||
| 17701 | span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down'); | ||
| 17692 | }); | 17702 | }); |
| 17703 | function updateFilterCounts() { | ||
| 17704 | var itemElems = $grid.isotope('getFilteredItemElements'); | ||
| 17705 | var count_items = $(itemElems).length; | ||
| 17706 | if (count_items > counter) { | ||
| 17707 | $("#load-more").hide(); | ||
| 17708 | } else { | ||
| 17709 | $("#load-more").show(); | ||
| 17710 | } | ||
| 17711 | if ($('.element-item').hasClass('hidden')) { | ||
| 17712 | $('.element-item').removeClass('hidden'); | ||
| 17713 | } | ||
| 17714 | var index = 0; | ||
| 17715 | $(itemElems).each(function () { | ||
| 17716 | if (index >= counter) { | ||
| 17717 | $(this).addClass('hidden'); | ||
| 17718 | } | ||
| 17719 | index++; | ||
| 17720 | }); | ||
| 17721 | console.log('updateFilterCounts'); | ||
| 17722 | console.log(index); | ||
| 17723 | if (index === 0) { | ||
| 17724 | $("#load-more").hide(); | ||
| 17725 | } else { | ||
| 17726 | $("#load-more").show(); | ||
| 17727 | } | ||
| 17728 | $grid.isotope('layout'); | ||
| 17729 | } | ||
| 17693 | 17730 | ||
| 17694 | //**************************** | 17731 | //**************************** |
| 17695 | // Isotope Load more button | 17732 | // Isotope Load more button |
| ... | @@ -17722,7 +17759,7 @@ | ... | @@ -17722,7 +17759,7 @@ |
| 17722 | } | 17759 | } |
| 17723 | 17760 | ||
| 17724 | //append load more button | 17761 | //append load more button |
| 17725 | $grid.after('<div class="viewPlan"><a href="#" id="load-more">Load More</a></div>'); | 17762 | $grid.after('<div class="view-plan"><a class="btn" href="#" id="load-more">LOAD MORE programs</a></div>'); |
| 17726 | 17763 | ||
| 17727 | //when load more button clicked | 17764 | //when load more button clicked |
| 17728 | $(document).on("click", "#load-more", function (e) { | 17765 | $(document).on("click", "#load-more", function (e) { |
| ... | @@ -17737,6 +17774,12 @@ | ... | @@ -17737,6 +17774,12 @@ |
| 17737 | counter = counter + initShow; | 17774 | counter = counter + initShow; |
| 17738 | loadMore(counter); | 17775 | loadMore(counter); |
| 17739 | }); | 17776 | }); |
| 17777 | $(document).on("click", "#filter-more", function (e) { | ||
| 17778 | e.preventDefault(); | ||
| 17779 | $('.filter-group').toggleClass('open'); | ||
| 17780 | var span = $(this).find('.glyphicon'); | ||
| 17781 | span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down'); | ||
| 17782 | }); | ||
| 17740 | }); | 17783 | }); |
| 17741 | 17784 | ||
| 17742 | // Add your custom JS here. | 17785 | // Add your custom JS here. | ... | ... |
This diff could not be displayed because it is too large.
This diff is collapsed.
Click to expand it.
This diff could not be displayed because it is too large.
| ... | @@ -2,8 +2,6 @@ import jQuery from 'jquery'; | ... | @@ -2,8 +2,6 @@ import jQuery from 'jquery'; |
| 2 | import jQueryBridget from 'jquery-bridget'; | 2 | import jQueryBridget from 'jquery-bridget'; |
| 3 | import Isotope from "isotope-layout"; | 3 | import Isotope from "isotope-layout"; |
| 4 | 4 | ||
| 5 | |||
| 6 | |||
| 7 | jQueryBridget( 'isotope', Isotope, $ ); | 5 | jQueryBridget( 'isotope', Isotope, $ ); |
| 8 | 6 | ||
| 9 | jQuery( document ).ready(function($) { | 7 | jQuery( document ).ready(function($) { |
| ... | @@ -15,27 +13,23 @@ var qsRegex; | ... | @@ -15,27 +13,23 @@ var qsRegex; |
| 15 | var $grid = $('.grid').isotope({ | 13 | var $grid = $('.grid').isotope({ |
| 16 | itemSelector: '.element-item', | 14 | itemSelector: '.element-item', |
| 17 | layoutMode: 'fitRows', | 15 | layoutMode: 'fitRows', |
| 16 | getSortData: { | ||
| 17 | coursename: '.name', | ||
| 18 | date: '[data-ticks]', | ||
| 19 | }, | ||
| 18 | filter: function() { | 20 | filter: function() { |
| 19 | return qsRegex ? $(this).text().match( qsRegex ) : true; | 21 | var $this = $(this); |
| 22 | var filterText = qsRegex ? $(this).text().match( qsRegex ) : true; | ||
| 23 | var buttonResult = filterValue ? $this.is( filterValue ) : true; | ||
| 24 | return filterText && buttonResult; | ||
| 20 | } | 25 | } |
| 21 | }); | 26 | }); |
| 22 | 27 | ||
| 23 | 28 | ||
| 24 | var filterFns = { | ||
| 25 | // show if number is greater than 50 | ||
| 26 | numberGreaterThan50: function() { | ||
| 27 | var number = $(this).find('.number').text(); | ||
| 28 | return parseInt( number, 10 ) > 50; | ||
| 29 | }, | ||
| 30 | // show if name ends with -ium | ||
| 31 | ium: function() { | ||
| 32 | var name = $(this).find('.name').text(); | ||
| 33 | return name.match( /ium$/ ); | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | 29 | ||
| 37 | // use value of search field to filter | 30 | // use value of search field to filter |
| 38 | var $quicksearch = $('.quicksearch').keyup( debounce( function() { | 31 | var $quicksearch = $('#quicksearch').keyup( debounce( function() { |
| 32 | console.log($quicksearch.val()); | ||
| 39 | qsRegex = new RegExp( $quicksearch.val(), 'gi' ); | 33 | qsRegex = new RegExp( $quicksearch.val(), 'gi' ); |
| 40 | $grid.isotope(); | 34 | $grid.isotope(); |
| 41 | }, 200 ) ); | 35 | }, 200 ) ); |
| ... | @@ -56,80 +50,141 @@ function debounce( fn, threshold ) { | ... | @@ -56,80 +50,141 @@ function debounce( fn, threshold ) { |
| 56 | } | 50 | } |
| 57 | 51 | ||
| 58 | 52 | ||
| 53 | // filter with selects and checkboxes | ||
| 54 | var $checkboxes = $('.category-filter input'); | ||
| 55 | var filterValue; | ||
| 56 | |||
| 57 | $checkboxes.change( function() { | ||
| 58 | // map input values to an array | ||
| 59 | var inclusives = []; | ||
| 60 | // inclusive filters from checkboxes | ||
| 61 | $checkboxes.each( function( i, elem ) { | ||
| 62 | // if checkbox, use value if checked | ||
| 63 | if ( elem.checked ) { | ||
| 64 | inclusives.push( elem.value ); | ||
| 65 | } | ||
| 66 | }); | ||
| 59 | 67 | ||
| 60 | // bind filter button click | 68 | // combine inclusive filters |
| 61 | $('.filters-button-group').on( 'click', 'button', function() { | 69 | filterValue = inclusives.length ? inclusives.join(', ') : '*'; |
| 62 | var filterValue = $( this ).attr('data-filter'); | 70 | $grid.isotope(); |
| 63 | // use filterFn if matches value | 71 | updateFilterCounts(); |
| 64 | filterValue = filterFns[ filterValue ] || filterValue; | ||
| 65 | $grid.isotope({ filter: filterValue }); | ||
| 66 | }); | 72 | }); |
| 67 | 73 | ||
| 68 | // change is-checked class on buttons | 74 | |
| 69 | $('.button-group').each( function( i, buttonGroup ) { | 75 | $('.sort-button-group').on( 'click', 'button', function() { |
| 70 | var $buttonGroup = $( buttonGroup ); | 76 | var sortValue = $(this).attr('data-sort-value'); |
| 71 | $buttonGroup.on( 'click', 'button', function() { | 77 | var direction = $(this).attr('data-sort-direction'); |
| 72 | $buttonGroup.find('.is-checked').removeClass('is-checked'); | 78 | var isAscending = (direction == 'asc'); |
| 73 | $( this ).addClass('is-checked'); | 79 | var newDirection = (isAscending) ? 'desc' : 'asc'; |
| 74 | }); | 80 | $grid.isotope({ sortBy: sortValue, sortAscending: isAscending }); |
| 81 | $(this).attr('data-sort-direction', newDirection); | ||
| 82 | var span = $(this).find('.glyphicon'); | ||
| 83 | span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down'); | ||
| 75 | }); | 84 | }); |
| 76 | 85 | ||
| 86 | |||
| 87 | |||
| 88 | function updateFilterCounts() { | ||
| 89 | |||
| 90 | var itemElems = $grid.isotope('getFilteredItemElements'); | ||
| 91 | var count_items = $(itemElems).length; | ||
| 92 | |||
| 93 | if (count_items > counter) { | ||
| 94 | $("#load-more").hide(); | ||
| 95 | |||
| 96 | }else { | ||
| 97 | $("#load-more").show(); | ||
| 98 | } | ||
| 99 | if ($('.element-item').hasClass('hidden')) { | ||
| 100 | $('.element-item').removeClass('hidden'); | ||
| 101 | } | ||
| 102 | var index = 0; | ||
| 103 | |||
| 104 | $(itemElems).each(function () { | ||
| 105 | if (index >= counter) { | ||
| 106 | $(this).addClass('hidden'); | ||
| 107 | } | ||
| 108 | index++; | ||
| 109 | }); | ||
| 110 | console.log('updateFilterCounts'); | ||
| 111 | console.log(index); | ||
| 112 | if(index === 0){ | ||
| 113 | |||
| 114 | $("#load-more").hide(); | ||
| 115 | |||
| 116 | }else{ | ||
| 117 | $("#load-more").show(); | ||
| 118 | |||
| 119 | } | ||
| 120 | $grid.isotope('layout'); | ||
| 121 | |||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 77 | 125 | ||
| 78 | 126 | ||
| 79 | //**************************** | 127 | //**************************** |
| 80 | // Isotope Load more button | 128 | // Isotope Load more button |
| 81 | //**************************** | 129 | //**************************** |
| 82 | 130 | ||
| 83 | var initShow = 3; //number of images loaded on init & onclick load more button | 131 | var initShow = 3; //number of images loaded on init & onclick load more button |
| 84 | var counter = initShow; //counter for load more button | 132 | var counter = initShow; //counter for load more button |
| 85 | var iso = $grid.data('isotope'); // get Isotope instance | 133 | var iso = $grid.data('isotope'); // get Isotope instance |
| 86 | console.log('iso'); | 134 | console.log('iso'); |
| 87 | console.log(iso); | 135 | console.log(iso); |
| 88 | console.log(iso.elemCount); | 136 | console.log(iso.elemCount); |
| 89 | 137 | ||
| 90 | loadMore(initShow); //execute function onload | 138 | loadMore(initShow); //execute function onload |
| 91 | 139 | ||
| 92 | function loadMore(toShow) { | 140 | function loadMore(toShow) { |
| 93 | 141 | ||
| 94 | $grid.find(".hidden").removeClass("hidden"); | 142 | $grid.find(".hidden").removeClass("hidden"); |
| 95 | 143 | ||
| 96 | var hiddenElems = iso.filteredItems.slice(toShow, iso.filteredItems.length).map(function(item) { | 144 | var hiddenElems = iso.filteredItems.slice(toShow, iso.filteredItems.length).map(function(item) { |
| 97 | console.log('hiddenElem'); | 145 | console.log('hiddenElem'); |
| 98 | console.log(item.element); | 146 | console.log(item.element); |
| 99 | return item.element; | 147 | return item.element; |
| 100 | }); | 148 | }); |
| 101 | $(hiddenElems).addClass('hidden'); | 149 | $(hiddenElems).addClass('hidden'); |
| 102 | $grid.isotope('layout'); | 150 | $grid.isotope('layout'); |
| 103 | 151 | ||
| 104 | //when no more to load, hide show more button | 152 | //when no more to load, hide show more button |
| 105 | if (hiddenElems.length == 0) { | 153 | if (hiddenElems.length == 0) { |
| 106 | $("#load-more").hide(); | 154 | $("#load-more").hide(); |
| 107 | } | 155 | } else { |
| 108 | else { | 156 | $("#load-more").show(); |
| 109 | $("#load-more").show(); | 157 | }; |
| 110 | }; | 158 | |
| 111 | 159 | } | |
| 112 | } | 160 | |
| 113 | 161 | ||
| 114 | 162 | //append load more button | |
| 115 | //append load more button | 163 | $grid.after('<div class="view-plan"><a class="btn" href="#" id="load-more">LOAD MORE programs</a></div>'); |
| 116 | $grid.after('<div class="viewPlan"><a href="#" id="load-more">Load More</a></div>'); | 164 | |
| 117 | 165 | //when load more button clicked | |
| 118 | //when load more button clicked | 166 | $(document).on("click", "#load-more", function(e) { |
| 119 | $(document).on("click", "#load-more", function(e) { | 167 | e.preventDefault(); |
| 120 | e.preventDefault(); | 168 | |
| 121 | 169 | if ($('#filters').data('clicked')) { | |
| 122 | if ($('#filters').data('clicked')) { | 170 | //when filter button clicked, set initial value for counter |
| 123 | //when filter button clicked, set initial value for counter | 171 | counter = initShow; |
| 124 | counter = initShow; | 172 | j$('#filters').data('clicked', false); |
| 125 | j$('#filters').data('clicked', false); | 173 | } else { |
| 126 | } else { | 174 | counter = counter; |
| 127 | counter = counter; | 175 | }; |
| 128 | }; | 176 | |
| 129 | 177 | counter = counter + initShow; | |
| 130 | counter = counter + initShow; | 178 | |
| 131 | 179 | loadMore(counter); | |
| 132 | loadMore(counter); | 180 | }); |
| 133 | }); | 181 | |
| 182 | $(document).on("click", "#filter-more", function(e) { | ||
| 183 | e.preventDefault(); | ||
| 184 | $('.filter-group').toggleClass('open'); | ||
| 185 | var span = $(this).find('.glyphicon'); | ||
| 186 | span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down'); | ||
| 187 | }); | ||
| 188 | |||
| 134 | 189 | ||
| 135 | }); | 190 | }); | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment