Skip to content

Commit

Permalink
Sync JointJS 0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDurman committed Sep 10, 2015
1 parent b7a4f9f commit 0c82a3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 19 additions & 4 deletions src/vectorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ V = Vectorizer = (function() {
return 'v-' + id;
}

// Replace all spaces with the Unicode No-break space (http://www.fileformat.info/info/unicode/char/a0/index.htm).
// IE would otherwise collapse all spaces into one. This is used in the text() method but it is
// also exposed so that the programmer can use it in case he needs to. This is useful e.g. in tests
// when you want to compare the actual DOM text content without having to add the unicode character in
// the place of all spaces.
function sanitizeText(text) {
return (text || '').replace(/ /g, '\u00A0');
}

function isObject(o) {
return Object(o) === Object(o);
return o === Object(o);
}

function isArray(o) {
Expand Down Expand Up @@ -355,6 +364,9 @@ V = Vectorizer = (function() {

text: function(content, opt) {

// Replace all spaces with the Unicode No-break space (http://www.fileformat.info/info/unicode/char/a0/index.htm).
// IE would otherwise collapse all spaces into one.
content = sanitizeText(content);
opt = opt || {};
var lines = content.split('\n');
var i = 0;
Expand Down Expand Up @@ -487,11 +499,12 @@ V = Vectorizer = (function() {

} else {

// Make sure the textContent is never empty. If it is, add an additional
// space (an invisible character) so that following lines are correctly
// Make sure the textContent is never empty. If it is, add a dummy
// character and make it invisible, making the following lines correctly
// relatively positioned. `dy=1em` won't work with empty lines otherwise.
vLine.addClass('v-empty-line');
vLine.node.textContent = ' ';
vLine.node.style.opacity = 0;
vLine.node.textContent = '-';
}

V(textNode).append(vLine);
Expand Down Expand Up @@ -1337,6 +1350,8 @@ V = Vectorizer = (function() {
return annotations;
};

V.sanitizeText = sanitizeText;

return V;

})();
10 changes: 5 additions & 5 deletions test/jointjs/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('construction', function() {
equal(textEls.length, 1, 'there is exactly one <text> element in the paper');
equal(rectEls.length, 1, 'there is exactly one <rect> element in the paper');

equal(textEls[0].textContent, 'my rectangle', 'text element has a proper content');
equal(textEls[0].textContent, V.sanitizeText('my rectangle'), 'text element has a proper content');

});

Expand All @@ -63,7 +63,7 @@ asyncTest('async: resetCells', function() {
equal(textEls.length, 3, 'there is exactly 3 <text> elements in the paper');
equal(rectEls.length, 3, 'there is exactly 3 <rect> elements in the paper');

equal(textEls[0].textContent, 'my rectangle', 'text element has a proper content');
equal(textEls[0].textContent, V.sanitizeText('my rectangle'), 'text element has a proper content');

start();

Expand Down Expand Up @@ -95,7 +95,7 @@ asyncTest('async: addCells', function() {
equal(textEls.length, 5, 'there is exactly 5 <text> elements in the paper');
equal(rectEls.length, 5, 'there is exactly 5 <rect> elements in the paper');

equal(textEls[0].textContent, 'my rectangle', 'text element has a proper content');
equal(textEls[0].textContent, V.sanitizeText('my rectangle'), 'text element has a proper content');

start();

Expand Down Expand Up @@ -620,8 +620,8 @@ test('clone()', function() {
equal(textEls.length, 2, 'there are exactly two <text> elements in the paper');
equal(rectEls.length, 2, 'there are exactly two <rect> elements in the paper');

equal(textEls[0].textContent, 'my rectangle', 'text element has a proper content');
equal(textEls[1].textContent, 'my rectangle', 'text element of the cloned element has a proper content');
equal(textEls[0].textContent, V.sanitizeText('my rectangle'), 'text element has a proper content');
equal(textEls[1].textContent, V.sanitizeText('my rectangle'), 'text element of the cloned element has a proper content');

checkBbox(this.paper, r2, 20, 30, 120, 80, 'cloned element is at the exact same position as the original element');

Expand Down

0 comments on commit 0c82a3d

Please sign in to comment.