tangzhengwen / base

reengineering wheel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

base v2.5.12

reengineering wheel

something like jQuery

small

Getting Started

  1. include base.js

    <script src="base.js" type="text/javascript" charset="utf-8"></script>
  2. the global variables BASE can be use

API

BASE.getUrl(url, ignore)

  • get the value of attr from URL search, e.g. ?a=1&b=123
  • url String
  • ignore Boolean, ignore case
  • return String, e.g. BASE.getUrl('b') === '123'

BASE.concatUrl(url, obj)

  • concat url
  • url String
  • obj Object
  • return String, e.g. url?a=1&b=123

BASE.extendObj(srcObj, tarObj, bool, subExtend)

  • extend the source obj according to the target obj
  • srcObj,tarObj Object
  • bool Boolean, true tar is srcObj else is tarObj
  • subExtend Boolean, extend sub obj
  • return srcObj

BASE.jsonParse(txt)

  • try to catch JOSN parse error
  • txt String
  • return Object

BASE.jsonStringify(obj, replacer, space)

  • try to catch JOSN stringify error
  • obj Object
  • return String

BASE.strCompare(aStr, bStr, splitDot)

  • string compare
  • aStr,bStr String
  • splitDot String, default is '.'
  • aStr > bStr return 1
  • aStr < bStr return -1
  • aStr == bStr return 0
  • 2.0.123 > 2.0.1221.5

BASE.dataRound(val, bit)

  • 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

BASE.getCoord(e, c)

  • get event targe coord
  • e Event
  • c String, 'Y' or 'X'(default)
  • return Number

BASE.cssPxChange(styleStr, adpRate)

  • change style px value to adp*value
  • styleStr String, css style
  • adpRate Number, adp rate except 0
  • return String

BASE.getEle(str)

  • get DOM Element
  • str String, '#id', '.class', 'tag'
  • return Element(#id) or Array Elements(.class tag)

BASE.creEle(tag, parEle, id, cls)

  • create DOM Element
  • tag String, default is 'div'
  • parEle Element, parent node
  • id,cls String
  • return Element

BASE.txtEle(ele, str)

  • text str to Element
  • ele Element
  • str String or Number, empty mean clear
  • return undefined

BASE.disEle(ele, opt)

  • haddle DOM Element hide and show

  • ele Element

  • opt Boolean or String

    if (opt === 'display') {
        return ele.style.display;
    }
    if (opt) {
        ele.style.display = (typeof opt === 'string') ? opt : 'block';
    } else {
        ele.style.display = 'none';
    }

BASE.rmvEle(ele, isSelf)

  • remove DOM Element
  • ele Element
  • isSelf Boolean, true remove ele self, false remove ele children
  • return undefined

BASE.parEle(tarElement, parElement)

  • determine whether parElement is tarElement's parent element
  • tarElement,parElement Element
  • return Boolean

BASE.dealCls(ele, cls, opt)

  • add cls or delete cls for ele
  • ele Element
  • cls String
  • opt String, 'add'|'del'|'has'(default)
  • return Boolean or undefined

BASE.execFun(callback, arg1, arg2)

  • if callback is function then execute it
  • callback Function
  • return callback(arg1, arg2)

BASE.getPrefix(str)

  • get css3 prefix str
  • str String, e.g. transition, transform
  • return String, e.g. webkitTransition

BASE.getStorage(item, attr)

  • get data from localStorage
  • item String, record key
  • attr String, the data obj attribute value
  • return String or Others

BASE.setStorage(item, strobj)

  • set data to localStorage
  • item String, record key
  • strobj String, Object or Number
  • return undefined

BASE.newXhr()

  • return XMLHttpRequest

BASE.xhrRes(xhr, callback, errback)

  • handle XMLHttpRequest
  • xhr XMLHttpRequest
  • callback,errback Function
  • return undefined

BASE.ajax(options)

  • 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
    };

BASE.styleReady(id, cssnum, callback)

  • check style load ready
  • id String
  • cssnum Number
  • callback Function
  • return undefined

BASE.txtReader(url, callback, sync)

  • reader file as txt
  • url String
  • callback Function
  • sync Boolean
  • return undefined

BASE.jsReader(url, id, callback)

  • reader js >ie8
  • url String
  • id String, tag id
  • callback Function, load js finish to call
  • return undefined

BASE.cssReader(url, id, callback)

  • reader css
  • url String
  • id String, tag id
  • callback Function, load js finish to call
  • return undefined

BASE.createStyle(styleStr, id, callback)

  • create css style tag
  • styleStr String, css style
  • id String, style tag id
  • callback Function, style ready to call
  • return undefined

BASE.adpAryScopeStyle(styleStr, adpAry, adp, bool, id, callback)

  • create css style in an adp array scope
  • styleStr String, css style
  • adpAry Array, adp style point array
  • adp Number, standard adp scale
  • bool Boolean, adp according to innerHeight
  • id String, style tag id
  • callback Function, style ready to call
  • return undefined

BASE.adpOneAbsStyle(styleStr, size, adp, bool, id, callback)

  • create css style in absolute size
  • styleStr String, css style
  • size Number, adp absolute size
  • adp Number, standard adp scale
  • bool Boolean, adp according to innerHeight
  • id String, style tag id
  • callback Function, style ready to call
  • return undefined

BASE.adpAllStyle(styleStr, id, callback, adp, bool)

  • create css style and change px to px*scale
  • styleStr String, css style
  • id String, style tag id
  • callback Function, style ready to call
  • adp Number, standard adp scale, default is 480(w) or 690(h)
  • bool Boolean, adp according to innerHeight
  • return undefined

BASE.adpRateStyle(styleStr, id, callback, width, height, isMini)

  • create css style and change px to px*scale according width : height
  • styleStr String, css style
  • id String, style tag id
  • callback Function, style ready to call
  • width Number, width standard adp scale, default is 480
  • height Number, height standard adp scale, default is 690
  • isMini Boolean, is mini adp rate
  • return undefined

License

MIT

About

reengineering wheel

License:MIT License


Languages

Language:JavaScript 79.8%Language:CSS 12.0%Language:HTML 8.2%