Module: nmui

Name-ui tool, an html element ui tool based on name attribute.

Contents

  1. Tools
  2. Resource tools

  3. Initializing tools

Example
var nmui= require("nmui");

Methods

(inner) addCss(cssText)

Add css text to document style

Parameters:
Name Type Description
cssText string

Css stylesheet text

Returns:

void

(inner) bindEvent(thisObj, nameMapping, eventConfig)

Bind event process from event config array

Parameters:
Name Type Description
thisObj object

A this object

nameMapping object

An object mapping dom elements' name attributes to their ids, refer to getMapping()

eventConfig Array.<eventConfigItem>

An array of eventConfigItem, to configure event binding.

Returns:

void

(inner) getId(ele, prefixopt)

Get the id of a dom element. If there's none, create and set a unique id for the element.

Parameters:
Name Type Attributes Description
ele element

A dom element

prefix string <optional>

Prefix string for new id, default is "nmui_".

Returns:

The id of the ei

(inner) getMapping(ele)

Get an object that mapping dom elements' name attributes to their ids.

Parameters:
Name Type Description
ele element

A dom element

Returns:

An object

  • mapping descendant's name to their id
  • mapping "" to the id of the ele itself

(inner) init(ei, uiObject, configopt)

Initialize a nmui object
This function will add following properties to the uiObject,

Parameters:
Name Type Attributes Description
ei element

A dom element

uiObject object

A javascript object that bound to ei, an object of nmuiObject type.

config object <optional>

A config object of nmuiConfig type.

  • If config is empty, the existed uiObject.config will be used to initialize uiObject.
  • If config is not empty, it will be saved to uiObject.config.
Returns:

void

(inner) nme(name)

Get the name mapping dom element, by document.getElementById(...).
This is a property function, in which the this is a nmuiObject object

This:
  • nmuiObject
Parameters:
Name Type Description
name string

An element's name string

Returns:
  • A dom element

  • null if unfound

Type Definitions

eventConfigItem

Event config item

[ name, eventName, func, argArray ]

Properties:
Name Type Attributes Description
name string

[0] A dom element name attribute

eventName string

[1] An event name string, - don't prefix string "on"

func string | function <optional>

[2] A function name string in this, or a function.
* If the func is empty, a string of name+'_on'+EventName is supposed to filled into func (first letter of eventName is in upper case)

argArray array <optional>

[3] An argument array for calling func

Example
[ 'btn1', 'click', 'btn1_onClick' ]
//or
[ 'divMsg', 'dblclick', 'divMsg_onDblclick', [1,2,3] ]	//with extra argument
//or
[ 'spanHint', 'mouseover' ]		//string "spanHint_onMouseover" is set as function name

nmuiConfig

Nmui config object

Properties:
Name Type Attributes Description
html string

A html string for dom element innerHTML

event Array.<eventConfigItem>

An array of eventConfigItem, to configure event binding.

css string

Css stylesheet text

cssLoaded boolean <optional>

A flag, that is set to true after css is loaded to the page.

nmuiObject

Nmui object

Properties:
Name Type Description
config object

An object of nmuiConfig type

nm object

A name mapping object, for saving the result of mapping dom elements' name attribute to their id, refer to getMapping() and init()

nme function

A function to get the name mapping dom element, refer .nme().