lithium php,Gitee 极速下载

Lithium for jQuery

Lithium adds the following useful APIs to be used along with jQuery:

Data type assertion: isDefined,isElement...

Things like bind,inherit,namespace...

Publisher-subscriber pattern that can be used to communicate between loosly coupled modules/components.

Browser detection (which is still useful for fixing certain bugs or for statistics).

Lithium depends on jQuery. Lithium is seperated into modules, so you use only what you need.

Browser support

Latest Chrome,Firefox,Safari,Opera,MS Edge and IE9+.

Usage

Lithium is split into 5 modules:

lithium.js - Core (other modules depends on this module).

lithium.pubsub.js - Publisher-Subscriber.

lithium.browser.js - Browser detection.

lithium.dom.js - Advanced DOM utilities

lithium.extras.js - Contains additional utility methods.

API

Data types

Li.isDefined(val) - Returns true if val isn't undefined.

Li.isElement(o) - Returns true if o is an instance of HTMLElement

Li.isNaN(val) - Returns true if val is NaN.

Similarly Li.isObject, Li.isArray, Li.isFunction, Li.isNumber, Li.isFinite, Li.isBoolean, Li.isString.

Patterns

Li.namespace(string) - Creates a global namespace.

Li.namespace('app.utils');

Li.extend(base, obj) - Classical inheritence

var myClass1 = Li.extend(Object, {

constructor: function (cfg) {

$.extend(this, cfg);

},

prop: "Lithium",

method: function () { return 1;},

statics: { //Special property to defined static methods/properties

staticProp: "prop"

}

});

//Create myClass2 using myClass1 as base class.

var myClass2 = Li.extend(myClass1, {

constructor: function (cfg) {

this.super([cfg]); //call base class constructor

//alternatively, this.super(arguments);

//or this.superclass().constructor.call(this, cfg);

},

//Override 'method'

method: function () {

//Add 1 to the result of base class 'method'.

return 1 + this.super(arugments);

}

});

Li.forEach(obj [, callback, context]) - forEach on any object. For arrays, Array.forEach is called internally.

Li.format(formatString, ...) - A quick string format method

Li.format('

Li.format('

//Both returns '

Li.dom(htmlString, ...) - Converts htmlString to DOM, inserts them into a document fragment and returns the fragment.

Internally this uses Li.format for string formatting.

var df = Li.dom('

document.body.appendChild(df);

Publisher-Subscriber

//Publisher class

var Restaurant = Li.extend(Li.Publisher, {

eventType: ['freefood'], //list of events this class may fire.

//Methods

salesOffer: function () {

this.trigger('freefood', '1.00 PM');

}

});

/*Subscriber/Listener*/

var HungryMan = Li.extend(Object, {

constructor: function (name, restaurant) {

this.name = name;

//Add listener

restaurant.on('freefood', function (time) {

console.log(name + ' says: Yay! Free food!');

}, this);

}

});

/*----------------------------------*/

/*Demonstration*/

/*----------------------------------*/

var someRestaurant = new Restaurant();

new HungryMan('man1', someRestaurant),

new HungryMan('man2', someRestaurant);

//Somewhere in a onclick event we execute...

someRestaurant.salesOffer(); //...this would call all listeners. In this case it will display..

//man1 says: Yay! Free food!

//man2 says: Yay! Free food!

Li.lbind(fn [, context, args...]) - Binds context and arguments to a function (like the JS.1.8.1 Function.bind). Argument list is prepended to fn.

element.onclick = Li.lbind(function (val, e) {

console.log(this === element); //true

console.log(val); //10

console.log(e); //If IE9+, you'll get event.

}, element, 10);

Li.rbind - Same as lbind, except that arguments are appended to fn arugment list.

Li.uuid([len=10, hypenate=false]) - Returns a random UID with length 'len' and hyphenated if hypenate=true, as string.

Li.string.htmlEncode and Li.string.htmlDecode - Encodes/Decodes >,

Browser Detection

Li.isIE - will be set when browser is MS IE.

Li.isIE9 - will be set when browser is MS IE 9.

Li.isChrome

Li.isWebKit

...similar for other browsers and versions

Li.isWindows

Li.isAndroid

Li.isIPhone

Li.isIPad

Li.isMobile - True if iPhone, Android, BlackBerry (Phone), Windows Phone or Symbian.

Additionally:

Li.browser.name - e.g. 'IE'

Li.browser.version - e.g. '9'

Li.browser.OS - e.g. 'Windows'

Li.browser.OSVersion (set if available) - e.g. '6.1'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值