mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-03-13 05:51:03 +00:00
add fetching of shortened URIs
seea00dfcf247
and alsocb020faba8
for daemon version
This commit is contained in:
parent
68fe2b0174
commit
3e43fdb594
@ -385,6 +385,9 @@
|
|||||||
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
||||||
<!-- template for user links in message (open profile modal) -->
|
<!-- template for user links in message (open profile modal) -->
|
||||||
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
||||||
|
<div id="template-link-shortened">
|
||||||
|
<a class="link-shortened" rel="nofollow" target="_blank"></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- template para ir dentro de avatar-row -->
|
<!-- template para ir dentro de avatar-row -->
|
||||||
<a id="avatar-row-template" class="open-profile-modal" href="">
|
<a id="avatar-row-template" class="open-profile-modal" href="">
|
||||||
|
@ -807,7 +807,10 @@ function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) {
|
|||||||
elem.html(formatted.html);
|
elem.html(formatted.html);
|
||||||
elem.find('a').each(function (i, elem) {
|
elem.find('a').each(function (i, elem) {
|
||||||
var href = elem.getAttribute('href');
|
var href = elem.getAttribute('href');
|
||||||
if (href && href[0] === '#')
|
if (elem.classList.contains('link-shortened')) {
|
||||||
|
$(elem).on('click mouseup', {preventDefault: true}, muteEvent);
|
||||||
|
fetchShortenedURI(href);
|
||||||
|
} else if (href && href[0] === '#')
|
||||||
$(elem)
|
$(elem)
|
||||||
.on('click', {preventDefault: true}, muteEvent)
|
.on('click', {preventDefault: true}, muteEvent)
|
||||||
.on('mouseup', {route: href}, routeOnClick)
|
.on('mouseup', {route: href}, routeOnClick)
|
||||||
@ -819,6 +822,31 @@ function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) {
|
|||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fetchShortenedURI(req) {
|
||||||
|
// FIXME need to check if ret for req is cached here
|
||||||
|
if (parseInt(twisterVersion) < 93500) {
|
||||||
|
console.warn('can\'t fetch URI "' + req + '": daemon is obsolete, version 0.9.35 or higher is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
twisterRpc('decodeshorturl', [req],
|
||||||
|
function gotShortURI(req, ret) {
|
||||||
|
// FIXME need to cache ret here
|
||||||
|
var elems = $('.link-shortened[href="' + req + '"]')
|
||||||
|
.attr('href', ret)
|
||||||
|
.removeClass('link-shortened')
|
||||||
|
.off('click mouseup')
|
||||||
|
.on('click mouseup', muteEvent)
|
||||||
|
;
|
||||||
|
for (var i = 0; i < elems.length; i++)
|
||||||
|
if (elems[i].text === req)
|
||||||
|
elems[i].text = ret;
|
||||||
|
}, req,
|
||||||
|
function (req, ret) {
|
||||||
|
console.warn('can\'t fetch URI "' + req + '": ' + ret.message);
|
||||||
|
}, req
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function routeOnClick(event) {
|
function routeOnClick(event) {
|
||||||
|
|
||||||
function routeNewTab(event) {
|
function routeNewTab(event) {
|
||||||
|
@ -25,6 +25,7 @@ $(document).ready(function() {
|
|||||||
_htmlFormatMsgLinkTemplateHashtag = _htmlFormatMsgLinkTemplateHashtag[0].cloneNode();
|
_htmlFormatMsgLinkTemplateHashtag = _htmlFormatMsgLinkTemplateHashtag[0].cloneNode();
|
||||||
_htmlFormatMsgLinkTemplateHashtag.removeAttribute('id');
|
_htmlFormatMsgLinkTemplateHashtag.removeAttribute('id');
|
||||||
}
|
}
|
||||||
|
twister.tmpl.linkShortened = extractTemplate('#template-link-shortened')[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
// format "userpost" to html element
|
// format "userpost" to html element
|
||||||
@ -626,36 +627,33 @@ function htmlFormatMsg(msg, opt) {
|
|||||||
+ '</samp><br>'
|
+ '</samp><br>'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (getSubStrEnd(msg.str, i + 1, whiteSpacesUrl, false, '') < k) // use only first word as href target, others drop silently
|
if ((x = getSubStrEnd(msg.str, i + 1, whiteSpacesUrl, false, '')) < k) // use only first word as href target, others drop silently
|
||||||
k = getSubStrEnd(msg.str, i + 1, whiteSpacesUrl, false, '');
|
k = x;
|
||||||
|
linkName = applyHtml( // we're handling markup inside [] of []()
|
||||||
|
markout(markout(markout(markout(
|
||||||
|
{str: linkName, htmlEntities: msg.htmlEntities},
|
||||||
|
markoutOpt, '*', 'b'), // bold
|
||||||
|
markoutOpt, '~', 'i'), // italic
|
||||||
|
markoutOpt, '_', 'u'), // underlined
|
||||||
|
markoutOpt, '-', 's') // striketrough
|
||||||
|
)
|
||||||
|
.replace(/&(?!lt;|gt;)/g, '&');
|
||||||
if (markoutOpt === 'apply') {
|
if (markoutOpt === 'apply') {
|
||||||
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
if (msg.str.slice(i, i + 6).toLowerCase() === 'twist:' && msg.str[i + 17] === '='
|
||||||
newHtmlEntityLink(_htmlFormatMsgLinkTemplateExternal,
|
&& getSubStrStart(msg.str, i + 16, stopCharsRightHashtags, false, '') === i + 6)
|
||||||
proxyURL(msg.str.slice(i, k + 1)),
|
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||||
applyHtml( // we're trying markup inside [] of []()
|
newHtmlEntityLink(twister.tmpl.linkShortened,
|
||||||
markout(markout(markout(markout(
|
msg.str.slice(i, i + 18), linkName)
|
||||||
{str: linkName, htmlEntities: msg.htmlEntities},
|
);
|
||||||
markoutOpt, '*', 'b'), // bold
|
else
|
||||||
markoutOpt, '~', 'i'), // italic
|
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||||
markoutOpt, '_', 'u'), // underlined
|
newHtmlEntityLink(_htmlFormatMsgLinkTemplateExternal,
|
||||||
markoutOpt, '-', 's') // striketrough
|
proxyURL(msg.str.slice(i, k + 1)), linkName)
|
||||||
)
|
);
|
||||||
.replace(/&(?!lt;|gt;)/g, '&')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else { // markoutOpt === 'clear' so we're clearing markup
|
} else { // markoutOpt === 'clear' so we're clearing markup
|
||||||
str = msg.str.slice(i, k + 1);
|
str = msg.str.slice(i, k + 1);
|
||||||
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
msg = msgAddHtmlEntity(msg, j - 1, getSubStrEnd(msg.str, k + 1, ')', true, '') + 2,
|
||||||
applyHtml( // we're trying to clear markup inside [] of []()
|
linkName);
|
||||||
markout(markout(markout(markout(
|
|
||||||
{str: linkName, htmlEntities: msg.htmlEntities},
|
|
||||||
markoutOpt, '*', 'b'), // bold
|
|
||||||
markoutOpt, '~', 'i'), // italic
|
|
||||||
markoutOpt, '_', 'u'), // underlined
|
|
||||||
markoutOpt, '-', 's') // striketrough
|
|
||||||
)
|
|
||||||
.replace(/&(?!lt;|gt;)/g, '&')
|
|
||||||
);
|
|
||||||
// here we put link target as plain text to handle it usual way (search http[s]:// and so on)
|
// here we put link target as plain text to handle it usual way (search http[s]:// and so on)
|
||||||
i = msg.i + 1
|
i = msg.i + 1
|
||||||
msg.str = msg.str.slice(0, i) + ' ' + str + msg.str.slice(i);
|
msg.str = msg.str.slice(0, i) + ' ' + str + msg.str.slice(i);
|
||||||
@ -692,6 +690,12 @@ function htmlFormatMsg(msg, opt) {
|
|||||||
i = msg.i;
|
i = msg.i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (msg.str.slice(i, i + 6).toLowerCase() === 'twist:' && msg.str[i + 17] === '='
|
||||||
|
&& getSubStrStart(msg.str, i + 16, stopCharsRightHashtags, false, '') === i + 6) {
|
||||||
|
str = msg.str.slice(i, i + 18);
|
||||||
|
msg = msgAddHtmlEntity(msg, i, i + str.length,
|
||||||
|
newHtmlEntityLink(twister.tmpl.linkShortened, str, str));
|
||||||
|
i = msg.i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,6 +256,9 @@
|
|||||||
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
||||||
<!-- template for user links in message (open profile modal) -->
|
<!-- template for user links in message (open profile modal) -->
|
||||||
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
||||||
|
<div id="template-link-shortened">
|
||||||
|
<a class="link-shortened" rel="nofollow" target="_blank"></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="prompt-wrapper">
|
<div class="prompt-wrapper">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -461,6 +461,9 @@
|
|||||||
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
||||||
<!-- template for user links in message (open profile modal) -->
|
<!-- template for user links in message (open profile modal) -->
|
||||||
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
||||||
|
<div id="template-link-shortened">
|
||||||
|
<a class="link-shortened" rel="nofollow" target="_blank"></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<audio id="player"></audio>
|
<audio id="player"></audio>
|
||||||
|
@ -817,6 +817,9 @@
|
|||||||
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
<a id="external-page-link-template" rel="nofollow" target="_blank"></a>
|
||||||
<!-- template for user links in message (open profile modal) -->
|
<!-- template for user links in message (open profile modal) -->
|
||||||
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
<a id="hashtag-link-template" class="open-hashtag-modal"></a>
|
||||||
|
<div id="template-link-shortened">
|
||||||
|
<a class="link-shortened" rel="nofollow" target="_blank"></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- template para ir dentro de avatar-row -->
|
<!-- template para ir dentro de avatar-row -->
|
||||||
<a id="avatar-row-template" class="open-profile-modal" href="">
|
<a id="avatar-row-template" class="open-profile-modal" href="">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user