Browse Source

many bugfixes, handle removal updates

raylu 14 years ago
parent
commit
dc49f0338a
3 changed files with 33 additions and 37 deletions
  1. 4 3
      static/base.css
  2. 0 1
      static/poller.js
  3. 29 33
      static/script.js

+ 4 - 3
static/base.css

@@ -82,10 +82,10 @@ header input[type="submit"] {
 div#results {
 	display: none;
 	position: absolute;
-	width: 428px;
+	width: 430px;
 	height: 560px;
-	left: 392px;
-	top: 82px;
+	left: 390px;
+	top: 83px;
 	background-color: #111;
 	border: 1px solid #aaa;
 	z-index: 1;
@@ -99,6 +99,7 @@ div#results ul li {
 	display: block;
 	height: 50px;
 	margin: 5px 0;
+	overflow: hidden;
 }
 div#results ul li:hover {
 	background-color: #024;

+ 0 - 1
static/poller.js

@@ -8,7 +8,6 @@ function getUpdates() {
 		url: '/poll/',
 		dataType: 'json',
 		data: {pid: pid, timestamp: timestamp},
-		timeout: 1000 * 30,
 		success: handleUpdates
 	});
 }

+ 29 - 33
static/script.js

@@ -16,13 +16,16 @@ $(document).ready(function () {
 		for (var i = 0; i < e.data.updates.length; i++) {
 			update = e.data.updates[i];
 			switch (update.action) {
-			case 0:
+			case 0: // see updates.go:addAction
 				drawAdd(update);
 				break;
+			case 1:
+				drawRemove(update.yid);
+				break;
 			}
 		}
 	}
-	poller.postMessage({'pid': pid});
+	poller.postMessage({pid: pid});
 });
 
 function drawBar(id) {
@@ -121,14 +124,14 @@ function showPause(yid) {
 
 function search(query) {
 	params = {
-		'q': query,
+		q: query,
 		'max-results': 10,
-		'v': 2,
-		'strict': true,
-		'alt': 'json',
-		'fields': 'entry(title,media:group(yt:videoid))',
-		'safeSearch': 'none',
-		'key': 'AI39si7SaaRqtvAZTa8lePOq6XC5r7S5Xzp3AB6oYPfeCArPbA4dIq7tSVeuIDwAkcFFDeI3rzNmYxkyN_fg8X_7w800pIvVOA'
+		v: 2,
+		strict: true,
+		alt: 'json',
+		fields: 'entry(title,media:group(yt:videoid))',
+		safeSearch: 'none',
+		key: 'AI39si7SaaRqtvAZTa8lePOq6XC5r7S5Xzp3AB6oYPfeCArPbA4dIq7tSVeuIDwAkcFFDeI3rzNmYxkyN_fg8X_7w800pIvVOA'
 	}
 	$.getJSON('https://gdata.youtube.com/feeds/api/videos', params,
 		function (data) {
@@ -136,9 +139,10 @@ function search(query) {
 			var items = [];
 			for (var i = 0; i < entries.length; i++) {
 				var title = entries[i].title.$t;
+				var escapedTitle = escape(title.replace("'", '\\\''));
 				var id = entries[i].media$group.yt$videoid.$t;
 				var html = '<li id="r_' + id + '">';
-				html += '<a href="javascript:add(\'' + id + '\', \'' + escape(title) + '\')">';
+				html += '<a href="javascript:add(\'' + id + '\', \'' + escapedTitle + '\')">';
 				html += '<img src="http://i.ytimg.com/vi/' + id  + '/1.jpg" alt="' + id + '">';
 				html +=	title;
 				html += '</a></li>';
@@ -154,18 +158,12 @@ function search(query) {
 function add(id, title) {
 	var user = $('#user').val();
 	params = {
-		'pid': pid,
-		'yid': id,
-		'title': title,
-		'user': user
+		pid: pid,
+		yid: id,
+		title: title,
+		user: user
 	}
-	$.getJSON('/add/', params,
-		function (data) {
-			if (data != 1)
-				return;
-			drawAdd(params);
-		}
-	);
+	$.getJSON('/add/', params);
 }
 
 function drawAdd(s) {
@@ -194,17 +192,15 @@ function drawAdd(s) {
 function remove(id) {
 	var user = $('#user').val();
 	params = {
-		'pid': pid,
-		'yid': id,
+		pid: pid,
+		yid: id,
 	}
-	$.getJSON('/remove/', params,
-		function (data) {
-			if (data == 1) {
-				var element = $('#' + id);
-				element.slideUp(100, function () {
-					element.remove();
-				});
-			}
-		}
-	);
+	$.getJSON('/remove/', params);
+}
+
+function drawRemove(id) {
+	var element = $('#' + id);
+	element.slideUp(100, function () {
+		element.remove();
+	});
 }