Karelia Community Forum

Join a conversation, pose a question, or help a fellow user: The best place to discuss all things Karelia.

You are not logged in.

#1 March 24, 2012 12:34 pm

seanc
Hero

Unique CSS IDs?

Mike:

I've run into another unexpected "gotcha" with my plugin.  The method:

// For when you need to guarantee the element's ID is unique within the document.
- (NSString *)startElement:(NSString *)elementName
           preferredIdName:(NSString *)preferredID
                 className:(NSString *)className
                attributes:(NSDictionary *)attributes;

I was expecting this to generate a unique ID for every plugin instance in the "document", but it only creates unique IDs for multiple instances within a single collection. ie, if I insert 3 plugins in 3 different collections, it assigns the same ID to all 3.

Is this normal behavior, or should they all be unique?  Is there a way to make every instance unique?

Sean

Offline

#2 March 24, 2012 4:11 pm

mikeabdullah
Administrator

Re: Unique CSS IDs?

Hi Sean,

IDs from that method are unique within the page being generated. If you want a site-wide unique ID, that would have to be generated and stored yourself, such as from the CFUUID API.

Offline

#3 March 25, 2012 9:02 am

seanc
Hero

Re: Unique CSS IDs?

mikeabdullah wrote:

IDs from that method are unique within the page being generated. If you want a site-wide unique ID, that would have to be generated and stored yourself, such as from the CFUUID API.

OK, thanks Mike.  Looks like I have more work to do.

Alternatively, is there such thing as a "shared" inspector, or properties?  To keep them all in-sync?

Sean

Offline

#4 March 27, 2012 3:36 am

mikeabdullah
Administrator

Re: Unique CSS IDs?

I'm not really sure what you mean!

Sandvox is free to instantiate as many copies of your SVInspector as it likes, since the user can have multiple Inspectors open at once.

We don't provide any shared properties as such. But of course your plug-in can store whatever it likes as its own state. You could store things in NSUserDefaults so long as the keys are properly prefixed I guess.

Offline

#5 March 27, 2012 10:08 am

seanc
Hero

Re: Unique CSS IDs?

Mike, don't know how best to explain the situation, but I'm left with 3 choices:

  1. provide a means to insure site-wide unique IDs, or ...

  2. provide a means to auto-synchronize ALL plugin instances to a single set of properties, or ...

  3. leave it up to the user to ensure synchronized properties

CFUUID would work for unique IDs, but produces very long, non-descript, numerical strings. Still investigating it.

Auto-synchronizing means that changes made to any single inspector would have to automatically propagate to ALL other instances of the plugin.

For the moment, I'm using #3 - leave it up to the user.  For that, I am using NSUserDefaults, by manual "Save" button, not automatically.  This is still error-prone though.  Documented in the demo plugin:

http://www.macalchemy.com/nmdemo/demo-p … nudemo.zip

Sean

Offline

Board footer

Powered by FluxBB