Open Side Menu Go to the Top

01-06-2013 , 07:44 PM
Two JavaScript programmers walk into a bar and immediately begin arguing with each other. Meanwhile, an Io and a Erlang programmer are sitting next to each other at the bar laughing their asses off.
Learning Javascript Thread Quote
Learning Javascript Thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Learning Javascript Thread
01-07-2013 , 08:23 PM
Haha I just laughed pretty hard at that
Learning Javascript Thread Quote
01-12-2013 , 11:46 AM
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!
Learning Javascript Thread Quote
01-13-2013 , 11:58 PM
Quote:
Originally Posted by Draidin
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!
Well what exactly are you trying to do?
Learning Javascript Thread Quote
01-18-2013 , 11:45 PM
It's been years since I bought a programming book. But I usually found the Cookbooks were pretty useful when learning a new language.
Learning Javascript Thread Quote
01-22-2013 , 07:04 PM
Quote:
Originally Posted by Draidin
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!
$('.navbar li').on('activate', function() { ... });

assuming you have jquery
Learning Javascript Thread Quote
02-22-2013 , 09:29 PM
I want to bump this old flamewar just to point out that having started getting more heavily into JS/JS frameworks the last few weeks, like 1/2 of the tutorials/stackoverflow questions seem to be in coffeescript. I can follow it well enough, but I do need to sit down and learn it, because it seems like it's becoming more widely spread. It also does look simpler and at least for me, less different from ruby/rails.

Also, front end has become way more fun since I started messing around with backbone. It's also fun to structure all my rails controllers/models to be restful APIs, as a bit of a different challenge.
Learning Javascript Thread Quote
03-03-2013 , 05:34 PM
Rendering HTML client-side is a challenging, fun and rewarding experience. There are certainly perils that come with it. Testing and performance are two that come to mind.

I'm glad to see you're learning/getting into CoffeeScript, though. A similar framework to Backbone, but written in CoffeeScript, is Spine. I wouldn't recommend using it due to it not being actively maintained, but reading its source code can be quite enlightening.

