Source Code

for file /controls/Menubar.js

// Menubar.js
// Javascript Behaviour for the Menubar Control
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// ----- 
// 24.04.2007 created by Matthias Hertel
// this is a basic behavior definition for menubars
// 17.06.2007 OpenAjax event publishing added.
// 12.07.2007 no event is fired when the element is disabled.
// 15.09.2007 now using jcl.BuildFullEventname.
// 05.01.2008 documentation added.
// 19.11.2016 simplified by using HTML5 compatible implementation.

var MenubarBehavior = {
  /// <summary>This JavaScript behavior implements a menubar functionality that publishes OpenAjax events.</summary>

  init: function () {
    /// <summary>Initialize the Menubar control.
    /// Disable the focus mechanism for all menuitems.</summary>
    var o = this.firstElementChild;
    while (o != null) {
      o.setAttribute("unselectable", "on");
      o = o.nextElementSibling;
    } // while()
  }, // init


  onclick: function (evt) {
    /// <summary>If an event attribute is pressent then start the event by using the OpenAjax hub publishing mechanism.</summary>
    evt = evt || window.event;
    var t = evt.target || evt.srcElement;
    var cmd = jcl.BuildFullEventname(t);
    if ((cmd) && (t.className.indexOf("disabled") < 0)) {
      cmd = cmd.split(';');
      OpenAjax.hub.publish(cmd[0], cmd[1]);
    } // if
  } // onclick

}; // MenubarBehavior


This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.