Kraken

← Kraken Home

The Kraken Code Guide

Some basic standards to ensure that Kraken add-ons and forks share a common language and approach.

Table of Contents


The Golden Rule

Write code for humans. That means clear section headers, ample white space, and lots of inline documentation.


HTML

HTML Syntax

Incorrect example:

<HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<title>Page title</title>
</head>
<body>
<img src='img/company-logo.png' alt='Company' />
<h1 class='text-muted'>Hello, world!</h1>
</body>
</html>

Correct example:

<!DOCTYPE html>
<html>
    <head>
        <title>Page title</title>
    </head>
    <body>
        <img src="img/company-logo.png" alt="Company">
        <h1 class="text-muted">Hello, world!</h1>
    </body>
</html>

Attribute Order

HTML attributes should be written in this order for easier reading of code:

Example:

<a class="" id="" data-target="" href="">Example link</a>

CSS

CSS Syntax

Incorrect example:

.selector, .selector-secondary, .selector[type=text] {
font-size:15px;
line-height:1.2em;
color:#FFFFFF;
margin:0px auto;
padding:17px}

Correct example:

.selector,
.selector-secondary,
.selector[type="text"] {
    font-size: .882352941em
    line-height: 1.2;
    color: #fff;
    margin-left: auto;
    margin-right: auto;
    padding: 1em;
}

Declaration Order

Related declarations should be grouped together, placing box-model and positioning properties closest to the top, followed by typographic properties, margin and padding, and visual properties.

.declaration-order {
    /* Box-model */
    display: block;
    width: 100%;
    max-height: 20em;
    float: right;

    /* Positioning */
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;

    /* Typography */
    font-size: .875em;
    line-height: 1.5;
    color: #272727;
    text-align: center;

    /* Margin & Padding */
    margin-bottom: 1em;
    padding: 2em;

    /* Visual */
    background-color: #e5e5e5;
    border: 1px solid #808080;
    border-radius: .25em;

    /* Misc */
    opacity: .7;
}

Formatting Exceptions

.selector {
    -webkit-transition: opacity 0.35s ease;
       -moz-transition: opacity 0.35s ease;
        -ms-transition: opacity 0.35s ease;
         -o-transition: opacity 0.35s ease;
            transition: opacity 0.35s ease;
}
            
.icon-logo:before   { content: "\e000"; }
.icon-github:before { content: "\e001"; }
.icon-docs:before   { content: "\e002"; }

h1, h2, h2, h4, h5, h6 { 
    line-height: 1.2; 
    font-weight: normal;
}

Class Names

Bad example:

.b { ... }
.btnWarning { ... }
.btn_Large { ... }

Good example:

.btn { ... }
.btn-red { ... }
.btn-large { ... }

Selectors

Bad example:

header { ... }
.container #main #nav .icon { ... }

Good example:

.text-large { ... }
.nav .icon { ... }
.icon-bar { ... }

JavaScript

JavaScript Syntax

Incorrect example:

$('.collapse-toggle').click(function(e) {
    e.preventDefault();
    var $data_id = $(this).attr('data-target');
    $(data_id).toggleClass('active'); 
});

Correct example:

(function($) {
    $('.collapse-toggle').click(function(e) {
        e.preventDefault();
        var dataID = $(this).attr('data-target');
        $(dataID).toggleClass('active'); 
    });
});

Progressive Enhancement

JavaScript should always be a progressive enhancement. Check for JS support before hiding or altering content.

JavaScript:

(function($) {
    $(function () {
        $('body').addClass('js'); // On page load, add the .js class to the  element.
    });
})(jQuery);

CSS:

.selector { /* Default styles */ }
.js .selector { /* Progressively-enhanced styles */ }

Organization & Documentation

Guidelines

Headings & Sections

File headings and section titles should be clear and distinct. Include five line breaks of white space between sections. Use the following format for files headings and section titles.

File Headings:

/* =============================================================

    Name v1.0
    Description of file by your name
    http://your-url.com

    Free to use under the MIT License.
    http://opensource.org/licenses/MIT
    
 * ============================================================= */

Section Titles:

/* =============================================================
    SECTION TITLE
    Section description
 * ============================================================= */

Inline Documentation

Inline documentation should describe both what a snippet of is and what it does.

/*  Removes list styling.
 *  For semantic reasons, should only 
 *  be used on unordered lists. */
.list-unstyled { 
    margin-left: 0; 
    list-style: none; 
}

Thanks

Thanks for helping make Kraken better. This code guide was inspired by Mark Otto.