• Stars
    star
    287
  • Rank 144,232 (Top 3 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A New Way to Javascript Your HTML

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

More Repositories

1

BOOTSTRA.386

A vintage 1980s DOS inspired Twitter Bootstrap theme
HTML
6,512
star
2

TickTick

JSON in your Bash scripts
Shell
569
star
3

Porter-Stemmer

A Javascript Implementation of the Porter Stemmer
JavaScript
95
star
4

PiggyPack

Hiding Things Out In The Open
Ruby
76
star
5

mansnip

📺 "The new way to search through manpages that everyone is talking about!"
Python
65
star
6

ascsee

An organic image viewer
C
52
star
7

db.js

Thin portable Javascript document store event-driven database
JavaScript
40
star
8

tumblr-scraper

scrapin da tumblr.
Ruby
30
star
9

Porter2-Stemmer

JavaScript
26
star
10

apophnia

Image server
C
20
star
11

_inject

Javascript Code Injection for Debugging
HTML
19
star
12

DRR

A DVR to record the radio that doesn't get podcasted
JavaScript
19
star
13

quick-color

A quick way to manipulate colors without all the nonsense in between
HTML
17
star
14

tools

General purpose tools
Shell
16
star
15

music-explorer

A music scraper, navigator, archiver, and cataloger for people looking for new sounds.
Shell
15
star
16

UniFig

Unicode Figlet conversion
CSS
12
star
17

ytmix

YouTube large playlist navigator web app.
JavaScript
9
star
18

bash-org-tools

bash.org tools
JavaScript
9
star
19

js1k

my js1k spring 2k13 submission
C
9
star
20

vimbuild

A vim builder
Vim Script
9
star
21

phpwtf

Search PHP's documentation from the command line.
PHP
8
star
22

EvDa

Events and Data
JavaScript
7
star
23

tube-get

A tube-site downloader
Python
7
star
24

skype-search

Global skype search fast and easy
JavaScript
6
star
25

aclock

ascii art clock
C
5
star
26

emptyv

80s emptyv clone
JavaScript
4
star
27

proxy

An HTTP Proxy Exclusively For Debugging Alone.
C
4
star
28

jsrand

seeded pseudo-random number generating in javascript
JavaScript
4
star
29

lists

lists of things
3
star
30

Coinbase-pro-portfolio-analyzer

A command-line portfolio analyzer for coinbase pro
Python
3
star
31

ascii-gol-helloworld

A festive ASCII art Hello world
C
3
star
32

acidx

coloring of terminals
C
3
star
33

reddit-comment-miner

Powerful Trolling Technology
3
star
34

similarcolors

Color matching system
C
3
star
35

ComputerHistoryPodcast

Shell
3
star
36

super-secret-github-scraper

shh, secret secret secret
Shell
2
star
37

services-parser

parser of services file, and easy c++ lookup system
C++
2
star
38

js-copypasta

small js helpers designed to be copy pasted into code.
HTML
2
star
39

bracket

a rewritten version of db.js
JavaScript
2
star
40

linkgo.es

url rewriter
HTML
2
star
41

reddit-user-track

just some set of tools to do some reddit stuff.
Python
2
star
42

slowchurn

a new kind of social media + commenting site
2
star
43

ocr-confirm

1
star
44

scout-mysql-nagger

Execute arbitrary mysql queries to your databank of choice.
JavaScript
1
star
45

webspace

JavaScript
1
star
46

js-shell

A javascript debugging shell
JavaScript
1
star
47

articles

the things I write.
HTML
1
star
48

githater

githater core
Python
1
star
49

frustrometer

the legendary frustrometer
HTML
1
star
50

crappy-notion

My Notion configuration. Not a good one at that.
Lua
1
star
51

news-analyzer

Manufacturing Consent meets the Internet
Python
1
star
52

curses_text

A tool for putting text in a curses window
C++
1
star
53

lowcon

Shaming unreadable websites
PHP
1
star
54

syfin

pitch deck for a fake company, weee.
HTML
1
star