How to add an anchor <a> in KTOR? - ktor

How can we declare a <a> in KTOR's HTML DSL? I know there's a tag like a { href = "example.com" }, but I can't set its label. So, it doesn't appear.

From the docs you can get the following example:
a(target = "myCustomValue") { + "..." }
so for your case, this would be:
a(href= "example.com") { + "example.com" }

Related

Catch URL after click with Cypress (window.location changes)

I would like to know how to capture and read the URL after a click event on an <a> link.
On the onClick event our javascript does some string manipulation of the actual href of the clicked link and then a window.location.href = myNewReplacebleURL is done on the fly. The original href is not necessarily the location you get to after the onClick.
Here is how I started:
describe("Twitter", function() {
it("Should assert that via value is set correctly in JS", function() {
cy.server();
cy.visit(Cypress.config("appUrl") + "/probes/sha/sha-via.html");
cy.get("#v_test ul.share li a")
.click();
});
});
EDIT: What I would like is to catch the URL located at the "Page Load" step.
You should be able to use cy.on to perform your assertions inside the url:changed event callback:
cy.on("url:changed", (newUrl) => {
expect(newUrl).to.contain("?magic=true")
})
You can use thecy.location() command, example:
cy.get("#v_test ul.share li a")
.click();
cy.location('href').should('eq', 'newUrl');
Also, as an alias to the cy.location('href') command you could use cy.url().

Kotlin: Ktor how to respond text as html

I want to use library kotlin-html to produce html instead of kotlinx.html.
This library produces just a html-text:
p("A paragraph").render()
// => <p>A paragraph</p>
but I can't find how to respond html instead of text using Ktor
fun Routing.root() {
get("/") {
call.respondText {"<p>A paragraph</p>"}
}
}
This code will produce a page with text <p>A paragraph</p> instead of html-page. And it seems that call.respondHtml only works with kotlinx.html DSL. How can I do this using plain text?
You can specify ContentType.Text.Html for the ContentType parameter to respondText
call.respondText("<p>foo</p>", ContentType.Text.Html)
ContentType.Text.Plain is used by default if no ContentType if provided.
Ktor has a special module for working with kotlinx.html, so you can use
call.respondHtml {
head {
title { +"Async World" }
}
body {
h1(id = "title") {
+"Title"
}
}
}
See details here: https://ktor.io/servers/features/templates/html-dsl.html

How do I use the HTML attribute in i18n's TValueConverter with parameters?

In Aurelia's i18n it's possible to use HTML tags by this:
<span t="[html]title">Title</span>
But how do I use HTML tags when I need to use TValueConverter syntax like this one:
${'title' | t: {'some':'param'}}
I need to use that syntax because I have some parameters to pass here.
Is it even possible?
It is explained in the docs here.
// Translation file
{
"paramstest": "Some text with <strong>{{content}}</strong>"
}
// View
<span t="[html]paramstest" t-params.bind="params"></span>
// ViewModel
class MyVM {
params = { content: 'ABC' }
[...]
}

Response.Redirect not changing URL

After clicking an element on my webpage, I get the expected behavior from Response.Redirect in the trace, the break point on the expected page gets hit and proceeds to process normally. However when I'd expect the new page to be loaded, the display in the browser is not changed. It looks and behaves like the click brought you back to the same page.
I've moved the redirect call out of a try-catch block, and have tried different combinations of true/false as the second parameter with HttpContext...CompleteRequest()
What might prevent a page from being loaded after a call from Response.Redirect and the Page_Load sub completes?
Edit:
The site uses css and javascript to create a hoverable dropdown menu containing self referencing links, see below. I have tried using Chrome's dev tools to see what the network was processing. As far as I can tell from reading the Network Tab the click was creating the correct call; status 200, type xhr. xhr was the only thing that I found odd, but it looks like this is simply a reference to ajax? This leaves me in the same position. I am telling the site to redirect to new url, and I see the network take a request for that url, but the url in the address bar doesn't change; not the displayed page.
$(document).on('click','.navigation', function () {
loadItems($(this).attr('id'), $(this).attr('itemName'));
return false;
}
);
var loadItems = function (id, itemName) {
var editInfor =
{
"method": "getChildItems",
"id": id
};
$.ajax
(
{
type: "POST",
url: $.url,
dataType: "json",
data: JSON.stringify(editInfor),
success: function (jsonReply) {
$("#chkEnabled").attr('checked', jsonReply.enabled)
if (jsonReply.method == 'getChildItems') {
$("#childrens").html('');
var html = '<table>'
if (jsonReply.successfull) {
$.each(jsonReply.children, function (i, item) {
html += '<tr><td><span class="children">' + item.text + '</span></td><td><a class="moveItemUp btn" href="#" id="moveItemUp' + item.id + '">Move Up <i class="icon-circle-arrow-up"></i></a> <a class="moveItemDown btn" href="#" id="moveItemDown' + item.id + '">Move Down <i class="icon-circle-arrow-down"></i></a></td><td>Remove</td></tr>'
});
}
html += '</table>'
$($.childrens).html(html);
}
}
}
);
Please try this:
$.mobile.changePage( "/Exmaple.aspx", {
transition: "pop"
});

Windows Metro: links in img tag won't work

I am developing an app in Metro using HTML+Javascript. My links are not working when they are used to create a link in a img tag:
<h4>Go to child page</h4>
<img src="/images/home/child.jpg" />
The first link works OK and the second does not. When I click the image, it blocks the app.
For the links, I'm using a Application.PageControlNavigator as suggested in the documentation. My JS has:
(function () {
"use strict";
function linkClickEventHandler(eventInfo) {
eventInfo.preventDefault();
var link = eventInfo.target;
WinJS.Navigation.navigate(link.href);
}
WinJS.UI.Pages.define("/pages/home/home.html", {
ready: function (element, options) {
WinJS.Utilities.query("a").listen("click", linkClickEventHandler, false);
WinJS.UI.processAll();
}
});
})();
The problem is that the link.href returns the src string instead of the href string when having the tag used inside the tag . In your case the link.href returns "/images/home/child.jpg". I asssume this is a bug and not a feature. The workaround is not to use the href.link.
You can do this:
Use the onclick property of the <a> tag and call a handler() function as shown below:
<a onclick="handler();"><img src="/images/home/child.png" /></a>
Body of the handler function is as shown below:
function handler()
{
WinJS.Navigation.navigate('/pages/childpage.html');
}
Worked fine for me.
By blocks, I assume you mean "hang"? Is it calling your linkClickEventHandler when you click the image?