Permalink
Browse files

Merge branch 'master' of github.com:iZRIdJJ53S/syaberi-house

  • Loading branch information...
2 parents d113950 + 9de7cf3 commit a7fdd3d5a9559eb8b7072cd1991f50187abee87b @nsyee nsyee committed Nov 12, 2012
Showing with 72 additions and 6 deletions.
  1. +28 −0 lib/controllers/chatroom.js
  2. +30 −2 lib/utils/index.js
  3. +2 −2 public/js/templates/chat.js
  4. +12 −2 views/chatroom.ejs
@@ -241,6 +241,34 @@ exports.show = function(req, res, next) {
// }
// });
+
+ // 画像系 / youtube のチェック
+ chats.forEach(function(chat) {
+ // urlの判断 message
+ if (utils.isUrl(chat.message)) {
+ var tmp_url = utils.getUrl(chat.message);
+
+
+ // 画像urlの判断
+ if (utils.isImageUrl(tmp_url)) {
+ // 画像urlをset
+ chat.extImageUrl = tmp_url;
+ }
+ // Youtube の判断
+ else if (utils.isYoutube(tmp_url)) {
+ var youtube_vid = utils.getYoutubeVid(tmp_url);
+ if (youtube_vid) {
+ chat.youtubeVid = youtube_vid;
+ }
+
+ }
+ } else {
+ chat.extImageUrl = '';
+ chat.youtubeVid = '';
+ }
+ });
+
+
//URLでテンプレートファイルを切り替え
var template = isUrlOpen ? 'chatroom' : 'lounge';
View
@@ -88,12 +88,40 @@ function isImageUrl(url) {
if (url.length == 0) {
return false;
}
- url.match(/(\.(jpg|jpeg|gif|png)$)/i);
- if (RegExp.$1 != null && RegExp.$1.length > 0) {
+ if (url.match(/(\.(jpg|jpeg|gif|png)$)/i)) {
return true;
}
return false;
}
exports.isImageUrl = isImageUrl;
+
+// Youtube の判定
+function isYoutube(url) {
+ if (url.length == 0) {
+ return false;
+ }
+
+ if (url.indexOf('youtube.com')) {
+ return true;
+ }
+ return false;
+}
+exports.isYoutube = isYoutube;
+
+
+// Youtube の動画ID取得
+function getYoutubeVid(url) {
+ if (url.length == 0) {
+ return false;
+ }
+ var youtube_vid = url.match(/[&\?]v=([\d\w-]+)/);
+ if (youtube_vid[1]) {
+ return youtube_vid[1];
+ }
+ return false;
+}
+exports.getYoutubeVid = getYoutubeVid;
+
+
@@ -23,7 +23,7 @@
{{/if}}\
{{#if youtubeVid}}\
<iframe width="500" height="300" src="\
- http://www.youtube.com/embed/{{youtubeVid}}"\
+ //www.youtube.com/embed/{{youtubeVid}}"\
frameborder="0" allowfullscreen></iframe>\
{{/if}}\
<div class="owner-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>\
@@ -49,7 +49,7 @@
{{/if}}\
{{#if youtubeVid}}\
<iframe width="500" height="300" src="\
- http://www.youtube.com/embed/{{youtubeVid}}"\
+ //www.youtube.com/embed/{{youtubeVid}}"\
frameborder="0" allowfullscreen></iframe>\
{{/if}}\
<div class="member-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>\
View
@@ -176,7 +176,12 @@
</div>
<div class="owner-titlebox">
<p class="owner-title"><%- esc(chat.message) %></p>
- <!--img class="owner-img" src="http://www1.u-netsurf.ne.jp/~tukinowa/gallery/picture/fuji-gennsou.jpg"-->
+ <% if (chat.extImageUrl) { // 外部画像URLがあれば %>
+ <img src="<%= chat.extImageUrl %>" class="owner-img">
+ <% } %>
+ <% if (chat.youtubeVid) { // Youtube %>
+ <iframe width="500" height="300" src="//www.youtube.com/embed/<%= chat.youtubeVid %>" frameborder="0" allowfullscreen></iframe>
+ <% } %>
<div class="owner-username">
<% if (chat.isInactive) { %>
by.退会済み
@@ -202,7 +207,12 @@
</div>
<div class="member-titlebox">
<p class="member-title"><%- esc(chat.message) %></p>
- <!--img class="member-img" src="http://www1.u-netsurf.ne.jp/~tukinowa/gallery/picture/fuji-gennsou.jpg"-->
+ <% if (chat.extImageUrl) { // 外部画像URLがあれば %>
+ <img src="<%= chat.extImageUrl %>" class="member-img">
+ <% } %>
+ <% if (chat.youtubeVid) { // Youtube %>
+ <iframe width="500" height="300" src="//www.youtube.com/embed/<%= chat.youtubeVid %>" frameborder="0" allowfullscreen></iframe>
+ <% } %>
<div class="member-username">
<% if (chat.isInactive) { %>
by.退会済み

0 comments on commit a7fdd3d

Please sign in to comment.