Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Created September 12, 2012 10:42
Show Gist options
  • Save Haraldson/3705865 to your computer and use it in GitHub Desktop.
Save Haraldson/3705865 to your computer and use it in GitHub Desktop.
PLUpload example implementation
var uploader;
$(function()
{
uploader = new plupload.Uploader(
{
runtimes: 'flash,html5,html4',
container: 'upl-img-wrap',
browse_button: 'edit-user-upload-image',
max_file_size: '4mb',
unique_names: true,
url: '/userhandler/content/image/14',
flash_swf_url: '/extension/minmatprat/design/minmatprat/flash/plupload.flash.swf',
urlstream_upload: true,
filters: [
{
title: 'Image files',
extensions: 'jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG'
}]
});
uploader.init();
uploader.bind('FilesAdded', function(up, files)
{
up.start();
up.refresh(); // Reposition Flash/Silverlight
$('#' + uploader.settings.browse_button)
.data('upload-text', $(this).text())
.text('Bilde valgt')
.siblings('.note')
.text(files[0].name);
$('#status').addClass('loading');
});
uploader.bind('Error', function(up, err)
{
up.refresh(); // Reposition Flash/Silverlight
$('#status').text('Noe gikk galt. Husk at filen må være et bilde på maks 4MB.');
});
uploader.bind('FileUploaded', function(up, file, response)
{
var image = $.parseJSON(response.response);
$.ajax(
{
url : '/index.php/layout/set/ajax/cookbook/handler/preview/' + image.object_id + '/Avatar140',
dataType : 'html',
success : function(resp)
{
var data = $(resp);
$('li.img span.img').html($(data[0]));
$('#' + uploader.settings.browse_button)
.text('Bildet er lastet opp');
//.text($(this).data('upload-text'));
$('#status').removeClass('loading');
kqw_kmie.infoUrl(image.object_id, 'km_image', 'Avatar140');
kqw_kmie.cropUrl(image.object_id, 'km_image', 'Avatar140');
$('.kqw-kmie-start').show();
$('.deleteimg').show();
/*$('form.create-recipe')
.trigger('submit'); */
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment