From 3790eedc2f48c725c586b8c7b924875fedbeb7b4 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 21 Apr 2013 20:00:42 -0400 Subject: getting ready to push --- www/static/js/search.js | 191 ------------------------------------------------ 1 file changed, 191 deletions(-) delete mode 100755 www/static/js/search.js (limited to 'www/static/js/search.js') diff --git a/www/static/js/search.js b/www/static/js/search.js deleted file mode 100755 index e644026..0000000 --- a/www/static/js/search.js +++ /dev/null @@ -1,191 +0,0 @@ -YOUTUBE_SEARCH_URL = "https://gdata.youtube.com/feeds/api/videos" -YOUTUBE_URL_PREFIX = "http://youtube.com/watch?v=" -function courtesy_s (quantity, noun) - { - if (quantity > 1) - return quantity + " " + noun + "s" - return quantity + " " + noun - } -var Search = - { - start: 0, - limit: 20, - sj: function () - { - Search.start = 0 - Search.terms = $("#search-terms").val() - Search.sjSearch (Search.terms, Search.start) - }, - sjSearch: function (terms, start) - { - var params = - { - "q": terms, - "start": Search.start, - "limit": Search.limit, - "session": Auth.session, - } - $.post(API.URL.video.search, params, Search.sjCallback) - $("#search-instructions").hide() - $("#search-results").html("").hide() - $("#search-loading").show() - $("#search-results-container").show() - }, - sjCallback: function (raw) - { - var lines = API.parse ("/video/search", raw) - var items = [] - for (var i = 0; i < lines.length; i++) - { - // 0 id 1 score 2 user 3 usercount 4 title 5 url 6 thumbnail - var line = lines[i].split("\t") - if (line.length < 7) - continue - var video = - { - url: line[5], - thumbnail: line[6], - title: line[4], - user: line[2], - quantify: "", - } - if (parseInt(line[3]) > 1) - video['user'] += " + " + courtesy_s (parseInt(line[3])-1, "other") - if (parseInt(line[1]) > 0) - video['quantify'] = courtesy_s (parseInt(line[1]), "like") - var tag = Search.resultTag (video) - items.push(tag) - } - if (items.length === Search.limit) - { - Search.start += Search.limit - $("#search-next-page").show() - } - else - { - $("#search-next-page").hide() - } - $("#search-loading").hide() - $("#search-results").html(items.join("")).show() - $("#search-instructions").show() - $("#curtain").bind("click", Search.close).css({"background-color": "transparent", "z-index": 99}).show() - }, - youtube: function () - { - var terms = $("#search-terms").val() - var params = - { - "q": terms, - "v": 2, - "alt": "jsonc", - } - $.get(YOUTUBE_SEARCH_URL, params, Search.youtubeCallback, "jsonp") - $("#search-results-container").show() - $("#search-results").html("").hide() - $("#search-loading").show() - }, - durationToString: function (duration) - { - return Math.floor(duration / 60) + ":" + (duration % 60) - }, - viewCountToString: function (viewCount) - { - if (! viewCount) - return '0' - var vc = viewCount.toString () - var commas = /(\d+)(\d{3})/; - while (commas.test(vc)) - { - vc = vc.replace(commas, '$1' + ',' + '$2'); - } - return vc - }, - resultTag: function (video) - { - var tag = "
  • " - tag += "
    " - tag += "

    " + video['title'] + "

    " - tag += "" - tag += "Preview" - tag += "
  • " - return tag - }, - youtubeCallback: function (data) - { - var items = [] - for (var i = 0; i < data['data']['items'].length; i++) - { - var item = data['data']['items'][i] - var video = - { - url: YOUTUBE_URL_PREFIX+item['id'], - thumbnail: item['thumbnail']['sqDefault'], - title: item['title'], - user: item['uploader'], - quantify: Search.viewCountToString(item['viewCount']) + "views", - } - var tag = Search.resultTag (video) - items.push(tag) - } - $("#search-loading").hide() - $("#search-results").html(items.join("")).show() - }, - keydown: function (e) - { - if (e.keyCode === 13) - { - Search.sj () - } - if (e.keyCode === 27) - { - Search.close () - Keyboard.focusTextarea () - } - }, - nextPage: function () - { - Search.sjSearch (Search.terms, Search.start) - }, - loadResult: function () - { - var url = $(this).parent().data("url") - $.post(API.URL.room.say, {room: Room.name, session: Auth.session, msg: url}) - Search.close () - }, - close: function () - { - $("#curtain").unbind("click", Search.close).hide() - $("#search-results-container").hide() - $("#search-terms").val("") - }, - blurSearchTextarea: function () - { - $(window).unbind("keydown") - $("#chat-message").unbind("keydown").bind("keydown", Keyboard.textareaMap) - $("#chat-message").unbind("focus").focus().bind("focus", Keyboard.focusTextarea) - if ($("#chat-message").val().length === 0) - Keyboard.enteredText = false - }, - focusSearchTextarea: function () - { - $(window).unbind("keydown") - $("#chat-message").unbind("keydown") - }, - init: function () - { - $("#search-results li div").live("click", Search.loadResult) - $("#search-results li h4").live("click", Search.loadResult) - $("#search-results li span").live("click", Search.loadResult) - $("#search-terms").bind("keydown", Search.keydown) - $("#search-terms").bind("focus", Search.focusSearchTextarea) - $("#search-terms").bind("blur", Search.blurSearchTextarea) - // $("#search-terms").val("glock n my hand") - // Search.sj () - } - } -Search.init () - -- cgit v1.2.3-70-g09d2