From: Matěj Cepl on 18 Dec 2009 13:31 Dne 18.12.2009 17:52, Thomas 'PointedEars' Lahn napsal(a): > And here is a better (but still improvable), production code from another > project that I have not backported yet: I will gladly improve it, if I can ... what's the license? You mentioned in the previous post GPLv3, but I would much prefer (for many reasons) MIT/X11. Can I, please, or do I have to rewrite it from scratch? Thanks a lot for the ideas anyway, Matěj -- http://www.ceplovi.cz/matej/, Jabber: mcepl<at>ceplovi.cz GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC Our lives are spectacles of powerlessness. -- Richard Rohr
From: Thomas 'PointedEars' Lahn on 18 Dec 2009 14:46 Matěj Cepl wrote: > Thomas 'PointedEars' Lahn napsal(a): >> And here is a better (but still improvable), production code from another >> project that I have not backported yet: > > I will gladly improve it, if I can ... what's the license? This will be probably be distributed under the GPLv3, too, as it will replace what I had in mind for the next release for the most part. > You mentioned in the previous post GPLv3, but I would much prefer (for > many reasons) MIT/X11. Can I, please, or do I have to rewrite it from > scratch? AFAIK, the MIT License without modifications is fully GPL-compatible. AIUI, that means code under the former license can be combined with a program licensed under the GPL without conflict, but not vice-versa. So, IIUC, if you want to use this code with an MIT-licensed product you will need to rewrite it from scratch. > Thanks a lot for the ideas anyway, You are welcome. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: David Mark on 18 Dec 2009 15:00 On Dec 18, 11:52Â am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > Thomas 'PointedEars' Lahn wrote: > > MatÄj Cepl wrote: > >> Dne 16.12.2009 22:55, Thomas 'PointedEars' Lahn napsal(a): > >>> You can store the form data in a cookie or Storage, and restore the form > >>> data from it when applicable. Â You could make an non-modifying XHR > >>> request to your server and handle it synchronously to see if you are > >>> online. Â You need to assume you are online if XHR is not supported. > > >> Hmm, sounds interesting. I have in meantime dived a little bit more into > >> forms submission technology and I think I am getting some ideas now. It > >> will be fun to put it all together but it sounds doable. If I have > >> enough time, that is :(. > > > Following the beta of a form serialization method that I am going to > > distribute as free software (under the GNU GPL v3) as part of > > httprequest.js, which should be enough to get you started: > > > [...] > > And here is a better (but still improvable), production code from another > project that I have not backported yet: > > /* ------------------------------------------------------------------ */ > > /** > Â * @param f : Form|HTMLFormElement > Â * @return string > Â */ > function serializeForm(f) > { > Â var gotSubmit = false; > > Â /** > Â Â * @param o > Â Â */ > Â function serializeControl(o) > Â { > Â Â /* HTML 4.01: Controls that are disabled cannot be successful. */ > Â Â if (!o.disabled) > Â Â { > Â Â Â /* > Â Â Â Â * If a form contains more than one submit button, > Â Â Â Â * only the activated submit button is successful. > Â Â Â Â * (here: the first one) > Â Â Â Â */ > Â Â Â var isSubmit = /(^|\s)(submit|image)(\s|$)/i.test(o.type); > Â Â Â if (!gotSubmit || !isSubmit) > Â Â Â { > Â Â Â Â if (isSubmit) gotSubmit = true; > > Â Â Â Â /* > Â Â Â Â Â * For menus, the control name is provided by a SELECT element > Â Â Â Â Â * and values are provided by OPTION elements. Only selected > Â Â Â Â Â * options may be successful. When no options are selected, > Â Â Â Â Â * the control is not successful and neither the name nor any > Â Â Â Â Â * values are submitted to the server when the form is submitted. > Â Â Â Â Â */ > Â Â Â Â var m = /(^|\s)(select(-one)?|undefined)(\s|$)/i.exec(o.type); > Â Â Â Â if (m) > Â Â Â Â { > Â Â Â Â Â /* select-one */ > Â Â Â Â Â if (m[3]) > Â Â Â Â Â { > Â Â Â Â Â Â if (o.selectedIndex > -1) > Â Â Â Â Â Â { > Â Â Â Â Â Â Â items.add(o.name, o.options[o.selectedIndex].value); This is a problem. You need to know if the value attribute is present. Depends on the context, of course. > Â Â Â Â Â Â } > Â Â Â Â Â } > > Â Â Â Â Â /* select */ > Â Â Â Â Â else if (m[2]) > Â Â Â Â Â { > Â Â Â Â Â Â for (var i = 0, opts = o.options, len = opts && opts.length; > Â Â Â Â Â Â Â Â Â i < len; i++) > Â Â Â Â Â Â { > Â Â Â Â Â Â Â var opt = opts[i]; > Â Â Â Â Â Â Â if (opt.selected) > Â Â Â Â Â Â Â { > Â Â Â Â Â Â Â Â items.add(o.name, opt.value); Same here. > Â Â Â Â Â Â Â } > Â Â Â Â Â Â } > Â Â Â Â Â } > Â Â Â Â } > > Â Â Â Â /* > Â Â Â Â Â * All "on" checkboxes may be successful.. > Â Â Â Â Â * For radio buttons that share the same value of the > Â Â Â Â Â * name attribute, only the "on" radio button may be successful. > Â Â Â Â Â */ > Â Â Â Â else if (!/(^|\s)file|reset(\s|$)/i.test(o.type) > Â Â Â Â Â Â Â Â Â && !(/(^|\s)object(\s|$)/i.test(o.tagName) && o.declare) > Â Â Â Â Â Â Â Â Â && !/(^|\s)(checkbox|radio)(\s|$)/i.test(o.type) > Â Â Â Â Â Â Â Â Â || o.checked) > Â Â Â Â { > Â Â Â Â Â items.add(o.name, o.value); > Â Â Â Â } > Â Â Â } > Â Â } > Â } > > Â var es = getFeature(f, "elements"); > Â if (es) > Â { > Â Â var items = []; > > Â Â items.add = function(sName, sValue) { > Â Â Â var s = esc(sName) + "=" + esc(sValue); > Â Â Â this.push(s); > Â Â }; > > Â Â if (!isMethod(items, "push")) Is this the host method test function? > Â Â { > Â Â Â items.push = function() { > Â Â Â Â for (var i = 0, len = arguments.length; i < len; i++) > Â Â Â Â { > Â Â Â Â Â items[items.length] = arguments[i]; > Â Â Â Â } > Â Â Â }; > Â Â } > > Â Â for (var i = 0, len = es.length; i < len; i++) > Â Â { > Â Â Â var e = es[i]; > > Â Â Â /* > Â Â Â Â * Elements with the same name create a NodeList object, > Â Â Â Â * however options of select objects are also indexable in Gecko. > Â Â Â Â */ > Â Â Â if (typeof e[0] != "undefined" && typeof e.options == "undefined") I don't care for that. > Â Â Â { > Â Â Â Â for (var j = 0, len2 = e.length; j < len2; j++) > Â Â Â Â { > Â Â Â Â Â serializeControl(e[j]); > Â Â Â Â } > Â Â Â } > Â Â Â else > Â Â Â { > Â Â Â Â serializeControl(e); > Â Â Â } > Â Â } > > Â Â return items.join("&"); > Â } > > Â return ""; > > } > > /* ------------------------------------------------------------------ */ > > esc(), getFeature() and isMethod() are user-defined, of course, but you > probably get the idea.. > Mostly.
From: Thomas 'PointedEars' Lahn on 18 Dec 2009 16:02 David Mark wrote: > Thomas 'PointedEars' Lahn wrote: >> items.add(o.name, o.options[o.selectedIndex].value); > > This is a problem. You need to know if the value attribute is > present. Depends on the context, of course. You are mistaken. Keep in mind that this is supposed to serialize the form as if it was submitted as usual. >> [...] >> for (var i = 0, opts = o.options, len = opts && opts.length; >> i < len; i++) >> { >> var opt = opts[i]; >> if (opt.selected) >> { >> items.add(o.name, opt.value); > > Same here. No. >> if (!isMethod(items, "push")) > > Is this the host method test function? It is a general one. I make no distinction there. >> /* >> * Elements with the same name create a NodeList object, >> * however options of select objects are also indexable in Gecko. >> */ >> if (typeof e[0] != "undefined" && typeof e.options == "undefined") > > I don't care for that. You should. If the second `typeof' test would be omitted, execution would enter the loop with a SELECT element in a Gecko-based UA. >> { >> for (var j = 0, len2 = e.length; j < len2; j++) >> { >> serializeControl(e[j]); >> } >> } >> else >> { >> serializeControl(e); >> } >> [...] PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16
From: David Mark on 18 Dec 2009 16:36 On Dec 18, 4:02 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > David Mark wrote: > > Thomas 'PointedEars' Lahn wrote: > >> items.add(o.name, o.options[o.selectedIndex].value); > > > This is a problem. You need to know if the value attribute is > > present. Depends on the context, of course. > > You are mistaken. Keep in mind that this is supposed to serialize the form > as if it was submitted as usual. I know what it is supposed to do and you are mistaken. What do you make of these? <option></option> <option>test</option> <option value=""></option> <option value="">test</option> > > >> [...] > >> for (var i = 0, opts = o.options, len = opts && opts.length; > >> i < len; i++) > >> { > >> var opt = opts[i]; > >> if (opt.selected) > >> { > >> items.add(o.name, opt.value); > > > Same here. > > No. Yes. :) > > >> if (!isMethod(items, "push")) > > > Is this the host method test function? > > It is a general one. I make no distinction there. > > >> /* > >> * Elements with the same name create a NodeList object, > >> * however options of select objects are also indexable in Gecko. > >> */ > >> if (typeof e[0] != "undefined" && typeof e.options == "undefined") > > > I don't care for that. > > You should. If the second `typeof' test would be omitted, execution would > enter the loop with a SELECT element in a Gecko-based UA. I understand why, but don't like the way you did it.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Redirect after child loads, without sending data back from child Next: kaviya number visit now |