<commit_before>﻿/* Yet Another Forum.NET
 * Copyright (C) 2006-2009 <NAME>
 * http://www.yetanotherforum.net/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using YAF.Classes.Utils;

namespace YAF.Classes.Core
{
	public class PageElementRegister
	{
		private readonly List<string> _registeredElements = new List<string>();
		/// <summary>
		/// Elements (using in the head or header) that are registered on the page.
		/// Used mostly by RegisterPageElementHelper.
		/// </summary>
		public List<string> RegisteredElements
		{
			get
			{
				return _registeredElements;
			}
		}

		public bool PageElementExists(string name)
		{
			return _registeredElements.Contains(name.ToLower());
		}

		public void AddPageElement( string name )
		{
			_registeredElements.Add( name.ToLower() );
		}

		/// <summary>
		/// Adds the given CSS to the page header within a <![CDATA[<style>]]> tag
		/// </summary>
		/// <param name="element">Control to add element</param>
		/// <param name="name">Name of this element so it is not added more then once (not case sensitive)</param>
		/// <param name="cssContents">The contents of the text/css style block</param>
		public void RegisterCssBlock(Control element, string name, string cssContents)
		{
			if (!PageElementExists( name ))
			{
				// Add to the end of the controls collection
				element.Controls.Add(ControlHelper.MakeCssControl(cssContents));
				AddPageElement( name );
			}
		}

		public void RegisterCssBlock(string name, string cssContents)
		{
			RegisterCssBlock(YafContext.Current.CurrentForumPage.TopPageControl, name, cssContents);
		}

		/// <summary>
		/// Add the given CSS to the page header within a style tag
		/// </summary>
		/// <param name="cssUrl">Url of the CSS file to add</param>
		public void RegisterCssInclude(string cssUrl)
		{
			RegisterCssInclude(YafContext.Current.CurrentForumPage.TopPageControl, cssUrl);
		}

		/// <summary>
		/// Adds the given CSS to the page header within a <![CDATA[<style>]]> tag
		/// </summary>
		/// <param name="element">Control to add element</param>
		/// <param name="cssUrl">Url of the CSS file to add</param>
		public void RegisterCssInclude(Control element, string cssUrl)
		{
			if (!PageElementExists(cssUrl))
			{
				element.Controls.Add( ControlHelper.MakeCssIncludeControl( cssUrl.ToLower() ) );
				AddPageElement(cssUrl);
			}
		}<commit_msg>Added javascript pass-through functions.<commit_after>﻿/* Yet Another Forum.NET
 * Copyright (C) 2006-2009 <NAME>
 * http://www.yetanotherforum.net/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using YAF.Classes.Utils;

namespace YAF.Classes.Core
{
	public class PageElementRegister
	{
		private readonly List<string> _registeredElements = new List<string>();
		/// <summary>
		/// Elements (using in the head or header) that are registered on the page.
		/// Used mostly by RegisterPageElementHelper.
		/// </summary>
		public List<string> RegisteredElements
		{
			get
			{
				return _registeredElements;
			}
		}

		public bool PageElementExists(string name)
		{
			return _registeredElements.Contains(name.ToLower());
		}

		public void AddPageElement( string name )
		{
			_registeredElements.Add( name.ToLower() );
		}

		/// <summary>
		/// Adds the given CSS to the page header within a <![CDATA[<style>]]> tag
		/// </summary>
		/// <param name="element">Control to add element</param>
		/// <param name="name">Name of this element so it is not added more then once (not case sensitive)</param>
		/// <param name="cssContents">The contents of the text/css style block</param>
		public void RegisterCssBlock(Control element, string name, string cssContents)
		{
			if (!PageElementExists( name ))
			{
				// Add to the end of the controls collection
				element.Controls.Add(ControlHelper.MakeCssControl(cssContents));
				AddPageElement( name );
			}
		}

		/// <summary>
		/// Registers a Javascript block using the script manager. Adds script tags.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="script"></param>
		public void RegisterJsBlock(string name, string script )
		{
			RegisterJsBlock( YafContext.Current.CurrentForumPage, name, script );
		}

		/// <summary>
		/// Registers a Javascript block using the script manager. Adds script tags.
		/// </summary>
		/// <param name="thisControl"></param>
		/// <param name="name"></param>
		/// <param name="script"></param>
		public void RegisterJsBlock( Control thisControl, string name, string script )
		{
			ScriptManager.RegisterClientScriptBlock( thisControl, thisControl.GetType(), name, script,
																							 true );
		}

		/// <summary>
		/// Registers a Javascript include using the script manager.
		/// </summary>
		/// <param name="thisControl"></param>
		/// <param name="name"></param>
		/// <param name="url"></param>
		public void RegisterJsInclude( Control thisControl, string name, string url )
		{
			ScriptManager.RegisterClientScriptInclude( thisControl, thisControl.GetType(), name, url );
		}

		/// <summary>
		/// Registers a Javascript include using the script manager.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="url"></param>
		public void RegisterJsInclude( string name, string url )
		{
			RegisterJsInclude( YafContext.Current.CurrentForumPage, name, url );
		}

		/// <summary>
		/// Registers a Javascript resource include using the script manager.
		/// </summary>
		/// <param name="thisControl"></param>
		/// <param name="name"></param>
		/// <param name="relativeResourceUrl"></param>
		public void RegisterJsResourceInclude( Control thisControl, string name, string relativeResourceUrl )
		{
			ScriptManager.RegisterClientScriptInclude( thisControl, thisControl.GetType(), name,
			                                           YafForumInfo.GetURLToResource( relativeResourceUrl ) );
		}

		/// <summary>
		/// Registers a Javascript resource include using the script manager.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="relativeResourceUrl"></param>
		public void RegisterJsResourceInclude( string name, string relativeResourceUrl )
		{
			RegisterJsResourceInclude( YafContext.Current.CurrentForumPage, name, relativeResourceUrl );			
		}

		public void RegisterCssBlock(string name, string cssContents)
		{
			RegisterCssBlock(YafContext.Current.CurrentForumPage.TopPageControl, name, cssContents);
		}

		/// <summary>
		/// Add the given CSS to the page header within a style tag
		/// </summary>
		/// <param name="cssUrl">Url of the CSS file to add</param>
		public void RegisterCssInclude(string cssUrl)
		{
			RegisterCssInclude(YafContext.Current.CurrentForumPage.TopPageControl, cssUrl);
		}

		/// <summary>
		/// Add the given CSS to the page header within a style tag
		/// </summary>
		/// <param name="cssUrlResource">Url of the CSS Resource file to add</param>
		public void RegisterCssIncludeResource( string cssUrlResource )
		{
			RegisterCssInclude( YafContext.Current.CurrentForumPage.TopPageControl,
			                    YafForumInfo.GetURLToResource( cssUrlResource ) );
		}

		/// <summary>
		/// Adds the given CSS to the page header within a <![CDATA[<style>]]> tag
		/// </summary>
		/// <param name="element">Control to add element</param>
		/// <param name="cssUrl">Url of the CSS file to add</param>
		public void RegisterCssInclude(Control element, string cssUrl)
		{
			if (!PageElementExists(cssUrl))
			{
				element.Controls.Add( ControlHelper.MakeCssIncludeControl( cssUrl.ToLower() ) );
				AddPageElement(cssUrl);
			}
		}
{'fraction_non_alphanumeric': 0.11711810505537888, 'fraction_numerical': 0.005044412764557517, 'mean_word_length': 3.4574780058651027, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7392292', 'n_tokens_mistral': 2875, 'n_tokens_neox': 2526, 'n_words': 857}