[Proto-Scripty] Form.serialize without empty inputs.
Hello. Is it possible to serialize a form but without empty inputs? I've been looking on the Internet for an example and I have tried code like this one, but without achieving success: $('step2').serialize(true).each(function(s, index) {if (s.empty()) {$ ('step2').remove(key)}}) or $('step2').serialize(true).each(function(s, index) {if (s.empty()) {this.remove(key)}}) Any help is appreciated. Best regards, B. -- 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] Prototype script.aculo.us and conflict
Hello, I use Prototype script.aculo.us (latest version) on a fluxbb forum to have autocomplete and autorefresh feature. The problem is that when i display a smiley bar with an other javascript function, i get many error messages on apache log. Here is an example on error message : [Fri Nov 05 03:07:18 2010] [error] [client 66.131.132.226] (20024)The given path is misformatted or contained invalid characters: access to / img/smilies/function (_58) {var _59 = true;this.each(function (_5a, _5b) {_59 = _59 !!(_58 || Prototype.K)(_5a, _5b);if (!_59) {throw $break;}});return _59;} failed The function wich cause the error is : tb.barSmilies(smilies); Here is the function : function btSmilies(img, label) { addButton(img, label, function() { var element = document.getElementById('smilies'); if (element.style.display == 'block' ) { textarea.focus(); element.style.display = 'none'; } else { textarea.focus(); element.style.display = 'block'; } }); } And the addButton function : function addButton(src, title, fn) { var i = document.createElement('img'); i.src = bt_img_path + src; i.title = title.replace(/quot;/g, ''); i.style.padding = '0 5px 0 0'; i.onclick = function() { try { fn() } catch (e) { } return false }; i.tabIndex = 400; toolbar.appendChild(i); } Every function are in an other with begin by : function toolBar(textarea, bt_img_path, smilies_img_path) { if (!document.createElement) return; if ((typeof(document['selection']) == 'undefined') (typeof(textarea['setSelectionRange']) == 'undefined')) return; var toolbar = document.createElement('div'); toolbar.id = 'toolbar'; toolbar.style.padding = '4px 0'; var smilies = document.createElement('div'); smilies.id = 'smilies'; smilies.style.display = 'none'; smilies.style.padding = '0.3em 0'; I really don't understand how Prototype script.aculo.us can cause this error. And i'm sure it come from Prototype script.aculo.us and these functions. Because when i remove my script call to Prototype script.aculo.us, there is no more errors, and it's the same when i comment btSmilies function. Could you help me to correct the problem please ? -- 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] Rails UJS data-remote fires on any click
Hello, I was wondering if was intentional for ajax links (link_to ... :remote = true ... ) to fire on any click. I want links to behave where a left click fires of the ajax request, but a right click can allow you to copy link location or open in a new tab, depending on your browser. I found that in firefox, you get the context menu on a right click, but the action fires off anyway, not waiting for the user to decide what they want to do on the right click. Same behaviour for a middle click, which in some browsers would normally open up a new tab. I was able to modify rails.js around line 133 to test if this is a left click before handling the event in the usual manner. 133 document.on(click, a[data-remote], function(event, element) { 134 if (event.stopped) return; 135 // If loop inserted for left click only behaviour 136 if (event.button == 0) { 137 handleRemote(element); 138 event.stop(); 139 } 140 }); My main question is... is this going to hurt my site in any way? Also, is this something worthy of submitting a ticket over (if so, where) and if not, what was the idea behind making links fire off on any type of click. Thanks a lot, -- Matthew Smart -- 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] the working of Template.evaluate
I am learning the Prototype library in-depth and my question is about the inner logic of the Template.evaluate method. Everything is clear as long as the original match provided by the gsub function from the stored template is further processed. a.) what kind of scenario is the inner regular expresion used to handle? b.) what is going on in the while loop /* cut */ var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; match = pattern.exec(expr); if (match == null) return before; while (match != null) { var comp = match[1].startsWith('[') ? match[2].replace(/]/ g, ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); match = pattern.exec(expr); } /* cut */ -- 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] hash.__properties is undefined
Hi, I'm upgrading from 1.5 to 1.6.1, and Firefox reports an error in prototype_update_helper.js (line 380) that hash.__properties is undefined. When I set a breakpoint it works fine. I have no idea what can be the problem. When I try it with prototype version 1.6.0.3, there's no such errors, and the update helper reports a few issues in my code. But it doesn't work with 1.6.1. -- 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: Form.serialize without empty inputs.
Hi, `Form#serialize` returns a plain object (with a property for each form element, where the value of the property is the value of the element). Plain objects don't have an `#each` method. But for what you're trying to do, JavaScript itself has a built-in each mechanism: `for..in`. `for..in` enumerates the property names of an object. So you'd just use `for..in` and look for properties with as a value and delete them from the object: var data, name; // Get an object with the form data as properties data = $('step2').serialize(true); // Loop through the form data for (name in data) { // Does this element have a blank value? if (data[name] === ) { // Yes, remove it from the data delete data[name]; } } Here's an example: http://jsbin.com/icasa4 (The only Prototype- specific code in the above is the `#serialize` call.) You may be wondering if it's safe to modify the object's list of properties (via `delete`) when you're looping through that list (via `for..in`). It is, the spec[1] covers this in Section 12.6.4 (The for- in Statement): Properties of the object being enumerated may be deleted during enumeration. [1] http://www.ecma-international.org/publications/standards/Ecma-262.htm HTH, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Nov 5, 9:14 pm, Braulio brau...@solsoft.biz wrote: Hello. Is it possible to serialize a form but without empty inputs? I've been looking on the Internet for an example and I have tried code like this one, but without achieving success: $('step2').serialize(true).each(function(s, index) {if (s.empty()) {$ ('step2').remove(key)}}) or $('step2').serialize(true).each(function(s, index) {if (s.empty()) {this.remove(key)}}) Any help is appreciated. Best regards, B. -- 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: Prototype script.aculo.us and conflict
Hi, You haven't actually quoted the bit of code that loops through `smilies_img_path`, or the code that calls `toolBar`, but from the error message I can make two predictions: 1. The `smilies_img_path` parameter to `toolBar` is an Array. 2. The code for looping through outputting the smilies looks something like this: for (smiley_path in smilies_img_path) { // ...output the smiley using smiley_path... } If I'm correct about those assumptions, the problem is that the author of that code doesn't understand what `for..in` does (a LOT of people don't). They're assuming it loops through the indexes of an array. It doesn't. Details here: http://blog.niftysnippets.org/2010/11/myths-and-realities-of-forin.html If I'm right about the above, then the only way you'll get Prototype and this other software to happily co-exist is to get the authors of the other software to fix their `for..in` loops, because Prototype adds a lot of functions to the `Array.prototype` and that's why you're seeing functions in the result. (Again, details in the link above.) HTH, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Nov 5, 9:59 pm, Bagu bagu@gmail.com wrote: Hello, I use Prototype script.aculo.us (latest version) on a fluxbb forum to have autocomplete and autorefresh feature. The problem is that when i display a smiley bar with an other javascript function, i get many error messages on apache log. Here is an example on error message : [Fri Nov 05 03:07:18 2010] [error] [client 66.131.132.226] (20024)The given path is misformatted or contained invalid characters: access to / img/smilies/function (_58) { var _59 = true; this.each(function (_5a, _5b) {_59 = _59 !!(_58 || Prototype.K)(_5a, _5b);if (!_59) {throw $break;}}); return _59;} failed The function wich cause the error is : tb.barSmilies(smilies); Here is the function : function btSmilies(img, label) { addButton(img, label, function() { var element = document.getElementById('smilies'); if (element.style.display == 'block' ) { textarea.focus(); element.style.display = 'none'; } else { textarea.focus(); element.style.display = 'block'; } }); } And the addButton function : function addButton(src, title, fn) { var i = document.createElement('img'); i.src = bt_img_path + src; i.title = title.replace(/quot;/g, ''); i.style.padding = '0 5px 0 0'; i.onclick = function() { try { fn() } catch (e) { } return false }; i.tabIndex = 400; toolbar.appendChild(i); } Every function are in an other with begin by : function toolBar(textarea, bt_img_path, smilies_img_path) { if (!document.createElement) return; if ((typeof(document['selection']) == 'undefined') (typeof(textarea['setSelectionRange']) == 'undefined')) return; var toolbar = document.createElement('div'); toolbar.id = 'toolbar'; toolbar.style.padding = '4px 0'; var smilies = document.createElement('div'); smilies.id = 'smilies'; smilies.style.display = 'none'; smilies.style.padding = '0.3em 0'; I really don't understand how Prototype script.aculo.us can cause this error. And i'm sure it come from Prototype script.aculo.us and these functions. Because when i remove my script call to Prototype script.aculo.us, there is no more errors, and it's the same when i comment btSmilies function. Could you help me to correct the problem please ? -- 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: How should I model this if extending the DOM is bad?
Sorry, I don't understand. How would you store a reference to the Object in the paragraph? Or would you keep a list (or an array) of paragraph-objects that have a reference to the paragraph-DOM-Element? On Nov 6, 7:33 pm, buda www...@pochta.ru wrote: Keep reference to the object in storage of a paragraph, video and etc On 4 ноя, 23:09, Luke kickingje...@gmail.com wrote: Hi, sorry for the non-descriptive topic, I couldn't think of anything better. However, I'm currently working on a project where you can create simple webpages by adding different types of paragraphs, (eg. Text, Image, Video) one below the other, and edit their contents, move or delete them. Basically like this: http://blogage.de/files/60901/image Im rewriting the JS and I have a little problem here; I recently read that extending the DOM is basically a bad idea and that in Prototype 2 they will even stop that practice. Now my idea (actually) was, for a project like this, to create classes for each paragraph-type with methods and properties that I would extend the paragraph-DOM with. I mean that if I had, like in the above image, three paragraphs, each would be represented by a DIV with the class=paragraph text or class=paragraph video etc. On the JS-side there would be classes like Text or Video which would have a method that would extend those DIVs with functions and properties necessary to edit, move or delete that paragraph. When, for example, the user clicks on an editlink, it simply would call its paragraph's edit-method. Everything would be nice and clean. But now I know, extending is bad. So I'm kinda stuck here, I don't know how to write unobtrusive JS without writing terrible spaghetti- esque code with lots of observers. I mean I could still organize parts of the code in classes, but there would be a long list of observers (eg. for clicking an edit-link) with switch-cases for the types of paragraphs. Actually even with extending the DOM I'm not totally sure how I would catch the edit-clicking event. As I said, I'm kind of stuck :). Can you help me with ideas? How would you do this? Thanks a lot, Luke -- 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] Finding the position of a scroll bar for an element with overflow:auto
I have an element that has overflow:auto. The contents of the element are updated from time to time via ajax calls. I want to ensure that when this happens, if the user has scrolled down into the content, their scroll position stays the same even through the content is effectively regenerated. Is there a way to get the scrollTop for an element? -- Shane McCarron halindr...@gmail.com -- 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: the working of Template.evaluate
Hi, They're both there to handle property accessors within the template. It's missing from the documentation, but templates can actually handle things like: Hi #{person[firstname]} #{person.lastname} ...where what you feed in is: t.evaluate({person: { firstname: Joe, lastname: Bloggs }); (Example: http://jsbin.com/axuzo3) The regex plus the loop are what make that happen, both the subscript notation (the first one) and the dotted notation (the second one). I think it only works one level deep with the bracketed notation, though. HTH, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Nov 6, 7:52 pm, petrob petrob...@yahoo.com wrote: I am learning the Prototype library in-depth and my question is about the inner logic of the Template.evaluate method. Everything is clear as long as the original match provided by the gsub function from the stored template is further processed. a.) what kind of scenario is the inner regular expresion used to handle? b.) what is going on in the while loop /* cut */ var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; match = pattern.exec(expr); if (match == null) return before; while (match != null) { var comp = match[1].startsWith('[') ? match[2].replace(/]/ g, ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); match = pattern.exec(expr); } /* cut */ -- 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: hash.__properties is undefined
Hi, I'm upgrading from 1.5 to 1.6.1, and Firefox reports an error in prototype_update_helper.js (line 380)... As there's no prototype_update_helper.js in Prototype itself, you'll need to show the actual code being used. If it's using the internals of the `Hash` object (instead of its published API), I'm afraid you'll have to rewrite it to use the API instead (as internals can change from a dot rev to a dot rev without notice). FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Nov 7, 8:10 am, Iravanchi iravan...@gmail.com wrote: Hi, I'm upgrading from 1.5 to 1.6.1, and Firefox reports an error in prototype_update_helper.js (line 380) that hash.__properties is undefined. When I set a breakpoint it works fine. I have no idea what can be the problem. When I try it with prototype version 1.6.0.3, there's no such errors, and the update helper reports a few issues in my code. But it doesn't work with 1.6.1. -- 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.