npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hhuploadify

v0.1.1

Published

HHuploadify is a plugin to help developer to build a image uploader quickly. It's on the shoulder of Huploadify which is based on uploadify. But it's different from the other two:

Downloads

7

Readme

HHuploadify

HHuploadify is a plugin to help developer to build a image uploader quickly. It's on the shoulder of Huploadify which is based on uploadify. But it's different from the other two:

  • most useful features for pictures, remove no use features
  • without jquery
  • auto upload
  • preview before/during upload
  • easy to extend

screenshot

Browsers <=IE8 are not supported. IE9 is partly supported, there may be some problems when you recieve responseText after uploaded.

Install

<link rel="stylesheet" href="dist/HHuploadify.css">
<script src="dist/HHuploadify.js"></script>

or with es6 module & webpack:

import './src/HHuploadify.css'
import HHuploadify from './src/HHuploadify'

using npm:

npm install --save hhuploadify
import HHuploadify from 'HHuploadify' // es6

then:

let uploader = new HHuploadify({
  container: '#upload',
  url: 'http://localhost/uploadImage',
})

Files in dist dir is only used for browser window global, those in src is only used for es6 module.

Usage

let uploader = new HHuploadify(options)
uploader.reset([ ..files.. ])

Options

defaults:

{
  container: '', // i.e. #upload

  // upload options
  url: '', // upload to which server url
  method: 'post', // http request type: post/put
  field: 'file', // upload file name field, php $_FILES['file']
  data: null, // append data in your request like: {key1:value1,key2:value2}

  // view options
  fileTypeExts: 'jpg,jpeg,png,gif,JPG,PNG,GIF,JPEG', // file can be uploaded exts like: 'jpg,png'
  fileSizeLimit: 2048, // max upload file size: KB

  multiple: true, // be or not be able to choose multi files
  single: false, // force to upload only one item, even through multiple is true
  auto: false, // auto begin to upload after select local files

  chooseText: 'Choose', // words on choose button
  uploadText: 'Upload', // words on upload button, if auto is true, upload button will not show

  template: `
    <span id="uploadify-{queueId}-{fileId}" class="uploadify-item">
      <span class="uploadify-item-container">
        <span class="uploadify-item-progress"></span>
        <a href="javascript:void(0);" class="uploadify-item-delete" data-fileid="{fileId}">&times;</a>
      </span>
    </span>
  `,

  files: null, // array, if files is not empty, list will be rendered when plugin loaded, see demo

  showUploadProcess: 'size', // bar|percent|size, when uploading, which one to show the process of uploading status
  showPreview: 1, // whether preview file before/during upload, 0: close; 1: only preview local origin file; 2: preview file on server by result 'url' fields after upload complated
  showPreviewField: 'url', // when showPreview is 2, which field will be used as image url from server side in response json

  // envents callback functions
  onInit: null, // when plugin is ready
  onSelect: null, // when select a file
  onSelectError: null,
  onUploadStart: null, // when a file upload start
  onUploadSuccess: null,// when a file upload success
  onUploadError: null, // when a file upload fail
  onUploadComplete: null, // when a file upload finished, success or failure
  onUploadCancel: null, // when cancel a file to upload
  onQueueComplete: null, // when all of the files in a queue complate (success or error), may you have more than one queue
  onRemoved: null, // when remove a file in the list
  onDestroy: null, // when all resource removed
  onReset: null, // when after reset done
}

Demo on your local machine

NodeJS and NPM should be installed on your system, then:

git clone https://github.com/tangshuang/HHuploadify.git
cd HHuploadify

npm install
npm start

Browser will be open and you can try it. You'd better to change network throttling by using browser developer tool.

We use babel & webpack to build the component, if you want to develop on it, please send a pull request.

Dragable

Through you can implement this feature by yourself, I have write one in the library, you can use it directly.

<link rel="stylesheet" href="../dist/HHuploadify.css">
<script src="../vendors/jquery-2.2.0.min.js"></script>
<script src="../vendors/jquery.dragsort-0.5.2.min.js"></script>
<script src="../dist/HHuploadify.dragable.js"></script>

You should import jquery and jquery.dragsort first. It is the same usage with previous. You can try in demo too.

Help

Q: How could I submit my picture to the database? After I upload the pictures, how can I record the picture to the article or other usage?

A: it is project level question. If you want to know the record id of your uploaded file, you should return its id in your server side response json, like:

[
  {
    id: "xxx",
    url: "xxx"
  }
]

After upload done, onUploadSuccess will be invoked. So you can do like this:

new HHuploadify({
  ...
  onUploadSuccess(file, res) {
    let data = JSON.parse(res)
    let id = data.id

    $(file.element).append('<input name="fileIdOnServer" value="' + id + '"')
  }
})

Look, a new input is in your HTML DOM, you can put HHuploadify instance in a form and then submit this form to your server.

Q: If I want to show default images when I open a page, how could I implement?

A: There is a method called reset which will reset the items in your list. But it's recommended to use it when there is no item in your list. And a more direct way is to use option.files:

let files = [
  {
    path: '...'
  },
  {
    path: '..'
  }
]
new HHuploadify({
  ...
  files,
})

Then when the instance created, there will be two default pictures in your list. You can look up this in demo.

Q: what should I return from server side?

A: because IE9 do not support FromData, I use iframe instead, which is not support json directly, so you should use Content-Type: text/plain in your response header.

Data structure is json(text):

{
  url: "xxx"
}

You can use your own fields, it is based on yourself.

More questions, submit an issue.