Cross-browser infinite scrolling by dariot

E33544ce36b1844b222c46a9d032e66b?size=52

Lots of suggestions out there for implementing an infinite scrolling that works for all the major browsers, but of all the code snippets that I found there wasn't a single one that would work for Chrome, Firefox and IE8. So I set out to do a little hands-on research and after some trial-and-error this is the code that works for me: Read on

jQuery on() and live() by dariot

E33544ce36b1844b222c46a9d032e66b?size=52

Starting with version 1.7 of jQuery the live() function is deprecated.

As many of you already know, the live() function is used to associate event listeners to some DOM element. For example: Read on

A snippet for enabling maximum of checked checkboxes by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

Just wrap your inputs with <div data-max-values="3">...</div> and add the following #js

$('div[data-max-values]').on 'change :checkbox', ->
  condition = $(':checked', @).length >= Number($(@).data('max-values'))
  $(':not(:checked)', @).prop 'disabled', condition
$('div[data-max-values]').each (i, e) ->
  $(':checkbox:first', e).trigger('change')

#query required. #html #forms

arrayfrom vs [].foreach by hemanth

D32a6bf2b43bf62a7212f0c793d76319?size=52
var divs = document.querySelectorAll('div');
Array.from(divs).forEach(function (node) {
    console.log(node);
});


var divs = document.querySelectorAll('div');
[].forEach.call(divs, function (node) {
    console.log(node);
});

#code #javascript #es6

Javascript HashMapping by YakovL

B8777d6d8668975a34892ddf7664dc8c?size=52

Javascript allows simple "hashmapping" like the one under the cut. I wonder if this is still an ordinary js object and what specifications define it - for instance, not all "properties" of such "object" can be accessed by the dot notation. examples

Best way for runtime-included js assets? by drakmail

558e7fdf5c8c73f03f5bc645d16afa21?size=52

What is best way to compile javascripts, that included in runtime?

While scripts included like this way in may JS file:

$.include('<%= javascript_path 'some.js' %>')
$.include('<%= javascript_path 'some.other.minified.js' %>')

I has this error:

ActionView::Template::Error (some.js isn't precompiled)

Dirty way to avoid this is add ["*.js"] to config.assets.precompile .

Does exist any more clean way to do this?

#rails #js

Rebind best_in_place by Fodoj

2bd08a9429d11ba6a5d818331f2254c5?size=52

Finally found how to rebind best_in_place editor. (Unbind is pretty simple - $(elem).unbind('click')).

editor = $(elem).data().bestInPlaceEditor;
$(elem).bind("click", {editor: editor }, editor.clickHandler );

That's all - best_in_place works with this element again. Hope that helps.

#javascript #best_in_place