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
akadajet
Sep 14, 2003

Uziel posted:

What's the "best" javascript/html IDE right now? I have an upcoming Javascript/HTML5 class starting in a few weeks so I'm looking around. I'm a Visual Studio person and I think Jetbrains is awesome but I see that they have WebStorm for $29 under academic. Is this the best option or is there something out there free that will suit my needs?

You could use Visual Studio to debug javascript in IE if you want. IDEs in JS dev aren't as important/useful as they are for other languages. The best tools and debuggers are built into the browsers themselves.

Adbot
ADBOT LOVES YOU

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

akadajet posted:

You could use Visual Studio to debug javascript in IE if you want. IDEs in JS dev aren't as important/useful as they are for other languages. The best tools and debuggers are built into the browsers themselves.
Yeah I just want to broaden my experiences a bit. I currently use Visual Studio and and the browser's tools for debugging at work and a few personal projects but I want to move out of my comfort zone some and try something new that isn't Notepad++/notepad. I know I won't get away from the browser tools for debugging though.

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

Uziel posted:

What's the "best" javascript/html IDE right now? I have an upcoming Javascript/HTML5 class starting in a few weeks so I'm looking around. I'm a Visual Studio person and I think Jetbrains is awesome but I see that they have WebStorm for $29 under academic. Is this the best option or is there something out there free that will suit my needs?

the jetbrains javascript editor is hands-down the best i've found.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Uziel posted:

What's the "best" javascript/html IDE right now? I have an upcoming Javascript/HTML5 class starting in a few weeks so I'm looking around. I'm a Visual Studio person and I think Jetbrains is awesome but I see that they have WebStorm for $29 under academic. Is this the best option or is there something out there free that will suit my needs?

Jetbrains it pretty good, in my experience. You even have the option of using JSLint and JSHint, which you should get in the habit of using. JSLint is probably a bit too opinionated, but I've already become accustomed to it so I don't mind that much. JSHint is far more lenient w/r/t formatting and such, but will still catch scoping errors and other actual errors.

With large files (like the 5452 line monstrosity I'm refactoring right now), it becomes really slow with some operations

e:

Uziel posted:

Yeah I just want to broaden my experiences a bit. I currently use Visual Studio and and the browser's tools for debugging at work and a few personal projects but I want to move out of my comfort zone some and try something new that isn't Notepad++/notepad. I know I won't get away from the browser tools for debugging though.

Notepad++ it okay for Javascript development, but again, install the JSLint plugin.

Mogomra
Nov 5, 2005

simply having a wonderful time
A lot of hipsters have been using https://c9.io for JavaScript development, and I find that it works ok for free. Of course you need internet access to use it. I guess it's more geared towards Node.js development too, but it works for vanilla JavaScript/HTML5.

jkyuusai
Jun 26, 2008

homegrown man milk
Sublime Text 3 all the way baby. Make sure to install Package Control and browse around the repo for cool things to install. ST + Package Control is crazy powerful and pretty to boot.

ST asks you to buy a license every couple times you save a file. Unlimited trial and not crippled in any way, though. It's a great piece of software and well worth the $70 I paid for it.

As already suggested, for JS, make sure to install a good linter. I use the Sublime Linter package. It defaults to using JSHint. (Note that it needs to be installed manually for ST3.) Oh, and don't forget to install nodejs if you don't already have it.

edit: VVVV Snippets are the poo poo. I'm embarrassed to say I just started using them a few weeks ago - only took me a year.

jkyuusai fucked around with this message at 04:01 on Sep 15, 2013

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL
Sublime with emmett and jshint is great, especially if you do much jquery mobile stuff like I do where you use a lot of snippets over and over again.

TURTLE SLUT
Dec 12, 2005

Snippets are great in Sublime Text but I wish I had more control over them. As is it's loading about 200 snippets for JS where I only would really need about 10. Gets sort of annoying.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
Thanks all for the suggestions, I had forgotten entirely about the existence of linters!

Aniki
Mar 21, 2001

Wouldn't fit...
I have a client that wants me to develop a "storyboard" type application that allows a customer to sketch, write notes, and add pictures so they can better express what they are looking for. I've come across a couple sketching libraries like wPaint, Sketch.js, and jqScribble that look interesting. I'm curious if there are any other drawing/sketching libraries that are worth considering for this project?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I don't know of any particular libraries, but I do know that canvas is really easy to work with if you decide to roll your own. You just have to give the finger to IE8 (excanvas works, but gently caress me it's slow and would be horrible with mouse events for drawing).

abraham linksys
Sep 6, 2010

:darksouls:

Chenghiz posted:

What kind of web apps do you guys use MVCs for?

I'm finishing up working on an app for retailers to do inventory control which seems like kind of a big deal but I'm still not sure it would be that much more efficient/effective to use an MVC versus mimicking MVC architecture using jQuery and a basic javascript object data model. I'm also coming at this from a distinctly not CS background so maybe I'm just Doing It Wrong.

http://noted.herokuapp.com/ this is an app I made to learn Ember. It made it easy to architect it like a desktop app - everything is just magically wired together. Sometimes the magic breaks horribly, but it's good until then.

Currently, I'm using Ember to work on a big ol' table-based admin panel with sorting/filtering/pagination/etc. Ember's made it easy to structure all of this in general ways, and lessened the amount of explicit wiring up of components. At the same time, it's harder to write abstracted magic than a bunch of manual boilerplate, so I don't know if I'm really doing it any faster. Sure as hell having more fun doing it, though.

I use Angular occasionally, too. I made this in it, which is just directives, but I used it more fully at work for a while. If nothing else, directives are awesome. A general personal rule of thumb is that if the project doesn't involve client side routing, Angular is a good choice. Ember's router is incredibly robust, and makes it easy to make real, URL-driven web apps, whereas I've heard nothing but horror stories about Angular's routers (yes, plural - there's a built-in one and ui-router, which is supposed to be better). Still, the lack of a separate data layer (just $.ajax your poo poo into $scope, no model definitions required) and the lack of required build tooling (unlike Ember, which really needs template compilation among other things) make it easy to integrate into existing, primarily server-side projects.

And use Backbone if you hate yourself or if you're really against the concept of opinionated libraries. The only happy Backbone users I know have developed their own libraries on top of it. I've been interviewing at a company that uses it with their own, custom-developed view layer, which just seems to me to do the same poo poo Angular directives or Ember views/components do out of the box. Backbone is seriously the worst of both worlds.

I've been thinking of making a "bleeding-edge front-end development" thread, covering stuff like JS MVC frameworks, build tools, etc.

abraham linksys fucked around with this message at 07:09 on Sep 17, 2013

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
I have this idea festering, but it needs me to write javascript that generates javascript. Is there anything that would facilitate such a thing, or am I looking at a lot of escaping and string concatenation?

abraham linksys
Sep 6, 2010

:darksouls:

FeloniousDrunk posted:

I have this idea festering, but it needs me to write javascript that generates javascript. Is there anything that would facilitate such a thing, or am I looking at a lot of escaping and string concatenation?

escodegen is pretty rad.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

abraham linksys posted:

I made this in it, which is just directives, but I used it more fully at work for a while.

Just so you know, the fontawesome files on that site aren't loading on FF Nightly 26.0a1.

abraham linksys posted:

I've been thinking of making a "bleeding-edge front-end development" thread, covering stuff like JS MVC frameworks, build tools, etc.

I'd be interested in this. I have very little experience with JS MVC frameworks and would like to see what other people have done/can do with them.

Aniki
Mar 21, 2001

Wouldn't fit...

Bognar posted:

I don't know of any particular libraries, but I do know that canvas is really easy to work with if you decide to roll your own. You just have to give the finger to IE8 (excanvas works, but gently caress me it's slow and would be horrible with mouse events for drawing).

I'll take a look at that. I think I'd still rather use an existing jQuery library or plugin, but it's good to have that as an option.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

FeloniousDrunk posted:

I have this idea festering, but it needs me to write javascript that generates javascript. Is there anything that would facilitate such a thing, or am I looking at a lot of escaping and string concatenation?

I don't know about that crazy parser codegen thing, but if you end up needing to concat a shitload of strings, the best way is to make an array and .push() them on, then .join() the array when you are done.

You could use eval to run a string of code but another option would be converting your script to base64 and setting it as a data:uri for the src attribute in a dynamically created <script> tag. This might play better with debugging/line numbers compared to eval, but I haven't tried data:uri on javascript source, only images.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

peepsalot posted:

I don't know about that crazy parser codegen thing, but if you end up needing to concat a shitload of strings, the best way is to make an array and .push() them on, then .join() the array when you are done.

You could use eval to run a string of code but another option would be converting your script to base64 and setting it as a data:uri for the src attribute in a dynamically created <script> tag. This might play better with debugging/line numbers compared to eval, but I haven't tried data:uri on javascript source, only images.

Yeah, though the codegen thing does look interesting for something deeper, I'm basically just wanting to plug values into a template to generate a bookmarklet (so I don't even have to eval() it, just set the src of an <a> tag and say "drag me to your bookmarks bar"). But I would be interested in making the bookmarklet code somewhat obfuscated as well. I guess I could write the template with placeholders, obfuscate, then replace the placeholders when the time comes.

Still on the same festering idea, if I want to pop up a dialog on *any* webpage via HTML injection from a bookmarklet, what would be a good way to ensure a consistent set of styles? I'm sort of doing this at the moment:

code:
var inject=document.createElement('div');
inject.style.backgroundColor='white';
inject.style.fontFamily='Sans-Serif';
inject.style.fontSize='16px';
inject.style.color='black';
/* ...various other styles, attempting to get a consistent appearance... */
inject.innerHTML="<p>butts</p>";
document.body.appendChild(inject);
Which seems inefficient and likely to miss something (just noticed I'll have to do zIndex=Math.MAXINT or whatever as well, and I suppose lineHeight, and whatever else is out there, drop shadow, columns, cripes).

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Make your pop-up be an iframe, then you can write whatever you want into it and it won't be affected by styles on the containing page.

sim
Sep 24, 2003

abraham linksys posted:

And use Backbone if you hate yourself or if you're really against the concept of opinionated libraries. The only happy Backbone users I know have developed their own libraries on top of it. I've been interviewing at a company that uses it with their own, custom-developed view layer, which just seems to me to do the same poo poo Angular directives or Ember views/components do out of the box. Backbone is seriously the worst of both worlds.

I've been thinking of making a "bleeding-edge front-end development" thread, covering stuff like JS MVC frameworks, build tools, etc.

I started a new job in May and had to learn Backbone on the job. I will agree that it requires a lot of work to do things that would be simple in other libraries. Marionette really helps with views. If I was going to start a new project from scratch, I probably would try out Ember or Angular, but at this point I'm really glad I've learned Backbone.

Please start that bleeding edge thread. If you don't, I will.

hedgecore
May 2, 2004

Chenghiz posted:

What kind of web apps do you guys use MVCs for?

Addy Osmani has addressed many of these things in this article.
http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/
("Frameworks: When To Use What?" and onward is probably most relevant to you)

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Speaking of Backbone (and other such libraries, but Backbone is the only I've used):

How should I separate view data from server data?

If I have a view such as this (rendered as HTML):
HTML code:
<select multiple>
	<option value="1" selected>Butt</option>
	<option value="2" selected>Arse</option>
	<option value="3">Rump</option>
</select>

And the user has selected the first two values (and not set programmatically, just set to "selected" to illustrate the point). Then some refresh script in the background updates the model, with
JavaScript code:
{
	1:"Butt",
	2:"Arse",
	3:"Rump",
	4:"Buns"
}
How do I preserve the user's selection when I re-render the select in response to "change:butts" event? The "selected" state is part of the view's state, it's not something that is synchronized back to the server, but it should not be lost just because an element changed.

If the answer is "don't use Backbone", then what should I use?

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL

hedgecore posted:

Addy Osmani has addressed many of these things in this article.
http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/
("Frameworks: When To Use What?" and onward is probably most relevant to you)

Ah thanks, I remember reading that a while ago and I guess I didn't retain much of it.

darthbob88
Oct 13, 2011

YOSPOS
I need to tell when a page changes content. Specifically, on this site I need to know when somebody's looking at a product page like this so I can call a certain function. Should I attach a handler to a certain event, like document.onchange or whatever, or should I just have a function running every few hundred milliseconds looking for a product page element? The latter option is simpler, but seems unprofessional for some reason.

smug forum asshole
Jan 15, 2005

darthbob88 posted:

I need to tell when a page changes content. Specifically, on this site I need to know when somebody's looking at a product page like this so I can call a certain function. Should I attach a handler to a certain event, like document.onchange or whatever, or should I just have a function running every few hundred milliseconds looking for a product page element? The latter option is simpler, but seems unprofessional for some reason.

Please do not attempt to do the latter. Your urls both link to the same place, but I think I get the idea. I think you'll want to look for hashchange events on the document. You should be able to attach a function that listens for whenever there's a hashchange and fires itself.

darthbob88
Oct 13, 2011

YOSPOS

smug forum rear end in a top hat posted:

Please do not attempt to do the latter. Your urls both link to the same place, but I think I get the idea. I think you'll want to look for hashchange events on the document. You should be able to attach a function that listens for whenever there's a hashchange and fires itself.
Onhashchange is exactly the one I want, thanks. Should be easy enough to whip a small function up to do what I need it to.

I noticed the URL problem a bit after writing that post. Apparently the site only has one page, and loads all content dynamically through either iphonenav.js or mobile.js, I think the latter. That's useful for me because I'd only have to download jQuery once but on the other hand I have to check periodically for changes in content.

abraham linksys
Sep 6, 2010

:darksouls:
I wrote a thread about modern front-end development! It is here.

DholmbladRU
May 4, 2006
I have a design question for google maps api v3. Currently I am developing a google maps visualization to be placed ontop of some reporting software. So essentially end users will run a report which contains US states, and then they receive a google map with those states plotted out in polygons. Now the problem comes when they try to view the report at a lower level such as zip code or county, this will cause a large number of polygons to render.

Now it has to be dynamic in the fact that I have to render the data that is returned, for example they can filter to specific states or zipcodes.

Question: What would be the fastest way to perform this. Currently my polygons are stored as json objects which contain lat/long arrays.

I have though about a few options.

1. Prebuild the javascript objects for each row in the database, for example parse the json and turn it into an entire google v3 api polygon in javascript Nevatives: if there are a large # lat/long the column may be too long

2. Keep as Json and parse out the lat/long on runtime for each record

3. ????

o.m. 94
Nov 23, 2009

Hi gang, I need to improve my JS/jQuery skills so I thought I'd start a dumb sideproject in order to do so. Come pay a visit and lend me some friendly advice so I can improve.

Sylink
Apr 17, 2004

Is there an easy way to find the index of an object in an array of objects in JS? I am trying to avoid an extra library to add in but if I have to I will (looking at underscore).

For example
code:

var foo = [{test:1,some:3,thing:4},{test:2,some:5,thing:6}];

How do I search for a specific index such as what is the index of {test:2,some:5,thing:6}? (which we know is 1 by looking).

IndexOf does not work for this correctly it would seem.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

You could just look at the source for _.isEqual and then use that as a comparator (without invoking the whole _ library). might have to write a loop for the array though, idk if indexOf takes a comparator

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

A MIRACLE posted:

You could just look at the source for _.isEqual and then use that as a comparator (without invoking the whole _ library). might have to write a loop for the array though, idk if indexOf takes a comparator

Or _.findWhere.

Underscore is pretty great, though.

Sylink
Apr 17, 2004

Yah I had to do a loop, would prefer a pre-made function, but I guess I will roll my own out of this, still easier than the standard functions.

code:
var test = [{name:"bob",id:5},{name:"dan",id:6}];

var check = {name:"dan",id:6};
for (var i = 0; i < test.length; i++) {
    var temp = _.isEqual(test[i],check); 
    if (temp === true) {
        alert(i);
    }
}

Stoph
Mar 19, 2006

Give a hug - save a life.

Sylink posted:

Yah I had to do a loop, would prefer a pre-made function, but I guess I will roll my own out of this, still easier than the standard functions.


code:
var test = [{name:"bob",id:5},{name:"dan",id:6}];
var check = {name:"dan",id:6};
var match = _.find(test, _.bind(_.isEqual, _, check));

WHERE MY HAT IS AT
Jan 7, 2011
I have kind of a weird issue. I have a function that's intended to validate a form before sending it off. The code looks like this:
code:
        function validateForm(){
            var valid = false;
            var radioButtons = document.getElementsByName("studentFacultyButton");

            if (!checkName()){
                alert("You must enter a name!");
            }

            if (!checkAddress()){
                alert("You must enter an address!");
            }

            if (!checkCity()){
                alert("You must enter a city!");
            }

            if (!checkPostal()){
                alert("You must enter a valid postal code!");
            }

            if((!radioButtons[0].checked) && (!radioButtons[1].checked)){
                alert("You must select either faculty or student!");
            }

            else {
                valid = true;
            }

            return valid;
        }
It all works fine except for the first condition. If the first condition fails, it submits the form anyways. If any of the other conditions fail, it won't submit (as expected). It doesn't seem to matter which condition is the first one, whichever field that is can fail and it will still submit. Is there some kind of limit on the number of chained ifs that I'm hitting or something?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
You don't have any chained ifs there. Only the last condition failing will result in the form not submitting, not any of them but the first.

WHERE MY HAT IS AT
Jan 7, 2011

Plorkyeran posted:

You don't have any chained ifs there. Only the last condition failing will result in the form not submitting, not any of them but the first.

:blush: I've been staring at this too long, I was missing the forest for the trees. Thank you!

Skiant
Mar 10, 2013

A MIRACLE posted:

You could just look at the source for _.isEqual and then use that as a comparator (without invoking the whole _ library). might have to write a loop for the array though, idk if indexOf takes a comparator

You can also use a custom build of Lo-Dash to get only the module(s) your project requires.

o.m. 94
Nov 23, 2009

Apologies for the question as it may take a bit of code reading, but if anyone's up for it:

https://github.com/persepoliz/ascii-timewaster/blob/master/js/game.js

The object TerrainObj has a method, load_terrain. Originally, instead of declaring the locally scoped variable terrain, then assigning the result to TerrainObj.terrain, I just set it to the variable this.terrain.

For some reason, even though the load_terrain method is invoked, and locally this.terrain is populated, when I went to reference it later as TerrainObj.terrain, it would be an empty array, as it was originally initialized in the object literal notation. The only way I could "force" TerrainObj.terrain to be populated is to explicity state it as I have done in the code you see. So for some reason, outside of the method, any assignment has been ignored or overriden by the OLN definition above.

I am probably misunderstanding the purpose of "this", but I assumed that since load_terrain is a method of TerrainObj, then invoking this.terrain would indeed reference TerrainObj.terrain.

I am confused, because another method in TerrainObj, generate_display_layer, populates an attribute using "this" without any problems.

Thoughts?

o.m. 94 fucked around with this message at 11:04 on Sep 29, 2013

Adbot
ADBOT LOVES YOU

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

oiseaux morts 1994 posted:

Apologies for the question as it may take a bit of code reading, but if anyone's up for it:

https://github.com/persepoliz/ascii-timewaster/blob/master/js/game.js

The object TerrainObj has a method, load_terrain. Originally, instead of declaring the locally scoped variable terrain, then assigning the result to TerrainObj.terrain, I just set it to the variable this.terrain.

For some reason, even though the load_terrain method is invoked, and locally this.terrain is populated, when I went to reference it later as TerrainObj.terrain, it would be an empty array, as it was originally initialized in the object literal notation. The only way I could "force" TerrainObj.terrain to be populated is to explicity state it as I have done in the code you see. So for some reason, outside of the method, any assignment has been ignored or overriden by the OLN definition above.

I am probably misunderstanding the purpose of "this", but I assumed that since load_terrain is a method of TerrainObj, then invoking this.terrain would indeed reference TerrainObj.terrain.

I am confused, because another method in TerrainObj, generate_display_layer, populates an attribute using "this" without any problems.

Thoughts?

If you're referring to line 93, it's because "this" refers to the context of the $.ajax callback.

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