Giter Site home page Giter Site logo

stho01 / module-js Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 445 KB

A library that you can use to modularize your frontend code rather than building all code inside one big file.

License: MIT License

CSS 4.00% JavaScript 8.73% TypeScript 84.61% HTML 2.67%
javascript typescript html module-system lightweight easy-to-use plug-and-play

module-js's Introduction

ModuleJS

A lightweight javascript library that provides an easy and effortless instantiation of javascript modules.

Build Setup

# install dependencies
npm install

# Build distribution files
grunt "Build Distribution"

# Build example
grunt "Build Test Application"

Nuget Package

# Nuget
https://www.nuget.org/packages/ModuleJS/

# Package Manager
> Install-Package ModuleJs

# .NET CLI
> dotnet add package ModuleJS

TypeScript Example

// TypeScript Class 
namespace Modules {
    export class MyModule implements ModuleJs.Abstract.IModule {
        /**
         * Initialize module
         */
        init(moduleHtml: HTMLElement): void {
            console.log(moduleHtml);
        }

        /**
         * On load is called after every module on page has initialized.
         */
        onLoad(): void {
            console.log("MyModule loaded");
        }

        /**
         * Dispose is called if module is removed from DOM.
         */
        dispose(): void {
            // Detach event handlers etc.
        }
    }
}
<html>
<head>...</head>
<body>
    <div data-module="MyModule">
        <p>Hello world</p>
    </div>
    <script src="scripts/MyModule.js"></script>
    <script src="scripts/modulejs.js"></script>
    <script>
        ModuleJS({ namespaces: ["Modules"]});
    </script>
</body>
</html>

Javascript Example

<html>
<head>...</head>
<body>
    <div data-module="MyModule">
        <p>Hello world</p>
    </div>
    <script src="scripts/modulejs.js"></script>
    <script>
        (function(Modules) {
            Modules.MyModule = function() {
                //...
            };
            Modules.MyModule.prototype = {
                constructor: Modules.MyModule,
                init: function(moduleHtml) {
                    console.log(moduleHtml);
                }
            }
        })(window.Modules || (window.Modules = {}));

        ModuleJS({ namespaces: ["Modules"]});
    </script>
</body>
</html>

console log output:

<div data-module="MyModule">
    <p>Hello world</p>
</div>

Run Example

Use any web server you want and host from /wwwwroot.

module-js's People

Contributors

holste10 avatar stho01 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

module-js's Issues

TypeScript support

The project is written in typescript, but there is no declaration files in the nuget package.

Logo design

I would like to contribute to the development of the project. I am a graphic designer. I want to help. I want to design a logo. What do you say?

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.