Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added [serialize] parameter
  • Loading branch information
icsmw committed Jun 5, 2016
1 parent dbed891 commit 3cdd1ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
46 changes: 33 additions & 13 deletions patterns/patterns.js
Expand Up @@ -161,6 +161,10 @@
HOOK_WRAPPERS: '.flex_patterns_hook_wrapper'
},
},
serialize: [
[/</gi, '&lt;'],
[/>/gi, '&gt;'],
],
other : {
INDEXES : '__indexes'
}
Expand Down Expand Up @@ -1560,8 +1564,17 @@
}
return model.current.binds;
},
update : function (clone) {
update : function (clone, _serialize) {
function bind(group, binds) {
function serialize(value) {
var result = value;
if (_serialize) {
settings.serialize.forEach(function (pear) {
result = result.replace(pear[0], pear[1]);
});
}
return result;
};
function correctStyle(prop) {
var result = '';
prop.split('-').forEach(function (part, index) {
Expand Down Expand Up @@ -1632,7 +1645,8 @@
(function (binds, key, node, attr_name, handles) {
binds[key] = node.getAttribute(attr_name);
_object(binds).binding().bind(key, function (current, previous) {
var execute = false;
var execute = false,
current = serialize(current);
if (node.getAttribute(attr_name) !== current) {
node.setAttribute(attr_name, current);
execute = true;
Expand All @@ -1653,6 +1667,7 @@
(function (binds, key, node, prop, handles) {
binds[key] = node.style[prop];
_object(binds).binding().bind(key, function (current, previous) {
var current = serialize(current);
if (node.style[prop] !== current) {
node.style[prop] = current;
executeHandles(handles, node.style, prop, current);
Expand All @@ -1665,6 +1680,7 @@
(function (binds, key, node, prop, handles) {
binds[key] = node[prop];
_object(binds).binding().bind(key, function (current, previous) {
var current = serialize(current);
if (node[prop] !== current) {
node[prop] = current;
executeHandles(handles, node, prop, current);
Expand Down Expand Up @@ -2016,7 +2032,7 @@
},
};
methods = {
build : function (_hooks, _resources, _conditions) {
build : function (_hooks, _resources, _conditions, _serialize) {
var nodes = [],
_map = [],
_binds = [],
Expand All @@ -2039,7 +2055,7 @@
dom. iteration();
hooks. apply(_hooks, clone.setters, hooks_map);
map. update(clone.clone);
model. update(clone.clone);
model. update(clone.clone, _serialize);
model. clear(clone.clone);
dom. update(clone.dom);
nodes = nodes.concat(Array.prototype.filter.call(clone.clone.childNodes, function () { return true; }));
Expand Down Expand Up @@ -2072,9 +2088,9 @@
});
}
},
bind : function (hooks, resources, conditions) {
bind : function (hooks, resources, conditions, serialize) {
return function () {
return methods.build(hooks, resources, conditions);
return methods.build(hooks, resources, conditions, serialize);
};
}
};
Expand Down Expand Up @@ -2468,7 +2484,7 @@
throw logs.caller.CANNOT_GET_CHILD_PATTERN;
} else {
hooks.apply(_hooks);
return _instance.bind(_hooks, value.resources(), value.conditions());
return _instance.bind(_hooks, value.resources(), value.conditions(), value.serialize());
}
}
},
Expand Down Expand Up @@ -2518,7 +2534,7 @@
hooks.apply();
privates.pattern = instance.init(self.url);
if (privates.pattern !== null) {
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions);
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions, privates.serialize);
if (privates.pattern instanceof settings.classes.RESULT) {
privates.pattern.mount(privates.node, privates.before, privates.after, privates.replace);
if (privates.callbacks.success !== null) {
Expand All @@ -2541,7 +2557,7 @@
hooks.apply();
privates.pattern = instance.init(self.url);
if (privates.pattern !== null) {
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions);
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions, privates.serialize);
if (privates.pattern instanceof settings.classes.RESULT) {
return privates.pattern;
}
Expand All @@ -2553,14 +2569,16 @@
};
returning = {
render : render,
hooks : function () { return privates.hooks; },
resources : function () { return privates.resources;},
conditions : function () { return privates.conditions; }
};
hooks : function () { return privates.hooks; },
resources : function () { return privates.resources; },
conditions : function () { return privates.conditions; },
serialize : function () { return privates.serialize; },
};
return {
render : returning.render,
hooks : returning.hooks,
conditions : returning.conditions,
serialize : returning.serialize,
resources : returning.resources
};
},
Expand Down Expand Up @@ -2591,6 +2609,7 @@
{ name: 'conditions', type: 'object', value: null },
{ name: 'callbacks', type: 'object', value: {} },
{ name: 'resources', type: 'object', value: {} },
{ name: 'serialize', type: 'boolean', value: true },
{ name: 'remove_missing_hooks', type: 'boolean', value: true }]) !== false) {
flex.oop.objects.validate(parameters.callbacks, [ { name: 'before', type: 'function', value: null },
{ name: 'success', type: 'function', value: null },
Expand All @@ -2611,6 +2630,7 @@
data : parameters.data,
conditions : parameters.conditions,
callbacks : parameters.callbacks,
serialize : parameters.serialize,
remove_missing_hooks: parameters.remove_missing_hooks,
resources : parameters.resources,
//Local
Expand Down
2 changes: 1 addition & 1 deletion patterns/patterns.min.js

Large diffs are not rendered by default.

0 comments on commit 3cdd1ba

Please sign in to comment.