Re: [jQuery] highlightFade for same id

2007-03-30 Thread Blair Mitchelmore
Selecting by ID in that syntax only selects the first element. Also, 
pages should only have one element of the same ID, but if you want to 
you can search using attribute checks.

$("[EMAIL 
PROTECTED]'show_credit_card']").highlightFade({color:'yellow',speed:1000,iterator:'sinusoidal'});
 


But it seems your elements also have that as a class name, so you can 
also modify your original as:

$('.show_credit_card').highlightFade({color:'yellow',speed:1000,iterator:'sinusoidal'});
 


-blair

Web Specialist wrote:
> How can I display highlightFade for the same id? Using this script 
> below only the first element(Credit Card Flag) with that id looks with 
> highlight.
>   
> $('#show_credit_card').highlightFade({color:'yellow',speed:1000,iterator:'sinusoidal'});
>  
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Any regular expression gurus here?

2007-03-29 Thread Blair Mitchelmore
Also, when perl 6 is released it will have support for a much more 
powerful system called rules which can handle nested parentheses quite 
handily.

-blair

Jake McGraw wrote:
> Christof:
>
> This may be true of traditional regular expressions, which is
> something you'll encounter in a college level automata class but very
> rarely in the real world. The fact is that most modern, since the 80s
> at least, regex implementations (JavaScript, Java, PHP,...) can handle
> many "nonregular" grammars, by making use of features such as
> look-ahead, atomic grouping, backreferences, etc.  For specifics on
> this, see:
>
> http://en.wikipedia.org/wiki/Regular_expression#Patterns_for_irregular_languages
>
> - jake
>
> On 3/29/07, Karl Swedberg <[EMAIL PROTECTED]> wrote:
>>
>> On Mar 29, 2007, at 4:55 AM, Christof Donat wrote:
>>
>>
>> Regular Expressions are used to define regular (Type 3 in Chomsky Hirarchy)
>>
>> grammars. You can not express nested parentheses in regular grammar, you
>> need
>>
>> a context free (Type 2) but not regular grammar.
>> Christof, that is fascinating! Thanks for that information!
>>
>>
>> This is something I'll have to remember for the next dinner conversation
>> with friends. You never know where Noam Chomsky[1] might pop up in a
>> conversation. :)
>>
>>
>> --Karl
>>
>> [1] http://en.wikipedia.org/wiki/Chomsky
>> _
>> Karl Swedberg
>> www.englishrules.com
>> www.learningjquery.com
>>
>>
>> ___
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/
>>
>>
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] bind two events to same function

2007-03-27 Thread Blair Mitchelmore
You're right, thanks for catching that.

-blair

Aaron Heimlich wrote:
> I'm pretty sure your code would cause an infinite loop.
>
> It should probably be (untested):
>
> jQuery.fn._bind = jQuery.fn.bind;
> jQuery.fn.bind = function(names,action) {
> var self = this;
> jQuery.each (names.split(/\s*,\s*/),function() {
>  self._bind(this,action); // self._bind(), not self.bind()
> };
>     return this;
> };
>
> On 3/27/07, * Blair Mitchelmore* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Or if you wanted to hack jQuery a bit for some syntactic sugar:
>
> jQuery.fn._bind = jQuery.fn.bind;
> jQuery.fn.bind = function(names,action) {
> var self = this;
> jQuery.each(names.split(/\s*,\s*/),function() {
>  self.bind(this,action);
> };
> return this;
> };
>
> That code might not work as intended, but the principle is valid.
>
> -blair
>
> Aaron Heimlich wrote:
> > function doSuperCoolStuff(evt) {
> > // do super cool stuff...
> > }
> >
> > $('[EMAIL PROTECTED]"submit"]').bind("mouseover",
> > doSuperCoolStuff).bind("mouseout", doSuperCoolStuff);
> >
> > On 3/27/07, *Josh Nathanson* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>> wrote:
> >
> > What is the syntax to bind two events to the same function?
> >
> > I want to do something like
> >
> > $("[EMAIL PROTECTED]").bind("mouseover,mouseout",
> function() {
> > stuff here
> > });
> >
> > But it doesn't work.  TIA
> >
> > -- Josh
> >
> >
> > ___
> > jQuery mailing list
> > discuss@jquery.com <mailto:discuss@jquery.com>
> <mailto:discuss@jquery.com <mailto:discuss@jquery.com>>
> > http://jquery.com/discuss/ <http://jquery.com/discuss/>
> <http://jquery.com/discuss/>
> >
> >
> >
> >
> > --
> > Aaron Heimlich
> > Web Developer
> > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
> > http://aheimlich.freepgs.com <http://aheimlich.freepgs.com
> <http://aheimlich.freepgs.com>>
> >
> >
> 
> >
> > ___
> > jQuery mailing list
> > discuss@jquery.com <mailto:discuss@jquery.com>
> > http://jquery.com/discuss/
>
>
> ___
> jQuery mailing list
> discuss@jquery.com <mailto:discuss@jquery.com>
> http://jquery.com/discuss/
>
>
>
>
> -- 
> Aaron Heimlich
> Web Developer
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> http://aheimlich.freepgs.com
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] bind two events to same function

2007-03-27 Thread Blair Mitchelmore
Or if you wanted to hack jQuery a bit for some syntactic sugar:

jQuery.fn._bind = jQuery.fn.bind;
jQuery.fn.bind = function(names,action) {
var self = this;
jQuery.each(names.split(/\s*,\s*/),function() {
 self.bind(this,action);
};
return this;
};

That code might not work as intended, but the principle is valid.

-blair

Aaron Heimlich wrote:
> function doSuperCoolStuff(evt) {
> // do super cool stuff...
> }
>
> $('[EMAIL PROTECTED]"submit"]').bind("mouseover", 
> doSuperCoolStuff).bind("mouseout", doSuperCoolStuff);
>
> On 3/27/07, *Josh Nathanson* <[EMAIL PROTECTED] 
> > wrote:
>
> What is the syntax to bind two events to the same function?
>
> I want to do something like
>
> $("[EMAIL PROTECTED]").bind("mouseover,mouseout", function() {
> stuff here
> });
>
> But it doesn't work.  TIA
>
> -- Josh
>
>
> ___
> jQuery mailing list
> discuss@jquery.com 
> http://jquery.com/discuss/ 
>
>
>
>
> -- 
> Aaron Heimlich
> Web Developer
> [EMAIL PROTECTED] 
> http://aheimlich.freepgs.com 
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] NEW Plug-in: cfjs (ColdFusionJavaScript)

2007-03-13 Thread Blair Mitchelmore
'!!' double negates the object thus converting it to a boolean.

-blair

Daemach wrote:
> What does the !! do?
>
>
> Dan G. Switzer, II wrote:
>>> Please add:
>>>
>>> StructKeyExists: function(s,k){
>>> for(var n in s){
>>> if (n == k) return true;
>>> }
>>> return false;
>>> },
>>>
>>>
>>> Shall we post additions and updates here?
>> This would be much more efficient:
>>
>> StructKeyExists: function(s,k){
>>  return !!s[k];
>> },
>>
>> However, it's also important to remember that a ColdFusion "structure"
>> isn't
>> the exact same thing as a JavaScript Object.
>>
>> -Dan


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Options for Validation...

2007-03-08 Thread Blair Mitchelmore
You might want to look into Mike Alsup's Taconite plug-in 
. Seems to be able to do what 
you want.

-blair

Rick Faircloth wrote:
>
> Calling all jQuery/CF’ers…
>
> I’m not real satisfied with the error message placement
>
> options in Jorn Zaefferer’s validation plug-in.
>
> I like to place my error messages right above the form field
>
> that the error message references.
>
> Right now, as I understand it, Jorn’s plug-in doesn’t allow
>
> for that type of placement.
>
> Among the options are placement after the invalid element.
>
> Don’t like that…
>
> Another option is to validate onSubmit and, while that’s ok,
>
> I’m still limited to grouping the error messages at the top
>
> of the form. That’s not a good user experience when the
>
> form may be 50 fields long and the user has to scroll up and
>
> down to check errors messages.
>
> Here’s my scenario and question:
>
> I’m using jQuery to calculate a mortgage payment. Once the
>
> form is submitted, the form info is sent to a CF pages for
>
> processing, then the resulting payment is returned to the calling
>
> page. Very nice…
>
> The question is this…can I use CF to validate the form data
>
> and then, if there’s an error, set some error messages in a scope,
>
> such as Form_Errors.Principal, etc., and send that info back to the
>
> calling page and display it in the form as described above?
>
> If all user input passes validation, then the other CF code processes
>
> the payment and returns it to the calling page.
>
> Is this kind validation possible without page refreshing?
>
> Rick
>
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] get element inside a div simple question

2007-03-02 Thread Blair Mitchelmore
If I recall correctly, to get it in order you need to take all elements 
and then filter manually or do it hierarchically.

One way:
$('*',main_content).each(function() {
if (this.tagName.toLowerCase() == 'h1')
   // ...
else if (this.tagName.toLowerCase() == 'h2')
   // ...
// etc.
});

The Other:
$('h1',main_content).each(function() {
$('h2',this).each(function() {
   // and so on..
});
});

Which one you use would depend on what your ultimate goal is, though I'm 
sure either technique can be modified to suit any situation.

-blair

sebastianw wurtz wrote:
> But still isnt what i need i making a auto gen table of content list i 
> have this
>
> var main_content = $("#main_content");
> var toBeTOCced = $("h2,h3,h4,h5", main_content);
> toBeTOCced.each(function(i) {
>.
>.
> });
>
> * 1. Title 1
> * 3. Title 2
> * 4. Title 3
> * 5. Title 4
> * 6. Title 5
> * 7. Title 2.1
> * 8. Title 2.2
> * 9. Title 4.1
> * 10. Title 4.1
>
> Seems to be not in order. Like is usual i need to put the
> 2
> 2.1
> 2.2
> 
> ...
>
>
>
>
> - Mensaje original 
> De: Blair Mitchelmore <[EMAIL PROTECTED]>
> Para: jQuery Discussion. 
> Enviado: viernes 2 de marzo de 2007, 20:44:55
> Asunto: Re: [jQuery] get element inside a div simple question
>
> var main_content = $("#main_content");
> var toBeTOCced = $("h2,h3,h4,h5", main_content); // there it is
>
> -blair
>
> sebastianw wurtz wrote:
> > I want to get all the Heading element up to 5 (ex |h2,h3,h4,h5| )
> > inside a div like #main_content
> >
> > something like this, but inside the #main_content
> > |var toBeTOCced = getElementsByTagNames('h2,h3,h4,h5');|
> >
> > How i can do that with jquery?
> >
> >
> > thanks
> >
> > Sebastián
> >
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] get element inside a div simple question

2007-03-02 Thread Blair Mitchelmore
var main_content = $("#main_content");
var toBeTOCced = $("h2,h3,h4,h5", main_content); // there it is

-blair

sebastianw wurtz wrote:
> I want to get all the Heading element up to 5 (ex |h2,h3,h4,h5| ) 
> inside a div like #main_content
>
> something like this, but inside the #main_content
> |var toBeTOCced = getElementsByTagNames('h2,h3,h4,h5');|
>
> How i can do that with jquery?
>
>
> thanks
>
> Sebastián
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] How do I check for the existence of an object?

2007-02-23 Thread Blair Mitchelmore
You can do (typeof myObj == 'undefined') and I think you can also do 
(myObj == undefined) thanks to the completely mind-blowing line of code 
at the beginning of jQuery
window.undefined = window.undefined;

-blair

Daemach wrote:
> I want to create a global object to store some settings in, but only if it
> doesn't exist already.  If it doesn't exist and I try to use something like
> if (myObj == 'undefined') myObj = new Object();  I get an error saying the
> object is not defined.
>
> Yeah I should know stuff like this ;)


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-23 Thread Blair Mitchelmore
I think your problem might be that in your autosave plug-in you call fcn 
directly. Try running fcn.apply(this) instead to manually adjust the 
scope so 'this' references the DOM element again.

-blair

