Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
beforeunload
component {
this.Name = 'beforeunload'
this.dataSource = 'beforeunload'
this.SessionManagement = true
this.ScriptProtect = 'all'
this.currentTemplatePath = GetCurrentTemplatePath()
this.directoryFromPath = GetDirectoryFromPath(this.currentTemplatePath)
this.mappings['Inc'] = this.directoryFromPath & 'Inc'
// this.mappings['com'] = this.directoryFromPath & 'com'
function onSessionStart() {
session.msg = ''
session.mod = 'label-info' // or 'none'
session.dataSource = this.dataSource
session.RemoteAddr = getPageContext().getRequest().getRemoteAddr()
}
function onRequestStart(LogCFCName) {
setting showDebugOutput=false;
if (isDefined('url.onSessionStart')) {
onSessionStart()
}
request.msg = session.msg
request.mod = session.mod
request.dataSource = session.dataSource
request.RemoteAddr = session.RemoteAddr
request.title='beforeunload'
request.home = '/beforeunload'
request.css = url.css ?: true
request.js = url.js ?: true
request.bootstrap = url.bootstrap ?: true
request.tryCatch = url.tryCatch ?: false
request.navbar = url.navbar ?: true
request.container = url.container ?: true
request.GoogleMaterialdesign = url.GoogleMaterialdesign ?: true
request.jQueryUI = url.jQueryUI ?: false
request.jQueryUI_theme = 'ui-lightness' // black-tie,blitzer,cupertino,dark-hive,dot-luv,eggplant,excite-bike,flick,hot-sneaks,humanity,le-frog,mint-choc,overcast,pepper-grinder,redmond,smoothness,south-street,start,sunny,swanky-purse,trontastic,ui-darkness,ui-lightness,vader
request.cgiName = getPageContext().getRequest().getServletPath()
request.cgiName = Left(request.cgiName,Len(request.cgiName)-4)
request.cgiName = ListLast(request.cgiName,'/')
request.cssName = request.cgiName & '.css'
request.jsName = request.cgiName & '.js'
request.Save = '<button name="Save" type="submit">Save</button>'
if (isDefined('url.logout')) {
StructDelete(session,'Usr')
}
if (isDefined('url.ID')) {
local.UsrID = session.Usr.UsrID ?: 0
StructDelete(session,'Usr')
if (Len(url.ID) != 36) {
request.msg = 'ID must be a length of 36'
} else if (Mid(url.ID,09,1) != '-') {
request.msg = 'Position 9 has to be a dash character.'
} else if (Mid(url.ID,14,1) != '-') {
request.msg = 'Position 14 has to be a dash character.'
} else if (Mid(url.ID,19,1) != '-') {
request.msg = 'Position 19 has to be a dash character.'
} else if (Mid(url.ID,24,1) != '-') {
request.msg = 'Position 24 has to be a dash character.'
} else if (Find('--',url.ID)) {
request.msg = 'Two dashes? Really?'
} else {
for (var i=1; i <= Min(36,Len(url.ID)); i++) {
if (!Find(Mid(url.ID,i,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-')) {
request.msg = Mid(url.ID,i,1) & ' says what?'
}
}
}
if (request.msg == '') {
storedproc procedure='Usr.WhereGloballyUniqueIdentifier' {
procparam cfSqlType='cf_sql_integer' value=local.UsrID;
procparam cfSqlType='cf_sql_varchar' value=request.RemoteAddr;
procparam cfSqlType='cf_sql_varchar' value=url.ID;
procresult resultset=1 name='Usr';
}
if (Usr.recordCount) {
session.Usr = Duplicate(Usr)
} else {
request.msg = url.ID & ' not found.'
}
}
}
if (!isDefined('session.Usr')) {
if (request.msg == '') {
request.msg = 'You have been logged out.'
request.mod = 'label-danger'
}
include '/Inc/Login.cfm'
return false
}
}
function onRequestEnd(LogCFCName) {
session.msg = ''
session.mod = 'label-info'
}
}
</head>
<body>
<cfif request.navbar>
<cfoutput>
<nav class="navbar navbar-fixed-top">
<div class="navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="##navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand glyphicon glyphicon-home" href="#request.home#/"
data-toggle="tooltip" data-placement="left" title="Home"></a>
</div>
</div>
</div>
<cfif request.mod NEQ "none">
<div class="navbar-default">
<cfset request.msg = "my message">
<div class="msg container<cfif request.msg NEQ ''> #request.mod#</cfif>">
<span id="msg">#request.msg#</span>
</div>
</div>
</cfif>
</nav>
</cfoutput>
</cfif>
<main role="main" class="<cfif request.container>container<cfelse>container-fluid</cfif>">
<cfscript>
if (request.js) {
if (FileExists(request.home & '/' & request.jsName)) {
echo('<script src="' & GetFileFromPath(request.jsName) & '"></script>')
}
echo('
<script src="' & request.home & '/Inc/End.js"></script>')
}
</cfscript>
</body>
</html>
$('[data-toggle=tooltip]').tooltip()
if ($.material) {
$.material.init()
}
$('main').fadeTo(400,1)
</main>
<cfoutput>
<cfif request.js>
<script src="//cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script src="#request.home#/Inc/foot.js"></script>
<cfif request.bootstrap>
<script src="//cdn.jsdelivr.net/bootstrap/latest/js/bootstrap.min.js"></script>
<cfif request.GoogleMaterialdesign>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.2.2/js/ripples.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.2.2/js/material.js"></script>
</cfif>
</cfif>
<cfif request.jQueryUI>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
</cfif>
</cfif>
</cfoutput>
window.log = function(arg) {
if (this.console) {
// console.log(Array.prototype.slice.call(arguments)) //paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog
console.log(arg)
}
}
;(function() {
var local = {}
$(document).on('mouseenter', 'button[name="Delete"]', function() {
$(this).addClass('btn-danger')
})
$(document).on('mouseleave', 'button[name="Delete"]', function() {
$(this).removeClass('btn-danger')
})
$('table').not('.no-table').addClass('table')
$('table').not('.no-table,.no-hover').addClass('table-hover')
$('table').not('.no-table,.no-striped').addClass('table-striped')
$('table').not('.no-table,.no-bordered').addClass('table-bordered')
$('table').not('.no-table,.no-condensed').addClass('table-condensed')
$('table').not('.no-sortable').addClass('sortable')
$('textarea,input:text,input:password,input[type=email],select').addClass('form-control')
$('form').attr('role','form')
$('form>div').addClass('form-group')
$('button,.btn-lg,.btn-block,.btn-default,.btn-primary,.btn-success,.btn-info,.btn-warning,.btn-danger,.btn-link').addClass('btn')
$('.btn').addClass('btn-lg')
$('.no-lg').addClass('btn').removeClass('btn-lg')
$('#Save,button[name=Save]').addClass('btn-primary')
$('.btn').not('.btn-success,.btn-primary,.btn-info,.btn-warning,.btn-danger').addClass('btn-default')
$('section').addClass('row')
// $('table').not('.no-table').addClass('table').wrap('<div class="table-responsive"></div>')
// $('img').not('[hidden]').addClass('img-responsive') // img-rounded
if (!$('form').attr('method')) {
$('form').attr('method','post')
}
local.global = false
local.type = 'POST'
$.ajaxSetup(local)
})()
window.dom = {}
dom.msg = $('#msg')
dom.fail = function(xhr, status, response) {
if (response) {
dom.msg.text(status + ': ' + response).addClass('label-warning')
}
if (xhr.responseText) {
dom.main.html(xhr.responseText)
}
debugger
}
<cfoutput>
<!doctype html>
<html lang="en" class="no-js">
<head>
<title>#request.title#</title>
<cfif request.css>
<meta charset="utf-8">
<meta content="Phillip Senn" name="author">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<cfif request.bootstrap>
<link rel="stylesheet" type="text/css" href="/cdn/Bootstrap/css/Bootstrap.css">
<cfif request.GoogleMaterialdesign>
<cfset Ripple.css = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.2.2/css/ripples.css">
<link rel="stylesheet" type="text/css" href="#Ripple.css#">
<cfset wfont.css = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.2.2/css/material-wfont.css">
<link rel="stylesheet" type="text/css" href="#wfont.css#"> <!--- Dreamweaver was reading from cloudflare --->
<cfelse>
<link rel="stylesheet" type="text/css" href="/cdn/Bootstrap/#request.Bootstrap_theme#.css">
</cfif>
</cfif>
<link rel="stylesheet" href="#request.home#/Inc/html.css">
<cfif FileExists(request.cssName)>
<link rel="stylesheet" href="#request.cssName#">
</cfif>
<cfif request.jQueryUI>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1/themes/#request.jQueryUI_theme#/jquery-ui.css">
</cfif>
</cfif>
<cfif request.js>
<script src="//cdn.jsdelivr.net/modernizr/latest/modernizr.js"></script>
</cfif>
</cfoutput>
@import url('//cdn.PhillipSenn.com/html.css');
body {
padding-top:100px;
background-color:white;
}
main {
opacity:0;
}
.navbar .btn {
margin-top:0px;
margin-bottom:0px;
}
main.container {
padding-left:0px;
}
.container {
padding-right:0px;
}
<cfscript>
</cfscript>
<cfoutput>
<cfinclude template="/Inc/html.cfm">
<cfinclude template="/Inc/body.cfm">
<cfinclude template="/Inc/foot.cfm">
<div #request.hidden#>
<p id="UsrID">1</p>
</div>
<cfinclude template="/Inc/End.cfm">
</cfoutput>
(function() {
$(window).on('beforeunload', beforeunload)
function beforeunload() {
var local = {}
local.url = 'Finished.cfm'
local.data = {}
local.data.UsrID = $('#UsrID').text()
result = $.ajax(local)
result.fail(dom.fail)
};
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment