diff --git a/ajax/libs/dollar.js/1.1.0/dollar.js b/ajax/libs/dollar.js/1.1.0/dollar.js new file mode 100644 index 000000000..f0a52f27f --- /dev/null +++ b/ajax/libs/dollar.js/1.1.0/dollar.js @@ -0,0 +1,719 @@ +/** + * DollarJS + * A jQuery-compatible and non-All-in-One library which is more "Zepto" than Zepto.js + * Focus on DOM operations and mobile platform, wrap native API wherever possible. + * + * using AMD (Asynchronous Module Definition) API with OzJS + * see http://ozjs.org for details + * + * Copyright (C) 2010-2012, Dexter.Yy, MIT License + * vim: et:ts=4:sw=4:sts=4 + */ +define("dollar", [ + "mo/lang/es5", + "mo/lang/mix", + "mo/lang/type" +], function(es5, _, detect){ + + var window = this, + doc = window.document, + NEXT_SIB = 'nextElementSibling', + PREV_SIB = 'prevElementSibling', + FIRST_CHILD = 'firstElementChild', + MATCHES_SELECTOR = ['webkitMatchesSelector', 'mozMatchesSelector', 'matchesSelector'] + .map(function(name){ + return this[name] && name; + }, doc.body).filter(pick)[0], + _MOE = 'MouseEvents', + SPECIAL_EVENTS = { click: _MOE, mousedown: _MOE, mouseup: _MOE, mousemove: _MOE }, + CSS_NUMBER = { + 'column-count': 1, 'columns': 1, 'font-weight': 1, + 'line-height': 1, 'opacity': 1, 'z-index': 1, 'zoom': 1 + }, + RE_HTMLTAG = /^\s*<(\w+|!)[^>]*>/, + isFunction = detect.isFunction, + _array_each = Array.prototype.forEach, + _array_map = Array.prototype.map, + _array_push = Array.prototype.push, + _getComputedStyle = document.defaultView.getComputedStyle, + _next_pointer, + _elm_display = {}, + _html_containers = {}; + + + function $(selector, context){ + if (selector) { + if (selector.constructor === $) { + return selector; + } else if (typeof selector !== 'string') { + var nodes = new $(); + _array_push[selector.push === _array_push + ? 'apply' : 'call'](nodes, selector); + return nodes; + } else if (RE_HTMLTAG.test(selector)) { + return create_nodes(selector); + } else if (context) { + return $(context).find(selector); + } else { + return ext.find(selector); + } + } else if (this === window) { + return new $(); + } + } + + var ext = $.fn = $.prototype = []; + + ['map', 'filter', 'slice', 'reverse', 'sort'].forEach(function(method){ + var origin = this['_' + method] = this[method]; + this[method] = function(){ + return $(origin.apply(this, arguments)); + }; + }, ext); + + ['splice', 'concat'].forEach(function(method){ + var origin = this['_' + method] = this[method]; + this[method] = function(){ + return $(origin.apply(this._slice(), _array_map.call( + arguments, function(i){ + return i._slice(); + }) + )); + }; + }, ext); + + _.mix(ext, { + + constructor: $, + + // Traversing + + find: function(selector){ + var nodes = new $(), contexts; + if (this === ext) { + contexts = [doc]; + } else { + nodes.prevObject = contexts = this; + } + if (/^#/.test(selector)) { + var elm = (contexts[0] || doc).getElementById(selector.substr(1)); + if (elm) { + nodes.push(elm); + } + } else { + var query = /\W/.test(selector) ? 'querySelectorAll' + : 'getElementsByTagName'; + if (contexts[1]) { + contexts.forEach(function(context){ + this.push.apply(this, context[query](selector)); + }, nodes); + } else if (contexts[0]) { + nodes.push.apply(nodes, contexts[0][query](selector)); + } + } + return nodes; + }, + + eq: function(i){ + return i === -1 ? this.slice(-1) : this.slice(i, i + 1); + }, + + not: function(selector){ + return this.filter(function(node){ + return node && !this(node, selector); + }, matches_selector); + }, + + has: function(selector){ + return this.filter(function(node){ + return this(node, selector); + }, matches_selector); + }, + + parent: find_near('parentNode'), + + parents: function(selector){ + var ancestors = new $(), p = this, + finding = selector ? find_selector(selector, 'parentNode') : function(node){ + return this[this.push(node.parentNode) - 1]; + }; + while (p.length) { + p = p.map(finding, ancestors); + } + return ancestors; + }, + + closest: function(selector){ + var ancestors = new $(), p = this, + finding = find_selector(selector, 'parentNode'); + while (p.length && !ancestors.length) { + p = p.map(finding, ancestors); + } + return ancestors.length && ancestors || this; + }, + + siblings: find_sibs(NEXT_SIB, FIRST_CHILD), + + next: find_near(NEXT_SIB), + + nextAll: find_sibs(NEXT_SIB), + + nextUntil: find_sibs(NEXT_SIB, false, true), + + prev: find_near(PREV_SIB), + + prevAll: find_sibs(PREV_SIB), + + prevUntil: find_sibs(PREV_SIB, false, true), + + children: function(){ + return _.merge.apply(_, this.map(function(node){ + return this(node.children); + }, $)); + }, + + contents: function(){ + return _.merge.apply(_, this.map(function(node){ + return this(node.childNodes); + }, $)); + }, + + // Detection + + is: function(selector){ + return this.some(function(node){ + return matches_selector(node, selector); + }); + }, + + hasClass: function(cname){ + for (var i = 0, l = this.length; i < l; i++) { + if (this[i].classList.contains(cname)) { + return true; + } + } + return false; + }, + + // Properties + + addClass: function(cname){ + return foreach_farg(this, cname, 'className', function(node, cname){ + node.classList.add(cname); + }); + }, + + removeClass: function(cname){ + return foreach_farg(this, cname, 'className', function(node, cname){ + node.classList.remove(cname); + }); + }, + + toggleClass: function(cname, force){ + return foreach_farg(this, cname, 'className', function(node, cname){ + node.classList[typeof this === 'undefined' && 'toggle' + || this && 'add' || 'remove'](cname); + }, force); + }, + + attr: kv_access(function(node, name, value){ + node.setAttribute(name, value); + }, function(node, name){ + return node && node.getAttribute(name); + }), + + removeAttr: function(name){ + this.forEach(function(node){ + node.removeAttribute(this); + }, name); + return this; + }, + + prop: kv_access(function(node, name, value){ + node[name] = value; + }, function(node, name){ + return (node || {})[name]; + }), + + removeProp: function(name){ + this.forEach(function(node){ + delete node[this]; + }, name); + return this; + }, + + data: kv_access(function(node, name, value){ + node.dataset[css_method(name)] = value; + }, function(node, name){ + return (node || {}).dataset[css_method(name)]; + }), + + removeData: function(name){ + this.forEach(function(node){ + delete node.dataset[this]; + }, name); + return this; + }, + + val: function(value){ + var node = this[0]; + if (value === undefined) { + if (node) { + if (node.multiple) { + return $('option', this).filter(function(item){ + return item.selected; + }).map(function(item){ + return item.value; + }); + } + return node.value; + } + } else { + return foreach_farg(this, value, 'value', function(node, value){ + node.value = value; + }); + } + }, + + empty: function(){ + this.forEach(function(node){ + node.innerHTML = ''; + }); + return this; + }, + + html: function(str){ + return str === undefined ? (this[0] || {}).innerHTML + : foreach_farg(this, str, 'innerHTML', function(node, str){ + if (RE_HTMLTAG.test(str)) { + this(node).empty().append(str); + } else { + node.innerHTML = str; + } + }, $); + }, + + text: function(str){ + return str === undefined ? (this[0] || {}).textContent + : foreach_farg(this, str, 'textContent', function(node, str){ + node.textContent = str; + }); + }, + + clone: function(){ + return this.map(function(node){ + return node.cloneNode(true); + }); + }, + + css: kv_access(function(node, name, value){ + var prop = css_prop(name); + if (!value && value !== 0) { + node.style.removeProperty(prop); + } else { + node.style.cssText += ';' + prop + ":" + css_unit(prop, value); + } + }, function(node, name){ + return node && (node.style[css_method(name)] + || _getComputedStyle(node, '').getPropertyValue(name)); + }, function(self, dict){ + var prop, value, css = ''; + for (var name in dict) { + value = dict[name]; + prop = css_prop(name); + if (!value && value !== 0) { + self.forEach(function(node){ + node.style.removeProperty(this); + }, prop); + } else { + css += prop + ":" + css_unit(prop, value) + ';'; + } + } + self.forEach(function(node){ + node.style.cssText += ';' + this; + }, css); + }), + + hide: function(){ + return this.css("display", "none"); + }, + + show: function(){ + this.forEach(function(node){ + if (node.style.display === "none") { + node.style.display = null; + } + if (this(node, '').getPropertyValue("display") === "none") { + node.style.display = default_display(node.nodeName); + } + }, _getComputedStyle); + return this; + }, + + // Dimensions + + offset: function(){ + var set = this[0].getBoundingClientRect(); + return { + left: set.left + window.pageXOffset, + top: set.top + window.pageYOffset, + width: set.width, + height: set.height + }; + }, + + width: dimension('Width'), + + height: dimension('Height'), + + // Manipulation + + appendTo: operator_insert_to(1), + + append: operator_insert(1), + + prependTo: operator_insert_to(3), + + prepend: operator_insert(3), + + insertBefore: operator_insert_to(2), + + before: operator_insert(2), + + insertAfter: operator_insert_to(4), + + after: operator_insert(4), + + replaceAll: function(targets){ + var t = $(targets); + this.insertBefore(t); + t.remove(); + return this; + }, + + replaceWith: function(contents){ + return $(contents).replaceAll(this); + }, + + wrap: function(boxes){ + return foreach_farg(this, boxes, false, function(node, boxes){ + this(boxes).insertBefore(node).append(node); + }, $); + }, + + wrapAll: function(boxes){ + $(boxes).insertBefore(this.eq(0)).append(this); + return this; + }, + + wrapInner: function(boxes){ + return foreach_farg(this, boxes, false, function(node, boxes){ + this(node).contents().wrapAll(boxes); + }, $); + }, + + unwrap: function(){ + this.parent().forEach(function(node){ + this(node).children().replaceAll(node); + }, $); + return this; + }, + + remove: function(){ + this.forEach(function(node){ + var parent = node.parentNode; + if (parent) { + parent.removeChild(node); + } + }); + return this; + }, + + // Event + + bind: event_access('add'), + + unbind: event_access('remove'), + + trigger: function(event, argv){ + if (typeof event === 'string') { + event = Event(event); + } + _.mix(event, argv); + this.forEach(event.type == 'submit' + && !event.defaultPrevented ? function(node){ + node.submit(); + } : function(node){ + if ('dispatchEvent' in node) { + node.dispatchEvent(this); + } + }, event); + return this; + }, + + // Miscellaneous + + end: function(){ + return this.prevObject || new $(); + }, + + each: function(fn){ + for (var i = 0, l = this.length; i < l; i++){ + var re = fn.call(this[i], i); + if (re === false) { + break; + } + } + return this; + } + + }); + + // private + + function pick(v){ + return v; + } + + function matches_selector(elm, selector){ + return elm && elm[MATCHES_SELECTOR](selector); + } + + function find_selector(selector, attr){ + return function(node){ + if (attr) { + node = node[attr]; + } + if (matches_selector(node, selector)) { + this.push(node); + } + return node; + }; + } + + function find_near(prop){ + return function(selector){ + return $(_.unique([undefined, doc, null].concat( + this._map(selector ? function(node){ + var n = node[prop]; + if (n && matches_selector(n, selector)) { + return n; + } + } : function(node){ + return node[prop]; + }) + )).slice(3)); + }; + } + + function find_sibs(prop, start, has_until){ + return function(target, selector){ + if (!has_until) { + selector = target; + } + var sibs = new $(); + this.forEach(function(node){ + var until, + n = start ? node.parentNode[start] : node; + if (has_until) { + until = $(target, node.parentNode); + } + do { + if (until && until.indexOf(n) > -1) { + break; + } + if (node !== n && (!selector + || matches_selector(n, selector))) { + this.push(n); + } + } while (n = n[prop]); + }, sibs); + return _.unique(sibs); + }; + } + + function foreach_farg(nodes, arg, prop, cb, context){ + var is_fn_arg = isFunction(arg); + nodes.forEach(function(node, i){ + cb.call(context, node, !is_fn_arg ? arg + : arg.call(this, i, prop && node[prop])); + }, nodes); + return nodes; + } + + function kv_access(setter, getter, map){ + return function(name, value){ + if (typeof name === 'object') { + if (map) { + map(this, name); + } else { + for (var k in name) { + this.forEach(function(node){ + setter(node, this, name[this]); + }, k); + } + } + } else { + if (value !== undefined) { + var is_fn_arg = isFunction(value); + this.forEach(function(node, i){ + setter(node, name, !is_fn_arg ? value + : value.call(this, i, getter(node, name))); + }, this); + } else { + return getter(this[0], name); + } + } + return this; + }; + } + + function event_access(action){ + function access(subject, cb){ + if (typeof subject === 'object') { + for (var i in subject) { + access.call(this, [i, subject[i]]); + } + } else if (cb) { + this.forEach(function(node){ + node[action + 'EventListener'](subject, this, false); + }, cb); + } // not support 'removeAllEventListener' + return this; + } + return access; + } + + function Event(type, props) { + var bubbles = true, + event = document.createEvent(SPECIAL_EVENTS[type] || 'Events'); + if (props) { + if ('bubbles' in props) { + bubbles = !!props.bubbles; + delete props.bubbles; + } + _.mix(event, props); + } + event.initEvent(type, bubbles, true); + return event; + } + + function css_method(name){ + return name.replace(/-+(.)?/g, function($0, $1){ + return $1 ? $1.toUpperCase() : ''; + }); + } + + function css_prop(name) { + return name.replace(/::/g, '/') + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') + .replace(/([a-z\d])([A-Z])/g, '$1_$2') + .replace(/_/g, '-') + .toLowerCase(); + } + + function css_unit(name, value) { + return typeof value == "number" && !CSS_NUMBER[name] + && value + "px" || value; + } + + function default_display(tag) { + var display = _elm_display[tag]; + if (!display) { + var tmp = document.createElement(tag); + doc.body.appendChild(tmp); + display = _getComputedStyle(tmp, '').getPropertyValue("display"); + tmp.parentNode.removeChild(tmp); + if (display === "none") { + display = "block"; + } + _elm_display[tag] = display; + } + return display; + } + + function dimension(method){ + return function(){ + var offset; + return this[0] === window + ? window['inner' + method] + : this[0] === doc + ? doc.documentElement['offset' + method] + : (this.offset() || {})[method.toLowerCase()]; + }; + } + + function create_nodes(str, attrs){ + var tag = (RE_HTMLTAG.exec(str) || [])[0] || str; + var temp = _html_containers[tag]; + if (!temp) { + temp = _html_containers[tag] = tag === 'tr' && document.createElement('tbody') + || (tag === 'tbody' || tag === 'thead' || tag === 'tfoot') + && document.createElement('table') + || (tag === 'td' || tag === 'th') && document.createElement('tr') + || document.createElement('div'); + } + temp.innerHTML = str; + var nodes = new $(); + _array_push.apply(nodes, temp.childNodes); + nodes.forEach(function(node){ + this.removeChild(node); + }, temp); + if (attrs) { + for (var k in attrs) { + nodes.attr(k, attrs[k]); + } + } + return nodes; + } + + function insert_node(target, node, action){ + if (node.nodeName.toUpperCase() === 'SCRIPT' + && (!node.type || node.type === 'text/javascript')) { + window['eval'].call(window, node.innerHTML); + } + switch(action) { + case 1: target.appendChild(node); break; + case 2: target.parentNode.insertBefore(node, target); break; + case 3: target.insertBefore(node, target.firstChild); break; + case 4: target.parentNode.insertBefore(node, target.nextSibling); break; + default: break; + } + } + + function insert_nodes(action, is_reverse){ + var fn = is_reverse ? function(target){ + insert_node(target, this, action); + } : function(content){ + insert_node(this, content, action); + }; + return function(elms){ + this.forEach(function(node){ + this.forEach(fn, node); + }, $(elms)); + return this; + }; + } + + function operator_insert_to(action){ + return insert_nodes(action, true); + } + + function operator_insert(action){ + return insert_nodes(action); + } + + // public static API + + $.find = $; + $.matchesSelector = matches_selector; + $.createNodes = create_nodes; + $.camelize = css_method; + $.dasherize = css_prop; + $.Event = Event; + + $.VERSION = '1.1.0'; + + return $; + +}); diff --git a/ajax/libs/dollar.js/1.1.0/dollar.min.js b/ajax/libs/dollar.js/1.1.0/dollar.min.js new file mode 100644 index 000000000..da9508524 --- /dev/null +++ b/ajax/libs/dollar.js/1.1.0/dollar.min.js @@ -0,0 +1,17 @@ +define("dollar",["mo/lang/es5","mo/lang/mix","mo/lang/type"],function(M,f,I){function d(a,b){if(a){if(a.constructor===d)return a;if("string"!==typeof a){var c=new d;r[a.push===r?"apply":"call"](c,a);return c}return s.test(a)?y(a):b?d(b).find(a):m.find(a)}if(this===h)return new d}function k(a,b){return a&&a[J](b)}function z(a,b){return function(c){b&&(c=c[b]);k(c,a)&&this.push(c);return c}}function t(a){return function(b){return d(f.unique([void 0,l,null].concat(this._map(b?function(c){if((c=c[a])&& +k(c,b))return c}:function(b){return b[a]}))).slice(3))}}function n(a,b,c){return function(e,u){c||(u=e);var g=new d;this.forEach(function(g){var v,f=b?g.parentNode[b]:g;c&&(v=d(e,g.parentNode));do{if(v&&-1]*>/,A=I.isFunction,L=Array.prototype.map,r=Array.prototype.push,x=document.defaultView.getComputedStyle,H={},E={},m=d.fn=d.prototype=[];["map","filter","slice","reverse","sort"].forEach(function(a){var b=this["_"+a]=this[a];this[a]=function(){return d(b.apply(this,arguments))}},m);["splice","concat"].forEach(function(a){var b=this["_"+a]=this[a];this[a]=function(){return d(b.apply(this._slice(),L.call(arguments,function(a){return a._slice()})))}},m);f.mix(m, +{constructor:d,find:function(a){var b=new d,c;this===m?c=[l]:b.prevObject=c=this;if(/^#/.test(a))(c=(c[0]||l).getElementById(a.substr(1)))&&b.push(c);else{var e=/\W/.test(a)?"querySelectorAll":"getElementsByTagName";c[1]?c.forEach(function(b){this.push.apply(this,b[e](a))},b):c[0]&&b.push.apply(b,c[0][e](a))}return b},eq:function(a){return-1===a?this.slice(-1):this.slice(a,a+1)},not:function(a){return this.filter(function(b){return b&&!this(b,a)},k)},has:function(a){return this.filter(function(b){return this(b, +a)},k)},parent:t("parentNode"),parents:function(a){for(var b=new d,c=this,a=a?z(a,"parentNode"):function(a){return this[this.push(a.parentNode)-1]};c.length;)c=c.map(a,b);return b},closest:function(a){for(var b=new d,c=this,a=z(a,"parentNode");c.length&&!b.length;)c=c.map(a,b);return b.length&&b||this},siblings:n("nextElementSibling","firstElementChild"),next:t("nextElementSibling"),nextAll:n("nextElementSibling"),nextUntil:n("nextElementSibling",!1,!0),prev:t("prevElementSibling"),prevAll:n("prevElementSibling"), +prevUntil:n("prevElementSibling",!1,!0),children:function(){return f.merge.apply(f,this.map(function(a){return this(a.children)},d))},contents:function(){return f.merge.apply(f,this.map(function(a){return this(a.childNodes)},d))},is:function(a){return this.some(function(b){return k(b,a)})},hasClass:function(a){for(var b=0,c=this.length;b