uploading.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * AJAX uploading
  4. */
  5. $maxfilesize = (int) elgg_get_plugin_setting('maxfilesize', 'tidypics');
  6. $max_files = 10;
  7. ?>
  8. elgg.provide('elgg.tidypics.uploading');
  9. elgg.tidypics.uploading.init = function() {
  10. var fields = ['Elgg', 'user_guid', 'album_guid', 'batch', 'tidypics_token'];
  11. var data = elgg.security.token;
  12. $(fields).each(function(i, name) {
  13. var value = $('input[name=' + name + ']').val();
  14. if (value) {
  15. data[name] = value;
  16. }
  17. });
  18. $("#uploader").plupload({
  19. // General settings
  20. runtimes : 'html5,html4',
  21. url : elgg.config.wwwroot + 'action/photos/image/ajax_upload',
  22. file_data_name : 'Image',
  23. dragdrop: true,
  24. multipart_params : data,
  25. max_file_size : '<?php echo $maxfilesize; ?>mb',
  26. filters : [
  27. {title : "<?php echo elgg_echo('tidypics:uploader:filetype'); ?>", extensions : "jpg,gif,png"}
  28. ],
  29. // Views to activate
  30. views: {
  31. list: true,
  32. thumbs: true,
  33. active: 'thumbs'
  34. },
  35. init : {
  36. UploadComplete: function(up, files) {
  37. // Called when all files are either uploaded or failed
  38. elgg.action('photos/image/ajax_upload_complete', {
  39. data: {
  40. album_guid: data.album_guid,
  41. batch: data.batch
  42. },
  43. success: function(json) {
  44. var url = elgg.normalize_url('photos/edit/' + json.batch_guid)
  45. window.location.href = url;
  46. }
  47. });
  48. },
  49. FilesAdded: function(up, files) {
  50. var maxfiles = <?php echo $max_files;?>;
  51. if(up.files.length > maxfiles ) {
  52. alert("<?php echo elgg_echo('tidypics:exceedmax_number', array($max_files));?>");
  53. }
  54. if(up.files.length > maxfiles ) {
  55. up.splice(maxfiles);
  56. }
  57. if (up.files.length >= maxfiles) {
  58. up.disableBrowse(true);
  59. }
  60. },
  61. FilesRemoved: function(up, files) {
  62. var maxfiles = <?php echo $max_files;?>;
  63. if (up.files.length < maxfiles) {
  64. up.disableBrowse(false);
  65. }
  66. }
  67. }
  68. });
  69. };
  70. elgg.register_hook_handler('init', 'system', elgg.tidypics.uploading.init);