javascript

How to optimize this js (now CPU is over 40% when the page is opened)

I have this piece of JavaScript on my page and it loads the CPU considerably. Is there any way to optimize the code? ( I'm using jQuery, so jQuery solutions will be fine ) function Particle() { this.particleContainerWidth = $('#particle-container').width() - 100; this.particleContainerHeight = $('#particle-conta...

Distinguishing closure and local variables

A local function in the closure declares a variable with the same name which exists in the closure. So, how could we access closure's variable from the local function? function closure() { var xVar; function func1() { var xVar; // how to distinguish local and closure scopes. return xVar; } re...

Can Flash applications have a Javascript API?

How is the interaction between these two worlds in a browser? ...

Link terms on page to Wikipedia articles in pure JavaScript

While browsing I came across this blog post about using the Wikipedia API from JavaScript, to link a single search term to it's definition. At the end of the blog post the author mentions possible extensions including: A plugin which auto links terms to Wikipedia articles. This fits the bill perfectly for a project requirement I'm...

Javascript defaultValue property for use on SELECT?

Javascript has textObject.defaultValue=somevalue for retrieving the default value (stored value from page load) of an input even if you wipe the input and replace the contents, you can still get the default back. Like this: // in the html page <input id="addr1" type="text" value="21 Oak St." /> // the jquery myInput = $("#addr1"); // t...

jquery write html into variable

i am writing two list application where data from one list can be shifted to other list. i am using DIV like this <div id="all_users"> <div id="user1" userid="1" class="innertxt"> <img src="images/images.jpg" width="50" height="50"><strong>Test User 01</strong> <ul> <li>User ID: 1</li> <li>Email: u...

javascript include function window.onload

I have 2 functions on a seperate page that I am including of the header of the .html page. Under the part where I include it, I have this code: window.onload = func1; I want to take that little snippet of code, and include it inside the included .js page which has the function in it, so essentially there will be the function, then righ...

call future javascript function compatibility on all browsers?

let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment doSometingNow() is created callSomethingInFutureNotExistNow() not exist yet. It will be created in the future, on firefox, this doesn't show any error on firebug. Will these kind of function compatible on all browsers ...

Compass spinning javascript problem with angle - rotate/translate

Hi i'm building a compass for the iphone, duh, just for experiment purpose and to learn how to do it, in javascript, with phonegap. now i'm already able to get the degrees, i was able to apply the deg 0-360 to a div (let's call it the "wheel") using the webkit-transform translateZ (or i could use rotate) but i have a bug: when the w...

Sharing information between two XUL applications

I am currently developing a toolbar and sidebar for firefox. I want to have the two share information, but upon loading the .js file I want them to share, it is loaded twice and has two instances instead of one. How can I get the toolbar and the sidebar access the same information or global variables in a single javascript file? Thanks...

Why doesn't this Javascript RGB to HSL code work?

I found this RGB to HSL script over at http://www.mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript. I can't find any other small decent ones. The issue is that this code doesn't even really work. Would anybody know why? (I don't know a bit of color math, but maybe it's returning the complem...

Queuing asynchronous HTTP file uploads

Is there a way to queue file uploads without resorting to Flash or Silverlight, just with cleverly used forms and JavaScript? Note that the upload should be executed asynchronously. By "queuing" uploads I mean that if the user tries to upload multiple files, they should not be transferred simultaneously, but rather one at a time, in a s...

event.target points to a child element

When a user clicks on a <li>-element or on a child element of it, I want to add a class to this <li>-element. This works fine, but for performance enhancement I decided to bind this event to the <ul>-element, so unbinding and binding this event is much faster in a list consisting of 1000 <li>-elements. The only change I thought I had to...

How is it done "Manage this list" on amazon ?

I'm specifically looking, how is the hover on done? and what did they use? JavaScript? Jquery, DHTML? and does anyone have example? Now, I'm new to web programming. (but not new to programming, I'm c++ and c# prg). I'm looking into getting web dev. for personal use. I saw this amazon feature and thought to myself that it would be nice to...

Security error on attempted access to twisted rpc server from javascript in the same domain but served from different port

Hi, I have a django server that serves the basic site with user, auth etc and a twisted web server that 'should' deliver live content as json streams. Django server is running on 127.0.0.1:8080 Twisted 127.0.0.1:9897 The problem is that when ever I try to make an http request to twisted server from a page in the django site, I get a ...

How to detect the selected value of a dropdown

When I select one item from 1st dropdown, an ajax event will fire up, invoke another function that will and load information to the second dropdown. I do not want this (No button solution please) <select id=combo1> <option>...</option> ... </select> <input type=button onclick="loadCombo2()"> ...

Pure CSS Dropdown Menu

Hello, I have been working on facebook application and you know on facebook native javascript is not allowed, they have their own implementation FBJS which is troublesome when it comes to creating stuff like menus. Is there any pure CSS dropdown solution without any involvement of javascript (javascript is used in all the solutions i h...

Using controls requiring different jQuery Versions

I am trying to use an Apycom menu requiring jQuery 1.3.2 on the same pages as Flexigrid for Rails which depends on jQuery 1.2.3. To add to the confusion I'm trying to include the Rails 'prototype.js' and use this as well. Here is my include order: <%= javascript_include_tag :defaults %> <%= yield(:head) %> <script src="/javascripts/jq...

Why are some object-literal properties quoted and others not?

I see this all the time: object literals declared such that some keys are surrounded with quotes and others are not. An example from jQuery 1.4.2: jQuery.props = { "for": "htmlFor", "class": "className", readonly: "readOnly", maxlength: "maxLength", cellspacing: "cellSpacing", rowspan: "rowSpan", colspan: "co...

How to disable mouse gestures as a developer?

Hi, I'm developing a web application and I noticed how irritating mouse gestures can be on it, so, is there a way to disable them (Firefox and Opera particularly)? Edit: It seems there is some confusion. I'm developing a web based software that has an interface with such complex actions and tasks such as mouse selections, file drag and...