<commit_before>/**
 * Crée une instance de Webos.Stylesheet, representant une feuille de style CSS.
 * @param {String} path Le chemin vers la feuille de style.
 * @param {String} [container] L'element auquel sera applique le style.
 * @since 1.0 alpha 1
 * @constructor
 */
Webos.Stylesheet = function WStylesheet(path, container) {
	if (!/^(\/|~\/)/.test(path)) {
		path = '/'+path;
	}
	
	if (Webos.Stylesheet._cache[path]) {
		Webos.Stylesheet.insertCss(Webos.Stylesheet._cache[path], container);
		return;
	}
	
	new Webos.ServerCall({
		'class': 'FileController',
		method: 'getContents',
		arguments: {
			file: path
		},
		async: false
	}).load(function(response) {
		var css = response.getStandardChannel();
		if (css) {
			Webos.Stylesheet._cache[path] = css;
			Webos.Stylesheet.insertCss(css, container);
		}
	});
};

/**
 * Cache des feuilles de style.
 * @private
 * @static
 */
Webos.Stylesheet._cache = {};

/**
 * Appliquer une feuille de style CSS.
 * @param {String} css La feuille de style CSS.
 * @param {String} [container] L'element auquel sera applique le style.
 * @static
 */
Webos.Stylesheet.insertCss = function insertCss(css, container) {
	if (container) {
		css = css
			.replace(/\/\*([\s\S]*?)\*\//g, '') //On enleve les commentaires
			.replace(/([\s\S]+?)\{([\s\S]*?)\}/g, function(str, p1, p2) {
				var result = '';
				
				p1 = p1.replace(/\s+/g, ' ');
				
				if (/^\s*@/.test(p1)) {
					if (/^\s*(@.+;)+/.test(p1)) {
						result += /@.+;/g.exec(p1).join('');
					} else {
						return p1+'{'+p2+'}';
					}
				}
				
				var selectors = p1.split(',');
				
				result += container+' '+selectors.join(', '+container+' ')+'{'+p2+'}';
				result = result.replace(/\s+/g, ' ');
				return result;
			});
	}
	
	var cssTag = document.createElement('style');
	cssTag.setAttribute('type', 'text/css');
	var cssText = document.createTextNode(css);
	cssTag.appendChild(cssText);
	$('head').append(cssTag);
};<commit_msg>Added comments<commit_after>/**
 * A CSS stylesheet.
 * @param {String} path The path to the CSS file.
 * @param {String} [container] The element on which CSS rules will be applied.
 * @since 1.0 alpha 1
 * @constructor
 */
Webos.Stylesheet = function WStylesheet(path, container) {
	if (!/^(\/|~\/)/.test(path)) { //Old path notation support - deprecated
		path = '/'+path;
	}
	
	if (Webos.Stylesheet._cache[path]) { //Is the file in cache ?
		Webos.Stylesheet.insertCss(Webos.Stylesheet._cache[path], container);
		return;
	}
	
	new Webos.ServerCall({
		'class': 'FileController',
		method: 'getContents',
		arguments: {
			file: path
		},
		async: false
	}).load(function(response) {
		var css = response.getStandardChannel();
		if (css) { //If there is some CSS
			Webos.Stylesheet._cache[path] = css;
			Webos.Stylesheet.insertCss(css, container); //Insert CSS in the page
		}
	});
};

/**
 * Cache for CSS stylesheets.
 * @private
 * @static
 */
Webos.Stylesheet._cache = {};

/**
 * Apply some CSS rules .
 * @param {String} css CSS rules.
 * @param {String} [container] The element on which CSS rules will be applied. If ommited, CSS rules will be applied to the whole page.
 * @static
 */
Webos.Stylesheet.insertCss = function insertCss(css, container) {
	if (container) {
		css = css
			.replace(/\/\*([\s\S]*?)\*\//g, '') //Delete comments
			.replace(/([\s\S]+?)\{([\s\S]*?)\}/g, function(str, p1, p2) { //Replace each selector
				var result = '';
				
				p1 = p1.replace(/\s+/g, ' ');
				
				if (/^\s*@/.test(p1)) { //Not a selector ?
					if (/^\s*(@.+;)+/.test(p1)) {
						result += /@.+;/g.exec(p1).join('');
					} else {
						return p1+'{'+p2+'}';
					}
				}
				
				var selectors = p1.split(',');
				
				result += container+' '+selectors.join(', '+container+' ')+'{'+p2+'}';
				result = result.replace(/\s+/g, ' ');
				return result;
			});
	}
	
	//Insert CSS rules
	var cssTag = document.createElement('style');
	cssTag.setAttribute('type', 'text/css');
	var cssText = document.createTextNode(css);
	cssTag.appendChild(cssText);
	$('head').append(cssTag);
};

{'fraction_non_alphanumeric': 0.20301681503461919, 'fraction_numerical': 0.006923837784371909, 'mean_word_length': 3.1024340770791077, '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': '1251056', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1467, 'n_words': 338}