Skip to content

Instantly share code, notes, and snippets.

@pavelgordon
Created September 16, 2016 15:49
Show Gist options
  • Save pavelgordon/1895332306f6e924c1bc00ffb18c534d to your computer and use it in GitHub Desktop.
Save pavelgordon/1895332306f6e924c1bc00ffb18c534d to your computer and use it in GitHub Desktop.
what the fuck
@media screen and (max-width:1000px) {
#hilfeButton + td, #barrierefreiheitButton + td{
display: none;
}
#impressumButton + td{
display: none;
}
}
Ext.namespace('Custom.config');
/**
* The Configparser is responsible for:
*
* 1. loading the json-config-file into the application
* 2. parsing the json-file into a javascript object
* (while already transforming values for tileSize, extent and layer-attributes into
* their respective objects)
* 3. rendering the application:
* the parsed json is used to create the different sections of the application through
* the parsing-methods provided in Custom.config.Map and Custom.config.modules. The returned
* objects are then embedded into the layout and rendered.
*
* @param {String} url The location (relative or absolute) of the JSON-config-file
*/
Custom.config.ConfigParser = function (url) {
this.url = url;
};
/**
* Loads the config-file via an XML-HTTP-Request and triggers the parseResponse-method if the
* request was successful. In case of an error the handleFailure-method is called.
*/
Custom.config.ConfigParser.prototype.load = function () {
var request = Ext.Ajax.request({
method: 'GET',
url: this.url,
success: this.parseResponse,
failure: this.handleFailure,
scope: this
});
};
/**
* @private
* Shows an error-message to indicate that the loading of the Config-file failed
*/
Custom.config.ConfigParser.prototype.handleFailure = function (a, b, c) {
alert("Loading the json-config failed! \n Please check the URL.")
};
/**
* @private
* Parses the json-String into a JSON-object. Values for some nodes are directly
* converted into their respective object-types through the reviver-method of the
* parser. The reviver-method is called for each value with the key and the value
* as parameters and the returned object of this method replaces the value
* (e.g. for the tileSize-key a OpenLayers.Size-object is generated by the
* createTileSize-method).
*
* After parsing the doRender-method is called.
*
* @param {Object} response The response-object of the XML-HTTP-request
*/
Custom.config.ConfigParser.prototype.parseResponse = function (response) {
var that = this;
/*
* Definition of the keys which´s values shall be transformed
* and the method that shall be used for the transformation
*/
var parseableKeys = {
baseLayers: function (value) {
return that.createLayers(value);
},
tileSize: function (value) {
return that.createTileSize(value);
},
tileOrigin: function (value) {
return that.createLonLat(value);
},
projection: function (value) {
return that.createProjection(value);
},
maxExtent: function (value) {
return that.createBounds(value);
},
initialExtent: function (value) {
return that.createBounds(value);
}
};
// the reviver-method for the JSON-parser
var parseConfigKeys = function (key, value) {
if (key in parseableKeys) {
return parseableKeys[key](value);
}
return value;
};
var jsonConfig = JSON.parse(response.responseText, parseConfigKeys);
this.doRender(jsonConfig);
};
// ====================================================================
// = Transform-Methods
// ====================================================================
//Methods for transforming certain values in the JSON-Config-File into
//specific Objects (e.g. into layer-objects)
/**
* @private
* Transforms a value for the tile-size into a OpenLayers.Size-object
*
* @param {Integer} value The pixel-size of the tiles
* @return {OpenLayers.Size} (if value shouldn´t be a number, only the value
* is returned)
*/
Custom.config.ConfigParser.prototype.createTileSize = function (value) {
if (typeof value == "number") {
return new OpenLayers.Size(value, value)
}
return value;
};
/**
* @private
* Transforms a coordinate-pair into a OpenLayers.LonLat-object
*
* @param {Object} value Object containing the Lon and Lat-value, for example:
* <pre><code> {lon: 123414, lat: 125634}</code></pre>
* @return {OpenLayers.LonLat} (if the value doesn´t match the required format
* only the value is returned)
*/
Custom.config.ConfigParser.prototype.createLonLat = function (value) {
if (typeof value.lon != "undefined" && typeof value.lat != "undefined") {
return new OpenLayers.LonLat(value.lon, value.lat);
} else if (typeof value === "string" && value.split(",").length === 2) {
return new OpenLayers.LonLat(value.split(",")[0], value.split(",")[1]);
} else {
return value;
}
};
/**
* @private
* Transforms a EPSG-coordinate-string into a OpenLayers.Projection-object
*
* @param {String} value The EPSG-string (e.g. "EPSG:4326")
* @return {OpenLayers.Projection} (if the value isn´t a String only the value is returned)
*/
Custom.config.ConfigParser.prototype.createProjection = function (value) {
if (typeof value == "string") {
return new OpenLayers.Projection(value);
}
return value;
};
/**
* @private
* Transform a array of coordinates into a OpenLayers.Bounds object
*
* @param {Number[]} value Array of the coordinates defining the bounds
* (in the order: left,bottom,right,top)
* @return {OpenLayers.Bounds} (if the value doesn´t match the required format only
* the value is returned)
*/
Custom.config.ConfigParser.prototype.createBounds = function (value) {
if (typeof value == "object" && value.length && value.length == 4) {
return OpenLayers.Bounds.fromArray(value);
} else if (typeof value === "string" && value.split(",").length === 4) {
var coords = value.split(",");
return new OpenLayers.Bounds(coords[0], coords[1], coords[2], coords[3]);
} else {
return value;
}
};
/**
* @private
* loops through the array of layer-configs and triggers the
* create-layer-method for each of them. The created layers are
* saved in-place (i.e. in the JSON-object)
* @param {Object} value The array of layerconfigs
*/
Custom.config.ConfigParser.prototype.createLayers = function (value) {
if (typeof value == "object" && value.length) {
for (var i = 0; i < value.length; i++) {
if (value[i].url && value[i].title && value[i].layer) {
value[i] = this.createLayer(value[i], true);
}
}
}
return value;
};
/**
* @private
* creates an OpenLayers-layerobject based on a layer-config from the JSON
* @param {Object} value The layer-configuration
* @return {OpenLayers.Layer.ArcGISCache} layerObject
*/
Custom.config.ConfigParser.prototype.createLayer = function (value, isBaseLayer) {
if (value.wmsUrl) {
// Basiskarte
var layerObject = new OpenLayers.Layer.ArcGISCache(value.title, value.url, {
layers: value.layer,
transparent: true,
//Rausgenommen, TD, 05.03.2015: wms: value.wmsUrl,
port: value.portForWMSLayer,
tileSize: value.tileSize ? value.tileSize : null,
tileOrigin: value.tileOrigin ? value.tileOrigin : null,
projection: value.projection ? value.projection : null,
transitionEffect: value.transitionEffect ? value.transitionEffect : 'resize',
isBaseLayer: isBaseLayer ? isBaseLayer : true
});
} else {
// Orthophotos
var layerObject = new OpenLayers.Layer.WMS(value.title, value.url, {
layers: value.layer,
format: 'image/jpeg'
}, {
projection: value.projection ? value.projection : null,
tileSize: value.tileSize ? value.tileSize : null,
tileOrigin: value.tileOrigin ? value.tileOrigin : null,
transitionEffect: value.transitionEffect ? value.transitionEffect : 'resize',
isBaseLayer: isBaseLayer ? isBaseLayer : false
});
}
if (typeof layerObject != "undefined") {
return layerObject;
}
return value;
};
// ====================================================================
// = Render-method
// ====================================================================
/**
* @private
* after parsing the JSON (including transformations), the layout is created
* based on this configuration. This includes:
*
* - creation of mapObject and mapPanel
* - creation of the modules (= Panels in the westPanel)
* - creation of the toolbar-items
* - creation of the layout-containers (westPanel, centerPanel, viewport)
*
* Links to the created items are saved in the refs-object (while the refs
* are saved in every layout-item)
* @param {Object} jsonConfig The parsed JSON
*/
Custom.config.ConfigParser.prototype.doRender = function (jsonConfig) {
/*
* setting up the refs-object that will be filled with references to all relevant
* parts of the application. Elements that need to have access to those parts are
* equiped with a reference to the refs-object.
*/
var refs = {};
// saving reference to the jsonConfig
refs.jsonConfig = jsonConfig;
// make it available in Customs
Custom.jsonConfig = jsonConfig;
// creating the config-interface
refs.configInterface = new Custom.config.ConfigInterface(refs);
// creating mapObject and mapPanel
var mapObject = Custom.config.Map.createMapObject(jsonConfig.map.mapSettings);
var mapPanel = Custom.config.Map.createMapPanel(jsonConfig.map.mapSettings, mapObject);
refs.mapObject = mapObject;
refs.mapPanel = mapPanel;
// creating the map-toolbar
var mapToolbar = [];
if (jsonConfig.map.toolbar) {
var tbItemsArray = Custom.config.Map.createToolbarItems(jsonConfig.map.toolbar, refs);
//empty bottom toolbar
var tb = new Ext.Toolbar({
autoHeight: true
});
//create panel with 2 toolbars
mapToolbar = new Ext.Panel({
// items: tbItemsArray,
id: 'tlb_pane',
tbar: tbItemsArray,
bbar: tb
})
}
var moduleArray = Custom.config.Modules.createModules(jsonConfig.modules, refs);
// ==================================================================
// = Layout-Panels =
// ==================================================================
// prepare refs for saving references to layout-panels
refs.layout = {};
refs.layout.mapToolbar = mapToolbar;
// container for making the map fill the rest of the space in the vbox-layout
var mapContainer = new Ext.Container({
layout: 'fit',
items: mapPanel,
flex: 1
});
/*
* Westpanel using the Ext.ux.PortalColumn-class which allows changing the order
* of Panels insided via drag-and-drop
*/
var westPanel = new Ext.ux.PortalColumn({
columnWidth: 1,
items: moduleArray
});
refs.layout.westPanel = westPanel;
/*
* Proxy
*/
if (jsonConfig.general.proxy && jsonConfig.general.proxy.url && jsonConfig.general.proxy.url != "") {
OpenLayers.ProxyHost = jsonConfig.general.proxy.url;
}
/*
* Creating logo for the application if it was defined in the config-script
*/
if (jsonConfig.general && jsonConfig.general.logo && jsonConfig.general.logo.displayLogo === true) {
var logoConf = jsonConfig.general.logo;
var imgHeight = logoConf.height ? logoConf.height : 35;
var logoContainer = new Ext.Container({
style: {
padding: '2px',
textAlign: 'center'
},
html: "<img src='" + logoConf.logoSrc + "' height='" + imgHeight + "'/>",
width: '100%',
height: logoConf.height ? (logoConf.height + 4) : 39
})
}
/*
* Container for the elements in the westpanel
*/
var westPanelContainer = new Ext.ux.Portal({
region: 'west',
width: 300,
minWidth: 200,
collapsible: true,
split: true,
autoScroll: true,
items: [westPanel],
tbar: logoContainer ? logoContainer : null,
bbar: [{
text: "Alle minimieren",
id: 'alleminimieren',
refs: refs,
handler: function () {
var modules = this.refs.modules;
for (var module in modules) {
modules[module].collapse();
}
}
}, {
text: "Alle maximieren",
id: 'allemaximieren',
refs: refs,
handler: function () {
var modules = this.refs.modules;
for (var module in modules) {
modules[module].expand();
}
}
}]
});
refs.layout.westPanelContainer = westPanelContainer;
/*
* CenterPanel: Container for the mapPanel and toolbar(s)
*/
var centerPanel = new Ext.Panel({
autoDestroy: false,
layout: {
type: 'vbox',
align: 'stretch'
},
region: 'center',
items: [mapToolbar, mapContainer],
hideBorders: true
});
refs.layout.centerPanel = centerPanel;
/*
* The viewport containing all elements visible on intial load
*/
refs.layout.viewport = new Ext.Viewport({
layout: "fit",
hideBorders: true,
items: {
layout: "border",
// deferredRender : false,
items: [westPanelContainer, centerPanel]
}
});
/*
* this two zoom-actions seem to be necessary for the map to display
* correctly
*/
mapPanel.map.zoomIn();
mapPanel.map.zoomOut();
/**
* finally we detect potential URL parameters and zoom to specific
* object geometries by their id.
*
* we will show a loadingmask and load all asynctreenodes in the beginning
* as this is required for toggling layers automatically on and off after
* reacting on url parameters. Otherwise, the nodes and layers would not exist
* in the beginning, only after user has actively requested them by click on
* the matching folder in the tree
*/
var loadMask = new Ext.LoadMask(Ext.getBody(), {msg: "Bitte warten, Themen werden abgerufen..."});
loadMask.show();
/**
* function will handle given url params in order to zoom to an specfic
* object on map, highlight it and activate the corresponding layer
*/
var handleUrlParams = function () {
var params = OpenLayers.Util.getParameters(),
mapPanel = GeoExt.MapPanel.guess(),
map = mapPanel.map,
urlKeys = [],
urlVals = [],
filterLayer;
Ext.iterate(params, function (k, v) {
var matchInConfigFound = false;
Ext.iterate(jsonConfig.map.featureFilterAttribute2LayerMapping,
function (configKey, configValue) {
if (configKey === k) {
matchInConfigFound = true;
return false;
}
});
if (matchInConfigFound) {
urlKeys.push(k);
urlVals.push(v);
} else {
Ext.Msg.alert("Fehler", "Es wurde ein Filter übergeben, aber " +
"kein passender Layer mit der zugeordneten Eigenschaft gefunden!");
}
});
if (urlKeys.length === 1) {
// handling a single filter parameter.
// this can be potential any layer, so we will check the property
// name against the jsonConfig.map.featureFilterAttribute2LayerMapping
// to identify the correct layer
var urlFilterProperty = urlKeys[0],
layerName = jsonConfig.map.featureFilterAttribute2LayerMapping[urlFilterProperty],
tree = Ext.getCmp('layertree'),
root = tree.getRootNode(),
layer,
node;
root.cascade(function (n) {
if (n.attributes.text === layerName) {
node = n;
layer = n.attributes.layer;
}
});
if (!Ext.isEmpty(layer) && !Ext.isEmpty(node)) {
// make the layer visible
if (!layer.map) {
map.addLayer(layer);
}
node.ui.toggleCheck(true);
// setup the filter url
// example url: http://ds90101a.applrs.de.tmo:8399/arcgis/rest/services/telekomgeometrien/MapServer/1/query?where=kvz_id%3D%2722863A142%27&f=pjson&maxAllowableOffset=5000
var baseUrl = layer.wms ? layer.wms : layer.url,
fid = urlVals[0],
filterProperty = urlKeys[0],
layerId = (layer.params && layer.params.LAYERS &&
layer.params.LAYERS.indexOf("show:") > -1) ?
layer.params.LAYERS.split("show:")[1] : null,
maxAllowableOffset = jsonConfig.map.featureFilterMaxAllowableOffset ?
jsonConfig.map.featureFilterMaxAllowableOffset :
(map.getExtent().right - map.getExtent().left) / map.getCurrentSize().w;
// removing potential "export" path in URL
if (baseUrl.indexOf("/export") > -1) {
baseUrl = baseUrl.replace("/export", "");
}
url = baseUrl + "/" + layerId + "/query?where=" +
filterProperty + "%3D%27" + fid + "%27" +
"&f=pjson&maxAllowableOffset=" + maxAllowableOffset;
// register listener on mappanel to zoom to feature
mapPanel.on('featureFromArcGisServerArrived', Custom.zoomToAndHighlightFeature, this, {single: true});
// request the feature
Custom.getFeatureFromArcGisServer(url, true);
} else {
Ext.Msg.alert("Fehler", "Es konnte kein Layer mit dem Namen " + layerName + " gefunden werden!");
}
} else if (urlKeys.length > 1) {
Ext.Msg.alert("Fehler", "Es wurden mehrere URL-Parameter zum Zoomen auf ein " +
"Objekt übergeben, aber es kann nur auf ein Objekt eines Themas " +
"gezoomt werden!");
}
};
/**
* starting a delayed task to have the viewport already rendered and the
* loadmask shown before expanding the roots childnodes
*/
var expandNodesTask = new Ext.util.DelayedTask(function () {
var layerTree = Ext.getCmp('layertree'),
root = layerTree.getRootNode();
root.expandChildNodes();
});
expandNodesTask.delay(1000);
/**
* checking the treestate regularly to detect when all async layernodes have
* been loaded to continue with filtering
*/
var checkTreeStateTask = {
run: function () {
var layerTree = Ext.getCmp('layertree'),
root = layerTree.getRootNode(),
expectedRenderedCount = root.childNodes.length,
renderedNodes = 0;
root.eachChild(function (asyncNode) {
if (asyncNode.loaded) {
renderedNodes++;
}
});
if (renderedNodes === expectedRenderedCount) {
root.collapse();
loadMask.hide();
Ext.TaskMgr.stopAll();
handleUrlParams();
}
},
interval: 1000
};
Ext.TaskMgr.start(checkTreeStateTask);
};
// Declaring array of tabIndices and IDs of elements
var elem = {};
// Declaring array of elements which should be tabable
tabableElements = ["Client", "Toolbar", "FeatureInfo", "Pan", "ZoomIn", "ZoomOut", "Gesamtansicht",
"Suche", "Transparenz", "Legende", "Hilfe", "Impressum", "Karte", "Up", "Left", "Right", "Down",
"Plus", "Minus", "LayerHinzufuegen", "AktiveLayer", "MapLayers", "Filter", "LayerTransparenz",
"Slider", "AlleMinimieren", "AlleMaximieren", "Collapse"];
// Function to check whether an element has a certain class
var hasClass = function(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
};
var keyboardControl = new OpenLayers.Control();
var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
keydown: function(evt) {
switch (evt.keyCode) {
// clicking Alt+A activates Aktive Layer
case evt.altKey && 97:
case evt.altKey && 65:
document.getElementById(elem.AktiveLayer.id).focus();
var layers = document.getElementById(elem.AktiveLayer.id).getElementsByClassName('x-tree-node-ct')[0].childNodes;
for (var i = 0, len = layers.length - 2; i < len; i++) {
layers[i].getElementsByTagName('input')[0].setAttribute('tabIndex', elem.AktiveLayer.index + len * i + 2);
layers[i].getElementsByClassName('x-tree-node-icon')[0].setAttribute('tabIndex', elem.AktiveLayer.index + len * i + 3);
layers[i].getElementsByClassName('x-tree-node-icon')[1].setAttribute('tabIndex', elem.AktiveLayer.index + len * i + 4);
layers[i].getElementsByTagName('a')[0].getElementsByTagName('span')[0].setAttribute('tabIndex', elem.AktiveLayer.index + len * i + 5);
layers[i].getElementsByClassName('x-tree-node-anchor')[0].removeAttribute('tabIndex');
}
layers[layers.length-2].firstChild.setAttribute("tabIndex", elem.AktiveLayer.index + 2 + (layers.length-2)*4);
layers[layers.length-1].firstChild.setAttribute("tabIndex", elem.AktiveLayer.index + 2 + (layers.length-1)*4);
break;
// clicking Alt+C activates Collapsing/Expanding left side menu
case evt.altKey && 99:
case evt.altKey && 67:
document.getElementById(elem.Collapse.id).click();
break;
// clicking Alt+D activates Layer Hinzufuegen
case evt.altKey && 100:
case evt.altKey && 68:
document.getElementById(elem.LayerHinzufuegen.id).focus();
break;
// clicking Alt+F activates/deactivates FeatureInfo
case evt.altKey && 102:
case evt.altKey && 70:
document.getElementById(elem.FeatureInfo.id).click();
break;
// clicking Alt+I activates Suche Panel
case evt.altKey && 105:
case evt.altKey && 73:
document.getElementById(elem.Filter.id).focus();
document.getElementById('andradiobutton').setAttribute('tabIndex', -1);
document.getElementById('orradiobutton').setAttribute('tabIndex', -1);
elem.AndRadioButton.id = document.getElementById('andradiobutton').parentElement.id;
elem.OrRadioButton.id = document.getElementById('orradiobutton').parentElement.id;
document.getElementById(elem.AndRadioButton.id).setAttribute('tabIndex', elem.AndRadioButton.index);
document.getElementById(elem.OrRadioButton.id).setAttribute('tabIndex', elem.OrRadioButton.index);
break;
// clicking Alt+L activates/deactivates Legende
case evt.altKey && 108:
case evt.altKey && 76:
document.getElementById('checkBoxLegend').click();
break;
// clicking Alt+M activates the map area
case evt.altKey && 109:
case evt.altKey && 77:
var map = GeoExt.MapPanel.guess().map;
map.getControlsByClass('OpenLayers.Control.KeyboardDefaults')[0].activate();
document.getElementById(elem.Karte.id).focus();
break;
// clicking Alt+P activates/deactivates Transparenz
case evt.altKey && 112:
case evt.altKey && 80:
document.getElementById('checkBoxTransparency').click();
break;
// clicking Alt+S activates Suche
case evt.altKey && 115:
case evt.altKey && 83:
document.getElementById('checkBoxFilter').click();
break;
// clicking Alt+Q activates Barrierefreiheit functionality
case evt.altKey && 113:
case evt.altKey && 81:
Ext.getCmp('barrierefreiheitButton').handler();
break;
// clicking Alt+T activates Toolbar
case evt.altKey && 116:
case evt.altKey && 84:
document.getElementById(elem.Toolbar.id).focus();
break;
// clicking Alt+W activates Collapsing/Expanding left panels
case evt.altKey && 119:
case evt.altKey && 87:
if (hasClass(document.getElementById(elem.LayerHinzufuegen.id), "x-panel-collapsed") &&
hasClass(document.getElementById(elem.AktiveLayer.id), "x-panel-collapsed")) {
document.getElementById(elem.AlleMaximieren.id).click();
} else {
document.getElementById(elem.AlleMinimieren.id).click();
}
return;
// clicking Alt+Z activates the Layer-Transparenz panel
case evt.altKey && 122:
case evt.altKey && 90:
document.getElementById(elem.LayerTransparenz.id).focus();
var transparenzEingabeFeld;
var slider = document.getElementById('transparencyslider');
var sliderId = slider.getElementsByClassName('x-slider-thumb')[0].id;
if (document.getElementById('transparencyvalue') == null) {
var sliderParentId = slider.parentElement.id;
var sliderParent = document.getElementById(sliderParentId);
transparenzEingabeFeld = document.createElement('span');
transparenzEingabeFeld.setAttribute("id", "transparencyvalue");
sliderParent.appendChild(transparenzEingabeFeld);
}
// Initiating observer for tracking any changes in the element's style
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName == "style") {
var sliderValue = document.getElementById(sliderId).style['left'].match(/(\d*\.?){2}/);
var sliderWidth = parseFloat(slider.firstChild.firstChild.style['width'].match(/(\d*\.?){2}/));
var transparencyValue = Math.round(parseFloat(sliderValue)/sliderWidth*100);
transparenzEingabeFeld.innerHTML = "Der Transparenzwert ist " + transparencyValue + "%";
}
});
});
observer.observe(document.getElementById(sliderId), {attributes: true});
break;
// clicking enter triggers expanding tree nodes
case 13:
if (hasClass(document.activeElement, 'x-tree-node-anchor')) {
document.activeElement.parentElement.children[1].click();
}
break;
// clicking escape triggers closing FeatureInfo
case 27:
document.getElementsByClassName('x-tool-close')[0].click();
break;
// clicking space triggers selecting tree nodes
case 32:
if (hasClass(document.activeElement, 'x-tree-node-anchor') &&
(document.activeElement.childElementCount == 1)) {
document.activeElement.parentElement.children[2].click();
}
if (hasClass(document.activeElement, 'x-tree-node-icon')) {
document.activeElement.click();
}
if (document.activeElement.id == elem.Suche.id ||
document.activeElement.id == elem.Transparenz.id ||
document.activeElement.id == elem.Legende.id) {
document.activeElement.firstChild.click();
}
if (document.activeElement.parentNode.hasAttribute('hidefocus')) {
document.activeElement.click();
}
if (hasClass(document.activeElement, 'x-form-check-wrap') &&
(document.activeElement.querySelectorAll('input[type=radio]').length > 0)) {
document.activeElement.firstChild.click();
}
if (hasClass(document.activeElement, 'x-tree-node-leaf') &&
(document.activeElement.querySelectorAll('input[type=radio]').length > 0)) {
document.activeElement.querySelectorAll('input[type=radio]')[0].click();
}
//tab in featureInfo popup
if(hasClass(document.activeElement, 'popup_tab')){
if (hasClass(document.activeElement, 'x-tab-strip-active')){
var tab_id = document.activeElement.id;
var panel_id = tab_id.split('__')[1];
var panel = document.getElementById(panel_id);
var panel_header = panel.getElementsByClassName('x-grid3-hd-row')[0];
for(var i = 0; i < panel_header.childNodes.length; i++) {
var attribute_name = panel_header.childNodes[i];
attribute_name.className +=" attribute";
attribute_name.tabIndex =6203 + i;
}
}
console.log('click', document.activeElement);
document.activeElement.children[1].click();
};
break;
// blocking map shifting when left menu panels are activated
case 37:
case 38:
case 39:
var map = GeoExt.MapPanel.guess().map;
if (document.activeElement.id == elem.Karte.id ||
document.getElementById(elem.Karte.id).contains(document.activeElement)) {
map.getControlsByClass('OpenLayers.Control.KeyboardDefaults')[0].activate();
} else {
map.getControlsByClass('OpenLayers.Control.KeyboardDefaults')[0].deactivate();
}
break;
// clicking down arrow to get into the tree children
case 40:
var map = GeoExt.MapPanel.guess().map;
if (document.activeElement.id == elem.Karte.id) {
map.getControlsByClass('OpenLayers.Control.KeyboardDefaults')[0].activate();
} else {
map.getControlsByClass('OpenLayers.Control.KeyboardDefaults')[0].deactivate();
if (document.activeElement.id == elem.LayerHinzufuegen.id) {
console.log('dafuq');
console.log(document.activeElement);
document.activeElement.getElementsByClassName('x-tree-node-el')[0].focus();
document.activeElement.getElementsByClassName('x-tree-node-el')[0].click();
}
}
break;
}
}
});
keyHandler.activate();
activateBarrierefreiheit = function(){
elem = {
'Client': {'id': document.getElementsByClassName('x-toolbar')[1].parentElement.id, 'index': -1},
'Toolbar': {'id': document.getElementsByClassName('x-toolbar')[1].id, 'index': 1},
'FeatureInfo': {
'id': document.getElementById('toolbarFeatureInfo').getElementsByTagName('button')[0].id,
'index': 2
},
'Pan': {'id': document.getElementById('toolbarPan').getElementsByTagName('button')[0].id, 'index': 3},
'ZoomIn': {'id': document.getElementById('toolbarZoomIn').getElementsByTagName('button')[0].id, 'index': 4},
'ZoomOut': {'id': document.getElementById('toolbarZoomOut').getElementsByTagName('button')[0].id, 'index': 5},
'Gesamtansicht': {
'id': document.getElementById('toolbarGesamtansicht').getElementsByTagName('button')[0].id,
'index': 6
},
'Suche': {'id': document.getElementById('checkBoxFilter').parentElement.id, 'index': 7},
'Transparenz': {'id': document.getElementById('checkBoxTransparency').parentElement.id, 'index': 8},
'Legende': {'id': document.getElementById('checkBoxLegend').parentElement.id, 'index': 9},
'Hilfe': {'id': document.getElementById('hilfeButton').getElementsByTagName('button')[0].id, 'index': 10},
'Impressum': {
'id': document.getElementById('impressumButton').getElementsByTagName('button')[0].id,
'index': 11
},
'Karte': {'id': 'MapAreaPanel', 'index': 20},
'Up': {'id': 'OpenLayers.Control.PanZoomBar_10_panup', 'index': 21},
'Left': {'id': 'OpenLayers.Control.PanZoomBar_10_panleft', 'index': 22},
'Right': {'id': 'OpenLayers.Control.PanZoomBar_10_panright', 'index': 23},
'Down': {'id': 'OpenLayers.Control.PanZoomBar_10_pandown', 'index': 24},
'Plus': {'id': 'OpenLayers.Control.PanZoomBar_10_zoomin', 'index': 25},
'Minus': {'id': 'OpenLayers.Control.PanZoomBar_10_zoomout', 'index': 26},
'LayerHinzufuegen': {'id': 'layertree', 'index': 100},
'AktiveLayer': {'id': 'aktivelayer', 'index': 200},
'MapLayers': {'id': 'extdd-3', 'index': 201},
'Filter': {'id': 'suchepanel', 'index': 0},
'LayerTransparenz': {
'id': document.getElementById('transparencyslider').parentElement.parentElement.parentElement.id,
'index': 0
},
'Slider': {'id': 'transparencyslider', 'index': 0},
'AlleMinimieren': {
'id': document.getElementById('alleminimieren').getElementsByTagName('button')[0].id,
'index': 0
},
'AlleMaximieren': {
'id': document.getElementById('allemaximieren').getElementsByTagName('button')[0].id,
'index': 0
},
'Collapse': {'id': document.getElementsByClassName('x-tool-collapse-west')[0].id, 'index': -1},
'AndRadioButton': {'index': 0},
'OrRadioButton': {'index': 0},
FeatureInfoPopup: {
popup_window: { class_name: "popup_window", tag: document.getElementsByClassName(this.class_name)[0], index: 50},
// head_panel: {
// close: {tag: document.getElementsByClassName('popup_window')[0].getElementsByClassName('x-tool x-tool-close')[0], index: 6213},
// maximize: {tag: document.getElementsByClassName('popup_window')[0].getElementsByClassName('x-tool x-tool-maximize')[0], index: 6212},
// unpin: {tag: document.getElementsByClassName('popup_window')[0].getElementsByClassName('x-tool x-tool-unpin')[0], index: 6211}
// },
tabs: {class_name: "popup_tabs", index: 51},
//...
bottom_panel:{
btn:{
}
}
}
};
// removing all tabIndex properties that are already set (especially for the tree)
var elementsToUntab = document.getElementsByClassName('x-tree-node-anchor');
for (var i = 0, len = elementsToUntab.length; i < len; i++) {
elementsToUntab[i].removeAttribute("tabindex");
}
if (!document.getElementById("barrierefreiheitcss")) {
// adding styles for Barrierefreiheit
var css = '#' + elem.Karte.id + ':focus,' +
'#' + elem.Toolbar.id + ':focus,' +
'#' + elem.FeatureInfo.id + ':focus,' +
'.popup_window:focus,' +
'.popup_window_head:focus,' +
'.popup_window_tabs:focus,' +
'.popup_tab:focus,' +
'.'+'popup_close' + ':focus,' +
'.'+'popup_maximize' + ':focus,' +
'.'+'popup_unpin' + ':focus,' +
'.'+'object_attribute' + ':focus,' +
'#' + elem.Hilfe.id + ':focus,' +
'#' + elem.Impressum.id + ':focus,' +
'#' + elem.LayerHinzufuegen.id + ':focus,' +
'#' + elem.AktiveLayer.id + ':focus,' +
'#' + elem.Filter.id + ':focus,' +
'#' + elem.LayerTransparenz.id + ':focus,' +
'#' + elem.Slider.id + ':focus,' +
'#' + elem.Collapse.id + ':focus,' +
'#' + elem.MapLayers.id + ':focus,' +
'.x-tree-node-leaf:focus,' +
'.x-form-check-wrap:focus,' +
'.x-tree-node-icon:focus,' +
'.x-tree-node-el a span:focus,' +
'.x-toolbar-cell button:focus,' +
'.x-toolbar-cell .x-form-check-wrap:focus {' +
'border: 1px solid magenta;' +
'}' +
'input[type="checkbox"]:focus {' +
'background: magenta;' +
'outline: 1px solid magenta;' +
'}';
head = document.getElementsByTagName('head')[0];
style = document.createElement('style');
style.type = 'text/css';
style.id = "barrierefreiheitcss";
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
}
// Assigning tabIndices to the elements
for (var i = 0, len = tabableElements.length; i < len; i++) {
var name = tabableElements[i];
document.getElementById(elem[name].id).setAttribute('tabIndex', elem[name].index);
}
document.getElementById(elem.Client.id).focus();
};
window.onresize =function() {
//getting toolbar panel
//panel has topToolbar and bottomToolbar
var panel = window.Ext.getCmp('tlb_pane');
var tbar = panel.getTopToolbar();
var bbar = panel.getBottomToolbar();
var items,topItems, botItems;
console.log(screen);
console.log(window.screen.availHeight - (window.outerHeight - window.innerHeight));
if(window.innerWidth < 1000){
console.log('Wild two panels appears!');
console.log(document.getElementById('barrierefreiheitButton').parentElement.parentElement);
document.getElementById('barrierefreiheitButton').parentElement.parentElement.style.display = "none";
items = tbar.items.items;
//splitting elements of top toolbar on two parts
//second part goes to bottom toolbar
topItems = items.slice(0,10);
botItems = items.slice(10);
//bottom bar has elements already
if (bbar.items.items.length > 4)
return;
//adding elements to bottombar
//AND removing them from topbar
var l = botItems.length;
for(var i = 0 ; i < l; i++){
bbar.add(botItems[i]);
}
//show hidden bottom toolbar
panel.bbar.show();
//render changes
tbar.doLayout();
bbar.doLayout();
}else {
topItems = tbar.items.items;
botItems = bbar.items.items;
items = [];
for(var i = 0; i ,i< botItems.length;i ++)
items.push(botItems[i]);
if (botItems.length == 0)
return;
for(var j = 0 ; j < items.length; j++){
tbar.add(items[j]);
}
//get rid of this stupid white strip
panel.bbar.setVisibilityMode(Ext.Element.DISPLAY);
panel.bbar.hide();
panel.syncSize();
//render changes
tbar.doLayout();
bbar.doLayout();
//panel with Hilfe and K appears again
document.getElementById('barrierefreiheitButton').parentElement.parentElement.style.display = "";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment