/** * @namespace WORKAREA.adminToolbar */ WORKAREA.registerModule('adminToolbar', (function () { 'use strict'; var focusSearch = function ($toolbar) { var $scope = $toolbar.contents(); $('#primary_nav_admin_search', $scope).trigger('focus'); }, collapse = function ($toolbar) { var $header = $('.header', $toolbar.contents()); $toolbar.removeClass('admin-toolbar--expanded'); $header.removeClass('header--takeover'); }, expand = function ($toolbar) { var $header = $('.header', $toolbar.contents()); $toolbar.addClass('admin-toolbar--expanded'); $header.addClass('header--takeover'); }, bindEscapeKey = function ($toolbar) { var toolbarWindow = $toolbar[0].contentWindow; $(toolbarWindow).on('keyup.adminToolbar', function (event) { if (event.keyCode !== 27) { return; } // only care about escape collapse($toolbar); }); }, bindTakeoverToggle = function ($toolbar) { var $scope = $toolbar.contents(), triggerSelectors = [ '.header__search-form', '.header__menu-button' ].join(','); $(triggerSelectors, $scope).on('click', function (event) { event.preventDefault(); if ($(event.currentTarget).is('.header__menu-button--close')) { collapse($toolbar); } else { expand($toolbar); focusSearch($toolbar); } }); return $toolbar; }, notify = function ($toolbar) { $(window).trigger('adminToolbar:loaded'); return $toolbar; }, url = function () { var globalId = $('meta[property="global-id"]').attr('content'), params = {}; params.return_to = window.location.href; if (globalId) { params.id = globalId; } return '/admin/toolbar?' + $.param(params); }, shouldDisplay = function (user) { return user.impersonating || user.browsing_as_guest || (user.admin && user.logged_in); }, create = function (user) { if ( ! shouldDisplay(user)) { return; } $('