Create an HTML5 Inline Text Editing Page Effect using jQuery




After testing many jQuery plugins recently I have found something exquisite. The Popline.js script allows inline-editable content from users. It will generate a unique toolbar for creating headers, formatted text, hyperlinks, and other neat features. You can also generate a separate view-only mode where visitors can share content out to social networks, or search the keywords in Google.

For this tutorial I want to demonstrate how we can implement Popline on a typical webpage. You need to choose the specific content sections which users are allowed to edit. There are also numerous options you can pass into the function for customizing the interface. Check out my live sample demo to get an idea of what we are creating.

jquery plugin popline tutorial howto demo page

Live DemoDownload Source Code

Getting Started

First we need to download a copy of the Popline script from the official Github repo. There are a large number of dependencies which are required to get this running. The plugin relies on Font Awesome which provides glyph icons based in fonts to naturally resize icons based on the toolbar height.

<!doctype html>
<html lang="en-US">
<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Type" content="text/html">
  <title>Popline jQuery Text Editing Toolbar - Demo</title>
  <meta name="author" content="Jake Rocheleau">
  <link rel="shortcut icon" href="http://spyrestudios.com/favicon.ico">
  <link rel="icon" href="http://spyrestudios.com/favicon.ico">
  <link rel="stylesheet" type="text/css" media="all" href="css/styles.css">
  <link rel="stylesheet" type="text/css" media="all" href="css/default.css">
  <link rel="stylesheet" type="text/css" media="all" href="font-awesome/css/font-awesome.min.css">
  <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  <script type="text/javascript" src="js/jquery.popline.min.js"></script>
</head>

The first relative file styles.css is my own custom stylesheet. This will be used to setup the page layout and typography. Then we have default.css which is copied from the Popline folder. All of these CSS styles target the popline toolbar, both positioning and design. Also to get the webfonts loaded properly we need font-awesome.min.css.

If you notice I have included the entire folder named “font-awesome” because it has multiple stylesheets and webfont files. The easiest method is to copy this into your root directory along with /css/ and /js/ folders.

As for the JavaScript files, we only need to include a copy of the Popline plugin along with a recent copy of jQuery. Since there are already so many local scripts it is easiest to download a compressed version of jQuery and keep this stored locally.

Webpage Styles

The typical default.css file has a lot of unique customizations which are solely built around popline. The class .popline is added to a new unordered list which becomes the blue toolbar you see in my demo. So all of these styles may be updated to change the font size, color, spacing, and many other attributes.

