|
You should be able to access the globals like jQuery just fine, it doesn't really go around clobbering everything because it makes use of dependency injection. Is everything loading properly in the first place? Any logs you can provide, how far is your angular apps execution going?
|
# ? Jun 28, 2013 15:57 |
|
|
# ? May 16, 2024 16:31 |
|
It loads up the page but breaks scope when I try to use geoip because it isn't loaded until after it's referenced, since I have to GET from maxmind. I just now figured that out and loaded it before angular but I'm getting an e401 for some reason. At least the rest of the page loads fine As far as JQuery goes I have no idea, I might not even be using it right now -- I'll have to check. I thought I was.
|
# ? Jun 28, 2013 16:24 |
|
ARACHNOTRON posted:It loads up the page but breaks scope when I try to use geoip because it isn't loaded until after it's referenced, since I have to GET from maxmind. I just now figured that out and loaded it before angular but I'm getting an e401 for some reason. At least the rest of the page loads fine
|
# ? Jun 28, 2013 22:52 |
|
Hi all, I'm new to JavaScript and I want to use it to build a Spotify app. I need to be able to access a database of some kind with my back-end code. All my previous JS experience (such as it is) has been limited to client-side stuff, so I don't know what the best way of going about this is. I know that node.js is designed to be a back-end implementation of JS but this is a small project so it doesn't seem to me that using node is warranted. Or is it? Does anyone have any suggestions about how to go about interfacing JS and a database? Thanks!
|
# ? Jun 30, 2013 01:33 |
|
Wardende posted:Hi all, You don't? I don't see anything beyond "use our js stuff on an html page"?
|
# ? Jun 30, 2013 02:43 |
|
I don't think that there's any restrictions on what JavaScript you can use? I didn't see that in any of their developer docs. If that's the case then I may have to write it using their C API.
|
# ? Jun 30, 2013 03:06 |
|
Wardende posted:Hi all, It sounds like you might just want to use something built on top of node, you might as well if you want to use an entirely js framework. Maybe try Express?
|
# ? Jun 30, 2013 03:26 |
|
Wardende posted:Hi all, Wow, what a coincidence! I worked on the highest ranked Spotify app (TuneWiki) for over a year. I'm sure you know it but anything you build on your back-end code (e.g. in node.js, or Ruby on Rails or Django or something similar) will not be running inside Spotify. You will need to access your back-end server over HTTP from your Spotify app code. Generally speaking you'll want to do something like:
Normally this sort of thing (sending AJAX requests across domains or protocols) is a pain in the rear end, but Spotify allows apps to whitelist hosts which your app is allowed to send cross-domain requests to, which is very nice. Consult their sort-of-lovely documentation or their tutorial app for details. I'm unemployed right now and have tons of free time, so feel free to PM me your email address or a Google Talk username and I'd be happy to help you out ther when I can. My email address and GTalk is tom@crystae.net
|
# ? Jun 30, 2013 07:20 |
|
Oh cool, awesome! I'll definitely be in touch. Thanks so much for offering to help!
|
# ? Jun 30, 2013 18:00 |
|
I'm trying to build a page that's going to dynamically look up systems from a database based on OEM, then power supplies compatible with those systems depending on OEM and type of system. I'm trying to do this with AJAX, but this is my first time using AJAX and I'm having trouble wrapping my head around it. Should I be using jQuery, or can I do it easily enough with vanilla AJAX?
|
# ? Jul 1, 2013 22:25 |
|
ManiacClown posted:I'm trying to build a page that's going to dynamically look up systems from a database based on OEM, then power supplies compatible with those systems depending on OEM and type of system. I'm trying to do this with AJAX, but this is my first time using AJAX and I'm having trouble wrapping my head around it. Should I be using jQuery, or can I do it easily enough with vanilla AJAX? You don't have to use jQuery, but jQuery has done the work of making it so XMLHTTPRequest is called the correct way on the different platforms so you don't need to do the cross-browser support yourself. I think there may be other frameworks may do that plumbing for you as well.
|
# ? Jul 2, 2013 02:53 |
|
I'm having some trouble getting a script to work right, when you first load the page it executes correctly but when you click on the button to regenerate it refuses to work but on my local machine it works just fine. All the script does is make a 1280x720 canvas and draw randomly colored squares in a grid on it. The script canvas.js code:
code:
|
# ? Jul 2, 2013 23:26 |
|
Themage posted:I'm having some trouble getting a script to work right, when you first load the page it executes correctly but when you click on the button to regenerate it refuses to work but on my local machine it works just fine. All the script does is make a 1280x720 canvas and draw randomly colored squares in a grid on it. You realize every time this function is called, your arrays are just getting bigger and bigger, since you never clear them out. Then your drawing code never references anything but the values set the first time. But seeing as how you are just storing numbers that are the same as your loop indexes, you can get rid of the arrays and this function entirely.
|
# ? Jul 3, 2013 05:09 |
|
Themage posted:
I'm going to say that it's the <form> tag. The browser submits the "form" when you click the button. Remove the form tag and it works.
|
# ? Jul 3, 2013 07:15 |
|
Wheany posted:I'm going to say that it's the <form> tag. The browser submits the "form" when you click the button. Remove the form tag and it works. alternatively remove the onclick attribute from the <button> and instead use an onsubmit attribute on the <form> tag (and use evt.preventDefault() where evt is the argument passed to the handler) in this case yeah, just remove the <form> tag. but on a real form if you ever add a click event handler to the submit button instead of adding a handler to the form's submit event you're a bad person
|
# ? Jul 3, 2013 08:29 |
|
Deus Rex posted:in this case yeah, just remove the <form> tag. but on a real form if you ever add a click event handler to the submit button instead of adding a handler to the form's submit event you're a bad person Not just on forms. I think it is a violation of Geneva's convention to use inline javascript event handlers in 2013. Or at least, it should be.
|
# ? Jul 3, 2013 08:51 |
|
Skiant posted:Not just on forms. That's a separate issue and one I'm not totally sure I agree with 100% . In a large application you want to use jQuery or addEventListener (and probably some Backbone-like structure for constructing your views and managing events…), but for small one-off things it's simpler to do it this way. The form submit event — my pet peeve — is an accessibility and usability issue (try using 'Enter' to submit a form that uses a click handler on the submit <button>).
|
# ? Jul 3, 2013 09:42 |
|
Deus Rex posted:That's a separate issue and one I'm not totally sure I agree with 100% . In a large application you want to use jQuery or addEventListener (and probably some Backbone-like structure for constructing your views and managing events…), but for small one-off things it's simpler to do it this way. Fair point. I admit I'm a bit of an extremist when it comes to be super-organized from the ground up even for small projects, because in almost every job or side-project I had so far, there was always a moment where a small one-off became a huge, messy project full of spaghetti and no one wants/has the time to clean it up.
|
# ? Jul 3, 2013 13:16 |
|
Skiant posted:Fair point. I'm contracting on one of these right now. No one wants to be the guy who says to the client, 'we need to stop adding/changing features because we need to pay back technical debt'.
|
# ? Jul 3, 2013 13:27 |
|
Maluco Marinero posted:I'm contracting on one of these right now. No one wants to be the guy who says to the client, 'we need to stop adding/changing features because we need to pay back technical debt'. I 've been that guy for 8 months in a previous job before they let me throw everything away and start fresh (there was literally nothing to salvage in that project). It is a very delicate thing to do. Mostly, it boils down to peacefully presenting facts on how the current code is preventing you from working fast and well. It takes a lot of patience, though. You also need basic people skills in order to avoid going full tantrum when faced with idiocy and incompetence, which will happen more than once if you take that kind of path. Prepare attack points by carefully picking identified issues, and always come up with a solution that provides multiple enhancements. And it looks like I'm going to be that guy again in my new job (started last month). We're working with a set of nodeJS libraries written by one single guy from the team, and that dude is a terrible team player. He can't even be bothered to let us know when he changes something critical in the lib, because according to him, we should not need docs or anything, just read his code.
|
# ? Jul 3, 2013 15:09 |
|
d3.js question. I still suck at selections and telling apart data from datum, and how exactly operating on data arrays (csv, tsv, json) work, but specific to this case, I am struggling with adding data point dots to a chart. Take this multi-series line chart, and this article on adding the "dots" with this code: JavaScript code:
EDIT: I think I found out what breaks - not how to fix it. The values d.name and d.temperature (d.close in the .dot code example) are not defined for the scope of the dot code, so I have write the code to retrieve them myself, from what I can tell. I think it might involve the datum() definition, but I'll take a look and see what I can surmise. ufarn fucked around with this message at 18:25 on Jul 4, 2013 |
# ? Jul 4, 2013 15:04 |
|
I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit. Real world codes here: I have an $http GET request where the Success and Error functions return an object containing some data that I need. I've split this off of my controller since it's not really controller stuff but I need my controller to access that object somehow. I thought maybe if I returned the result of the $http call since I figured it might work exactly like a deferred chain but no, I'm not getting anything back from it. JavaScript code:
|
# ? Jul 4, 2013 17:31 |
|
ARACHNOTRON posted:I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit. JavaScript code:
|
# ? Jul 5, 2013 15:39 |
|
That is certainly an option, and I can't believe I hadn't thought of it. Thanks. It just seems a little anti-MVC to me but I'll mull it over this weekend and probably go ahead with it anyway.
|
# ? Jul 7, 2013 01:13 |
|
ARACHNOTRON posted:That is certainly an option, and I can't believe I hadn't thought of it. Thanks. It just seems a little anti-MVC to me but I'll mull it over this weekend and probably go ahead with it anyway. Not sure how that would be "anti-MVC" as it makes the function very generic, since passing in the function to be called on AJAX return decouples it from any specific "caller" class. If it bothers you, there's other ways to do it via delegation and so on, but I don't see any sort of MVC violation here (although I think primarily of SmallTalk / Cocoa when I think MVC, so we might come from different places there.)
|
# ? Jul 7, 2013 17:16 |
|
Javascript is asynchronous so you can't just return results so you have to use callbacks.
|
# ? Jul 7, 2013 19:04 |
|
Strong Sauce posted:Javascript is asynchronous so you can't just return results so you have to use callbacks. Except you can 'almost' get it like that if you use promise structures, like Angular's stripped down implementation of Q, which are incredibly powerful once you get your head around them. After writing an indexedDB/websql library in them I just love them to bits. They'll make reasoning and passing around asynchronous operations/results so much more flexible and easy to manage without inadvertently creating race conditions
|
# ? Jul 7, 2013 20:34 |
|
Lumpy posted:Not sure how that would be "anti-MVC" as it makes the function very generic, since passing in the function to be called on AJAX return decouples it from any specific "caller" class. If it bothers you, there's other ways to do it via delegation and so on, but I don't see any sort of MVC violation here (although I think primarily of SmallTalk / Cocoa when I think MVC, so we might come from different places there.) It just seemed a little wrong to me to work even a miniscule amount of data manipulation into a controller-class function but I suppose considering that I'm parsing/formatting to send off to other areas and the view it's totally "fine". I'm just scared to stray from extremely strict definitions!!
|
# ? Jul 7, 2013 21:23 |
|
I need a textarea with bold support, so I'm using a div with contenteditable. Unfortunately, I need to manipulate what's being entered. At the moment, I'm starting with thiscode:
My method, therefore, is as follows: 1) On keypress, setTimeout to the tag replace function to allow the element to accept the keypress event. 2) the timeout function gets the cursor position, makes the html changes, and then reinstates the cursor position. However, in this code, the element loses focus afterwards and afaik, the cursor position is ignored. code:
|
# ? Jul 11, 2013 20:13 |
|
ARACHNOTRON posted:I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit. In my own controllers/services, I usually follow a pattern like this: JavaScript code:
|
# ? Jul 11, 2013 23:47 |
|
Got a fairly simple question for you guys. So I'm learning JQuery/Javascript and currently have a piece of code that is responsible for updating the visuals for a list of elements. This is what it looks like: code:
As a said, I'm learning Javascript but am familiar with OOP programming so to me this seems like those function parameters become singletons and are just updated with the latest value that is input. How can I solve this problem?
|
# ? Jul 12, 2013 07:20 |
|
You need to look up what a closure is, and what an IIFE is. Also need to know that Javascript is scoped by function, not by block. Essentially the variable `website` is not scoped within the function of bind.input nor within the function of the deleteLink.click event. Thus when you exit that loop, the value of website is websites[i] where websites[i] is the last element of the array. To fix this you need to wrap those functions within a closure/IIFE to force `website` into the correct scope of those functions. E.g. code:
Strong Sauce fucked around with this message at 08:06 on Jul 12, 2013 |
# ? Jul 12, 2013 08:04 |
|
Strong Sauce posted:You need to look up what a closure is, and what an IIFE is. Also need to know that Javascript is scoped by function, not by block. Thanks for the explanation! I understood closure but didn't realize it was scoped by function instead of the block as you said. I actually managed to fix it by passing the website as a parameter into the bind function: code:
On your example, is the (website) at the bottom a typo and supposed to be part of the comment? code:
Edit: When you say is "scoped by function", you mean the singleton that that function is created as? To me it means it ends up being the equivalent of a static function/class in Java where the website that is mentioned reads from what would be equivalent to static value; is that the case here, or am I wrong to think of functions as objects? dereekb fucked around with this message at 08:37 on Jul 12, 2013 |
# ? Jul 12, 2013 08:23 |
|
dereekb posted:Thanks for the explanation! I understood closure but didn't realize it was scoped by function instead of the block as you said. That is an IIFE: Immediately Invoked Function Expression. You do that so the function you just created gets executed immediately. quote:Edit: When you say is "scoped by function", you mean the singleton that that function is created as? To me it means it ends up being the equivalent of a static function/class in Java where the website that is mentioned reads from what would be equivalent to static value; is that the case here, or am I wrong to think of functions as objects? Javascript is function-scoped, meaning any variables but variables declared get "hoisted" to the top of the function the variable is currently enclosed in. I'm not sure about the 2nd part of your question, but functions are objects in javascript and you can create static members/functions, but there is no classical "class" type in javascript. So what you would do is: code:
Strong Sauce fucked around with this message at 08:59 on Jul 12, 2013 |
# ? Jul 12, 2013 08:40 |
So, it's been a while since I worked on my node project but I just tried to fire it up this morning to no avail. I'm not sure what is going on, it just doesn't run basically. Same problem with meteorite. Meteor works however.Bash code:
|
|
# ? Jul 15, 2013 16:16 |
|
With node aren't you supposed to supply a JS file for it to run against? Ex: node web.js
|
# ? Jul 15, 2013 17:37 |
excidium posted:With node aren't you supposed to supply a JS file for it to run against? Yeah sorry, I was just posting that as an example. It's the same result either way though.
|
|
# ? Jul 15, 2013 18:29 |
|
A MIRACLE posted:Yeah sorry, I was just posting that as an example. It's the same result either way though. i wonder if it's a shell problem does `node --version` work? how about `which node`?
|
# ? Jul 15, 2013 19:52 |
Also what I suspect, but I'm not sure if it's like, a hardlinking issue or some other unixy nonsense that I don't fully understand.Bash code:
|
|
# ? Jul 15, 2013 20:03 |
|
|
# ? May 16, 2024 16:31 |
|
Well that ain't right. Reinstall node maybe? I definitely had packaging issues with node both on ubuntu and osx so they are not uncommon.
|
# ? Jul 15, 2013 20:12 |