Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
@snoyberg
91 lines (81 sloc) 2.878 kB
function setupDropZones() {
var dz = "<li class='dropzone hidden'>Drop Here</li>"; // TRANS
$("li.dropzone").detach();
$("#map li").before(dz);
$("#map ul").append(dz);
$("#topics > ul").append(dz);
}
$(function(){
$.each($("#map li.node"), function(i, x){
var y = $(x);
var id = y.attr("id").substring(1);
var z = $("#" + id);
y.prepend("<span>" + z.html() + "</span>");
z.detach();
y.attr("id", id);
});
setupDropZones();
var selectedNode;
$("#topics > ul > li").append("<ul></ul>");
$("li.node > span").click(function(){
var t = $(this).parent();
var isSel = t.hasClass("selected");
$("li.selected").removeClass("selected");
$("li.dropzone").addClass("hidden");
if (! isSel) {
selectedNode = t.addClass("selected");
$("li.dropzone").removeClass("hidden");
t.prev().addClass("hidden");
t.next().addClass("hidden");
$("li.selected li.dropzone").addClass("hidden");
$("#topics li.selected ~ li.dropzone").addClass("hidden");
}
});
$("li.dropzone").live("click", function(){
selectedNode.removeClass("selected");
$(this).before(selectedNode);
setupDropZones();
});
$("#submit > button").click(function(){
$("#tree").attr("value", mkTree($("#map > ul > li.node")));
});
$("li[slug] > span > a.viewtopic").after("<a href='#' class='editslug'>Edit Slug</a>");
$("li[slug].realtopic > span > a.editslug").after("<a href='#' class='tosubmap'>Make submap</a>");
$("a.editslug").click(function(){
var li = $(this).parent().parent();
var slug = li.attr("slug");
var msg = slug ? "Your current slug is: " + slug + ". Please enter a new slug." : "Please enter a slug";
slug = prompt(msg);
if (slug) li.attr("slug", slug);
return false;
});
$("a.tosubmap").click(function(){
var li = $(this).parent().parent();
var slug = li.attr("slug");
var html = [];
html.push("<form method='post' action='@{MakeSubMapR mid $ MapNodeSlug ""}" + li.attr("slug") + "'>");
html.push("<input type=submit value='Do it'>");
html.push("</form>");
$(this).before(html.join("")).detach();
return false;
});
});
function mkTree(lis) {
var x = ["["];
$.each(lis, function(i, li){
var l = $(li);
if (i != 0) x.push(",");
x.push("{\"topic\":\"");
x.push(l.attr("id"));
var slug = l.attr("slug");
if (slug) {
x.push("\",\"slug\":\"");
x.push(slug);
}
x.push("\",\"children\":");
x.push(mkTree(l.children("ul").children("li.node")));
x.push("}");
});
x.push("]");
return x.join("");
}
Jump to Line
Something went wrong with that request. Please try again.