Skip to content

Commit

Permalink
getLettersMap() now returns [{element: HTMLElement, index: Number}]
Browse files Browse the repository at this point in the history
  • Loading branch information
kityan committed Sep 6, 2014
1 parent 23f64bb commit b9052a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions morfana.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ $(document).ready(function(){
*/
function wrapPadding(data, letterIndex, paddingType){
var rng = rangy.createRange();
rng.setStart(data.maps.actual[letterIndex].obj, data.maps.actual[letterIndex].index);
rng.setEnd(data.maps.actual[letterIndex].obj, data.maps.actual[letterIndex].index+1);
rng.setStart(data.maps.actual[letterIndex].element, data.maps.actual[letterIndex].index);
rng.setEnd(data.maps.actual[letterIndex].element, data.maps.actual[letterIndex].index+1);
var newNode = document.createElement('span');
var val = Math.ceil((paddingType == 'after')?(data.height * 0.4 + 13):5); // padding params in px
var side = (paddingType != 'start') ? 'right' : 'left';
Expand Down Expand Up @@ -263,15 +263,15 @@ function calculateMetrics(data, justHeightReturnWordHeight){

tmpDiv.find('.morfana-paddings').each(function(){var obj = $(this); if (obj.text() == ''){obj.remove()}});
if (data.letters && (data.letters[i].stop['ok'] || data.letters[i].after['ok']) ){
if (data.letters[i].stop['ok']){$(tmpDiv_map[i].obj).unwrap();}
if (data.letters[i].after['ok']){$(tmpDiv_map[i].obj).unwrap();}
if (data.letters[i].stop['ok']){$(tmpDiv_map[i].element).unwrap();}
if (data.letters[i].after['ok']){$(tmpDiv_map[i].element).unwrap();}
}

var newNode = document.createElement('span');
$(newNode).css('letter-spacing', 0);

rng.setStart(tmpDiv_map[i].obj, tmpDiv_map[i].index);
rng.setEnd(tmpDiv_map[i].obj, tmpDiv_map[i].index+1);
rng.setStart(tmpDiv_map[i].element, tmpDiv_map[i].index);
rng.setEnd(tmpDiv_map[i].element, tmpDiv_map[i].index+1);
rng.surroundContents(newNode);

data.metrics[i].w = tmpDiv.width();
Expand Down Expand Up @@ -357,7 +357,7 @@ function getLettersMap(obj) {
} else {
for (var j=0; j < data.length; j++) {
// map all letters of this fragment of word
map[shift] = {'obj': obj[0].childNodes[i], 'index': j};
map[shift] = {'element': obj[0].childNodes[i], 'index': j};
shift++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/markup_children.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/rangy/1.2.3/rangy-core.js"></script>
<script type="text/javascript" src="./../morfana.js"></script>
<script type="text/x-morfana-config">Morfana.configure({autoStart: false});</script>
<script type="text/x-morfana-config">Morfana.configure({autoStart: false, stroke: 'rgb(255,0,0)', strokeWidth: 3});</script>
</head>
<body>
<ul>
Expand Down

0 comments on commit b9052a6

Please sign in to comment.