Browse Source

makes example of Footer/Header variables more explicit

* Use "decodeURI" instead of "unescape", because "unescape" is deprecated
* Rename variable to more explicit code is easier to understand
* Updated the variables (see css_selector_classes ) to contain only the variables currently available in wkhtmltopdf
Fábio C. Barrionuevo da Luz 9 years ago
parent
commit
b2cefd737d
1 changed files with 17 additions and 8 deletions
  1. 17 8
      src/pdf/pdfdocparts.cc

+ 17 - 8
src/pdf/pdfdocparts.cc

@@ -189,14 +189,23 @@ void PdfCommandLineParser::outputHeaderFooterDoc(Outputter * o) const {
 	o->verbatim(
 	o->verbatim(
 "<html><head><script>\n"
 "<html><head><script>\n"
 "function subst() {\n"
 "function subst() {\n"
-"  var vars={};\n"
-"  var x=window.location.search.substring(1).split('&');\n"
-"  for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}\n"
-"  var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];\n"
-"  for (var i in x) {\n"
-"    var y = document.getElementsByClassName(x[i]);\n"
-"    for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];\n"
-"  }\n"
+"    var vars = {};\n"
+"    var query_strings_from_url = document.location.search.substring(1).split('&');\n"
+"    for (var query_string in query_strings_from_url) {\n"
+"        if (query_strings_from_url.hasOwnProperty(query_string)) {\n"
+"            var temp_var = query_strings_from_url[query_string].split('=', 2);\n"
+"            vars[temp_var[0]] = decodeURI(temp_var[1]);\n"
+"        }\n"
+"    }\n"
+"    var css_selector_classes = ['page', 'frompage', 'topage', 'webpage', 'section', 'subsection', 'date', 'isodate', 'time', 'title', 'doctitle', 'sitepage', 'sitepages'];\n"
+"    for (var css_class in css_selector_classes) {\n"
+"        if (css_selector_classes.hasOwnProperty(css_class)) {\n"
+"            var element = document.getElementsByClassName(css_selector_classes[css_class]);\n"
+"            for (var j = 0; j < element.length; ++j) {\n"
+"                element[j].textContent = vars[css_selector_classes[css_class]];\n"
+"            }\n"
+"        }\n"
+"    }\n"
 "}\n"
 "}\n"
 "</script></head><body style=\"border:0; margin: 0;\" onload=\"subst()\">\n"
 "</script></head><body style=\"border:0; margin: 0;\" onload=\"subst()\">\n"
 "<table style=\"border-bottom: 1px solid black; width: 100%\">\n"
 "<table style=\"border-bottom: 1px solid black; width: 100%\">\n"