social_stream-linkser 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/linkser.js.erb +59 -0
- data/app/assets/javascripts/social_stream-linkser.js +2 -1
- data/app/assets/stylesheets/linkser.css.scss +19 -0
- data/app/controllers/linkser_controller.rb +1 -8
- data/app/models/link.rb +17 -9
- data/app/views/links/_link.html.erb +15 -2
- data/app/views/links/_link_preview.html.erb +3 -0
- data/lib/social_stream/linkser/version.rb +1 -1
- data/social_stream-linkser.gemspec +1 -1
- metadata +7 -9
- data/app/views/links/_link_with_details.html.erb +0 -4
- data/app/views/posts/_new_activity_fields.erb +0 -53
@@ -0,0 +1,59 @@
|
|
1
|
+
var SocialStream = SocialStream || {};
|
2
|
+
SocialStream.Linkser = SocialStream.Linkser || {};
|
3
|
+
SocialStream.Linkser.initiate = function() {
|
4
|
+
$.preloadImages("assets/loading.gif");
|
5
|
+
var urlDetect = function() {
|
6
|
+
this.currentValue = $("#input_activities").val();
|
7
|
+
if(this.lastValue == null)
|
8
|
+
this.lastValue = "";
|
9
|
+
|
10
|
+
var regexp = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/
|
11
|
+
if(regexp.test($("#input_activities").val())) {
|
12
|
+
$("#link_url").val($("#input_activities").val());
|
13
|
+
$("#link_loaded").val(false);
|
14
|
+
$("#new_post").attr("action", "/links");
|
15
|
+
if(this.currentValue != this.lastValue) {
|
16
|
+
$("#link_preview").html($('<img>').attr('src', 'assets/loading.gif').addClass('loading'));
|
17
|
+
this.lastValue = this.currentValue;
|
18
|
+
var url = this.currentValue;
|
19
|
+
var urlDetect = this;
|
20
|
+
$.ajax({
|
21
|
+
type : "GET",
|
22
|
+
url : "/linkser_parse?url=" + url,
|
23
|
+
success : function(html) {
|
24
|
+
if($("#input_activities").val() == url) {//Only show if input value is still the same
|
25
|
+
$("#link_preview").html(html);
|
26
|
+
$("#link_loaded").val(true);
|
27
|
+
}
|
28
|
+
},
|
29
|
+
error : function(xhr, ajaxOptions, thrownError) {
|
30
|
+
if($("#input_activities").val() == url) {//Only show if input value is still the same
|
31
|
+
$("#link_preview").html($('<div>').addClass('loading').html("<%= I18n.t('link.errors.loading') %> " + url));
|
32
|
+
}
|
33
|
+
}
|
34
|
+
});
|
35
|
+
}
|
36
|
+
$("#link_preview").show();
|
37
|
+
} else {
|
38
|
+
$("#new_post").attr("action", "/posts");
|
39
|
+
$("#link_preview").hide();
|
40
|
+
$("#link_preview").html("");
|
41
|
+
$("#link_url").val("");
|
42
|
+
}
|
43
|
+
}
|
44
|
+
if($("#new_post").length) {
|
45
|
+
$("#input_activities").change(urlDetect).keyup(urlDetect);
|
46
|
+
$("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[owner_id]').attr('id', 'link_owner_id').val($("#post_owner_id").val()));
|
47
|
+
$("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[url]').attr('id', 'link_url'));
|
48
|
+
$("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[loaded]').attr('id', 'link_loaded').val(false));
|
49
|
+
$("#new_post").append($('<div>').attr('id', 'link_preview').css('display', 'none'));
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
SocialStream.Linkser.openCallback = function(id,url){
|
54
|
+
$("#" + id).html($('<iframe>').attr('src',url).attr('width','470').attr('height','353'));
|
55
|
+
}
|
56
|
+
|
57
|
+
$(function(){
|
58
|
+
SocialStream.Linkser.initiate();
|
59
|
+
});
|
@@ -1 +1,2 @@
|
|
1
|
-
//= require_tree .
|
1
|
+
//= require_tree .
|
2
|
+
|
@@ -11,16 +11,32 @@
|
|
11
11
|
margin: auto;
|
12
12
|
margin-top: 40px;
|
13
13
|
}
|
14
|
+
#link_preview div.loading{
|
15
|
+
margin: auto;
|
16
|
+
margin-top: 50px;
|
17
|
+
}
|
14
18
|
.link {
|
15
19
|
position: relative;
|
16
20
|
padding: 10px;
|
17
21
|
}
|
18
22
|
.link .thumbnail, .link .thumbnail img{
|
23
|
+
position: relative;
|
19
24
|
float: left;
|
20
25
|
max-height: 100px;
|
21
26
|
max-width: 120px;
|
22
27
|
margin-right:10px;
|
23
28
|
}
|
29
|
+
.link .thumbnail img.play_button{
|
30
|
+
position: absolute;
|
31
|
+
bottom: 2px;
|
32
|
+
left: 2px;
|
33
|
+
opacity:0.6;
|
34
|
+
filter:alpha(opacity=60); /* For IE8 and earlier */
|
35
|
+
}
|
36
|
+
.link .thumbnail img.play_button:hover{
|
37
|
+
opacity:0.8;
|
38
|
+
filter:alpha(opacity=80); /* For IE8 and earlier */
|
39
|
+
}
|
24
40
|
.link .info{
|
25
41
|
float: left;
|
26
42
|
width: 360px;
|
@@ -39,3 +55,6 @@
|
|
39
55
|
}
|
40
56
|
.link .info .description{
|
41
57
|
}
|
58
|
+
.link iframe{
|
59
|
+
border: 0;
|
60
|
+
}
|
@@ -5,14 +5,7 @@ class LinkserController < ApplicationController
|
|
5
5
|
o = Linkser.parse url, {:max_images => 1}
|
6
6
|
if o.is_a? Linkser::Objects::HTML
|
7
7
|
link = Link.new
|
8
|
-
link.
|
9
|
-
link.description = o.description if o.description
|
10
|
-
link.url = o.last_url
|
11
|
-
if o.ogp and o.ogp.image
|
12
|
-
link.image = o.ogp.image
|
13
|
-
elsif o.images and o.images.first
|
14
|
-
link.image = o.images.first.url
|
15
|
-
end
|
8
|
+
link.fill o
|
16
9
|
render :partial => "links/link_preview", :locals => {:link => link}
|
17
10
|
return
|
18
11
|
end
|
data/app/models/link.rb
CHANGED
@@ -15,18 +15,26 @@ class Link < ActiveRecord::Base
|
|
15
15
|
has created_at
|
16
16
|
end
|
17
17
|
|
18
|
+
def fill linkser_object
|
19
|
+
self.title = linkser_object.title if linkser_object.title
|
20
|
+
self.description = linkser_object.description if linkser_object.description
|
21
|
+
self.url = linkser_object.last_url
|
22
|
+
r = linkser_object.resource
|
23
|
+
if r and r.type and r.url
|
24
|
+
self.callback_url = r.url
|
25
|
+
end
|
26
|
+
if linkser_object.ogp and linkser_object.ogp.image
|
27
|
+
self.image = linkser_object.ogp.image
|
28
|
+
elsif linkser_object.images and linkser_object.images.first
|
29
|
+
self.image = linkser_object.images.first.url
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
18
33
|
def check_loaded
|
19
|
-
if !self.loaded.eql?"true" and self.title.nil? and self.description.nil? and self.image.nil?
|
34
|
+
if !self.loaded.eql? "true" and self.title.nil? and self.description.nil? and self.image.nil?
|
20
35
|
o = Linkser.parse self.url, {:max_images => 1}
|
21
36
|
if o.is_a? Linkser::Objects::HTML
|
22
|
-
self.
|
23
|
-
self.description = o.description if o.description
|
24
|
-
self.url = o.last_url
|
25
|
-
if o.ogp and o.ogp.image
|
26
|
-
self.image = o.ogp.image
|
27
|
-
elsif o.images and o.images.first
|
28
|
-
self.image = o.images.first.url
|
29
|
-
end
|
37
|
+
self.fill o
|
30
38
|
end
|
31
39
|
end
|
32
40
|
end
|
@@ -1,7 +1,20 @@
|
|
1
1
|
<%= div_for link, :class => 'content_size' do %>
|
2
2
|
<% if link.image %>
|
3
3
|
<div class="thumbnail">
|
4
|
-
|
4
|
+
<% if link.callback_url %>
|
5
|
+
<%= link_to image_tag(link.image),"javascript:void(0)" %>
|
6
|
+
<%= link_to image_tag("btn/btn_play.png", :class => "play_button"),"javascript:void(0)" %>
|
7
|
+
<%= javascript_tag do %>
|
8
|
+
$("#link_<%= link.id.to_s %> img").each(function(){
|
9
|
+
$(this).click(function(){
|
10
|
+
SocialStream.Linkser.openCallback("link_<%= link.id.to_s %>", "<%= link.callback_url %>");
|
11
|
+
});
|
12
|
+
});
|
13
|
+
|
14
|
+
<% end %>
|
15
|
+
<% else %>
|
16
|
+
<%= link_to image_tag(link.image),link.url, :target => "_blank" %>
|
17
|
+
<% end %>
|
5
18
|
</div>
|
6
19
|
<% end %>
|
7
20
|
<div class="info">
|
@@ -11,7 +24,7 @@
|
|
11
24
|
</div>
|
12
25
|
<% end %>
|
13
26
|
<div class="url">
|
14
|
-
<%=
|
27
|
+
<%= link_to link.url, link.url, :target => "_blank" %>
|
15
28
|
</div>
|
16
29
|
<% if link.description %>
|
17
30
|
<div class="description">
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
13
13
|
|
14
14
|
# Gem dependencies
|
15
|
-
s.add_runtime_dependency('social_stream-base', '~> 0.10.
|
15
|
+
s.add_runtime_dependency('social_stream-base', '~> 0.10.6')
|
16
16
|
s.add_runtime_dependency('linkser', '~> 0.0.6')
|
17
17
|
# Development Gem dependencies
|
18
18
|
s.add_development_dependency('sqlite3-ruby')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_stream-linkser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-12-
|
19
|
+
date: 2011-12-09 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 59
|
31
31
|
segments:
|
32
32
|
- 0
|
33
33
|
- 10
|
34
|
-
-
|
35
|
-
version: 0.10.
|
34
|
+
- 6
|
35
|
+
version: 0.10.6
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -169,11 +169,9 @@ files:
|
|
169
169
|
- app/models/link.rb
|
170
170
|
- app/views/links/_link.html.erb
|
171
171
|
- app/views/links/_link_preview.html.erb
|
172
|
-
- app/views/links/_link_with_details.html.erb
|
173
172
|
- app/views/links/create.js.erb
|
174
173
|
- app/views/links/destroy.js.erb
|
175
174
|
- app/views/links/show.html.erb
|
176
|
-
- app/views/posts/_new_activity_fields.erb
|
177
175
|
- config/locales/en.yml
|
178
176
|
- config/locales/es.yml
|
179
177
|
- config/routes.rb
|
@@ -1,53 +0,0 @@
|
|
1
|
-
<%= f.text_field :text, :id => "input_activities", :size => 85 %>
|
2
|
-
<%= hidden_field_tag "link[owner_id]", Actor.normalize_id(receiver) %>
|
3
|
-
<%= hidden_field_tag "link[url]" %>
|
4
|
-
<%= hidden_field_tag "link[loaded]", false %>
|
5
|
-
<div id="link_preview" style="display:none;"></div>
|
6
|
-
|
7
|
-
<%= javascript_tag do %>
|
8
|
-
$(function() {
|
9
|
-
$.preloadImages ("assets/loading.gif");
|
10
|
-
$("#input_activities").Watermark("<%= I18n.t('post.input') %>","#666");
|
11
|
-
|
12
|
-
var urlDetect = function(){
|
13
|
-
this.currentValue = $("#input_activities").val();
|
14
|
-
if(this.lastValue==null) this.lastValue = "";
|
15
|
-
|
16
|
-
var regexp = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/
|
17
|
-
if(regexp.test($("#input_activities").val())){
|
18
|
-
$("#link_url").val($("#input_activities").val());
|
19
|
-
$("#link_loaded").val(false);
|
20
|
-
$("#new_post").attr("action","<%= links_path %>");
|
21
|
-
if(this.currentValue!=this.lastValue){
|
22
|
-
$("#link_preview").html("<%= escape_javascript(image_tag('loading.gif', :class => :loading)) %>");
|
23
|
-
this.lastValue = this.currentValue;
|
24
|
-
var url = this.currentValue;
|
25
|
-
var urlDetect = this;
|
26
|
-
$.ajax({
|
27
|
-
type : "GET",
|
28
|
-
url : "<%= linkser_parse_url %>?url=" + url,
|
29
|
-
success : function(html) {
|
30
|
-
console.log("Peticion guay a " + url);
|
31
|
-
if ($("#input_activities").val()==url){ //Only show if input value is still the same
|
32
|
-
$("#link_preview").html(html);
|
33
|
-
$("#link_loaded").val(true);
|
34
|
-
}
|
35
|
-
},
|
36
|
-
error: function (xhr, ajaxOptions, thrownError){
|
37
|
-
$("#link_preview").html("<span class=\"loading\"><%= escape_javascript(t("link.errors.loading"))%> " + url + "</span>");
|
38
|
-
}
|
39
|
-
});
|
40
|
-
}
|
41
|
-
$("#link_preview").show();
|
42
|
-
}else{
|
43
|
-
$("#new_post").attr("action","<%= posts_path %>");
|
44
|
-
$("#link_preview").hide();
|
45
|
-
$("#link_preview").html("");
|
46
|
-
$("#link_url").val("");
|
47
|
-
}
|
48
|
-
}
|
49
|
-
$("#input_activities").change(urlDetect).keyup(urlDetect);
|
50
|
-
|
51
|
-
});
|
52
|
-
|
53
|
-
<% end %>
|