-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtower.js
104 lines (99 loc) · 3.98 KB
/
tower.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
tower = $(function(){
return {
num : 1,
n : 0,
sizeOfBlocks : function(){
n = n < 3 ? 4 : n;
var start=10,
end=30,
width=[],
part=(end-start)/n,
j=0,
height=parseInt(500/n);
for (var i=part;i<=end-start;i += part){
width[j]=parseInt(start+i);
j++;
}
//alter
var pt=parseInt((100-10)/n),
wth=[];
j=0;
for (var z=10;z<=100;z += pt){
wth[j]=parseInt(z);
j++;
}
console.log(width);
console.log(height);
console.log(wth);
},
init : function(){
var n=($('#NumberOfBlocks').attr('value')>0)?$('#NumberOfBlocks').attr('value'):4,
width=40,
height=150/n;
$('.takeit').html('');
//$("#block1").html('');
//$("#block2").html('');
//$("#block3").html('');
for (var i = 1; i <= n; i++) {
$('#block1').append('<div align="center" id="'+i+ '" class="textBlock" number="'+i+'" lst="1">'+i+'</div>');
$('#'+i).css('width',(width-(n-2*i*i))+'%').css('height',height+'px');
}
$('#block1').children().first().draggable({
revert:'invalid'
}).draggable('enable');
},
save : function(){
$('#block3').children().draggable( 'disable' );
$.post("save.php",
{tofile: $('#res').html()},function(data){
$('#dialog-intro').html('Вы победили за '+(num-1)+' иттераций! <a href="logs/'+data+'"> Здесь хранится запись ваших шагов </a>');
$('#dialog').dialog();
});
},
pp : function(){
$('.takeit').children().draggable('disable');
//$('#block1').children().draggable( 'disable' );
//$('#block2').children().draggable( 'disable' );
//$('#block3').children().draggable( 'disable' );
//$('#block1').children().first().draggable({
//helper:'clone'
// revert:'invalid'
// }).draggable( 'enable' );
$('.takeit').children().first().draggable({revert:'invalid'}).draggable('enable');
/*$('#block2').children().first().draggable({
//helper:'clone'
revert:"invalid"
}).draggable( 'enable' );
$('#block3').children().first().draggable({
//helper:'clone'
revert:"invalid"
}).draggable( 'enable' );
*/
$('#block1').children().first().draggable( 'enable' );
$('div.wrapper').children().droppable({
hoverClass: 'dropHere',//accept:function(el){return el.hasClass("someClass")}
drop: function(event, ui) {
if(!$(this).is('.textBlock')){
if ($(this).children().first().attr('number')>ui.draggable.attr('number') || $(this).children().is('.textBlock')!=true) {
if($(this).attr('lst')!=ui.draggable.attr('lst')){
$('#res').append(' \r\n №'+num/*ui.draggable.attr('number')*/+' '+ui.draggable.attr('lst')+' -> '+$(this).attr('lst'));
}
ui.draggable.attr('lst',$(this).attr('lst'));
$(this).prepend($('<div id="'+ui.draggable.attr('id')+ '" class="textBlock" number="'+ui.draggable.attr('number')+'" lst="'+ui.draggable.attr('lst')+'" style="width:'+ui.draggable.css('width')+';height:'+ui.draggable. css(' height')+'">' + ui.draggable.html() + '</div>'));
num++;
ui.draggable.remove();
pp();
} else {
$('#block'+ui.draggable.attr('lst')).prepend($('<div id="'+ui.draggable.attr('id')+ '" class="textBlock" number="'+ui.draggable.attr('number')+'" lst="'+ui.draggable.attr('lst')+'" style="width:'+ui.draggable.css(' width')+ ';height:'+ui.draggable.css('height')+';">' + ui.draggable.html() + '</div>'));
ui.draggable.remove();
pp();
}
}
if ($('#block3').children().length == n){
save();
}
}
});
}
}
});