Giter VIP home page Giter VIP logo

jslibraryboilerplate's Introduction

JavaScript Library Boilerplate

JavaScript Library Boilerplate helps you roll your own js library with a tiny and robust core base.

Create your own library such as jQuery, Zepto, Prototype, etc, very easy and adding your own methods.

The code is written in CoffeeScript, TypeScript and pure JavaScript.

Compiling


**Skip to Usage section if you want to use pure JavaScript version**

For compiling CoffeeScript or TypeScript you will need to install Node.js

After installing Node.js you can compile the files throgh command-line

CoffeeScript

Install CoffeeScript package:

$ npm install -g coffee-script

Compile file:

$ coffee jslibraryboilerplate_coffee.coffee

TypeScript

Install TypeScript package:

$ npm install -g typescript

Compile file:

$ tsc jslibraryboilerplate_class.ts

Usage

Include the .js file in an html document and you are done!

$(...)

Use any valid CSS selector for getting elements from the document

// all p elements
$('p');
// all elements with class 'test'
$('.test');
// checkboxes
$('input[type="checkbox"]');

Demo

Copy, paste to an .html file and run (Live demo)

<!doctype html>
  <title>JavaScript Library Boilerplate</title>
  <!-- include .js file (you may change the name) -->
  <script src="jslibraryboilerplate.js"></script>
  <script>
    // wait for the dom be ready
    $(function () {
      // get all p elements
      var ps = $('p');
      console.log('There are ' + ps.length + ' paragraphs on the page');
      // set some text for the empty paragraphs
      $('.fillme').text('yeah!!');
      // iterate p elements to know if they are even or odd
      ps.each(function (i, el) {
        var evenodd = i % 2 === 0 ? ' even' : ' odd';
        this.textContent += ' (' + i +  evenodd + ')';
      });
    });
  </script>

  <p>This is a paragraph</p>
  <p>Another p</p>

  <p class="fillme"></p>
  <p class="fillme"></p>
  <p class="fillme"></p>

Adding new methods

You can add any method you need to work with a JSLB DOM collection

Example

$.fn.highlight = function (color) {
  color = color || 'yellow'
  return this.each(function () {
    this.style.setProperty('color', color);
  });
};

// highlight all 'strong' elements
$('strong').highlight('red');

That's all, go and roll your own JavaScript Library.

License

See LICENSE.txt

jslibraryboilerplate's People

Contributors

dciccale avatar

Watchers

 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.