summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-11-16 14:27:01 -0800
committerBrion Vibber <brion@pobox.com>2010-11-16 14:27:01 -0800
commitb5fc71253c5ad1d28bcff37733d11467eb15ca91 (patch)
treee04be419a74fb99bba3c9260f3487f40b5fd87d2
parenteeb7f02b98f104e1536cc116f4a8607dfde0d00b (diff)
LinkPreview: restructure a bit so we can pass config over
-rw-r--r--plugins/LinkPreview/LinkPreviewPlugin.php6
-rw-r--r--plugins/LinkPreview/linkpreview.js65
2 files changed, 43 insertions, 28 deletions
diff --git a/plugins/LinkPreview/LinkPreviewPlugin.php b/plugins/LinkPreview/LinkPreviewPlugin.php
index d887ca040..6f7c99a38 100644
--- a/plugins/LinkPreview/LinkPreviewPlugin.php
+++ b/plugins/LinkPreview/LinkPreviewPlugin.php
@@ -52,6 +52,12 @@ class LinkPreviewPlugin extends Plugin
$user = common_current_user();
if ($user) {
$action->script('plugins/LinkPreview/linkpreview.js');
+ $data = json_encode(array(
+ 'api' => common_config('oohembed', 'endpoint'),
+ 'width' => common_config('attachments', 'thumbwidth'),
+ 'height' => common_config('attachments', 'thumbheight'),
+ ));
+ $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
}
return true;
}
diff --git a/plugins/LinkPreview/linkpreview.js b/plugins/LinkPreview/linkpreview.js
index 6af3e920d..db9921229 100644
--- a/plugins/LinkPreview/linkpreview.js
+++ b/plugins/LinkPreview/linkpreview.js
@@ -2,27 +2,11 @@
* (c) 2010 StatusNet, Inc.
*/
-$(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?:\/\/.+?\/.+?)(?= |$)/mg;
- var links = [];
- var matches;
- while ((matches = re.exec(text)) !== null) {
- links.push(matches[1]);
- }
- return links;
- }
-
+(function() {
var oEmbed = {
api: 'http://oohembed.com/oohembed',
+ width: 100,
+ height: 75,
cache: {},
callbacks: {},
@@ -69,8 +53,8 @@ $(function() {
var params = {
url: url,
format: 'json',
- maxwidth: 100,
- maxheight: 75,
+ maxwidth: oEmbed.width,
+ maxheight: oEmbed.height,
callback: '?'
};
$.get(oEmbed.api, params, function(data, xhr) {
@@ -80,6 +64,24 @@ $(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?:\/\/.+?\/.+?)(?= |$)/mg;
+ 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.
*
@@ -137,12 +139,19 @@ $(function() {
prepLinkPreview(id, links[i]);
}
}
- $('#form_notice').append('<div id="link-preview" class="thumbnails"></div>');
- // Piggyback on the counter update...
- var origCounter = SN.U.Counter;
- SN.U.Counter = function(form) {
- previewLinks($('#notice_data-text').val());
- return origCounter(form);
+ SN.Init.LinkPreview = function(params) {
+ if (params.api) oEmbed.api = params.api;
+ if (params.width) oEmbed.width = params.width;
+ if (params.height) oEmbed.height = params.height;
+
+ $('#form_notice').append('<div id="link-preview" class="thumbnails"></div>');
+
+ // Piggyback on the counter update...
+ var origCounter = SN.U.Counter;
+ SN.U.Counter = function(form) {
+ previewLinks($('#notice_data-text').val());
+ return origCounter(form);
+ }
}
-});
+})();