Responsive Design Drag and Drop

Sometimes we need drag and drop functionality on websites. Maybe we need to drag one element into another element, or just reorder something just by dragging.

I researched a lot of libraries open source available online, and came to conclusion that JQuery library for Draggable and Droppable is the best so far. Because its methods are very simple, or event handlers for drag and drop. Besides, many other libraries build on top of this JQuery library.

Also because it is very simple to use and implement.

Here is the source code for the HTML page I created. video follows it:

<html>
<!– DESIGN BY JINAN KORDAB –>
<!– DATE: APRIL 9, 2019 –>
<!– BOOTSTRAP RESPONSIVE DESIGN – FRONT END ONLY –>
<!– DEMO USAGE OFDRAG AND DROP FUNCTIONALITY. –>
<!– I FOUND THAT JAVASCRIPT IS THE BEST OPTIONS O FAR FOR HANDLING DRAG AND DROP SINCE THERE ARE MANY THIRD PARTY LIBRARIES AS WELL –>
<!– THIS PAGE SHOWS AN OPTIONS MENU,WITH BOOTSTRAP FOR RESPONSIVE DESIGN, WHEN DROPPED INTO THE MIDDLE CONTAINER,TRIGGERS THE droppable EVENT. –>
<!– INSIDE droppable EVENT,WE CAN ADD AJAX CALLS TO BACK END OT TO ASP.NET MVC CONTROLLERS AND ACTION RESULTS TO GET DATA FROMD ATA BASE –>
<!– YOU CAN USE THIS CODE AS YOU WISH –>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jinan Kordab Draggable with Boostrap Example</title>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script&gt;
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script&gt;
<script src="bootstrap.min.js"></script>
<script>
$( function() {
$( "#draggable" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>TIPS DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable2" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>SALES DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable3" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>MONTHLY DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable4" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>WEEKLY DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable5" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>YTD DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable6" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION ONE DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable7" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION TWO DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable8" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION THREE DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable9" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION FOUR DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable10" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION FIVE DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#draggable11" ).draggable({
opacity: 0.35,
containment: "#droppable",
revert: true,
helper: "clone",
helper: function( event ) {
return $( "<div class='badge badge-success'>OPTION SIX DETAILS</div>" );
},
snap: "#droppable",
start: function() {
},
drag: function() {
},
stop: function() {
}
});
$( "#droppable" ).droppable({
drop: function( event, ui ) {
var options = {};
var draggable = ui.draggable;
//alert(draggable.attr('id'));
if(draggable.attr('id') == "draggable")
{
$( "#draggable" ).effect( "bounce", options, 500, callback );
//$( "#draggable" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable2")
{
$( "#draggable2" ).effect( "bounce", options, 500, callback );
//$( "#draggable2" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable3")
{
$( "#draggable3" ).effect( "bounce", options, 500, callback );
//$( "#draggable3" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable4")
{
$( "#draggable4" ).effect( "bounce", options, 500, callback );
//$( "#draggable4" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable5")
{
$( "#draggable5" ).effect( "bounce", options, 500, callback );
//$( "#draggable5" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable6")
{
$( "#draggable6" ).effect( "bounce", options, 500, callback );
//$( "#draggable6" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable7")
{
$( "#draggable7" ).effect( "bounce", options, 500, callback );
//$( "#draggable7" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable8")
{
$( "#draggable8" ).effect( "bounce", options, 500, callback );
//$( "#draggable8" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable9")
{
$( "#draggable9" ).effect( "bounce", options, 500, callback );
//$( "#draggable9" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable10")
{
$( "#draggable10" ).effect( "bounce", options, 500, callback );
//$( "#draggable10" ).parent().innerText = $( "#draggable" ).innerText;
}
else if(draggable.attr('id') == "draggable11")
{
$( "#draggable11" ).effect( "bounce", options, 500, callback );
//$( "#draggable11" ).parent().innerText = $( "#draggable" ).innerText;
}
}
});
} );
function callback() {
};
</script>
<style type="text/css">
.col-sm.border.rounded.border-warning:hover {
border: 1px solid #6c757d !important;
}
.block {
/* display: block; */
width: 100%;
height: 45px;
/* border: none; */
/* background-color: silver; */
/* padding: 0px 0px; */
/* font-size: 13px; */
/* cursor: pointer; */
/* text-align: center; */
/* color: white; */
font-weight: bold;
overflow: hidden;
}
</style>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-light bg-info ">
<a class="navbar-brand text-white" href="#">LOGO</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active"><a class="nav-link text-white" href="#">HOME
<span class="sr-only">(current)</span></a> </li>
<li class="nav-item"><a class="nav-link text-white" href="#">CONTACT</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
SERVICES </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">SERVICE A</a>
<a class="dropdown-item" href="#">SERVICE B</a>
<div class="dropdown-divider">
</div>
<a class="dropdown-item" href="#">SERVICE C</a> </div>
</li>
<li class="nav-item"><a class="nav-link disabled text-white" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-warning my-2 my-sm-0 text-white" type="submit">
Search</button>
</form>
</div>
</nav>
<hr>
<div class="container-fluid" id="mainMenu">
<div class="row">
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important;">
<div id="draggable" class="btn btn-warning block" style="width:100%">
TIPS</div>
</div>
<div class="col-sm border rounded " style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable2" class="btn btn-warning block" style="width:100%">
SALES</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable3" class="btn btn-warning block" style="width:100%">
MONTHLY</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable4" class="btn btn-warning block" style="width:100%">
WEEKLY</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable5" class="btn btn-warning block" style="width:100%">
YTD</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable6" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable7" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable8" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable9" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable10" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
<div class="col-sm border rounded" style="padding-left:0px !important; padding-right:0px !important;padding-bottom:0px !important">
<div id="draggable11" class="btn btn-warning block" style="width:100%">
OPTION</div>
</div>
</div>
</div>
</div>
<div class="container-fluid" id="droppable" style="border:2px solid red;width:100%;height:98%;margin-top:5px">
</div>
</body>
</html>
view raw Draggable.html hosted with ❤ by GitHub
Drag and Drop for responsive design

Fibonacci Sequence Responsive Web Template – The Golden Spiral

When we mention patterns, we come across many programming language patterns like MVC, Gang Of Four, Repository, and many others. They are called design patterns. And when used in programming, they help write and complete projects, small and big, faster than usual, because in each pattern, a system is defined, by which one can successfully come to desired results and achieve the best optiomal end-result.
Fibonacci Sequence, or golden ratio spiral,can be observed in spirals in nature.The man who observed this sequence is Fibonacci. This sequence looks something like this: 1,1,2,3,5,8 … The next number is the sum of previous two. The formula is F(n) = F(n-1) + F(n-2). And the golden ratio of dividing upper number by previous saller number is always 1.61803 approaching infinity as the numbers grow bigger.

I read a lot of materials on Fibonacci Sequence. Moreover, I was interested in its applications in real life. And nothing much is said about it.Either because it is used by many people and no one wants to tell their secret to the world, although it is not their sequence but a nature’s way of sayign “hi”. Or because indeed it is not applicable or not yet revealed how to apply it in real world. Some examples that I came across is eqyption pyramids proportions, stock market percentages. In stock market buying and selling,Fibonacci Sequence for example is integrate into graphs of rising and falling stocks,where one can make predictions on buying or selling a particular stock, after coputing Fibonacci Sequence from high and low of a trend or stock.

And I did not find much else.Oh, sorry. I also found how people, many people describe where they see the spirals in nature. That is about it.

Since I write software, I thought how can it be applied to software. Proportional web template, based on Fibonacci Sequence, is the first thing that came to my mind.If you search the web for Fibonacci Sequence, you will find the golden ratio picture drawn in squares first, with proportions (height and width) starting with 1,1,2,3,5,8 ..meaning that first two squares have width and height of 1.Then 2X2. Then 3X3. then 5×5, and so on. And with the help of Drafting Compasses, if you draw arcs from one end of each square to its opposite, and continue as the numbers increase, you get the famous Fibonacci Sequence golden spiral which you see all over the web.

So, to design Fibonacci Sequence web template, it needs to be proportional, and maintain its ratio across all screens that the page is opened. In short, it needs to be responsive. So we have width and height that we will need to base on the golden proportion of 1.61803, meaning that the total width of the screen, when bigger column width is divided by shorter column width should equal to 1.61803,no matter what the size of the screen is. Same with height.

For our case, we will consider that for segment AB, AC will be < CB, and AC is left side of a segment and CB is right segment, so AC = left = smaller part, and CB = right = bigger part.

And we will use this JavaScript code to compute left, and right segments’ width and height respectively:


function computeGoldenRatio(widthOrHeight) {
if (!widthOrHeight) {
return {};
}
return {
width: widthOrHeight,
right: Math.round(widthOrHeight/ 1.61803),
total: Math.round(widthOrHeight* 1.61803),
left: widthOrHeight- Math.round(widthOrHeight/ 1.61803)
};
}

view raw

GoldenRatio.js

hosted with ❤ by GitHub

Then we design our basic HTML table, which in theory should have two rows, and two columns, where first column of first row is also divided into two rows, as shown below:


<table width="100%" id="tblMain" bgcolor="#FFFFFF">
<tr>
<td id="col3">
<table border="1" width="100%">
<tr>
<td colspan="2" id="col33" >
<p align="center"><font style="font-size:27px"><b>(3)</b></font></td>
</tr>
<tr>
<td id="col32">
<p align="center"><font style="font-size:27px"><b>(2)</b></font></td>
<td>
<table width="100%" >
<tr>
<td id="col31">
<p align="center"><font style="font-size:27px"><b>(1)</b></font></td>
</tr>
<tr>
<td id="col311">
<p align="center"><font style="font-size:27px"><b>(1)</b></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td id="col5">
<p align="center"><font style="font-size:27px"><b>(5)</b></font></td>
</tr>
<tr>
<td colspan="2" id="col8">
<p align="center"><font style="font-size:27px"><b>(8)</b></font></td>
</tr>
</table>

As you can see, the numbers 1, 1, 3, 5, and 8 resectively denote and represent visually the Fibonacci Sequence proportions.

The next step, for it to be responsive, in $(document).ready or when the document or page that we are loading is ready, we will set proportions. Here is the code for that:


$(document).ready(function () {
var GRWidth = computeGoldenRatio($(window).width());
var GRHeight = computeGoldenRatio($(window).height());
$("#tblMain").height($(window).height() + "px");
$("#tblMain").width($(window).width() + "px");
$("#col3").width(GRWidth.left + "px");
$("#col5").width(GRWidth.right + "px");
$("#col3").height(GRHeight.left + "px");
var GRcol3332H = computeGoldenRatio(GRHeight.left);
$("#col33").height(GRcol3332H.right + "px");
$("#col32").height(GRcol3332H.left + "px");
$("#col31").height((GRcol3332H.left/2) + "px");
$("#col311").height((GRcol3332H.left/2) + "px");
});

So, after doing this,as you can see, wherever the page is opened, even on TV screen, it will have Fibonacci Sequence proportions, and the golden ratio among its squares.

Let’s add very basic but important styles also, in order for content inside to stay inside each cell, and color borders, to see the first Fibonacci Sequence Responsive Web Template:


<style type=text/css>
table
{
table-layout:fixed;
border:1px solid grey;
cell-padding:0px;
cell-spacing:0px;
border-collapse:collapse
}
td{
border:1px solid grey
}
</style>

Also let’s add width to 100% to the body because we want it to scale to the container’s maximum width and height, thus obtaining Golden Ratio on whatever screen or device it is opened:

<body style=”width:100%”>

And, in the head, please add JQuery script, or translate it to pure javascript if you want, but I use JQuery:

jquery-3.3.1.min.js

All the scripts are included !

Below are the pictures of emulators on major phones and devices. And as you can see, it maintains its ratio.

 

And the code for basic phase one:


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="en-ca">
<script src="jquery-3.3.1.min.js"></script>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
$(document).ready(function () {
var GRWidth = computeGoldenRatio($(window).width());
var GRHeight = computeGoldenRatio($(window).height());
$("#tblMain").height($(window).height() + "px");
$("#tblMain").width($(window).width() + "px");
$("#col3").width(GRWidth.left + "px");
$("#col5").width(GRWidth.right + "px");
$("#col3").height(GRHeight.left + "px");
var GRcol3332H = computeGoldenRatio(GRHeight.left);
$("#col33").height(GRcol3332H.right + "px");
$("#col32").height(GRcol3332H.left + "px");
$("#col31").height((GRcol3332H.left/2) + "px");
$("#col311").height((GRcol3332H.left/2) + "px");
});
function computeGoldenRatio(widthOrHeight) {
if (!widthOrHeight) {
return {};
}
return {
width: widthOrHeight,
right: Math.round(widthOrHeight/ 1.61803),
total: Math.round(widthOrHeight* 1.61803),
left: widthOrHeight- Math.round(widthOrHeight/ 1.61803)
};
}
</script>
<style type=text/css>
table
{
table-layout:fixed;
border:1px solid grey;
cell-padding:0px;
cell-spacing:0px;
border-collapse:collapse
}
td{
border:1px solid grey
}
</style>
</head>
<body style="width:100%">
<table width="100%" id="tblMain" bgcolor="#FFFFFF">
<tr>
<td id="col3">
<table border="1" width="100%">
<tr>
<td colspan="2" id="col33" >
<p align="center"><font style="font-size:27px"><b>(3)</b></font></td>
</tr>
<tr>
<td id="col32">
<p align="center"><font style="font-size:27px"><b>(2)</b></font></td>
<td>
<table width="100%" >
<tr>
<td id="col31">
<p align="center"><font style="font-size:27px"><b>(1)</b></font></td>
</tr>
<tr>
<td id="col311">
<p align="center"><font style="font-size:27px"><b>(1)</b></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td id="col5">
<p align="center"><font style="font-size:27px"><b>(5)</b></font></td>
</tr>
<tr>
<td colspan="2" id="col8">
<p align="center"><font style="font-size:27px"><b>(8)</b></font></td>
</tr>
</table>
</body>
</html>

The next phase or step is to include content. I decided it would be great to include bootstrap css and javascript.So we will add two bootstrap scripts:


<link rel="stylesheet" href="bootstrap.min.css">
<script src="bootstrap.min.js"></script>

Then, for each Fibonacci Square, or td, in our case, we need to add following CSS:

style=”overflow-y: scroll;text-overflow: ellipsis;white-space: nowrap;position:relative;vertical-align:top”

And, here is the important part, include all the content that we want to put inside container of any kind, (div with class = container in our case), with position absolute. This is in order to achieve respectively full elements content stretch, and overflow scroll, which is when content is higher than the square, it will add a scroll bar on Y-axis. An example would be a twitter feed in one of the suares, 1,2, 3, 5, or 8.

In short, you can put anything in those squares.

Square 2, I left it for LOGO, BRAND name, TITLE, or NAME. The rest is content, bootstrap content, whichever you want.

In reality, we added a CSS wrapper outside bootstrap, which is Fibonacci Sequence Responsive Web Template, and then inside, we have bootstrap elements.

As an example, I added the following, as shown in the pictures below:

And the code after the bootstrap was added:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="bootstrap.min.css">
<script src="jquery-3.3.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
var GRWidth = computeGoldenRatio($(window).width());
var GRHeight = computeGoldenRatio($(window).height());
$("#tblMain").height($(window).height() + "px");
$("#tblMain").width($(window).width() + "px");
$("#col3").width(GRWidth.left + "px");
$("#col5").width(GRWidth.right + "px");
$("#col3").height(GRHeight.left + "px");
var GRcol3332H = computeGoldenRatio(GRHeight.left);
$("#col33").height(GRcol3332H.right + "px");
$("#col32").height(GRcol3332H.left + "px");
$("#col31").height((GRcol3332H.left/2) + "px");
$("#col311").height((GRcol3332H.left/2) + "px");
});
function computeGoldenRatio(widthOrHeight) {
if (!widthOrHeight) {
return {};
}
return {
width: widthOrHeight,
right: Math.round(widthOrHeight/ 1.61803),
total: Math.round(widthOrHeight* 1.61803),
left: widthOrHeight- Math.round(widthOrHeight/ 1.61803)
};
}
</script>
<style type="text/css">
table
{
table-layout:fixed;
border:0px solid grey;
cell-padding:0px;
cell-spacing:0px;
border-collapse:collapse
}
td{
border:0px solid grey;
white-space: nowrap;
overflow:hidden
}
</style>
</head>
<body style="width:100%">
<table width="100%" id="tblMain" bgcolor="#FFFFFF">
<tr>
<td id="col3">
<table border="1" width="100%">
<tr>
<td colspan="2" id="col33" style="overflow-y: scroll;text-overflow: ellipsis;white-space: nowrap;position:relative;vertical-align:top">
<div class="container" style="position:absolute">
<div class="list-group" style="max-width: 100%;">
<a href="#!" class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet, mollis diceret est in.</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-primary">
Ut sea periculis argumentum suscipiantur.</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-secondary">
Mei persequeris reprehendunt in, an qui malorum contentiones</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-success">
Pri hinc tamquam maiestatis te</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-danger">
Percipit legendos argumentum ut eam</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-warning">
Mutat commodo pro ad</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-info">
Ea nihil mollis definitionem sea</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-light">
Ius saepe dicunt ne, movet dicunt tamquam ei pri</a>
<a href="#!" class="list-group-item list-group-item-action list-group-item-dark">
Ex diceret placerat adipisci nec, sumo audiam platonem vix
id</a> </div>
</div>
</td>
</tr>
<tr>
<td id="col32">
<img src="phi-logo-2.png" style="width:100%;height:100%"></td>
<td>
<table width="100%">
<tr>
<td id="col31">
<button type="button" class="btn btn-info" style="width:100%;height:100%">
Sign In</button></td>
</tr>
<tr>
<td id="col311">
<button type="button" class="btn btn-info" style="width:100%;height:100%">
Sign Up</button></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td id="col5" style="overflow-y: scroll;text-overflow: ellipsis;white-space: nowrap;position:relative;vertical-align:top">
<div class="container" style="position:absolute">
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Te adipisci salutatus duo</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary float-right">Go somewhere</a>
</div>
</div>
<div class="card border-secondary mb-3" style="max-width: 100%;">
<div class="card-header">
Lorem ipsum</div>
<div class="card-body text-secondary">
<h5 class="card-title">Pro an postea tacimates</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
</div>
</div>
<div class="card text-white bg-dark mb-3" style="max-width: 100%;">
<div class="card-header">
Lorem ipsum</div>
<div class="card-body">
<h5 class="card-title">At dictas commodo vim</h5>
<p class="card-text text-white">Lorem ipsum dolor sit amet,
mollis diceret est in. Ut sea periculis argumentum suscipiantur.</p>
</div>
</div>
<div class="card text-white bg-warning mb-3" style="max-width: 100%;">
<div class="card-header">
Lorem ipsum</div>
<div class="card-body">
<h5 class="card-title">Suas vituperatoribus sit no</h5>
<p class="card-text text-white">Lorem ipsum dolor sit amet,
mollis diceret est in. Ut sea periculis argumentum suscipiantur.</p>
</div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Assum vivendum tacimates per id</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary float-right">Go somewhere</a>
</div>
</div>
<div class="card text-white bg-primary mb-3" style="max-width: 100%;">
<div class="card-header">
Lorem ipsum</div>
<div class="card-body">
<h5 class="card-title">Primary Panel title</h5>
<p class="card-text text-white">Lorem ipsum dolor sit amet,
mollis diceret est in. Ut sea periculis argumentum suscipiantur.</p>
</div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">His quem sumo latine cu, vix quod</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary">Go somewhere</a> </div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Mei porro aperiri suavitate te</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary">Go somewhere</a> </div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Mel te volumus placerat philosophia</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary">Go somewhere</a> </div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Ea mei iisque sapientem</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary">Go somewhere</a> </div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Ea posse oblique eos</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary float-right">Go somewhere</a>
</div>
</div>
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Ea sale alienum pri</h5>
<p class="card-text">Lorem ipsum dolor sit amet, mollis diceret
est in. Ut sea periculis argumentum suscipiantur.</p>
<a href="#!" class="btn btn-primary">Go somewhere</a> </div>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="2" id="col8" style="overflow-y: scroll;text-overflow: ellipsis;white-space: nowrap;position:relative;vertical-align:top">
<div class="container" style="position:absolute;max-width:100%">
<div class="card">
<h5 class="card-header h5">Lorem ipsum</h5>
<div class="card-body">
<h5 class="card-title">Data Table</h5>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Middle</th>
<th scope="col">Last</th>
</tr>
</thead>
<tr>
<th scope="row">1</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">5</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">6</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">7</th>
<td>Fname</td>
<td>Mname</td>
<td>@logo</td>
</tr>
<tr>
<th scope="row">8</th>
<td>Fname</td>
<td>Mname</td>
<td>Lnaem</td>
</tr>
<tr>
<th scope="row">9</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">10</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">11</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">12</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">13</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">14</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">15</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">16</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">17</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
<tr>
<th scope="row">18</th>
<td>Fname</td>
<td>Mname</td>
<td>Lname</td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>

Creating hyperlink [a href=”//””>Click Here ]

There are many different kinds of hyperlinks in HTML. I call the first one static which looks like so :

<a href =”https://www.domain.com”&gt; Click Here </a>

There is nothing special about this hyperlink. It is very basic, does what it is supposed to do, which is navigating to the address that you provided in href.

Next one, I call it semi-static, which navigates to exactly the page you want, like so:

<a href=”https://www.domain.com/page.html”>Click Here </a>

Next one, I call it dynamic link, because it has the ability to navigate to the same page but with different options on that page. It depends on the programmer what kind of options he or she want to show:

<a href=”https://www.domain.com/page.html?param1=123&param2=456&param3=789″>Click Here </a>

The final hyperlink that I wanted to mention is super dyamic, which looks like this:

<a href=”https://www.domain.com/api/345676/676545/876756799991/11232

The reason that I called it super dynamic is because it uses RESTful architecture and HTTP programming with GET, POST and PUT methods.But that is beyond the scope of this blog post.

Now, lets say, you have already WEB API written in C# and ASP.NET MVC. It has unique controller, and GET, POST and PUT methods in place. Meanwhile, an old website, written in classic ASP, with .asp file extension pages, needs to access our API to get full blown HTML page, and replace old page with newly designed cshtml view, by two ways:

  1. Either by clicking a link on an old ASP page and opening new cshtml view in new tab or window
  2. Or embedding our external cshtml view that our WEB API returns in an IFRAME or object in old classic ASP page.

Now, for either of the two cases, we need HREF. A link. A hyperlink. Besides, classic ASP page has different product numeric IDs, in a drop down list,  that need to be passed to WEB API to get static cshtml view, based on user selection.

So what do you think ? Which kind of hyperlink we will need ?

Obviously not static, and not semi static. We can use dynamic, but since we have WEB API C# in place, we need super dynamic hyperlink.

Now as you know, that passing pure product IDs in a query parameters is not a good idea, because someone very curious might want to try different ID instead of the one that is in our hyperlink, resulting him or her getting product that does not belong to him or her.

So, if your parameters are numerical, like 34523, or 88890889, and not strings, you could do something like this, from inside your classic ASP page:


<a target="myIframeInClassicASPPage" href="http://10.10.10.10:9988/api/values/<%=Response.Write(Server.URLEncode(Session("UserName&quot;)))%>/<%=Response.Write(698757 * Server.URLEncode(Session("product_id")))%>" >Click Here</a>

And in C# WEB API Controller, you will have a GET methos, that looks something like this:


public HttpResponseMessage Get(string u, string p)
{
Uri referrer = HttpContext.Current.Request.UrlReferrer;
dynamic myModel = new Models.MyModel();
CirculationMonitor.Controllers.HomeController hc = new HomeController();
string sd = DateTime.Now.ToShortDateString();
string ed = DateTime.Now.ToShortDateString();
var response = new HttpResponseMessage(HttpStatusCode.OK);
if (referrer != null)
{
hc.FillMysModel(myModel,(Convert.ToInt32(p) / 678957 ));
string myviewPath = HttpContext.Current.Server.MapPath(@"~/Views/Home/MyViewToReturn.cshtml");
var template = System.IO.File.ReadAllText(myviewPath);
string parsedView = RazorEngine.Razor.Parse(template, myModel);
response.Content = new StringContent(parsedView);
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html");
}
else
{
response.Content = new StringContent("<html><body><h5>Not authorized. Please use the link on ASP page to getyour product</h5></body></html>");
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html");
}
return response;
}

https://gist.github.com/thoughtsonprogramming/b87ae47fd93a53b5ee28b7de70fbff2f.js

If you notices, 678957 is being used on classic ASP page to multiply the product ID. It is like secret or salt in md5, something similar. And, same number above is used in WEB API c# code to divide the same number to get the original ID.

So building a hyperlink is not so easy it turns out to be. However simple it looks.

Also, first code block has a tag like this: target=myIframeInClassicASPPage“. It means it targets another tag with ID myIframeInClassicASPPage, which we decided to be iFrame. So we want the external cshtml view to load in iFrame, from ASP.NET MVC WEB API C# project in IIS.

Now, in case , and just in case, because I have stumbled across such a thing, your cshtml view does not load in classic ASP, or iFrame displays weird, check your IIS HTTP headers, and explicitly set  X-UA-Compatible property in HTTP Headers section ( You will have to define new HTTP header for your website ) to IE=edge.

This is for it to be cross browser and render properly in IE. I am writing this because I am assuming you are using scripts, bootstrap, font awesome, and all other libraries that need to load with cshtml page as well. So this helps, and works brilliantly !

The end result, is that we have built a super dunamic hyperlink that renders ASP.NET MVC views in classic ASP site page’s iFrame, with all of views scripts, references, etc, using WEB API.

You never know when you will need this !

Thank you.

Overriding inline styling in HTML.

Yes you can. Create a separate style sheet. Example:

myGlobalStyleSheet.css

Let’s say inside our HTML page we have horizontal rule <hr>

<hr size=”4″ align=”center” color=”#0000ff”></hr>

We want to override the color attribute somewhere in external style sheet, inside our myGlobalStyleSheet.css, and change it to #d61924

The CSS specifications at W3C Recommendation says that user !important rule overrides author !important rule.

So we are going to do something like this in external style sheet above:

hr[color] {

color:#d61924 !important;

background-color: #d61924;

border-color: #d61924

}

This will tell the interpreter of HTML, because HTML is interpreted and not compiled, to use the USER level style sheet for DOM element <HR> with COLOR attribute set to its own value, instead of AUTHOR styling which is online styling of an element itself.

The specs also say that AUTHOR level styling takes precedence over USER level styling ( global and external style sheets ), but if we use the !important declaration, it becomes vice versa.