Browse files

Compare string trims whitespace. Only fetch 5 results from AOL, rathe…

…r than slicing. Force sorting results by score. Use a textarea for descriptiong in playlist editing form
  • Loading branch information...
1 parent a61b48f commit 46ffb18901d5d2db0f03d24784f576f32d7875d0 @jwheare committed Dec 15, 2009
Showing with 28 additions and 9 deletions.
  1. +2 −1 public/playlick.css
  2. +14 −5 src/js/controllers/playlist.controller.js
  3. +11 −2 src/js/main/playdar.js
  4. +1 −1 src/js/util.js
View
3 public/playlick.css
@@ -369,7 +369,8 @@ form#playlistEditForm p {
form#playlistEditForm p.submit {
margin: 10px 0 0 0;
}
-form#playlistEditForm p.field input {
+form#playlistEditForm p.field input,
+form#playlistEditForm p.field textarea {
width: 510px;
}
View
19 src/js/controllers/playlist.controller.js
@@ -237,16 +237,25 @@ Playlist.prototype = {
}
return this.metadataElem;
},
- buildEditField: function (inputId, name, label, value) {
- return $('<p class="field">')
+ buildEditField: function (inputId, name, label, value, textarea) {
+ var field = $('<p class="field">')
.append($('<label>')
.attr('for', inputId)
.text(label))
- .append('<br>')
- .append($('<input type="text">')
+ .append('<br>');
+ if (textarea) {
+ field.append($('<textarea>')
+ .attr('rows', 5)
+ .attr('id', inputId)
+ .attr('name', name)
+ .text(value));
+ } else {
+ field.append($('<input type="text">')
.attr('id', inputId)
.attr('name', name)
.val(value));
+ }
+ return field;
},
buildEditForm: function () {
var that = this;
@@ -276,7 +285,7 @@ Playlist.prototype = {
.append(this.buildEditField('playlistEditTitle', 'title', 'Title', this.current.toString()))
.append(this.buildEditField('playlistEditUrl', 'url', 'Info URL', this.current.url))
.append(this.buildEditField('playlistEditSubtitle', 'subtitle', 'Subtitle', this.current.subtitle))
- .append(this.buildEditField('playlistEditDescription', 'description', 'Description', this.current.description))
+ .append(this.buildEditField('playlistEditDescription', 'description', 'Description', this.current.description, true))
.append(this.buildEditField('playlistEditImage', 'image', 'Image URL', this.current.image))
.append(this.buildEditField('playlistEditCopyright', 'copyright', 'Copyright', this.current.copyright))
.append(editSave);
View
13 src/js/main/playdar.js
@@ -55,6 +55,15 @@ var PLAYDAR = {
var resultsTable = $('<table cellspacing="0"></table>');
var foundPerfect = false;
+ response.results.sort(function (a, b) {
+ if (a.score > b.score) {
+ return -1;
+ }
+ if (a.score < b.score) {
+ return 1;
+ }
+ return 0;
+ });
$.each(response.results, function (i, result) {
// Register sound
Playdar.player.register_stream(result, {
@@ -250,12 +259,12 @@ var PLAYDAR = {
var aolUrl = 'http://music.aol.com/api/audio/search?c=?';
$.getJSON(aolUrl, {
start: 0,
- count: 20,
+ count: 5,
artistName: artist,
songTitle: track
}, function (json) {
if (json.response.data) {
- response.results = $.map(json.response.data.assets.slice(0, 5), function (result, i) {
+ response.results = $.map(json.response.data.assets, function (result, i) {
var score = 0.8;
if (UTIL.compareString(result.artistname, artist)
&& UTIL.compareString(result.songtitle, track)) {
View
2 src/js/util.js
@@ -25,7 +25,7 @@ var UTIL = {
compareString: function (a, b) {
a = a || '';
b = b || '';
- return a.toUpperCase() == b.toUpperCase();
+ return a.trim().toUpperCase() == b.trim().toUpperCase();
},
getHashParts: function () {
var hash_sections = window.location.hash.replace(/^#(.*)/, '$1').split(';');

0 comments on commit 46ffb18

Please sign in to comment.