fixed drafty's handling of undefined values
This commit is contained in:
@@ -6,7 +6,7 @@ and [icons](https://google.github.io/material-design-icons/#icon-font-for-the-we
|
||||
|
||||
This is work in progress. Bugs are expected. The app was tested in the latest Chrome & Firefox only.
|
||||
|
||||
Try it (possibly older version) live at http://api.tinode.co/x/example-react-js/. Login as one of `alice`, `bob`, `carol`, `dave`, `frank`. Password is `<login>123`, e.g. password for `alice` is `alice123`. You can discover other users by email or phone by prefixing them with `email:` or `tel:` respectively. Emails are `<login>@example.com`, e.g. `alice@example.com`, phones are `17025550001` through `17025550009`. The demo is reset every night at 2:15 am Pacific time.
|
||||
Try it (possibly newer or older version) live at https://api.tinode.co/x/example-react-js/. Login as one of `alice`, `bob`, `carol`, `dave`, `frank`. Password is `<login>123`, e.g. password for `alice` is `alice123`. You can discover other users by email or phone by prefixing them with `email:` or `tel:` respectively. Emails are `<login>@example.com`, e.g. `alice@example.com`, phones are `17025550001` through `17025550009`. The demo is reset every night at 2:15 am Pacific time.
|
||||
|
||||
License: [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
|
||||
@@ -507,6 +507,12 @@ Sample JSON representation of the text above:
|
||||
|
||||
var spans = [].concat(fmt);
|
||||
|
||||
// Zero values may have been stripped. Restore them.
|
||||
spans.map(function(s) {
|
||||
s.at = s.at || 0;
|
||||
s.len = s.len || 0;
|
||||
});
|
||||
|
||||
// Soft spans first by start index (asc) then by length (desc).
|
||||
spans.sort(function(a, b) {
|
||||
if (a.at - b.at == 0) {
|
||||
@@ -515,18 +521,23 @@ Sample JSON representation of the text above:
|
||||
return a.at - b.at;
|
||||
});
|
||||
|
||||
console.log(spans);
|
||||
|
||||
// Denormalize entities into spans. Create a copy of the objects to leave
|
||||
// original Drafty object unchanged.
|
||||
spans = spans.map(function(s) {
|
||||
var data;
|
||||
var tp = s.tp;
|
||||
if (s.key + 1 > 0) {
|
||||
if (!tp) {
|
||||
s.key = s.key || 0;
|
||||
data = ent[s.key].data;
|
||||
tp = ent[s.key].tp;
|
||||
}
|
||||
return {tp: tp, data: data, at: s.at, len: s.len};
|
||||
});
|
||||
|
||||
console.log(spans);
|
||||
|
||||
return forEach(txt, 0, txt.length, spans, formatter, context);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user