Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Pass doc into validator ui using url #20391

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion validator/webui/@polymer/webui-mainpage/webui-mainpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,17 @@

// Interprets the parameters after the '#' in the URL.
var params = getLocationHashParams();
// Extracts the code to be validated if sent as a query param.
const incomingDocStr = getIncomingDoc(params);
if (incomingDocStr) {
editor.setEditorValue(incomingDocStr);
const format = params['htmlFormat'] || 'AMP';
urlForm.setHtmlFormat(format)
}

// If #url=<url> was provided, load it, otherwise, start with the
// minimum valid AMP document.
if (params.hasOwnProperty('url') && params['url']) {
else if (params.hasOwnProperty('url') && params['url']) {
this.$.urlForm.setURLAndValidate(params['url']);
// If filter=<error_category> was provided, filter error-list.
if (params.hasOwnProperty('filter') && params['filter']) {
Expand Down
2 changes: 1 addition & 1 deletion validator/webui/serve-standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
//
// Handle '/'.
//
if r.RequestURI == "/" {
if r.URL.Path == "/" {
bytes, err := ioutil.ReadFile("index.html")
if err != nil {
http.Error(w, "File not found.", http.StatusNotFound)
Expand Down
16 changes: 16 additions & 0 deletions validator/webui/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the license.
*/

const DOC_INPUT_ATTR = 'doc';

// Extracts a dictionary of parameters from window.location.hash.
function getLocationHashParams() {
const paramStrings = window.location.hash.substr(1).split('&');
Expand Down Expand Up @@ -46,3 +48,17 @@ function setLocationHashParams(params) {
}
window.location.hash = out.join('&');
}

// Base64 encoded ascii to ucs-2 string.
function atou(str) {
return decodeURIComponent(escape(atob(str)));
}

// Get query param that may contain an encoded document to be validated. Decode
// and return.
function getIncomingDoc(params) {
if (!params || !params[DOC_INPUT_ATTR]) {
return null;
}
return atou(params[DOC_INPUT_ATTR]);
}