--- regenerate: false --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # J1: ~/assets/themes/j1/j1/js/adapters/owl_carousel.js # Liquid JS template to create the J1 Adapter for the Owl Carousel # # Product/Info: # http://jekyll.one # # Copyright (C) 2016 Juergen Adams # Copyright (C) 2016 Bartosz Wojciechowski # # J1 Template is licensed under the MIT License. # Owl Carousel is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Test data: # {{ config | debug }} # ----------------------------------------------------------------------------- {% endcomment %} /* # ----------------------------------------------------------------------------- # J1: ~/assets/themes/j1/j1/js/adapters/owl_carousel.js # JS Adapter for the Owl Carousel # # Product/Info: # http://jekyll.one # # Copyright (C) 2016 Juergen Adams # Copyright (C) 2016 Bartosz Wojciechowski # # J1 Template is licensed under the MIT License. # Owl Carousel is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ {% assign environment = site.environment %} {% assign config = site.data.modules.j1_owl_carousel %} {% assign default_options = site.data.modules.j1_owl_carousel.default %} {% if config.enabled %} {% assign slider_id = '' %} var J1OwlCarousel = function () { return { // Initialize init: function () { // jQuery slider options {% for item in config.carousel %} {% if item.show.enabled %} {% assign slider_id = item.show.id %} {% assign slider_title = item.show.title %} {% assign slider_type = item.show.type %} {% assign css_classes = item.show.css_classes %} {% assign lazyLoad = item.show.lightbox %} // Create an Carousel INSTANCE if slider on id: {{ slider_id }} exists if ( $('#{{slider_id}}').length ) { {% if environment == 'development' %} var start = moment(); var finished = ''; var elapsed = ''; var log_text = "[" +start.format("HH:mm:ss.SSS")+ "] J1 ADAPTER: Owl Carousel Slider for ID {{ slider_id }} being initialized .." console.log( log_text ); {% endif %} {% if item.show.slide_height != null %} // Set slide_height: {{item.show.slide_height}}vh {% assign slide_height = item.show.slide_height %} $('head').append(""); {% endif %} {% if item.show.slide_space_between %} {% assign slide_space = item.show.slide_space_between %} {% else %} {% assign slide_space = 3 %} {% endif %} {% if item.show.slide_border %} {% assign slide_border = "thumbnail" %} {% else %} {% assign slide_border = "" %} {% endif %} {% if slider_title %} var slider_title = '
{{slider_title}}
'; $('#{{ slider_id }}').before( slider_title ); {% endif %} $('head').append(""); //$('.{{slider_id}}-item').parent().addClass('owl-carousel'); //$('.owl-carousel .item').css('margin','{{slide_space}}px'); {% comment %} // Initialize default parameters $("#{{ slider_id }}").owlCarousel({ {% for option in default_options %} {{ option[0] | json }}: {{ option[1] | json }}, {% endfor %} }); {% endcomment %} // Initialize individual show parameters $("#{{ slider_id }}").owlCarousel({ {% for option in item.show.options %} {{ option[0] | json }}: {{ option[1] | json }}, {% endfor %} // Enable lazyLoad if lightbox is enabled {% if item.show.lightbox %} "lazyLoad": true, {% endif %} "jsonPath": {{ config.jsonPath | json }}, "jsonSuccess": customDataSuccess_{{forloop.index }} }); // Initialize instance variable {{ slider_id }} = $('#{{ slider_id }}').data('owlCarousel'); // jQuery show data functions function customDataSuccess_{{forloop.index}}(data){ var content = ""; for ( var i in data["{{ slider_id }}"] ) { {% if slider_type == 'image' %} var lb = data["{{ slider_id }}"][i].lb; var lb_caption = data["{{ slider_id }}"][i].lb_caption; var img = data["{{ slider_id }}"][i].img; var alt = data["{{ slider_id }}"][i].alt; {% endif %} {% if slider_type == 'text' %} var text = data["{{ slider_id }}"][i].text; {% endif %} var href = data["{{ slider_id }}"][i].href; {% if css_classes %} var css_classes = 'class="{{ css_classes }}";' {% else %} var css_classes = '' {% endif %} {% if slider_type == 'image' %} // If lightbox is enabled (preference over href) if ( lb ) { if ( lb_caption ) { content += '\t\t' + '
'+ '\n'; content += '\t\t\t' + '' + '\n'; content += '\t\t\t\t' + '' + '\n'; content += '\t\t\t' + '' + '\n'; if ( href ) { content += '\t\t\t' + '' +lb_caption+ ' ' + '\n'; } else { content += '\t\t\t' + '' +lb_caption+ '' + '\n'; } content += '\t\t' + '
' + '\n'; } else { content += ' ' +alt+ '' + '' } } else if ( href ) { content += '
' + '' +alt+ '' + '
' } else { content += '
' + '' +alt+ '' + '
' } {% endif %} {% if slider_type == 'text' %} if ( href ) { content += '
' + '

' +text+ '

' + '
' } else { content += '
' + '

' +text+ '

' + '
' } {% endif %} } $("#{{ slider_id }}").html(content); {% if environment == 'development' %} finished = moment(); elapsed = finished.diff(start) log_text = "[" +finished.format("HH:mm:ss.SSS")+ "] J1 ADAPTER: Owl Carousel Slider for ID {{ slider_id }} initializing finished. {" +elapsed+ "}" console.log( log_text ); {% endif %} } // end customDataSuccess_{{forloop.index}} } // end if carousel exists {% endif %} {% endfor %} } // end init }; // end return }(); {% endif %} // Owl Slider enabled {% endcapture %} {{ cache | strip_empty_lines }} {% assign cache = nil %}