All Projects → Fcmam5 → Nightly.js

Fcmam5 / Nightly.js

Licence: gpl-3.0
A zero dependency javascript library that enables the night mode in your website easily

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Nightly.js

Books
一些前端/设计相关的书籍(电子书)
Stars: ✭ 134 (-10.67%)
Mutual labels:  frontend
Frontend Download Sample
🎄 自己整理的一些项目中遇到过的关于上传和下载的一些Demo,仅供给位看官参考,避免踩坑,即插即用,欢迎fork和star🌟,为这个仓库添砖加瓦~(P.S. 个人认为如果没写过上传下载其实还是挺麻烦的~)
Stars: ✭ 142 (-5.33%)
Mutual labels:  frontend
Stpageflip
Simple library for creating realistic page turning effects
Stars: ✭ 146 (-2.67%)
Mutual labels:  frontend
Spring Boot Vuejs
Example project showing how to build a Spring Boot App providing a GUI with Vue.js
Stars: ✭ 1,818 (+1112%)
Mutual labels:  frontend
Frontenddaily
前端开发博客,分享互联网最精彩的前端技术,欢迎关注我微信公众号:前端开发博客,回复 1024,领取前端进阶资料包,回复 加群,与大神一起交流学习。
Stars: ✭ 1,901 (+1167.33%)
Mutual labels:  frontend
Overlayscrollbars
A javascript scrollbar plugin which hides native scrollbars, provides custom styleable overlay scrollbars and keeps the native functionality and feeling.
Stars: ✭ 2,054 (+1269.33%)
Mutual labels:  frontend
Tensor
Tensor - Comprehensive web-based automation framework and Centralized infrastructure management platform
Stars: ✭ 136 (-9.33%)
Mutual labels:  frontend
Kunafa
Easy to use, high level framework in Kotlin for front-end web-development
Stars: ✭ 148 (-1.33%)
Mutual labels:  frontend
Daily Apps
Everything you see on Daily 👀
Stars: ✭ 141 (-6%)
Mutual labels:  frontend
Weekly
前端精读周刊。帮你理解最前沿、实用的技术。
Stars: ✭ 16,996 (+11230.67%)
Mutual labels:  frontend
Webpack Unused
Check your frontend code for files/assets that are no longer used.
Stars: ✭ 137 (-8.67%)
Mutual labels:  frontend
Awesome Ember
A curated list of awesome Ember.js stuff like addons, articles, videos, gists and more.
Stars: ✭ 140 (-6.67%)
Mutual labels:  frontend
Gindex V4
A Vue Js Based G Index with Improved Dark Mode, Search and Video Player
Stars: ✭ 143 (-4.67%)
Mutual labels:  frontend
Learnquery
Learn JavaScript fundamentals by building your own jQuery equivalent library
Stars: ✭ 136 (-9.33%)
Mutual labels:  frontend
Blog
一般不会写 API 类文章,努力写有营养的文章,喜欢请点 star
Stars: ✭ 146 (-2.67%)
Mutual labels:  frontend
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-9.33%)
Mutual labels:  frontend
Roadmap Web Developer 2017
Front-end (HTML5/CSS3/Javascript related) technologies to learn in 2017
Stars: ✭ 142 (-5.33%)
Mutual labels:  frontend
Coloquent
Javascript/Typescript library mapping objects and their interrelations to JSON API, with a clean, fluent ActiveRecord-like (e.g. similar to Laravel's Eloquent) syntax for creating, retrieving, updating and deleting model objects.
Stars: ✭ 149 (-0.67%)
Mutual labels:  frontend
Lazy
Kule Lazy4 / CSS Framework
Stars: ✭ 147 (-2%)
Mutual labels:  frontend
Spring Petclinic Angular
Angular 8 version of the Spring Petclinic sample application (frontend)
Stars: ✭ 145 (-3.33%)
Mutual labels:  frontend

Nightly.js

GitHub license dependencies Status npm version Open Source Helpers

A zero dependency Javascript library for enabling dark/night mode in you UI.

Usage

  1. Include Nightly.js
  • Via <script> tag

    <!-- Download this repository then use "dist/nightly.min.js" -->
    <script src="nightly.min.js"></script>
    
    <!-- Or use CDN -->
    <script src="https://cdn.jsdelivr.net/gh/fcmam5/[email protected]/dist/nightly.min.js"></script>
    
  • Or if you prefer npm, run following command at you project's directory:

    npm install --save nightly.js
    

    Then include it

    var Nightly = require('nightly.js');
    
  1. In your main JavaScript file initiate the object

    • Using default Parameters with persistence disabled:

      var Nightly = new Nightly();
      
    • Or customize parameters yourself

      The first parameter is to customize default settings and the second is to enable persistence

      var nightModeConfig = {
        body: 'backgorund color', // Default: #282828
        texts: 'texts color', // Default: #f5f5f5
        inputs: {
          color: 'text color inside inputs', // Default: #f5f5f5
          backgroundColor: 'background color', // Default #313131
        },
        buttons: {
          color: "button's text color", // Default: #f5f5f5
          backgroundColor: "button's backgournd color", // #757575
        },
        links: 'links color (normal state)', // Default: #009688
        classes: [
          // Classes to apply when enabling the dark mode on certain elements
          {
            apply: 'my-selected-class', // just the class name (without the .)
            to: '.my-dark-class-to-the-selected-class .some-nested-class', // uses querySelectorAll
          },
          {
            apply: 'another-selected-class',
            to:
              '.another-dark-class-to-the-selected-class.some-class .some-nested-class',
          },
        ],
      };
      
      var Nightly = new Nightly(nightModeConfig, true); // To disable persistence, set false instead of true
      
  2. Call the darkify() or the toggle() function

// To enable the dark mode
Nightly.darkify();

// To disable the dark mode
Nightly.lightify();

// To toggle between dark and light modes
Nightly.toggle();
  • You can also pass callbacks to darkify(), lightify(). And toggle() takes two callbacks (enableDarkModeCallback, enableLightModeCallback), for example:
var sayGoodMorning = function () {
  console.log('Good morning !');
};

var sayGoodNight = function () {
  console.log('Good night!');
};

// Pass sayGoodMorning() as callback to darkify
Nightly.darkify(sayGoodMorning);

// toggle() takes two callbacks (darkifyCallback, lightifyCallback)
Nightly.toggle(sayGoodNight, sayGoodMorning);

Example

In our first example we created a simple page as the following:

<style media="screen">
  body {
    padding: 50px;
  }
  #btn {
    height: 50px;
    width: 150px;
  }
  .red-text {
    color: #d32f2f;
  }
