mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-21 17:12:50 -06:00
gfse/sort.js: make it more resusable
Move the gfse-specific list of sortable tags and class names from sort.js to editor.js.
This commit is contained in:
@@ -1598,6 +1598,7 @@ if(editor) {
|
|||||||
initial_view();
|
initial_view();
|
||||||
touch_edit();
|
touch_edit();
|
||||||
dir_bugfix();
|
dir_bugfix();
|
||||||
|
initialize_sorting(["DIV"],["fun","lin","lincat","oper"]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
editor.innerHTML="<p>This browser does not appear to support localStorage, and the grammar editor does not work without it. Sorry!"
|
editor.innerHTML="<p>This browser does not appear to support localStorage, and the grammar editor does not work without it. Sorry!"
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ This page does not work without JavaScript.
|
|||||||
<hr>
|
<hr>
|
||||||
<div class=modtime><small>
|
<div class=modtime><small>
|
||||||
HTML
|
HTML
|
||||||
<!-- hhmts start --> Last modified: Mon Feb 13 18:05:45 CET 2012 <!-- hhmts end -->
|
<!-- hhmts start --> Last modified: Thu Jun 21 16:40:51 CEST 2012 <!-- hhmts end -->
|
||||||
</small></div>
|
</small></div>
|
||||||
<a href="about.html">About</a>
|
<a href="about.html">About</a>
|
||||||
<pre id=debug></pre>
|
<pre id=debug></pre>
|
||||||
@@ -42,9 +42,9 @@ HTML
|
|||||||
<script type="text/javascript" src="localstorage.js"></script>
|
<script type="text/javascript" src="localstorage.js"></script>
|
||||||
<script type="text/javascript" src="gf_abs.js"></script>
|
<script type="text/javascript" src="gf_abs.js"></script>
|
||||||
<script type="text/javascript" src="example_based.js"></script>
|
<script type="text/javascript" src="example_based.js"></script>
|
||||||
|
<script type="text/javascript" src="sort.js"></script>
|
||||||
<script type="text/javascript" src="editor.js"></script>
|
<script type="text/javascript" src="editor.js"></script>
|
||||||
<script type="text/javascript" src="cloud2.js"></script>
|
<script type="text/javascript" src="cloud2.js"></script>
|
||||||
<script type="text/javascript" src="sort.js"></script>
|
|
||||||
<script type="text/JavaScript" src="../minibar/minibar.js"></script>
|
<script type="text/JavaScript" src="../minibar/minibar.js"></script>
|
||||||
<script type="text/JavaScript" src="../minibar/minibar_input.js"></script>
|
<script type="text/JavaScript" src="../minibar/minibar_input.js"></script>
|
||||||
<script type="text/JavaScript" src="../minibar/minibar_translations.js"></script>
|
<script type="text/JavaScript" src="../minibar/minibar_translations.js"></script>
|
||||||
|
|||||||
@@ -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) {
|
function sortable(elem) {
|
||||||
switch(elem.tagName) {
|
return elem && (sortable_tag[elem.tagName]
|
||||||
case "DIV":
|
? sortable_class[elem.className]
|
||||||
switch(elem.className) {
|
? elem
|
||||||
case "fun":
|
: null
|
||||||
case "lin":
|
: sortable(elem.parentNode))
|
||||||
case "lincat":
|
|
||||||
case "oper":
|
|
||||||
return elem;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return sortable(elem.parentNode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function move_element(elem,x,y) {
|
function move_element(elem,x,y) {
|
||||||
@@ -86,18 +92,21 @@ function startDrag(event,elem) {
|
|||||||
move_element(elem,dx,dy);
|
move_element(elem,dx,dy);
|
||||||
//jsdebug("dragging to "+elem.offsetLeft+" "+elem.offsetTop);
|
//jsdebug("dragging to "+elem.offsetLeft+" "+elem.offsetTop);
|
||||||
swap(elem,dy)
|
swap(elem,dy)
|
||||||
|
//event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
document.onmouseup=function() {
|
document.onmouseup=function(event) {
|
||||||
//jsdebug("dropped");
|
//jsdebug("dropped");
|
||||||
elem.style.zIndex=0;
|
elem.style.zIndex=0;
|
||||||
move_element(elem,0,0);
|
move_element(elem,0,0);
|
||||||
document.onmousemove=null;
|
document.onmousemove=null;
|
||||||
document.onmouseup=null;
|
document.onmouseup=null;
|
||||||
if(list.onsort) list.onsort();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
//event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +116,7 @@ function mousedown(event) {
|
|||||||
//else jsdebug("Clicked outside"/*+taglist(event.target)/*+show_props(event,"event")*/);
|
//else jsdebug("Clicked outside"/*+taglist(event.target)/*+show_props(event,"event")*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsdebug=debug;
|
//var jsdebug=debug;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
document.onmousedown=mousedown;
|
document.onmousedown=mousedown;
|
||||||
@@ -117,6 +126,4 @@ function init() {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize_sorting();
|
|
||||||
|
|
||||||
//Inspired by http://tool-man.org/examples/sorting.html
|
//Inspired by http://tool-man.org/examples/sorting.html
|
||||||
|
|||||||
Reference in New Issue
Block a user