|
| 1 | +$('#location_gallery').fileupload({ |
| 2 | + dataType:'json', |
| 3 | + url:'/upload/location', |
| 4 | + autoUpload: true, |
| 5 | + sequentialUploads:true, |
| 6 | + acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i, |
| 7 | + process:[ |
| 8 | + { |
| 9 | + action:'load', |
| 10 | + fileTypes:/^image\/(gif|jpeg|png)$/, |
| 11 | + maxFileSize: 20000000 // 20MB |
| 12 | + }, |
| 13 | + { |
| 14 | + action:'resize', |
| 15 | + maxWidth:1200, |
| 16 | + maxHeight:800 |
| 17 | + }, |
| 18 | + { |
| 19 | + action:'save' |
| 20 | + } |
| 21 | + ], |
| 22 | + dropZone: $('#gallery_dropzone'), |
| 23 | + progressall:function (e, data) { |
| 24 | + var progress = parseInt(data.loaded / data.total * 100, 10); |
| 25 | + $('#gallery_progress .bar').css('width', progress + '%'); |
| 26 | + }, |
| 27 | + filesContainer:$('#upload_gallery_files'), |
| 28 | + uploadTemplate:function (o) { |
| 29 | + var rows = $(); |
| 30 | + $.each(o.files, function (index, file) { |
| 31 | + var row = $('<li class="template-upload">' + |
| 32 | + '<div class="outer"><div class="preview"><span class="fade"></span></div>' + |
| 33 | + '<span class="cancel"><button type="button">Delete</button></span>' + |
| 34 | + '<span class="name"></span>' + |
| 35 | + '<span class="size"></span>' + |
| 36 | + (file.error ? '<span class="error">Error</span>' : |
| 37 | + '<p><div class="progress">' + |
| 38 | + '<div class="bar" style="width:0%;"></div></div></p>' + |
| 39 | + '<span class="start"><button type="button">Send</button></span>') + |
| 40 | + '</div></li>'); |
| 41 | + row.find('.name').text(file.name); |
| 42 | + row.find('.size').text(o.formatFileSize(file.size)); |
| 43 | + if (file.error) { |
| 44 | + row.find('.error').text(file.error || 'File upload error'); |
| 45 | + } |
| 46 | + rows = rows.add(row); |
| 47 | + }); |
| 48 | + return rows; |
| 49 | + }, |
| 50 | + downloadTemplate: function (o) { |
| 51 | + var rows = $(); |
| 52 | + $.each(o.files, function (index, file) { |
| 53 | + var row = $('<li class="template-download">' + |
| 54 | + '<div class="outer">' + |
| 55 | + (file.error ? '<span class="name"></span>' + |
| 56 | + '<span class="size"></span><span class="error"></span>' : |
| 57 | + '<div class="preview"></div>' + |
| 58 | + '<span class="name"><a></a></span>' + |
| 59 | + ' [<span class="size"></span>]') + |
| 60 | + '<span class="delete"><button type="button">Delete</button></span></div></li>'); |
| 61 | + row.find('.size').text(o.formatFileSize(file.size)); |
| 62 | + if (file.error) { |
| 63 | + row.find('.name').text(file.name); |
| 64 | + row.find('.error').text(file.error || 'File upload error'); |
| 65 | + } else { |
| 66 | + row.find('.name a').text(file.name); |
| 67 | + if (file.url) { |
| 68 | + row.find('.preview').append('<a><img></a>') |
| 69 | + .find('img').prop('src', file.small_url); |
| 70 | + row.find('a').prop('rel', 'gallery'); |
| 71 | + } |
| 72 | + row.find('a').prop('href', file.url); |
| 73 | + row.find('.delete button') |
| 74 | + .attr('data-type', file.delete_type) |
| 75 | + .attr('data-url', file.delete_url); |
| 76 | + // add file data input |
| 77 | + row.append('<input type="hidden" name="galleryImage[]">') |
| 78 | + .find('input[name="galleryImage[]"]').val(file.name); |
| 79 | + row.find('img').data('fileinfo',file); |
| 80 | + } |
| 81 | + rows = rows.add(row); |
| 82 | + }); |
| 83 | + return rows; |
| 84 | + } |
| 85 | +}); |
| 86 | + |
| 87 | +$('#location_cover').fileupload({ |
| 88 | + dataType:'json', |
| 89 | + url:'/upload/location', |
| 90 | + autoUpload: true, |
| 91 | + acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i, |
| 92 | + process:[ |
| 93 | + { |
| 94 | + action:'load', |
| 95 | + fileTypes:/^image\/(gif|jpeg|png)$/, |
| 96 | + maxFileSize: 20000000 // 20MB |
| 97 | + }, |
| 98 | + { |
| 99 | + action:'resize', |
| 100 | + maxWidth:1200, |
| 101 | + maxHeight:600 |
| 102 | + }, |
| 103 | + { |
| 104 | + action:'save' |
| 105 | + } |
| 106 | + ], |
| 107 | + dropZone: $('#cover_dropzone'), |
| 108 | + progressall:function (e, data) { |
| 109 | + var progress = parseInt(data.loaded / data.total * 100, 10); |
| 110 | + $('#cover_progress .bar').css('width', progress + '%'); |
| 111 | + }, |
| 112 | + filesContainer:$('#upload_cover_files'), |
| 113 | + uploadTemplate:function (o) { |
| 114 | + var rows = $(); |
| 115 | + $.each(o.files, function (index, file) { |
| 116 | + var row = $('<li class="template-upload">' + |
| 117 | + '<div class="outer"><div class="preview"><span class="fade"></span></div>' + |
| 118 | + '<span class="cancel"><button type="button">Delete</button></span>' + |
| 119 | + '<span class="name"></span>' + |
| 120 | + '<span class="size"></span>' + |
| 121 | + (file.error ? '<span class="error">Error</span>' : |
| 122 | + '<p><div class="progress">' + |
| 123 | + '<div class="bar" style="width:0%;"></div></div></p>' + |
| 124 | + '<span class="start"><button type="button">Send</button></span>') + |
| 125 | + '</div></li>'); |
| 126 | + row.find('.name').text(file.name); |
| 127 | + row.find('.size').text(o.formatFileSize(file.size)); |
| 128 | + if (file.error) { |
| 129 | + row.find('.error').text(file.error || 'File upload error'); |
| 130 | + } |
| 131 | + rows = rows.add(row); |
| 132 | + }); |
| 133 | + return rows; |
| 134 | + }, |
| 135 | + downloadTemplate: function (o) { |
| 136 | + var rows = $(); |
| 137 | + $.each(o.files, function (index, file) { |
| 138 | + var row = $('<li class="template-download">' + |
| 139 | + '<div class="outer">' + |
| 140 | + (file.error ? '<span class="name"></span>' + |
| 141 | + '<span class="size"></span><span class="error"></span>' : |
| 142 | + '<div class="preview"></div>' + |
| 143 | + '<span class="name"><a></a></span>' + |
| 144 | + '<span class="size"></span>') + |
| 145 | + '<span class="delete"><button type="button">Delete</button></span></div></li>'); |
| 146 | + row.find('.size').text(o.formatFileSize(file.size)); |
| 147 | + if (file.error) { |
| 148 | + row.find('.name').text(file.name); |
| 149 | + row.find('.error').text(file.error || 'File upload error'); |
| 150 | + } else { |
| 151 | + row.find('.name a').text(file.name); |
| 152 | + if (file.url) { |
| 153 | + row.find('.preview').append('<a><img></a>') |
| 154 | + .find('img').prop('src', file.medium_url); |
| 155 | + row.find('a').prop('rel', 'gallery'); |
| 156 | + } |
| 157 | + row.find('a').prop('href', file.url); |
| 158 | + row.find('.delete button') |
| 159 | + .attr('data-type', file.delete_type) |
| 160 | + .attr('data-url', file.delete_url); |
| 161 | + // add file data input |
| 162 | + row.append('<input type="hidden" name="excerptImage">') |
| 163 | + .find('input[name="excerptImage"]').val(file.name); |
| 164 | + row.find('img').data('fileinfo',file); |
| 165 | + } |
| 166 | + rows = rows.add(row); |
| 167 | + }); |
| 168 | + return rows; |
| 169 | + } |
| 170 | +}); |
| 171 | + |
| 172 | +$(document).bind('drop dragover', function (e) { |
| 173 | + e.preventDefault(); |
| 174 | +}); |
0 commit comments