Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion extracting one class out of a few
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ricardo  
View profile  
 More options Apr 16 2009, 2:52 am
From: Ricardo <ricardob...@gmail.com>
Date: Wed, 15 Apr 2009 23:52:08 -0700 (PDT)
Local: Thurs, Apr 16 2009 2:52 am
Subject: Re: extracting one class out of a few
Hi,

I tried to answer directly but your e-mail rejected it as spam.

We should move this topic to the jquery-en group or continue it
privately, as this group is about development of jQuery itself.

$('[class*='+options.cssprefix+'-]').each(function(){

       //parse the object string, faster than eval
       function getOptions(str){
                var options = {},
                      str = str.replace(/[{}"'\s]/g, '').split(',');
                $.each(opt, function(i, val){
                       val = val.split(':');
                       options[val[0]] = val[1];
                });
                return options;
       };

       var sx = this.className.replace(/,\s+/, ',').match(/sx-\w+(\s+)?
{\S*}/
g);
       var effects;

       $.each(sx, function(index, val){
               val = val.split(/\s+/);
               effects[ val[0] ] = getOptions( val[1] );
       });

       console.log( effects );

});

It should log in the firebug console an object which contains all the
effects
for a certain element, each with it's options object. It allows either
the "sx-shake {option:'something'}" or "sx-shake{option:something}"
format in the class attribute.

cheers,
- ricardo

On 11 abr, 16:20, Gilles <gil...@netxtra.net> wrote:

> I am getting closer, changing the selector from:

> [class^='+options.cssprefix+'-]

> to

> [class*='+options.cssprefix+'-]

> solved the problem of not retrievingclassattribute with multipleclassname.

> After I use a regex to extract eachclassthat is related to the
> plugin only:

> sx-[^\s]+ ?{.*}|sx-[^\s]+

> that works fine in The Regex Coach for the follwoing example:

> red sx-dialog {var: 'val'} sx-draggable  black

> But it doesn't work (or I dont use it properly) somehow in the code:

>                // sxclassdetector regex ( sx-[^\s]+ ?{.*}|sx-[^\s]
> + )
>                 var sx_reg = new RegExp(options.cssprefix+'-[^\\s]+ ?\{.*
> \}|'+options.cssprefix+'-[^\s]+ \g');

>                 // scriptless elements?
>                 $('[class*='+options.cssprefix+'-]').each(function(i)
>                 {
>                         //classstring
>                         var clstr = $(this).attr('class');

>                         // get all classes
>                         var classes = sx_reg.exec(clstr);

>                         if (classes) $.each(classes, function(i){ alert(classes[i]); });
>                         else alert(clstr);
>                 });

> That would only return this format sx-foo {var:val} also the first
> match is always this format. I need to do more reading and testing,
> but it think it is the way to go. or well i will see.

> On Apr 10, 4:59 pm, Ricardo <ricardob...@gmail.com> wrote:

> > I don't have Firebug here so can't test anything and didn't bother to
> > read the whole source, but from what I see you're using a simple regex
> > that extracts each word in the className and then you *assume* your
> > requiredclassis the firstone, right?

> > You could try eliminating the whitespace between the mainclassand
> > it's options, that way you know they are related and don't need to
> > guess classes:

> > <div id="greenbox"class="green sx-shake{event: 'dblclick'}
> > someotherclass"></div>

> > $('[className*="sx-shake"]').each(function(){
> >   //here you know it's a 'shake' element, so use a special regex to
> > get the options:
> >  /sx\-shake\{(.*)\}/.exec( this.className) // something like that

> > });

> > Thisclass-gathering process could certainly be streamlined into a
> > single function.

> > On Apr 9, 10:05 am, Gilles <gil...@netxtra.net> wrote:

> > > Hi,

> > > I am still working on my plugin that this group helped me debug in the
> > > past and I have an other issue, which can probably ressolve quickly
> > > but i don't know how to attack the problem.

> > > Basically my script uses the HTMLclassattribute in order to set
> > > widgets, effects and plugins as well as passing through options (if
> > > any) for the set widgets, effects and plugins.

> > > I got it all working now, added event support, delay support, effects
> > > support ect... Anyway the issue is not there, everything works ok,
> > > also it can probably be optimized and cleaned up.

> > > The issue I have is if I want to have multipleclass, some that might
> > > not be related to my plugin and therefor need to be left behind like:

> > > <divclass="foobox sx-fold { sxFxSpeed: 500; }"> // where foobox need
> > > to be left behind and the rest extracted

> > > And some I want to be able to have more thanonespecialclassand set
> > > of options, like:

> > > <divclass="foobox sx-draggable { options} sx-resizable {options}"> //
> > > here foobox is left behind but the rest need to be recorded

> > > To be honest I have no idea on how to go and do that, I think the
> > > option I can use the same code and just check for m[0], m[1], m[2]
> > > ect...

> > > But the problem is as soon as I introduce an otherclassthe plugin
> > > just doesn't pick up anything anymore.

> > > The plugin in action:http://codeserenity.com/jquery/scriptless/demoX4.html
> > > The plugin code:http://codeserenity.com/jquery/scriptless/js/jquery.scriptlessX4.js

> > > If anyone could point me in the right direction that would be lovely
> > > and make sure to point out again everything I do wrong or that could
> > > be done better in the code as I always learn a lot from you guys and
> > > still have TONNES to learn as some of my attempt to help other often
> > > show :p

> > > Thanks in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.