/// <summary> /// Handles OnBeforeDataLoad event of the UI form. /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event argument</param> protected void EditForm_OnBeforeDataLoad(object sender, EventArgs e) { if (!EditForm.IsInsertMode) { // Ensure that dynamic language exists string lang = ValidationHelper.GetString(EditForm.GetDataValue("StylesheetDynamicLanguage"), String.Empty); CssPreprocessor prep = CssStylesheetInfoProvider.GetCssPreprocessor(lang); EditForm.Data["StylesheetDynamicLanguage"] = (prep != null) ? lang : CssStylesheetInfo.PLAIN_CSS; } // Set the flag in order to bypass additional logic in the case when no CSS preprocessor is registered if (CssStylesheetInfoProvider.CssPreprocessors.Count > 0) { plainCssOnly = false; } }
/// <summary> /// This method encapsulates both client- and server- side CSS processing. /// </summary> /// <param name="input">Stylesheet code in dynamic language syntax</param> /// <param name="language">CSS dynamic language</param> /// <param name="output">Plain CSS output</param> /// <param name="hiddenField">Hidden field that holds the result of client-side compilation</param> public static string ProcessCss(string input, string language, out string output, HiddenField hiddenField) { string errorMessage = String.Empty; CssPreprocessor prep = CssStylesheetInfoProvider.GetCssPreprocessor(language); EnsureClientSideCompiledCss(hiddenField); if (String.IsNullOrEmpty(CssPreprocessor.CurrentCompiledValue) || ((prep != null) && !prep.UsesClientSideCompilation)) { // Parse the style sheet code server-side errorMessage = CssStylesheetInfoProvider.TryParseCss(input, language, out output); if (String.IsNullOrEmpty(errorMessage)) { // Store last result CssPreprocessor.CurrentCompiledValue = output; } } else { // Use client-side parsed code output = CssPreprocessor.CurrentCompiledValue; // Check if client-side process result contains special sequence indicating that parser produced no output (this may not be an error) if (output.EqualsCSafe(BLANKOUTPUT)) { output = String.Empty; } else { if ((prep != null) && (prep.GetErrorDescription != null)) { // Handle error errorMessage = prep.GetErrorDescription(output); if (!String.IsNullOrEmpty(errorMessage)) { output = String.Empty; } } } } return(errorMessage); }
/// <summary> /// Adds JavaScript code required for client-side compilation to the page. /// </summary> private void RegisterClientSideCompilationScript() { CssPreprocessor prep = CssStylesheetInfoProvider.GetCssPreprocessor(LanguageFieldValue); if (prep != null) { // Register client scripts if (prep.RegisterClientCompilationScripts != null) { prep.RegisterClientCompilationScripts(); } } else { ScriptHelper.RegisterStartupScript(Control.Page, typeof(string), "CleanUpScript", "function GetCss() {}", true); } if (Editor != null) { ScriptHelper.RegisterStartupScript(Control.Page, typeof(string), "CompileScript", GetClientCompilationScript(Editor.ClientID, hidCompiledCss.ClientID), true); } }
/// <summary> /// Adds JavaScript code required for client-side compilation to the page. /// </summary> private void RegisterClientSideCompilationScript() { // Get dynamic language database value string originalLang = ValidationHelper.GetString(EditForm.GetDataValue("StylesheetDynamicLanguage"), CssStylesheetInfo.PLAIN_CSS); // Get dynamic language selected in the form string newLang = ValidationHelper.GetString(EditForm.GetFieldValue("StylesheetDynamicLanguage"), CssStylesheetInfo.PLAIN_CSS); CssPreprocessor prep = null; // Indicate post-back and that dynamic language has changed if (RequestHelper.IsPostBack() && !originalLang.EqualsCSafe(newLang, true)) { /* * If the original language is plain CSS then load preprocessor according to new language. If the original language is dynamic then load * appropriate preprocessor and ignore selected new language. */ prep = CssStylesheetInfoProvider.GetCssPreprocessor(originalLang) ?? CssStylesheetInfoProvider.GetCssPreprocessor(newLang); } else { prep = CssStylesheetInfoProvider.GetCssPreprocessor(newLang); } // Register client scripts for appropriate preprocessor if (prep != null) { if (prep.RegisterClientCompilationScripts != null) { prep.RegisterClientCompilationScripts(Page); } } if (Editor != null) { ScriptHelper.RegisterStartupScript(this, typeof(string), "CompileScript", CSSStylesheetNewControlExtender.GetClientCompilationScript(Editor.ClientID, hidCompiledCss.ClientID), true); } }