Skip to content

Commit

Permalink
Merge pull request #75 from RandomlyKnighted/throttle-fix
Browse files Browse the repository at this point in the history
Removed underscoreThrottle function by @RandomlyKnighted 
If you experience issues needing throttle, please let us know.
  • Loading branch information
steveathon committed Dec 30, 2015
2 parents 627472c + cddb0fd commit b4b774e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 56 deletions.
10 changes: 5 additions & 5 deletions examples/multiple-editors.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<link href="../bower_components/google-code-prettify/src/prettify.css" rel="stylesheet" />
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet" />
<link href="../css/style.css" rel="stylesheet" />
<link href="../css/style.css" rel="stylesheet" />
</head>

<body>
<div class="container">
<h1>Multiple Editors with Toolbars</h1>
Expand Down Expand Up @@ -63,8 +63,8 @@ <h3>First Editor</h3>
</div>
<div class="btn-group">
<a class="btn btn-default" data-edit="unlink" title="Remove Hyperlink"><i class="fa fa-unlink"></i></a>
<span class="btn btn-default" title="Insert picture (or just drag & drop)" id="pictureBtn"> <i class="fa fa-picture-o"></i>
<input class="imgUpload" type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
<span class="btn btn-default" title="Insert picture (or just drag & drop)" id="picBtn"> <i class="fa fa-picture-o"></i>
<input class="imgUpload" type="file" data-role="magic-overlay" data-target="#picBtn" data-edit="insertImage" />
</span>
</div>
<div class="btn-group">
Expand Down Expand Up @@ -147,7 +147,7 @@ <h3>Second Editor</h3>
<script type='text/javascript'>
$('#first-editor').wysiwyg();
$('#second-editor').wysiwyg();

$(".dropdown-menu > input").click(function (e) {
e.stopPropagation();
});
Expand Down
2 changes: 1 addition & 1 deletion js/bootstrap-wysiwyg.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 8 additions & 50 deletions src/bootstrap-wysiwyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,7 @@

(function ($) {
'use strict';
/** underscoreThrottle()
* From underscore http://underscorejs.org/docs/underscore.html
*/
var underscoreThrottle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) {
options = {};
}
var later = function() {
previous = options.leading === false ? 0 : $.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) {
context = args = null;
}
};
return function() {
var now = $.now();
if (!previous && options.leading === false) {
previous = now;
}
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) {
context = args = null;
}
}
else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};

var readFileIntoDataUrl = function (fileInfo) {
var loader = $.Deferred(),
fReader = new FileReader();
Expand Down Expand Up @@ -120,10 +78,10 @@
var parts = commandWithArgs.split('-');

if ( parts.length === 1 ) {
underscoreThrottle(document.execCommand(command, false, args), options.keypressTimeout);
document.execCommand(command, false, args);
}
else if ( parts[0] === 'format' && parts.length === 2 ) {
underscoreThrottle(document.execCommand('formatBlock', false, parts[1] ), options.keypressTimeout);
document.execCommand('formatBlock', false, parts[1] );
}

editor.trigger('change');
Expand All @@ -135,7 +93,7 @@
if (editor.attr('contenteditable') && editor.is(':visible')) {
e.preventDefault();
e.stopPropagation();
underscoreThrottle(execCommand(command), options.keypressTimeout);
execCommand(command);
}
}).keyup(hotkey, function (e) {
if (editor.attr('contenteditable') && editor.is(':visible')) {
Expand Down Expand Up @@ -206,7 +164,7 @@
$.each(files, function (idx, fileInfo) {
if (/^image\//.test(fileInfo.type)) {
$.when(readFileIntoDataUrl(fileInfo)).done(function (dataUrl) {
underscoreThrottle(execCommand('insertimage', dataUrl), options.keypressTimeout);
execCommand('insertimage', dataUrl);
editor.trigger('image-inserted');
}).fail(function (e) {
options.fileUploadError("file-reader", e);
Expand All @@ -219,7 +177,7 @@
markSelection = function (input, color) {
restoreSelection();
if (document.queryCommandSupported('hiliteColor')) {
underscoreThrottle(document.execCommand('hiliteColor', false, color || 'transparent'), options.keypressTimeout);
document.execCommand('hiliteColor', false, color || 'transparent');
}
saveSelection();
input.data(options.selectionMarker, color);
Expand All @@ -233,7 +191,7 @@
toggleHtmlEdit();
}
else {
underscoreThrottle(execCommand($(this).data(options.commandRole)), options.keypressTimeout);
execCommand($(this).data(options.commandRole));
}
saveSelection();
});
Expand All @@ -245,7 +203,7 @@
restoreSelection();
if (newValue) {
editor.focus();
underscoreThrottle(execCommand($(this).data(options.commandRole), newValue), options.keypressTimeout);
execCommand($(this).data(options.commandRole), newValue);
}
saveSelection();
}).on('focus', function () {
Expand Down

0 comments on commit b4b774e

Please sign in to comment.