Skip to content

Commit

Permalink
callback for Morfana.draw()
Browse files Browse the repository at this point in the history
  • Loading branch information
kityan committed Sep 29, 2014
1 parent 9c9d1dd commit 77718bc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Demo HTML document
For more demos visit [official website](http://morfana.ru/)

##Changelog
`2.3.0b` / `29.09.2014`
- Added 'callback' to Morfana.draw(). Called when queue goes empty.


`2.2.0b` / `10.09.2014`
- Code refactoring: adding paddings for '(zero)-ending' and positioning them
- Changed default of configp['zeroEndingWidthFactor'], now is 0.7
Expand Down
15 changes: 11 additions & 4 deletions morfana.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Copyright 2013-2014, Pavel Kityan ([email protected])
Licensed under the MIT license.
Version: 2.2.0b
Build date: 10 September 2014
Version: 2.3.0b
Build date: 29 September 2014
*/

(function (root, factory) {
Expand All @@ -27,6 +27,7 @@

var development = {colorize: false, log: false, showTmpDiv: false};
var config = {} ;
var onQueueEmptyCallback;

// set default values
configure({
Expand Down Expand Up @@ -549,7 +550,8 @@ function setAllChildren(obj, param, value) {
* @param {string} selector - selector for jQuery
* @param {string} markup - value for adding/replacing element's attribute "data-morfana-markup".
*/
function draw (selector, markup) {
function draw (selector, markup, callback) {
onQueueEmptyCallback = (callback) ? callback : undefined;
if (selector) {
if (markup) {
$(selector).data('morfana-markup', markup);
Expand Down Expand Up @@ -587,7 +589,12 @@ function doQueue() {
}
if (qty > 1) { // more than 1 berfore queue.pop()?
setTimeout(doQueue, 10);
}
} else { // queue empty
if (onQueueEmptyCallback && typeof onQueueEmptyCallback == 'function'){
onQueueEmptyCallback();
onQueueEmptyCallback = undefined;
}
}
}


Expand Down
29 changes: 29 additions & 0 deletions tests/test.callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<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>
</head>
<body>
<span class="test1" style="font-size: 25px; color: red;" data-morfana-markup="ok:3-5;ok:9-12;ko:1-2;ko:6-8;">двумя́ста́ми</span>
<span class="test1" style="font-size: 25px; color: red;" data-morfana-markup="ok:3-5;ok:9-12;ko:1-2;ko:6-8;">двумя́ста́ми</span>
<span class="next">next</span>


<script type="text/javascript">
$(document).ready(function(){
Morfana.draw('.test1', false, function(){console.log('callback1');});

$('.next').on('click', function(){
Morfana.draw('.test1', 'ko:1-1;ko:2-2');
});

});
</script>
</body>
</html>


0 comments on commit 77718bc

Please sign in to comment.