Best JavaScript code snippet using puppeteer
navigationPanel.js
Source:navigationPanel.js
1VisualDeveloper.NavigationPanel = {2 visualDeveloperInstance : {},3 _lang : {4 panelOptionGlobal : "Select Structure Based Elements",5 panelOptionGlobalClass : "Select Structure Class Smart Based Elements",6 panelOptionCurrent : "Current Element",7 panelOptionParentElement : "Parent Element",8 panelOptionReset : "Reset",9 panelOptionAdvancedCreation : "Advanced Creation",10 panelOptionGlobalIcon : "panel-option-structure",11 panelOptionGlobalClassIcon : "panel-option-structure-class",12 panelOptionCurrentIcon : "panel-option-current",13 panelOptionParentElementIcon : "panel-option-parent",14 panelOptionResetIcon : "panel-option-reset",15 panelOptionActiveIcon : "panel-option-active",16 panelOptionAdvancedCreationIcon : "panel-option-advanced-creation",17 userActionNotificationGlobal : "<strong>Start customizing</strong>, similar elements have been easily matched.",18 userActionNotificationGlobalClass : "<strong>Start customizing</strong>, similar elements have been smartly matched.",19 userActionNotificationCurrent : "<strong>Start customizing</strong> your current element",20 userActionNotificationParentElement : false,21 userActionNotificationReset : "The previous element is no longer selected, please chose a different one."22 },23 _settings : {24 navigationNamespace : '-navigation-panel',25 navigationArrangeEvents : 'scroll resize',26 navigationPanelID : 'navigation-panel',27 navigationPanelToolBarClass : 'navigation-panel-toolbar',28 navigationOptionGlobalID : 'navigation-panel-option-global',29 navigationOptionGlobalClassID : 'navigation-panel-option-global-class',30 navigationOptionCurrentID : 'navigation-panel-option-current',31 navigationOptionParentElementID : 'navigation-panel-option-parent-element',32 navigationOptionAdvancedCreationID : 'navigation-panel-option-advanced-creation',33 navigationOptionResetID : 'navigation-panel-option-reset',34 navigationOptionIndicatorEvent : 'mouseenter',35 navigationOptionIndicatorCloseEvent : 'mouseleave',36 navigationOptionSelectEvent : 'click'37 },38 currentNavigationPanelObject : false,39 currentNavigationJQueryDOMElement : false,40 currentNavigationMirrorJQueryDOMElement : false,41 currentNavigationPanelOptionCurrent : false,42 currentNavigationPanelOptionGlobal : false,43 currentNavigationPanelOptionParentElement : false,44 currentNavigationPanelOptionReset : false,45 currentNavigationPanelOptionAdvancedCreation : false,46 Init : function(visualDeveloperInstance) {47 this.visualDeveloperInstance = visualDeveloperInstance;48 this._initDependencies();49 },50 _initDependencies : function() {51 this._settings.navigationNamespace = this.visualDeveloperInstance.namespace + this._settings.navigationNamespace;52 this._settings.navigationArrangeEvents = this._settings.navigationArrangeEvents53 .replace(/ /g, '.' + this._settings.navigationNamespace + ' ') +54 '.' + this._settings.navigationNamespace + ' ';55 this._settings.navigationOptionIndicatorEvent = this._settings.navigationOptionIndicatorEvent56 .replace(/ /g, '.' + this._settings.navigationNamespace + ' ') +57 '.' + this._settings.navigationNamespace + ' ';58 this._settings.navigationOptionIndicatorCloseEvent = this._settings.navigationOptionIndicatorCloseEvent59 .replace(/ /g, '.' + this._settings.navigationNamespace + ' ') +60 '.' + this._settings.navigationNamespace + ' ';61 this._settings.navigationOptionSelectEvent = this._settings.navigationOptionSelectEvent62 .replace(/ /g, '.' + this._settings.navigationNamespace + ' ') +63 '.' + this._settings.navigationNamespace + ' ';64 this._prefixCSSSettings();65 },66 _prefixCSSSettings : function() {67 this._settings = this.visualDeveloperInstance.PrefixNonEventSettings(68 this._settings, this.visualDeveloperInstance.styleNamespace);69 },70 ActivateNodeInstance : function(jQueryDOMElement) {71 this._clearCurrentNavigationJQueryDOMElement();72 this.currentNavigationJQueryDOMElement = jQueryDOMElement;73 this.visualDeveloperInstance.Navigation.MarkNavigationVisualSelectedElement(jQueryDOMElement);74 this.triggerNodeInstancePanel();75 },76 triggerNodeInstancePanel : function() {77 var objectInstance = this;78 jQuery('body').append(this._getPanelHTML());79 this.currentNavigationPanelObject = jQuery('#' + this._settings.navigationPanelID);80 this.currentNavigationPanelOptionParentElement = jQuery('#' + this._settings.navigationOptionParentElementID);81 this.currentNavigationPanelOptionCurrent = jQuery('#' + this._settings.navigationOptionCurrentID);82 this.currentNavigationPanelOptionGlobal = jQuery('#' + this._settings.navigationOptionGlobalID);83 this.currentNavigationPanelOptionGlobalClass = jQuery('#' + this._settings.navigationOptionGlobalClassID);84 this.currentNavigationPanelOptionReset = jQuery('#' + this._settings.navigationOptionResetID);85 this.currentNavigationPanelOptionAdvancedCreation = jQuery('#' + this._settings.navigationOptionAdvancedCreationID);86 this._arrangePanel();87 this._assignPanelAction();88 jQuery(window).bind(this._settings.navigationArrangeEvents, function(){89 objectInstance._arrangePanel();90 });91 if(this.currentNavigationJQueryDOMElement.is("body")) {92 objectInstance._enableElementPanelOnPattern("body");93 }94 },95 _getPanelHTML : function() {96 var panelHTML = '';97 panelHTML += '<div id="' + this._settings.navigationPanelID + '">';98 panelHTML += '<div class="' + this._settings.navigationPanelToolBarClass + '">';99 panelHTML += '<span id="' + this._settings.navigationOptionResetID + '"' +100 'class="icon ' + this._lang.panelOptionResetIcon + ' hint--primary hint--top" data-hint="' + this._lang.panelOptionReset + '"' +101 '> </span>';102 panelHTML += '<span id="' + this._settings.navigationOptionParentElementID + '"' +103 'class="icon ' + this._lang.panelOptionParentElementIcon + ' hint--primary hint--top" data-hint="' + this._lang.panelOptionParentElement + '"' +104 '> </span>';105 panelHTML += '<span id="' + this._settings.navigationOptionCurrentID + '"' +106 'class="icon ' + this._lang.panelOptionCurrentIcon + ' ' +107 (this.visualDeveloperInstance.ElementPanel108 .HasPattern(this.visualDeveloperInstance.GetElementAbsolutePath(this.currentNavigationJQueryDOMElement))109 ? this._lang.panelOptionActiveIcon + ' ' : ''110 ) +111 ' hint--primary hint--top" ' +112 'data-hint="' + this._lang.panelOptionCurrent + '"' +113 '> </span>';114 panelHTML += '<span id="' + this._settings.navigationOptionGlobalID + '"' +115 'class="icon ' + this._lang.panelOptionGlobalIcon + ' ' +116 (this.visualDeveloperInstance.ElementPanel117 .HasPattern(this.visualDeveloperInstance.GetElementGenericPath(this.currentNavigationJQueryDOMElement))118 ? this._lang.panelOptionActiveIcon + ' ' : ''119 ) +120 ' hint--primary hint--top" ' +121 'data-hint="' + this._lang.panelOptionGlobal + '"' +122 '> </span>';123 panelHTML += '<span id="' + this._settings.navigationOptionGlobalClassID + '"' +124 'class="icon ' + this._lang.panelOptionGlobalClassIcon + ' ' +125 (this.visualDeveloperInstance.ElementPanel126 .HasPattern(this.visualDeveloperInstance.GetElementGenericPath(this.currentNavigationJQueryDOMElement, false))127 ? this._lang.panelOptionActiveIcon + ' ' : ''128 ) +129 ' hint--primary hint--top" ' +130 'data-hint="' + this._lang.panelOptionGlobalClass + '"' +131 '> </span>';132 panelHTML += '<span id="' + this._settings.navigationOptionAdvancedCreationID + '"' +133 'class="icon ' + this._lang.panelOptionAdvancedCreationIcon + ' hint--primary hint--top" ' +134 'data-hint="' + this._lang.panelOptionAdvancedCreation + '"' +135 '> </span>';136 panelHTML += '<span class="' + this.visualDeveloperInstance._settings.clearClass + '"></span>';137 panelHTML += '</div>';138 panelHTML += '</div>';139 return panelHTML;140 },141 _assignPanelAction : function() {142 var objectInstance = this;143 jQuery(this.currentNavigationPanelOptionParentElement).bind(this._settings.navigationOptionSelectEvent, function(event){144 event.preventDefault();145 event.stopImmediatePropagation();146 if(objectInstance._lang.userActionNotificationParentElement !== false) {147 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(objectInstance._lang.userActionNotificationParentElement);148 } else {149 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(150 objectInstance.visualDeveloperInstance.GetElementAbsolutePath(151 objectInstance.currentNavigationJQueryDOMElement.parent()152 )153 );154 }155 objectInstance.ActivateNodeInstance(objectInstance.currentNavigationJQueryDOMElement.parent());156 });157 jQuery(this.currentNavigationPanelOptionReset).bind(this._settings.navigationOptionSelectEvent, function(event){158 event.preventDefault();159 event.stopImmediatePropagation();160 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(objectInstance._lang.userActionNotificationReset);161 objectInstance.visualDeveloperInstance.Navigation.OpenNavigation();162 });163 jQuery(this.currentNavigationPanelOptionCurrent).bind(this._settings.navigationOptionSelectEvent, function(event){164 event.preventDefault();165 event.stopImmediatePropagation();166 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(objectInstance._lang.userActionNotificationCurrent);167 objectInstance._enableElementPanelOnPattern(objectInstance.visualDeveloperInstance.GetElementAbsolutePath(objectInstance.currentNavigationJQueryDOMElement));168 });169 jQuery(this.currentNavigationPanelOptionCurrent).bind(this._settings.navigationOptionIndicatorEvent, function(event){170 event.preventDefault();171 event.stopImmediatePropagation();172 var currentPattern = objectInstance.visualDeveloperInstance.GetElementAbsolutePath(objectInstance.currentNavigationJQueryDOMElement),173 currentObject = jQuery(currentPattern);174 currentObject.not(objectInstance.currentNavigationJQueryDOMElement);175 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(currentPattern);176 objectInstance._highlightNavigationMirrorJQueryDOMElement(currentObject);177 });178 jQuery(this.currentNavigationPanelOptionCurrent).bind(this._settings.navigationOptionIndicatorCloseEvent, function(event){179 event.preventDefault();180 event.stopImmediatePropagation();181 objectInstance._clearCurrentNavigationMirrorJQueryDOMElement();182 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(" ");183 });184 jQuery(this.currentNavigationPanelOptionGlobal).bind(this._settings.navigationOptionSelectEvent, function(event){185 event.preventDefault();186 event.stopImmediatePropagation();187 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(objectInstance._lang.userActionNotificationGlobal);188 objectInstance._enableElementPanelOnPattern(objectInstance.visualDeveloperInstance.GetElementGenericPath(objectInstance.currentNavigationJQueryDOMElement));189 });190 jQuery(this.currentNavigationPanelOptionGlobal).bind(this._settings.navigationOptionIndicatorEvent, function(event){191 event.preventDefault();192 event.stopImmediatePropagation();193 var currentPattern = objectInstance.visualDeveloperInstance.GetElementGenericPath(objectInstance.currentNavigationJQueryDOMElement),194 currentObject = jQuery(currentPattern);195 currentObject.not(objectInstance.currentNavigationJQueryDOMElement);196 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(currentPattern);197 objectInstance._highlightNavigationMirrorJQueryDOMElement(currentObject);198 });199 jQuery(this.currentNavigationPanelOptionGlobal).bind(this._settings.navigationOptionIndicatorCloseEvent, function(event){200 event.preventDefault();201 event.stopImmediatePropagation();202 objectInstance._clearCurrentNavigationMirrorJQueryDOMElement();203 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(" ");204 });205 jQuery(this.currentNavigationPanelOptionGlobalClass).bind(this._settings.navigationOptionSelectEvent, function(event){206 event.preventDefault();207 event.stopImmediatePropagation();208 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(objectInstance._lang.userActionNotificationGlobalClass);209 objectInstance._enableElementPanelOnPattern(objectInstance.visualDeveloperInstance.GetElementGenericPath(objectInstance.currentNavigationJQueryDOMElement, false));210 });211 jQuery(this.currentNavigationPanelOptionGlobalClass).bind(this._settings.navigationOptionIndicatorEvent, function(event){212 event.preventDefault();213 event.stopImmediatePropagation();214 var currentPattern = objectInstance.visualDeveloperInstance.GetElementGenericPath(objectInstance.currentNavigationJQueryDOMElement, false),215 currentObject = jQuery(currentPattern);216 currentObject.not(objectInstance.currentNavigationJQueryDOMElement);217 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(currentPattern);218 objectInstance._highlightNavigationMirrorJQueryDOMElement(currentObject);219 });220 jQuery(this.currentNavigationPanelOptionGlobalClass).bind(this._settings.navigationOptionIndicatorCloseEvent, function(event){221 event.preventDefault();222 event.stopImmediatePropagation();223 objectInstance._clearCurrentNavigationMirrorJQueryDOMElement();224 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(" ");225 });226 jQuery(this.currentNavigationPanelOptionAdvancedCreation).bind(this._settings.navigationOptionSelectEvent, function(event){227 event.preventDefault();228 event.stopImmediatePropagation();229 var cssRule = objectInstance.visualDeveloperInstance.GetElementGenericPath(objectInstance.currentNavigationJQueryDOMElement, false);230 objectInstance._clearCurrentNavigationJQueryDOMElement();231 objectInstance232 .visualDeveloperInstance233 .Utility234 .DomRuleBuilder235 .InitInstance(236 cssRule,237 objectInstance,238 objectInstance._enableElementPanelOnPattern239 );240 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(" ");241 });242 },243 _enableElementPanelOnPattern : function(elementPanelPattern) {244 if(elementPanelPattern == false) {245 this.visualDeveloperInstance.Panel.SetUserNotification(this._lang.userActionNotificationReset);246 this.visualDeveloperInstance.Navigation.OpenNavigation();247 return;248 }249 this._clearCurrentNavigationJQueryDOMElement();250 this.visualDeveloperInstance.Panel.DisableQuickAccessHighlighting();251 this.visualDeveloperInstance.ElementPanel.InitPatternCustomization(elementPanelPattern);252 },253 _arrangePanel : function() {254 this.currentNavigationPanelObject.css("top", this.currentNavigationJQueryDOMElement.offset().top - this.currentNavigationPanelObject.height() - 5);255 this.currentNavigationPanelObject.css("left", this.currentNavigationJQueryDOMElement.offset().left);256 },257 _clearCurrentNavigationJQueryDOMElement : function() {258 jQuery(window).unbind(this._settings.navigationArrangeEvents);259 if(this.currentNavigationJQueryDOMElement !== false) {260 this.visualDeveloperInstance.Navigation.UnMarkNavigationVisualSelectedElement(this.currentNavigationJQueryDOMElement);261 this.currentNavigationJQueryDOMElement = false;262 }263 this._clearCurrentNavigationMirrorJQueryDOMElement();264 if(this.currentNavigationPanelObject !== false) {265 jQuery(this.currentNavigationPanelObject).find('*').unbind(this._settings.navigationNamespace);266 this.currentNavigationPanelObject.remove();267 this.currentNavigationPanelObject = false;268 }269 },270 _highlightNavigationMirrorJQueryDOMElement : function(mirrorJQueryDOMElement) {271 this._clearCurrentNavigationMirrorJQueryDOMElement();272 this.currentNavigationMirrorJQueryDOMElement = mirrorJQueryDOMElement;273 this.visualDeveloperInstance.Navigation.MarkNavigationVisualSelectedMirrorElement(this.currentNavigationMirrorJQueryDOMElement);274 },275 _clearCurrentNavigationMirrorJQueryDOMElement : function() {276 if(this.currentNavigationMirrorJQueryDOMElement !== false) {277 this.visualDeveloperInstance.Navigation.UnMarkNavigationVisualSelectedMirrorElement(this.currentNavigationMirrorJQueryDOMElement);278 this.currentNavigationMirrorJQueryDOMElement = false;279 }280 },281 CloseNavigationPanel : function() {282 this._clearCurrentNavigationJQueryDOMElement();283 }...
admin_navigation.js
Source:admin_navigation.js
1/*2 Copyright (C) 2015 PencilBlue, LLC3 This program is free software: you can redistribute it and/or modify4 it under the terms of the GNU General Public License as published by5 the Free Software Foundation, either version 3 of the License, or6 (at your option) any later version.7 This program is distributed in the hope that it will be useful,8 but WITHOUT ANY WARRANTY; without even the implied warranty of9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10 GNU General Public License for more details.11 You should have received a copy of the GNU General Public License12 along with this program. If not, see <http://www.gnu.org/licenses/>.13 */14//dependencies15var util = require('./util.js');16module.exports = function AdminNavigationModule(pb) {17 //PB dependencies18 var SecurityService = pb.SecurityService;19 var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE;20 /**21 * Provides function to construct the structure needed to display the navigation22 * in the Admin section of the application.23 *24 * @module Services25 * @submodule Admin26 * @class AdminNavigation27 * @constructor28 */29 function AdminNavigation() {}30 /**31 *32 * @private33 * @static34 * @property additions35 * @type {Array}36 */37 AdminNavigation.additions = {};38 /**39 *40 * @private41 * @static42 * @property childrenAdditions43 * @type {Object}44 */45 AdminNavigation.childrenAdditions = {};46 /**47 *48 * @private49 * @static50 * @readonly51 * @property MULTISITE_NAV52 * @returns {Array}53 */54 var MULTISITE_NAV = Object.freeze({55 id: 'site_entity',56 title: 'MANAGE_SITES',57 icon: 'sitemap',58 href: '/admin/sites',59 access: SecurityService.ACCESS_ADMINISTRATOR60 }61 );62 /**63 *64 * @private65 * @static66 * @readonly67 * @property CONTENT_NAV68 * @returns {Array}69 */70 var CONTENT_NAV = Object.freeze({71 id: 'content',72 title: 'CONTENT',73 icon: 'quote-right',74 href: '#',75 access: SecurityService.ACCESS_WRITER,76 children: [77 {78 id: 'navigation',79 title: 'NAVIGATION',80 icon: 'th-large',81 href: '/admin/content/navigation',82 access: SecurityService.ACCESS_EDITOR83 },84 {85 id: 'topics',86 title: 'TOPICS',87 icon: 'tags',88 href: '/admin/content/topics',89 access: SecurityService.ACCESS_EDITOR90 },91 {92 id: 'pages',93 title: 'PAGES',94 icon: 'file-o',95 href: '/admin/content/pages',96 access: SecurityService.ACCESS_EDITOR97 },98 {99 id: 'articles',100 title: 'ARTICLES',101 icon: 'files-o',102 href: '/admin/content/articles',103 access: SecurityService.ACCESS_WRITER104 },105 {106 id: 'media',107 title: 'MEDIA',108 icon: 'camera',109 href: '/admin/content/media',110 access: SecurityService.ACCESS_WRITER111 },112 {113 id: 'comments',114 title: 'COMMENTS',115 icon: 'comments',116 href: '/admin/content/comments',117 access: SecurityService.ACCESS_EDITOR118 },119 {120 id: 'custom_objects',121 title: 'CUSTOM_OBJECTS',122 icon: 'cubes',123 href: '/admin/content/objects/types',124 access: SecurityService.ACCESS_EDITOR125 }126 ]127 });128 var PLUGINS_NAV = Object.freeze({129 id: 'plugins',130 title: 'PLUGINS',131 icon: 'puzzle-piece',132 href: '#',133 access: SecurityService.ACCESS_ADMINISTRATOR,134 children: [135 {136 divider: true,137 id: 'manage',138 title: 'MANAGE',139 icon: 'upload',140 href: '/admin/plugins'141 },142 {143 id: 'themes',144 title: 'THEMES',145 icon: 'magic',146 href: '/admin/themes'147 }148 ]149 });150 var USERS_NAV = Object.freeze({151 id: 'users',152 title: 'USERS',153 icon: 'users',154 href: '#',155 access: SecurityService.ACCESS_EDITOR,156 children: [157 {158 id: 'manage',159 title: 'MANAGE',160 icon: 'users',161 href: '/admin/users',162 access: SecurityService.ACCESS_EDITOR163 },164 {165 id: 'permissions',166 title: 'PERMISSIONS',167 icon: 'lock',168 href: '/admin/users/permissions',169 access: SecurityService.ACCESS_ADMINISTRATOR170 }171 ]172 });173 var VIEW_SITE_NAV = Object.freeze({174 id: 'view_site',175 title: 'VIEW_SITE',176 icon: 'desktop',177 href: '/',178 access: SecurityService.ACCESS_WRITER179 });180 var LOGOUT_NAV = Object.freeze({181 id: 'logout',182 title: 'LOGOUT',183 icon: 'power-off',184 href: '/actions/logout',185 access: SecurityService.ACCESS_WRITER186 });187 function buildSettingsNavigation(site) {188 var settingsNav = {189 id: 'settings',190 title: 'SETTINGS',191 icon: 'cogs',192 href: '#',193 access: SecurityService.ACCESS_ADMINISTRATOR,194 children: [195 {196 id: 'site_settings',197 title: 'SITE_SETTINGS',198 icon: 'cog',199 href: '/admin/site_settings',200 access: SecurityService.ACCESS_ADMINISTRATOR201 },202 {203 id: 'content_settings',204 title: 'CONTENT',205 icon: 'quote-right',206 href: '/admin/site_settings/content',207 access: SecurityService.ACCESS_ADMINISTRATOR208 },209 {210 id: 'email_settings',211 title: 'EMAIL',212 icon: 'envelope',213 href: '/admin/site_settings/email',214 access: SecurityService.ACCESS_ADMINISTRATOR215 }216 ]217 };218 if (pb.SiteService.isGlobal(site)) {219 settingsNav.children.push({220 id: 'library_settings',221 title: 'LIBRARIES',222 icon: 'book',223 href: '/admin/site_settings/libraries',224 access: SecurityService.ACCESS_ADMINISTRATOR225 });226 }227 return Object.freeze(settingsNav);228 }229 function getDefaultNavigation(site) {230 return util.clone([CONTENT_NAV, PLUGINS_NAV, USERS_NAV, buildSettingsNavigation(site), VIEW_SITE_NAV, LOGOUT_NAV]);231 }232 function getMultiSiteNavigation() {233 return util.clone([MULTISITE_NAV]);234 }235 function getGlobalScopeNavigation(site) {236 return util.clone([PLUGINS_NAV, USERS_NAV, buildSettingsNavigation(site), LOGOUT_NAV]);237 }238 /**239 *240 * @private241 * @static242 * @method getAdditions243 * @return {Array}244 */245 function getAdditions(site) {246 return getAdditionsInScope(AdminNavigation.additions, site);247 }248 /**249 *250 * @private251 * @static252 * @method getChildrenAdditions253 * @return {Object}254 */255 function getChildrenAdditions(site) {256 return getAdditionsInScope(AdminNavigation.childrenAdditions, site);257 }258 /**259 * @private260 * @method getAdditionsInScope261 * @param {Object} additions262 * @param {String} site263 */264 function getAdditionsInScope(additions, site) {265 if (additions.hasOwnProperty(site)) {266 return util.clone(additions[site]);267 }268 else if (additions.hasOwnProperty(pb.SiteService.GLOBAL_SITE)) {269 return util.clone(additions[pb.SiteService.GLOBAL_SITE]);270 }271 return util.clone(additions);272 }273 /**274 *275 * @private276 * @static277 * @method buildNavigation278 * @return {Array}279 */280 function buildNavigation(site) {281 var i;282 var navigation = [];283 var additions = getAdditions(site);284 var childrenAdditions = getChildrenAdditions(site);285 if (pb.config.multisite.enabled) {286 var multiSiteAdditions = getMultiSiteNavigation();287 util.arrayPushAll(multiSiteAdditions, navigation);288 }289 if (pb.config.multisite.enabled && pb.SiteService.isGlobal(site)) {290 // Don't include content or view site in the nav for multitenancy global scope.291 util.arrayPushAll(getGlobalScopeNavigation(site), navigation);292 }293 else {294 var defaultNavigation = getDefaultNavigation(site);295 util.arrayPushAll(defaultNavigation, navigation);296 }297 util.arrayPushAll(additions, navigation);298 //retrieve the nav items to iterate over299 var ids = Object.keys(childrenAdditions);300 if (ids.length === 0) {301 return navigation;302 }303 //convert to hash to create quick lookup304 var lookup = util.arrayToHash(navigation, function(navigation, i) {305 return navigation[i].id;306 });307 //add additions308 Object.keys(childrenAdditions).forEach(function(id) {309 var children = childrenAdditions[id];310 //find the nav that the children should be added to311 var nav = lookup[id];312 if (!nav) {313 return;314 }315 if (!util.isArray(nav.children)) {316 nav.children = [];317 }318 util.arrayPushAll(children, nav.children);319 });320 return navigation;321 }322 /**323 * @private324 * @static325 * @method localizeNavigation326 * @param navigation327 * @param ls328 * @return {*}329 */330 function localizeNavigation(navigation, ls) {331 navigation.forEach(function(nav) {332 nav.title = ls.get(nav.title);333 if(util.isArray(nav.children)) {334 nav.children = localizeNavigation(nav.children, ls);335 }336 });337 return navigation;338 }339 /**340 * @private341 * @static342 * @method isDuplicate343 * @param {String} id344 * @param {Array} navigation345 * @return {boolean}346 */347 function isDuplicate(id, navigation, site) {348 if (!navigation) {349 navigation = buildNavigation(site);350 }351 for (var i = 0; i < navigation.length; i++) {352 var node = navigation[i];353 if (node.id === id) {354 return true;355 }356 if (node.children && isDuplicate(id, node.children, site)) {357 return true;358 }359 }360 return false;361 }362 function exists(id, site) {363 var isGlobal = pb.SiteService.isGlobal(site);364 var nav = buildNavigation(site);365 return isDuplicate(id, nav) ||366 (!isGlobal && isDuplicate(id, buildNavigation(pb.SiteService.GLOBAL_SITE)));367 }368 /**369 * @private370 * @static371 * @method isDefaultNode372 * @param {String} id373 * @return {Boolean}374 */375 function isDefaultNode(id, site) {376 return isDuplicate(id, getDefaultNavigation(site));377 }378 /**379 * Retrive the admin navigation hierarchy380 * @static381 * @method get382 * @param {object} session383 * @param {array} activeMenuItems Array of nav item names that are active384 * @param {Object} ls Localization service385 * @return {object} Admin navigation386 */387 AdminNavigation.get = function (session, activeMenuItems, ls, site) {388 var navigation = AdminNavigation.removeUnauthorized(389 session,390 buildNavigation(site),391 activeMenuItems392 );393 return localizeNavigation(navigation, ls);394 };395 AdminNavigation.addChild = function(parentId, node) {396 AdminNavigation.addChildToSite(parentId, node, pb.SiteService.GLOBAL_SITE);397 }398 /**399 * Adds a new child node to an existing top level node400 * @static401 * @method addChildToSite402 * @param {String} parentId403 * @param {Object} node404 * @param {String} site - site unique id405 * @return {Boolean}406 */407 AdminNavigation.addChildToSite = function (parentId, node, site) {408 if (util.isNullOrUndefined(site)) {409 site = GLOBAL_SITE;410 }411 if (exists(node.id, site)) {412 return false;413 }414 var additionsMap;415 if (!(site in AdminNavigation.childrenAdditions)) {416 additionsMap = AdminNavigation.childrenAdditions[site] = {};417 } else {418 additionsMap = AdminNavigation.childrenAdditions[site];419 }420 if (!additionsMap[parentId]) {421 additionsMap[parentId] = [];422 }423 additionsMap[parentId].push(node);424 return true;425 };426 /**427 * Adds a new top level node428 * @static429 * @method addToSite430 * @param {Object} node431 * @param site432 * @return {Boolean}433 */434 AdminNavigation.addToSite = function (node, site) {435 if (util.isNullOrUndefined(site)) {436 site = GLOBAL_SITE;437 }438 if (exists(node.id, site)) {439 return false;440 }441 if (!(site in AdminNavigation.additions)) {442 AdminNavigation.additions[site] = [];443 }444 AdminNavigation.additions[site].push(node);445 return true;446 };447 /**448 * Remove a navigation node449 * @static450 * @method removeFromSite451 * @param id452 * @param site453 * @return {boolean}454 */455 AdminNavigation.removeFromSite = function (id, site) {456 if (!isDuplicate(id, buildNavigation(site))) {457 return false;458 }459 if (isDefaultNode(id)) {460 pb.log.warn("Admin Navigation: Attempting to remove default Node %s", id);461 return false;462 }463 function removeNode(id, navigation) {464 for (var i = 0; i < navigation.length; i++) {465 if (navigation[i].id === id) {466 navigation.splice(i, 1);467 return navigation;468 }469 if (navigation[i].children) {470 navigation[i].children = removeNode(id, navigation[i].children);471 }472 }473 return navigation;474 }475 AdminNavigation.additions[site] = removeNode(id, AdminNavigation.additions[site]);476 var childAdditionsMap = AdminNavigation.childrenAdditions[site];477 util.forEach(childAdditionsMap, function(value, key) {478 if(key === id){479 delete childAdditionsMap[key];480 }else {481 childAdditionsMap[key] = removeNode(id, value);482 }483 });484 return true;485 };486 /**487 * @static488 * @method removeUnauthorized489 * @param {Object} session490 * @param {Array} adminNavigation491 * @param {Array} activeItems492 * @return {Array}493 */494 AdminNavigation.removeUnauthorized = function (session, adminNavigation, activeItems) {495 for (var i = 0; i < adminNavigation.length; i++) {496 if (typeof adminNavigation[i].access !== 'undefined') {497 if (!pb.security.isAuthorized(session, {admin_level: adminNavigation[i].access})) {498 adminNavigation.splice(i, 1);499 i--;500 continue;501 }502 }503 for (var o = 0; o < activeItems.length; o++) {504 if (activeItems[o] === adminNavigation[i].id) {505 adminNavigation[i].active = 'active';506 break;507 }508 }509 if (typeof adminNavigation[i].children !== 'undefined') {510 if (adminNavigation[i].children.length > 0) {511 adminNavigation[i].dropdown = 'dropdown';512 for (var j = 0; j < adminNavigation[i].children.length; j++) {513 if (typeof adminNavigation[i].children[j].access !== 'undefined') {514 if (!pb.security.isAuthorized(session, {admin_level: adminNavigation[i].children[j].access})) {515 adminNavigation[i].children.splice(j, 1);516 j--;517 continue;518 }519 }520 for (var p = 0; p < activeItems.length; p++) {521 if (activeItems[p] == adminNavigation[i].children[j].id) {522 adminNavigation[i].children[j].active = 'active';523 break;524 }525 }526 }527 }528 }529 }530 return adminNavigation;531 };532 //exports533 return AdminNavigation;...
NavigationBar.js
Source:NavigationBar.js
1/*2 * Copyright (C) 2013 Apple Inc. All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions6 * are met:7 * 1. Redistributions of source code must retain the above copyright8 * notice, this list of conditions and the following disclaimer.9 * 2. Redistributions in binary form must reproduce the above copyright10 * notice, this list of conditions and the following disclaimer in the11 * documentation and/or other materials provided with the distribution.12 *13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF23 * THE POSSIBILITY OF SUCH DAMAGE.24 */25WebInspector.NavigationBar = function(element, navigationItems, role, label) {26 WebInspector.Object.call(this);27 this._element = element || document.createElement("div");28 this._element.classList.add(this.constructor.StyleClassName || WebInspector.NavigationBar.StyleClassName);29 this._element.tabIndex = 0;30 31 if (role)32 this._element.setAttribute("role", role);33 if (label)34 this._element.setAttribute("aria-label", label);35 this._element.addEventListener("focus", this._focus.bind(this), false);36 this._element.addEventListener("blur", this._blur.bind(this), false);37 this._element.addEventListener("keydown", this._keyDown.bind(this), false);38 this._element.addEventListener("mousedown", this._mouseDown.bind(this), false);39 document.addEventListener("load", this.updateLayout.bind(this), false);40 this._styleElement = document.createElement("style");41 this._navigationItems = [];42 if (navigationItems) {43 for (var i = 0; i < navigationItems.length; ++i)44 this.addNavigationItem(navigationItems[i]);45 }46 document.head.appendChild(this._styleElement);47};48WebInspector.Object.addConstructorFunctions(WebInspector.NavigationBar);49WebInspector.NavigationBar.StyleClassName = "navigation-bar";50WebInspector.NavigationBar.CollapsedStyleClassName = "collapsed";51WebInspector.NavigationBar.Event = {52 NavigationItemSelected: "navigation-bar-navigation-item-selected"53};54WebInspector.NavigationBar.prototype = {55 constructor: WebInspector.NavigationBar,56 // Public57 addNavigationItem: function(navigationItem, parentElement)58 {59 return this.insertNavigationItem(navigationItem, this._navigationItems.length, parentElement);60 },61 insertNavigationItem: function(navigationItem, index, parentElement)62 {63 console.assert(navigationItem instanceof WebInspector.NavigationItem);64 if (!(navigationItem instanceof WebInspector.NavigationItem))65 return;66 if (navigationItem.parentNavigationBar)67 navigationItem.parentNavigationBar.removeNavigationItem(navigationItem);68 navigationItem._parentNavigationBar = this;69 console.assert(index >= 0 && index <= this._navigationItems.length);70 index = Math.max(0, Math.min(index, this._navigationItems.length));71 this._navigationItems.splice(index, 0, navigationItem);72 if (!parentElement)73 parentElement = this._element;74 var nextSibling = this._navigationItems[index + 1];75 var nextSiblingElement = nextSibling ? nextSibling.element : null;76 if (nextSiblingElement && nextSiblingElement.parentNode !== parentElement)77 nextSiblingElement = null;78 parentElement.insertBefore(navigationItem.element, nextSiblingElement);79 this._minimumWidthNeedsRecalculation = true;80 this._needsStyleUpdated = true;81 this.updateLayoutSoon();82 return navigationItem;83 },84 removeNavigationItem: function(navigationItemOrIdentifierOrIndex, index)85 {86 var navigationItem = this._findNavigationItem(navigationItemOrIdentifierOrIndex);87 if (!navigationItem)88 return;89 navigationItem._parentNavigationBar = null;90 if (this._selectedNavigationItem === navigationItem)91 this.selectedNavigationItem = null;92 this._navigationItems.remove(navigationItem);93 navigationItem.element.remove();94 this._minimumWidthNeedsRecalculation = true;95 this._needsStyleUpdated = true;96 this.updateLayoutSoon();97 return navigationItem;98 },99 updateLayoutSoon: function()100 {101 if (this._updateLayoutTimeout)102 return;103 this._needsLayout = true;104 function update()105 {106 delete this._updateLayoutTimeout;107 if (this._needsLayout || this._needsStyleUpdated)108 this.updateLayout();109 }110 this._updateLayoutTimeout = setTimeout(update.bind(this), 0);111 },112 updateLayout: function()113 {114 if (this._updateLayoutTimeout) {115 clearTimeout(this._updateLayoutTimeout);116 delete this._updateLayoutTimeout;117 }118 if (this._needsStyleUpdated)119 this._updateStyle();120 this._needsLayout = false;121 if (typeof this.customUpdateLayout === "function") {122 this.customUpdateLayout();123 return;124 }125 // Remove the collapsed style class to test if the items can fit at full width.126 this._element.classList.remove(WebInspector.NavigationBar.CollapsedStyleClassName);127 // Tell each navigation item to update to full width if needed.128 for (var i = 0; i < this._navigationItems.length; ++i)129 this._navigationItems[i].updateLayout(true);130 var totalItemWidth = 0;131 for (var i = 0; i < this._navigationItems.length; ++i) {132 // Skip flexible space items since they can take up no space at the minimum width.133 if (this._navigationItems[i] instanceof WebInspector.FlexibleSpaceNavigationItem)134 continue;135 totalItemWidth += this._navigationItems[i].element.offsetWidth;136 }137 var barWidth = this._element.offsetWidth;138 // Add the collapsed class back if the items are wider than the bar.139 if (totalItemWidth > barWidth)140 this._element.classList.add(WebInspector.NavigationBar.CollapsedStyleClassName);141 // Give each navigation item the opportunity to collapse further.142 for (var i = 0; i < this._navigationItems.length; ++i)143 this._navigationItems[i].updateLayout();144 },145 get selectedNavigationItem()146 {147 return this._selectedNavigationItem || null;148 },149 set selectedNavigationItem(navigationItemOrIdentifierOrIndex)150 {151 var navigationItem = this._findNavigationItem(navigationItemOrIdentifierOrIndex);152 // Only radio navigation items can be selected.153 if (!(navigationItem instanceof WebInspector.RadioButtonNavigationItem))154 navigationItem = null;155 if (this._selectedNavigationItem === navigationItem)156 return;157 if (this._selectedNavigationItem)158 this._selectedNavigationItem.selected = false;159 this._selectedNavigationItem = navigationItem || null;160 if (this._selectedNavigationItem)161 this._selectedNavigationItem.selected = true;162 // When the mouse is down don't dispatch the selected event, it will be dispatched on mouse up.163 // This prevents sending the event while the user is scrubbing the bar.164 if (!this._mouseIsDown)165 this.dispatchEventToListeners(WebInspector.NavigationBar.Event.NavigationItemSelected);166 },167 get navigationItems()168 {169 return this._navigationItems;170 },171 get element()172 {173 return this._element;174 },175 get minimumWidth()176 {177 if (typeof this._minimumWidth === "undefined" || this._minimumWidthNeedsRecalculation) {178 this._minimumWidth = this._calculateMinimumWidth();179 delete this._minimumWidthNeedsRecalculation;180 }181 return this._minimumWidth;182 },183 get sizesToFit()184 {185 // Can be overriden by subclasses.186 return false;187 },188 // Private189 _findNavigationItem: function(navigationItemOrIdentifierOrIndex)190 {191 var navigationItem = null;192 if (navigationItemOrIdentifierOrIndex instanceof WebInspector.NavigationItem) {193 if (this._navigationItems.contains(navigationItemOrIdentifierOrIndex))194 navigationItem = navigationItemOrIdentifierOrIndex;195 } else if (typeof navigationItemOrIdentifierOrIndex === "number") {196 navigationItem = this._navigationItems[navigationItemOrIdentifierOrIndex];197 } else if (typeof navigationItemOrIdentifierOrIndex === "string") {198 for (var i = 0; i < this._navigationItems.length; ++i) {199 if (this._navigationItems[i].identifier === navigationItemOrIdentifierOrIndex) {200 navigationItem = this._navigationItems[i];201 break;202 }203 }204 }205 return navigationItem;206 },207 _mouseDown: function(event)208 {209 // Only handle left mouse clicks.210 if (event.button !== 0)211 return;212 // Remove the tabIndex so clicking the navigation bar does not give it focus.213 // Only keep the tabIndex if already focused from keyboard navigation. This matches Xcode.214 if (!this._focused)215 this._element.removeAttribute("tabindex");216 var itemElement = event.target.enclosingNodeOrSelfWithClass(WebInspector.RadioButtonNavigationItem.StyleClassName);217 if (!itemElement || !itemElement.navigationItem)218 return;219 this._previousSelectedNavigationItem = this.selectedNavigationItem;220 this.selectedNavigationItem = itemElement.navigationItem;221 this._mouseIsDown = true;222 this._mouseMovedEventListener = this._mouseMoved.bind(this);223 this._mouseUpEventListener = this._mouseUp.bind(this);224 // Register these listeners on the document so we can track the mouse if it leaves the resizer.225 document.addEventListener("mousemove", this._mouseMovedEventListener, false);226 document.addEventListener("mouseup", this._mouseUpEventListener, false);227 event.preventDefault();228 event.stopPropagation();229 },230 _mouseMoved: function(event)231 {232 console.assert(event.button === 0);233 console.assert(this._mouseIsDown);234 if (!this._mouseIsDown)235 return;236 event.preventDefault();237 event.stopPropagation();238 var itemElement = event.target.enclosingNodeOrSelfWithClass(WebInspector.RadioButtonNavigationItem.StyleClassName);239 if (!itemElement || !itemElement.navigationItem) {240 // Find the element that is at the X position of the mouse, even when the mouse is no longer241 // vertically in the navigation bar.242 var element = document.elementFromPoint(event.pageX, this._element.totalOffsetTop);243 if (!element)244 return;245 itemElement = element.enclosingNodeOrSelfWithClass(WebInspector.RadioButtonNavigationItem.StyleClassName);246 if (!itemElement || !itemElement.navigationItem)247 return;248 }249 if (this.selectedNavigationItem)250 this.selectedNavigationItem.active = false;251 this.selectedNavigationItem = itemElement.navigationItem;252 this.selectedNavigationItem.active = true;253 },254 _mouseUp: function(event)255 {256 console.assert(event.button === 0);257 console.assert(this._mouseIsDown);258 if (!this._mouseIsDown)259 return;260 if (this.selectedNavigationItem)261 this.selectedNavigationItem.active = false;262 this._mouseIsDown = false;263 document.removeEventListener("mousemove", this._mouseMovedEventListener, false);264 document.removeEventListener("mouseup", this._mouseUpEventListener, false);265 delete this._mouseMovedEventListener;266 delete this._mouseUpEventListener;267 // Restore the tabIndex so the navigation bar can be in the keyboard tab loop.268 this._element.tabIndex = 0;269 // Dispatch the selected event here since the selectedNavigationItem setter surpresses it270 // while the mouse is down to prevent sending it while scrubbing the bar.271 if (this._previousSelectedNavigationItem !== this.selectedNavigationItem)272 this.dispatchEventToListeners(WebInspector.NavigationBar.Event.NavigationItemSelected);273 delete this._previousSelectedNavigationItem;274 event.preventDefault();275 event.stopPropagation();276 },277 _keyDown: function(event)278 {279 if (!this._focused)280 return;281 if (event.keyIdentifier !== "Left" && event.keyIdentifier !== "Right")282 return;283 event.preventDefault();284 event.stopPropagation();285 var selectedNavigationItemIndex = this._navigationItems.indexOf(this._selectedNavigationItem);286 if (event.keyIdentifier === "Left") {287 if (selectedNavigationItemIndex === -1)288 selectedNavigationItemIndex = this._navigationItems.length;289 do {290 selectedNavigationItemIndex = Math.max(0, selectedNavigationItemIndex - 1);291 } while (selectedNavigationItemIndex && !(this._navigationItems[selectedNavigationItemIndex] instanceof WebInspector.RadioButtonNavigationItem));292 } else if (event.keyIdentifier === "Right") {293 do {294 selectedNavigationItemIndex = Math.min(selectedNavigationItemIndex + 1, this._navigationItems.length - 1);295 } while (selectedNavigationItemIndex < this._navigationItems.length - 1 && !(this._navigationItems[selectedNavigationItemIndex] instanceof WebInspector.RadioButtonNavigationItem));296 }297 if (!(this._navigationItems[selectedNavigationItemIndex] instanceof WebInspector.RadioButtonNavigationItem))298 return;299 this.selectedNavigationItem = this._navigationItems[selectedNavigationItemIndex];300 },301 _focus: function(event)302 {303 this._focused = true;304 },305 _blur: function(event)306 {307 this._focused = false;308 },309 _updateStyle: function()310 {311 this._needsStyleUpdated = false;312 var parentSelector = "." + (this.constructor.StyleClassName || WebInspector.NavigationBar.StyleClassName);313 var styleText = "";314 for (var i = 0; i < this._navigationItems.length; ++i) {315 if (!this._navigationItems[i].generateStyleText)316 continue;317 if (styleText)318 styleText += "\n";319 styleText += this._navigationItems[i].generateStyleText(parentSelector);320 }321 this._styleElement.textContent = styleText;322 },323 _calculateMinimumWidth: function()324 {325 var wasCollapsed = this._element.classList.contains(WebInspector.NavigationBar.CollapsedStyleClassName)326 // Add the collapsed style class to calculate the width of the items when they are collapsed.327 if (!wasCollapsed)328 this._element.classList.add(WebInspector.NavigationBar.CollapsedStyleClassName);329 var totalItemWidth = 0;330 for (var i = 0; i < this._navigationItems.length; ++i) {331 // Skip flexible space items since they can take up no space at the minimum width.332 if (this._navigationItems[i] instanceof WebInspector.FlexibleSpaceNavigationItem)333 continue;334 totalItemWidth += this._navigationItems[i].element.offsetWidth;335 }336 // Remove the collapsed style class if we were not collapsed before.337 if (!wasCollapsed)338 this._element.classList.remove(WebInspector.NavigationBar.CollapsedStyleClassName);339 return totalItemWidth;340 }341};...
Navigator.js
Source:Navigator.js
1// @flow2// @author Dmitry Patsura <talk@dmtry.me> https://github.com/ovr3import * as React from 'react';4import { BackHandler } from 'react-native';5import { connect } from 'react-redux';6import { addNavigationHelpers, StackNavigator, NavigationActions, Header } from 'react-navigation';7import { __ } from 'utils/i18n';8import { addListener } from 'utils/navigation-redux';9import type { NavigationState } from 'reducers/navigation';10import {11 ModalsContext,12 //13 SideMenuButton,14 SideMenuDrawer,15 HomeHeaderRight,16 //17 OAuthScreen,18 FeedScreen,19 FeedSettingsScreen,20 SettingsScreen,21 ThemeSelectScreen,22 LoginScreen,23 CommitScreen,24 RepositoryIssueScreen,25 RepositoryPullRequestScreen,26 ProfileScreen,27 RepositoryScreen,28 AboutScreen,29 AccountIssues,30 AccountPullRequests,31 AccountNotifications,32} from 'containers';33export const AppNavigator = StackNavigator(34 {35 Home: {36 screen: FeedScreen,37 navigationOptions: {38 headerLeft: <SideMenuButton />,39 headerRight: <HomeHeaderRight />40 }41 },42 Login: {43 screen: LoginScreen,44 navigationOptions: {45 header: null46 }47 },48 OAuth: {49 screen: OAuthScreen,50 navigationOptions: () => ({51 headerTintColor: '#fff',52 headerTitleStyle: {53 color: '#fff',54 },55 headerStyle: {56 backgroundColor: '#000',57 },58 title: 'Continue With GitHub'59 }),60 },61 Issue: {62 screen: RepositoryIssueScreen,63 navigationOptions: ({ navigation }) => {64 const params = navigation.state.params;65 return {66 title: `${params.repo}#${params.number}`67 };68 },69 },70 PullRequest: {71 screen: RepositoryPullRequestScreen,72 navigationOptions: ({ navigation }) => {73 const params = navigation.state.params;74 return {75 title: `${params.repo}#${params.number}`76 };77 },78 },79 Settings: {80 screen: SettingsScreen,81 navigationOptions: {82 title: 'Settings'83 }84 },85 ThemeSelect: {86 screen: ThemeSelectScreen,87 navigationOptions: {88 header: null89 }90 },91 Commit: {92 screen: CommitScreen,93 navigationOptions: {94 title: 'Commit overview'95 }96 },97 FeedSettings: {98 screen: FeedSettingsScreen,99 navigationOptions: {100 title: 'Feed Settings'101 }102 },103 Profile: {104 screen: ProfileScreen,105 navigationOptions: ({ navigation }) => {106 const params = navigation.state.params;107 return {108 title: params.id ? params.id : 'Profile'109 };110 },111 },112 Repository: {113 screen: RepositoryScreen,114 navigationOptions: ({ navigation }) => {115 const params = navigation.state.params;116 return {117 title: params.repo ? params.repo : 'Repository'118 };119 },120 },121 AccountIssues: {122 screen: AccountIssues,123 navigationOptions: {124 title: __('AccountIssues.Title'),125 },126 },127 AccountPullRequests: {128 screen: AccountPullRequests,129 navigationOptions: {130 title: __('AccountPullRequests.Title'),131 },132 },133 AccountNotifications: {134 screen: AccountNotifications,135 navigationOptions: {136 title: __('AccountNotifications.Title'),137 },138 },139 AboutScreen: {140 screen: AboutScreen,141 navigationOptions: {142 title: 'About',143 },144 },145 },146 {147 cardStyle: {148 backgroundColor: 'white'149 },150 navigationOptions: {151 // eslint-disable-next-line react/display-name152 header: (props) => <NavBar {...props} />,153 }154 }155);156const NavBar = connect(157 (state: State, ownProps) => ({158 getScreenDetails: (scene) => {159 const details = ownProps.getScreenDetails(scene);160 return {161 ...details,162 options: {163 headerTintColor: state.settings.headerTitleColor,164 headerTitleStyle: {165 color: state.settings.headerTitleColor,166 },167 headerStyle: {168 backgroundColor: state.settings.headerBackgroundColor169 },170 ...details.options,171 }172 };173 },174 })175)(Header);176type AppWithNavigationStateProps = {177 navigation: NavigationState,178 dispatch: Dispatch179};180class AppWithNavigationState extends React.Component<AppWithNavigationStateProps, void> {181 componentDidMount() {182 BackHandler.addEventListener('hardwareBackPress', () => {183 const { dispatch, navigation } = this.props;184 if (navigation.index === 0) {185 return false;186 }187 dispatch(NavigationActions.back());188 return true;189 });190 }191 componentWillUnmount() {192 BackHandler.removeEventListener('hardwareBackPress');193 }194 render() {195 return (196 <SideMenuDrawer>197 <AppNavigator navigation={addNavigationHelpers({198 dispatch: this.props.dispatch,199 state: this.props.navigation,200 addListener201 })} />202 <ModalsContext />203 </SideMenuDrawer>204 );205 }206}207const mapStateToProps = state => ({208 navigation: state.navigation,209 settings: state.settings,210});...
navigation.js
Source:navigation.js
1VisualDeveloper.Navigation = {2 visualDeveloperInstance : {},3 _settings : {4 navigationVisualIndicatorClass : 'navigation-item',5 navigationSelectedIndicatorClass : 'navigation-item-selected',6 navigationSelectedMirrorIndicatorClass : 'navigation-item-selected-mirror',7 navigationIndicatorTarget : '*:not([id^="visual-developer"])',8 navigationIndicatorEvent : 'mouseenter',9 navigationIndicatorCloseEvent : 'mouseleave',10 navigationSelectionEvent : 'click'11 },12 Init : function(visualDeveloperInstance) {13 this.visualDeveloperInstance = visualDeveloperInstance;14 this._initDependencies();15 },16 _initDependencies : function() {17 this._prefixCSSSettings();18 this._settings.navigationIndicatorEvent = this._settings.navigationIndicatorEvent + '.' + this.visualDeveloperInstance.namespace + "-navigation";19 this._settings.navigationIndicatorCloseEvent = this._settings.navigationIndicatorCloseEvent + '.' + this.visualDeveloperInstance.namespace + "-navigation";20 this._settings.navigationSelectionEvent = this._settings.navigationSelectionEvent + '.' + this.visualDeveloperInstance.namespace + "-navigation";21 },22 _prefixCSSSettings : function() {23 this._settings = this.visualDeveloperInstance.PrefixNonEventSettings(24 this._settings, this.visualDeveloperInstance.styleNamespace);25 },26 OpenNavigation : function() {27 var objectInstance = this;28 this.CloseNavigation();29 jQuery(this._settings.navigationIndicatorTarget)30 .bind(this._settings.navigationIndicatorEvent, function(event){31 event.stopImmediatePropagation();32 event.preventDefault();33 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(34 objectInstance.visualDeveloperInstance.GetElementAbsolutePath(jQuery(this))35 );36 jQuery(this).addClass(objectInstance._settings.navigationVisualIndicatorClass);37 jQuery(this).parents().removeClass(objectInstance._settings.navigationVisualIndicatorClass);38 }).bind(this._settings.navigationIndicatorCloseEvent, function(event){39 event.stopImmediatePropagation();40 event.preventDefault();41 jQuery(this).removeClass(objectInstance._settings.navigationVisualIndicatorClass);42 }).bind(this._settings.navigationSelectionEvent, function(event){43 event.stopImmediatePropagation();44 event.preventDefault();45 jQuery(this).removeClass(objectInstance._settings.navigationVisualIndicatorClass);46 objectInstance.visualDeveloperInstance.Panel.SetUserNotification(47 objectInstance.visualDeveloperInstance.GetElementAbsolutePath(jQuery(this))48 );49 objectInstance.visualDeveloperInstance.NavigationPanel.ActivateNodeInstance(jQuery(this));50 objectInstance._closeNavigationVisualIndicator();51 });52 },53 MarkNavigationVisualSelectedElement : function(jQueryElementObject) {54 jQueryElementObject.addClass(this._settings.navigationSelectedIndicatorClass);55 },56 UnMarkNavigationVisualSelectedElement : function(jQueryElementObject) {57 jQueryElementObject.removeClass(this._settings.navigationSelectedIndicatorClass);58 },59 MarkNavigationVisualSelectedMirrorElement : function(jQueryElementObject) {60 jQueryElementObject.addClass(this._settings.navigationSelectedMirrorIndicatorClass);61 },62 UnMarkNavigationVisualSelectedMirrorElement : function(jQueryElementObject) {63 jQueryElementObject.removeClass(this._settings.navigationSelectedMirrorIndicatorClass);64 },65 _closeNavigationVisualIndicator : function() {66 jQuery(this._settings.navigationIndicatorTarget)67 .trigger(this._settings.navigationIndicatorCloseEvent)68 .unbind(this._settings.navigationIndicatorEvent)69 .unbind(this._settings.navigationIndicatorCloseEvent)70 .unbind(this._settings.navigationSelectionEvent);71 },72 CloseNavigation : function() {73 this._closeNavigationVisualIndicator();74 this.visualDeveloperInstance.NavigationPanel.CloseNavigationPanel();75 }...
menu-plus-customizer.js
Source:menu-plus-customizer.js
1/**2 * Main navigation background3 * Empty: transparent4 */5generate_colors_live_update( 'slideout_background_color', '.main-navigation.slideout-navigation', 'background-color', '' );6/**7 * Primary navigation text color8 * Empty: link_color9 */10generate_colors_live_update( 'slideout_text_color', '.slideout-navigation.main-navigation .main-nav ul li a, .slideout-navigation a, .slideout-navigation', 'color', '' );11/**12 * Primary navigation text color hover13 * Empty: link_color_hover14 */15generate_colors_live_update( 'slideout_text_hover_color',16 '.slideout-navigation.main-navigation .main-nav ul li:hover > a,\17 .slideout-navigation.main-navigation .main-nav ul li:focus > a,\18 .slideout-navigation.main-navigation .main-nav ul li.sfHover > a',19 'color', ''20);21/**22 * Primary navigation menu item hover23 * Empty: link_color_hover24 */25generate_colors_live_update( 'slideout_background_hover_color',26 '.slideout-navigation.main-navigation .main-nav ul li:hover > a,\27 .slideout-navigation.main-navigation .main-nav ul li:focus > a,\28 .slideout-navigation.main-navigation .main-nav ul li.sfHover > a',29 'background-color', 'transparent'30);31/**32 * Primary sub-navigation color33 * Empty: transparent34 */35generate_colors_live_update( 'slideout_submenu_background_color', '.slideout-navigation.main-navigation ul ul', 'background-color', '' );36/**37 * Primary sub-navigation text color38 * Empty: link_color39 */40generate_colors_live_update( 'slideout_submenu_text_color', '.slideout-navigation.main-navigation .main-nav ul ul li a', 'color', '' );41/**42 * Primary sub-navigation hover43 */44var slideout_submenu_hover = '.slideout-navigation.main-navigation .main-nav ul ul li:hover > a,\45 .slideout-navigation.main-navigation .main-nav ul ul li:focus > a,\46 .slideout-navigation.main-navigation .main-nav ul ul li.sfHover > a';47/**48 * Primary sub-navigation text hover49 * Empty: link_color_hover50 */51generate_colors_live_update( 'slideout_submenu_text_hover_color', slideout_submenu_hover, 'color', '' );52/**53 * Primary sub-navigation background hover54 * Empty: transparent55 */56generate_colors_live_update( 'slideout_submenu_background_hover_color', slideout_submenu_hover, 'background-color', '' );57/**58 * Navigation current selectors59 */60var slideout_current = '.slideout-navigation.main-navigation .main-nav ul li[class*="current-menu-"] > a,\61 .slideout-navigation.main-navigation .main-nav ul li[class*="current-menu-"] > a:hover,\62 .slideout-navigation.main-navigation .main-nav ul li[class*="current-menu-"].sfHover > a';63/**64 * Primary navigation current text65 * Empty: link_color66 */67generate_colors_live_update( 'slideout_text_current_color', slideout_current, 'color', '' );68/**69 * Primary navigation current text70 * Empty: transparent71 */72generate_colors_live_update( 'slideout_background_current_color', slideout_current, 'background-color' );73/**74 * Primary sub-navigation current selectors75 */76var slideout_submenu_current = '.slideout-navigation.main-navigation .main-nav ul ul li[class*="current-menu-"] > a,\77 .slideout-navigation.main-navigation .main-nav ul ul li[class*="current-menu-"] > a:hover,\78 .slideout-navigation.main-navigation .main-nav ul ul li[class*="current-menu-"].sfHover > a';79/**80 * Primary sub-navigation current text81 * Empty: link_color82 */83generate_colors_live_update( 'slideout_submenu_text_current_color', slideout_submenu_current, 'color', '' );84/**85 * Primary navigation current item background86 * Empty: transparent87 */...
resetNavigation.js
Source:resetNavigation.js
1import {NavigationActions} from 'react-navigation'2const resetNavigation = {3 dispatchToSingleRoute: (navigation, routeName) => {4 const resetAction = NavigationActions.reset({5 index: 0,6 actions: [7 NavigationActions.navigate({routeName}),8 ],9 })10 navigation.dispatch(resetAction)11 },12 dispatchToDrawerRoute: (navigation, drawerRoute) => {13 const resetAction = NavigationActions.reset({14 index: 0,15 actions: [16 NavigationActions.navigate({17 routeName: 'Home',18 params: {},19 action: NavigationActions.navigate({routeName: drawerRoute}),20 }),21 ],22 })23 navigation.dispatch(resetAction)24 },25 dispatchUnderHome: (navigation, drawerRoute) => {26 const resetAction = NavigationActions.reset({27 index: 1,28 actions: [29 NavigationActions.navigate({30 routeName: 'Home',31 }),32 NavigationActions.navigate({33 routeName: drawerRoute,34 }),35 ],36 })37 navigation.dispatch(resetAction)38 },39 dispatchUnderDrawer: (navigation, drawerRoute, finalRoute) => {40 if (drawerRoute === "GetVerified") {41 const resetAction = NavigationActions.reset({42 index: 0,43 actions: [44 NavigationActions.navigate({45 routeName: 'Home',46 params: {},47 action: NavigationActions.navigate({routeName: drawerRoute}),48 }),49 //NavigationActions.navigate({routeName: finalRoute}),50 ],51 })52 navigation.dispatch(resetAction)53 } else {54 const resetAction = NavigationActions.reset({55 index: 1,56 actions: [57 NavigationActions.navigate({58 routeName: 'Home',59 params: {},60 action: NavigationActions.navigate({routeName: drawerRoute}),61 }),62 NavigationActions.navigate({routeName: finalRoute}),63 ],64 })65 navigation.dispatch(resetAction)66 }67 },68 dispatchUnderTwoFactor: (navigation) => {69 const resetAction = NavigationActions.reset({70 index: 2,71 actions: [72 NavigationActions.navigate({73 routeName: 'Home',74 action: NavigationActions.navigate({routeName: 'Settings'}),75 }),76 NavigationActions.navigate({routeName: 'SettingsSecurity'}),77 NavigationActions.navigate({routeName: 'TwoFactor'})78 ],79 })80 navigation.dispatch(resetAction)81 },82 dispatchUnderDrawerWithParams: (navigation, drawerRoute, finalRoute, params) => {83 const resetAction = NavigationActions.reset({84 index: 1,85 actions: [86 NavigationActions.navigate({87 routeName: 'Home',88 params: {},89 action: NavigationActions.navigate({routeName: drawerRoute}),90 }),91 NavigationActions.navigate({92 routeName: finalRoute,93 params,94 }),95 ],96 })97 navigation.dispatch(resetAction)98 },99}...
navigationSlice.js
Source:navigationSlice.js
1import { createSelector, createEntityAdapter, createSlice } from '@reduxjs/toolkit';2import navigationConfig from 'app/fuse-configs/navigationConfig';3import FuseUtils from '@fuse/utils';4import i18next from 'i18next';5import _ from '@lodash';6const navigationAdapter = createEntityAdapter();7const emptyInitialState = navigationAdapter.getInitialState();8const initialState = navigationAdapter.upsertMany(emptyInitialState, navigationConfig);9export const appendNavigationItem = (item, parentId) => (dispatch, getState) => {10 const navigation = selectNavigationAll(getState());11 return dispatch(setNavigation(FuseUtils.appendNavItem(navigation, item, parentId)));12};13export const prependNavigationItem = (item, parentId) => (dispatch, getState) => {14 const navigation = selectNavigationAll(getState());15 return dispatch(setNavigation(FuseUtils.prependNavItem(navigation, item, parentId)));16};17export const updateNavigationItem = (id, item) => (dispatch, getState) => {18 const navigation = selectNavigationAll(getState());19 return dispatch(setNavigation(FuseUtils.updateNavItem(navigation, id, item)));20};21export const removeNavigationItem = id => (dispatch, getState) => {22 const navigation = selectNavigationAll(getState());23 return dispatch(setNavigation(FuseUtils.removeNavItem(navigation, id)));24};25export const {26 selectAll: selectNavigationAll,27 selectIds: selectNavigationIds,28 selectById: selectNavigationItemById29} = navigationAdapter.getSelectors(state => state.fuse.navigation);30export const selectNavigation = createSelector(31 [selectNavigationAll, ({ i18n }) => i18n.language],32 (navigation, language) => {33 function setTranslationValues(data) {34 // loop through every object in the array35 return data.map(item => {36 if (item.translate && item.title) {37 item.title = i18next.t(`navigation:${item.translate}`);38 }39 // see if there is a children node40 if (item.children) {41 // run this function recursively on the children array42 item.children = setTranslationValues(item.children);43 }44 return item;45 });46 }47 return setTranslationValues(_.merge([], navigation));48 }49);50const navigationSlice = createSlice({51 name: 'navigation',52 initialState,53 reducers: {54 setNavigation: navigationAdapter.setAll,55 resetNavigation: (state, action) => initialState56 }57});58export const { setNavigation, resetNavigation } = navigationSlice.actions;...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'google.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'google.png'});13 await browser.close();14})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.screenshot({path: 'example.png'});20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.screenshot({path: 'example.png'});27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.screenshot({path: 'example.png'});34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();40 await page.screenshot({path: 'example.png'});41 await browser.close();42})();43const puppeteer = require('puppeteer');44(async () => {45 const browser = await puppeteer.launch();46 const page = await browser.newPage();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 await browser.close();14})();15Navigation is an important aspect of web testing. When we test a web application, we will be moving
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await page.waitFor(1000);6 await page.click('a[href="news"]');7 await page.waitFor(1000);8 await page.click('a[href="newest"]');9 await page.waitFor(1000);10 await page.click('a[href="front"]');11 await page.waitFor(1000);12 await page.click('a[href="newcomments"]');13 await page.waitFor(1000);14 await page.click('a[href="show"]');15 await page.waitFor(1000);16 await page.click('a[href="ask"]');17 await page.waitFor(1000);18 await page.click('a[href="jobs"]');19 await page.waitFor(1000);20 await page.click('a[href="submit"]');21 await page.waitFor(1000);22 await page.click('a[href="login"]');23 await page.waitFor(1000);24 await page.click('a[href="logout"]');25 await page.waitFor(1000);26 await browser.close();27})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch({headless: false});5 const page = await browser.newPage();6 const dimensions = await page.evaluate(() => {7 return {8 };9 });10 console.log('Dimensions:', dimensions);11 await page.screenshot({path: 'example.png'});12 await browser.close();13})();14const puppeteer = require('puppeteer');15const fs = require('fs');16(async () => {17 const browser = await puppeteer.launch({headless: false});18 const page = await browser.newPage();19 const dimensions = await page.evaluate(() => {20 return {21 };22 });23 console.log('Dimensions:', dimensions);24 await page.screenshot({path: 'example.png'});25 await browser.close();26})();27const puppeteer = require('puppeteer');28const fs = require('fs');29(async () => {30 const browser = await puppeteer.launch({headless: false});31 const page = await browser.newPage();32 const dimensions = await page.evaluate(() => {33 return {34 };35 });36 console.log('Dimensions:', dimensions);37 await page.screenshot({path: 'example.png'});38 await browser.close();39})();40const puppeteer = require('puppeteer');41const fs = require('fs');42(async () => {
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.screenshot({path: 'example.png'});20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.screenshot({path: 'example.png'});27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.screenshot({path: 'example.png'});34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();
Using AI Code Generation
1await page.type('input[title="Search"]', 'puppeteer');2await page.click('input[value="Google Search"]');3await page.waitForNavigation();4await page.screenshot({path: 'example.png'});5await browser.close();6await page.type('input[title="Search"]', 'puppeteer');7await page.click('input[value="Google Search"]');8await page.waitForSelector('h3');9await page.screenshot({path: 'example.png'});10await browser.close();11await page.type('input[title="Search"]', 'puppeteer');12await page.click('input[value="Google Search"]');13await page.screenshot({path: 'example.png'});14await browser.close();15await page.type('input[title="Search"]', 'puppeteer');16await page.click('input[value="Google Search"]');17await page.waitForFunction('document.querySelector("h3")');18await page.screenshot({path: 'example.png'});19await browser.close();20await page.type('input[title="Search"]', 'puppeteer');21await page.click('input[value="Google Search"]');22await page.waitFor(3000);23await page.screenshot({path: 'example.png'});24await browser.close();25await page.type('input[title="Search"]', 'puppeteer');26await page.click('input[value="Google Search"]');27await page.screenshot({path: 'example.png'});28await browser.close();29await page.type('input[title="Search"]', 'puppeteer');30await page.click('input[value="Google Search"]');
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4const dir = path.join(__dirname, 'screenshots');5if (!fs.existsSync(dir)) {6 fs.mkdirSync(dir);7}8(async () => {9 const browser = await puppeteer.launch();10 const page = await browser.newPage();11 await page.goto(url);12 await page.screenshot({path: 'screenshots/homepage.png'});13 await page.type('input[title="Search"]', 'puppeteer');14 await page.click('input[value="Google Search"]');15 await page.waitForNavigation();16 await page.screenshot({path: 'screenshots/search.png'});17 await browser.close();18})();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!