<% ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' HTML Editor v1.1 ' Infolink ' Carlos A. Madrigal ' ' This is a What You See Is What You Get HTML Editor that runs in a normal web page. It uses ' the capabilities of Microsoft Internet Explorer for PC to edit HTML. ' ' With this tool, users can edit content in an easy way: ' ' June 11, 2002 ' I added the following features: ' · Native support for browsers that not support HTML editing. ' · HTML source code view. ' · Image support. ' · Color support. ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const TA_ROWS = 35 ' Rows used when rendering text area controls Const TA_COLS = 80 ' Cols used when rendering text area controls Dim g_bIsBrowserCapable ' Tells if browser is capable of displaying the HTML Editor ' Initialize HTML Editor HTMLInit ' Checks browser version and determines if the browser is able to display the HTML Editor. Sub HTMLInit() Dim sUserAgent, i, j ' Initialize variables g_bIsBrowserCapable = False ' Read browser identification string sUserAgent = Request.ServerVariables("HTTP_USER_AGENT") ' Check if we are talking about Internet Explorer 4.0+ i = InStr(1, sUserAgent, "MSIE") If i > 0 Then ' Browser is IE, check version j = InStr(i, sUserAgent, ";") sUserAgent = Mid(sUserAgent, i+4, j-i-4) g_bIsBrowserCapable = CDbl(sUserAgent) >= 4.0 End If sUserAgent = Request.ServerVariables("HTTP_USER_AGENT") mac = InStr(1, sUserAgent, "Mac_PowerPC") If mac > 0 Then g_bIsBrowserCapable = False End If End Sub ' Renders a HTML Editor control. Both, HtmlEdit and HtmlEdit2 do the same. ' ' sName This is the name of a hidden variable where data is copied to and from. ' sJSObjectName This is the name of the control while in Javascript. ' iHeight Control height. ' sImageFolder Folder where images are located. Use vbNullstring if no images are used for this control. ' sImageList A comma-delimited list of file names that are going to be displayed in the control. Use ' GenerateImageList to dynamically generate lists from files stored in a web site folder. ' ' For sakes of simplicity and backwards compatibility, I made two functions for the same purpose. HtmlEdit is the older ' one. This should work with older implementations of HtmlEdit. Use this one if you don't require image support. HtmlEdit2 ' is the newest and fully implemented function, use this one when you require image support. Sub HtmlEdit(sName, sJSObjName, iHeight) HtmlEdit2 sName, sJSObjName, iHeight, vbNullString, vbNullString End Sub Sub HTMLEdit2(sName, sJSObjName, iHeight, sImageFolder, sImageList) If g_bIsBrowserCapable Then%>
<% Else %>
<% End If End Sub ' Generates a comma-delimitted list of the images that are inside the folder. ' sImageFolder Web site folder to look for images. ' sValidImageExtensions A comma-delimitted list of valid image extensions. This function ' looks in the provided web site folder and returns only files if they ' have one of this valid extensions. This parameter can be vbNullString. Function GenerateImageList(ByVal sImageFolder, ByVal sValidImageExtensions) Dim objFSO, objImagesFolder, objFile Dim dicImages, sExtension, iExtStarts ' If second parameter comes empty, I set it to some defaults If Len(sValidImageExtensions) = 0 Then sValidImageExtensions = "gif,jpg,jpeg,jpe,png" ' Get access to web server's file system Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objImagesFolder = objFSO.GetFolder(Server.MapPath(sImageFolder)) ' Create a dictionary to store the images that are going to be on the list Set dicImages = Server.CreateObject("Scripting.Dictionary") ' Search images in web site folder For Each objFile In objImagesFolder.Files ' Extract extension from filename iExtStarts = InStrRev(objFile.Name, ".") If iExtStarts > 0 Then sExtension = Mid(objFile.Name, iExtStarts+1) Else sExtension = "" If InStr(1, sValidImageExtensions, sExtension, vbTextCompare) Then ' Using 1 for vbTextCompare dicImages.Add objFile.Name, objFile.Name End If Next ' Return image name list GenerateImageList = Join(dicImages.Keys, ",") End Function ' Transforms the HTML string into a valid Javascript string. ' sContent Content to be transformed Function HtmlToJSString(sContent) HtmlToJSString = Replace(sContent, vbCr, "") HtmlToJSString = Replace(HtmlToJSString, vbLf, "") HtmlToJSString = Replace(HtmlToJSString, """", "\""") HtmlToJSString = Replace(HtmlToJSString, "'", "\'") End Function %>