Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</style>
</head>
<body>
<div class="juxtapose">
<div class="juxtapose" data-interaction="hover">
<img src="http://placekitten.com/500/300" data-label="Cat" alt="A cat" />
<img src="http://placebear.com/500/300" data-label="Bear" alt="A bear"/>
</div>
Expand Down
64 changes: 46 additions & 18 deletions juxtapose/js/juxtapose.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
makeResponsive: true,
startingPosition: "50%",
mode: 'horizontal',
interaction: 'click',
callback: null // pass a callback function if you like
};

Expand Down Expand Up @@ -552,32 +553,56 @@
self.setWrapperDimensions();
});


// Set up Javascript Events
// On mousedown, call updateSlider then set animate to false
// (if animate is true, adds css transition when updating).

this.slider.addEventListener("mousedown", function(e) {
e = e || window.event;
e.preventDefault();
self.updateSlider(e, true);
animate = true;

this.addEventListener("mousemove", function(e) {
if (this.options.interaction == 'click') {
// On mousedown, call updateSlider then set animate to false
// (if animate is true, adds css transition when updating).
this.slider.addEventListener("mousedown", function(e) {
e = e || window.event;
e.preventDefault();
if (animate) { self.updateSlider(e, false); }
self.updateSlider(e, true);
animate = true;

this.addEventListener("mousemove", function(e) {
e = e || window.event;
e.preventDefault();
if (animate) { self.updateSlider(e, false); }
});

this.addEventListener('mouseup', function(e) {
e = e || window.event;
e.preventDefault();
e.stopPropagation();
this.removeEventListener('mouseup', arguments.callee);
animate = false;
});
});

this.addEventListener('mouseup', function(e) {
} else if (this.options.interaction == 'hover') {
// On mouseover, call updateSlider and set animate to false on
// mouseout. If animate is true, adds css transitions when updating.
this.slider.addEventListener("mouseover", function(e) {
e = e || window.event;
e.preventDefault();
e.stopPropagation();
this.removeEventListener('mouseup', arguments.callee);
animate = false;
self.updateSlider(e, true);
animate = true;

this.addEventListener("mousemove", function(e) {
e = e || window.event;
e.preventDefault();
if (animate) { self.updateSlider(e, false); }
});

this.addEventListener('mouseout', function(e) {
e = e || window.event;
e.preventDefault();
e.stopPropagation();
this.removeEventListener('mouseup', arguments.callee);
animate = false;
});
});
});
}

// Always add event listeners for touchscreens
this.slider.addEventListener("touchstart", function(e) {
e = e || window.event;
e.preventDefault();
Expand Down Expand Up @@ -677,6 +702,9 @@
if (w.getAttribute('data-makeresponsive')) {
options.mode = w.getAttribute('data-makeresponsive');
}
if (w.getAttribute('data-interaction')) {
options.interaction = w.getAttribute('data-interaction');
}

specificClass = 'juxtapose-' + idx;
addClass(element, specificClass);
Expand Down
1 change: 1 addition & 0 deletions website/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function optionsFromForm() {
showCredits: $("#show-credits").prop('checked'),
makeResponsive: $("#make-responsive").prop('checked'),
mode: ($("#vertical").prop('checked')) ? 'vertical' : 'horizontal',
interaction: ($("#interaction").prop('checked')) ? 'hover' : 'click',
startingPosition: pos,
};
return options;
Expand Down
1 change: 1 addition & 0 deletions website/templates/_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ <h6>Options</h6>
<label class="checkbox" ><input id="animate" class='auto-update' type="checkbox" value="true" checked />Animate<a class="help" href="javascript:" data-placement="right" data-content="If checked, the divider will glide to the point where someone clicks; otherwise, it will jump.">&nbsp;<i class="icon-question-sign icon-large"></i></a></label>
<label class="checkbox" ><input id="make-responsive" class='auto-update' type="checkbox" value="true" checked />Make Responsive<a class="help" href="javascript:" data-placement="right" data-content="If checked, the iframe will be set to 100% width instead of an absolute pixel value.">&nbsp;<i class="icon-question-sign icon-large"></i></a></label>
<label class="checkbox" ><input id="vertical" class='auto-update' type="checkbox" value="false" />Vertical<a class="help" href="javascript:" data-placement="right" data-content="If checked, the divider will move vertically instead of horizontally.">&nbsp;<i class="icon-question-sign icon-large"></i></a></label>
<label class="checkbox" ><input id="interaction" class='auto-update' type="checkbox" value="false" />Hover<a class="help" href="javascript:" data-placement="right" data-content="If checked, the juxtapose can be controlled via mouse hover, rather than click.">&nbsp;<i class="icon-question-sign icon-large"></i></a></label>
</div>
</div>

Expand Down