Sorry all! After examining it further and playing around with
javascript in the live preview plugin, I found the answer to my
question about the conditional as well as the fix for my plugin.

In case anyone else with limited javascript experience wanted to know
the answer, the !tag in the if(!tag ||
tag.tags.contains("excludeLists")) conditional is there to prevent an
error. When it's referring to tag, it's not referring to the title of
the tag, but to a tiddler corresponding to that tag (e.g. if it were
excludeSearch, it wouldn't be checking to see if excludeSearch is an
entry in a tag list, it would be checking to see if there is a tiddler
named excludeSearch in the current TiddlyWiki or store). If tag
doesn't exist as an actual tiddler yet, calling
tag.tags.contains("excludeLists") would throw an error since it would
be querying a non-existent tiddler.

I'm sure this was obvious to anyone with any experience in serious
programming, but the fix to my plugin was to add a similar check in
the conditional  if(!config.options.chkHttpReadOnly || !
tag.tags.contains(config.options.txtEditorOnlyTag))

The final plugin code is now the following:

//{{{


config.macros.tags.handler =
function(place,macroName,params,wikifier,paramString,tiddler)
{
        params =
paramString.parseParams("anon",null,true,false,false);
        var ul = createTiddlyElement(place,"ul");
        var title = getParam(params,"anon","");
        if(title && store.tiddlerExists(title))
                tiddler = store.getTiddler(title);
        var sep = getParam(params,"sep"," ");
        var lingo = config.views.wikified.tag;
        var label = null;
        for(var t=0; t<tiddler.tags.length; t++) {
                var tag = store.getTiddler(tiddler.tags[t]);
                if(!tag || !tag.tags.contains("excludeLists")) {
                        if(!config.options.chkHttpReadOnly || (tag
&& !
tag.tags.contains(config.options.txtEditorOnlyTag))) {
                                if(!label)
                                        label =
createTiddlyElement(ul,"li",null,"listTitle",lingo.labelTags.format([tiddle­
r.title]));


createTagButton(createTiddlyElement(ul,"li"),tiddler.tags[t],tiddler.title)­;
                                if(t<tiddler.tags.length-1)
                                        createTiddlyText(ul,sep);
                        }
                }
        }
        if(!label)


createTiddlyElement(ul,"li",null,"listTitle",lingo.labelNoTags.format([tidd­
ler.title]));



};


//}}}

(with {{{config.options.txtEditorOnlyTag = excludeSearch;}}} in my
configOptions tiddler)


Sorry for being completely daft!

Thanks,

Scott


On Jun 23, 5:56 pm, Scott Steele <[email protected]> wrote:
> I've set up a plugin to exclude tags and tiddlers from tag and
> reference lists only when my site is in read-only mode and only then
> if the tag or tiddler is tagged with a special Editor-Only Tag, which
> indicates that that tag or tiddler is strictly backstage and should
> not be visible to the casual visitor.
>
> From the visitor's standpoint, the plugin works great. It does what it
> is supposed to do. However, when I am backstage myself and manually go
> to a tiddler with the Editor-Only Tag, I'm getting a 'macro error' in
> the tag list instead of a 'no tags' label.
>
> Here's my plugin code:
>
> //{{{
>
> config.macros.tags.handler =
> function(place,macroName,params,wikifier,paramString,tiddler)
> {
>         params = paramString.parseParams("anon",null,true,false,false);
>         var ul = createTiddlyElement(place,"ul");
>         var title = getParam(params,"anon","");
>         if(title && store.tiddlerExists(title))
>                 tiddler = store.getTiddler(title);
>         var sep = getParam(params,"sep"," ");
>         var lingo = config.views.wikified.tag;
>         var label = null;
>         for(var t=0; t<tiddler.tags.length; t++) {
>                 var tag = store.getTiddler(tiddler.tags[t]);
>                 if(!tag || !tag.tags.contains("excludeLists")) {
>                         if(!config.options.chkHttpReadOnly || !
> tag.tags.contains(config.options.txtEditorOnlyTag)) {
>                                 if(!label)
>                                         label =
> createTiddlyElement(ul,"li",null,"listTitle",lingo.labelTags.format([tiddle­r.title]));
>
> createTagButton(createTiddlyElement(ul,"li"),tiddler.tags[t],tiddler.title)­;
>                                 if(t<tiddler.tags.length-1)
>                                         createTiddlyText(ul,sep);
>                         }
>                 }
>         }
>         if(!label)
>
> createTiddlyElement(ul,"li",null,"listTitle",lingo.labelNoTags.format([tidd­ler.title]));
>
> };
>
> //}}}
>
> The only thing I did to change it from the main tags handler was to
> add this conditional mid-way down:
> {{{if(!config.options.chkHttpReadOnly || !
> tag.tags.contains(config.options.txtEditorOnlyTag)) }}}
>
> (I'm currently using excludeSearch as txtEditorOnlyTag since
> excludeSearch does a number of viewer/editor segregation chores for me
> already.)
>
> The conditional I'm trying to understand is {{{ if(!tag || !
> tag.tags.contains("excludeLists")) }}}
> It comes right after {{{ var tag =
> store.getTiddler(tiddler.tags[t]); }}}
>
> Why is !tag in there as the first part of the OR formula? It looks
> like it will never evaluate to true if there's a value for tag. It
> will evaluate to true if tag is empty, but that would mean we've gone
> through the entire tag list and are trying to keep going even though
> we're inside of a for loop based on the length of that tag list,
> right?
>
> So why is that conditional an OR formula with !tag as one of the
> components?
>
> Sorry if I'm being completely daft.
>
> Thanks,
>
> Scott

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to