1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-01 22:00:31 +02:00

Add permalink to setup for comparing images with webroot/compare/compare.php, fix #92.

This commit is contained in:
Mikael Roos
2015-05-08 09:38:12 +02:00
parent 2651c9ea02
commit 7a0626d9bf
3 changed files with 60 additions and 36 deletions

View File

@@ -8,6 +8,8 @@ Revision history
v0.7.0.x (latest) v0.7.0.x (latest)
------------------------------------- -------------------------------------
* Add permalink to setup for comparing images with `webroot/compare/compare.php`, fix #92.
* Support spaces in filenames for image src, fix #91.
* Support redirections for remote images, fix #87, fix #90. * Support redirections for remote images, fix #87, fix #90.
* Improving usage of Travis and Scrutinizer. * Improving usage of Travis and Scrutinizer.
* Naming cache-file using md5 for remote images, fix #86. * Naming cache-file using md5 for remote images, fix #86.

View File

@@ -43,13 +43,15 @@ input[type=text] {
<h1>Compare images</h1> <h1>Compare images</h1>
<p>Add link to images and visually compare them. Change the link och press return to load the image. <a href="http://dbwebb.se/opensource/cimage">Read more...</a></p> <p>Add link to images and visually compare them. Change the link och press return to load the image. <a href="http://dbwebb.se/opensource/cimage">Read more...</a></p>
<p><a id="permalink" href="?">Direct link to this setup.</a></p>
<form> <form>
<p> <p>
<label>Image 1: <input type="text" id="input1" data-id="1"></label> <img id="thumb1"></br> <label>Image 1: <input type="text" id="input1" data-id="1"></label> <img id="thumb1"></br>
<label>Image 2: <input type="text" id="input2" data-id="2"></label> <img id="thumb2"></br> <label>Image 2: <input type="text" id="input2" data-id="2"></label> <img id="thumb2"></br>
<label>Image 3: <input type="text" id="input3" data-id="3"></label> <img id="thumb3"></br> <label>Image 3: <input type="text" id="input3" data-id="3"></label> <img id="thumb3"></br>
<label>Image 4: <input type="text" id="input4" data-id="4"></label> <img id="thumb4"></br> <label>Image 4: <input type="text" id="input4" data-id="4"></label> <img id="thumb4"></br>
<label><input type="checkbox" id="viewDetails">Hide image details?</label><br/> <label><input type="checkbox" id="viewDetails">Show image details</label><br/>
<label><input type="checkbox" id="stack">Stack images?</label> <label><input type="checkbox" id="stack">Stack images?</label>
</p> </p>
</form> </form>
@@ -66,25 +68,25 @@ input[type=text] {
<div id="area1" class="area"> <div id="area1" class="area">
<code>Image 1</code><br> <code>Image 1</code><br>
<img id="img1"> <img id="img1">
<pre id="json1" class="json"></pre> <pre id="json1" class="json hidden"></pre>
</div> </div>
<div id="area2" class="area"> <div id="area2" class="area">
<code>Image 2</code><br> <code>Image 2</code><br>
<img id="img2"> <img id="img2">
<pre id="json2" class="json"></pre> <pre id="json2" class="json hidden"></pre>
</div> </div>
<div id="area3" class="area"> <div id="area3" class="area">
<code>Image 3</code><br> <code>Image 3</code><br>
<img id="img3"> <img id="img3">
<pre id="json3" class="json"></pre> <pre id="json3" class="json hidden"></pre>
</div> </div>
<div id="area4" class="area"> <div id="area4" class="area">
<code>Image 4</code><br> <code>Image 4</code><br>
<img id="img4"> <img id="img4">
<pre id="json4" class="json"></pre> <pre id="json4" class="json hidden"></pre>
</div> </div>
</div> </div>
@@ -96,9 +98,23 @@ input[type=text] {
<script src="../js/cimage.js"></script> <script src="../js/cimage.js"></script>
<script> <script>
<?php <?php
if (isset($script)) { if (isset($_GET['input1'])) {
// Use incoming from querystring as defaults
?>
CImage.compare({
"input1": "<?=$_GET['input1']?>",
"input2": "<?=$_GET['input2']?>",
"input3": "<?=$_GET['input3']?>",
"input4": "<?=$_GET['input4']?>",
"json": <?=$_GET['json']?>,
"stack": <?=$_GET['stack']?>
});
<?php
} else if (isset($script)) {
// Use default setup from js configuration
echo $script; echo $script;
} else { } else {
// Use defaults
echo "CImage.compare({});"; echo "CImage.compare({});";
} ?> } ?>
</script> </script>

View File

@@ -5,11 +5,37 @@ window.CImage = (function(){
"use strict"; "use strict";
/**
* Update the permalink.
*/
function updatePermaLink() {
var link,
input1 = document.getElementById("input1"),
input2 = document.getElementById("input2"),
input3 = document.getElementById("input3"),
input4 = document.getElementById("input4"),
details = document.getElementById("viewDetails"),
stack = document.getElementById("stack"),
permalink = document.getElementById("permalink");
link = "?";
link += "input1=" + encodeURIComponent(input1.value) + "&";
link += "input2=" + encodeURIComponent(input2.value) + "&";
link += "input3=" + encodeURIComponent(input3.value) + "&";
link += "input4=" + encodeURIComponent(input4.value) + "&";
link += "json=" + encodeURIComponent(details.checked) + "&";
link += "stack=" + encodeURIComponent(stack.checked);
permalink.href = link;
}
/** /**
* Init the compare page with details. * Init the compare page with details.
*/ */
function compareLoadImage(event) { function compareLoadImage(event) {
var img, json, button, area, deck, id; var img, json, button, area, deck, id, permalink;
id = this.dataset.id; id = this.dataset.id;
img = document.getElementById("img" + id); img = document.getElementById("img" + id);
@@ -18,6 +44,8 @@ window.CImage = (function(){
area = document.getElementById("area" + id); area = document.getElementById("area" + id);
deck = document.getElementById("deck" + id); deck = document.getElementById("deck" + id);
updatePermaLink();
if (this.value == "") { if (this.value == "") {
// Clear image if input is cleared // Clear image if input is cleared
button.setAttribute("disabled", "disabled"); button.setAttribute("disabled", "disabled");
@@ -57,31 +85,6 @@ window.CImage = (function(){
stack = document.getElementById("stack"), stack = document.getElementById("stack"),
buttons = document.getElementById("buttonWrap"); buttons = document.getElementById("buttonWrap");
/* img1 = document.getElementById("img1"),
img2 = document.getElementById("img2"),
img3 = document.getElementById("img3"),
img4 = document.getElementById("img4"),
img01 = document.getElementById("img01"),
img02 = document.getElementById("img02"),
img03 = document.getElementById("img03"),
img04 = document.getElementById("img04"),
json1 = document.getElementById("json1"),
json2 = document.getElementById("json2"),
json3 = document.getElementById("json3"),
json4 = document.getElementById("json4"),
json01 = document.getElementById("json01"),
json02 = document.getElementById("json02"),
json03 = document.getElementById("json03"),
json04 = document.getElementById("json04"),
button1 = document.getElementById("button1"),
button2 = document.getElementById("button2"),
button3 = document.getElementById("button3"),
button4 = document.getElementById("button4"),
area1 = document.getElementById("area1"),
area2 = document.getElementById("area2"),
area3 = document.getElementById("area3"),
area4 = document.getElementById("area4");*/
input1.addEventListener("change", compareLoadImage); input1.addEventListener("change", compareLoadImage);
input2.addEventListener("change", compareLoadImage); input2.addEventListener("change", compareLoadImage);
input3.addEventListener("change", compareLoadImage); input3.addEventListener("change", compareLoadImage);
@@ -93,10 +96,12 @@ window.CImage = (function(){
for (var element of elements) { for (var element of elements) {
element.classList.toggle("hidden"); element.classList.toggle("hidden");
} }
updatePermaLink();
console.log("View JSON");
}); });
// Do not show json as default // Show json as default
if (options.json === false) { if (options.json === true) {
details.setAttribute("checked", "checked"); details.setAttribute("checked", "checked");
myEvent = new CustomEvent("change"); myEvent = new CustomEvent("change");
details.dispatchEvent(myEvent); details.dispatchEvent(myEvent);
@@ -117,6 +122,7 @@ window.CImage = (function(){
} }
} }
onTop.classList.toggle("top"); onTop.classList.toggle("top");
updatePermaLink();
console.log("Stacking"); console.log("Stacking");
}); });