Navigates to the menu page if it exists

@inner
@alias module:navigation.navigateToMenuPage

@return {Promise}      Returns a Promise that resolves upon successful navigation.
192416
function navigateToMenuPage() {

    console.log('navigating to menu...');

    return new Promise((resolve, reject) => {
        if (!menuDoc) {
            initMenu();
        }
        if (!menuDoc) {
            console.warn('No menu configuration exists, cannot navigate to the menu page.');
            reject();
        } else {
            cleanNavigate(menuDoc);
            resolve(menuDoc);
        }
    });
}
1323920
function doAfterAllPromises (params) {

          // Desctructuring:
          var $ul = params.$ul;
          var $promises = params.$promises;
          var level = params.level;
          var event = params.event;
          var leftOriented = String(params.orientation).toLowerCase() === 'left';

          $q.all($promises).then(function () {
            var topCoordinate  = event.pageY;
            var menuHeight = angular.element($ul[0]).prop('offsetHeight');
            var winHeight = $window.pageYOffset + event.view.innerHeight;

            /// the 20 pixels in second condition are considering the browser status bar that sometimes overrides the element
            if (topCoordinate > menuHeight && winHeight - topCoordinate < menuHeight + 20) {
              topCoordinate = event.pageY - menuHeight;
              /// If the element is a nested menu, adds the height of the parent li to the topCoordinate to align with the parent
              if(level && level > 0) {
                topCoordinate += event.event.currentTarget.offsetHeight;
              }
            } else if(winHeight <= menuHeight) {
              // If it really can't fit, reset the height of the menu to one that will fit
              angular.element($ul[0]).css({ 'height': winHeight - 5, 'overflow-y': 'scroll' });
              // ...then set the topCoordinate height to 0 so the menu starts from the top
              topCoordinate = 0;
            } else if(winHeight - topCoordinate < menuHeight) {
              var reduceThresholdY = 5;
              if(topCoordinate < reduceThresholdY) {
                reduceThresholdY = topCoordinate;
              }
              topCoordinate = winHeight - menuHeight - reduceThresholdY;
            }

            var leftCoordinate = event.pageX;
            var menuWidth = angular.element($ul[0]).prop('offsetWidth');
            var winWidth = event.view.innerWidth + window.pageXOffset;
            var padding = 5;

            if (leftOriented) {
              if (winWidth - leftCoordinate > menuWidth && leftCoordinate < menuWidth + padding) {
                leftCoordinate = padding;
              } else if (leftCoordinate < menuWidth) {
                var reduceThresholdX = 5;
                if (winWidth - leftCoordinate < reduceThresholdX + padding) {
                  reduceThresholdX = winWidth - leftCoordinate + padding;
                }
                leftCoordinate = menuWidth + reduceThresholdX + padding;
              } else {
                leftCoordinate = leftCoordinate - menuWidth;
              }
            } else {
              if (leftCoordinate > menuWidth && winWidth - leftCoordinate - padding < menuWidth) {
                leftCoordinate = winWidth - menuWidth - padding;
              } else if(winWidth - leftCoordinate < menuWidth) {
                var reduceThresholdX = 5;
                if(leftCoordinate < reduceThresholdX + padding) {
                  reduceThresholdX = leftCoordinate + padding;
                }
                leftCoordinate = winWidth - menuWidth - reduceThresholdX - padding;
              }
            }

            $ul.css({
              display: 'block',
              position: 'absolute',
              left: leftCoordinate + 'px',
              top: topCoordinate + 'px'
            });
          });

        }
762569
function callAction(request, response, callback) {
    if (typeof callback == 'function') {
      return Promive.resolve()
        .then(callback.bind(null, request, response));
    }

    try {
      var Action = require(ACTION_PATH + '/' + callback.action + '.js');
    } catch (error) {
      if (error.message == 'Cannot find module \'' + ACTION_PATH + '/' + callback.action + '.js\'') {
        return Promise.reject('Action ' + callback.action + ' does not exist.')
          .catch(this.onPageNotFound.bind(this, request, response));
      }
      return Promise.reject(error)
        .catch(this.onError.bind(this, request, response));
    }

    var instance = new Action(request, response);
    // Test if method exists
    if (!instance[callback.method]) {
      return Promise.reject(new Error('Method "' + callback.method + '" not found in action "' + callback.action + '"'));
    }

    var promise = Promise.resolve();
    if (instance.init && 'function' == typeof instance.init) {
      promise = promise.then(function () {
        return instance.init();
      });
    }

    promise = promise.then(function () {
      return instance[callback.method].apply(instance, callback.arguments);
    });

    if (instance.onError && 'function' == typeof instance.onError) {
      promise = promise.catch(function (error) {
        return instance.onError.call(instance, error)
      });
    }

    promise = promise.catch(this.onError.bind(this, request, response));

    return promise;
  }
680020
function Navigation(beyond, pages, events) {
        "use strict";
    
        // Set pathname as a property of the navigation object.
        pathname(this, events);
        var root = this.root;
    
        var mode = 'pushState';
        if (location.protocol === 'file:') mode = 'hash';
        else if (location.pathname.substr(location.pathname.length - 11) === '/index.html') mode = 'hash';
    
        Object.defineProperty(this, 'mode', {
            'get': function () {
                return mode;
            }
        });
    
        var active, navigating;
        Object.defineProperty(this, 'active', {
            'get': function () {
                return active;
            }
        });
    
        function updateHref(pathname, state) {
    
            var url = pathname;
            if (mode === 'hash') url = '#' + pathname.substr(1);
            if (beyond.params.local) url = root + url;
    
            history.pushState(state, '', url);
    
        }
    
        // On any change in navigation, the variable navigationID increments.
        // Helps to process only the active navigation on asynchronous calls
        // of the pages.get method & the defaultUrl function.
        var navigationID = 0;
    
        var showPage = Delegate(this, function (pathname, search, state, callback) {
    
            if (active && active.pathname === this.pathname) {
                return;
            }
    
            if (active) {
                active.hide();
                active = undefined;
            }
    
            var callID = navigationID;
    
            // showTime defines when the new active page must be shown to give the time to the previous
            // page transition to finish.
            var showTime = Date.now() + 500;
    
            pages.get(pathname, state, function (response) {
    
                if (navigationID !== callID) {
                    // This is a callback function being called from a previous page show.
                    return;
                }
    
                // Response being a string means it is an error
                if (typeof response === 'string') {
                    console.error(response);
                    return;
                }
    
                var page = response.page;
                if (!page) {
                    console.error('Page undefined');
                    return;
                }
    
                history.replaceState(response.state, '', location.href);
    
                if (callback) {
    
                    var onRendered = function () {
                        callback();
                        page.unbind('rendered', onRendered);
                    };
                    page.bind('rendered', onRendered);
    
                }
    
                active = page;
    
                page.state = response.state;
                page.search = search;
                if (!page.initialised) {
                    page.initialise();
                }
                page.show(showTime);
    
            });
    
        });
    
        var defaultUrl = Delegate(this, function (callback) {
    
            var callID = navigationID;
    
            var timer;
            setTimeout(function () {
                if (callID !== navigationID) return;
                console.error('Routing event to get the default page is taking too much time to respond.');
            }, 5000);
    
            var event = {
                'event': 'routing',
                'cancellable': true,
                'async': true
            };
    
            events.trigger(event, '/', function (response) {
    
                clearTimeout(timer);
                if (callID !== navigationID) return;
    
                if (!response) {
                    console.error('Page default is not defined.', response);
                    return;
                }
                if (typeof response !== 'object' || typeof response.pathname !== 'string' || !response.pathname) {
                    console.error('Page default is invalid.', response);
                    return;
                }
                if (response.pathname === '/') {
                    console.error('Default pathname cannot be "/". It would result in an infinity loop.', response);
                    return;
                }
    
                callback(response);
    
            });
    
        });
    
        var navigateDefaultUrl = Delegate(this, function () {
    
            if (navigating === '/') return;
    
            navigationID++;
            navigating = '/';
    
            var callID = navigationID;
    
            defaultUrl(Delegate(this, function (response) {
    
                // In case another updateDefaultUrl call was made and this one is older.
                if (callID !== navigationID) return;
    
                updateHref(response.pathname, response.state);
                updateNavigation();
    
            }));
    
        });
    
        /*
         updateNavigation takes the history.state to use as the parameters to be sent to the page.
         Remember to update the state before calling this function.
         */
        var updateNavigation = Delegate(this, function (callback) {
    
            if (navigating === this.pathname) return;
            backToHome = false;
    
            navigationID++;
            navigating = this.pathname;
    
            var search;
            if (mode === 'hash') {
                var hash = location.hash;
                search = hash.substr(hash.indexOf('?'));
            }
            else {
                search = location.search;
            }
    
            showPage(this.pathname, search, history.state, callback);
    
        });
    
        var onpopstate = Delegate(this, function () {
    
            if (this.pathname === '/') {
                navigateDefaultUrl();
            }
            else {
                updateNavigation();
            }
    
        });
    
        this.navigate = function (pathname, state) {
    
            if (pathname === '/') {
    
                if (typeof state !== 'undefined') {
                    console.warn('Parameters can not be sent to the default page.');
                }
                navigateDefaultUrl();
    
            }
            else {
                updateHref(pathname, state);
                updateNavigation();
            }
    
        };
    
        beyond.done(Delegate(this, function () {
    
            window.addEventListener('popstate', onpopstate);
    
            // Hide the splashscreen
            beyond.phonegap.done(function () {
    
                if (navigator.splashscreen) {
                    setTimeout(function () {
                        navigator.splashscreen.hide();
                    }, 1000);
                }
    
            });
    
            if (location.hash) {
    
                var pathname = location.hash.substr(1);
                if (pathname.substr(0, 1) !== '/') {
                    pathname = '/' + pathname;
                }
    
                beyond.navigate(pathname);
                return;
    
            }
    
            if (this.pathname === '/') {
                navigateDefaultUrl();
            }
            else {
                updateNavigation(function () {
    
                    // Required by phantom
                    $('body').append('<div />').attr('id', 'phantom-ready');
    
                });
            }
    
        }));
    
        var backToHome;
        Object.defineProperty(this, 'backToHome', {
            'get': function () {
                return !!backToHome;
            },
            'set': function (value) {
                // normally this property is set before the navigate,
                // the navigate cleans the backToHome
                setTimeout(function () {
                    backToHome = !!value;
                }, 0);
            }
        });
        Object.defineProperty(beyond, 'backToHome', {
            'get': function () {
                return beyond.navigation.backToHome;
            },
            'set': function (value) {
                beyond.navigation.backToHome = value;
            }
        });
    
        function back() {
            if (!backToHome && history.length) {
                history.back();
            }
            else {
                backToHome = false;
                beyond.navigate('/');
            }
        }
    
        this.back = back;
        beyond.back = back;
    
    }
483489
function topNav($menu_set=false) {
        global $CFG, $LAUNCH;
        $sess_key = 'tsugi_top_nav_'.$CFG->wwwroot;
        $launch_return_url = $LAUNCH->ltiRawParameter('launch_presentation_return_url', false);

        $same_host = false;
        if ( $CFG->apphome && startsWith($launch_return_url, $CFG->apphome) ) $same_host = true;
        if ( $CFG->wwwroot && startsWith($launch_return_url, $CFG->wwwroot) ) $same_host = true;

        // Canvas bug: launch_target is iframe even in new window (2017-01-10)
        $launch_target = LTIX::ltiRawParameter('launch_presentation_document_target', false);
        if ( $menu_set === false && $this->session_get($sess_key) ) {
            $menu_set = \Tsugi\UI\MenuSet::import($this->session_get($sess_key));
        } else if ( $menu_set === true ) {
            $menu_set = self::defaultMenuSet();
        } else if ( $same_host && $launch_return_url ) {
            // If we are in an iframe we will be hidden
            $menu_set = self::returnMenuSet($launch_return_url);
        } else if ( $launch_target !== false && strtolower($launch_target) == 'window' ) {
            $menu_set = self::closeMenuSet();
        // Since Coursers sets precious little
        } else if ( $LAUNCH->isCoursera() ) {
            $menu_set = self::closeMenuSet();
        // Since canvas does not set launch_target properly
        } else if ( $launch_target !== false && ( $LAUNCH->isCanvas() || $LAUNCH->isCoursera() ) ) {
            $menu_set = self::closeMenuSet();
        } else if ( $launch_return_url !== false ) {
            $menu_set = self::returnMenuSet($launch_return_url);
        }

        // Always put something out if we are an outer page - in an iframe, it will be hidden
        if ( $menu_set === false && defined('COOKIE_SESSION') ) {
            $menu_set = self::defaultMenuSet();
        }

        if ( $menu_set === false ) {
            $menu_set = self::closeMenuSet();
        }

        $menu_txt = self::menuNav($menu_set);
        if ( $this->buffer ) return $menu_txt;
        echo($menu_txt);
    }
