Monday, March 28, 2016

Zip It! Zip It Good with Rails and Rubyzip

In our day-to-day activities we are often interacting with archives. When you want to send your friend a bunch of documents, you’d probably archive them first. When you download a book from the web, it will probably be archived alongside with accompanying materials. So, how can we interact with archives in Ruby? Today we will […]

Continue reading %Zip It! Zip It Good with Rails and Rubyzip%


by Ilya Bodrov-Krukowski via SitePoint

Streamline Your Coding Workflow & Become a Better Programmer

To be a great programmer, it’s not enough to master a programming language—you also need to know how to use the tools, frameworks, and techniques that’ll make it even better. And that’s exactly what the Ultimate Web Developer Bundle teaches. Get it for $59 at SitePoint Shop and save 91%. This bundle is packed with […]

Continue reading %Streamline Your Coding Workflow & Become a Better Programmer%


by SitePoint Offers via SitePoint

Create an Inline Text Editor With the contentEditable Attribute

Creating an inline editor requires effort. You begin by switching the element to be edited with an input or textarea field. For a seamless user experience, you might also have to use some CSS in order to match the styling of swapped elements to the original one. Once the user is done editing, you will again have to switch the elements after copying all the content to the original ones. 

The contentEditable attribute makes this task a lot easier. All you have to do is set this attribute to true and standard HTML5 elements will become editable. In this tutorial, we will create an inline rich text editor based on this feature.

The Basics

This attribute can take three valid values. These are true, false and inherit. The value true indicates that the element is editable. An empty string will also evaluate to true. false indicates that the element is not editable. The value inherit is the default value. inherit indicates that an element will be editable if its immediate parent is editable. This implies that if you make an element editable, all its children and not just immediate ones will become editable as well, unless you explicitly set their contentEditable attribute to false

You can change these values dynamically with JavaScript. If the new value is none of the three valid ones then it throws a SyntaxError exception.

Creating the Editor

To create the inline editor, you need to have the ability to change the value of the contentEditable attribute whenever a user decides to edit something. 

While toggling the contentEditable attribute, it is necessary to know what value the attribute holds currently. To accomplish that, you can use the isContentEditable property. If isContentEditable returns true for an element then the element is currently editable, otherwise it is not. We will use this property shortly to determine the state of various elements in our document.

The first step in building the editor is the creation of a button to toggle editing and some editable elements.

Each element that we intend to keep editable needs to have its own unique Id. This will be helpful when we have to save the changes or retrieve them later to replace the text inside each element.

The following JavaScript code handles all the editing and saving.

We use querySelectorAll() to store all editable elements in a variable. This method returns a NodeList which contains all the elements in our document that are matched by specified selectors. This way it is easier to keep track of editable elements with one variable. For instance, the title of our document can be accessed by using editables[0], which is what we will do next.

Next, we add an event listener to our button's click event. Every time a user clicks on the Edit Document button, we check if the title is editable. If it is not editable, we set the contentEditable property on each of the editable elements to true. Moreover, the text 'Edit Document' changes to 'Save Changes'. After users have made some edits, they can click on the 'Save Changes' button and the changes made can be saved permanently.

If the title is editable, we set the contentEditable property on each of the editable elements to false. At this point, we can also save the content of our document on the server to retrieve later or synchronize the changes to a copy that exists somewhere else. In this tutorial I am going to save everything in localStorage instead. When saving the value in localStorage, I am using the Id of each element to make sure that I don't overwrite anything. 

See my live CodePen demo.

Retrieving Saved Content

If you make changes to any of the elements in the previous demo and reload the page, you will notice that the changes you made are gone. This is because there is no code in place to retrieve the saved data. Once the content has been saved in localStorage, we need to retrieve it later when a user visits the webpage again.

The code above checks if the title, author or content already exist in localStorage. If they do, we set the innerHTML of the respective elements to the retrieved values.

See another CodePen demo

Making the Editor More User-Friendly

To further improve our inline editor, we need to make two changes. The first one is to provide a clear distinction between what is editable and what is not. This may be achieved by changing the appearance of editable elements with CSS. Changing the font and color of the concerned elements should do the trick. The [contenteditable="true"] selector will apply the following style to elements whenever the contenteditable attribute is set to true.

The second improvement would be the ability to auto-save data. You can do it in multiple ways, like auto-save every five seconds. 

You can also save the changes on every keydown event.

In this tutorial I am sticking with the former method. You are free to trigger auto-save based on any event that seems more appropriate in your projects.

View the CodePen demo.

Editing the Entire Page With Design Mode

contentEditable is useful when you have to edit a few elements on a webpage. When the content of all or almost all the elements on a webpage has to be changed, you can use the designMode property. This property is applicable to the whole document. To turn it on and off, you use document.designMode = 'on'; and document.designMode = 'off'; respectively.

