From 77718bcb25ce5cf557a48d748a2ca5050e03c9af Mon Sep 17 00:00:00 2001 From: Pavel Kityan Date: Mon, 29 Sep 2014 22:46:02 +0400 Subject: [PATCH] callback for Morfana.draw() --- README.md | 4 ++++ morfana.js | 15 +++++++++++---- tests/test.callback.html | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/test.callback.html diff --git a/README.md b/README.md index 607a768..6b07331 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/morfana.js b/morfana.js index 015df4a..fe50be1 100644 --- a/morfana.js +++ b/morfana.js @@ -5,8 +5,8 @@ Copyright 2013-2014, Pavel Kityan (pavel@kityan.ru) 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) { @@ -27,6 +27,7 @@ var development = {colorize: false, log: false, showTmpDiv: false}; var config = {} ; +var onQueueEmptyCallback; // set default values configure({ @@ -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); @@ -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; + } + } } diff --git a/tests/test.callback.html b/tests/test.callback.html new file mode 100644 index 0000000..496220e --- /dev/null +++ b/tests/test.callback.html @@ -0,0 +1,29 @@ + + + + + + + + + + +двумя́ста́ми +двумя́ста́ми +next + + + + + + +