Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Denis Salem
VenC
Commits
ff218a9b
Commit
ff218a9b
authored
Dec 17, 2018
by
Denis Salem
Browse files
done with Infinite Scroll hook
parent
984b26b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
changelog.md
View file @
ff218a9b
...
...
@@ -148,9 +148,8 @@
DONE | Escape patterns.
DONE | Chapters engine.
DONE | Fix pattern (i.e .:GetEntryTitle:.) access in template's metadata.
WIP
| Infinite scroll use html anchor instead of harcoded indexing.
DONE
| Infinite scroll use html anchor instead of harcoded indexing.
WIP | Prevent Infinite scroll to block when ressource isn't available.
WIP | Code improvement on Infinite Scroll
TODO | Fix unit test.
TODO | Open with navigator manual.
TODO | Client-side search engine.
...
...
src/share/themes/dummy/assets/VenC-Infinite-Scroll-1.
0
.0.js
→
src/share/themes/dummy/assets/VenC-Infinite-Scroll-1.
1
.0.js
View file @
ff218a9b
var
VENC_INFINITE_SCROLL
=
{
queue
:
0
,
end
:
false
,
hideVenCNavigation
:
true
,
page
Offset
:
0
,
page
Hook
:
""
,
interval
:
250
,
xmlhttp
:
Object
,
timer
:
Object
,
...
...
@@ -30,33 +31,34 @@ var VENC_INFINITE_SCROLL = {
console
.
log
(
"
VenC: There is no __VENC_LOADING__ element.
"
);
}
},
initPageOffset
:
function
()
{
currentFilename
=
this
.
currentLocation
;
if
(
currentFilename
==
''
|
currentFilename
==
"
index.html
"
)
currentFilename
=
'
0
'
;
else
if
(
currentFilename
.
replace
(
/
[
.html0123456789
]
+/g
,
''
)
!=
"
index
"
)
{
return
;
getPageHook
:
function
()
{
v
=
document
.
querySelectorAll
(
'
[data-venc-api-infinite-scroll-hook]
'
)
if
(
v
.
length
==
1
)
{
this
.
pageHook
=
v
[
0
].
dataset
.
vencApiInfiniteScrollHook
;
}
this
.
pageOffset
=
parseInt
(
currentFilename
.
replace
(
/^
\D
+/g
,
''
).
replace
(
/
[
.html
]
+/g
,
''
))
+
1
;
else
if
(
v
.
length
>
1
)
{
console
.
log
(
"
VenC: There is more than one infinite scroll hook in DOM. Aborting...
"
)
}
console
.
log
(
"
getPageHook
"
,
this
.
pageHook
);
},
pushColumns
:
function
()
{
getContent
:
function
()
{
if
(
window
.
XMLHttpRequest
)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
this
.
xmlhttp
=
new
XMLHttpRequest
();
}
else
{
// code for IE6, IE5
this
.
xmlhttp
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);
}
this
.
xmlhttp
.
onreadystatechange
=
this
.
ajax
;
this
.
xmlhttp
.
open
(
"
GET
"
,
"
index
"
+
this
.
pageOffset
+
"
.html
"
,
true
);
this
.
pageOffset
++
;
this
.
xmlhttp
.
onreadystatechange
=
this
.
domUpdate
;
this
.
xmlhttp
.
open
(
"
GET
"
,
this
.
pageHook
,
true
);
this
.
xmlhttp
.
send
();
},
dontWait
:
false
,
currentLocation
:
Object
,
ajax
:
Object
domUpdate
:
Object
};
function
VENC_INFINITE_SCROLL_
AJAX
()
{
function
VENC_INFINITE_SCROLL_
UPDATE_DOM
()
{
if
(
VENC_INFINITE_SCROLL
.
xmlhttp
.
readyState
==
4
&&
VENC_INFINITE_SCROLL
.
xmlhttp
.
status
==
200
)
{
xmlDoc
=
document
.
implementation
.
createHTMLDocument
(
''
);
xmlDoc
.
body
.
innerHTML
=
VENC_INFINITE_SCROLL
.
xmlhttp
.
responseText
;
...
...
@@ -99,10 +101,30 @@ function VENC_INFINITE_SCROLL_AJAX() {
currentColumns
[
i
].
appendChild
(
entriesClones
[
j
]);
}
}
// Update Hook
new_hook
=
xmlDoc
.
querySelectorAll
(
'
[data-venc-api-infinite-scroll-hook]
'
)
old_hook
=
document
.
querySelectorAll
(
'
[data-venc-api-infinite-scroll-hook]
'
)
if
(
new_hook
.
length
==
1
)
{
// There is no verificaton because hook exists at this point of code.
oh
=
old_hook
[
0
];
old_hook_parent
=
oh
.
parentNode
;
old_hook_parent
.
replaceChild
(
new_hook
[
0
],
oh
);
VENC_INFINITE_SCROLL
.
getPageHook
();
}
else
{
console
.
log
(
"
VenC: Infinite Scroll hook not found. Exiting...
"
);
VENC_INFINITE_SCROLL
.
end
=
true
;
}
}
};
function
VENC_INFINITE_SCROLL_RUN
()
{
if
(
VENC_INFINITE_SCROLL
.
end
)
{
clearInterval
(
VENC_INFINITE_SCROLL
.
timer
);
console
.
log
(
"
VenC: Done.
"
)
return
;
}
if
(
VENC_INFINITE_SCROLL
.
queue
==
0
)
{
VENC_INFINITE_SCROLL
.
idle
();
}
...
...
@@ -113,8 +135,8 @@ function VENC_INFINITE_SCROLL_RUN() {
viewPortHeight
=
Math
.
max
(
document
.
documentElement
.
clientHeight
,
window
.
innerHeight
||
0
);
for
(
i
=
0
;
i
<
currentColumns
.
length
;
i
++
)
{
if
(
currentColumns
[
i
].
clientHeight
<=
viewPortHeight
+
window
.
pageYOffset
)
{
if
((
VENC_INFINITE_SCROLL
.
queue
==
0
||
VENC_INFINITE_SCROLL
.
dontWait
)
&&
(
VENC_INFINITE_SCROLL
.
currentLocation
.
replace
(
/
[
.html0123456789
]
+/g
,
''
)
==
"
index
"
||
VENC_INFINITE_SCROLL
.
currentLocation
==
""
)
)
{
VENC_INFINITE_SCROLL
.
pushColumns
();
if
((
VENC_INFINITE_SCROLL
.
queue
==
0
||
VENC_INFINITE_SCROLL
.
dontWait
)
&&
!
VENC_INFINITE_SCROLL
.
end
)
{
VENC_INFINITE_SCROLL
.
getContent
();
return
1
;
}
}
...
...
@@ -124,7 +146,7 @@ function VENC_INFINITE_SCROLL_RUN() {
function
VENC_INFINITE_SCROLL_ON_LOAD
()
{
VENC_INFINITE_SCROLL
.
currentLocation
=
window
.
location
.
pathname
.
split
(
'
/
'
)[
window
.
location
.
pathname
.
split
(
'
/
'
).
length
-
1
]
VENC_INFINITE_SCROLL
.
ini
tPage
Offset
()
VENC_INFINITE_SCROLL
.
ge
tPage
Hook
()
if
(
VENC_INFINITE_SCROLL
.
hideVenCNavigation
&&
(
VENC_INFINITE_SCROLL
.
currentLocation
.
replace
(
/
[
.html0123456789
]
+/g
,
''
)
==
"
index
"
||
VENC_INFINITE_SCROLL
.
currentLocation
==
""
))
{
try
{
document
.
getElementById
(
"
__VENC_NAVIGATION__
"
).
setAttribute
(
"
style
"
,
"
display: none;
"
);
...
...
@@ -133,7 +155,7 @@ function VENC_INFINITE_SCROLL_ON_LOAD() {
console
.
log
(
"
VenC: There is no __VENC_NAVIGATION__ element.
"
);
}
}
VENC_INFINITE_SCROLL
.
ajax
=
VENC_INFINITE_SCROLL_
AJAX
;
VENC_INFINITE_SCROLL
.
domUpdate
=
VENC_INFINITE_SCROLL_
UPDATE_DOM
;
VENC_INFINITE_SCROLL
.
timer
=
setInterval
(
VENC_INFINITE_SCROLL_RUN
,
VENC_INFINITE_SCROLL
.
interval
);
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment