Giter Club home page Giter Club logo

jquery-slick-rails's Introduction

jQuerySlickRails

Gem Version Build Status Dependency Status

A ruby gem that uses the Rails asset pipeline to include the jQuery Slick plugin by Ken Wheeler (https://kenwheeler.github.io/slick/).

Installation

Add this line to your application's Gemfile:

gem "jquery-slick-rails"

And then execute:

$ bundle

Or install it yourself as:

$ gem install jquery-slick-rails

NOTE: this is a jQuery plugin so you will also need the jquery-rails gem (it is not added by default starting from Rails 5.1):

Usage

You will need to add this line into your application.js:

//= require jquery.slick

Then into application.scss:

@import 'slick';

or into application.css:

/*
*= require slick
*/

Starting from version 1.4.0 Slick provides an optional theme, so if you want to employ default styling, include the following line into application.scss:

@import 'slick-theme';

or into application.css:

/*
*= require slick-theme
*/

You may use this simple Rails app as an example (it also shows how to use the plugin with Turbolinks).

Turbolinks Gotcha

If you are using Slick with Turbolinks, you might run into some problems with the browser's "back" button. If that happens, the following solution might help. Add this code to your layouts/application.html.erb:

<head>
  <% if content_for?(:head) %>
    <%= yield(:head) %>
  <% end %>
</head>

And then on any page that has Slick:

<% content_for :head do %>
  <meta name="turbolinks-cache-control" content="no-cache">
<% end %>

The idea is that we are opting the page out of caching, as Turbolinks uses it during restoration visits (that is, when you click "back").

Another solution was to employ the unslick method to prepare your document before Turbolinks caches it:

jQuery(document).on('turbolinks:before-cache', $('.scroller').slick('unslick'))

    However, this does not seem to work anymore - maybe because Slick has lots of opened issues related to unslick.

Read more on StackOverflow.

Testing

Run

$ bundle install

and then

$ rake test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make sure tests are passing
  4. Commit your changes (git commit -am 'Added some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

This plugin is licensed under the MIT License.

Copyright (c) 2017 Ilya Bodrov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.