<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
-->
<Module>
<ModulePrefs title="Sample Action Runner"
             height="250">
<Require feature="actions"></Require>
<Require feature="selection"></Require>
</ModulePrefs>
<Content type="html">
<![CDATA[
<script>
var selection;
gadgets.selection.addListener(
  function(s){selection = s;}
);

function runAction() {
  id = document.getElementById('action_id_field').value;
  gadgets.actions.runAction(id, selection);
}

function showActions(actions) {
  var a = document.createElement("a");
  a.href="#";
  a.onclick = function() {
    gadgets.actions.runAction(actions[0].id);
  };
  var t = document.createTextNode(actions[0].label);
  a.appendChild(t);
  a.id = actions[0].id;
  var m = document.getElementById("menu")
  if (m.childNodes.length > 0) {
    var s = document.createTextNode(" | ");
    m.appendChild(s);
  }
  m.appendChild(a);
}

function hideActions(actions) {
  var m = document.getElementById("menu");
  while (m.childNodes.length > 0) 
    m.removeChild(m.childNodes[0]);
}

gadgets.actions.registerShowActionsListener(showActions);
gadgets.actions.registerHideActionsListener(hideActions);

</script>
<div id="menu"></div>

<div>
<input type="text" id="action_id_field">
<input type="button" value="Run Action" onclick="runAction()"/>
</div>
]]>
</Content>
</Module>
