facilmap/frontend/index/index.js

63 wiersze
2.0 KiB
JavaScript
Czysty Zwykły widok Historia

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
fm.app.controller("PadCtrl", function($scope, $timeout, $element, fmUtils) {
$scope.padId = decodeURIComponent(location.pathname.match(/[^\/]*$/)[0]);
2016-10-20 08:26:17 +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)
});
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);
}
}
$timeout(function() {
var map = angular.element($("facilmap", $element)).controller("facilmap");
2016-10-20 08:26:17 +00:00
$scope.$watch(() => (map.client.padData && map.client.padData.name), function(newVal) {
$scope.padName = newVal;
});
2016-10-20 08:26:17 +00:00
$scope.$watch(() => (map.client.padId), function(padId) {
if(padId)
history.replaceState(null, "", fm.URL_PREFIX + padId + location.search + location.hash);
2016-10-20 08:26:17 +00:00
});
}, 0);
// Dereferrer
$(document).on("click", "a", function(e) {
var el = $(this);
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();
});