免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1485 | 回复: 1
打印 上一主题 下一主题

jQ.Mobi源代码 2。。。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-03 17:41 |只看该作者 |倒序浏览
jQ.Mobi源代码 2。。。。
  1. 351.                return this;   
  2. 352.            },   
  3. 353.            attr: function(attr, value) {   
  4. 354.                if (this.length === 0)   
  5. 355.                    return undefined;   
  6. 356.                if (value === undefined && !$.isObject(attr)) {   
  7. 357.                    var val = this[0].getAttribute(attr);   
  8. 358.                       
  9. 359.                    try {   
  10. 360.                        val = JSON.parse(val);   
  11. 361.                    } catch (e) {   
  12. 362.                    }   
  13. 363.                    return val;   
  14. 364.                }   
  15. 365.                value = $.isArray(value) || $.isObject(value) ? JSON.stringify(value) : value;   
  16. 366.                for (var i = 0; i < this.length; i++) {   
  17. 367.                    if ($.isObject(attr)) {   
  18. 368.                        for (var key in attr)   
  19. 369.                        {   
  20. 370.                            if (value == null && value !== undefined)   
  21. 371.                                this[i].removeAttribute(key);   
  22. 372.                            else  
  23. 373.                                this[i].setAttribute(key, attr[key]);   
  24. 374.                        }   
  25. 375.                    }   
  26. 376.                    else   
  27. 377.                    if (value == null && value !== undefined)   
  28. 378.                        this[i].removeAttribute(attr);   
  29. 379.                    else  
  30. 380.                        this[i].setAttribute(attr, value);   
  31. 381.                }   
  32. 382.                return this;   
  33. 383.            },   
  34. 384.            removeAttr: function(attr) {   
  35. 385.                var that = this;   
  36. 386.                for (var i = 0; i < this.length; i++) {   
  37. 387.                    attr.split(/\s+/g).forEach(function(param) {   
  38. 388.                        that[i].removeAttribute(param);   
  39. 389.                    });   
  40. 390.                }   
  41. 391.                return this;   
  42. 392.            },   
  43. 393.            remove: function(selector) {   
  44. 394.                var elems = $(this).filter(selector);   
  45. 395.                for (var i = 0; i < elems.length; i++) {   
  46. 396.                    elems[i].parentNode.removeChild(elems[i]);   
  47. 397.                }   
  48. 398.                return elems;   
  49. 399.            },   
  50. 400.            addClass: function(name) {   
  51. 401.                for (var i = 0; i < this.length; i++) {   
  52. 402.                    var cls = this[i].className;   
  53. 403.                    var classList = [];   
  54. 404.                    var that = this;   
  55. 405.                    name.split(/\s+/g).forEach(function(cname) {   
  56. 406.                        if (!that.hasClass(cname, that[i]))   
  57. 407.                            classList.push(cname);   
  58. 408.                    });   
  59. 409.                       
  60. 410.                    this[i].className += (cls ? " " : "") + classList.join(" ");   
  61. 411.                    this[i].className = this[i].className.trim();   
  62. 412.                }   
  63. 413.                return this;   
  64. 414.            },   
  65. 415.            removeClass: function(name) {   
  66. 416.                for (var i = 0; i < this.length; i++) {   
  67. 417.                    if (name == undefined) {   
  68. 418.                        this[i].className = '';   
  69. 419.                        return this;   
  70. 420.                    }   
  71. 421.                    var classList = this[i].className;   
  72. 422.                    name.split(/\s+/g).forEach(function(cname) {   
  73. 423.                        classList = classList.replace(classRE(cname), "");   
  74. 424.                    });   
  75. 425.                    if (classList.length > 0)   
  76. 426.                        this[i].className = classList.trim();   
  77. 427.                    else  
  78. 428.                        this[i].className = "";   
  79. 429.                }   
  80. 430.                return this;   
  81. 431.            },   
  82. 432.            hasClass: function(name, element) {   
  83. 433.                if (this.length === 0)   
  84. 434.                    return false;   
  85. 435.                if (!element)   
  86. 436.                    element = this[0];   
  87. 437.                return classRE(name).test(element.className);   
  88. 438.            },   
  89. 439.            bind: function(event, callback) {   
  90. 440.                if (event === "" || event == undefined)   
  91. 441.                    return;   
  92. 442.                for (var i = 0; i < this.length; i++) {   
  93. 443.                    (function(obj) {   
  94. 444.                           
  95. 445.                        var id = obj._eventID ? obj._eventID : _eventID++;   
  96. 446.                        obj._eventID = id;   
  97. 447.                        var that = obj;   
  98. 448.                        event.split(/\s+/g).forEach(function(name) {   
  99. 449.                            var prxFn = function(event) {   
  100. 450.                                event.originalEvent = event; //for backwards compatibility with jQuery...leh sigh   
  101. 451.                                var result = callback.call(that, event);   
  102. 452.                                if (result === false)   
  103. 453.                                    event.preventDefault();   
  104. 454.                                return result;   
  105. 455.                            };   
  106. 456.                            eventHandlers[id + "_" + name] = prxFn;   
  107. 457.                            obj.addEventListener(name, prxFn, false);   
  108. 458.                        });   
  109. 459.                    })(this[i]);   
  110. 460.                  
  111. 461.                }   
  112. 462.                return this;   
  113. 463.            },   
  114. 464.            unbind: function(event) {   
  115. 465.                if (event === "" || event == undefined)   
  116. 466.                    return;   
  117. 467.                for (var i = 0; i < this.length; i++) {   
  118. 468.                    (function(obj) {   
  119. 469.                        var id = obj._eventID;   
  120. 470.                        var that = obj;   
  121. 471.                        event.split(/\s+/g).forEach(function(name) {   
  122. 472.                            if (eventHandlers[id + "_" + name]) {   
  123. 473.                                var prxFn = eventHandlers[id + "_" + name];   
  124. 474.                                delete eventHandlers[id + "_" + name];   
  125. 475.                                that.removeEventListener(name, prxFn, false);   
  126. 476.                            }   
  127. 477.                        });   
  128. 478.                    })(this[i]);   
  129. 479.                }   
  130. 480.                  
  131. 481.                return this;   
  132. 482.            },   
  133. 483.            trigger: function(event, data) {   
  134. 484.                if (this.length === 0)   
  135. 485.                    return this;   
  136. 486.                if (typeof (event) === "string") {   
  137. 487.                    var evtName = event;   
  138. 488.                    var newEvent = document.createEvent("Event");   
  139. 489.                    newEvent.type = evtName;   
  140. 490.                    newEvent.target = this[0];   
  141. 491.                    newEvent.initEvent(evtName, false, true);   
  142. 492.                }   
  143. 493.                else  
  144. 494.                    var newEvent = event;   
  145. 495.                newEvent.data = data;   
  146. 496.                this[0].dispatchEvent(newEvent);   
  147. 497.                return this;   
  148. 498.            },   
  149. 499.            append: function(element, insert) {   
  150. 500.                if (element && element.length != undefined && element.length === 0)   
  151. 501.                    return this;   
  152. 502.                if ($.isArray(element) || $.isObject(element))   
  153. 503.                    element = $(element);   
  154. 504.                var i;   
  155. 505.                  
  156. 506.                for (i = 0; i < this.length; i++) {   
  157. 507.                    if (element.length && typeof element != "string") {   
  158. 508.                        element = $(element);   
  159. 509.                        for (var j = 0; j < element.length; j++)   
  160. 510.                            insert != undefined ? this[i].insertBefore(element[j], this[i].firstChild) : this[i].appendChild(element[j]);   
  161. 511.                    }   
  162. 512.                    else {   
  163. 513.                        var obj = $(element).get();   
  164. 514.                           
  165. 515.                        if (obj == undefined || obj.length == 0) {   
  166. 516.                            obj = document.createTextNode(element);   
  167. 517.                        }   
  168. 518.                        if (obj.nodeName != undefined && obj.nodeName.toLowerCase() == "script" && (!obj.type || obj.type.toLowerCase() === 'text/javascript')) {   
  169. 519.                            window.eval(obj.innerHTML);   
  170. 520.                        }   
  171. 521.                           
  172. 522.                        else  
  173. 523.                            insert != undefined ? this[i].insertBefore(obj, this[i].firstChild) : this[i].appendChild(obj);   
  174. 524.                    }   
  175. 525.                }   
  176. 526.                return this;   
  177. 527.            },   
  178. 528.            prepend: function(element) {   
  179. 529.                return this.append(element, 1);   
  180. 530.            },   
  181. 531.            get: function(index) {   
  182. 532.                index = index == undefined ? 0 : index;   
  183. 533.                if (index < 0)   
  184. 534.                    index += this.length;   
  185. 535.                return (this[index]) ? this[index] : undefined;   
  186. 536.            },   
  187. 537.            offset: function() {   
  188. 538.                if (this.length === 0)   
  189. 539.                    return undefined;   
  190. 540.                var obj = this[0].getBoundingClientRect();   
  191. 541.                return {   
  192. 542.                    left: obj.left + window.pageXOffset,   
  193. 543.                    top: obj.top + window.pageYOffset,   
  194. 544.                    width: parseInt(this[0].style.width),   
  195. 545.                    height: parseInt(this[0].style.height)   
  196. 546.                };   
  197. 547.            },   
  198. 548.            parent: function(selector) {   
  199. 549.                if (this.length == 0)   
  200. 550.                    return undefined;   
  201. 551.                var elems = [];   
  202. 552.                for (var i = 0; i < this.length; i++)   
  203. 553.                {   
  204. 554.                    if (this[i].parentNode)   
  205. 555.                        elems.push(this[i].parentNode);   
  206. 556.                }   
  207. 557.                return this.setupOld($(unique(elems)).filter(selector));   
  208. 558.            },   
  209. 559.            children: function(selector) {   
  210. 560.                  
  211. 561.                if (this.length == 0)   
  212. 562.                    return undefined;   
  213. 563.                var elems = [];   
  214. 564.                for (var i = 0; i < this.length; i++)   
  215. 565.                {   
  216. 566.                    elems = elems.concat(siblings(this[i].firstChild));   
  217. 567.                }   
  218. 568.                return this.setupOld($((elems)).filter(selector));   
  219. 569.               
  220. 570.            },   
  221. 571.            siblings: function(selector) {   
  222. 572.                if (this.length == 0)   
  223. 573.                    return undefined;   
  224. 574.                var elems = [];   
  225. 575.                for (var i = 0; i < this.length; i++)   
  226. 576.                {   
  227. 577.                    if (this[i].parentNode)   
  228. 578.                        elems = elems.concat(siblings(this[i].parentNode.firstChild, this[i]));   
  229. 579.                }   
  230. 580.                return this.setupOld($(elems).filter(selector));   
  231. 581.            },   
  232. 582.            closest: function(selector, context) {   
  233. 583.                if (this.length == 0)   
  234. 584.                    return undefined;   
  235. 585.                var elems = [], cur = this[0];   
  236. 586.                  
  237. 587.                var start = $(selector, context);   
  238. 588.                if (start.length == 0)   
  239. 589.                    return $();   
  240. 590.                while (cur && start.indexOf(cur) == -1) {   
  241. 591.                    cur = cur !== context && cur !== document && cur.parentNode;   
  242. 592.                }   
  243. 593.                return $(cur);   
  244. 594.               
  245. 595.            },   
  246. 596.            filter: function(selector)   
  247. 597.            {   
  248. 598.                if (this.length == 0)   
  249. 599.                    return undefined;   
  250. 600.                  
  251. 601.                if (selector == undefined)   
  252. 602.                    return this;   
  253. 603.                var elems = [];   
  254. 604.                for (var i = 0; i < this.length; i++) {   
  255. 605.                    var val = this[i];   
  256. 606.                    if (val.parentNode && $(selector, val.parentNode).indexOf(val) >= 0)   
  257. 607.                        elems.push(val);   
  258. 608.                }   
  259. 609.                return this.setupOld($(unique(elems)));   
  260. 610.            },   
  261. 611.            not: function(selector) {   
  262. 612.                if (this.length == 0)   
  263. 613.                    return undefined;   
  264. 614.                var elems = [];   
  265. 615.                for (var i = 0; i < this.length; i++) {   
  266. 616.                    var val = this[i];   
  267. 617.                    if (val.parentNode && $(selector, val.parentNode).indexOf(val) == -1)   
  268. 618.                        elems.push(val);   
  269. 619.                }   
  270. 620.                return this.setupOld($(unique(elems)));   
  271. 621.            },   
  272. 622.            data: function(key, value) {   
  273. 623.                return this.attr('data-' + key, value);   
  274. 624.            },   
  275. 625.            end: function() {   
  276. 626.                return this.oldElement != undefined ? this.oldElement : $();   
  277. 627.            },   
  278. 628.            clone: function(deep) {   
  279. 629.                deep = deep === false ? false : true;   
  280. 630.                if (this.length == 0)   
  281. 631.                    return undefined;   
  282. 632.                var elems = [];   
  283. 633.                for (var i = 0; i < this.length; i++)   
  284. 634.                {   
  285. 635.                    elems.push(this[i].cloneNode(deep));   
  286. 636.                }   
  287. 637.                  
  288. 638.                return $(elems);   
  289. 639.            },   
  290. 640.            size: function() {   
  291. 641.                return this.length;   
  292. 642.            }   
  293. 643.           
  294. 644.        };   
  295. 645.  
  296. 646.  
  297. 647.        /* AJAX functions */  
  298. 648.           
  299. 649.        function empty() {   
  300. 650.        }   
  301. 651.        var ajaxSettings = {   
  302. 652.            type: 'GET',   
  303. 653.            beforeSend: empty,   
  304. 654.            success: empty,   
  305. 655.            error: empty,   
  306. 656.            complete: empty,   
  307. 657.            context: undefined,   
  308. 658.            timeout: 0   
  309. 659.        };   
  310. 660.           
  311. 661.        $.jsonP = function(options) {   
  312. 662.            var callbackName = 'jsonp_callback' + (++_jsonPID);   
  313. 663.            var abortTimeout = "",   
  314. 664.            context;   
  315. 665.            var script = document.createElement("script");   
  316. 666.            var abort = function() {   
  317. 667.                $(script).remove();   
  318. 668.                if (window[callbackName])   
  319. 669.                    window[callbackName] = empty;   
  320. 670.            };   
  321. 671.            window[callbackName] = function(data) {   
  322. 672.                clearTimeout(abortTimeout);   
  323. 673.                $(script).remove();   
  324. 674.                delete window[callbackName];   
  325. 675.                options.success.call(context, data);   
  326. 676.            };   
  327. 677.            script.src = options.url.replace(/=\?/, '=' + callbackName);   
  328. 678.            $('head').append(script);   
  329. 679.            if (options.timeout > 0)   
  330. 680.                abortTimeout = setTimeout(function() {   
  331. 681.                    options.error.call(context, "", 'timeout');   
  332. 682.                }, options.timeout);   
  333. 683.            return {};   
  334. 684.        };   
  335. 685.           
  336. 686.        $.ajax = function(opts) {   
  337. 687.            var xhr;   
  338. 688.            try {   
  339. 689.                xhr = new window.XMLHttpRequest();   
  340. 690.                var settings = opts || {};   
  341. 691.                for (var key in ajaxSettings) {   
  342. 692.                    if (!settings[key])   
  343. 693.                        settings[key] = ajaxSettings[key];   
  344. 694.                }   
  345. 695.                  
  346. 696.                if (!settings.url)   
  347. 697.                    settings.url = window.location;   
  348. 698.                if (!settings.contentType)   
  349. 699.                    settings.contentType = "application/x-www-form-urlencoded";   
  350. 700.                if (!settings.headers)   
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-02-03 17:41 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP