aboutsummaryrefslogtreecommitdiff
path: root/identify.js
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-02-01 03:01:40 +0100
committerJoop Kiefte <ikojba@gmail.com>2020-02-01 03:01:40 +0100
commitd5aa1cc524d34f112298f0d4cac0d6ccfb8817b1 (patch)
tree401bf3520bdbb2fcc69259bc57717434586739c5 /identify.js
parent908e4d9c762957876b8babee2b58c7ffd8c53a1e (diff)
parentd9325369c27eb5d96522d045004f32f1b01049f8 (diff)
Merge new contents and translate as much as possible TODO: translate settings.js
Diffstat (limited to 'identify.js')
-rw-r--r--identify.js233
1 files changed, 206 insertions, 27 deletions
diff --git a/identify.js b/identify.js
index 83191e1..17e3f6c 100644
--- a/identify.js
+++ b/identify.js
@@ -1,21 +1,90 @@
-function identify (src, profile, keys) {
+function identify (src, profile, keys, name) {
var identifyDiv = h('div')
- if (src != keys.publicKey) {
- identifyDiv.appendChild(h('p', ['Atentu: ' + src + ' ne estas vi.']))
+ if ((src[0] == '@') && (src != keys.publicKey)) {
+ identifyDiv.appendChild(h('p', [
+ 'Atentu: ' + src.substring(0, 10) + '... ne estas vi. Vi estas: ',
+ h('a', {href: '#' + keys.publicKey}, [keys.publicKey.substring(0, 10) + '...'])
+ ]))
}
var photoURL = {}
+ // this could be a hell of a lot dry-er
+
+ // also we need to get rid of UI glitches when you hit the cancel button (it should return to the same state it started in)
+
+ var newBackground = h('span', [
+ h('input', {id: 'input', type: 'file',
+ onclick: function () {
+ var canvas = document.getElementById("canvas")
+ var ctx = canvas.getContext("2d")
+
+ var maxW
+ var maxH
+
+ var input = document.getElementById('input')
+ input.addEventListener('change', handleFiles)
+
+ function handleFiles(e) {
+ var img = new Image
+ img.onload = function() {
+ var iw = img.width
+ var ih = img.height
+
+ maxW = 800
+ maxH = 800
+
+ var scale = Math.min((maxW/iw), (maxH/ih))
+ var iwScaled = iw*scale
+ var ihScaled = ih*scale
+ canvas.width = iwScaled
+ canvas.height = ihScaled
+ ctx.drawImage(img, 0, 0, iwScaled, ihScaled)
+ photoURL.value = canvas.toDataURL('image/jpeg', 0.7)
+ }
+ img.src = URL.createObjectURL(e.target.files[0])
+ }
+ }
+ }),
+ h('canvas', {id: 'canvas', width: '0', height: '0'}),
+ h('button', {
+ onclick: function () {
+ identifyDiv.appendChild(identifyButtons)
+ newBackground.parentNode.removeChild(newBackground)
+ }
+ }, ['Cancel']),
+ h('button', {
+ onclick: function () {
+ if (photoURL.value) {
+ content = {
+ type: 'background',
+ backgrounded: src,
+ background: photoURL.value
+ }
+ localforage.removeItem('image:' + src)
+ publish(content, keys).then(post => {
+ open(post).then(msg => {
+ nameInput.value = ''
+ scroller.insertBefore(render(msg, keys), scroller.childNodes[1])
+ })
+ })
+ newBackground.parentNode.removeChild(newBackground)
+ identifyDiv.appendChild(identifyButton)
+ }
+ }
+ }, ['Afiŝi'])
+ ])
+
var newPhoto = h('span', [
h('input', {id: 'input', type: 'file',
onclick: function () {
var canvas = document.getElementById("canvas")
var ctx = canvas.getContext("2d")
- var maxW = 250
- var maxH = 250
+ var maxW
+ var maxH
var input = document.getElementById('input')
input.addEventListener('change', handleFiles)
@@ -24,29 +93,42 @@ function identify (src, profile, keys) {
var img = new Image
img.onload = function() {
var iw = img.width
+ console.log(iw)
var ih = img.height
+ console.log(ih)
+
+ if (iw > ih) {
+ maxW = 680
+ maxH = 500
+ }
+ if (iw < ih) {
+ maxW = 500
+ maxH = 680
+ }
+ if (iw == ih) {
+ maxW = 500
+ maxH = 500
+ }
+
var scale = Math.min((maxW/iw), (maxH/ih))
var iwScaled = iw*scale
var ihScaled = ih*scale
canvas.width = iwScaled
canvas.height = ihScaled
ctx.drawImage(img, 0, 0, iwScaled, ihScaled)
- console.log(canvas.toDataURL('image/jpeg', 0.9))
photoURL.value = canvas.toDataURL('image/jpeg', 0.9)
- //identifyDiv.appendChild(h('img', {src: photoURL.value}))
}
img.src = URL.createObjectURL(e.target.files[0])
}
}
}),
- h('p', ['Ni rekomendas alŝuti kvadratan foton. Ĝi aŭtomate tranĉiĝas al 250 je 250 px.']),
h('canvas', {id: 'canvas', width: '0', height: '0'}),
h('button', {
onclick: function () {
identifyDiv.appendChild(identifyButtons)
newPhoto.parentNode.removeChild(newPhoto)
}
- }, ['Cancel']),
+ }, ['Nuligi']),
h('button', {
onclick: function () {
if (photoURL.value) {
@@ -55,7 +137,6 @@ function identify (src, profile, keys) {
imaged: src,
image: photoURL.value
}
- console.log(content)
localforage.removeItem('image:' + src)
publish(content, keys).then(post => {
open(post).then(msg => {
@@ -67,7 +148,69 @@ function identify (src, profile, keys) {
identifyDiv.appendChild(identifyButton)
}
}
- }, ['Publikigi'])
+ }, ['Afiŝi'])
+ ])
+
+ var descInput = h('textarea', {placeholder: 'Nova priskribo'})
+
+ var newDescription = h('div', [
+ descInput,
+ h('button', {
+ onclick: function () {
+ if (descInput.value) {
+ content = {
+ type: 'description',
+ descripted: src,
+ description: descInput.value
+ }
+ publish(content, keys).then(post => {
+ open(post).then(msg => {
+ descInput.value = ''
+ scroller.insertBefore(render(msg, keys), scroller.childNodes[1])
+ })
+ })
+ newDescription.parentNode.removeChild(newDescription)
+ identifyDiv.appendChild(identifyButton)
+ }
+ }
+ }, ['Afiŝi']),
+ h('button', {
+ onclick: function () {
+ identifyDiv.appendChild(identifyButtons)
+ newDescription.parentNode.removeChild(newDescription)
+ }
+ }, ['Nuligi'])
+ ])
+
+ var locInput = h('input', {placeholder: 'Nova loko'})
+
+ var newLocation = h('div', [
+ locInput,
+ h('button', {
+ onclick: function () {
+ if (locInput.value) {
+ content = {
+ type: 'location',
+ located: src,
+ loc: locInput.value
+ }
+ publish(content, keys).then(post => {
+ open(post).then(msg => {
+ locationInput.value = ''
+ scroller.insertBefore(render(msg, keys), scroller.childNodes[1])
+ })
+ })
+ newLocation.parentNode.removeChild(newLocation)
+ identifyDiv.appendChild(identifyButton)
+ }
+ }
+ }, ['Afiŝi']),
+ h('button', {
+ onclick: function () {
+ identifyDiv.appendChild(identifyButtons)
+ newLocation.parentNode.removeChild(newLocation)
+ }
+ }, ['Nuligi'])
])
var nameInput = h('input', {placeholder: 'Nova nomo'})
@@ -93,7 +236,7 @@ function identify (src, profile, keys) {
identifyDiv.appendChild(identifyButton)
}
}
- }, ['Publikigi']),
+ }, ['Afiŝi']),
h('button', {
onclick: function () {
identifyDiv.appendChild(identifyButtons)
@@ -102,35 +245,71 @@ function identify (src, profile, keys) {
}, ['Nuligi'])
])
- var identifyButtons = h('span', [
- h('button', {
+ var identifyButtons = h('span')
+
+ if (src[0] == '@') {
+ identifyButtons.appendChild(h('button', {
onclick: function () {
identifyDiv.appendChild(newName)
identifyButtons.parentNode.removeChild(identifyButtons)
}
- }, ['Identigi ' + src.substring(0, 10) + '... per nova nomo']),
- h('button', {
+ }, ['Nova nomo']))
+ identifyButtons.appendChild(h('button', {
onclick: function () {
- identifyDiv.appendChild(newPhoto)
+ identifyDiv.appendChild(newBackground)
identifyButtons.parentNode.removeChild(identifyButtons)
}
- }, ['Identigi ' + src.substring(0, 10) + '... per nova foto']),
- h('button', {
+ }, ['Nova fono']))
+ identifyButtons.appendChild(h('button', {
onclick: function () {
- identifyDiv.appendChild(identifyButton)
+ identifyDiv.appendChild(newDescription)
identifyButtons.parentNode.removeChild(identifyButtons)
}
- }, ['Nuligi'])
- ])
+ }, ['Nova priskribo']))
- var identifyButton = h('button', {
+ }
+ //}, ['Identify ' + src.substring(0, 10) + '... with a new name']),
+ identifyButtons.appendChild(h('button', {
onclick: function () {
- profile.appendChild(identifyDiv)
- profile.appendChild(identifyButtons)
- identifyButton.parentNode.removeChild(identifyButton)
+ identifyDiv.appendChild(newPhoto)
+ identifyButtons.parentNode.removeChild(identifyButtons)
}
- },['Identigi ' + src.substring(0, 10) + '...'])
+ }, ['Nova bildo']))
+ identifyButtons.appendChild(h('button', {
+ onclick: function () {
+ identifyDiv.appendChild(newLocation)
+ identifyButtons.parentNode.removeChild(identifyButtons)
+ }
+ }, ['Nova loko']))
+
+
+ //}, ['Identify ' + src.substring(0, 10) + '... with a new photo']),
+ identifyButtons.appendChild(h('button', {
+ onclick: function () {
+ identifyDiv.appendChild(identifyButton)
+ identifyButtons.parentNode.removeChild(identifyButtons)
+ }
+ }, ['Nuligi']))
+ /*if (src[0] == '@') {
+ var identifyButton = h('button', {
+ onclick: function () {
+ profile.appendChild(identifyDiv)
+ profile.appendChild(identifyButtons)
+ identifyButton.parentNode.removeChild(identifyButton)
+ }
+ }, ['Identify ' + name])
+ } else { */
+ var identifyButton = h('button', {
+ onclick: function () {
+ profile.appendChild(identifyDiv)
+ profile.appendChild(identifyButtons)
+ identifyButton.parentNode.removeChild(identifyButton)
+ }
+ //}, ['Add to ' + src.substring(0, 10) + '...'])
+ }, ['+'])
+ //}
+
return identifyButton
}