Created
November 20, 2010 21:50
-
-
Save hayeah/708206 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $ () -> | |
| window.search = new LiveSearch("#search") | |
| class LiveSearch | |
| constructor: (context,result) -> | |
| el = @context = $(context) | |
| @result = el.find(".result") | |
| @form = el.find("form") | |
| @form.bind "ajax:success", (e,data) => | |
| window.data = data | |
| @update($(data)) | |
| @checkboxes = @form.find(":checkbox") | |
| @checkboxes.bind "change", () => | |
| @submit() | |
| @sliders = @form.find(".slider").map (i,slider) => new Slider(this,slider) | |
| submit: () -> | |
| @form.callRemote() | |
| update: (deals) -> | |
| @result.find(".deals").replaceWith(deals) | |
| class Slider | |
| constructor: (@search,context) -> | |
| el = @context = $(context) | |
| # slider config | |
| @slider = $("<div>") | |
| @display = $("<div>") | |
| el.append(@display) | |
| el.append(@slider) | |
| @options = $.parseJSON @context.find(".options").text() | |
| @slider.slider(@options) | |
| @slider.bind "slide", (event,ui) => | |
| @update(ui.values || ui.value || 0) | |
| @slider.bind "slidechange", (event,ui) => | |
| @search.submit() | |
| @input = el.find(":input") | |
| @update(@options.values || 0) | |
| update: (values) -> | |
| @update_display(values) | |
| @input.val values.toString() | |
| update_display: (values) -> | |
| # humanize the display according to specified type | |
| if values instanceof Array | |
| display = "#{@format(values[0])}, #{@format(values[1])}" | |
| else | |
| value = values | |
| display = @format(value) | |
| @display.html(display) | |
| format: (value) -> | |
| switch @options.format | |
| when "million" then "$#{value / 1000000}M" | |
| when "percent" then "#{value / 100}%" | |
| else value.toString() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment