123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035 |
- //#region 选择器区域
- //var win = window;// doc = document;
- window._$_ = window.$; //记录命名控件 //全局使用 解决jquery覆盖我们的选择器的问题。
- /*下面的写法会导致程序在window.onload之前执行,为什么要在window.onload之前执行,如果非要执行,能否把所有要做window.onload之前执行的整合在一个文件?并列明必须先执行的理由?*/
- /*
- 选择器前言
- 好处:
- 1、简化项目的代码
- 2、当我对系统的ocument.getElementById document.getElementsByTagName document.getElementsByClassName有奇异 觉得里面需要修改添加一些新的方法处理 可以统一处理
- */
- //#region 创建元素
- /*
- *使用$$操作符简化编码长度。
- *例:$$("div", { "style": { "cssText": "font-size:16px;float:left;line-height:33px;width:40%;margin:0px 0px 0px 15px;" }, "innerHTML": "文件名" }, Inner_J)
- * @param {string} 元素的类型tagName 例如:"div"
- * @param {object} 集合,类似 { "style": { "cssText": "font-size:16px;float:left;line-height:33px;width:40%;margin:0px 0px 0px 15px;" }, "innerHTML": "文件名" }
- * @param {element} 所要追加的父亲元素,把第二个参数作为孩子节点追加到第三个参数。par代表父亲元素
- * @param {element} 追加的位置,如果有此参数,则把创建的元素追加到此元素的前面。此元素必须为第三个参数的孩子节点。
- */
- window.$$ = function (str, obj, par, child) { //创建基本元素元素
- //不传递第三个参数,即父亲元素,则只创建,不追加。不呈现。
- par = par || "";
- var i, _element;
- var _UL = par ? par.length : 0; //
- var _UAE = { "frag": "createDocumentFragment", "text": "createTextNode" };
- if (_UAE[str]) {
- _element = document[_UAE[str]]();
- }
- else {
- _element = document.createElement(str);
- }
- //添加元素
- //如果有样式或者有属性?则给元素添加属性
- if (obj) {
- $(_element).addAttrArray(obj);
- }
- //如果存在父亲,则追加孩子节点。
- if (par) {
- //如果存在第四个参数,则追加到第四个参数的前面。否则,追加在最后面。
- if (child) {
- par.insertBefore(_element, child);
- }
- else {
- par.appendChild(_element);
- }
- }
- return _element;
- }
- window.$$.NS = function (UNE, UDE, UPE, UCE, UUE) { //创建带有命名空间的元素
- var _UDOD = $(document.createElementNS(UUE || "http://www.w3.org/2000/svg", UNE));
- _UDOD.addAttrArray(UDE); (UPE) && (_UDOD.appendTo(UPE, 0, UCE)); return _UDOD[0]; //添加属性
- }
- //#endregion
- //#region 选择器区
- //#region 1473用的快速选择器 去除没有必要的功能 只保留简单的选择功能
- /**
- * 初始化编辑区域
- *
- * @param {string} 选择 首先我们会定义3个获取元素的方法代替系统的 document.getElementById document.getElementsByTagName document.getElementsByClassName
- * @param {元素} 在元素下面搜索符合参数一的所有孩子节点
- 例一、$("#U_Help");找名为U_Help唯一id。
- 例二、$("div", UDKF):在元素UDKF下面搜索所有div元素。
- 例三:$(".className", UDKF) 在元素UDKF下面找classname等于classname的元素。不建议用,性能太低。
- */
- $ = function (name, el) {
- el = el || document; //如果不指定元素,默认为document.
- if (U.Ut.isString(name)) { //检测为普通选择器使用
- var _el = $.getElementByString(name, el); //获取制定的元素
- if (!_el || !_el.init) { //没有给初始化的工具
- return new $.SetMethod(_el); //这个是方法集合
- }
- return _el;
- }
- else { //复杂选择器使用
- return U.Select(name, el);
- }
- }
- //通过元素的来获取
- /**
- * 使用正则表带是
- *
- * @param {string} 选择
- * @param {document} 搜索的层次
- */
- $.getElementByString = function (name, doc) {
- var _e, //这个是获取成功的函数
- _r = name.substring(0, 1), //获取特殊字符 . # 或者 ""
- _n = name.substring(1, name.length); //去除特殊字符后
- doc = doc || document;
- //这里是判断获取
- try { //这里利用基础的选择器选取数据
- switch (_r) {
- case "#": //根据id获取 因为id获取只能通过全局搜索 但是由于项目中有存在克隆的情况 会出现id不唯一的情况
- (doc == document && U.MS.EN.test(_n)) && (_e = document.getElementById(_n));
- break;
- case ".": //根据className获取
- (U.MS.EN.test(_n)) && (_e = doc.getElementsByClassName(_n));
- break;
- default: //标签的获取 //获取指定的元素
- (U.MS.EN.test(name)) && (_e = doc.getElementsByTagName(name)); //除去特殊字符的处理
- break;
- }
- }
- catch (e) { }
- if (_e == null) { //基础的选择器无效 使用html5
- _e = window.SelectorElement(name, doc);
- if (!_e) { //基础选择器html5选择器使用 无法获取结果 使用自定义复杂选择器
- _e = U.Select(name, doc);
- }
- }
- //返回
- return _e;
- }
- /**
- * 元素方法
- *
- * @param {$object} 设置的域
- */
- $.SetMethod = function (el) {
- el = el || [];
- if (U.Ut.IHtmlC(el) || el.length == null) {
- el = [el];
- }
- this.length = el.length;
- for (var i = 0; i < el.length; i++) {
- if (el[i]) {
- this[i] = el[i];
- (el[i].id) && (this[el[i].id] = el[i]);
- }
- }
- }
- //#region 出让命名空间
- //出让命名空间
- //只有外部项目才会使用 为了和其他框架兼容的方案
- $.noConflict = function (UDE) {
- var _UDE = window._$_;
- if (_UDE && _UDE != $) {
- window._$_ = window.$; window.$ = _UDE;
- return window._$_;
- }
- return $;
- }
- //#endregion
- //#endregion
- //#region 通用选择器
- /**
- * 初始化编辑区域
- *
- * @param {string} 选择的元素,例如"div"
- * @param {document} 搜索的层次
- * 返回值:数组 [elment,elment,element]
- <body>
- <div class="classname">
- <div class="classname">
- <input />
- </div>
- <div class="classname">
- <input />
- </div>
- <div class="classname"></div>
- <div class="classname"></div>
- </div>
- <div>
- <div>
- <input />
- </div>
- <div>
- <input />
- </div>
- <div></div>
- <div></div>
- </div>
- </body>
- var a=U.Select("div.classname",body);
- var b=U.Select("input,a)
- */
- U.Select = function (USE, UD) { //定义类
- if (U.Ut.isFunction(USE)) {//函数的处理
- U.Select(document).ready(USE);
- }
- else {//返回选择器的实例
- return (new U.Select.fn.init(USE, UD));
- }
- }
- /**
- * 初始化编辑区域
- *
- * @param {string} 选择特殊字符串 包含# & []
- * @param {document} 搜索的层次
- */
- U.Select.GetSelector = function (UST) { //处理选择器
- if (UST == "#") { //getElementById 的选择符
- return " #";
- }
- else if (UST == "&") { //className联合的选择符
- return " ";
- }
- else if (UST.charAt(0) == "!") { //自定义参数的选择符
- return "[name='" + UST.substr(1) + "']";
- }
- else { //自定义参数使用
- return "[" + UST.substr(1).replace(U.Select.fn.match.ename, "='$1'") + "]";
- }
- };
- /**
- * 动画处理使用
- *
- * @param {string} 选择特殊字符串 包含# & []
- * @param {document} 搜索的层次
- * @param {document} 搜索的层次
- */
- U.Select.IsAnimate = function (UDE, UIE, UCL) {
- var i = UIE || 0, _UL = UIE == null ? UDE.length : UIE + 1, _UTF = arguments.length > 0;
- for (; i < _UL; i++) {
- if (_UTF) {
- UDE[i].__Animate__ = [UDE[i].style.cssText, UDE[i].className, UCL];
- }
- else {
- UDE[i].__Animate__ = null; delete UDE[i].__Animate__;
- }
- }
- };
- /**
- * 这里是选择器的方法集合
- *
- */
- U.Select.fn = U.Select.prototype = {//原型对象使用
- /**
- * 定义选择器构造器
- *
- * @param {string} 选择特殊字符串 包含# & []
- * @param {document} 搜索的层次
- * @return {$object} 返回创建的对象
- */
- init: function (USE, UD) {//
- var _UCE = this.context,
- _URE = this.selector;
- //设置值
- this.length = this.length || 0; //选择元素的总长度
- this.context = _UCE || UD || document; //选择器的域
- this.selector = (typeof USE === "string" ? _URE ? _URE + " " + USE : USE : USE); //选择器的所在的搜索字符串
- //获取元素选择
- this.select(USE, UD); //选择元素
- return this;
- },
- /**
- * 定义选择器构造器
- *
- * @param {string} 选择特殊字符串 包含# & []
- * @param {document} 搜索的层次
- */
- select: function (USE, UD) { //选择器选择
- UD = UD || document;
- if (U.Ut.isString(USE)) { //判断是为选择字符串
- if (USE.indexOf("<") > -1) { //判断是否为创建元素的字符串
- _UDE = $$(USE);
- }
- else {
- var i, j, k, _UTP, _UIE, _UTF, _UVE, _UGE, _UXE, _UJE, _UOT, _UST = "",
- _UDE = UD,
- _UME = this.match, //获取选取的正则
- _UCE = USE.replace(_UME.escape, U.Select.GetSelector),
- _UCN = _UME.con,
- _UKE = [],
- _UBE = browser.ver; //浏览器版本
- _UBE = (_UBE[1] == "msie" && _UBE[2].toInt()); //ie的版本
- //拆分选择器
- do {
- _UCN.exec("");
- _UCE = _UCN.exec(_UCE);
- _UKE.push(_UCE[1] + (_UCE[2] || ""));
- _UCE = _UCE[3];
- }
- while (_UCE); //生成获取集合
- _UXE: for (i = 0; (i < _UKE.length && _UDE); i++) {
- if (_UBE < 6 && _UME.nregular.test((_UTF = _UKE[i + 1]))) {//处理选择伪类等
- if (_UTF == "+" || _UTF == "~") { //向下选择
- if (_UOT = (_UME.pos.test(_UKE[i]) || _UME.child.test(_UKE[i]))) { _UVE = this.getelement(_UKE[i], _UDE, _UST); (U.Ut.IHtmlC(_UVE)) && (_UVE = [_UVE]); } else { _UJE = this.getType(_UKE[i]); }
- _UIE = this.getType(_UKE[i + 2]); _UDE = this.gete(_UDE, _UIE[4], _UST, _UIE);
- for (j = 0; j < _UDE.length; j++) { //判断获取
- _UTP = false; this.celement.apply[_UDE[j]], [_UTF == "+" ? "previousSibling" : "prevaAll", NaN, _UGE = []]; //获取
- for (k = 0; k < _UGE.length; k++) { if (_UOT) { if (_UVE.indexOf(_UGE[k]) > -1) { _UTP = true; break; } } else if (_UGE[0][_UJE[3]].toLowerCase() == _UKE[i]) { _UTP = true; break; } } (!_UTP) && (_UDE.splice(j, 1), j--);
- }
- }
- else if (_UTF == ">") { //子元素
- _UVE = this.getelement(_UKE[i], _UDE, _UST); if (typeof _UVE == "string") { _UVE == this.gete(_UDE, "", _UST); }
- if ((_UDE = _UVE)) {
- (U.Ut.IHtmlC(_UDE)) && (_UDE = [_UDE]); _UGE = []; _UIE = this.getType(_UKE[i + 2]); _UVE = this.gete(_UDE, _UIE[4], "", _UIE);
- for (j = 0; j < _UVE.length; j++) { for (k = 0; k < _UDE.length; k++) { if (_UDE[k] == _UVE[j].parentNode) { _UGE.push(_UVE[j]); break; } } }; _UDE = _UGE;
- }
- }
- _UST = ""; i += 2; (_UIE[2]) && (_UDE = this.getelement("", _UDE, _UIE[2]));
- }
- else { if (_UKE[i].length > 1 && _UKE[i].indexOf("*") > -1) { _UKE[i] = _UKE[i].substr(1); if (!(_UDE = document[_UKE[i]])) { if (browser.msie) { _UDE = document.getElementById(_UKE[i]); } else { _UDE = document.embeds[_UKE[i]]; } } _UST = ""; } else { _UVE = this.getelement(_UKE[i], _UDE, _UST); if (typeof _UVE == "string") { _UST += _UVE; } else if (_UVE) { _UDE = _UVE; _UST = ""; } else if (_UVE === null) { _UDE = null; break _UXE; } else { _UST += _UKE[i]; } } } //IE6以上的直接使用选择器
- }
- if (_UST && _UDE) { _UIE = this.getType(_UST); _UTF = (_UIE && !_UIE[2].trim()); _UDE = this.gete(_UDE, _UIE ? _UIE[4] : "", _UTF ? "" : _UST, _UTF ? _UIE : null); } //添加元素
- }
- }
- else { var _UDE = USE || []; }
- (_UDE) && (this.osadd(_UDE)); return this;
- },
- //正则匹配选择器
- match: {
- number: /\(([\s\S]*?)\)/, //数字的使用
- ename: /=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*/g, //[]选择符的使用
- escape: /(&|![\w\u00c0-\uFFFF\-]|\@[\w\u00c0-\uFFFF\-]+=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*)/g, //需要转义的正则
- nregular: /[>|+|~]/g, //伪类选择
- con: /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, //通用符的使用
- className: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, //className的定义
- id: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, //id的定义
- name: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, //name选择符处理
- attr: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
- tagName: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, child: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/, //标签选择符处理
- pos: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, //子元素选择器
- pseudo: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
- },
- //多个选择
- osel: function (UTP, UTV, UDE, UTE) {
- var i, j, _UKE, _UAE = [], _UCE = [], _UTP = "parentNode", _UTF = true;
- if (UTP) { //选择
- _UCE = [];
- for (i = 0; i < UDE.length; i++) {
- if (UDE[i][UTP] == UTV || UDE[i].getAttribute(UTP) == UTV || UTV === undefined) {
- _UCE.push(UDE[i]);
- }
- }
- }
- else {
- for (i = 0; i < UDE.length; i++) {
- for (j = 0; j < _UAE.length; j++) {
- if (UDE[i][_UTP] == _UAE[j][0]) {
- _UAE[j][1].push(UDE[i]); break;
- }
- _UAE.push[UDE[i][_UTP], [UDE[i]]];
- }
- } //选择的元素
- for (i = 0; i < _UAE.length; i++) { //选择
- _UKE = (UTE && _UAE[0][UTE]) ? _UAE[0][UTE](UTP) : SelectorElement(UTP, _UAE[0]); //获取
- for (j = 0; j < _UKE.length; j++) {
- if (!_UAE[1].length) { break; }
- ((i = _UAE[1].indexOf(_UKE[j])) > -1) && (_UCE.push(_UKE[j]), _UAE[1].splice(i, 1));
- }
- }
- }
- return _UCE;
- },
- //添加选择的元素
- osadd: function (UDE) {
- if (U.Ut.IHtmlC(UDE) || UDE.length == null) {
- UDE = [UDE];
- }
- for (var i = 0; i < UDE.length; i++) {
- if (UDE[i]) {
- this[this.length++] = UDE[i];
- (UDE[i].id) && (this[UDE[i].id] = UDE[i]);
- }
- }
- return this; //添加元素
- },
- //移除元素
- del: function (UIE, UTF) {
- var i, _UL = this.length; (UIE != null) && (this[UIE] = null);
- if (!UTF) {
- for (i = 0; i < _UL; i++) {
- if (this[i] == null) {
- if (this[i + 1]) {
- this[i] = this[i + 1];
- this[i + 1] = null;
- }
- else { delete this[i]; } this.length--;
- }
- }
- }
- },
- gete: function (UDE, UTP, UTS, USM) {//获取元素
- var i, _UCE, _UKE = []; (U.Ut.IHtmlC(UDE)) && (UDE = [UDE]);
- for (i = 0; i < UDE.length; i++) {
- _UCE = UDE[i]; _UCE = (!UTS && (USM[1].length >= USM[0].length - 1) && _UCE[UTP]) ? _UCE[UTP](USM[1]) : SelectorElement(UTS + (USM ? USM[0] : ""), _UCE);
- if (_UCE) { (U.Ut.IHtmlC(_UCE)) && (_UCE = [_UCE]); _UKE = _UKE.concat(U.M.toArray(_UCE)); }
- }
- return _UKE;
- },
- getelement: function (UCE, UDE, USE) {//通过选择字符串获取元素
- var i, _UME = this.match, _UAE = UCE ? this.getType(UCE) : "", _UST = _UAE && _UAE[2], _UBE = browser.ver, _UTF = _UME.pos.test(_UST) || _UME.child.test(_UST); _UBE = (_UBE[1] == "msie", _UBE[2].toInt()); if (!_UAE && UCE) { return _UAE; }
- if (_UAE && USE !== true && (_UAE[0] == UCE || _UAE[2].indexOf(":") == -1) || (!_UTF || (!_UBE || _UBE > 8 || (UCE.indexOf("first-child") > -1 && _UBE > 6)))) { return UCE + " "; } //兼容添加选择值
- else {
- if (_UTF) { //过滤选择 //伪类选择
- _UST = _UST.split(":"); _UAE[0] += _UST[0]; UDE = this.gete(UDE, _UAE[4], USE, _UAE);
- for (i = 1; i < _UST.length; i++) { if (_UST[i] && !U.Ut.IHtmlC(UDE)) { UDE = this.selecte[_UST[i].split("(")[0]].call(this, UDE, _UST[i]); } }
- }
- else { UDE = this.gete(UDE, _UAE[4], "", _UAE); }; return UDE
- }
- },
- getType: function (UCE) {//获取格式
- var i, _UJE, _UME = this.match, _UAE = { "name": "getElementsByName", "id": "getElementById", "tagName": "getElementsByTagName", "className": "getElementsByClassName" };
- for (i in _UAE) { if ((_UJE = _UME[i].exec(UCE))) { return [_UJE[0], _UJE[1], UCE.replace(_UJE[0], ""), i, _UAE[i]]; } } //获取值
- },
- getValue: function (USE) { //通过选择字符串生成响应的选择
- var i, _UDE = {}, _UNC = this.common.nregular, _UC = this.common.regular, _UNCA = (USE.match(_UNC) || []), _UCA = USE.match(_UC) || ["*"];
- for (i = 0; i < _UCA.length; i++) { switch (_UNCA[j]) { case "!": _UDE["name"] = _UCA[j]; break; case "#": _UDE["id"] = _UCA[j]; break; case ".": _UDE["className"] = _UCA[j]; break; case "": case "&": _UDE["tagName"] = _UCA[j]; break; } } //获取
- return _UDE;
- },
- extend: function (UDE) { //扩展选择器
- U.Ut.AddObj(this, UDE)
- },
- length: 0, //初始化长度
- splice: Array.prototype.splice, //筛选的方法
- constructor: U.Select //原型构造器设为本身
- }
- U.Select.fn.init.prototype = U.Select.fn; //添加扩展
- //#endregion
- //#region 扩展选择器
- U.Select.fn.extend({
- //参数一:字符串,形如"div"
- //参数二:整形,从哪个下标开始找。
- find: function (USE, UIE) { //获取元素的后代
- var j;
- var i = UIE || 0;
- var _UL = UIE + 1 || this.length;
- var _elements = []; //
- for (; i < _UL; i++) {
- _elements.concat(U.Select(USE, this[i]));
- // _elements.init(USE, this[i]);
- } //筛选
- //去除选取出来的重复项[element,elment,elment,element]
- _elements.unique();
- return _elements;
- },
- filter: function (UTF, UDE) {//结果集筛选
- UDE = UDE || this; var _UTF, _UCE = [], j, i = 0; if (typeof UTF == "string") { UTF = this.getValue(UTF) } //处理制定的选择 转化成可识别选择
- for (i = 0; i < this.length; i++) {
- for (j in UTF) { if (UTF.hasOwnProperty(j)) { if (this[i][j] != UTF[j]) { break; } } }
- (this[i][j] == UTF[j]) && (_UCE.push(this[i]));
- }
- return U.Select().osadd(_UCE); //添加子元素到制定的位置
- },
- Nodes: function (UIE) { //获取所有的子元素
- UIE = UIE || 0; return this[UIE] ? this[UIE].childNodes : null;
- },
- //UIE 需要给选择的元素数组的第几个
- Child: function (UIE) {//获取有效元素孩子节点
- UIE = UIE || 0; //由于选择选择出来的元素是数组,所以需要筛选出第几个需要获取子节点
- var _UDE = this[UIE] ? U.M.GTCN(this[UIE].childNodes) : null; //如果选择的元素存在则获取子节点 通过U.M.GTCN 可以把 #text节点过滤
- return _UDE;
- // UIE = UIE || 0; var _UDE = this[UIE] ? U.M.GTCN(this[UIE].childNodes, UTP) : null;
- // return UIF != null ? _UDE[UIF] : _UDE;
- },
- siblings: function (UIE) { //当前元素所有的兄弟节点
- var i, _UDE = ["preva", "next"], _UAE = U.Select();
- for (i = 0; i < _UDE.length; i++) { this.celement(_UDE[i] + "All", UIE, _UAE); }
- return _UAE
- },
- celement: function (UTP, UIE, UAE) { //获取元素
- var _UDOD, j, i = UIE || 0, _UL = UIE + 1 || this.length, _UTF = { "prevaAll": "previousSibling", "nextAll": "nextSibling"}[UTP]; UTP = _UTF || UTP; UAE = UAE || U.Select();
- for (i = 0; i < _UL; i++) { //获取指定元素结果
- j = 1; _UDOD = this[i]; while ((j > 0 || (_UTF && _UDOD)) && _UDOD[UTP]) {
- do { _UDOD = _UDOD[UTP]; }
- while (_UDOD && _UDOD.nodeType !== 1);
- (_UDOD) && (UAE[UAE.length++] = _UDOD);
- j--;
- }
- }
- return UAE;
- },
- ofparent: function (UIE, UTF) {//获取offsetParent
- var i = UIE || 0, _UL = UIE + 1 || this.length, UAE = U.Select();
- for (i = 0; i < _UL; i++) { UAE[UAE.length++] = U.M.TOSP(this[i]); }
- return UAE;
- },
- prev: function (UIE) { //当前元素前一个兄弟节点
- return this.celement("previousSibling", UIE);
- },
- prevaAll: function (UIE) {//当前元素之前所有的兄弟节点
- return this.celement("prevaAll", UIE);
- },
- next: function (UIE) { //当前元素之后第一个兄弟节点
- return this.celement("nextSibling", UIE);
- },
- nextAll: function (UIE) { //当前元素之后所有的兄弟节点
- return this.celement("nextAll", UIE);
- },
- //如果没有参数,则是查找自己的父亲,如果有参数,则查找符合条件的祖先元素。
- //如果UTF是数字n,则向上查找n层祖先。
- //如果UTF是属性,则查找符合条件的属性。
- Parent: function (UTF) {//获取上级父亲层
- var i, _USE, _UDOD = this[0]; UTF = UTF || 1;
- if (U.Ut.isNumber(UTF)) { for (i = 0; i < UTF; i++) { (_UDOD) && (_UDOD = _UDOD.parentNode); } }
- else if (U.Ut.isString(UTF)) { _UDOD = U.M.GTPN(_UDOD, UTF); }
- else {
- _USE: while (_UDOD && _UDOD != document) {
- for (i in UTF) {
- if (UTF.hasOwnProperty(i)) {
- if (UTF[i] != _UDOD[i] && _UDOD.getAttribute(i) != UTF[i]) {
- _UDOD = _UDOD.parentNode;
- } else { break _USE; }
- }
- }
- }
- } //条件搜索
- return _UDOD;
- },
- replaceAll: function (UDE, UIE) {
- var _UME, i = UIE || 0, _UL = UIE + 1 || 1;
- for (; i < _UL; i++) {
- if (U.Ut.isString(UDE)) { _UME = $$(UDE); } else { _UME = U.Select(UDE).clone(true); }
- this.Parent(1, i).replaceChild(this[i], _UME);
- }
- },
- //获取孩子节点,能够过滤txt文本。否则,txt文本也可能作为孩子节点,不能精确匹配。
- //UIE 基本没有用
- //UIF 是获取返回子元素的第几个。
- //UTP 基本没有用
- childg: function (UIE, UIF, UTP) {//获取孩子节点
- return U.Select(this.Child.apply(this, arguments));
- },
- parentg: function (UTF, ITF) {//获取父亲节点
- return U.Select(this.Parent(UTF, ITF));
- },
- even: function () { //获取偶数元素
- return this.Auxiliary.selectel("even", this);
- },
- odd: function () { //获取奇数元素
- return this.Auxiliary.selectel("odd", this);
- },
- eq: function (UIE) { //索引制定位置的元素
- return this.Auxiliary.selectel("=" + UIE, this);
- },
- gt: function (UIE) { //索引大于的元素
- return this.Auxiliary.selectel(">" + UIE, this);
- },
- lt: function (UIE) {//索引小于的元素
- return this.Auxiliary.selectel("<" + UIE, this);
- },
- each: function (UCB, UDE) { //遍历数据
- if (UCB) { var i; UDE = UDE || this; for (i = 0; i < UDE.length; i++) { UCB(i, UDE[i]); } }
- },
- only: function (UIE) { //选择没有兄弟节点的元素
- var i, j, _UCE, _UPE, UL = UIE + 1 || this.length;
- for (i = 0; i < UL; i++) { _UCE = this.parentg(1, i).Child(); (_UCE.length != 1 || _UCE[0] != this[i]) && (this.del(i, true)); }
- this.del(); return this;
- },
- checked: function (UIE) {//获取所有给单选或者复选的元素
- var _UCE, j, i = UIE || 0, _UL = UIE + 1 || this.length, _UVE = U.Select();
- for (i = 0; i < _UL; i++) {
- _UCE = U.Select("input@type=checkbox", this[i]); //获取复选框
- for (j = 0; j < _UCE.length; j++) { (_UCE[j].checked) && (_UVE.osadd(_UCE[j])); } //添加所有给复选的元素
- }
- return _UVE;
- },
- selected: function (UIE) {//获取下拉列表中给选择的元素
- var _UCE, j, i = UIE || 0, _UL = UIE + 1 || this.length, _UVE = U.Select();
- for (i = 0; i < _UL; i++) { }
- },
- clone: function (UTF, UIE, UDOD, UDID, USE) { //克隆元素
- var _UDTD, _UDE = [], i = UIE || 0, _UL = UIE + 1 || this.length;
- for (; i < _UL; i++) { _UDE.push(this[i].cloneNode(UTF || false)); }
- _UDTD = U.Select(_UDE); (USE) && (_UDTD.Aattr(USE)); (UDID && !UDOD) && (UDOD = U.Select(UDID).Parent());
- (UDOD) && (_UDTD.appendTo(UDOD, undefined, UDID)); return _UDTD; //直接追加元素
- },
- appendTo: function (UDOD, UIE, UDTD) {//添加元素到制定的位置
- var i = UIE || 0, _UL = UIE + 1 || this.length; UDOD = U.Select(UDOD);
- for (; i < _UL; i++) { UDOD["append"](this[i], 0, UDTD || null); }
- return this;
- },
- append: function (UDOD, UIE, UDTD) {//插入元素
- if (UDOD) {
- if (typeof UDOD == "string") { UDOD = $$("div", { "innerHTML": UDOD }).childNodes; } else { (UDOD.length == null || UDOD.tagName) && (UDOD = [UDOD]); }
- var i, _UL = UDOD.length; for (i = 0; i < UDOD.length; ((_UL == UDOD.length) && (i++))) { this[UIE || 0][UDTD ? "insertBefore" : "appendChild"](UDOD[i] || UDOD, UDTD || null); }
- } return this;
- },
- before: function (UDOD, UIE) { //被选择元素前插入指定元素
- var i = UIE || 0, _UL = (UIE || 0) + 1;
- for (; i < UIE; i++) { this.append(UDOD, i, this[i].firstChild); }
- },
- remove: function (UIE, UTF) {//移除元素
- var _UDOD, i = UIE = UIE || 0, _UL = (UIE || this.length - 1) + 1;
- if (UTF == "animate") { this.fadeOut("fast", function (UIF) { var _UDOD = this[i]; (_UDOD && _UDOD.parentNode) && (_UDOD.parentNode.removeChild(_UDOD)); }, UIE); }
- else { for (; i < _UL; i++) { _UDOD = this[i]; (_UDOD && _UDOD.parentNode) && (_UDOD.parentNode.removeChild(_UDOD)); } }
- return this;
- },
- top: function (UIE) { //获取offsetTop
- return this[UIE || 0].offsetTop;
- },
- left: function (UIE) { //获取offsetLeft
- return this[UIE || 0].offsetLeft;
- },
- width: function (UIE) {//获取长
- return U.M.GETHW(this[UIE || 0], "width");
- },
- innerWidth: function (UIE) { //获取内宽度 包含padding
- return this[UIE || 0].clientWidth;
- },
- outerWidth: function (UIE, UTF) { //获取整体宽度 包含 padding border ture包含margin
- this[UIE || 0].offsetWidth + this.css("marginLeft") + this.css("marginRight");
- },
- height: function (UIE) { //获取宽
- return U.M.GETHW(this[UIE || 0], "height");
- },
- innerHeight: function () { //内高度
- return this[UIE || 0].clientHeight;
- },
- outerHeight: function () { //外高度
- this[UIE || 0].offsetWidth + this.css("marginTop") + this.css("marginBottom");
- },
- replaceC: function (UDOD, UIE) { //元素顶替
- UIE = UIE || 0; var _UDPD, _UDTD = this[UIE];
- if (_UDTD) { _UDPD = this.Parent(1, UIE); (_UDPD) && (_UDPD.replaceChild(UDOD, _UDTD)); this[UIE] = UDOD; }; return this;
- },
- Center: function (ITF, UCB) { //元素居中
- var i = ITF || 0, _UL = ITF + 1 || this.length;
- for (; i < _UL; i++) { U.D.PopupWindow(this[i]); } //居中弹出
- (UCB) && (UCB()); return this;
- },
- html: function (UHT, UIE) { return UHT != null ? this.Aattr({ "innerHTML": UHT }, UIE) : this[UIE || 0].innerHTML; }, //获取innerhtml
- text: function (UHT, UIE) { return UHT != null ? this.Aattr({ "innerText": UHT }, UIE) : this[UIE || 0].innerText; }, //获取innerText
- GetElementInfo: function (ITF) { return U.M.GetElementInfo(this[ITF || 0]); }, //获取元素的大小和位置等等
- //和jquery一致,
- css: function (UDE, UVE, UIE) {//获取指定的css值
- if (UDE) {
- var i = UIE || 0, _UL = UIE + 1 || this.length, _UTF = (typeof UDE == "object");
- if (UVE != null || _UTF) {
- if (_UTF) { this.addAttrArray({ "style": UDE }, UVE); } //添加style
- else { for (i; i < _UL; i++) { UDE = U.M.CssTHH(UDE); this[i].style[UDE] = UVE; } } //循环添加class值
- }
- else { return U.M.GetStyle(this[i], UDE); } //获取css值
- }
- return this;
- },
- getBackgroundColor: function (UDE) { //获取设置背景图片
- if (U.Ut.isString(UDE)) { }
- else if (U.Ut.isArray(UDE)) { }
- },
- first: function () { //获取结果里的第一个元素
- return U.Select(this[0]);
- },
- last: function () { //获取最后一个元素
- return U.Select(this[this.length - 1]);
- },
- addClass: function (UCN, ITF) { //添加Class
- U.M.ARClass(this, ITF, UCN, "Add");
- return this;
- },
- removeClass: function (UCN, ITF) {//移除制定的class
- U.M.ARClass(this, ITF, UCN, "RE");
- return this;
- },
- hasClass: function (UCN, ITF) {//判断元素是否有制定的class
- return U.M.ARClass(this, ITF, UCN, "");
- },
- attr: function (USN, UV, UIE, UTP) { //添加属性
- var i, _UCE, _UTF = (typeof UDE == "object");
- if (!UV && _UTF) { //添加属性
- _UCE = USN; (!_UTF) && (_UCE = {}, _UCE[USN] = UV);
- for (i in _UCE) { (_UCE.hasOwnProperty(i)) && (U.M.SRAttr(this, USN, UV, UIE ? (UIE.length ? UIE : [UIE]) : null)); } //添加属性
- }
- else { return UTP ? this[UIE || 0][UTP].getAttribute(USN) : this[UIE || 0].getAttribute(USN); } //获取属性
- },
- rmAttr: function (USN, UIE, UTP) { //移除属性
- U.M.SRAttr(UIE != null ? [this[UIE]] : this, USN, null, UTP); //移除元素
- return this;
- },
- Aattr: function (UDE, UIE) { return this.addAttrArray(UDE, UIE); },
- addAttrArray: function (UDE, UIE) {//赋值区域
- var i, j, k, _UNE, _UTP, _UVE, _UAE, _UST, _UTE = this, i = UIE || 0, _UL = UIE + 1 || this.length, _UGE = { "class": "className", "html": "innerHTML", "text": "innerText", "float": "cssFloat" }, _UME = ["width,height,top,bottom,left,right", "px"];
- for (; (i < _UL && i < this.length); i++) {
- for (j in UDE) {
- if (UDE.hasOwnProperty(j)) {
- if (j == "style") { //style赋值
- _UVE = ""; _UAE = UDE[j];
- for (k in _UAE) { //添加cssText
- if (_UAE.hasOwnProperty(k)) {
- _UTP = U.M.CssTHH(k, true); _UNE = _UAE[k];
- if ((k in this[i][j]) && (_UTP == "css-text" || _UAE[k]) && this[i].cloneNode) {
- if (_UTP == "css-text") { _UVE = _UAE[k] + ";" + _UVE; } //cssText赋值
- else { (_UME[0].split(",").indexOf(_UTP, null, true) > -1 && U.Ut.isStringInt(_UNE)) && (_UNE += _UME[1]); _UVE += _UTP + ":" + _UNE + ";"; } //单个属性赋值
- continue;
- }
- this[i][j][U.M.CssTHH(k)] = _UAE[k] || "";
- }
- }
- (_UVE != null) && (this[i][j]["cssText"] += ";" + _UVE); //添加css值
- }
- else { //其它属性赋值
- if (j.indexOf("on") == 0 && "array,string".indexOf(U.M.GetType((_UVE = UDE[j]))) > -1) { ((_UVE = UDE[j]) && typeof _UVE[0] == "function") && (_UVE = [_UVE]); UDE[j] = U.M.apply(this[i], _UVE); } //事件特殊处理
- if (typeof (_UAE = this[i])[j] == "object" && typeof UDE[j] == "object") { U.Ut.AddObj(_UAE[j], UDE[j]); } //object赋值
- else { if (_UAE[j] !== UDE[j]) { _UST = _UAE[j]; k = _UGE[j] || j; if (U.Ut.isString((_UVE = UDE[j])) && U.M.Arrt(_UAE, k)) { try { _UAE.setAttribute(k, _UVE); } catch (e) { } } _UAE[k] = UDE[j]; } } //非原属性下的
- }
- }
- }
- }
- return this;
- },
- animate: function (UDE, USP, UCB, UIF, UGE) { //css3动画效果和js原始动画 动画排队
- if (UDE) {
- var i, j, k, _UTE, _UKW, _USE, _UE, _UDID, _UTID, _UME,
- _UL = UIF + 1 || this.length,
- _UDSD = $$("div").style,
- _UAE = [{ "style": {} }, "", {}],
- _UCE = ["width", "height", "top", "bottom", "left", "right"],
- _UBE = U.CI.getBrowser(), _UTF = _UBE.browser == "msie" && parseInt(_UBE["ver"]), _USD = { "fast": 300, "normal": 1000, "slow": 3000}[USP], _UAF = UDE["IES"]; delete UDE["IES"]; _USD = _USD || USP || 1000;
- for (i in UDE) { if (UDE.hasOwnProperty(i)) { if (_UDSD[(_UKW = U.M.CssTHH(i))] === undefined) { _UAE[0][i] = UDE[i]; } else { _UAE[0]["style"][_UKW] = UDE[i]; if (_UKW == "cssText") { _UAE[1] += UDE[i] + ";"; } else { _UAE[1] += (_UKW = U.M.CssTHH(i, true)) + ":" + UDE[i] + ";"; for (j = 0; j < _UCE.length; j++) { if (_UCE[j] == i || _UKW.indexOf(_UCE[j]) > -1) { _UAE[2][_UKW] = ""; break; } } } } } } //设置css3动画和js动画
- for (i = (UIF || 0); i < _UL; i++) { _USE = ""; for (j in _UAE[2]) { if (UDE.hasOwnProperty(j)) { j += j.indexOf("padding") > -1 ? "-width" : ""; _UE = this.css(j, null, i); _UE = isNaN(_UE.toInt()) ? ((this[j] ? this[j](i) : 0) + "px") : _UE; _USE += j + ":" + _UE + ";"; } }; (_USE) && (this.addAttrArray({ "style": { "cssText": _USE} }, i)); } //设置初始值
- if (_UTF && _UTF < 10 && _UAF == null) { this.addAttrArray(_UAE[0], UIF); (U.Ut.isFunction(UCB)) && (UCB()); } //Ie8不动画 (UCB) && (setTimeout(UCB, 0));
- else { //IE9以上动画渲染
- if (((!_UTF || _UTF > 9) && (_UAE[1] || _UAE[0].className))) { //css3动画加速
- _USE = U.M.GCssAe();
- _UDID = "UEM" + Guid.guidNoDash();
- _UE = _USE[0] + ":all " + (_USD / 1000) + "s linear;";
- if (UGE) {
- for (i in UGE) { _UE += _USE[0] + "-" + i + ":" + UGE[i] + ";"; }
- }
- _UE = "." + _UDID + " {" + _UE + "}"; //设置动画属性
- this.bind(_USE[1], (_UTE = U.M.apply(this, function () {
- this.unbind(_USE[1], _UTE);
- U.M.AsynCssEM.apply(this, [_UDID, _UDSD, UCB, UIF]);
- }))); //添加动画
- _UDSD = U.M.CCssStyle(_UE);
- U.Select.IsAnimate(this, UIF, _UDID);
- this.addClass(_UDID, UIF);
- (_UAE[0].className) && (this.addClass(_UAE[0].className, UIF), delete _UAE[0].className);
- this.addAttrArray(_UAE[0], UIF); delete _UAE[0].className; delete _UAE[0].style; //移除设置回调
- }
- for (i in _UAE[0]) {
- if (_UAE[0].hasOwnProperty(i)) { //非css动画或者IE8动画
- _UME = U.M.Animation({ "cb": U.M.apply(this, [[this.Auxiliary.animate, [[UIF, _UL, _UTID, _USE ? null : UCB], _UAE[0]]]]), "ti": _USD }); //动画加速
- U.Select.IsAnimate(this, UIF, _UME);
- break;
- }
- }
- }
- }
- return this;
- },
- stop: function (UIE) { //停止动画回播
- var _USE, i = UIE || 0,
- _UL = UIE == null ? this.length : UIE + 1;
- for (; i < _UL; i++) {
- if ((_USE = this[i].__Animate__)) {
- if (U.Ut.isString(_USE[2])) {
- this[i].className = _USE[2];
- this.addClass(_USE[1], i);
- this.css("cssText", _USE[0], i);
- }
- else {
- _USE[2].stop();
- }
- }
- }
- },
- opacity: function (UVE, UIE) { //设置透明度 全兼容
- if (this.length) {
- var i, _USE = {}, _UDE = { opacity: 1, "-webkit-opacity": 1, "-moz-opacity": 1, "-khtml-opacity": "", filter: "" };
- for (i in _UDE) { if (i in this[0].style) { _USE[i] = (_UDE[i] = i == "filter" ? "alpha(opacity=" + (UVE * 100) + ")" : UVE); } }
- }
- },
- fadeIn: function (USP, UCB, UIE) {//动画淡出,,
- var i, _UKE, _USE = {}, _UDOD = $$("div").style, _UDE = ["opacity", "-webkit-opacity", "-moz-opacity", "-khtml-opacity", "filter"]; UCB = U.M.apply(this, [[this.addAttrArray, [{ "style": (_UKE = { "display": "none" }) }, UIE]], [UCB]]); //设置回调
- for (i = 0; i < _UDE.length; i++) { if (_UDE[i] in _UDOD) { _UKE[_UDE[i]] = ""; _USE[_UDE[i]] = _UDE[i] == "filter" ? "alpha(opacity=0)" : "0"; break; } }; return this.animate(_USE, USP || "fast", UCB, UIE); //查看
- },
- fadeOut: function (USP, UCB, UIE) {//动画淡入
- var i, _USE = {}, _UDOD = $$("div").style, _UDE = ["opacity", "-webkit-opacity", "-moz-opacity", "-khtml-opacity", "filter"]; for (i = 0; i < _UDE.length; i++) { if (_UDE[i] in _UDOD) { _USE[_UDE[i]] = _UDE[i] == "filter" ? "alpha(opacity=100)" : "1"; _UDE = _UDE[i]; break; } };
- _USE[_UDE] = _UDE == "filter" ? "alpha(opacity=100)" : "1"; this.addAttrArray({ "style": { "display": "block"} }); return this.animate(_USE, USP || "fast", UCB, UIE); //查看 _USE
- },
- slideUp: function (USP, UCB, UIE) { //滑动消失
- this.slideToggle(USP, UCB, UIE);
- },
- slideDown: function (USP, UCB, UIE) { //滑动出现
- this.slideToggle(USP, UCB, UIE, false);
- },
- transition: function (UDE, USP, UCB, UIE) { //过度动画使用
- var i, j, _UDW, _UTP, _UFN, _UAE = {}, _UHE = {}, _UME = [["scale", ""], ["translate,perspective", "px"], ["skew,rotate", "deg"]], _UCE = U.M.GCssAe(); //scale
- if (_UCE) {//Html5兼容
- _UTP = _UCE[2] + "transform"; _UAE[_UTP] = "";
- _UFN: for (i in UDE) {
- for (j = 0; j < _UME.length; j++) { if (_UME[j][0].split(",").indexOf(i) > -1) { _UDW = _UME[j][1]; _UAE[_UTP] += i + "(" + UDE[i] + _UDW + ") "; continue _UFN; } }
- _UHE[_UTP + "-" + i] = UDE[i];
- }
- this.addAttrArray({ "style": _UHE }).animate(_UAE, USP, UCB, UIE); //执行动画
- }
- },
- slideToggle: function (UST, UCB, UIE, UTF) {//滑动效果
- var j, _UTP, _UDE, _USC, i = UIE || 0, _UL = UIE + 1 || this.length, _USE = { height: "", marginBottom: "", marginTop: "", paddingBottom: "", paddingTop: "", display: "block" }, _UKE = _USE; //变化值
- for (; i < _UL; i++) { //设置动画
- _USC = this.css("cssText"); _$(_USE).Each(U.M.apply(this, function (UAE, UIE) { if (UIE != "display") { if (UIE == "height") { _USE[UIE] = this.height() + "px"; } else { _USE[UIE] = this.css(UIE, null, i); } } })); //原初始值
- _UDE = [_USE, { "cssText": "height:0px;margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;display:block;overflow:hidden"}]; //初始化隐藏动画
- if ((_UTP = (UTF === false || (UTF == null && this.css("display", "") == "none")))) { _UDE.reverse(); } //设置显示动画
- this.addAttrArray({ style: _UDE[0] }, i).animate(_UDE[1], UST, U.M.apply(this, [[this.Auxiliary.slideToggle, [_USC + ";display:" + (_UTP ? "block" : "none"), i, _UL, UCB]]]), i); //设置出现和取消
- }
- },
- hide: function (UIE) { //隐藏元素
- this.css({ "display": "none" }, UIE);
- },
- show: function (UIE) { //显示元素
- this.css({ "display": "block" }, UIE);
- },
- ready: function (UCB) { //添加doc ready函数
- var _UTF = document.attachEvent ? "readystatechange" : "DOMContentLoaded", _UCB = [];
- _UCB[0] = U.M.apply(document, [[U.M.ReEvent, [_UTF, document, _UCB]], [UCB]]); U.M.AddEvent(_UTF, document, _UCB[0]);
- },
- load: function (UCB) { //load加载页面
- (!this.length) && (this.osadd(window)); var _UFN = function () { this.unbind("load", _UFN, 0); UCB(); };
- this.bind("load", _UFN, 0);
- },
- contents: function () { },
- mouseenter: function (UCB, UIE) { //enter事件
- this.addAttrArray({ "onmouseover": [[U.M.mouseLE, [UCB]]] }, UIE);
- return this;
- },
- mouseleave: function (UCB, UIE) { //leave事件
- this.addAttrArray({ "onmouseout": [[U.M.mouseLE, [UCB]]] }, UIE);
- return this;
- },
- resize: function (UCB, UIE) { //resize事件
- this.bind("resize", U.M.resize(UCB), UIE);
- },
- resizestart: function (UCB, UIE) { //resoze开始
- this.resize({ s: UCB }, UIE);
- },
- resizeend: function (UCB, UIE) { //设置sizeend
- this.resize({ e: UCB }, UIE);
- },
- message: function () { //message 事件绑定
- },
- //此bind和系统bind有什么区别?系统bind可以实现:var foo = { x: 3} var bar = function(){ console.log(this.x);} bar(); // undefined var boundFunc = bar.bind(foo);boundFunc(); // 3 但系统bind不支持ie8以下。
- bind: function (UDE, UAE, UIE) { //事件绑定
- if (UDE) {
- var j, _UTP;
- var _UTF = (typeof UDE == "string");
- var _UIF = (_UTF ? UIE : UAE), i = _UIF || 0, _UL = (_UIF + 1) || this.length;
- (_UTF) && (_UTP = UDE, (UDE = {})[_UTP] = UAE);
- for (; i < _UL; i++) {
- for (j in UDE) {
- if (UDE.hasOwnProperty(j)) {
- new this.cacheE(this[i]).addevent(j, UDE[j]);
- U.M.AddEvent(j, this[i], UDE[j]);
- }
- }
- }
- return this;
- }
- },
- unbind: function (UDE, UAE, UIE) { //事件绑定取消
- var _UTF = (typeof UDE == "string"), _UIF = (_UTF ? UIE : UAE), i = _UIF || 0, _UL = (_UIF + 1) || this.length;
- for (; i < _UL; i++) { new this.cacheE(this[i]).removeEvent(UDE, UAE); } return this; //移除事件
- },
- mousedown: function (UCB, UTF, UIE) { //左右事件
- (UCB) && (this.bind("mousedown", function () { var _UTF = event.button; _UTF = _UTF == 2 || _UTF == 3; if (!UTF || (UTF == "right" && _UTF) || (UTF == "left" && !_UTF)) { UCB(); } }, UIE));
- return this;
- },
- on: function (UE, US, UCB, UIE) { //事件绑定
- var _UDE = this; (US) && (_UDE = this.find(US, UIE)); _UDE.bind(UE, UCB, UIE);
- },
- off: function (UE, US, UCB, UIE) { //取消事件绑定
- var _UDE = this; (US) && (_UDE = this.find(US, UIE)); _UDE.unbind(UE, UCB, UIE);
- },
- scrollTo: function (UT, UTI) {//移动变化
- var _UDOD = this[0]; (_UDOD) && (U.M.SCT(UT, _UDOD, UTI));
- }
- });
- //#region 事件监听区域
- U.Select.fn.extend({
- cache: [], //保存对象使用选择器保留值
- cacheE: function (UDOD) {//保存对象的值
- var i, _UDE = U.Select.fn.cache;
- for (i = 0; i < _UDE.length; i++) { if (_UDE[i].UDOD === UDOD) { return _UDE[i]; } } //获取制定的元素绑定
- this.events = {}; this.UDOD = UDOD; this.id = Guid.guidNoDash(); _UDE.push(this); return this; //添加事件监听对象
- }
- });
- U.Select.fn.cacheE.prototype = {
- removeEvent: function (UDE, UAE) { //删除event
- var i, j, _UME, _UDOD = this.UDOD, _UCE = this.events; (typeof UDE == "string") && (_UME = UDE, (UDE = {})[_UME] = UAE); UDE = UDE || _UCE;
- for (i in UDE) { if (UDE.hasOwnProperty(i) && (_UME = _UCE[i])) { for (j = 0; j < _UME.length; j++) { if (_UME[j] == UDE[i] || _UCE == UDE || !UDE[i]) { U.M.ReEvent(i, _UDOD, _UME.splice(j, 1)[0]); j--; } } } } //清除事件
- },
- addevent: function (UDE, UAE) { //添加event监听
- var i, _UCE = this.events;
- (!_UCE[UDE]) && (_UCE[UDE] = []); _UCE[UDE].push(UAE);
- }
- }
- //#endregion
- //#region 辅助函数
- U.Select.fn.extend({
- selecte: {
- "only-child": function (UDE) { //获取作为单一孩子节点元素
- return Array.prototype.slice.call(U.Select(UDE).only());
- },
- "nth-child": function (UDE, UTP) { //获取第几个元素
- var i, j, _UCE, _UN = UTP.match(this.match.number)[1], _UTF = _UN.indexOf("n") > -1, _UAE = []; _UN = _UN.toInt();
- if (!_UTF || _UN) {
- for (i = 0; i < UDE.length; i++) {
- _UCE = U.Select(UDE[i]).parentg().Child();
- if (_UTF) { for (j = _UN; j <= _UCE.length; j += _UN) { if (UDE[i] == _UCE[j - 1]) { _UAE.push(UDE[i]); (_UN == 1) && (j++); break; } } } //(xn)查找
- else { (_UCE[_UN - 1] == UDE[i]) && (_UAE.push(UDE[i])); } //直接获取第几个
- }
- }
- return _UAE;
- },
- "first-child": function (UDE) { //获取开头元素
- var i, _UAE = [];
- for (i = 0; i < UDE.length; i++) { (!U.Select(UDE[i]).prev().lenght) && (_UAE.push(UDE[i])); }
- return _UAE;
- },
- "last-child": function (UDE) { //获取末尾元素
- var i, _UAE = [];
- for (i = 0; i < UDE.length; i++) { (!U.Select(UDE[i]).next().length) && (_UAE.push(UDE[i])); }
- return _UAE;
- },
- first: function (UDE) { //获取第一个匹配的元素
- return UDE.length ? UDE[0] : UDE;
- },
- last: function (UDE) { //获取最后一个匹配元素
- return UDE.length ? UDE[UDE.length - 1] : UDE;
- },
- nth: function (UDE, UTP) { //获取匹配的第几个元素
- var i, _UAE = [], _UN = UTP.match(this.match.number)[1], _UTF = _UN.indexOf("n") > -1; _UN = _UN.toInt();
- if (_UTF || _UN) {
- if (_UTF) { for (i = _UN; i <= UDE.length; i += _UN) { _UAE.push(UDE[i - 1]); } }
- else { (UDE[_UN]) && (_UAE.push(UDE[_UN])); }
- }
- return _UAE;
- },
- getevenodd: function (UDE, UTP) { //获取奇数和偶数集
- var i, j, _UDPD, _UCE, _UTF, _UPE = [], _UAE = [];
- for (i = 0; i < UDE.length; i++) {
- _UCE = null; _UDPD = UDE[i].parentNode;
- for (j = 0; j < _UPE.length; j++) { if (_UPE[j][0] == _UDPD) { _UCE = _UPE[j]; _UCE[1].push(UDE[i]); } }
- (!_UCE) && (_UPE.push((_UCE = [_UDPD, [UDE[i]]]))); _UTF = (_UCE[1].length - 1) % 2; ((UTP == "even" && !_UTF) || (UTP == "odd" && _UTF)) && (_UAE.push(UDE[i]));
- }
- return _UAE;
- },
- even: function (UDE) { //获取偶数集
- return this.selecte.getevenodd(UDE, "even");
- },
- odd: function (UDE) { //获取奇数集
- return this.selecte.getevenodd(UDE, "odd");
- },
- eq: function (UDE, UTP) { //获取制定的位置列
- return UDE[UTP.match(this.match.number)[1].toInt()];
- },
- gt: function (UDE, UTP) { //索引大于的元素
- U.Select(UDE).gt(UTP.match(this.match.number)[1].toInt());
- },
- lt: function (UDE, UTP) {//索引小于的元素
- U.Select(UDE).lt(UTP.match(this.match.number)[1].toInt());
- },
- "first-of-type": function () { },
- "last-of-type": function () { },
- "only-of-type": function () { },
- "nth-last-child": function () { },
- "nth-of-type": function () { },
- "nth-last-of-type": function () { }
- },
- Auxiliary: {
- an: function (UDE) { //缓存对象设置
- },
- slideToggle: function (UDE, UIE, UL, UCB) { //下拉动画回调
- this[UIE].style.cssText = UDE; (UIE == UL - 1 && UCB) && (UCB());
- },
- animate: function (UDE, UAE, UIE) {//js动画调用使用区域
- var _UTF, _USE, i = UDE[0] || 0,
- _UL = UDE[1] || i + 1,
- _UTID = UDE[2],
- _UCB = UDE[3];
- for (; i < _UL; i++) {
- if (UIE) { _USE = U.M.JsEM(this[i], UAE, UIE); }
- else { _USE = UAE; _UTF = true; } this.addAttrArray(_USE, i);
- }
- if (_UTF) {
- (_UTID == null && _UCB) && (_UCB()); return true;
- }
- },
- selectel: function (UTF, UDE) { //条件选择元素
- var _UFT, i = 0, _UL = UDE.length, _UCE = [], _UAE = U.Select(), _UIE = UTF.match(U.MS.RNum);
- if (_UIE) { _UIE = _UIE[0].toInt(); switch (UTF.replace(_UIE + "", "")) { case ">": i = _UIE + 1; break; case "<": _UL = _UIE; break; default: i = _UIE; _UL = i + 1; break; } }
- for (; i < _UL; i++) { switch (UTF) { case "even": _UFT = !(i % 2); break; case "odd": _UFT = (i % 2) > 0; break; default: _UFT = true; break; } (_UFT) && (_UCE.push(UDE[i])); _UFT = false; }
- return _UAE.osadd(_UCE);
- }
- }
- });
- //简单的复杂的方法统一
- $.SetMethod.prototype = U.Select.prototype;
- //#endregion
- //#endregion
|