[Pro] Writing a simple action that doesn't have a surrounding div

I’m trying to get into learning how to write actions to perform simple tasks and have written this super simple one as an example. But I am wondering how I can modify it to remove the surrounding div that get’s generated?

PHP Date <?php echo date("Y") ?>

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

First, make sure you have inserted your Action inline within a run of text in an HTML box. As far as I know, an Action will only emit a surrounding DIV tag if it was drawn in place on the page. It has to, in order to create a positionable object so it doesn’t end up in the top-left corner of the page.

For future reference, you may want to step into the deep end of the pool of Action authoring.

What you have here is how the Actions in Freeway 2 (where the Actions API first arrived) were written. When Freeway 3 introduced the <action-javascript> mechanism, that’s when things became much more interesting. In that format, you define exactly what tag you want to build and programmatically build it up.

If you wanted this to be in a <time> tag, then you could do that. If you wanted it to just appear inline without a surrounding wrapper, you could do that as well. Here’s the former:

<action-encoding>UTF-8</action-encoding>
<action name="PHP Date" width=60 height=15>
<action-version version="1.0">
PHP Date
</action-version>
<action-javascript>
function fwBeforeEndBody(){
  var thisItem = fwDocument.fwTags.fwFind(fwItem); // a reference to the Action itself
  // the code you will add
  var date = '<time datetime="<?php echo date("c", strtotime(date("Y"))); ?>"><?php echo date("Y"); ?></time>';
  // add the code to the action
  thisItem.fwAddRaw(date);
}
</action-javascript>
</action>

Obviously, you could just thisItem.fwAddRaw('<?php echo date("Y"); ?>') if you really only wanted the string in its non-semantic form.

It’s important to note that this may only work as written in Freeway 7 and only because you have declared the dimensions of your action-item. There was a bug in Freeway 6 (I am not sure if it was ever fixed there) where the Action would always insert a tag for the action itself within a run of code. If the Action was inserted in a run of text, this tag was always a span, however, never a div. If you remove the dimensions, then the action-item becomes resizable (starting at 100px square, usually) and then will always emit a surrounding tag, unless you took pains to remove it. That technique would look like this:

function fwBeforeEndBody(){
  var thisItem = fwDocument.fwTags.fwFind(fwItem); // a reference to the Action itself
  // wrap it with a "null" tag:
  var dummy = thisItem.fwAddEnclosing('', true);
  var date = '<time datetime="<?php echo date("c", strtotime(date("Y"))); ?>"><?php echo date("Y"); ?></time>';
  // add the code to the dummy wrapper
  dummy.fwAddRaw(date);
  // remove the action-item itself
  thisItem.fwDelete();
}

Walter

On Jan 24, 2015, at 5:25 AM, Sly email@hidden wrote:

I’m trying to get into learning how to write actions to perform simple tasks and have written this super simple one as an example. But I am wondering how I can modify it to remove the surrounding div that get’s generated?

PHP Date <?php echo date("Y") ?>

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