1249443
function prompt(menu){
    return new Promise(function(resolve, reject){

        // user confirmation required!
        _prompt.start();
        _prompt.message = '';
        _prompt.delimiter = '';
        _prompt.colors = false;

        _prompt.get(menu, function (err, result){
            if (err){
                reject(err);
            }else{
                resolve(result);
            }
        });

    });
}
737059
def navigate(store_id, category_id, node_id)
      response = api_get("Stores.egg", "Navigation", "#{store_id}/#{category_id}/#{node_id}")
      categories = JSON.parse(response.body)
    end
232536
function(fragment, options={}) {

    // Default trigger to true unless otherwise specified
    (options.trigger === undefined) && (options.trigger = true);

    // Stringify any data passed in the options hash
    var query = options.data ? (~fragment.indexOf('?') ? '&' : '?') + $.url.query.stringify(options.data) : '';

    // Un-Mark any `active` links in the page container
    var $container = $(this.config.containers).unMarkLinks();

    // Navigate to the specified path. Return value is the value from the router
    // callback specified on the component
    var resp = Backbone.history.navigate(fragment + query, options);

    // Always return a promise. If the response of `Backbone.histroy.navigate`
    // was a promise, wait for it to resolve before resolving. Once resolved,
    // mark relevent links on the page as `active`.
    return new Promise(function(resolve, reject) {
      if(resp && resp.constructor === Promise) resp.then(resolve, resolve);
      resolve(resp);
    }).then(function(resp){
      $container.markLinks();
      return resp;
    });
  }
1162727
function _initNavigationMenuItems() {
        var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
        menu.addMenuItem(NAVIGATION_JUMP_BACK, "", Menus.AFTER, Commands.NAVIGATE_PREV_DOC);
        menu.addMenuItem(NAVIGATION_JUMP_FWD, "", Menus.AFTER, NAVIGATION_JUMP_BACK);
    }
1228910
def get_navigation(self, request, **kwargs):
        

        if self.navigation == self.parent_attr:
            if self.parent:
                return self.parent.get_navigation(request, **kwargs)
            return ()
        else:
            return self._nav_from_tuple(request, self.navigation,
                                **kwargs)
940893
function initMenu() {
    let menuCfg = defaults.menu;

    // no configuration given and neither the menu created earlier
    // no need to proceed
    if (!menuCfg && !Menu.created) {
        return;
    }

    // set options to create menu
    if (menuCfg) {
        Menu.setOptions(menuCfg);
    }

    menuDoc = Menu.get();
    Page.prepareDom(menuDoc);
}
974660
function pushDocument(doc) {
    if (!(doc instanceof Document)) {
        console.warn('Cannot navigate to the document.', doc);
        return;
    }
    navigationDocument.pushDocument(doc);
}
1067282
def on_menu(self, event):
        ''''''
        state = self.state
        # see if it is a popup menu
        if state.popup_object is not None:
            obj = state.popup_object
            ret = obj.popup_menu.find_selected(event)
            if ret is not None:
                ret.call_handler()
                state.event_queue.put(SlipMenuEvent(state.popup_latlon, event,
                                                    [SlipObjectSelection(obj.key, 0, obj.layer, obj.selection_info())],
                                                    ret))
                state.popup_object = None
                state.popup_latlon = None
        if state.default_popup is not None:
            ret = state.default_popup.popup.find_selected(event)
            if ret is not None:
                ret.call_handler()
                state.event_queue.put(SlipMenuEvent(state.popup_latlon, event, [], ret))
            
        # otherwise a normal menu
        ret = self.menu.find_selected(event)
        if ret is None:
            return
        ret.call_handler()
        if ret.returnkey == 'toggleGrid':
            state.grid = ret.IsChecked()
        elif ret.returnkey == 'toggleFollow':
            state.follow = ret.IsChecked()
        elif ret.returnkey == 'toggleDownload':
            state.download = ret.IsChecked()
        elif ret.returnkey == 'setService':
            state.mt.set_service(ret.get_choice())
        elif ret.returnkey == 'gotoPosition':
            state.panel.enter_position()
        elif ret.returnkey == 'increaseBrightness':
            state.brightness *= 1.25
        elif ret.returnkey == 'decreaseBrightness':
            state.brightness /= 1.25
        state.need_redraw = True
