prototype

Javascript - check if method prototype has been changed?

What's the best method to check if the protoype of a method has been changed? ...

How to return Element ID instead of [object HTMLDivElement] (Prototype.js)

I know this is simple, but I can't wrap my head around it. Currently the following code returns "[object HTMLDivElement],[object HTMLDivElement]" I'd like it to return "div1,div2". Any thoughts? Thanks guys. <HTML> <HEAD> <script type="text/javascript" src="path_to/prototype.js"></script> <script> function linkClick () { alert($$...

How can I unobtrusively disable submit buttons with Javascript and Prototype?

So I found this recommendation, but I can't quite seem to figure out how. This is the code I originally started with: function greySubmits(e) { var value = e.srcElement.defaultValue; // This doesn't work, but it needs to $(e).insert('<input type="hidden" name="commit" value="' + value + '" />'); // This caus...

scoping of private variables in object prototype methods

This question is about the behavior of an object with methods added to its prototype chain and a few private variables. Just out of curiosity and to get my head around this riddle. function SomeObject() { if (this instanceof SomeObject) { var args = arguments[0], proto = SomeObject.prototype, privatevalue ...

Preventing ASP.NET MVC from Replacing period with underscore in Html Helper IDs

Having just upgraded to the latest ASP.NET MVC Release Candidate I noticed that, when using Html Helpers, any name with a period "." in it will have this replaced by an underscore "_" when the element's ID is output. I believe this is to aid in using JQuery and the use of the period is to aid in the use of ModelBinders. This has broken ...

How to iterate over every property of an object in javascript?

Is there a way to iterate over every property of an object using the Prototype JavaScript framework? Here's the situation: I am getting an AJAX response in JSON that looks something like this: {foo: 1, bar: 2, barobj: {75: true, 76: false, 85: true}} If I evaluate that json response in to a variable response, I want to be able to ite...

Is there really no way to expose the prototype of a html element in IE (<8)?

I cooked up a pattern to create and extend html elements using their prototype. This works like a charm in non-ie browsers. Example code can be found @jsbin (see page source) The advantage of this pattern should be speed (the methods are in the elements prototype chain, so they are referenced once). You guessed right: IE no go. In IE < ...

using reCAPTCHA with ajax....javascript loading problem

Hi, I trying to implement reCAPTCHA in one of my forms,...but i am using ajax as the submission. (More specifically the prototype ajax.updater) Once I submit and error check my form I try to load the reCAPCHTA widget thingy (in my updated div element) which basically just calls a javascript file like so: <script type="text/javascript"...

How can I add properties to an object in IE6?

I've got a particularly tricky problem using AJAX, which works fine in IE7 and Firefox, but not in IE6. I have a very simple home-grown AJAX framework, which requires that I extend the XMLHttpRequest object (or in the case of IE, the XMLHttpRequest ActiveXObject) by adding a couple of properties. Relevant section of code is as follows: ...

Is it possible to pass a type as a variable in Actionscript?

The actionscript I want to write looks like this: public function API(requestClass:Type=URLLoader) { var req:URLLoader = new requestClass(new URLRequest("some url")); req.load(url); //etc } so that I can test the API class by passing in a mocked subclass of URLLoader. This doesn't appear to be possible in Actionscript's type sys...

Treating Classes as First Class Objects

I was reading the GoF book and in the beginning of the prototype section I ready this: This benefit applies primarily to languages like C++ that don't treat classes as first class objects. I've never used C++ but I do have a pretty good understanding of OO programming, yet, this doesn't really make any sense to me. Can anyone ...

Robust keyboard shortcut handling using JavaScript

What's the most robust way of creating a global keyboard shortcut handler for a Web application using JavaScript i.e. which event(s) should I handle and what should the event handler(s) be attached to? I want something like the system in Gmail which can handle both single keypress shortcuts and also shortcuts with modifier keys e.g. Ctr...

JavaScript augmented prototype lifecycle

Hi, If I want to add an isEmpty method to all JavaScript arrays, I would use the following code Array.prototype.isEmpty = function() { return this.length == 0; } Assume this code is in a file foo.js. If I want isEmpty to be available on all pages of a web site, would I need to include foo.js in all the HTML files? In other words, d...

How to append child before. prototype

I making a website with the javascript library. If the user select a option on a dropdown (select) box there must be added a label and a textbox. This I do with the appendChild option. The only problem with the appenChild option is that the items always be added after the items in used element. This is my code: var newFreeformLabel = do...

Extending Number.prototype in javascript and the Math object?

I've always wondered why Javascript has the global Math object instead of giving numbers their own methods. Is there a good reason for it? Also are there any drawbacks (other than efficiency) to doing something like this?: Number.prototype.round = function(){ return Math.round(this); }; Just to make clear, I understand that const...

What lessons can be learned from the prototype model in javascript?

The question is from a language design perspective. I should explain a little about the situation. I am working on a javascript variant which does not support prototypes, however it is overdue a decent type system (most importantly support for instanceof). The ecmascript spec is not important, so i have the freedom to implement somethin...

Prototype/Scriptaculous: Selecting groups of paragraphs (<p>) by clicking on them.

A list of paragraphs (<p>) is given. As soon as the user clicks on paragraph A the class of paragraph A changes to "activated". Now the user selects paragraph B and all the paragraphs between A and B change their class to "activated". By clicking on B again, only A remains with the class "active". By clicking on A the class "active" ...

prototype/javascript - firefox not firing keypress/keydown event unless focus is in textbox

The following works fine on IE6, IE7, and chrome. Not working on ff 3.0.7. <html><head> <script src="prototype.js" type="text/javascript" ></script> <script type="text/javascript"> Event.observe(window, 'load', function(){ Event.observe(document.body, 'keydown', myEventHandler); alert('window load'); }); function myE...

RJS: Check for existing page element?

I have a textfield with the id "foo" that sometimes exists and sometimes not. If it exists I'd like to fill in a certain value. How do you do this by using RJS (in Rails 2.2)? I tried this and it doesn't work: if page[:foo] page[:foo].value = "bar" end I get TypeError: Null Value if the textfield doesn't exist. ...

Prototype menu

Does anyone know of a good javascript menu using the prototype library. I need to produce a list of links available for each row of a HTML table as a hover/click dropdown menu. Constraints The list of links is the same for every row, however, a link needs to post an id param unique to the row. The table is in a scroll pane, so the ...