Ok, now it works.

This commit is contained in:
Zixaphir 2014-01-14 12:48:27 -07:00
parent 82646724e5
commit eb1b6e39fc
4 changed files with 97 additions and 90 deletions

View File

@ -2983,15 +2983,14 @@
};
})();
$.remove = function(array, value) {
$.remove = function(arr, value) {
var i;
i = array.indexOf(value);
if (i > -1) {
array.splice(i, 1);
return true;
} else {
i = arr.indexOf(value);
if (i === -1) {
return false;
}
arr.splice(i, 1);
return true;
};
$$ = function(selector, root) {
@ -13143,11 +13142,10 @@
return Settings.open("Mascots");
},
importMascot: function() {
var file, len, reader;
var file, reader;
file = this.files[0];
reader = new FileReader();
len = Conf["Deleted Mascots"].length;
reader.onload = function() {
reader.onload = function(e) {
var err, mascots;
try {
mascots = JSON.parse(e.target.result);
@ -13156,34 +13154,39 @@
alert(err);
return;
}
$.get("userMascots", {}, function(_arg) {
var mascot, message, name, userMascots, _i, _len;
return $.get("userMascots", {}, function(_arg) {
var userMascots;
userMascots = _arg.userMascots;
if (name = mascots["Mascot"]) {
MascotTools.parse(mascots, userMascots);
return message = "" + name + " successfully imported!";
} else if (mascots.length) {
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
mascot = mascots[_i];
MascotTools.parse(mascot, userMascots);
}
return message = "Mascots imported!";
} else {
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
}
});
$.set('userMascots', userMascots);
if (len !== Conf["Deleted Mascots"].length) {
$.set('Deleted Mascots', Conf['Deleted Mascots']);
}
new Notice('info', message, 10);
return Settings.openSection.call({
open: Settings.mascots,
hyphenatedTitle: 'mascots'
return MascotTools.load(mascots, userMascots);
});
};
return reader.readAsText(file);
},
load: function(mascots, userMascots) {
var len, mascot, message, name, _i, _len;
len = Conf["Deleted Mascots"].length;
if (name = mascots["Mascot"]) {
MascotTools.parse(mascots, userMascots);
message = "" + name + " successfully imported!";
} else if (mascots.length) {
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
mascot = mascots[_i];
MascotTools.parse(mascot, userMascots);
}
message = "Mascots imported!";
} else {
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
}
$.set('userMascots', userMascots);
if (len !== Conf["Deleted Mascots"].length) {
$.set('Deleted Mascots', Conf['Deleted Mascots']);
}
new Notice('info', message, 10);
return Settings.openSection.call({
open: Settings.mascots,
hyphenatedTitle: 'mascots'
});
},
parse: function(mascot, userMascots) {
var name;
if (!(name = mascot["Mascot"])) {

View File

@ -2988,15 +2988,14 @@
};
})();
$.remove = function(array, value) {
$.remove = function(arr, value) {
var i;
i = array.indexOf(value);
if (i > -1) {
array.splice(i, 1);
return true;
} else {
i = arr.indexOf(value);
if (i === -1) {
return false;
}
arr.splice(i, 1);
return true;
};
$$ = function(selector, root) {
@ -13132,11 +13131,10 @@
return Settings.open("Mascots");
},
importMascot: function() {
var file, len, reader;
var file, reader;
file = this.files[0];
reader = new FileReader();
len = Conf["Deleted Mascots"].length;
reader.onload = function() {
reader.onload = function(e) {
var err, mascots;
try {
mascots = JSON.parse(e.target.result);
@ -13145,34 +13143,39 @@
alert(err);
return;
}
$.get("userMascots", {}, function(_arg) {
var mascot, message, name, userMascots, _i, _len;
return $.get("userMascots", {}, function(_arg) {
var userMascots;
userMascots = _arg.userMascots;
if (name = mascots["Mascot"]) {
MascotTools.parse(mascots, userMascots);
return message = "" + name + " successfully imported!";
} else if (mascots.length) {
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
mascot = mascots[_i];
MascotTools.parse(mascot, userMascots);
}
return message = "Mascots imported!";
} else {
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
}
});
$.set('userMascots', userMascots);
if (len !== Conf["Deleted Mascots"].length) {
$.set('Deleted Mascots', Conf['Deleted Mascots']);
}
new Notice('info', message, 10);
return Settings.openSection.call({
open: Settings.mascots,
hyphenatedTitle: 'mascots'
return MascotTools.load(mascots, userMascots);
});
};
return reader.readAsText(file);
},
load: function(mascots, userMascots) {
var len, mascot, message, name, _i, _len;
len = Conf["Deleted Mascots"].length;
if (name = mascots["Mascot"]) {
MascotTools.parse(mascots, userMascots);
message = "" + name + " successfully imported!";
} else if (mascots.length) {
for (_i = 0, _len = mascots.length; _i < _len; _i++) {
mascot = mascots[_i];
MascotTools.parse(mascot, userMascots);
}
message = "Mascots imported!";
} else {
return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5);
}
$.set('userMascots', userMascots);
if (len !== Conf["Deleted Mascots"].length) {
$.set('Deleted Mascots', Conf['Deleted Mascots']);
}
new Notice('info', message, 10);
return Settings.openSection.call({
open: Settings.mascots,
hyphenatedTitle: 'mascots'
});
},
parse: function(mascot, userMascots) {
var name;
if (!(name = mascot["Mascot"])) {

View File

@ -404,13 +404,11 @@ $.set = do ->
return
<% } %>
$.remove = (array, value) ->
i = array.indexOf value
if i > -1
array.splice i, 1
true
else
false
$.remove = (arr, value) ->
i = arr.indexOf value
return false if i is -1
arr.splice i, 1
true
$$ = (selector, root=d.body) ->
[root.querySelectorAll(selector)...]

View File

@ -337,9 +337,8 @@ MascotTools =
importMascot: ->
file = @files[0]
reader = new FileReader()
len = Conf["Deleted Mascots"].length
reader.onload = ->
reader.onload = (e) ->
try
mascots = JSON.parse e.target.result
catch err
@ -347,26 +346,30 @@ MascotTools =
return
$.get "userMascots", {}, ({userMascots}) ->
if name = mascots["Mascot"]
MascotTools.parse mascots, userMascots
message = "#{name} successfully imported!"
else if mascots.length
MascotTools.parse mascot, userMascots for mascot in mascots
message = "Mascots imported!"
else
return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5
$.set 'userMascots', userMascots
$.set 'Deleted Mascots', Conf['Deleted Mascots'] unless len is Conf["Deleted Mascots"].length
new Notice 'info', message, 10
Settings.openSection.call
open: Settings.mascots
hyphenatedTitle: 'mascots'
MascotTools.load mascots, userMascots
reader.readAsText file
load: (mascots, userMascots) ->
len = Conf["Deleted Mascots"].length
if name = mascots["Mascot"]
MascotTools.parse mascots, userMascots
message = "#{name} successfully imported!"
else if mascots.length
MascotTools.parse mascot, userMascots for mascot in mascots
message = "Mascots imported!"
else
return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5
$.set 'userMascots', userMascots
$.set 'Deleted Mascots', Conf['Deleted Mascots'] unless len is Conf["Deleted Mascots"].length
new Notice 'info', message, 10
Settings.openSection.call
open: Settings.mascots
hyphenatedTitle: 'mascots'
parse: (mascot, userMascots) ->
unless name = mascot["Mascot"]
new Notice 'warning', "Failed to import a mascot. Mascot has no name.", 5