135031
function (navigation) {
        "use strict";
    
        var root = '';
        if (navigation.mode === 'hash') {
            root = location.pathname;
        }
        else if (beyond.params.local) {
    
            var pathname = location.pathname.split('/');
            root = [''];
    
            if (pathname[1] === 'applications') root = root.concat(pathname.splice(1, 2));
            if (pathname[1] === 'languages') root = root.concat(pathname.splice(1, 2));
    
            root = root.join('/');
    
        }
    
        Object.defineProperty(navigation, 'root', {
            'get': function () {
                return root;
            }
        });
    
        Object.defineProperty(navigation, 'pathname', {
            'get': function () {
    
                if (navigation.mode === 'hash') {
    
                    var hash = location.hash;
                    if (hash.substr(0, 1) === '#') {
                        hash = hash.substr(1);
    
                        var index = hash.indexOf('?');
                        if (index !== -1) {
                            hash = hash.substr(0, index);
                        }
                    }
                    return '/' + hash;
    
                }
    
                var pathname = location.pathname.substr(root.length);
    
                if (!pathname) pathname = '/';
                else if (pathname && pathname.substr(0, 1) !== '/') pathname = '/' + pathname;
    
                return pathname;
    
            }
        });
    
    }
523051
function updateNavButtonsState() {
            // Item navigation
            if (itemNav) {
                var isFirst = rel.activeItem === 0,
                    isLast  = rel.activeItem >= items.length - 1,
                    itemsButtonState = isFirst ? 'first' : isLast ? 'last' : 'middle';

                if (last.itemsButtonState !== itemsButtonState) {
                    last.itemsButtonState = itemsButtonState;

                    if ($prevButton.is('button,input')) {
                        $prevButton.prop('disabled', isFirst);
                    }

                    if ($nextButton.is('button,input')) {
                        $nextButton.prop('disabled', isLast);
                    }

                    $prevButton[isFirst ? 'removeClass' : 'addClass'](o.disabledClass);
                    $nextButton[isLast ? 'removeClass' : 'addClass'](o.disabledClass);
                }
            }

            // Page navigation
            if ($pages[0]) {
                var isStart = pos.dest <= pos.start,
                    isEnd = pos.dest >= pos.end,
                    pagesButtonState = isStart ? 'first' : isEnd ? 'last' : 'middle';

                // Update paging buttons only if there has been a change in their state
                if (last.pagesButtonState !== pagesButtonState) {
                    last.pagesButtonState = pagesButtonState;

                    if ($prevPageButton.is('button,input')) {
                        $prevPageButton.prop('disabled', isStart);
                    }

                    if ($nextPageButton.is('button,input')) {
                        $nextPageButton.prop('disabled', isEnd);
                    }

                    $prevPageButton[isStart ? 'removeClass' : 'addClass'](o.disabledClass);
                    $nextPageButton[isEnd ? 'removeClass' : 'addClass'](o.disabledClass);
                }
            }
        }
731131
public function menuAction()
    {
        $params     = $this->params();
        $navigation = $this->getServiceLocator()
                           ->get( 'Grid\Menu\Model\Menu\Model' )
                           ->findNavigation( $params->fromRoute( 'id' ) );

        $view = new ViewModel( array(
            'navigation' => $navigation,
        ) );

        $this->getResponse()
             ->getHeaders()
             ->addHeaderLine( 'Content-Type', 'application/xml' );

        return $view->setTerminal( true );
    }
195838
function withPromise(callback, {raf = false} = {}) {
  return new Promise((resolve, reject) => {
    if (raf) {
      requestAnimationFrame(() => {
        callback(resolve, reject);
      });
    } else {
      callback(resolve, reject);
    }
  });
}