Created
September 26, 2009 18:14
-
-
Save rmurphey/194346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var $specials = $('#specials'); | |
$specials.find('li.buttons').remove(); | |
var cachedResponse = null; | |
var $details = $('<div/>').appendTo($specials); | |
var handleResponse = function(specials, val) { | |
var daySpecial = specials[val]; | |
var html = '<h3>' + daySpecial.title + '</h3>'; | |
html += '<p>' + daySpecial.text + '</p>'; | |
$details.html(html); | |
$('<img/>') | |
.attr('src', daySpecial.image) | |
.appendTo($details); | |
$details.css('color', daySpecial.color); | |
}; | |
var $select = $specials.find('select') | |
.change(function() { | |
var val = $select.val(); | |
if (!val) { | |
$details.empty(); | |
return; | |
} | |
if (cachedResponse) { | |
handleResponse(cachedResponse, val); | |
} else { | |
$.ajax({ | |
type : 'get', | |
dataType : 'json', | |
url : 'json/specials.json', | |
success : function(specials) { | |
handleResponse(specials, val); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment