|
TildeATH posted:Dots after always makes more sense, but it looks so wrong because nobody does it. It looks wrong because it is wrong.
|
# ? Feb 26, 2014 23:16 |
|
|
# ? Jun 3, 2024 23:03 |
Peanut and the Gang posted:It looks wrong because it is wrong. I agree but I do it the other way because my IDE / vim auto indents for me with trailing periods!
|
|
# ? Feb 26, 2014 23:26 |
|
Helado posted:Thinking about it more today, I misspoke about the 3rd case above where you call: I hadn't checked the structure before, but you're right: it generates a bunch of ps outside the body. That .data() applies to an element's parent is kinda hosed up but at least the order of operations in the examples is a little clearer.
|
# ? Feb 27, 2014 00:20 |
|
Munkeymon posted:I hadn't checked the structure before, but you're right: it generates a bunch of ps outside the body. That .data() applies to an element's parent is kinda hosed up but at least the order of operations in the examples is a little clearer. It's not so much that data applies to the parent as how the object that enter() returns is defined. This part is kind of goofy, but you can think of data() returning an array of all of the element/data pairs that contain both valid data and a valid element. https://github.com/mbostock/d3/wiki/Selections#wiki-enter posted:Another way to think about the entering placeholder nodes is that they are pointers to the parent node (in this example, the document body); however, they only support append and insert. So the goofy part is that when data() creates new elements in the array they are these 'placeholder nodes' that point to the parent node. When you call enter() you are getting just these placeholder nodes. Similarly when exit() is called, it returns all of the existing nodes which are now not required. I was going to say about how it is one big array, but the thing is that it seems it keeps the currently defined elements separate from the enter() and exit() lists. If you call para.append('hr') in the above example before calling enter(), you get a hr within each existing p. I half expected an extra one to get appended, but this makes more sense in that the order of your enter()/update/exit() won't be as important. So you can think of any action you call on data() is going to be on the valid entries. enter() is the entries with valid data, but not a valid element. And exit() is those without valid data, but they have a valid element. http://jsfiddle.net/LZsfP/5/ edit: And the reason why I think the placeholder nodes point to the parent is to re-use the existing append function while also preserving hierarchy within selections.
|
# ? Feb 27, 2014 02:23 |
|
Munkeymon posted:I hadn't checked the structure before, but you're right: it generates a bunch of ps outside the body. That .data() applies to an element's parent is kinda hosed up but at least the order of operations in the examples is a little clearer. .data() doesn't apply to the parent, it applies to the selection. Your selection in your example is the body, to which you append a data array of 7 elements, and then you use the .enter() function to say "For each data array object for which there is not already a DOM element in my selection, do the following" which you state is to append a <p>. Your selection, though, is on the <body> element, so the <p> is appended to that selection, which exists at the same level in the DOM. Selections are a bit difficult to get your head around. Like Helado says, they're actually an object that consists of a dataset paired with a set of elements and when there's more of one or the other, then it fires the exit() or enter() behaviors that you've defined. Often, a selection starts out as an empty set of all the <p> elements in a <div> (when you know there are no <p> elements in that <div>) to which you bind data with .data() after which you tell it enter().append('p') so it creates a new <p> for each data object.
|
# ? Feb 27, 2014 06:47 |
|
To force myself to finally give in and learn JS, I'm making a small web app with MVC3 and javascript/jquery/knockout on the frontend and I'm completely stumped now.code:
The code works fine for now and it puts all the order names in an accordion, but the orders array has an Id property as well, and I was wondering how I could get the value of the order.Id and use it to call a function that creates another observableArray that I want to use in a inner-accordion. The function is already there and works, I just don't know how to get the Id value edit: well, that's what you get for staring at the same problem for too long.. I somehow decided to forget how I got the array to the html in the first place.. Howmuch fucked around with this message at 13:02 on Feb 28, 2014 |
# ? Feb 28, 2014 10:46 |
|
So I decided to get fancy and created this monstrosity:code:
What happens in practice is that as soon as it hits a "y" value, it breaks, which makes sense given that it's a switch statement. I'm at a brick wall here. How can I loop through an array an alert for each specific index of "y"? jsfiddle here: http://jsfiddle.net/bhuHe/2/ Raskolnikov2089 fucked around with this message at 23:45 on Mar 5, 2014 |
# ? Mar 5, 2014 23:42 |
|
Raskolnikov2089 posted:jsfiddle here: http://jsfiddle.net/bhuHe/2/ You're making it too hard. code:
If you wanted it to work the way you have it set up you would have to convert each case and the switch value to a string. code:
excidium fucked around with this message at 00:10 on Mar 6, 2014 |
# ? Mar 6, 2014 00:02 |
q1 being in array index 0 is confusing. What do you plan on doing with radioArray after this?code:
|
|
# ? Mar 6, 2014 00:10 |
|
fletcher posted:q1 being in array index 0 is confusing. What do you plan on doing with radioArray after this? The alerts were added for debugging. My end goal is to populate a new <div> with additional information triggered for each index with a "y" value. The array with a for loop seemed the easiest way to store then cycle through the "y" values, but I'm open to other suggestions. Also I wanted to try out arrays since I'm still pretty new to javascript. code:
Raskolnikov2089 fucked around with this message at 00:33 on Mar 6, 2014 |
# ? Mar 6, 2014 00:29 |
Right on. The alerts can be handy for debugging. Are you familiar with the developer tools that are built into modern browsers? (hit f12!) I like to use console.log('hi there') and console.dir(myObject) when debugging things, it can be a little less annoying than the alerts. If you do need the array, I would suggest with going with something like this: code:
|
|
# ? Mar 6, 2014 00:47 |
|
fletcher posted:.serializeArray(); Thank you for that, that's a much more elegant way to create an array than I was going about it. I think I'm at the point where I know enough to create things, but not a way to do it efficiently. This is surprisingly fun. Maybe I missed my calling. excidium posted:If you wanted it to work the way you have it set up you would have to convert each case and the switch value to a string. This finally clicked this morning. What I ended up with was: code:
JSfiddle for reference :http://jsfiddle.net/bhuHe/18/ Raskolnikov2089 fucked around with this message at 19:59 on Mar 6, 2014 |
# ? Mar 6, 2014 19:56 |
|
I am attempting to create some functionality which will get and set the document of an iframe. I have been unsuccessful at performing this with jquery... code:
Scenario: 1. Page loads, iframe a & b are rendered 2. User navigates inside iframe A to different pages **below this is functionality I cannot figure out 3. User clicks button to take DOM from iframe a and replace the DOM for Iframe b This will essentially set the content of iframe b to be where the user had navigated in iframe a
|
# ? Mar 6, 2014 20:00 |
|
Can you describe why you would want to do this? Why not continue navigating in frame A?
|
# ? Mar 6, 2014 21:47 |
|
excidium posted:Can you describe why you would want to do this? Why not continue navigating in frame A? Thanks for the reply. I am integrating an application into another application within an iframe. That iframe resides on a "tab" within the parrent application. When that "tab" is navigated away from and then back to the iframe reloads. So I need to some how keep the content of the iframe stored somewhere. I was thinking if I could just switch the DOM of a hidden iframe back and forth this would work. Let me know if that doesnt make sense.. DholmbladRU fucked around with this message at 21:54 on Mar 6, 2014 |
# ? Mar 6, 2014 21:52 |
|
Raskolnikov2089 posted:Thank you for that, that's a much more elegant way to create an array than I was going about it. I think I'm at the point where I know enough to create things, but not a way to do it efficiently. This is surprisingly fun. Maybe I missed my calling. There is no need to do a switch/case statement. You already know radioArray[i] is "y" so you just push ("radioArray" + i) into contentArray instead of doing switch/case. Also you should take care to use a code editor that will help you indent and clean your code Also you can do a lot of this implementing list comprehensions provided by the Array class. They are available unless you need to support older versions of browsers. Edit: Also you have an off by one error (should be x < arrLength, i < radioA, not <=)
|
# ? Mar 6, 2014 22:04 |
|
Raskolnikov2089 posted:So I decided to get fancy and created this monstrosity: Wow, wayyyyy too complex. I could make this a one-liner or close to it, but I made it a little longer for your comprehension. jsfiddle JavaScript code:
_areaman fucked around with this message at 01:54 on Mar 7, 2014 |
# ? Mar 7, 2014 01:36 |
btw in your code tags if you write code=<language> it syntax highlights stuff
|
|
# ? Mar 7, 2014 01:44 |
|
Dolex posted:You could recreate highcharts with D3. Anyway, that's why I just looked for and found this thread. If a d3 thread starts, great, but yeah ultimately I'm just going to have to learn javascript and DOM and (sounds like) SVG so might as well hang out here, too.
|
# ? Mar 11, 2014 20:28 |
|
Since I don't see it anywhere near the OP (and that's 5 years old anyway), would anyone be able to reccomend a good book/online learning resource for picking up javascript? I've gone through the codeacademy lessons for js and jquery, but it doesn't seem they've gotten me anywhere near close to starting on even small mess-about apps. Just looking for anything decent that can give me a good foundation. I'm planning on getting a good grip on javascript, before maybe messing about with coffeescript and some of the more commonly used frameworks. Maybe figure out some of the game creation libraries/frameworks before the next ludum dare comes around. Don't feel the need to point out the advantages of these unless it's really worth knowing before jumping in. Like I said, I'm definitely looking to get a good grip on base js before starting on any of these extras, unless a different approach is recommended nowadays? sharktamer fucked around with this message at 22:25 on Mar 12, 2014 |
# ? Mar 12, 2014 22:22 |
|
sharktamer posted:Since I don't see it anywhere near the OP (and that's 5 years old anyway), would anyone be able to reccomend a good book/online learning resource for picking up javascript? I've gone through the codeacademy lessons for js and jquery, but it doesn't seem they've gotten me anywhere near close to starting on even small mess-about apps. Just looking for anything decent that can give me a good foundation. I unreservedly recommend http://effectivejs.com/ -- Dave is a great writer, understands JS as deeply as any human alive, is a great teacher, and has a lot of experience teaching and working with a variety of languages. I worked on JS engines (including with Dave) for many years, and recommend this to everyone. Fake edit: the book, I mean. I don't necessarily recommend working on JS engines.
|
# ? Mar 13, 2014 01:29 |
|
Subjunctive posted:I unreservedly recommend http://effectivejs.com/ -- Dave is a great writer, understands JS as deeply as any human alive, is a great teacher, and has a lot of experience teaching and working with a variety of languages. I worked on JS engines (including with Dave) for many years, and recommend this to everyone. This book is definitely not for beginners. The book assumes you already know JavaScript. For a beginners resource that is available online try eloquentjavascript. Search that online since I am on my phone and can't provide the link
|
# ? Mar 16, 2014 17:54 |
Strong Sauce posted:This book is definitely not for beginners. The book assumes you already know JavaScript. http://eloquentjavascript.net/chapter1.html It is an awesome resource quote:There are those who will say terrible things about JavaScript. Many of these things are true. When I was for the first time required to write something in JavaScript, I quickly came to despise the language. It would accept almost anything I typed, but interpret it in a way that was completely different from what I meant. This had a lot to do with the fact that I did not have a clue what I was doing, but there is also a real issue here: JavaScript is ridiculously liberal in what it allows. The idea behind this design was that it would make programming in JavaScript easier for beginners. In actuality, it mostly makes finding problems in your programs harder, because the system will not point them out to you.
|
|
# ? Mar 16, 2014 18:11 |
|
Strong Sauce posted:This book is definitely not for beginners. The book assumes you already know JavaScript. My recollection is that it starts pretty basic, but I don't have my copy to hand. Eloquent is also great, definitely.
|
# ? Mar 16, 2014 19:12 |
|
Thanks for the suggestions everyone. I'll read both, eloquent first.
|
# ? Mar 16, 2014 19:51 |
|
sharktamer posted:Thanks for the suggestions everyone. I'll read both, eloquent first. Since you're a beginner, you should immediately get into the habit of using a linter. If nothing has changed in the last year, JSHint is probably the best best there. JSLint is also very good, but extremely opinionated about the structure and formatting of your code. Also use console.log() instead of alert() for debug messages. And learning to use breakpoints, watches and the console is really useful for debugging. Place a breakpoint and use watches or the console to observe a variable, or use the console to even change a variable's value on-the-fly.
|
# ? Mar 16, 2014 21:37 |
Wheany posted:Since you're a beginner, you should immediately get into the habit of using a linter. If nothing has changed in the last year, JSHint is probably the best best there. JSLint is also very good, but extremely opinionated about the structure and formatting of your code. If you're up to using an IDE (trust me, as a sublime text convert, it's not that bad) check out WebStorm (or any of their other products if you're doing cross-language development like PHPStorm, etc) http://www.jetbrains.com/webstorm/ Full support out of the box for linters and stuff.
|
|
# ? Mar 16, 2014 21:52 |
|
code:
This is a problem because it means the js on that page doesn't work properly and it reloads the page before it gets a chance to do the work it needs to do
|
# ? Mar 17, 2014 00:09 |
|
You're executing the function and then passing the result to settimeout. Try: code:
|
# ? Mar 17, 2014 00:12 |
|
Peanut and the Gang posted:You're executing the function and then passing the result to settimeout. Hmm thanks, it still just seems to blow through it without stopping in either case. The only reason why I think this is even necessary is that on any random time I try to use the button that the js is for, it will sometimes work, but other times it requires me to manually refresh the page to see the changes I might be looking in the wrong place for the problem but I dont think so
|
# ? Mar 17, 2014 00:34 |
|
Oh, you're getting owned by the async nature of javascript. Taste the ~({[OWNAGE]})~ What you need to do is put the reload() inside of the $.get callback, like this: code:
|
# ? Mar 17, 2014 00:44 |
|
Thank you! That works and makes sense. Well your explanation makes sense, but that seems really annoying. I have had to use only little bits of Javascript in the past week and it has been a nightmare most of the time
|
# ? Mar 17, 2014 00:54 |
|
code:
My Django View mandates that when Page B receives a POST it is meant to add some data to the database and then render Page B template. When I perform an action (search) on Page B, it POSTS itself, and then displays the search results. What I am trying to do is, activate this script from Page A, and POST data to Page B, and then have Page B display the results like normal. What happens though is that the POST is successful (I can see data being added to the database) but it wont render Page B with the search results and just comes up a blank page. I am REALLY not sure if this is a JS problem this time though - am I being owned by the asynchronous nature again or does this JS just not make sense to begin with?
|
# ? Mar 17, 2014 01:25 |
|
I need some help. I'm trying to write a function that will validate the input in a text box with a phone number upon invoking the onblur function of said text box. For some reason I can't get it to work and I have no idea what I'm doing wrong. The code for the page in question Any advice or solutions that can be offered will be greatly appreciated.
|
# ? Mar 17, 2014 04:16 |
|
Valeyard posted:Thank you! That works and makes sense. Well your explanation makes sense, but that seems really annoying. I have had to use only little bits of Javascript in the past week and it has been a nightmare most of the time You'll get used to it when you do more javascript. Traditionally everything is asynchronous and you pass around a bunch of callbacks and your code starts getting shaped into an arrow with more and more callbacks inside callbacks. There are ways of "flattening" the code, but I'm not going to go into them. Valeyard posted:
Is "Page B" "properurl" in above code? If it is, i think your page gets rendered as it should, but it is returned inside that "data" variable in your callback. Try adding a console.log(data) inside that function, possibly putting a breakpoint there, so you can examine the result. So: JavaScript code:
Firebug: Firefox native: Chrome IE: (old) Opera Dragonfly Just open a debugger of your choice (Press F12 in Chrome, IE or Firefox, Ctrl-shift-I in Opera 12), open the scripts/sources tab in the debugger and click on the row number of the row where you want to add a breakpoint. Next time the code execution reaches that point, it will halt and you can inspect the state of the variables in real time, just by hovering over them in the code window, adding watches, or by writing the variable's name in the console and pressing enter.
|
# ? Mar 17, 2014 10:15 |
|
IronSaber posted:I need some help. I'm trying to write a function that will validate the input in a text box with a phone number upon invoking the onblur function of said text box. For some reason I can't get it to work and I have no idea what I'm doing wrong. Line 85: code:
Line 80: code:
code:
|
# ? Mar 17, 2014 10:34 |
|
fakemirage posted:Line 85: And this is one reason why you use a linter.
|
# ? Mar 17, 2014 11:09 |
|
Wheany posted:You'll get used to it when you do more javascript. Traditionally everything is asynchronous and you pass around a bunch of callbacks and your code starts getting shaped into an arrow with more and more callbacks inside callbacks. There are ways of "flattening" the code, but I'm not going to go into them. Hey thanks for this detailed reply. Page B is indeed "properurl". I just checked out "data" using a breakpoint and I can see that the html contained within is actually what I want to see, so I think you are right about it being returned inside "data". I am looking at the documentation for the jquery post function and I can't see what I should do different. I tried adding a line code:
|
# ? Mar 17, 2014 13:57 |
|
Valeyard posted:Hey thanks for this detailed reply. Page B is indeed "properurl". I just checked out "data" using a breakpoint and I can see that the html contained within is actually what I want to see, so I think you are right about it being returned inside "data". Is the data returned from page B a complete html file, or just a fragment? $("#result").html(data); sets the innerHTML of the element whose id is "result" to the html that is returned, so that might not work if it's a complete page and not just a fragment. You do have some html element on the page with id="result", right?
|
# ? Mar 17, 2014 14:21 |
|
|
# ? Jun 3, 2024 23:03 |
|
Wheany posted:Is the data returned from page B a complete html file, or just a fragment? $("#result").html(data); sets the innerHTML of the element whose id is "result" to the html that is returned, so that might not work if it's a complete page and not just a fragment. If he wants it to show the response page, the easiest thing might be to create a hidden form and then just submit it. The browser takes over and there's no more asynchrony to futz with.
|
# ? Mar 17, 2014 15:22 |