Skip to content

Commit acd063d

Browse files
committed
Add double tap support on mobile for subworkflows
1 parent a54bcdb commit acd063d

File tree

1 file changed

+89
-84
lines changed

1 file changed

+89
-84
lines changed

src/main/resources/static/js/workflow.js

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ require(['jquery', 'bootstrap.modal', 'svg-pan-zoom', 'hammerjs', 'jquery.svg'],
9393
instance.zoom(initialScale * ev.scale)
9494
});
9595

96+
// Handle double click
97+
this.hammer.on('doubletap', function(e){
98+
goToSubworkflow(e.target.closest(".node"));
99+
});
100+
96101
// Prevent moving the page on some devices when panning over SVG
97102
options.svgElement.addEventListener('touchmove', function(e){
98103
e.preventDefault();
@@ -165,86 +170,7 @@ require(['jquery', 'bootstrap.modal', 'svg-pan-zoom', 'hammerjs', 'jquery.svg'],
165170
}, 100);
166171
});
167172
}
168-
});
169-
170-
/**
171-
* Handle the dot graph modal and related features
172-
*/
173-
require(['jquery', 'bootstrap.modal'],
174-
function ($, modal) {
175-
/**
176-
* DOT graph modal textarea automatically focuses when opened
177-
*/
178-
$('#dotGraph').on('shown.bs.modal', function () {
179-
$('#dot').focus();
180-
});
181-
182-
/**
183-
* DOT graph textarea focus selects all
184-
*/
185-
$("#dot").focus(function() {
186-
$(this).select();
187-
});
188-
189-
/**
190-
* Downloading of the DOT graph as a .gv file
191-
*/
192-
$('#download-dot').click(function (event) {
193-
// Generate download link src
194-
var dotGraph = $("#dot").val();
195-
var src = "data:text/vnd.graphviz;charset=utf-8," + encodeURIComponent(dotGraph);
196-
197-
// Set hidden download link href to contents and click it
198-
var downloadLink = $("#download-link-dot");
199-
downloadLink.attr("href", src);
200-
downloadLink[0].click();
201-
202-
// Stop default button action
203-
event.preventDefault();
204-
});
205-
});
206-
207-
/**
208-
* Code for including the link to the Research Object Bundle download
209-
* without refresh once generated
210-
*/
211-
require(['jquery'],
212-
function ($) {
213-
/**
214-
* AJAX function to add download link to page if generated
215-
*/
216-
function getDownloadLink() {
217-
$.ajax({
218-
type: 'HEAD',
219-
url: $('#download').attr('href'),
220-
dataType: "json",
221-
success: function () {
222-
// Hide generating, show link
223-
$("#generating").addClass("hide");
224-
$("#generated").removeClass("hide");
225-
},
226-
error: function () {
227-
// Show generating, hide link
228-
$("#generated").addClass("hide");
229-
$("#generating").removeClass("hide");
230-
231-
// Retry in 5 seconds if still not generated
232-
setTimeout(function () {
233-
getDownloadLink();
234-
}, 5000)
235-
}
236-
});
237-
}
238173

239-
getDownloadLink();
240-
});
241-
242-
/**
243-
* Highlighting step in graph when table row is
244-
* hovered over or vice-versa
245-
*/
246-
require(['jquery', 'jquery.svg', 'jquery.svgdom'],
247-
function ($) {
248174
/**
249175
* endsWith function to check suffix
250176
*/
@@ -319,6 +245,18 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
319245
}
320246
}, "#graph");
321247

248+
/**
249+
* Follow the link to a subworkflow if one exists
250+
* @param node The node of the visualisation
251+
*/
252+
function goToSubworkflow(node) {
253+
var matchingTableRow = getTableRow(node);
254+
var subworkflowLink = $(matchingTableRow).find("a.subworkflow");
255+
if (subworkflowLink.length > 0) {
256+
location.href = subworkflowLink.attr("href");
257+
}
258+
}
259+
322260
/**
323261
* When a graph box is hovered over/clicked, highlight
324262
*/
@@ -337,11 +275,7 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
337275
},
338276
dblclick: function() {
339277
// Follow link to subworkflow if possible
340-
var matchingTableRow = getTableRow(this);
341-
var subworkflowLink = $(matchingTableRow).find("a.subworkflow");
342-
if (subworkflowLink.length > 0) {
343-
location.href = subworkflowLink.attr("href");
344-
}
278+
goToSubworkflow(this);
345279
},
346280
mouseenter: function() {
347281
getTableRow(this).addClass("hover");
@@ -420,7 +354,78 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
420354
expandSelection($(this).parent(), "inList");
421355
});
422356
});
357+
});
358+
359+
/**
360+
* Handle the dot graph modal and related features
361+
*/
362+
require(['jquery', 'bootstrap.modal'],
363+
function ($, modal) {
364+
/**
365+
* DOT graph modal textarea automatically focuses when opened
366+
*/
367+
$('#dotGraph').on('shown.bs.modal', function () {
368+
$('#dot').focus();
369+
});
370+
371+
/**
372+
* DOT graph textarea focus selects all
373+
*/
374+
$("#dot").focus(function() {
375+
$(this).select();
376+
});
377+
378+
/**
379+
* Downloading of the DOT graph as a .gv file
380+
*/
381+
$('#download-dot').click(function (event) {
382+
// Generate download link src
383+
var dotGraph = $("#dot").val();
384+
var src = "data:text/vnd.graphviz;charset=utf-8," + encodeURIComponent(dotGraph);
385+
386+
// Set hidden download link href to contents and click it
387+
var downloadLink = $("#download-link-dot");
388+
downloadLink.attr("href", src);
389+
downloadLink[0].click();
423390

391+
// Stop default button action
392+
event.preventDefault();
393+
});
394+
});
395+
396+
/**
397+
* Code for including the link to the Research Object Bundle download
398+
* without refresh once generated
399+
*/
400+
require(['jquery'],
401+
function ($) {
402+
/**
403+
* AJAX function to add download link to page if generated
404+
*/
405+
function getDownloadLink() {
406+
$.ajax({
407+
type: 'HEAD',
408+
url: $('#download').attr('href'),
409+
dataType: "json",
410+
success: function () {
411+
// Hide generating, show link
412+
$("#generating").addClass("hide");
413+
$("#generated").removeClass("hide");
414+
},
415+
error: function () {
416+
// Show generating, hide link
417+
$("#generated").addClass("hide");
418+
$("#generating").removeClass("hide");
419+
420+
// Retry in 5 seconds if still not generated
421+
setTimeout(function () {
422+
getDownloadLink();
423+
}, 5000)
424+
}
425+
});
426+
}
427+
428+
getDownloadLink();
424429
});
425430

426431
/**

0 commit comments

Comments
 (0)