ètica profissional video aula 1

Pré-visualização4 páginas
var globalNavMenu = {

 // how long after the menu loses focus to wait, before closing it
 MENU_CLOSE_TIMER_INTERVAL: 1000,

 // the id of the timer responsible for closing the menu
 menuCloseTimerId : null,

 // the key code for the space key
 KEY_SPACE: 32,

 ACTIVE_SECTION_KEY: "globalNavMenu:activeSection",

 /**
 * Starts a timer that closes the menu after a short interval.
 */
 initiateMenuClose : function () {
 globalNavMenu.menuCloseTimerId = setTimeout ( function() { globalNavMenu.toggleMenu(false); }, globalNavMenu.MENU_CLOSE_TIMER_INTERVAL );
 },

 /**
 * Called when the menu loses focus.
 *
 * @param event An onmouseout event
 */
 menuAbandoned: function (event) {

 // figure out where the mouse has moved to
 var target = event.toElement || event.relatedTarget;

 // if it hasn't moved anywhere within the confines of the menu or its invoking link,
 // start the process of closing it
 if ( target && target != $("global-nav-flyout") && !target.up("#global-nav-flyout") && target != $("global-nav") && !target.up("#global-nav") ) {
 globalNavMenu.initiateMenuClose();
 }
 },

 /**
 * Called when the menu gains focus
 */
 menuEntered: function () {

 // if the menu is scheduled to be closed, cancel the close
 if ( globalNavMenu.menuCloseTimerId ) {
 clearTimeout(globalNavMenu.menuCloseTimerId);
 globalNavMenu.menuCloseTimerId = null;
 }

 },

 /**
 * Initialize the menu.
 */
 init : function( toolActivityEnabled )
 {
 // initialize the tool_service
 if ( toolActivityEnabled )
 {
 window.tool_service.register ( "globalnavmenu", globalNavMenu.activityListener );
 }

 globalNavMenu.attachEventHandlers();

 if (window.matchMedia("(max-width: 1024px)").matches) {
 globalNavMenu.mobileMenuMods();
 }

 $j(window).resize(function() {
 if($j(window).width() < 1025) {
 globalNavMenu.mobileMenuMods();
 } else {
 globalNavMenu.reverseMobileMenuMods();
 }
 });
 },

 attachEventHandlers : function ()
 {
 // Since the global nav menu should open only as tall as the current size of the browser window
 // (so that users do not have to scroll to access the left-hand-side tools when there are lots of
 // them), close the global nav menu when the user resizes the browser window. Make an exception for mobile
 // browsers (ok, just Safari for now) since one cannot intentionally resize a window (though resize
 // events do fire indirectly as a consequence of user actions such as orientation change) in a mobile (iOS)
 // device.
 if ( !Prototype.Browser.MobileSafari )
 {
 Event.observe( window, "resize", function() { globalNavMenu.toggleMenu( false ); } );
 }

 Event.observe( window, "beforeunload", function() { globalNavMenu.toggleMenu( false ); } );

 // for ie only, we invoke the menu when the link is focused, because that's the only way
 // to get it to open with the accesskey -- IE fires a focus event, not a click event,
 // when the menu's access key is pressed
 if ( Prototype.Browser.IE ) {
 $("global-nav-link").observe( "focus", globalNavMenu.onNavLinkClick );
 $("global-nav-link").observe( "click", globalNavMenu.preventDefault );
 }
 else {
 $("global-nav-link").observe( "click", globalNavMenu.onNavLinkClick );
 }

 // watch for focus entering/exiting the menu or the menu header
 $("global-nav-link").observe( "mouseout", globalNavMenu.menuAbandoned );
 $("global-nav-link").observe( "mouseover", globalNavMenu.menuEntered );
 $("global-nav-flyout").observe( "mouseout", globalNavMenu.menuAbandoned );
 $("global-nav-flyout").observe( "mouseover", globalNavMenu.menuEntered );
 $("global-nav-flyout").observe( "click", window.welcomeOverlay.closeOverlay );

 // attach event handlers to the bottom buttons
 $$(".bottom-buttons a").each( function ( bottomButton ) {

 // keyboard navigation for the bottom buttons
 bottomButton.observe( "keydown", function(event) {

 var key = event.keyCode;

 switch (key) {

 // down takes you to the next button over
 case Event.KEY_DOWN:
 var nextButton = this.up("li").next();
 if (nextButton) {
 nextButton.down("a").focus();
 }
 event.stop();
 break;

 // up takes you to the previous button, or the previous section if we're already
 // at the leftmost extent of the button area
 case Event.KEY_UP:

 // if this is the first button, jump back up the last section
 if ( this == $$(".bottom-buttons a:first").first() ) {

 var lastSection = $$(".accordion-wrapper div.accordion_toggle:last").first();
 if ( lastSection ) {
 lastSection.focus();
 }
 }

 // otherwise, move to the previous button
 else {
 this.up(0).previous('li', 0).down('a', 0).focus();
 }

 event.stop();

 break;
 case Event.KEY_TAB:

 // if this is the last button, close the menu
 if ( this == $$(".bottom-buttons a:last").first() ) {
 globalNavMenu.keyboardCloseMenu();
 event.stop();
 }

 break;

 }

 });

 });

 // keyboard navigation for the menu
 $("global-nav-flyout").observe( "keydown", function(event) {

 var key = event.keyCode;

 if (key === Event.KEY_ESC ) {
 // escape closes the menu
 globalNavMenu.keyboardCloseMenu();
 }

 });

 $("topframe.logout.label").observe( "click", function(event){
 ClientCache.clear();
 });
 },

 attachEventHandlersInsideFlyout : function ()
 {
 // watch for menu rail shortcut clicks
 $$("#global-list-tools a").each( function( shortcut ) {
 if ( !shortcut.onclick ) {
 shortcut.observe( "click", globalNavMenu.onShortcutClick );
 }
 });

 // attach event handlers to section headers
 $$(".accordion_toggle").each( function( sectionHeader ) {

 // open/close the section when its header is clicked
 sectionHeader.observe( "click", globalNavMenu.onSectionClick );

 // watch for keyboard events on the section headers
 sectionHeader.observe( "keydown", function (event) {

 var contentArea = this.down();

 var sectionId = contentArea.readAttribute( "data-section-id" );
 var sectionUri = contentArea.readAttribute( "data-section-uri" );

 var sectionContent = $(sectionId+'-content');
 var sectionTitle = $(sectionId+'-title');

 // TODO is there a more generic way to do this
 var key = event.keyCode;

 switch (key) {

 // open the section
 case Event.KEY_RETURN:
 case Event.KEY_RIGHT:
 case globalNavMenu.KEY_SPACE:

 if ( !sectionContent.visible() ) {
 globalNavMenu.openSection( sectionContent, sectionUri );
 }

 globalNavMenu.focusFirstSectionLink(sectionContent);

 event.stop();
 break;

 // move focus to the next section header
 case Event.KEY_DOWN:

 var nextToggle = sectionTitle.next(".accordion_toggle");

 // if there's another section below us
 if ( nextToggle ) {
 nextToggle.focus();
 }

 // otherwise, we're at the bottom of the section area
 else {
 $('topframe.home.label').focus();
 }

 event.stop();

 break;

 // focus the previous