Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dirk Rockendorf
metager-app
Commits
a4465150
Commit
a4465150
authored
Oct 26, 2017
by
Phil Höfer
Browse files
Improve stability by allowing multiple (3) tries to load results.
parent
873e05b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
www/app/results.js
View file @
a4465150
...
...
@@ -6,30 +6,46 @@ xhttp.send("");
return
xhttp
.
responseXML
;
}
function
render
(
content
)
function
render
(
err
,
content
)
{
style
=
loadXMLDoc
(
"
style/material.xsl
"
);
if
(
document
.
implementation
&&
document
.
implementation
.
createDocument
)
{
xsltProcessor
=
new
XSLTProcessor
();
xsltProcessor
.
importStylesheet
(
style
);
resultDocument
=
xsltProcessor
.
transformToFragment
(
content
,
document
);
document
.
body
.
replaceWith
(
resultDocument
);
}
if
(
err
)
{
}
else
{
style
=
loadXMLDoc
(
"
style/material.xsl
"
);
if
(
document
.
implementation
&&
document
.
implementation
.
createDocument
)
{
xsltProcessor
=
new
XSLTProcessor
();
xsltProcessor
.
importStylesheet
(
style
);
resultDocument
=
xsltProcessor
.
transformToFragment
(
content
,
document
);
document
.
body
.
replaceWith
(
resultDocument
);
}
}
}
/**
*
Return
s OpenSearch responseXML for the given query.
*
Deliver
s OpenSearch responseXML
to callback
for the given query.
*/
function
search
(
query
,
focus
)
{
function
search
(
query
,
focus
,
callback
,
tries
)
{
query
=
query
||
"
eingabe=
"
;
focus
=
focus
||
"
focus=web
"
;
return
loadXMLDoc
(
"
https://metager3.de/meta/meta.ger3?
"
+
focus
+
"
&
"
+
query
+
"
&encoding=utf8&out=atom10&appversion=0.1.0
"
);
let
doc
;
tries
=
tries
||
3
;
try
{
doc
=
loadXMLDoc
(
"
https://metager3.de/meta/meta.ger3?
"
+
focus
+
"
&
"
+
query
+
"
&encoding=utf8&out=atom10&appversion=3.0.0
"
);
callback
(
null
,
doc
);
}
catch
(
e
)
{
if
(
--
tries
)
{
console
.
log
(
"
search error, tries left:
"
+
tries
);
search
(
query
,
focus
,
callback
,
tries
);
}
else
{
callback
(
e
);
}
};
}
function
boot
()
{
render
(
search
(
getParameter
(
'
eingabe
'
),
getParameter
(
'
focus
'
)
)
);
search
(
getParameter
(
'
eingabe
'
),
getParameter
(
'
focus
'
)
,
render
);
}
function
getParameter
(
parameterName
)
{
...
...
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