javascript

Mocking Javascript objects (specifically YUI)

Hi, I'm trying to mock YUI for javascript testing. I want to mock a datatable, but im not sure how to do it. Something like YAHOO.widget.DataTable = function(){ }; so latter I could do something like assert.that(returnedDatatable, isOfType(YAHOO.widget.DataTable)); ...

Jquery Problem Sort of Auto Slideshow

Hi there, I'm having some problems, I'd like to have a sort of slideshow where users have 4 buttons, and when they click one div appears and the others disappear. The div's are all in the same place with the same size. I'd also like to put this automatic var Idx = 1; var IntervalKey = setInterval = (auto, 5000); var auto = function() ...

internet explorer 8 and issue with calling external scripts in https

Hi, Is there some sort of issue between internet explorer 8 and referencing external scripts outside the domain when using https. I used script from to lookup addresses using postcodes etc. using the script from http://www.postalcodeanywhere.com/. A button shows up in Firefox to do the address lookup but it does not show in IE 8. The sc...

javascript function return data

I have a function like this that does an ajax call to grab some data from a database. function db (content) { $.post('/ajax/db.php', { operation:operation, content:content }, function(data) { console.log(data); return data; }); } console.log(data); ...

Replace all spaces in a string with '+'

I have a string that contains multiple spaces. I want to replace these with a plus symbol. I thought I could use var str = 'a b c'; var replaced = str.replace(' ', '+'); but it only replaces the first occurrance. How can I get it replace all occurrances? ...

oo javascript with properties from server, methods from cache, best practice?

I'm converting procedural JS to OO and would appreciate any help. In a nutshell, what I have is a html-page containing: <script type="text/javascript"> var serverTime='11:32:20'; //time generated by server (php) </script> <script scr="myProcFuncs.js" type="text/javascript"> /* which is containing procedural functions such as fun...

Rails 3 - including JavaScript on a View?

Hello, here's what I'm trying to do right.... When a user signs in and is redirect to the landing page, I want to run a bit of jquery ajax to grab and inject some content. I originally had it in my application.js file but the problem with that is that the code is there for user's that aren't logged in, which means I have to add logic to...

What kind of architecture should I learn to make good JavaScript based software?

Hi, I know Model-View-Controller well, have known about it for years and used it in terms of server-side development with languages like PHP. However, I am now working with JavaScript and building a big application with it utilizing SVG, Canvas among other great features modern browsers support. The project is big, so, the architecture...

How to set a cookie to expire in 1 hour in Javascript?

How to set this cookie to expire in one hour from the current time: document.cookie = 'username=' + value; + 'expires=' + WHAT GOES HERE?; + 'path = /'; ...

How does an object reference itself in Javascript?

I was experimenting with inheritance in javascript, and wrote those two functions: Object.prototype.inherits=function(obj){this.prototype=new obj;} Object.prototype.pass=function(obj){obj.prototype=new this;} This code works very well: Dog.inherits(Animal); But the following fails: Animal.pass(Dog); As I understand it, my pass f...

Using Raphael javascript for hovering with arrays

Hi, using Raphael, I'm trying to get a shape to appear when you hover over an invisible area near the shape. The following code does not work - where am I going wrong? Each shape has two Raphael paths associated with it: one for the visible shape, and the other for the invisible area. <script type="text/javascript" charset="utf-8"> $("...

capturing title and metatags from a textarea

Hi There I am trying to capture html <title></title> and Metadata from with in a form1 but not exactly sure how to do it... My quess is to do it like: document.write(document.form1.title); or document.write.texteara.(document.form1.title); but this is not working for me... <textarea name="textarea" id="textarea" cols="45" rows...

ASP.net, C# Page load on lightbox close issue

I want to know what exact events fires when ASP.NET page load event fires. As i am using a lightbox in which some insertion is going on and after insertion i want that the parent page reloads with the new value loaded in gridview which i have in parent page. In light box page i added javascript event of parent window reload but sometime ...

Why is my jquery .each() function not working properly?

I wrote this function: jQuery(document).ready(function() { jQuery('input[type=text]').each( function(i) { thisval = jQuery(this).val(); jQuery(this).blur( function() { if (jQuery(this).val() == '') { jQuery(this).val(thisval); } }); // end blur function jQuery(...

webkit profiler

what are the 'self' and 'total' columns? The 'total' column does not add up to 100% (much higher) and it looks like the self does. I suspect self is non-cumulative and total is. So if methodA calls methodB calls methodC, in self Id see the % for each method call individually, whereas in total methodA would show the total of all three ...

how do you prevent page scroll in textarea on mobile safari

I am trying to make a little note pad app for mobile safari for funzies but so far it doesn't seem to be working out. I want to prevent page scrolling so it doesn't have the rubberband and feel like a webapp but to do this I am using: document.ontouchmove = function(e){ alert("calling prevent default"); e.preventDefault(); } ...

Android WebView playing audio with javascript.

I'm trying to very quickly port over an html application with plays sound (with soundmanager2) to a native android app using WebView. From my research, I haven't seen any evidence that sound, such as mp3s, can be played via javascript or any other methods using WebView. My goal now is to quickly port over the html app and then eventual...

conditional check for focus is in textarea or input field

$('body').keyup(function(e) { var code = e.keyCode ? e.keyCode : e.which; switch(code) { case 8: alert('blah'); break; } }); When a user hits backspace, I want the alert to pop up UNLESS the cursor is positioned within a textearea, input, etc. Any ideas on how to do this? ...

"<" sign not showing in javascript?

Hi! I have a div-element that I want to show the symbol '<'. div-element.innerHMTL = '<'; The string actually do not appears, I think the problem lies in that the browser thinks that it is a beginning of a tag element Anyone seen this problem before? ...

How Does One Attach A Handler To A Link Which Is Dynamically Loaded?

How do I attach a handler to the click event of a link, which is dynamically loaded i.e. it is only loaded in response to another action on the page? N.B. I am asking how to do this using the Prototype JavaScript library, but am not adverse to additional examples in JQuery as well. In the code below, the link is inside the page fragmen...