Daemach wrote:
> Bleh.
>
> When I pass a function in via the plugin's method with the below code, it
> doesn't recognize the "this" scope anymore.  Am I not passing the function
> in correctly?
>
> $('input:[EMAIL PROTECTED]').each( function() {
> $(this).autoSave(function(){
> $.AjaxCFC({
> url: "some.cfc",
> method: "updateAttendee",
> data: {
> fid:this.id,
> field:this.id.split("_")[0],
> id:this.id.split("_")[1],
> value:this.value},
> success: function(r){}
> });
> });
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] How do I grab just the selected objects out of the jquery object?

2007-02-23 Thread Blair Mitchelmore
$("p").get() returns a regular array with the jQuery set as its members.

-blair

Daemach wrote:
> I got burned by a debug plugin last night so I'm modifying a great object
> dumper to run as a jquery plugin.  Dumping the entire jquery object is too
> much and not useful for this application - I only want the objects in the
> current selection set.  If I do:
>
> var tmp = $("p");
>
> and there are  2 "p" elements on the page, the selection set is tmp[0] and
> tmp[1].  Is there another location in the object where these references
> reside? Or what is an elegant and fast way to strip just those items?
>
> Eventually I want to call this using $("p").dump() or $("p").debug()


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-23 Thread Blair Mitchelmore
Functions in JavaScript run at a certain scope. A lot of the time, if 
the function isn't a part of some Object that scope defaults to the 
window object. All JavaScript functions also have two functions that 
allow you to redefine the scope of a function as you call it: apply and 
call. apply takes 2 arguments: the new scope to call the function under 
and an array of arguments to call the function with. call does the same 
thing but instead of an array of arguments, you just supply the 
arguments as additional arguments to that function call.

Example:
var scope = "Scope";
var arg = "Arg";
var fn = function(e) {
window.alert(this + " => " + e);
};
fn(arg); // alerts " => Arg"
fn.apply(scope,[arg]); // alerts "Scope => Arg"
fn.call(scope,arg); // alerts "Scope => Arg"

This allows you to redefine the this variable on the fly. Additionally, 
the reason self is used rather than this in fn.apply(self) is because 
'this' changes scope once you enter a new function. So inside the 
anonymous function defined in the setTimeout call, the scope variable 
'this' is likely to be the window object. So you have to save a 
reference to the 'this' you want to use as a separate variable so it can 
be referenced elsewhere: hence self = this followed by (inside the 
anonymous function) fn.apply(self).

-blair

Daemach wrote:
> Yeah that worked.  I'm not certain I understand why though :)
>
> It does make sense that the closure would actually have to be created inside
> the event handler but .apply(self) is a new one for me.  What exactly is
> that doing?
>
>
> Blair Mitchelmore-2 wrote:
>> $(document).ready( function() {
>>  var timer;
>>  var fn = function(e) {
>>  if (e && e.type == 'blur') {
>>  if (timer)
>>  window.clearTimeout(timer);
>>  }
>>  // Do stuff
>>  alert(this.id);
>>  }
>>  $('#test').blur(fn).keyup(function() {
>>  var self = this;
>>  timer = window.setTimeout(function() {
>>  fn.apply(self);
>>  },2000);
>>  }).keydown(function() {
>>  if (timer) window.clearTimeout(timer);
>>  });
>> });

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Reference to newly inserted item?

2007-02-22 Thread Blair Mitchelmore
$(this).parents("div.sidebarToDo").find("input.editableTDItem");  is probably 
finding every thing you're added. Are you sure there's only one element in the 
resultant jQuery object? Either way, if the last input field is the only one 
your care about at the moment you can modify your search to be 
$(this).parents("div.sidebarToDo").find("input.editableTDItem:last");

-blair

[EMAIL PROTECTED] wrote:
> Hi,
>
> If I have
>
> $(this).parents("div.sidebarToDo").find("td.sidebarText").empty().append('  type="text" value="" size="10" class="editableItem">');
>
> What is the best way to get a reference to the newly created text field?  
> Note that it does not have an ID and I would prefer a more generic way of 
> finding it other than "input.editableItem" because on PC IE 6, if I insert 
> multiple text fields, like the above, this call  ...
>
> $(this).parents("div.sidebarToDo").find("input.editableTDItem");  
>
> only returns a correct reference for the first time a textfield is added.  I 
> cant get the most recent addition with the above call if there had been text 
> fields added in the past.
>
> Thanks, please let me know what info I can provide to make this question more 
> clear, - Dave


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-22 Thread Blair Mitchelmore
I understand your frustration. When I first got into JavaScript all I 
ever heard was closures and I had no idea what they were, but you've 
pretty much got it. The problem you're having with the code you have 
there is that window.setTimeout doesn't modify scope, it uses the window 
as the scope of the function. That's why this.id doesn't work when using 
the timeout method. I forgot that my plug-in fixed that problem so I 
didn't write the setTimeout section properly. What you need to do is 
create a function that calls that function in the proper scope. There 
used to be a closure plug-in at <http://mg.to/jquery-code/closure.js> 
but it's fairly dated by now. Here's a quick rewrite of your solution 
that should fix the setTimeout problems you have:

$(document).ready( function() {
var timer;
var fn = function(e) {
if (e && e.type == 'blur') {
if (timer)
window.clearTimeout(timer);
}
// Do stuff
alert(this.id);
}
$('#test').blur(fn).keyup(function() {
var self = this;
timer = window.setTimeout(function() {
fn.apply(self);
},2000);
}).keydown(function() {
if (timer) window.clearTimeout(timer);
});
});

The fn function now gets called inside the setTimeout function with a 
reassigned scope so even in the setTimeout situation this refers to the DOM 
element in question.


-blair

Daemach wrote:
> I appreciate you taking the time to lay this out.  I'm really just trying to
> understand more than anything.  Obviously this isn't the right forum to be
> asking questions about closures specifically, but if I can just get a grip
> on this...
>
> I tested this yesterday with the following code.  At the moment it tries to
> pop 2 alert boxes because the first alert blurs the text field -
> interestingly, in the second alert box "this.id" is undefined.  Would that
> be because the timer function wasn't being created inside of the blur
> function like it is on the keyup?  Closures are all about context right? 
> I'm assuming the reason the fn function knows about "this" being the dom
> element is because the timer function is being created inside the keyup
> event, but that's just a guess.
>
> Thanks again for all the help.
>
> 
> $(document).ready( function() {
>   var timer;
>   var fn = function(e) {
>   if (e && e.type == 'blur') {
>   if (timer)
>   window.clearTimeout(timer);
>   }
>   // Do stuff
>   alert(this.id);
>   }
>   $('#test').blur(fn).keyup(function() {
>   var el = this.id;
>   timer = window.setTimeout(fn,2000);
>   }).keydown(function() {
>   if (timer) window.clearTimeout(timer);
>   });
> });
> 
>
>
> 
>
>
>
> Blair Mitchelmore-2 wrote:
>>> $(document).ready( function() {
>>> $('[EMAIL PROTECTED]').each( function() {
>>> $(this).blur( function() {
>>> $.AjaxCFC({
>>> url: "/namechangedtoprotecttheinnocent.cfc",
>>> method: "updateAttendee",
>>> data: {
>>> fid:this.id,
>>> field:this.id.split("_")[0],
>>> id:this.id.split("_")[1],
>>> value:this.value
>>> },
>>> success: function(r){
>>> $('#'+r).css("backgroundColor","#ddFFdd");
>>> }
>>> });
>>> $(this).css("backgroundColor","#FF");
>>> });
>>> });
>>> }); 
>> Well it looks like the variables you need to access are all a part of 
>> the DOM element, right? So you can access that element by the same 
>> 'this' variable because both the blur and the once function reassign 
>> 'this' to be the DOM element. I am again using my plugin to make the 
>> code simpler, but you don't need to.
>>
>> Code:
>>
>> var fn = function(e) {
>>  if (e && e.type == 'blur') $(this).stop();
>>  $.AjaxCFC({
>>  url: "/namechangedtoprotecttheinnocent.cfc",
>>   

Re: [jQuery] Gmail-style updates

2007-02-22 Thread Blair Mitchelmore
> $(document).ready( function() {
> $('[EMAIL PROTECTED]').each( function() {
> $(this).blur( function() {
> $.AjaxCFC({
> url: "/namechangedtoprotecttheinnocent.cfc",
> method: "updateAttendee",
> data: {
> fid:this.id,
> field:this.id.split("_")[0],
> id:this.id.split("_")[1],
> value:this.value
> },
> success: function(r){
> $('#'+r).css("backgroundColor","#ddFFdd");
> }
> });
> $(this).css("backgroundColor","#FF");
> });
> });
> }); 
Well it looks like the variables you need to access are all a part of 
the DOM element, right? So you can access that element by the same 
'this' variable because both the blur and the once function reassign 
'this' to be the DOM element. I am again using my plugin to make the 
code simpler, but you don't need to.

Code:

var fn = function(e) {
if (e && e.type == 'blur') $(this).stop();
$.AjaxCFC({
url: "/namechangedtoprotecttheinnocent.cfc",
method: "updateAttendee",
data: {
fid:this.id,
field:this.id.split("_")[0],
id:this.id.split("_")[1],
value:this.value
},
success: function(r){
$('#'+r).css("backgroundColor","#ddFFdd");
}
});
$(this).css("backgroundColor","#FF");
}
$(whatever).blur(fn).keyup(function() {
$(this).once(2000,fn);
}).keydown(function() {
$(this).stop();
});

Let me know if that works.

-blair

Daemach wrote:
> Grrr Nabble is tricky ;)  Try this thread: 
> http://www.nabble.com/forum/ViewPost.jtp?post=9089663&framed=y
>
>
>
> Blair Mitchelmore-2 wrote:
>> Could I maybe see the code? It's hard to customize something to a 
>> situation I nothing about.
>>
>> -blair
>>
>> Daemach wrote:
>>> OK I played around with this for a while with a fresh head.  As I
>>> understand
>>> it, the main power of closures is that they retain the environment in
>>> which
>>> they were created.  I'm not sure how that applies here, since closures
>>> have
>>> to be defined inside of another function then returned to retain that
>>> environment, but I'm sure it's something I'm overlooking.
>>>
>>> The problem with the code below is that I need to pass other variables in
>>> addition to the event, such as the id and  value of the input element
>>> that
>>> this event handler is being registered on - how can I do this with the
>>> below
>>> code?
>>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-22 Thread Blair Mitchelmore
Could I maybe see the code? It's hard to customize something to a 
situation I nothing about.

-blair

Daemach wrote:
> OK I played around with this for a while with a fresh head.  As I understand
> it, the main power of closures is that they retain the environment in which
> they were created.  I'm not sure how that applies here, since closures have
> to be defined inside of another function then returned to retain that
> environment, but I'm sure it's something I'm overlooking.
>
> The problem with the code below is that I need to pass other variables in
> addition to the event, such as the id and  value of the input element that
> this event handler is being registered on - how can I do this with the below
> code?
>
>
>
> Blair Mitchelmore-2 wrote:
>> Well first off, my plugin's code can be found at 
>> <http://jquery.offput.ca/js/jquery.every.js> but I haven't yet set up a 
>> page which explains the plug-in's capabilities and I haven't optimised 
>> the code or really debugged it as I wrote it on a lark a while ago and 
>> haven't put much thought to it since. So after all these disclaimers I 
>> suggest you use it with caution. In fact, I've taken the liberty of 
>> re-writing my previous code with regular setTimeouts...
>>
>> Example:
>> var timer;
>> var fn = function(e) {
>>  if (e && e.type == 'blur') {
>>  if (timer)
>>  window.clearTimeout(timer);
>>  }
>>  // Do stuff
>> }
>> $(whatever).blur(fn).keyup(function() {
>>  timer = window.setTimeout(fn,2000);
>> }).keydown(function() {
>>  if (timer) window.clearTimeout(timer);
>> });
>>
>> This previous example also takes advantage of another feature you 
>> require: closures. The basic idea behind closures is that you can create 
>> an anonymous function which takes advantage of data currently in scope 
>> even if not existence in the scope the function is ultimately called. 
>> You see this when I create the timer variable and then use it inside the 
>> fn function I created. Any variables in scope when you define your 
>> function can be accessed later on by that function. It's one of the 
>> coolest and most powerful features of JavaScript. Hope all that helped.
>>
>> -blair
>>
>> Daemach wrote:
>>> Would you mind posting a link to your timer plugin?
>>>
>>> If I'm going to use an external function I will need to pass additional
>>> parameters.  How do you force passing the event type along with extra
>>> data? 
>>> I'm newish to javascript...
>>>
>>>
>>>
>>> Blair Mitchelmore-2 wrote:
>>>> It might be better if you didn't use an anonymous function so you could 
>>>> reference it multiple times. (I'm going to use a plugin I wrote that 
>>>> jQuerizizes timer events cause it really simplifies the syntax of the 
>>>> solution but something equivalent could be done without it.)
>>>>
>>>> Example:
>>>> var fn = function(e) {
>>>> if (e.type == 'blur') $(this).stop();
>>>> // Do stuff
>>>> }
>>>> $(whatever).blur(fn).keyup(function() {
>>>> $(this).once(2000,fn);
>>>> }).keydown(function() {
>>>> $(this).stop();
>>>> });
>>>>
>>>> Hope that helps.
>>>>
>>>> -blair
>>>>
>>>> Daemach wrote:
>>>>> I have a form with which I want to do ajax updates as they type.  If
>>>>> they
>>>>> stop typing for more than 2 seconds it should update the field.  If the
>>>>> field blurs before the 2 seconds are up it should update the field.  
>>>>>
>>>>> I have the ajax side of it worked out, and currently the updates work
>>>>> properly when the field blurs.  I just need some ideas on how to write
>>>>> the
>>>>> timer function for the keypresses and how it integrates with the blur
>>>>> function so the function doesn't get called twice and so there are no
>>>>> memory
>>>>> leaks from timers set then abandoned because the blur event got to it
>>>>> first.
>>>>>
>>>>> I'm going for elegance here :)  I could write an outside function that
>>>>> gets
>>>>> called from both event handlers but that seems cheezy.  There must be a
>>>>> way
>>>>> to do this with an anonymous function...

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-21 Thread Blair Mitchelmore
Well first off, my plugin's code can be found at 
<http://jquery.offput.ca/js/jquery.every.js> but I haven't yet set up a 
page which explains the plug-in's capabilities and I haven't optimised 
the code or really debugged it as I wrote it on a lark a while ago and 
haven't put much thought to it since. So after all these disclaimers I 
suggest you use it with caution. In fact, I've taken the liberty of 
re-writing my previous code with regular setTimeouts...

Example:
var timer;
var fn = function(e) {
if (e && e.type == 'blur') {
if (timer)
window.clearTimeout(timer);
}
// Do stuff
}
$(whatever).blur(fn).keyup(function() {
timer = window.setTimeout(fn,2000);
}).keydown(function() {
if (timer) window.clearTimeout(timer);
});

This previous example also takes advantage of another feature you 
require: closures. The basic idea behind closures is that you can create 
an anonymous function which takes advantage of data currently in scope 
even if not existence in the scope the function is ultimately called. 
You see this when I create the timer variable and then use it inside the 
fn function I created. Any variables in scope when you define your 
function can be accessed later on by that function. It's one of the 
coolest and most powerful features of JavaScript. Hope all that helped.

-blair

Daemach wrote:
> Would you mind posting a link to your timer plugin?
>
> If I'm going to use an external function I will need to pass additional
> parameters.  How do you force passing the event type along with extra data? 
> I'm newish to javascript...
>
>
>
> Blair Mitchelmore-2 wrote:
>> It might be better if you didn't use an anonymous function so you could 
>> reference it multiple times. (I'm going to use a plugin I wrote that 
>> jQuerizizes timer events cause it really simplifies the syntax of the 
>> solution but something equivalent could be done without it.)
>>
>> Example:
>> var fn = function(e) {
>> if (e.type == 'blur') $(this).stop();
>> // Do stuff
>> }
>> $(whatever).blur(fn).keyup(function() {
>> $(this).once(2000,fn);
>> }).keydown(function() {
>> $(this).stop();
>> });
>>
>> Hope that helps.
>>
>> -blair
>>
>> Daemach wrote:
>>> I have a form with which I want to do ajax updates as they type.  If they
>>> stop typing for more than 2 seconds it should update the field.  If the
>>> field blurs before the 2 seconds are up it should update the field.  
>>>
>>> I have the ajax side of it worked out, and currently the updates work
>>> properly when the field blurs.  I just need some ideas on how to write
>>> the
>>> timer function for the keypresses and how it integrates with the blur
>>> function so the function doesn't get called twice and so there are no
>>> memory
>>> leaks from timers set then abandoned because the blur event got to it
>>> first.
>>>
>>> I'm going for elegance here :)  I could write an outside function that
>>> gets
>>> called from both event handlers but that seems cheezy.  There must be a
>>> way
>>> to do this with an anonymous function...
>>
>> ___
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/
>>
>>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Gmail-style updates

2007-02-21 Thread Blair Mitchelmore
It might be better if you didn't use an anonymous function so you could 
reference it multiple times. (I'm going to use a plugin I wrote that 
jQuerizizes timer events cause it really simplifies the syntax of the 
solution but something equivalent could be done without it.)

Example:
var fn = function(e) {
if (e.type == 'blur') $(this).stop();
// Do stuff
}
$(whatever).blur(fn).keyup(function() {
$(this).once(2000,fn);
}).keydown(function() {
$(this).stop();
});

Hope that helps.

-blair

Daemach wrote:
> I have a form with which I want to do ajax updates as they type.  If they
> stop typing for more than 2 seconds it should update the field.  If the
> field blurs before the 2 seconds are up it should update the field.  
>
> I have the ajax side of it worked out, and currently the updates work
> properly when the field blurs.  I just need some ideas on how to write the
> timer function for the keypresses and how it integrates with the blur
> function so the function doesn't get called twice and so there are no memory
> leaks from timers set then abandoned because the blur event got to it first.
>
> I'm going for elegance here :)  I could write an outside function that gets
> called from both event handlers but that seems cheezy.  There must be a way
> to do this with an anonymous function...


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Getting parent nodes

2007-02-20 Thread Blair Mitchelmore
$(this).parent("div");

-blair

[EMAIL PROTECTED] wrote:
> Hi,
>
> If I have a "this.id" reference to an element in my DOM, how would i get its 
> parent node?  
>
> More challenging, how would I get the first DIV node that the element is in?  
> That is, it may be nested within an arbitrary number of table cells, but 
> there is a DIV lurking at the top ...
>
> 
> 
> 
>
>   
>  
>
> In the example here, I would like to get a reference to the DIV with ID = 
> "inner".
>
> Thanks, you guys are the best, - Dave
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Select "orphan" text.

2007-02-20 Thread Blair Mitchelmore
Well that behaviour makes sense because to jQuery it would look like a 
css selector for a plainText1 element, but that doesn't explain why 
leading and trailing text gets stripped... *reads code* aha, the jQuery 
object, when it does it's little search for html tags (line 32 of svn 
rev 1323) in the jQuery initialization argument, only saves what it 
finds (inclusively) between the first and last html tags in the string.
var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
It passes m[1] (the first matched sequence) to jQuery.clean rather than 
the whole string. So unless that gets changed at the core, you're out of 
luck for those leading and trailing text elements.

-blair

Abel Tamayo wrote:
> Actually when you evaluate a string in the jQuery object, you get an 
> empty object in return: $("plainText1") becomes the empty object [].
>
> On 2/20/07, *Blair Mitchelmore* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Well seeing as it only affects the first and the last 'elements' you
> could try testing the first and last elements of the jQuery object
> manually. Then you might see why the first element isn't being
> recognized as an orphan node when it is and be able to compensate for
> that in the filtering function.
>
> -blair
>
> Abel Tamayo wrote:
> > Thanks, Blair. Your solution works 'perfectly'. Only problem is it
> > doesn't select orphan nodes at the beginning and end of the string,
> > i.e: in $("plain1
> formated1plain2formatted2plain3") only
> > ["plain2"] is selected.
> >
> > Any idea how I can work around this?
> >
> > Abel.
> >
> > On 2/20/07, *Blair Mitchelmore* < [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
> >
> > I'm not sure if this would work at all and I'm not sure of
> the syntax
> > for the function usage of filter but I think it'd work like this
> > (theoretically):
> >
> > $(whatevah).filter(function() {
> > return this.nodeType && this.nodeType == 3; // nodeType
> of 3 is a
> > Text node.
> > });
> >
> > I have no idea if this works but it's the only thing I could
> think of.
> > Hope it helps.
> >
> > -blair
> >
> > Abel Tamayo wrote:
> > > Hi all,
> > >
> > > this time I need to know the way to select text that is not
> > inside a
> > > tag. That is, in $("orphan1  in span  orphan2
>  in p
> > >  orphan3") i would need to get a jQuery object like this :
> > > ["orphan1", "orphan2", "orphan3"].
> > >
> > > I've been trying with functions like .filter(String) or
> > > .not("HTMLElement"), but none of them seem to work.
> > >
> > > Any ideas? Thanks in advance.
> > >
> > > Abel.
> > >
> <http://jquery.com/discuss/>
>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Select "orphan" text.

2007-02-20 Thread Blair Mitchelmore
Well seeing as it only affects the first and the last 'elements' you 
could try testing the first and last elements of the jQuery object 
manually. Then you might see why the first element isn't being 
recognized as an orphan node when it is and be able to compensate for 
that in the filtering function.

-blair

Abel Tamayo wrote:
> Thanks, Blair. Your solution works 'perfectly'. Only problem is it 
> doesn't select orphan nodes at the beginning and end of the string, 
> i.e: in $("plain1 formated1plain2formatted2plain3") only 
> ["plain2"] is selected.
>
> Any idea how I can work around this?
>
> Abel.
>
> On 2/20/07, *Blair Mitchelmore* < [EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> I'm not sure if this would work at all and I'm not sure of the syntax
> for the function usage of filter but I think it'd work like this
> (theoretically):
>
> $(whatevah).filter(function() {
> return this.nodeType && this.nodeType == 3; // nodeType of 3 is a
> Text node.
> });
>
> I have no idea if this works but it's the only thing I could think of.
> Hope it helps.
>
> -blair
>
> Abel Tamayo wrote:
> > Hi all,
> >
> > this time I need to know the way to select text that is not
> inside a
> > tag. That is, in $("orphan1  in span  orphan2  in p
> >  orphan3") i would need to get a jQuery object like this :
> > ["orphan1", "orphan2", "orphan3"].
> >
> > I've been trying with functions like .filter(String) or
> > .not("HTMLElement"), but none of them seem to work.
> >
> > Any ideas? Thanks in advance.
> >
> > Abel.
> >
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Sortables question

2007-02-20 Thread Blair Mitchelmore
$('ol.steps li').each(function(index) {
$(this).append('List item ' + (index + 1) + 
'');
});

Would convert:


Cut a hole in a box
Put your junk in that box
Make her open the box


into:


Cut a hole in a boxList item 1
Put your junk in that boxList item 2
Make her open the boxList item 3


...I think...

If each li element has an id attribute you can access them by using 
this.id inside the each iterator function.

-blair

[EMAIL PROTECTED] wrote:
> Regarding the sortables plug-in and the specific example
>
> http://interface.eyecon.ro/demos/sort_lists.html
>
> does anyone know how I would iterate over the items in the list in the order 
> in which they appear on screen?  My goal is to list the ids in the order they 
> appear.
>
> Your help is greatly appreciated as always, - Dave
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Select "orphan" text.

2007-02-20 Thread Blair Mitchelmore
I'm not sure if this would work at all and I'm not sure of the syntax 
for the function usage of filter but I think it'd work like this 
(theoretically):

$(whatevah).filter(function() {
return this.nodeType && this.nodeType == 3; // nodeType of 3 is a 
Text node.
});

I have no idea if this works but it's the only thing I could think of. 
Hope it helps.

-blair

Abel Tamayo wrote:
> Hi all,
>
> this time I need to know the way to select text that is not inside a 
> tag. That is, in $("orphan1  in span  orphan2  in p 
>  orphan3") i would need to get a jQuery object like this : 
> ["orphan1", "orphan2", "orphan3"].
>
> I've been trying with functions like .filter(String) or 
> .not("HTMLElement"), but none of them seem to work.
>
> Any ideas? Thanks in advance.
>
> Abel.
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Unable to chain Find with multiple classes

2007-02-20 Thread Blair Mitchelmore
I think you're looking for filter not find. Try this:

$(function(){
$("[EMAIL PROTECTED]").change(function(){
$(".group").hide().filter("."+$(this).val()).show();
}).val("us").change();
});

-blair

Jake McGraw wrote:
> Hey all, not sure if this is a bug, but I came across it today:
>
> Let's say my document looks like this:
>
> 
> Pick a country
>
>   United States
>   United Kingdom
>   Australia
>
> 
> United States
> United States
> United Kingdom
> Australia
> 
>
> and my js looks like this:
>
> $(function(){
> $("[EMAIL PROTECTED]").change(function(){
>$(".group").hide().find("."+$(this).val()).show();
> }).val("us").change();
> });
>
> What I've found is that jQuery won't "find" the jQuery objects when 
> chaining find(".class_name") to a group of jQuery objects already 
> selected by class. Hope that sentence made sense. This script will 
> work fine if I split up the show/hide into two calls, that is:
>
> $(".group").hide();
> $("."+$(this).val()).show();
>
> So, my question is, if find() will operate on elements of the same 
> level using element name or id ($("li").find(".group") returns all 
> li.group) why won't it work on elements of the same level when using 
> only class names ($(".group").find(".us") returns nothing)?
>
> - jake
>
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] How do I get the XML of an ajax request?

2007-02-18 Thread Blair Mitchelmore
Looks like your request worked and you got XML back. You can try 
inspecting the XML response to see what was return to extract the data 
manually or if you could also try wrapping the XML document in a jQuery 
Object and calling the .html() method to get the value of your xml 
response without any dirty work. I don't know if that works or not, I 
haven't worked with ajax for over six months and it was before I 
discovered jQuery. Hope this helps:

$.get("/rgeo/",
{ x: document.rgeo.x.value, y: document.rgeo.y.value },
function(data){
console.log(data);
$("textarea#response")[0].value = $(data).html();
}
);

-blair

djl wrote:
> Hi all,
>
> How do I get the XML response of an ajax request? I want to put the XML 
> text into a textarea and can do find this documented.
>
>  $.get("/rgeo/",
>  { x: document.rgeo.x.value, y: document.rgeo.y.value },
>  function(data){
>  console.log(data);
>  $("textarea#response")[0].value = data;
>  }
>  );
>
>
>
> My textarea ends up with the string "[object XMLDocument]"
>
> I also tried:
>
>
>  $.ajax({
>  url: "/rgeo/",
>  dataType: "xml",
>  data: {
>  x: document.rgeo.x.value,
>  y: document.rgeo.y.value
>  },
>  success: function(data){
>  console.log(data);
>  $("textarea#response")[0].value = data;
>  }
>  });
>
> Thanks,
>-Steve


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring : How to keep plugin state?

2007-02-18 Thread Blair Mitchelmore
If you only want the last time the function was called:

jQuery.debug; // Stores last called date for jQuery.fn.debug
jQuery.fn.debug = function() {
jQuery.debug = new Date();
return this.each(function() {
   alert(this);
});
};

Other things like recording all previous calls and possibly including 
the number of elements or other useful information would be similarly 
accomplished but would use an array rather than a simple Date Object. 
And obviously the variable name I chose simply for style, it can be any 
variable you want it to be.

-blair

howard chen wrote:
> e.g.
>
> jQuery.fn.debug = function() {
> // i want to save the current time into a global variable?
>   return this.each(function(){
> alert(this);
>   });
> };
>
> I want save the time of the last plugin being executed for later use,
> any recommened method?
>
> thanks.
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] get nth item with jquery still usable - not get()

2007-02-14 Thread Blair Mitchelmore
Use eq(n). It does the same thing as get(n) but doesn't break the jQuery 
chain.

-blair

Matthew Delmarter wrote:
> Hi all,
>
> I am trying to get to the nth item in an array of results - while still
> being able to use jQuery on the object.
>
> I am quite familiar with using get(n) - which returns the DOM object. I want
> the equivalent for jQuery.
>
> Any tips much appreciated - getting lost in the docs here and I am sure
> there must be an easy way to do this?
>
> Does this all make sense?
>
> ___
> Matthew Delmarter
>
>
>
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] .load() on IE7 returns Cached results

2007-02-06 Thread Blair Mitchelmore
Try adding a random number or a timestamp to the url you request. IE 
loves to retrieve caches when you don't want it to.

-blaie


Michael E. Carluen wrote:
> Hello folks. I’ve been using load() to return some data. Works fine on 
> Firefox. However, IE7 seems to load data that’s been cached. The page 
> being loaded already includes all the flavors of no-cache meta tags. 
> Any suggestions? Thanks in advance.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Embedding jQuery in a Greasemonkey script

2007-01-31 Thread Blair Mitchelmore
I would guess that the best way would be to pack the jQuery source into 
the greasemonkey xpi and access it using the chrome URI interface 
somehow. I have very limited experience with firefox extensions but that 
would seem to be the best way in terms of bandwidth and in terms of 
usability (you wouldn't need to add a dynamic script load to every page 
load just to use jQuery in your user scripts)

-blair

Nicolas Hoizey wrote:
> Hello Joan,
>
>> Yes, I remember the threads talking about this, and I was curious  
>> about it. After some days I figured out how to load jQuery and  
>> simply make it work giving jQuery power to my userscripts in  
>> Greasemonkey.
>> Here is the url, check it out.
>> http://joanpiedra.com/jquery/greasemonkey/
>
> Your solution is better than the first I have been trying, but it  
> still gets the jQuery source directly from jquery.com, which is not  
> really nice. If the greasemonkey script gains a lot of users, and is  
> executed on a lot of pages, the load on jquery.com may become  
> noticeable.
>
> John, am I right, or do you authorize such bandwidth "abuse"?
>
>
> -Nicolas
>
>> On 1/30/07, Nicolas Hoizey <[EMAIL PROTECTED]> wrote: Hello,
>>
>> I want to improve some of my Greasemonkey scripts by using jQuery
>> instead of "traditionnal" JS.
>>
>> I tried to load the library during execution[1] and it didn't work as
>> intended. It was loaded from jquery.com, so I didn't want it anyway.
>> I can't load it from my host either.
>>
>> I found a way to integrate the compact version of jQuery directly in
>> my script[2], but it is an old release, and I can't find how to do
>> the same with current 1.1.1 release. The author (SunSean) just said
>> he had "slightly edited [jQuery] for greasemonkey" without explaining
>> what he did change, and Firebug tells me "Component is not available".
>>
>> Any idea on how to do it?
>>
>> Here is my current version with the old jQuery embedded: > userscripts.org/scripts/show/2243>
>>
>>
>> Thanks a lot!
>>
>>
>> [1] > jQueryMonkey.aspx>
>> [2] < http://jquery.com/pipermail/discuss_jquery.com/2006-June/
>> 006355.html>
>>
>> -Nicolas
>>
>> --
>> Nicolas "Brush" HOIZEY
>> Clever Age   : http://www.clever-age.com/
>> Gastero Prod : http://www.gasteroprod.com/
>> Photos : http://www.flickr.com/gp/[EMAIL PROTECTED]/M1c002
>> phpHeaven: http://www.phpheaven.net/
>>
>>
>> -- 
>> Joan Piedra || Frontend webdeveloper
>> http://joanpiedra.com/
>
> -Nicolas

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Custom borders

2007-01-30 Thread Blair Mitchelmore
Unless someone has custom code that extends the Array objects prototype 
property. Then those functions will become a part of the iteration.

-blair

Ⓙⓐⓚⓔ wrote:
> it's safe when you know what's in the array, and you are sure it's not
> an array-like object
>
> On 1/30/07, Michael Geary <[EMAIL PROTECTED]> wrote:
>>> $.fn.border = function(prefix){
>>>var classNames = [ 'north', 'east', 'south', 'west', 'northeast',
>> 'southeast', 'southwest', 'northwest'];
>>>return this.each(function(){
>>>   for (var index in classNames){
>>>  className = (prefix || '')+ classNames[index];
>>>  $(this).wrap("")
>>>   }
>>>})
>>> };
>> Danger warning! Don't use for..in on an array! Use a C-style loop instead.
>> 


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery doesn't get along with old Prototype

2007-01-26 Thread Blair Mitchelmore
This topic has been completely exhaustingly beaten to death by every 
single JavaScript conversation ever. The general consensus is that until 
customizable iterators in JavaScript 2.0 become widespread, avoid 
Object.prototype like the plague. All the other alternatives are too 
heavy to be worth it, especially in the time-sensitive world of 
JavaScript. I believe is that we, as a community, cannot and should not 
be expected to handle broken code. And until the language can handle 
Object.prototype intelligently, any use of it is broken.

-blair

Arrix wrote:
> I'm writing a bookmarklet application using jQuery and it fails with 
> any page that uses Prototype 1.3.1.
> I found that it's Object.prototype.extend that breaks jQuery.
> jQuery's extend method gets overwritten after the first call to 
> jQuery.extend({/**/}).
> It's rare to use jQuery and Prototype 1.3.1 together, but it's 
> absolutely possible that jQuery will coexist with some poorly written 
> code.
>
> Anyway to make jQuery more robust?
> Can we check hasOwnProperty() before copying properties inside 
> jQuery.extend?
> Or can we have a black-list to filter out properties that conflict 
> with jQuery?
>
> -- 
> Arrix


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] $(ele).css('height') and $.css(ele, 'height') are different?

2007-01-24 Thread Blair Mitchelmore
Not sure on this but...

I believe that's because .css() - in the case of IE - returns the 
element.currentStyle value which is exactly the same as what the 
stylesheet says. In other browsers, 
document.defaultView.getComputedStyle is used which computes the actual 
pixel value of what it returns based on what the stylesheet says.

-blair

Arrix wrote:
> html: Hello
>
> JavaScript: $(function() {
> alert($('#div1').css('height') + ' ' + $('#div1').height() + ' ' + 
> $.css($('#div1')[0], 'height'));
> });
>
> The result is as follows
>  
> Firefox:  19px 19 19
> Opera:   19px 19 19
> IE: auto 19 19
>
> Why is $(ele).css('height') in IE different? Is this a bug or by design?
> -- 
> Arrix
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1, Site, Docs, Surprise

2007-01-14 Thread Blair Mitchelmore
jQuery makes every aspect of JavaScript programming not only easier but 
fun as well! Thanks all for the tremendous contribution of time and 
skill to create this inimitable framework. Also, I submitted the story 
to digg, so let's get it on the front page.

http://digg.com/programming/jQuery_1_1_Released

-blair

John Resig wrote:
> Hi Everyone -
>
> jQuery 1.1 has just been release, along with an overhaul of the site
> design, and the documentation; all tied together with a brand new
> surprise!
>
> The full details can be found here:
> http://jquery.com/blog/2007/01/14/jquery-birthday-11-new-site-new-docs/
>
> Enjoy - and be sure to thank the whole jQuery team that made this come 
> together.
>
> --John
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] .not($(obj))

2006-12-31 Thread Blair Mitchelmore
I'm not sure but I think that .not(obj) is currently implemented to 
exclude singular DOM elements, meaning arrays of elements and jQuery 
element sets wouldn't do anything. That could maybe be an API change for 
jQuery 1.1?

-blair

Oliver Boermans wrote:
> Hi all
>
> It would be useful to be able subtract a list of elements generated
> from a compound selector - from the results of another.
>
> I thought I might be able to do this using what is documented as
> $(obj) within a .not() but isn't working for me. Perhaps there is a
> good reason it's failing?
>
> Here's a silly simplistic example, where I want to select the
> paragraphs that are not bold and don't have a class of 'odd':
>
> var evenweak = $("p").not(".odd").not("[b]");
>
> // This works but I want the opposite
> $( evenweak ).css("color","red");
>
> // These don't work (the not is ignored)
> $("p").not( $( evenweak ) ).css("color","red");
> $("p").not( $( evenweak ).get() ).css("color","red");
>
> With this HTML:
> one
> two
> three
> four
>
> Before you suggest one of the many easier ways to do this - I know
> this example is less than sensible with this example HTML. My real
> problem is more complex - just want to kill off this direction before
> I try another.
>
> Any insights?
> Cheers
> Ollie
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] DOM traversing then applying a non JQuery function

2006-12-18 Thread Blair Mitchelmore
That would require a change in the moveCodeToImg function. A naive 
example would be:

function moveCodeToImg(element) {
// Catch $().each() calls of the function
if (typeof element == 'number') element = this;
// do stuff to element
}

-blair

Abel Tamayo wrote:
> Wow, thanks everyone for the superfast response.
> Ok, as Brandon suggested, the right way was using
>
> $('.oneClass').each(function() { moveCodeToImg(this); });
>
> wich I had already tried but didn't realize i had to change some 
> things in the function used since i was recycling it and the 
> parameters and variables returned where all new (also, don't see why 
> you have to use the reserved word function() when moveCodeToImg is 
> already a function, the kind of paramenter that each(function) 
> expects, but anyway). Now I'm intrigued about Mike's answer:
>
> $('.oneClass').each(moveCodeToImg);
>
> since I don't remember reading about sintax like that in the 
> documentation of jQuery. How come you can call a function without 
> parentheses and the parameters it expects and how do you rearrange a 
> function to receive an "index" or where can i read more about this 
> nomenclature?
>
> Thanks again. Great community.
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] highlightFade's source code missing...

2006-12-15 Thread Blair Mitchelmore
Damn broken symlinks...

-blair

aedmonds wrote:
> Hey everybody,
>
> It seems that the maintainer at http://jquery.offput.ca/highlightFade/ has
> some problems with the site. I can't access any of the code for the
> highlightFade plugin. It's not available in the jQuery SVN either.
>
> Could someone please post the uncompressed code for me?
>
> Thanks a bunch,
>
> -A

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1 by the end of Nov

2006-11-15 Thread Blair Mitchelmore
What exactly do you mean when you say the handler doesn't know which 
argument is passed via trigger versus bind? Can you give me an example 
of this so I can better understand the problem?

-blair

Jörn Zaefferer wrote:
>> The way I coded the trigger and handle functions in my system it worked 
>> like this (or at least it should. This is untested but theoretically 
>> sound and the way I intended for it to work).
>>
>> $().click(fn1,arg1,arg2);
>> $().click(fn2,arg3,arg4);
>> // someone clicks there
>> // fn1 runs with arguments [event,arg1,arg2]
>> // fn2 runs with args [event,arg3,arg4]
>> $().trigger('click');
>> // fn1 runs with args [event,arg1,arg2]
>> // fn2 runs with args [event,arg3,arg4]
>> $().trigger('click',arg5,arg6);
>> // fn1 runs with args [event,arg1,arg2,arg5,arg6]
>> // fn2 runs with args [event,arg3,arg4,arg5,arg6]
>>
>> To me this is the least surprising result, would you agree?
>
> No. The general idea of passing arguments via trigger and bind is to 
> modularize code. Think of a big system where you can't rely on closures. Or 
> where you want to pass arguments to a plugin via trigger. The event handler 
> maybe implemented by the user, while the argument to bind are coming from 
> plugin code and may change.
>
> With your implementation, the handler had no idea how to identify which 
> argument was passed via bind and which via trigger, but that is important.
>
> --
> Jörn Zaefferer
>
> http://bassistance.de

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1 by the end of Nov

2006-11-15 Thread Blair Mitchelmore
And to correct myself, my system didn't do that and it will not do that. 
In fact the arguments sent into the trigger call have precedence and in 
retrospect that makes some semblance of sense to me. So my below trigger 
example actually does this:

$().trigger('click',arg5,arg6);
// fn1 runs with args [event,arg5,arg6,arg1,arg2]
// fn2 runs with args [event,arg5,arg6,arg3,arg4]

NB. My system doesn't actually do that... I thought I had rewritten that 
section but I hadn't. I will later today but for now I'm off to lectures...

-blair


Blair Mitchelmore wrote:
> Well hello right back Jörn!
>
> Jörn Zaefferer wrote:
>> Hi Blair!
>>
>>> Since this has come up again, I thought I'd mention - despite my distate 
>>> for plugin pimping - my own event++ system ( 
>>> http://jquery.offput.ca/event++ ) I wrote which could be used as the new 
>>> system. It can handle additional arguments sent to the event simply by 
>>> adding arguments to the event bind function call. It can also handle 
>>> limiting the number of event occurrence to run but as the first argument 
>>> to bind, click, et. al. It also handles scope arbitration using the 
>>> final argument provided to the event bind function call. There's a 
>>> little more detail available at the link above but regardless it seems 
>>> like it's a system people would appreciate and it barely adds any code 
>>> complexity to the current system.
>> Thanks, I'll keep that in mind.
>>
>> It looks like there were some changes to the event system since you wrote 
>> your system, we have to be careful with those.
>>
>> The additonal scope looks interesting, but rather useless. Do you have an 
>> example where that is really helping instead of only brain-twisting?
>>
>> Please don't get me wrong, but that scope seems to be way too geeky.
>>
>> By the way: We could simply allow Arrays and Objects for additonal argument: 
>> If it is a number, it's the amount of events to handle, otherwise its a 
>> pass-through argument.
>>
>> Remains the question on how to actualy pass the additonal stuff, because:
>> var x = $(...).bind("click", handler, args);
>> x.trigger("click", moreArgs);
>>
>> How to write the handler?
>>
>> var handler = function(event, bind, trigger) {
>>   // do something with bind and trigger, we have to list bind also when 
>> using only trigger
>> };
>>
>> var handler = function(event) {
>>   // do something with event.bind and event.trigger, they contain the data 
>> passed to bind and trigger, if any
>> };
>>
>> I'd prefer the second approach. Documenting callback parameters is difficult 
>> anyway.
>>
>> --
>> Jörn Zaefferer
>>
>> http://bassistance.de
> Yeah scope modification is really only useful when you're writing a 
> large object oriented system and you are writing event functions within 
> the object that is using it and want to write the code using 'this' to 
> make it explicit that you are referencing the object. I agree it's very 
> rare for most web development but including in the system wouldn't be 
> much of a bother and it would be a boon for OO obsessed coders out there.
>
> The way I coded the trigger and handle functions in my system it worked 
> like this (or at least it should. This is untested but theoretically 
> sound and the way I intended for it to work).
>
> $().click(fn1,arg1,arg2);
> $().click(fn2,arg3,arg4);
> // someone clicks there
> // fn1 runs with arguments [event,arg1,arg2]
> // fn2 runs with args [event,arg3,arg4]
> $().trigger('click');
> // fn1 runs with args [event,arg1,arg2]
> // fn2 runs with args [event,arg3,arg4]
> $().trigger('click',arg5,arg6);
> // fn1 runs with args [event,arg1,arg2,arg5,arg6]
> // fn2 runs with args [event,arg3,arg4,arg5,arg6]
>
> To me this is the least surprising result, would you agree?
>
> -blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1 by the end of Nov

2006-11-15 Thread Blair Mitchelmore
Well hello right back Jörn!

Jörn Zaefferer wrote:
> Hi Blair!
>
>> Since this has come up again, I thought I'd mention - despite my distate 
>> for plugin pimping - my own event++ system ( 
>> http://jquery.offput.ca/event++ ) I wrote which could be used as the new 
>> system. It can handle additional arguments sent to the event simply by 
>> adding arguments to the event bind function call. It can also handle 
>> limiting the number of event occurrence to run but as the first argument 
>> to bind, click, et. al. It also handles scope arbitration using the 
>> final argument provided to the event bind function call. There's a 
>> little more detail available at the link above but regardless it seems 
>> like it's a system people would appreciate and it barely adds any code 
>> complexity to the current system.
>
> Thanks, I'll keep that in mind.
>
> It looks like there were some changes to the event system since you wrote 
> your system, we have to be careful with those.
>
> The additonal scope looks interesting, but rather useless. Do you have an 
> example where that is really helping instead of only brain-twisting?
>
> Please don't get me wrong, but that scope seems to be way too geeky.
>
> By the way: We could simply allow Arrays and Objects for additonal argument: 
> If it is a number, it's the amount of events to handle, otherwise its a 
> pass-through argument.
>
> Remains the question on how to actualy pass the additonal stuff, because:
> var x = $(...).bind("click", handler, args);
> x.trigger("click", moreArgs);
>
> How to write the handler?
>
> var handler = function(event, bind, trigger) {
>   // do something with bind and trigger, we have to list bind also when using 
> only trigger
> };
>
> var handler = function(event) {
>   // do something with event.bind and event.trigger, they contain the data 
> passed to bind and trigger, if any
> };
>
> I'd prefer the second approach. Documenting callback parameters is difficult 
> anyway.
>
> --
> Jörn Zaefferer
>
> http://bassistance.de
Yeah scope modification is really only useful when you're writing a 
large object oriented system and you are writing event functions within 
the object that is using it and want to write the code using 'this' to 
make it explicit that you are referencing the object. I agree it's very 
rare for most web development but including in the system wouldn't be 
much of a bother and it would be a boon for OO obsessed coders out there.

The way I coded the trigger and handle functions in my system it worked 
like this (or at least it should. This is untested but theoretically 
sound and the way I intended for it to work).

$().click(fn1,arg1,arg2);
$().click(fn2,arg3,arg4);
// someone clicks there
// fn1 runs with arguments [event,arg1,arg2]
// fn2 runs with args [event,arg3,arg4]
$().trigger('click');
// fn1 runs with args [event,arg1,arg2]
// fn2 runs with args [event,arg3,arg4]
$().trigger('click',arg5,arg6);
// fn1 runs with args [event,arg1,arg2,arg5,arg6]
// fn2 runs with args [event,arg3,arg4,arg5,arg6]

To me this is the least surprising result, would you agree?

-blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1 by the end of Nov

2006-11-15 Thread Blair Mitchelmore
I actually probably should have explicitly showed the syntax for my 
event number handling technique. I used an optional first argument which 
defined that. If the first argument isn't a number then it doesn't need 
to worry about that and just goes through with a regular event bind.

$().click(3,fn1); // fn1 called on the first three clicks
$().click(fn2); // fn2 called on every click

Using this techniques allows you to have arbitrary additional arguments 
without having to worry about it accidentally triggering a 
repeat-limited event.

-blair

Blair Mitchelmore wrote:
> Since this has come up again, I thought I'd mention - despite my distate 
> for plugin pimping - my own event++ system ( 
> http://jquery.offput.ca/event++ ) I wrote which could be used as the new 
> system. It can handle additional arguments sent to the event simply by 
> adding arguments to the event bind function call. It can also handle 
> limiting the number of event occurrence to run but as the first argument 
> to bind, click, et. al. It also handles scope arbitration using the 
> final argument provided to the event bind function call. There's a 
> little more detail available at the link above but regardless it seems 
> like it's a system people would appreciate and it barely adds any code 
> complexity to the current system.
>
> -blair
>
> Kolman Nándor wrote:
>> What about using an object instead of an array?
>>
>> bind("click", handler, 1, {x: 1});
>> bind("click", handler, {x: 1});
>> ...
>>
>> Nandi
>>
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of "Jörn 
>> Zaefferer"
>> Sent: Wednesday, November 15, 2006 1:22 PM
>> To: jQuery Discussion.
>> Subject: Re: [jQuery] jQuery 1.1 by the end of Nov
>>
>>>> Dunno how to handle the current oneEvents like oneclick: Extending bind
>>> with an additonal parameter for the number of events to handle before the
>>> handler should be removed would be one way, another to add a bindAmount() or
>>> binds().
>>>
>>> Allowing a number of events to be defined before handler is removed 
>>> would be very cool!
>> I'm just not sure how this should be integrated into the existing API: Add a 
>> new method, add parameter to bind? How to combine this with additional 
>> parameters that are to be passed to the handler?
>>
>> Consider these:
>> bind("click", handler) // normal
>> bind("click", handler, 1) // only once
>> bind("click", handler, 5) // five times
>> bind("click", handler, [true, 5, "stuff"]) // pass additional argument to 
>> handler
>> bind("click", handler, true, 5, "stuff") // pass additonal arguments to 
>> handler
>> bind("click", handler, 1, [true, 5, "stuff"]) // ...
>> bind("click", handler, 1, true, 5, "stuff") // ...
>>
>> I think the best approach would be to pass additional arguments always as an 
>> Array. That allows the implementation to check for the type of the third and 
>> fourth argument: If it's a number, use it as amount, if it is an array, use 
>> it as additonal arguments.
>>
>> --
>> Jörn Zaefferer
>>
>> http://bassistance.de

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery 1.1 by the end of Nov

2006-11-15 Thread Blair Mitchelmore
Since this has come up again, I thought I'd mention - despite my distate 
for plugin pimping - my own event++ system ( 
http://jquery.offput.ca/event++ ) I wrote which could be used as the new 
system. It can handle additional arguments sent to the event simply by 
adding arguments to the event bind function call. It can also handle 
limiting the number of event occurrence to run but as the first argument 
to bind, click, et. al. It also handles scope arbitration using the 
final argument provided to the event bind function call. There's a 
little more detail available at the link above but regardless it seems 
like it's a system people would appreciate and it barely adds any code 
complexity to the current system.

-blair

Kolman Nándor wrote:
> What about using an object instead of an array?
>
> bind("click", handler, 1, {x: 1});
> bind("click", handler, {x: 1});
> ...
>
> Nandi
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of "Jörn 
> Zaefferer"
> Sent: Wednesday, November 15, 2006 1:22 PM
> To: jQuery Discussion.
> Subject: Re: [jQuery] jQuery 1.1 by the end of Nov
>
>>> Dunno how to handle the current oneEvents like oneclick: Extending bind
>> with an additonal parameter for the number of events to handle before the
>> handler should be removed would be one way, another to add a bindAmount() or
>> binds().
>>
>> Allowing a number of events to be defined before handler is removed 
>> would be very cool!
>
> I'm just not sure how this should be integrated into the existing API: Add a 
> new method, add parameter to bind? How to combine this with additional 
> parameters that are to be passed to the handler?
>
> Consider these:
> bind("click", handler) // normal
> bind("click", handler, 1) // only once
> bind("click", handler, 5) // five times
> bind("click", handler, [true, 5, "stuff"]) // pass additional argument to 
> handler
> bind("click", handler, true, 5, "stuff") // pass additonal arguments to 
> handler
> bind("click", handler, 1, [true, 5, "stuff"]) // ...
> bind("click", handler, 1, true, 5, "stuff") // ...
>
> I think the best approach would be to pass additional arguments always as an 
> Array. That allows the implementation to check for the type of the third and 
> fourth argument: If it's a number, use it as amount, if it is an array, use 
> it as additonal arguments.
>
> --
> Jörn Zaefferer
>
> http://bassistance.de

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Refresh an image with dynamic src URL?

2006-11-13 Thread Blair Mitchelmore
If you want to defeat the cache you could try appending the current time 
as a query string:

img.src = fileName + "?" + (new Date()).getTime();

-blair

Matt Grimm wrote:
> What would be an ideal way to refresh an image whose src attribute is a
> script that dynamically generates the image? Would it be best to store
> the value of the src attribute in a variable, remove the img element
> from the DOM, and append a new image element with the same URL? In my
> quick tests, it seemed like the browser was just using the same image
> from the cache and I'm not sure how to get around that.
> 
> Thanks for anything!
> 
> m.
> 
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] new plugin: AnimateClass/animateStyle

2006-11-09 Thread Blair Mitchelmore
Beautiful plug-in Paul! I haven't looked at the code yet, but I'm sure 
it's spectacular. You've officially put my highlightFade plug-in out of 
business. ;)

--
blair

Paul Bakaus wrote:
> Hi jQuerians,
>
> I managed to get the core functionality of my new plugin done today. 
> Still, cross-browser support is nowhere perfect, only IE and Firefox 
> seem to perform quite well.
> For all who don't know what I'm talking about:
>
> This is my new animateClass/animateStyle plugin!
> Using it you can:
>
> 1.) Animate to a certain css class (as described in a stylesheet)
> 2.) Animate from a class to a class
> 3.) Animate using pure css as in the style tag ("border:1x solid #000; 
> margin: 5px")
>
> Check out this page for more info, examples and download:  
> http://paul.jquery.com/plugins/animateClass/ . You can also check the 
> SVN plugin directory for a more current one. What has been improved 
> since I wrote the draft:
>
> 1) Rewritten parts of the code for faster execution
> 2) Added color transistions for all(?) browsers (You can now input 
> rgb(0,0,0), #0, #000, black in both IE and Firefox)
> 3) Fixed many IE issues
> 4) Wrote better examples, bette descriptions and better inline comments
> 5) Finished animateStyle
> 6) Added basic queueing (not really, if a new animation is passed in 
> without the previous one ended, it just stops...maybe someone can 
> explain me how to use jQuery's interal queue.)
>
> Feel free to give me input and comments! Have fun!
>
> -- 
> Paul Bakaus
> Web Developer
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] New Plugin: ODBCDate functions

