Skip to content

Instantly share code, notes, and snippets.

@d1rtym0nk3y
Created June 29, 2013 19:06
Show Gist options
  • Save d1rtym0nk3y/5892276 to your computer and use it in GitHub Desktop.
Save d1rtym0nk3y/5892276 to your computer and use it in GitHub Desktop.
<cfsetting requesttimeout="999999" enablecfoutputonly="true" />
<cfscript>
progress("Importing data", 0);
recordcount = 100;
for(i=1; i<=recordcount; i++) {
// do something
sleep(250);
progress("Importing data", i, recordcount)
}
progress("Importing data", 1)
</cfscript>
<cffunction name="progress">
<cfargument name="type" />
<cfargument name="x" default="0" />
<cfargument name="total" type="numeric" default="1" />
<cfset var key = hash(type) />
<cfset var p = "" />
<cftry>
<cfif not isNumeric(x)>
<cfset p = x />
<cfelseif x is total>
<cfset p = "done" />
<cfelse>
<cfset p = fix((x/total)*100) & "%" />
</cfif>
<cfcatch>
<cfset p = "" />
</cfcatch>
</cftry>
<cfif not structKeyExists(request, "progress_types")>
<cfset request.progress_types = {} />
<cfoutput>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
</cfoutput>
<cfflush />
</cfif>
<cfif !structKeyExists(request.progress_types, key)>
<cfset request.progress_types[key] = 1 />
<cfoutput>
<div>#type# : <span id="type_#key#"></span></div>
<script>window.scrollBy(0,500);</script>
</cfoutput>
</cfif>
<cfoutput>
<script>$("##type_#key#").text("#p#");</script>
</cfoutput>
<cfflush />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment