Changeset 2597622
- Timestamp:
- 09/12/2021 05:31:10 PM (5 years ago)
- Location:
- no-bs-image-slider/trunk
- Files:
-
- 1 deleted
- 3 edited
-
changelog.txt (deleted)
-
plugin.php (modified) (14 diffs)
-
readme.txt (modified) (3 diffs)
-
style.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
no-bs-image-slider/trunk/plugin.php
r2522382 r2597622 5 5 Plugin URI: https://planetjon.ca/projects/no-bs-image-slider/ 6 6 Description: For displaying a light-weight image slider 7 Version: 1. 6.17 Version: 1.7.0 8 8 Requires at least: 4.7 9 Tested up to: 5. 79 Tested up to: 5.8.1 10 10 Requires PHP: 5.4 11 11 Author: Jonathan Weatherhead … … 26 26 $sliderName = $args['name'] ?? ''; 27 27 $sliderDescription = $args['description'] ?? ''; 28 $slideDuration = $args['slideDuration'] ?: default_slide_duration;29 28 $slideCount = count( $slides ); 30 29 $showCounter = filter_var( $args['showCounter'], FILTER_VALIDATE_BOOLEAN ); 30 $slideDuration = filter_var( $args['slideDuration'], FILTER_VALIDATE_INT, [ 31 'options' => [ 'default' => default_slide_duration, 'min_range' => 1 ] 32 ] ); 31 33 32 34 $sliderKeyframes = ''; … … 64 66 } 65 67 66 $sliderAria = [ 'aria-role="region"', 'aria-roledescription="carousel"'];68 $sliderAria = ['aria-role="region"', 'aria-roledescription="carousel"']; 67 69 if( $sliderDescription ) { 68 70 $sliderAria []= sprintf( 'aria-label="%s"', $sliderDescription ); … … 86 88 $aria = [ 87 89 'role="group"', 88 'aria-roledescription="slide"',89 sprintf( 'aria-label="%d of %d"', $counter,$slideCount )90 'aria-roledescription="slide"', 91 sprintf( 'aria-label="%d of %d"', $counter,$slideCount ) 90 92 ]; 91 93 … … 102 104 'slider' => '', 103 105 'duration' => default_slide_duration, 104 'showcounter' => 'no' 106 'showcounter' => 'no', 107 'lazy' => 'no' 105 108 ] ); 106 109 … … 110 113 $slideDuration = $params['duration']; 111 114 $showCounter = $params['showcounter']; 115 $loadingAttribute = filter_var( $params['lazy'], FILTER_VALIDATE_BOOLEAN ) ? 'lazy' : false; 112 116 113 117 $sliderInfo = get_term_by( 'slug', $slider, 'no_bs_image_slider' ); … … 138 142 139 143 $slideDeck = []; 144 $imgAttributes = [ 'loading' => $loadingAttribute ]; 140 145 foreach( $slides as $idx => $slide ) { 141 146 $slideDeck []= [ 142 147 'id' => $slide->ID, 143 'img' => get_the_post_thumbnail( $slide, 'full' ),148 'img' => get_the_post_thumbnail( $slide, 'full', $imgAttributes ), 144 149 'url' => get_post_meta( $slide->ID, 'nbisl', true ), 145 150 'title' => get_the_title( $slide->ID ), … … 149 154 150 155 wp_enqueue_style( 'no-bs-image-slider', plugins_url( 'no-bs-image-slider/style.css' ), [], null ); 151 renderS Lider(156 renderSlider( 152 157 $slider, 153 158 $slideDeck, … … 158 163 'stylesCallback' => function( $slider ) { 159 164 do_action( 'nbis_additional_styles', $slider ); 165 do_action( 'nbis_additional_styles_' . $slider, $slider ); 160 166 } 161 167 ] … … 184 190 echo $args['before_widget']; 185 191 186 if ( $instance['title'] ) {187 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];188 }189 190 192 $slider = $instance['nbis']; 191 193 $slideDuration = $instance['nbisd']; 192 194 $showCounter = $instance['nbisc']; 195 $lazyImages = $instance['nbisl']; 193 196 194 197 showSlider( [ 195 "slider" => $slider, 196 "duration" => $slideDuration, 197 "showcounter" => $showCounter 198 'slider' => $slider, 199 'duration' => $slideDuration, 200 'showcounter' => $showCounter, 201 'lazy' => $lazyImages 198 202 ] ); 199 203 … … 210 214 $slideDuration = $instance['nbisd'] ?: default_slide_duration; 211 215 $showCounter = $instance['nbisc']; 216 $lazyImages = $instance['nbisl']; 212 217 213 218 printf( … … 247 252 checked( $showCounter, 'yes', false ), 248 253 ); 254 255 printf( 256 '<p><label>%s <input type="checkbox" id="%s" name="%s" value="%s" %s /></label></p>', 257 __( 'Lazy load images?', 'no-bs-image-slider' ), 258 esc_attr( $this->get_field_id( 'nbisl' ) ), 259 esc_attr( $this->get_field_name( 'nbisl' ) ), 260 'yes', 261 checked( $lazyImages, 'yes', false ), 262 ); 249 263 } 250 264 251 265 public function update( $new, $old ) { 252 266 $instance = [ 253 'nbis' => !empty( $new['nbis'] ) ? sanitize_text_field( $new['nbis'] ) : '', 254 'nbisd' => !empty( $new['nbisd'] ) && $new['nbisd'] >= 1 ? sanitize_text_field( $new['nbisd'] ) : $old['nbisd'], 255 'nbisc' => !empty( $new['nbisc'] ) ? sanitize_text_field( $new['nbisc'] ) : $old['nbisc'] 267 'nbis' => !empty( $new['nbis'] ) ? sanitize_text_field( $new['nbis'] ) : false, 268 'nbisd' => !empty( $new['nbisd'] ) ? sanitize_text_field( $new['nbisd'] ) : false, 269 'nbisc' => !empty( $new['nbisc'] ) ? sanitize_text_field( $new['nbisc'] ) : false, 270 'nbisl' => !empty( $new['nbisl'] ) ? sanitize_text_field( $new['nbisl'] ) : false 256 271 ]; 257 272 … … 261 276 262 277 function createSlidesType() { 263 register_post_type( 'no_bs_image_slide',264 [265 ' labels' => [266 'name' => __( 'Image Slides' ),267 'singular_name' => __( 'Image Slide' )268 ],269 'public' => false,270 'show_ui' => true,271 'supports' => ['title', 'thumbnail', 'excerpt'],272 'register_meta_box_cb' => function( WP_Post $post ) {273 add_meta_box(274 'image_slide_meta',275 'Image Slider Meta',276 function( WP_Post $post, Array $metabox ) {277 $title_field = get_post_meta( $post->ID, 'nbisl', true);278 $outline = sprintf('<label>%s <input type="url" name="nbisl" value="%s"/></label>', esc_html__( 'Link', 'no-bs-image-slider' ), esc_attr( $title_field ) ); 279 280 echo $outline;281 }282 );283 }284 ] 285 );278 $slideType = [ 279 'labels' => [ 280 'name' => __( 'Image Slides' ), 281 'singular_name' => __( 'Image Slide' ) 282 ], 283 'public' => false, 284 'show_ui' => true, 285 'supports' => ['title', 'thumbnail', 'excerpt'], 286 'register_meta_box_cb' => function( WP_Post $post ) { 287 add_meta_box( 288 'image_slide_meta', 289 'Image Slider Meta', 290 function( WP_Post $post, Array $metabox ) { 291 $title_field = get_post_meta( $post->ID, 'nbisl', true ); 292 $outline = sprintf('<label>%s <input type="url" name="nbisl" value="%s"/></label>', esc_html__( 'Link', 'no-bs-image-slider' ), esc_attr( $title_field ) ); 293 294 echo $outline; 295 } 296 ); 297 } 298 ]; 299 300 register_post_type( 'no_bs_image_slide', $slideType ); 286 301 } 287 302 … … 299 314 300 315 function createSliderTaxonomy() { 301 register_taxonomy( 302 'no_bs_image_slider', 303 null, 304 [ 305 'public' => false, 306 'show_ui' => true, 307 'labels' => [ 308 'name' => __( 'Image Sliders' ), 309 'singular_name' => __( 'Image Slider' ) 310 ] 316 $sliderTaxonomy = [ 317 'public' => false, 318 'show_ui' => true, 319 'labels' => [ 320 'name' => __( 'Image Sliders' ), 321 'singular_name' => __( 'Image Slider' ) 311 322 ] 312 ); 313 323 ]; 324 325 register_taxonomy( 'no_bs_image_slider', null, $sliderTaxonomy ); 314 326 register_taxonomy_for_object_type( 'no_bs_image_slider', 'no_bs_image_slide' ); 315 327 } -
no-bs-image-slider/trunk/readme.txt
r2522377 r2597622 4 4 Tags: carousel, slideshow, responsive, accessible 5 5 Requires at least: 4.7 6 Tested up to: 5. 76 Tested up to: 5.8.1 7 7 Requires PHP: 5.4 8 8 Stable tag: trunk … … 29 29 3. Use the No BS Image Slider widget to configure which slider you want displayed, and the duration of each slide. 30 30 31 A great [rundown of the plugin](https://planetjon.ca/4778/making-an-image-carousel-with-no-bs-image-slider "Making an image carousel with No BS Image Slider") is available on the Planetjon blog. 32 33 === Shortcode === 34 35 To manually insert a slider, use the shortcode [nbis]. 36 You must provide at minimum the slider slug. 37 38 39 The shortcode attributes are 40 41 * slider="slug" 42 * duration="number" (default 5) 43 * showcounter="yes|no" (default no) 44 * lazy="yes|no" (default no) 45 46 === Widget === 47 48 A widget that exposes all of the above options is available. 49 31 50 == Frequently Asked Questions == 32 51 … … 37 56 The CSS weighs in at under 2 kilobytes, blowing away all of the major slider plugins by a mile. 38 57 58 = How can I set the order of slides in a slider = 59 60 While there are no admin options for this, it can be done by using custom CSS. 61 Sliders are ID'd with `no-bs-image-slider-<sliderId>` and slides are ID'd with `nbis-slide-<slideId>`. 62 63 64 An approach would be to style the slider as Flexbox, and set the order on the slides. 65 66 #no-bs-image-slider-123 { 67 display: flex; 68 } 69 70 #no-bs-image-slider-123 #nbis-slide-1 { 71 order: 1; 72 } 73 74 #no-bs-image-slider-123 #nbis-slide-2 { 75 order: 0; 76 } 77 39 78 == Changelog == 79 80 = 1.7.0 = 81 * Images loaded eagerly be default. 82 * Image lazy loading parameter. 40 83 41 84 = 1.6.1 = -
no-bs-image-slider/trunk/style.css
r2522361 r2597622 1 1 .no-bs-image-slider 2 2 { 3 display: block;4 position: relative;5 overflow: hidden;6 counter-reset: nbis-slides;3 display: block; 4 position: relative; 5 overflow: hidden; 6 counter-reset: nbis-slides; 7 7 } 8 8 9 9 .no-bs-image-slider:hover::before 10 10 { 11 content: "\23F8";12 position: absolute;13 padding: 0.25em 0.5em;14 background-color: black;15 z-index: 1;16 color: white;17 font-size: 1.5em;11 content: "\23F8"; 12 position: absolute; 13 padding: 0.25em 0.5em; 14 background-color: black; 15 z-index: 1; 16 color: white; 17 font-size: 1.5em; 18 18 } 19 19 20 20 .no-bs-image-slider .scrollpane 21 21 { 22 display: flex;23 animation-direction: normal;24 animation-timing-function: ease;25 animation-iteration-count: infinite;22 display: flex; 23 animation-direction: normal; 24 animation-timing-function: ease; 25 animation-iteration-count: infinite; 26 26 } 27 27 28 28 .no-bs-image-slider .scrollpane:hover 29 29 { 30 animation-play-state: paused;30 animation-play-state: paused; 31 31 } 32 32 33 .n o-bs-image-slider .nbis-slide33 .nbis-slide 34 34 { 35 display: block;36 flex-shrink: 0;37 box-sizing: border-box;38 width: 100%;39 margin: 0;40 padding: 0;41 counter-increment: nbis-slide;42 counter-reset: nbis-slides var(--slide-count);35 display: block; 36 flex-shrink: 0; 37 box-sizing: border-box; 38 width: 100%; 39 margin: 0; 40 padding: 0; 41 counter-increment: nbis-slide; 42 counter-reset: nbis-slides var(--slide-count); 43 43 } 44 44 45 . no-bs-image-slider.show-counter .nbis-slide::before45 .show-counter .nbis-slide::before 46 46 { 47 47 48 content: counter(nbis-slide) " / " counter(nbis-slides);49 display: block;50 position: absolute;51 top: 0px;52 width: 100%;53 text-align: center;48 content: counter(nbis-slide) " / " counter(nbis-slides); 49 display: block; 50 position: absolute; 51 top: 0px; 52 width: 100%; 53 text-align: center; 54 54 } 55 55 56 .n o-bs-image-slider .nbis-slide a56 .nbis-slide a 57 57 { 58 display: block;59 position: absolute;60 width: 100%;61 height: 100%;62 z-index: 1;58 display: block; 59 position: absolute; 60 width: 100%; 61 height: 100%; 62 z-index: 1; 63 63 } 64 64 65 .n o-bs-image-slider .nbis-slide img65 .nbis-slide img 66 66 { 67 width: 100%;68 height: auto;67 width: 100%; 68 height: auto; 69 69 } 70 70 71 .n o-bs-image-slider .nbis-slide figcaption71 .nbis-slide figcaption 72 72 { 73 display: block;74 position: absolute;75 bottom: 0;76 width: 100%;73 display: block; 74 position: absolute; 75 bottom: 0; 76 width: 100%; 77 77 } 78 78 79 .n o-bs-image-slider .nbis-slide figcaption:empty79 .nbis-slide figcaption:empty 80 80 { 81 display: none;81 display: none; 82 82 }
Note: See TracChangeset
for help on using the changeset viewer.