jQuery.Moxa

Dividing a JavaScript file. No global pollution. Lightweight simple library.

CODE v0.6.6

DIVIDING

It provides a mechanism to separate JavaScript files for each several roles. And you may not write all of the code into a JavaScript file. In addition, it can work when concat files and minify by gulp.

NO GLOBAL

It deters that you define global functions without reason. You don't have to suffer from the global function that someone wrote.

SIMPLE

It is easy to remember. You'll be able to master even immediately. jQuery.Moxa only provides a simple rule. Let's use another library if desired a number of functions.

このエントリーをはてなブックマークに追加

Get

You can get it on npm or bower.

npm install jquery.moxa --save

bower install jquery.moxa --save

If you're not into package management, download a file.

Setup

Include script after the jQuery library.

<script src="/path/to/jquery.moxa.min.js"></script>

Usage


// Controller
$.moxa.controller(function(aViews, aObserver, aDef, aUtil, aAjax){
	// set view -> controller received functions
	aObserver.set({
		some: function(data){
			// do something.
		}
	});

	// ajax data.
	var mData = {
	 	some: null
	};

	// get somejson
	aAjax.get('some.json', null, function(data){
		// save data.
		mData.some = data;
		// send data to view
		aViews.top.init(mData.some);
	});

	// window.Moxa is assigned the object. be able to access of global.
	return {
	 	swf: function(){
	 		// do something.
	 	}
	}
});
		
// Top View
$.moxa.view('top', function(aController, aDef, aUtil, aViewObserver){
	// set controller -> view received functions
	aController.set({
		init: function(data){
			// do something.
		}
	});

	// click events.
	(function(){
		$('#button').on('click', function(){
			// trigger to controller.
			aController.some();
		});
	})();

	// define functions.
	// $.append(), $.remove(), $hide(), $.addClass()........etc
});
		

controller's function is executed from $(document).ready() or Ext.onReady().

jQuery.Moxa By is to implement the process for each role(controller, view..etc) to provide, is suppressed to be a global function definition.

Each role function of the argument , or , is done via observer of jQuery.Moxa. And also it works to concat files and minify by gulp.

Features

Targets

Rules

Just observe the following rules, readability, maintainability will be greatly improved.

jQuery.Moxa Objects

Controller

$.moxa.controller(callback)

The callback is run from the $(document).ready() or Ext.onReady(). Please implement the mainly call divided of view, ajax of execution, data processing. It can be only one registration.

callback(views, observer, def, util, ajax)

View

$.moxa.view(name, callback)

The name, please specify a string that is easy to identify in Controller callback. The callback is run from the $ (document).ready() or Ext.onReady(). Please implement the mainly Click · DOM · CSS -related processing. View you can be multiple registration.

callback(controller, def, util, viewObserver)

Util

isEmpty(data)

It will return false if the empty string, null, [ ].

isShow(el)

It will return false if el is hidden(display: none).

$.moxa.util(properties)

By passing an object that keys and functions as a set in it, you will be able to extend the Util.

Def

$.moxa.def(properties)

By keys and values ​​to pass an object as a set, you can be registered in the Def. When you register a URL · setting flag · message string , etc. It is convenient.

Ajax

get(url, data, success, error)

This will contact the server at the GET request.

post(url, data, success, error)

This will contact the server at the POST request.

$.moxa.ajax(properties)

By passing an object that keys and functions as a set in it, you will be able to extend the Ajax. Common ajax processing, for example, it is useful to register and the like want to do a specific process in the request failure.

Examples

Playground

RUN