Coder Social home page Coder Social logo

toplevel's Introduction

TopLevel

TopLevel enables you to template your HTML, CSS, and Javascript at the Top Level like so:

<!doctype html>
<html>
  <head>
    <script src="YourBrowserCheckCode.js"></script>
    <script src="toplevel.js"></script>

    <!--% if ( CheckBrowser() == "broken" ) { -->
      <link rel="stylesheet" href="broken.css">
    <!--% } else { -->
      ...
    <!--% } -->
    ...

The stylesheet above will never load unless the branch is satisfied.

  • This Is Not a solution of injecting stuff after a page load.
  • This Is Not a solution of downloading and then removing things from the DOM.

The HTML code including the stylesheet will never be interpreted by the browser unless the function CheckBrowser() returns the string "broken". ... seriously ...


Another example:

<!doctype html>
<html>
  <head>
    <script src="toplevel.js"></script>
  </head>

  <body>

    <!--% for(var ix = 0; ix < 10; ix++) { -->
      <p><!--= ix --></p>
    <!--% } -->

  </body>

</html>

When you load the page in the browser you will see 10 paragraph blocks with numbers inside of them.

This Is A Total Game-Changer.

You can put TopLevel stanzas inside of CSS, HTML blocks, even HTML attributes. Take this for example:

<div id="header">
  <img src="logo_<!--= (isMobile() ? "50x50" : "200x200") -->.jpg">
</div>

Only one image will load - the right one for the browser.

There will be no broken looking "flash" --- the delivery is smooth and polished.

All Your JS Still Works.

  • $(document).ready
  • CSS selectors
  • Underscore
  • AMD Loaders, CoffeeScript, Knockout, Angular, Socket.io, Backbone, D3, yes --- all of them.

TopLevel is fast, transparent, and totally rewrites the rules of how you will create webpages.

Works Everywhere And Is 0.6 KB gzipped.

(1.2 KB minified and 4.4 KB for the development version)

It Works On:

  • Chrome
  • Firefox
  • Safari
  • IE
  • Opera
  • Dolphin
  • Seamonkey
  • Chromium

They're all in and all the features are there.

Proof? Ok, sure!

You're welcome.

Add this massive functionality in a single include with under a kilobyte of gzipped code.

Uses Underscore's Templating Engine

TopLevel takes its templating right from underscore. The functionality is identical with a slight change of syntax.

Template functions can both interpolate variables, using <!--= … -->, as well as execute arbitrary JavaScript code, with <!--% … -->. If you wish to interpolate a value, and have it be HTML-escaped, use <!--- … -->.

That is to say, a regular HTML comment block with the first character being either =, %, or -. Keep this in mind, and refer to the underscore documentation for further information!

Easily Enable TopLevel to Use Any Third-Party Library

Everything after the <script src="toplevel.js"></script> gets interpreted. If you want TopLevel to use a say, an MV* framework, simply include it before TopLevel, at the top of the HTML file like so:

<!doctype html>
<html>
  <head>
    ... dependencies you want to expose to TopLevel ...
    <script src="toplevel.js"></script>
    ...

License & Contributions

toplevel's People

Contributors

kristopolous avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.