parent
4dc6465f51
commit
8724a01a71
@ -1,95 +1,117 @@ |
|||||||
|
var just_a_flag = false; |
||||||
|
|
||||||
function onTemplateLoadedCallback() { |
function onTemplateLoadedCallback() { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
function revert($e) { |
function revert($e) { |
||||||
var elmt = $e.css("left","auto").css("top", "auto").removeClass("inBox").get(0); |
var elmt = $e.css("left","auto").css("top", "auto").removeClass("inBox").get(0); |
||||||
if(elmt) |
if(elmt) |
||||||
elmt.className = elmt.className.replace(/(d(\d+))/, ""); |
elmt.className = elmt.className.replace(/(d(\d+))/, ""); |
||||||
} |
} |
||||||
|
|
||||||
function getN(range) { |
function getN(range) { |
||||||
if(range > 1) |
if(range > 1) |
||||||
return Math.floor(Math.random()*range); |
return Math.floor(Math.random()*range); |
||||||
else if(range == 1) |
else if(range == 1) |
||||||
return Math.round(Math.random()*10)/10;
|
return Math.round(Math.random()*10)/10;
|
||||||
else if(range == 0.1) |
else if(range == 0.1) |
||||||
return Math.round(Math.random()*0.1*100)/100;
|
return Math.round(Math.random()*0.1*100)/100;
|
||||||
} |
} |
||||||
|
|
||||||
function reloadApp(app) { |
function reloadApp(app) { |
||||||
var operator = app.parameters.value("operator"); |
var operator = app.parameters.value("operator"); |
||||||
var range = parseFloat(app.parameters.value("range")); |
var range = parseFloat(app.parameters.value("range")); |
||||||
var count = parseInt(app.parameters.value("count")); |
var count = parseInt(app.parameters.value("count")); |
||||||
|
var show = app.parameters.value("show"); |
||||||
$scene = $("#scene"); |
if(!just_a_flag){ |
||||||
$scene.empty(); |
just_a_flag = true; |
||||||
|
show = "3"; |
||||||
$labels = $("<div id='labels'></div>"); |
} |
||||||
$scene.append($labels); |
switch(show){ |
||||||
|
case "1": |
||||||
$drops = $("<div id='drops'></div>"); |
$("#labels div div").each(function(){ |
||||||
$scene.append($drops); |
$(this).css("top","auto").css("left","auto") |
||||||
|
}) |
||||||
var meeted = []; |
break; |
||||||
|
case "2": |
||||||
for (var i = 0; i < count; i++) { |
break; |
||||||
|
default: |
||||||
var n = getN(range); |
$scene = $("#scene"); |
||||||
|
$scene.empty(); |
||||||
while($.inArray(n, meeted) != -1) |
|
||||||
n = getN(range); |
$labels = $("<div id='labels'></div>"); |
||||||
|
$scene.append($labels); |
||||||
meeted.push(n); |
|
||||||
|
$drops = $("<div id='drops'></div>"); |
||||||
$label = $("<div id='l"+i+"' class='label'>"+n+"</div>"); |
$scene.append($drops); |
||||||
$labels.append($label); |
|
||||||
$label.wrap("<div/>"); |
var meeted = []; |
||||||
|
|
||||||
$label.draggable({ |
for (var i = 0; i < count; i++) { |
||||||
containment: "#scene", |
|
||||||
scroll: false, |
var n = getN(range); |
||||||
snap: ".drop", |
|
||||||
snapMode: "inner" |
while($.inArray(n, meeted) != -1) |
||||||
}); |
n = getN(range); |
||||||
|
|
||||||
$drop = $("<div id='d"+i+"' class='drop'></div>"); |
meeted.push(n); |
||||||
$drops.append($drop); |
|
||||||
$drop.droppable({ |
$label = $("<div id='l"+i+"' class='label'>"+n+"</div>"); |
||||||
hoverClass: "ui-state-hover", |
$labels.append($label); |
||||||
activeClass: "ui-state-active",
|
$label.wrap("<div/>"); |
||||||
greedy: true, |
|
||||||
drop: function(event, ui) { |
$label.draggable({ |
||||||
var id = $(this).attr("id"); |
containment: "#scene", |
||||||
var $current = $(".inBox."+id); |
scroll: false, |
||||||
if($current.size() > 0 && $current.attr("id") != ui.draggable.attr("id")) |
snap: ".drop", |
||||||
revert($current); |
snapMode: "inner" |
||||||
ui.draggable.get(0).className = ui.draggable.get(0).className.replace(/(d(\d+))/, ""); |
}); |
||||||
ui.draggable.addClass("inBox").addClass(id); |
|
||||||
} |
$drop = $("<div id='d"+i+"' class='drop'></div>"); |
||||||
}); |
$drops.append($drop); |
||||||
if(i != count-1) { |
$drop.droppable({ |
||||||
$("<div class='operator'>"+operator+"</div>").appendTo($drops); |
hoverClass: "ui-state-hover", |
||||||
} |
activeClass: "ui-state-active",
|
||||||
}; |
greedy: true, |
||||||
|
drop: function(event, ui) { |
||||||
$scene.droppable({ |
var id = $(this).attr("id"); |
||||||
drop: function(event, ui) { |
var $current = $(".inBox."+id); |
||||||
revert(ui.draggable); |
if($current.size() > 0 && $current.attr("id") != ui.draggable.attr("id")) |
||||||
} |
revert($current); |
||||||
}); |
ui.draggable.get(0).className = ui.draggable.get(0).className.replace(/(d(\d+))/, ""); |
||||||
|
ui.draggable.addClass("inBox").addClass(id); |
||||||
|
} |
||||||
|
}); |
||||||
|
if(i != count-1) { |
||||||
|
$("<div class='operator'>"+operator+"</div>").appendTo($drops); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$scene.droppable({ |
||||||
|
drop: function(event, ui) { |
||||||
|
revert(ui.draggable); |
||||||
|
} |
||||||
|
}); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
function reloadCallback(parameter) { |
function reloadCallback(parameter) { |
||||||
if(parameter === undefined) |
if(parameter === undefined) |
||||||
reloadApp(this); |
reloadApp(this); |
||||||
} |
} |
||||||
|
|
||||||
$(document).ready(function(){ |
$(document).ready(function(){ |
||||||
var callbacks = { |
var callbacks = { |
||||||
onTemplatesLoaded: onTemplateLoadedCallback, |
onTemplatesLoaded: onTemplateLoadedCallback, |
||||||
onEdit: reloadApp, |
onEdit: reloadApp, |
||||||
onView: reloadApp |
onView: reloadApp |
||||||
}; |
}; |
||||||
init(reloadCallback, {toolbar: toolbarTemplate, parameters: parametersTemplate}, callbacks); |
init(reloadCallback, { |
||||||
|
toolbar: toolbarTemplate,
|
||||||
|
parameters: parametersTemplate |
||||||
|
}, callbacks); |
||||||
}); |
}); |
Loading…
Reference in new issue