<commit_before>/**
 * JS-API for starting hopscotch tours
 * 
 * @author	<NAME>
 * @copyright	2013 Thurnax.com
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.thurnax.wcf.tour
 */
WCF.Tour = {
	/**
	 * list of available tours
	 * @var	array<string>
	 */
	availableTours: [],
	
	/**
	 * dependencies to load
	 * @var	array<string>
	 */
	_dependencies: [ WCF_PATH + 'js/3rdParty/tour/hopscotch-0.1.2.min.js', WCF_PATH + 'js/3rdParty/tour/hopscotch-0.1.2.min.css' ],
	
	/**
	 * ID of the currently active tour
	 * @var	integer
	 */
	_activeTourID: null,
	
	/**
	 * Loads a tour.
	 * 
	 * @param	string	tourName
	 */
	loadTour: function(tourName) {
		if (this._activeTourID || !WCF.inArray(tourName, this.availableTours)) { // tour is already taken
			return;
		}
		
		// load tour
		this._setup();
		this._proxy.setOption('data', {
			className: 'wcf\\data\\tour\\TourAction',
			actionName: 'loadTourByName',
			parameters: {
				tourName: tourName
			}
		});
		this._proxy.sendRequest();
	},

	/**
	 * Loads a tour by the id. Do *not* use this method.
	 * 
	 * @param	integer	tourID
	 */
	loadTourByID: function(tourID) {
		this._setup();
		this._proxy.setOption('data', {
			className: 'wcf\\data\\tour\\TourAction',
			actionName: 'loadTour',
			objectIDs: [ tourID ]
		});
		this._proxy.sendRequest();
	},

	/**
	 * Sets up the environment.
	 */
	_setup: function() {
		if (this._dependencies !== null) {
			// init proxy
			this._proxy = new WCF.Action.Proxy({
				success: $.proxy(this._success, this),
				failure: $.proxy(this._failure, this),
				showLoadingOverlay: false
			});

			// load hopscotch
			head.load(this._dependencies, $.proxy(this._initHopscotch, this));
			this._dependencies = null;
		}
	},
	
	/**
	 * Callback after loading hopscotch.
	 */
	_initHopscotch: function() {
		// register helpers
		hopscotch.registerHelper('redirect_forward', function(url) { location.href = url; });
		hopscotch.registerHelper('redirect_back', function(url) { history.back(); });
		
		WCF.System.Dependency.Manager.invoke('hopscotch');
	},
	
	/**
	 * Handles AJAX responses.
	 * 
	 * @param	object		data<commit_msg>Add additional dependency manager target "hopscotch_register_helpers"<commit_after>/**
 * JS-API for starting hopscotch tours
 * 
 * @author	<NAME>
 * @copyright	2013 Thurnax.com
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.thurnax.wcf.tour
 */
WCF.Tour = {
	/**
	 * list of available tours
	 * @var	array<string>
	 */
	availableTours: [],
	
	/**
	 * dependencies to load
	 * @var	array<string>
	 */
	_dependencies: [ WCF_PATH + 'js/3rdParty/tour/hopscotch-0.1.2.min.js', WCF_PATH + 'js/3rdParty/tour/hopscotch-0.1.2.min.css' ],
	
	/**
	 * ID of the currently active tour
	 * @var	integer
	 */
	_activeTourID: null,
	
	/**
	 * Loads a tour.
	 * 
	 * @param	string	tourName
	 */
	loadTour: function(tourName) {
		if (this._activeTourID || !WCF.inArray(tourName, this.availableTours)) { // tour is already taken
			return;
		}
		
		// load tour
		this._setup();
		this._proxy.setOption('data', {
			className: 'wcf\\data\\tour\\TourAction',
			actionName: 'loadTourByName',
			parameters: {
				tourName: tourName
			}
		});
		this._proxy.sendRequest();
	},

	/**
	 * Loads a tour by the id. Do *not* use this method.
	 * 
	 * @param	integer	tourID
	 */
	loadTourByID: function(tourID) {
		this._setup();
		this._proxy.setOption('data', {
			className: 'wcf\\data\\tour\\TourAction',
			actionName: 'loadTour',
			objectIDs: [ tourID ]
		});
		this._proxy.sendRequest();
	},

	/**
	 * Sets up the environment.
	 */
	_setup: function() {
		if (this._dependencies !== null) {
			// init proxy
			this._proxy = new WCF.Action.Proxy({
				success: $.proxy(this._success, this),
				failure: $.proxy(this._failure, this),
				showLoadingOverlay: false
			});

			// load hopscotch
			head.load(this._dependencies, $.proxy(this._initHopscotch, this));
			this._dependencies = null;
		}
	},
	
	/**
	 * Callback after loading hopscotch.
	 */
	_initHopscotch: function() {
		// register helpers
		hopscotch.registerHelper('redirect_forward', function(url) { location.href = url; });
		hopscotch.registerHelper('redirect_back', function(url) { history.back(); });
		
		WCF.System.Dependency.Manager.invoke('hopscotch_register_helpers');
		WCF.System.Dependency.Manager.invoke('hopscotch');
	},
	
	/**
	 * Handles AJAX responses.
	 * 
	 * @param	object		data
{'fraction_non_alphanumeric': 0.15895953757225434, 'fraction_numerical': 0.005335704757670075, 'mean_word_length': 3.1851162790697676, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3668694', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1550, 'n_words': 311}