Skip to content

Latest commit

 

History

History
113 lines (82 loc) · 2.86 KB

optionsjs.md

File metadata and controls

113 lines (82 loc) · 2.86 KB

Options & Callbacks - JavaScript

Options

The options are the second parameter of the ImgSelect() function. This must be an object.

new ImgSelect($('#imgselect_container'), { 
    url : 'server/upload.php',
    // more options...
});

url

URL to which the request is sent. Default: server/upload.php

crop

Object of options for the Jcrop. If set to null the crop will be disabled.

  • aspectRatio - Aspect ratio of width/height (e.g. 1 for square). Default: null
  • minSize - Minimum width/height (e.g. [100, 100]). Default: null
  • maxSize - Maximum width/height (e.g. [500, 500]). Default: null
  • setSelect - Set an initial selection area ([ x1, y1, x2, y2 ]). Default: null

​data

Object or Function of custom data to be sent to the server.

Example:

// Object
data: {
    id: 12,
    val: 'hello',
},

// Or function
data: function () {
    return {
        id: 12,
        val: $('#my-input').val(),
    };
},

On the server side, inside the callbacks, the data can be retrieved using $_POST['data'].

new ImgSelect(array(
    // ...
    'before_before' => function ($crop) {
        $id = $_POST['data']['id'];
        $val = $_POST['data']['val'];
    },
));

messages

Object of messages.

  • invalidJson: 'Invalid JSON response.'
  • uploadError: 'Ajax upload error.'
  • webcam: 'Webcam Error: '
  • flashwebcam: 'Webcam Error. Please try again.'
  • uploading: 'Uploading...'
  • saving: 'Saving...'
  • jcrop: 'jQuery Jcrop not loaded'
  • minCropWidth: 'Crop selection requires a minimum width of '
  • maxCropWidth: 'Crop selection exceeds maximum width of '
  • minCropHeight: 'Crop selection requires a height of '
  • maxCropHeight: 'Crop selection exceeds maximum height of '

Callbacks

The callbacks are functions that are executed when an action is completed.

uploadComplete(image)

Called when the upload is completed. The image parameter has the following properties:

  • name - Uploaded file name (including the file extension).
  • type - File extension.
  • url - The URL to the uploaded file.
  • size - Uploaded file size in bytes.
  • width - Image width.
  • height - Image height.

Example:

new ImgSelect($('#imgselect_container'), {
    uploadComplete: function(image) {
        alert(image.name);
    },
});

cropComplete(image)

Called after the image was cropped. Is the same as uploadComplete (but does not have size property).

alert(message, type)

Called whenever an error occurs, or when the file is uploading. If you use this the default one will be override.

The type is a numeric value: 0 - hide message, 1 - success message, 2 - warning/loading message and 3 - error message.