|
108 | 108 | border-radius: 3px;
|
109 | 109 | }
|
110 | 110 | .b-file {
|
| 111 | + height: 40px; |
111 | 112 | padding: 5px;
|
| 113 | + position: relative; |
112 | 114 | overflow: hidden;
|
113 | 115 | border-radius: 3px;
|
| 116 | + background-color: #fcfcfc; |
114 | 117 | background: -webkit-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
|
115 | 118 | background: -moz-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
|
116 | 119 | background: -o-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
|
117 | 120 | background: linear-gradient(to bottom, #fcfcfc 0%, #f6f6f6 100%);
|
| 121 | + clear: both; |
118 | 122 | }
|
119 | 123 | .b-file__left {
|
120 | 124 | float: left;
|
|
147 | 151 | font-size: 12px;
|
148 | 152 | margin-top: 3px;
|
149 | 153 | }
|
150 |
| - .b-file_upload .b-file__info { display: none; } |
151 | 154 |
|
152 | 155 | .b-file__bar {
|
153 | 156 | padding-top: 4px;
|
|
159 | 162 | .b-file__done {
|
160 | 163 | color: #458383;
|
161 | 164 | }
|
| 165 | + .b-file__abort { |
| 166 | + top: 10px; |
| 167 | + right: 20px; |
| 168 | + width: 15px; |
| 169 | + height: 15px; |
| 170 | + position: absolute; |
| 171 | + color: #c00; |
| 172 | + cursor: pointer; |
| 173 | + font-size: 20px; |
| 174 | + display: none; |
| 175 | + } |
| 176 | + .b-file_upload .b-file__abort { display: block; } |
162 | 177 |
|
163 | 178 | .b-progress {
|
164 | 179 | width: 200px;
|
|
281 | 296 | <div id="preview" style="margin-top: 30px"></div>
|
282 | 297 |
|
283 | 298 | <script id="b-file-ejs" type="text/ejs">
|
284 |
| - <div id="file-<%=FileAPI.uid(file)%>" class="b-file b-file_<%=file.type.split('/')[0]%>"> |
| 299 | + <div id="file-<%=FileAPI.uid(file)%>" class="js-file b-file b-file_<%=file.type.split('/')[0]%>"> |
285 | 300 | <div class="js-left b-file__left">
|
286 | 301 | <img src="<%=icon[file.type.split('/')[0]]||icon.def%>" width="32" height="32" style="margin: 2px 0 0 3px"/>
|
287 | 302 | </div>
|
|
292 | 307 | <div class="b-progress"><div class="js-bar b-progress__bar"></div></div>
|
293 | 308 | </div>
|
294 | 309 | </div>
|
| 310 | + <i class="js-abort b-file__abort" title="abort">×</i> |
295 | 311 | </div>
|
296 | 312 | </script>
|
297 | 313 |
|
298 | 314 | <script id="b-layer-ejs" type="text/ejs">
|
299 | 315 | <div class="b-layer">
|
300 | 316 | <div class="b-layer__h1"><%=file.name%></div>
|
301 |
| - <% if( info.exif ){ %> |
302 |
| - <div class="js-img b-layer__img"></div> |
303 |
| - <% } %> |
| 317 | + <div class="js-img b-layer__img"></div> |
304 | 318 | <div class="b-layer__info">
|
305 | 319 | <%
|
306 | 320 | FileAPI.each(info, function(val, key){
|
|
360 | 374 | },
|
361 | 375 |
|
362 | 376 | files: [],
|
| 377 | + index: 0, |
363 | 378 | active: false,
|
364 | 379 |
|
365 | 380 | add: function (file){
|
|
368 | 383 | if( /^image/.test(file.type) ){
|
369 | 384 | FileAPI.Image(file).preview(35).get(function (err, img){
|
370 | 385 | if( !err ){
|
371 |
| - |
372 | 386 | FU._getEl(file, '.js-left')
|
373 | 387 | .addClass('b-file__left_border')
|
374 | 388 | .html(img)
|
375 | 389 | ;
|
376 |
| - |
377 |
| - FU._getEl(file).click(function (){ |
378 |
| - FU.showLayer(file); |
379 |
| - return false; |
380 |
| - }); |
381 | 390 | }
|
382 | 391 | });
|
383 | 392 | }
|
384 |
| - else { |
385 |
| - FU._getEl(file).click(function (){ |
386 |
| - FU.showLayer(file); |
387 |
| - return false; |
388 |
| - }); |
| 393 | + }, |
| 394 | + |
| 395 | + getFileById: function (id){ |
| 396 | + var i = FU.files.length; |
| 397 | + while( i-- ){ |
| 398 | + if( FileAPI.uid(FU.files[i]) == id ){ |
| 399 | + return FU.files[i]; |
| 400 | + } |
389 | 401 | }
|
390 | 402 | },
|
391 | 403 |
|
392 |
| - showLayer: function (file){ |
393 |
| - var $Layer = $('#layer-'+FileAPI.uid(file)); |
| 404 | + showLayer: function (id){ |
| 405 | + var $Layer = $('#layer-'+id), file = this.getFileById(id); |
394 | 406 |
|
395 | 407 | if( !$Layer[0] ){
|
396 |
| - $Layer = $('<div/>').appendTo('body').attr('id', 'layer-'+FileAPI.uid(file)); |
| 408 | + $Layer = $('<div/>').appendTo('body').attr('id', 'layer-'+id); |
397 | 409 | }
|
398 | 410 |
|
| 411 | + $Layer.css('top', $(window).scrollTop() + 30); |
| 412 | + |
399 | 413 | FileAPI.getInfo(file, function (err, info){
|
400 | 414 | $Layer
|
401 | 415 | .click(function (){ $(document).click(); })
|
402 |
| - .html(tmpl($('#b-layer-ejs').html(), { file: file, info: err ? {} : info })) |
| 416 | + .html(tmpl($('#b-layer-ejs').html(), { |
| 417 | + file: file |
| 418 | + , info: $.extend(err ? {} : info, { size: (file.size/1024).toFixed(3) + ' KB' }) |
| 419 | + })) |
403 | 420 | ;
|
404 | 421 |
|
405 | 422 | if( /image/i.test(file.type) ){
|
406 |
| - FileAPI.Image(file).preview(300).get(function (err, img){ |
407 |
| - $Layer.find('.js-img').append(img); |
408 |
| - }); |
| 423 | + if( err ){ |
| 424 | + $Layer.find('.js-img').html('Ooops.'); |
| 425 | + } |
| 426 | + else { |
| 427 | + FileAPI.Image(file).preview(300).get(function (err, img){ |
| 428 | + $Layer.find('.js-img').append(img); |
| 429 | + }); |
| 430 | + } |
| 431 | + } else { |
| 432 | + $Layer.find('.js-img').remove(); |
409 | 433 | }
|
410 | 434 |
|
411 | 435 | $(document).off('click.layer keyup.layer').one('click.layer keyup.layer', function (evt){
|
|
414 | 438 | });
|
415 | 439 | },
|
416 | 440 |
|
417 |
| - clone: function (el){ |
418 |
| - if( /canvas/i.test(el.nodeName) ){ |
419 |
| - var newEl = $(el).clone()[0]; |
420 |
| - newEl.getContext('2d').drawImage(el, 0, 0); |
421 |
| - el = newEl; |
| 441 | + start: function (){ |
| 442 | + if( !FU.active && (FU.active = FU.files.length > FU.index) ){ |
| 443 | + FU._upload(FU.files[FU.index]); |
422 | 444 | }
|
423 |
| - return $(el); |
424 | 445 | },
|
425 | 446 |
|
426 |
| - start: function (){ |
427 |
| - if( !FU.active && (FU.active = FU.files.length > 0) ){ |
428 |
| - FU._upload(FU.files.shift()); |
| 447 | + abort: function (id){ |
| 448 | + var file = this.getFileById(id); |
| 449 | + if( file.xhr ){ |
| 450 | + file.xhr.abort(); |
429 | 451 | }
|
430 | 452 | },
|
431 | 453 |
|
|
436 | 458 |
|
437 | 459 | _upload: function (file){
|
438 | 460 | if( file ){
|
439 |
| - FileAPI.upload({ |
440 |
| - url: 'http://rubaxa.org/index.php', |
| 461 | + file.xhr = FileAPI.upload({ |
| 462 | + url: 'http://www.rubaxa.org/index.php', |
441 | 463 | files: { file: file },
|
442 | 464 | upload: function (){
|
| 465 | + FU._getEl(file).addClass('b-file_upload'); |
443 | 466 | FU._getEl(file, '.js-progress')
|
444 | 467 | .css({ opacity: 0 }).show()
|
445 | 468 | .animate({ opacity: 1 }, 100)
|
|
451 | 474 | complete: function (err, xhr){
|
452 | 475 | var state = err ? 'error' : 'done';
|
453 | 476 |
|
| 477 | + FU._getEl(file).removeClass('b-file_upload'); |
454 | 478 | FU._getEl(file, '.js-progress').animate({ opacity: 0 }, 200, function (){ $(this).hide() });
|
455 |
| - FU._getEl(file, '.js-info').append(', <b class="b-file__'+state+'">'+state+'</b>'); |
| 479 | + FU._getEl(file, '.js-info').append(', <b class="b-file__'+state+'">'+(err ? (xhr.statusText || err) : state)+'</b>'); |
456 | 480 |
|
| 481 | + FU.index++; |
457 | 482 | FU.active = false;
|
| 483 | + |
458 | 484 | FU.start();
|
459 | 485 | }
|
460 | 486 | });
|
|
466 | 492 | var $Queue = $('<div/>').prependTo('#preview');
|
467 | 493 |
|
468 | 494 | FileAPI.each(files, function (file){
|
469 |
| - $Queue.append(tmpl($('#b-file-ejs').html(), { file: file, icon: FU.icon })); |
| 495 | + if( file.size >= 25*FileAPI.MB ){ |
| 496 | + alert('Sorrow.\nMax size 25MB') |
| 497 | + } |
| 498 | + else if( file.size === void 0 ){ |
| 499 | + $('#oooops').show(); |
| 500 | + $('#buttons-panel').hide(); |
| 501 | + } |
| 502 | + else { |
| 503 | + $Queue.append(tmpl($('#b-file-ejs').html(), { file: file, icon: FU.icon })); |
470 | 504 |
|
471 |
| - FU.add(file); |
472 |
| - FU.start(); |
| 505 | + FU.add(file); |
| 506 | + FU.start(); |
| 507 | + } |
473 | 508 | });
|
474 | 509 | }
|
| 510 | + |
| 511 | + |
| 512 | + $(document) |
| 513 | + .on('click', '.js-file', function (evt){ |
| 514 | + if( !evt.isDefaultPrevented() ){ |
| 515 | + FU.showLayer(evt.currentTarget.id.split('-')[1]); |
| 516 | + evt.preventDefault(); |
| 517 | + } |
| 518 | + }) |
| 519 | + .on('click', '.js-abort', function (evt){ |
| 520 | + FU.abort($(evt.target).closest('.js-file').attr('id').split('-')[1]); |
| 521 | + evt.preventDefault(); |
| 522 | + }) |
| 523 | + ; |
475 | 524 | }); // ready
|
476 | 525 | </script>
|
477 | 526 |
|
|
0 commit comments