<commit_before>/*
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2016 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
(function() {

"use strict";

var ui = angular.module('axelor.ui');

function getStylePopup(element, styles) {

	return function ($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list')
	                           .attr('unselectable', 'on');

		$.each(styles, function(format, name) {
	        var $link = $('<a/>').attr('href','#')
	                             .html(name)
	                             .click(function(event) {
	                                $(element).wysiwyg('shell').format(format).closePopup();
	                                event.stopPropagation();
	                                event.preventDefault();
	                                return false;
	                            });
	        $list.append($link);
	    });

		$popup.append($list);
	};
}

function getFontNamePopup(element, fonts) {

	return function ($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list')
	                           .attr('unselectable', 'on');

		$.each(fonts, function(font, name) {
	        var $link = $('<a/>').attr('href','#')
	                             .html(name)
	                             .click(function(event) {
	                                $(element).wysiwyg('shell').fontName(font).closePopup();
	                                event.stopPropagation();
	                                event.preventDefault();
	                                return false;
	                            });
	        $list.append($link);
	    });

		$popup.append($list);
	};
}

function getFontSizePopup(element, sizes) {

	return function ($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list')
	                           .attr('unselectable', 'on');

		$.each(sizes, function(size, name) {
	        var $link = $('<a/>').attr('href','#')
	                             .html(name)
	                             .click(function(event) {
	                            	$(element).focus();
	                            	$(element).wysiwyg('shell').fontSize(size).closePopup();
	                                event.stopPropagation();
	                                event.preventDefault();
	                                return false;
	                            });
	        $list.append($link);
	    });

		$popup.append($list);
	};
}

function getButtons(scope, element) {

	var lite = scope.field.lite;

	return {
		style: lite ? false : {
			title: _t('Style'),
			image: '\uf1dd',
			popup: getStylePopup(element, {
				'<p>' 			: _t('Normal'),
				'<pre>' 		: '<pre>' + _t('Formatted') + '</pre>',
				'<blockquote>'	: '<blockquote>' + _t('Blockquote') + '</blockquote>',
				'<h1>': '<h1>' + _t('Header 1') + '</h1>',
				'<h2>': '<h2>' + _t('Header 2') + '</h2>',
				'<h3>': '<h3>' + _t('Header 3') + '</h3>',
				'<h4>': '<h4>' + _t('Header 4') + '</h4>',
				'<h5>': '<h5>' + _t('Header 5') + '</h5>',
				'<h6>': '<h6>' + _t('Header 6') + '</h6>'
		    })
		},
		fontName: (lite || !$.browser.chrome) ? false : {
			title: _t('Font'),
			image: '\uf031',
			popup: getFontNamePopup(element, {
				'"Times New Roman", Times, serif': '<span style="font-family: \"Times New Roman\", Times, serif">Times New Roman</span>',
				'Arial, Helvetica, sans-serif': '<span style="font-family: Arial, Helvetica, sans-serif">Arial</span>',
				'"Courier New", Courier, monospace': '<span style="font-family: \"Courier New\", Courier, monospace">Courier New</span>',
				'Comic Sans, Comic Sans MS, cursive': '<span style="font-family: Comic Sans, Comic Sans MS, cursive">Comic Sans</span>',
				'Impact, fantasy': '<span style="font-family: Impact, fantasy">Impact</span>',
		    })
		},
		fontSize: (lite || !$.browser.chrome) ? false : {
			title: _t('Font size'),
			image: '\uf035',
			popup: getFontSizePopup(element, {<commit_msg>Allow font name/size change from html widget<commit_after>/*
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2016 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
(function() {

"use strict";

var ui = angular.module('axelor.ui');

function getStylePopup(element, styles) {

	return function($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list').attr('unselectable', 'on');

		$.each(styles, function(format, name) {
			var $link = $('<a/>').attr('href', '#').html(name).click(
					function(event) {
						$(element).wysiwyg('shell').format(format).closePopup();
						event.stopPropagation();
						event.preventDefault();
						return false;
					});
			$list.append($link);
		});

		$popup.append($list);
	};
}

function getFontNamePopup(element, fonts) {

	return function($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list').attr('unselectable', 'on');

		$.each(fonts, function(font, name) {
			var $link = $('<a/>').attr('href', '#').html(name).click(
					function(event) {
						try {
							document.execCommand('styleWithCSS', false, false);
							$(element).wysiwyg('shell').fontName(font).closePopup();
						} finally {
							document.execCommand('styleWithCSS', false, true);
						}
						event.stopPropagation();
						event.preventDefault();
						return false;
					});
			$list.append($link);
		});

		$popup.append($list);
	};
}

function getFontSizePopup(element, sizes) {

	return function($popup, $button) {

		var $list = $('<div/>').addClass('wysiwyg-plugin-list').attr('unselectable', 'on');

		$.each(sizes, function(size, name) {
			var $link = $('<a/>').attr('href', '#').html(name).click(
					function(event) {
						$(element).focus();
						try {
							document.execCommand('styleWithCSS', false, false);
							$(element).wysiwyg('shell').fontSize(size).closePopup();
						} finally {
							document.execCommand('styleWithCSS', false, true);
						}
						event.stopPropagation();
						event.preventDefault();
						return false;
					});
			$list.append($link);
		});

		$popup.append($list);
	};
}

function getButtons(scope, element) {

	var lite = scope.field.lite;

	return {
		style: lite ? false : {
			title: _t('Style'),
			image: '\uf1dd',
			popup: getStylePopup(element, {
				'<p>' 			: _t('Normal'),
				'<pre>' 		: '<pre>' + _t('Formatted') + '</pre>',
				'<blockquote>'	: '<blockquote>' + _t('Blockquote') + '</blockquote>',
				'<h1>': '<h1>' + _t('Header 1') + '</h1>',
				'<h2>': '<h2>' + _t('Header 2') + '</h2>',
				'<h3>': '<h3>' + _t('Header 3') + '</h3>',
				'<h4>': '<h4>' + _t('Header 4') + '</h4>',
				'<h5>': '<h5>' + _t('Header 5') + '</h5>',
				'<h6>': '<h6>' + _t('Header 6') + '</h6>'
		    })
		},
		fontName: lite ? false : {
			title: _t('Font'),
			image: '\uf031',
			popup: getFontNamePopup(element, {
				'"Times New Roman", Times, serif': '<span style="font-family: \"Times New Roman\", Times, serif">Times New Roman</span>',
				'Arial, Helvetica, sans-serif': '<span style="font-family: Arial, Helvetica, sans-serif">Arial</span>',
				'"Courier New", Courier, monospace': '<span style="font-family: \"Courier New\", Courier, monospace">Courier New</span>',
				'Comic Sans, Comic Sans MS, cursive': '<span style="font-family: Comic Sans, Comic Sans MS, cursive">Comic Sans</span>',
				'Impact, fantasy': '<span style="font-family: Impact, fantasy">Impact</span>',
		    })
		},
		fontSize: lite ? false : {
			title: _t('Font size'),
			image: '\uf035',
			popup: getFontSizePopup(element, {
{'fraction_non_alphanumeric': 0.18809030177378483, 'fraction_numerical': 0.009214466712739, 'mean_word_length': 2.562987279441937, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5320671', 'n_tokens_mistral': 3148, 'n_tokens_neox': 2724, 'n_words': 652}