Giter Site home page Giter Site logo

bodrovis / jquery-slick-rails Goto Github PK

View Code? Open in Web Editor NEW
93.0 6.0 33.0 296 KB

Integrates Slick carousel, a jQuery plugin, into your Rails app.

License: MIT License

Ruby 15.03% HTML 3.05% CSS 1.70% JavaScript 80.22%
slick jquery-plugin javascript rails asset-pipeline

jquery-slick-rails's Introduction

jQuerySlickRails

Gem Build Status Downloads total

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

If you are using Rails 6 with Webpacker then you don't need this gem (install Slick directly from NPM instead). Check out this sample app for more info.

DEPRECATION NOTICE

This gem was created in 2014 and since then it has been downloaded more than 2 million times. I'm glad you guys found it useful! However, it's time to move on. Rails 6 uses Webpacker as a de-facto standard to bundle assets therefore this gem became redundant for setups that utilize Webpacker or other bundlers like esbuild. Moreover, Rails 7 is coming in December 2021 and this new version uses another modern approach: you can rely on jsbundling-rails and choose your favourite bundler (Webpacker, esbuild, rollup). Basically, it means that it's not recommended to install front-end packages as Ruby gems anymore.

Another thing to mention is that Slick itself was abandoned by its maintainer: there are no new releases since 2018. Slick was a great solution back in the day but now it was superseded by other modern libraries that do not rely on jQuery.

Therefore, jquery-slick-rails is officially deprecated since December, 2021. Version 1.10.0 is the final release I'm going to roll out: it is tested with Rails 7 so it should still work fine with older setups. But once again: it's very much recommended to migrate to jsbundling-rails or Webpacker.

Thank you for your attention, and hopefully you'll find my other solutions useful.

Ilya Bodrov-Krukowski

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
*/

Demos

Check out this repo showing how to use Slick carousel with Rails app with and without Webpacker (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', function() { $('.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

jquery-slick-rails's People

Contributors

bodrovis avatar cprodhomme avatar dependabot[bot] avatar erpe avatar finist avatar nazark avatar nfabredev avatar raysuelzer avatar techfounder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jquery-slick-rails's Issues

Sass says file cannot be found slick.

Sass is saying that @import 'slick'; cannot be found, but *= require slick works. Also, can you help me implement this plugin to my view. Ruby on Rails struggles with JavaScript at certain points. I followed the instructions to no avail. Please provide a short tutorial to assist me in getting this working on rails.

The slick carousel breaks second time loading page.

The first time I visit a page with the slick carousel on it it operates normally. If I route to another page and then back to the carousel the images will all stack on top of each other and the carousel will be broken. The site is also using bootstrap4 so I don't know if they are clashing.

Latest Slick version?

I was trying to play around with verticalSwiping, but it doesn't seem like this has the most updated version of slick.

CSS3111: @font-face encountered unknown error

Hi, I'm getting an
CSS3111: @font-face encountered unknown error
slick.eot?#iefix
on the IE9 console which completely blocks the site from rendering. When I remove the slick-theme that error goes away but of course I don't have the default theme. Any idea how to fix the problem?

Assets not found

After installing the gem, all of slick's functionality works as expected, however I get errors saying that the woff and tiff files cannot be found in my assets directory.

screen shot 2014-12-01 at 11 55 50 pm

File to import not found or unreadable: slick. on Windows

Win 10, Ruby 2.2.4p230, Rails 5.0.0.1, 'sass-rails', '5.0.6', 'jquery-rails', '4.1.1'

File to import not found or unreadable: slick.
Load paths:
CompassRails::SpriteImporter
...
CompassRails::SpriteImporter
D:/app/assets/config
D:/app/assets/fonts
D:/app/assets/images
D:/app/assets/javascripts
D:/app/assets/stylesheets
D:/vendor/assets/javascripts
D:/vendor/assets/stylesheets
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/ckeditor-4.1.3/app/assets/javascripts
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/ckeditor-4.1.3/app/assets/stylesheets
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/ckeditor-4.1.3/vendor/assets/javascripts
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/coffee-rails-4.2.1/lib/assets/javascripts
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actioncable-5.0.0.1/lib/assets/compiled
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/turbolinks-source-5.0.0/lib/assets/javascripts
D:/app/assets/stylesheets
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/susy-2.2.12/sass
Compass::SpriteImporter

Error: jquery-ujs has already been loaded!

Get this error every time try to work with slick in a coffee script file, for a particular model, in my case photo.js.coffee.

//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require jquery.slick
//= require turbolinks
//= require_tree .

application.html.erb

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title><%= content_for?(:title) ? yield(:title) : "foundation-rails" %></title>

    <%= stylesheet_link_tag    "application" %>
    <%= javascript_include_tag "vendor/modernizr" %>
    <%= csrf_meta_tags %>
  </head>

  <body>

    <%= yield %>
    <%= javascript_include_tag "application" %>
  </body>
</html>

application.css

 *
 *= require_tree .
 *= require_self
 *= require foundation_and_overrides
 */
@import 'slick';

Could you release version 1.8.1?

Hi! Thanks for packaging Slick as a gem. Slick 1.8.1 was released a few days ago. I'm filing this issue to ask for a gem release with 1.8.1, when you get around to it, and so that I get notified when you do. :)

Possible issue with height?

Hi, I don't know if this is an issue or it's intended to be like this. I'm using slick in my rails app, but I encounter a problem with the height of the images. I want my images to have the same height, for that I used adaptiveHeight: false, but this is still happening: gpdi9

Why is that happening? And if is not a issue can you please tell me how to fix this without me fixing the height statically.

Thank you!

Modifying slick-style.css

I've made a modified version of slick-style.css and put it in my assets/stylesheets directory. However, in slick-style.css, there are references to the slick fonts. How would I go about revising these references to use wherever this gem's fonts are so that my slider arrows can look like the slick arrows, and not the default arrow characters?

Does it support rails 6 so far?

Hi, First of all, thanks for the good gem you provide. It's pretty good!

SO, the question is does it work for rails 6?
If yes, is there any guide or installation recipe for rails 6, If No, do have any upgrade plan on that?

Thanks!!

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.