summaryrefslogtreecommitdiff
path: root/src/www/gfse/sort.js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-06-21 15:39:31 +0000
committerhallgren <hallgren@chalmers.se>2012-06-21 15:39:31 +0000
commitb12e6ec1e413963d90f563ca7d9c1aeaeabcdec0 (patch)
treed78f5391591e1381abb587c27f09b0c94d9117e8 /src/www/gfse/sort.js
parentffa1e7731d3ef7a3892366f72b708e934eb840d5 (diff)
gfse/sort.js: make it more resusable
Move the gfse-specific list of sortable tags and class names from sort.js to editor.js.
Diffstat (limited to 'src/www/gfse/sort.js')
-rw-r--r--src/www/gfse/sort.js47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/www/gfse/sort.js b/src/www/gfse/sort.js
index cbf4183cb..eae779d5a 100644
--- a/src/www/gfse/sort.js
+++ b/src/www/gfse/sort.js
@@ -1,21 +1,27 @@
-function initialize_sorting() {
+function initialize_sorting(tagList,classList) {
+ /*
+ var debugoutput=empty("pre");
+ document.body.appendChild(debugoutput)
+ function jsdebug(txt) {
+ //clear(debugoutput)
+ debugoutput.appendChild(text(txt+"\n"))
+ }
+ */
+ function listToSet(list) {
+ var set={}
+ for(var i in list) set[list[i]]=true
+ return set;
+ }
+ var sortable_tag=listToSet(tagList)
+ var sortable_class=listToSet(classList)
function sortable(elem) {
- switch(elem.tagName) {
- case "DIV":
- switch(elem.className) {
- case "fun":
- case "lin":
- case "lincat":
- case "oper":
- return elem;
- default:
- return null;
- }
- default:
- return sortable(elem.parentNode)
- }
+ return elem && (sortable_tag[elem.tagName]
+ ? sortable_class[elem.className]
+ ? elem
+ : null
+ : sortable(elem.parentNode))
}
function move_element(elem,x,y) {
@@ -86,18 +92,21 @@ function startDrag(event,elem) {
move_element(elem,dx,dy);
//jsdebug("dragging to "+elem.offsetLeft+" "+elem.offsetTop);
swap(elem,dy)
+ //event.stopPropagation();
return false;
}
- document.onmouseup=function() {
+ document.onmouseup=function(event) {
//jsdebug("dropped");
elem.style.zIndex=0;
move_element(elem,0,0);
document.onmousemove=null;
document.onmouseup=null;
if(list.onsort) list.onsort();
- else jsdebug("no list.onsort "+list.className+" "+list.firstChild.ident);
+ //else jsdebug("no list.onsort "+list.className+" "+list.firstChild.ident);
+ //event.stopPropagation();
return false;
}
+ //event.stopPropagation();
return false;
}
@@ -107,7 +116,7 @@ function mousedown(event) {
//else jsdebug("Clicked outside"/*+taglist(event.target)/*+show_props(event,"event")*/);
}
- var jsdebug=debug;
+ //var jsdebug=debug;
function init() {
document.onmousedown=mousedown;
@@ -117,6 +126,4 @@ function init() {
init();
}
-initialize_sorting();
-
//Inspired by http://tool-man.org/examples/sorting.html