/* version: 0.3.7, born: 20-10-2016 9:44 */ var Absurd = (function(w) { var lib = { 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' || v == '../html/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 if(v == __dirname + '/../../../../') { return Absurd; } else if(v == '../helpers/CSSParse') { return lib.helpers.CSSParse; } else { return function() {} } }; var __dirname = ""; var queue = function(funcs, scope) { (function next() { if(funcs.length > 0) { funcs.shift().apply(scope || {}, [next].concat(Array.prototype.slice.call(arguments, 0))); } })(); } var str2DOMElement = function(html) { var wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], area: [ 1, "", "" ], param: [ 1, "", "" ], thead: [ 1, "", "
" ], tr: [ 2, "", "
" ], col: [ 2, "", "
" ], td: [ 3, "", "
" ], body: [0, "", ""], _default: [ 1, "
", "
" ] }; wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; var match = /<\s*\w.*?>/g.exec(html); var element = document.createElement('div'); if(match != null) { var tag = match[0].replace(//g, '').split(' ')[0]; if(tag.toLowerCase() === 'body') { var dom = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null); var body = document.createElement("body"); // keeping the attributes element.innerHTML = html.replace(//g, ''); var attrs = element.firstChild.attributes; body.innerHTML = html; for(var i=0; i= 0) classes.splice(existingIndex, 1); else classes.push(className); el.className = classes.join(' '); } return this; } var bind = function(func, scope, args) { if(scope instanceof Array) { args = scope; scope = this; } if(!scope) scope = this; return function() { func.apply(scope, (args || []).concat(Array.prototype.slice.call(arguments, 0))); } } 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= e2.childNodes.length) { for(var i=0; i') }; } } compile(); } else if(typeof this.html === 'object') { HTMLSource = extend({}, this.html); compile(); } else { next(); } } else { next(); } return this; }; api.applyHTML = function(data, skipAutoPopulation) { this.html = data; if(!skipAutoPopulation) { this.populate(); } return this; }; var appended = false api.__append = function(next) { if(!appended && this.el && this.get("parent")) { appended = true; this.get("parent").appendChild(this.el); } next(); return this; } var cache = { events: {} }; api.__handleEvents = function(next) { if(this.el) { var self = this; var registerEvent = function(el) { var attrValue = el.getAttribute('data-absurd-event'); var processAttributes = function(attrValue) { attrValue = attrValue.split(":"); if(attrValue.length >= 2) { var eventType = attrValue[0]; var methodName = attrValue[1]; attrValue.splice(0, 2); var args = attrValue; if(!cache.events[eventType] || cache.events[eventType].indexOf(el) < 0) { if(!cache.events[eventType]) cache.events[eventType] = []; cache.events[eventType].push(el); addEventListener(el, eventType, function(e) { if(typeof self[methodName] === 'function') { var f = self[methodName]; f.apply(self, [e].concat(args)); } }); } } } attrValue = attrValue.split(/, ?/g); for(var i=0; i'; }; 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 ''; }; api.wire = function(event) { absurd.components.events.on(event, this[event] || function() {}, this); return this; }; var isPopulateInProgress = false; api.populate = function(options) { if(isPopulateInProgress) return; isPopulateInProgress = true; var empty = function(next) { next(); return this; }; queue([ options && options.css === false ? empty : api.__handleCSS, options && options.html === false ? empty : api.__handleHTML, api.__append, api.__handleEvents, api.__handleAsyncFunctions, function() { isPopulateInProgress = false; async = { funcs: {}, index: 0 } var data = { css: CSS, html: { element: this.el } }; this.dispatch("populated", data); if(options && typeof options.callback === 'function') { options.callback(data); } } ], this); return this; }; api.str2DOMElement = str2DOMElement; api.addEventListener = addEventListener; api.queue = queue; api.qs = qs; api.qsa = qsa; api.getStyle = getStyle; api.addClass = addClass; api.removeClass = removeClass; api.replaceClass = replaceClass; api.bind = bind; api.toggleClass = toggleClass; api.compileHTML = function(HTML, callback, data) { absurd.flush().morph("html").add(HTML).compile(callback, data); }; api.compileCSS = function(CSS, callback, options) { absurd.flush().add(CSS).compile(callback, options); }; api.delay = function(time, fn, args) { var self = this; setTimeout(function() { fn.apply(self, args); }, time); } return api; }; var injecting = function(absurd) { absurd.di.register('is', { appended: function(selector) { if(typeof selector == 'undefined') selector = this.host.html; return qs(selector) ? true : false; }, hidden: function(el) { el = el || this.host.el; return el.offsetParent === null; } }); absurd.di.register('router', { routes: [], mode: null, root: '/', getFragment: function() { var fragment = ''; if(this.mode === 'history') { if(!location) return ''; fragment = this.clearSlashes(decodeURI(location.pathname + location.search)); fragment = fragment.replace(/\?(.*)$/, ''); fragment = this.root != '/' ? fragment.replace(this.root, '') : fragment; } else { if(!window) return ''; var match = window.location.href.match(/#(.*)$/); fragment = match ? match[1] : ''; } return this.clearSlashes(fragment); }, clearSlashes: function(path) { return path.toString().replace(/\/$/, '').replace(/^\//, ''); }, add: function(re, handler) { if(typeof re == 'function') { handler = re; re = ''; } this.routes.push({ re: re, handler: handler}); return this; }, remove: function(param) { for(var i=0, r; i 0) { for(var i=0; decl=rule.declarations[i]; i++) { if(decl.type === "declaration") { absurdProps[decl.property] = decl.value; } } // absurdObj[rule.selectors.join(", ")] = absurdProps; if(rule.selectors && rule.selectors.length > 0) { for(var i=0; selector=rule.selectors[i]; i++) { absurdObj[selector] = extend({}, absurdProps); } } _api.add(absurdObj, stylesheet); } return _api; } // hooks _api.addHook = function(method, callback) { if(!_hooks[method]) _hooks[method] = []; var isAlreadyAdded = false; for(var i=0; c=_hooks[method][i]; i++) { if(c === callback) { isAlreadyAdded = true; } } isAlreadyAdded === false ? _hooks[method].push(callback) : null; } _api.callHooks = function(method, args) { if(_hooks[method]) { for(var i=0; c=_hooks[method][i]; i++) { if(c.apply(_api, args) === true) return true; } } return false; } // internal variables _api.numOfAddedRules = 0; // absurd.components API _api.components = (function(api) { var extend = lib.helpers.Extend, clone = lib.helpers.Clone, comps = {}, instances = [], events = extend({}, Component()), exports = {}; (function(fn) { if(!window) return; if (window.addEventListener) { window.addEventListener('load', fn); } else if(window.attachEvent) { window.attachEvent('onload', fn); } })(function() { exports.broadcast("ready"); }) return exports = { numOfComponents: 0, events: events, register: function(name, cls) { this.numOfComponents += 1; 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>> ' + selector, "\n", props); stylesheet = stylesheet || "mainstream"; // catching null values if(props === null || typeof props === 'undefined' || props === false) return; if(!parentSelector && !selector) selector = ''; // classify if(typeof props.classify != 'undefined' && props.classify === true) { props = typeof props.toJSON != 'undefined' ? props.toJSON() : props.toString(); } // multiple selectors if(/, ?/g.test(selector) && options.combineSelectors) { var parts = selector.replace(/, /g, ',').split(','); for(var i=0; i= 0) { addRule(p.replace(/&/g, selector), _objects[prop], stylesheet, parentSelector); } else { addRule(p, _objects[prop], stylesheet, typeof parentSelector !== "undefined" ? parentSelector + " " + selector : selector); } } } else { addRule(prop.replace(/&/g, selector), _objects[prop], stylesheet, parentSelector); } // check for media query } else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { addRule(selector, _objects[prop], prop, parentSelector); // check for media query } else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { addRule(prop, _objects[prop], selector, parentSelector); // moving the selector to the top of the chain } else if(selector.indexOf("^") === 0) { // selector, props, stylesheet, parentSelector addRule( selector.substr(1, selector.length-1) + (typeof parentSelector !== "undefined" ? " " + parentSelector : '') + " " + prop, _objects[prop], stylesheet ); // check for plugins } else if(checkAndExecutePlugin(selector, prop, _objects[prop], stylesheet, parentSelector) === false) { addRule(prop, _objects[prop], stylesheet, (parentSelector ? parentSelector + " " : "") + selector); } } for(var prop in _functions) { var o = {}; o[prop] = _functions[prop](); addRule(selector, o, stylesheet, parentSelector); } } var add = function(rules, stylesheet, opts) { if(API.jsonify) { extend(API.getRules(stylesheet || 'mainstream'), rules); return API; } try { toRegister = []; API.numOfAddedRules += 1; if(typeof stylesheet === 'object' && typeof opts === 'undefined') { options = { combineSelectors: typeof stylesheet.combineSelectors != 'undefined' ? stylesheet.combineSelectors : options.combineSelectors, preventCombining: options.preventCombining.concat(stylesheet.preventCombining || []) }; stylesheet = null; } if(typeof opts != 'undefined') { options = { combineSelectors: opts.combineSelectors || options.combineSelectors, preventCombining: options.preventCombining.concat(opts.preventCombining || []) }; } var typeOfPreprocessor = API.defaultProcessor.type, uid; for(var selector in rules) { addRule(selector, rules[selector], stylesheet || "mainstream"); } // looping through the rules for registering for(var i=0; i= 0 ? '~~' + API.numOfAddedRules + '~~' : ''; // overwrite already added value var current = allRules[uid + selector] || {}; for(var propNew in props) { var value = props[propNew]; propNew = uid + propNew; if(typeof value != 'object') { if(typeOfPreprocessor == "css") { // appending values if(value.toString().charAt(0) === "+") { if(current && current[propNew]) { current[propNew] = current[propNew] + ", " + value.substr(1, value.length-1); } else { current[propNew] = value.substr(1, value.length-1); } } else if(value.toString().charAt(0) === ">") { if(current && current[propNew]) { current[propNew] = current[propNew] + " " + value.substr(1, value.length-1); } else { current[propNew] = value.substr(1, value.length-1); } } else { current[propNew] = value; } } else { current[propNew] = value; } } } allRules[uid + selector] = current; } return API; } catch(err) { throw new Error("Error adding: " + JSON.stringify({rules: rules, error: err.toString()})); } } return add; } var extend = require("../helpers/Extend"); lib.api.compile = function(api) { return function() { var path = null, callback = function() {}, options = null; for(var i=0; i= 0) obj['-webkit-' + p.prop] = value; if(p.prefix === '' || p.prefix.indexOf('m') >= 0) obj['-moz-' + p.prop] = value; if(p.prefix === '' || p.prefix.indexOf('s') >= 0) obj['-ms-' + p.prop] = value; if(p.prefix === '' || p.prefix.indexOf('o') >= 0) obj['-o-' + p.prop] = value; } }, nonPrefixProp: function(prop) { var p = prefixExtract(prop); if(p.prefix !== false) { if(p.prefix == '') { p.prefix = '-'; } else { p.prefix = '-' + p.prefix + '-'; } } return p; } } lib.helpers.RequireUncached = function(module) { delete require.cache[require.resolve(module)] return require(module); } lib.helpers.TransformUppercase = function(prop, options) { var transformed = ""; for(var i=0; c=prop.charAt(i); i++) { if(c === c.toUpperCase() && c.toLowerCase() !== c.toUpperCase()) { transformed += "-" + c.toLowerCase(); } else { transformed += c; } } return transformed; } var compileComponent = function(input, callback, options) { var css = "", html = "", all = [], api = options.api; cssPreprocessor = require(__dirname + "/../css/CSS.js")(), htmlPreprocessor = require(__dirname + "/../html/HTML.js")(); var processCSS = function(clb) { for(var i=0; i input.length-1) { clb(error); return; } var c = input[index]; if(typeof c === "function") { c = c(); } api.morph("html").add(c.html ? c.html : {}); htmlPreprocessor(api.getRules(), function(err, result) { html += result; index += 1; error = err; processComponent(); }, options); } processComponent(); } var checkForNesting = function(o) { for(var key in o) { if(key === "_include") { if(o[key] instanceof Array) { for(var i=0; i= 0) { result[stylesheet] = {}; for(var selector in styles) { result[stylesheet][selector] = {} for(var prop in styles[selector]) { result[stylesheet][selector][prop] = styles[selector][prop]; } } } } return result; } // combining selectors var combineSelectors = function(rules, preventCombining) { var map = [], arr = {}; var preventCombining = [].concat(preventCombining || []); preventCombining.splice(0, 0, ''); preventCombining = preventCombining.join('|'); // extracting every property for(var selector in rules) { var props = rules[selector]; for(var prop in props) { map.push({ selector: selector, prop: prop, value: props[prop], combine: preventCombining.indexOf('|' + prop) < 0 && selector.indexOf('@font-face') < 0 }); } } // combining for(var i=0; i', 'g'); if(typeof storage[prop] != 'function') { css = css.replace(re, storage[prop]); } else { css = css.replace(re, storage[prop]()); } } } return css; } lib.processors.css.CSS = function() { var processor = function(rules, callback, options) { options = options || defaultOptions; if(options.api && options.api.jsonify) { var json = toJSON(rules, options); callback(null, json); return json; } var css = ''; for(var stylesheet in rules) { var r = rules[stylesheet]; r = options.combineSelectors ? combineSelectors(r, options.preventCombining) : r; if(stylesheet === "mainstream") { css += toCSS(r, options); } else { css += stylesheet + " {" + newline + toCSS(r, options, [' ', ' ']) + "}" + newline; } } css = replaceDefined(css, options); // Dynamic CSS if(options && options.api && options.api.dynamicCSS) { css = require("../html/helpers/TemplateEngine")(css, options); } // Minification if(options.minify) { css = minimize(css); if(callback) callback(null, css); } else { if(callback) callback(null, css); } return css; } processor.type = "css"; return processor; } lib.processors.css.plugins.charset = function() { return function(api, charsetValue) { if(typeof charsetValue === "string") { api.raw("@charset: \"" + charsetValue + "\";"); } else if(typeof charsetValue === "object") { charsetValue = charsetValue.charset.replace(/:/g, '').replace(/'/g, '').replace(/"/g, '').replace(/ /g, ''); api.raw("@charset: \"" + charsetValue + "\";"); } } } lib.processors.css.plugins.document = function() { return function(api, value) { if(typeof value === "object") { var stylesheet = ''; stylesheet += '@' + value.vendor + 'document'; stylesheet += ' ' + value.document; if(value.rules && value.rules.length) { for(var i=0; rule=value.rules[i]; i++) { api.handlecssrule(rule, stylesheet); } } else if(typeof value.styles != "undefined") { api.add(value.styles, stylesheet); } } } } lib.processors.css.plugins.keyframes = function() { return function(api, value) { var processor = require(__dirname + "/../CSS.js")(); var prefixes = require(__dirname + "/../../../helpers/Prefixes"); if(typeof value === "object") { // js or json var frames; if(typeof value.frames != "undefined") { frames = value.frames; // css } else if(typeof value.keyframes != "undefined") { frames = {}; for(var i=0; rule=value.keyframes[i]; i++) { if(rule.type === "keyframe") { var f = frames[rule.values] = {}; for(var j=0; declaration=rule.declarations[j]; j++) { if(declaration.type === "declaration") { f[declaration.property] = declaration.value; } } } } } if(api.jsonify) { var r = {}; r.keyframes = { name: value.name, frames: frames } api.add(r); } else { var absurd = require(__dirname + '/../../../../')(); absurd.add(frames).compile(function(err, css) { var content = '@keyframes ' + value.name + " {\n"; content += css; content += "}"; content = content + "\n" + content.replace("@keyframes", "@-webkit-keyframes"); api.raw(content); }, {combineSelectors: false}); } } } } lib.processors.css.plugins.media = function() { return function(api, value) { var processor = require(__dirname + "/../CSS.js")(); if(typeof value === "object") { var content = '@media ' + value.media + " {\n"; var rules = {}, json = {}; for(var i=0; rule=value.rules[i]; i++) { var r, rjson; if (rule.selectors) { r = rules[rule.selectors.toString()] = {}; rjson = json[rule.selectors.toString()] = {}; if(rule.type === "rule") { for(var j=0; declaration=rule.declarations[j]; j++) { if(declaration.type === "declaration") { r[declaration.property] = declaration.value; rjson[declaration.property] = declaration.value; } } } } } content += processor({mainstream: rules}); content += "}"; if(api.jsonify) { api.add(json, '@media ' + value.media); } else { api.raw(content); } } } } lib.processors.css.plugins.namespace = function() { return function(api, value) { if(typeof value === "string") { api.raw("@namespace: \"" + value + "\";"); } else if(typeof value === "object") { value = value.namespace.replace(/: /g, '').replace(/'/g, '').replace(/"/g, '').replace(/ /g, '').replace(/:h/g, 'h'); api.raw("@namespace: \"" + value + "\";"); } } } lib.processors.css.plugins.page = function() { return function(api, value) { if(typeof value === "object") { var content = ""; if(value.selectors.length > 0) { content += "@page " + value.selectors.join(", ") + " {\n"; } else { content += "@page {\n"; } for(var i=0; declaration=value.declarations[i]; i++) { if(declaration.type == "declaration") { content += " " + declaration.property + ": " + declaration.value + ";\n"; } } content += "}"; api.raw(content); } } } lib.processors.css.plugins.supports = function() { return function(api, value) { var processor = require(__dirname + "/../CSS.js")(); if(typeof value === "object") { var content = '@supports ' + value.supports + " {\n"; var rules = {}; for(var i=0; rule=value.rules[i]; i++) { var r = rules[rule.selectors.toString()] = {}; if(rule.type === "rule") { for(var j=0; declaration=rule.declarations[j]; j++) { if(declaration.type === "declaration") { r[declaration.property] = declaration.value; } } } } content += processor({mainstream: rules}); content += "}"; api.raw(content); } } } var data = null, newline = '\n', defaultOptions = {}, tags = [], beautifyHTML = require('js-beautify').html, tu = require("../../helpers/TransformUppercase"), passedOptions = {}; var processTemplate = function(templateName) { var html = ''; for(var template in data) { if(template == templateName) { var numOfRules = data[template].length; for(var i=0; i", obj); var html = '', attrs = '', childs = ''; var tagAnalized = require("./helpers/PropAnalyzer")(tagName); tagName = tagAnalized.tag; if(tagAnalized.attrs != "") { attrs += " " + tagAnalized.attrs; } if(typeof obj === "string" || obj === null) { return packTag(tagName, attrs, obj); } var addToChilds = function(value) { if(childs != '') { childs += newline; } childs += value; } var addEventAttribute = function(obj) { var addition = []; for(var eventName in obj) { addition.push(eventName.replace(/^\$/, '') + ':' + obj[eventName]); } if(addition.length > 0) { if(/data-absurd-event/g.test(attrs)) { attrs.replace(/data-absurd-event="(.*)"/, 'data-absurd-event="$1,' + addition.join(',') + '"'); } else { attrs += ' data-absurd-event="' + addition.join(',') + '"'; } } } // process directives for(var directiveName in obj) { var value = obj[directiveName]; if(/^\$/.test(directiveName)) { addEventAttribute(obj); } else { switch(directiveName) { case "_attrs": for(var attrName in value) { if(typeof value[attrName] === "function") { attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName]() + "\""; } else { attrs += " " + prepareProperty(attrName, passedOptions) + "=\"" + value[attrName] + "\""; } } break; case "_": addToChilds(value); break; case "_tpl": if(typeof value == "string") { addToChilds(processTemplate(value)); } else if(value instanceof Array) { var tmp = ''; for(var i=0; tpl=value[i]; i++) { tmp += processTemplate(tpl) if(i < value.length-1) tmp += newline; } addToChilds(tmp); } break; case "_include": var tmp = ''; var add = function(o) { if(typeof o === "function") { o = o(); } if(o.css && o.html) { o = o.html; } // catching a component tmp += process('', o); } if(value instanceof Array) { for(var i=0; i 0) { var tmp = ''; for(var i=0; v=value[i]; i++) { tmp += process('', typeof v == "function" ? v() : v); if(i < value.length-1) tmp += newline; } addToChilds(process(directiveName, tmp)); } else { addToChilds(process(directiveName, value)); } break; case "function": addToChilds(process(directiveName, value())); break; } break; } } } if(tagName != '') { html += packTag(tagName, attrs, childs); } else { html += childs; } return html; } var packTag = function(tagName, attrs, childs) { var html = ''; if(tagName == '' && attrs == '' && childs != '') { return childs; } tagName = tagName == '' ? 'div' : tagName; if(childs !== null) { html += '<' + prepareProperty(tagName, passedOptions) + attrs + '>' + newline + childs + newline + ''; } else { html += '<' + prepareProperty(tagName, passedOptions) + attrs + '/>'; } return html; } var prepareHTML = function(html) { html = require("./helpers/TemplateEngine")(html.replace(/[\r\t\n]/g, ''), passedOptions); if(passedOptions.minify) { return html; } else { return beautifyHTML(html, {indent_size: passedOptions.indentSize || 4}); } } lib.processors.html.HTML = function() { var processor = function(rules, callback, options) { data = rules; callback = callback || function() {}; options = passedOptions = options || defaultOptions; var html = prepareHTML(processTemplate("mainstream")); callback(null, html); return html; } processor.type = "html"; return processor; } lib.processors.html.helpers.PropAnalyzer = function(prop) { var res = { tag: '', attrs: '' }, numOfChars = prop.length, tagName = "", className = "", readingClass = false, classes = [], idName = "", readingId = false, ids = [], attributes = "", readingAttributes = false; if(/(#|\.|\[|\])/gi.test(prop) === false) { return { tag: prop, attrs: '' }; } for(var i=0; i/g, reExp = /(^( )?(var|if|for|else|switch|case|break|{|}|;))(.*)?/g, code = 'with(obj) { var r=[];\n', cursor = 0, result, match; var add = function(line, js) { js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); return add; } while(match = re.exec(html)) { add(html.slice(cursor, match.index))(match[1], true); cursor = match.index + match[0].length; } add(html.substr(cursor, html.length - cursor)); code = (code + 'return r.join(""); }').replace(/[\r\t\n]/g, ' '); try { result = new Function('obj', code).apply(options, [options]); } catch(err) { console.error("'" + err.message + "'", " in \n\nCode:\n", code, "\n"); } return result; } ; return client(); })(window);