</style>

<h1>
  Hello, world <span class="red-text">!</span>
  <button type="button" name="button" id="btn">Toggle</button>
</h1>

<p>Please, <a href="#">Click here</a></p>

<div id="form-container">
  <form>
    <label for="name">Your name</label>
    <input type="text" name="name" value="Hello world" placeholder="name" />
  </form>
</div>

Then the result was as following:

Before using Nightly.js

We included nightly.js just before closing the body tag, initiated Nightly object with no arguments, then set an event listener to a button to execute our toggle() method, that switches between darkify() and lightify()

<script src="../src/nightly.js" charset="utf-8"></script>
<script type="text/javascript">
  // Persistence disabled
  var Nightly = new Nightly();
  document.getElementById("btn").addEventListener("click", function(){
    Nightly.toggle();
  });

</script>
</body>

The result was as following:

After using Nightly.js

TODO

  • [x] Add state persistence: use localstorage
  • [ ] Add supported browsers section after testing it
  • [ ] Improve usage section
  • [ ] Document and refactor the code
  • [ ] Continue writing tests
  • [ ] Write plugins for frameworks like Bootstrap:
    • [ ] Bootstrap
    • [ ] Foundation
    • [ ] Materialize

License

This project is licensed under the GNU GPL v3.0 License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].