git ssb

3+

dust / capsule



Commit 578ffa8b1012f2827ca12664c52bd3cca2dd9757

added editable title field

dust committed on 4/9/2016, 6:56:37 PM
Parent: 4454455d4d9af8c8c0690cb55d81ad5af6d19157

Files changed

chromium/capsule.htmlchanged
chromium/capsule.jschanged
chromium/capsule.htmlView
@@ -69,8 +69,9 @@
6969 .section {
7070 padding: 2px 1% 0px;
7171 border: 2px solid black;
7272 border-radius: 2px;
73+ height: 1.5em;
7374 }
7475
7576 #capsule-menu {
7677 position: relative;
@@ -83,16 +84,17 @@
8384 position: relative;
8485 width: 97%;
8586 overflow: scroll;
8687 max-height: 400px;
87- height: 320px;
88+ height: 300px;
8889 padding: 2px 1% 0px;
8990 border: 2px solid black;
9091 }
9192
9293 #capsule-hrule {
9394 height: 2px;
9495 border-radius: 8px;
96+ margin: 1px 1px;
9597 }
9698
9799 #capsule-title {
98100 text-align: center;
@@ -143,8 +145,11 @@
143145 </head>
144146 <body>
145147 <div id="capsule-menu" class="bkg-color-s-2-2">
146148 <div id="capsule-title" class="section bkg-color-p-0 color-s-1-3">capsule</div>
149+ <div id="capsule-title-field" class="section bkg-color-s-1-2 color-s-2-3" contenteditable>
150+ enter title
151+ </div>
147152 <div id="capsule-selected-content" class="section bkg-color-comp-2 color-comp-3">
148153 no selected HTML could be parsed :(
149154 </div>
150155 <hr id="capsule-hrule" class="section bkg-color-comp-4" />
chromium/capsule.jsView
@@ -12,17 +12,18 @@
1212 })
1313 }
1414
1515 var renderSelectedHTML = function(selection) {
16- const parsedSelection = JSON.parse(selection)
17-
18- var modify = []
16+ chrome.tabs.getSelected(function(selectedTab) {
17+ const titleField = document.getElementById('capsule-title-field')
18+ titleField.innerText = selectedTab.title
1919
20- const selectedBox = document.getElementById('capsule-selected-content')
21-
22- if (parsedSelection.html) {
23- selectedBox.innerHTML = parsedSelection.html
24- }
20+ const parsedSelection = JSON.parse(selection)
21+ const selectedBox = document.getElementById('capsule-selected-content')
22+ if (parsedSelection.html) {
23+ selectedBox.innerHTML = parsedSelection.html
24+ }
25+ })
2526 }
2627
2728 var encodeHTMLString = function(htmlString) {
2829 // see:
@@ -32,13 +33,13 @@
3233 // anyway we're just going to base64 it
3334 return btoa(encodeURIComponent(htmlString))
3435 }
3536
36-var sendHTML = function(htmlString, comment, channel) {
37+var sendHTML = function(htmlString, title, comment, channel) {
3738 chrome.tabs.getSelected(function(selectedTab) {
3839 let serialisedURI = 'ssb-capsule://?body='
3940 .concat(encodeHTMLString(htmlString))
40- .concat('&title=').concat(selectedTab.title)
41+ .concat('&title=').concat(title)
4142
4243 if (typeof selectedTab.url === 'string') {
4344 serialisedURI = serialisedURI.concat('&src=').concat(selectedTab.url)
4445 }
@@ -50,9 +51,9 @@
5051 if (typeof channel === 'string') {
5152 serialisedURI = serialisedURI.concat('&channel=').concat(channel)
5253 }
5354
54-
55+
5556 const serialiserTabProps = {
5657 url: encodeURI(serialisedURI),
5758 active: true
5859 }
@@ -73,27 +74,34 @@
7374 }
7475
7576 var hookToElements = function() {
7677 const sendButton = document.getElementById('capsule-send')
78+ const titleField = document.getElementById('capsule-title-field')
7779 const commentBox = document.getElementById('capsule-comment-field')
7880 const channelField = document.getElementById('capsule-channel-field')
7981
8082 channelField.addEventListener('click', clearField())
83+ channelField.addEventListener('focus', clearField())
8184 commentBox.addEventListener('click', clearField())
85+ commentBox.addEventListener('focus', clearField())
8286
8387 sendButton.addEventListener('click', function() {
8488 const selectedBox = document.getElementById('capsule-selected-content')
89+ const titleField = document.getElementById('capsule-title-field')
8590 const commentBox = document.getElementById('capsule-comment-field')
8691 const channelField = document.getElementById('capsule-channel-field')
8792
88- // optional args: comment, channel choice
93+ // optional args: title, comment, channel choice
94+ const title = (titleField.innerText.length > 0 &&
95+ titleField.innerText !== 'title here') ?
96+ titleField.innerText : null
8997 const comment = (commentBox.innerText.length > 0 &&
90- commentBox.innerText !== 'Comment here') ?
98+ commentBox.innerText !== 'comment here') ?
9199 commentBox.innerText : null
92100 const channel = channelField.innerText.length > 0 ?
93101 channelField.innerText : null
94102
95- sendHTML(selectedBox.innerHTML, comment, channel)
103+ sendHTML(selectedBox.innerHTML, title, comment, channel)
96104 })
97105 }
98106
99107 document.addEventListener('DOMContentLoaded', getSelectedHTML)

Built with git-ssb-web