Skip to content

Commit

Permalink
Using Google Feedback when there is no Feedback link provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasgarnier committed Sep 3, 2019
1 parent b4d6882 commit 3dac865
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions claat/render/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<script src="{{.Prefix}}/codelab-elements/custom-elements.min.js"></script>
<script src="{{.Prefix}}/codelab-elements/prettify.js"></script>
<script src="{{.Prefix}}/codelab-elements/codelab-elements.js"></script>
<script type="text/javascript" src="//www.gstatic.com/feedback/api.js"></script>

</body>
</html>
10 changes: 10 additions & 0 deletions codelab-elements/google-codelab/google_codelab.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,16 @@ class Codelab extends HTMLElement {
const feedback = this.getAttribute(FEEDBACK_LINK_ATTR);
const steps = this.steps_.map((step) => step.getAttribute(LABEL_ATTR));
soy.renderElement(this.drawer_, Templates.drawer, {steps, feedback});
// Start Google Feedback when the feedback link is clicked, if it exists.
const feedbackLink = this.drawer_.querySelector('#codelab-feedback');
if (feedbackLink) {
this.eventHandler_.listen(feedbackLink, events.EventType.CLICK,
(e) => {
if (userfeedback && userfeedback.api) {
userfeedback.api.startFeedback({productId: '5143948'});
}
});
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions codelab-elements/google-codelab/google_codelab.soy
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@
{/for}
</ol>
</div>
{if $feedback}
<div id="feedback" class="metadata">
<a target="_blank" href="{$feedback}">
<div class="metadata">
<a target="_blank" {if $feedback}href="{$feedback}"{else}href="#" id="codelab-feedback"{/if}>
<i class="material-icons">bug_report</i> Report a mistake
</a>
</div>
{/if}
{/template}

0 comments on commit 3dac865

Please sign in to comment.