[Proto-Scripty] Re: Cross-browser function for Text content
We've been getting these requests in the past. Take a look at, for example: URL: http://groups.google.com/group/prototype-core/browse_thread/thread/8ef26e7cedb43afc/47033b4bc8dc4c74#47033b4bc8dc4c74 I still think that it's not a trivial solution (for the reasons outlined in the post linked above) and so is best handled by a standalone plugin. And using context-unaware `stripTags` on something like HTML is usually asking for trouble :) (imagine what stripTags would do to a string like this — foo bar scriptfunction wrap(html) { return 'div' + html + '/div'}/script baz; and then there are other elements with CDATA content model, like STYLE) -- kangax On Apr 13, 8:20 am, T.J. Crowder t...@crowdersoftware.com wrote: On Apr 13, 10:39 am, Eric lefauv...@gmail.com wrote: wouldn't it be wiser to check for the native method once and use it? Probably. I'd also check for innerText (in fact, I'd check for that first), since it's supported by IE, WebKit (so Chrome, Safari), and Opera; only Mozilla holds out. textContent is supported by all of them except IE. So: Element.addMethods((function() { return { /** * Element.text() - String * * Gets the text within the element, ignoring any tags (essentially the sum of all of the * text nodes within). **/ text: (function() { var element, testvalue; element = document.createElement(span); element.innerHTML = testvalue = foo; if (text_fromInnerText(element) == testvalue) { return text_fromInnerText; } if (text_fromTextContent(element) == testvalue) { return text_fromTextContent; } return text_fromStripping; })() }; // Get the element's inner text via innerText if available (IE, WebKit, Opera, ...) function text_fromInnerText(element) { if (!(element = $(element))) return; return element.innerText; } // Get the element's inner text via textContent if available (Gecko, WebKit, Opera, ...) function text_fromTextContent(element) { if (!(element = $(element))) return; return element.textContent; } // Get the element's inner text by getting innerHTML and stripping tags (fallback) function text_fromStripping(element) { if (!(element = $(element))) return; return element.innerHTML.stripTags(); } })()); Do people think I should submit this to core? jQuery has an equivalent function, and I think I saw one in Closure as well. So it's not just the OP who wants to do this... -- T.J. :-) On Apr 13, 10:39 am, Eric lefauv...@gmail.com wrote: Oooops, gmail sent the message before I finished... :o) Here is the correct message (please ignore the previous one) On Apr 12, 7:04 pm, T.J. Crowder t...@crowdersoftware.com wrote: Element.addMethods({ text: function(element) { if (!(element = $(element))) return; return element.innerHTML.stripTags(); } }); wouldn't it be wiser to check for the native method once and use it? Something like (untested) Element.addMethods({ text: ($$('BODY').first().textContent===undefined) ? function(element) { if (!(element = $(element))) return; return element.innerText; } : function(element) { if (!(element = $(element))) return; return element.textContent; } }); Eric NB: I know, the testing condition is ugly... feel free to post a better one :o) -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Finding the first form item of any type within a div
On Jan 5, 10:17 am, Tony Andrews tony.andrew...@googlemail.com wrote: I have already posted a question about this on StackOverflow here (http://stackoverflow.com/questions/2006432/finding-the-first- focusable-item-of-any-type-within-a-div) so I won't repeat the whole thing. My issue is that I want to select the first form item of any type (input, select etc.) within a div. When I try $('mydiv').select ('input', 'select') for example, it returns all the inputs, then all the selects. So the first item it returns is not necessarily the first item in document order: if the first item is a select and the scond is an input, it will return the second item first. Any ideas? DOM L2 HTML module defines `elements` property [1] as part of `HTMLFormElement` interface [2], which FORM elements implement. As you can see, `elements` returns collection of all form control elements; that collection is of type `HTMLCollection` [3], which is a live DOM representation of a tree. There's also an `item` method of `HTMLCollection`, which [...] retrieves a node specified by ordinal index. Nodes are numbered in tree order (depth-first traversal order). [...] So... I think it's safe to assume that `$('myDiv').elements.item(0)` should return a first form control element in a document order. And of course this kind of retrieval should be an order of magnitude faster than `selector`-based approach ;) HTH [1] http://web5.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479 [2] http://web5.w3.org/TR/DOM-Level-2-HTML/html.html#ID-40002357 [3] http://web5.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506 -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: accessing DOM of iFrame
On Sep 3, 11:42 am, Jim Higson j...@wikizzle.org wrote: On Thursday 03 September 2009 16:29:33 Jim Higson wrote: On Thursday 03 September 2009 06:51:19 kangax wrote: On Sep 2, 2:23 pm, Mojito tokyot...@gmail.com wrote: What's the Prototyped syntax equivalent of: window.frames['iFrameID'].document.getElementById ('elementInsideIFrame'); Current version of Prototype doesn't really support programmatic context extension (such as that of `window.frames['iframeID']` in your example). Instead, Prototype initialization for a given frame is usually accomplished by inserting script referencing prototype.js directly into that frame's document. Once loaded, parsed and executed, that script automatically extends frame's context with all of the prototype goodness. It's then possible to do something like - `window.frames['iframeID'].$$('...')`. Also, don't forget that most of the Prototype DOM abstractions do not play well with elements originating from different documents (since internally, Prototype practically always operates on original document - that which exists in a context where Prototype was initialized, not an actual document of an element). Yes, It gets really confusing sometimes. So... which document is this Node from? Is $ here the $ using the top frame's document or the iframe's document? Ok, so this node is from the other document, which also loads Prototype, but when I extended it with $ I added in functions which were scoped in this document so it breaks, but since Prototype extends Element in Firefox, if I hadn't have done that, it might have worked Some of this could be fixed if Prototype used element.ownerDocument instead of just document (implicitly, window.document) for the Element methods. Actually, I'm starting to think this isn't really so. Some cases would work but there are a *lot* of references to document in the Prototype source and in many cases there isn't an element to query for its ownerDocument. [...] Well, using `ownerDocument` of an element passed to a method should solve most of these problems. When method doesn't take an element, one possibility is to pass document reference as an optional argument to a method. For example, - $('foo', otherDocument); Unfortunately, things like these should really be accounted for from the beginning (when designing API of a library). Prototype didn't account for it in the beginning and made `$` a variadic function (which actually has its own problems, but that's unrelated to context issue :)). This design decision pretty much prevents document passing as long as `$` has to be backwards compatible. Another thing that can be employed is keeping publicly available current document reference somewhere on Prototype (e.g., `Prototype.document`); then, internally, always access document via that one single reference. This way, instead of: foo(/*...*/, someDocument); bar(/*...*/, someDocument); baz(/*...*/, someDocument); - user could do - Prototype.document = someDocument; foo(/*...*/); bar(/*...*/); baz(/*...*/); or maybe even: Prototype.withDocument(someDocument, function(){ foo(/*...*/); bar(/*...*/); baz(/*...*/); }); - where `withDocument` would set and unset certain document around callback (second argument) execution. Another problem with multiple contexts and Prototype is in its core architecture. The fact that Prototype needs certain native objects to be augmented makes it difficult to work with different contexts. For example, Prototype augments `document` with `fire` method during its initialization. It then, quite reasonable, assumes that `document.fire` is always present. Now, if some method utilizes `document.fire` (or, say, `Prototype.document.fire`), it's possible that `Prototype.document` references pure unmodified document and that this document has no `fire` at all. To work around that, Prototype has to always use something like `Event.fire(document, ...)` instead of `document.fire(...)` or, perhaps, augment document with certain methods before trying to use them (if they don't exist). -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: accessing DOM of iFrame
On Sep 2, 2:23 pm, Mojito tokyot...@gmail.com wrote: What's the Prototyped syntax equivalent of: window.frames['iFrameID'].document.getElementById ('elementInsideIFrame'); Current version of Prototype doesn't really support programmatic context extension (such as that of `window.frames['iframeID']` in your example). Instead, Prototype initialization for a given frame is usually accomplished by inserting script referencing prototype.js directly into that frame's document. Once loaded, parsed and executed, that script automatically extends frame's context with all of the prototype goodness. It's then possible to do something like - `window.frames['iframeID'].$$('...')`. Also, don't forget that most of the Prototype DOM abstractions do not play well with elements originating from different documents (since internally, Prototype practically always operates on original document - that which exists in a context where Prototype was initialized, not an actual document of an element). -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 16, 4:57 am, T.J. Crowder t...@crowdersoftware.com wrote: Heya, If XHTML isn't necessary for Prototype, I'd suggest we change the doctype of the examples and unit tests. Good idea. Exclusively using XHTML doctype either shows our ignorance on the subject or the fact that we prefer to serve browsers with broken tag soup with no apparent benefits. What doctype do you use? You've been using and contributing to Prototype for a long time, I'll totally jump ship to whatever you're using. I'm using HTML 4.01 strict, but I really don't want you to jump this ship just because I'm on it :) I'd rather you realize why this is the only viable option at the moment (seriously, look at that article link to which I pasted earlier). [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Doctypes
On Jun 16, 5:52 am, Chris Sansom ch...@highway57.co.uk wrote: I'm curious about the recent discussion that's arisen as a sideline from the 'Creating new lines and bypassing them through escapeHTML' thread. I've been using Prototype for a little while now (though not Scriptaculous - yet!). I'm not by any stretch of the imagination an expert and I'm sure I'm still not using it as fully as I could (I keep coming across things in the docs that make me go 'Doh! I could have been doing that all this time'). However, I've also been working exclusively in XHTML 1.0 Strict for some time and I haven't been aware of anything not behaving as advertised. Also, unless I've missed something obvious, I don't /think/ I've seen any reference to doctypes in the API docs or Tips Tutorials at prototypejs.org. So should I be changing my ways here? I seriously don't want to have to convert several large and complex PHP-driven sites to a different doctype if I can help it! You certainly shouldn't rush and change all the doctypes, but you should probably change them to HTML 4.01 strict some time in the future. Remember that by serving documents with XHTML doctype and text/ html content-type makes browsers parse those documents as HTML, not XHTML. Browsers simply correct invalid HTML that you're sending. Most of the time, there's absolutely no need to confuse browsers by serving such documents with XHTML doctype; there's not benefit in changing doctype from HTML to XHTML. As always, you can find tons of info on this subject online. HTH. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 15, 3:48 am, T.J. Crowder t...@crowdersoftware.com wrote: Heya, I thought it wouldn't come as a surprise that using XHTML makes no sense... Hey, HTML and CSS make no sense, let alone XHTML. But that's OT. :-) I'm just saying, the doctype that seems to be recommended is XHTML transitional, so that's what I use as I don't have a strong reason for I would certainly not recommend any type of XHTML doctype (when designing apps for general web). I don't see a reason for Prototype to recommend or encourage it either. As I said, there's no point in using xhtml 99% of the time (for the reasons described well in that article). That's pretty much all I'm saying ;) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 14, 4:15 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi, Isn't the recommended doctype when using Prototype xhtml transitional? br doesn't validate in xhtml transitional, it has no closing tag. I thought it wouldn't come as a surprise that using XHTML makes no sense http://hixie.ch/advocacy/xhtml. I know that Rails blindly uses XHTML. I remember Mislav mentioned that the issue was brought up on Rails mailing list but that noone seemed to care http:// mislav.uniqpath.com/rails/cargo-culting-xhtml-considered-harmful/ I'm not sure about recommended doctype, but I know that Prototype most likely doesn't work when served and parsed as application/xhtml+xml. Object model of documents parsed as XML is different: from what I remember, `document.write` doesn't work, `innerHTML` parser works differently, etc. All of the Prototype's unit tests use XHTML doctype, but fail to set proper content-type response header. This means that browsers are told to *parse and render page as HTML*, but are actually being served a so- called xhtml tag soup http://en.wikipedia.org/wiki/Tag_soup, which they simply correct into proper HTML (this correction also takes time, of course, but I'm not sure if it's significant). I personally have never seen Prototype tests run as real XHTML, so I can't be sure that it works. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: how use fire + bind/curry?
On Jun 11, 8:00 pm, Miguel Beltran R. yourpa...@gmail.com wrote: Hi list Trying to do made more functions generics now I try with fire option. But this not work ('element1').observe('change', function(evt){document.fire.curry(evt.element()).('space:observer');}); ('element1').observe('change', function(evt){document.fire.bind(evt.element()).('space:observer');}); ('element1').observe('change', function(evt){document.fire.('space:observer').curry(evt.element());}); ('element1').observe('change', function(evt){document.fire.('space:observer').bind(evt.element());}); There are too many permutations here to find correct way by trial and error ; ) You haven't really said what it is you're trying to do, or at least what you expect event handler to be - its `this`, its `arguments`, etc. Perhaps, you want something like this: $('element1').observe('change', function(ev) { document.fire('space:observer', { element: ev.element() }); }); ... document.observe('space:observer', function(ev) { console.log('event: %o, element: %o', ev, ev.memo.element); }); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 13, 3:32 am, T.J. Crowder t...@crowdersoftware.com wrote: [...] I don't think browsers ever put a \r before the \n in textareas, but I couldn't swear to it, so if it were me I'd probably hedge my bets and optionally include it: after = before.escapeHTML().replace(/\r?\n/g, br/); br/ should really be br 99% of the time ; ) [...] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: When are is final 1.6.1 going to be released?
On Jun 3, 4:09 am, KHelal karim.he...@gmail.com wrote: Hi all, Do you have any ETA on the final version of 1.6.1? IE8 is being force- fed by Microsoft and is starting to show usage for some of our customers. Hopefully, within a week or two. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: evalScripts and functions
On May 24, 10:24 am, Michael mich...@michaelminella.com wrote: I understand how Prototype works with regards to the removal of script tags after evaling the results of an Ajax request. However, I was doing some research and am now starting to wonder why the way I declare functions works. According to the Prototype documentation, you need to declare the function and assign it to a global variable: myFunction = function() {alert('hi');} It's usually a good idea to avoid undeclared assignments (for clarity/ compatibility/robustness). Instead, consider assigning to a `window` property directly - window.myFunction = function(){ ... }; - or if you're extra cautious about assigning to an unpredictable and not-necessarily existent host object (which `window` happens to be), assign to an actual Global object - var global = (function(){return this;})(); global.myFunction = function(){ ... }; That makes sense. However, in all of my scenarios, I've declared functions like this: var myFunction = function myFunction() {alert('hi');} Named function expressions, which you're using here, have their own quirks across browsers. Be careful with them. and the calls to myFunction work just fine. My question is...why does my way work? According to the Prototype documentation, the local variable myFunction should be thrown away after the eval. Any insight anyone can provide would be appreciated. Thanks in advance! `myFunction` probably leaks into a global scope from within somewhere else. There's no other way for it to be declared globally, as long as `eval` (used internally by `evalScripts`) is spec-compliant and so evaluates in the scope of its caller - an internal anonymous function in case of Prototype.js. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Prototype/Javascript scoping question
On May 16, 12:51 pm, Tobie Langel tobie.lan...@gmail.com wrote: FYI, fastest way is #1 as you're avoiding creating a closure altogether (just using Function#call internally). Isn't closure formed in both #1 and #2 as soon as FunExpr. (passed to `each`) is being evaluated? [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Check element class against array
On May 14, 8:24 pm, Gabriel Gilini gabr...@usosim.com.br wrote: On Wed, May 13, 2009 at 3:34 PM, louis w louiswa...@gmail.com wrote: I have an array containing a number of strings. I would like to continue exucuting my script only if an item has ANY/ALL of the strings assigned as a class name. $A(['foo', 'bar', 'foob']); Is there an elegant want to do this without having to loop through the items? Supposing you have the aforementioned element stored in the - elm - variable, and the classes' array in the - classesArr - variable: var classNamesRegex = new RegExp('\\b(' + classesArr.join('|') + ')\\b'); // Generates /\b(foo|bar|foob)\b/ if(!classNamesRegex.test(elm.className)){ window.alert('get me out of here'); } Please don't use boundaries to separate class values. I wonder who came up with this silly idea and why it keeps circulating around. /\bfoo\b/ matches values such as foo-bar which is, of course, wrong. Class tokens are separated by whitespace (well, technically there's a particular set of characters. HTML5, for example, defines them as - [\ \u0020\\u0009\\u000A\\u000C\\u000D]) and so regex to match certain className should be wrapped with whitespace characters (as well as start of line/end of line tokens) - /(^|\s)foo(\s|$)/ -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Classes vs Objects - Best Practice?
On May 11, 6:38 pm, Ryan Gahl ryan.g...@gmail.com wrote: Louis, Your error is that you should not be using the new keyword before Class.create() Class.create() is a helper function that essentially just returns a function. Note, in js, all named functions are considered constructors. They don't really have to be named (i.e. have an identifier - optional in FunctionExpression and required in FunctionDeclaration). All Function objects have internal [[Construct]] method and so can be initialized with `new` (which happens to invoke that internal method) ;) var j = new (function(name){ this.name = name; })('John'); j.name; // John OP's issue is related to the fact that `new` operator has a higher precedence than a function call in an expression: function F(){}; new F(); // [[Construct]]'s `F` new (F()); // Calls `F`, then [[Construct]]'s *return value* of that function So technically speaking, OP only needed to wrap `Class.create` expression with parenthesis, to make sure he's constructing return value of `Class.create`'s invocation and not `klass` function itself. var j = new Class.create({initialize: function(name){ this.x = 5; }}); j.x; // undefined var j = new (Class.create({initialize: function(name){ this.x = 5; }})); j.x; // 5 [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Extracting methods from codebase
On Apr 30, 11:54 am, Bertrand bertrand.char...@gmail.com wrote: Because there's a reason why Prototype, jQuery and the likes have such success. It lies in the fact that the developers are very talented and provide good code. Unfortunately, I'm kind of new to the whole Success doesn't always mean quality. Quality is often far from the main driving force. When it comes to Javascript libraries, ease of use, documentation quality and community play much bigger role in library's success than the quality of its code. Also don't forget that libraries that's being around for a (relatively) long time carry a burden of back-compatibility; If something is known to cause problems or performs in not the most efficient way, it's not always (if ever) possible to *just get rid of it*. Prototype.js is also designed in such way that many of its internals are tightly coupled and rely on each other. This means that it won't be easy to just cut `insert` method out of the source; you would need to take care of all the dependencies and branches that it uses. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Extending Prototype.BrowserFeatures the right way?
On Apr 22, 7:14 pm, Tim Snadden tim.snad...@gmail.com wrote: Hi all - I've extended Prototype.BrowserFeatures and thought I'd check with those in the know whether this makes sense as an approach or how it could be improved. Basically I want to test to see if the browser supports setting border-radius with CSS so that I can only use javascript methods for browsers that need it. alphaPNG is to test whether or not I need to use any hacks to make transparency work for IE6. I don't know of any way to actually test that feature so I just basically sniffed for 'less than IE7'. Object.extend(Prototype.BrowserFeatures,{ borderRadius: ( function(){ var radiusTest = $(document).createElement('div'); try { return !!( radiusTest.getStyle('-webkit-border-radius') !== undefined || radiusTest.getStyle('-moz-border-radius') !== undefined || radiusTest.getStyle('border-radius') !== undefined ); } catch(x) { return false; } }() ), alphaPNG: !(Prototype.Browser.IE !window.XMLHttpRequest) }); Thanks for your input, Tim You shouldn't need try/catch for merely testing types of certain properties. I would check `borderRadius` first, since it's a standard CSS3 property. `el` also needs to be `null`ed. I think a more descriptive name for the test would be `hasBorderRadius` (instead of `borderRadius`) - to denote that it is of a boolean value. ... hasBorderRadius: (function(){ var el = document.createElement('div'); var s = el.style; var result = typeof s.borderRadius == 'string' || typeof s.MozBorderRadius == 'string' || typeof s.WebkitBorderRadius == 'string'; el = null; return result; })() ... -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: 1.6.1_rc2 checkDeficiency('applet') issue
On Apr 17, 5:44 pm, Greenosity greenos...@gmail.com wrote: The call to checkDeficiency('applet') in prototype.js version 1.6.1_rc2 causes a problem with IE 8 on a computer that does not have Java installed (for me, Vista). Creating the applet element triggers IE8 to display the following warning: The page you are viewing uses Java. ... Uh, no it doesn't. This is not good. Interesting. Can you check what `navigator.javaEnabled()` returns for you when java is disabled? I wonder if there's any way to test this behavior without actually causing a warning (is it a modal dialog, btw?). Maybe global `HTMLAppletElement` is only present when java is installed? I tried disabling Java plugin in IE8 but a warning never appears. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: 1.6.1 RC2: What happened to $A()?
On Apr 15, 11:19 am, mr_justin gro...@jperkins.otherinbox.com wrote: [...] (). Looks like this is one regression bug that has really helped us out. That's funny : ) Yes, I'll definitely make a patch to type convert `iterable`. Thanks for catching that. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: 1.6.1 RC2: What happened to $A()?
On Apr 13, 6:25 pm, mr_justin gro...@jperkins.otherinbox.com wrote: This is a regression. OK, that's good to hear. so `$A('one', 'two', 'three')`, as in your example, should produce - ['o', 'n', 'e']. That doesn't seem right. In the past, it has always produced a 3-item array out of the arguments, not the characters of the first argument. Essentially behaving just like a normal square bracket-declared array. I used this technique quite a bit because it was easy to go from ['one', 'two', 'three'] to $A('one', 'two', 'three'). At least 1.6.0.3 has already been operating on `iterable` which is a first argument of `$A`. Do you remember which version was flattening all of the arguments? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: 1.6.1 RC2: What happened to $A()?
On Apr 13, 12:51 pm, mr_justin gro...@jperkins.otherinbox.com wrote: Trying out the RC2 and ran into some trouble with existing code working with the new version of prototype. Old code: $A('one', 'two', 'three') This no longer works and requires either to wrap the arguments in square brackets or use the $w() method. This change doesn't seem to be documented, but on an existing (large) project, the impact is quite large. Not on the scale of the Hash change in 1.6.0, but still, big enough to give pause. Is it safe to just go ahead and start updating our code to use the new syntax or was this issue introduced inadvertently? Here's the changeset that introduced the issue:http://github.com/sstephenson/prototype/commit/1a375daea249ee6a42a1dd... This is a regression. $A('foo') should return ['f', 'o', 'o'] (since 'foo' is a string and strings are extended with `toArray` which delegates to `split('')`, essentuially returning an array of string characters). AFAIK, arguments other than first were never taken into account, so `$A('one', 'two', 'three')`, as in your example, should produce - ['o', 'n', 'e']. The fact that non-object values now throw errors is a clear mistake on our part. We need to explicitly type- convert any value to an object before attempting to use it on RHS of `in`: function $A(iterable) { if (!iterable) return []; if ('toArray' in Object(iterable)) return iterable.toArray(); var length = iterable.length || 0, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } Hope this helps. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Why Element.Remove doesnt clean events and storage?
On Apr 9, 2:20 pm, buda www...@pochta.ru wrote: And how about this behaviour as an option parameter in Remove method? I dont stand on it but to realise every time helper method - is not write way! We don't remove event handlers because `remove` is not a final operation. `remove` removes an element from the document, but it doesn't destroy an element per se. A reference to an element is returned from `remove` and can then be reinserted into a document, modified or whatever. We considered an opt-in solution such as optional parameter, but never got a chance to actually implement it. Mind creating an enhancement ticket for this? [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: readAttribute not working as expected in IE7, 1.6.1 RC2
On Apr 9, 6:34 pm, Jason jbo...@gmail.com wrote: Starting with 1.6.1 RC2, I discovered that using Element#readAttribute with an attribute name of store causes IE7 to return a function instead of null when the property doesn't exist: function() { var a = update([this], arguments); return __method.apply(null, a); } This didn't happen in Firefox or IE8, only IE7. Can anyone confirm this? Testing for null on this attribute was Yes, I can confirm this. unpredictable across browsers. My solution was to not use the attribute name store. Is this a bug? I would say yes, it's a bug, since `readAttribute`, IIRC, guarantees to return either `null` or a string value. You'll be surprised but there are about 50 (if not more) other names that will cause similar outcome. The reason for this is that DOM in IE8 is broken as designed and Prototype is being careless with its brokenness. `getAttribute`, which `readAttribute` uses internally does not differentiate between attributes and properties. Since prototype.js directly extends elements with Element methods, all of them are mistakenly returned by `getAttribute`: typeof $(myElement).getAttribute('show'); // function 1.6.1RC2 introduced another method - `store` - and is exactly why you're having this issue. This is, of course, yet another reason not to extend native elements, but a temporary fix could be for a `readAttribute` to ensure that only `null` or string value is allowed to be returned (i.e. turning non-string values such as function to `null`). I would also recommend not to introduce custom attributes when including Prototype. Could you file a bug? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: IE8 compatibility
On Mar 22, 4:42 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Juriy, Btw, as of today, all DOM tests fully pass on IE8. T.J., do you mind giving it a spin? On IE7, you mean? (I have only IE6 and IE7 systems right now.) I meant IE8 :) IE7 on Windows still has issues in form, dom, and selector tests with the trunk (assuming git pull brings me up to date, I'm a git newbie): ** selector_test.html: testSelectorWithEmpty 0 assertions, 2 failures, 0 errors Failure: #level1 *:empty expected: [span id=level3_1, span id=level3_2, div id=level2_3], actual: [span id=level3_1, span id=level3_2, em id=level_only_child, div id=level2_3] Failure: newlines count as content! expected: [], actual: [em id=level_only_child] Andrew knows about this issue and, afaik, should be taking care of it shortly. ** dom_test.html: testViewportDimensions 1 assertions, 1 failures, 0 errors Failure: NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS expected: 523, actual: 485 ** form_test.html: testFormMethodsOnExtendedElements 4 assertions, 1 failures, 1 errors Failure: assert got undefined TypeError: Object doesn't support this property or method, error= ([object Error]) Thanks. I could reproduce this in IE6 and just pushed a fix http://github.com/sstephenson/prototype/commit/2c986d8eaff47a6a181a1c1f43d88443cedfa418 Can someone point me to an IE7 setting that controls whether JavaScript can change the size of the window? The DOM test may be running afoul of a setting I can't immediately find (in a rush this morning). I only have IE6 and IE8, both with default settings (I think) inside virtual machine. Both fully pass DOM tests (including window resizing tests) When I get a chance, I'll fire up an IE6 VM and see how it does. Great. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: IE8 compatibility
On Mar 21, 10:16 pm, Completely Free Dating - Andrew andrewjdi...@gmail.com wrote: Hi All, This appears to be a bug in IE, not prototype, as it is not applying the class attribute using the specified 'className' property (http:// msdn.microsoft.com/en-us/library/ms533560(VS.85).aspx), but using the attribute name 'class' instead, so as a work around I have added this around line 1809 in prototype.js: if (Prototype.Browser.IE (parseFloat(navigator.appVersion.split (MSIE)[1]) = 8.0) (name == className)) name='class'; Do not ever rely on browser sniffing. The className issue is fixed in a trunk with a proper feature test [1]. Ironically, the test still happens in a huge `Prototype.Browser.IE` branch and only tests for IE 7,8 differences. We'll take it out of there as soon as possible. Btw, as of today, all DOM tests fully pass on IE8. T.J., do you mind giving it a spin? [...] [1] http://github.com/sstephenson/prototype/commit/30c1935cdb6f3a8d850dab8b07a37918740233fb -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: #readAttribute('class') returns wrong results in IE8 - where is solution?
On Mar 20, 12:09 pm, keemor kee...@gmail.com wrote: Hello, I have exactly this problem:http://prototype.lighthouseapp.com/projects/8886/tickets/364-ie8-does... I the last comment, Andrew Dupont says: This was fixed a while back when I made all the changes necessary to get the DOM tests passing in IE8. I'm very glad, but where can I find this solution? I'd like to patch library before 1.6.0.4 comes up. I got git clone git://github.com/sstephenson/prototype.git but there is no whole build library in 'dist' dir. Am I missing something? Thank you for your hard work Guys! Try again. It should work with today's revision. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: help with basic regular expression
On Mar 16, 9:44 pm, RobG rg...@iinet.net.au wrote: On Mar 17, 4:10 am, kangax kan...@gmail.com wrote: On Mar 16, 1:13 pm, arkady arkad...@gmail.com wrote: if trying to strip off the everything before the body and everything after /body response.replace(/.*(?=body)/, '').replace(/(\/body).*/, '$1'); That seems a bit risky, the string may not always have lower case tag names and the body opening tag may include attributes. New lines in I actually took OP's issue too literally; i.e. - strip off everything before the body and after /body : ) the string might trip it up too. In any case, it doesn't work for me at all in Firefox 3 or IE 6. Which string did you feed it with? dot doesn't match newlines, does it? [\s\S] should match: response.replace(/[\s\S]*(?=body)/i, ''); An alternative, provided all new lines are removed, is: response.match(/body.*body/i)[0]; or response.replace(/\s/g,' ').match(/\body.+body\/i)[0]; A sub-string version is: var start = response.toLowerCase().indexOf('body'); var end = response.toLowerCase().indexOf('/body') + 7; var theBody = response.substring(start, end) Obviously, string-based matching should be marginally faster than regex, especially when that regex is based on a relatively slow positive lookahead : ) var response = document.documentElement.innerHTML; console.time(1); for (var i=0; i100; i++) { var l = response.toLowerCase(); response.substring(l.indexOf('body'), l.indexOf('/body') + 7); } console.timeEnd(1); var response = document.documentElement.innerHTML; console.time(2); for (var i=0; i100; i++) { response.replace(/[\s\S]*(?=body)/i, '') .replace(/(\/body)[\s\S]*/i, '$1'); } console.timeEnd(2); //1: 186ms //2: 2664ms -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 15, 9:06 am, Robert Kieffer bro...@gmail.com wrote: On Mar 14, 8:24 am, kangax kan...@gmail.com wrote: Why not combine two? ... function() { if (arguments.length) { var ll = arguments.length; args.length = l + ll; while (ll--) { args[l+ll] = arguments[ll]; } } return fn.apply(context, args);} } This implementation won't work. args.length must be set for each call. Failure to do so will result in bugs like this (since args is shared across method calls): foo = someFunc.bind(1,2) foo(3) // calls someFunc(1,2,3) foo() // also calls someFunc(1,2,3)! (args unchanged from before) Thus, you have to move the args.length= assignment above the if block: function() { var ll = arguments.length; args.length = l + ll; if (ll) { while (ll--) { args[l+ll] = arguments[ll]; } } return fn.apply(context, args);} } ... and since if (ll) is redundant with while (ll--), you can get rid of it: function() { var ll = arguments.length; args.length = l + ll; while (ll--) args[l+ll] = arguments[ll]; return fn.apply(context, args);} } ... which, is the implementation I proposed in my previous post. Understood. Regarding your point about the 4 possible outcomes. We're not disputing the implementation for cases 1 or 2 - it's cases #3 and #4 that are what we care about, both of which end up having to run thru the above code. Given this, my claim about this being a tradeoff still stands. Reusing the 'args' array is faster if arguments are passed, but is slower if they aren't, because you have to take the time to do args.length=... in either case. My performance tests show this, and I still think it's a good tradeoff to make. Yes. As I said before, this is a good optimization of partial application (cases #3 and #4). I like it and I don't have problems with it being in a Prototype. All I'm saying is that optimizing cases #3, 4 is not as important as optimizing cases #1, 2, as these are the most widely used ones. Of course, it doesn't make your optimization any less useful for a particular use case. Tobie, are you OK with these changes? Regarding the viability of bindAsEventListener, I see that as a separate discussion. The kind of performance tweaks we're talking Yes, we need a new thread for that. about just don't matter that much where bindAsEventListener is used (since it's unlikely event listener functions will be called more than a few dozen times per second.) That said, I do agree that it is a bit Actually, frequent event listeners (mousemove, mouseover, mouseout, scroll, resize, etc.) are called quite often. I never use Prototype's bind on them, for example, as it slows things down noticeably. It's just that `bindAsEventListener` is practically useless, since you rarely want to curry arguments over event listeners. of a wart on the Prototype API. On the more general topic of binding arguments, Prototype has gone down a bit of a bad path with all of this. I've never seen a real need for this support in the bind() method. It's just as easy to bind values via closure context as it is to do using bind(): We already discussed the issues of binding earlier in this thread : ) var a = 1, b = 2; var foo = function() { // reference something with a b }.bind(obj); Now imagine `foo` is declared non-locally (in a different execution context) This code would clean up nicely if Prototype deprecated support for argument binding. Not that that's gonna happen. I'm just saying. :-) This is very unlikely. ES3.1 `Function.prototype.bind` does partial application. When browsers implement `bind` natively, it will be easy to delegate Prototype's bind to native one (or replace it altogether) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 15, 10:35 am, Tobie Langel tobie.lan...@gmail.com wrote: [...] The difficulty of abstracting your solution comes from the need for the bound function to keep a reference to the original length of the array so a to reset it before passing it to the original function. I suspect that the cleanest solution might be to keep a generic array updating method and reset the original before calling it. Isn't that what your internal (used with `Function.prototype` extensions) `update` does? function update(array, args) { var arrayLength = array.length, length = args.length; while (length--) array[arrayLength + length] = args[length]; return array; } -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 15, 10:54 am, Ryan Gahl ryan.g...@gmail.com wrote: So, (sorry not to capture all this in a single post)... To re-iterate, Kangax, you _should_ be using .bindAsEventListener in your first case if you want to guarantee backwards X-browser support. What do you mean by backwards X-browser support? Just like I said, IE (including v. 6) supports `attachEvent` which *does* pass event object as a first argument to event listener. If you use `attachEvent` (or, more likely, `observe`) you don't need to touch `window.event`. It is intrinsic event handler that doesn't pass event as a first argument. So, to reiterate, you do not need `bindAsEventListener` when using `observe` and not partially applying event listener : ) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 14, 9:15 am, Robert Kieffer bro...@gmail.com wrote: On Mar 13, 4:33 pm, Tobie Langel tobie.lan...@gmail.com wrote: It's this latter case where having the args array cached provides significant performance benefit, which I would argue is worth doing, even if it slightly lessens the performance of someFunc() with no arguments. That's the tradeoff we're talking about. I don't think that tradeoff is necessary, actually. Are you saying you don't think we should make this tradeoff (i.e. we should use Kangax's code) or that you believe we can get the best of both worlds? If the latter, I'm not sure how you manage that. We're either using Kangax's code for the inner-most function or the Improved code. (As a reminder to readers, both implementations are available at the bottom of the source on this page:http://www.broofa.com/Tools/JSLitmus/tests/PrototypeBind.html ). Here are the relevant snippets: Kangax: function() { return arguments.length ? fn.apply(context, args.concat(_slice.call(arguments))) : fn.apply(context, args); } Improved: function() { var ll = arguments.length; args.length = l + ll; while (ll--) args[l+ll] = arguments[ll]; return fn.apply(context, args); }; Where argumens.length is zero, the Improved code has *slightly* more overhead. But in the case of arguments 0, the Improved code reuses the args array instead of making the _slice.call(), which appears to be more performant in most cases. Ergo, it's a tradeoff of some sort - pick your implementation - and I feel the Improved variant provides more desirable performance characteristics. It provides the best performance for the slowest case (the weakest link). So for most projects I think it will provide better real-world performance. Why not combine two? ... function() { if (arguments.length) { var ll = arguments.length; args.length = l + ll; while (ll--) { args[l+ll] = arguments[ll]; } } return fn.apply(context, args); } ... On a side note, I am pretty sure that *most* of the projects do *not* do partial application. This means that second branch (the one that uses your optimization) is rarely entered. To make it clearer, let's mark 4 possible outcomes: var slice = Array.prototype.slice; function bind(context) { var fn = this; // plain version, no partial application if (arguments.length == 1) { return function() { return arguments.length // 1 ? fn.apply(context, arguments) // 2 : fn.call(context) } } // partial application var args = _slice.call(arguments, 1); return function() { return arguments.length // 3 ? fn.apply(context, args.concat(slice.call(arguments))) // 4 : fn.apply(context, args) } } When is #1 function used? When there was no partial, but arguments were passed to bound function: function foo(){}; var bound = foo.bind({}); bound('blah'); When is #2 function used? When there was no partial and arguments were not passed to bound function: function foo(){}; var bound = foo.bind({}); bound(); When is #3 function used? When there was partial and arguments were passed to bound function. This is your optimization branch. function foo(){}; var bound = foo.bind({}, 'bar'); bound('baz'); And finally, when is function #4 used? When there was partial and arguments were not passed to bound function. function foo(){}; var bound = foo.bind({}, 'bar'); bound(); In my opinion, first and second versions are the ones that are used more often (but I would want to hear other folks). These 2 versions never use arrays' concatenation (since there are no partial arguments to concat with in the first place). -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 14, 11:43 am, Tobie Langel tobie.lan...@gmail.com wrote: I'd like to see how we can combine all of this elegantly with bindAsEventListener and curry. I personally don't understand the need for `bindAsEventListener` at all. It's the most misunderstood method in Prototype. Its scope of use is so narrow that it makes sense to deprecate it. To explain: `bindAsEventListener` guarantees that an event object is being passed as a first argument to an event handler. The problem is that every single use of `bindAsEventListener` that I've seen is used with `observe`. When `observe` uses `attachEvent` (in MSHTML DOM) it already does pass event object as a first argument to event handler (which makes `event || window.event` in `bindAsEventListener` redundant). `bind` suffices most of the time, except when a partial application is used (or, of course, if you're not using `observe` in the first place, but an intrinsic event attribute). Another problem is that `bindAsEventListener` is almost *never* used with partial application (look at Scriptaculous, for example, or practically any other snippet on the web). What this all means is that these 2 expressions are functionally identical (considering that they are called from within the same execution context): myElement.observe('click', onClick.bind(this)); myElement.observe('click', onClick.bindAsEventListener(this)); And there's absolutely no need to use the latter one. myElement.observe('click', onClick.bindAsEventListener(this, 'foo', 'bar')); - on the other hand, ensures that an event handler, when called, will have an `event` object as a first argument (i.e. foo and bar will be second and third arguments, rather than first and second). This is exactly what's misunderstood about this method. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: $$ failing in FF3.1b3
On 10 Mar, 07:25, Jim Higson j...@wikizzle.org wrote: On Monday 09 March 2009 21:51:05 kangax wrote: It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. Makes sense. if( !hasOwnProperty ) hasOwnProperty = function hasOwnProperty(){ ... }; I was thinking of something like: var hasOwnProperty = (function(){ var hop = Object.prototype.hasOwnProperty; if (hop) { return function(obj, prop) { return hop.call(obj, prop); } } Why not: if( hop ) return hop; Does hop need to be wrapped? Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why not just encapsulate the `call`? return function(obj, prop) { if (obj) { var c = obj.constructor; if (c c.prototype) { return obj[prop] !== c.prototype[prop]; } } return null; } })(); This fallback not bullet-proof, but should cover most of the cases. Yep, the tragic case where something just happens to have a property in a prototype *and* the same property directly - could happen! Still, I think the code above would be fine for almost all cases. Another edge case is when an object does not expose (think host objects in MSHTML DOM) or is missing `constructor` altogether (e.g. if it was overwritten). I remember seeing solutions involving deleting object's `__proto__` (if supported), checking property with `in` and then restoring `__proto__` back. Relying on such manipulations is like playing with fire, of course : ) It is probably also slower. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: $$ failing in FF3.1b3
On Mar 10, 11:30 am, Jim Higson j...@wikizzle.org wrote: On Tuesday 10 March 2009 14:06:17 kangax wrote: [...] Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why not just encapsulate the `call`? Ah, yes, I imagined we'd be adding hasOwnProperty to Object.prototype to make the bad browsers like the good. Given the subject, probably not wise :-) We thought about it too, of course. I actually don't mind extending native prototypes if it is done to fix broken behavior. Unfortunately, in Safari 2 adding `hasOwnProperty` to `Object.prototype` would *not* give it a DontEnum flag and so it would be iterated over with for/in. Oh well : ) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 10, 12:41 pm, Robert Kieffer bro...@gmail.com wrote: [...] - bind() is so ubiquitous for us that performance is a top priority. Your version is still slower than it could be ; ) `$A`, `shift`, `apply` - all of those slow things down for no good reason. Take a look at http://prototype.lighthouseapp.com/projects/8886/tickets/215-optimize-bind-bindaseventlistener#ticket-215-9 [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Proposal for improving bind() + adding unbind() support
On Mar 10, 3:27 pm, T.J. Crowder t...@crowdersoftware.com wrote: I do agree there are just times when .bind() is called for, but I am fairly certain the majority of people WAY overuse it. +1 to that, where you're defining the function inline. Where you're not, while this may be faster: var self = this; handler = function() { self.realHandler(); } ...bind is (for me) much clearer: handler = realHandler.bind(this); But again, yeah, when you're defining the function inline _anyway_, take advantage of the native closure stuff. I absolutely agree that not using `bind` with local function works well and works fast. I also agree that `bind` is overused. What I want to stress, though, is that when binding a non-local function, `bind` actually *eliminates an extra closure* that would otherwise be implicitly created. You either save on memory, or on runtime performance: 1) Bound event handler is augmented and is slower than original one (at runtime), as it has to go through function call, `apply` invocation and even worse - `$A` normalization, etc. (in older versions of prototype) this.element.observe('click', this.onClick.bind(this)); 2) Non-bound event handler is faster at run time, as it accesses `onClick` from the proper object directly, but presumably consumes more memory (due to extra closure, created during function expression evaluation) var self = this; this.element.observe('click', function(){ self.onClick() }); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: $$ failing in FF3.1b3
On Mar 9, 6:57 am, Jim Higson j...@wikizzle.org wrote: On Friday 06 March 2009 15:26:49 kangax wrote: [...] It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. Makes sense. if( !hasOwnProperty ) hasOwnProperty = function hasOwnProperty(){ ... }; I was thinking of something like: var hasOwnProperty = (function(){ var hop = Object.prototype.hasOwnProperty; if (hop) { return function(obj, prop) { return hop.call(obj, prop); } } return function(obj, prop) { if (obj) { var c = obj.constructor; if (c c.prototype) { return obj[prop] !== c.prototype[prop]; } } return null; } })(); This fallback not bullet-proof, but should cover most of the cases. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opinions appreciated on approach to Getters and Setters.
On Mar 9, 9:50 am, webbear1000 normpo...@hotmail.com wrote: I'm interested in your opinions on how I'm handling getters and setters in classes. Can you see any problems with my approach and what trouble might I be getting myself into? The huge body of my programming work has been with ASP.NET in VB and C#. So I'm used to classic OOP rather than prototype inheritance. With that in mind, I'm trying to semi-replicate getters and setters thus ... -- this.property = function(value){ if(arguments.length == 0){ return localVariable; }else{ localVariable = value; }} -- So if no arguments are passed, the function becomes a getter or a setter if there are arguments. What do you think? I don't see how prototypal inheritance would not allow you to implement property accessors : ) It's easy to do so with either plain javascript: function Person(name) { this.setName(name); } Person.prototype.getName = function() { return this.name; } Person.prototype.setName = function(name) { this.name = name; } or using abstraction that Prototype.js provides: var Person = Class.create({ initialize: function(name) { this.setName(name); }, getName: function() { return this.name; }, setName: function(name) { this.name = name; } }); I'm not a fan of one-method-accessor API. I like `getXXX`, `setXXX` notation more, as it seems to be more descriptive and less error- prone. You are obviously free to use whichever you thinks suits better. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Class.create and klass() how do you use it folks?
On Mar 8, 8:58 pm, dzw! bartoszw...@googlemail.com wrote: Tobie, thanks for answer it is helpful but still what I am looking for is practical advice how do you handle it in Prototype. Just to clarify: //this is what I would do without using Prototype function PureClass(){}; var wow = new PureClass(); wow.constructor; // and I would get PureClass // in Prototype the same var PureClassPrototype = Class.create(); var wow_prototype = new PureClassPrototype(); wow_prototype.constructor; // here I get not very helpfull klass() - ok it is helpfull and much better than nothing :) wow_prototype.constructor == PureClassPrototype; // true So I am maybe wrong but in JS I get what I want, but in Prototype my guess is that there is some other way[i have few ideas how to go around that but I am quite sure It is already solved].. It's not about JS or Prototype : ) `Class.create` knows nothing about a variable that you assign its return value to, so obviously, it can not declare a function with the name matching the name of that variable. This is just how ECMAScript is designed - expression on a right hand side of an assignment is not aware of its left hand side context. In the former example you declare a function. When you declare a function, whatever comes after function keyword and before opening parenthesis is a function Identifier. That Identifier is what you see when inspecting a function. `Class.create` is not aware of which variables it is being assigned to and even if it's being assigned to something at all (e.g. it could simply be called with a `new` operator - `new Class.create({})`). That is why `Class.create` always declares a klass function internally and it is that function that is being returned as its resulting value. Another thing worth mentioning is that function Identifier can not be set from a string value, without using `eval`. This means that even if you passed some name as a string value to `Class.create`, `Class.create` would not be able to declare a function with an Identifier matching that name unless it resorted to using `eval`: - var name = 'boo'; eval('function ' + name + '(){}')`; // function boo(){} You can always assign the name as a property of constructor's prototype explicitly and then use it for whatever purposes: var Foo = Class.create({ __id: 'Foo', ... }); (new Foo()).__id; // 'Foo' or something like that... You can, of course, always create constructors and their prototypes manually instead of using `Class.create`. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: How do you add methods to Form.Element
On Mar 7, 4:34 pm, Walter Lee Davis wa...@wdstudio.com wrote: I have this little bit of fluff: Element.addMethods({ addText: function(input, theText) { if(typeof input.selectionStart != 'undefined'){ var start = input.selectionStart; var end = input.selectionEnd; input.value = input.value.substr(0, start) + theText + input.value.substr(end); input.selectionStart = start + theText.length; input.selectionEnd = start + theText.length; input.focus(); } } }); But I want to add it only to Form.Element. I tried just tacking `Form.` onto the front of this, but all I got was a syntax error. Could someone clue me in how to add this method only to Form.Element? (Obviously, it doesn't make much sense in a regular Element context.) Form.Element.Methods.addText = function(){ /* ... */ }; Element.addMethods(); -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: $$ failing in FF3.1b3
On Mar 6, 5:49 am, Jim Higson j...@wikizzle.org wrote: On Thursday 05 March 2009 23:22:26 Tobie Langel wrote: Hi, Extending Object.prototype is regarded as a Bad Thing[1]. Does Prototype state anywhere that it doesn't work if Object.prototype is extended? If this is a stated limitation then fair enough I guess. I think not, but probably should. Mind creating a ticket? It seems like some parts of Prototype are designed to work with code that adds to Object.Prototype, for example in the Hash class we have: get: function(key) { // simulating poorly supported hasOwnProperty if (this._object[key] !== Object.prototype[key]) return this._object[key]; }, Not exactly. The fact that it works with augmented `Object.prototype` is only a consequence of another workaround :) The check is there to return only user-defined keys; Even without `Object.prototype` modification, you would get unexpected result when querying for, say, `toString` on a new Hash instance: $H({ foo: 1, bar: 2 }).get('toString'); It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. The main reason being that cross-browser support for hasOwnProperty is fairly recent (Safari 2 doesn't have it for example). I didn't know that, thanks for the info. What happens if you use hasOwnProperty in Safari 2? Use as in try to call it? IIRC, you get hasOwnProperty is not a function error. In other words, it simply doesn't exist : ) I don't have any usage statistics but I'd guess Safari 2 isn't used much now. According to Wikipedia the last version was 2.0.4, released 13th January 2006 and was replaced with 3.0.0 on the 11th June 2007. Yeah, Safari 2 is pretty close to being out. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: writeAttribute problem
On Mar 6, 7:07 am, RobG rg...@iinet.net.au wrote: [...] The differences are in the browsers' implementation of setAttribute, For example, using setAttribute with any of the intrinsic event handlers. Setting intrinsic event handlers was never supported, as far as I remember, although some users did indeed try to set them and wondered why it wouldn't work. As much as I'd hate to have another exception, this deficiency should simply be stated in a documentation. From the API perspective, it would probably be nice to have such support, but realistically it's pretty much impossible to implement; When a string is passed to `writeAttribute` it's practically impossible to tell whether this string corresponds to an event attribute (and so a simple property assignment should be performed). MSHTML, for example, defines a great deal of non-standard proprietary events; other browsers probably do the same thing. This rules out the possibility of some kind of static hash table to perform a test against. Determining event- like attributes by testing attribute name against /^on/ obviously fails miserable when given a custom property of the same pattern (e.g. on_myapp_started). Gotta love browser scripting... I personally almost always use simple property assignment, because I know what works and what doesn't; the speed benefits of `element.title = 'foo'` vs. $(element).writeAttribute('title', 'foo') are quite noticeable - no need to extend an element (that's O(N) in MSHTML), no need to call a method, no need to perform testing/translation/mapping inside that method, and so on and so forth. But then I miss on unified API, of course : ) Oh well. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: How do sort a hash.
On Mar 2, 9:58 am, Richard Quadling rquadl...@googlemail.com wrote: Hi. This might be one of the those odd situations where there is no answer, but I have a hash coming from PHP via JSONP to JS/Prototype. In IE and FF, the ordering is maintained. In Chrome the order is not maintained. The key part is numeric and is NOT in order. The value is sorted alphabetically. I suppose I could reverse the key/value pairing and work that way, but as the dox say, order is not guaranteed. Alternatively, as the data is going to be used for a select tag, can I sort the options by value? Look into `sortBy`: $H({ a: 20, b: 1, c: 10 }).sortBy(function(pair){ return pair.value; // or `return pair.key` (to sort by key) }); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: How do sort a hash.
On Mar 2, 11:23 am, Richard Quadling rquadl...@googlemail.com wrote: 2009/3/2 kangax kan...@gmail.com: On Mar 2, 9:58 am, Richard Quadling rquadl...@googlemail.com wrote: Hi. This might be one of the those odd situations where there is no answer, but I have a hash coming from PHP via JSONP to JS/Prototype. In IE and FF, the ordering is maintained. In Chrome the order is not maintained. The key part is numeric and is NOT in order. The value is sorted alphabetically. I suppose I could reverse the key/value pairing and work that way, but as the dox say, order is not guaranteed. Alternatively, as the data is going to be used for a select tag, can I sort the options by value? Look into `sortBy`: $H({ a: 20, b: 1, c: 10 }).sortBy(function(pair){ return pair.value; // or `return pair.key` (to sort by key) }); [...] -- kangax Argh!!! Thank you Kangax. I think this would be a great case for cross linking in the documentation. Hash can be thought of as an associative array, binding unique keys to values (which are not necessarily unique), though it can not guarantee consistent order its elements when iterating, but sortBy() can alleviate this issue. I actually find plain JS object sufficient most of the time for hashtable purposes. There are edge cases of course, but the performance gains of using plain objects (vs. `Hash` instances) can not be underestimated. Is there a way I can commit changes to the documentation? Sure. Create a ticket at Lighthouse and mark it as a documentation related enhancement. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Detecting an empty [] as a parameter to a function.
On Feb 25, 3:27 am, SWilk wilkola...@gmail.com wrote: [...] It's not that Richard does want to use it. It's that the PHP json_encode() function produces inconsistent output for empty arrays. If you do json_encode(array('key' = 'value'); you will get: { key: value }; And I assume that `json_encode(array('a', 'b', 'c'))` returns `[a, b, c]`? [...] I think in most cases: var _a=[]; _a = (Object.isArray(_a) !_a.length) ? {} : _a; var hash = $H(_a); That should work, but wouldn't you want to differentiate between these broken arrays (which should really be empty objects) and the actual empty arrays (returned from json)? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: When?
On Feb 25, 4:28 pm, Lox gecka.comp...@gmail.com wrote: [...] then prototype is becoming the mature and stable platform for standardised/cross platform javascript development. I understand that, and quite second that, but Peppy or Sizzle are much more faster at selecting elements by css selector witch, these days where javascript apps a getting bigger, is a must have. Someone talked about a lot of patches floating around. What are they? Where are they? Which patches? To me prototype can be optimized without changing its functionalities. Optimized how? The bug tracker is public and anyone is free to suggest optimizations, patches, tests, etc. I recently had a case where, in a well formed dom, it didn't find something like '#mydiv span.class' witch was anoying. I remember I had to find a workaround and also that Peppy found it Submitting bug is a good way to let developers know about it. Otherwise, the chances of it being found and fixed are much lower, as you can probably guess. In which browser did that query not work? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Inheritance with Class.create()
On Feb 19, 12:04 pm, dashifen dashi...@dashifen.com wrote: Hacking around a bit, I have a working solution. Where I used to say something like this.responders.afterOpen = someOtherFunction() if I instead simply make it this.afterOpen = someOtherFunction() I can specify two different afterOpen actions for two different instances of a Dashbox object and it works fine. That'll at least let me continue with the project, but I must admit that I'm baffled regarding why the behavior is different. Any light shed on that would be greatly appreciated. In short: When you access `this.responders` from within a subclass, it refers to `responders` properties of a superclass, since that is where it is found during a property lookup. You end up assigning values to the properties of the very same object. In long: When `this.responders.afterOpen` is evaluated, `responders` property is being looked up on an object referred to by `this`. That object (i.e. instance of `Dashdate` subclass) has no such property and so the next object in its prototype chain is being looked up - `Dashdate.prototype`. `Dashdate.prototype` doesn't have such property either, and so the lookup continues its way up the prototype chain, until it finally finds `responders` on `Dashbox.prototype` (where you inadvertently defined it with`Class.create`). The same process happens to resolve `afterOpen` property of `this.responders`. In the end, `this.responders.afterOpen` refers to a `Prototype.emptyFunction` (that you defined earlier) and your assignment overwrites it with a new value - `someOtherFunction`. To have a per-instance `responders` object, you can create such property on an object itself: var Foo = Class.create({ initialize: function() { ... this.responders = { ... }; ... }, ... }); To have a per-constructor (aka per-class) responders object, you can create it on constructor prototype's itself: var Sub = Class.create(Super, { ... responders: { ... }, initialize: function() { ... } ... }); The latter version is more memory efficient and is shared between all of the instances of a subclass. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Odd behaviour with chained calls.
On Feb 16, 11:10 am, Richard Quadling rquadl...@googlemail.com wrote: Hi. I want to set an error message for 20 seconds ... $('sessionError').update(o_E.responseText).show().hide.delay(20); The message is displayed correctly. But not hidden again after 20 seconds or so. Instead, I'm getting an error ... element.style is undefined. If I ... $('sessionError').update('An error').show().hide(20); at the command prompt in FB, then no problems. It seems delay is not working as I would expect. If I ... $('sessionError').update('An error').show().hide.delay(20); at the command prompt I get a number which I assume is the id of the timer so I can cancel it. Example online (requires a javascript console). Go tohttp://www.prototypejs.organd enter the following code into your javascript console. $('header').update('Prototype is quite good!').show().hide.delay(2) You will see the timer ID (4 in my case) and then the error message (after a little while). $('header').update('Prototype is quite good!').show().hide.delay(2) 4 $(element).style is undefined [Break on this error] $(element).style.display = 'none'; prototype.js (line 1349) The problem is that `hide` is not being called in a context of an element (but rather in a context of what `delay` specifies, which is a `hide` function itself). You can work around it by binding `hide` to `el` - in other words, making sure `hide` is to be called in a context of `el`: var el = $('header'); el.update('Prototype is quite good!').show(); el.hide.bind(el).delay(2); Even better, you can take advantage of `delay` being able to `curry` arguments of a reciever function: var el = $('header'); el.update('Prototype is quite good!').show(); Element.hide.delay(2, el); You can of course shorten it up further to something like: Element.hide.delay(2, $('header').update('Prototype is quite good!').show()); but I wouldn't, as it becomes rather cryptic : ) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Prototype bug?
On Feb 10, 10:05 am, Richard Quadling rquadl...@googlemail.com wrote: [...] So, it seems the only place where things go wonky is with eval(). `eval ` treats passed string as a Program, and evaluates it as such. There's nothing wonky about it : ) And the odd behaviour indicates that the toString() method isn't called on a string object when using eval(). More wierd. s1 = 2 + 2 2 + 2 String literal (primitive) is created. s2 = new String(3 + 3) 3 + 3 String object (with the internal [[Value]] set to 3 + 3) is created. eval(s1) 4 2 + 2 string primitive is evaluated as a Program and the result of its production is returned - `4` eval(s2) 3 + 3 `eval` does *NOT* do anything when you pass it a non-string value (which you do in this case - as `s2` is an Object, not a string). It simply returns what was given (which is an object with a value of 3 + 3) eval(s2.toString()) 6 Here, you take that String object and call its `toString` method. `toString` returns whatever is stored in String object's internal [[Value]] - that is 3 + 3. The returned 3 + 3 is a string primitive and so `eval` rightfully evaluates it, returning `6` Read ECMA specs URL http://bclary.com/2004/11/07/ if you really want to know what's going on under the hood (or even to be able to explain/understand simple examples like the above). You'll be surprised how clear everything becomes once you do ; ) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Prototype bug?
On Feb 8, 8:19 am, RobG rg...@iinet.net.au wrote: [...] It can hardly be called a bug when it does what the documentation says it does (I think works as designed is the polite response). The function itself is a bit pointless though, as are similar functions like isNumber, e.g. It's not pointless, but the scope of its use is indeed pretty narrow. Since neither `instanceof` operator nor `constructor` value check can not be relied upon when working with multiple contexts (frames), `Object.isString` is here to take care of it. AFAIK, ES committee is planning to finally document ECMA behavior in context of multiple global objects. Object.isNumber(NaN); // true Should it return `false`? 4.3.23 (NaN) says that ... This value is a member of the Number type.. Also, `typeof NaN == number`, NaN's `constructor` is `Number`, its [[Class]] is Number and it's [[Prototype]] references `Number.prototype`? Should we return `false` for practical reasons? And what should `Object.isNumber` return for +/-Inifinity? Adding `isFinite` to `isNumber` would be able to take care of both - `NaN` and `Infinity` cases. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Prototype bug?
On Feb 8, 9:59 pm, RobG rg...@iinet.net.au wrote: On Feb 9, 11:37 am, kangax kan...@gmail.com wrote: [...] Of course. `isNumber` (as it is in a trunk) will return `true` for Number *object*, while `typeof` will obviously return object. Whether Number objects are something that should be present in a script (rather than simple number primitives) is a different topic. Not at all, it's what I was asking for. I can't conceive of a situation where I would use isNumber (either in its current state or the proposed modification). I'm asking for a scenario where I would *use* it. I can't think of such scenario. I personally never use primitive wrappers explicitly (language does a pretty good job at wrapping primitives for me :)) [...] `isNumber` is an abstraction level. A noble (but ill-conceived) goal to unify type checking in diverse Javascript land : ) IIRC, the first version of `isNumber` looked like - `return typeof object == number`, and was added for *consistency* with other `Object.is*` methods - an infamous `isArray` was one of the first ones (following by others). Right now, I don't believe in generic solutions. The best way to go is to get familiar with language and use whatever fits the best. Nevertheless, checking for [[Class]] == Number seems to cover most of what masses desire (I'm also inclined to making `isNumber` filter out `NaN` and `Infinity`) Now you are back on topic. But [[Class]] can only be indirectly read via toString, so it isn't that reliable but might be good enough for most. Anything that has a [[Class]] of Number should probably emulate the properties of a native Number. The argument now goes to the same place as isArray - no need to repeat that here. :-) Getting [[Class]] is actually very much reliable (and is clearly documented in specs). I wrote a post about it some time ago [1]. The only downside is host objects, which are obviously permitted to have any [[Class]] value, including one of the native ones - Array, Function, Number, etc. IIRC, ES commitee is currently discussing this as well (Restrictions of [[Class]] values in context of host objects). [...] Given that in version 1.6.0.3 (the current version as far as I know) it is: isNumber: function(object) { return typeof object == number; }, the documentation is correct. Perhaps you meant change the documentation when the new version is published. Yes, we need to change it once the next release (current trunk) comes out. [...] [1] http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/ -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Prototype bug?
On Feb 7, 9:55 am, Jim Higson j...@333.org wrote: alert( Object.isString( foo )); // alerts string alert( Object.isString( new String( foo ) )); // alerts object I know why this happens - because Prototype uses the underlying typeof's understanding of type. Personally I think this is a bug though - Javascript is just being difficult here and Prototype should make stuff like this easier. It should return string regardless of how the string was created. Anyone agree I should file this as a bug, or is there a good reason the current behaviour is desirable? Javascript is actually quite flexible in this regard. If you want to check whether an object is a string *primitive* - use `typeof` and compare result to string. If you want to know whether an object is an instance of `String` function and inherits from `String.prototype`, use `instanceof` operator or check object's `constructor` property. If you need to use any of `String.prototype.*` methods, explicitly check for a presence of those methods on an object (since property lookup would propagate up the prototype chain) - e.g. `if (typeof object.charCodeAt == 'function') { ... }`; Finally, you can always check object's internal [[Class]] for a value of String (which all *native* String *objects* have). In a trunk of prototype.js, we use this last method - Object.prototype.toString.call(object) === '[object String]', where `call` first converts a value to an object and `Object.prototype.toString` then checks that object's [[Class]] value; It works for both - primitives and their object representations. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: validation for alphanumeric field/sequence
On Feb 6, 7:36 am, ColinFine colin.f...@pace.com wrote: On Feb 5, 9:29 pm, Michael mich...@vermontsnows.com wrote: Thank you all - Kangax's low profile technique works like a champ. Walter Lee: Regular expressions hurt my head. I will get there one day. The actual thing I am working on take about 100 alpha/numeric sequences of no real logical order... so making it in regular expression would take far longer (for me) then juts stubbing the 100 sequences in there. In Perl, I would not use regular expressions for this at all, but a hash: (equivalent of) var hash = {V3: true, B47242:true, V54000:true}; function checkValid(value) { return hash[value];} (or 'return hash[value] == true' if you're picky). This is a good idea in Perl because the language is optimised for accessing hash values: I don't know how true that is in javascript. I'm pretty sure property lookup is faster than regexp in Javascript too. The only downside to this approach is that there's no reliable (native) hash structure in Javascript. There also needs to be a boolean type conversion in your example, so that the function consistently returns either `true` or `false` (and not, say, `undefined` - for missing members). Regular property lookup is unreliable in such way that it takes object's prototype chain into account; That means there could be a conflict with `Object.prototype.*` properties - e.g.: `isValid('toString')` would return `Object.prototype.toString` which is a Function object and just like any object - type converts to `true` : ) In more generic method, it would probably be a good idea to use `Object.prototype.hasOwnProperty`, but in this case, strict equality operator would do: var isValid = (function(){ var hTable = { V3000: true, B47242: true, V54000: true } return function(value) { return hTable[value] === true; // return Object.prototype.hasOwnProperty.call(hTable, value); } })(); -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Hash#filter returns an Array?
On Feb 4, 1:20 am, T.J. Crowder t...@crowdersoftware.com wrote: [...] I'm not talking intuitive vs. non-intuitive (it's far too subjective), I'm talking the current documented (and implemented!) behavior. Remember that Enumerable is a contract, and code dealing with an Enumerable may not happen to know that it's dealing with a Hashy kind of Enumerable. :-) I do agree -- not that it matters! ;-) -- that for (say) 2.0, an argument can be made for changing Enumerable to say that for these kinds of methods, it returns an Enumerable (not an Array), and that concrete classes should (where appropriate) return the same type as the original. But (due respect to kangax) to me that's not a bug, that's a request for API enhancement, and not the kind of thing to do in a dot release or by making Hash a special case. Agreed. Bug or not bug, but we can't make this change without breaking backwards compatibility (just like we can't change form serialization to return an array, rather than an object - to preserve an order, as per specs; just like we can't rename `Element#wrap` which conflicts with textarea elements' wrap property in MSHTML DOM; just like we can't remove somewhat useless global `ObjectRange` and other, barely used globals) : ) Having said that, it always seemed unintuitive to me how enumerable integrates with hashes. Apparently, Ruby creators/users found this confusing as well. Just like all of the enumerable methods delegate its enumeration logic to Hash's _each (which enumerates over *all* keys, not just numeric ones as `Array.prototype._each` does), the logic of return value should be delegated to Hash too (imo) : ) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: validation for alphanumeric field/sequence
On Feb 5, 11:44 am, SWilk wilkola...@gmail.com wrote: Walter Lee Davis pisze: Isn't that just /(V3)|(B47242)|(V54000)/ ?? No, I think it is not. I think it should be /^(V3)|(B47242)|(V54000)$/ cause the 'bleblabliV3anything' should not match ;) There's no need for so many parentheses, really: /^(V3|B47242|V54000)$/ -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Songbird.
On Jan 30, 8:21 pm, Simon hs767...@gmail.com wrote: I get a is not a function message for some - but not all - of the prorotype commands. A minimal failing test case would help to identify the problem. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Songbird.
On Jan 29, 2:36 am, Simon hs767...@gmail.com wrote: Has anyone managed to get prototype running in Songbird yet? It is based on a Gecko renderer (like Firefox) but prototype seem not to run on it? Describe seem not to run on it. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Get first dd of a dl
On Jan 28, 2:09 pm, Anjanesh anjanesh.for...@gmail.com wrote: Im trying to get the first dd in dl but couldnt find a way to do so. $$('#someDIVId dl dd:first') n FireBug returns [dd, dd] Why does it return [dd, dd] - shouldnt it return just dd ? $$('#someDIVId dl dd:first-child'); Note that it will return an array, not a single element. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Possible incompatibility with JSON library?
On Jan 25, 7:30 pm, nlloyds nllo...@gmail.com wrote: I'm using this code: script src=http://www.json.org/json2.js;/script script runat=server src=https://ajax.googleapis.com/ajax/libs/ prototype/1.6.0.3/prototype.js/script script runat=server document.write(JSON.stringify([])); /script Which will output null with the Prototype script tag. If that tag is removed, the output is [], as I had expected. I believe the JSON library checks for at toJSON property on objects, which doesn't normally exist for Array, but does after Prototype.js augments them. Any ideas? I get [] with both prototype.js (1.6.0.3) and json2.js included: html head title/title /head body script src=http://www.json.org/json2.js;/script script src=https://ajax.googleapis.com/ajax/libs/prototype/ 1.6.0.3/prototype.js/script script type=text/javascript document.write(JSON.stringify([1,2,3])); /script /body /html -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Modifying prototypescriptaculous to work alongside jQuery
On Jan 24, 8:46 am, Радослав Станков rstan...@gmail.com wrote: Some time ago I played with prototype to make it more other frameworks friendly. So I wrapped all prototype.js code in closure, and in the end just pass to the window all needed objects defined by prototype, I excluded some objects like - Abstract, Field, Form, Try, Insertation, witch I think should not be global variables or are deprecated. So I I agree. It seems like those globals are almost never used. Unfortunately, there's to much of a legacy code relying on all of this. this way I released from the framework only the variable I needed and use. Obviously I didn't prevent javascript prototype extensions, but I didn't want to do so :) Err... Extending host objects is not any better (if not worse) than spawning global variables. You can find plenty of evidence in a bug tracker. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Garbage Collection in Javascript
On Jan 24, 11:40 am, Jonathan Rosenberg j...@tabbysplace.org wrote: This isn't specific to Prototype, but I figured this would be a good place to ask. I'm wondering how JS does garbage collection for objects created via new. The same way as objects created without `new` : ) GC removes objects that are no longer referenced. When it does so and how it does so is implementation dependent. If you want a certain object to be collected (whenever GC decides to do so), best you can do is to make sure nothing references that object. I doesn't seem at all obvious to me how this works, especially since there is not (as far as I know) a way to destroy an object. You're right. At least not in the standard specification (IIRC, JScript has some proprietary ways to force/trigger GC). -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Garbage Collection in Javascript
On Jan 24, 4:46 pm, Jonathan Rosenberg j...@tabbysplace.org wrote: [...] Ahhh ... so now you're starting to answer my original question: How does js do garbage collection? It's not as simple as it appears (at least, to me). So, can I assume that the naked new Ajax.Request object will be marked as garbage once it's done its job? Or is this up to each interpreter? If so, it would seem to be good practice to hold a ref to the object set to null once it's served its purpose. I would assume that naked `new Ajax.Request` is garbage collected as soon as it no longer needs to respond to events (i.e. when server response is completed and all callbacks, if any, are executed). Doesn't this behavior looks logical? If GC was allowed to collect objects that have asynchronous callbacks as their properties, the integrity of a program would be compromised and there wouldn't be much use in this asynchronous behavior at all. If don't recall any client that would behave in such way. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Modifying prototypescriptaculous to work alongside jQuery
On Jan 23, 10:11 am, Jan Hansen j...@nhl-data.dk wrote: I've been in the same problematic situation as well. However, we managed to use jQuerys noConflict mode in the 3'rd part component so that was great - but two questions: 1) Would it be possible to implement a noConflict mode in prototype? (why isn't there one already?) Because the actual philosophy of prototype.js goes somewhat against such mode. There are quite few native and host objects being augmented. There are also quite few global properties being created/ modified. Eliminating all of that would take a good portion of what prototype.js is all about. Such thing is also impossible to accomplish without breaking backwards compatibility. There are plans to change current approach in next major (backwards-incompatible) release but it's not clear when it will be done and how it will be done. 2) Why use the $ per default? is it by nature of some javascript thing I havent realized - or is it just by convention, aka could it have been P or £ just as well? `$` is just one of the characters allowed to be part of (and a first character) of `Identifier` (in other words, variable name) as per ECMAScript specs. Back in the days when libraries picked it up, it was probably due to the fact that it looked distinguishable enough and short enough for such frequently-used functionality (querying element by id and/or extending element) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Adding methods to Elements of a certain class.
On Jan 23, 10:29 am, Richard Quadling rquadl...@googlemail.com wrote: 2009/1/23 Richard Quadling rquadl...@googlemail.com: [...] This works ... $$('.tabC').each( function(el) { el.addSheet = addSheet.methodize(); }); I wouldn't suggest doing this. You are burdening all of those elements with a methodized function instead of putting that function (once!) and *sharing* it on `Element.prototype` or `HTMLElement.prototype` or `HTMLDivElement.prototype` or whatever it would end up on when using prototype's `Element.addMethods`. Granted, you have no choice but to extend each element in IE which doesn't support element extensions, but why cripple normal browsers? : ) Is it really necessary to have such precise control of which methods end up on which elements? If the elements you want to extend are of the same type, then extend just that type; If not - extend elements generically and check for `className` explicitly. This will save you tons of memory and remove chances of leaks in IE: Element.addMethods({ foo: function(el, ...) { ... if (el.hasClassName('bar')) { bar(); } else { baz(); } ... } }); ... -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Modifying prototypescriptaculous to work alongside jQuery
On Jan 23, 3:00 pm, Gabriel Gilini gabr...@usosim.com.br wrote: Quoting the Ecma-262: This standard specifies one departure from the grammar given in the Unicode standard: The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code. Thank god they removed the last sentence from ES3.1 (as of current draft) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Having trouble with .without().
On Jan 22, 7:18 pm, Richard Quadling rquadl...@googlemail.com wrote: 2009/1/22 Matt Foster mattfoste...@gmail.com: [...] I completely misread the Array.without(). I saw the individual elements and I must have had a brain fart. You can, of course, always use `Function.prototype.apply` as a workaround : ) var set1 = [1,2,3,4]; var set2 = [1,3]; var subset = set1.without.apply(set1, set2); // etc. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Modifying prototypescriptaculous to work alongside jQuery
On Jan 21, 11:30 am, Phil W phi...@googlemail.com wrote: I suppose I could use jQuery UI as it wouldn't clash, but I'd like to stick with Scriptaculous as the code can be in onClick etc events rather than all specified in the head region. [...] I'm pretty sure simply replacing all occurrences of `$` with, say `_ $`, should work just fine. What exactly did you do last time and how did it break? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: prototype and image selection?
On Jan 19, 10:58 am, Walter Lee Davis wa...@wdstudio.com wrote: [...] form action= method=post input type=hidden name=user_id value=123 / input type=text name=name id=name value=Pete / input type=text name=phone id=phone value=123 456-7890 / You do have label or title for those, don't you? ;) (Remember that screen reader does not understand which description to associate with particular field - that is unless you give field a corresponding label or a title attribute) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: prototype and image selection?
On Jan 18, 2:55 pm, geoffcox g...@freeuk.com wrote: [...] Is it possible to use prototype to do this? Yes, although querying those elements will be slower than using `elements` collection: $(formElement).select('[type=image]'); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: prototype and image selection?
On Jan 19, 1:53 am, geoffcox g...@freeuk.com wrote: Kangax do you mean that prototype can deal with input type=image though? What happened to the snippet I just gave you? [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Help me with this
On Jan 17, 1:18 pm, Colorblind dust_...@yahoo.com wrote: Hy everyone, I have the following script : if (Object.isUndefined(Axent)) { var Axent = { } } Axent.SelfLabeledInput = Class.create({ initialize: function() { var labelSelector = arguments[0] || 'label'; $$(labelSelector).findAll(function(l) {return (l.readAttribute ('for') !== null)}).each(function(l){ Why not just - `$$('label[for]')`? l.hide(); $(l.readAttribute('for'))._value = l.innerHTML; if ($(l.readAttribute('for')).value.empty()) { $(l.readAttribute('for')).value = $(l.readAttribute ('for'))._value Executing `$(l.readAttribute('for'))` more than once seems unnecessary. Why not save it in a variable? } $(l.readAttribute('for')).observe ('blur',function(e){if (Event.element(e).value == '') Event.element(e).value = Event.element (e)._value;}); $(l.readAttribute('for')).observe ('focus',function(e){if (Event.element(e).value == Event.element(e)._value) Event.element (e).value = '';}); }); } }); I want to write a function from this script that when i press the You want to write a function from this script. What does that mean? submit on a form, if an input is focused, it hides/clears it, so it doesn`t get submitted to the database. Work with the latest Prototype You can't really track focused elements using native DOM methods. Instead, you can observe all of the elements for focus/blur events and mark them as focused accordingly. You can then check which element is currently focused right before submitting a form. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: I think i found a bug in IE6(not yet test in IE7), it will throw a error when I create a instance object in sub window use the Class defined by its opener.
On Jan 16, 3:10 am, Eric smcdl6...@gmail.com wrote: [...] Who can tell me why ? Prototype doesn't have much support for cross-frame scripting. Some things work and some don't. If you could attach a minimal test case, I'll look into what exactly is going on. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: My Element.inserts are coming out strangely... please give me a nudge?
On Jan 16, 4:09 pm, Ian R i...@fairmountfair.com wrote: [...] wrap: function() { var prev_value = this.orientation == 'horizontal' ? 'larr;' : 'uarr;'; var next_value = this.orientation == 'horizontal' ? 'rarr;' : 'darr;'; prev_value = prev_value.unescapeHTML(); next_value = next_value.unescapeHTML(); //make a new div for the top var w = new Element('div',{'class':'listwrap'}); var h = this.el.select('h1'); var h = this.el.down('h1'); [...] P.S. `unescapeHTML` should work. I'm not sure what could be the problem there. -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Memory Leaks in IE7, Prototype or Prototip2?
On Jan 14, 3:22 pm, mr_justin gro...@jperkins.otherinbox.com wrote: [...] It was recently brought to my attention that the Element cache in Prototype does not get cleared out on page unload, so I added code to do just that. Unfortunately, the leak persists. Can you show the relevant snippet of how you cleared the cache? [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opera and $$('.wrapper .class') seems not to work correctly
On Jan 13, 6:26 am, Cyrus arianglan...@googlemail.com wrote: [...] What would you suggest? File a bug report at Opera, Prototype or both? I can confirm this with 9.61 on Mac OSX. Here's a minimal failing test case: !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html head title/title script src=http://ajax.googleapis.com/ajax/libs/prototype/ 1.6.0.3/prototype.js type=text/javascript/script /head body div class=wrapper a href=# class=classtest/a /div div div class=wrapper a href=# class=classtest/a /div /div script type=text/javascript document.write($$('.wrapper .class').length); /script /body /html Should write 2 but writes 1. This looks like an Opera bug. Moreover, I think we already have a similar ticket filed (which was essentially due to a bug in Opera's XPath engine bug and the way it handles descendant selectors). For example, switching to child selector ('.wrapper .class') returns proper result - 2. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opera and $$('.wrapper .class') seems not to work correctly
On Jan 13, 8:30 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Juriy, That inline script could muddy the water in terms of DOM availability, etc. Perhaps a minor mod: I usually try to eliminate as much of irrelevant prototypeism as possible when creating a testcase : ) Why use dom:loaded (which is also known to be unreliable in IE in its current implementation) when we can simply run script at the time when body is definitely loaded and parsed. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opera Mobile support
On Jan 13, 5:48 pm, Laurent Dinclaux laurent.dincl...@gmail.com wrote: [...] I will also send the rendering result of js-cecker page when I find where opera saved it on my handset... Sounds great. Unfortuantely, I wasn't able to simulate Opera Mobile on desktop so your results would help a lot. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opera and $$('.wrapper .class') seems not to work correctly
On Jan 12, 10:37 am, Cyrus arianglan...@googlemail.com wrote: Hi there, I have found a weird behaviour in the opera browser. I am not sure if this is really a bug or an intended behaviour. [...] Which versions of Prototype.js and Opera? -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Opera Mobile support
On Jan 12, 9:10 pm, Lox laurent.dincl...@gmail.com wrote: [...] I only found one clue. A guy says that Jquery won't work with Opera Mobile because it relies on function decompile (http://my.opera.com/ hallvors/blog/show.dml/1665828). Does prototype relies on function decompile too? Yes it does (although prototype only parses function arguments, and not function body). Could you open this page [1] in Opera Mobile and check what the output is under Function decompilation section? I created it specifically for testing mobile browsers. [...] [1] http://yura.thinkweb2.com/js-checker/ -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Is this a bug? an element is enclosed unexpectedly by an inserted method.
On Jan 12, 11:04 pm, Hamamoto Noriaki norisu...@gmail.com wrote: Hey Kangax, Thank you for the reply. Do you think the reason of the problem I met is because of using div/ instead of div/div ? is Using /div prohibitted? Do you know why it happns? I'm pretty sure some browsers (at least FF) parses div / as an opening one in this case. You can see how html parser works in a simple example: var el = document.createElement('div'); el.innerHTML = 'div id=foo //div id=bar /'; el.innerHTML; // div id=foo/div el.childNodes.length; // 1 When using broken markup, you're relying on a closed-source mechanism of browser parsing, or rather the way browser parser *corrects* invalid markup. Just use standard constructs and chances are you won't run into such annoying anomalies. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: IE6 select element issue
On Jan 10, 5:36 am, jason maina jason.ma...@gmail.com wrote: [...] widely in the application, problem is on the first page it loads ok but on subsequent pages it loads but without content. What does subsequent pages mean? Also, a reduced example would make it easier to find a problem. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: form.serialize and radio buttons?
On Jan 10, 4:44 pm, geoffcox g...@freeuk.com wrote: Hello, I have made a little progress! I now have the code below which works in IE but not in the latest version of Firefox. Can anyone see why? And how exactly does it not work? [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Removing option from form bean
On Jan 9, 7:04 pm, cyiam shintamann...@wellsfargo.com wrote: [...] HELP! The javascript looks as below: $('removeFeature').observe('click',function(){ var deletedFeatures = $A($F('features')); deletedFeatures.each( function(feature){ $(feature).remove(); }); }); Try something like: $('removeFeature').observe('click',function() { $A($('features').options).findAll(function(el) { return el.selected; }).invoke('remove'); }); P.S. It would be nice if there was a support for `:selected` css pseudo class -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Anchor event
On Jan 7, 7:37 pm, tmarin teimat...@gmail.com wrote: I want to execute some code when a user reaches a fragment anchor (the # part of a link), is there any event for this? If I understand you correctly, you can check value of `document.location.hash` on page load (or periodically poll for it, if you're interested in hash changes after page load) Thanks in advance tmarin -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Observe an event with multiple elements.
On Jan 8, 5:52 am, T.J. Crowder t...@crowdersoftware.com wrote: [snip excellent reply] (And yes, lurking pedants, I could have avoided repeating ClassName in that, at the expense of readability and maintainability IMHO.) No, that would be just silly : ) On the other hand, I'm quite fond of: function(e, el) { if (el = e.findElement('cssExpression')) { // do stuff with el } } [1]http://www.prototypejs.org/api/utility/dollar-dollar [2]http://www.w3.org/TR/css3-selectors/#attribute-substrings [3]http://www.prototypejs.org/api/enumerable/invoke [4]http://www.prototypejs.org/api/function/defer HTH, -- T.J. Crowder tj / crowder software / com [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Custom Property on TextNode
On Jan 5, 11:23 am, Matt Foster mattfoste...@gmail.com wrote: Hey Everyone, I'm working on a project that swaps out text nodes. I need to save a reference to the new text node with the existing node. In FF I am able to set custom properties no problem, IE however throws an error of Object does not support this property or method. I was thinking I could use a hash object and the text nodes node value property as the key, and the new node as the value but this seems incredibly sloppy, especially as its a hack for IE only. Anyone know how I can get around it this error? Damn, just killed an hour of work time to solve the puzzle : ) Hash sounds good, but would fail when given nodes with non-unique text values (since JS doesn't natively support non-string object keys). It seems like IE's textNode's throw error for any property assignment except when property is named `nodeValue` or `data`. It is, unfortunately, impossible to use those properties since their change is immediately reflected in the document (i.e. changing node's text). I would suggest to leave text nodes along for maximum compatibility/ reliability, but if you must here's a workaround: var t = document.createTextNode('boo'); t.nodeValue.toString.toString = function() { alert('Muahaha!'); }; t.nodeValue.toString.toString(); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Event.observer with mouseup?
On Jan 4, 10:21 am, Joe Athman jjath...@gmail.com wrote: Another alternative is to use Prototype's Curry function which let's you create new functions with default arguments. So you could write: Event.observe(window, 'mouseup', alert.curry('hi')); `alert.curry(hi)` won't work in IE, where `window.alert` is not an instance of Function object and does not inherit from `Function.prototype` (as, pretty much, any other JScript host method). You can, of course, try to call `curry` from the `Function.prototype` directly (`Function.prototype.curry.call(window.alert, 1)`), but since `curry` internally tries to invoke `call` directly on a context object, this will fail once again. It would work if Prototype.js was invoking `call` from the `Function.prototype` rather than from the context object `(Function.prototype.call.call(alert, window, 1))` but it doesn't and it's not clear if such change is even worth the trouble. Never expect anything from host objects. Joe [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Cloning an Array, no properties
On Dec 29, 4:33 am, Jon Kleiser jon.klei...@usit.uio.no wrote: Hi, The Prototype docs on Object.clone() says that it Clones the passed object using shallow copy (copies all the original's properties to the result). It's good to remember that `Object.clone` copies all *enumerable* properties of an object or its prototype chain. However, if I give my array some extra properties, they will not get copied! Try this: var x=[];x.foo=1;var y=x.clone();alert(y.foo); You're using `Array.prototype.clone` here, not `Object.clone`. `Array.prototype.clone` only affects numeric properties (since internally it uses `Array.prototype.concat` in older versions and `Array.prototype.slice` in trunk version) Rather disappointing! I'm using prototype-1.6.0.3.js. var x=[]; x.foo=1; var y=Object.clone(x); alert(y.foo); Although, this will make `y` an object (not an array). To fix this, you can do something like: var x = [1,2,3]; x.foo = 1; var y = x.clone(); Object.extend(y, x); alert(y.foo); /Jon -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: IS LIGHTBOX CONTENT INDEXED BY GOOGLE?
On Dec 28, 7:08 am, gbas gbasvi...@gmail.com wrote: Hi there, good afternoon, I am trying to understand (with no success so far) whether google indexes or not the content displayed using lightbox effect. I am developing a website based on different activities (like camping, mountain bike and so on). The site is developed in php, you will access the content from the home or clicking on a section (i.e. mountain bike) than a range of different mountain bike paths would be shown. Then (and here is the trick) if you click on any of them a lightbox appears with all the information concerning the activity (distante, time required, level of difficulty, map location, eetc, etc). My problem is that most of the information will be displayed into a lightbox so, if google doesn’t index the content my website will be, from the eyes of google, almost empty and irrelevant to the user (in terms of serch). Could anyone please help me out on this, I would really appreciate. Thanks a lot for your help. If content is present in the document (rather than generated dynamically/requested from remote service), it should be indexed by search spiders (including google ones). It also probably matters where that content is present and how semantic it is, but that's besides the point. On a side note, it's a good idea to develop documents in such way that they work without javascript and then add scripting on top. Best regards, Guillermo -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Element.observe questions
On Dec 29, 3:27 pm, K.C.Leung z4423...@gmail.com wrote: [...] script type=text/javascript var testForm = $( testForm ) ; testForm.observe ( submit, function ( e ) { alert ( submit ) ; return false ; // return false is meaningless. It is continue e.stop(); [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Element.observe questions
On Dec 29, 6:13 pm, K.C.Leung z4423...@gmail.com wrote: oh ! thanks ! var form = e.element ( ) ; if ( invalid ) { alert ( invalid ) ; e.stop ( ) ; return ; no need to `return` here ; ) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Custom attributes or not custom attributes ?
On Dec 27, 8:51 pm, buda www...@pochta.ru wrote: Of course not: !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html headtitle/title/head body foo=bar script type=text/javascript // writes CSS1Compat (would print BackCompat in Quirks) document.write(document.compatMode); /script /body /html but this document does not pass validation - Error found while checking this document as HTML 4.01 Strict! Of course it doesn't. That's because there are invalid attributes, yet you can see how browser still renders document in standard mode. That was exactly the point of this example. You just need to understand that invalid markup and mode switching have nothing to do with each other ; ) what does this mean for the browser and why should I well form my document if tere is not difference correct it or not - its in every case strict document!? You could ask that at c.i.w.a.html [1] Nevertheless, try not to use custom attributes, unless you want to run into troubles later on (e.g. remember that the entire DOM in IE is implemented in such way that there's no distinction between element attributes and properties). I dont fully understand what you mean - e.g. remember that the entire DOM in IE is implemented in such way that there's no distinction between element attributes and properties). and how should I do in case when I need to somewhere to storemetadata about every element in a form to make some validation or save their states? or manipulate with them in case of some rules state in my bussines rules Earlie you sad It is indeed useful about custom attributes and now you tell me not to use them ?! What should I do instead of storin some metadat in elements custom attributes??? It is useful, but I don't think it's worth the trouble and I personally don't use it. IE's DOM is one example of what makes custom attributes troublesome - you never know which issues you will run into due to every custom attribute ending up as a property of an element. What if attribute name (which becomes a property name) is a reserved word (according to ECMAScript/JScript)? What if it corresponds to some IE's proprietary element property? Which of them takes precedence and which issues it might cause? etc. [1] http://groups.google.com/group/comp.infosystems.www.authoring.html/topics --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Custom attributes or not custom attributes ?
On Dec 27, 6:15 am, buda www...@pochta.ru wrote: From one hand - custom attributes, if they are not described in DTD, are evil for valid Transitional or Strict modes - they lead document to quirck mode No. Quirks mode is triggered by the lack of doctype declaration, not the presence of custom attributes. IE is the only exception in that it *also* triggers quirks when anything non-whitespace precedes doctype declaration. From another hand - they make the life easy for developers with their ability to store a lot of metadata like: required=true mask=^w+... oldValue=345 emptyVlue=0 min=10 max=1000 rowID=1213 and etc It is indeed useful. HTML5 even introduced custom data-* attributes [1] there is an offer to store whole metadata into css classname attribute (it maybe a very long string with keypairs) - which as for me its very very complex to analyze and modify What do you think about it? I think you should use class attributes or some alternative approach, and keep your markup valid. On a side note, there's a data manipulation addition in prototype's trunk; Element#store and Element#retrieve. You might want to look into that. [1] http://www.whatwg.org/specs/web-apps/current-work/#custom-data-attribute -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Custom attributes or not custom attributes ?
On Dec 27, 1:56 pm, buda www...@pochta.ru wrote: No. Quirks mode is triggered by the lack of doctype declaration, not the presence of custom attributes. IE is the only exception in that it *also* triggers quirks when anything non-whitespace precedes doctype declaration. If document is decleared as strict or transitional - it must be valid - otherwise it switch to quirck mode - am I right Custom attributes are not valid in thiese modes only in quirck mode If document is declared as strict or transitional it must validate against corresponding DTD's in order to be valid. When there's no declaration, there's nothing to validate against. If quirks mode is triggered by lack of doctype declaration, then validity does not even apply, since there's no declaration to validate against. Am I missing something? It is indeed useful. HTML5 even introduced custom data-* attributes [1] When will it the standard? 2022 I think you should use class attributes or some alternative approach, and keep your markup valid. On a side note, there's a data manipulation addition in prototype's trunk; Element#store and Element#retrieve. You might want to look into that. Element#store, Element#retrieve - where can I view it? http://github.com/sstephenson/prototype/tree/master/src/dom/dom.js#L1221 [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Custom attributes or not custom attributes ?
On Dec 27, 6:27 pm, buda www...@pochta.ru wrote: If document is declared as strict or transitional it must validate against corresponding DTD's in order to be valid. When there's no declaration, there's nothing to validate against. If quirks mode is triggered by lack of doctype declaration, then validity does not even apply, since there's no declaration to validate against. Am I missing something? But if I decleared strict or transitional and then add a custom attribute to an element - the browser swithes to quirck mode or Iam wrong? Of course not: !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html headtitle/title/head body foo=bar script type=text/javascript // writes CSS1Compat (would print BackCompat in Quirks) document.write(document.compatMode); /script /body /html It is indeed useful. HTML5 even introduced custom data-* attributes [1] When will it the standard? 2022 Huh? we have enough time to fell free ) I'm sure we'll see different browsers implement most of html5 features long before this revision becomes a recommendation. Some of them are already present in modern browsers (e.g. `document.getElementsByClassName` or `document.querySelector`). Nevertheless, try not to use custom attributes, unless you want to run into troubles later on (e.g. remember that the entire DOM in IE is implemented in such way that there's no distinction between element attributes and properties). -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: change link behavior by classname
On Dec 26, 5:43 pm, Harry Porto Schroeter harry.po...@gmail.com wrote: Hi, i have this group of links with the same classname, i want to make a click behavior so when clicked it executes a function and in that function i want to use as parameters the query string from the href attribute on the links but i don't want the links to be executed with the browser going to the href address and these links were written on the page from a previous ajax.update how i do that? document.observe('click', function(e, el) { if (el = e.findElement('.myClassName')) { e.stop(); alert(e.element().href); } }) thanks! -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: DOM building with Prototype library
On Dec 24, 12:06 am, Ashwin ashwink...@gmail.com wrote: [...] var checkBoxNode = new Element('input', {type:'checkbox',id:'n'+count,checked:true,value:'true'}); Firefox/Safari render this checkbox as checked, but IE refuses to recognize the checked = true attribute setting. Try `defaultChecked: true` Thanks. Ashwin -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Subclassing Array
On Dec 23, 7:23 am, Jon Kleiser jon.klei...@usit.uio.no wrote: Hi, I'm using prototype-1.6.0.3.js, and I'm trying to subclass Array like this: var MyArr = Class.create(Array, { initialize: function($super, arg) { $super(arg); } }); Or just like this: var MyArr = Class.create(Array, {}); Neither seems to work at all. In the Firefox Error Console I get Error: parent.subclasses is undefined with a reference to line 62 in the prototype file. Is it possible to subclass Array? That would depend on what you mean by subclass an Array. Prototype's `Class.create` uses quite popular `clone`/`beget` inheritance pattern. While such pattern allows to actually create an Array subclass (i.e. a constructor function that creates objects with `Array.prototype` somewhere in their prototype chain) any such object is doomed to be missing some of the traits of native array objects - i.e. index properties' manipulation does not affect `length` property and vice versa. What were you planning to use this subclass for? /Jon -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Adding properties to all form elements
On Dec 18, 11:16 am, Diodeus diod...@gmail.com wrote: I don't believe html properties elements are extensible. All you can do is add css class names. Actually they are. At least in Mozilla: HTMLFormElement.prototype.foo = 5; document.createElement('form').foo; // 5 [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Adding properties to all form elements
On Dec 18, 12:18 pm, Kupido kup...@hotmail.com wrote: Unfortunately I need my application to be compatible with IE too... :( What about the initialization function? Object.extend(Form.Methods, { initialize: function (form) { form = $(form); form.property1 = 'test'; form.property2 = ['t', 'e', 's', 't']; // and so on } }); This is working for stardard forms but not for dinamically created forms (document.createElement). Why? Is there a better way of doing this? I'm not sure how this could work and what exactly it does. A preferred way to add properties to FORM elements is by using `Element.addMethods ('form', { /* ... */ })`. The only problem is that Prototype discards any properties which are not functions (or rather those that return falsy result from `Object.isFunction`). That is why your non- function properties are never applied. This was brought up before but doesn't seem like an important (or even necessary) addition. You can always open a ticket, of course ; ) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---