<commit_before>/**
 * @namespace hs.permalink
 * @memberOf hs
 */
define(['angular', 'bson', 'map', 'core'],

    function(angular, bson) {
        angular.module('hs.permalink', ['hs.core', 'hs.map'])
            .directive('hs.permalink.directive', function() {
                return {
                    templateUrl: hsl_path + 'components/permalink/partials/directive.html?bust=' + gitsha
                };
            })
            .service("hs.permalink.service_url", ['$rootScope', 'hs.map.service', 'Core', 'hs.utils.service',
                function($rootScope, OlMap, Core, utils) {
                    var BSON = bson().BSON;
                    var url_generation = true;
                    //some of the code is taken from http://stackoverflow.com/questions/22258793/set-url-parameters-without-causing-page-refresh
                    var me = {};
                    me.current_url = "";
                    me.update = function(e) {
                        var view = OlMap.map.getView();
                        var paramJson = {};
                        paramJson.hsX = view.getCenter()[0];
                        paramJson.hsY = view.getCenter()[1];
                        paramJson.hsZ = view.getZoom();
                        paramJson.hsPanel = Core.mainpanel;
                        var visible_layers = [];
                        OlMap.map.getLayers().forEach(function(lyr) {
                            if (lyr.get('show_in_manager') != null && lyr.get('show_in_manager') == false) return;
                            if (lyr.getVisible()) {
                                visible_layers.push(lyr.get("title"));
                            }
                        });
                        paramJson.hsVisibleLayers = visible_layers.join(";");

                        me.push('state', utils.createHexString(BSON.serialize(paramJson, false, true, false)));
                        history.pushState({}, "", me.current_url);
                        $rootScope.$broadcast('browserurl.updated');
                    };
                    me.parse = function(str) {
                        if (typeof str !== 'string') {
                            return {};
                        }

                        str = str.trim().replace(/^\?/, '');

                        if (!str) {
                            return {};
                        }

                        return str.trim().split('&').reduce(function(ret, param) {
                            var parts = param.replace(/\+/g, ' ').split('=');
                            var key = parts[0];
                            var val = parts[1];

                            key = decodeURIComponent(key);
                            // missing `=` should be `null`:
                            // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
                            val = val === undefined ? null : decodeURIComponent(val);

                            if (!ret.hasOwnProperty(key)) {
                                ret[key] = val;
                            } else if (Array.isArray(ret[key])) {
                                ret[key].push(val);
                            } else {
                                ret[key] = [ret[key], val];
                            }

                            return ret;
                        }, {});
                    };
                    me.stringify = function(obj) {
                        return obj ? Object.keys(obj).map(function(key) {
                            var val = obj[key];

                            if (Array.isArray(val)) {
                                return val.map(function(val2) {
                                    return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
                                }).join('&');
                            }

                            return encodeURIComponent(key) + '=' + encodeURIComponent(val);
                        }).join('&') : '';
                    };
                    me.push = function(key, new_value) {
                        me.params[key] = new_value;
                        var new_params_string = me.stringify(me.params);
                        me.current_url = window.location.pathname + '?' + new_params_string;
                    };
                    me.params = me.parse(location.search);
                    me.getParamValue = function(param, loc) {
                        if (!loc) loc = location.search;
                        var tmp = me.parse(loc);
                        if (tmp.state) {
                            var jsonString = BSON.deserialize(utils.parseHexString(tmp.state));
                            delete tmp.state;
                            tmp['hs_x'] = jsonString.hsX;
                            tmp['hs_y'] = jsonString.hsY;
                            tmp['hs_z'] = jsonString.hsZ;
                            tmp['hs_panel'] = jsonString.hsPanel;
                            tmp['visible_layers'] = jsonString.hsVisibleLayers;
                        }

                        if (tmp[param]) return tmp[param];
                        else return null;
                    };<commit_msg>base64 hashing of permalink<commit_after>/**
 * @namespace hs.permalink
 * @memberOf hs
 */
define(['angular', 'bson', 'map', 'core'],

    function(angular, bson) {
        angular.module('hs.permalink', ['hs.core', 'hs.map'])
            .directive('hs.permalink.directive', function() {
                return {
                    templateUrl: hsl_path + 'components/permalink/partials/directive.html?bust=' + gitsha
                };
            })
            .service("hs.permalink.service_url", ['$rootScope', 'hs.map.service', 'Core', 'hs.utils.service',
                function($rootScope, OlMap, Core, utils) {
                    var BSON = bson().BSON;
                    var url_generation = true;
                    //some of the code is taken from http://stackoverflow.com/questions/22258793/set-url-parameters-without-causing-page-refresh
                    var me = {};
                    me.current_url = "";
                    me.update = function(e) {
                        var view = OlMap.map.getView();
                        var paramJson = {};
                        paramJson.hsX = view.getCenter()[0];
                        paramJson.hsY = view.getCenter()[1];
                        paramJson.hsZ = view.getZoom();
                        paramJson.hsPanel = Core.mainpanel;
                        var visible_layers = [];
                        OlMap.map.getLayers().forEach(function(lyr) {
                            if (lyr.get('show_in_manager') != null && lyr.get('show_in_manager') == false) return;
                            if (lyr.getVisible()) {
                                visible_layers.push(lyr.get("title"));
                            }
                        });
                        paramJson.hsVisibleLayers = visible_layers.join(";");

                        me.push('state', window.btoa(utils.createHexString(BSON.serialize(paramJson, false, true, false))));
                        history.pushState({}, "", me.current_url);
                        $rootScope.$broadcast('browserurl.updated');
                    };
                    me.parse = function(str) {
                        if (typeof str !== 'string') {
                            return {};
                        }

                        str = str.trim().replace(/^\?/, '');

                        if (!str) {
                            return {};
                        }

                        return str.trim().split('&').reduce(function(ret, param) {
                            var parts = param.replace(/\+/g, ' ').split('=');
                            var key = parts[0];
                            var val = parts[1];

                            key = decodeURIComponent(key);
                            // missing `=` should be `null`:
                            // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
                            val = val === undefined ? null : decodeURIComponent(val);

                            if (!ret.hasOwnProperty(key)) {
                                ret[key] = val;
                            } else if (Array.isArray(ret[key])) {
                                ret[key].push(val);
                            } else {
                                ret[key] = [ret[key], val];
                            }

                            return ret;
                        }, {});
                    };
                    me.stringify = function(obj) {
                        return obj ? Object.keys(obj).map(function(key) {
                            var val = obj[key];

                            if (Array.isArray(val)) {
                                return val.map(function(val2) {
                                    return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
                                }).join('&');
                            }

                            return encodeURIComponent(key) + '=' + encodeURIComponent(val);
                        }).join('&') : '';
                    };
                    me.push = function(key, new_value) {
                        me.params[key] = new_value;
                        var new_params_string = me.stringify(me.params);
                        me.current_url = window.location.pathname + '?' + new_params_string;
                    };
                    me.params = me.parse(location.search);
                    me.getParamValue = function(param, loc) {
                        if (!loc) loc = location.search;
                        var tmp = me.parse(loc);
                        if (tmp.state) {
                            var jsonString = BSON.deserialize(utils.parseHexString(atob(tmp.state)));
                            delete tmp.state;
                            tmp['hs_x'] = jsonString.hsX;
                            tmp['hs_y'] = jsonString.hsY;
                            tmp['hs_z'] = jsonString.hsZ;
                            tmp['hs_panel'] = jsonString.hsPanel;
                            tmp['visible_layers'] = jsonString.hsVisibleLayers;
                        }

                        if (tmp[param]) return tmp[param];
                        else return null;
                    };
{'fraction_non_alphanumeric': 0.12054296912341077, 'fraction_numerical': 0.005353216709683586, 'mean_word_length': 0.9743347801471975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3082880', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2450, 'n_words': 407}