HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="mdlContr">
<div id="toolBar">
<label class="entityCount">Entity Count: </label>
<input id="iEntityCount" class="iEntityCount"
style=""
value="200"/>
<button onclick="genEntityTest()" id="genBtn">gen</button>
<div id="status"></div>
</div><!-- toolBar -->
<div class="entityViewPort" id="vp" onscroll="adjustView()">
<div id="artBoard"></div>
</div>
<div id="tint" style="display:none;" onclick="hideDialogPanel()">
</div><!-- tint -->
<div id="dia" style="display:none;">
</div><!-- dia -->
</div> <!-- mdlContr -->
<div style="display:none">
This is an image container...
<img src="./images/PKeyIcon.png" id="pkIcon">
</div><!-- image container -->
#mdlContr {
position:relative;top:-8px;left:-8px;width:100%;
background:black;height:50px;overflow:hidden;
}
label {
color:#e6e6e6;
font-family:tahoma;
font-size:9pt;
}
textarea {
font-family:Lucida Console;
font-size:13pt;
width:758px;
height:160px;
}
.entityCount {
position:absolute;left:50px;top:12px;
}
.iEntityCount{
position:absolute;left:125px;top:9px;
}
#toolBar {
position:absolute;
left:0;top:0;background:#4d4d4d;
height:40px;width:1000px;
}
.entityViewPort {
position:absolute;
left:4px;
top:44px;
border:solid silver 1px;
width:1400px;
height:800px;
overflow:scroll;
background:blue;
}
#artBoard {
position:absolute;
left:0;
top:0;
width:100%;
height:40px;
border:none;
background-image: radial-gradient(ellipse farthest-corner at center, #FFFFFF 0%, #BDE4FF 80%);
}
.baseEntity {
background:lightgreen;
border: solid black 1px;
position:absolute;
margin:0;
overflow:hidden;
border-radius:3px;
box-shadow: 5px 5px 14px -3px rgba(0,0,0,0.75);
}
.entityFrame {
}
.entityName {
width:100%;
height:18px;
margin:0;
border-bottom:solid black 1px;
text-align:center;
font-family:tahoma;
font-size:10pt;
box-shadow: 0px 5px 14px -3px rgba(0,0,0,0.75);
cursor:move;
}
.hoverEntity {
position:absolute;
}
.members {
margin:0;
padding-top:2px;
padding-left:15px;
list-style-type:none;
font-family:tahoma;
font-size:9pt;
}
.memberCntr {
position:relative;
top:0;
left:0;
height:11pt;
width:240px;
padding:0;
margin:0;
}
.pkIcon {
padding:0;
margin:0;
width:8px;
height:14px;
position:absolute;
left:-10px;
top:0px;
z-index:2;
}
.altMemberBar {
position:absolute;
z-index:1;
background:black;
opacity:.1;
width:370px;
height:13px;
top:2px;
left:-20px;
padding:0;
margin:0;
}
.memberName {
position:absolute;
top:0;
left:0;
width:150px;
height:11pt;
overflow:hidden;
cursor:default;
z-index:2;
}
.memberDataType {
position:absolute;
top:0;
left:150px;
width:90px;
height:11pt;
overflow:hidden;
cursor:default;
z-index:2;
}
#iEntityCount {
width:50px;
text-align:right;
border:solid gray 1px;
}
#status {color:#e6e6e6;
font-family:tahoma;
font-size:9pt;
position:absolute;
top:12px;left:240px;width:1200px;
}
#genBtn {
position:absolute;
left:180px;
top:9px;
}
#tint {
position:absolute;
top:0;
left:0;
background:black;
opacity:.5;
z-index:100;
}
#dia {
position:absolute;
width:800px;
height:400px;
background:white;
opacity:1;
border:solid black 2px;
z-index:101;
padding:4px;
font-family:tahoma;
}
var dta = {};
dta.entities = [];
dta.entitiesByPrimaryKey = [];
dta.entitiesByEntityName = [];
dta.renderCallId = -1;
dta.snippetFileName = "";
pageSetup();
function pageSetup() {
var sMsgKey;
console.clear();
genEntityTest();
sizeStuff();
document.addEventListener("resize", sizeStuff);
document.addEventListener("mousedown", mouseDownStuff);
sMsgKey = getHashValue("intro");
} // end of function pageSetup()
function getWebPageAdr() {
var sAdr="";
try {
sAdr = document.location.href;
} catch(err) {
} // end of try/catch
return sAdr;
} // end of function getWebPageAdr()
function sizeStuff() {
var mdlContr = $("#mdlContr")[0];
var dia = $("#dia")[0];
var tint = $("#tint")[0];
var nWidth = window.innerWidth;
var nHeight = window.innerHeight;
var entityViewPort = $("#vp")[0];
var toolBar = $("#toolBar")[0];
var bdy = document.getElementsByTagName("body")[0];
mdlContr.style.width = (nWidth)+"px";
mdlContr.style.height = (nHeight)+"px";
toolBar.style.width = (nWidth)+"px";
entityViewPort.style.width = (nWidth - 8)+"px";
entityViewPort.style.height = (nHeight - 44)+"px";
tint.style.width = (nWidth)+"px";
tint.style.height = (nHeight)+"px";
dia.style.left = Math.floor((nWidth - 800) / 2)+"px";
dia.style.top = Math.floor((nHeight - 400) / 2)+"px";
bdy.style.overflow = "hidden";
} // end of function sizeStuff()
function mouseDownStuff(e) {
var el = e.srcElement || e.originalTarget;
//debugger;
var nEntityIdx = getAtrVal(el, "entity-idx", -1) - 0;
var entity;
if (nEntityIdx > -1) {
entity = dta.entities[nEntityIdx];
dta.currentEntity = entity;
showEntityCodeDia(entity);
} // end if
} // end of function mouseDownStuff()
function getAtrVal(el, sAttrName, defVal) {
var val;
try{
val = el.attributes[sAttrName].value;
} catch(err) {
return defVal;
} // end of try/catch
if (typeof val === "undefined") {
val = defVal;
} // end if
return val;
} // end of function
/*
called when viewport is scrolled. (onscroll event in HTML)
*/
function adjustView() {
if (dta.renderCallId !== -1) {
clearTimeout(dta.renderCallId);
dta.renderCallId = -1; // prob not needed... but hey!
} // end if
dta.renderCallId = setTimeout("renderEntities()",200);
} // end of function adjustView()
function genEntityTest() {
var artBoard = document.getElementById("artBoard");
var status = document.getElementById("status");
var genBtn = document.getElementById("genBtn");
var iEntityCount = document.getElementById("iEntityCount");
var nCount = iEntityCount.value - 0;
var s = [];
var nStartIndex = 0;
console.clear();
if (isNaN(nCount)) {
status.innerHTML = "Value is Not a Number... Please Fix";
return;
} // end if
dta.totalEntities = nCount;
status.innerHTML = "One Moment... Generating...";
genBtn.style.display = "none";
s[s.length] = "<h1 style='width:2000px;text-align:center;color:blue'>";
s[s.length] = "<br><br>";
s[s.length] = "Building Test Entities</h1>";
artBoard.innerHTML = s.join("");
// get some stuff up quickly on the screen
// if (nCount > 40) {
// genEntityTest2(0, 40);
// nStartIndex = 40;
// renderEntities();
//} // end if
setTimeout("genEntityTest2("+nStartIndex+","+nCount+")",100);
} // end of function genEntityTest()
/*
*/
function genEntityTest2(nStartIndex, iGenTotal) {
var nTotalEntities = iGenTotal;
// calcDim(nInput)
var nAcross = calcDim(nTotalEntities);
var n;
var entities = [];
var status = document.getElementById("status");
var upDown = document.getElementById("upDown");
var leftRight = document.getElementById("leftRight");
var nTop = 50;
var nStart = 50;
var nLeft = nStart;
const nSpacing = 60;
var xCount = 0;
var entity;
var vp = document.getElementById("vp");
var artBoard = document.getElementById("artBoard");
var genBtn = document.getElementById("genBtn");
var nMaxWidth = vp.offsetWidth;
var nMaxHeight = vp.offsetHeight;
var nMaxEntityHeight=0; // for a "row"
var nOverallMaxEntityHeight=0; // for whole model
var nOverallMaxEntityWidth =0;
var sPrimaryKey,cc;
var startTime = new Date();
var endTime;
var nTotRows = 1; // total "rows" (mainly used for validation)
var s=[];
var nTotRendered = 0; // how many entities where rendered... for validation
const sSpacer = " | ";
console.log("nAcross: "+nAcross);
for (n=nStartIndex;n<nTotalEntities;n++) {
if (n===0) {
entity = genEntity({idx:n,
top:nTop+rndTopOffset(),
left:nLeft,
entityName:"users"
});
entity.addMember({name:"userId",primaryKey:true});
entity.addMember({name:"userName",dataType:"Varchar",size:20});
entity.addMember({name:"firstName",dataType:"Varchar",size:60});
entity.addMember({name:"lastName",dataType:"Varchar",size:60});
entity.addMember({name:"emailAddress",dataType:"Varchar",size:255});
entity.addMember({name:"createUserId"});
entity.addMember({name:"updateUserId"});
entity.addMember({name:"createDate", dataType: "Date"});
entity.addMember({name:"updateDate", dataType: "Date"});
} else {
entity = genEntity({idx:n,
top:nTop+rndTopOffset(),
left:nLeft,
entityName:genCamelCaseTestValue()
});
cc=getRndEntityColor();
entity.colorName = cc.colorName;
entity.color = cc.entityColorCode;
entity.titleColor = cc.titleColorCode;
sPrimaryKey = entity.entityName+ "Id";
entity.addMember({name:sPrimaryKey,primaryKey:true});
entity.addMember({name:"createUserId"});
entity.addMember({name:"updateUserId"});
entity.addMember({name:"createDate", dataType: "Date"});
entity.addMember({name:"updateDate", dataType: "Date"});
addOtherTestMembers(entity);
} // end if/else
entities[n] = entity;
if (entity.height > nMaxEntityHeight) {
nMaxEntityHeight = entity.height;
} // end if
if (entity.width > nOverallMaxEntityWidth) {
nOverallMaxEntityWidth = entity.width;
} // end if
nLeft = nLeft + entity.width + nSpacing;
xCount = xCount + 1;
if (nLeft+entity.width+(nSpacing * 2) > nMaxWidth) {
nMaxWidth = nLeft+entity.width+(nSpacing * 2)+30;
} // end if
if (xCount > nAcross) {
xCount = 0;
nLeft = nStart;
nTop = nTop + nMaxEntityHeight + nSpacing;
if (nTop + nMaxEntityHeight + (nSpacing * 2) > nMaxHeight) {
nMaxHeight = nTop + nMaxEntityHeight + (nSpacing * 2) + 30;
if (nMaxHeight > nOverallMaxEntityHeight) {
nOverallMaxEntityHeight = nMaxHeight;
} // end if (nMaxHeight > nOverallMaxEntityHeight)
} // end if (nTop + nMaxEntityHeight + (nSpacing * 2) > nMaxHeight)
nMaxEntityHeight=0;
nTotRows++;
} // end if (xCount > nAcross)
} // next n
dta.entities = entities;
dta.scrollLeft = 0;
dta.scrollTop = 0;
dta.maxArtboardWidth = nMaxWidth;
dta.maxArtboardHeight = nMaxHeight;
dta.largestEntityHeight = nOverallMaxEntityHeight;
dta.largestEntityWidth = nOverallMaxEntityWidth;
artBoard.style.width = nMaxWidth+"px";
artBoard.style.height = nMaxHeight+"px";
endTime = new Date();
dta.genTestDataMs = (endTime.getMilliseconds() - startTime.getMilliseconds());
console.log("Total Entities Generated: "+entities.length);
nTotRendered = renderEntities();
s[s.length] = "Done generating "+nTotalEntities+" entities";
s[s.length] = sSpacer+"total 'rows': "+nTotRows;
s[s.length] = sSpacer+"Entities Rendered: "+nTotRendered;
s[s.length] = sSpacer+"Build Test Data Time: "+(dta.genTestDataMs)+"ms";
s[s.length] = sSpacer+"Render Time: <span id='renderTime'>"+(dta.renderMs)+"</span>ms";
status.innerHTML = s.join("");
genBtn.style.display = "block";
} // end of function genEntityTest2()
function genEntity(params) {
var entity = {};
var nWidth = 260;
var nHeight = 200;
var sColorName = "Default Color";
var sColor = "lightyellow";
var sTitleColor = "#b3b3b3";
entity.objType = "entity";
entity.entityName = params.entityName;
entity.width = nWidth;
entity.height = nHeight;
entity.idx = params.idx;
entity.left = params.left;
entity.top = params.top;
entity.colorName = sColorName;
entity.color = sColor;
entity.titleColor = sTitleColor;
entity.needToGenRender = true;
entity.partOfDOM = false;
entity.domId = "baseEntity-id-"+entity.idx;
entity.domHoverId = "hoverEntity-id-"+entity.idx;
entity.entitySelected = false;
entity.membersByIndex = [];
entity.membersByMemberName = [];
entity.primaryKeyMembersByIndex = [];
entity.addMember = function(params2) {
var member = {};
var sDataType = popValue({input:params2.dataType,defaultValue:"Long Int"});
var nSize = popValue({input:params2.size,defaultValue:50});
var bPrimaryKey = popValue({input:params2.primaryKey,defaultValue:false});
member.objType = "member";
member.entity = entity;
member.memberName = params2.name;
member.idx = entity.membersByIndex.length;
member.dataType = sDataType;
member.size = nSize;
member.primaryKey = bPrimaryKey;
entity.membersByIndex[entity.membersByIndex.length] = member;
entity.membersByMemberName[member.memberName] = member;
entity.height = calcEntityHeight();
return member;
} // end of addMember method
return entity;
// internal private function
function calcEntityHeight() {
const nMemberHeight = 15;
const nHeaderHeight = 18;
const nVPadding = 7;
var nHeight = nHeaderHeight + ((entity.membersByIndex.length+1)*nMemberHeight)+nVPadding;
return nHeight;
} // end of function calcEntityHeight()
}// end of function
function renderEntities() {
dta.renderCallId = -1;
var nMax = dta.entities.length;
var n;
var vp = document.getElementById("vp");
var artBoard = document.getElementById("artBoard");
var nVpHeight = vp.offsetHeight;
var nVpWidth = vp.offsetWidth;
var entities = dta.entities;
var entity;
var s = [];
var nTopViewportEdge,nLeftViewportEdge;
var nBottomViewportEdge,nRightViewportEdge;
var nTopEntityPos,nBottomEntityPos;
var nLeftEntityPos,nRightEntityPos;
var nEntitiesRendered = 0;
var ves = [];
var ep = [];
var startTime = new Date();
var endTime;
var bHorzInView,bVertInView;
if (nMax===0) {
return;
} // end if
dta.scrollLeft = vp.scrollLeft;
dta.scrollTop = vp.scrollTop;
nTopViewportEdge = dta.scrollTop;
nBottomViewportEdge = dta.scrollTop+nVpHeight;
nLeftViewportEdge = dta.scrollLeft;
nRightViewportEdge = dta.scrollLeft+nVpWidth;
/* ves[ves.length] = "VIEWPORT EDGE SETTINGS:";
ves[ves.length] = " =======================";
ves[ves.length] = " nTopViewportEdge: "+nTopViewportEdge;
ves[ves.length] = " nBottomViewportEdge: "+nBottomViewportEdge;
ves[ves.length] = " nLeftViewportEdge: "+nLeftViewportEdge;
ves[ves.length] = " nRightViewportEdge: "+nRightViewportEdge;
console.log(ves.join("\n")); */
for (n=0;n<nMax;n++) {
entity = entities[n];
nLeftEntityPos = entity.left;
nRightEntityPos = entity.left + entity.width;
nTopEntityPos = entity.top;
nBottomEntityPos = entity.top + entity.height;
bHorzInView = false;
bVertInView = false;
if (nRightEntityPos >= nLeftViewportEdge && nLeftEntityPos <= nRightViewportEdge) {
bHorzInView = true;
} // end if
if (nBottomEntityPos >= nTopViewportEdge && nTopEntityPos <= nBottomViewportEdge) {
bVertInView = true;
} // end if
/* if (n===-1) {
ep = [];
ep[ep.length]="ENTITY POSITION:";
ep[ep.length]=" ================";
ep[ep.length]=" Entity Index#: "+n;
ep[ep.length]=" entity.left: "+entity.left;
ep[ep.length]=" nLeftEntityPos: "+nLeftEntityPos;
ep[ep.length]=" nRightEntityPos: "+nRightEntityPos;
ep[ep.length]=" nTopEntityPos: "+nTopEntityPos;
ep[ep.length]=" nBottomEntityPos: "+nBottomEntityPos;
console.log(ep.join("\n"));
} // end if
*/
// is some of the entity visible in the view port?
if (bHorzInView && bVertInView) {
s[s.length] = renderEntity(entity);
nEntitiesRendered++;
} // end if
} // next n
endTime = new Date();
dta.renderMs = (endTime.getMilliseconds() - startTime.getMilliseconds());
console.log("Entities Rendered: "+nEntitiesRendered);
artBoard.innerHTML = s.join("");
return nEntitiesRendered;
} // end of function renderEntities()
function renderEntity(entity) {
var s = [];
var Q = '"';
var nHoverPadding = 25;
if (entity.needToGenRender) {
// create a hover area around the entity block on the screen
s[s.length] = "<div class='hoverEntity' ";
s[s.length] = "id='"+entity.domHoverId+"' ";
s[s.length] = "entity-idx='"+entity.idx+"' ";
s[s.length] = "style="+Q;
s[s.length] = "top:"+(entity.top-nHoverPadding)+"px;";
s[s.length] = "left:"+(entity.left-nHoverPadding)+"px;";
s[s.length] = "width:"+(entity.width+nHoverPadding*2)+"px;";
s[s.length] = "height:"+(entity.height+nHoverPadding*2)+"px;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "</div>"; // hoverEntity
s[s.length] = "<div class='baseEntity' ";
s[s.length] = "id='"+entity.domId+"' ";
s[s.length] = "entity-idx='"+entity.idx+"' ";
s[s.length] = "style="+Q;
s[s.length] = "top:"+entity.top+"px;";
s[s.length] = "left:"+entity.left+"px;";
s[s.length] = "width:"+entity.width+"px;";
s[s.length] = "height:"+entity.height+"px;";
s[s.length] = "background-color:"+entity.color+";";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = renderEntityName(entity);
s[s.length] = renderEntityMembers(entity);
s[s.length] = "</div>";
entity.renderedHtml = s.join("");
entity.needToGenRender = false;
} else {
s[s.length] = entity.renderedHtml;
} // end if/else
return s.join("");
} // end of function
function renderEntityName(entity) {
var s=[];
var Q='"';
s[s.length] = "<div ";
s[s.length] = " entity-idx='"+entity.idx+"' ";
s[s.length] = " class='entityName' ";
s[s.length] = " style="+Q;
s[s.length] = "background:"+entity.titleColor+";";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = entity.entityName;
s[s.length] = "</div>";
return s.join("");
} // end of function
function rndTopOffset() {
var nOffsetValues = [-3,-2,-2,-1,-1,0,0,0,0,0,1,1,2,2,3,4,5,5,6,6];
return getRndArrayVal(nOffsetValues);
} // end of function
function getSyllableCount() {
var a=[2,2,2,2,2,3,3,3,1,4,4];
return getRndArrayVal(a);
} // end of function
function getPhraseLetterCount() {
var a=[5,5,5,5,5,5,4,4,4,4,3,3,3,2,2];
return getRndArrayVal(a);
} // end of function
function getPhrase() {
var vowels = ["a","e","i","o","u","ou"]; // look into this later
var cons = ["a","b","br","bl"]; // look into this later
var sLetters = ["a","a","a","a","a","b","c","c","d","e","e","e","e","e",
"f","g","g","h","h","i","i","i","i","i","j","k","l","m",
"n","n","o","o","o","o","p","qu","r","s","s","t","t","u","v","w",
"x","y","y","y","z"];
var nLetters = getPhraseLetterCount();
var phrase = [];
var n;
for (n=0;n<nLetters;n++) {
phrase[phrase.length] = getRndArrayVal(sLetters);
} // next n
return phrase.join("");
} // end of function
function genCamelCaseTestValue() {
var nSyllables = getSyllableCount();
var s=[];
var n,sPhrase;
for (n=0;n<nSyllables;n++) {
sPhrase = getPhrase();
if (n>0) {
sPhrase = sPhrase.charAt(0).toUpperCase()+sPhrase.substr(1,sPhrase.length-1);
} // end if
s[s.length] = sPhrase;
} // next n
return s.join("")
} // end of function
function getRndEntityColor() {
var arr = [
{"colorName":"violet",
"entityColorCode":"#e6ccff",
"titleColorCode":"#cc99ff"},
{"colorName":"rose",
"entityColorCode":"#ffcccc",
"titleColorCode":"#ff8080"},
{"colorName":"lime",
"entityColorCode":"#c1f0c1",
"titleColorCode":"#84e184"}
];
return getRndArrayVal(arr);
} // end of function
function getRndArrayVal(arr) {
return arr[genIntRnd(arr.length)];
} // end of function
/*
generate an int from 0 to nMax - 1
*/
function genIntRnd(nMax) {
var num = Math.floor(Math.random() * nMax);
return num;
} // end of function
/*
Sample: sNewPhone = popValue({input:sPhone,defaultValue:"n/a"});
*/
function popValue(params) {
var overrideValue = params.input;
var defaultValue = params.defaultValue;
var value = defaultValue;
if (typeof overrideValue !== "undefined") {
value = overrideValue;
} // end if
return value;
} // end of function
function addOtherTestMembers(entity) {
var nTotMembers = genIntRnd(18) + 3;
var n;
var sName,sDataType,nSize;
for (n=0;n<nTotMembers;n++) {
sDataType = pickADataType();
nSize = 50;
if (sDataType==="Varchar") {
nSize = pickASize();
} // end if
sName = genCamelCaseTestValue();
entity.addMember({name:sName,dataType:sDataType,
size:nSize});
} // next n
} // end of function
function pickADataType() {
var a = ["Long Int","Long Int","Long Int","Long Int","Int","Int",
"Varchar","Varchar","Varchar","Varchar","Varchar","Blob",
"Date", "Date", "Date", "Date", "Date", "Float",
"Float","Float","Float","Float"];
return getRndArrayVal(a);
} // end of function
function pickASize() {
var a = [0,50,50,50,40,50,40,10,10,5,5,5,4,4,4,2,2,2,2,2,3,3,3,60,60,
60,80,80,80,80,255,255,1024,1024];
var nSize = getRndArrayVal(a);
if (nSize === 0) {
nSize = genIntRnd(60)+5;
} // end if
return nSize;
} // end of function pickASize()
function renderEntityMembers(entity) {
var s = [];
var members = entity.membersByIndex;
var nMax = members.length;
var member,n;
var sDataType;
var Q = '"';
var bShowAltMemberBar = false;
s[s.length] = "<ul class='members'>";
for (n=0;n<nMax;n++) {
member = members[n];
s[s.length] = "<li>";
s[s.length] = "<div class='memberCntr'>";
if (bShowAltMemberBar) {
s[s.length] = "<div class='altMemberBar'></div>";
} // end if
if (member.primaryKey) {
s[s.length] = "<img src="+Q;
// s[s.length] = "./images/PKeyIcon.png";
s[s.length] = "http://chomer.com/wp-content/customPages/dataModel1/images/PKeyIcon.png";
s[s.length] = Q;
s[s.length] = " class='pkIcon' ";
s[s.length] = " title='Primary Key field' ";
// s[s.length] = " style="+Q;
// s[s.length] = Q;
s[s.length] = ">";
} // end if
s[s.length] = "<div class='memberName' ";
s[s.length] = "title="+Q;
s[s.length] = "Member Name: \n";
s[s.length] = member.memberName;
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = member.memberName;
s[s.length] = "</div>"; // memberName
sDataType = member.dataType;
if (sDataType==="Varchar") {
sDataType = sDataType + "(" + member.size + ")";
} // end if
s[s.length] = "<div class='memberDataType'>";
s[s.length] = sDataType;
s[s.length] = "</div>"; // memberDataType
// toggle effect back and forth between rows:
if (bShowAltMemberBar) {
bShowAltMemberBar = false;
} else {
bShowAltMemberBar = true;
} // end if
s[s.length] = "</div>"; // memberCntr
s[s.length] = "</li>";
} // next n
// place to add new field
s[s.length] = "<li>";
s[s.length] = "<div class='memberCntr'>";
s[s.length] = "</div>"; // memberCntr
s[s.length] = "</li>";
s[s.length] = "</ul>";
// temp: height if member line (right now): 14px
/*s[s.length] = "<div style="+Q;
s[s.length] = "position:absolute;left:38px;top:166px;overflow:hidden;";
s[s.length] = "background:red;width:3px;height:3px;z-index:3;";
s[s.length] = Q + ">.</div>";
s[s.length] = "<div style="+Q;
s[s.length] = "position:absolute;left:38px;top:"+(166 + 14)+"px;overflow:hidden;";
s[s.length] = "background:red;width:3px;height:3px;z-index:3;";
s[s.length] = Q + ">.</div>"; */
return s.join("");
} // end of function
/*
*/
function calcDim(nInput) {
var nCallCounter = 0; // closure recursion call counter
var bLogProc = false; // set to true for debug log
var aLogByIndex = [];
var nRes;
var nEnd;
var nLastCheckedValue;
console.log("calcDim() called... nInput: "+nInput);
nInput = nInput - 0; // cast value (if needed)
nEnd = Math.floor(nInput / 2);
if (bLogProc) {
debugger;
} // end if
// inp strt end
nRes = calcDim2(nInput, 1, nEnd);
if (bLogProc) {
debugger;
} // end if
return nRes;
// **************************************
function calcDim2(nInput, nStart, nEnd) {
//console.log("calling calcDim2()");
var nMidCount = Math.floor((nEnd - nStart)/2);
var nTestValue = nStart + nMidCount;
var nCheck = nTestValue * nTestValue;
var sMsg = [],logEntry;
nCallCounter++;
nLastCheckedValue = nCheck;
if (bLogProc) {
logEntry = {"callCounter":nCallCounter,
"nInput":nInput,
"nStart":nStart,
"nEnd":nEnd,
"nMidCount":nMidCount,
"nTestValue":nTestValue,
"nCheck":nCheck};
aLogByIndex[aLogByIndex.length] = logEntry;
} // end if (bLogProc)
if (Math.abs(nEnd - nStart)<2) {
return nEnd;
} //
if (nCallCounter>nInput) {
console.log("failure... there is a problem.");
return -2; // basically a "stack overflow" (stop before it occures)
} // end if
if (nCheck === nInput) {
// is it an exact match?
return nTestValue;
} else if (nCheck >= nInput -1 && nCheck <= nInput + 1) {
// is it close enough?
return nTestValue + 1;
} else {
// do we keep looking?
if (nCheck < nInput) {
return calcDim2(nInput, nTestValue, nEnd);
} else {
return calcDim2(nInput, nStart, nTestValue);
} // end if/else
} // end if / ifelse / else
return -1; // should never happen
} // end of function calcDim2(nInput, nStart, nEnd)
} // end of function calcDim(nInput)
function dspPhpClass() {
var s = [];
var entity = dta.currentEntity;
s[s.length] = genPhpClassSource(entity).join("\n");
showCodeSample(s);
} // end of function dspPhpClass()
function dspPhpILQuery() {
var s = [];
var entity = dta.currentEntity;
var aQry = genEntitySelectQuery(entity);
var Q = '"';
var sSPreC = "$sSQL = "+Q;
var sPreC = "$sSQL = $sSQL . "+Q;
var sPostC = Q+";";
var cnt = [];
s[s.length] = "<?php";
s[s.length] = "";
cnt = genPhPConnectString();
cnt = codeIndent(cnt,1);
s[s.length] = cnt.join("\n");
aQry = addPrePostCode(aQry, sSPreC, sPreC, sPostC);
aQry[aQry.length] = "$rsSample = mysqli_query($con, $sSQL);";
aQry = codeIndent(aQry,1);
s[s.length] = aQry.join("\n");
s[s.length] = "";
s[s.length] = "?>";
dta.snippetFileName = entity.entityName + "_inlineQueryExample.php";
showCodeSample(s);
} // end of function dspPhpILQuery()
function codeIndent(arrCode,nIndent) {
var nMax = arrCode.length;
var n;
var sIndent = " ";
var arrCode2 = [];
for (n=0;n<nMax;n++) {
arrCode2[n] = sIndent.repeat(nIndent) + arrCode[n];
} // next n
return arrCode2;
} // end of function
function addPrePostCode(arrCode,sStartPreCode, siOtherPreCode,sPostCode) {
var nMax = arrCode.length;
var n;
var sPreCode = sStartPreCode;
var arrCode2 = [];
var sOtherPreCode = "";
if (typeof siOtherPreCode !== "undefined") {
sOtherPreCode = siOtherPreCode;
} // end if
for (n=0;n<nMax;n++) {
arrCode2[n] = sPreCode + arrCode[n] + sPostCode;
if (sOtherPreCode !== "") {
sPreCode = sOtherPreCode;
} // end if
} // next n
return arrCode2;
} // end of function
function genEntitySelectQuery(entity) {
var s=[];
var n,member;
var members = entity.membersByIndex;
var nMax = members.length;
var sComma;
s[s.length] = "SELECT ";
for (n=0;n<nMax;n++) {
member = members[n];
sComma = ",";
if (n===nMax-1) {
sComma = "";
} // end if
s[s.length] = " "+member.memberName+sComma;
} // next n
s[s.length] = "FROM ";
s[s.length] = " "+entity.entityName;
return s; // not joined in this case!
} // end of function
function genEntitySelectSP(entity) {
} // end of function
function genEntityCreateTableQuery(entity) {
} // end of function
function genPhPConnectString() {
var cnt=[];
cnt[cnt.length] = "$user = 'root';";
cnt[cnt.length] = "$password = 'yourPasswordHere';";
cnt[cnt.length] = "$dbName = 'yourDbNameHere';";
cnt[cnt.length] = "$host = 'localhost'; // yada...";
cnt[cnt.length] = "$port = 8889; // yada!";
cnt[cnt.length] = "";
cnt[cnt.length] = "$con = mysqli_init();";
cnt[cnt.length] = "$success = mysqli_real_connect(";
cnt[cnt.length] = " $con, ";
cnt[cnt.length] = " $host,";
cnt[cnt.length] = " $user,";
cnt[cnt.length] = " $password,";
cnt[cnt.length] = " $dbName,";
cnt[cnt.length] = " $port";
cnt[cnt.length] = ");";
cnt[cnt.length] = "";
return cnt;
} // end of function genPhPConnectString()
function genPhpClassSource(entity) {
var s=[];
var n,member;
var members = entity.membersByIndex;
var nMax = members.length;
s[s.length] = "<?php ";
s[s.length] = "";
s[s.length] = " class "+entity.entityName+" {";
s[s.length] = "";
s[s.length] = " // -- instance variables: ";
for (n=0;n<nMax;n++) {
member = members[n];
s[s.length] = " var $"+member.memberName+";";
} // next n
s[s.length] = "";
s[s.length] = " // -- getters and setters:";
for (n=0;n<nMax;n++) {
member = members[n];
s[s.length] = " function set_"+member.memberName+"($new_"+member.memberName+") {";
s[s.length] = " $this->"+member.memberName+" = $new_"+member.memberName+";";
s[s.length] = " } // end of function ";
s[s.length] = " ";
s[s.length] = " function get_"+member.memberName+"() {";
s[s.length] = " return $this->"+member.memberName+";";
s[s.length] = " } // end of function ";
s[s.length] = " ";
} // next n
s[s.length] = " } // End of '"+entity.entityName+"' class definition";
s[s.length] = "";
s[s.length] = "?>";
return s; // not joined in this case!
} // end of function genPhpClassSource()
function displayTint() {
var tint = $("#tint")[0];
tint.style.display = "block";
} // end of function
function hideTint() {
var tint = $("#tint")[0];
tint.style.display = "none";
} // end of function
function showDialogPanel(sPanelContent) {
var dia = $("#dia")[0];
displayTint();
dia.innerHTML = sPanelContent;
dia.style.display = "block";
} // end of function showDialogPanel()
function hideDialogPanel() {
var dia = $("#dia")[0];
dia.style.display = "none";
hideTint();
} // end of function hideDialogPanel()
function showEntityCodeDia(entity) {
var s=[];
var Q ='"';
s[s.length] = "<span style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:8px;";
s[s.length] = "font-weight:bold;";
s[s.length] = "font-size:24pt;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "Show Selected Entity Code Samples";
s[s.length] = "</span>";
s[s.length] = "<span style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:60px;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "Entity Name: "+entity.entityName;
s[s.length] = "</span>";
s[s.length] = "<span style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:100px;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "Select Output For:";
s[s.length] = "</span>";
s[s.length] = "<select id='outputType' style="+Q;
s[s.length] = "width:200px;";
s[s.length] = "position:absolute;";
s[s.length] = "left:160px;top:100px;";
s[s.length] = Q;
s[s.length] = " onchange='pickCodeOutputType()'";
s[s.length] = ">";
s[s.length] = "<option value='--'>--- web platform ---</option>";
s[s.length] = webPlatformSelections(" ");
s[s.length] = "<option value='--'>--- database ---</option>";
s[s.length] = databaseSelections(" ");
s[s.length] = "</select>"; // outputType
s[s.length] = opnDiv({"id":"lvl2","top":100,"left":380,"display":"none",
"width":380,"bkColor":"white"});
s[s.length] = "<span style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:0px;top:0px;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "Now Select:";
s[s.length] = "</span>";
s[s.length] = "<select id='nowSel' style="+Q;
s[s.length] = "width:200px;";
s[s.length] = "position:absolute;";
s[s.length] = "left:100px;top:0px;";
s[s.length] = Q;
s[s.length] = " onchange='pickNowSel()'";
s[s.length] = ">";
s[s.length] = "</select>"; // nowSel
s[s.length] = "</div>"; // lvl2
s[s.length] = opnDiv({"id":"lvl3","top":140,"left":20,"display":"none",
"width":380,"bkColor":"white"});
s[s.length] = "Finally Select:";
s[s.length] = "<select id='finSel' style="+Q;
s[s.length] = "width:200px;";
s[s.length] = "position:absolute;";
s[s.length] = "left:140px;top:0px;";
s[s.length] = Q;
s[s.length] = " onchange='pickFinSel()'";
s[s.length] = ">";
s[s.length] = "</select>"; // finSel
s[s.length] = "</div>"; // lvl3
s[s.length] = "<span style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:180px;";
s[s.length] = Q;
s[s.length] = ">";
s[s.length] = "Code Snippet:";
s[s.length] = "</span>";
s[s.length] = "<textarea readonly rows='12' cols='107'";
s[s.length] = " style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:200px;";
s[s.length] = "background:lightyellow;";
s[s.length] = Q;
s[s.length] = " id='codeSnippet'></textarea>";
s[s.length] = "<button style="+Q;
s[s.length] = "position:absolute;";
s[s.length] = "left:20px;top:375px;";
s[s.length] = Q;
s[s.length] = " onclick='hideDialogPanel()'>Close</button>";
s[s.length] = "<button id='saveSnippetBtn' style="+Q;
s[s.length] = "position:absolute;display:none;";
s[s.length] = "left:80px;top:375px;";
s[s.length] = Q;
s[s.length] = " onclick='saveCodeSnippet()'>Save</button>";
showDialogPanel(s.join(""));
} // end of function showEntityCodeDia()
function showCrazyMsg(dta) {
var s = [];
var sAdr = getWebPageAdr();
var Q='"';
var sMsgs = dta.msgs;
var nMax = sMsgs.length,n,para,n2,nMax2;
// document.location.href = sAdr + "#CrazyMsgVisited";
// saveHashValue("intro", "");
if (dta.title === "") {
dta.title = "O' Visitor";
} // end if
s[s.length] = "<center><h1>";
s[s.length] = "Welcome "+dta.title+" to this Crazy Demo!";
s[s.length] = "</h1></center>";
for (n=0;n<nMax;n++) {
s[s.length] = "<p style='margin-left:40px;margin-right:40px;'>";
para = sMsgs[n];
nMax2 = para.text.length;
for (n2=0;n2<nMax2;n2++) {
s[s.length] = para.text[n2];
} // next n2
s[s.length] = "</p>";
} // next n
s[s.length] = "<center><hr><br><button ";
s[s.length] = "style="+Q;
s[s.length] = "font-size:24pt;";
s[s.length] = Q;
s[s.length] = " onclick='hideDialogPanel()'>";
s[s.length] = "CLOSE";
s[s.length] = "</button></center>";
showDialogPanel(s.join(""));
} // end of function showCrazyMsg()
function pickCodeOutputType() {
var outputType = $("#outputType")[0];
var lvl2 = $("#lvl2")[0];
var lvl3 = $("#lvl3")[0];
var codeSnippet = $("#codeSnippet")[0];
var nowSel = $("#nowSel")[0];
var sVal = outputType.value;
lvl2.style.display = "block";
lvl3.style.display = "none";
codeSnippet.value = "";
switch (sVal) {
case "--":
lvl2.style.display = "none";
break;
case "php":
popPhpCodeOptions(nowSel);
break;
case "cf":
break;
case "java":
break;
case "sqlSvr":
break;
case "oracle":
break;
case "mysql":
break;
} // end of switch
} // end of function pickCodeOutputType()
function pickNowSel() {
var nowSel = $("#nowSel")[0];
var sVal = nowSel.value;
switch(sVal) {
case "phpClass":
dspPhpClass();
break;
case "phpILQuery":
dspPhpILQuery();
break;
} // end of switch()
} // end of function pickNowSel()
function pickFinSel() {
} // end of function
function showCodeSample(s) {
var codeSnippet = $("#codeSnippet")[0];
var sCode = s.join("\n");
codeSnippet.value = sCode;
} // end of function showCodeSample()
function popPhpCodeOptions(sel) {
sel.options.length=0; // clear previous entries
newOpt({"ctl":sel,"value":"phpClass","caption":"Class","selected":true});
newOpt({"ctl":sel,"value":"phpILQuery","caption":"In-line Query"});
pickNowSel();
} // end of function popPhpCodeOptions()
/*
Examples:
newOpt({"ctl":ctl,"value":"optValue","caption":"My Option"});
newOpt({"ctl":ctl,"value":"optValue","caption":"My Option","selected":true});
*/
function newOpt(params) {
var ctl = params.ctl;
var bSel = getTheValue({"input":params.selected,"default":false});
var vValue = params.value;
var sCaption = params.caption;
var opt = document.createElement("option");
opt.text = sCaption;
opt.value = vValue;
if (bSel) {
opt.selected = true;
} // end if
ctl.add(opt);
} // end of function newOpt()
function opnDiv(params) {
var sId = getTheValue({"input":params.id,"default":""});
var sBackgroundColor = getTheValue({"input":params.bkColor,"default":"lightblue"});
var sPosition = getTheValue({"input":params.position,"default":"absolute"});
var nLeft = getTheValue({"input":params.left,"default":20});
var nTop = getTheValue({"input":params.top,"default":20});
var nWidth = getTheValue({"input":params.width,"default":200});
var nHeight = getTheValue({"input":params.height,"default":20});
var sOverflow = getTheValue({"input":params.overflow,"default":"hidden"});
var sDisplay = getTheValue({"input":params.display,"default":"block"});
var s=[];
var Q='"';
s[s.length] = "<div ";
if (sId !=="") {
s[s.length] = "id="+Q+sId+Q+" ";
} // end if
s[s.length] = " style="+Q;
s[s.length] = "background:"+sBackgroundColor+";";
s[s.length] = "position:"+sPosition+";";
s[s.length] = "top:"+nTop+"px;";
s[s.length] = "left:"+nLeft+"px;";
s[s.length] = "width:"+nWidth+"px;";
s[s.length] = "height:"+nHeight+"px;";
s[s.length] = "overflow:"+sOverflow+"px;";
if (sDisplay !== "block") {
s[s.length] = "display:"+sDisplay+";";
} // end if
s[s.length] = Q + ">";
return s.join("");
} // end of function opnDiv()
function getTheValue(params) {
var vInput = params.input;
var vDefault = params.default;
if (typeof vInput === "undefined") {
vInput = vDefault;
} // end if
return vInput;
} // end of function getTheValue()
function webPlatformSelections(sIndent) {
var s=[];
s[s.length] = "<option value='php'>"+sIndent+"PHP</option>";
s[s.length] = "<option value='cf'>"+sIndent+"ColdFusion</option>";
s[s.length] = "<option value='java'>"+sIndent+"Java</option>";
return s.join("");
} // end of function
function databaseSelections(sIndent) {
var s=[];
s[s.length] = "<option value='sqlSvr'>"+sIndent+"SQL Server</option>";
s[s.length] = "<option value='oracle'>"+sIndent+"Oracle</option>";
s[s.length] = "<option value='mysql'>"+sIndent+"mySQL</option>";
return s.join("");
} // end of function
Also see: Tab Triggers