Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
excidium
Oct 24, 2004

Tambahawk Soars

Thermopyle posted:

Speaking of angularjs, I'm just now working through the official tutorial and...am I alone in thinking this is a terrible piece of documentation? (maybe I'm just a terrible tutorial reader)

I mean, they just drop new stuff in there all the time with no clear explanation. Take, for example, step-11. They make a Phone resource and use several methods on it with no explanation of where they came from. I mean, I figured it out because I'm awesome, but judging by the comments on nearly every page the tutorial, it's just a bad bit of teaching material.

Any other introductory Angular reading I should use instead of (or in addition to) this piece of poo poo?

Here's the main source of documentation that I use. A compiled list of tutorials and write-ups on an array of subjects.
https://github.com/jmcunningham/AngularJS-Learning

As far as tutorials go, Thinkster.io is a comprehensive layer over the very good Egghead.io videos.
http://www.thinkster.io/
http://egghead.io/

Adbot
ADBOT LOVES YOU

Tres Burritos
Sep 3, 2009

Ugghh, I'm having a hell of a time wrapping my head around JQuery UI. It's like all of the components that I need are there, I can see them, I'm just not sure how to properly hook them together yet.

Anyways, what I'm trying to do is drag and drop tabs across multiple tab divs. I got something that sort of works, but it doesn't behave properly and I'm not sure what to do next. If I drag a tab into a different div, it's content still shows up in the original location and not in the new one. I was thinking the "out" event would do something for me on the source and the "create" event would do something on the destination.

Here's a fiddle that illustrates the problem: http://jsfiddle.net/Tpt4t/


It's like I can see that JQuery will do all the stuff I want but I'm missing some basic assumptions/concepts on the way stuff works. Web isn't really my forte and it's getting sort of frustrating.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Tres Burritos posted:

Ugghh, I'm having a hell of a time wrapping my head around JQuery UI. It's like all of the components that I need are there, I can see them, I'm just not sure how to properly hook them together yet.

Anyways, what I'm trying to do is drag and drop tabs across multiple tab divs. I got something that sort of works, but it doesn't behave properly and I'm not sure what to do next. If I drag a tab into a different div, it's content still shows up in the original location and not in the new one. I was thinking the "out" event would do something for me on the source and the "create" event would do something on the destination.

Here's a fiddle that illustrates the problem: http://jsfiddle.net/Tpt4t/


It's like I can see that JQuery will do all the stuff I want but I'm missing some basic assumptions/concepts on the way stuff works. Web isn't really my forte and it's getting sort of frustrating.

Take a look at this reference: http://jqueryui.com/sortable/#connect-lists-through-tabs

IronDoge
Nov 6, 2008

Tres Burritos posted:

Ugghh, I'm having a hell of a time wrapping my head around JQuery UI. It's like all of the components that I need are there, I can see them, I'm just not sure how to properly hook them together yet.

Anyways, what I'm trying to do is drag and drop tabs across multiple tab divs. I got something that sort of works, but it doesn't behave properly and I'm not sure what to do next. If I drag a tab into a different div, it's content still shows up in the original location and not in the new one. I was thinking the "out" event would do something for me on the source and the "create" event would do something on the destination.

Here's a fiddle that illustrates the problem: http://jsfiddle.net/Tpt4t/


It's like I can see that JQuery will do all the stuff I want but I'm missing some basic assumptions/concepts on the way stuff works. Web isn't really my forte and it's getting sort of frustrating.
From what hieronymus posted, it seems you are missing code that moves the content over to whatever tab group you drag it to. I was a little short on time but I think it needs to look something similar to this:
http://jsfiddle.net/b2mtD/

Not sure if I'm being dumb about it and there's a way to automatically move tab contents over from div to another, but I think you're going to need to make it so it moves to appropriate html over to the target tab.

Tres Burritos
Sep 3, 2009


Yeah, I was looking at that but my problem is that I can't parse what the hell is going on.

I get as far as

code:
var $tabs = $( "#tabs" ).tabs();
Then I look at the documentation and wonder what .tabs() returns. I'm ... not finding an explanation.

I guess it's just implicitly a "getter"?

I'm really struggling with the documentation.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Tres Burritos posted:

Yeah, I was looking at that but my problem is that I can't parse what the hell is going on.

I get as far as

code:
var $tabs = $( "#tabs" ).tabs();
Then I look at the documentation and wonder what .tabs() returns. I'm ... not finding an explanation.

I guess it's just implicitly a "getter"?

I'm really struggling with the documentation.

http://jqueryui.com/tabs/

That line makes the html element with id 'tabs' start being tab-able (probably some stylesheet fuckery)

1. Use the F12 developer tools! Press F12, put a break point on any line you don't understand!
2. Use Google!

Tres Burritos
Sep 3, 2009

hieronymus posted:

1. Use the F12 developer tools! Press F12, put a break point on any line you don't understand!
:aaa: gently caress gently caress gently caress gently caress gently caress. I had firebug installed and everything, Jesus this makes everything so much less painful.

edit: specifically I had no idea that you could set javascript breakpoints.


hieronymus posted:

2. Use Google!

:suicide: It pains me so much that you had to type that out.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Tres Burritos posted:

:aaa: gently caress gently caress gently caress gently caress gently caress. I had firebug installed and everything, Jesus this makes everything so much less painful.

edit: specifically I had no idea that you could set javascript breakpoints.


:suicide: It pains me so much that you had to type that out.

Yeah. If anything has a metric poo poo ton of Google-able answers its JavaScript and jquery. The amount of scenarios where someone hasn't asked the question before you have is minimal, even in advanced cases.

Tres Burritos
Sep 3, 2009

Maluco Marinero posted:

Yeah. If anything has a metric poo poo ton of Google-able answers its JavaScript and jquery. The amount of scenarios where someone hasn't asked the question before you have is minimal, even in advanced cases.

Yeah, part of my problem was I didn't (still don't?) know what some of the correct terminology is for the stuff I'm trying to achieve. In this case "connected" seems to be the correct search term for the idea of sharing tabs across tab widgets. The second result for "jquery connected tabs" gets me exactly what I want.

revmoo
May 25, 2006

#basta
What do you guys think about the various frameworks? I've looked at most of the big ones the past couple days and the only one that has stood out for me is knockout. I really like the simplicity, the relatively clean templating, and the docs/site. Any thoughts? I have a project coming up that involves a wizard of sorts that will be used to book flights. I could do it all w/ just jQuery but for the amount of data back-and-forth there will be to the server I want something more structured.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
I like AngularJS and I'm currently using it for a number of projects, but Christ on a tricycle the documentation sucks. Beyond just content, the whole structure needs to change from a series of disjointed articles. Contemplating rewriting as a project to take up, it really can't get that much worse.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Yeah, Google's technical documentation is some of the worst.

revmoo
May 25, 2006

#basta
Yep I noticed. I'd say the two most important things for me would be good docs, and clean templating.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Suspicious Dish posted:

Yeah, Google's technical documentation is some of the worst.

I've been trying to figure out the youtube API while at the same time learning Angular.

It's amazing how bad all these docs are.

sim
Sep 24, 2003

revmoo posted:

What do you guys think about the various frameworks? I've looked at most of the big ones the past couple days and the only one that has stood out for me is knockout. I really like the simplicity, the relatively clean templating, and the docs/site. Any thoughts? I have a project coming up that involves a wizard of sorts that will be used to book flights. I could do it all w/ just jQuery but for the amount of data back-and-forth there will be to the server I want something more structured.

I've used Knockout on a few different projects and like you said, it's a very simple integration. But, other than two-way data-binding, Knockout doesn't give you a lot of features. It certainly doesn't give you more structure. If that's your requirement, I would look more into Backbone, Ember, or Angular. I'm still on the fence about using HTML attributes for templating/logic like Knockout and Angular. I've been using Backbone+Handlebars for almost everything and love it.

Also, there's a thread for hipster JavaScript MVCs.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Thermopyle posted:

I've been trying to figure out the youtube API while at the same time learning Angular.

It's amazing how bad all these docs are.

I was messing around on a project I was doing that had OAuth support for Google logins. I tried using their java library to decode the JWT payloads which seemed to be this horribly confusing weird library, then one day the link to the documentation for it changed to a completely different library that seemed to do roughly the same thing but in a completely different way and I couldn't find any information on this new package/library/thing anywhere. Google confuses me.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I have come to dread doing anything involving Google APIs or Google libraries. They're frequently shockingly bad, and when they aren't, the documentation is.

revmoo
May 25, 2006

#basta

sim posted:

I've used Knockout on a few different projects and like you said, it's a very simple integration. But, other than two-way data-binding, Knockout doesn't give you a lot of features. It certainly doesn't give you more structure. If that's your requirement, I would look more into Backbone, Ember, or Angular. I'm still on the fence about using HTML attributes for templating/logic like Knockout and Angular. I've been using Backbone+Handlebars for almost everything and love it.

Also, there's a thread for hipster JavaScript MVCs.

Thanks for the insight.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Plorkyeran posted:

I have come to dread doing anything involving Google APIs or Google libraries. They're frequently shockingly bad, and when they aren't, the documentation is.

*cough google closure cough*

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Simple dumb question. I'm replacing a URL with the quantity of a textbox when that textbox is changed. Apologies for the basic question, but I'm a database/analytics guy first. The HTML:
code:
<input type="text" id="txtQty"></input>
<a id="addQty" href="plus.aspx?productid=x&something=y&qty=1">add some!</a>
And the jquery:
code:
    $('#txtQty').blur(function () {
        var newHref = 'plus.aspx?productid=x&something=y&qty=' + $('#txtQty').val();
        $('#addQty').attr('href', newHref);
    });
So this appears to work, in that when I change the quantity in txtQty, when I mouse over the link it now shows "&qty=5" or whatever other number I put in there. When I view source after changing the quantity, it says qty=5, as does Chrome inspector.

However, when I retrieve the querystring on plus.aspx after clicking (using Request("qty"))it says qty=1. Is there something I'm missing; is the href change cosmetic only?

kedo
Nov 27, 2007

e: Never mind, misread your post.

e2: I've been fiddling with that by just sticking http://example.com in the text field and then clicking the link... It appears to be working fine. That JS is so simple I have a hard time believing that's where the bug is.

Silly question, but you're not clicking the link before the field loses focus, are you?

