@@ -478,7 +478,9 @@ qq.FileUploader = function(o){
478
478
// additional options
479
479
qq . extend ( this . _options , {
480
480
element : null ,
481
-
481
+ // if set, will be used instead of qq-upload-list in template
482
+ listElement : null ,
483
+
482
484
template : '<div class="qq-uploader">' +
483
485
'<div class="qq-upload-drop-area"><span>Drop files here to upload</span></div>' +
484
486
'<div class="qq-upload-button">Upload a file</div>' +
@@ -492,8 +494,8 @@ qq.FileUploader = function(o){
492
494
'<span class="qq-upload-size"></span>' +
493
495
'<a class="qq-upload-cancel" href="#">Cancel</a>' +
494
496
'<span class="qq-upload-failed-text">Failed</span>' +
495
- '</li>' ,
496
-
497
+ '</li>' ,
498
+
497
499
classes : {
498
500
// used to get elements from templates
499
501
button : 'qq-upload-button' ,
@@ -516,10 +518,12 @@ qq.FileUploader = function(o){
516
518
qq . extend ( this . _options , o ) ;
517
519
518
520
this . _element = this . _options . element ;
519
- this . _element . innerHTML = this . _options . template ;
520
- this . _classes = this . _options . classes ;
521
+ this . _element . innerHTML = this . _options . template ;
522
+ this . _listElement = this . _options . _listElement || this . _find ( this . _element , 'list' ) ;
521
523
522
- this . _button = this . _createUploadButton ( this . _getElement ( 'button' ) ) ;
524
+ this . _classes = this . _options . classes ;
525
+
526
+ this . _button = this . _createUploadButton ( this . _find ( this . _element , 'button' ) ) ;
523
527
524
528
this . _bindCancelEvent ( ) ;
525
529
this . _setupDragDrop ( ) ;
@@ -531,19 +535,9 @@ qq.extend(qq.FileUploader.prototype, qq.FileUploaderBasic.prototype);
531
535
qq . extend ( qq . FileUploader . prototype , {
532
536
/**
533
537
* Gets one of the elements listed in this._options.classes
534
- * First optional element is root for search (this._element default)
535
- * 1. this._getElement('button');
536
- * 2. this._getElement(item, 'file');
537
538
**/
538
- _getElement : function ( parent , type ) {
539
- if ( typeof parent == 'string' ) {
540
- // parent was not passed
541
- type = parent ;
542
- parent = this . _element ;
543
- }
544
-
545
- var element = qq . getByClass ( parent , this . _options . classes [ type ] ) [ 0 ] ;
546
-
539
+ _find : function ( parent , type ) {
540
+ var element = qq . getByClass ( parent , this . _options . classes [ type ] ) [ 0 ] ;
547
541
if ( ! element ) {
548
542
throw new Error ( 'element not found ' + type ) ;
549
543
}
@@ -552,7 +546,7 @@ qq.extend(qq.FileUploader.prototype, {
552
546
} ,
553
547
_setupDragDrop : function ( ) {
554
548
var self = this ,
555
- dropArea = this . _getElement ( 'drop' ) ;
549
+ dropArea = this . _find ( this . _element , 'drop' ) ;
556
550
557
551
var dz = new qq . UploadDropZone ( {
558
552
element : dropArea ,
@@ -598,7 +592,7 @@ qq.extend(qq.FileUploader.prototype, {
598
592
qq . FileUploaderBasic . prototype . _onProgress . apply ( this , arguments ) ;
599
593
600
594
var item = this . _getItemByFileId ( id ) ;
601
- var size = this . _getElement ( item , 'size' ) ;
595
+ var size = this . _find ( item , 'size' ) ;
602
596
size . style . display = 'inline' ;
603
597
604
598
var text ;
@@ -615,8 +609,8 @@ qq.extend(qq.FileUploader.prototype, {
615
609
616
610
// mark completed
617
611
var item = this . _getItemByFileId ( id ) ;
618
- qq . remove ( this . _getElement ( item , 'cancel' ) ) ;
619
- qq . remove ( this . _getElement ( item , 'spinner' ) ) ;
612
+ qq . remove ( this . _find ( item , 'cancel' ) ) ;
613
+ qq . remove ( this . _find ( item , 'spinner' ) ) ;
620
614
621
615
if ( result . success ) {
622
616
qq . addClass ( item , this . _classes . success ) ;
@@ -628,14 +622,14 @@ qq.extend(qq.FileUploader.prototype, {
628
622
var item = qq . toElement ( this . _options . fileTemplate ) ;
629
623
item . qqFileId = id ;
630
624
631
- var fileElement = this . _getElement ( item , 'file' ) ;
625
+ var fileElement = this . _find ( item , 'file' ) ;
632
626
qq . setText ( fileElement , this . _formatFileName ( fileName ) ) ;
633
- this . _getElement ( item , 'size' ) . style . display = 'none' ;
627
+ this . _find ( item , 'size' ) . style . display = 'none' ;
634
628
635
- this . _getElement ( 'list' ) . appendChild ( item ) ;
629
+ this . _listElement . appendChild ( item ) ;
636
630
} ,
637
631
_getItemByFileId : function ( id ) {
638
- var item = this . _getElement ( 'list' ) . firstChild ;
632
+ var item = this . _listElement . firstChild ;
639
633
640
634
// there can't be txt nodes in dynamically created list
641
635
// and we can use nextSibling
@@ -649,7 +643,7 @@ qq.extend(qq.FileUploader.prototype, {
649
643
**/
650
644
_bindCancelEvent : function ( ) {
651
645
var self = this ,
652
- list = this . _getElement ( 'list' ) ;
646
+ list = this . _listElement ;
653
647
654
648
qq . attach ( list , 'click' , function ( e ) {
655
649
e = e || window . event ;
0 commit comments