reengineering wheel
something like jQuery
small
-
include
base.js
<script src="base.js" type="text/javascript" charset="utf-8"></script>
-
the global variables
BASE
can be use
- get the value of attr from URL search, e.g.
?a=1&b=123
url
Stringignore
Boolean, ignore case- return String, e.g.
BASE.getUrl('b') === '123'
- concat url
url
Stringobj
Object- return String, e.g.
url?a=1&b=123
- extend the source obj according to the target obj
srcObj
,tarObj
Objectbool
Boolean, true tar is srcObj else is tarObjsubExtend
Boolean, extend sub obj- return srcObj
- try to catch JOSN parse error
txt
String- return Object
- try to catch JOSN stringify error
obj
Object- return String
- string compare
aStr
,bStr
StringsplitDot
String, default is '.'aStr > bStr
return 1aStr < bStr
return -1aStr == bStr
return 0- 2.0.123 > 2.0.1221.5
- numerical precision control
val
Number or String, e.g. 123 or '123'bit
Number, precision, default is 0- return Number, e.g.
BASE.dataRound('123.25', 1) === 123.3
- get event targe coord
e
Eventc
String, 'Y' or 'X'(default)- return Number
- change style px value to adp*value
styleStr
String, css styleadpRate
Number, adp rate except 0- return String
- get DOM Element
str
String, '#id', '.class', 'tag'- return Element(#id) or Array Elements(.class tag)
- create DOM Element
tag
String, default is 'div'parEle
Element, parent nodeid
,cls
String- return Element
- text str to Element
ele
Elementstr
String or Number, empty mean clear- return undefined
-
haddle DOM Element hide and show
-
ele
Element -
opt
Boolean or Stringif (opt === 'display') { return ele.style.display; } if (opt) { ele.style.display = (typeof opt === 'string') ? opt : 'block'; } else { ele.style.display = 'none'; }
- remove DOM Element
ele
ElementisSelf
Boolean, true remove ele self, false remove ele children- return undefined
- determine whether
parElement
istarElement
's parent element tarElement
,parElement
Element- return Boolean
- add cls or delete cls for ele
ele
Elementcls
Stringopt
String, 'add'|'del'|'has'(default)- return Boolean or undefined
- if callback is function then execute it
callback
Function- return callback(arg1, arg2)
- get css3 prefix str
str
String, e.g.transition
,transform
- return String, e.g.
webkitTransition
- get data from localStorage
item
String, record keyattr
String, the data obj attribute value- return String or Others
- set data to localStorage
item
String, record keystrobj
String, Object or Number- return undefined
- return XMLHttpRequest
- handle XMLHttpRequest
xhr
XMLHttpRequestcallback
,errback
Function- return undefined
-
achieve 'ajax' communications
-
options
Object -
return undefined
var defaults = { url: '', //ajax request url data: null, //url parameter, Object method: 'GET', //request type async: true, //asynchronous request send: null, //send data timeout: null, //unit ms,synchronous mode is the delay time error: null, //communication error callback function success: null //communication success callback function, with callback parameter };
- check style load ready
id
Stringcssnum
Numbercallback
Function- return undefined
- reader file as txt
url
Stringcallback
Functionsync
Boolean- return undefined
- reader js >ie8
url
Stringid
String, tag idcallback
Function, load js finish to call- return undefined
- reader css
url
Stringid
String, tag idcallback
Function, load js finish to call- return undefined
- create css style tag
styleStr
String, css styleid
String, style tag idcallback
Function, style ready to call- return undefined
- create css style in an adp array scope
styleStr
String, css styleadpAry
Array, adp style point arrayadp
Number, standard adp scalebool
Boolean, adp according to innerHeightid
String, style tag idcallback
Function, style ready to call- return undefined
- create css style in absolute size
styleStr
String, css stylesize
Number, adp absolute sizeadp
Number, standard adp scalebool
Boolean, adp according to innerHeightid
String, style tag idcallback
Function, style ready to call- return undefined
- create css style and change px to px*scale
styleStr
String, css styleid
String, style tag idcallback
Function, style ready to calladp
Number, standard adp scale, default is 480(w) or 690(h)bool
Boolean, adp according to innerHeight- return undefined
- create css style and change px to px*scale according width : height
styleStr
String, css styleid
String, style tag idcallback
Function, style ready to callwidth
Number, width standard adp scale, default is 480height
Number, height standard adp scale, default is 690isMini
Boolean, is mini adp rate- return undefined