-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
217 lines (186 loc) · 5.9 KB
/
index.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<html>
<head>
<meta charset="utf-8">
<script src="js/notes.js" type="text/javascript"></script>
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
<script src="js/jquery-mousewheel-3.0.6/jquery.mousewheel.min.js" type="text/javascript"></script>
<script src="js/jquery.base64.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<script>
var theta = 10;
var new_note_text = "edit me!";
var floater = false;
var on_note = false;
var colors = { 1:"yellow",
2:"pink" };
var total_colors = Object.keys(colors).length;
function page_scroll_avoid(){
$('body').css('overflow', 'hidden');
$(window).scroll(function(){
$(this).scrollTop(top).scrollLeft(left);
});
}
function page_scroll_allow(){
$('body').css('overflow', 'auto');
$(window).unbind('scroll');
}
function context_show(note){
$(note).children('span.delete_icon').show();
$(note).children('span.color_icon').show();
$(note).children('span.resize_icon').show();
}
function context_hide(note){
$(note).children('span.delete_icon').hide();
$(note).children('span.color_icon').hide();
$(note).children('span.resize_icon').hide();
}
function save_load_binding(){
$('span.save').click(save);
$('span.load').click(load);
}
function save(){
inputs_set_attr();
textarea_set_placeholder();
var html = $('.canvas').clone();
var htmlString = html.html();
var data = $.base64.encode(htmlString);
$.ajax({
url: 'ajax_save.php',
type: 'POST',
data: { canvas: data},
success: function(data) {
alert(data);
}
});
}
function inputs_set_attr(){
$.each($('input'),function(){
$(this).attr('value', $(this).val());
});
}
function textarea_set_placeholder(){
$.each($('textarea'),function(){
$(this).html($(this).val());
});
}
function load(){
$.ajax({
url: 'ajax_load.php',
success: function(data) {
$('.canvas').html($.base64.decode(data));
$.each($('.note'),function(){
note_binding($(this));
});
canvas_binding();
save_load_binding();
}
});
}
function canvas_binding(){
$('.canvas').dblclick(function(){
if(!on_note){
var div = create_note();
$(this).append(div);
note_binding(div);
}
});
}
function create_note(){
var div = $(document.createElement('div')).addClass('note ui-draggable yellow');
var span = $(document.createElement('span')).addClass('text');
var input = $(document.createElement('input'));
var textarea = $(document.createElement('textarea'));
var delete_icon = $(document.createElement('span')).addClass('delete_icon');
var color_icon = $(document.createElement('span')).addClass('color_icon');
var resize_icon = $(document.createElement('span')).addClass('resize_icon');
$(input).attr('size', '10');
$(input).attr('value', new_note_text);
$(delete_icon).attr('title', "delete");
$(color_icon).attr('title', "color");
$(resize_icon).attr('title', "resize");
/*$(span).append(input);*/
$(span).append(textarea);
$(div).append(span);
//$(div).append(resize_icon);
$(div).append(color_icon);
$(div).append(delete_icon);
return div;
}
function note_binding(note){
$(note).data('angle' , 0);
$(note).data('color' , 0);
$(note).draggable({ containment: ".canvas", scroll: false });
$(note).children('span.delete_icon').click(function(){
$(note).remove();
});
$(note).children('span.color_icon').click(function(){
$.each(colors,function(){
$(note).removeClass(this.toString());
});
var color = ($(note).data('color') + 1)%(total_colors);
$(note).data('color' , color);
$(note).addClass(colors[color+1]);
});
$(note).children('span.resize_icon').click(function(){
$(note).remove();
});
$(note).bind('mousewheel', function(event, delta) {
var old = $(this).data('angle');
$(this).data('angle', old + theta*delta*(-1));
$(this).css('-moz-transform', 'rotate('+ $(this).data('angle') +'deg)');
$(this).css('-webkit-transform', 'rotate('+ $(this).data('angle') +'deg)');
});
$(note).mouseover(function(){
on_note = true;
page_scroll_avoid();
context_show($(this));
});
$(note).mouseout(function(){
on_note = false;
page_scroll_allow();
context_hide($(this));
});
}
$(function() {
note_binding('.note');
$('.canvas').dblclick(function(){
if(!on_note){
var div = create_note();
$(this).append(div);
note_binding(div);
}
});
save_load_binding();
$('span.save').click(save);
$('span.load').click(load);
});
</script>
<body>
<h1>Post-It App</h1>
<div class="canvas">
<span class="save" title="save"></span>
<span class="load" title="load"></span>
<!-- BEGIN Note -->
<div class="note pink">
<span class="text">
<!--<input type="text" size="10" value="Some idea">-->
<textarea rows="4" cols="8" class="area">Nota</textarea>
</span>
<!--<span class="icon resize_icon" title="resize"></span>-->
<span class="icon color_icon" title="color"></span>
<span class="icon delete_icon" title="delete"></span>
</div>
<!--- END Note -->
</div>
<div class="instructions">
<ul>
<li>Drag-and-Drop notes</li>
<li>Double click the canvas for a new note</li>
<li>Activate the mouse wheel over a note to rotate it</li>
<li>Click a note in the center for editing</li>
</ul>
</div>
</body>
</html>