diff --git a/config/routes.rb b/config/routes.rb index c9dbe82..037e429 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,5 +57,5 @@ Beathaven::Application.routes.draw do # match ':controller(/:action(/:id(.:format)))' match 'artist/autocomplete' => 'artist#autocomplete' - match 'artist(/:name)' => 'artist#data' + match 'artist/(:name)/' => 'artist#data', :constraints => { :name => /[^\/]*/ } end diff --git a/public/demo/index.html b/public/demo/index.html index 86da85e..14799cf 100644 --- a/public/demo/index.html +++ b/public/demo/index.html @@ -7,16 +7,17 @@ - - - - - - - - + + + + + + + + + + -
diff --git a/public/demo/search.html b/public/demo/search.html index c168272..c0d3470 100644 --- a/public/demo/search.html +++ b/public/demo/search.html @@ -7,7 +7,7 @@ $('#search_field').autocomplete({ width: 415, // Ширина списка zIndex: 9999, // z-index списка deferRequestBy: 150, // Задержка запроса (мсек) - onSelect: loadArtistData + onSelect: Ajax.loadArtistData }); $('#search_field').focus(); @@ -16,4 +16,5 @@ $('#search_field').focus(); + \ No newline at end of file diff --git a/public/images/loader.gif b/public/images/loader.gif new file mode 100644 index 0000000..91dc959 Binary files /dev/null and b/public/images/loader.gif differ diff --git a/public/javascripts/ajax.js b/public/javascripts/ajax.js deleted file mode 100644 index 7117a30..0000000 --- a/public/javascripts/ajax.js +++ /dev/null @@ -1,50 +0,0 @@ -function loadArtistData(name) { - setArchor('/artist/'+ name +'/'); - $.get('/artist/'+ name +'/', function(data){ - if (typeof data.error != 'undefined') { - if (data.error == 'loading') { - loadArtistData(name); - } else if (data.error == 404) { - load404Page(); - } - return false; - } - Pages.renderArtist(data); - }) -} -function loadSearchPage() { - setArchor('/search/'); - $.get('/demo/search.html', function(data){ - $('#data-container').html(data); - }) -} -function loadWheePage() { - $.get('/demo/whee.html', function(data){ - $('#data-container').html(data); - }) -} -function load404Page() { - $.get('/demo/404.html', function(data){ - $('#data-container').html(data); - }) -} - -$(function(){ - $('a.data.artist').live('click', function(){ - loadArtistData($(this).html()); - return false; - }); - $('.search').live('click', function(){ - loadSearchPage(); - return false; - }); - $('#search_form').live('submit', function(){ - $('.autocomplete-container').remove(); - loadArtistData($('#search_field').val()); - return false; - }); -}) - -function setArchor(anchor) { - window.location = '#'+ anchor; -} diff --git a/public/javascripts/beathaven/ajax.js b/public/javascripts/beathaven/ajax.js new file mode 100644 index 0000000..7f5bccf --- /dev/null +++ b/public/javascripts/beathaven/ajax.js @@ -0,0 +1,77 @@ +var Ajax = { + loadArtistData: function(name) { + $('#search-container input').attr('disabled', 'disabled').blur(); + $('#search-container img').show(); + name = name.replace(' ', '+'); + Ajax.setArchor('/artist/'+ name +'/'); + $.get('/artist/'+ name +'/', function(data){ + if (typeof data.error != 'undefined') { + if (data.error == 'loading') { + Ajax.loadArtistData(name); + } else if (data.error == 404) { + Ajax.load404Page(); + } + return false; + } + Pages.renderArtist(data); + }) + }, + + loadSearchPage: function() { + Ajax.setArchor('/search/'); + $.get('/demo/search.html', function(data){ + $('#data-container').html(data); + }) + }, + + loadWheePage: function() { + $.get('/demo/whee.html', function(data){ + $('#data-container').html(data); + }) + }, + + load404Page: function() { + $.get('/demo/404.html', function(data){ + $('#data-container').html(data); + }) + }, + + setArchor: function(anchor) { + window.location = '#'+ anchor; + }, + + getAnchor: function() { + var tmp = window.location.href.split('#'); + if (typeof tmp[1] !== 'undefined') { + return tmp[1]; + } + return ''; + }, + + detectStartPage: function() { + if (m = this.getAnchor().match(/\/artist\/(.+)\//)) { + this.loadArtistData(m[1]); + } else if (this.getAnchor() === '' || this.getAnchor().match(/\/search\//)) { + this.loadSearchPage(); + } else { + this.load404Page(); + } + } +} + + +$(function(){ + $('a.data.artist').live('click', function(){ + Ajax.loadArtistData($(this).html()); + return false; + }); + $('.search').live('click', function(){ + Ajax.loadSearchPage(); + return false; + }); + $('#search_form').live('submit', function(){ + $('.autocomplete-container').remove(); + Ajax.loadArtistData($('#search_field').val()); + return false; + }); +}) \ No newline at end of file diff --git a/public/javascripts/audio.js b/public/javascripts/beathaven/audio.js similarity index 100% rename from public/javascripts/audio.js rename to public/javascripts/beathaven/audio.js diff --git a/public/javascripts/layout.js b/public/javascripts/beathaven/layout.js similarity index 95% rename from public/javascripts/layout.js rename to public/javascripts/beathaven/layout.js index 20266c6..ed8aea8 100644 --- a/public/javascripts/layout.js +++ b/public/javascripts/beathaven/layout.js @@ -7,7 +7,7 @@ var beathaven = { init: function () { this.drawInterface(); this.adjustSizes(); - loadSearchPage(); + Ajax.detectStartPage(); }, drawInterface: function() { }, diff --git a/public/javascripts/pages.js b/public/javascripts/beathaven/pages.js similarity index 71% rename from public/javascripts/pages.js rename to public/javascripts/beathaven/pages.js index ca34220..8379795 100644 --- a/public/javascripts/pages.js +++ b/public/javascripts/beathaven/pages.js @@ -53,34 +53,4 @@ var Pages = { $('#data-container').html('').append(artist_info).append(albums_info).scrollbar(); } -} - -/* - -