Skip to content

Commit 711cec9

Browse files
committed
Merge branch 't/9816'
2 parents e6f88ac + 2252695 commit 711cec9

File tree

3 files changed

+298
-195
lines changed

3 files changed

+298
-195
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ CKEditor 4 Changelog
33

44
## CKEditor 4.2.1
55

6+
* [#9816](http://dev.ckeditor.com/ticket/9816): Floating toolbar does not reposition vertically in several cases.
7+
68
## CKEditor 4.2
79

810
**Important Notes:**

core/tools.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,73 @@
10121012
}
10131013

10141014
return !!domain;
1015+
},
1016+
1017+
/**
1018+
* Buffers `input` events (or any `input` calls)
1019+
* and triggers `output` not more often than once per `minInterval`.
1020+
*
1021+
* var buffer = CKEDITOR.tools.eventsBuffer( 200, function() {
1022+
* console.log( 'foo!' );
1023+
* } );
1024+
*
1025+
* buffer.input();
1026+
* // 'foo!' logged immediately
1027+
* buffer.input();
1028+
* // nothing logged
1029+
* buffer.input();
1030+
* // nothing logged
1031+
* // ... after 200ms single 'foo!' will be logged
1032+
*
1033+
* Can be easily used with event:
1034+
*
1035+
* var buffer = CKEDITOR.tools.eventsBuffer( 200, function() {
1036+
* console.log( 'foo!' );
1037+
* } );
1038+
*
1039+
* editor.on( 'key', buffer.input );
1040+
* // Note: there's no need to bind buffer as a context.
1041+
*
1042+
* @since 4.2.1
1043+
* @param {Number} minInterval Minimum interval between `output` calls in milliseconds.
1044+
* @param {Function} output Function that will be executed as `output`.
1045+
* @returns {Object}
1046+
* @returns {Function} return.input Buffer's input method.
1047+
* @returns {Function} return.reset Resets buffered events – `output` will not be executed
1048+
* until next `input` is triggered.
1049+
*/
1050+
eventsBuffer: function( minInterval, output ) {
1051+
var scheduled,
1052+
lastOutput = 0;
1053+
1054+
function triggerOutput() {
1055+
lastOutput = ( new Date() ).getTime();
1056+
scheduled = false;
1057+
output();
1058+
}
1059+
1060+
return {
1061+
input: function() {
1062+
if ( scheduled )
1063+
return;
1064+
1065+
var diff = ( new Date() ).getTime() - lastOutput;
1066+
1067+
// If less than minInterval passed after last check,
1068+
// schedule next for minInterval after previous one.
1069+
if ( diff < minInterval )
1070+
scheduled = setTimeout( triggerOutput, minInterval - diff );
1071+
else
1072+
triggerOutput();
1073+
},
1074+
1075+
reset: function() {
1076+
if ( scheduled )
1077+
clearTimeout( scheduled );
1078+
1079+
scheduled = lastOutput = 0;
1080+
}
1081+
};
10151082
}
10161083
};
10171084
})();

0 commit comments

Comments
 (0)