kedo fucked around with this message at 20:14 on Oct 16, 2013

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Ha ha, okay this now makes way more sense. The href is pointing to a NyroModal floating iframe/div on the page, which is why I can't just take over the click event; the modal has to be launched in context. For whatever reason the NyroModal won't take my new URL as a parameter when launching on click (my guess being it's registered at page load) so I have to do it manually using:
code:
 $.nmManual('plus.aspx?productid=x&thing=y&qty=' + $('txtQty').val(),
            {
                model: true, sizes:
                  { minW: 450, minH: 450 },
                showCloseButton: false,
                anim: { resize: true, showTrans: true }
            });

Dominoes
Sep 20, 2007

I'm going through Codeacademy's JS tutorial. I'm new to programming, and currently only am familiar with Python.

I'm curious what needs to be declared and what doesn't: It seems like only the outside variable in a data structure needs to be declared. Ie, If I have an object of arrays of objects of strings, only the outside level object needs to be declared. Is this correct and if so, what's the reasoning behind it?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Dominoes posted:

I'm going through Codeacademy's JS tutorial. I'm new to programming, and currently only am familiar with Python.

I'm curious what needs to be declared and what doesn't: It seems like only the outside variable in a data structure needs to be declared. Ie, If I have an object of arrays of objects of strings, only the outside level object needs to be declared. Is this correct and if so, what's the reasoning behind it?

Javascript has a nasty thing called implied globals. Undeclared variables, when they get assigned, will be assumed to belong in the global scope, which isn't a particularly nice way to write programs.

Basically, you don't have to declare variables for them to work, but implied globals mean the times when you shouldn't declare are very very few.

The attributes to your Objects and Arrays are not in this discussion unless you create or reference them separate to the base Object, in which case you would declare them to avoid the global scope. Just accessing variables through `yourObject['thisAttr'] = 'value'` doesn't require declaration because you're not needing to access any scope at all beyond yourObject.

One of the biggest things to learn with Javascript is how to properly control your variable scope, so you'll find most projects will do all or most code inside a closure, basically a function (even if it only gets run once) that acts as a container for your variables. Scoping is much more fluid in Javascript than in Python, so make sure you spend some time making sure you understand it.

Maluco Marinero fucked around with this message at 21:59 on Oct 19, 2013

Dominoes
Sep 20, 2007

Maluco Marinero posted:

Javascript has a nasty thing called implied globals. Undeclared variables, when they get assigned, will be assumed to belong in the global scope, which isn't a particularly nice way to write programs.

Basically, you don't have to declare variables for them to work, but implied globals mean the times when you shouldn't declare are very very few.

The attributes to your Objects and Arrays are not in this discussion unless you create or reference them separate to the base Object, in which case you would declare them to avoid the global scope. Just accessing variables through `yourObject['thisAttr'] = 'value'` doesn't require declaration because you're not needing to access any scope at all beyond yourObject.

One of the biggest things to learn with Javascript is how to properly control your variable scope, so you'll find most projects will do all or most code inside a closure, basically a function (even if it only gets run once) that acts as a container for your variables. Scoping is much more fluid in Javascript than in Python, so make sure you spend some time making sure you understand it.
Thank you.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Note that in a modern browser, if you put:

JavaScript code:
"use strict"
(with quotes!) at the top of your JS file, then these things will be errors instead of silent global assignments.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Suspicious Dish posted:

Note that in a modern browser, if you put:

JavaScript code:
"use strict"
(with quotes!) at the top of your JS file, then these things will be errors instead of silent global assignments.

Javascript has function scope. Any variable introduced anywhere inside a function is actually visible everywhere within that function.

You can nest functions inside other functions. Variables declared in outer functions are visible in inner functions. Variables declared in inner functions are not visible in outer functions.

Strongly consider using a linter (JSHint, or if you hate yourself, JSLint)

Also: use yout browser's debugging tools. Use breakpoints. Step through code. Set watches. Use console.log()

Dominoes
Sep 20, 2007

I'll read up on JS inheritance.

Are JS objects essentially a hybrid of associative arrays (ie dicts/hashes) and classes/objects ? Their functionality and use seem to share properties of, and take the role of each.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dominoes posted:

I'll read up on JS inheritance.

Are JS objects essentially a hybrid of associative arrays (ie dicts/hashes) and classes/objects ? Their functionality and use seem to share properties of, and take the role of each.

Yes. The idea is that one object can "chain" to another, if a property isn't found in one, sort of like traditional inheritance. To create an object a that inherits from object b:

JavaScript code:
var b = { foo: 10, bar: 20 };
var a = Object.create(b);
You can build something that looks like class inheritance with this, along with constructors (which I won't touch, because they're really confusing)

Deus Rex
Mar 5, 2005

Wheany posted:

Javascript has function scope. Any variable introduced anywhere inside a function is actually visible everywhere within that function.

You can nest functions inside other functions. Variables declared in outer functions are visible in inner functions. Variables declared in inner functions are not visible in outer functions.

Strongly consider using a linter (JSHint, or if you hate yourself, JSLint)

Also: use yout browser's debugging tools. Use breakpoints. Step through code. Set watches. Use console.log()

yes, I'm sure S. Dish knows that. Strict mode raises an error if you try to assign to an identifier which has not been explicitly declared as a var. Check the console here:

http://bl.ocks.org/tomjakubowski/7078088

minidracula
Dec 22, 2007

boo woo boo
New dumb JS question from me.

I have a gauge derived from the sample shown here: http://bl.ocks.org/msqr/3202712

That thing has a function called "updateReadings()" defined and called within onDocumentReady(). In the sample, updateReadings() just calls the gauge's "update" method with random numbers as spat out by a call to Math.random.

In my hacked-together code that includes my derivative of this gauge, I want to call update, say via updateReadings(), but I want to gut the body of updateReadings() and use the value of a variable that is set by a WebSocket onmessage event elsewhere in the same code. I'm still JavaScript-stupid, and my flailing around trying things I think either should or might work hasn't netted me anything. I know I'm getting data back from my WebSocket call that I expect, because I've added console.log statements to those bits. I can see when I get a new batch of data, as well as the specific value I want to use to update the gauge.

What obvious thing am I missing here?

EDIT: I "fixed" this by making the var ("gaugeValue") I was trying to update from the WebSocket onmessage event a global. I feel dirty doing it this way though. So now I have a global var that is init'd to 0, then as a WebSocket message comes in (with the right key-value pair), I update that var with the value. updateReadings() in the onDocumentReady() gauge code now basically just calls powerGauge.update(gaugeValue) and a console.log statement for debugging. Is this sane?

minidracula fucked around with this message at 09:34 on Oct 21, 2013

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

mnd posted:

New dumb JS question from me.

I have a gauge derived from the sample shown here: http://bl.ocks.org/msqr/3202712

That thing has a function called "updateReadings()" defined and called within onDocumentReady(). In the sample, updateReadings() just calls the gauge's "update" method with random numbers as spat out by a call to Math.random.

In my hacked-together code that includes my derivative of this gauge, I want to call update, say via updateReadings(), but I want to gut the body of updateReadings() and use the value of a variable that is set by a WebSocket onmessage event elsewhere in the same code. I'm still JavaScript-stupid, and my flailing around trying things I think either should or might work hasn't netted me anything. I know I'm getting data back from my WebSocket call that I expect, because I've added console.log statements to those bits. I can see when I get a new batch of data, as well as the specific value I want to use to update the gauge.

What obvious thing am I missing here?
Not sure exactly what you're asking here. Posting a jsfiddle or jsbin link to your code might help.

minidracula
Dec 22, 2007

boo woo boo

peepsalot posted:

Not sure exactly what you're asking here. Posting a jsfiddle or jsbin link to your code might help.
Just edited my post above; I "solved" this by making the var a global. I feel unclean, but perhaps this is fine?

EDIT: peepsalot: I'll try to minimize a sample and put it up somewhere, but it may take me a while. Now that I've got this part working, I'm on to the next thing I need to do. I'll post again once I've put code up though, since I really would like to understand this rather than just stop at having hacked something together that merely seems to work (but without a clear idea of why or how to do it better). Thanks!

minidracula fucked around with this message at 09:42 on Oct 21, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Deus Rex posted:

yes, I'm sure S. Dish knows that. Strict mode raises an error if you try to assign to an identifier which has not been explicitly declared as a var. Check the console here:

http://bl.ocks.org/tomjakubowski/7078088

Yeah, that reply was not meant for suspicious dish as such, it was meant as additional information. Those (and explicit "this") were things that tripped me up before I actually learned the language.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

mnd posted:

EDIT: I "fixed" this by making the var ("gaugeValue") I was trying to update from the WebSocket onmessage event a global.

There is no gaugeValue anywhere in your example.

DholmbladRU
May 4, 2006
I am extending the functionality of a Business Intelligence tool. This is a web based application. Currently attempting to create some type of "form" validation. The strange thing is that this application reuses the same input for every single one of the form inputs. Once the user clicks away from the input html object, some javascript moves the value entered into the input into the text within a div.

**Before**:

code:
    <div>
    </div>
Input **filled out**:
code:
    <input type="text" value="this is a test">
**Result**:
code:
    <div>
    this is a test>
    </div>
Is there any way to create a listener which will validate what is written inside of the div?

The BI tool is designed to reuse the same input element for some reason.. Dont ask me why, but it reuses it with javascript then writes the value into a div. Can I validate what is written to that div??

TURTLE SLUT
Dec 12, 2005

Suspicious Dish posted:

Yes. The idea is that one object can "chain" to another, if a property isn't found in one, sort of like traditional inheritance. To create an object a that inherits from object b:

JavaScript code:
var b = { foo: 10, bar: 20 };
var a = Object.create(b);
You can build something that looks like class inheritance with this, along with constructors (which I won't touch, because they're really confusing)

The company I work for uses this pattern:

JavaScript code:
var SuperClass = function(param){
    this.param = param;
};

var Subclass = function(param){
    SuperClass.call(this, param);
    this.whatever = 1;
};

var instance = new Subclass('butt');
I've been wondering if it has any downsides compared to these other ways of implementing inheritance in JS. I think it looks nicer. You can even do an arbitrary amount of logic before you inherit stuff from the SuperClass, which is sort of useful.

bartkusa
Sep 25, 2005

Air, Fire, Earth, Hope

JOHN SKELETON posted:

I've been wondering if it has any downsides compared to these other ways of implementing inheritance in JS. I think it looks nicer.

My employer uses Dojo. It's kinda heavy, but we've hit a nice balanced ratio of power/insanity.

dojo.declare makes it really easy for Java devs (like myself) to pretend that JS has classes.

Dojo supports multiple inheritance through mixins, which makes it easy to glom functionality onto widgets.

The Insect Court
Nov 22, 2012

by FactsAreUseless

DholmbladRU posted:

I am extending the functionality of a Business Intelligence tool. This is a web based application. Currently attempting to create some type of "form" validation. The strange thing is that this application reuses the same input for every single one of the form inputs. Once the user clicks away from the input html object, some javascript moves the value entered into the input into the text within a div.

Is there any way to create a listener which will validate what is written inside of the div?

The BI tool is designed to reuse the same input element for some reason.. Dont ask me why, but it reuses it with javascript then writes the value into a div. Can I validate what is written to that div??

Attach an onblur handler to the input element, have it do validation of the input. Have some property that tracks the state of the weird pseudo-form so it knows what to validate for.

Adbot
ADBOT LOVES YOU

Mogomra
Nov 5, 2005

simply having a wonderful time
Here's a stupid question that doesn't deserve its own thread. What's the deal with "new," or rather not using it? What's the logic behind defaulting "this" to the window, or whatever the global object is? Why not default to "this" from the scope that the function was called? It's stupid, and there's no reason not to use "new" when it's needed, I just don't get why JavaScript does what it does when you leave it out.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply