一个显示图例的coldfusion程序

这个程序只是让使用者更简单地显示图例。希望对大家有帮助。在IE,Firefox和Chrome测试过。当然,可能要大家自己测试一下才行。

调用如下:

<cf_这个程序 color1="red" text1="你好" color2=“blue” text2=“大家好”>

显示结果如下:

你好大家好

 

代码如下:

<cfsilent>
<cfparam name="attributes.height" default="10">
<cfparam name="attributes.width" default="10">
<cfparam name="attributes.topmargin" default="3">
<cfparam name="attributes.float" default=""> <!--- empty, left or right --->
<cfparam name="attributes.PaddingBetweenLegend" default="4">
<cfparam name="attributes.PaddingBetweenColorAndText" default="2">
<cfset legendSequence = "">
<cfloop collection="#attributes#" item="attribute">
	<cfset numberSequence = "">
	<cfif isvalid("regex", lcase(attribute), "color(\d+)$")>
		<cfset numberSequence = replacenocase(attribute,"color", "")>
	</cfif>
	<cfif isvalid("regex", lcase(attribute), "text(\d+)$")>
		<cfset numberSequence = replacenocase(attribute,"text", "")>
	</cfif>
	<cfif listfind(legendSequence, numberSequence) eq 0>
		<cfset legendSequence = listappend(legendSequence, numberSequence)>
	</cfif>
</cfloop>
<cfset legendSequence = listsort(legendSequence, "numeric")>
<cfif legendSequence eq ""><cfexit></cfif>
<cfset displayString = "">
<cfloop list="#legendSequence#" index="keyLegend">
	<cfif isdefined("attributes.color#keyLegend#")>
		<cfset colorName = attributes["color" & keyLegend]>
	<cfelse>
		<cfset colorName = "##ffffff">
	</cfif>
	<cfif isdefined("attributes.text#keyLegend#")>
		<cfset textName = attributes["text" & keyLegend]>
	<cfelse>
		<cfset textName = "N/A">
	</cfif>	
	<cfoutput><cfsavecontent variable="displaySubstring"><span style="width:#attributes.width#px; height:#attributes.height#px; font-size:5px; padding:0px;margin:0px; display:inline-block; background-color:#colorName#; border:1px solid black;"></span><span style="margin-left:#attributes.PaddingBetweenColorAndText#px;margin-right:#attributes.PaddingBetweenLegend#px;"> #textName#</span></cfsavecontent></cfoutput>
	<cfset displayString = displayString & displaySubstring>
</cfloop>
<cfset cssFloat = attributes.float>
<cfif cssFloat neq "">
	<cfset cssFloat = "float:" & cssFloat & ";">
</cfif>
<cfset cssMarginTop = attributes.topmargin>
<cfif cssMarginTop neq "">
	<cfset cssMarginTop = "margin-top:" & cssMarginTop & ";">
</cfif>
</cfsilent>
<cfoutput><div style="#cssMarginTop# #cssFloat#">#displayString#</div></cfoutput>

阅读更多
个人分类: Coldfusion
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