|
Jabor posted:Not be default, though many JS frameworks have a convenience function that gives you a random integer in a given range, just because it's so helpful. Hmm, I'm using Coffeescript right now cause it's real similar to Python syntax-wise. Does that count as a framework? I'm also trying to figure out a decent way to do string formatting in Coffeescript, in a manner similar to printf(). I want o use sprintf() for this purpose and tried to include it into the final .js file, but CS doesn't want to compile whenever I try to use it. My initial attempt was coffee -j sprintf.js stdh.coffee stdh.js. Is that not how it should work?
|
# ? Dec 8, 2013 00:38 |
|
|
# ? May 16, 2024 19:13 |
|
You don't need a library for that. Coffeescript has string interpolation: http://coffeescript.org/#strings By the way Coffeescript takes more of it's cues from Ruby than Python, and remember that Javascript is VERY different in terms of behaviour to Python and Ruby. (saying this cause I know you're a beginner, don't let the Coffeescript stop you from learning Javascript itself)
|
# ? Dec 8, 2013 03:41 |
|
Maluco Marinero posted:You don't need a library for that. Coffeescript has string interpolation: http://coffeescript.org/#strings Yeah, I was going to say this. In fact, I think I would say you shouldn't use Coffeescript at all until you have a firm grounding in JS.
|
# ? Dec 8, 2013 04:00 |
|
Jabor posted:Not be default, though many JS frameworks have a convenience function that gives you a random integer in a given range, just because it's so helpful. Or add the method to Array itself by adding to the prototype, so you can just do myArray.randomEl();
|
# ? Dec 8, 2013 15:22 |
|
MDN's Math.random() page has a couple of implementations for "give me a random number between X and Y" - one for floats and one for ints.
|
# ? Dec 9, 2013 16:21 |
|
Crossposting from the wordpress thread: I have a wordpress theme that doesn't recognize that I have the latest version of Jquery. When the code checks for the version it needs - v1.2.3 or higher, it reads my v1.10.2 as "1.1" and gives me an error message. So, even though I have upgraded to the newest version, a bug prevents my theme from recognizing it. This seems to be a well-documented issue and is addressed here: http://wordpress.org/support/topic/...roblem-solution However, I do not have a file name in my theme folder that has the phrase "blockUI" in it, so I don't know where to copy the code contained in http://malsup.github.io/jquery.blockUI.js and apply it to my site. I do have these files: In wp-content/themes/zagetti/js there are: jquery.colorbox-min jquery.easing.1.3 jquery.effects.core jquery.mousewheel.min jquery.ui.totop jquery-1.5.2.min And in wp-content/themes/zagetti/js/ui there is: jquery.effects.core And in themes/zagetti/js/cp/js there is: jquery There are a few others here and there, but that's it for everything in the theme content folder. I don't really know JS, and I cant figure it out. Where do I put this file/code? ZeldaLeft fucked around with this message at 16:31 on Dec 9, 2013 |
# ? Dec 9, 2013 16:28 |
|
ZeldaLeft posted:Crossposting from the wordpress thread: Easy but terrible solution: roll back to jQuery 1.9
|
# ? Dec 9, 2013 20:31 |
Can you not edit the source of wp plugins? Alternate solution: rename your jquery file name
|
|
# ? Dec 9, 2013 20:42 |
|
A MIRACLE posted:Can you not edit the source of wp plugins? Alternate solution: rename your jquery file name Yes, you can, but jquery seems to be integrated into my theme (specifically to to an image slider) and I can't find which files to edit. Which file would I rename? And to what end?
|
# ? Dec 9, 2013 21:15 |
|
Had a pretty good experience setting up and using buster.js today. Any thoughts from you guys? Seems to be that it was very chock full of all sorts of useful features and I didn't have to run around the web picking and choosing critical pieces to make it work.
|
# ? Dec 10, 2013 09:44 |
|
Best practice question:JavaScript code:
|
# ? Dec 10, 2013 16:58 |
|
Personally, I would use this.bar() instead of foo.bar() there, but that would change the semantics if you call baz with another object as this. Of course, as is, the behavior will change if the value of foo changes at any time.
|
# ? Dec 10, 2013 22:30 |
|
I found this line of code in a blockui.js file in my theme: */ ;(function($) { if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) { alert('blockUI requires jQuery v1.2.3 or later! You are using v' + $.fn.jquery); I assume this is the bit of code that checks to see if im running something above v1.2.3 but doesn't see v1.10.2 as a valid option. how can I change this so it recognizes (or at least skips by) things properly?
|
# ? Dec 10, 2013 23:31 |
|
add // before the alert alternatively, change the conditional from if (x || y) to if (false && (x || y)) which will make it never fire
|
# ? Dec 10, 2013 23:41 |
|
changing it to this didn't change my error message: */;(function($) {if (false && (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.0/.test($.fn.jquery))) {alert('blockUI requires jQuery v1.2.3 or later! You are using v' + $.fn.jquery); and neither did this: */;(function($) {if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.0/.test($.fn.jquery)) //{alert('blockUI requires jQuery v1.2.3 or later! You are using v' + $.fn.jquery); Did I do them both wrong?
|
# ? Dec 11, 2013 00:08 |
|
ZeldaLeft posted:changing it to this didn't change my error message: Is your browser caching the js maybe?
|
# ? Dec 11, 2013 00:12 |
|
ZeldaLeft posted:changing it to this didn't change my error message: The first one should work properly, try erasing your cache and/or ensure that the message is coming from that exact line and not another one.
|
# ? Dec 11, 2013 00:15 |
|
kedo posted:Best practice question: Based on how you've written your question I'm not sure you know what is going on here. You aren't setting the values to anything other than functions, which happen to reference other functions in the object. The value of baz() will be determined when it's called, not when you declare foo. Of course it's fine for an object to reference parts of itself in it's functions, although as pointed out you might want to use "this" instead of "foo" in the function body. Are you trying to ask about something like this: JavaScript code:
JavaScript code:
|
# ? Dec 11, 2013 01:12 |
|
it was the cache. Thank you so much!!
|
# ? Dec 11, 2013 01:28 |
|
HappyHippo posted:Based on how you've written your question I'm not sure you know what is going on here. You're more right than you know - I'm more or less self taught and do not come from a programming background, so I know enough to make things work, but I don't always completely understand the underlying reasons why they work or whether or not I'm doing something the right way. Thus my attempt to learn. HappyHippo posted:Of course it's fine for an object to reference parts of itself in it's functions, although as pointed out you might want to use "this" instead of "foo" in the function body. This is really what I was trying to get at. To elaborate a bit to make this a bit less abstract: in the real world my object is just gathering information about a DOM element a user clicked. bar is checking whether the item is main or sub-navigation, and then baz is performing additional logic based on the results. All the information is being gathered at once and I'm not modifying anything in foo after the fact, so I suppose in this case it doesn't really matter if I use "bar" or "this" since they're both going to return the same thing? I've only just working objects into my code, so I'm still wrapping my brain around 'em to a certain extent.
|
# ? Dec 11, 2013 02:22 |
|
Just to be clear, are you trying to collect this information and then store the results in the object foo, or are you trying to attach functions to the object to do the collecting?
|
# ? Dec 11, 2013 03:16 |
|
HappyHippo posted:Just to be clear, are you trying to collect this information and then store the results in the object foo, or are you trying to attach functions to the object to do the collecting? The former. Here's a simplified chunk of the actual code, it's part of a URL hashing function. clicked gathering information about what a user clicked, and later I use the values it returns to construct the actual hash. JavaScript code:
kedo fucked around with this message at 15:41 on Dec 11, 2013 |
# ? Dec 11, 2013 15:35 |
|
kedo posted:The former. Here's a simplified chunk of the actual code, it's part of a URL hashing function. clicked gathering information about what a user clicked, and later I use the values it returns to construct the actual hash. I would not do it like that if I wasn't using clicked.parentType() anywhere else in the setMenuHash object. You are currently doing the same check twice. I wouldn't have the clicked object at all in your current code sample. I'd just set window.location.hash with if statements. I generally use JavaScript objects like your clicked object for encapsulation and code re-use, which doesn't appear in your code sample. There are like a million ways to do what you are doing and it all depends on your style. The most important thing is that it works and that you (and your coworkers?) can read and maintain it.
|
# ? Dec 11, 2013 17:21 |
|
Reality posted:I generally use JavaScript objects like your clicked object for encapsulation and code re-use, which doesn't appear in your code sample. Thanks, this is valuable. I'm reusing clicked.parentType() and the entire object itself a couple of times, but probably not enough to justify it. Your second point is really the main reason why I did this all with an object in the first place – I'm handing off a lot of code these days and I want to make sure I'm doing things in a way that make sense to a third party even if it's not the most perfect and beautiful code in the world. Seems that in this case I might have been over thinking it. Thanks again!
|
# ? Dec 11, 2013 17:40 |
|
I've got a node.js app that I want to print from... specifically I want to print an svg image that I have generated to a label printer. I don't know what label printer yet, and I don't know exactly what hardware, but I'm trying to think through the best way to do this. It's kiosky, so the printer could be connected to the backend server or the actual device the app is displayed on. I'm thinking it will be something like a microsoft surface tablet. What I don't want is a 'print options' dialog popping up. I just want a label to spit out when someone presses a button on the page. I'll have complete control over the tablet, so the app can be in the trusted sites list, a particular browser can be forced, that sort of thing. Can this be done with some simple javascript or will I need to look at writing a browser addin or separate app to talk to?
|
# ? Dec 11, 2013 20:11 |
|
I have a comment in the last line of one of my scripts that helps Chrome not be useless for debugging it when it's loaded dynamically (downloaded and exec'd, basically):JavaScript code:
Edit: I think it only happens when the script is included on a page with a doctype that triggers compatibility mode. Maybe. Need to look into it more. Munkeymon fucked around with this message at 21:09 on Dec 11, 2013 |
# ? Dec 11, 2013 20:54 |
|
kedo posted:The former. Here's a simplified chunk of the actual code, it's part of a URL hashing function. clicked gathering information about what a user clicked, and later I use the values it returns to construct the actual hash. Ok, so I apologize if you are already aware of this, but these "values" (parentType and hashValue) aren't values, they're functions you're attaching to the object "clicked". Neither is evaluated until the line "window.location.hash = clicked.hashValue();". I don't see the point of attaching functions to a private object to be used in the setMenuHash function; just declare them as private functions and call them as needed. If it was your intention to evaluate those values you need to understand the difference between these two lines: code:
code:
code:
|
# ? Dec 12, 2013 04:17 |
|
bobua posted:I've got a node.js app that I want to print from... specifically I want to print an svg image that I have generated to a label printer. I don't know what label printer yet, and I don't know exactly what hardware, but I'm trying to think through the best way to do this. It's not possible using JS (It'd be pretty lame if a website could take over your printer) but apparently you can do it with VBScript of all things. Of course It'd only work in IE and I've no idea if it would work on a surface, but it might be worth a try: code:
Another option would be to hook the printer to the server running node and expose an API to allow the clients to print. I've never attempted to print from a node app but it's gotta be possible, do some searching on npm and maybe you'll get lucky! Otherwise I'd say your best bet would be to find a CLI print tool and call it as a child process.
|
# ? Dec 12, 2013 06:04 |
|
HappyHippo posted:Ok, so I apologize if you are already aware of this, but these "values" (parentType and hashValue) aren't values, they're functions you're attaching to the object "clicked". Please don't apologize! Again, this is all really valuable. Yes I'm aware that they're functions not values (this is another byproduct of not coming from a programming background... I never use the right terminology for stuff), but I think for my purposes doing it one way or the other doesn't really change the final result. However I guess if I wanted to improve my existing function I could use hashValue: (function() { ... })() (what's the correct term for this?) everywhere instead of what I'm doing now which would limit the number of times I touch the DOM and prevent nearly every private function from being run multiple times. If I'm gathering information about a DOM element every time the function is run, and that information is always going to remain the same, there's no reason to grab it multiple times. Which now seems like a big "duh." I should probably take a Javascript class. Thanks again, you've been incredibly helpful!
|
# ? Dec 12, 2013 15:47 |
|
kedo posted:Please don't apologize! Again, this is all really valuable. Yes I'm aware that they're functions not values (this is another byproduct of not coming from a programming background... I never use the right terminology for stuff), but I think for my purposes doing it one way or the other doesn't really change the final result. Not sure if that construction has a name or not, it just follows from javascript's syntax. The stuff in brackets declares an anonymous function and then the () calls it right there. There are good reasons to do that but I don't think they apply here. Resist the urge to get fancy, you can just declare clicked and then add the parentType and hashValue values directly, no functions needed.
|
# ? Dec 12, 2013 23:36 |
|
HappyHippo posted:Not sure if that construction has a name or not, it just follows from javascript's syntax. The stuff in brackets declares an anonymous function and then the () calls it right there. I like immediately-invoked function expression.
|
# ? Dec 12, 2013 23:48 |
|
I'm using Processing.js to implement Conway's Game of Life, and I'm trying to draw equally sized rectangles at each corner of the canvas to get a hand of PJ. For some reason, though, the rectangles are clearly different sizes, even though my logic is (afaik) correct. Can someone check my work? http://jsfiddle.net/ydLKN/38/ edit: Also I'm realizing that my method of creating a 2D array is hosed. What's the best way to do that? Pollyanna fucked around with this message at 01:40 on Dec 13, 2013 |
# ? Dec 13, 2013 00:54 |
|
Pollyanna posted:I'm using Processing.js to implement Conway's Game of Life, and I'm trying to draw equally sized rectangles at each corner of the canvas to get a hand of PJ. For some reason, though, the rectangles are clearly different sizes, even though my logic is (afaik) correct. Can someone check my work? change this code:
code:
Like, the lower right box is going out of the margins it seems. Couldn't say why though.
|
# ? Dec 13, 2013 01:41 |
Even just a -1 will do it, not sure what the deal is there. http://jsfiddle.net/HdL8W/ * removed the 400x400 attributes on the canvas since they were confusing * added a border to the canvas so we can position the rectangle a little easier * put a space between new & Array instead of newArray to get rid of javascript error edit: oh probably because the pixels are 0 indexed so a size of 250x250 gives you pixels 0 to 249 to work with so you want it to be (244, 244) to (249, 249) for the bottom right rectangle fletcher fucked around with this message at 01:48 on Dec 13, 2013 |
|
# ? Dec 13, 2013 01:45 |
|
Tres Burritos posted:change this That is really weird, cause the canvas is 200x200, and the lower right rectangle is spawned at (195, 195) and is 5x5, so it shouldn't be running off the canvas because it's within the boundaries. This implies that the canvas doesn't want to draw past (195, 195) which makes no sense I updated the JSFiddle, by the way. fletcher posted:Even just a -1 will do it, not sure what the deal is there. That makes sense. So it should be processing.rect((processingWidth - tileSize - 1), (processingHeight - tileSize - 1), tileSize, tileSize); then, correct? (thanks for changing the JSFiddle around btw) edit 2: I added some logic to the script for checking the neighbors of a cell and determining if the cell will live or die in the next round. However, I keep getting "Uncaught TypeError: Cannot read property '-1' of undefined" in the console. Can someone check my logic and see if it's right? http://jsfiddle.net/ydLKN/47/ Pollyanna fucked around with this message at 02:45 on Dec 13, 2013 |
# ? Dec 13, 2013 01:46 |
|
Pollyanna posted:edit 2: I added some logic to the script for checking the neighbors of a cell and determining if the cell will live or die in the next round. However, I keep getting "Uncaught TypeError: Cannot read property '-1' of undefined" in the console. Can someone check my logic and see if it's right? Most cells have neighbors on 8 sides, but if the cell is on the edge of the canvas then it might only have 5 or 3 neighbors. Where you declare cellNeighbors you do a lot of [x -1] and [y +1] but x could be zero and y could be the top of the array.
|
# ? Dec 13, 2013 20:28 |
|
Gism0 posted:It's not possible using JS (It'd be pretty lame if a website could take over your printer) but apparently you can do it with VBScript of all things. Of course It'd only work in IE and I've no idea if it would work on a surface, but it might be worth a try: Yeah, knew about the security issue, was just really hoping having complete control of the browser would mitigate that. Guess not. Really sucks, I'm shocked with all the web apps that printing like this hasn't been squared away. Thanks though.
|
# ? Dec 13, 2013 22:00 |
|
bobua posted:was just really hoping having complete control of the browser would mitigate that. Guess not. Having complete control of the browser does mitigate the problem, because you can always write and install a browser addin to allow printing to be scripted. Having complete control of the browser means literally nothing if you're only talking about Javascript running on a webpage. The complete control part comes in all the stuff you can do outside the webpage's own sandbox. See also Chrome's "--kiosk" and "--kiosk-printing" command line arguments. See here for more info. biznatchio fucked around with this message at 01:13 on Dec 15, 2013 |
# ? Dec 15, 2013 01:09 |
|
bobua posted:Yeah, knew about the security issue, was just really hoping having complete control of the browser would mitigate that. Guess not. The term 'web app' is a marketing thing - web applications are not first class citizens. It's very easy for desktop applications to do stuff like drag and drop between applications, print, save files to the hard drive, have keyboard shortcuts and accelerators and menu bars and floating toolbars, and a whole host of other poo poo that people take for granted in the desktop world that doesn't translate to the web/mobile experience. The worst thing your marketing team can do is look at an existing desktop application and go "Take this and make it be a webapp." That's why all that activex/client side java poo poo got super popular back in they day - people would just write lovely activex controls and voila, "webapp." There has been some progress in providing richer web/mobile platforms, but the progress has been made primarily in understanding the target platforms better, keeping it simple, and not trying to recreate the desktop experience.
|
# ? Dec 15, 2013 03:14 |
|
|
# ? May 16, 2024 19:13 |
|
biznatchio posted:
I was literally going to order a retarded network label printer for way too much money and set about doing all this on the back end and blah blah blah. Cannot believe this didn't show up when googling for a solution. Thank you. If you would like a forums upgrade or t-shirt with a sloth on it, pm me.
|
# ? Dec 16, 2013 21:31 |