Browse Source

add dummy URI shortener with link in .userMenu-config-dropdown

readme-update
Simon Grim 8 years ago
parent
commit
2c26754228
  1. 1
      home.html
  2. 26
      js/interface_common.js
  3. 31
      js/twister_actions.js

1
home.html

@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
<a href="#" class="mini-profile-name">Fulano da Silva</a>
<span class="mini-profile-view">View</span>
</div>
<a class="dropdown-menu-item uri-shortener" href="#">URI shortener</a>
<a class="dropdown-menu-item" href="options.html">Options</a>
<a class="dropdown-menu-item" href="network.html">Network config</a>
<a class="dropdown-menu-item" href="profile-edit.html">Setup account</a>

26
js/interface_common.js

@ -802,6 +802,30 @@ function openConversationModal(peerAlias, resource) { @@ -802,6 +802,30 @@ function openConversationModal(peerAlias, resource) {
});
}
function openRequestShortURIForm() {
if (!defaultScreenName) {
alertPopup({
//txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS
txtMessage: 'You can\'t short links because you are not logged in.'
});
}
var uri = prompt('enter a link, watch yourself carefully'); // FIXME
newShortURI(uri,
function (req, uriLong, uriShort) {
if (uriShort)
alertPopup({
txtTitle: 'URI shortener',
txtMessage: uriLong + ' — `' + uriShort + '`'
});
else
alertPopup({
txtTitle: 'URI shortener',
txtMessage: 'something went wrong. RPC error message:\n' + (uriShort && uriShort.message) ? uriShort.message : uriShort
});
}
);
}
function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) {
var formatted = htmlFormatMsg(txt, htmlFormatMsgOpt);
@ -2251,6 +2275,8 @@ function initInterfaceCommon() { @@ -2251,6 +2275,8 @@ function initInterfaceCommon() {
$('.tox-ctc').on('click', promptCopyAttrData);
$('.bitmessage-ctc').on('click', promptCopyAttrData);
$('.uri-shortener').on('click', openRequestShortURIForm); // FIXME implement Uri Shortener Center with links library etc
if ($.fn.textcomplete) {
$('.post-area-new textarea')
.on('focus', {req: getMentionsForAutoComplete}, setTextcompleteOnEventTarget)

31
js/twister_actions.js

@ -322,6 +322,37 @@ function newRtMsg(postData, msg) { @@ -322,6 +322,37 @@ function newRtMsg(postData, msg) {
}
}
function newShortURI(uri, cbFunc, cbReq) {
if (!uri || !defaultScreenName) return;
for (var i in twister.URIs)
if (twister.URIs[i] === uri) {
if (typeof cbFunc === 'function')
cbFunc(cbReq, uri, i);
return;
}
twisterRpc('newshorturl', [defaultScreenName, lastPostId + 1, uri],
function (req, ret) {
if (ret) {
ret = ret[0]; // FIXME there should be 1 element anyway for daemon version 93500
twister.URIs[ret] = req.uri;
$.localStorage.set('twistaURIs', twister.URIs);
incLastPostId();
} else
console.warn('RPC "newshorturl" error: empty response');
if (typeof req.cbFunc === 'function')
req.cbFunc(req.cbReq, req.uri, ret);
}, {uri: uri, cbFunc: cbFunc, cbReq: cbReq},
function (req, ret) {
console.warn('RPC "newshorturl" error: ' + (ret && ret.message) ? ret.message : ret);
if (typeof req.cbFunc === 'function')
req.cbFunc(req.cbReq, req.uri, ret);
}, {uri: uri, cbFunc: cbFunc, cbReq: cbReq}
);
}
function updateProfileData(profileModalContent, username) {
//profileModalContent.find("a").attr("href",$.MAL.userUrl(username));

Loading…
Cancel
Save