coffeescript

CoffeeScript - detect if current scroll position is below div

元气小坏坏 提交于 2019-12-12 02:34:22
问题 I would like to detect when the user scrolls past a certain point in the window. [Meta] X scroll below = alert() I'm quite new to CoffeeScript, so any help would be great! What I currently have is this: $("#area_1").bind('scroll', -> scrollPosition = $(this).scrollTop() + $(this).outerHeight() divTotalHeight = $(this)[0].scrollHeight() if (scrollPosition >= divTotalHeight) alert('end reached') ) And no alert is showing up. Any tips? Update I suspect that my problem have to do with my two

Creating jquery draggable “stop” callbacks in a for loop

跟風遠走 提交于 2019-12-12 02:33:28
问题 I have a for loop iterating through a variable number of draggable elements, creating a stop-event callback for each. The callback function needs to know the index of the item that it is linked to. I've encountered what I think is a closure problem: when the callbacks are fired off, the state of the loop iterator index variable that gets passed to the callback (_x) is the last value of the loop iterator index, rather than the value of that iterator index at the time the callback function was

How can one set a sequential delay on adding a class?

安稳与你 提交于 2019-12-12 02:29:21
问题 I'm using jQuery UI plugin and the latest jQuery. I would like to sequentially add on the class, one by one down my array of elements. Right now I have this : $(@el).addClass("gridBoxComplete", 400, "easeOutBounce").delay(800) Where @el is the current element in the array. This, however, does not delay this object before the next item in the iteration is run. I based this animation roughly off of this idea.. $(@).hide().each (index) -> $(@) .delay(index * 100) .fadeIn 500 回答1: delay() delays

Atom 'spec' files not being tested

不想你离开。 提交于 2019-12-12 02:15:25
问题 Following up from my previous question, here, I am trying to get 'spec' files registered by Atom, which I have succeeded in, however now, no matter how many describe and it 's I do, it doesn't do anything when I test it. I use the command, apm test , and all I get is: [655:0527/083825:WARNING:resource_bundle.cc(305)] locale_file_path.empty() for locale English [655:0527/083825:ERROR:file_io.cc(30)] read: expected 40, observed 0 [659:0527/083825:WARNING:resource_bundle.cc(305)] locale_file

Redirection on AJAX success using window.location.replace()

百般思念 提交于 2019-12-12 01:56:28
问题 I am trying to redirect the page on the successful ajax call, the following code works fine, $.ajax( { type: "POST", url: path, data: response1, contentType: "application/json", success: -> window.location.replace("http://172.16.17.141:81/configuration/manage_users") }); Problem with this approach is that the path I am giving is fixed, I want something like, $.ajax( { type: "POST", url: path, data: response1, contentType: "application/json", success: -> alert(window.location.host + "

Closures and CoffeeScript's Scoping

三世轮回 提交于 2019-12-12 01:53:03
问题 The following code defines two functions, lines and circles , that return a function, f and g respectively. Functions f and g are equal ( () -> size ) only for simplicity, but in general they are different functions of the variable size . lines = () -> size = 10 # default value f = () -> size f.size = (_) -> size = _ f f circles = () -> size = 15 # default value g = () -> size g.size = (_) -> size = _ g g On the console, the above code results on the following pattern, which is what I need: >

How do I execute a function only once in CoffeeScript

拥有回忆 提交于 2019-12-12 01:44:34
问题 I want to make a CoffeeScript function that even if it is invoked multiple times, has its effects only run once. Is one of these, or another way a good way to make a once-invokable function ? Is the extra do an issue or actually better ? once_maker_a = (f)-> done=false -> f.call() unless done done=true once_maker_b = (f)-> do(done=false)-> -> f.call() unless done done=true oa = once_maker_a(-> console.log 'yay A') ob = once_maker_b(-> console.log 'yay B') oa() yay A #runs the function passed

EmberJS hasMany association fetch not working properly

蹲街弑〆低调 提交于 2019-12-12 01:43:17
问题 Working on an app that has events and each event has many images Here is the association: images: DS.hasMany("event-image", { async: true }) The EventImage Model: `import DS from 'ember-data'` EventImage = DS.Model.extend event: DS.belongsTo("event") ### NATURAL ATTRIBUTES ### imageUrl: DS.attr("string", { defaultValue: "" }) fileName: DS.attr("string") fileSize: DS.attr("string") primary: DS.attr("boolean", { defaultValue: false }) featured: DS.attr("boolean", { defaultValue: false })

Ajax in rails returns alway error callback

风格不统一 提交于 2019-12-12 01:27:58
问题 I posted question recentry as same how to use local or instance variable inruby codein coffeescript in haml templ Getting helpful comment, I'm trying to pass param to controller in ajax but it always returns error callback I can't not find the reason. Here is my code. .html.haml :coffee $('input#field').change -> $.ajax url: '/posts/gaga' type: "GET" dataType: "json" data: { code: $('input#field').val() } error: (jqXHR, textStatus, errorThrown) -> alert "error" success: (data, textStatus,

In CoffeeScript, how can you make a function call with anonymous functions as parameters?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 01:27:15
问题 The following gives a syntax error related to the anonymous function: my_function = (f, x, str) -> alert str + f(x) my_function (x) -> 1 + x, 12, "The answer is: " The following works: my_function = (f, x, str) -> alert str + f(x) increment = (x) -> x + 1 my_function increment, 12, "The answer is: " 回答1: my_function ((x) -> x + 1), 12, "The answer is: " That should fix it. 来源: https://stackoverflow.com/questions/6720402/in-coffeescript-how-can-you-make-a-function-call-with-anonymous-functions