Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diaspora
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Milan
diaspora
Commits
f2af56f4
Commit
f2af56f4
authored
14 years ago
by
archi
Browse files
Options
Downloads
Patches
Plain Diff
Youtubelink support :)
Tested with Firefox, Chrome and Mobile Safari (IE8 is broken anyway)
parent
f676e284
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/helpers/status_messages_helper.rb
+9
-8
9 additions, 8 deletions
app/helpers/status_messages_helper.rb
public/javascripts/view.js
+6
-0
6 additions, 0 deletions
public/javascripts/view.js
with
15 additions
and
8 deletions
app/helpers/status_messages_helper.rb
+
9
−
8
View file @
f2af56f4
...
...
@@ -19,19 +19,20 @@ module StatusMessagesHelper
# next line is important due to XSS! (h is rail's make_html_safe-function)
message
=
h
(
message
).
html_safe
message
.
gsub!
(
/( |^)(www\.[^ ]+\.[^ ])/
,
'\1http://\2'
)
message
.
gsub!
(
/( |^)http:\/\/www\.youtube\.com\/watch
.
*v=([A-Za-z0-9_]+)
[^ ]*
/
,
'\1youtube.com::\2'
)
message
.
gsub!
(
/( |^)http:\/\/www\.youtube\.com\/watch
[^ ]
*v=([A-Za-z0-9_]+)/
,
'\1youtube.com::\2'
)
message
.
gsub!
(
/(http|ftp):\/\/([^ ]+)/
,
'<a target="_blank" href="\1://\2">\2</a>'
)
youtube
=
message
.
match
(
/youtube\.com::([A-Za-z0-9_]+)/
)
youtube
.
to_a
.
each
do
|
videoid
|
if
videoid
.
match
(
'::'
).
nil?
message
.
gsub!
(
'youtube.com::'
+
videoid
,
'<a onclick="openVideo(\'youtube.com\', \''
+
videoid
+
'\', this)" href="#video">Youtube: '
+
youtube_title
(
videoid
)
+
'</a>'
)
end
while
youtube
=
message
.
match
(
/youtube\.com::([A-Za-z0-9_]+)/
)
videoid
=
youtube
[
1
]
message
.
gsub!
(
'youtube.com::'
+
videoid
,
'<a onclick="openVideo(\'youtube.com\', \''
+
videoid
+
'\', this)" href="#video">Youtube: '
+
youtube_title
(
videoid
)
+
'</a>'
)
end
return
message
end
def
youtube_title
(
id
)
#TODO Check if id is cached, and return cached value
unless
@@youtube_title_cache
[
id
]
==
'no-title'
return
@@youtube_title_cache
[
id
]
end
ret
=
'Unknown Video Title'
#TODO add translation
http
=
Net
::
HTTP
.
new
(
'gdata.youtube.com'
,
80
)
...
...
@@ -42,7 +43,7 @@ module StatusMessagesHelper
ret
=
title
.
to_s
[
7
..-
9
]
end
#TODO Cache the value of ret for id
@@youtube_title_cache
[
id
]
=
ret
;
return
ret
end
...
...
This diff is collapsed.
Click to expand it.
public/javascripts/view.js
+
6
−
0
View file @
f2af56f4
...
...
@@ -72,6 +72,8 @@ $.fn.clearForm = function() {
});
};
var
video_active_container
=
null
;
function
openVideo
(
type
,
videoid
,
link
)
{
var
container
=
document
.
createElement
(
'
div
'
);
if
(
type
==
'
youtube.com
'
)
{
...
...
@@ -79,6 +81,10 @@ function openVideo(type, videoid, link) {
}
else
{
container
.
innerHTML
=
'
Invalid videotype <i>
'
+
type
+
'
</i> (ID:
'
+
videoid
+
'
)
'
;
}
if
(
video_active_container
!=
null
)
{
video_active_container
.
parentNode
.
removeChild
(
video_active_container
);
}
video_active_container
=
container
;
$
(
container
).
hide
();
link
.
parentNode
.
insertBefore
(
container
,
this
.
nextSibling
);
$
(
container
).
slideDown
(
'
fast
'
,
function
()
{
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment