This topic needs a title

Hello Weaver and anyone else who can recall this…
Just a quick question some time ago weaver gave an example of an action that looks to see if another instance of that same action has written to the html document and if it finds it, it then does not add to it. I suppose it’s a bit like the old once-before-end-head, but it allowed for variations of the action content to be published but an exact duplicate would be ignored.

Can any one remember what it was called or a reference to it. I think it was written way back before this version of the forum was setup so it may not be available any more… anyway if anyone knows, it would be handy, or if any one recalls something similar to this, then anything would be handy…
all the best max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

All of the content from the previous phpBB forum was imported into
this system when we flipped the switch. The formatting may be a little
(okay, a lot) weird, but you should still be able to read the text…

Walter

On May 18, 2009, at 12:04 PM, max wrote:

I think it was written way back before this version of the forum was
setup so it may not be available any more…


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,

Do you want to run some code once and only once, regardless of how
many instances of the Action are on the page/in the document? You can
do this by setting a page or document flag. First, check if the flag
has been set, of not run the code and then set the flag. The flag can
be set by using:

fwPage.whatever = value;

Or

fwDocument.whatever = value;

Where whatever is whatever you want the flag to be called and the
value can be anything from a primitive to an object (I usually just
use true or false).

Hope this helps,

Joe

On 18 May 2009, at 17:04, max wrote:

Hello Weaver and anyone else who can recall this…
Just a quick question some time ago weaver gave an example of an
action that looks to see if another instance of that same action has
written to the html document and if it finds it, it then does not
add to it. I suppose it’s a bit like the old once-before-end-head,
but it allowed for variations of the action content to be published
but an exact duplicate would be ignored.

Can any one remember what it was called or a reference to it. I
think it was written way back before this version of the forum was
setup so it may not be available any more… anyway if anyone knows,
it would be handy, or if any one recalls something similar to this,
then anything would be handy…
all the best max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Jo Walt and Tim

As usual I didn’t make it very clear, so just to be sure I thought I better paste what I am up to.
This is part of what I have been using up till now on one of the actions, and it’s worked, though for some time I have been thinking it’s been a little crude… It would be better if it could distinguish between the same action, with the same style sheet reference and the same action with a different style sheet reference. The ones that are duplicated would be only referenced a single time and the ones with a unique reference would add there reference.

function fwBeforeEndBody(){
// extra style sheet reference for this item
var headTag = fwDocument.fwTags.fwFind('head');
if (fwParameters["Enable"].fwBoolValue)
headTag.fwAddRawln('<style type="text/css">@import url("'+ fwParameters["param1"] + '");</style>');
} 

Tim now you have mentioned I do recall the example you mention some where in either a tech note or more likely in the js manual or so I will have a look to see if i can find that.

I still cant find the weaver example
… I thought I was positive about it being weaver’s but may be my marbles have gone and my poor memory is I just making it up.
Anyway thanks for the pointers Joe Tim and Walter

All the best max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
If I understand your need correctly then I’d suggest holding an array
in the document object with a reference to all of the styles. My Mals
actions do pretty much the same sort of thing and use this area to
hold product information that can then be added to, modified or even
destroyed later in the publishing process. Only at the end of the
publish cycle does the action actually write the code to the tag
stream. This is a lot more efficient (IMHO) than writing the code to
the tag stream and then having to rewrite it should another action
need to amend the code.
Anyway, back to your problem. Here’s what I would do;

//create an array in the document object if one doesn’t already exist
if (!fwDocument.stylesarray){
//create the array
fwDocument.stylesarray = new Array();
}
//get a pointer to the array
var mystylesarray = fwDocument.stylesarray;

//look for the instance of the style in the array and if not found
then add it
if (mystylesarray.indexOf(‘mystyle’) > -1){
//add the style to the array
fwDocument.stylesarray.push(‘mystyle’);
}

