]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
minify LinkPreview JS code
authorBrion Vibber <brion@pobox.com>
Mon, 6 Dec 2010 23:11:42 +0000 (15:11 -0800)
committerBrion Vibber <brion@pobox.com>
Mon, 6 Dec 2010 23:11:42 +0000 (15:11 -0800)
plugins/LinkPreview/LinkPreviewPlugin.php
plugins/LinkPreview/linkpreview.min.js [new file with mode: 0644]

index 39d2c9bf3918f7cdb2d51e8596b3357bb52da57b..65f896ca2745867200d2f31adbf594d08b9d4d57 100644 (file)
@@ -51,7 +51,7 @@ class LinkPreviewPlugin extends Plugin
     {
         $user = common_current_user();
         if ($user && common_config('attachments', 'process_links')) {
-            $action->script('plugins/LinkPreview/linkpreview.js');
+            $action->script('plugins/LinkPreview/linkpreview.min.js');
             $data = json_encode(array(
                 'api' => common_local_url('oembedproxy'),
                 'width' => common_config('attachments', 'thumbwidth'),
diff --git a/plugins/LinkPreview/linkpreview.min.js b/plugins/LinkPreview/linkpreview.min.js
new file mode 100644 (file)
index 0000000..a6fb9db
--- /dev/null
@@ -0,0 +1 @@
+(function(){var a={api:"http://oohembed.com/oohembed",width:100,height:75,cache:{},callbacks:{},lookup:function(c,d){if(typeof a.cache[c]=="object"){d(a.cache[c])}else{if(typeof a.callbacks[c]=="undefined"){a.callbacks[c]=[d];a.rawLookup(c,function(g){a.cache[c]=g;var f=a.callbacks[c];a.callbacks[c]=undefined;for(var e=0;e<f.length;e++){f[e](g)}})}else{a.callbacks[c].push(d)}}},rawLookup:function(c,e){var d={url:c,format:"json",maxwidth:a.width,maxheight:a.height,token:$("#token").val()};$.ajax({url:a.api,data:d,dataType:"json",success:function(f,g){e(f)},error:function(g,h,f){e(null)}})}};var b={links:[],state:[],refresh:[],findLinks:function(f){var d=/(?:^| )(https?:\/\/.+?\/.+?)(?= |$)/mg;var c=[];var e;while((e=d.exec(f))!==null){c.push(e[1])}return c},prepLinkPreview:function(d){var e="link-preview-"+d;var c=b.links[d];b.refresh[d]=false;b.markLoading(d);a.lookup(c,function(i){var f=null;var g=100;if(i&&typeof i.thumbnail_url=="string"){f=i.thumbnail_url;if(typeof i.thumbnail_width!=="undefined"){if(i.thumbnail_width<g){g=i.thumbnail_width}}}else{if(i&&i.type=="photo"&&typeof i.url=="string"){f=i.url;if(typeof i.width!=="undefined"){if(i.width<g){g=i.width}}}}if(f){var h=$('<span class="inline-attachment"><a><img/></a></span>');h.find("a").attr("href",c).attr("target","_blank").last().find("img").attr("src",f).attr("width",g).attr("title",i.title||i.url||c);$("#"+e).empty();$("#"+e).append(h)}else{b.clearLink(d)}if(b.refresh[d]){b.prepLinkPreview(d)}else{b.markDone(d)}})},previewLinks:function(f){var e;var c=b.links;var d=b.findLinks(f);b.links=d;for(e=0;e<c.length&&e<d.length;e++){if(d[e]!=c[e]){if(b.state[e]=="loading"){b.refresh[e]=true}else{b.prepLinkPreview(e)}}}if(d.length>c.length){for(e=c.length;e<d.length;e++){b.addPreviewArea(e);b.prepLinkPreview(e)}}else{if(c.length>d.length){for(e=d.length;e<c.length;e++){b.clearLink(e)}}}},addPreviewArea:function(c){var d="link-preview-"+c;$("#link-preview").append('<span id="'+d+'"></span>')},clearLink:function(c){var d="link-preview-"+c;$("#"+d).html("")},markLoading:function(c){b.state[c]="loading";var d="link-preview-"+c;$("#"+d).attr("style","opacity: 0.5")},markDone:function(c){b.state[c]="done";var d="link-preview-"+c;$("#"+d).removeAttr("style")},clear:function(){b.links=[];$("#link-preview").empty()}};SN.Init.LinkPreview=function(c){if(c.api){a.api=c.api}if(c.width){a.width=c.width}if(c.height){a.height=c.height}$("#form_notice").append('<div id="link-preview" class="thumbnails"></div>').bind("reset",function(){b.clear()});var d=SN.U.Counter;SN.U.Counter=function(e){b.previewLinks($("#notice_data-text").val());return d(e)}}})();
\ No newline at end of file