[jQuery] jQuery form Validation plugin with JSP
I have a static html page for testing and the remote field is wired correctly with email as the following rules: { FirstNameEdit: { required: true }, LastNameEdit: { required: true }, EmailEdit: { required: true, email: true, remote: emails.jsp } , EnrollYear: {required: true} }, messages: { FirstNameEdit: {required:First name is required}, LastNameEdit: {required:Last name is required}, EmailEdit: {required:Valid email address is required, remote:Incorrect email address}, EnrollYear: {required:Choose one from the list} } The emails.jsp page is very simple page as the following %@ page language=java contentType=text/html; charset=UTF-8 pageEncoding=UTF-8% html headtitleRemote Email Validator/title/head body % //get an instance of the email validator if (request.getParameter(email) == null) { out.print(false); } else { String email =request.getParameter(email); email = email.trim(); if(email.equals(a...@email.com)){ out.print(false); } else{ out.print(true); } } % /body /html I would like to know what did I do wrong such that email is not using the result from emails.jsp when making a remote validation. Thanks, Felix
[jQuery] jQuery Accessible RIA
I posted this to jQuery a11y and Jörn Zaefferer advised me to post this to the en and ui groups. So here it is: A few month ago I asked a bunch of questions in the a11y group to support my master thesis. I finished my work 6 weeks ago and now im ready to show my results: jQuery Accessible RIA, a collection of strictly WAI WCAG 2.0 and WAI ARIA conform web applications based on the popular Java-Script framework jQuery (using the UI Widget Factory). My goal was to provide some accessible, usable and easy to implement widgets to improve quality and working speed in frontend developers’ daily routine. So I picked some of the most seen design patterns on the web: currently a lightbox app, live form-validation, accessible tabs and sortable tables are ready to use. The code and the thesis are both licensed under a Creative Commons Attribution-Share Alike 3.0 Unported Licence. So please feel free to use my work, even in your commercial projects! Please check out the wiki at GitHub to learn about the features and how to use. There will definitely be further development and some handy new widgets, so it would be great to get some feedback in code quality and accessibility. http://wiki.github.com/fnagel/jQuery-Accessible-RIA yours Felix Nagel ps: Would be nice if you could post, tweet or talk about it :-)
[jQuery] Event click not fired by code added after the page is loaded
Hello, I have a page with a form, that represent questions and the corresponding answers. I defined the minimum questions, answers, and their maximum. So I added a link in the form to add question (along with the minimum amount of answers), and a link per question to add an answer in it. the click event for my links is like: $(document).ready(function(){ $(.addquestion).click(function(event){...}); $(.addanswer).click(function(event){alert(addanswer);...}); }); As I'm new to JQuery, the code look more like JS, but basically it adds the html code in the corresponding divs. The problem is the following: if I add a question, it also add a link to add answers to this question, but this link does not fire the event. Did I miss something to add to make it work? I mean the link in html page is exactly the same, I even tried not changing the part with the int, it still doesn't work. Thank you for your answers
[jQuery] Re: Event click not fired by code added after the page is loaded
Ok, I answer myself as I founded the answer, in case it can help someone: instead of $(.addanswer).click(function(event){});, put: $(.addanswer).live(click, function(){...}); On 14 août, 10:46, Felix slay0mit...@gmail.com wrote: Hello, I have a page with a form, that represent questions and the corresponding answers. I defined the minimum questions, answers, and their maximum. So I added a link in the form to add question (along with the minimum amount of answers), and a link per question to add an answer in it. the click event for my links is like: $(document).ready(function(){ $(.addquestion).click(function(event){...}); $(.addanswer).click(function(event){alert(addanswer);...});}); As I'm new to JQuery, the code look more like JS, but basically it adds the html code in the corresponding divs. The problem is the following: if I add a question, it also add a link to add answers to this question, but this link does not fire the event. Did I miss something to add to make it work? I mean the link in html page is exactly the same, I even tried not changing the part with the int, it still doesn't work. Thank you for your answers
[jQuery] select input within a table cell with wildcard
Hi all, I am running into the following problem. TABLE width=820PX align=center border=0 id=editableTable TR class=rowbgon TD colspan=1 nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; input type=hidden id='Seq_0' value=1509/ /TD TD colspan=1 input type=text name=Number value=0.1.1 style=width: 113px id=FormDraft_0_2/TD TD colspan=1 input type=text id=name value=me / /TD TD colspan=1 input type=text name=receivedDate value=22-Oct-2008 readonly=readonly style=width:113px id=RecivedDate_0_4/TD TD colspan=1 input type=text id=recDate value=01-Nov-2008/ TD colspan=1 input type=text name=actualCompletionDate value=01- Nov-2008 readonly=readonly style=width:113px id=ActualCompletionDate_0_5/td TD colspan=1 input type=text id=ACDDate value=01-Nov-2008/ /TD /TR /table My Jquery looks like this $(#editableTable input[id*='ActualCompletionDate_']).each(function (){ alert(selected = +$(this).val()); }); and when I ran it, nothing is alert out
[jQuery] Re: select input within a table cell with wildcard
Thanks for the information. I will try that out tomorrow. On Dec 10, 6:28 pm, MorningZ [EMAIL PROTECTED] wrote: It is because you are not understanding what means in a selector http://docs.jquery.com/Selectors/child#parentchild Matches all child elements specified by child of elements specified by parent so while #editableTable is the id of the table tag, then $(#editableTable input) wouldn't grab anything since there are no input objects that are direct children of the parent table drop the and your jQuery code should work fine On Dec 10, 9:21 pm, Felix [EMAIL PROTECTED] wrote: Hi all, I am running into the following problem. TABLE width=820PX align=center border=0 id=editableTable TR class=rowbgon TD colspan=1 nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; input type=hidden id='Seq_0' value=1509/ /TD TD colspan=1 input type=text name=Number value=0.1.1 style=width: 113px id=FormDraft_0_2/TD TD colspan=1 input type=text id=name value=me / /TD TD colspan=1 input type=text name=receivedDate value=22-Oct-2008 readonly=readonly style=width:113px id=RecivedDate_0_4/TD TD colspan=1 input type=text id=recDate value=01-Nov-2008/ TD colspan=1 input type=text name=actualCompletionDate value=01- Nov-2008 readonly=readonly style=width:113px id=ActualCompletionDate_0_5/td TD colspan=1 input type=text id=ACDDate value=01-Nov-2008/ /TD /TR /table My Jquery looks like this $(#editableTable input[id*='ActualCompletionDate_']).each(function (){ alert(selected = +$(this).val()); }); and when I ran it, nothing is alert out
[jQuery] dynamically generated form
I have a form that allows user to add and delete rows as they desire, I tried to use the clone function but the problem is the clone give the same id as the previous row and causes trouble duirng form submission. Also, one of the column have input that is a JQuery datepicker, I am wondering if the action is going to be preserved? Thanks, Felix
[jQuery] Re: Looking for a pop window to use for editing data in a table
I am interested in it as well. Also, if it is possible to pass data to and from the modal dialog when it is created? Can you give some detail description? Thanks On Oct 10, 4:33 am, MorningZ [EMAIL PROTECTED] wrote: Well, the UI Dialog (and jqModal) are just div's, so they are part of the page and can do exactly what you want... put a submit button inside the modal div and it'll work Suggestion those, instead of refreshing the whole page just because the user changed a row of data, just change said objects that were changed On Oct 10, 5:06 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I'm looking for some kind of modal window like the UI dialogue that may do true form submission and refreshes the parent window. Here's the scenario I'm looking to accomplish. I have a table of data, one of the column is editable. If the user clicks on the column of a particular table row, a modal window will pop up asking for additional information. The user fills out the information and submits. The window updates the info for that table via ajax and then force a refresh so the data in the table could be updated. Any idea if there's any plugins that may aid in accomplishing something like above using jQuery? Thanks
[jQuery] Re: JQuery Form Plugin and json
Does jQuery provides a way to convert to JSON string? Felix Halim On Tue, Sep 9, 2008 at 10:22 PM, Mike Alsup [EMAIL PROTECTED] wrote: I'm using the jQuery Form PlugIn(http://www.malsup.com/jquery/form/) to handle my Forms. I like it, but I have a question about an improvment: At this time all form fields are send using post, but it wold be nice, to send all form fields json encoded as one post parameter. Is there a way to do this? I still searching for a solution for this... Hope, the developer is reading here :-) Greetings, Stefan Sturm It's not supported by the plugin, but you can hook the beforeSubmit event and change what is posted to the server. beforeSubmit is passed an array of objects with name and value properties. You could iterate over these, build your json string, and then replace the array contents with a single object that has name and value properties, where the value prop is the json string. Mike Mike
[jQuery] Re: Superfish
Thank you very much... I tried this with another script, but at this point i didn't work. Now it's working! Thanks again! On 21 Aug., 03:33, ak732 [EMAIL PROTECTED] wrote: Try adding position:relative and z-index:1 to your top_menu css.
[jQuery] Superfish
Hi, I have a problem to get superfish working in IE. The problem is i have fixed div's and the menu doesn't extend over the borders. Here's my code: CSS: #top_menu { position:relative; left:0px; width:920px; height:30px; padding-top:20px; padding-left:35px; padding-right:45px; background: url(../img/design-design_02.gif); background-repeat: no-repeat; font-size: 11px; text-align:center; HTML: div id=top_menu ul class=sf-menu li class=current a href=#aAuftragsverwaltung #8595;/a ul li a href=#aaAngebote/a /li li class=current a href=#abAufträge #8594;/a ul li class=currenta href=#offen/a/li lia href=#abaabgeschlossen/a/li lia href=#abbstorniert/a/li /ul /li li a href=#menu item #8594;/a ul lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li /ul /li li a href=#menu item #8594;/a ul lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li lia href=#menu item/a/li /ul /li /ul /li /div I can't get it working to show the menu outside the div. Could someone give me a idea? It works in FF and Safari... But IE (6.0 7.0) don't work... Thanks in advance... Felix (Germany)
[jQuery] [autocomplete] required jquery version
Hi, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ states that the required version of jquery is 1.2.6. Is there a list why 1.2.6 is necessary? I write a trac plugin and trac 0.11 only ships 1.2.3 but I don't like to/can't insert my own version of jQuery. fs
[jQuery] [autocomplete] custom parse function
Hi, still using the autocomplete script from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ Currently the script expects by default that the response contains the data as visible text|other data with one item per line (at least this is what I figured out from reading the source, I did not find any documentation about this - maybe I'm wrong!). I have an application which returns HTML because this was the preferred format for another autocompletion script which uses a different js library. Now I want to make the switch to jQuery but I don't want to change the application if not absolutely necessary. It was quite easy using a custom parse function by using the parse option (again, undocumented). But for me its much easier to just transform my data into the default format and let the default parse function do its job. But I did not find a way to call the default parse function so I ended up copying it. Is there another way? Furthermore I like to know if custom parse functions are an official features (I did not find any documentation about them) or if they are likely to go away in the future... fs
[jQuery] [autocomplete] custom parse function
Hi, still using the autocomplete script from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ Currently the script expects by default that the response contains the data as visible text|other data with one item per line (at least this is what I figured out from reading the source, I did not find any documentation about this - maybe I'm wrong!). I have an application which returns HTML because this was the preferred format for another autocompletion script which uses a different js library. Now I want to make the switch to jQuery but I don't want to change the application if not absolutely necessary. It was quite easy using a custom parse function by using the parse option (again, undocumented). But for me its much easier to just transform my data into the default format and let the default parse function do its job. But I did not find a way to call the default parse function so I ended up copying it. Is there another way? Furthermore I like to know if custom parse functions are an official features (I did not find any documentation about them) or if they are likely to go away in the future... fs smime.p7s Description: S/MIME Cryptographic Signature
[jQuery] [autocomplete] Display a busy indicator?
Hi, I use the autocomplete script from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ There is something I could not figure out: Is it possible to show an busy indicator while the results are fetched from a remote server? thanks, fs
[jQuery] [autocomplete] Display a busy indicator?
Hi, I use the autocomplete script from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ There is something I could not figure out: Is it possible to show an busy indicator while the results are fetched from a remote server? thanks, fs smime.p7s Description: S/MIME Cryptographic Signature
[jQuery] Re: required jquery version
MorningZ schrieb: Right from the changelog (http://jquery.bassistance.de/autocomplete/ changelog.txt): * Updated package to jQuery 1.2.5, removing dimensions older versions (not exactly sure how old though) didn't have the dimensions built in Thanks for your answer. :-) So I hope everything will continue to work if I just ship the dimensions myself... Does it do any harm if I ship dimensions and trac decides to update jQuery to 1.2.5? fs smime.p7s Description: S/MIME Cryptographic Signature
[jQuery] Re: remove() deletes events in jQuery 1.2.1. Why?
Hey, http://brandonaaron.net/docs/livequery/ Destroying events connected to a removed element helps prevent memory leaks -- it is really the correct behavior. Well in most cases it probably is. However I actually got my own little framework used by all plugins I wrote, which attaches events to elements, and cleans them up when I destroy them . However, in this particularly case I was just temporarily removing an a from the DOM while replacing it with an input element for editing. I've changed it to use show() / hide() for now as it doesn't really make much of a difference, I was just interested in why I had to do it. I don't use livequery b/c I don't want to deal with the performance hit. My solution is fairly similar in terms of defining hash table of selectors to apply whenever an element is generated, but its tied into my internal event system and knows about its scope so its not trying to bind stuff whenever some dom manipulation method is run. Anyway thanks alot for the explanations!! -- Felix -- Blogger: http://www.thinkingphp.org/ Entrepreneur: http://www.posttask.com/ /-- currently in private beta, ask me for invite / password/ Freelancer: http://www.fg-webdesign.de/ AIM:theundefined87 Skype: TimeFor23 Other IM: felixge.de http://felixge.de/ Mobile (USA): +1 404 3888693 Mobile (GER): +49 162 9391612 Twitter:http://twitter.com/felixge Jeffrey Kretz wrote: If you haven't seen the livequery plugin, I would recommend looking it over -- this would really be the correct solution to this. http://brandonaaron.net/docs/livequery/ Destroying events connected to a removed element helps prevent memory leaks -- it is really the correct behavior. JK *From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Felix Geisendörfer *Sent:* Tuesday, November 06, 2007 1:46 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] remove() deletes events in jQuery 1.2.1. Why? Hey, I recently upgraded my app from jQuery 1.3.1 to 1.2.1 and the transition was incredibly easy. However, yesterday I noticed that $().remove() now seems to behave differently then it did in 1.3.1. Thats because now it deletes any events attached to the element removed. This happens to be a problem in my app b/c I remove unneeded elements from the DOM instead of hiding them and inject them back in later on. So when they are injected again, they suddenly don't work anymore : ). Now I looked through the manual and it says this is going to be the expected behavior in 1.2.2: http://docs.jquery.com/Manipulation/remove Which confuses me b/c it already seems to be the case in 1.2.1 and I'm also wondering how I could remove DOM elements without deleting their events in future? I'm also curious about why this change is being made, is it some anti-memory leak thingy? Thanks a lot, -- Felix -- Blogger: http://www.thinkingphp.org/ Entrepreneur: http://www.posttask.com/ //-- currently in private beta, ask me for invite / password// Freelancer: http://www.fg-webdesign.de/ *AIM:* theundefined87 *Skype:* TimeFor23 *Other IM:* felixge.de http://felixge.de/ *Mobile** (USA):* +1 404 3888693 *Mobile** (GER):* +49 162 9391612 *Twitter:* http://twitter.com/felixge
[jQuery] remove() deletes events in jQuery 1.2.1. Why?
Hey, I recently upgraded my app from jQuery 1.3.1 to 1.2.1 and the transition was incredibly easy. However, yesterday I noticed that $().remove() now seems to behave differently then it did in 1.3.1. Thats because now it deletes any events attached to the element removed. This happens to be a problem in my app b/c I remove unneeded elements from the DOM instead of hiding them and inject them back in later on. So when they are injected again, they suddenly don't work anymore : ). Now I looked through the manual and it says this is going to be the expected behavior in 1.2.2: http://docs.jquery.com/Manipulation/remove Which confuses me b/c it already seems to be the case in 1.2.1 and I'm also wondering how I could remove DOM elements without deleting their events in future? I'm also curious about why this change is being made, is it some anti-memory leak thingy? Thanks a lot, -- Felix -- Blogger: http://www.thinkingphp.org/ Entrepreneur: http://www.posttask.com/ /-- currently in private beta, ask me for invite / password/ Freelancer: http://www.fg-webdesign.de/ AIM:theundefined87 Skype: TimeFor23 Other IM: felixge.de http://felixge.de/ Mobile (USA): +1 404 3888693 Mobile (GER): +49 162 9391612 Twitter:http://twitter.com/felixge
[jQuery] Re: SITE: http://www.foodnetwork.com/
Hey, We're taking over people...we'll soon be reaching critical mass where businesses will be LOOKING for people who know jQuery! Are you kidding me? This has long happened! I've seen a ton of job / gig advertisements asking for jQuery expertise in the past : ). But yeah, eventually people will be like Moo...jo...proto...what : )? (Dojo might be an exception actually, I can see reasons people would want to use dojo). -- Felix -- Blogger: http://www.thinkingphp.org/ Entrepreneur: http://www.posttask.com/ /-- currently in private beta, ask me for invite / password/ Freelancer: http://www.fg-webdesign.de/ AIM:theundefined87 Skype: TimeFor23 Other IM: felixge.de http://felixge.de/ Mobile (USA): +1 404 3888693 Mobile (GER): +49 162 9391612 Twitter:http://twitter.com/felixge Andy Matthews wrote: Don't know if this has already been posted or not, but it appears that FoodTV giant FoodNetwork.com is using jQuery (1.1.4): http://www.foodnetwork.com/ We're taking over people...we'll soon be reaching critical mass where businesses will be LOOKING for people who know jQuery! hip hip hooray. andy
[jQuery] Faster then innerHTML
Here is an interesting blog post that I came across: http://blog.stevenlevithan.com/archives/faster-than-innerhtml The synopsis basically is that one can gain dramatic speed improvements on setting innerHTML when removing items that are going to be overwritten using DOM methods before inserting stuff via innerHTML. I could see how this would be a need addition to jQuery. -- Felix PS: If you like regex make sure to subscribe to this guys blog, he has some mad skills going on. -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de
[jQuery] Re: New plugin - Lazy Load
Very cool! That's a great idea to save traffic and optimize load times on image heavy pages. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Mika Tuupola wrote: Little something I worked on sunday. http://www.appelsiini.net/projects/lazyload Plugin which enables deferred loading (lazy loading) of images. In other words, images which are below the fold (far down the page not visible in browser) are not loaded before user scrolls down. This plugin should be useful with long pages which have lot of photo content. For example photoblogs. Demo pages is available. You might want to use Firebug or liveHTTP headers to better see what is happening. http://www.appelsiini.net/projects/lazyload/enabled.html
[jQuery] Re: Instant Messaging Capabilities
Um, that's not really a donation then, is it? --John This probably needs a new / better term. I read a while ago about some independent musician making more money then he/she'd make on iTunes by letting the people decide how much they pay for it. Theoretically you could 'donate' $0.01. The idea is that the buyer shows that he values whatever he is interested in and is willing to make whatever big (commercial) effort to honor it. I'd be interested in what you guys can come up with in terms of a new label / term for it? Donation is pretty misleading I'd think. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de John Resig wrote: The home of yShout is at http://yurivish.com/yshout/ Yuri only requires a small donation and he will send you the link to a zip file. Um, that's not really a donation then, is it? --John
[jQuery] Re: Looking for a calendar picker that allows for two instances on one page
I saw that, but I want to actually display the calendar itself, not just on popup, but fully displayed. AFAIK kevin's plugin is capable to do this. See: http://kelvinluck.com/assets/jquery/datePicker/v2/demo/renderCalendar.html -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Andy Matthews wrote: I saw that, but I want to actually display the calendar itself, not just on popup, but fully displayed. From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Alex Ezell Sent: Thursday, August 30, 2007 4:40 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Looking for a calendar picker that allows for two instances on one page Andy, I've used datePicker[1] from Kelvin Luck to do multiple date fields on the same page. I am still using v1 (because I am too lazy to update it and test the new v2), but I'm sure v2 would work fine for you. There are some cool things being done with time and date pickers that work nicely if you need time. [1] http://kelvinluck.com/assets/jquery/datePicker /alex On 8/30/07, Andy Matthews [EMAIL PROTECTED] wrote: I'm working on an app which allows users to search against data in our db using a date range (start, end). What I need is a calendar which allows a user to select both dates, then click submit. So I need a calendar which allows for two instances of itself on one page. I'm looking at jCalendar: http://tedserbinski.com/jcalendar/index.htmlwhich looks really great. But does anyone know if there's a better one? Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com
[jQuery] Select all elements except the first and the 3 last ones?
Hey folks, I need to select all but the first and the 3 last rows of a table. I found out that the following works: $('table tr:gt(0):not(:last:last:last)') Whoever it does not seem particular elegant to me and jQuery is always (!) elegant, so I'm wondering if one of you could come up with something cooler : ). (I know that giving the elements I'm looking for a class name is probably the desirable solution in the long run but I'm interested in the problem itself and changing the markup is cheating ^^) -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de
[jQuery] Re: Select all elements except the first and the 3 last ones?
Yeah that one-liner is sweet. I guess I was thinking too much about a selector. The project I need this for does run an older jQuery version and the deadline is preparing to make this ugly ugly sound that you get when not only upsetting the client but also ruining his business - so updating, hoping none of the virtually several hundred JS enhanced pages won't break is not in reach right now ; ). Anyway, thanks for the tip I'll keep it in mind : ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de John Resig wrote: Here's a one-liner: $('table tr').slice(1,-3); --John On 8/29/07, Joel Birch [EMAIL PROTECTED] wrote: Hi Felix, As of jQuery 1.1.4 there is a new slice() method which works similar to the JavaScript native Array.slice() method, except on jQuery objects. Therefore, I guess you could do something like: var $rows = $('table tr'); $rows.slice(1,$rows.length-3); I may not have calculated the slice parameters properly because I wanted to post this quick enough to beat Karl to the punch :) Joel Birch.
[jQuery] Re: One callback for two ajax requests
This just cried for an elegant solution, and I'm in anything-but-client-work-mood again : ). So here it comes: Usage: --- var Stack = new Callstack(); $.getJSON(jsonA.js, {}, Stack.add('requestA')); $.getJSON(jsonB.js, {}, Stack.add('requestB')); Stack.onComplete = function(stack) { console.log('All request are completed, see:', stack); console.log('Response from requestA:', stack.requestA.arguments[0]); } --- Code you need to use the above: --- var Callstack = function() {} $.extend(Callstack.prototype, { stack: {_length: 0} , add: function(name, callback) { if ($.isFunction(name)) { callback = name; } if (arguments[1] typeof arguments[1] == 'string') { name == arguments[1]; } if (name == '_length') { throw 'Callstack::add - Forbidden stack item name _length!'; } if (!name) { name = this.stack._length; } var item = { arguments: [] , callback: callback , completed: false }; this.stack[name] = item; this.stack._length++; var self = this; return function() { self.handle(item, arguments); } } , update: function() { var completed = true; $.each(this.stack, function(p) { if (p != '_length') { completed = completed this.completed; } }); if (completed == true) { delete this.stack['_length']; this.onComplete(this.stack); } } , handle: function(item, args) { var r; if ($.isFunction(item.callback)) { r = callback.apply(item.callback, args); if (r === false) { return r; } } item.arguments = args; item.completed = true; this.update(); return r; } , onComplete: function() { alert('Stack done executing!'); } , reset: function() { this.stack = {}; } }); --- I also threw in some good stuff, for example you do not have to explicitly name you stack items, it will use auto-incrementing values automatically if you don't. Also: You can pass a callback to the Stack.add() function that acts as a gatekeeper for determining if the stack item has executed successfully. If that function returns falls then the stack item will not be thought of as completed and the item can be triggered again using Callstack.handle(). One could also base a little plugin on this that will only trigger a function if all elements in the current selection have triggered a certain event: Sample usage: --- $(function() { $('a').stack('click', function(stack) { console.log('All links in this document where clicked once! See:', stack); }, function() { // Cancel link default event return false; }); }); --- Plugin code: --- $.fn.stack = function(event, onComplete, fn) { var Stack = new Callstack(); this.each(function() { var stackFn = Stack.add(); $(this)[event](function() { var r; if ($.isFunction(fn)) { r = fn.apply(this, arguments); } stackFn.apply(this, arguments); return r; }); }); Stack.onComplete = onComplete; } --- Hmm, I guess I should have and eventually will make a blog post about this. Meanwhile I hope you or somebody else finds it useful : ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Michael Geary wrote: Good ideas, Thiago. The second one - nested AJAX calls - will definitely work, and it is probably the simplest way to do this: $.getJSON(url1, {}, function( json1 ) { $.getJSON(url2, {}, function( json2 ) { // do something with json1 and json2 }); }); That does serialize the two AJAX/JSON calls instead of firing them both off at once, though. (The second request is made when the first one finishes.) If you want to fire the two AJAX calls together (especially a good idea if they are coming from different servers), then you'd want something like your first idea. There is one bug
[jQuery] Re: App similar to Google Homepages
A bit dated, but maybe kind of what you are looking for: http://sonspring.com/journal/jquery-portlets -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Andy Matthews wrote: Hey all... I'm in the process of writing an app that will offer information to our clients. The interface is open at this point, but I'm looking at the possibility of a display type similar to Google Homepages. It would be "module" based in that there would be multiple boxes containing various bits of information, and the user would be able to move these boxes around in a grid based system. Can anyone offer some input as to where I should start looking for this sort of thing? I'm sure that there are drag and drop plugins already, but I'm not sure of what all I would need. Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com
[jQuery] Re: $.clone
My function for cloning looks like this: It covers objects, arrays, functions and jQuery objects / custom objects with an own clone() function: -- $.extend({ clone: function(obj, deep) { // Clone a jQuery object / objects with a custom clone function if (obj obj obj.clone $.isFunction(obj.clone)) { return obj.clone(deep); } // Clone a function if ($.isFunction(obj)) { return function() {return obj.apply(this, arguments);}; } if (obj obj.constructor == Array) { // Clone an array var clone = []; for(var i = 0; i obj.length; i++) { clone[i] = (deep == true) ? obj[i] : $.clone(obj[i], deep); } return clone; } else if (obj obj.constructor == Object) { // Clone an object var clone = {}; for (var p in obj) { clone[p] = (deep == true) ? obj[p] : $.clone(obj[p], deep); } } return clone; } -- I'm interested to hear feedback, -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Erik Beeson wrote: Thanks for sharing this. I'm pretty sure what you suggest won't properly deal with arrays. Objects aren't the same as arrays. Here's how I do something like that: function deepCopy(obj) { if(obj obj.constructor == Object) { var newObj = new Object(); for(var field in obj) { newObj[field] = deepCopy(obj[field]); } return newObj; } else if(obj obj.constructor == Array) { var newArray = new Array(); for(var i = 0; i obj.length; i++) { newArray[i] = deepCopy(obj[i]); } return newArray; } return obj; } Also, while it's fine to use $ however you want in your own code, for code that you're making public, I suggest you checkout the plugin authoring guide about not using $ directly: http://docs.jquery.com/Plugins/Authoring#Custom_Alias --Erik On 8/5/07, *weepy * [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: During assingment, if the object is not primative, Javascript will return a pointer to the object rather than a copy. E.g. a = [1,2] b = a b[0]=3 a == [3,2] This clone function makes it possible to copy an object. $.clone = function (obj) { if(typeof(obj) != 'object') return obj; if(obj == null) return obj; var newobj = new Object(); for(var i in obj) newobj[i] = $.clone(obj[i]); return newobj; } a = [1,2] b = $.clone(a) b[0]=3 a == [1,2] I have found this function invaluable when comparing and complex Javascript objects.
[jQuery] Re: $.clone
BTW: you are missing a final ) Haha, ok it's official - I suck. Or at least am not allowed to paste code in here that I haven't at least given a quick firebug trial ; ). 1) I tried to replace my version with it and it didn't work. I did add in the $.clone(xxx,true) to my code. It wasn't obvious why it didn't work. Can you paste the code you tried and that shows the function failing? 2) Speed. Cloning can be quite slow due to the recursion. Is it possible to move the jQuery specific stuff to the end so it's not always run by default ? Give me a break ; ). I would of course need to benchmark this, but I doubt you'd gain any significant speed by that. Optimizing your jQuery selectors is a *much* better place to worry about speed. That being said, I think none of the stuff could be moved to the bottom as $.isFunction could theoretically return true for objects that have the constructor Object (somebody correct me if I'm wrong). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de weepy wrote: BTW: you are missing a final ) 2 comments : 1) I tried to replace my version with it and it didn't work. I did add in the $.clone(xxx,true) to my code. It wasn't obvious why it didn't work. 2) Speed. Cloning can be quite slow due to the recursion. Is it possible to move the jQuery specific stuff to the end so it's not always run by default ? On Aug 5, 6:46 pm, the_undefined [EMAIL PROTECTED] wrote: Sry for spamming the list, but I just spotted another error (that's what you get when doing quick refactorings for posting stuff in public without testing them properly ^^). Full code again / last post: $.extend({ clone: function(obj, deep) { // Clone a jQuery object / objects with a custom clone function if (obj obj obj.clone $.isFunction(obj.clone)) { return obj.clone(deep); } // Clone a function if ($.isFunction(obj)) { return function() {return obj.apply(this, arguments);}; } if (obj obj.constructor == Array) { // Clone an array var clone = []; for(var i = 0; i obj.length; i++) { clone[i] = (deep == true) ? obj[i] : $.clone(obj[i], deep); } return clone; } else if (obj obj.constructor == Object) { // Clone an object var clone = {}; for (var p in obj) { clone[p] = (deep == true) ? obj[p] : $.clone(obj[p], deep); } return clone; } return obj; } } -- Felix On Aug 5, 7:42 pm, the_undefined [EMAIL PROTECTED] wrote: Ups, that last line should read: return obj; not 'return clone;'. On Aug 5, 7:30 pm, Felix Geisendörfer [EMAIL PROTECTED] wrote: My function for cloning looks like this: It covers objects, arrays, functions and jQuery objects / custom objects with an own clone() function: -- $.extend({ clone: function(obj, deep) { // Clone a jQuery object / objects with a custom clone function if (obj obj obj.clone $.isFunction(obj.clone)) { return obj.clone(deep); } // Clone a function if ($.isFunction(obj)) { return function() {return obj.apply(this, arguments);}; } if (obj obj.constructor == Array) { // Clone an array var clone = []; for(var i = 0; i obj.length; i++) { clone[i] = (deep == true) ? obj[i] : $.clone(obj[i], deep); } return clone; } else if (obj obj.constructor == Object) { // Clone an object var clone = {}; for (var p in obj) { clone[p] = (deep == true) ? obj[p] : $.clone(obj[p], deep); } } return clone; } -- I'm interested to hear feedback, -- Felix -- My Blog:http://www.thinkingphp.org My Business:http://www.fg-webdesign.de Erik Beeson wrote: Thanks for sharing this. I'm pretty sure what you suggest won't properly
[jQuery] Re: [ANN] Dimensions 1.0 final is finally here!
You rock! I cannot imagine working without your plugin on complex/fancy UI stuff anymore ; ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Brandon Aaron wrote: The 1.0 release of Dimensions is finally here. It has been a long time in the making. Thanks to everyone who helped me test it! You can get the details and see an example using the new position method over at my blog: http://blog.brandonaaron.net/2007/07/22/dimensions-10/ You can download dimensions from the project page: http://jquery.com/plugins/project/dimensions Or via SVN: http://jqueryjs.googlecode.com/svn/trunk/plugins/dimensions/ If you find any bugs or have any feature requests ... be sure to report them at the dimensions project page. Oh... and you can check out the documentation over here: http://brandonaaron.net/docs/dimensions/ Thanks! -- Brandon Aaron
[jQuery] Re: Announce: Confirmer plugin
Cool idea. Just add support for a class that's being added to the button when in 'confirm' mode - otherwise there is no way to visually highlight this new UI approach for the user ; ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Stephan Beal wrote: Hi again, all! Confirmer is a plugin for jQuery which implements a novel approach to the process of confirming an action. Normally this is achieved via a yes/no dialog box or a button with a confirm checkbox next to it. The Confirmer plugin instead sets up a single button which changes to a confirm the action state if it is clicked one time. If the button is clicked again within a specified time then the action is confirmed, otherwise it times out and returns to its initial state. http://wanderinghorse.net/computing/javascript/jquery/confirmer/ Includes a live demo link. Happy hacking!
[jQuery] Re: Site Offline?
I have over 1000 emails a day frequently... and then there are RSS feeds. I don't read them all. Wasn't trying to be smart, don't flame someone until they earn it. :) You should forward most of that to people who actually have the time to read that many emails and are chronically depressed because their inbox is always empty. Has worked great for me in the past : ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de John Farrar wrote: Rey, I have over 1000 emails a day frequently... and then there are RSS feeds. I don't read them all. Wasn't trying to be smart, don't flame someone until they earn it. :) John Rey Bango wrote: Smartass! ;) Let me see whats up. Rey... John Farrar wrote: Did I miss an announcement that jQuery.com would be down this morning?
[jQuery] Re: Getting user agent stats with jQuery...
Alternately, does anyone know of some reliable piece of software which does this same sort of thing, but maybe cheaper? Google Analytics - it's free. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Andy Matthews wrote: My company currently uses a product called BrowserHawk, a combination of_javascript_ and Java files, to get a set of user data which we then store in our database. Currently this data set includes Flash player version, OS, Browser (and version),Screen Res, and more. The drawback is that this software is expensive, around $1000 per server (we have 3 right now), and we're not fully using the data it provides to us anyway. I know that jQuery core can provide browser (and version?), and I also know that you can get screen res with the dimensions plugin. I'm wondering if anyone has considered writing a jQuery plugin which mimics this behavior, returning an object containing user agent information. Alternately, does anyone know of some reliable piece of software which does this same sort of thing, but maybe cheaper? Thanks for the input. Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com
[jQuery] Re: Getting user agent stats with jQuery...
We wouldn't use it in "real-time" but we would need to be able to store that data ourselves and not just access it via their interface. You can aggregate and store it yourself. I wrote some code a while back that does that (it's for the CakePHP framework but could be decoupled from it or alternatively rewritten in any other language). http://www.thinkingphp.org/2006/06/19/google-analytics-php-api-cakephp-model/ -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Andy Matthews wrote: We wouldn't use it in "real-time" but we would need to be able to store that data ourselves and not just access it via their interface. Is that still possible? From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Aaron Porter Sent: Monday, July 16, 2007 12:04 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Getting user agent stats with jQuery... If you are only interested in storing the data (not using it real time) you may want to look into google analytics. http://www.google.com/analytics/ It has lots of info including browser type and version, operating system, screen resolution, colors, flash version, java version, and lots more. It has a very slick interface. Best of all it's free! Aaron Andy Matthews wrote: My company currently uses a product called BrowserHawk, a combination of_javascript_ and Java files, to get a set of user data which we then store in our database. Currently this data set includes Flash player version, OS, Browser (and version),Screen Res, and more. The drawback is that this software is expensive, around $1000 per server (we have 3 right now), and we're not fully using the data it provides to us anyway. I know that jQuery core can provide browser (and version?), and I also know that you can get screen res with the dimensions plugin. I'm wondering if anyone has considered writing a jQuery plugin which mimics this behavior, returning an object containing user agent information. Alternately, does anyone know of some reliable piece of software which does this same sort of thing, but maybe cheaper? Thanks for the input. Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com
[jQuery] Re: Announce: jFeed - jQuery RSS/ATOM feed parser plugin
Nifty idea, but this will only work within a single domain, right? No there is a proxy.php file to the package that allows you to load RSS files from other sites. Or just read the files locally on his server if you get bored (hint: check the fopen call : ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Michael Geary wrote: Nifty idea, but this will only work within a single domain, right? From: Jean-Francois Hovinne jFeed is a new jQuery plugin which parses RSS/ATOM feeds. It uses jQuery's built-in AJAX functions to get the XML and basic selectors to parse it. More info on my blog: http://www.hovinne.com/blog/index.php/2007/07/15/132-jfeed-jquery-rss-atom-f eed-parser-plugin Download: http://www.hovinne.com/dev/jquery/jfeed/jquery.jfeed.tar.gz Any feedback is welcome.
[jQuery] Re: Announce: jFeed - jQuery RSS/ATOM feed parser plugin
BTW, a basic one is provided in the archive for testing purposes. Oh in that case nevermind my last post. I guess the proxy.php is alright for *local* testing. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Jean-Francois Hovinne wrote: Yes, though you can use a server-side proxy to load external feeds. BTW, a basic one is provided in the archive for testing purposes. On 15 juil, 23:25, Michael Geary [EMAIL PROTECTED] wrote: Nifty idea, but this will only work within a single domain, right?
[jQuery] Re: Interested in porting another DOM creation plugin?
No kidding. I was disappointed to read about some of the missing things from javascript's implementation of regular expressions. No named groups and no look behinds. I'm still very new to javascript as a language, so I'm still feeling my way around some things. I'll post some results as soon as I have something worth showing. I really miss look-behind too! Maybe this could be hacked, but that's a rather ambitious goal ; ). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Josh Bush wrote: No kidding. I was disappointed to read about some of the missing things from javascript's implementation of regular expressions. No named groups and no look behinds. I'm still very new to javascript as a language, so I'm still feeling my way around some things. I'll post some results as soon as I have something worth showing. Josh On 7/13/07, *Jörn Zaefferer* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Josh Bush wrote: I think I may dig around the jQuery source to get some hints on parsing elements. I've yet to even take a peek inside! Beware of those regexp monsters! They can eat your brain. But there is nothing like a good brain eater for parsing strings... -- Jörn Zaefferer http://bassistance.de
[jQuery] Re: Syntactic sugar for checking whether an element exists
Christof: I appreciate your comments. Even more however I would have appreciated if you'd have taken into consideration why I made the proposal. I didn't do so because I personally need this functionality, but because I think both exists() and hasClass() would make the library more accessible to newcomers who do not understand the inner workings 100% perfectly. Now if you are saying that those should be educated rather then spoiled then you've got a valid point there. I just think that jQuery has gained a lot of it's popularity due to it's easy-to-learn factor (besides it's superiority and beauty that is : ) and think this could be a good addition to it. div class=myClass.../div div class=myOtherClass.../div $('div').hasClass('myClass'); What should this return now? It should return true. That's because $('a').attr('href') returns the 'href' attribute of the first anchor matched (afaik). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Christof Donat wrote: Hi, However, as you said this library is more then just code, it's art. And this is why I'm emphasizing those new functions: They empower the artist Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. (Antoine de Saint-Exupéry) Don't try to add paint to the Mona Lisa ;-) Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
But I don't think we disagree at all. I wasn't talking about .get() with no arguments, but rather .get(n) and .size(), which are just slower synonyms for [n] and .length. Yeah I agree with you on that. I just read: 'we should get rid of the get() function' and freaked : p -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Michael Geary wrote: There's no reason at all to stick with .get(n) and .size() now that the array-like jQuery object allows the simpler and more efficient [n] and .length. I disagree. Whenever you need to sort the elements in an ul or something then you'll have to use the Array.sort() function, so you need to do $('ul li').get().sort(...). Here is an example of where I needed this functionality: http://bin.cakephp.org/view/1632218532 It's not a big deal that I have to call get(), but it would be a big problem if it wasn't there! That's a good point about .get() with no arguments - it gives you a genuine Array object which can be quite useful. But I don't think we disagree at all. I wasn't talking about .get() with no arguments, but rather .get(n) and .size(), which are just slower synonyms for [n] and .length. -Mike
[jQuery] Re: Syntactic sugar for checking whether an element exists
if ($('#someID')) { // something matched the selector } See, and there you go making a wrong assumption that beginners are much more likely to run into. !![] is evaluating to true and so is a jQuery object that has not matched any items. I'm not blaming you for it, it's counter-intuitive (if you don't know objects always evaluate to true) but that's how JS works. So an exists() function could could probably help people avoiding this mistake. (Your other example where using [0] is a workable solution however) -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de RobG wrote: On Jul 10, 4:50 am, Sean Catchpole [EMAIL PROTECTED] wrote: I believe that learning jquery returns an array like object is more useful than creating a .exists() function. It seems to me that the most common reason for testing if an element exists is to use it later, so why not: var element; if ( (element=$('#someID')[0]) ) { /* element exists */ } else { /* damn... */ } Another idea is that if the seletor doesn't select any elements, return null (as does getElementById() in that case): if ($('#someID')) { // something matched the selector } but that may not be backward compatible. Of what use is an empty jQuery object? -- Rob
[jQuery] Re: Syntactic sugar for checking whether an element exists
In fact, if you find yourself doing a lot of if(something exists) { ... } else { ...}, you might want to consider trying to move some of your code into a plugin. The target audience for an exists() function would be new comers to jQuery. Those are generally a little scared about writing their own 'plugin' even so there isn't much to be scared about I think and I'm just making this assumption here ; ). Anyway, there are situations where plugins are not enough. For example if you have to modify other elements in case a certain screen element exists then a plugin won't really help you a lot unless it's very app-specifc. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Erik Beeson wrote: In fact, if you find yourself doing a lot of if(something exists) { ... } else { ...}, you might want to consider trying to move some of your code into a plugin. Most jQuery functions/plugins already deal with the if(exists)... part by simply not executing if nothing is selected. If you really want the 'else' part, you could imagine a simple plugin, something like (untested): $.fn.ifEmpty = function(f) { if(this.length == 0) f.apply(this); return this; } And use it like this: $('#foo').show().ifEmpty(function() { alert(foo doesn't exist); }); Which would show the element with ID foo, or show an alert if the element doesn't exist. Equivalent to: var $foo = $('#foo'); if($foo.length 0) { $foo.show(); } else { alert(foo doesn't exist); } Just an idea. --Erik On 7/9/07, Erik Beeson [EMAIL PROTECTED] wrote: Another idea is that if the seletor doesn't select any elements, return null (as does getElementById() in that case): ... but that may not be backward compatible. Of what use is an empty jQuery object? An empty jQuery object doesn't break chainability: $('#foo').hide(); Will hide the element with ID foo if it exists. Otherwise, it does nothing. If null were returned, that would generate a javascript error, so you would have to always check for the existence of the element if you wanted to be sure you didn't generate an error. This is one of the sweetest features of jQuery. --Erik
[jQuery] Re: Syntactic sugar for checking whether an element exists
jQuery is a language It was a library last time I checked ; ). and as such requires you to read at least a bit of documentation or examples before starting. Why? For me the sweetest thing about using jQuery has been it's intuitiveness right out of the box. When I started I just looked at some initial code samples (fancy API pages weren't around back then or I didn't know about them) and then was virtually able to 'guess' the jQuery functions I needed. Need to add a class? Hmm let me try addClass() - works, yeah! Now I want to remove an element from the DOM - oh remove() it is! So now I just need to check whether this element exists. Hm - exists() produces a fatal error. Let me search the docs: * http://docs.jquery.com/Special:Search?search=element+existsfulltext=Search http://docs.jquery.com/Special:Search?search=element+existsfulltext=Search * http://www.google.com/search?q=site%3Adocs.jquery.com%20element%20existshl=en http://www.google.com/search?q=site%3Adocs.jquery.com%20element%20existshl=en At this point I would need to actually post to the group or read the complete API docs in detail to find that is() is the answer to the problem. Same goes for hasClass() I think. Maybe .is() and .length should be more prominently visible in the doc, but I see no point in adding the .exists() and .hasClass() cruft to the (beautiful) jQuery code. I think is() is beautiful as well and there is nothing wrong with .length. However both pose a certain barrier for something new-comers will possibly try to do quite often. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Fil wrote: jQuery is a language and as such requires you to read at least a bit of documentation or examples before starting. Maybe .is() and .length should be more prominently visible in the doc, but I see no point in adding the .exists() and .hasClass() cruft to the (beautiful) jQuery code. -- Fil
[jQuery] Re: Syntactic sugar for checking whether an element exists
What about Array.prototype.sort.apply( $('li') ); Not sue if that'll work... I think that could work, but it's breaking chainability so I think the array plugin mentioned by Jörn earlier is a better alternative. However since I all I need is sort(), I actually am fine with using get() that one time. -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Klaus Hartl wrote: Felix Geisendörfer wrote: Felix, not to worry, there's nothing wrong at all with using .length - and it is obviously faster than a function call. I figured that by now. I think Matt was much better at explaining why I think an alternative exists() function is useful - it simply is the most intuitive thing a new jQuery user looks for. I also agree with his hasClass argument. I love the is() function, but I would have taken me a long time to find it if I my question was phrased Who can I determine if an element has a certain class.is() is more powerful but not nearly as intuitive as hasClass would be for new users. In the earliest versions of jQuery, the jQuery object was not an array, but had a private array object that you accessed using .get(n) and .size(). The only reason those functions still exist is for compatibility with old code. There's no reason at all to stick with .get(n) and .size() now that the array-like jQuery object allows the simpler and more efficient [n] and .length. I disagree. Whenever you need to sort the elements in an ul or something then you'll have to use the Array.sort() function, so you need to do $('ul li').get().sort(...). Here is an example of where I needed this functionality: http://bin.cakephp.org/view/1632218532 It's not a big deal that I have to call get(), but it would be a big problem if it wasn't there! What about Array.prototype.sort.apply( $('li') ); Not sue if that'll work... --Klaus
[jQuery] Re: Syntactic sugar for checking whether an element exists
ok, so next time i want to code something in jquery i'll just write $(make coffee) ? Haha, now I'm questioning your ambition. This is the holy grail of all programming, it's almost blasphemy to make fun of it ; ). For me (and I really mean not speaking for everyone) it's more intuitive if there is an internal logic that I can understand; Ok, I guess in this case the only language we share is jQuery ; ). Intuition irrational by definition, see: http://www.google.com/search?q=define:intuition. No, there are things that are intuitive **once you've understood the basics**. IOW intuitiveness is based on your assumptions and your knowledge. Why would you assume that .hasClass() exists? And not, e.g., isMemberOf() or .classMatches() ? It must depend of what you're already familiar with before you switch to jQuery. I agree with you that people will try to use stuff they know from other libraries first before falling back to intuition. So what would be two of the most popular ones to expect? Mootools: * includes a hasClass() function: http://docs.mootools.net/Native/Element.js#Element.hasClass * includes a remove() function: http://docs.mootools.net/Native/Element.js#Element.remove Prototype: * includes a hasClassName() function: http://www.prototypejs.org/api/element#method-hasclassname * includes a remove() function: http://www.prototypejs.org/api/element/remove To be fair. Neither Mootools nor Prototype seem to include an exists() function. This however could also be traced back by the fact that they do not share the jQuery philosophy in terms of advocating their CSS selector engine as a) their main element retrieval method and b) don't use it as a wrapper for chainability. Anyway I can see your argument about how an exists() function would be redundant. jQuery has a lot of convenience wrappers for things, but $.fn.exists = function(){return !!this.length}; would be the smallest and least functional one. Same is almost true for hasClass (return this.is('.'+class));. This is where you can convince me with a rational/scientific argument that those functions aren't needed. However, as you said this library is more then just code, it's art. And this is why I'm emphasizing those new functions: They empower the artist (who does not read the complete docs before getting started) and don't hurt the scientists What a rant ... haha Anyway, interesting discussion and good arguments, -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Fil wrote: jQuery is a language It was a library last time I checked ; ). yeah, well, it can be many things to many people; we all agree it's code. I think it's art, too Why? For me the sweetest thing about using jQuery has been it's intuitiveness right out of the box. ok, so next time i want to code something in jquery i'll just write $(make coffee) ? No, there are things that are intuitive **once you've understood the basics**. IOW intuitiveness is based on your assumptions and your knowledge. Why would you assume that .hasClass() exists? And not, e.g., isMemberOf() or .classMatches() ? It must depend of what you're already familiar with before you switch to jQuery. For me (and I really mean not speaking for everyone) it's more intuitive if there is an internal logic that I can understand; adding stuff that is redundant is merely adding cruft, and hence counter-intuitive. That's why I wanted to add my I don't agree message -- though I understand and respect your position, I don't share it. -- Fil
[jQuery] Syntactic sugar for checking whether an element exists
I've just been wondering if jQuery has some syntactic sugar for checking if an element exists. I know the following works: if ($('#my-element').length) { // #my-element exists } but is there also something similar to the following?: if ($('#my-element').exists()) { // #my-element exists } I'm asking because I know this was one of the things I was initially unsure about when learning jQuery and I just had a one of my many jQuery converted friends ask me about it again. So is anybody else thinking some syntactic sugar could be helpful here? Or what do you think about: $('#my-element').is('*') ? (Besides that it's probably inefficient *g*) -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de
[jQuery] Re: Syntactic sugar for checking whether an element exists
Sean, Mike: I agree with your notion that learning that the jQuery object is array-like (It'd be cool if it was a real array and .push / .sort would work on it) is very worthwhile. I knew that when I initially stumbled across the problem and knew that doing it via '.length' was one solution. I was only confused if it was the right way or could lead to undesired results as I was new to jQuery at this point and I didn't find it mentioned anywhere in specific. That's where my notion of an 'exists()' function could be useful comes from. But it's probably just something that should be put in the manual somewhere (if it isn't already in there and I missed it). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Sean Catchpole wrote: I believe that learning jquery returns an array like object is more useful than creating a .exists() function. ~Sean
[jQuery] Re: Syntactic sugar for checking whether an element exists
Felix, not to worry, there's nothing wrong at all with using .length - and it is obviously faster than a function call. I figured that by now. I think Matt was much better at explaining why I think an alternative exists() function is useful - it simply is the most intuitive thing a new jQuery user looks for. I also agree with his hasClass argument. I love the is() function, but I would have taken me a long time to find it if I my question was phrased Who can I determine if an element has a certain class.is() is more powerful but not nearly as intuitive as hasClass would be for new users. In the earliest versions of jQuery, the jQuery object was not an array, but had a private array object that you accessed using .get(n) and .size(). The only reason those functions still exist is for compatibility with old code. There's no reason at all to stick with .get(n) and .size() now that the array-like jQuery object allows the simpler and more efficient [n] and .length. I disagree. Whenever you need to sort the elements in an ul or something then you'll have to use the Array.sort() function, so you need to do $('ul li').get().sort(...). Here is an example of where I needed this functionality: http://bin.cakephp.org/view/1632218532 It's not a big deal that I have to call get(), but it would be a big problem if it wasn't there! -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Michael Geary wrote: Felix, not to worry, there's nothing wrong at all with using .length - and it is obviously faster than a function call. In the earliest versions of jQuery, the jQuery object was not an array, but had a private array object that you accessed using .get(n) and .size(). The only reason those functions still exist is for compatibility with old code. There's no reason at all to stick with .get(n) and .size() now that the array-like jQuery object allows the simpler and more efficient [n] and .length. -Mike *From:* Felix Geisendörfer Sean, Mike: I agree with your notion that learning that the jQuery object is array-like (It'd be cool if it was a real array and .push / .sort would work on it) is very worthwhile. I knew that when I initially stumbled across the problem and knew that doing it via '.length' was one solution. I was only confused if it was the right way or could lead to undesired results as I was new to jQuery at this point and I didn't find it mentioned anywhere in specific. That's where my notion of an 'exists()' function could be useful comes from. But it's probably just something that should be put in the manual somewhere (if it isn't already in there and I missed it). -- Felix -- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de Sean Catchpole wrote: I believe that learning jquery returns an array like object is more useful than creating a .exists() function. ~Sean
[jQuery] Re: Naming Conventions
I like it simple: [x] .mask [ ] .maskInput -- Felix -- My latest blog posts: My Business: http://www.fg-webdesign.de Josh Bush wrote: As my masked input plugin approaches 1.0, I'm noticing that my plugin isn't following the conventions of the jQuery library itself. Currently my plugins main method is .maskedinput(mask,options) I'm thinking I should change it to .maskInput(mask,options) or simpley .mask(mask,options) I think this change is good because it's a verb and it shows action. Also, there is a global method which allows user defined char placeholders which Jrn advided me to namespace off. So, I plan to put it in $.MaskedInput.addPlaceholder(character,regex). What do you all think of the proposed name changes? I think it's important to remain consistent with the base library. I want to make sure that I get everything settled once I reach 1.0. Thanks Josh digitalbush.com
[jQuery] Re: Naming Conventions
I would prefer .maskInput as the method name, coz, it conveys both the intention and what it applies to. "mask" doesnt convey where it applies to and probably can be used for a more generic plugin. $('input.date').mask(...) should be good enough to imply what is meant I think. I used to be in favor of longer function names myself a while back, but recently found that shorter is better in most cases. A good example is jQuery itself: we have css() instead of setStyle(), load() instead of ajaxLoad() etc. The thing is as longer your name get's the less intuitive it is. When I started using jQuery I would discover functions by virtually guessing their names and only use the API if that resulted in an error. So I'm going to vote for mask() again ; ). -- Felix -- My latest blog posts: My Business: http://www.fg-webdesign.de Ganeshji Marwaha wrote: I would prefer .maskInput as the method name, coz, it conveys both the intention and what it applies to. "mask" doesnt convey where it applies to and probably can be used for a more generic plugin. Regarding, the namespace for additional methods. I agree that MaskedInput is the one that actually makes sense. But for the sake of simplicity and consistency, i would name it MaskInput instead. -GTG On 6/28/07, Josh Bush [EMAIL PROTECTED] wrote: As my masked input plugin approaches 1.0, I'm noticing that my plugin isn't following the conventions of the jQuery library itself. Currently my plugins main method is .maskedinput(mask,options) I'm thinking I should change it to .maskInput(mask,options) or simpley .mask(mask,options) I think this change is good because it's a verb and it shows action. Also, there is a global method which allows user defined char placeholders which Jrn advided me to namespace off. So, I plan to put it in $.MaskedInput.addPlaceholder(character,regex). What do you all think of the proposed name changes?I think it's important to remain consistent with the base library.I want to make sure that I get everything settled once I reach 1.0. Thanks Josh digitalbush.com
[jQuery] Re: Overlay plugin?
I want to maintain proportion, but scale it to fit in the view port.0 Got some PHP code laying around that does just that. Should be easy to convert to JS: function fitObjectInBox($objectWidth, $objectHeight, $boxWidth, $boxHeight) { // Fit's our image in a box with a given width and heigth while proportions remain, // *or* resizes it based on one site proportionally if only width or height is given $widthRatio = @($boxWidth / $objectWidth); $heightRatio = @($boxHeight / $objectHeight); if (($widthRatio $heightRatio) ($widthRatio!=0) || ($heightRatio==0)) { $ratio = $widthRatio; } else { $ratio = $heightRatio; } $new_width = ceil($objectWidth * $ratio); $new_height = ceil($objectHeight * $ratio); return array($new_width, $new_height); } HTH, Felix -- My latest blog posts: My Business: http://www.fg-webdesign.de Glen Lipka wrote: Sorry, working on it right now. :) I fixed that. Trying to figure out how to position it in the middle of the screen and adjust the height width so it makes sense. The logic is a little tortuous on my mind. I want to maintain proportion, but scale it to fit in the view port. Is there a resize plugin? Glen On 6/23/07, Aaron Heimlich [EMAIL PROTECTED] wrote: I got this error on FF 2.0.0.4 (Mac OS 10.4.10): e.css is not a function http://www.commadot.com/jquery/easebox/easeBox.js Line 59 Stack trace: showZoom(a matt-big.jpg)easeBox.js (line 59) (no name)()easeBox.js (line 27) (no name)( click clientX=0, clientY=0)jquery-latest.js (line 1398) handle (click clientX=0, clientY=0)jquery-latest.js (line 1302) e.css("z-index","1001"); On 6/24/07, Glen Lipka [EMAIL PROTECTED] wrote: dimScreen is great. Check it out: http://www.commadot.com/jquery/easebox/ Although, I changed it slighly to use $(window).width() instead of $(document).width() This might only work with the dimensiosn plugin included. Glen On 6/23/07, Glen Lipka [EMAIL PROTECTED] wrote: It should be Rey Bingo! That's exactly it. Awesome. Thanks. :) Glen On 6/23/07, Rey Bango [EMAIL PROTECTED] wrote: dimScreen: http://docs.jquery.com/Plugins/dimScreen Glen Lipka wrote: I can't find it, but I vaguely remember someone had a plugin that just puts a 50% opacity overlay over the page. Sort of like a thickbox thing, but without all the other stuff. Does anyone know where it is? Glen -- BrightLight Development, LLC. 954-775- (o) 954-600-2726 (c) [EMAIL PROTECTED] http://www.iambright.com -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com
[jQuery] Re: Image resizing
Untested, off the cuff: centerPosition: function(objWidth, objHeight, boxWidth, boxHeight) { return { top: (boxWidth / 2) - (objWidth / 2) , left: (boxHeight / 2) - (objHeight / 2) } } var $myDiv = $('#my-div'); var $screen = $(document); mvDiv.css(centerPosition(myDiv.width(), myDiv.height(), $screen.width(), $screen.height())); See if that helps, -- Felix -- My latest blog posts: My Business: http://www.fg-webdesign.de Glen Lipka wrote: Felix Geisend hooked me up with some code, which seemed to work perfectly. function fitObjectInViewPort(zoomedImage) { // Fit's our image in a box with a given width and heigth while proportions remain, // *or* resizes it based on one site proportionally if only width or height is given var objectWidth = zoomedImage.width(); var objectHeight = zoomedImage.height(); var boxWidth = ($(window).width()) * maxImagePercent; var boxHeight = ($(window).height()) * maxImagePercent; widthRatio = (boxWidth / objectWidth); heightRatio = (boxHeight / objectHeight); if ((widthRatio heightRatio) (widthRatio!=0) || (heightRatio==0)) { ratio = widthRatio; } else { ratio = heightRatio; } new_width = Math.ceil(objectWidth * ratio); new_height = Math.ceil(objectHeight * ratio); //return array(new_width, new_height); new_left = (boxWidth - new_width) / 2; new_top = (boxHeight - new_height) / 2; bigThumb.animate({width:new_width,height:new_height}, {duration: 750, easing: "backinout"}); } My math to figure out how to center it in the viewport is a little sketchy, but I feel like it's making progress. Thanks Felix! Glen On 6/23/07, Glen Lipka [EMAIL PROTECTED] wrote: I'm sorry I am asking so many questions about this. Still working on this EaseBox thing. http://www.commadot.com/jquery/easebox/ My question has to do with finding the proper image size based on the viewport. Logic: maximum height and width of the zoomed image is a percentage of the viewport. var maxPercentage = 90%; this means that height nor width can be more than 90% of the viewport. if they are both less, then it should maximize to full size. if width is more and height it less it should reduce width to maxPercentage and keep height proportional and vice versa for height more, but width less. if height and width are higher, then it should pick the one that is higher and reduce that to maxPercentage of either height orwidth of viewport depending on which one is more. Once the image size is calculated, it should center it in the viewport horizontally and vertically. I guess that is left: viewport width - image width /2 top: viewport height- image height/2 Is that right? Man, this is making me dizzy. Then I have to put these variables into an animate function. What is the syntax to do that? Any help is greatly appreciated. Glen
[jQuery] Re: Masked Input Plugin RC1a
Thanks for that plugin : ). Call / apply are ones best friends when working with JS. Incredibly powerful stuff when used right. One of my favorite uses apply is to use it on a new array instance to force 'arguments' variable to behave like a real array and re-route function arguments based on the first value passed into the array: Sample: --- $.fn.task = function(fct) { var r = $.fn.task.fn[fct].apply(this[0], [].slice.call(arguments, 1)); return r === undefined ? this : r; }; $('tr[td]').task('field', 'value'); - calls $.fn.task.fn.field(value) --- Anyway, keep up the good work and thanks for the improvement, -- Felix -- My latest blog posts: My Business: http://www.fg-webdesign.de Josh Bush wrote: Hey guys and gals. I learned about the .call() functionality today and decided to modify the behavior of the optional mask completed function. Now you don't need to specify an parameter when you define your function; you can simply use "this". Before: $("#product").maskedinput("99/99/",{completed:function(input) {alert("You typed the following: "+input.val());}}); Now: $("#product").maskedinput("99/99/",{completed:function() {alert("You typed the following: "+this.val());}}); It's not a necessary change, I just wasn't happy with forcing the user to add a param to their functions. It seemed a bit kludgey to me. The new version is up at: http://digitalbush.com/projects/masked-input-plugin and also at the official jQuery plugin repository: http://jquery.com/plugins/project/maskedinput Thank You Josh
[jQuery] Re: Macrumors running live udpates of WWDC
On an (un)related note: Is anybody having rendering quirks with the Safari 3 beta on Win XP? I just noticed that a couple sites of mine that I thought would render well in Safari are messed up. Even Google Ads seems to be affected. Anybody with similar problems? -- Felix PS: Click on the link below for thinkingphp.org to see what I mean. -- http://www.thinkingphp.org http://www.fg-webdesign.de Klaus Hartl wrote: Mike Alsup wrote: I'm *really* excited to be able to run Safari on Windows, but has anyone used this beta? I've never seen anything render so slowly. It's entirely unusable on my XP box. It is also totally annoying that you can't run Safari 3 beta and 2 side by side on a Mac... grrr, Apple is making the same mistakes as Microsoft. Am I missing something? -- Klaus
[jQuery] Re: SlickSpeed CSS Selector TestSuite
Well here is my personal (and widely uneducated) opinion on this speed test. First what I think is good about it: * each framework get's it's own iframe - avoid conflicts between them * the test itself is written without using a framework What I think is bad about it: * There are 3 nth-child(x*n)-style tests that jQuery seems to choke on as those selectors are not implemented in 1.1.2 (correct me if I'm wrong). On my machine this equates in 617ms (20 %) of jQuery's total test time (2857ms) * The div ~ div selector seems to take jQuery really long to perform, 1125ms (43%) go into it * The div:only-child + div:contains selector seem to be slow in jQuery and 203ms total (12%) go into them What does this mean? It means that jQuery is nowhere as slow as the final test results make it appear (26x slower then mootools). It means that mootools got the performance lead in some specific selector (and does good in general) which is given way too much weight by the test itself. I'm also questioning how far one can even go in terms of benchmarking selector engines. I mean everybody has different needs. Most of the time I use very simple selectors which jQuery does very fast according to the test. So I'd actually be willing to loose performance on the more complicated selectors if that allows the more common ones to run faster. What's missing in my eyes is a survey or analysis of common selector usage that could be used to weigh in the different selector results. That being said I'm not trying to say jQuery is actually the fastest library and the evil test just made it look bad. I'm sure there is room for improvements and who knows what 1.1.3 will bring. But what I'm trying to communicate is that it's not an easy job to actually interpret the results coming from those speed tests and hence one should be very careful when using them to make a point for one lib being faster then another. -- Felix Geisendörfer aka the_undefined -- http://www.thinkingphp.org http://www.fg-webdesign.de Robert O'Rourke wrote: Michael Stuhr wrote: my results: FF 2.0.0.4 WinXP-SP2 http://onenterframe.de/temp/ micha Is Jquery slower because it's more compact then? ie. better for light usage? I much prefer the syntax and the community around jquery. I never got any helpful responses from anyone on the mootools forum when I was using that library. Rob
[jQuery] Re: Macrumors running live udpates of WWDC
I have SERIOUS, SERIOUS doubts that there are 18 million people using Safari. I doubt there are that many people using Macs to be perfectly honest. I also think that FF numbers are underestimated and IE numbers overesimtated: See http://www.w3schools.com/browsers/browsers_stats.asp -- Felix -- http://www.thinkingphp.org http://www.fg-webdesign.de Andy Matthews wrote: I have SERIOUS, SERIOUS doubts that there are 18 million people using Safari. I doubt there are that many people using Macs to be perfectly honest. *From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of * *Sent:* Monday, June 11, 2007 1:11 PM *To:* jquery-en@googlegroups.com *Subject:* [jQuery] Re: Macrumors running live udpates of WWDC 11:09 amSafari On WINDOWS 11:09 am18 Million Safari users Marketshare has climbed to 4.9% IE has 78%, Firefox 15%, others 2% We Dream Big On 6/11/07, *Shelane Enos* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: That's a feature they've previously announced that I'm looking forward to. On 6/11/07 10:52 AM, ?ⓐⓚⓔ [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: 10:49 amusing safari to make widgets from web pages Woo hoo! On 6/11/07, *?ⓐⓚⓔ* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: thanks Shelane! I've been tuned in since 10 am!!! On 6/11/07, *Shelane Enos* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Macrumors.com http://Macrumors.com http://Macrumors.com is running a continuous AJAX update of the keynote address of WWDC. No more update in 60 seconds countdown. -- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ
[jQuery] Re: Best way to determine if a user has Javascript enabled?
Detecting if JavaScript is enabled is actually fairly straightforward. No need to make it so complicated. Well I think this thread is about how to detect if JS is enabled on the Server-side ; ). Your method of course is the way to go if all one needs is to display a msg to the user. -- Felix -- http://www.thinkingphp.org http://www.fg-webdesign.de Giant Jam Sandwich wrote: Detecting if JavaScript is enabled is actually fairly straightforward. No need to make it so complicated. $(function(){ $(#is_disabled).css(display,none); }); ... div id=is_disabledYou have JavaScript disabled./div
[jQuery] Re: Best way to determine if a user has Javascript enabled?
Didn't read the entire thread but appending parameters like this to an url just doesn't seem right to me. Maybe your problem can be solved by looking if the client sent a X-Requested-With == 'XMLHttpRequest' header. That's how we in CakePHP find out if a page was requested via Ajax or not ; ). Note: This is nothing the XMLHttpRequest adds itself, but I know jQuery and also Prototype do it for all their ajax requests for you. -- Felix -- http://www.thinkingphp.org http://www.fg-webdesign.de