aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinar Egilsson2011-08-30 13:21:07 +0200
committerEinar Egilsson2011-08-30 13:21:07 +0200
commitf0843d03e265c47258c92499248f45bff4ece6f4 (patch)
tree7abba6e3fe48e2ec54e0c754f7ed77c8ab078bf4
parentb69f768ac83291de532161ae1da48ea20ffc01d6 (diff)
Move redirects by drag/drop
-rw-r--r--chrome/code/redirector.js7
-rw-r--r--chrome/js/settings.js40
-rw-r--r--chrome/settings.html7
3 files changed, 45 insertions, 9 deletions
diff --git a/chrome/code/redirector.js b/chrome/code/redirector.js
index 5c6fe81..8a5cbed 100644
--- a/chrome/code/redirector.js
+++ b/chrome/code/redirector.js
@@ -180,14 +180,11 @@ Redirector = {
this.exportRedirects(file);
},
- switchItems : function(index1, index2) {
- var item = this._list[index1];
- this._list[index1] = this._list[index2];
- this._list[index2] = item;
+ sortRedirects : function(sortFunc) {
+ this._list.sort(sortFunc);
this.save();
},
-
// nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
diff --git a/chrome/js/settings.js b/chrome/js/settings.js
index fbbc332..c5675f6 100644
--- a/chrome/js/settings.js
+++ b/chrome/js/settings.js
@@ -84,7 +84,7 @@ $(document).ready(function() {
node.find('.exampleUrl').html(redirect.exampleUrl);
node.find('.redirectResult').html(redirect.getMatch(redirect.exampleUrl).redirectTo);
node.appendTo('#redirect-list');
- node.redirect = redirect;
+ node.data('redirect', redirect);
}
$('#redirect-list li a').click(function() {
@@ -106,7 +106,45 @@ $(document).ready(function() {
bindConfig();
prefs.addListener({ changedPrefs:bindConfig});
+ var moving = false;
+ function drag() {
+
+ }
+ var movingElement = null;
+ $('li').mousedown(function() {
+ $(this).css('background', '-moz-linear-gradient(top, #aac, #99b)');
+ $('#redirect-list').css('cursor', 'move');
+ movingElement = this;
+ });
+
+
+ $('li').mouseover(function() {
+ if (movingElement && this !== movingElement) {
+ if ($(movingElement).offset().top > $(this).offset().top) {
+ $(movingElement).detach().insertBefore(this);
+ } else {
+ $(movingElement).detach().insertAfter(this);
+ }
+ }
+ });
+
+ $(document).mouseup(function() {
+ if (movingElement) {
+ $(movingElement).css('background', '');
+ movingElement = null;
+ $('#redirect-list').css('cursor', '');
+ var newOrder = {};
+ $('#redirect-list li').each(function(i) {
+ newOrder[$(this).data('redirect')] = i;
+ });
+
+ Redirector.sortRedirects(function(a,b) {
+ return newOrder[a] - newOrder[b];
+ });
+ }
+ });
+
$('#config input[type="checkbox"]').bind('CheckboxStateChange', function() {
var pref = $(this).attr('data-pref');
prefs[pref] = !!$(this).attr('checked');
diff --git a/chrome/settings.html b/chrome/settings.html
index 533118d..117a200 100644
--- a/chrome/settings.html
+++ b/chrome/settings.html
@@ -12,7 +12,8 @@
}
html {
height:100%;
- margin:0; padding:0;
+ margin:0;
+ padding:0;
}
h1 { text-align:center; color:#555; text-shadow:0px 0px 15px white; font-size:34pt; padding:0px; margin:20px 0px 0px 0px; }
label { display:table-cell; }
@@ -21,6 +22,8 @@
li:first-child { border-top:none;}
#actions { width:600px; margin:10px auto; text-align:center; }
#redirect-list {
+ -moz-user-select: -moz-none;
+
border:solid 1px grey;
margin:auto;
padding:0px;
@@ -60,8 +63,6 @@
<div>
<a href="#edit">Edit</a>
<a href="#delete">Delete</a>
- <a href="#up">Up</a>
- <a href="#down">Down</a>
</div>
</li>
</ul>