├── .gitignore ├── CHANGELOG ├── LICENSE ├── README.md ├── dist └── example.js ├── index.html ├── package.json ├── src ├── carousel.js ├── components │ ├── Comment.vue │ ├── Comments.vue │ ├── Photo.vue │ ├── Photos.vue │ └── Theater.vue ├── example.js └── store │ ├── actions.js │ ├── getters.js │ ├── mutations.js │ ├── states.js │ └── store.js └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | npm-debug.log 4 | .idea 5 | .vs 6 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | 5 | ## [0.5.0] 6 | 7 | ### Added 8 | - Add new Comment component 9 | - Add new Comments component 10 | - Add comments component to Theater component 11 | - Add new moment.js dependency 12 | 13 | ### Changed 14 | - Change dist name from "carousel.js" to "example.js" in order to separate example from the source 15 | - Improve import system for distributing the package with npmjs 16 | - Improve Photo component 17 | - Improve Theater component DOM tree 18 | - Improve Theater component flexbox system 19 | - Improve README and general documentation 20 | 21 | ### Removed 22 | - Remove vue instance from carousel.js 23 | 24 | 25 | ## [0.4.3] 26 | 27 | ### Added 28 | - Add new action file for the Vuex store. 29 | - Add new "hot to install" section inside readme 30 | - Add new Axios library for HTTP calls 31 | - Add new "Contributing guidelines" section inside readme 32 | 33 | 34 | ## [0.4.2] 35 | 36 | ### Added 37 | - previousPhotoOfIndex mutation 38 | - nextPhotoOfIndex mutation 39 | 40 | ### Changed 41 | - Improve theater nextPhoto and previousPhoto methods 42 | - Add new fancy comments 43 | 44 | ### Fixed 45 | - Fix changeSelectedPhoto not working correctly with undefined variables 46 | 47 | 48 | ## [0.4.1] 49 | 50 | ### Fixed 51 | - Fix a problem on changeSelectedPhoto mutation 52 | 53 | 54 | ## [0.4.0] - 27-12-2016 55 | 56 | ### Added 57 | - Add new Photo component 58 | - Add new badge on index.html 59 | 60 | ### Changed 61 | - Optimize Theater component 62 | - Improve the changeSelectedPhoto function on vuex 63 | - Improve code quality in order to have some standards across the source code 64 | 65 | ### Removed 66 | - Remove index as second parameter to change the Photo 67 | 68 | 69 | ## [0.3.0] - 23-12-2016 70 | 71 | ### Added 72 | - Add Vuex ad dependency 73 | - Add a new folder that contains the store system built with Vuex 74 | - Add components name 75 | - Add Type on components properties 76 | 77 | ### Changed 78 | - Improve the quality of the components with a complete refactor 79 | 80 | ### Fixed 81 | - Fix typo on readme 82 | 83 | ### Removed 84 | - Remove useless spacing inside the files 85 | - Remove the old shared events handler 86 | 87 | 88 | ## [0.2.1] - 07-12-2016 89 | 90 | ### Fixed 91 | - Fix a problem with npmjs.org sync 92 | 93 | 94 | ## [0.2.0] - 07-12-2016 95 | 96 | ### Added 97 | - Add Theater component 98 | - Add Photos component 99 | - Add new live demo with Bulma CSS framework 100 | 101 | ### Removed 102 | - Remove PhotoGallery component 103 | - Remove old live demo 104 | 105 | ### Fixed 106 | - Fix position of Theater component 107 | 108 | 109 | ## [0.1.0] - 29-11-2016 110 | 111 | ### Added 112 | - Add first version of the carousel component 113 | - Add simple example 114 | - Add Readme 115 | - Add this changelog 116 | - Add package.json file 117 | 118 | ### Changed 119 | - Change the example file to respect the new structure of the carousel 120 | 121 | ### Fixed 122 | 123 | ### Removed 124 | - Remove old file structure and source code 125 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Claudio Ludovico 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 all 13 | 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 THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://img.shields.io/npm/v/vuejs-carousel.svg)](https://www.npmjs.com/package/vuejs-carousel) 2 | [![Downloads](https://img.shields.io/npm/dt/vuejs-carousel.svg)](https://www.npmjs.com/package/vuejs-carousel) 3 | [![License](https://img.shields.io/npm/l/vuejs-carousel.svg)](https://www.npmjs.com/package/vuejs-carousel) 4 | 5 | [![Code Climate](https://codeclimate.com/github/ludo237/vuejs-carousel/badges/gpa.svg)](https://codeclimate.com/github/ludo237/vuejs-carousel) 6 | [![Test Coverage](https://codeclimate.com/github/ludo237/vuejs-carousel/badges/coverage.svg)](https://codeclimate.com/github/ludo237/vuejs-carousel/coverage) 7 | [![Issue Count](https://codeclimate.com/github/ludo237/vuejs-carousel/badges/issue_count.svg)](https://codeclimate.com/github/ludo237/vuejs-carousel) 8 | 9 | [![bitHound Overall Score](https://www.bithound.io/github/ludo237/vuejs-carousel/badges/score.svg)](https://www.bithound.io/github/ludo237/vuejs-carousel) 10 | [![bitHound Dependencies](https://www.bithound.io/github/ludo237/vuejs-carousel/badges/dependencies.svg)](https://www.bithound.io/github/ludo237/vuejs-carousel/master/dependencies/npm) 11 | [![bitHound Dev Dependencies](https://www.bithound.io/github/ludo237/vuejs-carousel/badges/devDependencies.svg)](https://www.bithound.io/github/ludo237/vuejs-carousel/master/dependencies/npm) 12 | [![bitHound Code](https://www.bithound.io/github/ludo237/vuejs-carousel/badges/code.svg)](https://www.bithound.io/github/ludo237/vuejs-carousel) 13 | 14 | # VueJs Carousel [![Awesome Vue](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/vuejs/awesome-vue) 15 | 16 | Easy to use VueJS component for Photo galleries, built with VueJS and web standards in mind 17 | 18 | ## How to install 19 | 20 | In order to use the carousel you have to follow 3 simple steps: 21 | 22 | - Install the package from npm `npm install vuejs-carousel --save` 23 | - Go into your Vue main file or main javascript file 24 | - Import the carousel `import {store, Photos, Theater} from "vuejs-carousel"` 25 | - Add the component inside your views 26 | 27 | 28 | ## How to use 29 | 30 | This carousel is pretty easy to use. Put the source code inside your page: 31 | 32 | 33 | 34 | Add the components to your page like the example: 35 | 36 |
37 | 38 | 39 |
40 | 41 | Try it with a source, for example you can use [Mockaroo](https://www.mockaroo.com/8e9a75b0) 42 | 43 | 44 | ## Configuration 45 | 46 | The current state of the component uses an array of `photos` objects and it expects this attributes: 47 | 48 | - id 49 | - thumbnail 50 | - photo 51 | - name 52 | - body 53 | - created_at 54 | - comments *array* 55 | - id 56 | - name 57 | - body 58 | - created_at 59 | 60 | **Be Aware**: If you have a different API structure you have to change the code a little bit in particular 61 | you have to change the attributes of `selectedPhoto` and of `photos`. I will try to make this as dynamic as 62 | possible soon... 63 | 64 | The source of the API is provided by [Mockaroo](https://www.mockaroo.com/8e9a75b0) 65 | 66 | ## Contributing 67 | 68 | If you want to contribute to this project issues and pull requests are welcome! In order to get started with the code you should: 69 | 70 | - Either download or clone this repository 71 | - Run `npm install` this will install all the necessary dependencies 72 | - Run `npm run dev` 73 | - Start coding :smile: 74 | 75 | ## License 76 | 77 | See [License file](LICENSE) for further details. 78 | 79 | ## Changelog 80 | 81 | See [Changelog File](CHANGELOG) for further details. 82 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | VueJs Carousel by Ludo237 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 | 34 |
35 | 36 |
37 |
38 |

39 | VueJs Carousel 40 | VueJs Version 41 | Part of Awesome VueJs 42 |

43 |

Easy to use VueJS component for Photo galleries, built with VueJS and web standards in mind

44 |
45 |
46 |
47 | 48 |
49 |
50 |
51 |

VueJs Carousel

52 |

VueJs Carousel is a photo gallery system that has two main components a Photos components that fetches the photos from a json request 53 | and renders them within a list and a Theater component used to display the full size of any selected photo from the gallery. The code is 54 | developed by following ECMA Script 2016 standards and is hosted on Github. Feel free to try this component and help me 55 | improving it by submitting issues or pull requests.

56 | 57 |

How to install

58 |

59 |
    60 |
  • Run npm install vuejs-carousel --save
  • 61 |
  • Include the Carousel component in your script
  • 62 |
  • Use the two components Photos and Theater inside your page
  • 63 |
  • Remember to attach a source to the Photos component
  • 64 |
65 | 66 |

Live Example

67 |

This live example uses JSON array from Mockaroo all thumbnails are 150x150 pixels and all the 68 | original images are 800x600 pixels. You can grab the current JSON schema of the example on Mockaroo

69 | 70 |
71 |
72 |
73 | 74 |
75 |
76 |
77 |

78 | VueJs Carousel by Ludo237. The source code is licensed 79 | MIT. The website content is powered by Bulma 80 | and is licensed CC ANS 4.0. 81 |

82 |

83 | 84 | 85 | 86 |

87 |
88 |
89 |
90 | 91 |
92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vuejs-carousel", 3 | "description": "Complete photo carousel build with VueJS and web standards in mind", 4 | "version": "0.6.0", 5 | "author": "Claudio Ludovico Panetta ", 6 | "private": false, 7 | "license": "MIT", 8 | "keywords": [ 9 | "carousel", 10 | "vuejs", 11 | "photo", 12 | "photo gallery", 13 | "gallery", 14 | "light box" 15 | ], 16 | "main": "src/carousel.js", 17 | "scripts": { 18 | "dev": "webpack-dev-server --open --inline --hot", 19 | "build": "webpack" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "https://github.com/ludo237/vuejs-carousel.git" 24 | }, 25 | "dependencies": { 26 | "axios": "^0.15.3", 27 | "moment": "^2.17.1", 28 | "vue": "^2.1.10", 29 | "vuex": "^2.1.2" 30 | }, 31 | "devDependencies": { 32 | "babel-core": "^6.23.1", 33 | "babel-loader": "^6.3.2", 34 | "babel-preset-es2015": "^6.22.0", 35 | "cross-env": "^3.1.4", 36 | "css-loader": "^0.26.1", 37 | "file-loader": "^0.10.0", 38 | "vue-loader": "^11.0.0", 39 | "vue-template-compiler": "^2.1.10", 40 | "webpack": "^2.1.1", 41 | "webpack-dev-server": "^2.3.0" 42 | }, 43 | "engines": { 44 | "node": ">=6.9.0" 45 | } 46 | } -------------------------------------------------------------------------------- /src/carousel.js: -------------------------------------------------------------------------------- 1 | import {store} from "./store/store"; 2 | import Photos from "./components/Photos.vue"; 3 | import Theater from "./components/Theater.vue"; 4 | 5 | export { 6 | store, 7 | Photos, 8 | Theater 9 | }; 10 | -------------------------------------------------------------------------------- /src/components/Comment.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 40 | 41 | 73 | -------------------------------------------------------------------------------- /src/components/Comments.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 35 | 36 | 48 | -------------------------------------------------------------------------------- /src/components/Photo.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 27 | 28 | 42 | -------------------------------------------------------------------------------- /src/components/Photos.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 34 | 35 | 44 | -------------------------------------------------------------------------------- /src/components/Theater.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | 109 | 110 | -------------------------------------------------------------------------------- /src/example.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import {store, Photos, Theater} from "./carousel"; 3 | 4 | 5 | const example = new Vue({ 6 | el: "#example-application", 7 | 8 | store, 9 | 10 | components: { 11 | Photos, Theater 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- 1 | import Axios from "axios"; 2 | 3 | export const actions = { 4 | 5 | /** 6 | * Load the photo from the source provided by 7 | * the gallery 8 | * 9 | * @param commit 10 | * @param {String} source 11 | */ 12 | loadPhotos: ({commit}, source) => { 13 | Axios.get(source).then(function (response) { 14 | commit("writePhotos", response.data); 15 | }).catch(function (error) { 16 | console.error(error); 17 | }); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- 1 | export const getters = { 2 | 3 | /** 4 | * Return the current array of 5 | * photos from the state property 6 | * 7 | * It doesn't matter if the array is 8 | * empty. 9 | * 10 | * @param state 11 | * @returns {Array} 12 | */ 13 | photos: state => { 14 | return state.photos; 15 | }, 16 | 17 | /** 18 | * Return the current selected photo as 19 | * an object. 20 | * 21 | * @param state 22 | * @returns {state.selectedPhoto|{}} 23 | */ 24 | selectedPhoto: state => { 25 | return state.selectedPhoto; 26 | }, 27 | 28 | /** 29 | * Returns a boolean that determine if there is 30 | * a selected photo or an empty object for the 31 | * "selectedPhoto" state 32 | * 33 | * @param state 34 | * @returns {boolean} 35 | */ 36 | isPhotoSelected: (state) => { 37 | return Object.keys(state.selectedPhoto).length > 0; 38 | }, 39 | 40 | /** 41 | * 42 | * @param state 43 | * @returns {number} 44 | */ 45 | photoIndex: state => { 46 | return state.photos.indexOf(state.selectedPhoto); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | export const mutations = { 2 | 3 | /** 4 | * Write the photos inside the Vuex store 5 | * so we can use them 6 | * 7 | * @param state 8 | * @param {Array} photos 9 | */ 10 | writePhotos(state, photos) { 11 | state.photos = photos; 12 | }, 13 | 14 | /** 15 | * Change the current photo on the theater if 16 | * exists otherwise we set the current photo to 17 | * an empty object and the theater will close automatically 18 | * 19 | * @param state 20 | * @param {Object} photo 21 | */ 22 | changeSelectedPhoto(state, photo) { 23 | state.selectedPhoto = ((photo !== undefined && photo !== null) && Object.keys(photo).length > 0) ? photo : {}; 24 | }, 25 | 26 | /** 27 | * If the index is equal to -1 we need to get the last photo of the gallery 28 | * so we can create that chain effect that we want instead of closing 29 | * the theater which is not intended at the moment. 30 | * 31 | * @param state 32 | * @param {number} index 33 | */ 34 | previousPhotoOfIndex(state, index) { 35 | index = (index + 1 === 0) ? state.photos.length - 1 : index; 36 | state.selectedPhoto = state.photos[index]; 37 | }, 38 | 39 | /** 40 | * If we reach the latest element of the array we want to go back to the first one 41 | * creating the second part of the chain for the photo gallery. 42 | * 43 | * @param state 44 | * @param {number} index 45 | */ 46 | nextPhotoOfIndex(state, index) { 47 | index = (index - state.photos.length === 0) ? 0 : index; 48 | state.selectedPhoto = state.photos[index]; 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /src/store/states.js: -------------------------------------------------------------------------------- 1 | export const state = { 2 | 3 | /** 4 | * Each time a photo is selected from 5 | * the gallery this property became a 6 | * Photo Object 7 | * 8 | * @type {Object} 9 | */ 10 | selectedPhoto: {}, 11 | 12 | /** 13 | * List of photos available inside 14 | * the gallery. 15 | * 16 | * @type {Array} 17 | */ 18 | photos: [] 19 | }; 20 | -------------------------------------------------------------------------------- /src/store/store.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Vuex from "vuex"; 3 | import {state} from "./states"; 4 | import {getters} from "./getters"; 5 | import {mutations} from "./mutations"; 6 | import {actions} from "./actions"; 7 | Vue.use(Vuex); 8 | 9 | /** 10 | * Carousel main store 11 | * 12 | * We are using the Vuex store system because 13 | * it easier to keep track of what's happening 14 | * between the Photo Gallery and the Theater 15 | * 16 | * @type {Store} 17 | */ 18 | export const store = new Vuex.Store({ 19 | state, 20 | getters, 21 | mutations, 22 | actions 23 | }); 24 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | entry: './src/example.js', 6 | output: { 7 | path: path.resolve(__dirname, './dist'), 8 | publicPath: '/dist/', 9 | filename: 'example.js' 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.vue$/, 15 | loader: 'vue-loader', 16 | options: { 17 | // vue-loader options go here 18 | } 19 | }, 20 | { 21 | test: /\.js$/, 22 | loader: 'babel-loader', 23 | exclude: /node_modules/ 24 | }, 25 | { 26 | test: /\.(png|jpg|gif|svg)$/, 27 | loader: 'file-loader', 28 | options: { 29 | name: '[name].[ext]?[hash]' 30 | } 31 | } 32 | ] 33 | }, 34 | resolve: { 35 | alias: { 36 | 'vue$': 'vue/dist/vue.common.js' 37 | } 38 | }, 39 | devServer: { 40 | historyApiFallback: true, 41 | noInfo: true 42 | }, 43 | devtool: '#eval-source-map' 44 | }; 45 | 46 | if (process.env.NODE_ENV === 'production') { 47 | module.exports.devtool = '#source-map'; 48 | // http://vue-loader.vuejs.org/en/workflow/production.html 49 | module.exports.plugins = (module.exports.plugins || []).concat([ 50 | new webpack.DefinePlugin({ 51 | 'process.env': { 52 | NODE_ENV: '"production"' 53 | } 54 | }), 55 | new webpack.optimize.UglifyJsPlugin({ 56 | sourceMap: true, 57 | compress: { 58 | warnings: false 59 | } 60 | }), 61 | new webpack.LoaderOptionsPlugin({ 62 | minimize: true 63 | }) 64 | ]); 65 | } 66 | --------------------------------------------------------------------------------