Simple script format (#31)

* New script format

* Add popstate listener to p.js

* Render site creation error with focus
This commit is contained in:
Uku Taht 2020-02-06 11:25:24 +02:00 committed by GitHub
parent 1e417f03a9
commit e1ed9d59d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 23 deletions

View File

@ -116,6 +116,7 @@
page();
}
}
window.addEventListener('popstate', page)
}
function configure(key, val) {

View File

@ -111,11 +111,12 @@
var his = window.history
if (his.pushState) {
var originalFn = his['pushState']
var originalPushState = his['pushState']
his.pushState = function() {
originalFn.apply(this, arguments)
originalPushState.apply(this, arguments)
page();
}
window.addEventListener('popstate', page)
}
const queue = (window.plausible && window.plausible.q) || []

View File

@ -21,7 +21,7 @@ defmodule PlausibleWeb.SiteController do
|> put_session(site.domain <> "_offer_email_report", true)
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet")
{:error, :site, changeset, _} ->
render(conn, "new.html", changeset: changeset)
render(conn, "new.html", changeset: changeset, layout: {PlausibleWeb.LayoutView, "focus.html"})
end
end

View File

@ -214,15 +214,11 @@
<div class="my-4">
<p>Include this snippet in the <code>&lt;head&gt;</code> of your website.</p>
<div class="relative">
<%= textarea f, :domain, id: "snippet_code", class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-2 resize-none", value: snippet(), rows: 9 %>
<%= textarea f, :domain, id: "snippet_code", class: "transition overflow-hidden bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 pr-6 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-2 resize-none", value: snippet(@site), rows: 2 %>
<a onclick="var textarea = document.getElementById('snippet_code'); textarea.focus(); textarea.select(); document.execCommand('copy');" href="javascript:void(0)" class="no-underline text-indigo text-sm hover:underline">
<svg class="absolute text-indigo" style="top: 24px; right: 12px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
</a>
</div>
<div class="mt-4 text-sm">
Is your website a single-page application?
<%= link("Read the docs", class: "text-indigo hover:underline", to: "https://docs.plausible.io/single-page-application-support", target: "_blank") %>
</div>
</div>
<% end %>

View File

@ -4,16 +4,13 @@
</div>
<div class="my-4">
<p>Paste this snippet in the <code>&lt;head&gt;</code> of your website.</p>
<div class="relative">
<%= textarea f, :domain, id: "snippet_code", class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-4 resize-none", value: snippet(), rows: 9 %>
<%= textarea f, :domain, id: "snippet_code", class: "transition overflow-hidden bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 pr-6 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-4 resize-none", value: snippet(@site), rows: 2 %>
<a onclick="var textarea = document.getElementById('snippet_code'); textarea.focus(); textarea.select(); document.execCommand('copy');" href="javascript:void(0)" class="no-underline text-indigo text-sm hover:underline">
<svg class="absolute text-indigo" style="top: 24px; right: 12px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
</a>
</div>
<div class="mt-4 text-sm">
Is your website a single-page application?
<%= link("Read the docs", class: "text-indigo hover:underline", to: "https://docs.plausible.io/single-page-application-support", target: "_blank") %>
</div>
</div>
<%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{URI.encode_www_form(@site.domain)}") %>
<% end %>

View File

@ -13,17 +13,9 @@ defmodule PlausibleWeb.SiteView do
PlausibleWeb.Endpoint.url() <> "/share/" <> link.slug
end
def snippet() do
def snippet(site) do
"""
<script>
(function (w,d,s,o,f,js,fjs) {
w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script', 'plausible', 'https://plausible.io/js/p.js'));
plausible('page')
</script>\
<script async defer data-domain="#{site.domain}" src="https://plausibe.io/js/plausible.js"></script>
"""
end
end