http://www.spinejs.com/docs/index
Learning Javascript Thread Quote
03-03-2013 , 07:26 PM
I've been learning and working with Angular lately, I'm really enjoying it. The API is pretty clean, good documentation, not a lot of boilerplate, good run time performance = pretty awesome combo.
Learning Javascript Thread Quote
04-30-2013 , 04:49 AM
Code:
var TodoList = Backbone.Collection.extend({

    ...

    remaining: function() {
      return this.without.apply( this, this.completed() );
    },

   ...
TodoList.completed() returns an array, is the bolded line just a quirky javascript way to pass arguments from an array into a function?
Learning Javascript Thread Quote
04-30-2013 , 06:51 AM
Quote:
Originally Posted by Shoe Lace
I've been learning and working with Angular lately, I'm really enjoying it. The API is pretty clean, good documentation, not a lot of boilerplate, good run time performance = pretty awesome combo.
I know this post is months old, but angularjs is awesome. I'm building an app that's getting fairly decent sized at this point with a rails backend... it's really fast, easy to use, and powerful.

I wouldn't call the documentation good though... but there's quite a solid community behind it so stackoverflow and blog posts can get you through most things.
Learning Javascript Thread Quote
04-30-2013 , 09:20 AM
Quote:
Originally Posted by e i pi
Code:
var TodoList = Backbone.Collection.extend({

    ...

    remaining: function() {
      return this.without.apply( this, this.completed() );
    },

   ...
TodoList.completed() returns an array, is the bolded line just a quirky javascript way to pass arguments from an array into a function?
The entire array should be passed as an argument. So the apply function would get 2 arguments.
Learning Javascript Thread Quote
04-30-2013 , 10:11 AM
right. I was just confused because I think of apply and call as being used to control the value of "this" and seeing it used just to pass in an array of arguments looked odd.
Learning Javascript Thread Quote
05-01-2013 , 02:25 PM
I have been following the Javascript is Sexy post (too lazy to link). So far, so good. It recommends Professional Javascript if you have any programming knowledge and I would agree with that. It is a good book.
Learning Javascript Thread Quote
05-04-2013 , 11:31 AM
Am trying to come up with a medium-level difficulty JS project. Any ideas / inspiration?

Maybe a todo list?

Also, whenever I look up AJAX info I always run into this:

XMLHttpRequest

But when I look up how to incorporate AJAX into Rails, the syntax is totally dif...usually something like:

$.ajax {
:url => '/rankings',
:type => 'get'
:data => 'json'}

Any idea what this is about? It has me pretty confused since it doesn't mention XMLHttpRequest at all...
Learning Javascript Thread Quote
05-04-2013 , 11:52 AM
$.ajax is doing an XMLHttpRequest under the covers.
Learning Javascript Thread Quote
05-04-2013 , 12:41 PM
ahh
Learning Javascript Thread Quote
05-06-2013 , 02:44 PM
backbone question,

Drupal is a bit special and expects some attributes to be in nested arrays like this,

Code:
model_property[und][0][value] = "some model value"
I know there is a .parse method for responses, which I already set up. Is there something like this for requests? Right now I'm fishing around in the .sync method but want to make sure I'm doing this right.
Learning Javascript Thread Quote
05-06-2013 , 03:55 PM
Are those really nested sequential arrays or just objects (or a combo)? Can you be a bit more specific as to the problem?

FYI - model_property['something'][0]['somevalue'] is the same as model_property.something[0].somevalue
Learning Javascript Thread Quote
05-06-2013 , 06:42 PM
Sorry, I wasn't clear. The property['und'][0]['value'] is on the server side in php.

So on the client side I have a model with attributes like model.title = 'some title', model.content = 'some content'. But on the server side it expects a json object like,
Code:
{
  "title": "some title", 
  "content": {
    "und": [{"value": "some content"}]}
}
I overrode the Backbone.sync with the following modifications to get it working,

from
Code:
    if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
      params.contentType = 'application/json';
      params.data = JSON.stringify(options.attrs || model.toJSON(options));
    }
to
Code:
    if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
      params.contentType = 'application/json';
      var modeldata = model.toJSON(options);  // I added this line
      modeldata.body = {und: [{value: model.body}]};  //and this line
      params.data = JSON.stringify(options.attrs || modeldata); //changed
    }
it works now but I'm curious about best practices. whenever I tried to change the params.data json directly it would fail validation somewhere and cut out my modifications so I copied the object and altered it before turning it to JSON and it seems to work.

I just realized it wasn't failing validation I was just adding properties to a string object. :\

Last edited by e i pi; 05-06-2013 at 06:49 PM. Reason: woops
Learning Javascript Thread Quote
05-07-2013 , 05:55 PM
Quote:
Originally Posted by suzzer99
$.ajax is doing an XMLHttpRequest under the covers.
Is there a good source on this? The rails docs kinda suck for how rails implements AJAX...
Learning Javascript Thread Quote
05-07-2013 , 08:49 PM
Quote:
Originally Posted by Mariogs37
Is there a good source on this? The rails docs kinda suck for how rails implements AJAX...
This has nothing to do with rails btw:

http://api.jquery.com/jQuery.ajax/
Learning Javascript Thread Quote
05-08-2013 , 12:14 AM
this is perfect, didnt realize it was a subset of jquery for some reason

thanks a ton!
Learning Javascript Thread Quote
05-08-2013 , 11:40 AM
So as of right now, I have a JSON object coming back from my AJAX request. I'm trying to use jQuery to append info from this JSON object but, instead of doing that, it simply prints the JSON object to the screen (looks like an array of strings)...

Code:
  $('#rankings_link').click(function(){
    $.ajax({
      dataType: 'json',
      url: '/rankings',
      type: 'get'
    }).done(function(received_data){
      for (var m = 0; m < received_data.length; m++) {
        $('#rankings ol').append('<li>' + received_data[m] + '</li>');
      }
    });
  });
Any idea what the issue is?
Learning Javascript Thread Quote
05-08-2013 , 11:50 AM
JSON/javascript objects don't have a length, you're thinking of an array. turn your json object into an array value so that you iterate through it.
Learning Javascript Thread Quote
Learning Javascript Thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Learning Javascript Thread

      
m