$(document).ready(function() { // editor save function var saveEditedImage = function(item) { // if still uploading // pend and exit if (item.upload && item.upload.status == 'loading') return item.editor.isUploadPending = true; // if not appended or not uploaded if (!item.appended && !item.uploaded) return; // if no editor if (!item.editor || !item.reader.width) return; // if uploaded // resend upload if (item.upload && item.upload.resend) { item.editor._namee = item.name; item.upload.resend(); } // if appended // send request if (item.appended) { // hide current thumbnail (this is only animation) item.imageIsUploading = true; item.image.addClass('fileuploader-loading').html(''); item.html.find('.fileuploader-action-popup').hide(); $.post('php/ajax_resize_file.php', {_file: item.file, _editor: JSON.stringify(item.editor), fileuploader: 1}, function() { item.reader.read(function() { delete item.imageIsUploading; item.html.find('.fileuploader-action-popup').show(); item.popup.html = item.popup.editor = item.editor.crop = item.editor.rotation = null; item.renderThumbnail(); }, null, true); }); } }; // enable fileuploader plugin $('input[name="files"]').fileuploader({ extensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp'], changeInput: ' ', theme: 'thumbnails', enableApi: true, addMore: true, thumbnails: { box: '
' + '' + '
', item: '
  • ' + '
    ' + '
    ${image}
    ' + '
    ' + '' + '' + '' + '
    ' + '
    ${progressBar}
    ' + '
    ' + '
  • ', item2: '
  • ' + '
    ' + '
    ${image}
    ' + '
    ' + '' + '' + '' + '
    ' + '
    ' + '
  • ', startImageRenderer: true, canvasImage: false, _selectors: { list: '.fileuploader-items-list', item: '.fileuploader-item', start: '.fileuploader-action-start', retry: '.fileuploader-action-retry', remove: '.fileuploader-action-remove', sorter: '.fileuploader-action-sort' }, onItemShow: function(item, listEl) { var plusInput = listEl.find('.fileuploader-thumbnails-input'); plusInput.insertAfter(item.html); if(item.format == 'image') { item.html.find('.fileuploader-item-icon').hide(); } } }, afterRender: function(listEl, parentEl, newInputEl, inputEl) { var plusInput = listEl.find('.fileuploader-thumbnails-input'), api = $.fileuploader.getInstance(inputEl.get(0)); plusInput.on('click', function() { api.open(); }); }, dragDrop: { container: '.fileuploader-thumbnails-input' }, onRemove: function(item) { $.post('php/upload_remove.php', { file: item.name }); }, editor: { cropper: { showGrid: true, }, onSave: function(dataURL, item) { saveEditedImage(item); } }, captions: { feedback: 'Drag and drop files here', feedback2: 'Drag and drop files here', drop: 'Drag and drop files here' }, sorter: { selectorExclude: null, placeholder: '
  • ', scrollContainer: window, onSort: function(list, listEl, parentEl, newInputEl, inputEl) { var api = $.fileuploader.getInstance(inputEl.get(0)), fileList = api.getFileList(), _list = []; $.each(fileList, function(i, item) { _list.push({ name: item.name, index: item.index }); }); $.post('php/ajax_sort_files.php', { _list: JSON.stringify(_list) }); } }, }); });