Coder Social home page Coder Social logo

ki.js's Introduction

ki.js

ki.js is a super-tiny jQuery-like JavaScript Library (552 bytes | 347 gzipped)

Browser support

ki.js (recommended) version is supported by the following browsers: IE9+, Chrome 6+, Safari 5+, Firefox 6+, Opera 11.5+.

ki.ie8.js version is supported by the previous browsers including IE8. (811 bytes | 468 gzipped)

What can I do with ki.js?

With ki.js you can do the basic stuff jQuery can, for example:

DOM Ready?

$(function () {
  // this will be executed when the dom is ready!
  alert('Hey the DOM is ready ;)');
});

This was just ki.js, no jQuery

CSS Selectors

Use any CSS selector that exists to get elements from the DOM.

$('p:nth-last-of-type(2)');
$('[attribute|=value]');
$('p:not(.note)');
$('p:empty');

See a list of all CSS selectors

Events

Yes, events with the known .on() and .off() methods

<button>ki.js</button>
$(function () {
  // ok now that the dom is ready i would like to add some events
  var alertMyName = function () {
    alert('My name is ' + this.textContent); // will allert 'ki.js'
  };
  
  $('button').on('click', alertMyName);
  // to turn it off just use .off()
  //$('button').off('click', alertMyName);
});

You can add any JavaScript event even touch events for mobile, under the hood ki.js uses addEventListener, so feel free to use any valid ECMAScript 5 event.

.each()

The each() is also included in the core of ki.js for easy iterating a DOM collection.

$(function () {
  // get all p tags
  $('p').each(function (elem, i) {
    // change color to red
    elem.style.color = 'red';
    // append the index to the text
    elem.textContent += i;
  });
});

Keep the chain!

All methods of ki.js are chainable, just like jQuery.

Plugins?

Yeah, you could write plugins for ki.js if you want, fork the project for making them, keep them super super xxs and I promise to merge them into the official repo.

How to make plugins?

Just add your methods to the prototype of ki.js and you're done. For example, let's add a text() method for setting or getting the text of the elements, in the tiniest way I can think of:

// minified is 106 bytes
$.prototype.text = function (a) {
  return a === []._ ? this[0].textContent : this.each(function (b) {
    b.textContent = a
  })
};

Now use the plugin just like the other methods:

$(function () {
  // <p>hello</p>
  
  // get the text from the p tag
  console.log($('p').text()); // hello
  
  // set another text
  $('p').text('bye'); // bye
});

Create your own plugin and let's make the tiniest JavaScript Library ever! Remember to write byte-saving code, see this [useful resource for JavaScript byte-saving techniques](https://github.com/jed/140bytes/wiki/Byte-saving-techniques) written by 140byt.es community

Where can i use ki.js?

In every cool and modern browser.

The Code

The code of ki.js was written for byte-saving, so I don't recommend using this script for a real application or website. It was done for fun, and the funniest part is that it actually works :)

License

See LICENSE.txt

ki.js's People

Contributors

dciccale avatar

Watchers

Laurent Dufour 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.