Skip to content

Commit

Permalink
Clean up variable scope. No changes to functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilton Janfield committed Sep 12, 2015
1 parent 1c9f9ec commit f215441
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
24 changes: 11 additions & 13 deletions js/jquery.enhsplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
var splitterCount = 0;
var splitters = [];
var currentSplitter = null;
var dragStartPosition = null;
var disableClick = false;

$.fn.enhsplitter = function (options) {
var data = this.data('splitter');
Expand Down Expand Up @@ -226,8 +224,8 @@
.on('click.splitter', '.splitter_handle', function (e) {
// Prevent clicks if the user started dragging too much.
// Some (all?) browsers fire the click event even after the bar has been dragged hundreds of pixels.
if (disableClick) {
return disableClick = false;
if (currentSplitter.disableClick) {
return currentSplitter.disableClick = false;
}
currentSplitter = $(this).closest('.splitter_container').data('splitter');

Expand Down Expand Up @@ -266,7 +264,7 @@
// first - or duplicate the code, which is bad, m'kay?
$(this).closest('.splitter_bar').trigger('mousedown');

dragStartPosition = (currentSplitter.settings.vertical) ? e.pageX : e.pageY;
currentSplitter.dragStartPosition = (currentSplitter.settings.vertical) ? e.pageX : e.pageY;
})

.on('mousedown.splitter touchstart.splitter', '.splitter_container > .splitter_bar', function (e) {
Expand All @@ -284,26 +282,26 @@
.on('mouseup.splitter touchend.splitter touchleave.splitter touchcancel.splitter', '.splitter_mask, .splitter_container > .splitter_bar', function (e) {
if (currentSplitter) {
e.preventDefault();
dragStartPosition = null;
currentSplitter.dragStartPosition = null;

// If the slider is dropped near it's collapsed position, set a saved position back to its
// original start position so the collapse handle works at least somewhat properly.
if (!currentSplitter.data('savedPosition')) {
if (currentSplitter.settings.collapseNormal) {
if (currentSplitter.currentPosition <= (currentSplitter.settings.lowerLimit + 5)) {
currentSplitter.data('savedPosition', self.translatePosition(currentSplitter.settings.position));
disableClick = false;
currentSplitter.disableClick = false;
}
} else {
if (currentSplitter.settings.vertical) {
if (currentSplitter.currentPosition >= (currentSplitter.containerWidth - currentSplitter.settings.upperLimit - 5)) {
currentSplitter.data('savedPosition', self.translatePosition(currentSplitter.settings.position));
disableClick = false;
currentSplitter.disableClick = false;
}
} else {
if (currentSplitter.currentPosition >= (currentSplitter.containerHeight - currentSplitter.settings.upperLimit - 5)) {
currentSplitter.data('savedPosition', self.translatePosition(currentSplitter.settings.position));
disableClick = false;
currentSplitter.disableClick = false;
}
}
}
Expand All @@ -325,10 +323,10 @@
}

// If the user started the drag with a mousedown on the handle, give it a 5-pixel delay.
if (dragStartPosition !== null) {
if (position > (dragStartPosition + 5) || position < (dragStartPosition - 5)) {
dragStartPosition = null;
disableClick = true;
if (currentSplitter.dragStartPosition !== null) {
if (position > (currentSplitter.dragStartPosition + 5) || position < (currentSplitter.dragStartPosition - 5)) {
currentSplitter.dragStartPosition = null;
currentSplitter.disableClick = true;
} else {
e.preventDefault();
return false;
Expand Down
11 changes: 10 additions & 1 deletion test.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ <h1>jquery.enhsplitter Features Tests</h1>
'Handle should pulsate in size as mouse moves left/right.'
);

var splitter = addTest(
{limit: 50},
'Test of CSS max-width functionality. The splitter has a limit of 50 set, however Panel One has a max-width of 200 and therefore should not be able to get any larger than that.<br>' +
'min-width is set, but not respected in regards to splitter position (but is useful to force a minimum content size, generating a scroll bar when needed)'
);
var panel = splitter.children().first().children().first();
panel.text('min-width: 100px; max-width: 200px;');
panel.css('min-width', '100px').css('max-width', '200px');


$(window).trigger('resize.splitter'); // temporary fix for Issue #12 to kep that issue out of these tests.

Expand All @@ -176,7 +185,7 @@ <h1>jquery.enhsplitter Features Tests</h1>
box.append(panel);

$('body').append(box);
panel.enhsplitter(options);
return panel.enhsplitter(options);

}
</script>
Expand Down

0 comments on commit f215441

Please sign in to comment.