Skip to content

Commit 3cdd1ba

Browse files
committed
Added [serialize] parameter
1 parent dbed891 commit 3cdd1ba

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

patterns/patterns.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@
161161
HOOK_WRAPPERS: '.flex_patterns_hook_wrapper'
162162
},
163163
},
164+
serialize: [
165+
[/</gi, '&lt;'],
166+
[/>/gi, '&gt;'],
167+
],
164168
other : {
165169
INDEXES : '__indexes'
166170
}
@@ -1560,8 +1564,17 @@
15601564
}
15611565
return model.current.binds;
15621566
},
1563-
update : function (clone) {
1567+
update : function (clone, _serialize) {
15641568
function bind(group, binds) {
1569+
function serialize(value) {
1570+
var result = value;
1571+
if (_serialize) {
1572+
settings.serialize.forEach(function (pear) {
1573+
result = result.replace(pear[0], pear[1]);
1574+
});
1575+
}
1576+
return result;
1577+
};
15651578
function correctStyle(prop) {
15661579
var result = '';
15671580
prop.split('-').forEach(function (part, index) {
@@ -1632,7 +1645,8 @@
16321645
(function (binds, key, node, attr_name, handles) {
16331646
binds[key] = node.getAttribute(attr_name);
16341647
_object(binds).binding().bind(key, function (current, previous) {
1635-
var execute = false;
1648+
var execute = false,
1649+
current = serialize(current);
16361650
if (node.getAttribute(attr_name) !== current) {
16371651
node.setAttribute(attr_name, current);
16381652
execute = true;
@@ -1653,6 +1667,7 @@
16531667
(function (binds, key, node, prop, handles) {
16541668
binds[key] = node.style[prop];
16551669
_object(binds).binding().bind(key, function (current, previous) {
1670+
var current = serialize(current);
16561671
if (node.style[prop] !== current) {
16571672
node.style[prop] = current;
16581673
executeHandles(handles, node.style, prop, current);
@@ -1665,6 +1680,7 @@
16651680
(function (binds, key, node, prop, handles) {
16661681
binds[key] = node[prop];
16671682
_object(binds).binding().bind(key, function (current, previous) {
1683+
var current = serialize(current);
16681684
if (node[prop] !== current) {
16691685
node[prop] = current;
16701686
executeHandles(handles, node, prop, current);
@@ -2016,7 +2032,7 @@
20162032
},
20172033
};
20182034
methods = {
2019-
build : function (_hooks, _resources, _conditions) {
2035+
build : function (_hooks, _resources, _conditions, _serialize) {
20202036
var nodes = [],
20212037
_map = [],
20222038
_binds = [],
@@ -2039,7 +2055,7 @@
20392055
dom. iteration();
20402056
hooks. apply(_hooks, clone.setters, hooks_map);
20412057
map. update(clone.clone);
2042-
model. update(clone.clone);
2058+
model. update(clone.clone, _serialize);
20432059
model. clear(clone.clone);
20442060
dom. update(clone.dom);
20452061
nodes = nodes.concat(Array.prototype.filter.call(clone.clone.childNodes, function () { return true; }));
@@ -2072,9 +2088,9 @@
20722088
});
20732089
}
20742090
},
2075-
bind : function (hooks, resources, conditions) {
2091+
bind : function (hooks, resources, conditions, serialize) {
20762092
return function () {
2077-
return methods.build(hooks, resources, conditions);
2093+
return methods.build(hooks, resources, conditions, serialize);
20782094
};
20792095
}
20802096
};
@@ -2468,7 +2484,7 @@
24682484
throw logs.caller.CANNOT_GET_CHILD_PATTERN;
24692485
} else {
24702486
hooks.apply(_hooks);
2471-
return _instance.bind(_hooks, value.resources(), value.conditions());
2487+
return _instance.bind(_hooks, value.resources(), value.conditions(), value.serialize());
24722488
}
24732489
}
24742490
},
@@ -2518,7 +2534,7 @@
25182534
hooks.apply();
25192535
privates.pattern = instance.init(self.url);
25202536
if (privates.pattern !== null) {
2521-
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions);
2537+
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions, privates.serialize);
25222538
if (privates.pattern instanceof settings.classes.RESULT) {
25232539
privates.pattern.mount(privates.node, privates.before, privates.after, privates.replace);
25242540
if (privates.callbacks.success !== null) {
@@ -2541,7 +2557,7 @@
25412557
hooks.apply();
25422558
privates.pattern = instance.init(self.url);
25432559
if (privates.pattern !== null) {
2544-
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions);
2560+
privates.pattern = privates.pattern.build(privates.hooks, privates.resources, privates.conditions, privates.serialize);
25452561
if (privates.pattern instanceof settings.classes.RESULT) {
25462562
return privates.pattern;
25472563
}
@@ -2553,14 +2569,16 @@
25532569
};
25542570
returning = {
25552571
render : render,
2556-
hooks : function () { return privates.hooks; },
2557-
resources : function () { return privates.resources;},
2558-
conditions : function () { return privates.conditions; }
2559-
};
2572+
hooks : function () { return privates.hooks; },
2573+
resources : function () { return privates.resources; },
2574+
conditions : function () { return privates.conditions; },
2575+
serialize : function () { return privates.serialize; },
2576+
};
25602577
return {
25612578
render : returning.render,
25622579
hooks : returning.hooks,
25632580
conditions : returning.conditions,
2581+
serialize : returning.serialize,
25642582
resources : returning.resources
25652583
};
25662584
},
@@ -2591,6 +2609,7 @@
25912609
{ name: 'conditions', type: 'object', value: null },
25922610
{ name: 'callbacks', type: 'object', value: {} },
25932611
{ name: 'resources', type: 'object', value: {} },
2612+
{ name: 'serialize', type: 'boolean', value: true },
25942613
{ name: 'remove_missing_hooks', type: 'boolean', value: true }]) !== false) {
25952614
flex.oop.objects.validate(parameters.callbacks, [ { name: 'before', type: 'function', value: null },
25962615
{ name: 'success', type: 'function', value: null },
@@ -2611,6 +2630,7 @@
26112630
data : parameters.data,
26122631
conditions : parameters.conditions,
26132632
callbacks : parameters.callbacks,
2633+
serialize : parameters.serialize,
26142634
remove_missing_hooks: parameters.remove_missing_hooks,
26152635
resources : parameters.resources,
26162636
//Local

patterns/patterns.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)