prototype

JavaScript prototype(ing) question

Trying to grasp Prototyping in Javascript. Trying to create my own namespace to extend the String object in JavaScript. Here is what I have so far (a snippet): var ns { alert: function() { alert (this); } } String.prototype.$ns = ns; As you can see, I am trying to place what will be a series of functions into the ns namespace. So...

How to access 'private functions' in a singleton from another object inside it.

I am currently trying to create a test suite for my javascript apps. My problem is that, it seems I cannot get access to init() from my utils object, as you can see below: I have my app that follow a singleton pattern: var appModal = function () { var utils = Object.create(moduleUtils); function init(caller, options ) { } ...

What are the benefits of prototypal inheritance over classical?

So I finally stopped dragging my feet all these years and decided to learn JavaScript "properly". One of the most head-scratching elements of the languages design is it's implementation of inheritance. Having experience in Ruby, I was really happy to see closures and dynamic typing; but for the life of me can't figure out what benefits...

Checking for attachments in JavaScript

Prior to submitting a form, I would like to check if a file has been attached and pop up a warning message saying that a file needs to be attached if it hasn't been. I was wondering how to accomplish this using JavaScript or Prototype or JQuery etc? ...

CSS selector for grouped iterations

Hi, I have a number of elements that i want to loop through as groups. Consider this HTML: <input class="matching match-1" /> <input class="matching match-1" /> <input class="matching match-2" /> <input class="matching match-2" /> <input class="matching match-2" /> <input class="matching match-3" /> <input class="matching match-3" /> /...

Improve this snippet from a prototype class

This is a snippet from a prototype class i am putting together. The scoping workaround feels a little hacky to me, can it be improved or done differently? var myClass = Class.create({ initialize: function() { $('formid').getElements().each(function(el){ $(el).observe("blur", function(){ this.valid...

CSS selector for the last occurrence of a class on a page

Is there a CSS selector for the last occurrence of a class on a page? Say i have this HTML <dd> <span> <a class="required" id="forename">foo</a> </span> </dd> <dd> <span> <a class="required" id="surname">bar</a> </span> </dd> Is there a CSS selector that would return the a tag with the ID of surname. S...

Javascript Running slow in IE

Hi, Javascript is running extremely slow on IE on some pages in our site. Profiling seems to show that the following methods are taking the most time: (Method, count, inclusive time, exclusive time) JScript - window script block 2,332 237.98 184.98 getDimensions 4 33 33 eh 213 32 32 extend 446 30 30 tt_HideSrcTagsRecurs ...

Firefox won't change image source

I'm trying to change an image in JavaScript+Prototype by changing the "src" attribute of the element. It works fine in IE, but not in Firefox. I don't get any errors and the script continues executing after this bit executes: var image = $('toggle'); image.setAttribute("src", "../images/icons/icon_minus.gif"); image.setAttribute("alt", ...

Scriptaculous Autocomplete to activate when the page is loaded.

Is there a way to fire up Scriptaculous's Autocomplete to search with the default word from the inputfield when the page is loaded? Something like this? <input type="text" id="autocomplete" class="autocomplete_input" name="autocomplete_parameter" value="friends"/> <span id="indicator1" style="display: none"> loading </span> <div id="au...

jquery noConflict not working in IE8 only

I have a website using the prootype framework and I am looking to use a jquery plugin. Everything works just not in IE8. It works in ie7 which amazes me. Any idea what maybe wrong? IE8 gives me object doesnt support this property or method where line jQuery.noConflict(); is <script src="/my/docs/jquery.js" type="text/javascript"></scr...

Dynamically loading CSS and JavaScript using Prototype

I have a classic ASP application that I've been constantly trying to modularize. Currently, almost all pages are divided in to two pages: an outer page that contains the layout, header, sidebar, footer an inner page that contains ASP code The outer pages use dreamweaver templates so updating layout and replicating changes is easy. Th...

Element.replace() leaks DOM nodes

I'm trying to replace a DOM element (a div) using Prototype's Element.replace() operation. It seems to do the replacement OK, but leaks a single DOM node in the process. I checked this with sIEve; all but one of the existing DOM elements is freed by the innerHTML="" bit. This is in turn leaking memory, which I can't afford in a long-runn...

Javascript: addClassName if input is checked and removeClassName if it was un-checked

Im trying to select all the li tags of the document and check if it hasClassName('yes') so if it has, it will remove it. But im having a TypeError: Object [object HTMLLIElement], has no method 'hasClassName' error. This is the DOM method: document.observe("dom:loaded", function() { $(document.body).select('input').each(function(ele...

Programmatically manipulating DOM element value doesn't fire onchange event

Hi all. I've got a hidden form field, and when a button gets pressed the value of the hidden field is changed. Now, I've added an observer to the hidden field, listening for changes to occur. For some reason, though, the event listener never kicks in, even though the value of the hidden element changes. I'm using Prototype and Firefox 3...

Style / Replace a select box using prototype / scriptactulous

Hey everyone, I'm trying to style my select box, I assume I need some type of javascript method. I'm using rails - and sticking with prototype/scriptactulous. Does anyone know of any solutions? EDIT: CSS doesn't do nearly what I'm trying to accomplish: ...

iPad HTML Prototype: Which JS Framework?

Hi, are there any Javascript frameworks (such as iUI) available for building iPad prototypes? I have found nothing useful so far. Best, Stefan ...

How can I catch a change event from an HTML text field when a user clicks on a link after editing?

Our webapp has a form with fields and values that change depending on values entered. Each time there is a change event on one of the form elements, we use an expensive AJAX call to update other elements on the page. This works great for selects, radio buttons and checkboxes. The issue comes in when a user adds content to a text field, ...

jquery range utility for quick iteration (prototype's $R equivalent)

In prototype the cumbersome for: for (i=0; i<10; i++) { ... } can be written as $R(0, 10).each(function(i){ ... }); Is there an equivalent of range in JQuery ? ...

Prototype Element.remove() not working in IE

Hi there. I have a javascript function that gets a DIV by an ID and makes a clone. Then, removes the original DIV from DOM and inserts the cloned object..Everything works fine, except in IE, because the original DIV is never removed... var loadingDiv = $(Sybil.conf.loadingDivId), loadingClone = loadingDiv.clone(true); console.l...