javascript

How to write a JavaScript plugin in the Pro/Ninja Way?

I don't need advice about the JavaScript code but about the files organization. I mean, I could write all my jedi code in a single .js file but I know it won't be the very best way to do it. So, this is a standard way to do this or it's all about free will? By the way, I'll host it in github, in case there's a thing as "the github way f...

Trying to achieve this animation effect in jQuery

I'm trying to achieve an effect like the one on this page (click the submit button). http://www.thewildtimes.com The modal drops down from the top of the page. I think it's a jQuery easing effect, but I am a little baffled by all the options. How can I do this? ...

Detach element style from html

I have bulk of html file like this <div style="min-height: 32px; padding: 5px; width: 800px; margin: 50px auto; overflow: auto; font-size: 12px;" class="selectable clearfix selected_layer" id="wrap"> <div class="selectable" id="l1" style="float: left; min-width: 64px; min-height: 32px; padding: 5px; margin: 5px; overflow: auto; width: 2...

How can I force the user to mark three checkboxes?

I have a html form. I want the user to be able to mark three checkboxes. If he marks more than three, I want to send an immediate warning message. How do I do this? (Never worked with JavaScript before). ...

Javascript single array to associative array

I'm trying to build a javascript that will autocomplete a textfield based off of a customer name in an array, but I would also like to set a hidden field to the customer ID. Im not sure how to build an associative array that will allow me to accomplish this. I've found a bunch of sniplets for autocomplete, but I'm struggling on how to bu...

How would I create a web based dynamic mind mapping application in Javascript?

I am trying to create a type of mind mapping software that runs on the web, and I am trying to figure out where to start. I would like this to be able to be used by the most number of people possible. My web application is currently written using Javascript for the front end and C# for the back-end. I was thinking of using Javascrip...

Javascript: Date Issue

I create a new Date in javascript and provide it the string value of a date like so: >>> string_date = '2009-09-09'; >>> var myDate = new Date(string_date); >>> myDate Tue Sep 08 2009 20:00:00 GMT-0400 (EST) { locale="en"} The string date comes from a calendar picker widget and I write the value from that widget to a hidden input fiel...

Do JavaScript compilers have its preference over how indentation, spaces, and curly braces are placed in the source code?

Hi all. I'm currently having my peer code review with my colleague and have had this question on the subject. Is there any preferable syntax for coding, say, if clause statement for JavaScript compilers(JavaScript Engines)? I personally prefer the pattern A when I review the code myself, but do the compilers have their preference too? ...

Would JavaScript fare any better had it been multithreaded

This is a follow up question to Is there a point to multithreading? If JavaScript were multithreaded, would it fare better than the existing system? Would multithreading with one UI thread and other tasks in different threads (background) bring in greater responsiveness and efficient usage of resources? Why did the designers of th...

Fade out message after 10 seconds, clearing the input elements using jQuery

I'm displaying a message (#final_msg) after the user submits the form. What I want to do is that, after 15 seconds, the message (#final_msg) should fade out, clearing away [or fading out] the text in the input elements as well. Is it possible to do this? else { //create post data var postDat...

Why is cosine used to calculate the x values and sine the y values for an arc?

I'm trying to understand the math on this raphael.js demo: http://raphaeljs.com/pie.js Checkout the sector method: function sector(cx, cy, r, startAngle, endAngle, params) { var x1 = cx + r * Math.cos(-startAngle * rad), x2 = cx + r * Math.cos(-endAngle * rad), y1 = cy + r * Math.sin(-startAngle * rad), y2 ...

How to kick-ass pass scope through "setInterval"

Dear Masterminds, I'm currently wondering if there is a better solution than passing this scope to the lambda-function via the parameter 'e' and then passing it to 'funkyFunction' using call()-method setInterval(function(e){e.funkyFunction.call(e)}, speed, this) (Minor question aside: I'd been reading something about memory-leaks in ...

Javascript issue with http://mysite.com vs http://www.mysite.com

Hello, I've never experienced this problem before, and it just came to our attention because a client was trying to access our page and couldn't see much of the javascript. He was navigating to http://www.mysite.com, when we've always just gone to http://mysite.com. There appear to be no problems server-side, as in both url's are poin...

IE6 specific javascript code

Hey guys -- I have a validation script that absolutely positions a series of <span>s using positioning. However, the positioning is off by about 10px to the right (aka 10 more pixels need to be added to the right) in IE6. I was wondering if I could jQuery to detect IE6 and add 10 more pixels to the right. This is the code I have: if ( ...

How to write a mutator method in javascript?

Array.prototype.clear = function(){ this = new Array(); return true; } That code raise an invalid assignment left-hand side error. How do I change the object itself within one of his methods? ...

INVALID_STATE_ERR: DOM Exception 11 (WebKit)

I recently tested a Cappuccino app I was working on with Chrome and Safari. I get the error: INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. The lack of information is frustrating. What object and where did I attempt to use it? Chrome tries to answer the second question b...

load content inside iframe using ajax

hi folks I have iframe that works at the server side : <iframe frameborder="0" runat="server" style="width: 100%; height: 700px; background-color: #bacad3;" id="I1" name="I1" src="Page.aspx"></iframe> and I change the content dynamically with this code : protected void Button1_Click(object sender, EventArgs e) { I1.Attri...

Scale and move a text smoothly with javascript

Hi, I'm having a text scaled and moved via JavaScript / jQuery. I can't use jQuerys animate() because it has to fade in and out and has to be repeated and with more elements (end result: "flying" from the background, moving in different directions and fading out). My problem: It's not running smoothly and causes quite the cpu-usage. He...

Why is my jQuery keydown feature only working on the first input element.

I've built a small jQuery script that adds a class to witch ever input field I'm writing in. However it only works on all input fields after something is written in the first input field, see dev.resihop.nu for example. The code: $('.field').keydown(function () { if ($('.field').val() !== 'Ort, gata eller kommun') { $(this).add...

Javascript eval() Exception - line number

In JavaScript I have a var str = ".a long string that contains many lines..." In case of exception that caused by eval(str); I had like to catch it and print the the line number that caused the exception. (the line internal to str..) Is it possible? EDIT As part of the Alligator project (http://github.com/mrohad/Alligator), an applica...