ECMAScript (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms and stand-alone interpreters / JIT engines. Use this tag for questions regarding ECMAScript 5 and its dialects / implementations: JavaScript, JScript, etc., excluding ...
2
votes
1answer
41 views
Underscore and general app design review
I'm working on my larger project to date, and on top of that I'm using underscore for the first time.
All is working perfectly but I'd like some criticism on the use of underscore templating and ...
1
vote
1answer
27 views
JQuery Dynamic Dropdown Update
This is based (somewhat loosely) on the code written in this railscast. I'm planning to re-use it in different places throughout the site, so I made it a bit more generic rather than based on IDs. ...
0
votes
0answers
7 views
Javascript Generic Components with Kineticjs shapes
I am planning to create an application to create software mockups. It will have some different elements but with similar behavior (like windows, buttons, menubars, etc), so I am planning to use the ...
3
votes
1answer
43 views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
[ "a", "b", "c" ]
Current approach:
var ...
0
votes
0answers
12 views
My second attempt at canvas spatial grid collision? Did I get it?
After posting my first question and my first attempt which you can see here,
My first attempt at canvas spatial grid collision? Please be honest!
I have re-written it to try and implement what the ...
2
votes
2answers
46 views
Form Validation (JQuery)
I made a simple form validation. It's working alright. The thing is I want my code to be optimized. Can somebody show me some pointers to improve my code? Thanks in advance.
...
2
votes
1answer
31 views
Add event listener when window loads
I've been using this code for quite some time, but am wondering if there's any improvements I can make to it. Basically it's just code that runs when the page loads or if the code is run after page ...
0
votes
0answers
9 views
Render arbitrary jade in express
We've got a "catch-all" in app.js that renders a .jade file if it exists:
app.get('*', routes.render);
index.js
render: function(req, res) {
fs.exists('views' + req.url + '.jade', ...
3
votes
1answer
56 views
My first attempt at canvas spatial grid collision? Please be honest!
The code,
$(document).ready(function() {
window.addEventListener('keydown', keyPress, true); // event listener for keyboard presses
function keyPress(evt) {
if(engine.activeBlock) { // block is ...
-1
votes
0answers
12 views
Stripchart using raphael.js in IE8 [closed]
I'm using Raphael.js to help in creating a Stripchart, but unfortunately it's not displaying the actual data in IE8. The grid for the chart is displaying but that's about it. Does anything in the code ...
3
votes
1answer
57 views
If statement, is the shortened version readable enough?
I have to perform an IF statement in my Javascript code. I utilised the first method shown below:
(someVar1 !== "someString") && (someVar2[i].disabled = (someVar3.find("." + someVar4).length ...
2
votes
2answers
29 views
Passing Context in CoffeeScript
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
var async = ...
0
votes
2answers
77 views
Elegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”
I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing ...
1
vote
0answers
36 views
Javascript inheritance selfmade or reinventing wheel
Background
I like to code javascript in a typical style with "classes" and inheritance. My goal was to create an easy way to make inheritance available and keep classes that inherits from others ...
-4
votes
1answer
20 views
Regex to change uri file name [closed]
Looking for regex to change file name in uri to allow linking to answer sheet from question bank.
...
4
votes
1answer
40 views
Is there a better way to write my jQuery slider?
First question here so please be gentle. I have developed a jQuery slider and I want to implement it in WordPress (it will be a Featured posts slider).
This is my slider logic:
If there are 1 or 3 ...
0
votes
2answers
28 views
Name-spaced JavaScript wrapped in self executing function
Is there any point in wrapping this code in the self executing function declaring window and undefined? I've read that it improves performance etc... (NOTE I will be making use of the window at some ...
0
votes
1answer
51 views
Can this iterating javascript code be optimized?
Say I have this type of code I'd like to execute. There's some data encapsulated around a big Javascript object containing methods & properties that I'd like to extract based on comparing some ...
2
votes
2answers
52 views
Parse and Redirect to uri in Javascript
Example that could be turned into a button to view user's public ftp where initial page is "http://user.school.edu/":
javascript:(function( {
var h,i,t;
...
3
votes
1answer
63 views
Optimize jQuery Iteration
I have a list of elements (well, nested lists of elements, really) that the user can reorder (using jQuery sortable()). A simplified view of the structure is something like:
<div ...
1
vote
0answers
36 views
JQuery Drag Div Code Simplification
My code allows for the user to move a div around a container div by clicking and dragging the top, much like a window on a desktop. It does this by waiting for mousedown then mousemove, getting ...
2
votes
1answer
62 views
Can I use jQuery's .when() to make this code DRY?
I'm trying to run a bit of code when my loginManager is logged in. It might be already, or I might be waiting:
var loginManager = chrome.extension.getBackgroundPage().LoginManager;
// If the ...
1
vote
1answer
42 views
Production code to be good for unit testing
I would like to advise if the following production code is good to be unit tested. The segment of the production code gets data from a backend service and displays it on the page. It is a class:
...
...
0
votes
2answers
65 views
How to optimize this?
This is a user Javascript for youtube, the point is to make the thumbnail bigger on mouseover, I just want some help making it better because I don't want it to waste resources with all the extensions ...
2
votes
1answer
28 views
Encapsulate results in div tags
I would like to turn the following:
<div>this is a $test</div>
into
<div>this is a <div>$test</div></div>
currently I have
var regexp = new ...
0
votes
1answer
72 views
How can I reduce/improve in this switch
Below is a chunk of some switch code used to create an array of objects which should be visible. Previously I combined case -1 and case 0 to reduce redundancy, but I am wondering if this code can be ...
2
votes
0answers
27 views
Stripping formatting from text - Am I using an efficient jQuery selector?
I'm making a comment box using a contenteditable div, but I want to remove formatting from text a user might copy/paste into it (also no CTRL+B or CTRL+I shortcuts allowed either). Only "approved" ...
2
votes
2answers
60 views
JavaScript event handlers, scope, and the module design pattern
I've been using JavaScript for some time now, but mostly just jQuery to prettify web pages. I've started doing some serious development with it in the last year.
So, I want to make sure I'm not ...
1
vote
1answer
14 views
Using multiple popup windows with bPopup
I'm using a lightweight jQuery popup plugin called 'bPopup'. I'm using it on my website at the moment to load multiple popup windows when clicked. I was recently told that my code was inefficient as I ...
4
votes
1answer
68 views
Javascript plugin DRY
I have written a Backbone View (javascript) for a component called "twist-panel".
A twist panel is basically a card flip, it has a front and back side, and can flip to the back and to the front.
...
2
votes
2answers
83 views
Whats a better way to do these nested if statements?
I forgot to mention using the result of bar to calculate foo's value in the question I asked here.
The function bar only needs to be called if conditionA is true. But when the result of bar ...
1
vote
1answer
49 views
Improving localStorage functions
As part of a larger web app we are producing, I was asked to help build functionality to tie a page's shopping cart into localStorage for persistency. What follows are the three functions that I wrote ...
1
vote
0answers
66 views
Simple Telnet Chat Server nodejs (correct way to write programs in node.js (asynchronous programming model))
I am new to node.js and asynchronous programming and this is my first small project to learn it. I have written a small Telnet Chat server and the program works but I want to know if this is the ...
2
votes
1answer
72 views
HTML - single page layout - absolute positioning
I am doing web apps, mostly single page apps. So i have to give absolute and fixed positioning a lot via css.
For Example, consider this page layout:
<html>
<div class="app-header">
...
3
votes
4answers
283 views
Whats a better (DRY) way to do this if statement
The function bar only needs to be called if conditionA is true. But when the result of bar (conditionB) is false, I want to run the code that would have run if conditionA had been false. Is there a ...
2
votes
1answer
23 views
Rotating color table object (for easy and consistent labeling)
I wanted to be able to consistently label an arbitrary number of objects on my site. It's pretty simple, but I if there's a more clever way...
// Usage:
// ColorTable.getColor('my link name');
...
1
vote
0answers
56 views
jQuery plugin for easy CSS3 transformation
I wrote it more for educational reasons and less as something that can compete with existing alternatives.
But I enjoyed writing it and wish to get some feedback, JavaScript is my second language :)
...
0
votes
0answers
25 views
Making one object the property of another whilst avoiding scope issues
After being inspired by some MVC style design patterns, I have been trying to separate data from views in my code and move toward a more sensibly organized object based approach. (please, don't bother ...
-2
votes
0answers
32 views
Recursive Function for create Menu Tree from Database in Asp.NET & C# website [closed]
In My Asp.NET website I want to Create tree structured Menu from Database .
1
vote
0answers
32 views
Creating and referencing markup…cloning, etc. efficient system for this plugin
I am pulling multiple feeds from youtube that have a callback function which makes markup from each feed. They add that markup to a documentFragment stored in var data. When all the feeds have ...
1
vote
2answers
53 views
Playing sound on a button click
I am new to javascript and want to make sure I am on the right track when playing a sound. Is there anything I should not be doing better or not be doing at all. Below is a simple function.
...
0
votes
2answers
57 views
AJAX response DOM element selection
I GET a HTML response from AJAX over cors and the response is a table. Each category has its title and sub elements. The title names vary quite a bit and are likely to change in the future. The sub ...
3
votes
1answer
114 views
javascript app code review
Hi I am new to javascript.
I would like to get feedback for possible improvements to the code of my little app.
It is a html / javascript app for calculating someones body mass index.
The app does ...
1
vote
1answer
53 views
Backbone.js Dependency Injection API Design
I'm writing a dependency injection plugin for the Backbone javascript framework, and I'm not sure what the API for constructor argument injection should look like.
Just for reference, Backbone ...
0
votes
1answer
33 views
Optimizing a jquery user interface application
I'm working on a javascript intensive user-interface application. (At least it's intensive for me, it's my first serious javascript project).
I have a few jquery functions going whenever a div is ...
2
votes
1answer
181 views
Instantiation/Inheritance Helper — Optimization / Pitfalls
For the sake of learning javascript better and getting used to the Google Chrome Extension Api, I'm currently writing a little Chrome Extension.
To keep things simple and being able to make use of ...
-1
votes
0answers
60 views
I found the piece of code that made my javascript run slow. How do I optimize it to run faster? [closed]
According to jsHint it should work fine however my website literally cannot load with this code in my javascript.js file. I've fixed all that I could think of is there anything else? Sorry, it's a bit ...
1
vote
2answers
72 views
jQuery code refactoring
Just wanted some opinions on how to write this code a little better, it is working properly, I'm just trying to learn how to write jQuery better so I wanted some smart peoples opinions. Thanks!
It is ...
3
votes
2answers
74 views
Replacing text in an array
I have this piece of code to replace current text inside an array of html divs with values coming from a JSON file:
$.each($('.something'), function(){
if($(this).text()=="1"){
...
3
votes
1answer
113 views
Javascript/Canvas Game Dev (pong)
This is the first time I've written javascript in this way (previously all I've done mostly is DOM manipulation and form validation in vanilla and jquery).
I've begun working on a basic pong game. ...