CSS Clearfix

.clearfix:after { content: “.”; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; }
.clearfix { display: inline-block; }

html[xmlns] .clearfix { display: block; }
* html .clearfix { height: 1%; }

 

This clearfix code has been around the Web for years circulating amongst savvy web developers. You should apply this class onto a container which holds floating elements. This will ensure any content which comes afterwards will not float but instead be pushed down and cleared.

CSS Resets

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
  outline: none;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html { height: 101%; }
body { font-size: 62.5%; line-height: 1; font-family: Arial, Tahoma, sans-serif; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
strong { font-weight: bold; }
table { border-collapse: collapse; border-spacing: 0; }
img { border: 0; max-width: 100%; }
p { font-size: 1.2em; line-height: 1.0em; color: #333; }

CSS “Stages” : Flash style canvases

I miss working in flash 5. It was a great development environment. It bridged the gap between visual art and code art. Allowed some creative and exciting user interaction. For the next gen it will all be about css and html 5. I am devving some “TimeLines”  , “Movie Clips” and some “Stages” for creating stuff.  Here is the “Stage” template: stage

Here are some prototypes of a “Movie Clip” made from jpg series.  Bubbles

Guie blink

Here is a comparison of image series rendered in flash, and using my “Movie Clip” and “Timeline”  prototypes

Allow user to print the contents of an element

Here is a cross browser solution to allow the user to press a button and print out the contents of an element. Suppose we have a content area with an id of “mycontentarea”, and a button that says “print”. We can attach a handler to the click event and run this code in the function to print out the contents of “mycontentarea”:

[code]
w=window.open();
reportinfo =  document.getElementById(‘mycontentarea’);
w.document.write(reportinfo.innerHTML);
w.document.close();
w.print();
w.close();[/code]

CSS Text Shadows and special effects

There are some great things you can do with the css text- shadow property.

Here is a cool stamped text effect using a background and a text shadow in combination.
Give your background element a grey background color, and give the text a white shadow.

[code language=”css”]
#stampedtext{
display:inline-block;
background-color:grey;
}

#stampedtext h1 {
text-shadow: 0px 1px 1px white;
color: black;
} [/code]

 

stamptedtext

 

Here is a css menu playground with some great css menu ideas: menuandlayout1

Here is css div styling and transformation playground: demo

Make a calendar date picker using jquery

Due to the strict Web Content Accessibility Guidelines for institutions that serve public internet content to users around the world, I am updating some legacy apps to use a date picker to allow user to enter their birthdate. After some research I’ve decided that the jQuery UI datepicker would be the perfect thing to use due to its ability to work in almost every browser that exists.

The first thing I will do is to  read the docs at jQuery official site. Now that I have a good understanding of the scripts and code involved, lets break down the minimum requirements to have this working in a page.

I would want the user to click into the text field…


…and have the picker pop up, with drop downs to choose the month and year…

…then they click to chose the day.

The audience for this user case scenario are adults of an age to be interested in information about college. The device target includes desktop and laptop computers. Mobile devices have native form controls that would conflict with this script.

We start with my html 5 template, then add the calls to the google cdn to get the jquery plug in scripts.
[code language=”html”]<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script>
<link rel=”stylesheet” href=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css” />
<script src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js”></script>[/code]
Next we have  a form  with a date element, given proper name and id attributes.

<form><input type="date" id="mydatefield" name="datefield" value="" placeholder="Enter birthdate" /></form>

Now, all I have to do is call the jquery date picker function on the form element, with options changeMonth and changeYear setup as so…

 $( "#mydatefield" ).datepicker({ changeMonth: true,   changeYear: true, yearRange:"c-80:c"  });

That’s all there is to it. While testing on the desktop, it is working well in Chrome,  Firefox and Internet Explorer.

To avoid the problems of overlayed natives on mobile devices , We  just use a “text” input instead of the html5 “date” input element. We can easily use CSS media queries JavaScript to change the data type on the fly.

detect object in dom jquery see if a table exists on html5 page by id

have a table that is created dynamiclly. need to see if its there, create it or append to it based on its existence.

 

Lets set a var usertableexists=false;