2006-11-09 Thread Blair Mitchelmore
The problem is the plugin uses d.getYear() which returns the current 
year minus 1900. To get the actual year that line should be changed to 
d.getFullYear(). Quick fix until the plugin gets officially updated.

-blair

Louise Dade wrote:
> Hi,
>
> [I'm usually a lurker, this is my first response - been using JQuery
> for a couple of months now and loving it!]
>
> On 09/11/06, Christopher Jordan <[EMAIL PROTECTED]> wrote:
>>  Today, I was in need of a function to parse strings in the ODBCDateTime
>> format. I needed to convert a string in the ODBCDateTime format to a valid
>> JavaScript Date object, and vise versa. So instead of just writing the
>> functions for me, I decided to make them a plugin for jQuery.
>
> I cheked out your plugin, and the conversion from ODBCDateTime to a JS
> string worked fine, but the 'JS to ODBCDatetime' function threw up a
> problem when I tried it/
>
> My current system time came up as:  106-11-9 10:50:59
>
> That puts me in the Iron Age!  (My system clock appears to be correct 
> elsewhere.
>
> Otherwise, great - and useful - addition.
>
> Regards,
> Louise Dade
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Enhanced jQuery Events Module

2006-10-27 Thread Blair Mitchelmore
Ah crud, it's already up. Oh well, it doesn't break any older syntax and 
this is an enhancement module anyways so what the hell.

--
blair

Jörn Zaefferer wrote:
>> If you're asking about Jörn's oneclick(), click(fn,num) syntax I just 
>> added it into a non-public version and it works fine. I modified it 
>> slightly to be .click(num,fn,...) and .bind(type,num,fn,...) to be 
>> easier to detect given the arbitrary additional arguments but the 
>> functionality is the same. I'll add that to the public vesion once I 
>> rewrite the demo page to include some demos of that.
>
> Actually, that API change is delayed at least till 1.1. Therefore you should 
> just ignore it and stick to your old code.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Enhanced jQuery Events Module

2006-10-27 Thread Blair Mitchelmore
Well the changes were actually pretty simple. The first thing I did was 
change all of the various .bind() and .click() et. al. functions to pass 
all their arguments along. So

jQuery.fn[o] = function(f){
return f ? this.bind(o, f) : this.trigger(o);
};

Becomes

jQuery.fn[o] = function(f){
return f != undefined ? this.bind.apply(this, 
[o].concat(jQuery.map(arguments,"a"))) : this.trigger(o);
};

and similarly for the other event related functions.

Then inside jQuery.event.add, rather than doing:

handlers[handler.guid] = handler;

I turned that into an array of the handler followed by an array of the 
arguments that came with the event. Slicing the first three off of the 
arguments array to remove the actual required arguments to jQuery.event.add:

handlers[handler.guid] = [handler,jQuery.map(arguments,"a").slice(3)];

Then I had to modify jQuery.event.handle to both call the new location 
of the handler and also check for scope modification on the events it calls.

var c = this.events[event.type];

var args = [].slice.call( arguments, 1 );
args.unshift( event );

for ( var j in c ) {
if ( c[j].apply( this, args ) === false ) {
event.preventDefault();
event.stopPropagation();
returnValue = false;
}
}

Becomes

var c = this.events[event.type];
   
for ( var j in c ) {
var f = c[j][0];
var a = c[j][1];
var args = jQuery.map(arguments,"a").slice(1).concat(a);
args.unshift(event);
var scope = args[args.length-1] === true ? args[args.length-2] : this;
if (scope != this) args = args.slice(0,-2);
if ( c[j][0].apply( scope, args ) === false ) {
event.preventDefault();
event.stopPropagation();
returnValue = false;
}
}

I also added a fix to the global event trigger so that when multiple 
events of the same type are added to the same element, each event is 
only called once. In the current version of jQuery each event is called 
the number of unique events of the same type there are on any given 
element (i.e. two click events, each gets called twice):

in jQuery.event.trigger:

var g = this.global[type];

becomes

var g = jQuery.map(this.global[type],"a");

--
blair

Jörn Zaefferer wrote:
> Hi Blair!
>
>> I was saddened and chagrined to discover that the event system didn't 
>> have additional arbitrary arguments as I thought it did and so I wrote 
>> them in. I modified the event system very slightly to allow for both 
>> additional arguments and scope modification (two features of the Yahoo 
>> Event Utility I always thought were very useful when I developed with 
>> it). I have my typical level of documentation (read: as little as I can 
>> manage) at the demo page I set up ( http://jquery.offput.ca/event++/ ). 
>> It was a pretty simple rewrite and hopefully it will be of use to someone.
>
> Could you explain your actual changes? That would help a lot.
>
> --
> Jörn Zaefferer
>
> http://bassistance.de


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Enhanced jQuery Events Module

2006-10-27 Thread Blair Mitchelmore
If you're asking about Jörn's oneclick(), click(fn,num) syntax I just 
added it into a non-public version and it works fine. I modified it 
slightly to be .click(num,fn,...) and .bind(type,num,fn,...) to be 
easier to detect given the arbitrary additional arguments but the 
functionality is the same. I'll add that to the public vesion once I 
rewrite the demo page to include some demos of that.

--
blair

[EMAIL PROTECTED] wrote:
> What i wonder is, can this code be integrated with the improved
> events stystem which was written just a while ago?


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Enhanced jQuery Events Module

2006-10-27 Thread Blair Mitchelmore
This is actually a bizarre construction. What it's doing is setting a 
click event on every element in the jQuery object '$l' but then it's 
setting the scope of the event handler as the actual jQuery object. This 
results in running jQuery.fn.hide on all elements of the jQuery set when 
either of them is clicked. Not really practical, just some fun code.

--
blair

David Duymelinck wrote:
> Blair Mitchelmore schreef:
>> I was saddened and chagrined to discover that the event system didn't 
>> have additional arbitrary arguments as I thought it did and so I wrote 
>> them in. I modified the event system very slightly to allow for both 
>> additional arguments and scope modification (two features of the Yahoo 
>> Event Utility I always thought were very useful when I developed with 
>> it). I have my typical level of documentation (read: as little as I can 
>> manage) at the demo page I set up ( http://jquery.offput.ca/event++/ ). 
>> It was a pretty simple rewrite and hopefully it will be of use to someone.
>>   
> I liked what i saw but can you explain why you need to set the variable 
> twice?
>
> $l.click(jQuery.fn.hide,$l,true);
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Enhanced jQuery Events Module

2006-10-26 Thread Blair Mitchelmore
I was saddened and chagrined to discover that the event system didn't 
have additional arbitrary arguments as I thought it did and so I wrote 
them in. I modified the event system very slightly to allow for both 
additional arguments and scope modification (two features of the Yahoo 
Event Utility I always thought were very useful when I developed with 
it). I have my typical level of documentation (read: as little as I can 
manage) at the demo page I set up ( http://jquery.offput.ca/event++/ ). 
It was a pretty simple rewrite and hopefully it will be of use to someone.

--
blair



___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] jQuery Global Events Slightly Askew

2006-10-26 Thread Blair Mitchelmore
So I noticed something recently when I found out about, and played 
around with, those zany global event triggers. If you add two different 
events of the same type to the same element, when you call the global 
event trigger for that type, each event will get called twice.

Example:
func1 = function() { window.alert("1"); };
func2 = function() { window.alert("2"); };
$('#box').click(func1).click(func2);
jQuery.event.trigger('click');

Problem:
You should see "1" and "2" both alerted twice.

Luckily there's a quick and painless fix to this. Inside the 
event.trigger function if the line

var g = this.global[type];

is changed to

var g = jQuery.map(this.global[type],"a");

jQuery.map will make sure there are no duplicate elements in the list 
before it is iterated through to call the events. Pretty esoteric bug 
but a bug nonetheless.

--
blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery and OOP

2006-10-24 Thread Blair Mitchelmore
A technique you might find slightly less ugly is passing 'this' as an 
argument when you bind the event. If I recall correctly, jQuery has the 
ability to pass an arbitrary number of additional arguments as an 
additional argument array to the event bind function.

function Counter() {
  $('#btnCounter').click(this.count,[this]);
  this.button = $('#btnCounter');
  this.nr = 0;
}

In the count method I set the incremented value of the counter to the text of 
the button.
Counter.prototype = {
  count: function(e,self) {
self.button.attr('value', self.nr++);
  }
}

--
blair

Kolman Nándor wrote:
> Hi,
>
> I am new to jQuery, and I have a question concerning object oriented 
> programming. I have created a sample scenario.
> In the HTML code I add a button:
> 
>
> In js, I create a class called Counter. In the constructor I add an event 
> handler to the click event of the button. The function I specify as the 
> handler is a method of the Counter class. I also store the button and the nr 
> (the current value of the counter) as an object property.
>
> function Counter() {
>   $('#btnCounter').click(this.count);
>   this.button = $('#btnCounter');
>   this.nr = 0;
> }
>
> In the count method I set the incremented value of the counter to the text of 
> the button.
> Counter.prototype = {
>   count: function() {
> this.button.attr('value', this.nr++);
>   }
> }
>
> And I need to create the object in the load event:
> $(window).load(function() {
>   new Counter();
> });
>
> If I try to run the code I get: 'this.button has no properties'. I know that 
> the 'this' in the count method will be the target of the event (the button). 
> But that is not what I need, it is the reference of the Counter object. 
>
> If I rewrite the constructor I can make it work:
> function Counter() {
>   var oThis = this;
>   $('#btnCounter').click(
> function() {
>   oThis.count();
> }
>   );
>   this.button = $('#btnCounter');
>   this.nr = 0;
> }
>
> But this is quite ugly :(. Is there a nicer way to achieve this?
>
> Thx
>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Expressions: Search for children within context

2006-10-22 Thread Blair Mitchelmore
I recall that $(" > dt",context) used to work, though I'm not sure if 
that was "fixed"

-blair

Jörn Zaefferer wrote:
> Hi jQueryians,
>
> how do I search for a children within a context?
>
> In other words, how to translate this:
> $(context).children("dt")...
> into something like this:
> $("/dt", context)
>
> The latter one does unfortuanetely not work...
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery Kinda Plugin: every

2006-10-20 Thread Blair Mitchelmore

Michael Geary wrote:
>
> You can simplify that code quite a bit. every() and doin() are nearly
> identical, so they can both call a common implementation. Ditto for the two
> inner loops in stop().
Great suggestions Mike. I noticed that they were very similar but I was 
too lazy to combine them but now you have challenged me, and I have 
realized that just as with the immortals, there can be only one.

The code you modified was the original rewrite which didn't include the 
additional passed arguments feature so my version of the rewrite is 
slightly different but inspired by yours.
>
> Since I was moving the whole thing inside a function to get a local scope
> for the every() helper, that gave me a chance to rename jQuery as $. This is
> a matter of taste, of course, but I like being able to write plugin code the
> same way as ordinary jQuery code, using $.
It's definitely a matter of taste, as I tend to prefer to use the jQuery 
in plug-in development seeing as the ultimate result is intended for 
much generic uses than my page specfici code so it brings me into a 
different more methodical mindset.

> One last thing - in the inner function inside every(), I changed the uses of
> "this" to "self", because there's a "var self = this;" at the top of the
> function. I think it helps readability to only use "self" after a "var self
> = this;" instead of mixing "this" and "self".
That's probably because self was an afterthought. I always forget about 
the intransitive nature of 'this' so my this closures are usually not 
written until I realize I need them.
>
> The code is untested, but should work the same as the original unless I
> goofed. :-)
>
> -Mike
Well Actually it wouldn't have worked because I made a goof in my code! 
Initially by setting interval to the result of jQuery.speed rather than 
the duration property of the result. Noticed when testing the new code.

Here's the updated code (it'll probably be wrapped by my mail client):
jQuery.fn.extend({
every: function(interval,id,fn) {
return 
jQuery.timer.add.apply(this,[false].concat(jQuery.map(arguments,"a")));
},
doin: function(interval,id,fn) {
return 
jQuery.timer.add.apply(this,[true].concat(jQuery.map(arguments,"a")));
},
stop: function(id) {
return jQuery.timer.remove.apply(this,[id]);
}
});

jQuery.extend({
timer: {
add: function(oneOff,interval,id,fn) {
var args = jQuery.map(arguments,"a"), slice = 4;
return this.each(function() {
var self = this, counter = 0;
interval = jQuery.speed(interval)['duration'];
if (fn == undefined || id.constructor == Function) {
fn = id;
id = interval;
slice = 3;
}
if (!self.timers) self.timers = {};
if (!self.timers[id]) self.timers[id] = [];
self.timers[id].push(window.setInterval(function() {
if (oneOff && counter++ >= 1) return 
jQuery(self).stop(id);
fn.apply(self,args.slice(slice));
},interval));
});
},
remove: function(id) {
return this.each(function() {
if (!this.timers) return;
jQuery.each(id == undefined ? this.timers : 
[this.timers[id]], function(i) {
jQuery.each(this,function(j) {
window.clearInterval(this);
});
});
});
}
}
});

-blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery Kinda Plugin: every

2006-10-20 Thread Blair Mitchelmore
Once again, I have an 11th hour code change. I had forgotten about 
Jörn's suggestion of allowing additional passed arguments. I'm not 
entirely sure what kind of implementation or usage was expected but I 
added my own version. Any argument provided to the .doin()/.every() 
function beyond the action function will be passed to the action 
function as an argument. Hopefully that's what he was talking about. 
Code Below:

jQuery.fn.extend({
every: function(interval,id,fn) {
var args = jQuery.map(arguments,"a"), slice = 3;
return this.each(function() {
var self = this;
interval = jQuery.speed(interval);
if (fn == undefined || id.constructor == Function) {
fn = id;
id = interval;
slice = 2;
}
if (!this.timers) this.timers = {};
if (!this.timers[id]) this.timers[id] = [];
this.timers[id].push(window.setInterval(function() {
fn.apply(self,args.slice(slice));
},interval));
});
},
doin: function(interval,id,fn) {
var args = jQuery.map(arguments,"a"), slice = 3;
return this.each(function() {
var self = this, counter = 0;
interval = jQuery.speed(interval);
if (fn == undefined || id.constructor == Function) {
fn = id;
id = interval;
slice = 2;
}
if (!this.timers) this.timers = {};
if (!this.timers[id]) this.timers[id] = [];
this.timers[id].push(window.setInterval(function() {
if (counter++ >= 1) return jQuery(self).stop(id);
fn.apply(self,args.slice(slice));
},interval));
});
},
stop: function(id) {
return this.each(function() {
if (!this.timers) return;
if (id == undefined)
jQuery.each(this.timers, function(i) {
jQuery.each(this,function(j) {
window.clearInterval(this);
});
});
else if (this.timers[id])
jQuery.each(this.timers[id],function(i) {
window.clearInterval(this);
    });
    });
}
});

Blair Mitchelmore wrote:
> Good suggestions John as always. .in() can't be done because 'in' is a 
> JS keyword and I wouldn't want to have to call it like $()['in']() all 
> the time. So I figured two JS keywords smashed together would work and 
> chose .doin() as the function name; if you have any better ideas (maybe 
> .timeout() and .interval()) let me know.
>
> So this can handle multiple different one-off delays and interval-ed 
> events. These can then be canceled based on their reference label or 
> their interval if you didn't provide a label (not both).
>
> Example:
> $('p.display')
> .doin(500,function() { window.alert("a"); })
> .doin(1000,function() { window.alert("b"); })
> .doin(500,function() { window.alert("c"); })
> .doin(1000,'other',function() { window.alert("d"); })
> .doin(500,'other',function() { window.alert("e"); });
>
> // Alerts: 'a','b','c'
> $('p.display').stop('other');
>
> // Alerts: 'b','d','e'
> $('p.display').stop(500);
>
> // Alerts: 'a','c','d','e'
> $('p.display').stop(1000);
>
> // Alerts Nothing
> $('p.display').stop();
>
> I'll probably host this on my server if there's any interest. Any Questions?
>
> -blair


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery Kinda Plugin: every

2006-10-20 Thread Blair Mitchelmore
Good suggestions John as always. .in() can't be done because 'in' is a 
JS keyword and I wouldn't want to have to call it like $()['in']() all 
the time. So I figured two JS keywords smashed together would work and 
chose .doin() as the function name; if you have any better ideas (maybe 
.timeout() and .interval()) let me know.

So this can handle multiple different one-off delays and interval-ed 
events. These can then be canceled based on their reference label or 
their interval if you didn't provide a label (not both).

Example:
$('p.display')
.doin(500,function() { window.alert("a"); })
.doin(1000,function() { window.alert("b"); })
.doin(500,function() { window.alert("c"); })
.doin(1000,'other',function() { window.alert("d"); })
.doin(500,'other',function() { window.alert("e"); });

// Alerts: 'a','b','c'
$('p.display').stop('other');

// Alerts: 'b','d','e'
$('p.display').stop(500);

// Alerts: 'a','c','d','e'
$('p.display').stop(1000);

// Alerts Nothing
$('p.display').stop();

I'll probably host this on my server if there's any interest. Any Questions?

-blair

Code Below:
jQuery.fn.extend({
every: function(interval,id,fn) {
return this.each(function() {
var self = this;
interval = jQuery.speed(interval);
if (fn == undefined) {
fn = id;
id = interval;
}
if (!this.timers) this.timers = {};
if (!this.timers[id]) this.timers[id] = [];
this.timers[id].push(window.setInterval(function() {
fn.call(self);
},interval));
});
},
doin: function(interval,id,fn) {
return this.each(function() {
var self = this, counter = 0;
interval = jQuery.speed(interval);
if (fn == undefined) {
fn = id;
id = interval;
}
if (!this.timers) this.timers = {};
if (!this.timers[id]) this.timers[id] = [];
this.timers[id].push(window.setInterval(function() {
if (counter++ >= 1) return jQuery(self).stop(id);
fn.call(self);
},interval));
});
},
stop: function(id) {
return this.each(function() {
if (!this.timers) return;
if (id == undefined)
jQuery.each(this.timers, function(i) {
jQuery.each(this,function(j) {
window.clearInterval(this);
});
});
else if (this.timers[id])
jQuery.each(this.timers[id],function(i) {
window.clearInterval(this);
});
});
}
});

John Resig wrote:
> What if you had a trifecta of functions:
> .every()
> .in()
> .stop()
>
> and allow for function calls like this:
>
> .every( 100, "text", function(){
> if ( !$(this).val() )
> $(this).stop("text");
> });
>
> or if you don't care about a name:
>
> .in( "slow", function(){
> $(this).hide();
> })
> .mouseover(function(){
> $(this).stop();
> });
>
> or if you wanna get really interesting, make it so that you can stop
> function calls by how long their timer is set for:
>
> .every( 500, function(){
> $("#foo").load("test.html");
> })
> .every( 100, function(){
> if ( !$(this).val() )
> $(this).stop(100);
> });
>
> Just throwing out some ideas, let me know which ones stick.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Possible Change to jQuery.map()

2006-10-19 Thread Blair Mitchelmore
OK, so I was trying to do something clever with jQuery.map by using the 
Function.call technique to iterate in my root Object's this scope, but 
it kept giving me window. Then I read the source and noticed you're 
calling the function outright.

[other stuff]
for ( var i = 0; i < elems.length; i++ ) {
var val = fn(elems[i],i);
[yet more stuff]

Since most people don't use 'this' inside .map() and window is always 
accessible via 'window' could we change that line to

[other stuff]
for ( var i = 0; i < elems.length; i++ ) {
var val = fn.call(this,elems[i],i);
[yet more stuff]

The main purpose is to make

// within some object's this scope
this.someDomElements = jQuery.map.call(this,new 
Array(someVal),function(obj,index) {
return jQuery('').appendTo(this.someDomElement).get(0);
};

possible without resorting to closures like

// within some object's this scope
var self = this;
this.someDomElements = jQuery.map(new Array(someVal),function(obj,index) {
return jQuery('').appendTo(self.someDomElement).get(0);
};

Calling on this is just the first thing that came to mind; if anyone 
else has a more intriguing idea using an additional argument or somesuch 
it'll be appreciated. I also know I don't really need to write it in 
either of those ways, but I figured beauty and function trumps function 
alone. It's yet another easy fix that would make things slightly more 
extensible for plugin developers and vanilla users alike.

-blair


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] jQuery Kinda Plugin: every

2006-10-19 Thread Blair Mitchelmore
And I just realized I should make it possible to stop the repeating 
function later on.

Code:
jQuery.fn.every = function(interval,fn) {
return this.each(function() {
var self = this;
this.$every = window.setInterval(function() { fn.call(self) 
},interval);
});
};

Example:
// Display the current time updated every 500 ms
$("p.display").every(500,function() {
$(this).html(new Date());
});

//... some point later in the code execution
$("p.display").each(function() {
window.clearInterval(this.$every);
this.$every = null;
});

-blair

Blair Mitchelmore wrote:
> I don't know if this exists already but I needed this and assumed it 
> didn't and wrote it myself. Essentially it lets you do something to an 
> element every given time interval.
>
>
> -blair
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] jQuery Kinda Plugin: every

2006-10-18 Thread Blair Mitchelmore
I don't know if this exists already but I needed this and assumed it 
didn't and wrote it myself. Essentially it lets you do something to an 
element every given time interval.

jQuery.fn.every = function(interval,fn) {
return this.each(function() {
var self = this;
window.setInterval(function() { fn.call(self) },interval);
});
};

I used it to get a millisecond amount display every so often to produce 
a live updated element. It's mostly for live clock updating (and I 
suppose it could be useful to implement polling) but I'm sure the 
creative among you could find some other purpose for it.

Example:
// Display the current time updated every 500 ms
$("p.display").every(500,function() {
$(this).html(new Date());
});

-blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] tableSorter question

2006-10-16 Thread Blair Mitchelmore
Well, I noticed that in some of the highlightFade instances you 
specified and end parameter, and my plug-in doesn't know that you want 
that style removed afterwards because that could lead to a bumpy colour 
transition. Add the final parameter set to an empty string and see if 
the highlightFade problems go away.

ie change

$("td:gt(3)",this.parentNode).highlightFade({start: 'green',end: '#D0FFDA'});   

to

$("td:gt(3)",this.parentNode).highlightFade({start: 'green',end: '#D0FFDA', 
final: ''});

-blair

Paul Bakaus wrote:
> Hi there,
>
> I still don't know what plugin it causes..however, it's not too 
> important, it's only a prototype. But if you want to look at it yourself:
>
> http://paul.jquery.com/plugins/demo_mk/ 
> <http://paul.jquery.com/plugins/demo_mk/>
>
> Save it and uncomment this line:
>
> $(drag).children().removeClass("highlighted");
>
> then try to drag a row around and drop it into the table again. Now 
> try the sorting, and you will see that the class doesn#t update again. 
> Strange, huh?
>
> Paul
>
> 2006/10/13, Blair Mitchelmore <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>>:
>
> I wrote highlightFade so that it would remove the styles it set after
> the fact except when necessary to keep them for some reason. Can
> you set
> up a simple test case of this error so I can see why it's happening?
>
> -blair
>
> Paul Bakaus wrote:
> > forget it, it was not a table sorter bug I had, but this was caused
> > because of the highlightFade plugin, which does not remove its
> inline
> > styles after fading. Doo :)
> >
> >
>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] tableSorter question