//then you can pull the data from the array when you need to publish
the page styles
for (var i=0; i < mystylesarray.length; i++){
var thisStyle = mystylesarray[i];
headTag.fwAddRawln(‘@import url("’+
thisStyle + ‘");’);
}

All of the above is completely untested but it should work - maybe! :slight_smile:
All the best,
Tim.

On 18 May 2009, at 12:41, max wrote:

Hi Jo Walt and Tim

As usual I didn’t make it very clear, so just to be sure I thought I
better paste what I am up to.
This is part of what I have been using up till now on one of the
actions, and it’s worked, though for some time I have been thinking
it’s been a little crude… It would be better if it could
distinguish between the same action, with the same style sheet
reference and the same action with a different style sheet
reference. The ones that are duplicated would be only referenced a
single time and the ones with a unique reference would add there
reference.

function fwBeforeEndBody(){
// extra style sheet reference for this item
var headTag = fwDocument.fwTags.fwFind(‘head’);
if (fwParameters[“Enable”].fwBoolValue)
headTag.fwAddRawln(‘@import url("’+
fwParameters[“param1”] + ‘");’);
}

Tim now you have mentioned I do recall the example you mention some
where in either a tech note or more likely in the js manual or so I
will have a look to see if i can find that.

I still cant find the weaver example
… I thought I was positive about it being weaver’s but may be
my marbles have gone and my poor memory is I just making it up.
Anyway thanks for the pointers Joe Tim and Walter

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Tim Joe and Walter
After a bit of mucking about I have managed to cobble something that now checks to see if the action with the same settings has already been used on another item and if so it wont add the new style sheet reference to the head tag

Again thanks for all the pointers, code snippets and time.
All the best max :o)


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How did to manage it in the end Max? Did you hold the data in a global
array or check the other action’s settings at runtime? Or maybe some
other way.
I’m interested to know how you tackled this.
Regards,
Tim.

On 19 May 2009, at 06:24, max wrote:

Hi Tim Joe and Walter
After a bit of mucking about I have managed to cobble something that
now checks to see if the action with the same settings has already
been used on another item and if so it wont add the new style sheet
reference to the head tag

Again thanks for all the pointers, code snippets and time.
All the best max :o)

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Tim
All I can say is it works… its a bloody mess and by trial and error, rereading everything a million times… even resorting to kicking things about the room, I have something that finally works… I am not sure what you call it (complicated) it sure feels complicated.

The problems I was having was being able to turn this function on and off It’s part of another action and this is an optional feature.
Anyway quite a few hours later and after many different variants. This is what I have ended up with.

function isActive(){
var active = fwParameters["Activate"].fwBoolValue;
return active;
}

function fwInterface()
{
for (var i=1; i < fwParameters.fwLength; i++)
{
fwParameters[i].fwEnable = isActive(); // Enable style sheet addition

var enabled = fwParameters["Enable"].fwBoolValue;
fwParameters["param1"].fwEnable = enabled; }
}

function fwBeforeEndBody() { var docHead = fwDocument.fwTags.fwFind('head'); 
if(!docHead) return false;
if (fwParameters["Enable"].fwBoolValue)
if(!fwPage['<style type="text/css">@import url("'+ fwParameters["param1"] + '");</style>']) { //checks to see if any other action has added the code and the exact settings
fwPage['<style type="text/css">@import url("'+ fwParameters["param1"] + '");</style>'] = docHead.fwAddRawln('<style type="text/css">@import url("'+ fwParameters["param1"] + '");</style>');}

// check to see if active button is on and if it is add the other script
 if (isActive()){
var theItem = fwDocument.fwTags.fwFind(fwItem,'');
var theDiv = theItem.fwEnclosing;
theItem.fwDelete();
var theContent = theDiv.fwAddRaw('<?php more webyep code ?>') // webyep item added here
	}
}

As you can see its a bit more complicated than I had hoped for though not quite as messy in real life. The code view above seems to have lost some of the returns

If you see any glaring whopper mistakes then I would be more than happy to know
all the best and thanks for the help
max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
Well the first thing to remember is that it works so well done on
that. If you can walk away from a project knowing that it does the job
then you’ve achieved your goal.
I think there are a couple of things you could improve if you wanted
to revisit this at some point.

  1. The second part of the fwInterface section that controls ‘Enable’
    needs to be affected by the ‘Activate’ control. At the moment ‘param1’
    will stay enabled regardless of the state of ‘Activate’ as long as
    ‘Enable’ is checked. You’ll find that ‘Enable’ can be checked (which
    enables ‘param1’) and even though ‘Activate’ is unchecked ‘param1’
    will stay active.
    Here’s a slight reshuffle of your code with a few comments thrown in
    for good measure;
    http://pastie.org/483678

Notice how the enabling/disabling of ‘param1’ has been taken out of
the fwParameters loop? We only need to set the control once. The
control now is enabled only if ‘Enable’ and ‘Activate’ are enabled
(checked).

  1. In fwBeforeEndBody you check to see if the style has already been
    applied to the page by checking the page object which looks like it
    would work well. However, on the next line you apply the style and
    update the page object not knowing if the following php insertion is
    going to work or not. If it fails then you’ll be left with a redundant
    stylesheet in the doc head. This may not be a major problem but other
    instances of the action will check to see if the style exists and will
    move on.
    Your logic should ideally follow this sort of flow;
    a. Have we already applied this style before on this page?
    b. If not apply the style
    c. If we have then do nothing
    d. If we applied the new style to the page then update the page object
    so we can use this as a checklist later for other actions

If you look at the modified version of the function at http://pastie.org/483678
you’ll see that adding the css style is the almost the last thing
that happens. If the action fails to locate the page head, div or
locates another style of the same type then the style isn’t applied.
The thing I always try and remember is that if the action has to bail
out at any moment will there be things that need to be tidied up
before I can leave the page as I found it. If I can structure the code
to only apply changes if all of the conditions are met then I should
be OK. What you don’t want is to have the action apply partial code
that may leave the page in a ‘half baked’ state.

Other than moving a couple of things around I think your code was in
pretty good shape. You may want to consider swapping out the
fwAddRawln lines for the more verbose, but searchable, fwAdd or
fwAddEnclosing. Doing so will allow your content to show up in the tag
stream so that other actions can mess up your nicely placed code! :slight_smile:
All the best,
Tim.

On 19 May 2009, at 15:26, max wrote:

Hi Tim
All I can say is it works… its a bloody mess and by trial and
error, rereading everything a million times… even resorting to
kicking things about the room, I have something that finally
works… I am not sure what you call it (complicated) it sure feels
complicated.

The problems I was having was being able to turn this function on
and off It’s part of another action and this is an optional feature.
Anyway quite a few hours later and after many different variants.
This is what I have ended up with.

function isActive(){
var active = fwParameters[“Activate”].fwBoolValue;
return active;
}

function fwInterface()
{
for (var i=1; i < fwParameters.fwLength; i++)
{
fwParameters[i].fwEnable = isActive(); // Enable style sheet
addition

var enabled = fwParameters[“Enable”].fwBoolValue;
fwParameters[“param1”].fwEnable = enabled; }
}

function fwBeforeEndBody() { var docHead =
fwDocument.fwTags.fwFind(‘head’);
if(!docHead) return false;
if (fwParameters[“Enable”].fwBoolValue)
if(!fwPage[‘@import url("’+
fwParameters[“param1”] + ‘");’]) { //checks to see if any
other action has added the code and the exact settings
fwPage[‘@import url("’+
fwParameters[“param1”] + ‘");’] =
docHead.fwAddRawln(‘@import url("’+
fwParameters[“param1”] + ‘");’);}

// check to see if active button is on and if it is add the other
script
if (isActive()){
var theItem = fwDocument.fwTags.fwFind(fwItem,‘’);
var theDiv = theItem.fwEnclosing;
theItem.fwDelete();
var theContent = theDiv.fwAddRaw(‘<?php more webyep code ?>’) //
webyep item added here
}
}

As you can see its a bit more complicated than I had hoped for
though not quite as messy in real life. The code view above seems to
have lost some of the returns

If you see any glaring whopper mistakes then I would be more than
happy to know
all the best and thanks for the help
max

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Tim
A big thank you for looking at what I had done
I had completely missed the enable still being enabled even if active was off and your suggestion worked perfectly.
Looking at what you have done it certainly looks a lot cleaner than mine and the way you have described the baking process, does make it a heck of lot clearer… in fact I have printed my version and yours, plus the description above, and added it to my Freeway js reference manual so I can refere back to it and compare when I forget how to tackle the general structure.

One thing I did notice was, as I was playing around with your script was that the enable turns off the other parts of the action which should be just effected by the isActive checkbox and I couldn’t work out how to stop that doing it. So I started to implemented your suggestion of only allowing the param1 to be active only if the Enable and the Active checkboxs are clicked on. Even though its working I do take your point about mine being in the wrong order etc so if you do get any free time it would be nice to see how it should be done, rather than my wrong order version… again thanks for all the time you have taken and the examples.

All the best max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
Sorry for the delayed reply- busy, busy, busy!
I’m going to be busy on other things over the weekend but if you can
get me either this action or a sample framework then I’ll happily
adjust it for you as an example. Just shoot me the action and what you
want the UI functionality to do and I’ll give it a stab early next week.
Regards,
Tim.

On 20 May 2009, at 08:53, max wrote:

Hi Tim
A big thank you for looking at what I had done
I had completely missed the enable still being enabled even if
active was off and your suggestion worked perfectly.
Looking at what you have done it certainly looks a lot cleaner than
mine and the way you have described the baking process, does make it
a heck of lot clearer… in fact I have printed my version and
yours, plus the description above, and added it to my Freeway js
reference manual so I can refere back to it and compare when I
forget how to tackle the general structure.

One thing I did notice was, as I was playing around with your script
was that the enable turns off the other parts of the action which
should be just effected by the isActive checkbox and I couldn’t work
out how to stop that doing it. So I started to implemented your
suggestion of only allowing the param1 to be active only if the
Enable and the Active checkboxs are clicked on. Even though its
working I do take your point about mine being in the wrong order etc
so if you do get any free time it would be nice to see how it
should be done, rather than my wrong order version… again thanks
for all the time you have taken and the examples.

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi tim its fine no problem.
I know what you mean when you say you are really busy… I have the actions working so its not a problem and I will stick with what I’ve got for now. But if you wanted to know what the problem was (for reference) the problem was with the script you uploaded to http://pastie.org/483678
I think when I tested it the enable checkbox also disabled everything else too, though from what I can recall it was only on publish and not in the actual interface.
Anyway as I said don’t worry as I have my old script with a few tweaks which were cribbed from your example.

Cheers and all the best…
Max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options