if($(“#mytableid”).length){usertableexists=true;}

console.log(“the table exist var is “+ usertableexists)

Using jquery document delegate to create Inline Editable fields.

I have come up with a technique to allow the user to edit content “Inline”.

Lets look at an example. I have a table of data, and the user needs to be able to edit the “Description” Field. Rather than take the user away from this ui view, I wish to enable “Inline Editing” like many powerful applications are offering these days.

The first step is to assign functions to the correct fields and capture the users input events. The user would click on the field to select it, so lets set up a doc delegate event to capture a click on the description field. We need to use doc delegate because the data is dynamic and so isn’t  in the DOM when the events handlers are normally assigned. Read my post about JQuery Document Delegate to catch up on this technique. I am going to delegate the capture of a click event on any table row <tr> with a class of “editBannerDescription”

$("#bannerslist").on("click", ".editBannerDescription", function(e){
var thedata=$(this).html();
alert(thedata);
 });

Yeah boyeee we have captured a click event for any element in the bannerslist table, and have access to the content that is in the table cell.

The next step is to alter the ui view so the user can edit the contents of the description table cell. I use a JQuery / JavaScript function to accomplish this:

enableEditDescription(object, bannernid){
     console.log("Message from enable Edit Description function: lets 
enable to edit the description of slide id:"+bannernid+" from
description of : "+$("#"+object).html()); }

I will continue to modify the enableEditDescription function to alter the ui view when the user clicks. I will grab the content from the cell, and replace the content with a text area whose value is the text that was in the cell.

The final code looks like this:

$("#bannerslist").on("click", ".editBannerDescription" , function(e){
var thedata=$(this).html();
var object=$(this).attr("id");
var getbannernid = object.match(/d+$/);
if(getbannernid){
    bannernid=parseInt(getbannernid[0], 10);
    console.log("Message from banner admin inc, here in doc delegate for 
     editBannerDescription with content of :"+thedata+" in cell 
     object id: "+object+" for banner nid: "+bannernid);
     enableEditDescription(object, bannernid);}
else{ alert('error getting id');}
 }); // end #bannerslist doc delegate actions

Now, when the user clicks a table cell with editable content, the cell changes into an inline editor.

The user needs to be able to “escape out” of the edit mode, discarding any changes that were made in the field.

Lets start with capturing the escape key press event when the user is in an editing field. We’ll use the good ol doc  delegate to capture this as so…

$("body").on("keydown", "textarea, input", function(e){
if(e.keyCode==27){
console.log("We have key press of escape key, on event target " + e.target.id + 
" lets exit edit mode without saving changes. Lets decide what place they're editing...");}
}); // end on keydown event handler

Now I can put back the original content of the cell and the user will have “escaped out” of edit mode.

The next step is going to be really fun. We are going to capture the press of the “Edit” button and save the new content into our cms.

Check for url anchor code in a string with JavaScript

Well, I have come across the need to make sure that a string doesn’t contain any code that would make it a link. For example, I need to allow the user to enter a filename but not have any html code in it.

For this current situation:
<a href=”myfile.html”> is an invalid string.
http://myfile.html        is an invalid string.

I want the user to only be able to submit “myfile.html” and then I will handle the linking and referencing using server side code.
[code] function checkurl(){ // function to ensure no a href or quotes get in here.
console.log(“Lets check the url to make sure no a href or quotes”);
var thelink=$(“#slide_external_link”).val();
if(thelink !== “”){ // check for stuff we dont want.
if(thelink.match(/href=”([^”]*”)/g) || /^(f|ht)tps?:///i.test(thelink)){ // this looks like it comments out after i.test, but its workin.
console.log(“Can’t process the request because there is code inside the string. We only want the address of page without anchor code”);
alert(“Please remove any anchor code from the external link. An example of valid entry is: directory.asp_Q_pagenumber_E_520”);
return false; } } } // end check url funk[/code]
Now I can call this function as part of my client side validation upon form submit. I also need to implement a server side catch as well, just in case.

Sort a table using JavaScript and Jquery

I have come across the need to update a ui view of tabular content to be sorted by numeric order ascending. Javascript has a sort() that can be used for this purpose. I will use jquery for its powerful and easy selection capabilities.

Here is a sample of the tablular data:

Sequence Filename Description Enabled Delete
0 sliders/test.jpg Its a slider True X
1 sliders/test2.jpg Its another slider! True X
2 my file location my file description True X

When the user changes the sequence, I would like to update the ui view to reflect the changes in the display order.

I have given each row of the table that contains sortable data a class of “sort”

Then I use Jquery to select those rows, and sort them by the number in the sequence column.

 function sortthetable(whattable){ var $tbody = $('#'+whattable); $tbody.find('tr.sort').sort(function(a,b){ var tda = $(a).find('td:eq(0)').text(); // can replace 0 with the column you want to sort on var tdb = $(b).find('td:eq(0)').text(); // this will sort on the firstcolumn // if a < b return 1 return tda > tdb ? 1 // else if a > b return -1 : tda < tdb ? -1 // else they are equal - return 0 : 0; }).appendTo($tbody); }