2006-10-13 Thread Blair Mitchelmore
I wrote highlightFade so that it would remove the styles it set after 
the fact except when necessary to keep them for some reason. Can you set 
up a simple test case of this error so I can see why it's happening?

-blair

Paul Bakaus wrote:
> forget it, it was not a table sorter bug I had, but this was caused 
> because of the highlightFade plugin, which does not remove its inline 
> styles after fading. Doo :)
>
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugins using jQuery instead of $ died with latest

2006-10-12 Thread Blair Mitchelmore
Unfortunately, http://jquery.com/src/latest/ doesn't actually return the 
lastest jQuery release. It returns svn revision 29 which was before the 
days of the jQuery object; jQuery 1.0.2 is based on svn revision 413. To 
download the latest stable version of jQuery go to 
http://jquery.com/src/jquery-1.0.2.js (packed version available at 
http://jquery.com/src/jquery-1.0.2.pack.js). Hope that helps.

-blair

Mika Tuupola wrote:
> Plugins using jQuery instead of $ dont seem to work anymore if using  
> jquery.js from: http://jquery.com/src/latest/
>
> FireBug spits out "jQuery is not defined". Found this while trying to  
> make tabs and panView work together.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Breakable Each

2006-10-12 Thread Blair Mitchelmore
I too prefer returning a variable and false is fine by me. It'll just 
have to be documented so some programmer out there that returns false 
for some reason or another doesn't get really confused.

An example would be a continue style situation:
$("p").each(function() {
// skip this iteration but keep going through the set
if ($(this).is(".skip")) return false;
$(this).remove();
});

Someone innocently returning false, maybe to remind himself that it's 
not the expected outcome, would get quite flummoxed if this isn't 
documented.

-blair

John Resig wrote:
> I really prefer doing a 'return false' instead of throwing exceptions.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Breakable Each

2006-10-11 Thread Blair Mitchelmore
It seems like it would be really easy to implement a breaking mechanism 
for jQuery .each() function. We could use the same technique prototype 
does by creating a unique object and letting users throw that to break. 
We could create a 'break' property inside jQuery that .each() could 
catch to break the loop.

Exception based (ala prototype) implementation:

Example:
$("p").each(function() {
if ($(this).is(".unnecessary.beyond.here")) throw $['break'];

$(this).addClass('this').addClass('was').addClass('totally').addClass('required');
};

Code:
jQuery['break'] = new Object();
jQuery.extend({
each: function( obj, fn, args ) {
if ( obj.length == undefined )
for ( var i in obj )
try {
fn.apply( obj[i], args || [i, obj[i]] );
} catch (e) {
if (e == jQuery['break']) break;
throw e;
}
else
for ( var i = 0; i < obj.length; i++ )
try {
fn.apply( obj[i], args || [i, obj[i]] );
} catch(e) {
if (e == jQuery['break']) break;
throw e;
}
return obj;
},
});

Return Value based implementation:

Example:
$("p").each(function() {
if ($(this).is(".unnecessary.beyond.here")) return $['break'];

$(this).addClass('this').addClass('was').addClass('totally').addClass('required');
};

Code:
jQuery['break'] = new Object();
jQuery.extend({
each: function( obj, fn, args ) {
if ( obj.length == undefined )
for ( var i in obj )
if ( fn.apply( obj[i], args || [i, obj[i]] ) == 
jQuery['break']) break;
else
for ( var i = 0; i < obj.length; i++ )
if ( fn.apply( obj[i], args || [i, obj[i]] ) == 
jQuery['break']) break;
return obj;
},
});

The code for this feature is marginal and it is one of the few things 
that I miss from my prototype days. This code is untested and might not 
work the way I expect it to, but you get the drift.

-blair

NB It may be better to use something other than 'break' as the variable 
name as it's a reserved word and you'd have to use the square bracket 
notation any time it is used.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Documentation of return objects?

2006-10-11 Thread Blair Mitchelmore
And if I recall correctly, .after() and its ilk return the original 
element if only for the logistical difficulty of determining what part 
of the (not necessarily single element wrapped. for example 
$('p').after(''); is the 
p.first in the jQuery set or is p.last in the jQuery set?) new elements 
to assign to the jQuery set. And .clone() returns the cloned elements 
but you can return to the original set through the wonders of .end()

-blair

Kurt Mackey wrote:
> Yep, that's correct, even if I can't write very clearly. ;)
>
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Blair Mitchelmore
> Sent: Wednesday, October 11, 2006 1:07 PM
> To: jQuery Discussion.
> Subject: Re: [jQuery] Documentation of return objects?
>
> I think what he's talking about is whether or not it returns what was 
> just added to the document or the original element. Another example 
> would be whether or not .clone() return the cloned elements in the 
> jQuery set or the original elements. Those sorts of things aren't listed
>
> in the documentation.
>
> -blair
>
> John Resig wrote:
>>> Anyway, that link's a start, but it doesn't help clarify what .after
>>> returns, for instance.
>> According to that link, .after() always returns a jQuery object. While
>> .html() can return either a jQuery object or a String, depending on
>> the arguments passed in.
>>
>> If something returns a jQuery object, that means that its chainable
>> and that you can continue to add actions on to it (e.g.
>> $().after().html("foo").after()...)
>>
>> --John
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Documentation of return objects?

2006-10-11 Thread Blair Mitchelmore
I think what he's talking about is whether or not it returns what was 
just added to the document or the original element. Another example 
would be whether or not .clone() return the cloned elements in the 
jQuery set or the original elements. Those sorts of things aren't listed 
in the documentation.

-blair

John Resig wrote:
>> Anyway, that link's a start, but it doesn't help clarify what .after
>> returns, for instance.
> According to that link, .after() always returns a jQuery object. While
> .html() can return either a jQuery object or a String, depending on
> the arguments passed in.
>
> If something returns a jQuery object, that means that its chainable
> and that you can continue to add actions on to it (e.g.
> $().after().html("foo").after()...)
>
> --John


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] oninput bug workaround

2006-10-08 Thread Blair Mitchelmore
This wouldn't be ideal, nor do I know if it even works but have you tested:

someFunction = function() { /* ... */ };
element.attr('oninput','someFunction()');

-blair

Duncan Anker wrote:
> I've been trying to use oninput to validate fields in firefox and have 
> had zero luck with it the jQuery way:
>
> element.bind('input', ...)
>
> is just not cutting it. After some digging around on the net I *finally* 
> found some useful, although mildly depressing, information about it. 
> What it seems to boil down to is a bug in firefox (and mozilla codebase 
> in general I expect).
>
> This is okay:
>
> 
>
> So is this:
>
> element.addEventListener('input', ...)
>
> This doesn't work:
>
> element.oninput = function() { ...
>
> So I'm figuring that jQuery must perform its cross-platform magic using 
> the latter form.
>
> Does anyone have any ideas about how to handle this? I want to stay 
> unobtrusive, so I don't want the handlers defined in my HTML, and I want 
> to be cross-platform, and I'd rather not implement a cross-platform 
> event handler just for the one event, especially since there is already 
> one in jQuery.
>
> Thoughts?
>
>
> Regards,
> Duncan
>


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] .each backwards ?

2006-10-06 Thread Blair Mitchelmore
I propose hcae:

jQuery.fn.hcae = function( fn, args ) {
return jQuery.hcae( this, fn, args );
};

jQuery.hcae = function( obj, fn, args ) {
if ( obj.length == undefined )
for ( var i in obj )
fn.apply( obj[i], args || [i, obj[i]] );
else
for ( var i = obj.length - 1; i >= 0; --i )
fn.apply( obj[i], args || [i, obj[i]] );
return obj;
};

-blair ;)

kenton.simpson wrote:
> Is there a way to make .each walk backwards threw the element collection?

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using $ to insert HTML into the page

2006-10-06 Thread Blair Mitchelmore
I'm pretty sure

If I recall correctly, jQuery's element creation technique is to create 
a temporary div (var div = document.createElement('div')) then add the 
html you provided to that elements innerHTML value (div.innerHTML = 
html) and then extracting the div's children (using the appropriate DOM 
method) and appending it to the real document. Hope that helps.

-blair

Matthew Pennell wrote:
> I just can't tell if elements or innerHTML are being inserted. As I 
> understand it, markup that is added using innerHTML cannot be later 
> manipulated by DOM-methods, whereas as DOM inserted (using 
> .createElement and .appendChild) elements can be.
>
> Matthew.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Highlight fade plugin bug

2006-10-05 Thread Blair Mitchelmore
OK, I uploaded a new packed version and just in case it mattered, your 
highlightFade code could be made prettier by setting some useful default 
values:

$.highlightFade.defaults['speed'] = 1000;
$.highlightFade.defaults['iterator'] = 'exponential';
$('td.link1').click(function() { $(this).highlightFade('#33') });
$('td.link1').hover(function() { $(this).highlightFade('#F0F0F0') 
},function() { return true });

-blair

Blair Mitchelmore wrote:
> OK, in what can officially be called the stupidest mistake ever, my 
> regex tested for #FFF before #FF so all 6 char colour strings got 
> caught and made into a 3 char so your F0F0F0 became F0F and therefore 
> purple... I've fixed the code in the unpacked version at 
> http://jquery.offput.ca/js/jquery.highlightFade.js but I'll have to get 
> home before I can get a chance to upload a new packed version...
>
> Man do I feel stupid... and amazed that this wasn't caught until now...
>
> -blair
>
> Still gonna look into that table cell highlighting issue later on as well...
>
> Rafael Santos wrote:
>> Yeah, it works on IE, but i didnt mention the real bug. This purple 
>> color is not defined.. lol
>>
>>
>> 2006/10/5, Blair Mitchelmore <[EMAIL PROTECTED] 
>> <mailto:[EMAIL PROTECTED]> >:
>>
>> That's pretty weird, the page works in firefox but not IE. I'll
>> have to
>> investigate in a bit; at the moment I've got a large scale software
>> engineering assignment due...
>>
>> -blair
>>
>> Rafael Santos wrote:
>> > hey, have you faced this bug?
>> >
>> > http://blocparty.com.br/js/teste2.html
>> >
>> > Should that happen?
>> >
>> >
>> 
>> >
>> > ___
>> > jQuery mailing list
>> > discuss@jquery.com <mailto:discuss@jquery.com>
>> > http://jquery.com/discuss/
>>
>>
>> ___
>> jQuery mailing list
>> discuss@jquery.com <mailto:discuss@jquery.com>
>> http://jquery.com/discuss/
>>
>>
>>
>> 
>>
>> ___
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/
>
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Highlight fade plugin bug

2006-10-05 Thread Blair Mitchelmore
OK, in what can officially be called the stupidest mistake ever, my 
regex tested for #FFF before #FF so all 6 char colour strings got 
caught and made into a 3 char so your F0F0F0 became F0F and therefore 
purple... I've fixed the code in the unpacked version at 
http://jquery.offput.ca/js/jquery.highlightFade.js but I'll have to get 
home before I can get a chance to upload a new packed version...

Man do I feel stupid... and amazed that this wasn't caught until now...

-blair

Still gonna look into that table cell highlighting issue later on as well...

Rafael Santos wrote:
> Yeah, it works on IE, but i didnt mention the real bug. This purple 
> color is not defined.. lol
>
>
> 2006/10/5, Blair Mitchelmore <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]> >:
>
> That's pretty weird, the page works in firefox but not IE. I'll
> have to
> investigate in a bit; at the moment I've got a large scale software
> engineering assignment due...
>
> -blair
>
> Rafael Santos wrote:
> > hey, have you faced this bug?
> >
> > http://blocparty.com.br/js/teste2.html
> >
> > Should that happen?
> >
> >
> 
> >
> > ___
> > jQuery mailing list
> > discuss@jquery.com <mailto:discuss@jquery.com>
> > http://jquery.com/discuss/
>
>
> ___
> jQuery mailing list
> discuss@jquery.com <mailto:discuss@jquery.com>
> http://jquery.com/discuss/
>
>
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Highlight fade plugin bug

2006-10-05 Thread Blair Mitchelmore
That's pretty weird, the page works in firefox but not IE. I'll have to 
investigate in a bit; at the moment I've got a large scale software 
engineering assignment due...

-blair

Rafael Santos wrote:
> hey, have you faced this bug?
>
> http://blocparty.com.br/js/teste2.html
>
> Should that happen?
>
> 
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] unhover and untoggle

2006-10-04 Thread Blair Mitchelmore
Well, while I might not need untoggle and unhover, I definitely enjoy a 
challenge! I've been thinking about a reliable way to allow multiple 
hover/toggles and to be able to remove them independently... I'll let 
you know if I get anywhere with it...

-blair

Brandon Aaron wrote:
> Nothing?
>
> Am I really the only person that needs unhover and untoggle?
>
> I've logged an enhancement ticket for this: 
> http://jquery.com/dev/bugs/bug/234/
>
> --
> Brandon Aaron
>
> On 10/3/06, Brandon Aaron <[EMAIL PROTECTED]> wrote:
>> This does limit the $().hover and $().toggle to once per an element.
>> Multiple uses will overwrite the pervious handler. Any tips on how to
>> manage this along with keeping the un version would be greatly
>> appreciated.
>>
>> --
>> Brandon Aaron
>>
>> On 10/3/06, Brandon Aaron <[EMAIL PROTECTED]> wrote:
>>> Well I've gone ahead and done it. I've added an unhover and untoggle method.
>>>
>>> Here is the example/test page:
>>> http://brandonaaron.net/jquery/unevents/unevents.html
>>> Here is the patch: http://brandonaaron.net/jquery/unevents/unevents.diff
>>>
>>> --
>>> Brandon Aaron
>>>
>>> On 10/3/06, Brandon Aaron <[EMAIL PROTECTED]> wrote:
 Is there a reason why there isn't an unhover and an untoggle? I could
 really use unhover in my current project and was thinking about
 building it and just logging it as an enhancement. Just calling
 .unmouseover().unmouseout() is not enough b/c I have other handlers
 for those as well and don't want them wiped out. I just want to
 unhover().

 --
 Brandon Aaron

>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] String Parsing

2006-10-03 Thread Blair Mitchelmore
To avoid running split twice, you could do it this way (removes IE5 from 
compatibility however):

var file1 = str1.split("\\").pop();

-blair

Tombo wrote:
> this might not be jquery related, but i noticed there are a lot of savvy
> javascript programmers in this mailing list.
>
> i want to grab just the filename and extension from the following string:
>
> str1="F:\\Test1\\Test2\\Test3\\test.txt";
>
> i want to grab "test.txt"
>
> i use this code:
>
> file1=(str1.split("\\"))[(str1.split("\\")).length-1];
>
>
> i was wondering if there is a better way to grab that part of the string
>
> Thx for any help


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Chainable if/else - hot or not?

2006-10-03 Thread Blair Mitchelmore
Brian wrote:
> Elegant?  Perhaps.
>
> Breaks the Principle of Least Surprise?  Absolutely, unfortunately.
I don't find it to be surprising at all. If you run filter without 
specifying what you want to do with the subset it creates via a 
secondary lambda argument, the stack is modified to allow you to act on 
that subset while retaining the original stack allowing you to return to 
it via an .end() call. If you specify a callback, it is smart enough to 
realize you want to use that callback on the subset and that's all. So 
it doesn't modify the set and the chain continues unmodified.

It makes sense to me but, as with anything, that means nothing for 
anyone else.

-blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Chainable if/else - hot or not?

2006-10-03 Thread Blair Mitchelmore
I thought, I'd add on my personal thoughts on this subject. Personally, 
I find the anonymous function version of filter et. al. to be quite 
intuitive. You can either modify the stack temporarily and continue the 
chain until you .end() this modified stack and return to the original, 
or you can simply apply the methods you want to the argument you 
provided leaving the original stack intact without needing to .end() the 
modified stack seeing as it wasn't modified. Please please keep this 
syntax as it's too elegant to not keep around.

-blair

Christof Donat wrote:
> Hi,
>
>> [...]
>> .method( Hash, arg1, ..., argN, ContextFunction )
>> [...]
>
> That all was not my point. My point was that it is irritating that the same 
> function may be destructive or not just by providing the context-function. 
> I'd vote for either never be destructive, or always. Since for functions like 
> filter() it is difficult to go the "never destructive"-way, I'd like it to be 
> always destructive and have an alternative version which is never 
> destructive.
>
>> So, with .filter("foo",function) I'm taking the opportunity to remove
>> the need for:
>> .filter("foo").each(function(){
>>
>> }).end()
>
> That is exactly what the suggestet the filterend()-function is for. That way 
> filter() ist always destructive and filterend() never. In both cases with or 
> without a context function.
>
> $('div').filter('.test') // return value only contains divs with class 'test'
> $('div').filter('.test,  // return value only contains divs with class 'test'
>   function() {
>   ...
>   });
> $('div').filterend('.test') // return value contains all divs (useless)
> $('div').filterend('.test,  // return value contains all divs
>   function() {
>   ...
>   });
>
> The last to calls have the same effect as
>
> $('div').filter('.test').end()
> $('div').filter('.test').each( function() {
>   ...
> }).end();
>
> In all cases the context function is evaluated for each div with the 
> class 'test'. The difference between filter() and filterend() is just the 
> return value.
>
> Christof
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] A bug and an improvement...

2006-09-29 Thread Blair Mitchelmore
While the solution appears more elegant, the document.onreadystateshange 
property is not as reliable as it should be (according to dean edwards): 
http://dean.edwards.name/weblog/2005/09/busted/#comment2529

I say we stick with what we know with confidence works.

-blair

Adam Schlag wrote:
> First off, jQuery has (so far) been excellent to work with, and I wish
> I had discovered it before investing time in some of the other
> JavaScript toolkits that are available!
>
> So, the bug:
>
> I the process of running through the examples I have noticed that
> Firefox's leak monitor extension reports a leak in the same bit of
> code from jquery.js.  I searched and apparently someone else has
> reported it on the list:
> http://jquery.com/pipermail/discuss_jquery.com/2006-May/005401.html
>
> The basic premise is that any time "addEventListener" is called a
> corresponding "removeEventListener" call must occur or there will be a
> leak.  I tested the fix from the post above and that indeed does the
> trick.  I haven't noticed a bug report on this, though...so, anyone
> object to me filing one?
>
> And for the improvement...
>
> I was actually working on my own solution for a set of
> "addOnLoad/addOnUnload" functions, and I came across this post by Dean
> Edwards (http://dean.edwards.name/weblog/2006/06/again/) and also this
> one by Jesse Skinner
> (http://www.thefutureoftheweb.com/blog/2006/6/adddomloadevent), but I
> didn't like the IE hack at all, and tried to find some other way...
>
> I'm not sure if anyone else has tried this, but a simple
> document.attachEvent will work instead of the messy script tag hack.
>
> Here is what is currently in jQuery:
> ...
> // If IE is used, use the excellent hack by Matthias Miller
> // 
> http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
> } else if ( jQuery.browser.msie ) {
>
>   // Only works if you document.write() it
>   document.write("   "src=//:><\/script>");
>
>   // Use the defer script hack
>   var script = document.getElementById("__ie_init");
>   script.onreadystatechange = function() {
>   if ( this.readyState != "complete" ) return;
>   this.parentNode.removeChild( this );
>   jQuery.ready();
>   };
>
>   // Clear from memory
>   script = null;
>
> // If Safari  is used
> } else if ( jQuery.browser.safari ) {
> ...
>
> And this is my proposed "fix", with no hacks :)
> ...
> } else if ( jQuery.browser.msie ) {
>
>   // Only works if you document.write() it
>   var __ie_init = function() {
>   if ( document.readyState != "complete" ) return;
>   document.detachEvent("onreadystatechange", __ie_init);
>   jQuery.ready();
>   }
>   document.attachEvent("onreadystatechange", __ie_init);
>
> // If Safari  is used
> } else if ( jQuery.browser.safari ) {
> ...
>
> I've tested this myself with Drip and it works with no leaks.  The
> readyState and detachEvent could even be added in to ready to include
> this new code as well as the Mozilla/Gecko fix from the other post:
>
> $.ready = function() {
>
> if (jQuery.browser.msie && document.readyState != "complete") return;
>
> if( jQuery.browser.mozilla || jQuery.browser.opera ) {
>   document.removeEventListener( "DOMContentLoaded", $.ready, null );
> } else if ( jQuery.browser.msie ) {
>   document.detachEvent("onreadystatechange", $.ready);
> }
>
> if ( $.$$timer ) {
>   clearInterval( $.$$timer );
>   $.$$timer = null;
>   for ( var i = 0; i < $.$$ready.length; i++ ) {
> $.apply( document, $.$$ready[i] );
>   }
>   $.$$ready = null;
> }
> };
>
> And the "hack" could simply be changed to this (which is almost
> identical to the Mozilla/Opera addEventListener):
> ...
> } else if ( jQuery.browser.msie ) {
>
>   document.attachEvent("onreadystatechange", jQuery.ready);
>
> // If Safari  is used
> } else if ( jQuery.browser.safari ) {
> ...
>
> Well, hope this made sense.  Feel free to let me know if you have any
> comments (or if this doesn't work for you).  Thanks, and hopefully
> this can make it in to a future version!
>
> Adam
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Hiding multiple elements, then showing one

2006-09-22 Thread Blair Mitchelmore
.get() breaks the chain returning the actual DOM element. .eq() does 
something similar without breaking the chain

$(settings.slide).hide().eq(i).fadeIn();

should work

-blair

Brian Litzinger wrote:
> I have a little bit of code that I want to hide x amount of divs, then when
> they're all hidden to show a specific one. Right now I have this...
>
> // hide all found divs
> $(settings.slide).hide();
> // get the slide that i want shown
> div = $(settings.slide).get(i);
> // show the slide when everything is hidden
> $(div).fadeIn();
>
> How do I chain a hide all, then show one function?


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Wildcards

2006-09-19 Thread Blair Mitchelmore
This isn't a fullproof solution (it will also find td elements with the 
id 'comments_td_' if you have one) but I'm not sure that jQuery has 
wildcard searches (unless the expression parser detects regex and passes 
it through as the test against the tag/attribute) so you could use
$("[EMAIL PROTECTED]'comments_td_']").click(fn);
which makes sure the elements selected have ids that begin with 
'comments_td_'

Hope that helps.

-blair

Junior wrote:
> I am using the following code:
>
> $("[EMAIL PROTECTED]").click(function(event) {
>
> I need to detect an onClick event for ANY  with an id beginning 
> with "comments_td_". In the example above, I have inserted "WILDCARD" 
> because I am unsure of what the JQuery synatx is for wildcard - I have 
> tried "*" but it did not work. Any recommendations?


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Sending array vs object

2006-09-14 Thread Blair Mitchelmore
If I'm not mistaken, anything can be used as a key if enclosed in quoted:
f = {"float":"right"} // no problem
Rather than with implicit quotes:
f = {float:"left"} // not so good

They can then be accessed via the array accessor
f['float']; // no problem
But you'll get trouble if you try the dot accessor
t.float; // problem

I think all of that's accurate.

-blair

Klaus Hartl wrote:
>
>> Something missing: Of course that could also be achieved by using 
>>
>> {"customerid":"47", "supplierid":"32", "asdf[]":[1243,1928], ...}
>
>
> Is "asdf[]" a valid key for a value?
>
>
> -- Klaus
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Cookie handling in JQuery

2006-09-13 Thread Blair Mitchelmore
I think it would be best if we kept this in the typically succinct 
syntax of jQuery. such as .html() setting and getting depending on the 
attributes. This is a simple version that just consolidates your 
functions but...

$.cookie = function(name, value, expires, path, domain, secure) {
if (typeof value == 'undefined') {
var name += "=";
var ca = document.cookie.split(';');
for (var i = 0; i < cs.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
} else if (value === false) {
arguments.callee(name,'',-1);
} else {
if (typeof expires == 'number') {
var date = new Date();
date.setTime(date.getTime() + (expires * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toGMTString();
} else {
expires = '';
}
path = (path) ? '; path=' + path : '';
domain = (domain) ? '; domain=' + domain : '';
secure = (secure) ? '; secure' : '';
document.cookie = name + '=' + value + expires + path + domain + 
secure;
}
};

Klaus Hartl wrote:
> Yehuda Katz schrieb:
>   
>> It doesn't have to do with DOM Scripting, but then, neither does $.ajax. 
>> It's a commonly enough required feature that obviously doesn't belong in 
>> the core, but would be nice to tack on to an existing jQuery 
>> installation as a plugin without worrying about incompatibilities.
>> 
>
>
> Here is a class based on scripts at quirksmode.org, just needs to be 
> ported to jQuery. If nobody does it, I will make a plugin out of it:
>
> var CookieHandler = new function() {
>  /**
>   * Reads a cookie.
>   *
>   * @param name the name of the cookie
>   *
>   * @return the value of the cookie
>   *
>   * @author Klaus Hartl (28.06.2006)
>   */
>  this.get = function(name) {
>  var nameEQ = name + '=';
>  var ca = document.cookie.split(';');
>  for (var i = 0; i < ca.length; i++) {
>  var c = ca[i];
>  while (c.charAt(0) == ' ') {
>  c = c.substring(1, c.length);
>  }
>  if (c.indexOf(nameEQ) == 0) {
>  return c.substring(nameEQ.length, c.length);
>  }
>  }
>  return null;
>  };
>  /**
>   * Sets a cookie with the given name and value and other optional 
> parameters.
>   *
>   * @param namethe name of the cookie
>   * @param value   the value of the cookie
>   * @param expires an integer specifying the expiration date from 
> now on
>   *in days. If you set the number of days to 0 the 
> cookie
>   *is trashed when the user closes the browser.
>   * @param pathpath where the cookie is valid (default: path of
>   *calling document).
>   * @param domain  domain where the cookie is valid (default: domain of
>   *calling document).
>   * @param secure  boolean value indicating if the cookie transmission
>   *requires a secure transmission.
>   *
>   * @author Klaus Hartl (28.06.2006)
>   */
>  this.set = function(name, value, expires, path, domain, secure) {
>  if (typeof expires == 'number') {
>  var date = new Date();
>  date.setTime(date.getTime() + (expires * 24 * 60 * 60 * 1000));
>  expires = '; expires=' + date.toGMTString();
>  } else {
>  expires = '';
>  }
>  path = (path) ? '; path=' + path : '';
>  domain = (domain) ? '; domain=' + domain : '';
>  secure = (secure) ? '; secure' : '';
>  document.cookie = name + '=' + value + expires + path + domain 
> + secure;
>  };
>  /**
>   * Deletes a cookie by setting the expiry date in the past.
>   *
>   * @param name the name of the cookie
>   *
>   * @author Klaus Hartl (28.06.2006)
>   */
>  this.erase = function(name) {
>  this.set(name, '', -1);
>  };
> };
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>   


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] swapClass

2006-09-08 Thread Blair Mitchelmore




Wouldn't your code be faster if you did it without generating a new
jQuery Object for each element you're doing this for. Also, you could
just use the internal jQuery.className.has(el,className) rather than
.is('.'+className) since .is() still needs to regex parse your input
string to determine that you're looking for a className followed by the
actual className test whereas jQuery.className.has(el,className) just
needs to do the className test.

$.fn.swapClass = function(c1, c2){
return this.each(function(){
if (jQuery.className.has(this,c1)) {
jQuery.className.remove(this,c1);
jQuery.className.add(this,c2);
} else {
jQuery.className.remove(this,c2);
jQuery.className.add(this,c1);
}
});
}
It's a marginal improvement but one that would be felt on large
projects that use this frequently.

-blair

Wil Stuckey wrote:

  
  Only
if the selected elements have either c1 or c2 initially. If they have
neither or both, it won't yield the same results.

  
  
  
Right this was my intention. I changed the plugin a bit to make it more
readable, IMO. What it does is looks for c1 if it's not present it adds
it. Then next time swapClass is run it finds c1 so it is removed and c2
is added.
  
  
You can see that here:
  http://sandbox.wilstuckey.com/jquery/swapClass.html
  
-Wil
  
  

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
  




___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Method Clarification

2006-09-07 Thread Blair Mitchelmore
Sam wrote:  
> I'm confused about whether .addClass operates on a jQuery object as 
> documented in jQuery.com/api/, and is listed as "Traversing" in the 
> cheat sheet.  Seems to me .addClass operates on the DOM, and is a 
> "Manipulation" method?
Technically it's listed as

jQuery addClass( String class )

which means it takes as its argument a string and returns a jQuery 
Object. While it does add classes to the elements referenced in the 
jQuery Object it specifically returns the same jQuery Object to allow 
chaining methods (ie 
$('p').addClass('paragraph').addClass('happy').hide();) which is 
jQuery's bread and butter.

Sam wrote:
> .eq(Number pos) and .get(Number num) appear nearly the same.  From 
> jquery.com/api/
.eq modifies the list of elements referenced in the jQuery Object to 
one, and .get returns the actual element specified. This means that .eq 
doesn't break the jQuery chain allowing you to do jQuery stuff with it 
(ie $('p').eq(3).addClass('sad').removeClass('happy');) and .get returns 
the actual original unmodified DOM Element allowing you to access those 
raw properties therein (ie ('p').get(3).className = "panda";) but breaks 
the jQuery chain.

Sam wrote:  
> The documents suggests .eq() operates on a jQuery object, .get() 
> operates on an Element, but the examples are the same.
If the docs show that same things happening to both, then either the 
docs are incorrect (or I'm incorrect it's been known to happen :) or 
this is a serendipitous event where there is a DOM method and a jQuery 
method which are identical.

Hope this was helpful (and accurate).

-blair

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/