lemonadejs
Advanced tools
Comparing version 2.1.2 to 2.1.5
/** | ||
* Lemonadejs v2.1.2.beta | ||
* Lemonadejs v2.1.5.beta | ||
* | ||
@@ -12,4 +12,4 @@ * Website: https://lemonadejs.net | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
global.lemonade = factory(); | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
global.lemonade = factory(); | ||
}(this, (function () { | ||
@@ -34,2 +34,9 @@ | ||
/** | ||
* Is a class | ||
*/ | ||
var isClass = function(f) { | ||
return typeof f === 'function' && /^class\s/.test(Function.prototype.toString.call(f)); | ||
} | ||
/** | ||
* Process all methods queued from the ready property | ||
@@ -115,3 +122,3 @@ */ | ||
*/ | ||
var dispatch = function(property) { | ||
var dispatch = function(property, first) { | ||
var self,t,v,e,p,i = null; | ||
@@ -144,3 +151,3 @@ // Tracking | ||
// Onchange // DOCS update | ||
if (typeof(self.onchange) == 'function') { | ||
if (! first && typeof(self.onchange) == 'function') { | ||
self.onchange.call(e, property, t, self); | ||
@@ -157,2 +164,4 @@ } | ||
var lemon = this; | ||
// First call | ||
var first = true; | ||
// Create the observer | ||
@@ -164,3 +173,5 @@ Object.defineProperty(this.self, p, { | ||
// Refresh binded elements | ||
dispatch.call(lemon, p); | ||
dispatch.call(lemon, p, first); | ||
// First call | ||
first = false; | ||
}, | ||
@@ -175,25 +186,22 @@ get: function() { | ||
var create = function(element, res, type) { | ||
var tokens = res.v.match(/self\.([a-zA-Z0-9_].*?)*/g); | ||
if (tokens.length) { | ||
var self = this.self; | ||
// Value | ||
var value = eval(res.v) || ''; | ||
// Create text node | ||
if (type == 'textContent') { | ||
var e = document.createTextNode(value); | ||
if (element.childNodes[0]) { | ||
element.insertBefore(e, element.childNodes[0].splitText(res.p)); | ||
} else { | ||
element.appendChild(e); | ||
} | ||
} else if (type == '@loop') { | ||
var e = element; | ||
var self = this.self; | ||
// Value | ||
var value = eval(res.v) || ''; | ||
// Create text node | ||
if (type == 'textContent') { | ||
var e = document.createTextNode(value); | ||
if (element.childNodes[0]) { | ||
element.insertBefore(e, element.childNodes[0].splitText(res.p)); | ||
} else { | ||
var e = element; | ||
setAttribute(element, value, type); | ||
element.appendChild(e); | ||
} | ||
} else if (type == '@loop') { | ||
var e = element; | ||
} else { | ||
var e = element; | ||
setAttribute(element, value, type); | ||
} | ||
if (! e) { | ||
return; | ||
} | ||
var tokens = res.v.match(/self\.([a-zA-Z0-9_].*?)*/g); | ||
if (tokens && tokens.length) { | ||
for (var i = 0; i < tokens.length; i++) { | ||
@@ -255,3 +263,2 @@ // Get property name | ||
} | ||
for (var i = result.length - 1; i >= 0; i--) { | ||
@@ -296,6 +303,6 @@ create.call(this, e, result[i], type); | ||
// Mark custom handlers | ||
if (this.components && element.constructor == HTMLUnknownElement) { | ||
if (this.components) { | ||
// Method name | ||
var m = element.tagName; | ||
// Custom uccase | ||
// Custom ucfirst | ||
m = m.charAt(0).toUpperCase() + m.slice(1).toLowerCase(); | ||
@@ -413,3 +420,3 @@ // Expected function | ||
// Create componet | ||
L.render(h, r, s, element.template, element); | ||
L.render(h, r, s, element.template, element, lemon.components); | ||
} | ||
@@ -482,6 +489,6 @@ // Remove component container | ||
*/ | ||
L.render = function(o, el, self, t, ref) { | ||
L.render = function(o, el, self, t, ref, ext) { | ||
// Root element but be a valid DOM element | ||
if (! isDOM(el)) { | ||
console.log('DOM element given is not valid') | ||
console.log('Not valid DOM') | ||
return false; | ||
@@ -496,7 +503,7 @@ } | ||
if (typeof(o) == 'function') { | ||
try { | ||
o = o.call(self, t); | ||
} catch { | ||
if (isClass(o)) { | ||
o = new o(self); | ||
o = L.element(o.render(t), o); | ||
o = L.element(o.render(t, ext), o); | ||
} else { | ||
o = o.call(self, t, ext); | ||
} | ||
@@ -550,3 +557,3 @@ } | ||
// Close any custom not fully closed component | ||
t = t.replace(/((<([A-Z]{1}[a-zA-Z0-9_-]+).*)\/.{0,1}>)/g, "$2><\/$3>"); | ||
t = t.replace(/((<([A-Z]{1}[a-zA-Z0-9_-]+)[\s\S]+?)\/.{0,1}>)/gm, "$2><\/$3>"); | ||
// Parse fragment | ||
@@ -553,0 +560,0 @@ t = t.replace(/<>/gi, "<root>").replace(/<\/>/gi, "<\/root>").trim(); |
@@ -17,3 +17,3 @@ { | ||
"main": "dist/lemonade.js", | ||
"version": "2.1.2" | ||
"version": "2.1.5" | ||
} |
23615
592