ender.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /*!
  2. * Ender-JS: open module JavaScript framework (client-lib)
  3. * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat)
  4. * https://ender.no.de
  5. * License MIT
  6. * Build: ender -b qwery bonzo
  7. */
  8. !function (context) {
  9. // Implements simple module system
  10. // losely based on CommonJS Modules spec v1.1.1
  11. // ============================================
  12. var modules = {};
  13. function require (identifier) {
  14. var module = modules[identifier] || window[identifier];
  15. if (!module) throw new Error("Requested module has not been defined.");
  16. return module;
  17. }
  18. function provide (name, what) {
  19. return modules[name] = what;
  20. }
  21. context['provide'] = provide;
  22. context['require'] = require;
  23. // Implements Ender's $ global access object
  24. // =========================================
  25. function aug(o, o2) {
  26. for (var k in o2) {
  27. k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]);
  28. }
  29. return o;
  30. }
  31. function boosh(s, r, els) {
  32. // string || node || nodelist || window
  33. if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) {
  34. els = ender._select(s, r);
  35. els.selector = s;
  36. } else {
  37. els = isFinite(s.length) ? s : [s];
  38. }
  39. return aug(els, boosh);
  40. }
  41. function ender(s, r) {
  42. return boosh(s, r);
  43. }
  44. aug(ender, {
  45. _VERSION: '0.2.5',
  46. ender: function (o, chain) {
  47. aug(chain ? boosh : ender, o);
  48. },
  49. fn: context.$ && context.$.fn || {} // for easy compat to jQuery plugins
  50. });
  51. aug(boosh, {
  52. forEach: function (fn, scope, i) {
  53. // opt out of native forEach so we can intentionally call our own scope
  54. // defaulting to the current item and be able to return self
  55. for (i = 0, l = this.length; i < l; ++i) {
  56. i in this && fn.call(scope || this[i], this[i], i, this);
  57. }
  58. // return self for chaining
  59. return this;
  60. },
  61. $: ender // handy reference to self
  62. });
  63. var old = context.$;
  64. ender.noConflict = function () {
  65. context.$ = old;
  66. return this;
  67. };
  68. (typeof module !== 'undefined') && module.exports && (module.exports = ender);
  69. // use subscript notation as extern for Closure compilation
  70. context['ender'] = context['$'] = ender;
  71. }(this);
  72. /*!
  73. * Qwery - A Blazing Fast query selector engine
  74. * https://github.com/ded/qwery
  75. * copyright Dustin Diaz & Jacob Thornton 2011
  76. * MIT License
  77. */
  78. !function (context, doc) {
  79. var c, i, j, k, l, m, o, p, r, v,
  80. el, node, len, found, classes, item, items, token,
  81. html = doc.documentElement,
  82. id = /#([\w\-]+)/,
  83. clas = /\.[\w\-]+/g,
  84. idOnly = /^#([\w\-]+$)/,
  85. classOnly = /^\.([\w\-]+)$/,
  86. tagOnly = /^([\w\-]+)$/,
  87. tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/,
  88. normalizr = /\s*([\s\+\~>])\s*/g,
  89. splitters = /[\s\>\+\~]/,
  90. splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\])/,
  91. dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g'),
  92. tokenizr = new RegExp(splitters.source + splittersMore.source),
  93. specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g,
  94. simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,
  95. attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,
  96. pseudo = /:([\w\-]+)(\(['"]?(\w+)['"]?\))?/,
  97. chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?'),
  98. walker = {
  99. ' ': function (node) {
  100. return node && node !== html && node.parentNode
  101. },
  102. '>': function (node, contestant) {
  103. return node && node.parentNode == contestant.parentNode && node.parentNode;
  104. },
  105. '~': function (node) {
  106. return node && node.previousSibling;
  107. },
  108. '+': function (node, contestant, p1, p2) {
  109. if (!node) {
  110. return false;
  111. }
  112. p1 = previous(node);
  113. p2 = previous(contestant);
  114. return p1 && p2 && p1 == p2 && p1;
  115. }
  116. };
  117. function cache() {
  118. this.c = {};
  119. }
  120. cache.prototype = {
  121. g: function (k) {
  122. return this.c[k] || undefined;
  123. },
  124. s: function (k, v) {
  125. this.c[k] = v;
  126. return v;
  127. }
  128. };
  129. var classCache = new cache(),
  130. cleanCache = new cache(),
  131. attrCache = new cache(),
  132. tokenCache = new cache();
  133. function array(ar) {
  134. r = [];
  135. for (i = 0, len = ar.length; i < len; i++) {
  136. r[i] = ar[i];
  137. }
  138. return r;
  139. }
  140. function previous(n) {
  141. while (n = n.previousSibling) {
  142. if (n.nodeType == 1) {
  143. break;
  144. }
  145. }
  146. return n
  147. }
  148. function q(query) {
  149. return query.match(chunker);
  150. }
  151. // this next method expect at most these args
  152. // given => div.hello[title="world"]:foo('bar')
  153. // div.hello[title="world"]:foo('bar'), div, .hello, [title="world"], title, =, world, :foo('bar'), foo, ('bar'), bar]
  154. function interpret(whole, tag, idsAndClasses, wholeAttribute, attribute, qualifier, value, wholePseudo, pseudo, wholePseudoVal, pseudoVal) {
  155. var m, c, k;
  156. if (tag && this.tagName.toLowerCase() !== tag) {
  157. return false;
  158. }
  159. if (idsAndClasses && (m = idsAndClasses.match(id)) && m[1] !== this.id) {
  160. return false;
  161. }
  162. if (idsAndClasses && (classes = idsAndClasses.match(clas))) {
  163. for (i = classes.length; i--;) {
  164. c = classes[i].slice(1);
  165. if (!(classCache.g(c) || classCache.s(c, new RegExp('(^|\\s+)' + c + '(\\s+|$)'))).test(this.className)) {
  166. return false;
  167. }
  168. }
  169. }
  170. if (pseudo && qwery.pseudos[pseudo] && !qwery.pseudos[pseudo](this, pseudoVal)) {
  171. return false;
  172. }
  173. if (wholeAttribute && !value) {
  174. o = this.attributes;
  175. for (k in o) {
  176. if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) {
  177. return this;
  178. }
  179. }
  180. }
  181. if (wholeAttribute && !checkAttr(qualifier, this.getAttribute(attribute) || '', value)) {
  182. return false;
  183. }
  184. return this;
  185. }
  186. function clean(s) {
  187. return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1'));
  188. }
  189. function checkAttr(qualify, actual, val) {
  190. switch (qualify) {
  191. case '=':
  192. return actual == val;
  193. case '^=':
  194. return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val))));
  195. case '$=':
  196. return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$')));
  197. case '*=':
  198. return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val))));
  199. case '~=':
  200. return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)')));
  201. case '|=':
  202. return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)')));
  203. }
  204. return 0;
  205. }
  206. function _qwery(selector) {
  207. var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children,
  208. tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr)),
  209. dividedTokens = selector.match(dividers), dividedToken;
  210. tokens = tokens.slice(0); // this makes a copy of the array so the cached original is not effected
  211. if (!tokens.length) {
  212. return r;
  213. }
  214. token = tokens.pop();
  215. root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc;
  216. if (!root) {
  217. return r;
  218. }
  219. intr = q(token);
  220. els = dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ? function (r) {
  221. while (root = root.nextSibling) {
  222. root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && r.push(root)
  223. }
  224. return r
  225. }([]) :
  226. root.getElementsByTagName(intr[1] || '*');
  227. for (i = 0, l = els.length; i < l; i++) {
  228. if (item = interpret.apply(els[i], intr)) {
  229. r[j++] = item;
  230. }
  231. }
  232. if (!tokens.length) {
  233. return r;
  234. }
  235. // loop through all descendent tokens
  236. for (j = 0, l = r.length, k = 0; j < l; j++) {
  237. p = r[j];
  238. // loop through each token backwards crawling up tree
  239. for (i = tokens.length; i--;) {
  240. // loop through parent nodes
  241. while (p = walker[dividedTokens[i]](p, r[j])) {
  242. if (found = interpret.apply(p, q(tokens[i]))) {
  243. break;
  244. }
  245. }
  246. }
  247. found && (ret[k++] = r[j]);
  248. }
  249. return ret;
  250. }
  251. function boilerPlate(selector, _root, fn) {
  252. var root = (typeof _root == 'string') ? fn(_root)[0] : (_root || doc);
  253. if (selector === window || isNode(selector)) {
  254. return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : [];
  255. }
  256. if (selector && typeof selector === 'object' && isFinite(selector.length)) {
  257. return array(selector);
  258. }
  259. if (m = selector.match(idOnly)) {
  260. return (el = doc.getElementById(m[1])) ? [el] : [];
  261. }
  262. if (m = selector.match(tagOnly)) {
  263. return array(root.getElementsByTagName(m[1]));
  264. }
  265. return false;
  266. }
  267. function isNode(el) {
  268. return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9));
  269. }
  270. function uniq(ar) {
  271. var a = [], i, j;
  272. label:
  273. for (i = 0; i < ar.length; i++) {
  274. for (j = 0; j < a.length; j++) {
  275. if (a[j] == ar[i]) {
  276. continue label;
  277. }
  278. }
  279. a[a.length] = ar[i];
  280. }
  281. return a;
  282. }
  283. function qwery(selector, _root) {
  284. var root = (typeof _root == 'string') ? qwery(_root)[0] : (_root || doc);
  285. if (!root || !selector) {
  286. return [];
  287. }
  288. if (m = boilerPlate(selector, _root, qwery)) {
  289. return m;
  290. }
  291. return select(selector, root);
  292. }
  293. var isAncestor = 'compareDocumentPosition' in html ?
  294. function (element, container) {
  295. return (container.compareDocumentPosition(element) & 16) == 16;
  296. } : 'contains' in html ?
  297. function (element, container) {
  298. container = container == doc || container == window ? html : container;
  299. return container !== element && container.contains(element);
  300. } :
  301. function (element, container) {
  302. while (element = element.parentNode) {
  303. if (element === container) {
  304. return 1;
  305. }
  306. }
  307. return 0;
  308. },
  309. select = (doc.querySelector && doc.querySelectorAll) ?
  310. function (selector, root) {
  311. if (doc.getElementsByClassName && (m = selector.match(classOnly))) {
  312. return array((root).getElementsByClassName(m[1]));
  313. }
  314. return array((root).querySelectorAll(selector));
  315. } :
  316. function (selector, root) {
  317. selector = selector.replace(normalizr, '$1');
  318. var result = [], collection, collections = [], i;
  319. if (m = selector.match(tagAndOrClass)) {
  320. items = root.getElementsByTagName(m[1] || '*');
  321. r = classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)'));
  322. for (i = 0, l = items.length, j = 0; i < l; i++) {
  323. r.test(items[i].className) && (result[j++] = items[i]);
  324. }
  325. return result;
  326. }
  327. for (i = 0, items = selector.split(','), l = items.length; i < l; i++) {
  328. collections[i] = _qwery(items[i]);
  329. }
  330. for (i = 0, l = collections.length; i < l && (collection = collections[i]); i++) {
  331. var ret = collection;
  332. if (root !== doc) {
  333. ret = [];
  334. for (j = 0, m = collection.length; j < m && (element = collection[j]); j++) {
  335. // make sure element is a descendent of root
  336. isAncestor(element, root) && ret.push(element);
  337. }
  338. }
  339. result = result.concat(ret);
  340. }
  341. return uniq(result);
  342. };
  343. qwery.uniq = uniq;
  344. qwery.pseudos = {};
  345. var oldQwery = context.qwery;
  346. qwery.noConflict = function () {
  347. context.qwery = oldQwery;
  348. return this;
  349. };
  350. context['qwery'] = qwery;
  351. }(this, document);!function (doc) {
  352. var q = qwery.noConflict();
  353. var table = 'table',
  354. nodeMap = {
  355. thead: table,
  356. tbody: table,
  357. tfoot: table,
  358. tr: 'tbody',
  359. th: 'tr',
  360. td: 'tr',
  361. fieldset: 'form',
  362. option: 'select'
  363. }
  364. function create(node, root) {
  365. var tag = /^<([^\s>]+)/.exec(node)[1]
  366. var el = (root || doc).createElement(nodeMap[tag] || 'div'), els = [];
  367. el.innerHTML = node;
  368. var nodes = el.childNodes;
  369. el = el.firstChild;
  370. els.push(el);
  371. while (el = el.nextSibling) {
  372. (el.nodeType == 1) && els.push(el);
  373. }
  374. return els;
  375. }
  376. $._select = function (s, r) {
  377. return /^\s*</.test(s) ? create(s, r) : q(s, r);
  378. };
  379. $.pseudos = q.pseudos;
  380. $.ender({
  381. find: function (s) {
  382. var r = [], i, l, j, k, els;
  383. for (i = 0, l = this.length; i < l; i++) {
  384. els = q(s, this[i]);
  385. for (j = 0, k = els.length; j < k; j++) {
  386. r.push(els[j]);
  387. }
  388. }
  389. return $(q.uniq(r));
  390. }
  391. , and: function (s) {
  392. var plus = $(s);
  393. for (var i = this.length, j = 0, l = this.length + plus.length; i < l; i++, j++) {
  394. this[i] = plus[j];
  395. }
  396. return this;
  397. }
  398. }, true);
  399. }(document);
  400. /*!
  401. * bonzo.js - copyright @dedfat 2011
  402. * https://github.com/ded/bonzo
  403. * Follow our software http://twitter.com/dedfat
  404. * MIT License
  405. */
  406. !function (context, win) {
  407. var doc = context.document,
  408. html = doc.documentElement,
  409. parentNode = 'parentNode',
  410. query = null,
  411. byTag = 'getElementsByTagName',
  412. specialAttributes = /^checked|value|selected$/,
  413. specialTags = /select|fieldset|table|tbody|tfoot|td|tr|colgroup/i,
  414. table = 'table',
  415. tagMap = { thead: table, tbody: table, tfoot: table, tr: 'tbody', th: 'tr', td: 'tr', fieldset: 'form', option: 'select' },
  416. stateAttributes = /^checked|selected$/,
  417. ie = /msie/i.test(navigator.userAgent),
  418. uidList = [],
  419. uuids = 0,
  420. digit = /^-?[\d\.]+$/,
  421. px = 'px',
  422. // commonly used methods
  423. setAttribute = 'setAttribute',
  424. getAttribute = 'getAttribute',
  425. trimReplace = /(^\s*|\s*$)/g,
  426. unitless = { lineHeight: 1, zoom: 1, zIndex: 1, opacity: 1 };
  427. function classReg(c) {
  428. return new RegExp("(^|\\s+)" + c + "(\\s+|$)");
  429. }
  430. function each(ar, fn, scope) {
  431. for (var i = 0, l = ar.length; i < l; i++) {
  432. fn.call(scope || ar[i], ar[i], i, ar);
  433. }
  434. return ar;
  435. }
  436. var trim = String.prototype.trim ?
  437. function (s) {
  438. return s.trim();
  439. } :
  440. function (s) {
  441. return s.replace(trimReplace, '');
  442. };
  443. function camelize(s) {
  444. return s.replace(/-(.)/g, function (m, m1) {
  445. return m1.toUpperCase();
  446. });
  447. }
  448. function is(node) {
  449. return node && node.nodeName && node.nodeType == 1;
  450. }
  451. function some(ar, fn, scope) {
  452. for (var i = 0, j = ar.length; i < j; ++i) {
  453. if (fn.call(scope, ar[i], i, ar)) {
  454. return true;
  455. }
  456. }
  457. return false;
  458. }
  459. var getStyle = doc.defaultView && doc.defaultView.getComputedStyle ?
  460. function (el, property) {
  461. var value = null;
  462. if (property == 'float') {
  463. property = 'cssFloat';
  464. }
  465. var computed = doc.defaultView.getComputedStyle(el, '');
  466. computed && (value = computed[camelize(property)]);
  467. return el.style[property] || value;
  468. } : (ie && html.currentStyle) ?
  469. function (el, property) {
  470. property = camelize(property);
  471. property = property == 'float' ? 'styleFloat' : property;
  472. if (property == 'opacity') {
  473. var val = 100;
  474. try {
  475. val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
  476. } catch (e1) {
  477. try {
  478. val = el.filters('alpha').opacity;
  479. } catch (e2) {}
  480. }
  481. return val / 100;
  482. }
  483. var value = el.currentStyle ? el.currentStyle[property] : null;
  484. return el.style[property] || value;
  485. } :
  486. function (el, property) {
  487. return el.style[camelize(property)];
  488. };
  489. function insert(target, host, fn) {
  490. var i = 0, self = host || this, r = [],
  491. nodes = query && typeof target == 'string' && target.charAt(0) != '<' ? function (n) {
  492. return (n = query(target)) && (n.selected = 1) && n;
  493. }() : target;
  494. each(normalize(nodes), function (t) {
  495. each(self, function (el) {
  496. var n = !el[parentNode] || (el[parentNode] && !el[parentNode][parentNode]) ?
  497. function () {
  498. var c = el.cloneNode(true);
  499. self.$ && self.cloneEvents && self.$(c).cloneEvents(el);
  500. return c;
  501. }() :
  502. el;
  503. fn(t, n);
  504. r[i] = n;
  505. i++;
  506. });
  507. }, this);
  508. each(r, function (e, i) {
  509. self[i] = e;
  510. });
  511. self.length = i;
  512. return self;
  513. }
  514. function xy(el, x, y) {
  515. var $el = bonzo(el),
  516. style = $el.css('position'),
  517. offset = $el.offset(),
  518. rel = 'relative',
  519. isRel = style == rel,
  520. delta = [parseInt($el.css('left'), 10), parseInt($el.css('top'), 10)];
  521. if (style == 'static') {
  522. $el.css('position', rel);
  523. style = rel;
  524. }
  525. isNaN(delta[0]) && (delta[0] = isRel ? 0 : el.offsetLeft);
  526. isNaN(delta[1]) && (delta[1] = isRel ? 0 : el.offsetTop);
  527. x !== null && (el.style.left = x - offset.left + delta[0] + 'px');
  528. y !== null && (el.style.top = y - offset.top + delta[1] + 'px');
  529. }
  530. function Bonzo(elements) {
  531. this.length = 0;
  532. if (elements) {
  533. elements = typeof elements !== 'string' &&
  534. !elements.nodeType &&
  535. typeof elements.length !== 'undefined' ?
  536. elements :
  537. [elements];
  538. this.length = elements.length;
  539. for (var i = 0; i < elements.length; i++) {
  540. this[i] = elements[i];
  541. }
  542. }
  543. }
  544. Bonzo.prototype = {
  545. each: function (fn, scope) {
  546. return each(this, fn, scope);
  547. },
  548. map: function (fn, reject) {
  549. var m = [], n, i;
  550. for (i = 0; i < this.length; i++) {
  551. n = fn.call(this, this[i]);
  552. reject ? (reject(n) && m.push(n)) : m.push(n);
  553. }
  554. return m;
  555. },
  556. first: function () {
  557. return bonzo(this[0]);
  558. },
  559. last: function () {
  560. return bonzo(this[this.length - 1]);
  561. },
  562. html: function (h, text) {
  563. var method = text ?
  564. html.textContent == null ?
  565. 'innerText' :
  566. 'textContent' :
  567. 'innerHTML', m;
  568. function append(el) {
  569. while (el.firstChild) {
  570. el.removeChild(el.firstChild);
  571. }
  572. each(normalize(h), function (node) {
  573. el.appendChild(node);
  574. });
  575. }
  576. return typeof h !== 'undefined' ?
  577. this.each(function (el) {
  578. (m = el.tagName.match(specialTags)) ?
  579. append(el, m[0]) :
  580. (el[method] = h);
  581. }) :
  582. this[0] ? this[0][method] : '';
  583. },
  584. text: function (text) {
  585. return this.html(text, 1);
  586. },
  587. addClass: function (c) {
  588. return this.each(function (el) {
  589. this.hasClass(el, c) || (el.className = trim(el.className + ' ' + c));
  590. }, this);
  591. },
  592. removeClass: function (c) {
  593. return this.each(function (el) {
  594. this.hasClass(el, c) && (el.className = trim(el.className.replace(classReg(c), ' ')));
  595. }, this);
  596. },
  597. hasClass: function (el, c) {
  598. return typeof c == 'undefined' ?
  599. some(this, function (i) {
  600. return classReg(el).test(i.className);
  601. }) :
  602. classReg(c).test(el.className);
  603. },
  604. toggleClass: function (c, condition) {
  605. if (typeof condition !== 'undefined' && !condition) {
  606. return this;
  607. }
  608. return this.each(function (el) {
  609. this.hasClass(el, c) ?
  610. (el.className = trim(el.className.replace(classReg(c), ' '))) :
  611. (el.className = trim(el.className + ' ' + c));
  612. }, this);
  613. },
  614. show: function (type) {
  615. return this.each(function (el) {
  616. el.style.display = type || '';
  617. });
  618. },
  619. hide: function (elements) {
  620. return this.each(function (el) {
  621. el.style.display = 'none';
  622. });
  623. },
  624. append: function (node) {
  625. return this.each(function (el) {
  626. each(normalize(node), function (i) {
  627. el.appendChild(i);
  628. });
  629. });
  630. },
  631. prepend: function (node) {
  632. return this.each(function (el) {
  633. var first = el.firstChild;
  634. each(normalize(node), function (i) {
  635. el.insertBefore(i, first);
  636. });
  637. });
  638. },
  639. appendTo: function (target, host) {
  640. return insert.call(this, target, host, function (t, el) {
  641. t.appendChild(el);
  642. });
  643. },
  644. prependTo: function (target, host) {
  645. return insert.call(this, target, host, function (t, el) {
  646. t.insertBefore(el, t.firstChild);
  647. });
  648. },
  649. next: function () {
  650. return this.related('nextSibling');
  651. },
  652. previous: function () {
  653. return this.related('previousSibling');
  654. },
  655. related: function (method) {
  656. return this.map(
  657. function (el) {
  658. el = el[method];
  659. while (el && el.nodeType !== 1) {
  660. el = el[method];
  661. }
  662. return el || 0;
  663. },
  664. function (el) {
  665. return el;
  666. }
  667. );
  668. },
  669. before: function (node) {
  670. return this.each(function (el) {
  671. each(bonzo.create(node), function (i) {
  672. el[parentNode].insertBefore(i, el);
  673. });
  674. });
  675. },
  676. after: function (node) {
  677. return this.each(function (el) {
  678. each(bonzo.create(node), function (i) {
  679. el[parentNode].insertBefore(i, el.nextSibling);
  680. });
  681. });
  682. },
  683. insertBefore: function (target, host) {
  684. return insert.call(this, target, host, function (t, el) {
  685. t[parentNode].insertBefore(el, t);
  686. });
  687. },
  688. insertAfter: function (target, host) {
  689. return insert.call(this, target, host, function (t, el) {
  690. var sibling = t.nextSibling;
  691. if (sibling) {
  692. t[parentNode].insertBefore(el, sibling);
  693. }
  694. else {
  695. t[parentNode].appendChild(el);
  696. }
  697. });
  698. },
  699. css: function (o, v, p) {
  700. // is this a request for just getting a style?
  701. if (v === undefined && typeof o == 'string') {
  702. // repurpose 'v'
  703. v = this[0];
  704. if (!v) {
  705. return null;
  706. }
  707. if (v == doc || v == win) {
  708. p = (v == doc) ? bonzo.doc() : bonzo.viewport();
  709. return o == 'width' ? p.width :
  710. o == 'height' ? p.height : '';
  711. }
  712. return getStyle(v, o);
  713. }
  714. var iter = o;
  715. if (typeof o == 'string') {
  716. iter = {};
  717. iter[o] = v;
  718. }
  719. if (ie && iter.opacity) {
  720. // oh this 'ol gamut
  721. iter.filter = 'alpha(opacity=' + (iter.opacity * 100) + ')';
  722. // give it layout
  723. iter.zoom = o.zoom || 1;
  724. delete iter.opacity;
  725. }
  726. if (v = iter['float']) {
  727. // float is a reserved style word. w3 uses cssFloat, ie uses styleFloat
  728. ie ? (iter.styleFloat = v) : (iter.cssFloat = v);
  729. delete iter['float'];
  730. }
  731. var fn = function (el, p, v) {
  732. for (var k in iter) {
  733. if (iter.hasOwnProperty(k)) {
  734. v = iter[k];
  735. // change "5" to "5px" - unless you're line-height, which is allowed
  736. (p = camelize(k)) && digit.test(v) && !(p in unitless) && (v += px);
  737. el.style[p] = v;
  738. }
  739. }
  740. };
  741. return this.each(fn);
  742. },
  743. offset: function (x, y) {
  744. if (x || y) {
  745. return this.each(function (el) {
  746. xy(el, x, y);
  747. });
  748. }
  749. var el = this[0];
  750. var width = el.offsetWidth;
  751. var height = el.offsetHeight;
  752. var top = el.offsetTop;
  753. var left = el.offsetLeft;
  754. while (el = el.offsetParent) {
  755. top = top + el.offsetTop;
  756. left = left + el.offsetLeft;
  757. }
  758. return {
  759. top: top,
  760. left: left,
  761. height: height,
  762. width: width
  763. };
  764. },
  765. attr: function (k, v) {
  766. var el = this[0];
  767. return typeof v == 'undefined' ?
  768. specialAttributes.test(k) ?
  769. stateAttributes.test(k) && typeof el[k] == 'string' ?
  770. true : el[k] : el[getAttribute](k) :
  771. this.each(function (el) {
  772. k == 'value' ? (el.value = v) : el[setAttribute](k, v);
  773. });
  774. },
  775. val: function (s) {
  776. return (typeof s == 'string') ? this.attr('value', s) : this[0].value;
  777. },
  778. removeAttr: function (k) {
  779. return this.each(function (el) {
  780. el.removeAttribute(k);
  781. });
  782. },
  783. data: function (k, v) {
  784. var el = this[0];
  785. if (typeof v === 'undefined') {
  786. el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids);
  787. var uid = el[getAttribute]('data-node-uid');
  788. uidList[uid] || (uidList[uid] = {});
  789. return uidList[uid][k];
  790. } else {
  791. return this.each(function (el) {
  792. el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids);
  793. var uid = el[getAttribute]('data-node-uid');
  794. var o = {};
  795. o[k] = v;
  796. uidList[uid] = o;
  797. });
  798. }
  799. },
  800. remove: function () {
  801. return this.each(function (el) {
  802. el[parentNode] && el[parentNode].removeChild(el);
  803. });
  804. },
  805. empty: function () {
  806. return this.each(function (el) {
  807. while (el.firstChild) {
  808. el.removeChild(el.firstChild);
  809. }
  810. });
  811. },
  812. detach: function () {
  813. return this.map(function (el) {
  814. return el[parentNode].removeChild(el);
  815. });
  816. },
  817. scrollTop: function (y) {
  818. return scroll.call(this, null, y, 'y');
  819. },
  820. scrollLeft: function (x) {
  821. return scroll.call(this, x, null, 'x');
  822. }
  823. };
  824. function normalize(node) {
  825. return typeof node == 'string' ? bonzo.create(node) : is(node) ? [node] : node; // assume [nodes]
  826. }
  827. function scroll(x, y, type) {
  828. var el = this[0];
  829. if (x == null && y == null) {
  830. return (isBody(el) ? getWindowScroll() : { x: el.scrollLeft, y: el.scrollTop })[type];
  831. }
  832. if (isBody(el)) {
  833. win.scrollTo(x, y);
  834. } else {
  835. x != null && (el.scrollLeft = x);
  836. y != null && (el.scrollTop = y);
  837. }
  838. return this;
  839. }
  840. function isBody(element) {
  841. return element === win || (/^(?:body|html)$/i).test(element.tagName);
  842. }
  843. function getWindowScroll() {
  844. return { x: win.pageXOffset || html.scrollLeft, y: win.pageYOffset || html.scrollTop };
  845. }
  846. function bonzo(els, host) {
  847. return new Bonzo(els, host);
  848. }
  849. bonzo.setQueryEngine = function (q) {
  850. query = q;
  851. delete bonzo.setQueryEngine;
  852. };
  853. bonzo.aug = function (o, target) {
  854. for (var k in o) {
  855. o.hasOwnProperty(k) && ((target || Bonzo.prototype)[k] = o[k]);
  856. }
  857. };
  858. bonzo.create = function (node) {
  859. return typeof node == 'string' ?
  860. function () {
  861. var tag = /^<([^\s>]+)/.exec(node);
  862. var el = doc.createElement(tag && tagMap[tag[1].toLowerCase()] || 'div'), els = [];
  863. el.innerHTML = node;
  864. var nodes = el.childNodes;
  865. el = el.firstChild;
  866. els.push(el);
  867. while (el = el.nextSibling) {
  868. (el.nodeType == 1) && els.push(el);
  869. }
  870. return els;
  871. }() : is(node) ? [node.cloneNode(true)] : [];
  872. };
  873. bonzo.doc = function () {
  874. var w = html.scrollWidth,
  875. h = html.scrollHeight,
  876. vp = this.viewport();
  877. return {
  878. width: Math.max(w, vp.width),
  879. height: Math.max(h, vp.height)
  880. };
  881. };
  882. bonzo.firstChild = function (el) {
  883. for (var c = el.childNodes, i = 0, j = (c && c.length) || 0, e; i < j; i++) {
  884. if (c[i].nodeType === 1) {
  885. e = c[j = i];
  886. }
  887. }
  888. return e;
  889. };
  890. bonzo.viewport = function () {
  891. var h = self.innerHeight,
  892. w = self.innerWidth;
  893. if (ie) {
  894. h = html.clientHeight;
  895. w = html.clientWidth;
  896. }
  897. return {
  898. width: w,
  899. height: h
  900. };
  901. };
  902. bonzo.isAncestor = 'compareDocumentPosition' in html ?
  903. function (container, element) {
  904. return (container.compareDocumentPosition(element) & 16) == 16;
  905. } : 'contains' in html ?
  906. function (container, element) {
  907. return container !== element && container.contains(element);
  908. } :
  909. function (container, element) {
  910. while (element = element[parentNode]) {
  911. if (element === container) {
  912. return true;
  913. }
  914. }
  915. return false;
  916. };
  917. var old = context.bonzo;
  918. bonzo.noConflict = function () {
  919. context.bonzo = old;
  920. return this;
  921. };
  922. context['bonzo'] = bonzo;
  923. }(this, window);!function ($) {
  924. var b = bonzo;
  925. b.setQueryEngine($);
  926. $.ender(b);
  927. $.ender(b(), true);
  928. $.ender({
  929. create: function (node) {
  930. return $(b.create(node));
  931. }
  932. });
  933. $.id = function (id) {
  934. return $([document.getElementById(id)]);
  935. };
  936. function indexOf(ar, val) {
  937. for (var i = 0; i < ar.length; i++) {
  938. if (ar[i] === val) {
  939. return i;
  940. }
  941. }
  942. return -1;
  943. }
  944. function uniq(ar) {
  945. var a = [], i, j;
  946. label:
  947. for (i = 0; i < ar.length; i++) {
  948. for (j = 0; j < a.length; j++) {
  949. if (a[j] == ar[i]) {
  950. continue label;
  951. }
  952. }
  953. a[a.length] = ar[i];
  954. }
  955. return a;
  956. }
  957. $.ender({
  958. parents: function (selector, closest) {
  959. var collection = $(selector), j, k, p, r = [];
  960. for (j = 0, k = this.length; j < k; j++) {
  961. p = this[j];
  962. while (p = p.parentNode) {
  963. if (indexOf(collection, p) !== -1) {
  964. r.push(p);
  965. if (closest) break;
  966. }
  967. }
  968. }
  969. return $(uniq(r));
  970. },
  971. closest: function (selector) {
  972. return this.parents(selector, true);
  973. },
  974. first: function () {
  975. return $(this[0]);
  976. },
  977. last: function () {
  978. return $(this[this.length - 1]);
  979. },
  980. next: function () {
  981. return $(b(this).next());
  982. },
  983. previous: function () {
  984. return $(b(this).previous());
  985. },
  986. appendTo: function (t) {
  987. return b(this.selector).appendTo(t, this);
  988. },
  989. prependTo: function (t) {
  990. return b(this.selector).prependTo(t, this);
  991. },
  992. insertAfter: function (t) {
  993. return b(this.selector).insertAfter(t, this);
  994. },
  995. insertBefore: function (t) {
  996. return b(this.selector).insertBefore(t, this);
  997. },
  998. siblings: function () {
  999. var i, l, p, r = [];
  1000. for (i = 0, l = this.length; i < l; i++) {
  1001. p = this[i];
  1002. while (p = p.previousSibling) {
  1003. p.nodeType == 1 && r.push(p);
  1004. }
  1005. p = this[i];
  1006. while (p = p.nextSibling) {
  1007. p.nodeType == 1 && r.push(p);
  1008. }
  1009. }
  1010. return $(r);
  1011. },
  1012. children: function () {
  1013. var i, el, r = [];
  1014. for (i = 0, l = this.length; i < l; i++) {
  1015. if (!(el = b.firstChild(this[i]))) {
  1016. continue;
  1017. }
  1018. r.push(el);
  1019. while (el = el.nextSibling) {
  1020. el.nodeType == 1 && r.push(el);
  1021. }
  1022. }
  1023. return $(uniq(r));
  1024. },
  1025. height: function (v) {
  1026. return dimension(v, this, 'height')
  1027. },
  1028. width: function (v) {
  1029. return dimension(v, this, 'width')
  1030. }
  1031. }, true);
  1032. function dimension(v, self, which) {
  1033. return v ?
  1034. self.css(which, v) :
  1035. function (r) {
  1036. r = parseInt(self.css(which), 10);
  1037. return isNaN(r) ? self[0]['offset' + which.replace(/^\w/, function (m) {return m.toUpperCase()})] : r
  1038. }()
  1039. }
  1040. }(ender || $);