Giter Site home page Giter Site logo

roshdy / meteor-autoform-slingshot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timbrandin/autoform-slingshot

0.0 2.0 0.0 37 KB

Autoform file upload directive using slingshot

License: MIT License

CoffeeScript 69.07% HTML 22.34% CSS 3.04% JavaScript 5.55%

meteor-autoform-slingshot's Introduction

Autoform Slingshot

Pretty much a clone of yogiben:autoform-file using edgee:slingshot instead of CFS, based on ryanswrt:autoform-slingshot.

NOTICE! There is no tests, so use at your own discretion! We are happy for any PR containing tests, and helping this package get to 1.0.

Usage

meteor add timbrandin:autoform-slingshot

Follow Slingshot's instructions on setting up a directive, then define the following autoform rules in your schema. If you want to resize before upload the following is an example using timbrandin:image-resize-client.

Upload a file

The resulting field will contain the URL of the uploaded file.

file: {
  type: String,
  optional:true,
  autoform: {
    type: 'slingshotFileUpload',
    afFieldInput:{
      slingshotdirective: 'myDefinedDirective'
    }
  }
}

Upload a resized picture

The resulting field will contain the URL of the uploaded picture.

We're using the Resize package from

picture_url: {
  type: String,
  optional:true,
  autoform: {
    type: 'slingshotFileUpload',
    afFieldInput:{
      slingshotdirective: {
        directive: 'myDefinedDirective',
        // onBeforeUpload is called once on each file.
        onBeforeUpload: function(file, callback) {
          Resizer.resize(file, {width: 1020, height: 1020, cropSquare: true}, function(err, file) {
            if( err ){
              console.error( err );
              callback( file );
            }else{
              callback( file );
            }
          });
        }
      }
    }
  }
}

Upload a picture (with multiple resized versions)

If you want multiple sizes for a uploaded picture and you want the client to do all the work resizing images for you, you can now define multiple directives:

picture: {
  // This package can also take type: [String],
  // but in that case it will only save the src.
  type: [Object],
  label: 'Select Picture', // (optional, defaults to "Select")
  optional: true, // (optional)
  autoform: {
    type: 'slingshotFileUpload', // (required)
    removeLabel: 'Remove', // (optional, defaults to "Remove")
    afFormGroup: { // (optional)
      label: false
    },
    afFieldInput: {
      // Specify which slingshotdirective to present as thumbnail when  this picture is uploaded, you can use the "key" or "directive".
      thumbnail: 'mobile',
      slingshotdirective: {
        mobile: { // <-- This is the "key" for the "mobile" version.
          directive: "myMobileDirective",
          onBeforeUpload: function(file, callback) {
            // Create a mobile 640x640 size version.
            Resizer.resize(file, {width: 640, height: 640, cropSquare: true}, function(err, file) {
              if( err ){
                console.error( err );
              }
              callback( file );
            });
          }
        },
        large: { // <-- This is the "key" for the "large" version.
          directive: "myLargeDirective",
          onBeforeUpload: function(file, callback) {
            // Create a large 1500x1500 size version.
            Resizer.resize(file, {width: 1500, height: 1500, cropSquare: false}, function(err, file) {
              if( err ){
                console.error( err );
              }
              callback( file );
            });
          }
        },
        original: "myOriginalDirective"
      }
    }
  }
},
// NOTICE! These are required for type: [Object].
'picture.$.key': { type: String },
'picture.$.filename': { type: String },
'picture.$.src': { type: String },
'picture.$.directive': { type: String }

Framework support

  • Bootstrap 3
  • Ionic (Meteoric)

meteor-autoform-slingshot's People

Contributors

jimmiebtlr avatar roshdy avatar ryanswart avatar ryanswrt avatar timbrandin avatar

Watchers

 avatar  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.