SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

Create an HTML5 Inline Text Editing Page Effect using jQuery

August 20, 2013 by Jake Rocheleau

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 Demo – Download 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 Demo – Download 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.

Filed Under: Tutorial Tagged With: editor, howto, html5, plugin

Recent Posts

  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022
  • How to Get Your First Web Design Client

Archives

  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022