.popline {
  position: absolute;
  height: 54px;
  line-height: 54px;
  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
  -ms-border-radius: 6px;
  -o-border-radius: 6px;
  border-radius: 6px;
  -webkit-box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.75);
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.75);
  background: -moz-linear-gradient(top, #2ca6f8 0%, #2b8ae2 100%);
  background: -webkit-linear-gradient(top, #2ca6f8 0%, #2b8ae2 100%);
  background: -o-linear-gradient(top, #2ca6f8 0%, #2b8ae2 100%);
  background: -ms-linear-gradient(top, #2ca6f8 0%, #2b8ae2 100%);
  background: linear-gradient(to bottom, #2ca6f8 0%, #2b8ae2 100%);
  opacity: 0.95;
  display: none;
  margin: 0;
  list-style: none;
  padding: 0px 5px;
  font-family: Arial, Helvetica, "Hiragino Sans GB", sans-serif;
  text-rendering: optimizeLegibility;
  white-space: nowrap; }

Granted this is just one block of code from the stylesheet, but it provides a nice glimpse into the custom setup. My own styles.css stylesheet doesn’t contain much other than typical resets and the wrapper container. This wrapper is centered at 900px and we include a separate Google Web Font using the CSS3 @import declaration.

@import url('http://fonts.googleapis.com/css?family=IM+Fell+Double+Pica');

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-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html { overflow-y: scroll; }
body { 
  font-size: 62.5%; 
  line-height: 1; 
  font-family: 'Helvetica Neue', Helvetica, Tahoma, sans-serif;
  color: #444;
  padding-bottom: 55px;
  background: #fafafa url('bg.png'); /* http://subtlepatterns.com/inspiration-geometry/ */
}

b { font-weight: bold; }
i { font-style: italic; }

br { display: block; line-height: 1.6em; } 

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }

input, textarea { 
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  outline: none; 
}

blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
strong { font-weight: bold; } 

hr {
    height: 12px;
    border: 0;
    box-shadow: inset 0 12px 12px -12px rgba(0,0,0,0.5);
}

table { border-collapse: collapse; border-spacing: 0; }
img { border: 0; max-width: 100%; }

h1 {
  font-family: "IM Fell Double Pica", "Times New Roman", serif;
  font-size: 3.8em;
  line-height: 1.5em;
  color: #555;
  margin-bottom: 16px;
}

h2 {
  font-family: "IM Fell Double Pica", "Times New Roman", serif;
  font-size: 3.0em;
  line-height: 1.5em;
  color: #383838;
  margin-bottom: 15px;
}

p {
  font-size: 1.8em;
  line-height: 1.35em;
  margin-bottom: 10px;
  font-family: "Calisto MT", "Bookman Old Style", Bookman, "Goudy Old Style", Garamond, "Hoefler Text", "Bitstream Charter", Georgia, serif;
}

Note that I have included some resets which are focused solely on deprecated tags, such as <b> and <i>. This is because the Popline plugin will add HTML code using these tags – but my CSS resets remove all the preformatted settings. If you’d rather keep everything simple then don’t use any resets and test out the raw custom Popline formatting styles.

Structuring Content

Inside your webpage there will be sections of content which contain the editable text. Users will not see anything special on the page unless you add a header or some notice that the text is editable.

<h2>Edit Mode:</h2>
<div id="editblock" contenteditable="true">
  <p>Te quiero. English, please. I love you! Great, now I'm late. We need a name. Maybe "Operation Hot Mother." No, let's try to top that. But I didn't take wasn't optimistic it could be done for an answer.</p>
  
  <p>I believe you will find the dessert to be both engrossing and high-grossing! So we don't get dessert? Obviously this blue part here is the land. There's a girl in my soup! You mean the guy we're meeting with can't even grow his own hair? Come on! If you're suggesting I play favorites, you're wrong. I love all of my children equally. I don't care for Gob.</p>
</div>
<br>
<hr>
<br>
<h2>View Mode:</h2>
<div id="viewblock" contenteditable="true">
  <p>But I'm the oldest. The matriarch if you will. Do the right thing here. String this blind girl along so that dad doesn't have to pay his debt to society.</p>
  
  <p>The worst that could happen is that I could spill coffee all over this $3,000 suit. COME ON. These are my awards, Mother. From Army. The seal is for marksmanship, and the gorilla is for sand racing.</p>
</div>

In my sample div containers we add the specific ID which is necessary for jQuery. These values would be #editblock and #viewblock, respectively. One very interesting feature is the HTML5 contenteditable attribute. Normally this will allow users to sit and type extra characters within the box. Obviously this is still possible using Popline but the plugin creates a handy toolbar, as well.

If you notice even my view block has the contenteditable attribute. It should be noted that view mode can be used without contenteditable, meaning that users can still highlight text for sharing without the ability to add their own text. It is flexible enough to work with any value which makes this plugin even more handy. You could theoretically customize all the internal sharing links to match a better theme on your website.

Popline with jQuery

Finally we need to call the main Popline function to get this whole thing working. I have created a new script tag before the closing </body> tag at the bottom of the file. Inside we have two distinct function calls which activate both of the Popline areas separately.

<script type="text/javascript">
$(function(){
  $("#editblock").popline();
  $("#viewblock").popline({mode:'view'});
});
</script>

A blank function call with no parameters works great and will configure Popline running with default settings. Also there are a number of custom options to remove some of the default tools. And based on the Github repo we can expect updates with even more dynamic options in the future. Here is a bit of sample code from the Github readme:

$(".editor").popline({enable: ["link", ["justify", ["justifyCenter", "indent"]] , "orderedList", "unOrderedList"]});
$(".editor").popline({disable: ["link", "blockquote"]});

Using the enable/disable parameters you can also reorder the position of these buttons. Granted that doesn’t seem very useful at first, but when you manage a social blogging platform where users are editing content daily it helps to slim down the toolbar. Overall this plugin still provides an exceptional experience with an easy CSS theme to customize.

jquery plugin popline tutorial howto demo page

Live DemoDownload Source Code

Final Thoughts

I do hope this tutorial can provide some unique insight for web developers. Popline is a very powerful experience which grants more control over to the user. Not all websites can find a use for these features, but it can certainly be utilized well in social networks or web applications. Feel free to download a copy of my source code and test out these plugin features in your own website projects.





About the author:

Jake is a creative designer, illustrator, and web developer. He frequently writes articles involving new-age design concepts and freelance management skills. You can find him in Google or follow his tweets @jakerocheleau

Comments:

Scroll back to the top