Here Routing API without HTML - here-api

I would like to ask you if it is possible to disable the html tags for the Routing API response.
For example:
Go to the <span class="company">U</span> station
<span class="station">U Pankstr. (Berlin)</span>
and take the <span class="transit">rail</span>
<span class="line">U8</span> towards
is the response. I would like to have this as a result:
Go to the U station
U Pankstr. (Berlin)
and take the rail
U8 towards
My api call is like the example api call from here:
https://developer.here.com/documentation/routing/dev_guide/topics/request-a-simple-route.html
It would be great if I could disable the html tags.
Thanks in advance.

If you add instructionFormat to text you get the instructions without the html tags. Example:
https://route.api.here.com/routing/7.2/calculateroute.json
?app_id={YOUR_APP_ID}
&app_code={YOUR_APP_CODE}
&waypoint0=geo!52.5,13.4
&waypoint1=geo!52.5,13.45
&instructionFormat=text
&mode=fastest;car;traffic:disabled

Related

Implementing cookies on a dismissible slide-in panel with AMP

I'm implementing a slide-in-on-scroll newsletter signup form on our site, which is built as AMP-native.
I added a button that hides the div on tap using amp-bind, but I'm struggling to get my head around how to save the closed state with cookies/localStorage in AMP.
I've gone through the favorite button example code - https://ampbyexample.com/advanced/favorite_button/ (as recommended here on SE), but I don't see how it relates to this particular use-case, especially with the use of amp-list.
Based on what I've read and few examples I found the credentials="include" attribute is needed, as is a valid CORS json endpoint and an auto generated client id appended to the endpoint url using AMPs variable substitution, but I'm not sure how to put it all together.
I took a stab hacking something together using the favorite button example, but the tutorial doesn't say much about how to setup the CORS endpoint and that particular example is for storing multiple likes to a single endpoint, as apposed to storing a specific users viewing preferences.
Here is my rough (poking-around-in-the-dark) stab at the code:
<form method="post"
id="side-newsletter-wrap"
action-xhr="/prefs&clientId=CLIENT_ID(prefs)"
target="_top"
on="submit:AMP.setState({
showSideNewsletter: !showSideNewsletter
});
submit-error:AMP.setState({
showSideNewsletter: !showSideNewsletter
});">
<button on="tap:side-newsletter-wrap.hide" class="close-button"><i
class="fa fa-times"></i></button>
<amp-list width="320"
height="360"
credentials="include"
items="."
single-item
src="/prefs&clientId=CLIENT_ID(prefs)">
<template type="amp-mustache">
{{#.}}
<?php winefolly_load_fragment('newsletter-embed'); ?>
{{/.}}
{{^.}}{{/.}}
</template>
</amp-list>
</form>
For the prefs endpoint, I'm guessing I'd need to register a new endpoint in WordPress that outputs simple array with the preferences?
Something along the lines of:
{
showSideNewsletter: "true",
winesIndexView: "grid",
winesIndexSort: "title"
}
I also tried the amp-user-notification component (which has the closed state built in) but that felt a bit hacky and the newsletter embed code (via iframe) doesn't get loaded due to a known bug - https://github.com/ampproject/amphtml/issues/18995).
Any suggestions would be much appreciated.
Chris
You're right amp-user-notification is the correct approach. Is there a way to implement the newsletter form in AMP until the amp-iframe bug is fixed?
Another way is to use amp-access, which allows you to change the layout of the page on page load. You have to store the user preference server-side though using the READER_ID to identify the user. Storing this server-side is required as you might not be able to write cookies if the page is served from the AMP Cache due to ITP 2.0.

Replace commas with <br> in CSS

We are using a CRM database which is accessed from a web console front-end. One of the merge fields retrieved from the database is the site address, which is returned as a one-line string separated by commas instead of the address format used for mailing addresses.
That is, instead of:
45 Seafield Place
FORT WILLIAM
PH33 4XJ
...it inserts:
45 Seafield Place, FORT WILLIAM, PH33 4XJ
As a proprietary product, we have no access to the configuration of the web server or the ability to modify the PHP used to generate the pages within it. The templates for customer letters are fully customisable and are simple HTML, with a #media print CSS block to control the styling when letters are printed straight from the browser (similar to Google Docs).
As I cannot control the content or make use of JavaScript/JQuery to perform text replacement, is there any way CSS can replace each comma within a class with a <br> tag?
unfortunately the only way to achieve this is using javascript.
since your server strips all javascript from the page, you have to 'trick' it and add javascript that it will not strip.
i believe it can be done by putting your javascript code into an onload attribute of your body element, this way the server will not see it as javascript but rather just an attribute and will leave it be.
<body onload="var spans = document.querySelectorAll('span');spans[0].innerHTML=spans[0].innerHTML.replace(/,/g,'<br/>');">
<span>
45 Seafield Place, FORT WILLIAM, PH33 4XJ
</span>
</body>
Live Example
UPDATE
you can even strip the javascript code yourself after executing it:
<body onload="var spans = document.querySelectorAll('span');spans[0].innerHTML=spans[0].innerHTML.replace(/,/g,'<br/>'); document.getElementsByTagName(
'body')[0].removeAttribute('onload');">
<span>
45 Seafield Place, FORT WILLIAM, PH33 4XJ
</span>
</body>
2nd Example

Spring MVC: How do I get current url in Thymeleaf

I am using Thymeleaf Template Engine with Spring Web MVC and I am got stuck while creating url's with the help of current url. Is there any way to get current inside Thymeleaf HTML file? eg: Suppose my current url in my browser address bar is:
http://localhost:8080/project/web/category/mobiles
and now I want to make a url like this http://localhost:8080/project/web/category/mobiles/store/samsung
or
http://localhost:8080/project/web/category/mobiles?min_price=10&max_price=100.
So I the code will look like this
<a th:with="currentUrl='http://localhost:8080/project/web/category/mobiles'"
th:href="#{__${currentUrl}__/__${store.name}__}">
Click to More Result
</a>
Here I am using currentUrl variable with hardcoded url, So I want to some solution for the same. The hardcoded value will not work everytime because I have dynamic categories.
I tried the same with relative url but its not working for me.
<a th:href="#{/store/__${store.name}__}">Click to More</a>
//will produce: http://localhost:8080/project/web/store/samsung
//I want: http://localhost:8080/project/web/category/mobiles/store/samsung
Please have a look and let me know if am I doing something wrong.
Oh I got the solution for this. I missed the {#httpServletRequest.requestURI} in the documentation.
Here is the solution which is working for me:
<a th:href="#{__${#httpServletRequest.requestURI}__/store/__${store.name}__}">Click to More</a>
//Will produce: http://localhost:8080/project/web/category/mobiles/store/samsung
You can get the current URL using two single ' quotes. Example:
<a th:href="#{''(lang=de)}">Deutsch</a>
Note that this unfortulately does not include existing URL parameters.
In Thymeleaf 3.1, the current URL can be obtained from the context object:
<form th:action="${#ctx.springRequestContext.requestUri}">
If the requested url is for example : http://localhost:8080/my-page
I could get this value: /my-page using this: httpServletRequest.requestURI
For example, if you have to load some resource , you can use:
<script th:src="#{|${#httpServletRequest.requestURI}/main.js|}"></script>
And renderized html will be:
<script src="/my-page/main.js"></script>

Google Analytics download link tracking

Is it necessary to URL escape the url in following js?
onclick="javascript: pageTracker._trackPageview('/internet/xyz/de/privatkunden.-Slot1-0113-File.File.FileRef.pdf/äü&.pdf');" href="/internet/xyz/de/privatkunden.-Slot1-0113-File.File.FileRef.pdf/äü&.pdf"
I JS-escaped it, before i write it on the page to make sure my JS will still work, but I'm not sure if URL escaping is required by google.
I couldn't find anything in the docs and on this board that said yes or no.
Thank you.
You don't need to escape your URL, the ga script do it for you.
äü&.pdf will be escaped as %25C3%25A4%25C3%25BC%26.pdf
Yes it works, but you should use this if you can:
Use the Async Snippet and then this:
<a onclick="_gaq.push(['_trackPageview', '/internet/xyz/de/privatkunden.-Slot1-0113-File.File.FileRef.pdf/äü&.pdf']);" href="/internet/xyz/de/privatkunden.-Slot1-0113-File.File.FileRef.pdf/äü&.pdf" target="_blank">pdf file name link</a>
The correct way to track a download link is by using the event tracking.
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
It's very similar to what you did - here is the code - _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
For example:
Download <strong>ZIP File</strong>

how can make all anchor tag (<a>) and image (<img>) fully qualified url in ASP.NET?

how can make all anchor tag and image tag in master and detail pages (asp.net) fully qualified url?
for example: http://example.com/path/file.aspx
Im using url rewriting and want all my path be fully qualified.
plz write your code.
use like below
sample
The only way I'm aware of to catch both server control output and standard HTML output is to rewrite the handler output on the fly. I wrote an HttpModule a long time ago that rewrites handler output to fully qualified URLs (<a href="../foo.gif"> to <a href="http://yoursite/images/foo.gif">) for use with FeedBurner. You may be able to take that code and adapt it for your needs.
Note that there may be a performance impact if you take this approach and you will want to ensure that's acceptable.

Resources