prototypejs

Breaking out of a PrototypeJS .each() loop

In this very contrived example, I have an array with 3 elements that I'm looping over using the .each() method. var vals = $w('foo bar baz'); vals.each( function(val) { alert(val); if( val == 'bar' ) { //This exits function(val) //but still continues with the .each() return; } }); I can easil...

Why does jQuery seem to discourage the use of regular OOP?

We recently built a web app using Prototype, making a fair amount of use of its Class.Create() functionality. Right now, we're considering migrating to jQuery as it seems to be considered a 'better' library. I've been doing some reading on the topic and found out that jQuery does not have straightforward built-in support for class-creati...

Proper event handling using jQuery

I've been working with some event handling in Javascript and recently decided to migrate from Prototype to jQuery. I already encountered some trouble using Prototype, but found some workarounds which at least solved the problems, but didn't look very nice to me. Now I'm rewriting everything anyway, I'd like to get it all straight on the ...

Class.create and this keyword

Hello, I'm trying to use the Class methods of prototype.js to manage my object hierarchy on my current project, but I have some trouble with the this keyword in conjonction with Class.create. Here is a piece of old-fashioned plain js code to create inheritance: var Super1 = function () { this.fu = "bar"; } var Sub1 = function () ...

How can I inject Javascript (including Prototype.js) in other sites without cluttering the global namespace?

I'm currently on a project that is a big site that uses the Prototype library, and there is already a humongous amount of Javascript code. We're now working on a piece of code that will get "injected" into other people's sites (picture people adding a <script> tag in their sites) which will then run our code and add a bunch of DOM elem...

How can I prevent auto-parsed, AJAX-gained JSON to become a window variable?

I'm using JSON to communicate some data through AJAX from the backend to the frontend (Javascript, of course). The XMLHttpRequest is done by a Prototypejs-written AJAX-handler (I'm still in the process of migrating to jQuery, but the noConflict-mode allows me to run both simultaneously), after which PHP sends the X-Json header with some ...

How to implement the OO in Javascript using prototype framework?

please give the example to me. I want a class, which is a abstract class name "Person" , and two abstract class named "Male" and "Female", which extends "Person", and two concrete class named "Young man" which extends "Male" and "Young woman" which extends "Female". Also, I need a multiple inherited class which called "Unknown", and it ...

Delete records from database with an Ajax request

hi all friends I am using php / mysql and protype.js to delete record from a table. The problem is that the record in the database is not deleted. index.php: <a href="javascript: deleteId('<?php echo $studentVo->id?>')">Delete</a></td> Script is function deleteId(id) { alert("ID : "+id); new Ajax.Request(...

refresh the div tag on click of the delete record

i'm using the prototype.js , PDO , PHP. i want to delete the records with refresh using ajax index.php <?php if(!isset($studentVoList)||count($studentVoList)==0){?> <tr><td colspan="3" align="center">No records found.</td></tr> <?php } else { foreach($studentVoList as $studentVo) { ?> <tr> <td align="center"><?php ech...

Observing events for elements with a certain class or that element's children using event delegation

I have a page with elements similar to this: <div id='things'> <div class='thing'> <div class='activator'> <span>Some text</span> </div> </div> </div> The code is similar to this: $('things').observe(click, function(event) { var e = event.element(); if (e.match('.activator')) { doSo...

Purpose of an 'Identity Function'?

I came across this subject when I was reading through PrototypeJS's docs: its Identity Function. I did some further searching&reading on it and I think I understand its mathematical basis (e.g. multiplication by 1 is an identity function (or did I misinterpret this?)), but not why you would write a JS(or PHP or C or whatever)-function th...

How can I dynamically add and remove <fieldsets> using prototype and scriptaculous?

I'm writing a basic recipe organization application and I would like to be able to dynamically add additional items to the list of ingredients using Ajax. This is what one ingredient <fieldset> looks like: <fieldset id="ingredient_item_0"> Ingredient <input id="ingredient_0" type="text" size="20" /> <div id="ingredient_list_0" style=...

Class inheritance in Prototype.js and arrays

I'm using the Prototype.js (from www.prototypejs.org) library to create classes which are extended by subclasses. I'm having trouble using arrays within instances of these classes though. I've made an example to illustrate this: var SuperClass = Class.create({ initialize: function(id) { this.id = id; } }); var SubClass = C...

link_to_remote in Rails renders incorrect URL when rendered from RJS

I have a partial for a "guest" object which renders a link to a destroy action like this: <%= link_to_remote "remove", :url => { :action => "destroy", :id => guest.id } %> When called from an ERB view it works fine, e.g. <div id="guests"> <%= render :partial => @event.guests %> That is, it renders something like: <a href="#"...

javascript memory leak

Hi, I'm trying to solve a problem with a memory leak in IE with Javascript. Basicaaly I'm using javascript to add icons on top of an image then I need to refresh the icons periodically by deleting them and re-adding them. When I run the app through drip though (IE6 memory usage indicating tool), when I delete the images before redrawin...

PrototypeJS mouseover menu

So i have this menu that is supposed to display submenus which are defined in object initialization by using script.aculo.us effect appear ( mouseover ) and hide them using effect fade ( mouseout from link and menu ). The problem is that i did the job with showing and hiding menus but when i get my mouse out of the link that is supposed ...

does jQuery have an effect like this? This is using prototype

http://blog.posterous.com/ Click on the comments link. Notice how the comments are loaded, kind of sliding down. ALso when you click on 'hide'. ...

Rails Modal Form Validation

I am using Lightbox Gone Wild to display a modal dialog with a form inside. I am using a vanilla New view. This works like a champ up until a user doesn't input valid form data. Invalid data causes the controller to direct the user to the New view directly with the error message. Obviously, I would prefer the error be returned to the mod...

Special characters not displaying when using Prototype/AJAX.Update

I've been looking around at all the people who have asked this question, but have yet to find an answer that works for me. Basically, I'm updating a div from an external HTML file that contians characters like é. For some reason, whenever the call gets made the characters are stripped out and replaced with question marks. I've tried bot...

Using Ajax.Request response inside of an object ? - PrototypeJS

Hi there, for past two hours i've been trying to pass responseText to the object i'm calling Ajax.Request in. And it just isn't happening :) Here's the code; var traziSuggest = Class.create({ initialize:function( elemenat, sugDiv ) { this.elemenat = $( elemenat ); this.elemenat.onkeyup = this.uzmiSug.bindAsEventList...