This will prove valuable in situations where you are the designer and someone else is the content creator. You provide them with a design and some dummy text. Later, they can replace it with real content. To see designMode in action, open up the console tab in your browser's developer tools. Type document.designMode = 'on'; into the console and press Enter. Everything on this page should be editable now.

Final Thoughts

The contentEditable attribute is convenient in situations like quickly editing articles or enabling users to edit their comments with a single click. This feature was first implemented by IE 5.5. Later, it was standardized by WHATWG. The browser support is also pretty good. All major browsers besides Opera Mini support this attribute.  

JavaScript has become one of the de-facto languages of working on the web. It’s not without it’s learning curves, and there are plenty of frameworks and libraries to keep you busy, as well. If you’re looking for additional resources to study or to use in your work, check out what we have available in the Envato marketplace.

This tutorial covered the basics of the contentEditable attribute and how it can be used to create a basic inline text editor. The next tutorial will teach you how to implement a toolbar and provide rich text editing capabilities.


by Monty Shokeen via Envato Tuts+ Code

What Are WordPress Themes?

12 Brackets Extensions That Will Make Your Life Easier

Brackets is a great source code editor for web designers and front-end web developers. It has a ton of useful features out of the box. You can make your Brackets experience even better by using extensions.

These Brackets extensions will help make your web design and front-end web development workflow a little easier.

1. CanIUse

Quickly see the current level of browser support a certain web technology has without leaving Brackets. This extension sources its data from Can I use.

CanIUse

2. HTML Skeleton

HTML Skeleton helps you set up your HTML files quickly by automatically inserting basic markup such as the doctype declaration, <html>, <head>, <body>, etc.

HTML Skeleton

Related: A Generic HTML5 Template

3. HTML Wrapper

Rapidly mark up a list of text into list items (<li>), table rows (<tr>), hyperlinks, (<a>), and more with HTML Wrapper.

HTML Wrapper

4. Brackets Icons

This is a super simple extension that adds file icons in Brackets’s sidebar. The icons are excellent visual cues that make it much easier to identify the file you’d like to work on.

Brackets Icons

5. Autoprefixer

Automatically and intelligently add vendor prefixes to your CSS properties with the Autoprefixer extension. It uses browser support data from Can I use to decide whether or not a vendor prefix is needed. It’ll also remove unnecessary vendor prefixes.

Autoprefixer

6. JS CSS Minifier

This extension will remove unneeded characters from your JavaScript and CSS files. This process is called minification, and it can improve your website’s speed.

JS CSS Minifier

7. CSSLint

This extension highlights CSS errors and code-quality issues. The errors and warnings reported by this extension are based on CSS Lint rules.

CSSLint

8. Emmet

Emmet is a collection of tools and keyboard shortcuts that can speed up HTML- and CSS-authoring.

Emmet

9. Lorem Ipsum Generator

Need some text to fill up your design prototype? The Lorem Ipsum Generator extension helps you conveniently generate dummy text. (And if you need image placeholders, have a look at Lorem Pixel or DEVimg.)

Lorem Ipsum Generator

10. Beautify

This extension will help keep your HTML, CSS, and JavaScript code consistently formatted, indented, and — most importantly — readable. An alternative option to check out is the CSSComb extension.

Beautify

11. Simple To-Do

Make sure you don’t forget your project tasks by using the Simple To-Do extension, which allows you to create and manage to-do lists for each project within Brackets.

Simple To-Do

12. eqFTP

Transferring and syncing your project’s files to your web host or server requires FTP or SFTP, but such a fundamental web development feature doesn’t come with Brackets. To remedy the situation, use the eqFTP extension, an FTP/STFP client that you can operate from within Brackets.

eqFTP

How to Install Brackets Extensions

The quickest way to install Brackets extensions is by using the Extension Manager — access it by choosing File > Extension Manager in Brackets’s toolbar.

Brackets Extension Manager

If I didn’t mention your favorite Brackets extension, please talk about it in the comments.

Jacob Gube is the founder of Six Revisions. He’s a front-end developer. Connect with him on Twitter and Facebook.

Related

A New Breed of Free Source Code Editors

10 Open Source Blogging Platforms for Developers

15 Free Books for People Who Code

Should Web Designers Know HTML and CSS?

5 Games That Teach You How to Code

The post 12 Brackets Extensions That Will Make Your Life Easier appeared first on Six Revisions.


by Jacob Gube via Six Revisions

How to Use Promoted Pins on Pinterest

ag-promoted-pins-560

Want to get your pins in front of customers? Have you considered using promoted pins? Pinterest promoted pins can help you drive referral traffic and increase sales. In this article you’ll discover how to create promoted pins on Pinterest. Why Promoted Pins? Pinterest’s promoted pins, which are now available to all businesses, are designed to [...]

This post How to Use Promoted Pins on Pinterest first appeared on .
- Your Guide to the Social Media Jungle


by Ana Gotter via

Bonobo Jeans

Interactive on-line catalog presenting the new collection through customized moodboards. Designed by Extrême Sensio & Studio Bonhomme.
by via Awwwards - Sites of the day