Permalink
Browse files

pull merge

  • Loading branch information...
2 parents 5b12250 + aa71e3b commit a765a3108898aee5d0925416460a5400938ee582 @Evangenieur committed Dec 16, 2012
@@ -5,7 +5,6 @@ _ = require "underscore"
cheerio = require "cheerio"
request = require "request"
-
video_platforms =
youtube:
domains: ["youtube.com", "youtu.be"]
@@ -53,8 +52,6 @@ http.get_redirect = (url, cb) ->
#console.log "get_redirect #{url} timeout"
cb null
-
-
module.exports = me =
def: video_platforms
lookup: (url) ->
@@ -69,11 +66,12 @@ module.exports = me =
provider: name
embed: URI.generate platform.embed, result
id: "#{name}/#{result.video_id}"
+ url: 'http://' + platform.domains[0] + URI.generate platform.urls[0], result
catch e
console.log e
not_found: url.toString()
- getVideoFromMsg: (msg, url, vdo ={}, deferred = Q.defer()) ->
+ getVideoFromMsg: (msg, url, vdo = {}, deferred = Q.defer()) ->
video = me.lookup url
#console.log video
if video.id
@@ -124,5 +122,4 @@ module.exports = me =
deferred.resolve vdo_meta
-
deferred.promise
@@ -1,12 +1,14 @@
(function() {
- var loader, socket, scroller, counter = 0,
+ var loader, socket, scroller, counter = 0, timerIdle, timerPlay,
$main = $('#main'),
+ $loading = $('#loading'),
$form = $('#form'),
$keyword = $('#keyword'),
$results = $('#results'),
$player = $('#player'),
$close = $('#close'),
$header = $('#header'),
+ $hashtags = $('#hashtags'),
$clickjack = $('#clickjack');
window.hvidio = {
@@ -47,9 +49,11 @@
//$close.on('click', function(e) {
$main.on('click', function(e) {
hvidio.hide();
+ e.stopPropagation();
+ });
+ $main.on('click', 'a', function(e) {
e.stopPropagation();
- e.preventDefault();
});
$keyword.on('click', function(e) {
@@ -72,6 +76,8 @@
$form.on('submit', function(e) {
var keyword = $keyword.val();
+ $hashtags.remove();
+
hvidio.search(keyword);
window.location.hash = "#" + keyword;
@@ -88,19 +94,19 @@
e.preventDefault();
break;
case 37: // left arrow
- hvidio.prev();
+ hvidio.prev(1000);
e.preventDefault();
break;
case 38: // up arrow
- hvidio.prev();
+ hvidio.prev(1000);
e.preventDefault();
break;
case 39: // right arrow
- hvidio.next();
+ hvidio.next(1000);
e.preventDefault();
break;
case 40: // down arrow
- hvidio.next();
+ hvidio.next(1000);
e.preventDefault();
break;
case 9: // tab
@@ -112,6 +118,20 @@
}
});
+ // Hastags
+ hvidio.hashtags();
+ $hashtags.on('click', 'a', function(e) {
+ var keyword = $(this).attr('href');
+ $keyword.val(keyword);
+
+ $form.submit();
+
+ $hashtags.hide();
+
+ e.stopPropagation();
+ e.preventDefault();
+ });
+
$main.addClass('bounceIn');
return this;
@@ -128,6 +148,16 @@
return this;
},
+ initTimer: function() {
+ // Hide main window when idle
+ $(window).on('mousemove keydown', function() {
+ clearTimeout(timerIdle);
+ timerIdle = setTimeout(function() { hvidio.hide() }, 20000);
+ });
+
+ return this;
+ },
+
search: function(keyword) {
if (keyword) {
this.keyword = keyword;
@@ -139,14 +169,13 @@
$main.addClass('large');
hvidio.templatize('#videosTemplate', { search: urlify(keyword), videos: data }, '#results');
-
- //hvidio.loading(false);
-
- hvidio.play(data[0].embed);
- hvidio.initScroller(true);
+ hvidio
+ .play(data[0].embed)
+ .initScroller()
+ .initTimer();
- $close.fadeIn(5000);
+ $close.show();
});
}
@@ -156,43 +185,33 @@
order: function(videos) {
console.log("order", videos, this.keyword, $('#results'));
hvidio.templatize('#videosTemplate', { search: urlify(this.keyword), videos: videos }, '#results');
- hvidio.loading(false);
- hvidio.play(videos[0].embed);
- hvidio.initScroller(true);
- $close.fadeIn(5000);
+
+ hvidio
+ .loading(false)
+ .play(videos[0].embed)
+ .initScroller(true);
},
+
fetch: function(keyword, callback) {
var self = this;
search = Search(keyword)
.on("video.new", function() {
var pos;
- this.msg = this.msgs[0];
- this.score = _.reduce(this.msgs, function(memo, num) {
- return (memo + (parseInt(num.votes) + 1)) || 1;
- }, 0);
-
- this.date = this.msgs[0].post_date;
if ((pos = this.embed.indexOf("?")) != -1) {
this.embed = this.embed.substr(0, pos);
}
- $('#counter').text(counter++);
+ $('#counter').text(++counter);
if (typeof search.initiated == "undefined") {
search.initiated = true;
- scroll = false;
callback([this]);
} else {
- var html = hvidio.templatize('#videoTemplate', { video: this });
- var $mylist = $("#video-list-" + urlify(keyword));
- //$list.append(html);
- /*
- $mylist.append(html);
- $(html).fadeIn()
- */
- var $html = $(html);
+ var html = hvidio.templatize('#videoTemplate', { video: this }),
+ $mylist = $("#video-list-" + urlify(keyword)),
+ $html = $(html);
$mylist.append($html);
@@ -203,11 +222,9 @@
}).on("video.update", function() {
console.log("update", this.dom_id);
- var $tip = $('#' + this.dom_id + ' .tip'),
- score = parseInt($tip.text()) || 1,
- newScore = score + 1; //(this.msgs[this.msgs.length - 1].votes || 1);
+ var $tip = $('#' + this.dom_id + ' .tip');
- $tip.text(newScore + '+');
+ $tip.text(this.score + '+');
$tip.addClass('incremented animated bounce');
}).on("finished", function() {
@@ -239,16 +256,25 @@
},
loading: function(bool) {
- //console.log("loader", loader);
if (bool) {
loader.show();
+ $loading.show();
} else {
loader.hide();
+ $loading.hide();
}
return this;
},
+ hashtags: function() {
+ var fp = $form.offset();
+ $hashtags
+ .css('top', (fp.top) + 'px')
+ .css('left', (fp.left + ($keyword.outerWidth())) + 'px')
+ .fadeIn('slow');
+ },
+
toggle: function() {
if ($main.is(':visible')) {
hvidio.hide();
@@ -269,6 +295,7 @@
hide: function() {
$main.removeClass('bounceIn fadeOutUp fadeOutDown');
$main.addClass('fadeOutDown');
+
setTimeout(function() { $main.hide() }, 500);
return this;
@@ -277,14 +304,14 @@
fadeImg: function(html) {
$('#results img').each(function() {
$(this).on('load', function () {
- $(this).css('visibility','visible').hide().fadeIn('slow');
+ $(this).css('visibility','visible').hide().fadeIn();
});
});
return this;
},
- play: function(embed) {
+ play: function(embed, delay) {
$results.find('.video').removeClass('current');
$results.find('a[href="'+ embed +'"]').closest('.video').addClass('current');
@@ -296,31 +323,34 @@
}
embed += "wmode=transparent&autoplay=1&autohide=1";
- $player.attr('src', embed);
+ clearTimeout(timerPlay);
+ timerPlay = setTimeout(function() {
+ $player.attr('src', embed);
+ }, delay);
return this;
},
- jump: function(index) {
+ jump: function(index, delay) {
var embed = $('.video').eq(index).find('.play').attr('href');
- hvidio.play(embed);
+ hvidio.play(embed, delay);
},
- next: function() {
+ next: function(delay) {
var index = $('.current').index('.video');
- index++;
+ ++index;
if (index > $('.video').size() - 1) {
index = 0;
$results.mCustomScrollbar("scrollTo", 0);
}
- hvidio.jump(index);
+ hvidio.jump(index, delay);
},
- prev: function() {
+ prev: function(delay) {
var index = $('.current').index('.video');
index--;
@@ -331,7 +361,7 @@
$results.mCustomScrollbar("scrollTo", 20000);
}
- hvidio.jump(index);
+ hvidio.jump(index, delay);
},
resize: function() {
@@ -347,6 +377,8 @@
rw = (Math.floor(mw / ew)) * ew;
$results.find('.video-list').width(rw);
+
+ hvidio.hashtags();
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -26,7 +26,14 @@ window.Search = class Search
delete video.msg
video.dom_id = video.id.replace "/", "-"
video.msgs = []
+
(@videos[video.id] or= video).msgs.push msg
+
+ # Jay: was here
+ @videos[video.id] = (@videos[video.id] or= video)
+ @videos[video.id].date = msg.post_date;
+ @videos[video.id].score = (@videos[video.id].score || 1) + msg.score;
+
console.log "videos ", Object.keys(@videos).length
@when _(@videos).keys().length, video.id

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit a765a31

Please sign in to comment.