LinkPreview: restructure to make it easier to keep old link data
This commit is contained in:
parent
73f28ffabe
commit
acdb9ac1e5
|
@ -62,13 +62,16 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var LinkPreview = {
|
||||||
|
links: [],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find URL links from the source text that may be interesting.
|
* Find URL links from the source text that may be interesting.
|
||||||
*
|
*
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
* @return {Array} list of URLs
|
* @return {Array} list of URLs
|
||||||
*/
|
*/
|
||||||
function findLinks(text)
|
findLinks: function (text)
|
||||||
{
|
{
|
||||||
// @fixme match this to core code
|
// @fixme match this to core code
|
||||||
var re = /(?:^| )(https?:\/\/.+?\/.+?)(?= |$)/mg;
|
var re = /(?:^| )(https?:\/\/.+?\/.+?)(?= |$)/mg;
|
||||||
|
@ -78,7 +81,7 @@
|
||||||
links.push(matches[1]);
|
links.push(matches[1]);
|
||||||
}
|
}
|
||||||
return links;
|
return links;
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start looking up info for a link preview...
|
* Start looking up info for a link preview...
|
||||||
|
@ -87,7 +90,7 @@
|
||||||
* @param {String} id
|
* @param {String} id
|
||||||
* @param {String} url
|
* @param {String} url
|
||||||
*/
|
*/
|
||||||
function prepLinkPreview(id, url)
|
prepLinkPreview: function(id, url)
|
||||||
{
|
{
|
||||||
oEmbed.lookup(url, function(data) {
|
oEmbed.lookup(url, function(data) {
|
||||||
var thumb = null;
|
var thumb = null;
|
||||||
|
@ -120,7 +123,7 @@
|
||||||
$('#' + id).append(link);
|
$('#' + id).append(link);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the live preview section with links found in the given text.
|
* Update the live preview section with links found in the given text.
|
||||||
|
@ -128,16 +131,17 @@
|
||||||
*
|
*
|
||||||
* @param {String} text: free-form input text
|
* @param {String} text: free-form input text
|
||||||
*/
|
*/
|
||||||
function previewLinks(text)
|
previewLinks: function(text)
|
||||||
{
|
{
|
||||||
var links = findLinks(text);
|
var links = LinkPreview.findLinks(text);
|
||||||
$('#link-preview').html('');
|
$('#link-preview').html('');
|
||||||
for (var i = 0; i < links.length; i++) {
|
for (var i = 0; i < links.length; i++) {
|
||||||
var id = 'link-preview-' + i;
|
var id = 'link-preview-' + i;
|
||||||
$('#link-preview').append('<span id="' + id + '"></span>');
|
$('#link-preview').append('<span id="' + id + '"></span>');
|
||||||
prepLinkPreview(id, links[i]);
|
LinkPreview.prepLinkPreview(id, links[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
SN.Init.LinkPreview = function(params) {
|
SN.Init.LinkPreview = function(params) {
|
||||||
if (params.api) oEmbed.api = params.api;
|
if (params.api) oEmbed.api = params.api;
|
||||||
|
@ -149,7 +153,7 @@
|
||||||
// Piggyback on the counter update...
|
// Piggyback on the counter update...
|
||||||
var origCounter = SN.U.Counter;
|
var origCounter = SN.U.Counter;
|
||||||
SN.U.Counter = function(form) {
|
SN.U.Counter = function(form) {
|
||||||
previewLinks($('#notice_data-text').val());
|
LinkPreview.previewLinks($('#notice_data-text').val());
|
||||||
return origCounter(form);
|
return origCounter(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user