2017-02-09 11:45:42 +00:00
|
|
|
import fm from '../entry.js';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import ng from 'angular';
|
2019-06-22 11:32:35 +00:00
|
|
|
import { registerDeobfuscationHandlers } from "../app/fieldTypes/obfuscation";
|
2016-10-20 08:26:17 +00:00
|
|
|
|
2017-11-17 16:26:55 +00:00
|
|
|
fm.app.controller("PadCtrl", function($scope, $timeout, $element, fmUtils) {
|
2017-02-09 11:45:42 +00:00
|
|
|
$scope.padId = decodeURIComponent(location.pathname.match(/[^\/]*$/)[0]);
|
2016-10-20 08:26:17 +00:00
|
|
|
|
2017-11-17 16:26:55 +00:00
|
|
|
let queryParams = fmUtils.decodeQueryString(location.search);
|
|
|
|
let toBoolean = (val, def) => (val == null ? def : val != "0" && val != "false" && val != "no");
|
|
|
|
Object.assign($scope, {
|
|
|
|
toolbox: toBoolean(queryParams.toolbox, true),
|
|
|
|
search: toBoolean(queryParams.search, true),
|
|
|
|
autofocus: toBoolean(queryParams.autofocus, parent === window),
|
2017-12-23 14:19:39 +00:00
|
|
|
legend: toBoolean(queryParams.legend, true),
|
|
|
|
interactive: toBoolean(queryParams.interactive, parent === window)
|
2017-11-17 16:26:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if(!location.hash || location.hash == "#") {
|
|
|
|
let moveKeys = Object.keys(queryParams).filter((key) => ([ "zoom", "lat", "lon", "layer", "l", "q", "s", "c" ].includes(key)));
|
|
|
|
if(moveKeys.length > 0) {
|
|
|
|
let hashParams = { };
|
|
|
|
moveKeys.forEach((key) => {
|
|
|
|
hashParams[key] = queryParams[key];
|
|
|
|
delete queryParams[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
let query = fmUtils.encodeQueryString(queryParams);
|
|
|
|
let hash = fmUtils.encodeQueryString(hashParams);
|
|
|
|
|
|
|
|
history.replaceState(null, "", fm.URL_PREFIX + ($scope.padId || "") + (query ? "?" + query : "") + "#" + hash);
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 11:48:40 +00:00
|
|
|
|
2017-02-09 11:45:42 +00:00
|
|
|
$timeout(function() {
|
2017-05-11 01:47:46 +00:00
|
|
|
var map = angular.element($("facilmap", $element)).controller("facilmap");
|
2016-10-20 08:26:17 +00:00
|
|
|
|
2017-05-11 01:47:46 +00:00
|
|
|
$scope.$watch(() => (map.client.padData && map.client.padData.name), function(newVal) {
|
2017-02-09 11:45:42 +00:00
|
|
|
$scope.padName = newVal;
|
|
|
|
});
|
2016-10-20 08:26:17 +00:00
|
|
|
|
2017-05-11 01:47:46 +00:00
|
|
|
$scope.$watch(() => (map.client.padId), function(padId) {
|
2017-02-09 11:45:42 +00:00
|
|
|
if(padId)
|
2017-11-17 16:26:55 +00:00
|
|
|
history.replaceState(null, "", fm.URL_PREFIX + padId + location.search + location.hash);
|
2016-10-20 08:26:17 +00:00
|
|
|
});
|
2017-02-09 11:45:42 +00:00
|
|
|
}, 0);
|
|
|
|
|
|
|
|
// Dereferrer
|
|
|
|
$(document).on("click", "a", function(e) {
|
2017-02-10 21:40:37 +00:00
|
|
|
var el = $(this);
|
2017-02-09 11:45:42 +00:00
|
|
|
var href = el.attr("href");
|
|
|
|
if(href && href.match(/^\s*(https?:)?\/\//i)) {
|
|
|
|
el.attr("href", "deref.html?"+encodeURIComponent(href));
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
el.attr("href", href);
|
|
|
|
}, 0);
|
|
|
|
}
|
2016-10-20 08:26:17 +00:00
|
|
|
});
|
2019-06-22 11:32:35 +00:00
|
|
|
|
|
|
|
registerDeobfuscationHandlers();
|
2017-02-09 11:45:42 +00:00
|
|
|
});
|