Giter VIP home page Giter VIP logo

simplegallery.js's Introduction

simpleGallery.js

Easy gallery upload. Native. Just 2kb gzipped.

Why

Upload, surely, is a hard part in programming, probably you have had problems with that. Why not simplify? No frameworks, just 2kb gzipped!

Working

Upload Images

Change Value

Flow

When you send images and is returned a JSON data, it is saved in hidden input value. Same occurs when you edit title, reorder and remove images. After all actions, you just need to save that JSON in your database submitting the form.

Dependencies

To reorder gallery, is required Sortable, "a minimalist JavaScript library".

Install

You can get it on npm.

npm install simple-gallery-js --save-dev

Or bower, too.

bower install simple-gallery-js --save-dev

If you're not into package management, just download a ZIP file.

Setup

First, include the script located on the dist folder.

<script src="dist/simple-gallery.min.js"></script>

Now, you need to instantiate it.

new SimpleGallery('.form-upload');

Usage

When you upload images, your server needs to return a JSON data like:

  [{ "url": "http://../image1.jpg" }, { "url": "http://../image2.jpg" }, ..]

Every data will be saved into a value of any hidden input, by default:

  <input type="hidden" name="gallery">

Lastly, you also need to create a div that will contain the gallery.

  <div class="gallery-container"></div>

If you are not happy with default, change it!

// 1. Form container.
// 2. Name of hidden input that will receive gallery data.
// 3. Gallery container.

new SimpleGallery('.form-upload', 'gallery', '.gallery-container');

Cheat

<form class="form-upload" action="/" method="POST" enctype="multipart/form-data">
  <input type="hidden" name="gallery">
  <label>Image Gallery</label>
  <div class="input-upload btn">
    Upload
    <input class="upload" type="file" multiple="multiple" accept="image/*">
  </div>
  <div class="gallery-container"></div>
</form>

Advanced Options

If you don't want use same URL for upload images, add a data-action-gallery.

<form class="form-upload" action="/" method="POST" data-action-gallery='/upload' enctype="multipart/form-data"></form>

Browser Support

Chrome Firefox IE Opera Safari
29+ ✔ 46+ ✔ 11+ ✔ Nope ✘ 9.1+ ✘

License

MIT LICENSE

Copyright 2016-2016 Fabio Carvalho [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

simplegallery.js's People

Contributors

fccoelho7 avatar

Watchers

Thiago Santos avatar

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.