<commit_before>define(['elaiJS/configuration', 'elaiJS/binder'],
          function(config, binder) {
	'use strict';
  
	var self = {};
	binder.addFunctions(self);
	
  var EVENT = {
    beforeUnload:           "beforeUnload",
    beforeUnloadInternal:   "beforeUnloadInternal",
    beforeUnloadNavigator:  "beforeUnloadNavigator",
    pageChanged:            "pageChanged",
    reload:                 "reload"
  };
	self.EVENT = EVENT;

  var ignoreHasChange = false;
  var beforeUnloadCallback;
	var beforeUnloadMessage;
	var beforeUnloadShowMessage;
	var currentPageInfo;
  
	self.initialize = function initialize() {
		window.onhashchange = function() {
		  if(ignoreHasChange)
		    return ignoreHasChange = false;
		  
		  if(beforeUnloadMessage) {
		    fire(EVENT.beforeUnload);
		    fire(EVENT.beforeUnloadInternal);
		    setTimeout(showInternalBeforeUnloadMessage());
		    return;
		  }

		  changeCurrentPage();
		};
		
		initializeCurrentPage();
	};
	
	function changeCurrentPage() {
    var oldPageInfo = currentPageInfo;
    initializeCurrentPage();
    fire(EVENT.pageChanged, currentPageInfo, oldPageInfo);
	}

	function fire(type, newPageInfo, oldPageInfo) {
		var event = {
		  type: type,
		  newPageInfo: newPageInfo,
		  oldPageInfo: oldPageInfo
		};

		self.fire(event);
	}
	
	function initializeCurrentPage() {
    currentPageInfo = buidCurrentPageInfo();
	}

	self.getCurrentPageInfo = function getCurrentPageInfo() {
	  return currentPageInfo;
	};

	self.goTo = function goTo(pageInfo) {
		location.hash = buildHash(pageInfo);
	};

	self.forward = function forward() {
		window.history.forward();
	};

	self.back = function back() {
		window.history.back();
	};

	self.reload = function reload() {
		fire(EVENT.reload, currentPageInfo);
	}
	
	self.getHistoryState = function getHistoryState(state) {
    return window.history.state;
	};
	
	self.saveHistoryState = function saveHistoryState(state) {
    window.history.pushState(state, "");
	};
	
	self.addToHistoryState = function addToHistoryState(params) {
    var state = self.getHistoryState();
	  if(!state)
	    state = {};
    
    for(var key in params)
      state[key] = params[key];
    
    self.saveHistoryState(state);
	};

	function buildHash(pageInfo) {
    if(!config.elaiJS.buildHash)
      throw new Error("Missing configuration for 'elaiJS.buildHash'.");

    return config.elaiJS.buildHash(pageInfo);
	}

	function buidCurrentPageInfo() {
    if(!config.elaiJS.extractPageInfo)
      throw new Error("Missing configuration for 'elaiJS.extractPageInfo'.");

    var hash = location.hash.substring(1);<commit_msg>Change pushState to replaceState for historyState<commit_after>define(['elaiJS/configuration', 'elaiJS/binder'],
          function(config, binder) {
	'use strict';
  
	var self = {};
	binder.addFunctions(self);
	
  var EVENT = {
    beforeUnload:           "beforeUnload",
    beforeUnloadInternal:   "beforeUnloadInternal",
    beforeUnloadNavigator:  "beforeUnloadNavigator",
    pageChanged:            "pageChanged",
    reload:                 "reload"
  };
	self.EVENT = EVENT;

  var ignoreHasChange = false;
  var beforeUnloadCallback;
	var beforeUnloadMessage;
	var beforeUnloadShowMessage;
	var currentPageInfo;
  
	self.initialize = function initialize() {
		window.onhashchange = function() {
		  if(ignoreHasChange)
		    return ignoreHasChange = false;
		  
		  if(beforeUnloadMessage) {
		    fire(EVENT.beforeUnload);
		    fire(EVENT.beforeUnloadInternal);
		    setTimeout(showInternalBeforeUnloadMessage());
		    return;
		  }

		  changeCurrentPage();
		};
		
		initializeCurrentPage();
	};
	
	function changeCurrentPage() {
    var oldPageInfo = currentPageInfo;
    initializeCurrentPage();
    fire(EVENT.pageChanged, currentPageInfo, oldPageInfo);
	}

	function fire(type, newPageInfo, oldPageInfo) {
		var event = {
		  type: type,
		  newPageInfo: newPageInfo,
		  oldPageInfo: oldPageInfo
		};

		self.fire(event);
	}
	
	function initializeCurrentPage() {
    currentPageInfo = buidCurrentPageInfo();
	}

	self.getCurrentPageInfo = function getCurrentPageInfo() {
	  return currentPageInfo;
	};

	self.goTo = function goTo(pageInfo) {
		location.hash = buildHash(pageInfo);
	};

	self.forward = function forward() {
		window.history.forward();
	};

	self.back = function back() {
		window.history.back();
	};

	self.reload = function reload() {
		fire(EVENT.reload, currentPageInfo);
	}
	
	self.getHistoryState = function getHistoryState() {
    return window.history.state;
	};
	
	self.saveHistoryState = function saveHistoryState(state) {
    window.history.replaceState(state, "");
	};
	
	self.addToHistoryState = function addToHistoryState(params) {
    var state = self.getHistoryState();
	  if(!state)
	    state = {};
    
    for(var key in params)
      state[key] = params[key];
    
    self.saveHistoryState(state);
	};

	function buildHash(pageInfo) {
    if(!config.elaiJS.buildHash)
      throw new Error("Missing configuration for 'elaiJS.buildHash'.");

    return config.elaiJS.buildHash(pageInfo);
	}

	function buidCurrentPageInfo() {
    if(!config.elaiJS.extractPageInfo)
      throw new Error("Missing configuration for 'elaiJS.extractPageInfo'.");

    var hash = location.hash.substring(1);
{'fraction_non_alphanumeric': 0.1149600304529882, 'fraction_numerical': 0.00038066235249333843, 'mean_word_length': 3.5935314685314683, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5965776', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1584, 'n_words': 296}