summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-11-16 13:16:25 -0800
committerBrion Vibber <brion@pobox.com>2010-11-16 13:16:25 -0800
commite851882f964c9eaa1cdd73f028fd09dd9acba734 (patch)
tree5665b0c1909a95673fc52070f9d68279061a8664 /plugins
parent450707fec626e4e2b2eed4e46591fcf06368d0a1 (diff)
LinkPreview: flesh out stub JS code a bit. URL splitting doesn't quite match core, note.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/LinkPreview/linkpreview.js47
1 files changed, 46 insertions, 1 deletions
diff --git a/plugins/LinkPreview/linkpreview.js b/plugins/LinkPreview/linkpreview.js
index 37710e7d5..f6a4dc34f 100644
--- a/plugins/LinkPreview/linkpreview.js
+++ b/plugins/LinkPreview/linkpreview.js
@@ -3,8 +3,53 @@
*/
$(function() {
+ /**
+ * Find URL links from the source text that may be interesting.
+ *
+ * @param {String} text
+ * @return {Array} list of URLs
+ */
+ function findLinks(text)
+ {
+ // @fixme match this to core code
+ var re = /(?:^| )(https?:\/\/.+?\/.+?)(?= |$)/g;
+ var links = [];
+ var matches;
+ while ((matches = re.exec(text)) !== null) {
+ links.push(matches[1]);
+ }
+ return links;
+ }
+
+ /**
+ * Start looking up info for a link preview...
+ * May start async data loads.
+ *
+ * @param {String} id
+ * @param {String} url
+ */
+ function prepLinkPreview(id, url)
+ {
+ console.log(id, url);
+ }
+
+ /**
+ * Update the live preview section with links found in the given text.
+ * May start async data loads.
+ *
+ * @param {String} text: free-form input text
+ */
+ function previewLinks(text)
+ {
+ var links = findLinks(text);
+ for (var i = 0; i < links.length; i++) {
+ var id = 'link-preview-' + i;
+ prepLinkPreview(id, links[i]);
+ }
+ }
+
$('#notice_data-text').change(function() {
var text = $(this).val();
- alert(text);
+ previewLinks(text);
});
});