- /**
- * Start looking up info for a link preview...
- * May start async data loads.
- *
- * @param {String} id
- * @param {String} url
- */
- prepLinkPreview: function(id, url)
- {
- oEmbed.lookup(url, function(data) {
- var thumb = null;
- var width = 100;
- if (typeof data.thumbnail_url == "string") {
- thumb = data.thumbnail_url;
- if (typeof data.thumbnail_width !== "undefined") {
- if (data.thumbnail_width < width) {
- width = data.thumbnail_width;
+ // Customize notice form init...
+ var origSetup = SN.Init.NoticeFormSetup;
+ SN.Init.NoticeFormSetup = function(form) {
+ origSetup(form);
+
+ form
+ .bind('reset', function() {
+ LinkPreview.clear();
+ });
+
+ var LinkPreview = {
+ links: [],
+ state: [],
+ refresh: [],
+
+ /**
+ * Find URL links from the source text that may be interesting.
+ *
+ * @param {String} text
+ * @return {Array} list of URLs
+ */
+ findLinks: function (text)
+ {
+ // @fixme match this to core code
+ var re = /(?:^| )(https?:\/\/.+?\/.+?)(?= |$)/mg;
+ var links = [];
+ var matches;
+ while ((matches = re.exec(text)) !== null) {
+ links.push(matches[1]);
+ }
+ return links;
+ },
+
+ ensureArea: function() {
+ if (form.find('.link-preview').length < 1) {
+ form.append('<div class="notice-status link-preview thumbnails"></div>');
+ }
+ },
+
+ /**
+ * Start looking up info for a link preview...
+ * May start async data loads.
+ *
+ * @param {number} col: column number to insert preview into
+ */
+ prepLinkPreview: function(col)
+ {
+ var id = 'link-preview-' + col;
+ var url = LinkPreview.links[col];
+ LinkPreview.refresh[col] = false;
+ LinkPreview.markLoading(col);
+
+ oEmbed.lookup(url, function(data) {
+ var thumb = null;
+ var width = 100;
+ if (data && typeof data.thumbnail_url == "string") {
+ thumb = data.thumbnail_url;
+ if (typeof data.thumbnail_width !== "undefined") {
+ if (data.thumbnail_width < width) {
+ width = data.thumbnail_width;
+ }