コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.BeforeUnloadWarning)
            {
                IncludeBeforeUnloadWarningScript(this.Page, fckEditor);
            }

            //set up CKFinder.
            CKFinder.FileBrowser fileBrowser = new CKFinder.FileBrowser();
            fileBrowser.BasePath = Page.ResolveUrl("~/WebModules/Components/TextEditor/fckeditor_ckfinder-1.4.3/");
            fileBrowser.SetupFCKeditor(fckEditor);

            //REMOVED: no longer necessary as of ckfinder 1.2.3.
            //HACK: fix the ImageBrowserURL. CKFinder.FileBrowser.SetupFCKeditor() is hard-coded to set FCKeditor.ImageBrowserURL to the "Images" resource type.
            //fckEditor.ImageBrowserURL = fckEditor.Config["ImageBrowserURL"].Replace("type=Images", "type=Image");

            //HACK: fix the 'quick upload' URL so that it writes to
            //      /userfiles/files/ instead of /userfiles/.
            //NOTE: do this _after_ CKFinder.FileBrowser.SetupFCKeditor().
            fckEditor.Config["LinkUploadURL"] = fckEditor.Config["LinkUploadURL"] + "&type=Files";

            if (this.IsRequired)
            {
                //FCKeditor does not work with asp:RequiredFieldValidator, so we must do a custom validator.
                //see: http://wiki.fckeditor.net/Troubleshooting#head-9b3ef5962fb1f578c84005f3bff3ff725d3f84c4

                string fxnName = "fckEditor_requiredFieldValidator_callback";
                if (!Page.ClientScript.IsClientScriptBlockRegistered(fxnName))
                {
                    string requiredFieldValidator_script = @"
function " + fxnName + @"(sender, args){
    var validator = document.getElementById(sender.id);
    var fckEditor = FCKeditorAPI.GetInstance(validator.controltovalidate);
    //valid if >0 non-whitespace characters.
    args.IsValid = (fckEditor.GetHTML().replace(/^\s+|\s+$/, '').length > 0);
}
";
                    Page.ClientScript.RegisterClientScriptBlock(typeof(TextEditorControl), fxnName, requiredFieldValidator_script, true);
                }

                fckRequiredFieldValidator.ClientValidationFunction = fxnName;
            }
        }