Comparing version 0.2.69 to 0.2.70
@@ -1,16 +0,47 @@ | ||
/* version: 0.2.69 */ | ||
/* version: 0.2.70 */ | ||
var Absurd = (function(w) { | ||
var lib = { | ||
api: {}, | ||
helpers: {}, | ||
plugins: {}, | ||
processors: { | ||
css: { plugins: {}}, | ||
html: { | ||
plugins: {}, | ||
helpers: {} | ||
}, | ||
component: { plugins: {}} | ||
} | ||
api: {}, | ||
helpers: {}, | ||
plugins: {}, | ||
processors: { | ||
css: { plugins: {}}, | ||
html: { | ||
plugins: {}, | ||
helpers: {} | ||
}, | ||
component: { plugins: {}} | ||
} | ||
}; | ||
var require = function(v) { | ||
// css preprocessor | ||
if(v.indexOf('css/CSS.js') > 0 || v == '/../CSS.js') { | ||
return lib.processors.css.CSS; | ||
} else if(v.indexOf('html/HTML.js') > 0) { | ||
return lib.processors.html.HTML; | ||
} else if(v.indexOf('component/Component.js') > 0) { | ||
return lib.processors.component.Component; | ||
} else if(v == 'js-beautify') { | ||
return { | ||
html: function(html) { | ||
return html; | ||
} | ||
} | ||
} else if(v == './helpers/PropAnalyzer') { | ||
return lib.processors.html.helpers.PropAnalyzer; | ||
} else if(v == '../../helpers/TransformUppercase') { | ||
return lib.helpers.TransformUppercase; | ||
} else if(v == './helpers/TemplateEngine') { | ||
return lib.processors.html.helpers.TemplateEngine; | ||
} else if(v == '../helpers/Extend') { | ||
return lib.helpers.Extend; | ||
} else if(v == '../helpers/Clone') { | ||
return lib.helpers.Clone; | ||
} else if(v == '../helpers/Prefixes' || v == '/../../../helpers/Prefixes') { | ||
return lib.helpers.Prefixes; | ||
} else { | ||
return function() {} | ||
} | ||
}; | ||
var __dirname = ""; | ||
var queue = function(funcs, scope) { | ||
@@ -95,385 +126,303 @@ (function next() { | ||
} | ||
var require = function(v) { | ||
// css preprocessor | ||
if(v.indexOf('css/CSS.js') > 0 || v == '/../CSS.js') { | ||
return lib.processors.css.CSS; | ||
} else if(v.indexOf('html/HTML.js') > 0) { | ||
return lib.processors.html.HTML; | ||
} else if(v.indexOf('component/Component.js') > 0) { | ||
return lib.processors.component.Component; | ||
} else if(v == 'js-beautify') { | ||
return { | ||
html: function(html) { | ||
return html; | ||
} | ||
var createNode = function(type, attrs, content) { | ||
var node = document.createElement(type); | ||
for(var i=0; i<attrs.length, a=attrs[i]; i++) { | ||
node.setAttribute(a.name, a.value); | ||
} | ||
node.innerHTML = content; | ||
return node; | ||
} | ||
var Component = function(componentName, absurd, eventBus, cls) { | ||
var api = lib.helpers.Extend({ | ||
__name: componentName | ||
}, cls); | ||
var extend = lib.helpers.Extend; | ||
var l = []; | ||
api.listeners = l; | ||
api.on = function(eventName, callback, scope) { | ||
if(!l[eventName]) { | ||
l[eventName] = []; | ||
} | ||
l[eventName].push({callback: callback, scope: scope}); | ||
return this; | ||
}; | ||
api.off = function(eventName, handler) { | ||
if(!l[eventName]) return this; | ||
if(!handler) l[eventName] = []; return this; | ||
var newArr = []; | ||
for(var i=0; i<l[eventName].length; i++) { | ||
if(l[eventName][i].callback !== handler) { | ||
newArr.push(l[eventName][i]); | ||
} | ||
} else if(v == './helpers/PropAnalyzer') { | ||
return lib.processors.html.helpers.PropAnalyzer; | ||
} else if(v == '../../helpers/TransformUppercase') { | ||
return lib.helpers.TransformUppercase; | ||
} else if(v == './helpers/TemplateEngine') { | ||
return lib.processors.html.helpers.TemplateEngine; | ||
} else if(v == '../helpers/Extend') { | ||
return lib.helpers.Extend; | ||
} else if(v == '../helpers/Clone') { | ||
return lib.helpers.Clone; | ||
} else if(v == '../helpers/Prefixes' || v == '/../../../helpers/Prefixes') { | ||
return lib.helpers.Prefixes; | ||
} else { | ||
return function() {} | ||
} | ||
l[eventName] = newArr; | ||
return this; | ||
}; | ||
var __dirname = ""; | ||
var Observer = function(eventBus) { | ||
var listeners = []; | ||
return { | ||
listeners: listeners, | ||
on: function(eventName, callback, scope) { | ||
if(!listeners[eventName]) { | ||
listeners[eventName] = []; | ||
api.dispatch = function(eventName, data, scope) { | ||
if(data && typeof data === 'object' && !(data instanceof Array)) { | ||
data.target = this; | ||
} | ||
if(l[eventName]) { | ||
for(var i=0; i<l[eventName].length; i++) { | ||
var callback = l[eventName][i].callback; | ||
callback.apply(scope || l[eventName][i].scope || {}, [data]); | ||
} | ||
} | ||
if(this[eventName] && typeof this[eventName] === 'function') { | ||
this[eventName](data); | ||
} | ||
if(eventBus) eventBus.dispatch(eventName, data); | ||
return this; | ||
}; | ||
var storage = {}; | ||
api.set = function(key, value) { | ||
storage[key] = value; | ||
return this; | ||
}; | ||
api.get = function(key) { | ||
return storage[key]; | ||
}; | ||
var CSS = false; | ||
api.__handleCSS = function(next) { | ||
if(this.css) { | ||
absurd.flush().add(this.css).compile(function(err, css) { | ||
if(!CSS) { | ||
var style = createNode( | ||
'style', [ | ||
{ name: "id", value: componentName + '-css' }, | ||
{ name: "type", value: "text/css"} | ||
], | ||
css | ||
); | ||
(select("head") || select("body"))[0].appendChild(style); | ||
CSS = { raw: css, element: style }; | ||
} else if(CSS.raw !== css) { | ||
CSS.raw = css; | ||
CSS.element.innerHTML = css; | ||
} | ||
listeners[eventName].push({callback: callback, scope: scope}); | ||
return this; | ||
}, | ||
off: function(eventName, handler) { | ||
if(!listeners[eventName]) return this; | ||
if(!handler) listeners[eventName] = []; return this; | ||
var newArr = []; | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
if(listeners[eventName][i].callback !== handler) { | ||
newArr.push(listeners[eventName][i]); | ||
next(); | ||
}); | ||
} else { | ||
next(); | ||
} | ||
} | ||
var HTMLSource = false; | ||
api.__mergeDOMElements = function(e1, e2) { | ||
removeEmptyTextNodes(e1); | ||
removeEmptyTextNodes(e2); | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined' || e1.isEqualNode(e2)) return; | ||
// replace the whole node | ||
if(e1.nodeName !== e2.nodeName) { | ||
if(e1.parentNode) { | ||
e1.parentNode.replaceChild(e2, e1); | ||
} | ||
return; | ||
} | ||
// nodeValue | ||
if(e1.nodeValue !== e2.nodeValue) { | ||
e1.nodeValue = e2.nodeValue; | ||
} | ||
// attributes | ||
if(e1.attributes) { | ||
var attr1 = e1.attributes, attr2 = e2.attributes, a1, a2, found = {}; | ||
for(var i=0; i<attr1.length, a1=attr1[i]; i++) { | ||
for(var j=0; j<attr2.length, a2=attr2[j]; j++) { | ||
if(a1.name === a2.name) { | ||
e1.setAttribute(a1.name, a2.value); | ||
found[a1.name] = true; | ||
} | ||
} | ||
listeners[eventName] = newArr; | ||
return this; | ||
}, | ||
dispatch: function(eventName, data, scope) { | ||
if(data && typeof data === 'object' && !(data instanceof Array)) { | ||
data.target = this; | ||
if(!found[a1.name]) { | ||
e1.removeAttribute(a1.name); | ||
} | ||
if(listeners[eventName]) { | ||
for(var i=0; i<listeners[eventName].length; i++) { | ||
var callback = listeners[eventName][i].callback; | ||
callback.apply(scope || listeners[eventName][i].scope || {}, [data]); | ||
} | ||
} | ||
for(var i=0; i<attr2.length, a2=attr2[i]; i++) { | ||
if(!found[a2.name]) { | ||
e1.setAttribute(a2.name, a2.value); | ||
} | ||
if(this[eventName] && typeof this[eventName] === 'function') { | ||
this[eventName](data); | ||
} | ||
if(eventBus) eventBus.dispatch(eventName, data); | ||
return this; | ||
} | ||
} | ||
} | ||
var Component = function(componentName, absurd) { | ||
var CSS = false, | ||
HTMLSource = false, | ||
HTMLElement = false, | ||
extend = lib.helpers.Extend, | ||
storage = {}, | ||
appended = false, | ||
async = { funcs: {}, index: 0 }, | ||
cache = { events: {} }; | ||
var handleCSS = function(next) { | ||
if(this.css) { | ||
absurd.flush().add(this.css).compile(function(err, css) { | ||
if(!CSS) { | ||
var style = document.createElement("style"); | ||
style.setAttribute("id", componentName + '-css'); | ||
style.setAttribute("type", "text/css"); | ||
style.innerHTML = css; | ||
(select("head") || select("body"))[0].appendChild(style); | ||
CSS = { raw: css, element: style }; | ||
} else if(CSS.raw !== css) { | ||
CSS.raw = css; | ||
CSS.element.innerHTML = css; | ||
} | ||
next(); | ||
}); | ||
} else { | ||
next(); | ||
// childs | ||
var newNodesToMerge = []; | ||
if(e1.childNodes.length >= e2.childNodes.length) { | ||
for(var i=0; i<e1.childNodes.length; i++) { | ||
if(!e2.childNodes[i]) { e2.appendChild(document.createTextNode("")); } | ||
newNodesToMerge.push([e1.childNodes[i], e2.childNodes[i]]); | ||
} | ||
} else { | ||
for(var i=0; i<e2.childNodes.length; i++) { | ||
e1.appendChild(document.createTextNode("")); | ||
newNodesToMerge.push([e1.childNodes[i], e2.childNodes[i]]); | ||
} | ||
} | ||
var setHTMLSource = function(next) { | ||
if(this.html) { | ||
if(typeof this.html === 'string') { | ||
if(HTMLElement === false) { | ||
var element = select(this.html); | ||
if(element.length > 0) { | ||
HTMLElement = element[0]; | ||
} | ||
HTMLSource = {'': HTMLElement.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
} | ||
next(); | ||
} else if(typeof this.html === 'object') { | ||
HTMLSource = extend({}, this.html); | ||
if(HTMLElement === false) { | ||
absurd.flush().morph("html").add(HTMLSource).compile(function(err, html) { | ||
HTMLElement = str2DOMElement(html); | ||
next(true); | ||
}, this); | ||
} else { | ||
next(); | ||
} | ||
for(var i=0; i<newNodesToMerge.length; i++) { | ||
api.__mergeDOMElements(newNodesToMerge[i][0], newNodesToMerge[i][1]); | ||
} | ||
}; | ||
api.__handleHTML = function(next) { | ||
var self = this; | ||
var compile = function() { | ||
absurd.flush().morph("html").add(HTMLSource).compile(function(err, html) { | ||
if(!self.el) { | ||
self.el = str2DOMElement(html); | ||
} else { | ||
next(); | ||
api.__mergeDOMElements(self.el, str2DOMElement(html)); | ||
} | ||
} else { | ||
next(); | ||
} | ||
}, self); | ||
} | ||
var handleHTML = function(next, skipCompilation) { | ||
if(HTMLSource && skipCompilation !== true) { | ||
absurd.flush().morph("html").add(HTMLSource).compile(function(err, html) { | ||
(function merge(e1, e2) { | ||
removeEmptyTextNodes(e1); | ||
removeEmptyTextNodes(e2); | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined' || e1.isEqualNode(e2)) return; | ||
// replace the whole node | ||
if(e1.nodeName !== e2.nodeName) { | ||
if(e1.parentNode) { | ||
e1.parentNode.replaceChild(e2, e1); | ||
} | ||
return; | ||
} | ||
// nodeValue | ||
if(e1.nodeValue !== e2.nodeValue) { | ||
e1.nodeValue = e2.nodeValue; | ||
} | ||
// attributes | ||
if(e1.attributes) { | ||
var attr1 = e1.attributes, attr2 = e2.attributes, a1, a2, found = {}; | ||
for(var i=0; i<attr1.length, a1=attr1[i]; i++) { | ||
for(var j=0; j<attr2.length, a2=attr2[j]; j++) { | ||
if(a1.name === a2.name) { | ||
e1.setAttribute(a1.name, a2.value); | ||
found[a1.name] = true; | ||
} | ||
} | ||
if(!found[a1.name]) { | ||
e1.removeAttribute(a1.name); | ||
} | ||
} | ||
for(var i=0; i<attr2.length, a2=attr2[i]; i++) { | ||
if(!found[a2.name]) { | ||
e1.setAttribute(a2.name, a2.value); | ||
} | ||
} | ||
} | ||
// childs | ||
var newNodesToMerge = []; | ||
if(e1.childNodes.length >= e2.childNodes.length) { | ||
for(var i=0; i<e1.childNodes.length; i++) { | ||
if(!e2.childNodes[i]) { e2.appendChild(document.createTextNode("")); } | ||
newNodesToMerge.push([e1.childNodes[i], e2.childNodes[i]]); | ||
} | ||
} else { | ||
for(var i=0; i<e2.childNodes.length; i++) { | ||
e1.appendChild(document.createTextNode("")); | ||
newNodesToMerge.push([e1.childNodes[i], e2.childNodes[i]]); | ||
} | ||
} | ||
for(var i=0; i<newNodesToMerge.length; i++) { | ||
merge(newNodesToMerge[i][0], newNodesToMerge[i][1]); | ||
} | ||
})(HTMLElement, str2DOMElement(html)); | ||
next(); | ||
}, this); | ||
if(this.html) { | ||
if(typeof this.html === 'string') { | ||
if(!this.el) { | ||
var element = select(this.html); | ||
this.el = element[0]; | ||
HTMLSource = {'': this.el.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
} | ||
compile(); | ||
} else if(typeof this.html === 'object') { | ||
HTMLSource = extend({}, this.html); | ||
compile(); | ||
} else { | ||
next(); | ||
} | ||
} else { | ||
next(); | ||
} | ||
var handleAsyncFunctions = function(next) { | ||
if(HTMLElement) { | ||
var funcs = []; | ||
if(HTMLElement.hasAttribute && HTMLElement.hasAttribute("data-absurd-async")) { | ||
funcs.push(HTMLElement); | ||
} else { | ||
var els = HTMLElement.querySelectorAll ? HTMLElement.querySelectorAll('[data-absurd-async]') : []; | ||
for(var i=0; i<els.length; i++) { | ||
funcs.push(els[i]); | ||
}; | ||
var appended = false | ||
api.__append = function(next) { | ||
if(!appended && this.el && this.get("parent")) { | ||
appended = true; | ||
this.get("parent").appendChild(this.el); | ||
} | ||
next(); | ||
} | ||
var cache = { events: {} }; | ||
api.__handleEvents = function(next) { | ||
if(this.el) { | ||
var self = this; | ||
var registerEvent = function(el) { | ||
var attrValue = el.getAttribute('data-absurd-event'); | ||
attrValue = attrValue.split(":"); | ||
if(attrValue.length >= 2) { | ||
if(!cache.events[attrValue[0]] || cache.events[attrValue[0]].indexOf(el) < 0) { | ||
if(!cache.events[attrValue[0]]) cache.events[attrValue[0]] = []; | ||
cache.events[attrValue[0]].push(el); | ||
addEventListener(el, attrValue[0], function(e) { | ||
if(typeof self[attrValue[1]] === 'function') { | ||
self[attrValue[1]](e); | ||
} | ||
}); | ||
} | ||
} | ||
if(funcs.length === 0) { | ||
next(); | ||
} else { | ||
var self = this; | ||
(function callFuncs() { | ||
if(funcs.length === 0) { | ||
next(); | ||
} else { | ||
var el = funcs.shift(), | ||
value = el.getAttribute("data-absurd-async"), | ||
replaceNodes = function(childElement) { | ||
if(typeof childElement === 'string') { | ||
el.parentNode.replaceChild(str2DOMElement(childElement), el); | ||
} else { | ||
el.parentNode.replaceChild(childElement, el); | ||
} | ||
callFuncs(); | ||
}; | ||
if(typeof self[async.funcs[value].name] === 'function') { | ||
self[async.funcs[value].name].apply(self, [replaceNodes].concat(async.funcs[value].args)); | ||
} else if(typeof async.funcs[value].func === 'function') { | ||
async.funcs[value].func.apply(self, [replaceNodes].concat(async.funcs[value].args)); | ||
} | ||
} | ||
})(); | ||
} | ||
} | ||
if(this.el.hasAttribute && this.el.hasAttribute('data-absurd-event')) { | ||
registerEvent(this.el); | ||
} | ||
var els = this.el.querySelectorAll ? this.el.querySelectorAll('[data-absurd-event]') : []; | ||
for(var i=0; i<els.length; i++) { | ||
registerEvent(els[i]); | ||
} | ||
} | ||
next(); | ||
} | ||
var async = { funcs: {}, index: 0 }; | ||
api.__handleAsyncFunctions = function(next) { | ||
if(this.el) { | ||
var funcs = []; | ||
if(this.el.hasAttribute && this.el.hasAttribute("data-absurd-async")) { | ||
funcs.push(this.el); | ||
} else { | ||
var els = this.el.querySelectorAll ? this.el.querySelectorAll('[data-absurd-async]') : []; | ||
for(var i=0; i<els.length; i++) { | ||
funcs.push(els[i]); | ||
} | ||
} | ||
if(funcs.length === 0) { | ||
next(); | ||
} | ||
} | ||
var append = function(next) { | ||
if(!appended && HTMLElement && this.get("parent")) { | ||
appended = true; | ||
this.get("parent").appendChild(HTMLElement); | ||
} | ||
next(); | ||
} | ||
var handleEvents = function(next) { | ||
if(HTMLElement) { | ||
} else { | ||
var self = this; | ||
var registerEvent = function(el) { | ||
var attrValue = el.getAttribute('data-absurd-event'); | ||
attrValue = attrValue.split(":"); | ||
if(attrValue.length >= 2) { | ||
if(!cache.events[attrValue[0]] || cache.events[attrValue[0]].indexOf(el) < 0) { | ||
if(!cache.events[attrValue[0]]) cache.events[attrValue[0]] = []; | ||
cache.events[attrValue[0]].push(el); | ||
addEventListener(el, attrValue[0], function(e) { | ||
if(typeof self[attrValue[1]] === 'function') { | ||
self[attrValue[1]](e); | ||
(function callFuncs() { | ||
if(funcs.length === 0) { | ||
next(); | ||
} else { | ||
var el = funcs.shift(), | ||
value = el.getAttribute("data-absurd-async"), | ||
replaceNodes = function(childElement) { | ||
if(typeof childElement === 'string') { | ||
el.parentNode.replaceChild(str2DOMElement(childElement), el); | ||
} else { | ||
el.parentNode.replaceChild(childElement, el); | ||
} | ||
}); | ||
callFuncs(); | ||
}; | ||
if(typeof self[async.funcs[value].name] === 'function') { | ||
self[async.funcs[value].name].apply(self, [replaceNodes].concat(async.funcs[value].args)); | ||
} else if(typeof async.funcs[value].func === 'function') { | ||
async.funcs[value].func.apply(self, [replaceNodes].concat(async.funcs[value].args)); | ||
} | ||
} | ||
} | ||
if(HTMLElement.hasAttribute && HTMLElement.hasAttribute('data-absurd-event')) { | ||
registerEvent(HTMLElement); | ||
} | ||
var els = HTMLElement.querySelectorAll ? HTMLElement.querySelectorAll('[data-absurd-event]') : []; | ||
for(var i=0; i<els.length; i++) { | ||
registerEvent(els[i]); | ||
} | ||
} | ||
})(); | ||
} | ||
} else { | ||
next(); | ||
} | ||
var component = { | ||
__name: componentName, | ||
populate: function(options) { | ||
queue([ | ||
handleCSS, | ||
setHTMLSource, | ||
handleHTML, | ||
append, | ||
handleEvents, | ||
handleAsyncFunctions, | ||
function() { | ||
async = { funcs: {}, index: 0 } | ||
var data = { | ||
css: CSS, | ||
html: { | ||
element: HTMLElement | ||
} | ||
}; | ||
this.dispatch("populated", data); | ||
if(options && typeof options.callback === 'function') { options.callback(data); } | ||
} | ||
} | ||
api.async = function() { | ||
var args = Array.prototype.slice.call(arguments, 0), | ||
func = args.shift(), | ||
index = '_' + (async.index++); | ||
async.funcs[index] = {args: args, name: func}; | ||
return '<script data-absurd-async="' + index + '"></script>'; | ||
}; | ||
api.child = function() { | ||
var args = Array.prototype.slice.call(arguments, 0), | ||
children = this.get("children"), | ||
component = children && children[args.shift()], | ||
index = '_' + (async.index++); | ||
async.funcs[index] = {args: args, func: function(callback) { | ||
component.populate({callback: function(data) { | ||
callback(data.html.element); | ||
}}); | ||
}}; | ||
return '<script data-absurd-async="' + index + '"></script>'; | ||
}; | ||
api.wire = function(event) { | ||
absurd.components.events.on(event, this[event] || function() {}, this); | ||
}; | ||
api.populate = function(options) { | ||
queue([ | ||
api.__handleCSS, | ||
api.__handleHTML, | ||
api.__append, | ||
api.__handleEvents, | ||
api.__handleAsyncFunctions, | ||
function() { | ||
async = { funcs: {}, index: 0 } | ||
var data = { | ||
css: CSS, | ||
html: { | ||
element: this.el | ||
} | ||
], this); | ||
return this; | ||
}, | ||
el: function() { | ||
return HTMLElement; | ||
}, | ||
set: function(key, value) { | ||
storage[key] = value; | ||
return this; | ||
}, | ||
get: function(key) { | ||
return storage[key]; | ||
}, | ||
wire: function(event) { | ||
absurd.components.events.on(event, this[event] || function() {}, this); | ||
}, | ||
async: function() { | ||
var args = Array.prototype.slice.call(arguments, 0), | ||
func = args.shift(), | ||
index = '_' + (async.index++); | ||
async.funcs[index] = {args: args, name: func}; | ||
return '<script data-absurd-async="' + index + '"></script>'; | ||
}, | ||
child: function() { | ||
var args = Array.prototype.slice.call(arguments, 0), | ||
children = this.get("children"), | ||
component = children && children[args.shift()], | ||
index = '_' + (async.index++); | ||
async.funcs[index] = {args: args, func: function(callback) { | ||
component.populate({callback: function(data) { | ||
callback(data.html.element); | ||
}}); | ||
}}; | ||
return '<script data-absurd-async="' + index + '"></script>'; | ||
}; | ||
this.dispatch("populated", data); | ||
if(options && typeof options.callback === 'function') { options.callback(data); } | ||
} | ||
], this); | ||
return api; | ||
}; | ||
api.utils = { | ||
str2DOMElement: str2DOMElement, | ||
addEventListener: addEventListener, | ||
queue: queue, | ||
compileHTML: function(HTML, data, callback) { | ||
absurd.flush().morph("html").add(HTML).compile(callback, data); | ||
}, | ||
compileCSS: function(CSS, data, callback) { | ||
absurd.flush().add(CSS).compile(callback, data); | ||
} | ||
return component; | ||
} | ||
var component = function(api) { | ||
return function(name, cls) { | ||
if(typeof cls == 'undefined') { | ||
return api.components.get(name); | ||
} else { | ||
return api.components.register(name, cls); | ||
} | ||
} | ||
} | ||
var components = function(absurd) { | ||
var extend = lib.helpers.Extend, | ||
clone = lib.helpers.Clone, | ||
api = {}, | ||
comps = {}, | ||
instances = []; | ||
api.events = extend({}, Observer()); | ||
api.register = function(name, cls) { | ||
return comps[name] = function() { | ||
var c = extend({}, Observer(api.events), Component(name, absurd), clone(cls)); | ||
absurd.di.resolveObject(c); | ||
instances.push(c); | ||
if(typeof c.constructor === 'function') { | ||
c.constructor.apply(c, Array.prototype.slice.call(arguments, 0)); | ||
} | ||
return c; | ||
}; | ||
} | ||
api.get = function(name) { | ||
if(comps[name]) { return comps[name]; } | ||
else { throw new Error("There is no component with name '" + name + "'."); } | ||
} | ||
api.remove = function(name) { | ||
if(comps[name]) { delete comps[name]; return true; } | ||
return false; | ||
} | ||
api.list = function() { | ||
var l = []; | ||
for(var name in comps) l.push(name); | ||
return l; | ||
} | ||
api.flush = function() { | ||
comps = {}; | ||
instances = []; | ||
return api; | ||
} | ||
api.broadcast = function(event, data) { | ||
for(var i=0; i<instances.length, instance=instances[i]; i++) { | ||
if(typeof instance[event] === 'function') { | ||
instance[event](data); | ||
} | ||
} | ||
return api; | ||
} | ||
return api; | ||
} | ||
}; | ||
var client = function() { | ||
@@ -493,3 +442,5 @@ return function(arg) { | ||
var _api = { defaultProcessor: lib.processors.css.CSS() }, | ||
var _api = { | ||
defaultProcessor: lib.processors.css.CSS() | ||
}, | ||
_rules = {}, | ||
@@ -550,5 +501,63 @@ _storage = {}, | ||
_api.numOfAddedRules = 0; | ||
_api.components = components(_api); | ||
_api.component = component(_api); | ||
// absurd.components API | ||
_api.components = (function(api) { | ||
var extend = lib.helpers.Extend, | ||
clone = lib.helpers.Clone, | ||
comps = {}, | ||
instances = [], | ||
events = extend({}, Component()); | ||
return { | ||
events: events, | ||
register: function(name, cls) { | ||
return comps[name] = function() { | ||
var c = extend({}, Component(name, api, events, clone(cls))); | ||
api.di.resolveObject(c); | ||
instances.push(c); | ||
if(typeof c.constructor === 'function') { | ||
c.constructor.apply(c, Array.prototype.slice.call(arguments, 0)); | ||
} | ||
return c; | ||
}; | ||
}, | ||
get: function(name) { | ||
if(comps[name]) { return comps[name]; } | ||
else { throw new Error("There is no component with name '" + name + "'."); } | ||
}, | ||
remove: function(name) { | ||
if(comps[name]) { delete comps[name]; return true; } | ||
return false; | ||
}, | ||
list: function() { | ||
var l = []; | ||
for(var name in comps) l.push(name); | ||
return l; | ||
}, | ||
flush: function() { | ||
comps = {}; | ||
instances = []; | ||
return this; | ||
}, | ||
broadcast: function(event, data) { | ||
for(var i=0; i<instances.length, instance=instances[i]; i++) { | ||
if(typeof instance[event] === 'function') { | ||
instance[event](data); | ||
} | ||
} | ||
return this; | ||
} | ||
} | ||
})(_api); | ||
// absurd.component shortcut | ||
_api.component = (function(api) { | ||
return function(name, cls) { | ||
if(typeof cls == 'undefined') { | ||
return api.components.get(name); | ||
} else { | ||
return api.components.register(name, cls); | ||
} | ||
} | ||
})(_api); | ||
// dependency injector | ||
@@ -610,4 +619,3 @@ _api.di = lib.DI(_api); | ||
} | ||
} | ||
lib.DI = function(api) { | ||
};lib.DI = function(api) { | ||
var injector = { | ||
@@ -614,0 +622,0 @@ dependencies: {}, |
@@ -1,1 +0,1 @@ | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}}},b=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},d=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},e=function(a){var b={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[1,"<div>","</div>"]};b.optgroup=b.option,b.tbody=b.tfoot=b.colgroup=b.caption=b.thead,b.th=b.td;var c=document.createElement("div"),d=/<\s*\w.*?>/g.exec(a);if(null!=d){var c,e=d[0].replace(/</g,"").replace(/>/g,""),f=b[e]||b._default;a=f[1]+a+f[2],c.innerHTML=a;for(var g=f[0]+1;g--;)c=c.lastChild}else c.innerHTML=a,c=c.lastChild;return c},f=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},g=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType&&f.test(b.nodeValue)&&(a.removeChild(b),e--,d--);return a},h=function(b){return b.indexOf("css/CSS.js")>0||"/../CSS.js"==b?a.processors.css.CSS:b.indexOf("html/HTML.js")>0?a.processors.html.HTML:b.indexOf("component/Component.js")>0?a.processors.component.Component:"js-beautify"==b?{html:function(a){return a}}:"./helpers/PropAnalyzer"==b?a.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==b?a.helpers.TransformUppercase:"./helpers/TemplateEngine"==b?a.processors.html.helpers.TemplateEngine:"../helpers/Extend"==b?a.helpers.Extend:"../helpers/Clone"==b?a.helpers.Clone:"../helpers/Prefixes"==b||"/../../../helpers/Prefixes"==b?a.helpers.Prefixes:function(){}},i="",j=function(a){var b=[];return{listeners:b,on:function(a,c,d){return b[a]||(b[a]=[]),b[a].push({callback:c,scope:d}),this},off:function(a,c){return b[a]?(c||(b[a]=[]),this):this},dispatch:function(c,d,e){if(!d||"object"!=typeof d||d instanceof Array||(d.target=this),b[c])for(var f=0;f<b[c].length;f++){var g=b[c][f].callback;g.apply(e||b[c][f].scope||{},[d])}return this[c]&&"function"==typeof this[c]&&this[c](d),a&&a.dispatch(c,d),this}}},k=function(c,h){var i=!1,j=!1,k=!1,l=a.helpers.Extend,m={},n=!1,o={funcs:{},index:0},p={events:{}},q=function(a){this.css?h.flush().add(this.css).compile(function(b,e){if(i)i.raw!==e&&(i.raw=e,i.element.innerHTML=e);else{var f=document.createElement("style");f.setAttribute("id",c+"-css"),f.setAttribute("type","text/css"),f.innerHTML=e,(d("head")||d("body"))[0].appendChild(f),i={raw:e,element:f}}a()}):a()},r=function(a){if(this.html)if("string"==typeof this.html){if(k===!1){var b=d(this.html);b.length>0&&(k=b[0]),j={"":k.outerHTML.replace(/</g,"<").replace(/>/g,">")}}a()}else"object"==typeof this.html?(j=l({},this.html),k===!1?h.flush().morph("html").add(j).compile(function(b,c){k=e(c),a(!0)},this):a()):a();else a()},s=function(a,b){j&&b!==!0?h.flush().morph("html").add(j).compile(function(b,c){!function d(a,b){if(g(a),g(b),"undefined"!=typeof a&&"undefined"!=typeof b&&!a.isEqualNode(b)){if(a.nodeName!==b.nodeName)return a.parentNode&&a.parentNode.replaceChild(b,a),void 0;if(a.nodeValue!==b.nodeValue&&(a.nodeValue=b.nodeValue),a.attributes){for(var c,e,f=a.attributes,h=b.attributes,i={},j=0;j<f.length,c=f[j];j++){for(var k=0;k<h.length,e=h[k];k++)c.name===e.name&&(a.setAttribute(c.name,e.value),i[c.name]=!0);i[c.name]||a.removeAttribute(c.name)}for(var j=0;j<h.length,e=h[j];j++)i[e.name]||a.setAttribute(e.name,e.value)}var l=[];if(a.childNodes.length>=b.childNodes.length)for(var j=0;j<a.childNodes.length;j++)b.childNodes[j]||b.appendChild(document.createTextNode("")),l.push([a.childNodes[j],b.childNodes[j]]);else for(var j=0;j<b.childNodes.length;j++)a.appendChild(document.createTextNode("")),l.push([a.childNodes[j],b.childNodes[j]]);for(var j=0;j<l.length;j++)d(l[j][0],l[j][1])}}(k,e(c)),a()},this):a()},t=function(a){if(k){var b=[];if(k.hasAttribute&&k.hasAttribute("data-absurd-async"))b.push(k);else for(var c=k.querySelectorAll?k.querySelectorAll("[data-absurd-async]"):[],d=0;d<c.length;d++)b.push(c[d]);if(0===b.length)a();else{var f=this;!function g(){if(0===b.length)a();else{var c=b.shift(),d=c.getAttribute("data-absurd-async"),h=function(a){"string"==typeof a?c.parentNode.replaceChild(e(a),c):c.parentNode.replaceChild(a,c),g()};"function"==typeof f[o.funcs[d].name]?f[o.funcs[d].name].apply(f,[h].concat(o.funcs[d].args)):"function"==typeof o.funcs[d].func&&o.funcs[d].func.apply(f,[h].concat(o.funcs[d].args))}}()}}else a()},u=function(a){!n&&k&&this.get("parent")&&(n=!0,this.get("parent").appendChild(k)),a()},v=function(a){if(k){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!p.events[c[0]]||p.events[c[0]].indexOf(a)<0)&&(p.events[c[0]]||(p.events[c[0]]=[]),p.events[c[0]].push(a),f(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};k.hasAttribute&&k.hasAttribute("data-absurd-event")&&c(k);for(var d=k.querySelectorAll?k.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()},w={__name:c,populate:function(a){return b([q,r,s,u,v,t,function(){o={funcs:{},index:0};var b={css:i,html:{element:k}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this),this},el:function(){return k},set:function(a,b){return m[a]=b,this},get:function(a){return m[a]},wire:function(a){h.components.events.on(a,this[a]||function(){},this)},async:function(){var a=Array.prototype.slice.call(arguments,0),b=a.shift(),c="_"+o.index++;return o.funcs[c]={args:a,name:b},'<script data-absurd-async="'+c+'"></script>'},child:function(){var a=Array.prototype.slice.call(arguments,0),b=this.get("children"),c=b&&b[a.shift()],d="_"+o.index++;return o.funcs[d]={args:a,func:function(a){c.populate({callback:function(b){a(b.html.element)}})}},'<script data-absurd-async="'+d+'"></script>'}};return w},l=function(a){return function(b,c){return"undefined"==typeof c?a.components.get(b):a.components.register(b,c)}},m=function(b){var c=a.helpers.Extend,d=a.helpers.Clone,e={},f={},g=[];return e.events=c({},j()),e.register=function(a,h){return f[a]=function(){var f=c({},j(e.events),k(a,b),d(h));return b.di.resolveObject(f),g.push(f),"function"==typeof f.constructor&&f.constructor.apply(f,Array.prototype.slice.call(arguments,0)),f}},e.get=function(a){if(f[a])return f[a];throw new Error("There is no component with name '"+a+"'.")},e.remove=function(a){return f[a]?(delete f[a],!0):!1},e.list=function(){var a=[];for(var b in f)a.push(b);return a},e.flush=function(){return f={},g=[],e},e.broadcast=function(a,b){for(var c=0;c<g.length,instance=g[c];c++)"function"==typeof instance[a]&&instance[a](b);return e},e},n=function(){return function(b){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:a.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){return f={},g=[],i={},e.defaultProcessor=a.processors.css.CSS(),e},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.components=m(e),e.component=l(e),e.di=a.DI(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in a.api)"compile"!==j&&(e[j]=a.api[j](e),e[j]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(j));for(var k in a.processors.css.plugins)e.plugin(k,a.processors.css.plugins[k]());return"function"==typeof b&&b(e),"undefined"!=typeof Organic&&Organic.init(e),e}};a.DI=function(){var a={dependencies:{},register:function(a,b){return this.dependencies[a]=b,this},resolve:function(){var a,b,c,d=this,e=!1;"string"==typeof arguments[0]?(a=arguments[1],b=arguments[0].replace(/ /g,"").split(","),c=arguments[2]||{}):(a=arguments[0],b=a.toString().match(/^function\s*[^\(]*\(\s*([^\)]*)\)/m)[1].replace(/ /g,"").split(","),c=arguments[1]||{});for(var f=0;f<b.length;f++)"undefined"!=typeof this.dependencies[b[f]]&&(e=!0);return e?function(){for(var e=[],f=Array.prototype.slice.call(arguments,0),g=0;g<b.length;g++){var h=b[g];e.push(d.dependencies[h]&&""!=h?d.dependencies[h]:f.shift())}return a.apply(c,e)}:a},resolveObject:function(a){if("object"==typeof a)for(var b in a)"function"==typeof a[b]?a[b]=this.resolve(a[b],a):a[b]instanceof Array&&2==a[b].length&&"string"==typeof a[b][0]&&"function"==typeof a[b][1]&&(a[b]=this.resolve(a[b][0],a[b][1],a));return this},flush:function(){return this.dependencies={},this}};return a},a.api.add=function(a){var b=(h("../helpers/Extend"),h("../helpers/Prefixes")),c=[],d=function(c,d,f,g,h){var i=b.nonPrefixProp(d),j=a.getPlugins()[i.prop];if("undefined"!=typeof j){var k=j(a,f,i.prefix);return k&&e(c,k,g,h),!0}return!1},e=function(a,f,g,h){if(g=g||"mainstream",/, ?/g.test(a))for(var i=a.replace(/, /g,",").split(","),j=0;j<i.length,p=i[j];j++)e(p,f,g,h);else if("undefined"==typeof f.length||"object"!=typeof f){if(!d(null,a,f,g,h)){var k={},l=a,m={},n={};for(var o in f){var q=typeof f[o];"object"!==q&&"function"!==q?d(a,o,f[o],g,h)===!1&&(l="undefined"!=typeof h?h+" "+a:a,k[o]=f[o],b.addPrefixes(o,k)):"object"===q?m[o]=f[o]:"function"===q&&(n[o]=f[o])}c.push({selector:l,props:k,stylesheet:g});for(var o in m)if(":"===o.charAt(0))e(a+o,m[o],g,h);else if(/&/g.test(o))if(/, ?/g.test(o))for(var i=o.replace(/, /g,",").split(","),j=0;j<i.length,p=i[j];j++)p.indexOf("&")>=0?e(p.replace(/&/g,a),m[o],g,h):e(p,m[o],g,"undefined"!=typeof h?h+" "+a:a);else e(o.replace(/&/g,a),m[o],g,h);else 0===o.indexOf("@media")||0===o.indexOf("@supports")?e(a,m[o],o,h):0===a.indexOf("@media")||0===o.indexOf("@supports")?e(o,m[o],a,h):d(a,o,m[o],g,h)===!1&&e(o,m[o],g,(h?h+" ":"")+a);for(var o in n){var r={};r[o]=n[o](),e(a,r,g,h)}}}else for(var j=0;j<f.length,o=f[j];j++)e(a,o,g,h)},f=function(b,d){c=[],a.numOfAddedRules+=1;var f=a.defaultProcessor.type;for(var g in b)e(g,b[g],d||"mainstream");for(var h=0;h<c.length;h++){var d=c[h].stylesheet,g=c[h].selector,i=c[h].props,j=a.getRules(d),k=j[g]||{};for(var l in i){var m=i[l];"object"!=typeof m&&(k[l]="css"==f?"+"===m.toString().charAt(0)?k&&k[l]?k[l]+", "+m.substr(1,m.length-1):m.substr(1,m.length-1):">"===m.toString().charAt(0)?k&&k[l]?k[l]+" "+m.substr(1,m.length-1):m.substr(1,m.length-1):m:m)}j[g]=k}return a};return f};var q=h("../helpers/Extend");a.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=q(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{t.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var r=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.darken=function(){return function(a,b){return r(a,-(b/100))}},a.api.define=function(a){return function(b,c){return a.getStorage().__defined||(a.getStorage().__defined={}),a.getStorage().__defined[b]=c,a}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var r=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.lighten=function(){return function(a,b){return r(a,b/100)}};var s={html:function(a){a.defaultProcessor=h(i+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=h(i+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};a.api.morph=function(a){return function(b){return s[b]&&(a.flush(),s[b](a)),a}},a.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},a.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}};{var t=h("fs");h("path")}a.api.rawImport=function(a){var b=function(b){var c=t.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return a}},a.api.register=function(a){return function(b,c){return a[b]=c,a}},a.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},a.helpers.Clone=function N(a){if(!a)return a;var b,c=[Number,String,Boolean];if(c.forEach(function(c){a instanceof c&&(b=c(a))}),"undefined"==typeof b)if("[object Array]"===Object.prototype.toString.call(a))b=[],a.forEach(function(a,c){b[c]=N(a)});else if("object"==typeof a)if(a.nodeType&&"function"==typeof a.cloneNode)var b=a.cloneNode(!0);else if(a.prototype)b=a;else if(a instanceof Date)b=new Date(a);else{b={};for(var d in a)b[d]=N(a[d])}else b=a;return b},a.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},a.helpers.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b};var u=function(a){var b,c;return(c=a.match(/^\-(w|m|s|o)+\-/)||"-"===a.charAt(0))?null!==c&&c[0]?(b={prefix:c[0].replace(/-/g,"")},b.prop=a.replace(c[0],"")):(b={prefix:""},b.prop=a.substr(1,a.length)):b={prefix:!1,prop:a},b};a.helpers.Prefixes={addPrefixes:function(a,b){var c=a,d=u(a),e=b[a];d.prefix!==!1&&(delete b[c],b[d.prop]=e,(""===d.prefix||d.prefix.indexOf("w")>=0)&&(b["-webkit-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("m")>=0)&&(b["-moz-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("s")>=0)&&(b["-ms-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("o")>=0)&&(b["-o-"+d.prop]=e))},nonPrefixProp:function(a){var b=u(a);return b.prefix!==!1&&(b.prefix=""==b.prefix?"-":"-"+b.prefix+"-"),b}},a.helpers.RequireUncached=function(a){return delete h.cache[h.resolve(a)],h(a)},a.helpers.TransformUppercase=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};var w=function(a,b,d){var e="",f="",g=[],j=d.api;cssPreprocessor=h(i+"/../css/CSS.js")(),htmlPreprocessor=h(i+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<g.length,l=g[b];b++)"function"==typeof l&&(l=l()),j.add(l.css?l.css:{});cssPreprocessor(j.getRules(),function(b,c){e+=c,a(b)},d)},m=function(b){var c=0,e=null,g=function(){if(c>a.length-1)return b(e),void 0;var h=a[c];"function"==typeof h&&(h=h()),j.morph("html").add(h.html?h.html:{}),htmlPreprocessor(j.getRules(),function(a,b){f+=b,c+=1,e=a,g()},d)};g()},n=function(a){for(var b in a)if("_include"===b)if(a[b]instanceof Array)for(var d=0;d<a[b].length,c=a[b][d];d++)"function"==typeof c&&(c=c()),g.push(c),n(c);else"function"==typeof a[b]&&(a[b]=a[b]()),g.push(a[b]),n(a[b]);else"object"==typeof a[b]&&n(a[b])},o=0;o<a.length,c=a[o];o++)"function"==typeof c&&(c=c()),g.push(c),n(c);j.flush(),k(function(a){j.morph("html"),m(function(c){b(a||c?{error:{css:a,html:c}}:null,e,f)})})};a.processors.component.Component=function(){var a=function(a,b,c){w(a.mainstream,b,c)};return a.type="component",a};var x="\n",y={combineSelectors:!0,minify:!1,keepCamelCase:!1},z=h("../../helpers/TransformUppercase"),A=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+x;else{var e=d+" {"+x;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=b&&b.keepCamelCase===!0?" "+f+": "+g+";"+x:" "+z(f)+": "+g+";"+x}e+="}"+x,c+=e}return c},B=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},C=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")},D=function(a,b){if(b&&b.api&&b.api.getStorage().__defined){var c=b.api.getStorage().__defined;for(var d in c){var e=new RegExp("<%( )?"+d+"( )?%>","g");a="function"!=typeof c[d]?a.replace(e,c[d]):a.replace(e,c[d]())}}return a};a.processors.css.CSS=function(){var a=function(a,b,c){c=c||y;var d="";for(var e in a){var f=a[e];f=c.combineSelectors?B(f):f,d+="mainstream"===e?A(f,c):e+" {"+x+A(f,c)+"}"+x}return d=D(d,c),c.minify?(d=C(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},a.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},a.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},a.processors.css.plugins.keyframes=function(){return function(a,b){var c=h(i+"/../CSS.js")(),d=h(i+"/../../../helpers/Prefixes");if("object"==typeof b)if("undefined"!=typeof b.frames){for(var e in b.frames)for(var f in b.frames[e])d.addPrefixes(f,b.frames[e]);var g="@keyframes "+b.name+" {\n";g+=c({mainstream:b.frames}),g+="}",a.raw(g+"\n"+g.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var g="@keyframes "+b.name+" {\n",j={},k=0;rule=b.keyframes[k];k++)if("keyframe"===rule.type)for(var l=j[rule.values]={},m=0;declaration=rule.declarations[m];m++)"declaration"===declaration.type&&(l[declaration.property]=declaration.value);g+=c({mainstream:j}),g+="}",a.raw(g+"\n"+g.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@media "+b.media+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}},a.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},a.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},a.processors.css.plugins.supports=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@supports "+b.supports+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}};var E=null,x="\n",y={},F=h("js-beautify").html,G=h("../../helpers/TransformUppercase"),H={},I=function(a){var b="";for(var c in E)if(c==a)for(var d=E[c].length,e=0;d>e;e++)b+=K("",E[c][e]);return b},J=function(a,b){return b&&b.keepCamelCase===!0?a:G(a,b)},K=function(a,b){var c="",d="",e="",f=h("./helpers/PropAnalyzer")(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return L(a,d,b);var g=function(a){""!=e&&(e+=x),e+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)d+="function"==typeof j[k]?" "+J(k,H)+'="'+j[k]()+'"':" "+J(k,H)+'="'+j[k]+'"';break;case"_":g(j);break;case"_tpl":if("string"==typeof j)g(I(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=I(tpl),m<j.length-1&&(l+=x);g(l)}break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=K("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);g(l);break;default:switch(typeof j){case"string":g(K(i,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=K("","function"==typeof v?v():v),m<j.length-1&&(l+=x);g(K(i,l))}else g(K(i,j));break;case"function":g(K(i,j()))}}}return c+=""!=a?L(a,d,e):e},L=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+J(a,H)+b+">"+x+c+x+"</"+J(a,H)+">":"<"+J(a,H)+b+"/>")},M=function(a){return a=h("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),H),H.minify?a:F(a,{indent_size:H.indentSize||4})};return a.processors.html.HTML=function(){var a=function(a,b,c){E=a,b=b||function(){},c=H=c||y;var d=M(I("mainstream"));return b(null,d),d};return a.type="html",a},a.processors.html.helpers.PropAnalyzer=function(a){var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1;if(/(#|\.|\[|\])/gi.test(a)===!1)return{tag:a,attrs:""};for(var k=0;k<a.length,c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b},a.processors.html.helpers.TemplateEngine=function(a,b){for(var c,d=/<%(.+?)%>/g,e=/(^( )?(if|for|else|switch|case|break|{|}|;))(.*)?/g,f="var r=[];\n",g=0,h=function(a,b){return f+=b?a.match(e)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",h};match=d.exec(a);)h(a.slice(g,match.index))(match[1],!0),g=match.index+match[0].length;h(a.substr(g,a.length-g)),f=(f+'return r.join("");').replace(/[\r\t\n]/g,"");try{c=new Function(f).apply(b)}catch(i){console.error("'"+i.message+"'"," in \n\nCode:\n",f,"\n")}return c},n()}(window); | ||
var Absurd=function(){var b={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}}},d=function(a){return a.indexOf("css/CSS.js")>0||"/../CSS.js"==a?b.processors.css.CSS:a.indexOf("html/HTML.js")>0?b.processors.html.HTML:a.indexOf("component/Component.js")>0?b.processors.component.Component:"js-beautify"==a?{html:function(a){return a}}:"./helpers/PropAnalyzer"==a?b.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==a?b.helpers.TransformUppercase:"./helpers/TemplateEngine"==a?b.processors.html.helpers.TemplateEngine:"../helpers/Extend"==a?b.helpers.Extend:"../helpers/Clone"==a?b.helpers.Clone:"../helpers/Prefixes"==a||"/../../../helpers/Prefixes"==a?b.helpers.Prefixes:function(){}},e="",f=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},g=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},h=function(a){var b={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[1,"<div>","</div>"]};b.optgroup=b.option,b.tbody=b.tfoot=b.colgroup=b.caption=b.thead,b.th=b.td;var c=document.createElement("div"),d=/<\s*\w.*?>/g.exec(a);if(null!=d){var c,e=d[0].replace(/</g,"").replace(/>/g,""),f=b[e]||b._default;a=f[1]+a+f[2],c.innerHTML=a;for(var g=f[0]+1;g--;)c=c.lastChild}else c.innerHTML=a,c=c.lastChild;return c},i=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},j=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType&&f.test(b.nodeValue)&&(a.removeChild(b),e--,d--);return a},k=function(b,c,d){for(var e=document.createElement(b),f=0;f<c.length,a=c[f];f++)e.setAttribute(a.name,a.value);return e.innerHTML=d,e},l=function(a,c,d,e){var l=b.helpers.Extend({__name:a},e),m=b.helpers.Extend,n=[];l.listeners=n,l.on=function(a,b,c){return n[a]||(n[a]=[]),n[a].push({callback:b,scope:c}),this},l.off=function(a,b){return n[a]?(b||(n[a]=[]),this):this},l.dispatch=function(a,b,c){if(!b||"object"!=typeof b||b instanceof Array||(b.target=this),n[a])for(var e=0;e<n[a].length;e++){var f=n[a][e].callback;f.apply(c||n[a][e].scope||{},[b])}return this[a]&&"function"==typeof this[a]&&this[a](b),d&&d.dispatch(a,b),this};var o={};l.set=function(a,b){return o[a]=b,this},l.get=function(a){return o[a]};var p=!1;l.__handleCSS=function(b){this.css?c.flush().add(this.css).compile(function(c,d){if(p)p.raw!==d&&(p.raw=d,p.element.innerHTML=d);else{var e=k("style",[{name:"id",value:a+"-css"},{name:"type",value:"text/css"}],d);(g("head")||g("body"))[0].appendChild(e),p={raw:d,element:e}}b()}):b()};var q=!1;l.__mergeDOMElements=function(a,b){if(j(a),j(b),"undefined"!=typeof a&&"undefined"!=typeof b&&!a.isEqualNode(b)){if(a.nodeName!==b.nodeName)return a.parentNode&&a.parentNode.replaceChild(b,a),void 0;if(a.nodeValue!==b.nodeValue&&(a.nodeValue=b.nodeValue),a.attributes){for(var c,d,e=a.attributes,f=b.attributes,g={},h=0;h<e.length,c=e[h];h++){for(var i=0;i<f.length,d=f[i];i++)c.name===d.name&&(a.setAttribute(c.name,d.value),g[c.name]=!0);g[c.name]||a.removeAttribute(c.name)}for(var h=0;h<f.length,d=f[h];h++)g[d.name]||a.setAttribute(d.name,d.value)}var k=[];if(a.childNodes.length>=b.childNodes.length)for(var h=0;h<a.childNodes.length;h++)b.childNodes[h]||b.appendChild(document.createTextNode("")),k.push([a.childNodes[h],b.childNodes[h]]);else for(var h=0;h<b.childNodes.length;h++)a.appendChild(document.createTextNode("")),k.push([a.childNodes[h],b.childNodes[h]]);for(var h=0;h<k.length;h++)l.__mergeDOMElements(k[h][0],k[h][1])}},l.__handleHTML=function(a){var b=this,d=function(){c.flush().morph("html").add(q).compile(function(c,d){b.el?l.__mergeDOMElements(b.el,h(d)):b.el=h(d),a()},b)};if(this.html)if("string"==typeof this.html){if(!this.el){var e=g(this.html);this.el=e[0],q={"":this.el.outerHTML.replace(/</g,"<").replace(/>/g,">")}}d()}else"object"==typeof this.html?(q=m({},this.html),d()):a();else a()};var r=!1;l.__append=function(a){!r&&this.el&&this.get("parent")&&(r=!0,this.get("parent").appendChild(this.el)),a()};var s={events:{}};l.__handleEvents=function(a){if(this.el){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!s.events[c[0]]||s.events[c[0]].indexOf(a)<0)&&(s.events[c[0]]||(s.events[c[0]]=[]),s.events[c[0]].push(a),i(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};this.el.hasAttribute&&this.el.hasAttribute("data-absurd-event")&&c(this.el);for(var d=this.el.querySelectorAll?this.el.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()};var t={funcs:{},index:0};return l.__handleAsyncFunctions=function(a){if(this.el){var b=[];if(this.el.hasAttribute&&this.el.hasAttribute("data-absurd-async"))b.push(this.el);else for(var c=this.el.querySelectorAll?this.el.querySelectorAll("[data-absurd-async]"):[],d=0;d<c.length;d++)b.push(c[d]);if(0===b.length)a();else{var e=this;!function f(){if(0===b.length)a();else{var c=b.shift(),d=c.getAttribute("data-absurd-async"),g=function(a){"string"==typeof a?c.parentNode.replaceChild(h(a),c):c.parentNode.replaceChild(a,c),f()};"function"==typeof e[t.funcs[d].name]?e[t.funcs[d].name].apply(e,[g].concat(t.funcs[d].args)):"function"==typeof t.funcs[d].func&&t.funcs[d].func.apply(e,[g].concat(t.funcs[d].args))}}()}}else a()},l.async=function(){var a=Array.prototype.slice.call(arguments,0),b=a.shift(),c="_"+t.index++;return t.funcs[c]={args:a,name:b},'<script data-absurd-async="'+c+'"></script>'},l.child=function(){var a=Array.prototype.slice.call(arguments,0),b=this.get("children"),c=b&&b[a.shift()],d="_"+t.index++;return t.funcs[d]={args:a,func:function(a){c.populate({callback:function(b){a(b.html.element)}})}},'<script data-absurd-async="'+d+'"></script>'},l.wire=function(a){c.components.events.on(a,this[a]||function(){},this)},l.populate=function(a){return f([l.__handleCSS,l.__handleHTML,l.__append,l.__handleEvents,l.__handleAsyncFunctions,function(){t={funcs:{},index:0};var b={css:p,html:{element:this.el}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this),l},l.utils={str2DOMElement:h,addEventListener:i,queue:f,compileHTML:function(a,b,d){c.flush().morph("html").add(a).compile(d,b)},compileCSS:function(a,b,d){c.flush().add(a).compile(d,b)}},l},m=function(){return function(a){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:b.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){return f={},g=[],i={},e.defaultProcessor=b.processors.css.CSS(),e},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.components=function(a){var c=b.helpers.Extend,d=b.helpers.Clone,e={},f=[],g=c({},l());return{events:g,register:function(b,h){return e[b]=function(){var e=c({},l(b,a,g,d(h)));return a.di.resolveObject(e),f.push(e),"function"==typeof e.constructor&&e.constructor.apply(e,Array.prototype.slice.call(arguments,0)),e}},get:function(a){if(e[a])return e[a];throw new Error("There is no component with name '"+a+"'.")},remove:function(a){return e[a]?(delete e[a],!0):!1},list:function(){var a=[];for(var b in e)a.push(b);return a},flush:function(){return e={},f=[],this},broadcast:function(a,b){for(var c=0;c<f.length,instance=f[c];c++)"function"==typeof instance[a]&&instance[a](b);return this}}}(e),e.component=function(a){return function(b,c){return"undefined"==typeof c?a.components.get(b):a.components.register(b,c)}}(e),e.di=b.DI(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in b.api)"compile"!==j&&(e[j]=b.api[j](e),e[j]=function(a){return function(){var c=b.api[a](e);return e.callHooks(a,arguments)?e:c.apply(e,arguments)}}(j));for(var k in b.processors.css.plugins)e.plugin(k,b.processors.css.plugins[k]());return"function"==typeof a&&a(e),"undefined"!=typeof Organic&&Organic.init(e),e}};b.DI=function(){var a={dependencies:{},register:function(a,b){return this.dependencies[a]=b,this},resolve:function(){var a,b,c,d=this,e=!1;"string"==typeof arguments[0]?(a=arguments[1],b=arguments[0].replace(/ /g,"").split(","),c=arguments[2]||{}):(a=arguments[0],b=a.toString().match(/^function\s*[^\(]*\(\s*([^\)]*)\)/m)[1].replace(/ /g,"").split(","),c=arguments[1]||{});for(var f=0;f<b.length;f++)"undefined"!=typeof this.dependencies[b[f]]&&(e=!0);return e?function(){for(var e=[],f=Array.prototype.slice.call(arguments,0),g=0;g<b.length;g++){var h=b[g];e.push(d.dependencies[h]&&""!=h?d.dependencies[h]:f.shift())}return a.apply(c,e)}:a},resolveObject:function(a){if("object"==typeof a)for(var b in a)"function"==typeof a[b]?a[b]=this.resolve(a[b],a):a[b]instanceof Array&&2==a[b].length&&"string"==typeof a[b][0]&&"function"==typeof a[b][1]&&(a[b]=this.resolve(a[b][0],a[b][1],a));return this},flush:function(){return this.dependencies={},this}};return a},b.api.add=function(a){var b=(d("../helpers/Extend"),d("../helpers/Prefixes")),c=[],e=function(c,d,e,g,h){var i=b.nonPrefixProp(d),j=a.getPlugins()[i.prop];if("undefined"!=typeof j){var k=j(a,e,i.prefix);return k&&f(c,k,g,h),!0}return!1},f=function(a,d,g,h){if(g=g||"mainstream",/, ?/g.test(a))for(var i=a.replace(/, /g,",").split(","),j=0;j<i.length,p=i[j];j++)f(p,d,g,h);else if("undefined"==typeof d.length||"object"!=typeof d){if(!e(null,a,d,g,h)){var k={},l=a,m={},n={};for(var o in d){var q=typeof d[o];"object"!==q&&"function"!==q?e(a,o,d[o],g,h)===!1&&(l="undefined"!=typeof h?h+" "+a:a,k[o]=d[o],b.addPrefixes(o,k)):"object"===q?m[o]=d[o]:"function"===q&&(n[o]=d[o])}c.push({selector:l,props:k,stylesheet:g});for(var o in m)if(":"===o.charAt(0))f(a+o,m[o],g,h);else if(/&/g.test(o))if(/, ?/g.test(o))for(var i=o.replace(/, /g,",").split(","),j=0;j<i.length,p=i[j];j++)p.indexOf("&")>=0?f(p.replace(/&/g,a),m[o],g,h):f(p,m[o],g,"undefined"!=typeof h?h+" "+a:a);else f(o.replace(/&/g,a),m[o],g,h);else 0===o.indexOf("@media")||0===o.indexOf("@supports")?f(a,m[o],o,h):0===a.indexOf("@media")||0===o.indexOf("@supports")?f(o,m[o],a,h):e(a,o,m[o],g,h)===!1&&f(o,m[o],g,(h?h+" ":"")+a);for(var o in n){var r={};r[o]=n[o](),f(a,r,g,h)}}}else for(var j=0;j<d.length,o=d[j];j++)f(a,o,g,h)},g=function(b,d){c=[],a.numOfAddedRules+=1;var e=a.defaultProcessor.type;for(var g in b)f(g,b[g],d||"mainstream");for(var h=0;h<c.length;h++){var d=c[h].stylesheet,g=c[h].selector,i=c[h].props,j=a.getRules(d),k=j[g]||{};for(var l in i){var m=i[l];"object"!=typeof m&&(k[l]="css"==e?"+"===m.toString().charAt(0)?k&&k[l]?k[l]+", "+m.substr(1,m.length-1):m.substr(1,m.length-1):">"===m.toString().charAt(0)?k&&k[l]?k[l]+" "+m.substr(1,m.length-1):m.substr(1,m.length-1):m:m)}j[g]=k}return a};return g};var n=d("../helpers/Extend");b.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=n(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{s.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},b.api.compileFile=function(a){return a.compile};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};b.api.darken=function(){return function(a,b){return q(a,-(b/100))}},b.api.define=function(a){return function(b,c){return a.getStorage().__defined||(a.getStorage().__defined={}),a.getStorage().__defined[b]=c,a}},b.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};b.api.lighten=function(){return function(a,b){return q(a,b/100)}};var r={html:function(a){a.defaultProcessor=d(e+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=d(e+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};b.api.morph=function(a){return function(b){return r[b]&&(a.flush(),r[b](a)),a}},b.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},b.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}};{var s=d("fs");d("path")}b.api.rawImport=function(a){var b=function(b){var c=s.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return a}},b.api.register=function(a){return function(b,c){return a[b]=c,a}},b.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},b.helpers.Clone=function M(a){if(!a)return a;var b,c=[Number,String,Boolean];if(c.forEach(function(c){a instanceof c&&(b=c(a))}),"undefined"==typeof b)if("[object Array]"===Object.prototype.toString.call(a))b=[],a.forEach(function(a,c){b[c]=M(a)});else if("object"==typeof a)if(a.nodeType&&"function"==typeof a.cloneNode)var b=a.cloneNode(!0);else if(a.prototype)b=a;else if(a instanceof Date)b=new Date(a);else{b={};for(var d in a)b[d]=M(a[d])}else b=a;return b},b.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},b.helpers.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b};var t=function(a){var b,c;return(c=a.match(/^\-(w|m|s|o)+\-/)||"-"===a.charAt(0))?null!==c&&c[0]?(b={prefix:c[0].replace(/-/g,"")},b.prop=a.replace(c[0],"")):(b={prefix:""},b.prop=a.substr(1,a.length)):b={prefix:!1,prop:a},b};b.helpers.Prefixes={addPrefixes:function(a,b){var c=a,d=t(a),e=b[a];d.prefix!==!1&&(delete b[c],b[d.prop]=e,(""===d.prefix||d.prefix.indexOf("w")>=0)&&(b["-webkit-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("m")>=0)&&(b["-moz-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("s")>=0)&&(b["-ms-"+d.prop]=e),(""===d.prefix||d.prefix.indexOf("o")>=0)&&(b["-o-"+d.prop]=e))},nonPrefixProp:function(a){var b=t(a);return b.prefix!==!1&&(b.prefix=""==b.prefix?"-":"-"+b.prefix+"-"),b}},b.helpers.RequireUncached=function(a){return delete d.cache[d.resolve(a)],d(a)},b.helpers.TransformUppercase=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};var u=function(a,b,f){var g="",h="",i=[],j=f.api;cssPreprocessor=d(e+"/../css/CSS.js")(),htmlPreprocessor=d(e+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<i.length,component=i[b];b++)"function"==typeof component&&(component=component()),j.add(component.css?component.css:{});cssPreprocessor(j.getRules(),function(b,c){g+=c,a(b)},f)},l=function(b){var c=0,d=null,e=function(){if(c>a.length-1)return b(d),void 0;var g=a[c];"function"==typeof g&&(g=g()),j.morph("html").add(g.html?g.html:{}),htmlPreprocessor(j.getRules(),function(a,b){h+=b,c+=1,d=a,e()},f)};e()},m=function(a){for(var b in a)if("_include"===b)if(a[b]instanceof Array)for(var d=0;d<a[b].length,c=a[b][d];d++)"function"==typeof c&&(c=c()),i.push(c),m(c);else"function"==typeof a[b]&&(a[b]=a[b]()),i.push(a[b]),m(a[b]);else"object"==typeof a[b]&&m(a[b])},n=0;n<a.length,c=a[n];n++)"function"==typeof c&&(c=c()),i.push(c),m(c);j.flush(),k(function(a){j.morph("html"),l(function(c){b(a||c?{error:{css:a,html:c}}:null,g,h)})})};b.processors.component.Component=function(){var a=function(a,b,c){u(a.mainstream,b,c)};return a.type="component",a};var w="\n",x={combineSelectors:!0,minify:!1,keepCamelCase:!1},y=d("../../helpers/TransformUppercase"),z=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+w;else{var e=d+" {"+w;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=b&&b.keepCamelCase===!0?" "+f+": "+g+";"+w:" "+y(f)+": "+g+";"+w}e+="}"+w,c+=e}return c},A=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},B=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")},C=function(a,b){if(b&&b.api&&b.api.getStorage().__defined){var c=b.api.getStorage().__defined;for(var d in c){var e=new RegExp("<%( )?"+d+"( )?%>","g");a="function"!=typeof c[d]?a.replace(e,c[d]):a.replace(e,c[d]())}}return a};b.processors.css.CSS=function(){var a=function(a,b,c){c=c||x;var d="";for(var e in a){var f=a[e];f=c.combineSelectors?A(f):f,d+="mainstream"===e?z(f,c):e+" {"+w+z(f,c)+"}"+w}return d=C(d,c),c.minify?(d=B(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},b.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},b.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},b.processors.css.plugins.keyframes=function(){return function(a,b){var c=d(e+"/../CSS.js")(),f=d(e+"/../../../helpers/Prefixes");if("object"==typeof b)if("undefined"!=typeof b.frames){for(var g in b.frames)for(var h in b.frames[g])f.addPrefixes(h,b.frames[g]);var i="@keyframes "+b.name+" {\n";i+=c({mainstream:b.frames}),i+="}",a.raw(i+"\n"+i.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var i="@keyframes "+b.name+" {\n",j={},k=0;rule=b.keyframes[k];k++)if("keyframe"===rule.type)for(var l=j[rule.values]={},m=0;declaration=rule.declarations[m];m++)"declaration"===declaration.type&&(l[declaration.property]=declaration.value);i+=c({mainstream:j}),i+="}",a.raw(i+"\n"+i.replace("@keyframes","@-webkit-keyframes"))}}},b.processors.css.plugins.media=function(){return function(a,b){var c=d(e+"/../CSS.js")();if("object"==typeof b){for(var f="@media "+b.media+" {\n",g={},h=0;rule=b.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=c({mainstream:g}),f+="}",a.raw(f)}}},b.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},b.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},b.processors.css.plugins.supports=function(){return function(a,b){var c=d(e+"/../CSS.js")();if("object"==typeof b){for(var f="@supports "+b.supports+" {\n",g={},h=0;rule=b.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=c({mainstream:g}),f+="}",a.raw(f)}}};var D=null,w="\n",x={},E=d("js-beautify").html,F=d("../../helpers/TransformUppercase"),G={},H=function(a){var b="";for(var c in D)if(c==a)for(var d=D[c].length,e=0;d>e;e++)b+=J("",D[c][e]);return b},I=function(a,b){return b&&b.keepCamelCase===!0?a:F(a,b)},J=function(a,b){var c="",e="",f="",g=d("./helpers/PropAnalyzer")(a);if(a=g.tag,""!=g.attrs&&(e+=" "+g.attrs),"string"==typeof b)return K(a,e,b);var h=function(a){""!=f&&(f+=w),f+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)e+="function"==typeof j[k]?" "+I(k,G)+'="'+j[k]()+'"':" "+I(k,G)+'="'+j[k]+'"';break;case"_":h(j);break;case"_tpl":if("string"==typeof j)h(H(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=H(tpl),m<j.length-1&&(l+=w);h(l)}break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=J("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);h(l);break;default:switch(typeof j){case"string":h(J(i,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=J("","function"==typeof v?v():v),m<j.length-1&&(l+=w);h(J(i,l))}else h(J(i,j));break;case"function":h(J(i,j()))}}}return c+=""!=a?K(a,e,f):f},K=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+I(a,G)+b+">"+w+c+w+"</"+I(a,G)+">":"<"+I(a,G)+b+"/>")},L=function(a){return a=d("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),G),G.minify?a:E(a,{indent_size:G.indentSize||4})};return b.processors.html.HTML=function(){var a=function(a,b,c){D=a,b=b||function(){},c=G=c||x;var d=L(H("mainstream"));return b(null,d),d};return a.type="html",a},b.processors.html.helpers.PropAnalyzer=function(a){var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1;if(/(#|\.|\[|\])/gi.test(a)===!1)return{tag:a,attrs:""};for(var k=0;k<a.length,c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b},b.processors.html.helpers.TemplateEngine=function(a,b){for(var c,d=/<%(.+?)%>/g,e=/(^( )?(if|for|else|switch|case|break|{|}|;))(.*)?/g,f="var r=[];\n",g=0,h=function(a,b){return f+=b?a.match(e)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",h};match=d.exec(a);)h(a.slice(g,match.index))(match[1],!0),g=match.index+match[0].length;h(a.substr(g,a.length-g)),f=(f+'return r.join("");').replace(/[\r\t\n]/g,"");try{c=new Function(f).apply(b)}catch(i){console.error("'"+i.message+"'"," in \n\nCode:\n",f,"\n")}return c},m()}(window); |
@@ -1,2 +0,2 @@ | ||
/* version: 0.2.69 */ | ||
/* version: 0.2.70 */ | ||
var Organic = (function(w){ | ||
@@ -54,4 +54,3 @@ var o = { | ||
return res; | ||
} | ||
o.helpers.args = function(value) { | ||
};o.helpers.args = function(value) { | ||
value = value.toString().replace(/\/ /g, '/').split('/'); | ||
@@ -58,0 +57,0 @@ return value; |
@@ -52,2 +52,2 @@ var o = { | ||
return res; | ||
} | ||
}; |
@@ -212,3 +212,3 @@ describe("Testing components (HTML compilation)", function() { | ||
} else { | ||
expect(this.el().outerHTML).toBe('<nav><a href="#">A</a><a href="#">C</a></nav>'); | ||
expect(this.el.outerHTML).toBe('<nav><a href="#">A</a><a href="#">C</a></nav>'); | ||
done(); | ||
@@ -215,0 +215,0 @@ } |
@@ -25,3 +25,3 @@ describe("Testing components events", function() { | ||
if(!this.tested) { | ||
var input = data.html.element.querySelector("input"); | ||
var input = this.el.querySelector("input"); | ||
input.value = "42"; | ||
@@ -31,3 +31,3 @@ this.tested = true; | ||
} else { | ||
expect(data.html.element.querySelector("p").innerHTML).toBe("42"); | ||
expect(this.el.querySelector("p").innerHTML).toBe("42"); | ||
done(); | ||
@@ -34,0 +34,0 @@ } |
@@ -20,3 +20,3 @@ describe("Testing components Observer", function() { | ||
it("should attach a listener and dispatch an event", function(done) { | ||
var observer = Observer(); | ||
var observer = absurd.component("Observer", {})(); | ||
observer.on("event", function(data) { | ||
@@ -29,3 +29,3 @@ expect(data.value).toBe(10); | ||
it("should remove a listener", function(done) { | ||
var observer = Observer(); | ||
var observer = absurd.component("Observer", {})(); | ||
var listener = function() {}; | ||
@@ -40,3 +40,4 @@ observer.on("event", listener); | ||
it("should keep the scope (passed on 'dispatch' method)", function(done) { | ||
var component = extend({}, Observer()); | ||
var observer = absurd.component("Observer", {})(); | ||
var component = extend({}, observer); | ||
component.name = 'Component'; | ||
@@ -51,3 +52,4 @@ component.on('event', function(data) { | ||
it("should keep the scope (passed on 'on' method)", function(done) { | ||
var component = extend({}, Observer()); | ||
var observer = absurd.component("Observer", {})(); | ||
var component = extend({}, observer); | ||
component.name = 'Component'; | ||
@@ -54,0 +56,0 @@ component.on('event', function(data) { |
@@ -1,2 +0,2 @@ | ||
describe("Testing components", function() { | ||
describe("Testing components (async)", function() { | ||
@@ -3,0 +3,0 @@ it("should use async", function(done) { |
@@ -7,2 +7,3 @@ var path = require("path"); | ||
concat: { | ||
// packing the nodejs code | ||
absurd: { | ||
@@ -20,3 +21,3 @@ src: [ | ||
], | ||
dest: 'client-side/tmp/absurd.js', | ||
dest: 'tasks/tmp/absurd.js', | ||
options: { | ||
@@ -32,2 +33,34 @@ process: function(src, filepath) { | ||
}, | ||
// packing organic framework | ||
organic: { | ||
src: [ | ||
'lib/processors/css/organic/**/*.js' | ||
], | ||
dest: 'tasks/tmp/absurd-organic.js', | ||
options: { | ||
process: function(src, filepath) { | ||
var moduleDef = filepath | ||
.replace(/\//g, '.') | ||
.replace(/\//g, '.') | ||
.replace(/\.js/g, '') | ||
.replace('lib.processors.css.organic', 'o'); | ||
return src.replace("module.exports", moduleDef); | ||
} | ||
} | ||
}, | ||
// packing client side code | ||
'absurd-client-code': { | ||
src: [ | ||
'client-side/lib/**/*.js', | ||
], | ||
dest: 'tasks/tmp/absurd-client-code.js', | ||
}, | ||
// packing client side code | ||
'absurd-organic-client-code': { | ||
src: [ | ||
'client-side/lib-organic/**/*.js', | ||
], | ||
dest: 'tasks/tmp/absurd-organic-client-code.js', | ||
}, | ||
// packing the nodejs tests for client-side usage | ||
'node-tests-to-client': { | ||
@@ -58,25 +91,7 @@ src: [ | ||
dest: 'client-side/tests/tests.from.node.js', | ||
}, | ||
organic: { | ||
src: [ | ||
'lib/processors/css/organic/**/*.js' | ||
], | ||
dest: 'client-side/tmp/absurd.organic.js', | ||
options: { | ||
process: function(src, filepath) { | ||
var moduleDef = filepath | ||
.replace(/\//g, '.') | ||
.replace(/\//g, '.') | ||
.replace(/\.js/g, '') | ||
.replace('lib.processors.css.organic', 'o'); | ||
return src.replace("module.exports", moduleDef); | ||
} | ||
} | ||
} | ||
}, | ||
'client-side': { | ||
// building the client-side port of absurd and organic | ||
build: { | ||
index: { | ||
src: '<%= concat.absurd.dest %>', | ||
organicSrc: '<%= concat.organic.dest %>', | ||
dest: 'client-side/build/absurd.js', | ||
@@ -86,2 +101,3 @@ organicDest: 'client-side/build/absurd.organic.js' | ||
}, | ||
// minification | ||
uglify: { | ||
@@ -97,2 +113,3 @@ absurd: { | ||
}, | ||
// watching | ||
watch: { | ||
@@ -106,3 +123,3 @@ commands: { | ||
], | ||
tasks: ['concat', 'client-side', 'uglify'] | ||
tasks: ['concat', 'build', 'uglify'] | ||
} | ||
@@ -128,4 +145,4 @@ }, | ||
grunt.registerTask('default', ['concat', 'client-side', 'uglify', 'lineending', 'watch']); | ||
grunt.registerTask('default', ['concat', 'build', 'uglify', 'lineending', 'watch']); | ||
} |
{ | ||
"name": "absurd", | ||
"version": "0.2.69", | ||
"version": "0.2.70", | ||
"homepage": "http://krasimir.github.io/absurd", | ||
@@ -5,0 +5,0 @@ "description": "CSS/HTML preprocessor. Check out krasimirtsonev.com/blog/article/AbsurdJS-fundamentals", |
Sorry, the diff of this file is not supported yet
668442
223
20845