[Prototype-core] OO concept in prototypejs
There are 2 classes FormExt, AjaxRequest I create a FormExt object and when the user submit the form, then I will call another AjaxRequest Object When the AjaxRequest finish the process, then it will trigger onComplete I would like the onComplete method will call the FormExt.reset() so hwo to do this? I must pass the FormExt obj to the AjaxRequest??? and other method??? var FormExt = Class.create({ initialize: function(id){ this.id=id; this.obj=$(this.id); this.ajaxObj=''; this.eventSubmit=this.submit.bindAsEventListener(this); Event.observe(this.id, 'submit', this.eventSubmit); }, submit:function(e){ this.ajaxObj=new AjaxForm(this.id); this.ajaxObj.startAjax(); break; }, reset:function(){ this.obj.reset(); } }); var AjaxRequest = Class.create({ initialize: function(id){ this.frmObj=$(id); this.ajaxObj=''; }, startAjax: function(){ this.ajaxObj = new Ajax.Request( 'abc.php',{ onComplete:this.onComplete.bind(this) } ); } onComplete:function(){ alert('complete now'); } }); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: OO concept in prototypejs
On 05/03/2008, vtsuper [EMAIL PROTECTED] wrote: There are 2 classes FormExt, AjaxRequest I create a FormExt object and when the user submit the form, then I will call another AjaxRequest Object When the AjaxRequest finish the process, then it will trigger onComplete I would like the onComplete method will call the FormExt.reset() so hwo to do this? I must pass the FormExt obj to the AjaxRequest??? and other method??? var FormExt = Class.create({ initialize: function(id){ this.id=id; this.obj=$(this.id); this.ajaxObj=''; this.eventSubmit=this.submit.bindAsEventListener(this); Event.observe(this.id, 'submit', this.eventSubmit); }, submit:function(e){ this.ajaxObj=new AjaxForm(this.id); this.ajaxObj.startAjax(); break; }, reset:function(){ this.obj.reset(); } }); var AjaxRequest = Class.create({ initialize: function(id){ this.frmObj=$(id); this.ajaxObj=''; }, startAjax: function(){ this.ajaxObj = new Ajax.Request( 'abc.php',{ onComplete:this.onComplete.bind(this) } ); } onComplete:function(){ alert('complete now'); } }); var AjaxRequest = Class.create ({ initialize: function(id) { this.frmObj=$(id); this.ajaxObj=''; }, startAjax: function() { this.ajaxObj = new Ajax.Request ( 'abc.php', { onComplete:function() { alert('complete now'); this.formObj.reset(); } } } }); maybe. Sorry for the reform. Makes it easier for me to read. Basically added this.formObj.reset(); to the onComplete function. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Array deletion methods
I use a similar function to removeAt. Just with 2 key differences: 1) Takes start (i) and end (j) indexes. Both are actually optional, defaulting to length and taking no effect. 2) Returns the altered array with a child array containing the last group of deleted items. (Note: simply using [].rem().clone() will remove the child array) If removeAt is the Ruby port, then this probably won't keep with that aspect of Prototype. But, I prefer it since it doesn't break chaining. Thoughts? /* Array#del([start [, end]]) = Array (with: deleted = Array) */ Object.extend(Array.prototype, { del : function (i, j) { i = (Object.isNumber(i) i = 0) ? i.floor() : this.length; j = (Object.isNumber(j) j = i) ? j.floor() : i; this.deleted = this.splice(i, ((j - i) + 1)); return this; } }); [1, 3, 5, 7, 9].del(1).del(2) //= [1, 5, 9] (with: deleted = [7]) [1, 3, 5, 7, 9].del(3) //= [1, 3, 5, 9] [1, 3, 5, 7, 9].del(5) //= [1, 3, 5, 7, 9] [1, 3, 5, 7, 9].del(3, 3) //= [1, 3, 5, 9] [1, 3, 5, 7, 9].del(3, 4) //= [1, 3, 5] [1, 3, 5].del(0) //= [3, 5] [1, 3, 5].del(0).deleted //= [1] [1, 3, 5].del(0, 1).deleted//= [1, 3] - Jon L. On Mar 4, 12:46 pm, Samuel Lebeau [EMAIL PROTECTED] wrote: I often wanted to be able to simply remove some objects from an array without creating another array (using Array#without for instance). Array#splice seems to be the only way to change an array in place, and using it is not really easy nor readable. I submitted a patch (http://dev.rubyonrails.org/ticket/11042) which defines two methods I find useful: - Array#removeAt(index), which removes an object given its index - Array#removeIf(iterator[, context]), which removes objects for which iterator returns a truthy value These two methods are directly inspired from they Ruby equivalent Array#delete_at and Array#delete_if, with delete renamed remove as delete is a Javascript keyword, and in anticipation of a future Array#remove(object). Ruby's Array#delete_if returns instance (this) but this implementation returns an array of removed objects, which I think is less suprising (please give your opinionon this point). There are also corresponding unit tests which passes on all supported platforms (adapted from Ruby trunk ones), and inline documentation in PDoc format. I hope this will be helpful for everyone ! Regards, Samuel Lebeau --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Detecting CTRL keydown
I am trying to detect if the control key has been pressed to change and action. I am using the latest proto build. Here is my code: script type=text/javascript document.observe('keydown', function(k) { if (k.keyCode != 17) return; alert('ctrl'); }); /script I have noticed that not always on keydown does it register, it comes to about every other time. Can you offer any advice. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: OO concept in prototypejs
but I have a question on your solution when you call this.formObj.reset(); directly, you are executing the form reset function, but you are not executing the objects method, right? my real reset function is like this reset:function(e){ if (this.withValidation()){ this.validObj.reset(); } this.obj.reset(); unsetResponseMsg(); if (this.actionID=='add'){ this.setAddFrmDefaultValue(); if (this.withMultiFCK()){ this.multiFCK.setContent(''); } } else { this.setActionID('reset'); this.getPageInitValue(); } }, so I think your solution won't really work in my case and if I pass the FormExt object into AjaxRequest, it should be work, but A object's method create B object, and then pass A object into B object I feel strange on it, so I don't know how to do to make it works. On 3月6日, 上午1時18分, Richard Quadling [EMAIL PROTECTED] wrote: On 05/03/2008, vtsuper [EMAIL PROTECTED] wrote: There are 2 classes FormExt, AjaxRequest I create a FormExt object and when the user submit the form, then I will call another AjaxRequest Object When the AjaxRequest finish the process, then it will trigger onComplete I would like the onComplete method will call the FormExt.reset() so hwo to do this? I must pass the FormExt obj to the AjaxRequest??? and other method??? var FormExt = Class.create({ initialize: function(id){ this.id=id; this.obj=$(this.id); this.ajaxObj=''; this.eventSubmit=this.submit.bindAsEventListener(this); Event.observe(this.id, 'submit', this.eventSubmit); }, submit:function(e){ this.ajaxObj=new AjaxForm(this.id); this.ajaxObj.startAjax(); break; }, reset:function(){ this.obj.reset(); } }); var AjaxRequest = Class.create({ initialize: function(id){ this.frmObj=$(id); this.ajaxObj=''; }, startAjax: function(){ this.ajaxObj = new Ajax.Request( 'abc.php',{ onComplete:this.onComplete.bind(this) } ); } onComplete:function(){ alert('complete now'); } }); var AjaxRequest = Class.create ({ initialize: function(id) { this.frmObj=$(id); this.ajaxObj=''; }, startAjax: function() { this.ajaxObj = new Ajax.Request ( 'abc.php', { onComplete:function() { alert('complete now'); this.formObj.reset(); } } } }); maybe. Sorry for the reform. Makes it easier for me to read. Basically added this.formObj.reset(); to the onComplete function. -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants!- 隱藏被引用文字 - - 顯示被引用文字 - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Opera 9.5 and document.viewport
The relevant code in version 1.6.0.2 is: dimensions[d] = (B.WebKit !document.evaluate) ? self['inner' + D] : (B.Opera) ? document.body['client' + D] : document.documentElement['client' + D]; Here Opera 9.5 in strict mode behaves just like Firefox and IE 6 in strict mode, so the above code will not work. Under Opera 9.5 strict, the current code will return the height of the body, not the viewport. But in Opera 6 to 9, document.body.clientHeight is always the height of the viewport, so a generic browser check won't suffice. So to summarize, viewport.getDimensions() is broken under Opera 9.5 strict but works fine in Opera 9.5 quirks, which is the opposite of what one would expect. I know Opera 9.5 is a beta, but surely its new behavior is intentional. -- Matthew Leverton --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Opera 9.5 and document.viewport
I can confirm this. Found it some time ago and decided to wait till release. On 3/6/08, Matthew [EMAIL PROTECTED] wrote: The relevant code in version 1.6.0.2 is: dimensions[d] = (B.WebKit !document.evaluate) ? self['inner' + D] : (B.Opera) ? document.body['client' + D] : document.documentElement['client' + D]; Here Opera 9.5 in strict mode behaves just like Firefox and IE 6 in strict mode, so the above code will not work. Under Opera 9.5 strict, the current code will return the height of the body, not the viewport. But in Opera 6 to 9, document.body.clientHeight is always the height of the viewport, so a generic browser check won't suffice. So to summarize, viewport.getDimensions() is broken under Opera 9.5 strict but works fine in Opera 9.5 quirks, which is the opposite of what one would expect. I know Opera 9.5 is a beta, but surely its new behavior is intentional. -- Matthew Leverton -- arty ( http://arty.name ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---