2018-07-16 23:06:37 +02:00
|
|
|
/* global $, send */ "use strict";
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-25 21:44:02 +02:00
|
|
|
initializeTour();
|
2018-07-16 23:06:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
if (window.location.href.search && window.location.href.split("?url=")[1]) { // pre-fill example one if search parameter exists
|
2018-07-27 00:18:26 +02:00
|
|
|
const searchParameter = window.location.href.split("?url=")[1];
|
|
|
|
fetchMetadata(1, searchParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-23 23:46:58 +02:00
|
|
|
$("body").on("click", "[data-action]", event => {
|
2018-07-16 23:06:37 +02:00
|
|
|
event.preventDefault();
|
2018-08-10 00:17:47 +02:00
|
|
|
|
|
|
|
let exampleNumber;
|
2018-07-16 23:06:37 +02:00
|
|
|
const data = event.currentTarget.dataset;
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
if (!parseInt($(".tour__sidebar__example.active")[0].dataset.example)) return;
|
|
|
|
exampleNumber = parseInt($(".tour__sidebar__example.active")[0].dataset.example);
|
|
|
|
|
2018-07-16 23:06:37 +02:00
|
|
|
switch(data.action) {
|
2018-07-25 00:29:25 +02:00
|
|
|
case "choose claim":
|
2018-08-10 00:17:47 +02:00
|
|
|
fetchMetadata(exampleNumber, data.claimId);
|
2018-07-16 23:06:37 +02:00
|
|
|
break;
|
|
|
|
|
2018-07-25 00:29:25 +02:00
|
|
|
case "execute claim":
|
|
|
|
if (!$("#fetch-claim-uri").val()) return;
|
2018-08-10 00:17:47 +02:00
|
|
|
fetchMetadata(exampleNumber, $("#fetch-claim-uri").val());
|
2018-07-16 23:06:37 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
case "tour, example 1":
|
2018-08-11 00:29:06 +02:00
|
|
|
if ($("#tour-loader").hasClass("tour__content__meme")) {
|
|
|
|
$("#tour-loader").removeClass("tour__content__meme").addClass("tour__content__trends");
|
|
|
|
}
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#fetch-claim-uri").val(""); // reset URL bar
|
2018-08-11 00:29:06 +02:00
|
|
|
if ($("#tour-url")[0].style.display === "none") $("#tour-url").show();
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
$(".tour__sidebar__example").removeClass("active");
|
|
|
|
$(".tour__sidebar__example:nth-child(1)").addClass("active");
|
2018-07-23 23:46:58 +02:00
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#tour-loader").empty().show(); // .html("");
|
|
|
|
$("#tour-results").empty().show(); // .html("");
|
2018-08-10 00:17:47 +02:00
|
|
|
|
|
|
|
send(JSON.stringify({
|
|
|
|
"message": `request for ${data.action}`
|
|
|
|
}));
|
2018-08-08 22:20:53 +02:00
|
|
|
|
2018-07-23 23:46:58 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
case "tour, example 2":
|
2018-08-11 00:29:06 +02:00
|
|
|
if ($("#tour-loader").hasClass("tour__content__trends")) {
|
|
|
|
$("#tour-loader").removeClass("tour__content__trends").addClass("tour__content__meme");
|
|
|
|
}
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#fetch-claim-uri").val(""); // reset URL bar
|
2018-08-11 00:29:06 +02:00
|
|
|
$("#tour-url").hide();
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
$(".tour__sidebar__example").removeClass("active");
|
|
|
|
$(".tour__sidebar__example:nth-child(2)").addClass("active");
|
2018-07-23 23:46:58 +02:00
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#tour-loader").empty().show(); // .html("");
|
|
|
|
$("#tour-results").empty().show(); // .html("");
|
2018-08-11 00:29:06 +02:00
|
|
|
|
|
|
|
send(JSON.stringify({
|
|
|
|
"message": `request for ${data.action}`
|
|
|
|
}));
|
|
|
|
|
2018-07-23 23:46:58 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
case "tour, example 3":
|
2018-08-11 00:29:06 +02:00
|
|
|
if ($("#tour-loader").hasClass("tour__content__meme")) {
|
|
|
|
$("#tour-loader").removeClass("tour__content__meme").addClass("tour__content__trends");
|
|
|
|
}
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#fetch-claim-uri").val(""); // reset URL bar
|
2018-08-11 00:29:06 +02:00
|
|
|
if ($("#tour-url")[0].style.display === "none") $("#tour-url").show();
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
$(".tour__sidebar__example").removeClass("active");
|
|
|
|
$(".tour__sidebar__example:nth-child(3)").addClass("active");
|
|
|
|
|
2018-08-14 22:15:27 +02:00
|
|
|
$("#tour-loader").empty().show(); // .html("");
|
|
|
|
$("#tour-results").empty().show(); // .html("");
|
2018-08-10 00:17:47 +02:00
|
|
|
|
|
|
|
send(JSON.stringify({
|
|
|
|
"message": `request for ${data.action}`
|
|
|
|
}));
|
2018-07-23 23:46:58 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2018-07-25 00:29:25 +02:00
|
|
|
case "upload image":
|
2018-08-10 00:17:47 +02:00
|
|
|
fetchMetadata(exampleNumber, getMemeInfo());
|
2018-07-25 00:29:25 +02:00
|
|
|
break;
|
|
|
|
|
2018-07-16 23:06:37 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
$("body").on("click", ".tour__content__meme__canvas__thumbnail", event => {
|
|
|
|
$(".tour__content__meme__canvas__thumbnail").removeClass("selected");
|
2018-07-24 18:44:32 +02:00
|
|
|
|
|
|
|
event.currentTarget.className += " selected";
|
|
|
|
updateCanvas(event.currentTarget);
|
|
|
|
});
|
|
|
|
|
2018-08-09 16:38:42 +02:00
|
|
|
$("#fetch-claim-uri").on("keyup", function (e) {
|
|
|
|
const key = e.keyCode ? e.keyCode : e.which;
|
|
|
|
if (key === 13 && $("#fetch-claim-uri").val()) fetchMetadata(1, $("#fetch-claim-uri").val());
|
|
|
|
});
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
$("body").on("keyup", "#meme-top-line, #meme-bottom-line", () => updateCanvas());
|
2018-07-24 18:44:32 +02:00
|
|
|
|
2018-07-18 22:31:05 +02:00
|
|
|
|
|
|
|
|
2018-07-23 23:46:58 +02:00
|
|
|
// H E L P E R S
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
function detectLanguageAndUpdate() { // eslint-disable-line
|
2018-07-23 23:46:58 +02:00
|
|
|
const compare = (array1, array2) => array2.filter(value => array2.indexOf(value)); // compare two arrays and get match(es)
|
|
|
|
const memeLocaleObject = $("#meme-language").children();
|
|
|
|
const memeLocales = [];
|
|
|
|
const userLocales = [];
|
|
|
|
|
|
|
|
for (const language of navigator.languages) userLocales.push(language);
|
|
|
|
|
|
|
|
for (const key in memeLocaleObject) {
|
|
|
|
if (memeLocaleObject[key] && memeLocaleObject[key].value) memeLocales.push(memeLocaleObject[key].value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
memeLocales.length &&
|
|
|
|
userLocales.length &&
|
|
|
|
compare(memeLocales, userLocales).length
|
|
|
|
) $("#meme-language").children(`option[value="${compare(memeLocales, userLocales)[0]}"]`).attr("selected", true);
|
|
|
|
}
|
|
|
|
|
2018-07-25 21:44:02 +02:00
|
|
|
function initializeTour() {
|
2018-08-09 16:38:42 +02:00
|
|
|
$("#fetch-claim-uri").val("").focus(); // reset
|
2018-08-10 00:17:47 +02:00
|
|
|
$(".tour__sidebar__example:nth-child(1)").addClass("active");
|
2018-07-25 21:44:02 +02:00
|
|
|
|
2018-08-08 01:15:34 +02:00
|
|
|
send(JSON.stringify({
|
|
|
|
"message": "landed on tour"
|
|
|
|
}));
|
|
|
|
|
2018-08-08 22:20:53 +02:00
|
|
|
/*
|
|
|
|
TODO:
|
|
|
|
- Account for someone wanting to make multiple resolves
|
|
|
|
*/
|
2018-07-25 21:44:02 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 22:31:05 +02:00
|
|
|
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
function fetchMetadata(exampleNumber, data) {
|
|
|
|
if (!exampleNumber) return;
|
2018-07-25 00:29:25 +02:00
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
switch(exampleNumber) {
|
2018-07-25 00:29:25 +02:00
|
|
|
case 1:
|
|
|
|
send(JSON.stringify({
|
|
|
|
"claim": data,
|
|
|
|
"message": "fetch metadata",
|
|
|
|
"method": "resolve",
|
2018-08-10 00:17:47 +02:00
|
|
|
"example": exampleNumber
|
2018-07-25 00:29:25 +02:00
|
|
|
}));
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
$("#fetch-claim-uri").val(data);
|
2018-07-25 00:29:25 +02:00
|
|
|
|
2018-08-08 22:20:53 +02:00
|
|
|
$("#tour-results").html(`
|
|
|
|
<pre><code class="language-bash">
|
2018-08-14 22:15:27 +02:00
|
|
|
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
|
|
|
|
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "resolve", "params": { "uri": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
|
2018-08-08 22:20:53 +02:00
|
|
|
</code></pre>
|
2018-07-18 22:31:05 +02:00
|
|
|
|
2018-08-08 22:20:53 +02:00
|
|
|
<div class="loader" id="temp-loader"></div>
|
2018-08-10 00:17:47 +02:00
|
|
|
<div id="example1-result"></div>
|
2018-07-25 00:29:25 +02:00
|
|
|
`);
|
|
|
|
|
2018-08-08 22:20:53 +02:00
|
|
|
$("#tour-loader").hide();
|
2018-07-25 00:29:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2018-07-25 20:35:59 +02:00
|
|
|
send(JSON.stringify({
|
|
|
|
"data": data,
|
|
|
|
"message": "fetch metadata",
|
|
|
|
"method": "publish",
|
2018-08-10 00:17:47 +02:00
|
|
|
"example": exampleNumber
|
|
|
|
}));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
send(JSON.stringify({
|
|
|
|
"claim": data,
|
|
|
|
"message": "fetch metadata",
|
|
|
|
"method": "wallet_send",
|
|
|
|
"example": exampleNumber
|
2018-07-25 20:35:59 +02:00
|
|
|
}));
|
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
$("#fetch-claim-uri").val(data);
|
|
|
|
|
|
|
|
$("#tour-results").html(`
|
|
|
|
<pre><code class="language-bash">
|
2018-08-14 22:15:27 +02:00
|
|
|
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
|
|
|
|
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "wallet_send", "params": { "amount": "0.01", "claim_id": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
|
2018-08-10 00:17:47 +02:00
|
|
|
</code></pre>
|
|
|
|
|
|
|
|
<div class="loader" id="temp-loader"></div>
|
|
|
|
<div id="example3-result"></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
$("#tour-loader").hide();
|
2018-07-25 00:29:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-18 22:31:05 +02:00
|
|
|
|
2018-07-25 20:35:59 +02:00
|
|
|
function getMemeInfo() { // TODO: Error handling
|
2018-08-10 00:17:47 +02:00
|
|
|
const info = {
|
|
|
|
description: $("#meme-description").val(),
|
|
|
|
file_path: $("#meme-canvas")[0].toDataURL("image/jpeg", 0.6),
|
|
|
|
language: $("#meme-language").val(),
|
|
|
|
license: $("#meme-license").val(),
|
|
|
|
name: $("#meme-title").val(),
|
|
|
|
nsfw: $("#meme-nsfw-flag")[0].checked,
|
|
|
|
title: $("#meme-title").val()
|
|
|
|
};
|
2018-07-25 00:29:25 +02:00
|
|
|
|
2018-08-10 00:17:47 +02:00
|
|
|
/*
|
2018-07-25 00:29:25 +02:00
|
|
|
info.description = $("#meme-description").val();
|
|
|
|
info.file_path = $("#meme-canvas")[0].toDataURL("image/jpeg", 0.6);
|
|
|
|
info.language = $("#meme-language").val();
|
|
|
|
info.license = $("#meme-license").val();
|
|
|
|
info.name = $("#meme-title").val();
|
2018-07-25 20:35:59 +02:00
|
|
|
info.nsfw = $("#meme-nsfw-flag")[0].checked;
|
2018-07-25 00:29:25 +02:00
|
|
|
info.title = $("#meme-title").val();
|
2018-08-10 00:17:47 +02:00
|
|
|
*/
|
2018-07-25 00:29:25 +02:00
|
|
|
|
|
|
|
return info;
|
2018-07-18 22:31:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:29:25 +02:00
|
|
|
|
|
|
|
|
2018-07-24 18:44:32 +02:00
|
|
|
function clearCanvas(canvas) {
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.globalCompositeOperation = "copy";
|
|
|
|
ctx.strokeStyle = "transparent";
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.lineTo(0, 0);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:29:06 +02:00
|
|
|
function initCanvas() { // eslint-disable-line
|
2018-07-24 18:44:32 +02:00
|
|
|
const canvas = document.getElementById("meme-canvas");
|
|
|
|
const canvasWidth = 400;
|
|
|
|
const canvasHeight = 300;
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
const img = document.getElementById("base-image");
|
|
|
|
|
|
|
|
clearCanvas(canvas);
|
|
|
|
|
|
|
|
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight, 0, 0, canvasWidth, canvasHeight);
|
|
|
|
ctx.fillStyle = "white";
|
|
|
|
ctx.font = "bold 28px Karla";
|
|
|
|
ctx.lineJoin = "round";
|
|
|
|
ctx.lineWidth = 4;
|
|
|
|
ctx.strokeStyle = "black";
|
|
|
|
ctx.textAlign = "center";
|
|
|
|
ctx.textBaseline = "top";
|
|
|
|
ctx.strokeText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
|
|
|
|
ctx.strokeText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
|
|
|
|
ctx.fillText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
|
|
|
|
ctx.fillText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCanvas(imageSource) {
|
|
|
|
const canvas = document.getElementById("meme-canvas");
|
|
|
|
const canvasWidth = 400;
|
|
|
|
const canvasHeight = 300;
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
const img = document.getElementById("base-image");
|
|
|
|
|
|
|
|
clearCanvas(canvas);
|
|
|
|
|
|
|
|
if (imageSource) {
|
|
|
|
ctx.drawImage(imageSource, 0, 0, canvasWidth, canvasHeight, 0, 0, canvasWidth, canvasHeight);
|
|
|
|
img.src = imageSource.src;
|
|
|
|
} ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight, 0, 0, canvasWidth, canvasHeight);
|
|
|
|
|
|
|
|
ctx.strokeText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
|
|
|
|
ctx.strokeText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
|
|
|
|
ctx.fillText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
|
|
|
|
ctx.fillText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
|
|
|
|
}
|