diff --git a/www/assets/js/main.js b/www/assets/js/main.js index d3631ef..6e3124e 100644 --- a/www/assets/js/main.js +++ b/www/assets/js/main.js @@ -23,6 +23,9 @@ var app = new Framework7({ popover: { backdrop: true }, + touch: { + tapHold: true + }, init: false, initOnDeviceReady: false, routes: routes diff --git a/www/assets/js/track.js b/www/assets/js/track.js index 08848a1..94aef33 100644 --- a/www/assets/js/track.js +++ b/www/assets/js/track.js @@ -20,7 +20,7 @@ function addTrackingSuggestions() { $("#tracking-history-list ul").html('
  • You haven\'t tracked anything yet.
  • '); } else { for (var i = history.length - 1; i >= 0; i--) { - $("#tracking-history-list ul").append('
  • ' + $("#tracking-history-list ul").append('
  • ' + '
    ' + history[i] + '
  • '); @@ -177,12 +177,46 @@ function trackOpenAsync( {to, resolve, reject}) { }, "GET"); } +$("#app").on("taphold contextmenu", ".tracking-code-history-link", function (evt) { + var code = $(this).data("trackingcode"); + + var action = app.actions.create({ + buttons: [ + [ + { + text: 'Track', + bold: true, + onClick: function () { + openTrackingInfoPage(code); + } + }, + { + text: 'Remove From List', + onClick: function () { + removeFromTrackingHistory(code); + addTrackingSuggestions(); + } + } + ], + [ + { + text: 'Cancel', + color: 'red' + } + ] + ] + }); + + action.open(); + return false; +}); + function getTrackingHistory() { var history = getStorage("trackinghistory"); - if (history != null) { - return JSON.parse(history); - } else { + if (history == "false" || history == "null" || history == null) { return []; + } else { + return JSON.parse(history); } } @@ -201,4 +235,21 @@ function addToTrackingHistory(code) { history.shift(); } setStorage("trackinghistory", JSON.stringify(history)); +} + +function removeFromTrackingHistory(code) { + var history = getTrackingHistory(); + + for (var i = 0; i < history.length; i++) { + if (history[i] == code) { + history.splice(i, 1); + } + } + + while (history.length > 10) { + history.shift(); + } + setStorage("trackinghistory", JSON.stringify(history)); + + $(".tracking-code-history-link[data-trackingcode=\"" + code + "\"]").parent("li").remove(); } \ No newline at end of file