[jQuery] Wrapping non empty text node with span
Hi all, I'm looking for a way to wrap text node with span. HTML: ul id=target liItem 1/li liItem 5 ul liItem 5-1/li liItem 5-2/li liItem 5-3 ul liItem 5-3-1/li /ul /li /ul /li liItem 6/li /ul Expected Outcome: ul id=target lispanItem 1/span/li lispanItem 5/span ul lispanItem 5-1/span/li lispanItem 5-2/span/li lispanItem 5-3/span ul lispanItem 5-3-1/span/li /ul /li /ul /li lispanItem 6/span/li /ul Currently I do it by: $(#target li).find(li).each(function(){ if(this.childNodes[0] this.childNodes[0].nodeType == 3){ var data = $.trim(this.childNodes[0].data); if(data){ this.childNodes[0].data = data; $(this.childNodes[0]).wrap(span/span); } } }); I wonder if there is any simpler way to do this? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Mousemove for simple signature panel
Hi all, I tried to create a simple signature panel ( http://jackysee.googlepages.com/sig.html). The principle is simple: create div when mouse is down and moving. But it seems that the 'mousemove' interval is quite large and the drag only gives a dotted line. Any way to improve this? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] jQuery validation use different event for differernt input
Hi all, Some question on the validation plugin. Say there are 3 fields, and the first one is user name.I want to check the availability of the user name on focusout using 'remote'. But for the rest of the fields, only validate when user clicking submit button. Can I do that? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Prevent IE Cross Page Leak
Hi all, I have some question about IE memory leakage. There are four type of leakage in IE as stated in http://msdn.microsoft.com/en-us/library/bb250448(VS.85).aspxOne of them is called 'Cross Page Leak', which is caused by DOM insertion order. (should have no intermediate object) The result is that the memory will not be released even if page is changed. So, will the following code introduce this kind of leakage? $('div') .append('pSome text/p') .append($('div/').append('abcdef')) //more append to create the complex dom objects //. .appendTo(body); My case is quite serious. I have a page with some modals displaying some small search box the ajax way. Whenever a modal is displayed, about 10MB of memory is consumed and it never returns. -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: Focus First 'visible' field
Someone found that this method does not handle visibility correctly. When a visibility:hidden parent with a visibility:show child, the child would override its parent's property (of course!). So the script only need to check display:none parent, which would introduce another filter: $(:text:visible:enabled).filter(function(){ return $(this).filter(function(){ this.style.display == none; }).size()==0; }).eq(0).focus(); On 4月17日, 下午9時40分, Jacky [EMAIL PROTECTED] wrote: To work on any type of input should be easy, just replace ':text' with input. I know that IE would give error when you're focusing a 'disappearing' input. (parent is hidden, for example). But I do not encounter any error like you described. Any sample code for your HTML? On Tue, Apr 15, 2008 at 9:00 AM, MichaelEvangelista [EMAIL PROTECTED] wrote: I've been looking for a solution like this, but that will work with any type of form input. The code I've been using is below (where form-id is the ID of the containing form) It works great in Firefox but IE throws the error 'this.parentNode.borderCss.on' is null or not an object I tried your example code above, and got the same error here is what I was using : // --- Put the cursor in the first field on page load var $firstfield = function(){ $('#form-id input:eq(0)').focus(); } $firstfield(); Could this have anything to do with my markup? I didnt get that error on your demo, but i did when I applied your code to my form. On Apr 13, 7:54 am, Jacky See [EMAIL PROTECTED] wrote: Hi all, For focusing first input text field, the usual solution is $ (':text:visible:enabled:eq(0)').focus(). However, when these fields are in an ':hidden' parent (not 'visible' by our eyes), it won't work. Currently I tried to solve this by: $(:text:visible:enabled).filter(function(){ return $(this).parents(:hidden).size()==0; }).slice(0,1).focus(); I have setup a test page for this: http://www.seezone.net/dev/focusField.html Try to toggle different parent to and click 'focus'. It should work correctly. I would like to know if there is any other 'selector-based' way to do so? -- Best Regards, Jacky 網絡暴民http://jacky.seezone.net
[jQuery] Re: Focus First 'visible' field
This is my very first implementation. But it fails on visibility:hidden parent which has a visibility:show child. You may try the updated demo page. Box 11 would still be visible even when you toggle its parent's visibility. http://www.seezone.net/dev/focusField.html ':hidden' selector would try to select both display:none and visibility:hidden element. Therefore, we need to only select display:none parent, not visibility:hidden. P.S. (I missed 'return' in the previous post) $(:text:visible:enabled).filter(function(){ return $(this).filter(function(){ return this.style.display == none; }).size()==0; }).eq(0).focus(); 2008/4/22 Erik Beeson [EMAIL PROTECTED]: Your inner $(this).filter(...) doesn't make sense to me. This works for me on FF2/Mac: $(':input:visible').filter(function() { return $(this).parents(':hidden').length == 0; }).slice(0,1).focus(); That is: Select all visible inputs elements, filter out any who have parents which are hidden, select the first one of those that remain, focus it. --Erik 2008/4/21 Jacky See [EMAIL PROTECTED]: Someone found that this method does not handle visibility correctly. When a visibility:hidden parent with a visibility:show child, the child would override its parent's property (of course!). So the script only need to check display:none parent, which would introduce another filter: $(:text:visible:enabled).filter(function(){ return $(this).filter(function(){ this.style.display == none; }).size()==0; }).eq(0).focus(); On 4月17日, 下午9時40分, Jacky [EMAIL PROTECTED] wrote: To work on any type of input should be easy, just replace ':text' with input. I know that IE would give error when you're focusing a 'disappearing' input. (parent is hidden, for example). But I do not encounter any error like you described. Any sample code for your HTML? On Tue, Apr 15, 2008 at 9:00 AM, MichaelEvangelista [EMAIL PROTECTED] wrote: I've been looking for a solution like this, but that will work with any type of form input. The code I've been using is below (where form-id is the ID of the containing form) It works great in Firefox but IE throws the error 'this.parentNode.borderCss.on' is null or not an object I tried your example code above, and got the same error here is what I was using : // --- Put the cursor in the first field on page load var $firstfield = function(){ $('#form-id input:eq(0)').focus(); } $firstfield(); Could this have anything to do with my markup? I didnt get that error on your demo, but i did when I applied your code to my form. On Apr 13, 7:54 am, Jacky See [EMAIL PROTECTED] wrote: Hi all, For focusing first input text field, the usual solution is $ (':text:visible:enabled:eq(0)').focus(). However, when these fields are in an ':hidden' parent (not 'visible' by our eyes), it won't work. Currently I tried to solve this by: $(:text:visible:enabled).filter(function(){ return $(this).parents(:hidden).size()==0; }).slice(0,1).focus(); I have setup a test page for this: http://www.seezone.net/dev/focusField.html Try to toggle different parent to and click 'focus'. It should work correctly. I would like to know if there is any other 'selector-based' way to do so? -- Best Regards, Jacky 網絡暴民http://jacky.seezone.net -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] [jqModal] IE keep loading after opening a modal
Hi all, I have come to an issue that IE is keep loading after a jqModal is opened. I think the issue might be related to an IE bug [link]. I tried to add window.status everywhere in code but still no progress. Anyone have encounter this before? [link] http://dangermoose.blogspot.com/2006/01/why-status-bar-keeps-loading-in.html -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: Focus First 'visible' field
To work on any type of input should be easy, just replace ':text' with input. I know that IE would give error when you're focusing a 'disappearing' input. (parent is hidden, for example). But I do not encounter any error like you described. Any sample code for your HTML? On Tue, Apr 15, 2008 at 9:00 AM, MichaelEvangelista [EMAIL PROTECTED] wrote: I've been looking for a solution like this, but that will work with any type of form input. The code I've been using is below (where form-id is the ID of the containing form) It works great in Firefox but IE throws the error 'this.parentNode.borderCss.on' is null or not an object I tried your example code above, and got the same error here is what I was using : // --- Put the cursor in the first field on page load var $firstfield = function(){ $('#form-id input:eq(0)').focus(); } $firstfield(); Could this have anything to do with my markup? I didnt get that error on your demo, but i did when I applied your code to my form. On Apr 13, 7:54 am, Jacky See [EMAIL PROTECTED] wrote: Hi all, For focusing first input text field, the usual solution is $ (':text:visible:enabled:eq(0)').focus(). However, when these fields are in an ':hidden' parent (not 'visible' by our eyes), it won't work. Currently I tried to solve this by: $(:text:visible:enabled).filter(function(){ return $(this).parents(:hidden).size()==0; }).slice(0,1).focus(); I have setup a test page for this: http://www.seezone.net/dev/focusField.html Try to toggle different parent to and click 'focus'. It should work correctly. I would like to know if there is any other 'selector-based' way to do so? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: [Validation]How to make two field check output one message?
I see... the group's key is not related to the rules/method. So the group would force the underlying fields to only display one message? This would be a problem because a field would also have its own message (like date format is incorrect). I tried my old demo, inputting all four fields with wrong date format and only two comes out. I think may be a more desirable way is to separate them... like... { rules: { //individual field date1: 'date requried', date2: 'date required', date3: 'date required', date4: 'date required' }, globalRules: { //I can't come up with appropriate name checkPlanDateRange: { group: 'date1 date2', rule: {dateRange:'plan'}, message: 'x' }, checkActualDateRange: { group: 'date3 date4', rule: {dateRange:'actual'}, message: 'y' } } } Just my two cents On Tue, Apr 15, 2008 at 4:20 AM, Jörn Zaefferer [EMAIL PROTECTED] wrote: Jacky schrieb: I'm thinking if I can do this: rules:{ planFromDate: {dateRange:'plan'}, planToDate: {dateRange:'plan'} actualFromDate: {dateRange:'actual'}, actualToDate: {dateRange:'actual'} } groups: { dateRange: planFromDate planToDate actualFromDate actualToDate } $.validator.addMethod('dateRange',function(value,elem,param){ var f = $(elem).parents(form:eq(0))[0]; from = f[param+'FromDate'].value; to = f[param+'ToDate'].value; if(!from || !to || /Invalid|NaN/.test(new Date(from)) || /Invalid|NaN/.test(new Date(to))) return true; return from to new Date(from) new Date(to); },'wrong date range'); Give this a try: rules:{ planFromDate: {dateRange:'plan'}, planToDate: {dateRange:'plan'} actualFromDate: {dateRange:'actual'}, actualToDate: {dateRange:'actual'} } groups: { plan: planFromDate planToDate, actual: actualFromDate actualToDate } $.validator.addMethod('dateRange',function(value,elem,param){ var f = elem.form; var from = f[param+'FromDate'].value; var to = f[param+'ToDate'].value; if(!from || !to || /Invalid|NaN/.test(new Date(from)) || /Invalid|NaN/.test(new Date(to))) return true; return from to new Date(from) new Date(to); },'wrong date range'); Jörn -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] [Validation] Validate differently based on different action
Hi all, I think this is a rather rare situation but it happens in our apps all the time. The layout is like --- Search Result table tr [checkbox] status [input text] [input text] [textarea] /tr /table [Delete button] [Reject Button] [Update Button] There are different case of validation: - when press delete button, validate if checkbox is checked only - when press reject button, validate if checkbox is checked and status is not rejected - when press update button, validate that all fields are filled and format correct. For the time being, I use some rude way to do so... var setting1 = {...}; var setting2 = {...}; var setting3 = {...}; $(#delete).click(function(){ var f = $(#form)[0]; $.removeDate(f, 'validator'); f.validate(setting1).submit(); }); //... similar for the reject and update button Any better way to do this? Or I should not use validation plugin under this situation?
[jQuery] Focus First 'visible' field
Hi all, For focusing first input text field, the usual solution is $ (':text:visible:enabled:eq(0)').focus(). However, when these fields are in an ':hidden' parent (not 'visible' by our eyes), it won't work. Currently I tried to solve this by: $(:text:visible:enabled).filter(function(){ return $(this).parents(:hidden).size()==0; }).slice(0,1).focus(); I have setup a test page for this: http://www.seezone.net/dev/focusField.html Try to toggle different parent to and click 'focus'. It should work correctly. I would like to know if there is any other 'selector-based' way to do so?
[jQuery] Re: [Validation]How to make two field check output one message?
I'm thinking if I can do this: rules:{ planFromDate: {dateRange:'plan'}, planToDate: {dateRange:'plan'} actualFromDate: {dateRange:'actual'}, actualToDate: {dateRange:'actual'} } groups: { dateRange: planFromDate planToDate actualFromDate actualToDate } $.validator.addMethod('dateRange',function(value,elem,param){ var f = $(elem).parents(form:eq(0))[0]; from = f[param+'FromDate'].value; to = f[param+'ToDate'].value; if(!from || !to || /Invalid|NaN/.test(new Date(from)) || /Invalid|NaN/.test(new Date(to))) return true; return from to new Date(from) new Date(to); },'wrong date range'); But it seems that it will only output single message. On Mon, Apr 14, 2008 at 1:07 AM, Jörn Zaefferer [EMAIL PROTECTED] wrote: Jacky See schrieb: I have put up a page to test. http://www.seezone.net/dev/dateValiation.html I need to use different method for different group of dates. In that case, a global dateRange method seems not possible? Thats a different issue. A better dateRange implementation could reuse the information provided via the groups-option, or use the DOM structure to find the associated element. Jörn -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: [Validation]How to make two field check output one message?
I have put up a page to test. http://www.seezone.net/dev/dateValiation.html I need to use different method for different group of dates. In that case, a global dateRange method seems not possible? On 4月11日, 上午6時03分, Jörn Zaefferer [EMAIL PROTECTED] wrote: Jacky See schrieb: Hi, Some question on the config of validation plugins. Suppose there are #fromDate and #toDate fields (using ui.datepicker). I have added these custom rules [...] It will output two messages of 'Please input correct date range'. How can I make it only ouput single one? I've implemented a solution, please give the latest revision a try:http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js You need to specify which elements to group using the new groups-option. A usage example (actually a test, will later add it to docs) is here:http://dev.jquery.com/view/trunk/plugins/validate/test/messages.js The interesting parts: form id=dateRangeForm input id=fromDate name=fromDate class=requiredDateRange / input id=toDate name=toDate class=requiredDateRange / span class=errorContainer/span /form $.validator.addClassRules({ requiredDateRange: {required:true, date:true, dateRange:true}}); $.validator.addMethod(dateRange, function() { return new Date($(#fromDate).val()) new Date($(#toDate).val());}, Please specify a correct date range.); $(#dateRangeForm).validate({ groups: { dateRange: fromDate toDate }, errorPlacement: function(error) { form.find(.errorContainer).append(error); } }); You'll most likely have to skip or modify the errorPlacement option, but the rest should work fine. Your feedback on it is very welcome. Jörn
[jQuery] Re: How to get a 'fresh' ui datepicker date?
The above code has some error. Here is my final solution: write another plugin to get the date. HTML: div id=dateRange Plan Date: input type=text id=eventFromDate/ to input type=text id=eventToDate/ br/ Actual Date: input type=text id=actualFromDate/ to input type=text id=actualToDate/ /div JS: $(#dateRange input).datepickerRange({showOn:'button'}); /* Update datepicker if found and return the date */ $.fn.getInputDate = function(){ var elem = this[0]; if(elem){ var inst = $.datepicker._getInst(elem._calId); if(inst){ inst._setDateFromField(elem); return inst._getDate(); } } return null; } /* Assume from/to date have same ID prefix options can provide suffix options's beforeShow is overriden */ $.fn.datepickerRange = function(options){ options = options || {}; var fromSuffix = options.fromSuffix || FromDate; var toSuffix = options.toSuffix || ToDate; options.beforeShow = function(input){ var isFrom = (new RegExp(fromSuffix+$)).test(input.id); var prefix = input.id.replace(new RegExp((+fromSuffix+|+toSuffix +)$),); return { minDate: isFrom? null: $(#+prefix+fromSuffix).getInputDate(), maxDate: !isFrom? null: $(#+prefix+toSuffix).getInputDate() }; } return this.datepicker(options); } On 4月11日, 上午3時14分, Jacky See [EMAIL PROTECTED] wrote: I have found some wicked way to do it. This is the code where I'm writing a plugin to accept date range pair and auto-init them. //Assuming from/to date have same prefix id (e.g. #eventFromDate, #eventToDate) $.fn.datepickerPair = function(options){ return this.datepicker( $.extend({ beforeShow:function(elem){ var id = elem.id; var isFrom = /FromDate$/.test(id); var prefix = id.replace(/(FromDate|ToDate)$/,''); var minDate = isFrom?null: $.datepicker._getInst($ (#+prefix+FromDate).get(0)._calId)._setDateFromField(#+prefix +FromDate); var maxDate = !isFrom?null: $.datepicker._getInst($ (#+prefix+ToDate).get(0)._calId)._setDateFromField(#+prefix +ToDate); return {minDate:minDate, maxDate:maxDate}; },options) ); } Any other 'cleaner' way? On 4月11日, 上午1時09分, Jacky See [EMAIL PROTECTED] wrote: Dear all, This is about the ui datepicker. I have an input field with a datepicker, using image as trigger. The field is not read only, user are allowed to input by keyboard. The problem is that when user type some invalid input like '33' the $('#input').datepicker('getdate'), will still only get the last selected date. Is that any way to get the 'fresh' date? Any trigger I can call? I need it to fill in a date range using 'beforeShow' option.
[jQuery] [Validation]How to make two field check output one message?
Hi, Some question on the config of validation plugins. Suppose there are #fromDate and #toDate fields (using ui.datepicker). I have added these custom rules jQuery.validator.addMethod(afterFromDate ,function(value, element, targetId){ var fromDate = $(#+targetId).datepicker(getDate); var toDate = $(element).datepicker(getDate); if(toDate fromDate fromDate toDate){ return false; } return true; }, Please input correct date range); jQuery.validator.addMethod(beforeToDate ,function(value, element, targetId){ var fromDate = $(element).datepicker(getDate); var toDate = $(#+targetId).datepicker(getDate); if(toDate fromDate fromDate toDate){ return false; } return true; }, Please input correct date range); And config like $(#form).validate({ rules:{ 'fromDate': { beforeToDate:'fromDate' }, 'toDate: { afterFromDate:'toDate' }, } }) It will output two messages of 'Please input correct date range'. How can I make it only ouput single one?
[jQuery] How to get a 'fresh' ui datepicker date?
Dear all, This is about the ui datepicker. I have an input field with a datepicker, using image as trigger. The field is not read only, user are allowed to input by keyboard. The problem is that when user type some invalid input like '33' the $('#input').datepicker('getdate'), will still only get the last selected date. Is that any way to get the 'fresh' date? Any trigger I can call? I need it to fill in a date range using 'beforeShow' option.
[jQuery] Re: How to get a 'fresh' ui datepicker date?
I have found some wicked way to do it. This is the code where I'm writing a plugin to accept date range pair and auto-init them. //Assuming from/to date have same prefix id (e.g. #eventFromDate, #eventToDate) $.fn.datepickerPair = function(options){ return this.datepicker( $.extend({ beforeShow:function(elem){ var id = elem.id; var isFrom = /FromDate$/.test(id); var prefix = id.replace(/(FromDate|ToDate)$/,''); var minDate = isFrom?null: $.datepicker._getInst($ (#+prefix+FromDate).get(0)._calId)._setDateFromField(#+prefix +FromDate); var maxDate = !isFrom?null: $.datepicker._getInst($ (#+prefix+ToDate).get(0)._calId)._setDateFromField(#+prefix +ToDate); return {minDate:minDate, maxDate:maxDate}; },options) ); } Any other 'cleaner' way? On 4月11日, 上午1時09分, Jacky See [EMAIL PROTECTED] wrote: Dear all, This is about the ui datepicker. I have an input field with a datepicker, using image as trigger. The field is not read only, user are allowed to input by keyboard. The problem is that when user type some invalid input like '33' the $('#input').datepicker('getdate'), will still only get the last selected date. Is that any way to get the 'fresh' date? Any trigger I can call? I need it to fill in a date range using 'beforeShow' option.
[jQuery] Validation Plugins: how to add global error
Hi all, some question about the validation plugins. There is a form with: - some search fields - a table of search result with checkboxes - some buttons to do next action with checked records Currently, the form is placing error message after each search fields. However, I also want to validate the button click, so that user must check something before proceed to next. So it would be inappropriate to display error messages after checkbox. I want to place a div and says 'Please check records before proceed!'. As sometimes there will be no 'checkbox', it seems not good to place a rule in the option. I realize one of the way is to use submitHandler as a final check on that. But then I have to manage these 'global errors' manually. Is there any recommended way to do it? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Drag and Drop rows across two tables
Hi all, Is that possible using ui draggable and droppables? In an initial attempt, I tried to create a table and apply $(#tabletbodytr).draggable(); It works in IE but not in Firefox. -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: [validate] does maxLength(20) supported in textarea?
Oh, because input type=text class=maxLength(20) / work so I thought the syntax is correct. Thx, I will try that later. On Feb 2, 2008 12:58 AM, Jörn Zaefferer [EMAIL PROTECTED] wrote: Jacky schrieb: I tried to do this textarea id=textarea cols=20 rows=4 name=desc class=maxLength(20) title=Description max length is 20/textarea But it doesn't work. So I guess it's not supported in textarea and I will need to add method? That syntax isn't valid. You've got two options to inline rules in this case: textarea id=textarea cols=20 rows=4 name=desc maxlength=20 title=Description max length is 20/textarea textarea id=textarea cols=20 rows=4 name=desc class={maxlength:20} title=Description max length is 20/textarea The latter requires the metadata plugin. Please note that maxLength and maxlength are currently the same, but maxLength is deprecated. Jörn -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] [validate] does maxLength(20) supported in textarea?
I tried to do this textarea id=textarea cols=20 rows=4 name=desc class=maxLength(20) title=Description max length is 20/textarea But it doesn't work. So I guess it's not supported in textarea and I will need to add method? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] is it a bug with validate?
Hi, I valiate two fields that depend on each other if blank,for example,user must supply he/her telephone number or mobile number,he/ her just need input the one of that(telephone number or mobile number). I set the rules like this: rules:{ telephone:{ required:#mobile:blank, digits:true }, mobile:{ required:#telephone:blank, digits:true } } if input non-digits characters to both of these two fields,digits validation is not working.
[jQuery] bug with clone method
Hi, there is a bug with clone method when clone a tr element with IE browser.It just return the content of the first column that the row cloned.It is fine in firefox.
[jQuery] jQuery.extend not working for function as target,is it a bug?
/* * jQuery 1.2.1 - New Wave Javascript * * Copyright (c) 2007 John Resig (jquery.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * $Date: 2007-11-29 07:53:54 +0800 (星期四, 29 十一月 2007) $ * $Rev: 3973 $ */ the jQuery reversion is #3973,function can't extend with jQuery.extend. function target(){ /**some code here*/ } jQuery.extend(target,{ someMethod:function(){ /** some code here */ } }); alert(typeof target.someMethod);// type of target.someMethod is undefined
[jQuery] Re: jQuery.extend not working for function as target,is it a bug?
Hi polyrhythmic, what reversion number of jquery you use? i use the newest jquery from svn.reversion number of the jquery is #3973,is that of you used? * $Date: 2007-11-29 07:53:54 +0800 (星期四, 29 十一月 2007) $ * $Rev: 3973 $ Regards Jacky 2007/11/30, polyrhythmic [EMAIL PROTECTED]: Hello Jacky, I can't reproduce your error. jQuery.extend should work for functions, this is how it works internally. Perhaps there is an issue in your code I cannot see. I ran the following through the Firebug console just now with these results: [ : my commands ] var targetfn = function() { console.log('I am tgtfn'); }; targetfn(); I am tgtfn $.extend(targetfn, { childfn: function() { console.log('I am childfn'); } }); function() targetfn.childfn(); I am childfn alert(typeof targetfn.childfn); [alerted function] What browser are you testing in? I know that there are issues with typeof not returning the proper value for functions, that's part of a long discussion on the jQuery-dev list: http://groups.google.com/group/jquery-dev/browse_thread/thread/89cc50c9e936feb6?hl=en Things are running right for me in Firefox 2.0.0.10 on XP. Charles On Nov 29, 4:15 am, Jacky [EMAIL PROTECTED] wrote: /* * jQuery 1.2.1 - New Wave Javascript * * Copyright (c) 2007 John Resig (jquery.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * $Date: 2007-11-29 07:53:54 +0800 (星期四, 29 十一月 2007) $ * $Rev: 3973 $ */ the jQuery reversion is #3973,function can't extend with jQuery.extend. function target(){ /**some code here*/ } jQuery.extend(target,{ someMethod:function(){ /** some code here */ } }); alert(typeof target.someMethod);// type of target.someMethod is undefined
[jQuery] Re: problems about jquery.validate
Hi, submit is called after remote validation.it is not good for user experience.it should just update the just field validation info. and another problem is that i can't define the name of the data that to be validation.in remote it is data:{value:value}.In my exists validation program,it not receive a field name as value,and i couldn't to change it,beacause some others programs use it already. understand me?sorry for my english. 2007/11/25, Jörn Zaefferer [EMAIL PROTECTED]: Hi Jack! can jquery.validate use custom validator? And another problem is about email validator,it can't pass validate with my email address [EMAIL PROTECTED] exactly validate email address. Yes, custom validations are possible. Take a look at this and let me know if that doesn't help you: http://jquery.bassistance.de/api-browser/plugins.html#jQueryvalidatoraddMethodStringFunctionString I've just added your example mail address to the testsuite and fixed the email validation accordingly. You can get that fixed revision here: http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js Regards Jörn
[jQuery] Re: problems about jquery.validate
Hi Jörn, you misunderstand my meaning.my english is poor,so i don't how to describe my opinion. The first problem is about the code following: stopRequest: function(valid) { this.pendingRequest--; if ( valid this.pendingRequest == 0 this.submitted this.form() ) { jQuery(this.currentForm).submit(); } } after ajax request success,it call the method of stopRequest,and form submit event was fired. In my opinion,don't submit the form,just show the message of the field that invoke remote validation if valid or not.understand me now? And the second problem is about the code following: data: { value: value, name: element.name } In my opinion is like this data:{ element.name:value } and people can add more params to it. I hope i presente that clearly to you. sorry for my poor english again.And thanks your replies.Thank you! 2007/11/29, Jörn Zaefferer [EMAIL PROTECTED]: Jacky Chen schrieb: Hi, submit is called after remote validation.it http://validation.it is not good for user experience.it http://experience.it should just update the just field validation info. Now, I didn't get that one. Try again? and another problem is that i can't define the name of the data that to be validation.in http://validation.in remote it is data:{value:value}.In my exists validation program,it not receive a field name as value,and i couldn't to change it,beacause some others programs use it already. If I undertand that right, you want to get both the value and the fieldname? That makes good sense to me, I'll add it right now for you to give it a try. Hope at least that helps. Jörn
[jQuery] is it a bug?
Hi, I make the Reversion #3944 of jQuery from svn,and there is an error, error: selector has no properties source:/jquery.js line:343 is it a bug?
[jQuery] Re: problems about jquery.validate
Hi Jörn, thanks your reply and great works. On 11月25日, 上午3时01分, Jörn Zaefferer [EMAIL PROTECTED] wrote: Hi Jack! can jquery.validate use custom validator? And another problem is about email validator,it can't pass validate with my email address [EMAIL PROTECTED] exactly validate email address. Yes, custom validations are possible. Take a look at this and let me know if that doesn't help you:http://jquery.bassistance.de/api-browser/plugins.html#jQueryvalidator... I've just added your example mail address to the testsuite and fixed the email validation accordingly. You can get that fixed revision here:http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js Regards Jörn
[jQuery] problems about jquery.validate
Hi there, can jquery.validate use custom validator? And another problem is about email validator,it can't pass validate with my email address [EMAIL PROTECTED] exactly validate email address. sorry for my poor english. Best Regards Jacky
[jQuery] Re: Any server status if use script tag for XSS?
If the server return something like 404/500 page, I guess it would cause a javascript error when browser try to evaluate, and the try-catch method could work. Timer would be a good idea, but to determine the time to wait would require some specific measure. -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 10/9/07, Scott Trudeau [EMAIL PROTECTED] wrote: I actually posted to the dev list about a similar issue (using JSONP, which is script-like). I'd like to put a short timer on the script calls and receive a timeout if the callback function fails to fire. Scott On 10/8/07, Jacky [EMAIL PROTECTED] wrote: Hi, I would like to call crossite script. So I use the script tag technique (create script tag, assign src and append to head) to do so. But unlike xmlhttprequest, I cannot get any response status from it. So I just wonder if there is anyway I can detect if the remote script is not available? I tried to use try-catch, which works on Firefox but not IE. Code: $(document).ready(function(){ try{ var s = document.createElement(script); s.type = text/javascript; s.src = http://thisurldoesnotexist/dsfsdlfjk.js ; document.appendChild(s); } catch(e){ alert(any error); } }); -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net -- -- Scott Trudeau scott.trudeau AT gmail DOT com http://sstrudeau.com/ AIM: sodthestreets
[jQuery] Re: Any server status if use script tag for XSS?
If I remember correctly, getScript can't do cross site. -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 10/9/07, Matt [EMAIL PROTECTED] wrote: Maybe you could attach an onload or onerror event to your html element (script) ? Anyway, jQuery has a home made method to let you do this, cross-browser: See http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback Matt 2007/10/9, Jacky [EMAIL PROTECTED]: Hi, I would like to call crossite script. So I use the script tag technique (create script tag, assign src and append to head) to do so. But unlike xmlhttprequest, I cannot get any response status from it. So I just wonder if there is anyway I can detect if the remote script is not available? I tried to use try-catch, which works on Firefox but not IE. Code: $(document).ready(function(){ try{ var s = document.createElement(script); s.type = text/javascript; s.src = http://thisurldoesnotexist/dsfsdlfjk.js ; document.appendChild(s); } catch(e){ alert(any error); } }); -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net -- Matthias ETIENNE
[jQuery] Re: Any server status if use script tag for XSS?
Thanks. After look into the getScript code, I tried to play around with the readyState of the script elements. script.onload = script.onreadystatechange = function(){ try{ document.body.innerHTML += p + this.readyState + /p; if (!this.readyState || this.readyState == loaded || this.readyState == complete){ document.body.innerHTML += pSuccess/p; head.removeChild( script ); } }catch(e){ alert(any error + e); } }; 1. http://urldoesnotexist.com/fdil.js This is a request where the browser should not be able to resolve the server. Firefox prints nothing, but IE do print all 'loading', 'loaded' and 'success'. 2. http://www.google.com/doesnothavethisjs.js Just a simple error page returned by google.com Firefox prints nothing, but IE prints 'loading', 'loaded' and 'success' 3. http://someserver/soemjs.js This request would return an HTML showing cannot find file on server like (2). It is on our own application server. Firefox prints 'undefined', 'success' and then have script error about HTML tag error (I guess because the return page is not a well-formed html). IE prints 'loading', 'loaded' and 'success' with script error saying 'syntax error'. Seems that in IE, I cannot quite distinguish what is going on. On 10/10/07, Karl Swedberg [EMAIL PROTECTED] wrote: Hey Jacky, it can now. :-) from http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback: Before jQuery 1.2, getScript was only able to load scripts from the same domain as the original page. As of 1.2, you can now load JavaScript files from any domain. --Karl _ Karl Swedberg www.englishrules.com www.learningjquery.com On Oct 9, 2007, at 12:54 PM, Jacky wrote: If I remember correctly, getScript can't do cross site. -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 10/9/07, Matt [EMAIL PROTECTED] wrote: Maybe you could attach an onload or onerror event to your html element (script) ? Anyway, jQuery has a home made method to let you do this, cross-browser: See http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback Matt 2007/10/9, Jacky [EMAIL PROTECTED]: Hi, I would like to call crossite script. So I use the script tag technique (create script tag, assign src and append to head) to do so. But unlike xmlhttprequest, I cannot get any response status from it. So I just wonder if there is anyway I can detect if the remote script is not available? I tried to use try-catch, which works on Firefox but not IE. Code: $(document).ready(function(){ try{ var s = document.createElement(script); s.type = text/javascript; s.src = http://thisurldoesnotexist/dsfsdlfjk.js ; document.appendChild(s); } catch(e){ alert(any error); } }); -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net -- Matthias ETIENNE -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Any server status if use script tag for XSS?
Hi, I would like to call crossite script. So I use the script tag technique (create script tag, assign src and append to head) to do so. But unlike xmlhttprequest, I cannot get any response status from it. So I just wonder if there is anyway I can detect if the remote script is not available? I tried to use try-catch, which works on Firefox but not IE. Code: $(document).ready(function(){ try{ var s = document.createElement(script); s.type = text/javascript; s.src = http://thisurldoesnotexist/dsfsdlfjk.js;; document.appendChild(s); } catch(e){ alert(any error); } }); -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: Why Choose jQuery Over Mootools
I'm not familiar with mootools so I'm not going to compare them. But the code you shown is not using any jQuery function, they're a just plain js object. Moreover, the code is not working. It can be rewritten it as: function ajax_request(options) { this.ajax_options = { test: 'test' }; this.test= function() { alert(this.ajax_options.test); } } var test = new ajax_request(); test.test(); JQuery does not provides any base class for creating object, just $.extend() for object inheritance (correct me if I'm wrong). -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 8/12/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have tried to post this on jQuery mailing list/forums system but it is not posting for whatever reason so maybe some people who have used either or both can help me out I have been working with mootools for a bit the past few months and started to take a look at jQuery too see what the hype is all about from what i have heard from a co-worker. From what i see, jQuery does not offer anything that mootools does not. I mean jQuery does have $().click and i don't believe Mootools has anything like that, they just have the: $().addEvent('click', function(){}); However this is just a shortcut and not a major thing. On thing that jQuery has is that there are far more scripts however this is just to the fact that jQuery has been around longer than mootools. However on the other hand mootools has is a very nice way to create new classes. All i have to do is: http://www.apex-wowguild.com/dev/javascript/ajax.js Now I have been told that jQuery tries to do things more like the OO method. Well to me the basically thing about OO is being able to combine members(variables) and methods(functions) into a common place(class/object). I have tried creating a simple class with jQuery and it does not work(this code if based off what i was told from these forums): var ajax_request = function(options) { ajax_options = { test: 'test' }; test = function() { alert(this.test); } } var test = new ajax_request(); test.test(); and this code tells me that test() is not a function of test. It seems that jQuery wants you to incorporate everything into the $() selector which does not make sense of everything. Being able create separate object is something that is important to me and jQuery does not seem to support that. Another thing that that jQuery says is that is it so small. Well comparing the full version of mootools(all options selected) to the full version of jQuery is unfair. In order to get allt he features of full mootools you would have to add jQuery interface script and comparing mootools to jQueryInterface script, mootools is still smaller. So why should someone choose jQuery over Mootools or is it really just a preference thing and and both are basically the same(i see a lot about jQuery vs prototype but not alot about jQuery vs mootools)
[jQuery] getScript problem
I have tried to test on the twitter json and so I use the getScript to do that. It works in IE but not Firefox. The js console error shows: [Exception... ' P ³å|ë method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent] nsresult: 0x8057001e (NS_ERROR_XPC_JS_THREW_STRING) location: unknown data: no] I'm using the latest packed version on jquery.com front page, which should be 1.1.2. Code: html head titleTest jQuery Twitter/title script type=text/javascript src=jquery.js/script script type=text/javascript $(document).ready(function(){ var url = http://twitter.com/statuses/user_timeline/jackysee.json?callback=twitterCallbackamp;count=1 ; $.getScript(url); }); function twitterCallback(obj){ $(#text).html(obj[0].text); } /script /head bodyp id=text/p/body /html -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: How to handle Pseudo leak in IE?
Some progress... by using a garbage collection bin (a dummy div to appendChild and then empty the innerHTML), the DOM usage is stable now. Code: jQuery.fn.discard = function(){ var garbageBin = document.getElementById('IELeakGarbageBin'); if (!garbageBin) { garbageBin = document.createElement('DIV'); garbageBin.id = 'IELeakGarbageBin'; //garbageBin.style.display = 'none'; document.body.appendChild(garbageBin); } this .unbind() //unbind all handlers .each(function(){ // move the element to the garbage bin garbageBin.appendChild(this); garbageBin.innerHTML = ''; }); garbageBin = null; } Usage: e.g. $(testtbody*).discard(); But there are stills some memory keep increasing in IE when those addRows and deleteRows repeat again and again. Not knowing why. On 5/22/07, Jacky [EMAIL PROTECTED] wrote: I have some problem in creating the ticket. It always timeout when I submitting... I will try later. Anyway, here is an example about it. Load it in IESieve , cilck refresh rows or set interval and watch the memory and dom usage. html head titleTest Mem Leak in IE6/title script type=text/javascript src=jquery-1.1.2.js/script script type=text/javascript var datas = [ [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5] ]; $(document).ready(function(){ $(#remove).click(removeAllRows); $(#refresh).click(refreshRows); $(#interval).click(startRefresh); }); function startRefresh(){ var interval = setInterval(refreshRows,5*1000); } function refreshRows(){ removeAllRows(); for(var i=0; idatas.length; i++){ var tr = document.createElement(tr); for(var j=0; jdatas[i].length; j++){ var td = document.createElement(td); var d = datas[i][j]*Math.floor(Math.random ()*100+1); td.innerHTML = a href='#' onclick='return false;'+d+/a + input type='button' onclick='buttonClick(this)' value='+datas[i][j]+'/; $(tr).append(td); td = null; d = null; } var tb = $(#testtbody).append(tr); } } function removeAllRows(){ var tb = $(#testtbody) .find(*).unbind().end() .html(); } function buttonClick(obj){ obj.value = 'btn'; } /script /head body table id=test border=1 thead tr thth1/th thth2/th thth3/th thth4/th thth5/th /tr /thead tbody /tbody /table input type=button value=remove all rows id=remove/ input type=button value=refresh all rows id=refresh/ input type=button value=start interval id=interval/ /body /html -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 5/21/07, Brandon Aaron [EMAIL PROTECTED] wrote: If you could create a ticket and a test case for this it would help a lot! I believe I could find some time to investigate it in detail soon. -- Brandon Aaron On 5/21/07, Jacky [EMAIL PROTECTED] wrote: Hi all, I'm dealing with the IE memory problem. There is an IE leak called 'pseudo leak', where removeChild() is not really removing child from memory. It is pseudo because it would be cleared after refresh. (some detail: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/IETechCol/dnwebgen/ie_leak_patterns.asp ) However, my app is not page-driven, it would stay on same page and refreshing ajax call, refreshing table rows, etc. So the memory would just keep raising by the pseudo leak. It is said in some site that by setting innerHTML = would prevent the leak. So I try to do something like: $(tbody) .find(*).unbind().end() //unbinding all handler to prevent another closure leak .find(td,tr).html().remove().end() //setting html = and remove itself .html(); //setting tbody html to empty I use IESieve ( http://home.wanadoo.nl/jsrosman/ ) to check for the the dom object creation but it just keep increasing. Is there anyone try to tackle this 'leak' before? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] How to handle Pseudo leak in IE?
Hi all, I'm dealing with the IE memory problem. There is an IE leak called 'pseudo leak', where removeChild() is not really removing child from memory. It is pseudo because it would be cleared after refresh. (some detail: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/IETechCol/dnwebgen/ie_leak_patterns.asp ) However, my app is not page-driven, it would stay on same page and refreshing ajax call, refreshing table rows, etc. So the memory would just keep raising by the pseudo leak. It is said in some site that by setting innerHTML = would prevent the leak. So I try to do something like: $(tbody) .find(*).unbind().end() //unbinding all handler to prevent another closure leak .find(td,tr).html().remove().end() //setting html = and remove itself .html(); //setting tbody html to empty I use IESieve (http://home.wanadoo.nl/jsrosman/) to check for the the dom object creation but it just keep increasing. Is there anyone try to tackle this 'leak' before? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net
[jQuery] Re: How to handle Pseudo leak in IE?
I have some problem in creating the ticket. It always timeout when I submitting... I will try later. Anyway, here is an example about it. Load it in IESieve , cilck refresh rows or set interval and watch the memory and dom usage. html head titleTest Mem Leak in IE6/title script type=text/javascript src=jquery-1.1.2.js/script script type=text/javascript var datas = [ [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5] ]; $(document).ready(function(){ $(#remove).click(removeAllRows); $(#refresh).click(refreshRows); $(#interval).click(startRefresh); }); function startRefresh(){ var interval = setInterval(refreshRows,5*1000); } function refreshRows(){ removeAllRows(); for(var i=0; idatas.length; i++){ var tr = document.createElement(tr); for(var j=0; jdatas[i].length; j++){ var td = document.createElement(td); var d = datas[i][j]*Math.floor(Math.random()*100+1); td.innerHTML = a href='#' onclick='return false;'+d+/a + input type='button' onclick='buttonClick(this)' value='+datas[i][j]+'/; $(tr).append(td); td = null; d = null; } var tb = $(#testtbody).append(tr); } } function removeAllRows(){ var tb = $(#testtbody) .find(*).unbind().end() .html(); } function buttonClick(obj){ obj.value = 'btn'; } /script /head body table id=test border=1 thead tr thth1/th thth2/th thth3/th thth4/th thth5/th /tr /thead tbody /tbody /table input type=button value=remove all rows id=remove/ input type=button value=refresh all rows id=refresh/ input type=button value=start interval id=interval/ /body /html -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net On 5/21/07, Brandon Aaron [EMAIL PROTECTED] wrote: If you could create a ticket and a test case for this it would help a lot! I believe I could find some time to investigate it in detail soon. -- Brandon Aaron On 5/21/07, Jacky [EMAIL PROTECTED] wrote: Hi all, I'm dealing with the IE memory problem. There is an IE leak called 'pseudo leak', where removeChild() is not really removing child from memory. It is pseudo because it would be cleared after refresh. (some detail: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/IETechCol/dnwebgen/ie_leak_patterns.asp ) However, my app is not page-driven, it would stay on same page and refreshing ajax call, refreshing table rows, etc. So the memory would just keep raising by the pseudo leak. It is said in some site that by setting innerHTML = would prevent the leak. So I try to do something like: $(tbody) .find(*).unbind().end() //unbinding all handler to prevent another closure leak .find(td,tr).html().remove().end() //setting html = and remove itself .html(); //setting tbody html to empty I use IESieve (http://home.wanadoo.nl/jsrosman/ ) to check for the the dom object creation but it just keep increasing. Is there anyone try to tackle this 'leak' before? -- Best Regards, Jacky 網絡暴民 http://jacky.seezone.net