@@ -165,6 +165,16 @@ var _dom = function(_this, string = false, querySelectorAll = false) {
165
165
this . removeClass ( ..._arguments ) ;
166
166
}
167
167
168
+ this . setAttribute = function ( name , value ) {
169
+
170
+ for ( let i = 0 , len = this . _this . length ; i < len ; i ++ )
171
+ {
172
+ this . _this [ i ] . setAttribute ( name , value ) ;
173
+ }
174
+
175
+ return this ;
176
+ }
177
+
168
178
this . getAttribute = function ( attribute ) {
169
179
170
180
for ( let i = 0 , len = this . _this . length ; i < len ; i ++ )
@@ -425,31 +435,24 @@ function calcReadingProgressWD()
425
435
426
436
function addImageToDom ( querySelector , path , animation = true )
427
437
{
428
- if ( animation )
429
- {
430
- let src = $ ( '.fi-sha-' + querySelector + ' img, .sha-' + querySelector + ' img, img.fi-sha-' + querySelector ) ;
438
+ let backgroundImage = 'url(' + path + ')' ;
431
439
432
- if ( src . length > 0 )
433
- src . attr ( 'src' , path ) . addClass ( 'a' ) ;
434
- else
435
- $ ( '.fi-sha-' + querySelector + ', .sha-' + querySelector + ' .item-image' ) . css ( { 'background-image' : 'url(' + path + ')' } ) . addClass ( 'a' ) ;
440
+ let src = dom . queryAll ( '.fi-sha-' + querySelector + ' img, .sha-' + querySelector + ' img, img.fi-sha-' + querySelector ) ;
436
441
437
- $ ( '.pi-sha-' + querySelector ) . css ( { 'background-image' : 'url(' + path + ')' } ) . addClass ( 'a' ) ;
438
- $ ( '.ri-sha-' + querySelector ) . attr ( 'src' , path ) ;
439
- $ ( '.continue-reading-sha-' + querySelector ) . css ( { 'background-image' : 'url(' + path + ')' } ) . addClass ( 'a' ) ;
440
- }
442
+ if ( src . _this . length > 0 )
443
+ src . setAttribute ( 'src' , path ) ;
441
444
else
442
- {
443
- let src = $ ( '.fi-sha-' + querySelector + ' img, .sha-' + querySelector + ' img, img.fi-sha-' + querySelector ) ;
445
+ src = dom . queryAll ( '.fi-sha-' + querySelector + ', .sha-' + querySelector + ' .item-image' ) . css ( { backgroundImage : backgroundImage } ) ;
444
446
445
- if ( src . length > 0 )
446
- src . attr ( 'src' , path ) ;
447
- else
448
- $ ( '.fi-sha-' + querySelector + ', .sha-' + querySelector + ' .item-image' ) . css ( { 'transition' : '0s' , 'background-image' : 'url(' + path + ')' } ) ;
447
+ let pi = dom . queryAll ( '.pi-sha-' + querySelector ) . css ( { backgroundImage : backgroundImage } ) ;
448
+ let ri = dom . queryAll ( '.ri-sha-' + querySelector ) . setAttribute ( 'src' , path ) ;
449
+ let cr = dom . queryAll ( '.continue-reading-sha-' + querySelector ) . css ( { backgroundImage : backgroundImage } ) ;
449
450
450
- $ ( '.pi-sha-' + querySelector ) . css ( { 'background-image' : 'url(' + path + ')' } ) ;
451
- $ ( '.ri-sha-' + querySelector ) . attr ( 'src' , path ) ;
452
- $ ( '.continue-reading-sha-' + querySelector ) . css ( { 'transition' : '0s' , 'background-image' : 'url(' + path + ')' } ) ;
451
+ if ( animation )
452
+ {
453
+ src . addClass ( 'a' ) ;
454
+ pi . addClass ( 'a' ) ;
455
+ cr . addClass ( 'a' ) ;
453
456
}
454
457
}
455
458
@@ -506,21 +509,15 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
506
509
}
507
510
else if ( file . folder || file . compressed )
508
511
{
509
- let poster = await getFolderPoster ( filePath ) ;
510
-
511
- let images = [ ] ;
512
-
513
- if ( ! poster )
514
- {
515
- images = await getFolderThumbnails ( filePath ) ;
516
- }
512
+ let images = await getFolderThumbnails ( filePath ) ;
517
513
518
514
pathFiles . push ( {
515
+ sha : file . sha ,
519
516
name : fileName ,
520
517
path : filePath ,
521
518
mainPath : mainPath ,
522
- poster : poster ,
523
- images : images ,
519
+ poster : images . poster ,
520
+ images : images . images ,
524
521
folder : true ,
525
522
} ) ;
526
523
}
@@ -670,17 +667,11 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
670
667
671
668
for ( let key in comics )
672
669
{
673
- let poster = await getFolderPoster ( comics [ key ] . path ) ;
674
-
675
- let images = [ ] ;
676
-
677
- if ( ! poster )
678
- {
679
- images = await getFolderThumbnails ( comics [ key ] . path ) ;
680
- }
670
+ let images = await getFolderThumbnails ( comics [ key ] . path ) ;
681
671
682
- comics [ key ] . poster = poster ;
683
- comics [ key ] . images = images ;
672
+ comics [ key ] . sha = sha1 ( comics [ key ] . path ) ;
673
+ comics [ key ] . poster = images . poster ;
674
+ comics [ key ] . images = images . images ;
684
675
comics [ key ] . mainPath = config . showFullPathLibrary ? p . parse ( comics [ key ] . path ) . root : comics [ key ] . path ;
685
676
}
686
677
@@ -831,43 +822,67 @@ async function _getFolderThumbnails(file, images, _images, path, folderSha, isAs
831
822
{
832
823
let shaIndex = { } ;
833
824
834
- for ( let i = 0 , len = _images . length ; i < len ; i ++ )
825
+ let poster = false ;
826
+
827
+ if ( Array . isArray ( _images ) )
835
828
{
836
- _images [ i ] . vars = { i : i } ;
837
- shaIndex [ i ] = _images [ i ] . sha ;
838
- }
829
+ if ( isAsync ) dom . queryAll ( '.sha-' + folderSha + ' .folder-poster' ) . remove ( ) ;
839
830
840
- _images = cache . returnThumbnailsImages ( _images , function ( data , vars ) {
831
+ for ( let i = 0 , len = _images . length ; i < len ; i ++ )
832
+ {
833
+ _images [ i ] . vars = { i : i } ;
834
+ shaIndex [ i ] = _images [ i ] . sha ;
835
+ }
841
836
842
- addImageToDom ( data . sha , data . path ) ;
843
- addImageToDom ( folderSha + '-' + vars . i , data . path ) ;
837
+ _images = cache . returnThumbnailsImages ( _images , function ( data , vars ) {
844
838
845
- } , file ) ;
839
+ addImageToDom ( data . sha , data . path ) ;
840
+ addImageToDom ( folderSha + '-' + vars . i , data . path ) ;
846
841
847
- for ( let i = 0 , len = images . length ; i < len ; i ++ )
848
- {
849
- let imageCache = _images [ shaIndex [ i ] ] ;
842
+ } , file ) ;
850
843
851
- if ( imageCache && imageCache . cache )
844
+ for ( let i = 0 , len = images . length ; i < len ; i ++ )
852
845
{
853
- images [ i ] . path = imageCache . path ;
854
- images [ i ] . cache = true ;
846
+ let imageCache = _images [ shaIndex [ i ] ] ;
855
847
856
- if ( isAsync )
848
+ if ( imageCache && imageCache . cache )
857
849
{
858
- addImageToDom ( imageCache . sha , imageCache . path ) ;
859
- addImageToDom ( folderSha + '-' + i , imageCache . path ) ;
850
+ images [ i ] . path = imageCache . path ;
851
+ images [ i ] . cache = true ;
852
+
853
+ if ( isAsync )
854
+ {
855
+ addImageToDom ( imageCache . sha , imageCache . path ) ;
856
+ addImageToDom ( folderSha + '-' + i , imageCache . path ) ;
857
+ }
860
858
}
861
859
}
862
860
}
861
+ else
862
+ {
863
+ if ( isAsync ) dom . queryAll ( '.sha-' + folderSha + ' .folder-images' ) . remove ( ) ;
864
+
865
+ poster = cache . returnThumbnailsImages ( { path : _images . path , sha : _images . sha } , function ( data ) {
866
+
867
+ addImageToDom ( data . sha , data . path ) ;
868
+ addImageToDom ( folderSha + '-0' , data . path ) ;
869
+
870
+ } , file ) ;
871
+
872
+ poster . sha = folderSha + '-0' ;
863
873
864
- return images ;
874
+ images = false ;
875
+ }
876
+
877
+ return { poster : poster , images : images } ;
865
878
}
866
879
867
880
async function getFolderThumbnails ( path )
868
881
{
869
882
let folderSha = sha1 ( path ) ;
870
883
884
+ let poster = { cache : false , path : '' , sha : folderSha + '-0' } ;
885
+
871
886
let images = [
872
887
{ cache : false , path : '' , sha : folderSha + '-0' } ,
873
888
{ cache : false , path : '' , sha : folderSha + '-1' } ,
@@ -877,87 +892,27 @@ async function getFolderThumbnails(path)
877
892
878
893
try
879
894
{
880
- try
881
- {
882
- let file = fileManager . file ( path ) ;
883
- file . updateConfig ( { cacheOnly : true } ) ;
884
- let _images = await file . images ( 4 ) ;
885
-
886
- images = await _getFolderThumbnails ( file , images , _images , path , folderSha ) ;
887
- }
888
- catch ( error )
889
- {
890
- if ( error . message && error . message === 'notCacheOnly' )
891
- {
892
- queue . add ( 'folderThumbnails' , async function ( path , folderSha ) {
893
-
894
- let file = fileManager . file ( path ) ;
895
- let _images = await file . images ( 4 ) ;
895
+ let file = fileManager . file ( path ) ;
896
+ file . updateConfig ( { cacheOnly : true } ) ;
897
+ let _images = await file . images ( 4 , false , true ) ;
896
898
897
- _getFolderThumbnails ( file , images , _images , path , folderSha , true ) ;
899
+ _images = await _getFolderThumbnails ( file , images , _images , path , folderSha ) ;
898
900
899
- } , path , folderSha ) ;
900
- }
901
- else
902
- {
903
- console . error ( error ) ;
904
- dom . compressedError ( error ) ;
905
- }
906
- }
901
+ poster = _images . poster ;
902
+ images = _images . poster ? false : _images . images ;
907
903
}
908
904
catch ( error )
909
905
{
910
- console . error ( error ) ;
911
- dom . compressedError ( error ) ;
912
- }
913
-
914
- return images ;
915
- }
916
-
917
- async function getFolderPoster ( path )
918
- {
919
- let dirname = p . dirname ( path ) ;
920
- let basename = p . basename ( path ) ;
921
- let name = p . parse ( basename ) . name ;
922
-
923
- try
924
- {
925
- let file = fileManager . file ( dirname ) ;
926
- file . updateConfig ( { cacheOnly : true , fastRead : true , specialFiles : true , sha : false } ) ;
927
- let files = await file . read ( ) ;
928
-
929
- let regex = new RegExp ( '^' + pregQuote ( name ) + '\.[a-z0-9]+' ) ;
930
- let poster = false ;
931
-
932
- for ( let i = 0 , len = files . length ; i < len ; i ++ )
933
- {
934
- let file = files [ i ] ;
935
-
936
- if ( ! file . folder && ! file . compressed && regex . test ( file . name ) )
937
- {
938
- file . sha = sha1 ( file . path ) ;
939
- poster = file ;
940
-
941
- break ;
942
- }
943
- }
944
-
945
- if ( poster )
906
+ if ( error . message && error . message === 'notCacheOnly' )
946
907
{
947
- let thumbnail = cache . returnThumbnailsImages ( { path : poster . path , sha : poster . sha } , function ( data ) {
908
+ queue . add ( 'folderThumbnails' , async function ( path , folderSha ) {
948
909
949
- addImageToDom ( data . sha , data . path ) ;
910
+ let file = fileManager . file ( path ) ;
911
+ let _images = await file . images ( 4 , false , true ) ;
950
912
951
- } , file ) ;
913
+ _getFolderThumbnails ( file , images , _images , path , folderSha , true ) ;
952
914
953
- return thumbnail ;
954
- }
955
- }
956
- catch ( error )
957
- {
958
- if ( error . message && error . message === 'notCacheOnly' )
959
- {
960
- // Nothing to do
915
+ } , path , folderSha ) ;
961
916
}
962
917
else
963
918
{
@@ -966,7 +921,7 @@ async function getFolderPoster(path)
966
921
}
967
922
}
968
923
969
- return false ;
924
+ return { poster : poster , images : images } ;
970
925
}
971
926
972
927
var indexPathControlA = [ ] , indexPathA = false , indexMainPathA = false ;
0 commit comments