aboutsummaryrefslogtreecommitdiffstats
path: root/addon/oembed/oembed.js
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-01-26 16:20:12 +0100
committerFabio Comuni <fabrix.xm@gmail.com>2011-01-26 16:20:12 +0100
commit62fda0a120fe4d068f1380924b5493adb70064ea (patch)
tree041dcaff18f8fb798771f32349e547e19b3abc5b /addon/oembed/oembed.js
parentaf8ab8cb5350a503bb4043e90484a2bece3de7b4 (diff)
downloadvolse-hubzilla-62fda0a120fe4d068f1380924b5493adb70064ea.tar.gz
volse-hubzilla-62fda0a120fe4d068f1380924b5493adb70064ea.tar.bz2
volse-hubzilla-62fda0a120fe4d068f1380924b5493adb70064ea.zip
oembed consumer plugin
Diffstat (limited to 'addon/oembed/oembed.js')
-rw-r--r--addon/oembed/oembed.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/addon/oembed/oembed.js b/addon/oembed/oembed.js
new file mode 100644
index 000000000..26541490b
--- /dev/null
+++ b/addon/oembed/oembed.js
@@ -0,0 +1,51 @@
+function oembed(){
+ $("#oembed").toggleClass('hide');
+}
+
+function oembed_do(){
+ embedurl = $('#oembed_url').attr('value');
+ var url = 'http://oohembed.com/oohembed/?url='+escape( embedurl )+"&callback=?";
+
+ $.getJSON(url, function(data) {
+ var ret="";
+ switch(data.type){
+ case "video": {
+ if (data.thumbnail_url){
+ tw = 200; if (data.thumbnail_width) tw=data.thumbnail_width;
+ th = 180; if (data.thumbnail_height) tw=data.thumbnail_height;
+ ret = "<a href='"+embedurl+"'>";
+ // tiny mce bbcode plugin not support image size......
+ ret += "<img width='"+tw+"' height='"+th+"' src='"+data.thumbnail_url+"'></a>";
+ } else {
+ ret = data.html;
+ }
+ }; break;
+ case "photo": {
+ // tiny mce bbcode plugin not support image size......
+ ret = "<img width='"+data.width+"' height='"+data.height+"' src='"+data.url+"'>";
+ }; break;
+ case "link": {
+ ret = "<a href='"+embedurl+"'>"+data.title+"</a>";
+ }; break;
+ case "rich": {
+ ret = data.html; // not so safe... http://www.oembed.com/ : "Consumers may wish to load the HTML in an off-domain iframe to avoid XSS"
+ }; break;
+ default: {
+ alert("Error retriving data!");
+ return;
+ }
+ }
+ var embedlink = embedurl;
+ if (data.title) embedlink = data.title
+ ret+="<br><a href='"+embedurl+"'>"+embedlink+"</a>";
+ if (data.author_name) {
+ ret+=" by "+data.author_name;
+ }
+ if (data.provider_name) {
+ ret+=" on "+data.provider_name;
+ }
+ tinyMCE.execCommand('mceInsertRawHTML',false,ret);
+ oembed();
+ });
+
+}