├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── bower.json
├── build.js
├── demos
├── default.html
├── emoji.html
├── responsive.html
└── touch.html
├── dist
├── basicSlider.min.css
├── basicSlider.min.js
└── themes
│ └── default.min.css
├── package.json
└── src
├── scripts
└── main.js
└── styles
├── _slider.scss
├── _vars.scss
├── main.scss
└── themes
└── default.scss
/.gitattributes:
--------------------------------------------------------------------------------
1 | dist/**/* binary
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: electerious
2 | custom: ['https://paypal.me/electerious', 'https://www.buymeacoffee.com/electerious']
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | yarn.lock
3 | package-lock.json
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6 |
7 | ## [1.1.5] - 2021-01-17
8 |
9 | ### Changed
10 |
11 | - Updated dependencies
12 |
13 | ## [1.1.4] - 2020-03-20
14 |
15 | ### Changed
16 |
17 | - Updated dependencies
18 |
19 | ## [1.1.3] - 2019-02-23
20 |
21 | ### Changed
22 |
23 | - Simplified demos
24 | - Replace `gulp` and `basicTasks` with custom build process
25 |
26 | ## [1.1.2] - 2017-12-17
27 |
28 | ### Changed
29 |
30 | - Syntax of JS and SCSS files
31 |
32 | ## [1.1.1] - 2017-08-08
33 |
34 | ### Added
35 |
36 | - Added a changelog
37 |
38 | ### Changed
39 |
40 | - Ignore `yarn.lock` and `package-lock.json` files
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Tobias Reich
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # basicSlider
2 |
3 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYKBESW577YWE)
4 |
5 | A slider in its purest form.
6 |
7 | ## Contents
8 |
9 | - [Demos](#demos)
10 | - [Features](#features)
11 | - [Requirements](#requirements)
12 | - [Setup](#setup)
13 | - [API](#api)
14 | - [Instance API](#instance-api)
15 | - [Options](#options)
16 | - [Themes](#themes)
17 |
18 | ## Demos
19 |
20 | | Name | Description | Link |
21 | |:-----------|:------------|:------------|
22 | | Default | All features with the default theme. | [Try it on CodePen](http://codepen.io/electerious/pen/GjpXRX) |
23 | | Responsive | Responsive slider with dynamic content. | [Try it on CodePen](http://codepen.io/electerious/pen/aJKyxx) |
24 | | Emoji | Default theme with emojis. | [Try it on CodePen](http://codepen.io/electerious/pen/MpXEVd) |
25 | | Touch | Slider with swipe support. | [Try it on CodePen](https://codepen.io/electerious/pen/vWMXoL) |
26 |
27 | ## Features
28 |
29 | - Works in all modern browsers and IE11 ([with polyfills](#requirements))
30 | - Supports any kind of content
31 | - No fancy shit, just a slider in its purest form
32 | - Zero dependencies
33 | - CommonJS and AMD support
34 | - Simple JS API
35 |
36 | ## Requirements
37 |
38 | basicSlider depends on the following browser APIs:
39 |
40 | - [NodeList.prototype.forEach](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach)
41 | - [Number.isFinite](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
42 | - [Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
43 |
44 | Some of these APIs are capable of being polyfilled in older browsers. Check the linked resources above to determine if you must polyfill to achieve your desired level of browser support.
45 |
46 | ## Setup
47 |
48 | We recommend installing basicSlider using [npm](https://npmjs.com) or [yarn](https://yarnpkg.com).
49 |
50 | ```sh
51 | npm install basicslider
52 | ```
53 |
54 | ```sh
55 | yarn add basicslider
56 | ```
57 |
58 | Include the CSS file in the `head` tag and the JS file at the end of your `body` tag…
59 |
60 | ```html
61 |
62 |
63 | ```
64 |
65 | ```html
66 |
67 | ```
68 |
69 | …or skip the JS file and use basicSlider as a module:
70 |
71 | ```js
72 | const basicSlider = require('basicslider')
73 | ```
74 |
75 | ```js
76 | import * as basicSlider from 'basicslider'
77 | ```
78 |
79 | ## API
80 |
81 | ### .create(elem, slides, opts)
82 |
83 | Creates a new basicSlider instance.
84 |
85 | Be sure to assign your instance to a variable. Using your instance, you can…
86 |
87 | * …get the current slide.
88 | * …navigate back and forward.
89 | * …goto a specific slide.
90 |
91 | Examples:
92 |
93 | ```js
94 | const instance = basicSlider.create(document.querySelector('#slider'), [
95 | 'Slide 1',
96 | 'Slide 2',
97 | 'Slide 3'
98 | ])
99 | ```
100 |
101 | ```js
102 | const instance = basicSlider.create(document.querySelector('#slider'), [
103 | '
Slide 1 with HTML
',
104 | '
Slide 2 with HTML
',
105 | '
Slide 3 with HTML
'
106 | ], {
107 | index: 1,
108 | arrows: false
109 | })
110 | ```
111 |
112 | Parameters:
113 |
114 | - `elem` `{Node}` The DOM element/node which should contain the slider.
115 | - `slides` `{Array}` Array of strings. Each item represents one slide. Any kind of HTML is allowed.
116 | - `opts` `{?Object}` An object of [options](#options).
117 |
118 | Returns:
119 |
120 | - `{Object}` The created instance.
121 |
122 | ## Instance API
123 |
124 | Each basicSlider instance has a handful of handy functions. Below are all of them along with a short description.
125 |
126 | ### .element()
127 |
128 | Returns the DOM element/node object associated with the instance.
129 |
130 | Example:
131 |
132 | ```js
133 | const elem = instance.element()
134 | ```
135 |
136 | Returns:
137 |
138 | - `{Node}` DOM element/node associated with the instance.
139 |
140 | ### .length()
141 |
142 | Returns the total number of slides.
143 |
144 | Example:
145 |
146 | ```js
147 | const length = instance.length()
148 | ```
149 |
150 | Returns:
151 |
152 | - `{Number}` Total number of slides.
153 |
154 | ### .current()
155 |
156 | Returns the current slide index.
157 |
158 | Example:
159 |
160 | ```js
161 | const current = instance.current()
162 | ```
163 |
164 | Returns:
165 |
166 | - `{Number}` Current slide index.
167 |
168 | ### .goto(newIndex)
169 |
170 | Navigates to a slide by index and executes the beforeChange and afterChange callback functions.
171 |
172 | Example:
173 |
174 | ```js
175 | instance.goto(0)
176 | ```
177 |
178 | Parameters:
179 |
180 | - `newIndex` `{Number}` Index of the slide to be displayed.
181 |
182 | ### .prev()
183 |
184 | Navigates to the previous slide and executes the beforeChange and afterChange callback functions.
185 |
186 | Example:
187 |
188 | ```js
189 | instance.prev()
190 | ```
191 |
192 | ### .next()
193 |
194 | Navigates to the next slide and executes the beforeChange and afterChange callback functions.
195 |
196 | Example:
197 |
198 | ```js
199 | instance.next()
200 | ```
201 |
202 | ## Options
203 |
204 | The option object can include the following properties:
205 |
206 | ```js
207 | {
208 | /*
209 | * Initial slide.
210 | */
211 | index: 0,
212 | /*
213 | * Show or hide prev/next arrows.
214 | */
215 | arrows: true,
216 | /*
217 | * Show or hide dot indicators.
218 | */
219 | dots: true,
220 | /*
221 | * Callback functions.
222 | * Returning false will stop the caller function and prevent the slider from changing.
223 | */
224 | beforeChange: (instance, newIndex, oldIndex) => {},
225 | afterChange: (instance, newIndex, oldIndex) => {}
226 | }
227 | ```
228 |
229 | ## Themes
230 |
231 | Layout and theme are separated CSS files. This makes it easy to style your own slider or to choose from the included themes.
232 |
233 | | Name | Demo |
234 | |:-----------|:------------|
235 | | Default theme | [Demo](http://codepen.io/electerious/pen/GjpXRX) |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basicSlider",
3 | "authors": [
4 | "Tobias Reich "
5 | ],
6 | "description": "A slider in its purest form.",
7 | "main": [
8 | "dist/basicSlider.min.css",
9 | "dist/basicSlider.min.js"
10 | ],
11 | "keywords": [
12 | "slider",
13 | "slides",
14 | "carousel"
15 | ],
16 | "ignore": [
17 | "**/.*",
18 | "demos",
19 | "build.js",
20 | "package.json"
21 | ],
22 | "license": "MIT",
23 | "homepage": "https://github.com/electerious/basicSlider",
24 | "repository": {
25 | "type": "git",
26 | "url": "https://github.com/electerious/basicSlider.git"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const { writeFile } = require('fs').promises
4 | const js = require('rosid-handler-js')
5 | const sass = require('rosid-handler-sass')
6 |
7 | sass('src/styles/main.scss', {
8 |
9 | optimize: true
10 |
11 | }).then((data) => {
12 |
13 | return writeFile('dist/basicSlider.min.css', data)
14 |
15 | })
16 |
17 | sass('src/styles/themes/default.scss', {
18 |
19 | optimize: true
20 |
21 | }).then((data) => {
22 |
23 | return writeFile('dist/themes/default.min.css', data)
24 |
25 | })
26 |
27 | js('src/scripts/main.js', {
28 |
29 | optimize: true,
30 | babel: {
31 | presets: [ '@babel/preset-env' ],
32 | babelrc: false,
33 | global: true
34 | },
35 | browserify: {
36 | standalone: 'basicSlider'
37 | }
38 |
39 | }).then((data) => {
40 |
41 | return writeFile('dist/basicSlider.min.js', data)
42 |
43 | })
--------------------------------------------------------------------------------
/demos/default.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | basicSlider Demo
6 |
7 |
8 |
9 |
10 |
11 |
12 |
42 |
43 |